Annotation of pmsdk/samples/petzold/chap16/buttons3.c, revision 1.1

1.1     ! root        1: /*----------------------------------------------------
        !             2:    BUTTONS3.C -- Square Button Demonstration with DLL
        !             3:   ----------------------------------------------------*/
        !             4: 
        !             5: #define INCL_WIN
        !             6: #define INCL_GPI
        !             7: #include <os2.h>
        !             8: #include "sqbtnlib.h"
        !             9: 
        !            10: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
        !            11: 
        !            12: HAB  hab ;
        !            13: 
        !            14: int main (void)
        !            15:      {
        !            16:      static CHAR  szClientClass[] = "Buttons3" ;
        !            17:      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU |
        !            18:                                  FCF_SIZEBORDER    | FCF_MINMAX  |
        !            19:                                  FCF_SHELLPOSITION | FCF_TASKLIST ;
        !            20:      HMQ          hmq ;
        !            21:      HWND         hwndFrame, hwndClient ;
        !            22:      QMSG         qmsg ;
        !            23: 
        !            24:      hab = WinInitialize (0) ;
        !            25:      hmq = WinCreateMsgQueue (hab, 0) ;
        !            26: 
        !            27:      WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
        !            28: 
        !            29:      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
        !            30:                                      &flFrameFlags, szClientClass, NULL,
        !            31:                                     0L, NULL, 0, &hwndClient) ;
        !            32: 
        !            33:      WinSendMsg (hwndFrame, WM_SETICON,
        !            34:                  WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
        !            35:                  NULL) ;
        !            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  szSqBtnClass [] = "SqBtn",
        !            49:                   *szButtonLabel [] = { "Smaller", "Larger" } ;
        !            50:      static HWND  hwndFrame, hwndButton [2] ;
        !            51:      static SHORT cxClient, cyClient, cxChar, cyChar ;
        !            52:      FONTMETRICS  fm ;
        !            53:      HPS          hps ;
        !            54:      SHORT        id ;
        !            55:      RECTL        rcl ;
        !            56: 
        !            57:      switch (msg)
        !            58:           {
        !            59:           case WM_CREATE :
        !            60:                hwndFrame = WinQueryWindow (hwnd, QW_PARENT, FALSE) ;
        !            61: 
        !            62:                hps = WinGetPS (hwnd) ;
        !            63:                GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ;
        !            64:                cxChar = (SHORT) fm.lAveCharWidth ;
        !            65:                cyChar = (SHORT) fm.lMaxBaselineExt ;
        !            66:                WinReleasePS (hps) ;
        !            67: 
        !            68:                RegisterSqBtnClass (hab) ;
        !            69: 
        !            70:                for (id = 0 ; id < 2 ; id++)
        !            71:                     hwndButton [id] = WinCreateWindow (
        !            72:                                         hwnd,               // Parent
        !            73:                                         "SqBtn",            // Class
        !            74:                                         szButtonLabel [id], // Text
        !            75:                                         WS_VISIBLE,         // Style
        !            76:                                         0, 0,               // Position
        !            77:                                         12 * cxChar,        // Width
        !            78:                                         2 * cyChar,         // Height
        !            79:                                         hwnd,               // Owner
        !            80:                                         HWND_BOTTOM,        // Placement
        !            81:                                         id,                 // ID
        !            82:                                         NULL,               // Ctrl Data
        !            83:                                         NULL) ;             // Pres Params
        !            84:                return 0 ;
        !            85: 
        !            86:           case WM_SIZE :
        !            87:                cxClient = SHORT1FROMMP (mp2) ;
        !            88:                cyClient = SHORT2FROMMP (mp2) ;
        !            89: 
        !            90:                for (id = 0 ; id < 2 ; id++)
        !            91:                     WinSetWindowPos (hwndButton [id], NULL,
        !            92:                               cxClient / 2 + (14 * id - 13) * cxChar,
        !            93:                               (cyClient - 2 * cyChar) / 2,
        !            94:                               0, 0, SWP_MOVE) ;
        !            95:                return 0 ;
        !            96: 
        !            97:           case WM_COMMAND:
        !            98:                WinQueryWindowRect (hwnd, &rcl) ;
        !            99:                WinMapWindowPoints (hwnd, HWND_DESKTOP, (PPOINTL) &rcl, 2) ;
        !           100: 
        !           101:                switch (COMMANDMSG(&msg)->cmd)               // Child ID
        !           102:                     {
        !           103:                     case 0:                                 // "Smaller"
        !           104:                          rcl.xLeft   += cxClient / 20 ;
        !           105:                          rcl.xRight  -= cxClient / 20 ;
        !           106:                          rcl.yBottom += cyClient / 20 ;
        !           107:                          rcl.yTop    -= cyClient / 20 ;
        !           108:                          break ;
        !           109: 
        !           110:                     case 1:                                 // "Larger"
        !           111:                          rcl.xLeft   -= cxClient / 20 ;
        !           112:                          rcl.xRight  += cxClient / 20 ;
        !           113:                          rcl.yBottom -= cyClient / 20 ;
        !           114:                          rcl.yTop    += cyClient / 20 ;
        !           115:                          break ;
        !           116:                     }
        !           117:                WinCalcFrameRect (hwndFrame, &rcl, FALSE) ;
        !           118: 
        !           119:                WinSetWindowPos (hwndFrame, NULL,
        !           120:                                (SHORT) rcl.xLeft, (SHORT) rcl.yBottom,
        !           121:                                (SHORT) rcl.xRight - (SHORT) rcl.xLeft,
        !           122:                                (SHORT) rcl.yTop   - (SHORT) rcl.yBottom,
        !           123:                                SWP_MOVE | SWP_SIZE) ;
        !           124:                return 0 ;
        !           125: 
        !           126:           case WM_ERASEBACKGROUND:
        !           127:                return 1 ;
        !           128:           }
        !           129:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
        !           130:      }

unix.superglobalmegacorp.com

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