|
|
1.1 root 1: /*++
2:
3: Copyright (c) 1993 Microsoft Corporation
4:
5: Module Name:
6:
7: controls.c
8:
9: Abstract:
10: This file implements the sun-classing and message processing of
11: the controls on the main ui dialog.
12:
13: Author:
14:
15: Wesley Witt (wesw) 1-May-1993
16:
17: Environment:
18:
19: User Mode
20:
21: --*/
22:
23: #include <windows.h>
24: #include <stdlib.h>
25: #include <stdio.h>
26: #include <string.h>
27:
28: #include "drwatson.h"
29: #include "proto.h"
30: #include "resource.h"
31:
32:
33: typedef struct _tagCONTROLINFO {
34: struct _tagCONTROLINFO *next;
35: HWND hwnd;
36: WNDPROC wndProc;
37: } CONTROLINFO, *PCONTROLINFO;
38:
39:
40: PCONTROLINFO ciHead = NULL;
41: PCONTROLINFO ciTail = NULL;
42: PCONTROLINFO ciFocus = NULL;
43: PCONTROLINFO ciDefault = NULL;
44:
45:
46:
47: void
48: SetFocusToCurrentControl( void )
49:
50: /*++
51:
52: Routine Description:
53:
54: Sets the focus to the current control.
55:
56: Arguments:
57:
58: None.
59:
60: Return Value:
61:
62: None.
63:
64: --*/
65:
66: {
67: if (ciFocus != NULL) {
68: SetFocus( ciFocus->hwnd );
69: }
70: }
71:
72: LRESULT
73: ControlWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
74:
75: /*++
76:
77: Routine Description:
78:
79: Processes focus messages and ensures that when the focus changes
80: from one button to another that the old button looses the focus
81: and the "default" state.
82:
83: Arguments:
84:
85: Standard WNDPROC entry.
86:
87: Return Value:
88:
89: LRESULT - Depending on input message and processing options.
90:
91: --*/
92:
93: {
94: PCONTROLINFO ci = ciHead;
95:
96: while (ci->hwnd != hwnd) {
97: ci = ci->next;
98: if (ci == NULL) {
99: dprintf( "unknown hwnd\n" );
100: return FALSE;
101: }
102: }
103:
104: switch(message) {
105: case WM_SETFOCUS:
106: ciFocus = ci;
107: break;
108:
109: case BM_SETSTYLE:
110: if (wParam == BS_DEFPUSHBUTTON) {
111: ciDefault = ci;
112: }
113: break;
114:
115: case BM_SETSTATE:
116: if ((GetWindowLong( hwnd, GWL_STYLE ) & 0xff) < BS_CHECKBOX) {
117: //
118: // change the button that had the focus
119: //
120: SendMessage( ciDefault->hwnd,
121: BM_SETSTYLE,
122: ( WPARAM ) BS_PUSHBUTTON,
123: ( LPARAM ) TRUE
124: );
125: UpdateWindow( ciDefault->hwnd );
126:
127: //
128: // change the button that is getting the focus
129: //
130: SendMessage( hwnd,
131: BM_SETSTYLE,
132: ( WPARAM ) BS_DEFPUSHBUTTON,
133: ( LPARAM ) TRUE
134: );
135: SetFocus( hwnd );
136: UpdateWindow( hwnd );
137: }
138: break;
139: }
140:
141: return CallWindowProc( ci->wndProc, hwnd, message, wParam, lParam );
142: }
143:
144:
145: BOOL CALLBACK
146: EnumChildProc( HWND hwnd, LPARAM lParam )
147:
148: /*++
149:
150: Routine Description:
151:
152: Subclass a controls in DrWatson's main window.
153:
154: Arguments:
155:
156: hwnd - Supplies the window handle for the main window.
157: lParam - non used
158:
159: Return Value:
160:
161: BOOL - Returns TRUE if each of the buttons in the ButtonHelpTable is
162: subclassed.
163:
164: --*/
165:
166: {
167: PCONTROLINFO ci;
168:
169: //
170: // add the control to the linked list
171: //
172: ci = (PCONTROLINFO) malloc( sizeof(CONTROLINFO) );
173: if (ci == NULL) {
174: return FALSE;
175: }
176: memset( ci, 0, sizeof(CONTROLINFO) );
177:
178: if (ciHead == NULL) {
179: ciHead = ciTail = ci;
180: }
181: else {
182: ciTail->next = ci;
183: ciTail = ci;
184: }
185:
186: //
187: // save the HWND
188: //
189: ci->hwnd = hwnd;
190:
191: //
192: // change the WNDPROC and save the address of the old one
193: //
194: ci->wndProc = (WNDPROC) SetWindowLong( hwnd,
195: GWL_WNDPROC,
196: (LONG)ControlWndProc
197: );
198:
199: if (GetWindowLong( hwnd, GWL_STYLE ) & BS_DEFPUSHBUTTON) {
200: ciDefault = ci;
201: }
202:
203: return TRUE;
204: }
205:
206: BOOL
207: SubclassControls( HWND hwnd )
208:
209: /*++
210:
211: Routine Description:
212:
213: Subclass the controls in DrWatson's main window.
214:
215: Arguments:
216:
217: hWnd - Supplies the window handle for the main window.
218:
219: Return Value:
220:
221: BOOL - Returns TRUE if each of the buttons in the ButtonHelpTable is
222: subclassed.
223:
224: --*/
225:
226: {
227: EnumChildWindows( hwnd, EnumChildProc, 0 );
228:
229: return TRUE;
230: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.