Annotation of pmsdk/samples/petzold/chap04/sysvals2.c, revision 1.1.1.2

1.1.1.2 ! root        1: /*---------------------------------------------------
        !             2:    SYSVALS2.C -- System Values Display Program No. 2
        !             3:   ---------------------------------------------------*/
        !             4: 
        !             5: #define INCL_WIN
        !             6: #define INCL_GPI
        !             7: #include <os2.h>
        !             8: #include <stdlib.h>
        !             9: #include <string.h>
        !            10: #include "sysvals.h"
        !            11: 
        !            12: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
        !            13: 
        !            14: int main (void)
        !            15:      {
        !            16:      static CHAR  szClientClass [] = "SysVals2" ;
        !            17:      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU  |
        !            18:                                  FCF_SIZEBORDER    | FCF_MINMAX   |
        !            19:                                  FCF_SHELLPOSITION | FCF_TASKLIST |
        !            20:                                  FCF_VERTSCROLL ;
        !            21:      HAB          hab ;
        !            22:      HMQ          hmq ;
        !            23:      HWND         hwndFrame, hwndClient ;
        !            24:      QMSG         qmsg ;
        !            25: 
        !            26:      hab = WinInitialize (0) ;
        !            27:      hmq = WinCreateMsgQueue (hab, 0) ;
        !            28: 
        !            29:      WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
        !            30: 
        !            31:      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
        !            32:                                      &flFrameFlags, szClientClass, NULL,
        !            33:                                      0L, NULL, 0, &hwndClient) ;
        !            34: 
        !            35:      WinSendMsg (hwndFrame, WM_SETICON,
        !            36:                  WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
        !            37:                  NULL) ;
        !            38: 
        !            39:      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
        !            40:           WinDispatchMsg (hab, &qmsg) ;
        !            41: 
        !            42:      WinDestroyWindow (hwndFrame) ;
        !            43:      WinDestroyMsgQueue (hmq) ;
        !            44:      WinTerminate (hab) ;
        !            45:      return 0 ;
        !            46:      }
        !            47: 
        !            48: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
        !            49:      {
        !            50:      static HWND  hwndVscroll ;
        !            51:      static SHORT cxChar, cxCaps, cyChar, cyDesc,
        !            52:                   sVscrollPos, cxClient, cyClient ;
        !            53:      CHAR         szBuffer [10] ;
        !            54:      FONTMETRICS  fm ;
        !            55:      HPS          hps ;
        !            56:      POINTL       ptl ;
        !            57:      SHORT        sLine ;
        !            58: 
        !            59:      switch (msg)
        !            60:           {
        !            61:           case WM_CREATE:
        !            62:                hps = WinGetPS (hwnd) ;
        !            63:                GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ;
        !            64: 
        !            65:                cxChar = (SHORT) fm.lAveCharWidth ;
        !            66:                cxCaps = (SHORT) fm.lEmInc ;
        !            67:                cyChar = (SHORT) fm.lMaxBaselineExt ;
        !            68:                cyDesc = (SHORT) fm.lMaxDescender ;
        !            69: 
        !            70:                WinReleasePS (hps) ;
        !            71: 
        !            72:                hwndVscroll = WinWindowFromID (
        !            73:                                    WinQueryWindow (hwnd, QW_PARENT, FALSE),
        !            74:                                    FID_VERTSCROLL) ;
        !            75: 
        !            76:                WinSendMsg (hwndVscroll, SBM_SETSCROLLBAR,
        !            77:                                    MPFROM2SHORT (sVscrollPos, 0),
        !            78:                                    MPFROM2SHORT (0, NUMLINES - 1)) ;
        !            79:                return 0 ;
        !            80: 
        !            81:           case WM_SIZE:
        !            82:                cxClient = SHORT1FROMMP (mp2) ;
        !            83:                cyClient = SHORT2FROMMP (mp2) ;
        !            84:                return 0 ;
        !            85: 
        !            86:           case WM_VSCROLL:
        !            87:                switch (SHORT2FROMMP (mp2))
        !            88:                     {
        !            89:                     case SB_LINEUP:
        !            90:                          sVscrollPos -= 1 ;
        !            91:                          break ;
        !            92: 
        !            93:                     case SB_LINEDOWN:
        !            94:                          sVscrollPos += 1 ;
        !            95:                          break ;
        !            96: 
        !            97:                     case SB_PAGEUP:
        !            98:                          sVscrollPos -= cyClient / cyChar ;
        !            99:                          break ;
        !           100: 
        !           101:                     case SB_PAGEDOWN:
        !           102:                          sVscrollPos += cyClient / cyChar ;
        !           103:                          break ;
        !           104: 
        !           105:                     case SB_SLIDERPOSITION:
        !           106:                          sVscrollPos = SHORT1FROMMP (mp2) ;
        !           107:                          break ;
        !           108:                     }
        !           109:                sVscrollPos = max (0, min (sVscrollPos, NUMLINES - 1)) ;
        !           110: 
        !           111:                if (sVscrollPos != SHORT1FROMMR (WinSendMsg (hwndVscroll,
        !           112:                                        SBM_QUERYPOS, NULL, NULL)))
        !           113:                     {
        !           114:                     WinSendMsg (hwndVscroll, SBM_SETPOS,
        !           115:                                 MPFROMSHORT (sVscrollPos), NULL) ;
        !           116:                     WinInvalidateRect (hwnd, NULL, FALSE) ;
        !           117:                     }
        !           118:                return 0 ;
        !           119: 
        !           120:           case WM_PAINT:
        !           121:                hps = WinBeginPaint (hwnd, NULL, NULL) ;
        !           122:                GpiErase (hps) ;
        !           123: 
        !           124:                for (sLine = 0 ; sLine < NUMLINES ; sLine++)
        !           125:                     {
        !           126:                     ptl.x = cxCaps ;
        !           127:                     ptl.y = cyClient - cyChar * (sLine + 1 - sVscrollPos)
        !           128:                                      + cyDesc ;
        !           129: 
        !           130:                     GpiCharStringAt (hps, &ptl,
        !           131:                               (LONG) strlen (sysvals[sLine].szIdentifier),
        !           132:                               sysvals[sLine].szIdentifier) ;
        !           133: 
        !           134:                     ptl.x += 20 * cxCaps ;
        !           135:                     GpiCharStringAt (hps, &ptl,
        !           136:                               (LONG) strlen (sysvals[sLine].szDescription),
        !           137:                               sysvals[sLine].szDescription) ;
        !           138: 
        !           139:                     ltoa (WinQuerySysValue (HWND_DESKTOP,
        !           140:                                sysvals[sLine].sIndex), szBuffer, 10) ;
        !           141: 
        !           142:                     ptl.x += 38 * cxChar ;
        !           143:                     GpiCharStringAt (hps, &ptl, (LONG) strlen (szBuffer),
        !           144:                                      szBuffer) ;
        !           145:                     }
        !           146:                WinEndPaint (hps) ;
        !           147:                return 0 ;
        !           148:           }
        !           149:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
        !           150:      }
        !           151: 

unix.superglobalmegacorp.com

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