source: trunk/src/user32/wndclass.cpp@ 196

Last change on this file since 196 was 196, checked in by sandervl, 26 years ago

Code for window message spy

File size: 33.0 KB
Line 
1/* $Id: wndclass.cpp,v 1.7 1999-06-25 21:35:27 sandervl Exp $ */
2
3/*
4 * Win32 Window Class Managment Code for OS/2
5 *
6 * 18-07-1998 SvL: Merged all class code into this file + bug fixes
7 * Register all system classes at dll init
8 * Rewrote incorrect callback code
9 *
10 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
11 *
12 *
13 * Project Odin Software License can be found in LICENSE.TXT
14 *
15 */
16#include <os2win.h>
17#include <stdarg.h>
18#include <assert.h>
19#include "misc.h"
20#include "user32.h"
21#include "wndproc.h"
22#include "wndclass.h"
23#include "hooks.h"
24#include <spy.h>
25
26//default window handlers that are registered by RegisterClass are called
27//in this callback handler
28LRESULT EXPENTRY_O32 OS2ToWinCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam);
29//default window handlers that are queried by GetClassInfo/GetClassLong is really
30//this callback handler
31LRESULT WIN32API WinToOS2Callback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam);
32
33#ifdef DEBUG
34char *GetMsgText(int Msg);
35#endif
36
37DWORD MapOEMToRealKey(DWORD wParam, DWORD lParam);
38
39WNDPROC_O32 ButtonHandler = 0;
40WNDPROC_O32 ListboxHandler = 0;
41WNDPROC_O32 ComboboxHandler = 0;
42WNDPROC_O32 EditHandler = 0;
43WNDPROC_O32 MdiClientHandler = 0;
44WNDPROC_O32 ScrollbarHandler = 0;
45WNDPROC_O32 StaticHandler = 0;
46
47HWND hwndButton = 0;
48HWND hwndListbox = 0;
49HWND hwndEdit = 0;
50HWND hwndCombobox = 0;
51HWND hwndScrollbar = 0;
52HWND hwndMdiClient = 0;
53HWND hwndStatic = 0;
54
55Win32WindowClass *ButtonClass = 0;
56Win32WindowClass *ListboxClass = 0;
57Win32WindowClass *EditClass = 0;
58Win32WindowClass *ComboboxClass = 0;
59Win32WindowClass *MdiClientClass = 0;
60Win32WindowClass *ScrollbarClass = 0;
61Win32WindowClass *StaticClass = 0;
62//******************************************************************************
63//******************************************************************************
64LRESULT WIN32API ButtonCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
65{
66 switch(Msg)
67 {
68 case WM_CREATE:
69 case WM_DESTROY:
70 case WM_LBUTTONDOWN:
71 case WM_MBUTTONDOWN:
72 case WM_RBUTTONDOWN:
73 NotifyParent(hwnd, Msg, wParam, lParam);
74 break;
75 }
76 return ButtonHandler(hwnd, Msg, wParam, lParam);
77}
78//******************************************************************************
79//******************************************************************************
80LRESULT WIN32API ListboxCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
81{
82 return ListboxHandler(hwnd, Msg, wParam, lParam);
83}
84//******************************************************************************
85//******************************************************************************
86LRESULT WIN32API ComboboxCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
87{
88 return ComboboxHandler(hwnd, Msg, wParam, lParam);
89}
90//******************************************************************************
91//******************************************************************************
92LRESULT WIN32API MdiClientCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
93{
94 return MdiClientHandler(hwnd, Msg, wParam, lParam);
95}
96//******************************************************************************
97//******************************************************************************
98LRESULT WIN32API EditCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
99{
100 return EditHandler(hwnd, Msg, wParam, lParam);
101}
102//******************************************************************************
103//******************************************************************************
104LRESULT WIN32API ScrollbarCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
105{
106 return ScrollbarHandler(hwnd, Msg, wParam, lParam);
107}
108//******************************************************************************
109//******************************************************************************
110LRESULT WIN32API StaticCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
111{
112 return StaticHandler(hwnd, Msg, wParam, lParam);
113}
114//******************************************************************************
115//SvL: 18-7-'98, Registers system window classes (button, listbox etc etc)
116//******************************************************************************
117void RegisterSystemClasses(ULONG hModule)
118{
119 WNDCLASSA wndclass;
120 HWND hwnd;
121
122 if(O32_GetClassInfo(NULL, "BUTTON", &wndclass)) {
123 dprintf(("Create BUTTON System class"));
124 ButtonClass = new Win32WindowClass(ButtonCallback, "BUTTON", hModule);
125 ButtonHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
126 hwndButton = O32_CreateWindow("BUTTON", "BUTTON", 0, 0, 0, 0, 0, 0, 0, 0, 0);
127 if(hwndButton == 0) {
128 dprintf(("RegisterSystemClasses failed!!"));
129 }
130 O32_SetClassLong(hwndButton, GCL_WNDPROC, (LONG)ButtonCallback);
131 }
132 if(O32_GetClassInfo(NULL, "LISTBOX", &wndclass)) {
133 dprintf(("Create LISTBOX System class"));
134 ListboxClass = new Win32WindowClass(ListboxCallback, "LISTBOX", hModule);
135 ListboxHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
136 hwndListbox = O32_CreateWindow("LISTBOX", "LISTBOX", 0, 0, 0, 0, 0, 0, 0, 0, 0);
137 if(hwndListbox == 0) {
138 dprintf(("RegisterSystemClasses failed!!"));
139 }
140 O32_SetClassLong(hwndListbox, GCL_WNDPROC, (LONG)ListboxCallback);
141 }
142 if(O32_GetClassInfo(NULL, "COMBOBOX", &wndclass)) {
143 dprintf(("Create COMBOBOX System class"));
144 ComboboxClass = new Win32WindowClass(ComboboxCallback, "COMBOBOX", hModule);
145 ComboboxHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
146 hwndCombobox = O32_CreateWindow("COMBOBOX", "COMBOBOX", 0, 0, 0, 0, 0, 0, 0, 0, 0);
147 if(hwndCombobox == 0) {
148 dprintf(("RegisterSystemClasses failed!!"));
149 }
150 O32_SetClassLong(hwndCombobox, GCL_WNDPROC, (LONG)ComboboxCallback);
151 }
152 if(O32_GetClassInfo(NULL, "EDIT", &wndclass)) {
153 dprintf(("Create EDIT System class"));
154 EditClass = new Win32WindowClass(EditCallback, "EDIT", hModule);
155 EditHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
156 hwndEdit = O32_CreateWindow("EDIT", "EDIT", 0, 0, 0, 0, 0, 0, 0, 0, 0);
157 if(hwndEdit == 0) {
158 dprintf(("RegisterSystemClasses failed!!"));
159 }
160 O32_SetClassLong(hwndEdit, GCL_WNDPROC, (LONG)EditCallback);
161 }
162 //TODO: This doens't work yet!! (need to create a normal window as parent)
163 if(O32_GetClassInfo(NULL, "MDICLIENT", &wndclass)) {
164 dprintf(("Create MDICLIENT System class"));
165 MdiClientClass = new Win32WindowClass(MdiClientCallback, "MDICLIENT", hModule);
166 MdiClientHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
167 hwndMdiClient = O32_CreateWindow("MDICLIENT", "MDICLIENT", WS_CHILD, 0, 0, 0, 0, hwndListbox, 0, 0, 0);
168 if(hwndMdiClient == 0) {
169 dprintf(("RegisterSystemClasses failed!!"));
170 }
171 O32_SetClassLong(hwndMdiClient, GCL_WNDPROC, (LONG)MdiClientCallback);
172 }
173 if(O32_GetClassInfo(NULL, "SCROLLBAR", &wndclass)) {
174 dprintf(("Create SCROLLBAR System class"));
175 ScrollbarClass = new Win32WindowClass(ScrollbarCallback, "SCROLLBAR", hModule);
176 ScrollbarHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
177 hwndScrollbar = O32_CreateWindow("SCROLLBAR", "SCROLLBAR", 0, 0, 0, 0, 0, 0, 0, 0, 0);
178 if(hwndScrollbar == 0) {
179 dprintf(("RegisterSystemClasses failed!!"));
180 }
181 O32_SetClassLong(hwndScrollbar, GCL_WNDPROC, (LONG)ScrollbarCallback);
182 }
183 if(O32_GetClassInfo(NULL, "STATIC", &wndclass)) {
184 dprintf(("Create STATIC System class"));
185 StaticClass = new Win32WindowClass(StaticCallback, "STATIC", hModule);
186 StaticHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
187 hwndStatic = O32_CreateWindow("STATIC", "STATIC", 0, 0, 0, 0, 0, 0, 0, 0, 0);
188 if(hwndStatic == 0) {
189 dprintf(("RegisterSystemClasses failed!!"));
190 }
191 O32_SetClassLong(hwndStatic, GCL_WNDPROC, (LONG)StaticCallback);
192 }
193//TODO: More standard classes in win95/NT4?
194}
195//******************************************************************************
196//******************************************************************************
197void UnregisterSystemClasses()
198{
199 dprintf(("KERNEL32: UnregisterSystemClasses"));
200 if(hwndButton) O32_DestroyWindow(hwndButton);
201 if(hwndListbox) O32_DestroyWindow(hwndListbox);
202 if(hwndCombobox) O32_DestroyWindow(hwndCombobox);
203 if(hwndMdiClient) O32_DestroyWindow(hwndMdiClient);
204 if(hwndEdit) O32_DestroyWindow(hwndEdit);
205 if(hwndScrollbar) O32_DestroyWindow(hwndScrollbar);
206 if(hwndStatic) O32_DestroyWindow(hwndStatic);
207 if(ButtonClass) delete ButtonClass;
208 if(ListboxClass) delete ListboxClass;
209 if(EditClass) delete EditClass;
210 if(ComboboxClass) delete ComboboxClass;
211 if(MdiClientClass) delete MdiClientClass;
212 if(ScrollbarClass) delete ScrollbarClass;
213 if(StaticClass) delete StaticClass;
214 ButtonClass = NULL;
215 EditClass = NULL;
216 ListboxClass = NULL;
217 ComboboxClass = NULL;
218 MdiClientClass = NULL;
219 ScrollbarClass = NULL;
220 StaticClass = NULL;
221}
222//******************************************************************************
223//SvL: 18-7-'98: Moved here from user32.cpp
224//******************************************************************************
225ATOM WIN32API RegisterClassA(const WNDCLASSA *lpWndClass)
226{
227 ATOM rc;
228 WNDCLASSA wc;
229
230#ifdef DEBUG
231 WriteLog("USER32: RegisterClassA\n");
232 WriteLog("USER32: lpWndClass->style %X\n", lpWndClass->style);
233 WriteLog("USER32: lpWndClass->lpfnWndProc %X\n", lpWndClass->lpfnWndProc);
234 WriteLog("USER32: lpWndClass->cbClsExtra %X\n", lpWndClass->cbClsExtra);
235 WriteLog("USER32: lpWndClass->cbWndExtra %X\n", lpWndClass->cbWndExtra);
236 WriteLog("USER32: lpWndClass->hInstance %X\n", lpWndClass->hInstance);
237 WriteLog("USER32: lpWndClass->hIcon %X\n", lpWndClass->hIcon);
238 WriteLog("USER32: lpWndClass->hCursor %X\n", lpWndClass->hCursor);
239 WriteLog("USER32: lpWndClass->hbrBackground %X\n", lpWndClass->hbrBackground);
240 WriteLog("USER32: lpWndClass->lpszMenuName %X\n", lpWndClass->lpszMenuName);
241 if((int)lpWndClass->lpszClassName >> 16 == 0)
242 WriteLog("USER32: lpWndClass->lpszClassName %X\n", lpWndClass->lpszClassName);
243 else WriteLog("USER32: lpWndClass->lpszClassName %s\n", lpWndClass->lpszClassName);
244#endif
245 memcpy(&wc, lpWndClass, sizeof(WNDCLASSA));
246
247 if((int)wc.lpszMenuName >> 16 != 0) {//convert string name identifier to numeric id
248 dprintf(("USER32: lpszMenuName %s\n", wc.lpszMenuName));
249 *(int *)&wc.lpszMenuName = ConvertNameId(0, (char *)wc.lpszMenuName);
250 dprintf(("USER32: Menu id = %d\n", (int)wc.lpszMenuName));
251 }
252#ifdef DEBUG
253 if(wc.style & (CS_PARENTDC | CS_CLASSDC)) {
254 dprintf(("USER32: Class uses an unsupported style!!!\n"));
255 }
256#endif
257 //These are not supported by Open32
258 wc.style &= ~(CS_PARENTDC | CS_CLASSDC);
259
260//SvL: 18-7-'98 Breaks apps (solitaire, rasmol..)
261#if 0
262 /* @@@PH 98/06/21 experimental fix for WInhlp32 */
263#ifndef CS_SYNCPAINT
264 #define CS_SYNCPAINT 0x02000000L
265#endif
266
267 wc.style |= CS_SYNCPAINT;
268#endif
269
270 wc.lpfnWndProc = (WNDPROC)Win32WindowClass::GetOS2ClassCallback();
271 rc = O32_RegisterClass(&wc);
272 if(rc) {
273 Win32WindowClass *wndclass = new Win32WindowClass((WNDPROC)lpWndClass->lpfnWndProc, (LPSTR)wc.lpszClassName, wc.hInstance);
274 }
275 dprintf(("USER32: RegisterClass returned %d (%d)\n", rc, GetLastError()));
276 return(rc);
277}
278//******************************************************************************
279//SvL: 18-7-'98: Moved here from user32.cpp
280//******************************************************************************
281ATOM WIN32API RegisterClassExA(const WNDCLASSEXA *lpWndClass)
282{
283 ATOM rc;
284 WNDCLASSEXA wc;
285
286#ifdef DEBUG
287 WriteLog("USER32: lpWndClass->cbSize %X\n", lpWndClass->cbSize);
288 WriteLog("USER32: lpWndClass->style %X\n", lpWndClass->style);
289 WriteLog("USER32: lpWndClass->lpfnWndProc %X\n", lpWndClass->lpfnWndProc);
290 WriteLog("USER32: lpWndClass->cbClsExtra %X\n", lpWndClass->cbClsExtra);
291 WriteLog("USER32: lpWndClass->cbWndExtra %X\n", lpWndClass->cbWndExtra);
292 WriteLog("USER32: lpWndClass->hInstance %X\n", lpWndClass->hInstance);
293 WriteLog("USER32: lpWndClass->hIcon %X\n", lpWndClass->hIcon);
294 WriteLog("USER32: lpWndClass->hCursor %X\n", lpWndClass->hCursor);
295 WriteLog("USER32: lpWndClass->hbrBackground %X\n", lpWndClass->hbrBackground);
296 WriteLog("USER32: lpWndClass->lpszMenuName %X\n", lpWndClass->lpszMenuName);
297 if((int)lpWndClass->lpszClassName >> 16 == 0)
298 WriteLog("USER32: lpWndClass->lpszClassName %X\n", lpWndClass->lpszClassName);
299 else WriteLog("USER32: lpWndClass->lpszClassName %s\n", lpWndClass->lpszClassName);
300#endif
301 memcpy(&wc, lpWndClass, sizeof(WNDCLASSEXA));
302
303 if((int)wc.lpszMenuName >> 16 != 0) {//convert string name identifier to numeric id
304 dprintf(("USER32: lpszMenuName %s\n", wc.lpszMenuName));
305 *(int *)&wc.lpszMenuName = ConvertNameId(0, (char *)wc.lpszMenuName);
306 dprintf(("USER32: Menu id = %d\n", (int)wc.lpszMenuName));
307 }
308 if(wc.cbSize != sizeof(WNDCLASSEXA))
309 return(0);
310
311#ifdef DEBUG
312 if(wc.style & (CS_PARENTDC | CS_CLASSDC)) {
313 dprintf(("USER32: Class uses an unsupported style!!!\n"));
314 }
315#endif
316 //These are not supported by Open32
317 wc.style &= ~(CS_PARENTDC | CS_CLASSDC);
318
319 wc.lpfnWndProc = (WNDPROC)Win32WindowClass::GetOS2ClassCallback();
320
321 rc = O32_RegisterClass((WNDCLASSA *)&wc.style);
322 if(rc) {
323 Win32WindowClass *wndclass = new Win32WindowClass((WNDPROC)lpWndClass->lpfnWndProc, (LPSTR)wc.lpszClassName, wc.hInstance);
324 }
325#ifdef DEBUG
326 WriteLog("USER32: RegisterClassExA, not completely supported, returned %d\n", rc);
327 if(rc == 0)
328 WriteLog("USER32: GetLastError returned %X\n", GetLastError());
329
330#endif
331 return(rc);
332}
333//******************************************************************************
334//******************************************************************************
335WORD WIN32API RegisterClassW(const WNDCLASSW *lpwc)
336{
337 ATOM rc;
338 WNDCLASSA wclass;
339
340 dprintf(("RegisterClassW\n"));
341 memcpy(&wclass, lpwc, sizeof(WNDCLASSA));
342 if(wclass.lpszMenuName && ((int)wclass.lpszMenuName >> 16 != 0)) {
343 wclass.lpszMenuName = UnicodeToAsciiString((LPWSTR)lpwc->lpszMenuName);
344 }
345 if(wclass.lpszClassName && ((int)wclass.lpszClassName >> 16 != 0)) {
346 wclass.lpszClassName = UnicodeToAsciiString((LPWSTR)lpwc->lpszClassName);
347 }
348
349 rc = RegisterClassA(&wclass);
350
351 //TODO: Assuming RegisterClass doesn't mess up our structure
352 if(lpwc->lpszMenuName && ((int)lpwc->lpszMenuName >> 16 != 0)) {
353 FreeAsciiString((char *)wclass.lpszMenuName);
354 }
355 if(lpwc->lpszClassName && ((int)lpwc->lpszClassName >> 16 != 0)) {
356 FreeAsciiString((char *)wclass.lpszClassName);
357 }
358 return(rc);
359}
360//******************************************************************************
361//******************************************************************************
362ATOM WIN32API RegisterClassExW(CONST WNDCLASSEXW *lpwc)
363{
364 ATOM rc;
365 WNDCLASSEXA wclass;
366
367 dprintf(("RegisterClassExW\n"));
368 memcpy(&wclass, lpwc, sizeof(WNDCLASSEXA));
369 if(wclass.lpszMenuName && ((int)wclass.lpszMenuName >> 16 != 0)) {
370 wclass.lpszMenuName = UnicodeToAsciiString((LPWSTR)lpwc->lpszMenuName);
371 }
372 if(wclass.lpszClassName && ((int)wclass.lpszClassName >> 16 != 0)) {
373 wclass.lpszClassName = UnicodeToAsciiString((LPWSTR)lpwc->lpszClassName);
374 }
375
376 rc = RegisterClassExA(&wclass);
377
378 //TODO: Assuming RegisterClassEx doesn't mess up our structure
379 if(lpwc->lpszMenuName && ((int)lpwc->lpszMenuName >> 16 != 0)) {
380 FreeAsciiString((char *)wclass.lpszMenuName);
381 }
382 if(lpwc->lpszClassName && ((int)lpwc->lpszClassName >> 16 != 0)) {
383 FreeAsciiString((char *)wclass.lpszClassName);
384 }
385 return(rc);
386}
387//******************************************************************************
388//******************************************************************************
389BOOL WIN32API UnregisterClassA(LPCSTR lpszClassName, HINSTANCE hinst)
390{
391 BOOL rc;
392
393 Win32WindowClass::UnregisterClass(hinst, (LPSTR)lpszClassName);
394 rc = O32_UnregisterClass(lpszClassName, hinst);
395 dprintf(("USER32: OS2UnregisterClassA returned %d\n", rc));
396
397 //Spintest returns FALSE in dll termination, so pretend it succeeded
398 return(TRUE);
399}
400//******************************************************************************
401//******************************************************************************
402BOOL WIN32API UnregisterClassW(LPCWSTR lpszClassName, HINSTANCE hinst)
403{
404 char *astring = NULL;
405 BOOL rc;
406
407 dprintf(("USER32: OS2UnregisterClassW\n"));
408 if((int)lpszClassName >> 16 != 0) {
409 astring = UnicodeToAsciiString((LPWSTR)lpszClassName);
410 }
411 else astring = (char *)lpszClassName;
412
413 Win32WindowClass::UnregisterClass(hinst, (LPSTR)astring);
414 rc = O32_UnregisterClass(astring, hinst);
415 if((int)astring >> 16 != 0) {
416 FreeAsciiString(astring);
417 }
418 //Spintest returns FALSE in dll termination, so pretend it succeeded
419 return(TRUE);
420}
421//******************************************************************************
422//******************************************************************************
423BOOL WIN32API GetClassInfoA(HINSTANCE arg1, LPCSTR arg2, WNDCLASSA * arg3)
424{
425 BOOL rc;
426
427 dprintf(("USER32: OS2GetClassInfoA\n"));
428 rc = O32_GetClassInfo(arg1, arg2, (WNDCLASSA *)arg3);
429 if(rc == TRUE) {
430 arg3->lpfnWndProc = (WNDPROC)Win32WindowClass::GetClassCallback((LPSTR)arg2);
431 }
432 return(rc);
433}
434//******************************************************************************
435//******************************************************************************
436BOOL WIN32API GetClassInfoW(HINSTANCE hinst,
437 LPCWSTR lpszClass,
438 WNDCLASSW *lpwc)
439{
440 WNDCLASSA wclass;
441 BOOL rc;
442 char *szClass = NULL;
443
444 dprintf(("USER32: OS2GetClassInfoW\n"));
445 if((int)lpszClass >> 16 != 0) {
446 szClass = UnicodeToAsciiString((LPWSTR)lpszClass);
447 dprintf(("USER32: OS2GetClassInfoW %s\n", szClass));
448 }
449 else szClass = (char *)lpszClass;
450
451 rc = GetClassInfoA(hinst, szClass, &wclass);
452 if(rc == TRUE) {
453 memcpy(lpwc, &wclass, sizeof(WNDCLASSA));
454 //TODO: Memory leak (create class object at RegisterClass and delete it at UnregisterClass)
455 if(lpwc->lpszMenuName && ((int)lpwc->lpszMenuName >> 16 != 0)) {
456 lpwc->lpszMenuName = (LPCWSTR)malloc(strlen(wclass.lpszMenuName)*sizeof(WCHAR)+2);
457 AsciiToUnicode((char *)wclass.lpszMenuName, (LPWSTR)lpwc->lpszMenuName);
458 }
459 if(lpwc->lpszClassName && ((int)lpwc->lpszClassName >> 16 != 0)) {
460 lpwc->lpszClassName = (LPCWSTR)malloc(strlen(wclass.lpszClassName)*sizeof(WCHAR)+2);
461 AsciiToUnicode((char *)wclass.lpszClassName, (LPWSTR)lpwc->lpszClassName);
462 }
463 }
464 dprintf(("USER32: OS2GetClassInfoW returned %d\n", rc));
465 return(rc);
466}
467/****************************************************************************
468 * Name : BOOL WIN32API GetClassInfoExA
469 * Purpose : The GetClassInfoEx function retrieves information about a window
470 * class, including the handle of the small icon associated with the
471 * window class. GetClassInfo does not retrieve the handle of the small icon.
472 * Parameters: HINSTANCE hinst handle of application instance
473 * LPCTSTR lpszClass address of class name string
474 * LPWNDCLASSEX lpwcx address of structure for class data
475 * Variables :
476 * Result : If the function finds a matching class and successfully copies
477 * the data, the return value is TRUE;
478 * otherwise, it is FALSE.
479 * To get extended error information, call GetLastError.
480 * Remark : PH: does not obtain handle of the small icon
481 * Status : UNTESTED STUB
482 *
483 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
484 *****************************************************************************/
485BOOL WIN32API GetClassInfoExA(HINSTANCE hInstance,
486 LPCTSTR lpszClass,
487 LPWNDCLASSEXA lpwcx)
488{
489 WNDCLASSA WndClass; /* structure for data transformation */
490 BOOL bResult; /* result of subsequent function calls */
491
492 dprintf(("USER32:GetClassInfoExA (%08xh,%s,%08x).\n",
493 hInstance,
494 lpszClass,
495 lpwcx));
496
497 /* convert the structures */
498 memcpy((PVOID)&WndClass,
499 (PVOID)&lpwcx->style,
500 sizeof(WndClass) );
501
502 bResult = GetClassInfoA(hInstance,
503 lpszClass,
504 (WNDCLASSA *)&WndClass);
505 if (bResult == TRUE)
506 {
507 /* convert data back to original structure */
508 memcpy((PVOID)&lpwcx->style,
509 (PVOID)&WndClass,
510 sizeof(WndClass) );
511 lpwcx->cbSize = sizeof(WNDCLASSEXA);
512 lpwcx->hIconSm = 0;
513 }
514
515 return (bResult);
516}
517/*****************************************************************************
518 * Name : BOOL WIN32API GetClassInfoExW
519 * Purpose : The GetClassInfoEx function retrieves information about a window
520 * class, including the handle of the small icon associated with the
521 * window class. GetClassInfo does not retrieve the handle of the small icon.
522 * Parameters: HINSTANCE hinst handle of application instance
523 * LPCWSTR lpszClass address of class name string
524 * LPWNDCLASSEX lpwcx address of structure for class data
525 * Variables :
526 * Result : If the function finds a matching class and successfully copies
527 * the data, the return value is TRUE;
528 * otherwise, it is FALSE.
529 * To get extended error information, call GetLastError.
530 * Remark : does not obtain handle of the small icon
531 * Status : UNTESTED STUB
532 *
533 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
534 *****************************************************************************/
535BOOL WIN32API GetClassInfoExW(HINSTANCE hInstance,
536 LPCWSTR lpszClass,
537 LPWNDCLASSEXW lpwcx)
538{
539 WNDCLASSW WndClass; /* structure for data transformation */
540 BOOL bResult; /* result of subsequent function calls */
541
542 dprintf(("USER32:GetClassInfoExW (%08xh,%s,%08x).\n",
543 hInstance,
544 lpszClass,
545 lpwcx));
546
547 /* convert the structures */
548 memcpy((PVOID)&WndClass,
549 (PVOID)&lpwcx->style,
550 sizeof(WndClass) );
551
552 bResult = GetClassInfoW(hInstance,
553 (LPWSTR)lpszClass,
554 (WNDCLASSW *)&WndClass);
555 if (bResult == TRUE)
556 {
557 /* convert data back to original structure */
558 memcpy((PVOID)&lpwcx->style,
559 (PVOID)&WndClass,
560 sizeof(WndClass) );
561 lpwcx->cbSize = sizeof(WNDCLASSEXW);
562 lpwcx->hIconSm = 0;
563 }
564
565 return (bResult);
566}
567//******************************************************************************
568//TODO: Not complete (unsupported extension in WNDCLASSEXA/W, unsupported styles etc)
569//******************************************************************************
570LONG WIN32API GetClassLongA(HWND hwnd, int nIndex)
571{
572 DWORD rc;
573
574 dprintf(("USER32: OS2GetClassLongA\n"));
575 rc = O32_GetClassLong(hwnd, nIndex);
576 if(nIndex == GCL_WNDPROC) {
577 char szClass[128];
578 Win32WindowClass *wclass;
579
580 if(GetClassNameA(hwnd, szClass, sizeof(szClass))) {
581 wclass = Win32WindowClass::FindClass(szClass);
582 if(wclass) {
583 return (LONG)wclass->GetWinCallback();
584 }
585 }
586 dprintf(("GetClassLongA, class of window %X not found\n", hwnd));
587 return 0; //TODO: set last error
588 }
589 return rc;
590}
591//******************************************************************************
592//******************************************************************************
593LONG WIN32API GetClassLongW(HWND hwnd, int nIndex)
594{
595 dprintf(("USER32: OS2GetClassLongW\n"));
596 if(nIndex == GCL_MENUNAME) { //TODO
597 dprintf(("USER32: Class Menu name not implemented yet\n"));
598 }
599 // NOTE: This will not work as is (needs UNICODE support)
600 return GetClassLongA(hwnd, nIndex);
601}
602//******************************************************************************
603//******************************************************************************
604int WIN32API GetClassNameA( HWND arg1, LPSTR arg2, int arg3)
605{
606 dprintf(("USER32: OS2GetClassNameA\n"));
607 return O32_GetClassName(arg1, arg2, arg3);
608}
609//******************************************************************************
610//******************************************************************************
611int WIN32API GetClassNameW(HWND hwnd, LPWSTR lpClassName, int nMaxCount)
612{
613 char *astring = (char *)malloc(nMaxCount);
614 int rc;
615
616 dprintf(("USER32: OS2GetClassNameW\n"));
617 rc = GetClassNameA(hwnd, astring, nMaxCount);
618 AsciiToUnicode(astring, lpClassName);
619 free(astring);
620 return(rc);
621}
622//******************************************************************************
623//******************************************************************************
624WORD WIN32API GetClassWord( HWND arg1, int arg2)
625{
626 dprintf(("USER32: OS2GetClassWord\n"));
627 return O32_GetClassWord(arg1, arg2);
628}
629//******************************************************************************
630//******************************************************************************
631LONG WIN32API SetClassLongA(HWND hwnd, int nIndex, LONG lNewVal)
632{
633 DWORD rc;
634
635 dprintf(("USER32: OS2SetClassLongA\n"));
636 if(nIndex == GCL_WNDPROC) {
637 char szClass[128];
638 Win32WindowClass *wclass;
639
640 if(GetClassNameA(hwnd, szClass, sizeof(szClass))) {
641 wclass = Win32WindowClass::FindClass(szClass);
642 if(wclass) {
643 rc = (DWORD)wclass->GetWinCallback();
644 wclass->SetWinCallback((WNDPROC)lNewVal);
645 return rc;
646 }
647 }
648 dprintf(("SetClassLongA, class of window %X not found\n", hwnd));
649 return 0; //TODO: set last error
650 }
651 return O32_SetClassLong(hwnd, nIndex, lNewVal);
652}
653//******************************************************************************
654//******************************************************************************
655LONG WIN32API SetClassLongW( HWND arg1, int arg2, LONG arg3)
656{
657 dprintf(("USER32: OS2SetClassLongW\n"));
658 // NOTE: This will not work as is (needs UNICODE support)
659 return O32_SetClassLong(arg1, arg2, arg3);
660}
661//******************************************************************************
662//******************************************************************************
663WORD WIN32API SetClassWord( HWND arg1, int arg2, WORD arg3)
664{
665 dprintf(("USER32: OS2SetClassWord\n"));
666 return O32_SetClassWord(arg1, arg2, arg3);
667}
668//******************************************************************************
669//Win32WindowClass methods:
670//******************************************************************************
671Win32WindowClass::Win32WindowClass(WNDPROC pUserCallback, LPSTR id, HINSTANCE hinst)
672{
673 //Insert it in front of the rest
674 next = wndclasses;
675 wndclasses = this;
676 if((int)id >> 16 != 0) {
677 strcpy(className, id);
678 classAtom = 0;
679 }
680 else {
681 className[0] = 0;
682 classAtom = (DWORD)id;
683 }
684 this->hinst = hinst;
685
686 pWinCallback = pUserCallback;
687 dprintf(("Win32WindowClass::Win32WindowClass %d\n", id));
688}
689//******************************************************************************
690//******************************************************************************
691Win32WindowClass::~Win32WindowClass()
692{
693 Win32WindowClass *wndclass = Win32WindowClass::wndclasses;
694
695 if(wndclass == this) {
696 wndclasses = next;
697 }
698 else {
699 while(wndclass->next != NULL) {
700 if(wndclass->next == this) {
701 wndclass->next = next;
702 break;
703 }
704 wndclass = wndclass->next;
705 }
706 }
707}
708//******************************************************************************
709//******************************************************************************
710Win32WindowClass *Win32WindowClass::FindClass(LPSTR id)
711{
712 Win32WindowClass *wndclass = wndclasses;
713
714 if(wndclass == NULL) return(NULL);
715
716 if((int)id >> 16 != 0) {
717 if(stricmp(wndclass->className, id) == 0) {
718 return(wndclass);
719 }
720 else {
721 wndclass = wndclass->next;
722 while(wndclass != NULL) {
723 if(stricmp(wndclass->className, id) == 0) {
724 return(wndclass);
725 }
726 wndclass = wndclass->next;
727 }
728 }
729 }
730 else {
731 if(wndclass->classAtom == (DWORD)id) {
732 return(wndclass);
733 }
734 else {
735 wndclass = wndclass->next;
736 while(wndclass != NULL) {
737 if(wndclass->classAtom == (DWORD)id) {
738 return(wndclass);
739 }
740 wndclass = wndclass->next;
741 }
742 }
743 }
744 return(NULL);
745}
746//******************************************************************************
747//******************************************************************************
748void Win32WindowClass::UnregisterClass(HINSTANCE hinst, LPSTR id)
749{
750 Win32WindowClass *wndclass;
751
752 dprintf(("::UnregisterClass, destroy class %X!!\n", id));
753 wndclass = FindClass(id);
754 if(wndclass && wndclass->hinst == hinst) {
755 delete wndclass;
756 return;
757 }
758 dprintf(("::UnregisterClass, couldn't find class %X!!\n", id));
759}
760//******************************************************************************
761//******************************************************************************
762WNDPROC Win32WindowClass::GetClassCallback(HINSTANCE hinst, LPSTR id)
763{
764 Win32WindowClass *wndclass;
765
766 wndclass = FindClass(id);
767 if(wndclass && wndclass->hinst == hinst) {
768 return wndclass->pWinCallback;
769 }
770 dprintf(("::GetClassCallback, couldn't find class %X!!\n", id));
771 return(NULL);
772}
773//******************************************************************************
774//******************************************************************************
775WNDPROC Win32WindowClass::GetClassCallback(LPSTR id)
776{
777 Win32WindowClass *wndclass;
778
779 wndclass = FindClass(id);
780 if(wndclass) {
781 return wndclass->pWinCallback;
782 }
783 dprintf(("::GetClassCallback2, couldn't find class %X!!\n", id));
784 return(NULL);
785}
786//******************************************************************************
787//******************************************************************************
788WNDPROC_O32 Win32WindowClass::GetOS2ClassCallback()
789{
790 return OS2ToWinCallback;
791}
792//******************************************************************************
793//******************************************************************************
794LRESULT EXPENTRY_O32 OS2ToWinCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
795{
796 char szClass[128];
797 Win32WindowClass *wclass;
798 LRESULT rc;
799 DWORD dwStyle, dwExStyle;
800 HWND parentHwnd;
801 Win32WindowProc *window;
802
803#ifdef DEBUG
804 dprintf(("OS2ToWinCallback %s for %x %x %x", GetMsgText(Msg), hwnd, wParam, lParam));
805 PostSpyMessage(hwnd, Msg, wParam, lParam);
806#endif
807
808 if(HkCBT::OS2HkCBTProc(hwnd, Msg, wParam, lParam) == TRUE) {//hook swallowed msg
809 return(0);
810 }
811
812 if(O32_GetClassName(hwnd, szClass, sizeof(szClass))) {
813 wclass = Win32WindowClass::FindClass(szClass);
814 if(wclass) {
815 switch(Msg)
816 {
817 case WM_CREATE://Open32 isn't sending WM_NCCREATE messages!!
818 window = Win32WindowProc::FindProc(hwnd, GetCurrentThreadId());
819 if(window) {
820 dprintf(("OS2ToWinCallback (class): New window object!"));
821 window->SetWindowHandle(hwnd);
822 }
823
824 if(wclass->GetWinCallback()(hwnd, WM_NCCREATE, 0, lParam) == 0) {
825 dprintf(("WM_NCCREATE returned FALSE\n"));
826 return(-1); //don't create window
827 }
828 //Send WM_CREATE message before notifying parent
829 rc = wclass->GetWinCallback()(hwnd, Msg, wParam, lParam);
830
831 NotifyParent(hwnd, WM_CREATE, wParam, lParam);
832 return(rc);
833
834 case WM_DESTROY: //nofity parent
835 case WM_LBUTTONDOWN:
836 case WM_MBUTTONDOWN:
837 case WM_RBUTTONDOWN:
838 NotifyParent(hwnd, Msg, wParam, lParam);
839 break;
840
841 case WM_KEYDOWN:
842 case WM_KEYUP:
843 case WM_CHAR: //SvL: Correct Open32 key mapping bug
844 lParam = MapOEMToRealKey(wParam, lParam);
845 break;
846 case WM_ACTIVATE:
847 if(LOWORD(wParam) != WA_INACTIVE)
848 {
849 //EB: I think the problem is not a missing wm_erasebkgnd.
850 //Maybe some wrong flags in open32 during async repainting.
851 //SvL: Bugfix, Open32 is NOT sending this to the window (messes up Solitaire)
852 RECT rect;
853 HRGN hrgn;
854 HDC hdc = GetDC(hwnd);
855
856 // erase the dirty rect
857 GetUpdateRect(hwnd, &rect, TRUE);
858 hrgn = CreateRectRgnIndirect(&rect);
859 SelectClipRgn (hdc, hrgn);
860 DeleteObject (hrgn);
861 wclass->GetWinCallback()(hwnd, WM_ERASEBKGND, hdc, (LPARAM)&rect);
862 SelectClipRgn (hdc, NULL);
863 ReleaseDC(hwnd, hdc);
864 }
865 break;
866 }
867 return wclass->GetWinCallback()(hwnd, Msg, wParam, lParam);
868 }
869 }
870 dprintf(("OS2ToWinCallback: couldn't find class procedure of window %X\n", hwnd));
871 return(0);
872}
873//******************************************************************************
874//******************************************************************************
875LRESULT WIN32API WinToOS2Callback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
876{
877 WNDPROC_O32 os2callback;
878
879 os2callback = (WNDPROC_O32)GetClassLongA(hwnd, GCL_WNDPROC);
880 if(os2callback) {
881 return os2callback(hwnd, Msg, wParam, lParam);
882 }
883 dprintf(("OS2ToWinCallback: window procedure == NULL!!\n"));
884 return(0);
885}
886//******************************************************************************
887//******************************************************************************
888Win32WindowClass *Win32WindowClass::wndclasses = NULL;
Note: See TracBrowser for help on using the repository browser.