Annotation of pmsdk/samples/petzold/chap10/convmenu.c, revision 1.1.1.1

1.1       root        1: /*-------------------------------------
                      2:    CONVMENU.C -- Conventional Menu Use
                      3:   -------------------------------------*/
                      4: 
                      5: #define INCL_WIN
                      6: #define INCL_GPI
                      7: 
                      8: #include <os2.h>
                      9: #include <stddef.h>
                     10: #include "convmenu.h"
                     11: 
                     12: #define ID_TIMER    1
                     13: 
                     14: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
                     15: 
                     16: CHAR szCaption [] = "Conventional Menu" ;
                     17: HAB  hab ;
                     18: 
                     19: int main (void)
                     20:      {
                     21:      static CHAR szClientClass[] = "ConvMenu" ;
                     22:      HMQ         hmq ;
                     23:      HWND        hwndClient, hwndFrame ;
                     24:      QMSG        qmsg ;
                     25:      ULONG       flFrameFlags = FCF_STANDARD ;
                     26:      ULONG       flFrameStyle = WS_VISIBLE | FS_ACCELTABLE ;
                     27:      
                     28:      hab = WinInitialize (0) ;
                     29:      hmq = WinCreateMsgQueue (hab, 0) ;
                     30: 
                     31:      WinRegisterClass (hab, szClientClass, ClientWndProc, 0L, 0) ;
                     32: 
                     33:      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, flFrameStyle,
                     34:                                      &flFrameFlags, szClientClass,
                     35:                                      szCaption,
                     36:                                      0L, NULL, ID_RESOURCE, &hwndClient) ;
                     37: 
                     38:      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
                     39:           WinDispatchMsg (hab, &qmsg) ;
                     40: 
                     41:      WinDestroyWindow (hwndFrame) ;
                     42:      WinDestroyMsgQueue (hmq) ;
                     43:      WinTerminate (hab) ;
                     44:      return 0 ;
                     45:      }
                     46: 
                     47: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
                     48:      {
                     49:      static BOOL  fTimerGoing = FALSE ;
                     50:      static COLOR colBackground [] = {
                     51:                                      0xFFFFFFL, 0xC0C0C0L, 0x808080L,
                     52:                                      0x404040L, 0x000000L
                     53:                                      } ;
                     54:      static HWND  hwndMenu ;
                     55:      static SHORT sCurrentBackground = IDM_WHITE ;
                     56:      HPS          hps ;
                     57:      RECTL        rcl ;
                     58: 
                     59:      switch (msg)
                     60:           {
                     61:           case WM_SIZE:
                     62:                if (hwndMenu == NULL)
                     63:                     hwndMenu = WinWindowFromID (
                     64:                                     WinQueryWindow (hwnd, QW_PARENT, FALSE),
                     65:                                     FID_MENU) ;
                     66:                return 0 ;
                     67: 
                     68:           case WM_INITMENU:
                     69:                switch (SHORT1FROMMP (mp1))
                     70:                     {
                     71:                     case IDM_TIMER:
                     72:                          WinSendMsg (hwndMenu, MM_SETITEMATTR,
                     73:                                    MPFROM2SHORT (IDM_START, TRUE),
                     74:                                    MPFROM2SHORT (MIA_DISABLED, 
                     75:                                              !fTimerGoing &&
                     76:                               WinQuerySysValue (HWND_DESKTOP, SV_CTIMERS) ?
                     77:                                              0 : MIA_DISABLED)) ;
                     78: 
                     79:                          WinSendMsg (hwndMenu, MM_SETITEMATTR,
                     80:                                    MPFROM2SHORT (IDM_STOP, TRUE),
                     81:                                    MPFROM2SHORT (MIA_DISABLED,
                     82:                                         fTimerGoing ? 0 : MIA_DISABLED)) ;
                     83:                          return 0 ;
                     84:                     }
                     85:                break ;
                     86: 
                     87:           case WM_COMMAND:
                     88:                switch (COMMANDMSG(&msg)->cmd)
                     89:                     {
                     90:                     case IDM_NEW:
                     91:                          WinMessageBox (HWND_DESKTOP, hwnd,
                     92:                                    "Bogus \"New\" Dialog",
                     93:                                    szCaption, 0, MB_OK | MB_ICONASTERISK) ;
                     94:                          return 0 ;
                     95: 
                     96:                     case IDM_OPEN:
                     97:                          WinMessageBox (HWND_DESKTOP, hwnd,
                     98:                                    "Bogus \"Open\" Dialog",
                     99:                                    szCaption, 0, MB_OK | MB_ICONASTERISK) ;
                    100:                          return 0 ;
                    101: 
                    102:                     case IDM_SAVE:
                    103:                          WinMessageBox (HWND_DESKTOP, hwnd,
                    104:                                    "Bogus \"Save\" Dialog",
                    105:                                    szCaption, 0, MB_OK | MB_ICONASTERISK) ;
                    106:                          return 0 ;
                    107: 
                    108:                     case IDM_SAVEAS:
                    109:                          WinMessageBox (HWND_DESKTOP, hwnd,
                    110:                                    "Bogus \"Save As\" Dialog",
                    111:                                    szCaption, 0, MB_OK | MB_ICONASTERISK) ;
                    112:                          return 0 ;
                    113: 
                    114:                     case IDM_EXIT:
                    115:                          WinSendMsg (hwnd, WM_CLOSE, 0L, 0L) ;
                    116:                          return 0 ;
                    117: 
                    118:                     case IDM_ABOUT:
                    119:                          WinMessageBox (HWND_DESKTOP, hwnd,
                    120:                                    "Bogus \"About\" Dialog",
                    121:                                    szCaption, 0, MB_OK | MB_ICONASTERISK) ;
                    122:                          return 0 ;
                    123: 
                    124:                     case IDM_START:
                    125:                          if (WinStartTimer (hab, hwnd, ID_TIMER, 1000))
                    126:                               fTimerGoing = TRUE ;
                    127:                          else
                    128:                               WinMessageBox (HWND_DESKTOP, hwnd,
                    129:                                    "Too many clocks or timers", szCaption, 0,
                    130:                                    MB_OK | MB_ICONEXCLAMATION) ;
                    131:                          return 0 ;
                    132: 
                    133:                     case IDM_STOP:
                    134:                          WinStopTimer (hab, hwnd, ID_TIMER) ;
                    135:                          fTimerGoing = FALSE ;
                    136:                          return 0 ;
                    137: 
                    138:                     case IDM_WHITE:
                    139:                     case IDM_LTGRAY:
                    140:                     case IDM_GRAY:
                    141:                     case IDM_DKGRAY:
                    142:                     case IDM_BLACK:
                    143:                          WinSendMsg (hwndMenu, MM_SETITEMATTR,
                    144:                                    MPFROM2SHORT (sCurrentBackground, TRUE),
                    145:                                    MPFROM2SHORT (MIA_CHECKED, 0)) ;
                    146: 
                    147:                          sCurrentBackground = COMMANDMSG(&msg)->cmd ;
                    148: 
                    149:                          WinSendMsg (hwndMenu, MM_SETITEMATTR,
                    150:                                    MPFROM2SHORT (sCurrentBackground, TRUE),
                    151:                                    MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED)) ;
                    152: 
                    153:                          WinInvalidateRect (hwnd, NULL, FALSE) ;
                    154:                          return 0 ;
                    155:                     }
                    156:                break ;
                    157: 
                    158:           case WM_HELP:
                    159:                WinMessageBox (HWND_DESKTOP, hwnd,
                    160:                               "Help not yet implemented",
                    161:                               szCaption, 0, MB_OK | MB_ICONEXCLAMATION) ;
                    162:                return 0 ;
                    163: 
                    164:           case WM_TIMER:
                    165:                WinAlarm (HWND_DESKTOP, WA_NOTE) ;
                    166:                return 0 ;
                    167: 
                    168:           case WM_PAINT:
                    169:                hps = WinBeginPaint (hwnd, NULL, NULL) ;
                    170:                GpiSavePS (hps) ;
                    171: 
                    172:                GpiCreateLogColorTable (hps, 0L, LCOLF_RGB, 0L, 0L, NULL) ;
                    173: 
                    174:                WinQueryWindowRect (hwnd, &rcl) ;
                    175: 
                    176:                WinFillRect (hps, &rcl,
                    177:                             colBackground [sCurrentBackground - IDM_WHITE]) ;
                    178: 
                    179:                GpiRestorePS (hps, -1L) ;
                    180:                WinEndPaint (hps) ;
                    181:                return 0 ;
                    182: 
                    183:           case WM_CLOSE:
                    184:                if (MBID_OK == WinMessageBox (HWND_DESKTOP, hwnd,
                    185:                                              "Really want to end program?",
                    186:                                              szCaption, 0,
                    187:                                              MB_OKCANCEL | MB_ICONQUESTION))
                    188:                     break ;
                    189: 
                    190:                return 0 ;
                    191: 
                    192:           case WM_DESTROY:
                    193:                if (fTimerGoing)
                    194:                     {
                    195:                     WinStopTimer (hab, hwnd, ID_TIMER) ;
                    196:                     fTimerGoing = FALSE ;
                    197:                     }
                    198:                return 0 ;
                    199:           }
                    200:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
                    201:      }

unix.superglobalmegacorp.com

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