home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chestnut's Multimedia Mania
/
MM_MANIA.ISO
/
players
/
winbeep
/
winbeep.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-10
|
7KB
|
226 lines
/****************************************************************************
PROGRAM: WinBeep.c
PURPOSE: WinBeep template for Windows applications
FUNCTIONS:
WinMain() - calls initialization function, processes message loop
WinBeepInit() - initializes window data and registers window
WinBeepWndProc() - processes messages
About() - processes messages for "About" dialog box
****************************************************************************/
#include "windows.h" /* required for all Windows applications */
#include "WinBeep.h" /* specific to this program */
#include "Sm.h"
HANDLE hInst; /* current instance */
HANDLE hMenu; /* Handle to my new menu */
char szAppName[]="WinBeep";
static BOOL WinBeepInit(HANDLE);
/****************************************************************************
FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
PURPOSE: calls initialization function, processes message loop
COMMENTS:
This will initialize the window class if it is the first time this
application is run. It then creates the window, and processes the
message loop until a PostQuitMessage is received. It exits the
application by returning the value passed by the PostQuitMessage.
****************************************************************************/
unsigned int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
/* current instance previous instance command line show-window type (open/icon) */
{
HWND hWnd; /* window handle */
MSG msg; /* message */
if (!hPrevInstance) /* Has application been initialized? */
if (!WinBeepInit(hInstance))
return (NULL); /* Exits if unable to initialize */
hInst = hInstance; /* Saves the current instance */
hMenu = LoadMenu(hInstance, "WinBeepMenu");
hWnd = CreateWindow(szAppName, /* window class */
"WinBeep Windows Application", /* window name */
WS_OVERLAPPEDWINDOW, /* window style */
CW_USEDEFAULT, /* x position */
CW_USEDEFAULT, /* y position */
CW_USEDEFAULT, /* width */
CW_USEDEFAULT, /* height */
NULL, /* parent handle */
hMenu, /* menu or child ID */
hInstance, /* instance */
NULL); /* additional info */
if (!hWnd) /* Was the window created? */
return (NULL);
ShowWindow(hWnd, SW_SHOWMINNOACTIVE); /* Shows the window */
UpdateWindow(hWnd); /* Sends WM_PAINT message */
while (GetMessage(&msg, /* message structure */
NULL, /* handle of window receiving the message */
NULL, /* lowest message to examine */
NULL)) { /* highest message to examine */
TranslateMessage(&msg); /* Translates virtual key codes */
DispatchMessage(&msg); /* Dispatches message to window */
}
return (msg.wParam); /* Returns the value from PostQuitMessage */
}
/****************************************************************************
FUNCTION: WinBeepInit(HANDLE)
PURPOSE: Initializes window data and registers window class
****************************************************************************/
static BOOL WinBeepInit(HANDLE hInstance)
/* current instance */
{
HANDLE hMemory; /* handle to allocated memory */
PWNDCLASS pWndClass; /* structure pointer */
BOOL bSuccess; /* RegisterClass() result */
hMemory = LocalAlloc(LPTR, sizeof(WNDCLASS));
pWndClass = (PWNDCLASS) LocalLock(hMemory);
pWndClass->style = NULL;
pWndClass->lpfnWndProc = WinBeepWndProc;
pWndClass->hInstance = hInstance;
pWndClass->hIcon = LoadIcon(NULL, IDI_APPLICATION);
pWndClass->hCursor = LoadCursor(NULL, IDC_ARROW);
pWndClass->hbrBackground = GetStockObject(WHITE_BRUSH);
pWndClass->lpszMenuName = "WinBeepMenu";
pWndClass->lpszClassName = (LPSTR) szAppName;
bSuccess = RegisterClass(pWndClass);
LocalUnlock(hMemory); /* Unlocks the memory */
LocalFree(hMemory); /* Returns it to Windows */
return (bSuccess); /* Returns result of registering the window */
}
/****************************************************************************
FUNCTION: WinBeepWndProc(HWND, unsigned, WORD, LONG)
PURPOSE: Processes messages
MESSAGES:
WM_CREATE - create window
WM_DESTROY - destroy window
WM_COMMAND - menu selections and others
COMMENTS:
****************************************************************************/
long FAR PASCAL WinBeepWndProc(HWND hWnd, unsigned int message, WORD wParam, LONG lParam)
/* window handle type of message additional information */
{
HMENU hlMenu; /* local handle to the System menu */
HANDLE hResource;
LPSTR lpSound;
switch (message) {
case WM_CREATE: /* message: window being created */
break;
case WM_MBUTTONDOWN:
DestroyWindow(hWnd);
break;
case WM_DESTROY: /* message: window being destroyed */
PostQuitMessage(0);
break;
case WM_QUERYOPEN: /* Keep the ICON an ICON */
break;
case WM_RBUTTONDOWN:
case WM_LBUTTONDOWN:
MessageBeep(5);
hResource=LoadResource(hInst,
FindResource(hInst,"bit3A","SOUND"));
lpSound=LockResource(hResource);
say3s(lpSound,GlobalSize(hResource),0,4,0,0);
UnlockResource(hResource);
GlobalUnlock(hResource);
FreeResource(hResource);
//---------------------------
hResource=LoadResource(hInst,
FindResource(hInst,"bit3b","SOUND"));
lpSound=LockResource(hResource);
say3s(lpSound,GlobalSize(hResource),0,4,0,0);
UnlockResource(hResource);
GlobalUnlock(hResource);
FreeResource(hResource);
//-----------------------------
hResource=LoadResource(hInst,
FindResource(hInst,"Bit8","SOUND"));
lpSound=LockResource(hResource);
say8(lpSound,GlobalSize(hResource),000,4,0);
UnlockResource(hResource);
GlobalUnlock(hResource);
FreeResource(hResource);
MessageBeep(5);
break;
case WM_COMMAND:
switch (wParam) {
case IDM_NEW:
case IDM_OPEN:
case IDM_SAVE:
case IDM_SAVEAS:
case IDM_ABOUT:
MessageBox(hWnd, "Command not implemented", (LPSTR) NULL, MB_OK);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default: break;
}
break;
default: /* Passes it on if unproccessed */
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return (NULL);
}