|
|
1.1 root 1: /*---------------------------------------------------
2: SYSVALS3.C -- System Values Display Program No. 3
3: ---------------------------------------------------*/
4:
5: #define INCL_WIN
6: #define INCL_GPI
7:
8: #include <os2.h>
9: #include <stdlib.h>
10: #include <stdio.h>
11: #include "sysvals.h"
12:
13: #define MAXWIDTH 60
14:
15: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
16:
17: int main (void)
18: {
19: static CHAR szClientClass [] = "SysVals3" ;
20: HAB hab ;
21: HMQ hmq ;
22: HWND hwndClient, hwndFrame ;
23: QMSG qmsg ;
24: ULONG flFrameFlags = FCF_STANDARD & ~FCF_MENU |
25: FCF_VERTSCROLL | FCF_HORZSCROLL ;
26: ULONG flFrameStyle = WS_VISIBLE ;
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: "Presentation Manager System Values",
36: 0L, NULL, 0, &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:
45: return 0 ;
46: }
47:
48: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
49: {
50: static HWND hwndHscroll, hwndVscroll ;
51: static SHORT sHscrollMax, sVscrollMax, sHscrollPos, sVscrollPos,
52: cxChar, cyChar, cyDesc, cxClient, cyClient ;
53: CHAR szBuffer [80] ;
54: FONTMETRICS fm ;
55: HPS hps ;
56: POINTL ptl ;
57: SHORT sLine, sPaintBeg, sPaintEnd, sHscrollInc, sVscrollInc ;
58: RECTL rclInvalid ;
59:
60: switch (msg)
61: {
62: case WM_CREATE:
63: hps = WinGetPS (hwnd) ;
64:
65: GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ;
66:
67: cxChar = (SHORT) fm.lAveCharWidth ;
68: cyChar = (SHORT) fm.lMaxBaselineExt ;
69: cyDesc = (SHORT) fm.lMaxDescender ;
70:
71: WinReleasePS (hps) ;
72:
73: hwndHscroll = WinWindowFromID (
74: WinQueryWindow (hwnd, QW_PARENT, FALSE),
75: FID_HORZSCROLL) ;
76:
77: hwndVscroll = WinWindowFromID (
78: WinQueryWindow (hwnd, QW_PARENT, FALSE),
79: FID_VERTSCROLL) ;
80: return 0 ;
81:
82: case WM_SIZE:
83: cxClient = SHORT1FROMMP (mp2) ;
84: cyClient = SHORT2FROMMP (mp2) ;
85:
86: sHscrollMax = max (0, MAXWIDTH + 2 - cxClient / cxChar) ;
87: sHscrollPos = min (sHscrollPos, sHscrollMax) ;
88:
89: WinSendMsg (hwndHscroll, SBM_SETSCROLLBAR,
90: MPFROM2SHORT (sHscrollPos, 0),
91: MPFROM2SHORT (0, sHscrollMax)) ;
92:
93: WinEnableWindow (hwndHscroll, sHscrollMax ? TRUE : FALSE) ;
94:
95: sVscrollMax = max (0, NUMLINES - cyClient / cyChar) ;
96: sVscrollPos = min (sVscrollPos, sVscrollMax) ;
97:
98: WinSendMsg (hwndVscroll, SBM_SETSCROLLBAR,
99: MPFROM2SHORT (sVscrollPos, 0),
100: MPFROM2SHORT (0, sVscrollMax)) ;
101:
102: WinEnableWindow (hwndVscroll, sVscrollMax ? TRUE : FALSE) ;
103: return 0 ;
104:
105: case WM_CALCVALIDRECTS:
106: return MRFROMSHORT (CVR_ALIGNLEFT | CVR_ALIGNTOP) ;
107:
108: case WM_HSCROLL:
109: switch (SHORT2FROMMP (mp2))
110: {
111: case SB_LINELEFT:
112: sHscrollInc = -1 ;
113: break ;
114:
115: case SB_LINERIGHT:
116: sHscrollInc = 1 ;
117: break ;
118:
119: case SB_PAGELEFT:
120: sHscrollInc = -8 ;
121: break ;
122:
123: case SB_PAGERIGHT:
124: sHscrollInc = 8 ;
125: break ;
126:
127: case SB_SLIDERPOSITION:
128: sHscrollInc = SHORT1FROMMP (mp2) - sHscrollPos;
129: break ;
130:
131: default:
132: sHscrollInc = 0 ;
133: break ;
134: }
135:
136: if (sHscrollInc = max (-sHscrollPos,
137: min (sHscrollInc, sHscrollMax - sHscrollPos)))
138: {
139: sHscrollPos += sHscrollInc ;
140: WinScrollWindow (hwnd, -cxChar * sHscrollInc, 0,
141: NULL, NULL, NULL, NULL, SW_INVALIDATERGN) ;
142:
143: WinSendMsg (hwndHscroll, SBM_SETPOS,
144: MPFROM2SHORT (sHscrollPos, 0L), NULL) ;
145: }
146: return 0 ;
147:
148: case WM_VSCROLL:
149: switch (SHORT2FROMMP (mp2))
150: {
151: case SB_LINEUP:
152: sVscrollInc = -1 ;
153: break ;
154:
155: case SB_LINEDOWN:
156: sVscrollInc = 1 ;
157: break ;
158:
159: case SB_PAGEUP:
160: sVscrollInc = min (-1, -cyClient / cyChar) ;
161: break ;
162:
163: case SB_PAGEDOWN:
164: sVscrollInc = max (1, cyClient / cyChar) ;
165: break ;
166:
167: case SB_SLIDERTRACK:
168: sVscrollInc = SHORT1FROMMP (mp2) - sVscrollPos;
169: break ;
170:
171: default:
172: sVscrollInc = 0 ;
173: break ;
174: }
175:
176: if (sVscrollInc = max (-sVscrollPos,
177: min (sVscrollInc, sVscrollMax - sVscrollPos)))
178: {
179: sVscrollPos += sVscrollInc ;
180: WinScrollWindow (hwnd, 0, cyChar * sVscrollInc,
181: NULL, NULL, NULL, NULL, SW_INVALIDATERGN) ;
182:
183: WinSendMsg (hwndVscroll, SBM_SETPOS,
184: MPFROM2SHORT (sVscrollPos, 0), NULL) ;
185: WinUpdateWindow (hwnd) ;
186: }
187: return 0 ;
188:
189: case WM_PAINT:
190: hps = WinBeginPaint (hwnd, NULL, &rclInvalid) ;
191:
192: GpiErase (hps) ;
193:
194: sPaintBeg = max (0, sVscrollPos +
195: (cyClient - (SHORT) rclInvalid.yTop) / cyChar) ;
196: sPaintEnd = min (NUMLINES, sVscrollPos +
197: (cyClient - (SHORT) rclInvalid.yBottom)
198: / cyChar + 1) ;
199:
200: for (sLine = sPaintBeg ; sLine < sPaintEnd ; sLine++)
201: {
202: ptl.x = cxChar * (1 - sHscrollPos) ;
203: ptl.y = cyClient - cyChar *
204: (sLine + 1 - sVscrollPos) + cyDesc ;
205:
206: GpiCharStringAt (hps, &ptl,
207: (LONG) sprintf (szBuffer, "%-20s%-34s%6ld",
208: sysvals[sLine].szIdentifier,
209: sysvals[sLine].szDescription,
210: WinQuerySysValue (HWND_DESKTOP,
211: sysvals[sLine].sIndex)),
212: szBuffer) ;
213: }
214:
215: WinEndPaint (hps) ;
216: return 0 ;
217: }
218: return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
219: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.