Annotation of pmsdk/samples/petzold/chap13/grafmenu.c, revision 1.1.1.1

1.1       root        1: /*------------------------------------
                      2:    GRAFMENU.C -- A Menu with Graphics
                      3:   ------------------------------------*/
                      4: 
                      5: #define INCL_WIN
                      6: #define INCL_GPI
                      7: #include <os2.h>
                      8: #include "grafmenu.h"
                      9: 
                     10: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
                     11: 
                     12: CHAR szClientClass[] = "GrafMenu" ;
                     13: 
                     14: int main (void)
                     15:      {
                     16:      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU  |
                     17:                                  FCF_SIZEBORDER    | FCF_MINMAX   |
                     18:                                  FCF_SHELLPOSITION | FCF_TASKLIST |
                     19:                                  FCF_MENU ;
                     20:      HAB          hab ;
                     21:      HMQ          hmq ;
                     22:      HWND         hwndFrame, hwndClient ;
                     23:      QMSG         qmsg ;
                     24: 
                     25:      hab = WinInitialize (0) ;
                     26:      hmq = WinCreateMsgQueue (hab, 0) ;
                     27: 
                     28:      WinRegisterClass (hab, szClientClass, ClientWndProc, 0L, 0) ;
                     29: 
                     30:      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
                     31:                                      &flFrameFlags, szClientClass, NULL,
                     32:                                      0L, NULL, ID_RESOURCE, &hwndClient) ;
                     33: 
                     34:      WinSendMsg (hwndFrame, WM_SETICON,
                     35:                  WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
                     36:                  NULL) ;
                     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 MENUITEM miBigHelp = { 0,                       // iPosition
                     50:                                    MIS_BITMAP | MIS_HELP,   // afStyle
                     51:                                    0,                       // afAttribute
                     52:                                    IDM_HELP,                // id
                     53:                                    NULL,                    // hwndSubMenu
                     54:                                    NULL } ;                 // hItem
                     55:      FONTMETRICS     fm ;
                     56:      HBITMAP         hbm ;
                     57:      HPS             hps ;
                     58:      HWND            hwndMenu ;
                     59: 
                     60:      switch (msg)
                     61:           {
                     62:           case WM_CREATE:
                     63: 
                     64:                     /*----------------------
                     65:                        Load bitmap resource
                     66:                       ----------------------*/
                     67: 
                     68:                hps = WinGetPS (hwnd) ;
                     69:                GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ;
                     70:                hbm = GpiLoadBitmap (hps, NULL, IDB_BIGHELP,
                     71:                                     64 * fm.lAveCharWidth / 3,
                     72:                                     64 * fm.lMaxBaselineExt / 8) ;
                     73:                WinReleasePS (hps) ;
                     74: 
                     75:                     /*-----------------------
                     76:                        Attach bitmap to menu
                     77:                       -----------------------*/
                     78: 
                     79:                miBigHelp.hItem = (ULONG) hbm ;
                     80: 
                     81:                hwndMenu = WinWindowFromID (
                     82:                                WinQueryWindow (hwnd, QW_PARENT, FALSE),
                     83:                                FID_MENU) ;
                     84: 
                     85:                WinSendMsg (hwndMenu, MM_SETITEM,
                     86:                            MPFROM2SHORT (0, TRUE), MPFROMP (&miBigHelp)) ;
                     87:                return 0 ;
                     88: 
                     89:           case WM_COMMAND:
                     90:                switch (COMMANDMSG(&msg)->cmd)
                     91:                     {
                     92:                     case IDM_NEW:
                     93:                     case IDM_OPEN:
                     94:                     case IDM_SAVE:
                     95:                     case IDM_SAVEAS:
                     96:                     case IDM_ABOUT:
                     97:                          WinAlarm (HWND_DESKTOP, WA_NOTE) ;
                     98:                          return 0 ;
                     99:                     }
                    100:                break ;
                    101: 
                    102:           case WM_HELP:
                    103:                WinMessageBox (HWND_DESKTOP, hwnd,
                    104:                               "Help not yet implemented",
                    105:                               szClientClass, 0, MB_OK | MB_ICONEXCLAMATION) ;
                    106:                return 0 ;
                    107: 
                    108:           case WM_ERASEBACKGROUND:
                    109:                return 1 ;
                    110:           }
                    111:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
                    112:      }

unix.superglobalmegacorp.com

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