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

  1. /*
  2.  *  SendMessage
  3.  *  sendmsg.c,
  4.  *
  5.  *  This program demonstrates the use of the function SendMessage.
  6.  *  It sends a message to the specified window immediately without
  7.  *  putting the message in the application queue. SendMessage does not
  8.  *  return until the message has been processed. The window function 
  9.  *  is called immediately, as a subroutine.
  10.  *
  11.  */
  12.  
  13. #include "windows.h"
  14.  
  15. long FAR PASCAL SampleWindowProc (HWND, unsigned, WORD, LONG);
  16.  
  17. /* Procedure called when the application is loaded for the first time */
  18. BOOL WinInit( hInstance )
  19. HANDLE hInstance;
  20. {
  21.     WNDCLASS   wcClass;
  22.  
  23.     /* registering the parent window class */
  24.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  25.     wcClass.hIcon          = LoadIcon (hInstance, (LPSTR)"WindowIcon");
  26.     wcClass.lpszMenuName   = (LPSTR)NULL;
  27.     wcClass.lpszClassName  = (LPSTR)"Sendmsg";
  28.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  29.     wcClass.hInstance      = hInstance;
  30.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  31.     wcClass.lpfnWndProc    = SampleWindowProc;
  32.     wcClass.cbClsExtra     = 0;
  33.     wcClass.cbWndExtra     = 0;
  34.  
  35.     RegisterClass( (LPWNDCLASS)&wcClass );
  36.     return TRUE;        /* Initialization succeeded */
  37. }
  38.  
  39.  
  40. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  41. HANDLE hInstance, hPrevInstance;
  42. LPSTR lpszCmdLine;
  43. int cmdShow;
  44. {
  45.     HWND   hWnd;                /* Handle to the parent window     */
  46.     MSG    msg;                 /* Message received from the queue */
  47.  
  48.     WinInit (hInstance);
  49.  
  50.     hWnd = CreateWindow((LPSTR)"Sendmsg",
  51.                         (LPSTR)"Sending Messages",
  52.                         WS_OVERLAPPEDWINDOW,
  53.                         50,                /* x         */
  54.                         50,                /* y         */
  55.                         600,               /* width     */
  56.                         250,               /* height    */
  57.                         (HWND)NULL,        /* no parent */
  58.                         (HMENU)NULL,       /* use class menu */
  59.                         (HANDLE)hInstance, /* handle to window instance */
  60.                         (LPSTR)NULL        /* no params to pass on */
  61.                        );
  62.  
  63.     /* Make window visible according to the way the app is activated */
  64.     ShowWindow( hWnd, cmdShow );
  65.     UpdateWindow( hWnd );
  66.  
  67.     /* Sending the window a WM_DESTROY message directly to the 
  68.      * window procedure immediately
  69.      */
  70.     MessageBox (hWnd, (LPSTR)"Sending the window a destroy message", 
  71.                 (LPSTR)"SENDING", MB_OK);
  72.     SendMessage (hWnd, WM_DESTROY, 0,0L);
  73.  
  74.     return 0;
  75. }
  76.  
  77. /* The window procedure for this program */
  78. long FAR PASCAL SampleWindowProc (hWnd, message, wParam, lParam)
  79. HWND hWnd;
  80. unsigned message;
  81. WORD wParam;
  82. LONG lParam;
  83. {
  84.     switch (message)
  85.       {  case WM_DESTROY:
  86.            MessageBox (hWnd, (LPSTR)"Destroy Message Received", 
  87.                        (LPSTR)"RECEIVED", MB_OK);
  88.            PostQuitMessage (0);
  89.            break;
  90.  
  91.          default:
  92.            return (DefWindowProc (hWnd, message, wParam, lParam));
  93.            break;
  94.       }
  95.     return 0L;
  96. }
  97.