home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / os2sdk / os2sdk11 / petzold / chap03 / welcome4.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-20  |  6.1 KB  |  146 lines

  1. /*-------------------------------------------------------------
  2.    WELCOME4.C -- Creates a Top-Level Window and Three Children
  3.   -------------------------------------------------------------*/
  4.  
  5. #define INCL_WIN
  6. #include <os2.h>
  7.  
  8. #define ID_BUTTON 1
  9. #define ID_SCROLL 2
  10. #define ID_ENTRY  3
  11.  
  12. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  13.  
  14. int main (void)
  15.      {
  16.      static CHAR  szClientClass [] = "Welcome4" ;
  17.      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU   |
  18.                                  FCF_BORDER        | FCF_MINBUTTON |
  19.                                  FCF_SHELLPOSITION | FCF_TASKLIST ;
  20.      HAB          hab ;
  21.      HMQ          hmq ;
  22.      HWND         hwndFrame,  hwndClient ;
  23.      QMSG         qmsg ;
  24.      RECTL        rcl ;
  25.  
  26.      hab = WinInitialize (0) ;
  27.      hmq = WinCreateMsgQueue (hab, 0) ;
  28.  
  29.      WinRegisterClass (
  30.                     hab,                // Anchor block handle
  31.                     szClientClass,      // Name of class being registered
  32.                     ClientWndProc,      // Window procedure for class
  33.                     CS_SIZEREDRAW,      // Class style
  34.                     0) ;                // Extra bytes to reserve
  35.  
  36.      hwndFrame = WinCreateStdWindow (
  37.                     HWND_DESKTOP,       // Parent window handle
  38.                     WS_VISIBLE,         // Style of frame window
  39.                     &flFrameFlags,      // Pointer to control data
  40.                     szClientClass,      // Client window class name
  41.                     NULL,               // Title bar text
  42.                     0L,                 // Style of client window
  43.                     NULL,               // Module handle for resources
  44.                     0,                  // ID of resources
  45.                     &hwndClient) ;      // Pointer to client window handle
  46.  
  47.      WinSendMsg (hwndFrame, WM_SETICON,
  48.                       WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
  49.                       NULL) ;
  50.  
  51.           /*--------------------------------------------------------
  52.              Find dimensions of client window for sizes of children
  53.             --------------------------------------------------------*/
  54.  
  55.      WinQueryWindowRect (hwndClient, &rcl) ;
  56.      rcl.xRight /= 3 ;                            // divide width in thirds
  57.  
  58.           /*---------------------------
  59.              Create push button window
  60.             ---------------------------*/
  61.  
  62.      WinCreateWindow (
  63.                     hwndClient,                   // Parent window handle
  64.                     WC_BUTTON,                    // Window class
  65.                     "Big Button",                 // Window text
  66.                     WS_VISIBLE                    // Window style
  67.                          | BS_PUSHBUTTON,
  68.                     10,                           // Window position
  69.                     10,
  70.                     (SHORT) rcl.xRight - 20,      // Window size
  71.                     (SHORT) rcl.yTop - 20,
  72.                     hwndClient,                   // Owner window handle
  73.                     HWND_BOTTOM,                  // Placement window handle
  74.                     ID_BUTTON,                    // Child window ID
  75.                     NULL,                         // Control data
  76.                     NULL) ;                       // Presentation parameters
  77.  
  78.           /*--------------------------
  79.              Create scroll bar window
  80.             --------------------------*/
  81.  
  82.      WinCreateWindow (
  83.                     hwndClient,                   // Parent window handle
  84.                     WC_SCROLLBAR,                 // Window class
  85.                     NULL,                         // Window text
  86.                     WS_VISIBLE                    // Window style
  87.                          | SBS_VERT,
  88.                     (SHORT) rcl.xRight + 10,      // Window position
  89.                     10,
  90.                     (SHORT) rcl.xRight - 20,      // Window size
  91.                     (SHORT) rcl.yTop - 20,
  92.                     hwndClient,                   // Owner window handle
  93.                     HWND_BOTTOM,                  // Placement window handle
  94.                     ID_SCROLL,                    // Child window ID
  95.                     NULL,                         // Control data
  96.                     NULL) ;                       // Presentation parameters
  97.  
  98.           /*---------------------------
  99.              Create entry field window
  100.             ---------------------------*/
  101.  
  102.      WinCreateWindow (
  103.                     hwndClient,                   // Parent window handle
  104.                     WC_ENTRYFIELD,                // Window class
  105.                     NULL,                         // Window text
  106.                     WS_VISIBLE                    // Window style
  107.                          | ES_MARGIN
  108.                          | ES_AUTOSCROLL,
  109.                     2 * (SHORT) rcl.xRight + 10,  // Window position
  110.                     10,
  111.                     (SHORT) rcl.xRight - 20,      // Window size
  112.                     (SHORT) rcl.yTop - 20,
  113.                     hwndClient,                   // Owner window handle
  114.                     HWND_BOTTOM,                  // Placement window handle
  115.                     ID_ENTRY,                     // Child window ID
  116.                     NULL,                         // Control data
  117.                     NULL) ;                       // Presentation parameters
  118.  
  119.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  120.           WinDispatchMsg (hab, &qmsg) ;
  121.  
  122.      WinDestroyWindow (hwndFrame) ;
  123.      WinDestroyMsgQueue (hmq) ;
  124.      WinTerminate (hab) ;
  125.      return 0 ;
  126.      }
  127.  
  128. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
  129.      {
  130.      switch (msg)
  131.           {
  132.           case WM_COMMAND:
  133.                switch (COMMANDMSG(&msg)->cmd)
  134.                     {
  135.                     case ID_BUTTON:
  136.                          WinAlarm (HWND_DESKTOP, WA_NOTE) ;
  137.                          return 0 ;
  138.                     }
  139.                break ;
  140.  
  141.           case WM_ERASEBACKGROUND:
  142.                return 1 ;
  143.           }
  144.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  145.      }
  146.