home *** CD-ROM | disk | FTP | other *** search
/ Chestnut's Multimedia Mania / MM_MANIA.ISO / players / winbeep / winbeep.c < prev    next >
C/C++ Source or Header  |  1990-08-10  |  7KB  |  226 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: WinBeep.c
  4.  
  5.     PURPOSE: WinBeep template for Windows applications
  6.  
  7.     FUNCTIONS:
  8.  
  9.     WinMain() - calls initialization function, processes message loop
  10.     WinBeepInit() - initializes window data and registers window
  11.     WinBeepWndProc() - processes messages
  12.     About() - processes messages for "About" dialog box
  13.  
  14. ****************************************************************************/
  15.  
  16. #include "windows.h"            /* required for all Windows applications */
  17. #include "WinBeep.h"            /* specific to this program             */
  18. #include "Sm.h"
  19.  
  20.     HANDLE    hInst;            /* current instance      */
  21.     HANDLE    hMenu;             /* Handle to my new menu */
  22.  
  23.     char    szAppName[]="WinBeep";
  24.  
  25. static BOOL WinBeepInit(HANDLE);
  26.  
  27. /****************************************************************************
  28.  
  29.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  30.  
  31.     PURPOSE: calls initialization function, processes message loop
  32.  
  33.     COMMENTS:
  34.  
  35.     This will initialize the window class if it is the first time this
  36.     application is run.  It then creates the window, and processes the
  37.     message loop until a PostQuitMessage is received.  It exits the
  38.     application by returning the value passed by the PostQuitMessage.
  39.  
  40. ****************************************************************************/
  41.  
  42. unsigned int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  43. /*                        current instance   previous instance     command line   show-window type (open/icon) */
  44. {
  45.     HWND hWnd;                     /* window handle             */
  46.     MSG msg;                     /* message                 */
  47.  
  48.  
  49.     if (!hPrevInstance)            /* Has application been initialized? */
  50.         if (!WinBeepInit(hInstance))    
  51.             return (NULL);       /* Exits if unable to initialize     */
  52.  
  53.     hInst = hInstance;            /* Saves the current instance         */
  54.  
  55.     hMenu = LoadMenu(hInstance, "WinBeepMenu");
  56.  
  57.     hWnd = CreateWindow(szAppName,  /* window class         */
  58.      "WinBeep Windows Application",  /* window name         */
  59.     WS_OVERLAPPEDWINDOW,              /* window style         */
  60.     CW_USEDEFAULT,                  /* x position             */
  61.     CW_USEDEFAULT,                  /* y position             */
  62.     CW_USEDEFAULT,                  /* width             */
  63.     CW_USEDEFAULT,                  /* height             */
  64.     NULL,                      /* parent handle         */
  65.     hMenu,                      /* menu or child ID         */
  66.     hInstance,                  /* instance             */
  67.     NULL);                      /* additional info         */
  68.  
  69.     if (!hWnd)                      /* Was the window created? */
  70.         return (NULL);
  71.  
  72.     ShowWindow(hWnd, SW_SHOWMINNOACTIVE);              /* Shows the window         */
  73.     UpdateWindow(hWnd);                  /* Sends WM_PAINT message  */
  74.  
  75.     while (GetMessage(&msg,           /* message structure                 */
  76.         NULL,               /* handle of window receiving the message */
  77.         NULL,               /* lowest message to examine             */
  78.         NULL)) {           /* highest message to examine         */
  79.         TranslateMessage(&msg);    /* Translates virtual key codes         */
  80.         DispatchMessage(&msg);    /* Dispatches message to window         */
  81.         }
  82.     return (msg.wParam);           /* Returns the value from PostQuitMessage */
  83. }
  84.  
  85.  
  86. /****************************************************************************
  87.  
  88.     FUNCTION: WinBeepInit(HANDLE)
  89.  
  90.     PURPOSE: Initializes window data and registers window class
  91.  
  92. ****************************************************************************/
  93.  
  94. static BOOL WinBeepInit(HANDLE hInstance)
  95.                 /* current instance  */
  96. {
  97.     HANDLE hMemory;                   /* handle to allocated memory */
  98.     PWNDCLASS pWndClass;               /* structure pointer         */
  99.     BOOL bSuccess;                   /* RegisterClass() result     */
  100.  
  101.     hMemory   = LocalAlloc(LPTR, sizeof(WNDCLASS));
  102.     pWndClass = (PWNDCLASS) LocalLock(hMemory);
  103.  
  104.     pWndClass->style          = NULL;
  105.     pWndClass->lpfnWndProc    = WinBeepWndProc;
  106.     pWndClass->hInstance      = hInstance;
  107.     pWndClass->hIcon          = LoadIcon(NULL, IDI_APPLICATION);
  108.     pWndClass->hCursor        = LoadCursor(NULL, IDC_ARROW);
  109.     pWndClass->hbrBackground  = GetStockObject(WHITE_BRUSH);
  110.     pWndClass->lpszMenuName   = "WinBeepMenu";
  111.     pWndClass->lpszClassName  = (LPSTR) szAppName;
  112.  
  113.     bSuccess = RegisterClass(pWndClass);
  114.  
  115.     LocalUnlock(hMemory);              /* Unlocks the memory    */
  116.     LocalFree(hMemory);              /* Returns it to Windows */
  117.  
  118.     return (bSuccess);         /* Returns result of registering the window */
  119. }
  120.  
  121. /****************************************************************************
  122.  
  123.     FUNCTION: WinBeepWndProc(HWND, unsigned, WORD, LONG)
  124.  
  125.     PURPOSE:  Processes messages
  126.  
  127.     MESSAGES:
  128.  
  129.     WM_CREATE    - create window
  130.     WM_DESTROY    - destroy window
  131.     WM_COMMAND    - menu selections and others
  132.  
  133.     COMMENTS:
  134.  
  135.  
  136. ****************************************************************************/
  137.  
  138. long FAR PASCAL WinBeepWndProc(HWND hWnd, unsigned int message, WORD wParam, LONG lParam)
  139. /*                  window handle  type of message      additional information  */
  140. {
  141.     HMENU  hlMenu;            /* local handle to the System menu  */
  142.     HANDLE hResource;
  143.     LPSTR  lpSound;
  144.  
  145.     switch (message) {
  146.  
  147.         case WM_CREATE:        /* message: window being created */
  148.         break;
  149.  
  150.        case WM_MBUTTONDOWN:
  151.         DestroyWindow(hWnd);
  152.         break;
  153.  
  154.        case WM_DESTROY:        /* message: window being destroyed */
  155.         PostQuitMessage(0);
  156.         break;
  157.  
  158.        case WM_QUERYOPEN:        /* Keep the ICON an ICON */
  159.         break;
  160.  
  161.        case WM_RBUTTONDOWN:
  162.        case WM_LBUTTONDOWN:
  163.         MessageBeep(5);
  164.         hResource=LoadResource(hInst,
  165.               FindResource(hInst,"bit3A","SOUND"));
  166.  
  167.         lpSound=LockResource(hResource);
  168.         say3s(lpSound,GlobalSize(hResource),0,4,0,0);
  169.  
  170.         UnlockResource(hResource);
  171.  
  172.         GlobalUnlock(hResource);
  173.         FreeResource(hResource);
  174.  
  175. //---------------------------
  176.         hResource=LoadResource(hInst,
  177.                 FindResource(hInst,"bit3b","SOUND"));
  178.  
  179.         lpSound=LockResource(hResource);
  180.         say3s(lpSound,GlobalSize(hResource),0,4,0,0);
  181.  
  182.         UnlockResource(hResource);
  183.         GlobalUnlock(hResource);
  184.         FreeResource(hResource);
  185. //-----------------------------
  186.         hResource=LoadResource(hInst,
  187.               FindResource(hInst,"Bit8","SOUND"));
  188.  
  189.         lpSound=LockResource(hResource);
  190.         say8(lpSound,GlobalSize(hResource),000,4,0);
  191.  
  192.         UnlockResource(hResource);
  193.         GlobalUnlock(hResource);
  194.         FreeResource(hResource);
  195.  
  196.         MessageBeep(5);
  197.         break;
  198.         
  199.         
  200.        case WM_COMMAND:
  201.         switch (wParam) {
  202.             case IDM_NEW:        
  203.             case IDM_OPEN:
  204.             case IDM_SAVE:        
  205.             case IDM_SAVEAS:
  206.                 case IDM_ABOUT:
  207.             MessageBox(hWnd, "Command not implemented", (LPSTR) NULL, MB_OK);
  208.             break;
  209.  
  210.             case IDM_EXIT:
  211.             DestroyWindow(hWnd);
  212.             break;
  213.  
  214.             default: break;
  215.  
  216.             }
  217.         break;
  218.  
  219.         default:              /* Passes it on if unproccessed    */
  220.         return (DefWindowProc(hWnd, message, wParam, lParam));
  221.         }
  222.  
  223.     return (NULL);
  224. }
  225.  
  226.