Annotation of pmsdk/samples/petzold/chap03/welcome4.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.