|
|
1.1 root 1: /*----------------------------------------
2: BUTTONS.C -- Push Button Demonstration
3: ----------------------------------------*/
4:
5: #define INCL_WIN
6: #define INCL_GPI
7:
8: #include <os2.h>
9: #include <stddef.h>
10:
11: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
12:
13: int main (void)
14: {
15: static CHAR szClientClass[] = "Buttons" ;
16: HAB hab ;
17: HMQ hmq ;
18: HWND hwndFrame, hwndClient ;
19: QMSG qmsg ;
20: ULONG flFrameFlags = FCF_STANDARD & ~FCF_MENU ;
21: ULONG flFrameStyle = WS_VISIBLE ;
22:
23: hab = WinInitialize (0) ;
24: hmq = WinCreateMsgQueue (hab, 0) ;
25:
26: WinRegisterClass (hab, szClientClass, ClientWndProc, CS_SIZEREDRAW, 0) ;
27:
28: hwndFrame = WinCreateStdWindow (HWND_DESKTOP, flFrameStyle,
29: &flFrameFlags, szClientClass,
30: "Push Button Demo",
31: 0L, NULL, 0, &hwndClient) ;
32:
33: while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
34: WinDispatchMsg (hab, &qmsg) ;
35:
36: WinDestroyWindow (hwndFrame) ;
37: WinDestroyMsgQueue (hmq) ;
38: WinTerminate (hab) ;
39:
40: return 0 ;
41: }
42:
43: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
44: {
45: static CHAR *szButtonLabel [] = { "Smaller", "Larger" } ;
46: static HWND hwndFrame, hwndButton [2] ;
47: static SHORT cxClient, cyClient, cxChar, cyChar ;
48: FONTMETRICS fm ;
49: HPS hps ;
50: SHORT s ;
51: RECTL rcl ;
52:
53: switch (msg)
54: {
55: case WM_CREATE :
56: hwndFrame = WinQueryWindow (hwnd, QW_PARENT, FALSE) ;
57:
58: hps = WinGetPS (hwnd) ;
59: GpiQueryFontMetrics (hps, (LONG) sizeof fm, &fm) ;
60: cxChar = (SHORT) fm.lAveCharWidth ;
61: cyChar = (SHORT) fm.lMaxBaselineExt ;
62: WinReleasePS (hps) ;
63:
64: for (s = 0 ; s < 2 ; s++)
65: hwndButton [s] = WinCreateWindow (
66: hwnd, /* Parent */
67: WC_BUTTON, /* Class */
68: szButtonLabel [s], /* Text */
69: WS_VISIBLE | /* Style */
70: BS_PUSHBUTTON,
71: 0, 0, /* Position */
72: 10 * cxChar, /* Width */
73: 7 * cyChar / 4, /* Height */
74: hwnd, /* Owner */
75: HWND_BOTTOM, /* Placement */
76: s, /* ID */
77: NULL, /* Ctrl Data */
78: NULL) ; /* Pres Params */
79: return 0 ;
80:
81: case WM_SIZE :
82: cxClient = SHORT1FROMMP (mp2) ;
83: cyClient = SHORT2FROMMP (mp2) ;
84:
85: for (s = 0 ; s < 2 ; s++)
86: WinSetWindowPos (hwndButton [s], NULL,
87: cxClient / 2 + (12 * s - 11) * cxChar,
88: cyClient / 2 - 7 * cyChar / 8,
89: 0, 0, SWP_MOVE) ;
90: return 0 ;
91:
92: case WM_COMMAND:
93: WinQueryWindowRect (hwnd, &rcl) ;
94: WinMapWindowPoints (hwnd, HWND_DESKTOP, (PPOINTL) &rcl, 2) ;
95:
96: switch (COMMANDMSG(&msg)->cmd)
97: {
98: case 0:
99: rcl.xLeft += cxClient / 20 ;
100: rcl.xRight -= cxClient / 20 ;
101: rcl.yBottom += cyClient / 20 ;
102: rcl.yTop -= cyClient / 20 ;
103: break ;
104:
105: case 1:
106: rcl.xLeft -= cxClient / 20 ;
107: rcl.xRight += cxClient / 20 ;
108: rcl.yBottom -= cyClient / 20 ;
109: rcl.yTop += cyClient / 20 ;
110: break ;
111: }
112: WinCalcFrameRect (hwndFrame, &rcl, FALSE) ;
113:
114: WinSetWindowPos (hwndFrame, NULL,
115: (SHORT) rcl.xLeft, (SHORT) rcl.yBottom,
116: (SHORT) rcl.xRight - (SHORT) rcl.xLeft,
117: (SHORT) rcl.yTop - (SHORT) rcl.yBottom,
118: SWP_MOVE | SWP_SIZE) ;
119: return 0 ;
120:
121: case WM_ERASEBACKGROUND:
122: return 1 ;
123: }
124: return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
125: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.