|
|
1.1 root 1: /*-------------------------------------
2: CONVMENU.C -- Conventional Menu Use
3: -------------------------------------*/
4:
5: #define INCL_WIN
6: #define INCL_GPI
7: #include <os2.h>
8: #include "convmenu.h"
9:
10: #define ID_TIMER 1
11:
12: MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
13:
14: CHAR szClientClass[] = "ConvMenu" ;
15: HAB hab ;
16:
17: int main (void)
18: {
19: static ULONG flFrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
20: FCF_SIZEBORDER | FCF_MINMAX |
21: FCF_SHELLPOSITION | FCF_TASKLIST |
22: FCF_MENU | FCF_ACCELTABLE ;
23: HMQ hmq ;
24: HWND hwndFrame, hwndClient ;
25: QMSG qmsg ;
26:
27: hab = WinInitialize (0) ;
28: hmq = WinCreateMsgQueue (hab, 0) ;
29:
30: WinRegisterClass (hab, szClientClass, ClientWndProc, 0L, 0) ;
31:
32: hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
33: &flFrameFlags, szClientClass, NULL,
34: 0L, NULL, ID_RESOURCE, &hwndClient) ;
35:
36: WinSendMsg (hwndFrame, WM_SETICON,
37: WinQuerySysPointer (HWND_DESKTOP, SPTR_APPICON, FALSE),
38: NULL) ;
39:
40: while (TRUE)
41: {
42: while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
43: WinDispatchMsg (hab, &qmsg) ;
44:
45: if (MBID_OK == WinMessageBox (HWND_DESKTOP, hwndClient,
46: "Really want to end program?",
47: szClientClass, 0,
48: MB_OKCANCEL | MB_ICONQUESTION))
49: break ;
50:
51: WinCancelShutdown (hmq, FALSE) ;
52: }
53:
54: WinDestroyWindow (hwndFrame) ;
55: WinDestroyMsgQueue (hmq) ;
56: WinTerminate (hab) ;
57: return 0 ;
58: }
59:
60: MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
61: {
62: static BOOL fTimerGoing = FALSE ;
63: static COLOR colBackground [] = {
64: 0xFFFFFFL, 0xC0C0C0L, 0x808080L,
65: 0x404040L, 0x000000L
66: } ;
67: static HWND hwndMenu ;
68: static SHORT sCurrentBackground = IDM_WHITE ;
69: HPS hps ;
70: RECTL rcl ;
71:
72: switch (msg)
73: {
74: case WM_CREATE:
75: hwndMenu = WinWindowFromID (
76: WinQueryWindow (hwnd, QW_PARENT, FALSE),
77: FID_MENU) ;
78: return 0 ;
79:
80: case WM_INITMENU:
81: switch (SHORT1FROMMP (mp1))
82: {
83: case IDM_TIMER:
84: WinSendMsg (hwndMenu, MM_SETITEMATTR,
85: MPFROM2SHORT (IDM_START, TRUE),
86: MPFROM2SHORT (MIA_DISABLED,
87: !fTimerGoing &&
88: WinQuerySysValue (HWND_DESKTOP, SV_CTIMERS) ?
89: 0 : MIA_DISABLED)) ;
90:
91: WinSendMsg (hwndMenu, MM_SETITEMATTR,
92: MPFROM2SHORT (IDM_STOP, TRUE),
93: MPFROM2SHORT (MIA_DISABLED,
94: fTimerGoing ? 0 : MIA_DISABLED)) ;
95: return 0 ;
96: }
97: break ;
98:
99: case WM_COMMAND:
100: switch (COMMANDMSG(&msg)->cmd)
101: {
102: case IDM_NEW:
103: WinMessageBox (HWND_DESKTOP, hwnd,
104: "Bogus \"New\" Dialog",
105: szClientClass, 0, MB_OK | MB_ICONASTERISK) ;
106: return 0 ;
107:
108: case IDM_OPEN:
109: WinMessageBox (HWND_DESKTOP, hwnd,
110: "Bogus \"Open\" Dialog",
111: szClientClass, 0, MB_OK | MB_ICONASTERISK) ;
112: return 0 ;
113:
114: case IDM_SAVE:
115: WinMessageBox (HWND_DESKTOP, hwnd,
116: "Bogus \"Save\" Dialog",
117: szClientClass, 0, MB_OK | MB_ICONASTERISK) ;
118: return 0 ;
119:
120: case IDM_SAVEAS:
121: WinMessageBox (HWND_DESKTOP, hwnd,
122: "Bogus \"Save As\" Dialog",
123: szClientClass, 0, MB_OK | MB_ICONASTERISK) ;
124: return 0 ;
125:
126: case IDM_EXIT:
127: WinSendMsg (hwnd, WM_CLOSE, 0L, 0L) ;
128: return 0 ;
129:
130: case IDM_ABOUT:
131: WinMessageBox (HWND_DESKTOP, hwnd,
132: "Bogus \"About\" Dialog",
133: szClientClass, 0, MB_OK | MB_ICONASTERISK) ;
134: return 0 ;
135:
136: case IDM_START:
137: if (WinStartTimer (hab, hwnd, ID_TIMER, 1000))
138: fTimerGoing = TRUE ;
139: else
140: WinMessageBox (HWND_DESKTOP, hwnd,
141: "Too many clocks or timers",
142: szClientClass, 0,
143: MB_OK | MB_ICONEXCLAMATION) ;
144: return 0 ;
145:
146: case IDM_STOP:
147: WinStopTimer (hab, hwnd, ID_TIMER) ;
148: fTimerGoing = FALSE ;
149: return 0 ;
150:
151: case IDM_WHITE:
152: case IDM_LTGRAY:
153: case IDM_GRAY:
154: case IDM_DKGRAY:
155: case IDM_BLACK:
156: WinSendMsg (hwndMenu, MM_SETITEMATTR,
157: MPFROM2SHORT (sCurrentBackground, TRUE),
158: MPFROM2SHORT (MIA_CHECKED, 0)) ;
159:
160: sCurrentBackground = COMMANDMSG(&msg)->cmd ;
161:
162: WinSendMsg (hwndMenu, MM_SETITEMATTR,
163: MPFROM2SHORT (sCurrentBackground, TRUE),
164: MPFROM2SHORT (MIA_CHECKED, MIA_CHECKED)) ;
165:
166: WinInvalidateRect (hwnd, NULL, FALSE) ;
167: return 0 ;
168: }
169: break ;
170:
171: case WM_HELP:
172: WinMessageBox (HWND_DESKTOP, hwnd,
173: "Help not yet implemented",
174: szClientClass, 0, MB_OK | MB_ICONEXCLAMATION) ;
175: return 0 ;
176:
177: case WM_TIMER:
178: WinAlarm (HWND_DESKTOP, WA_NOTE) ;
179: return 0 ;
180:
181: case WM_PAINT:
182: hps = WinBeginPaint (hwnd, NULL, NULL) ;
183: GpiSavePS (hps) ;
184:
185: GpiCreateLogColorTable (hps, 0L, LCOLF_RGB, 0L, 0L, NULL) ;
186:
187: WinQueryWindowRect (hwnd, &rcl) ;
188:
189: WinFillRect (hps, &rcl,
190: colBackground [sCurrentBackground - IDM_WHITE]) ;
191:
192: GpiRestorePS (hps, -1L) ;
193: WinEndPaint (hps) ;
194: return 0 ;
195:
196: case WM_DESTROY:
197: if (fTimerGoing)
198: {
199: WinStopTimer (hab, hwnd, ID_TIMER) ;
200: fTimerGoing = FALSE ;
201: }
202: return 0 ;
203: }
204: return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
205: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.