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

  1. /*
  2.  
  3. Description:   This function specifies whether the current window function
  4.     is processing a message that is passed to it through a call to the 
  5.     SendMessage function.
  6.  
  7. */
  8.  
  9.  
  10. #include <windows.h>
  11. #include "Reply.h"
  12. #include "string.h"
  13. #include "stdio.h"
  14.  
  15.        char         szAppName             [] = "Reply"             ;
  16.        HANDLE       hInstMain                                      ;
  17.        HWND         hWndMain                                       ;
  18.        char         szOutputBuffer1       [70]                     ;
  19.        char         szOutputBuffer2       [600]                    ;
  20.  
  21. /****************************************************************************/
  22. /************************    Message Structure      *************************/
  23. /****************************************************************************/
  24.  
  25. struct { char *szMessage; }
  26.        Messages [] = {
  27. "About\0",
  28. "     This is a sample application to demonstrate the\n\
  29. use  of  the  ReplyMessage Windows function.  ",
  30.  
  31. "Help Message",
  32. "     Sample program to illustrate the use of ReplyMessage.\n\
  33. Use the WINSPAWN program to spawn this program in one of\n\
  34. two ways.  The first way, 'Reply Using ReplyMessage',\n\
  35. will capture the input focus using the ReplyMessage\n\
  36. Windows Function.   The second way, 'Reply Regular Spawn',\n\
  37. will not capture the focus.",
  38.  
  39. "In Reply",
  40. "     Message sent and received from within Reply.\n\
  41. The Reply program has successfully captured the input\n\
  42. focus."
  43.  
  44. };    
  45. /****************************************************************************/
  46.  
  47. void ProcessMessage (HWND, int); 
  48.  
  49. void ProcessMessage (hWnd, MessageNumber) 
  50.      HWND     hWnd;
  51.      int      MessageNumber;
  52. {
  53.      sprintf (szOutputBuffer1, "%s", Messages [MessageNumber]);
  54.      sprintf (szOutputBuffer2, "%s", Messages [MessageNumber + 1]);
  55.      MessageBox (hWnd, szOutputBuffer2, szOutputBuffer1, MB_OK);
  56. }       
  57.  
  58. /****************************************************************************/
  59.  
  60. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  61.     HANDLE    hInstance, hPrevInstance;
  62.     LPSTR    lpszCmdLine;
  63.     int     nCmdShow;
  64.     {
  65.     HWND    hWnd;
  66.     MSG     msg;
  67.     WNDCLASS    wndclass;
  68.     HMENU    hMenu;
  69.     short   xScreen, yScreen;
  70.  
  71.  
  72.     if (!hPrevInstance)
  73.     {
  74.     wndclass.style             = CS_HREDRAW | CS_VREDRAW | CS_SAVEBITS;
  75.     wndclass.lpfnWndProc    = WndProc;
  76.     wndclass.cbClsExtra     = 0;
  77.     wndclass.cbWndExtra     = 0;
  78.     wndclass.hInstance      = hInstance;
  79.     wndclass.hIcon             = NULL; 
  80.    wndclass.hCursor        = LoadCursor (NULL, IDC_ARROW) ;
  81.     wndclass.hbrBackground    = GetStockObject (WHITE_BRUSH);
  82.     wndclass.lpszMenuName    = szAppName;
  83.     wndclass.lpszClassName    = szAppName;
  84.  
  85.     if (!RegisterClass (&wndclass) )
  86.         return FALSE;
  87.     }
  88.  
  89.      xScreen = GetSystemMetrics (SM_CXSCREEN);
  90.     yScreen = GetSystemMetrics (SM_CYSCREEN);
  91.  
  92.     hWnd = CreateWindow (szAppName, "Reply",
  93.            WS_OVERLAPPEDWINDOW, xScreen / 7, yScreen / 58,
  94.            xScreen * 3 / 4, yScreen * 49 / 50, NULL, NULL,
  95.            hInstance, NULL);
  96.  
  97.     hInstMain = hInstance;
  98.     hWndMain  = hWnd;
  99.  
  100.     ShowWindow (hWnd, nCmdShow);
  101.     UpdateWindow (hWnd);
  102.  
  103.     while (GetMessage (&msg, NULL, 0, 0))
  104.         {
  105.         TranslateMessage (&msg);
  106.         DispatchMessage (&msg);
  107.         }
  108.  
  109.     return msg.wParam;
  110. }
  111. /****************************************************************************/
  112.  
  113. long FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  114.    HWND      hWnd;
  115.    unsigned  iMessage;
  116.    WORD      wParam;
  117.    LONG      lParam;
  118.    {
  119.    HMENU         hMenu;
  120.    int           Index;
  121.    HANDLE        hDC;
  122.    HDC           hMemoryDC;
  123.    BITMAP        Bitmap;
  124.     short         foo;
  125.    BOOL          InSend;
  126.  
  127.    switch (iMessage)
  128.        {
  129.        case WM_CREATE:
  130.             hMenu = GetSystemMenu (hWnd, FALSE);
  131.      
  132.             ChangeMenu (hMenu, NULL, "&About", IDM_ABOUT, 
  133.                         MF_APPEND | MF_STRING);
  134.             break;
  135.  
  136.        case WM_SIZE:
  137.             break;
  138.  
  139.        case WM_SYSCOMMAND:
  140.             switch (wParam) {
  141.                case IDM_ABOUT:
  142.                     ProcessMessage (hWnd, 0);
  143.                     break;
  144.                default:
  145.                     return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
  146.             }
  147.        break;
  148.  
  149.  
  150.        case WM_COMMAND:
  151.             switch (wParam) {
  152.               case IDM_RECEIVE:
  153.                    ProcessMessage (hWnd, 4);
  154.                    break;
  155.  
  156.               case IDM_SEND:
  157.                    ReplyMessage (1L);
  158.                    SendMessage (hWnd, WM_COMMAND, IDM_RECEIVE, 0L);
  159.                    break;
  160.  
  161.               case IDM_REGULAR:
  162.                    break;
  163.  
  164.               case IDM_HELP:
  165.                    ProcessMessage (hWnd, 2);
  166.                    break;
  167.              }
  168.             break;
  169.  
  170.        case WM_DESTROY:
  171.             PostQuitMessage (0);
  172.             break;
  173.  
  174.         default:
  175.             return DefWindowProc( hWnd, iMessage, wParam, lParam );
  176.        }
  177.     return 0L;
  178. }
  179.  
  180. /****************************************************************************/
  181.  
  182.