Annotation of pmsdk/samples/petzold/chap03/welcome3.c, revision 1.1

1.1     ! root        1: /*-----------------------------------------------------------
        !             2:    WELCOME3.C -- Creates a Top-Level Window and Two Children
        !             3:   -----------------------------------------------------------*/
        !             4: 
        !             5: #define INCL_WIN
        !             6: 
        !             7: #include <os2.h>
        !             8: #include <stddef.h>
        !             9: 
        !            10: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
        !            11: MRESULT EXPENTRY ChildWndProc  (HWND, USHORT, MPARAM, MPARAM) ;
        !            12: 
        !            13: int main (void)
        !            14:      {
        !            15:      static CHAR szClientClass [] = "Welcome3" ;
        !            16:      static CHAR szChildClass  [] = "Welcome3.Child" ;
        !            17:      HAB         hab ;
        !            18:      HMQ         hmq ;
        !            19:      HWND        hwndFrame,  hwndChildFrame1,  hwndChildFrame2,
        !            20:                  hwndClient, hwndChildClient1, hwndChildClient2 ;
        !            21:      QMSG       qmsg ;
        !            22:      ULONG       flFrameFlags = FCF_STANDARD & ~FCF_MENU ;
        !            23:      ULONG       flFrameStyle = WS_VISIBLE ;
        !            24: 
        !            25:      hab = WinInitialize (0) ;
        !            26:      hmq = WinCreateMsgQueue (hab, 0) ;
        !            27: 
        !            28:      WinRegisterClass (
        !            29:                     hab,                /* Anchor block handle             */
        !            30:                    szClientClass,      /* Name of class being registered  */
        !            31:                     ClientWndProc,      /* Window procedure for class      */
        !            32:                     CS_SIZEREDRAW,      /* Class style                     */
        !            33:                     0) ;                /* Extra bytes to reserve          */
        !            34: 
        !            35:      WinRegisterClass (
        !            36:                     hab,                /* Anchor block handle             */
        !            37:                     szChildClass,       /* Name of class being registered  */
        !            38:                     ChildWndProc,       /* Window procedure for class      */
        !            39:                     CS_SIZEREDRAW,      /* Class style                     */
        !            40:                     sizeof (PVOID)) ;   /* Extra bytes to reserve          */
        !            41: 
        !            42:           /*-------------------------
        !            43:              Create top-level window
        !            44:             -------------------------*/
        !            45: 
        !            46:      hwndFrame = WinCreateStdWindow (
        !            47:                     HWND_DESKTOP,       /* Parent window handle            */
        !            48:                     flFrameStyle,       /* Style of frame window           */
        !            49:                    &flFrameFlags,      /* Pointer to control data         */
        !            50:                    szClientClass,      /* Client window class name        */
        !            51:                     "Top-Level Window", /* Title bar text                  */
        !            52:                     0L,                 /* Style of client window          */
        !            53:                     NULL,               /* Module handle for resources     */
        !            54:                     0,                  /* ID of resources                 */
        !            55:                     &hwndClient) ;      /* Pointer to client window handle */
        !            56: 
        !            57:           /*--------------------------
        !            58:              Create two child windows
        !            59:             --------------------------*/
        !            60: 
        !            61:      hwndChildFrame1 = WinCreateStdWindow (
        !            62:                     hwndClient,         /* Parent window handle            */
        !            63:                     flFrameStyle,       /* Style of frame window           */
        !            64:                    &flFrameFlags,      /* Pointer to control data         */
        !            65:                     szChildClass,       /* Client window class name        */
        !            66:                     "Child No. 1",      /* Title bar text                  */
        !            67:                     0L,                 /* Style of client window          */
        !            68:                     NULL,               /* Module handle for resources     */
        !            69:                     0,                  /* ID of resources                 */
        !            70:                     &hwndChildClient1) ;/* Pointer to client window handle */
        !            71: 
        !            72:      hwndChildFrame2 = WinCreateStdWindow (
        !            73:                     hwndClient,         /* Parent window handle            */
        !            74:                     flFrameStyle,       /* Style of frame window           */
        !            75:                    &flFrameFlags,      /* Pointer to control data         */
        !            76:                     szChildClass,       /* Client window class name        */
        !            77:                     "Child No. 2",      /* Title bar text                  */
        !            78:                     0L,                 /* Style of client window          */
        !            79:                     NULL,               /* Module handle for resources     */
        !            80:                     0,                  /* ID of resources                 */
        !            81:                     &hwndChildClient2) ;/* Pointer to client window handle */
        !            82: 
        !            83:           /*-----------------------------------------------------
        !            84:              Set reserved area of window to text string pointers
        !            85:             -----------------------------------------------------*/
        !            86: 
        !            87:      WinSetWindowPtr (hwndChildClient1, QWL_USER, "I'm a child ...") ;
        !            88:      WinSetWindowPtr (hwndChildClient2, QWL_USER, "... Me too!") ;      
        !            89: 
        !            90:      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
        !            91:           WinDispatchMsg (hab, &qmsg) ;
        !            92: 
        !            93:      WinDestroyWindow (hwndFrame) ;
        !            94:      WinDestroyMsgQueue (hmq) ;
        !            95:      WinTerminate (hab) ;
        !            96: 
        !            97:      return 0 ;
        !            98:      }
        !            99: 
        !           100: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
        !           101:      {
        !           102:      static CHAR szText [] = "I'm the parent of two children" ;
        !           103:      HPS         hps ;
        !           104:      RECTL       rcl ;
        !           105: 
        !           106:      switch (msg)
        !           107:           {
        !           108:           case WM_PAINT:
        !           109:                hps = WinBeginPaint (hwnd, NULL, NULL) ;
        !           110: 
        !           111:                WinQueryWindowRect (hwnd, &rcl) ;
        !           112: 
        !           113:                WinDrawText (hps, -1, szText, &rcl,
        !           114:                             CLR_NEUTRAL, CLR_BACKGROUND,
        !           115:                             DT_CENTER | DT_VCENTER | DT_ERASERECT) ;
        !           116: 
        !           117:                WinEndPaint (hps) ;
        !           118:                return 0 ;
        !           119:           }
        !           120:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
        !           121:      }
        !           122: 
        !           123: MRESULT EXPENTRY ChildWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
        !           124:      {
        !           125:      HPS    hps ;
        !           126:      RECTL  rcl ;
        !           127: 
        !           128:      switch (msg)
        !           129:           {
        !           130:           case WM_PAINT:
        !           131:                hps = WinBeginPaint (hwnd, NULL, NULL) ;
        !           132: 
        !           133:                WinQueryWindowRect (hwnd, &rcl) ;
        !           134: 
        !           135:                WinDrawText (hps, -1, WinQueryWindowPtr (hwnd, QWL_USER), &rcl,
        !           136:                             CLR_NEUTRAL, CLR_BACKGROUND,
        !           137:                             DT_CENTER | DT_VCENTER | DT_ERASERECT) ;
        !           138: 
        !           139:                WinEndPaint (hps) ;
        !           140:                return 0 ;
        !           141: 
        !           142:           case WM_CLOSE:
        !           143:                WinDestroyWindow (WinQueryWindow (hwnd, QW_PARENT, FALSE)) ;
        !           144:                return 0 ;
        !           145:           }
        !           146:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
        !           147:      }

unix.superglobalmegacorp.com

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