Annotation of pmsdk/samples/petzold/chap10/poormenu.c, revision 1.1

1.1     ! root        1: /*----------------------------------
        !             2:    POORMENU.C -- Poor Person's Menu
        !             3:   ----------------------------------*/
        !             4: 
        !             5: #define INCL_WIN
        !             6: 
        !             7: #include <os2.h>
        !             8: #include <stddef.h>
        !             9: 
        !            10: #define IDM_ABOUT   10
        !            11: #define IDM_HELP    11
        !            12: 
        !            13: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
        !            14: 
        !            15: CHAR szCaption [] = "Poor Person\'s Menu" ;
        !            16: 
        !            17: int main (void)
        !            18:      {
        !            19:      static CHAR     szClientClass[] = "PoorMenu" ;
        !            20:      HAB             hab ;
        !            21:      HMQ             hmq ;
        !            22:      HWND            hwndClient, hwndFrame ;
        !            23:      QMSG            qmsg ;
        !            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 (hab, szClientClass, ClientWndProc, 0L, 0) ;
        !            31: 
        !            32:      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, flFrameStyle,
        !            33:                                      &flFrameFlags, szClientClass,
        !            34:                                      szCaption,
        !            35:                                      0L, NULL, 0, &hwndClient) ;
        !            36: 
        !            37:      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
        !            38:           WinDispatchMsg (hab, &qmsg) ;
        !            39: 
        !            40:      WinDestroyWindow (hwndFrame) ;
        !            41:      WinDestroyMsgQueue (hmq) ;
        !            42:      WinTerminate (hab) ;
        !            43:      return 0 ;
        !            44:      }
        !            45: 
        !            46: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
        !            47:      {
        !            48:      static CHAR     *szMenuText [3] = { NULL, "About PoorMenu...", "Help" } ;
        !            49:      static MENUITEM mi [3] = {
        !            50:                               MIT_END, MIS_SEPARATOR, 0,         NULL, NULL,
        !            51:                               MIT_END, MIS_TEXT,      IDM_ABOUT, NULL, NULL,
        !            52:                               MIT_END, MIS_TEXT,      IDM_HELP,  NULL, NULL
        !            53:                               } ;
        !            54:      HWND            hwndSysMenu, hwndSysSubMenu ;
        !            55:      MENUITEM        miSysMenu ;
        !            56:      SHORT           sItem, idSysMenu ;
        !            57: 
        !            58:      switch (msg)
        !            59:           {
        !            60:           case WM_CREATE:
        !            61:                hwndSysMenu = WinWindowFromID (
        !            62:                                   WinQueryWindow (hwnd, QW_PARENT, FALSE),
        !            63:                                   FID_SYSMENU) ;
        !            64: 
        !            65:                idSysMenu = (SHORT) WinSendMsg (hwndSysMenu,
        !            66:                                                MM_ITEMIDFROMPOSITION,
        !            67:                                                NULL, NULL) ;
        !            68: 
        !            69:                WinSendMsg (hwndSysMenu, MM_QUERYITEM,
        !            70:                            MPFROM2SHORT (idSysMenu, FALSE),
        !            71:                            MPFROMP (&miSysMenu)) ;
        !            72: 
        !            73:                hwndSysSubMenu = miSysMenu.hwndSubMenu ;
        !            74: 
        !            75:                for (sItem = 0 ; sItem < 3 ; sItem++)
        !            76:                     WinSendMsg (hwndSysSubMenu, MM_INSERTITEM,
        !            77:                                 MPFROMP (mi + sItem),
        !            78:                                 MPFROMP (szMenuText [sItem])) ;
        !            79:                return 0 ;
        !            80: 
        !            81:           case WM_COMMAND:
        !            82:                switch (COMMANDMSG(&msg)->cmd)
        !            83:                     {
        !            84:                     case IDM_ABOUT:
        !            85:                          WinMessageBox (HWND_DESKTOP, hwnd,
        !            86:                                    "(C) Charles Petzold, 1988",
        !            87:                                    szCaption, 0, MB_OK | MB_ICONASTERISK) ;
        !            88:                          return 0 ;
        !            89: 
        !            90:                     case IDM_HELP:
        !            91:                          WinMessageBox (HWND_DESKTOP, hwnd,
        !            92:                                    "Help not yet implemented",
        !            93:                                    szCaption, 0, MB_OK | MB_ICONEXCLAMATION) ;
        !            94:                          return 0 ;
        !            95:                     }
        !            96:                break ;
        !            97: 
        !            98:           case WM_ERASEBACKGROUND:
        !            99:                return 1 ;
        !           100:           }
        !           101:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
        !           102:      }

unix.superglobalmegacorp.com

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