home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prog_pm / chap03 / welcome2.c next >
Encoding:
C/C++ Source or Header  |  1989-01-09  |  4.7 KB  |  126 lines

  1. /*------------------------------------------------------------
  2.    WELCOME2.C -- A Program that Creates Two Top-Level Windows
  3.   ------------------------------------------------------------*/
  4.  
  5. #define INCL_WIN
  6. #include <os2.h>
  7.  
  8. MRESULT EXPENTRY Client1WndProc (HWND, USHORT, MPARAM, MPARAM) ;
  9. MRESULT EXPENTRY Client2WndProc (HWND, USHORT, MPARAM, MPARAM) ;
  10.  
  11. int main (void)
  12.      {
  13.      static CHAR  szClientClass1 [] = "Welcome2.1",
  14.                   szClientClass2 [] = "Welcome2.2" ;
  15.      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
  16.                                  FCF_SIZEBORDER    | FCF_MINMAX  |
  17.                                  FCF_SHELLPOSITION | FCF_TASKLIST ;
  18.      HAB          hab ;
  19.      HMQ          hmq ;
  20.      HWND         hwndFrame1, hwndFrame2, hwndClient1, hwndClient2 ;
  21.      QMSG         qmsg ;
  22.  
  23.      hab = WinInitialize (0) ;
  24.      hmq = WinCreateMsgQueue (hab, 0) ;
  25.  
  26.      WinRegisterClass (
  27.                     hab,                // Anchor block handle
  28.                     szClientClass1,     // Name of class being registered
  29.                     Client1WndProc,     // Window procedure for class
  30.                     CS_SIZEREDRAW,      // Class style
  31.                     0) ;                // Extra bytes to reserve
  32.  
  33.      WinRegisterClass (
  34.                     hab,                // Anchor block handle
  35.                     szClientClass2,     // Name of class being registered
  36.                     Client2WndProc,     // Window procedure for class
  37.                     CS_SIZEREDRAW,      // Class style
  38.                     0) ;                // Extra bytes to reserve
  39.  
  40.      hwndFrame1 = WinCreateStdWindow (
  41.                     HWND_DESKTOP,       // Parent window handle
  42.                     WS_VISIBLE,         // Style of frame window
  43.                     &flFrameFlags,      // Pointer to control data
  44.                     szClientClass1,     // Client window class name
  45.                     NULL,               // Title bar text
  46.                     0L,                 // Style of client window
  47.                     NULL,               // Module handle for resources
  48.                     0,                  // ID of resources
  49.                     &hwndClient1) ;     // Pointer to client window handle
  50.  
  51.      hwndFrame2 = WinCreateStdWindow (
  52.                     HWND_DESKTOP,       // Parent window handle
  53.                     WS_VISIBLE,         // Style of frame window
  54.                     &flFrameFlags,      // Pointer to control data
  55.                     szClientClass2,     // Client window class name
  56.                     " - Window No. 2",  // Title bar text
  57.                     0L,                 // Style of client window
  58.                     NULL,               // Module handle for resources
  59.                     0,                  // ID of resources
  60.                     &hwndClient2) ;     // Pointer to client window handle
  61.  
  62.      WinSendMsg (hwndFrame1, WM_SETICON,
  63.                  WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
  64.                  NULL) ;
  65.  
  66.      WinSendMsg (hwndFrame2, WM_SETICON,
  67.                  WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
  68.                  NULL) ;
  69.  
  70.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  71.           WinDispatchMsg (hab, &qmsg) ;
  72.  
  73.      WinDestroyWindow (hwndFrame1) ;
  74.      WinDestroyWindow (hwndFrame2) ;
  75.      WinDestroyMsgQueue (hmq) ;
  76.      WinTerminate (hab) ;
  77.      return 0 ;
  78.      }
  79.  
  80. MRESULT EXPENTRY Client1WndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  81.      {
  82.      static CHAR szText [] = "Welcome to Window No. 1" ;
  83.      HPS         hps ;
  84.      RECTL       rcl ;
  85.  
  86.      switch (msg)
  87.           {
  88.           case WM_PAINT:
  89.                hps = WinBeginPaint (hwnd, NULL, NULL) ;
  90.  
  91.                WinQueryWindowRect (hwnd, &rcl) ;
  92.  
  93.                WinDrawText (hps, -1, szText, &rcl, CLR_NEUTRAL, CLR_BACKGROUND,
  94.                             DT_CENTER | DT_VCENTER | DT_ERASERECT) ;
  95.  
  96.                WinEndPaint (hps) ;
  97.                return 0 ;
  98.           }
  99.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  100.      }
  101.  
  102. MRESULT EXPENTRY Client2WndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  103.      {
  104.      static CHAR szText [] = "Welcome to Window No. 2" ;
  105.      HPS         hps ;
  106.      RECTL       rcl ;
  107.  
  108.      switch (msg)
  109.           {
  110.           case WM_PAINT:
  111.                hps = WinBeginPaint (hwnd, NULL, NULL) ;
  112.  
  113.                WinQueryWindowRect (hwnd, &rcl) ;
  114.  
  115.                WinDrawText (hps, -1, szText, &rcl, CLR_NEUTRAL, CLR_BACKGROUND,
  116.                             DT_CENTER | DT_VCENTER | DT_ERASERECT) ;
  117.  
  118.                WinEndPaint (hps) ;
  119.                return 0 ;
  120.  
  121.           case WM_CLOSE:
  122.                return 0 ;
  123.           }
  124.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  125.      }
  126.