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

1.1.1.2 ! root        1: /*--------------------------------------------
        !             2:    SYSVALS.C -- System Values Display Program
        !             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 [] = "SysVals" ;
        !            17:      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU  |
        !            18:                                  FCF_SIZEBORDER    | FCF_MINMAX   |
        !            19:                                  FCF_SHELLPOSITION | FCF_TASKLIST |
        !            20:                                  FCF_VERTSCROLL    | FCF_HORZSCROLL ;
        !            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: LONG RtJustCharStringAt (HPS hps, POINTL *pptl, LONG lLength, CHAR *pchText)
        !            49:      {
        !            50:      POINTL aptlTextBox[TXTBOX_COUNT] ;
        !            51: 
        !            52:      GpiQueryTextBox (hps, lLength, pchText, TXTBOX_COUNT, aptlTextBox) ;
        !            53: 
        !            54:      pptl->x -= aptlTextBox[TXTBOX_CONCAT].x ;
        !            55: 
        !            56:      return GpiCharStringAt (hps, pptl, lLength, pchText) ;
        !            57:      }
        !            58: 
        !            59: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
        !            60:      {
        !            61:      static HWND  hwndHscroll, hwndVscroll ;
        !            62:      static SHORT sHscrollMax, sVscrollMax, sHscrollPos, sVscrollPos,
        !            63:                   cxChar, cxCaps, cyChar, cyDesc, cxClient, cyClient,
        !            64:                   cxTextTotal ;
        !            65:      CHAR         szBuffer [10] ;
        !            66:      FONTMETRICS  fm ;
        !            67:      HPS          hps ;
        !            68:      POINTL       ptl ;
        !            69:      SHORT        sLine, sPaintBeg, sPaintEnd, sHscrollInc, sVscrollInc ;
        !            70:      RECTL        rclInvalid ;
        !            71: 
        !            72:      switch (msg)
        !            73:           {
        !            74:           case WM_CREATE:
        !            75:                hps = WinGetPS (hwnd) ;
        !            76:      
        !            77:                GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ;
        !            78: 
        !            79:                cxChar = (SHORT) fm.lAveCharWidth ;
        !            80:                cxCaps = (SHORT) fm.lEmInc ;
        !            81:                cyChar = (SHORT) fm.lMaxBaselineExt ;
        !            82:                cyDesc = (SHORT) fm.lMaxDescender ;
        !            83: 
        !            84:                WinReleasePS (hps) ;
        !            85: 
        !            86:                cxTextTotal = 28 * cxCaps + 38 * cxChar ;
        !            87: 
        !            88:                hwndHscroll = WinWindowFromID (
        !            89:                                    WinQueryWindow (hwnd, QW_PARENT, FALSE),
        !            90:                                    FID_HORZSCROLL) ;
        !            91: 
        !            92:                hwndVscroll = WinWindowFromID (
        !            93:                                    WinQueryWindow (hwnd, QW_PARENT, FALSE),
        !            94:                                    FID_VERTSCROLL) ;
        !            95:                return 0 ;
        !            96: 
        !            97:           case WM_SIZE:
        !            98:                cxClient = SHORT1FROMMP (mp2) ;
        !            99:                cyClient = SHORT2FROMMP (mp2) ;
        !           100: 
        !           101:                sHscrollMax = max (0, cxTextTotal - cxClient) ;
        !           102:                sHscrollPos = min (sHscrollPos, sHscrollMax) ;
        !           103: 
        !           104:                WinSendMsg (hwndHscroll, SBM_SETSCROLLBAR,
        !           105:                                         MPFROM2SHORT (sHscrollPos, 0),
        !           106:                                         MPFROM2SHORT (0, sHscrollMax)) ;
        !           107: 
        !           108:                WinEnableWindow (hwndHscroll, sHscrollMax ? TRUE : FALSE) ;
        !           109: 
        !           110:                sVscrollMax = max (0, NUMLINES - cyClient / cyChar) ;
        !           111:                sVscrollPos = min (sVscrollPos, sVscrollMax) ;
        !           112: 
        !           113:                WinSendMsg (hwndVscroll, SBM_SETSCROLLBAR,
        !           114:                                         MPFROM2SHORT (sVscrollPos, 0),
        !           115:                                         MPFROM2SHORT (0, sVscrollMax)) ;
        !           116: 
        !           117:                WinEnableWindow (hwndVscroll, sVscrollMax ? TRUE : FALSE) ;
        !           118:                return 0 ;
        !           119: 
        !           120:           case WM_HSCROLL:
        !           121:                switch (SHORT2FROMMP (mp2))
        !           122:                     {
        !           123:                     case SB_LINELEFT:
        !           124:                          sHscrollInc = -cxCaps ;
        !           125:                          break ;
        !           126: 
        !           127:                     case SB_LINERIGHT:
        !           128:                          sHscrollInc = cxCaps ;
        !           129:                          break ;
        !           130: 
        !           131:                     case SB_PAGELEFT:
        !           132:                          sHscrollInc = -8 * cxCaps ;
        !           133:                          break ;
        !           134: 
        !           135:                     case SB_PAGERIGHT:
        !           136:                          sHscrollInc = 8 * cxCaps ;
        !           137:                          break ;
        !           138: 
        !           139:                     case SB_SLIDERPOSITION:
        !           140:                          sHscrollInc = SHORT1FROMMP (mp2) - sHscrollPos;
        !           141:                          break ;
        !           142: 
        !           143:                     default:
        !           144:                          sHscrollInc = 0 ;
        !           145:                          break ;
        !           146:                     }
        !           147: 
        !           148:                sHscrollInc = max (-sHscrollPos,
        !           149:                              min (sHscrollInc, sHscrollMax - sHscrollPos)) ;
        !           150: 
        !           151:                if (sHscrollInc != 0)
        !           152:                     {
        !           153:                     sHscrollPos += sHscrollInc ;
        !           154:                     WinScrollWindow (hwnd, -sHscrollInc, 0,
        !           155:                                    NULL, NULL, NULL, NULL, SW_INVALIDATERGN) ;
        !           156: 
        !           157:                     WinSendMsg (hwndHscroll, SBM_SETPOS,
        !           158:                                 MPFROMSHORT (sHscrollPos), NULL) ;
        !           159:                     }
        !           160:                return 0 ;
        !           161: 
        !           162:           case WM_VSCROLL:
        !           163:                switch (SHORT2FROMMP (mp2))
        !           164:                     {
        !           165:                     case SB_LINEUP:
        !           166:                          sVscrollInc = -1 ;
        !           167:                          break ;
        !           168: 
        !           169:                     case SB_LINEDOWN:
        !           170:                          sVscrollInc = 1 ;
        !           171:                          break ;
        !           172: 
        !           173:                     case SB_PAGEUP:
        !           174:                          sVscrollInc = min (-1, -cyClient / cyChar) ;
        !           175:                          break ;
        !           176: 
        !           177:                     case SB_PAGEDOWN:
        !           178:                          sVscrollInc = max (1, cyClient / cyChar) ;
        !           179:                          break ;
        !           180: 
        !           181:                     case SB_SLIDERTRACK:
        !           182:                          sVscrollInc = SHORT1FROMMP (mp2) - sVscrollPos;
        !           183:                          break ;
        !           184: 
        !           185:                     default:
        !           186:                          sVscrollInc = 0 ;
        !           187:                          break ;
        !           188:                     }
        !           189: 
        !           190:                sVscrollInc = max (-sVscrollPos,
        !           191:                              min (sVscrollInc, sVscrollMax - sVscrollPos)) ;
        !           192: 
        !           193:                if (sVscrollInc != 0) ;
        !           194:                     {
        !           195:                     sVscrollPos += sVscrollInc ;
        !           196:                     WinScrollWindow (hwnd, 0, cyChar * sVscrollInc,
        !           197:                                    NULL, NULL, NULL, NULL, SW_INVALIDATERGN) ;
        !           198: 
        !           199:                     WinSendMsg (hwndVscroll, SBM_SETPOS,
        !           200:                                 MPFROMSHORT (sVscrollPos), NULL) ;
        !           201:                     WinUpdateWindow (hwnd) ;
        !           202:                     }
        !           203:                return 0 ;
        !           204: 
        !           205:           case WM_CHAR:
        !           206:                switch (CHARMSG(&msg)->vkey)
        !           207:                     {
        !           208:                     case VK_LEFT:
        !           209:                     case VK_RIGHT:
        !           210:                          return WinSendMsg (hwndHscroll, msg, mp1, mp2) ;
        !           211:                     case VK_UP:
        !           212:                     case VK_DOWN:
        !           213:                     case VK_PAGEUP:
        !           214:                     case VK_PAGEDOWN:
        !           215:                          return WinSendMsg (hwndVscroll, msg, mp1, mp2) ;
        !           216:                     }
        !           217:                break ;
        !           218: 
        !           219:           case WM_PAINT:
        !           220:                hps = WinBeginPaint (hwnd, NULL, &rclInvalid) ;
        !           221:                GpiErase (hps) ;
        !           222: 
        !           223:                sPaintBeg = max (0, sVscrollPos +
        !           224:                               (cyClient - (SHORT) rclInvalid.yTop) / cyChar) ;
        !           225:                sPaintEnd = min (NUMLINES, sVscrollPos +
        !           226:                               (cyClient - (SHORT) rclInvalid.yBottom)
        !           227:                                    / cyChar + 1) ;
        !           228: 
        !           229:                for (sLine = sPaintBeg ; sLine < sPaintEnd ; sLine++)
        !           230:                     {
        !           231:                     ptl.x = cxCaps - sHscrollPos ;
        !           232:                     ptl.y = cyClient - cyChar * (sLine + 1 - sVscrollPos)
        !           233:                                      + cyDesc ;
        !           234: 
        !           235:                     GpiCharStringAt (hps, &ptl,
        !           236:                               (LONG) strlen (sysvals[sLine].szIdentifier),
        !           237:                               sysvals[sLine].szIdentifier) ;
        !           238: 
        !           239:                     ptl.x += 20 * cxCaps ;
        !           240:                     GpiCharStringAt (hps, &ptl,
        !           241:                               (LONG) strlen (sysvals[sLine].szDescription),
        !           242:                               sysvals[sLine].szDescription) ;
        !           243: 
        !           244:                     ltoa (WinQuerySysValue (HWND_DESKTOP,
        !           245:                                sysvals[sLine].sIndex), szBuffer, 10) ;
        !           246: 
        !           247:                     ptl.x += 38 * cxChar + 6 * cxCaps ;
        !           248:                     RtJustCharStringAt (hps, &ptl, (LONG) strlen (szBuffer),
        !           249:                                         szBuffer) ;
        !           250:                     }
        !           251: 
        !           252:                WinEndPaint (hps) ;
        !           253:                return 0 ;
        !           254:           }
        !           255:      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
        !           256:      }
        !           257: 

unix.superglobalmegacorp.com

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