home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / message / dimess.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  1.9 KB  |  87 lines

  1. /*
  2.  *  Function Name:   DispatchMessage
  3.  *
  4.  *  Description:
  5.  *   This function passes all messages from the main procedure (WinMain) to
  6.  *   the window procedure.  It passes the message in the MSG structure to the
  7.  *   window function of the specified window.
  8.  */
  9.  
  10. #include "windows.h"
  11.  
  12. long    FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  13.  
  14.  
  15.  
  16. int    PASCAL WinMain(hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  17. HANDLE      hInstance, hPrevInstance;
  18. LPSTR      lpszCmdLine;
  19. int    cmdShow;
  20. {
  21.   MSG         msg;
  22.   HWND         hWnd;
  23.   WNDCLASS   wcClass;
  24.  
  25.   if (!hPrevInstance)
  26.   {
  27.     wcClass.style       = CS_HREDRAW | CS_VREDRAW;
  28.     wcClass.lpfnWndProc    = WndProc;
  29.     wcClass.cbClsExtra       = 0;
  30.     wcClass.cbWndExtra       = 0;
  31.     wcClass.hInstance       = hInstance;
  32.     wcClass.hIcon       = LoadIcon(hInstance, NULL);
  33.     wcClass.hCursor       = LoadCursor(NULL, IDC_ARROW);
  34.     wcClass.hbrBackground  = (HBRUSH)GetStockObject(WHITE_BRUSH);
  35.     wcClass.lpszMenuName   = NULL;
  36.     wcClass.lpszClassName  = "DispatchMessage";
  37.  
  38.     if (!RegisterClass(&wcClass))
  39.       return FALSE;
  40.   }
  41.  
  42.   hWnd = CreateWindow("DispatchMessage",
  43.       "DispatchMessage()",
  44.       WS_OVERLAPPEDWINDOW,
  45.       CW_USEDEFAULT,
  46.       CW_USEDEFAULT,
  47.       CW_USEDEFAULT,
  48.       CW_USEDEFAULT,
  49.       NULL,
  50.       NULL,
  51.       hInstance,
  52.       NULL);
  53.  
  54.   ShowWindow(hWnd, cmdShow);
  55.   UpdateWindow(hWnd);
  56.   MessageBox(hWnd, "DispatchMessage working in loop",
  57.       "DispatchMessage", MB_ICONASTERISK);
  58.   while (GetMessage(&msg, NULL, 0, 0))
  59.   {
  60.     TranslateMessage(&msg);
  61.     DispatchMessage(&msg);
  62.   }
  63.   return msg.wParam;
  64. }
  65.  
  66.  
  67. long    FAR PASCAL WndProc(hWnd, message, wParam, lParam)
  68. HWND       hWnd;
  69. unsigned    message;
  70. WORD       wParam;
  71. LONG       lParam;
  72. {
  73.   switch (message)
  74.   {
  75.   case WM_DESTROY:
  76.     {
  77.       PostQuitMessage(0);
  78.       break;
  79.     }
  80.   default:
  81.     return DefWindowProc(hWnd, message, wParam, lParam);
  82.   }
  83.   return(0L);
  84. }
  85.  
  86.  
  87.