1 | /* $Id: windowclass.cpp,v 1.16 2001-02-22 10:37:31 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Win32 Window Class Code for OS/2
|
---|
4 | *
|
---|
5 | *
|
---|
6 | * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 | #include <os2win.h>
|
---|
13 | #include <stdio.h>
|
---|
14 | #include <stdlib.h>
|
---|
15 | #include <string.h>
|
---|
16 | #include <stdarg.h>
|
---|
17 | #include <assert.h>
|
---|
18 | #include <misc.h>
|
---|
19 | #include <win32class.h>
|
---|
20 | #include <win32wbase.h>
|
---|
21 | #include <controls.h>
|
---|
22 |
|
---|
23 | #define DBG_LOCALLOG DBG_windowclass
|
---|
24 | #include "dbglocal.h"
|
---|
25 |
|
---|
26 | //******************************************************************************
|
---|
27 | //******************************************************************************
|
---|
28 | void RegisterSystemClasses(ULONG hModule)
|
---|
29 | {
|
---|
30 | dprintf(("RegisterSystemClasses\n"));
|
---|
31 | CONTROLS_Register();
|
---|
32 | }
|
---|
33 | //******************************************************************************
|
---|
34 | //******************************************************************************
|
---|
35 | void UnregisterSystemClasses()
|
---|
36 | {
|
---|
37 | dprintf(("UnregisterSystemClasses\n"));
|
---|
38 | CONTROLS_Unregister();
|
---|
39 | }
|
---|
40 | //******************************************************************************
|
---|
41 | //Note: RegisterClassA does NOT change the last error if successful! (verified in NT 4, SP6)
|
---|
42 | //******************************************************************************
|
---|
43 | ATOM WIN32API RegisterClassA(CONST WNDCLASSA *lpWndClass)
|
---|
44 | {
|
---|
45 | WNDCLASSEXA wc;
|
---|
46 | Win32WndClass *wclass;
|
---|
47 |
|
---|
48 | dprintf(("RegisterClassA\n"));
|
---|
49 | //CB: size new in ex structure
|
---|
50 | wc.cbSize = sizeof(wc);
|
---|
51 | memcpy(&wc.style, lpWndClass, sizeof(WNDCLASSA));
|
---|
52 | wc.hIconSm = 0;
|
---|
53 |
|
---|
54 | if(Win32WndClass::FindClass(wc.hInstance, (LPSTR)wc.lpszClassName)) {
|
---|
55 | if(HIWORD(wc.lpszClassName)) {
|
---|
56 | dprintf(("RegisterClassA %x %s already exists", wc.hInstance, wc.lpszClassName));
|
---|
57 | }
|
---|
58 | else dprintf(("RegisterClassA %x %x already exists", wc.hInstance, wc.lpszClassName));
|
---|
59 | SetLastError(ERROR_CLASS_ALREADY_EXISTS);
|
---|
60 | return 0;
|
---|
61 | }
|
---|
62 |
|
---|
63 | wclass = new Win32WndClass(&wc,FALSE);
|
---|
64 | if(wclass == NULL) {
|
---|
65 | dprintf(("ERROR: RegisterClassA winclass == NULL!"));
|
---|
66 | DebugInt3();
|
---|
67 | return(0);
|
---|
68 | }
|
---|
69 | return(wclass->getAtom());
|
---|
70 | }
|
---|
71 | //******************************************************************************
|
---|
72 | //Note: RegisterClassA does NOT change the last error if successful! (verified in NT 4, SP6)
|
---|
73 | //******************************************************************************
|
---|
74 | ATOM WIN32API RegisterClassExA(CONST WNDCLASSEXA *lpWndClass)
|
---|
75 | {
|
---|
76 | Win32WndClass *wclass;
|
---|
77 |
|
---|
78 | if(Win32WndClass::FindClass(lpWndClass->hInstance, (LPSTR)lpWndClass->lpszClassName)) {
|
---|
79 | if(HIWORD(lpWndClass->lpszClassName)) {
|
---|
80 | dprintf(("RegisterClassExA %x %s already exists", lpWndClass->hInstance, lpWndClass->lpszClassName));
|
---|
81 | }
|
---|
82 | else dprintf(("RegisterClassExA %x %x already exists", lpWndClass->hInstance, lpWndClass->lpszClassName));
|
---|
83 | SetLastError(ERROR_CLASS_ALREADY_EXISTS);
|
---|
84 | return 0;
|
---|
85 | }
|
---|
86 |
|
---|
87 | dprintf(("RegisterClassExA\n"));
|
---|
88 | wclass = new Win32WndClass((WNDCLASSEXA *)lpWndClass,FALSE);
|
---|
89 | if(wclass == NULL) {
|
---|
90 | dprintf(("ERROR: RegisterClassExA winclass == NULL!"));
|
---|
91 | DebugInt3();
|
---|
92 | return(0);
|
---|
93 | }
|
---|
94 | return(wclass->getAtom());
|
---|
95 | }
|
---|
96 | //******************************************************************************
|
---|
97 | //Note: RegisterClassA does NOT change the last error if successful! (verified in NT 4, SP6)
|
---|
98 | //******************************************************************************
|
---|
99 | WORD WIN32API RegisterClassW(CONST WNDCLASSW *lpwc)
|
---|
100 | {
|
---|
101 | ATOM rc;
|
---|
102 | WNDCLASSEXA wc;
|
---|
103 | Win32WndClass *winclass;
|
---|
104 |
|
---|
105 | dprintf(("RegisterClassW\n"));
|
---|
106 | //CB: size new in ex structure
|
---|
107 | wc.cbSize = sizeof(wc);
|
---|
108 | memcpy(&wc.style, lpwc, sizeof(WNDCLASSA));
|
---|
109 | wc.hIconSm = 0;
|
---|
110 |
|
---|
111 | if(Win32WndClass::FindClass(wc.hInstance, (LPWSTR)wc.lpszClassName)) {
|
---|
112 | dprintf(("RegisterClassW %x %x already exists", wc.hInstance, wc.lpszClassName));
|
---|
113 | SetLastError(ERROR_CLASS_ALREADY_EXISTS);
|
---|
114 | return 0;
|
---|
115 | }
|
---|
116 |
|
---|
117 | winclass = new Win32WndClass((WNDCLASSEXA *)&wc, TRUE);
|
---|
118 | if(winclass == NULL) {
|
---|
119 | dprintf(("ERROR: RegisterClassW winclass == NULL!"));
|
---|
120 | DebugInt3();
|
---|
121 | return 0;
|
---|
122 | }
|
---|
123 | rc = winclass->getAtom();
|
---|
124 |
|
---|
125 | return(rc);
|
---|
126 | }
|
---|
127 | //******************************************************************************
|
---|
128 | //Note: RegisterClassA does NOT change the last error if successful! (verified in NT 4, SP6)
|
---|
129 | //******************************************************************************
|
---|
130 | ATOM WIN32API RegisterClassExW(CONST WNDCLASSEXW *lpwc)
|
---|
131 | {
|
---|
132 | ATOM rc;
|
---|
133 | WNDCLASSEXA wc;
|
---|
134 | Win32WndClass *winclass;
|
---|
135 |
|
---|
136 | dprintf(("RegisterClassExW\n"));
|
---|
137 | memcpy(&wc, lpwc, sizeof(WNDCLASSEXA));
|
---|
138 |
|
---|
139 | if(Win32WndClass::FindClass(wc.hInstance, (LPWSTR)wc.lpszClassName)) {
|
---|
140 | dprintf(("RegisterClassW %x %x already exists", wc.hInstance, wc.lpszClassName));
|
---|
141 | SetLastError(ERROR_CLASS_ALREADY_EXISTS);
|
---|
142 | return 0;
|
---|
143 | }
|
---|
144 |
|
---|
145 | winclass = new Win32WndClass((WNDCLASSEXA *)&wc, TRUE);
|
---|
146 | if(winclass == NULL) {
|
---|
147 | dprintf(("ERROR: RegisterClassExW winclass == NULL!"));
|
---|
148 | DebugInt3();
|
---|
149 | return(0);
|
---|
150 | }
|
---|
151 | rc = winclass->getAtom();
|
---|
152 |
|
---|
153 | return(rc);
|
---|
154 | }
|
---|
155 | //******************************************************************************
|
---|
156 | //******************************************************************************
|
---|
157 | BOOL WIN32API UnregisterClassA(LPCSTR lpszClassName, HINSTANCE hinst)
|
---|
158 | {
|
---|
159 | BOOL ret;
|
---|
160 |
|
---|
161 | ret = Win32WndClass::UnregisterClassA(hinst, (LPSTR)lpszClassName);
|
---|
162 | #if 1
|
---|
163 | return ret;
|
---|
164 | #else
|
---|
165 | //Spintest returns FALSE in dll termination, so pretend it succeeded
|
---|
166 | // return(TRUE);
|
---|
167 | #endif
|
---|
168 | }
|
---|
169 | //******************************************************************************
|
---|
170 | //******************************************************************************
|
---|
171 | BOOL WIN32API UnregisterClassW(LPCWSTR lpszClassName, HINSTANCE hinst)
|
---|
172 | {
|
---|
173 | char *astring = NULL;
|
---|
174 | BOOL ret;
|
---|
175 |
|
---|
176 | dprintf(("USER32: UnregisterClassW\n"));
|
---|
177 | if(HIWORD(lpszClassName) != 0) {
|
---|
178 | astring = UnicodeToAsciiString((LPWSTR)lpszClassName);
|
---|
179 | }
|
---|
180 | else astring = (char *)lpszClassName;
|
---|
181 |
|
---|
182 | ret = Win32WndClass::UnregisterClassA(hinst, (LPSTR)astring);
|
---|
183 | if(HIWORD(astring) != 0)
|
---|
184 | FreeAsciiString((char *)astring);
|
---|
185 |
|
---|
186 | #if 1
|
---|
187 | return ret;
|
---|
188 | #else
|
---|
189 | //Spintest returns FALSE in dll termination, so pretend it succeeded
|
---|
190 | // return(TRUE);
|
---|
191 | #endif
|
---|
192 | }
|
---|
193 | //******************************************************************************
|
---|
194 | //******************************************************************************
|
---|
195 | BOOL WIN32API GetClassInfoA(HINSTANCE hInstance, LPCSTR lpszClass, WNDCLASSA *lpwc)
|
---|
196 | {
|
---|
197 | WNDCLASSEXA wc;
|
---|
198 | BOOL rc;
|
---|
199 | Win32WndClass *wndclass;
|
---|
200 |
|
---|
201 | if(HIWORD(lpszClass) != 0) {
|
---|
202 | dprintf(("USER32: GetClassInfoA %x %s %x", hInstance, lpszClass, lpwc));
|
---|
203 | }
|
---|
204 | else dprintf(("USER32: GetClassInfoA %x %x %x", hInstance, lpszClass, lpwc));
|
---|
205 |
|
---|
206 | wndclass = Win32WndClass::FindClass(hInstance, (LPSTR)lpszClass);
|
---|
207 | if(wndclass) {
|
---|
208 | wndclass->getClassInfo(&wc);
|
---|
209 | memcpy(lpwc, &wc.style, sizeof(WNDCLASSA));
|
---|
210 | SetLastError(ERROR_SUCCESS);
|
---|
211 | return(TRUE);
|
---|
212 | }
|
---|
213 | SetLastError(ERROR_CLASS_DOES_NOT_EXIST);
|
---|
214 | return(FALSE);
|
---|
215 | }
|
---|
216 | //******************************************************************************
|
---|
217 | //******************************************************************************
|
---|
218 | BOOL WIN32API GetClassInfoW(HINSTANCE hinst, LPCWSTR lpszClass, WNDCLASSW *lpwc)
|
---|
219 | {
|
---|
220 | WNDCLASSEXW wc;
|
---|
221 | BOOL rc;
|
---|
222 | Win32WndClass *wndclass;
|
---|
223 | char *astring = NULL;
|
---|
224 |
|
---|
225 | dprintf(("USER32: GetClassInfoW\n"));
|
---|
226 |
|
---|
227 | if(HIWORD(lpszClass) != 0) {
|
---|
228 | astring = UnicodeToAsciiString((LPWSTR)lpszClass);
|
---|
229 | }
|
---|
230 | else astring = (char *)lpszClass;
|
---|
231 |
|
---|
232 | wndclass = Win32WndClass::FindClass(hinst, astring);
|
---|
233 | if(HIWORD(astring) != 0)
|
---|
234 | FreeAsciiString((char *)astring);
|
---|
235 |
|
---|
236 | if(wndclass) {
|
---|
237 | wndclass->getClassInfo(&wc);
|
---|
238 | memcpy(lpwc, &wc.style, sizeof(WNDCLASSW));
|
---|
239 | SetLastError(ERROR_SUCCESS);
|
---|
240 | return(TRUE);
|
---|
241 | }
|
---|
242 | SetLastError(ERROR_CLASS_DOES_NOT_EXIST);
|
---|
243 | return(FALSE);
|
---|
244 | }
|
---|
245 | /****************************************************************************
|
---|
246 | * Name : BOOL WIN32API GetClassInfoExA
|
---|
247 | * Purpose : The GetClassInfoEx function retrieves information about a window
|
---|
248 | * class, including the handle of the small icon associated with the
|
---|
249 | * window class. GetClassInfo does not retrieve the handle of the small icon.
|
---|
250 | * Parameters: HINSTANCE hinst handle of application instance
|
---|
251 | * LPCTSTR lpszClass address of class name string
|
---|
252 | * LPWNDCLASSEX lpwcx address of structure for class data
|
---|
253 | * Variables :
|
---|
254 | * Result : If the function finds a matching class and successfully copies
|
---|
255 | * the data, the return value is TRUE;
|
---|
256 | * otherwise, it is FALSE.
|
---|
257 | * To get extended error information, call GetLastError.
|
---|
258 | * Remark : PH: does not obtain handle of the small icon
|
---|
259 | *****************************************************************************/
|
---|
260 | BOOL WIN32API GetClassInfoExA(HINSTANCE hInstance,
|
---|
261 | LPCTSTR lpszClass,
|
---|
262 | LPWNDCLASSEXA lpwcx)
|
---|
263 | {
|
---|
264 | BOOL rc;
|
---|
265 | Win32WndClass *wndclass;
|
---|
266 |
|
---|
267 | if(HIWORD(lpszClass)) {
|
---|
268 | dprintf(("USER32:GetClassInfoExA (%08xh,%s,%08x)",
|
---|
269 | hInstance, lpszClass, lpwcx));
|
---|
270 | }
|
---|
271 | else dprintf(("USER32:GetClassInfoExA (%08xh,%x,%08x)",
|
---|
272 | hInstance, lpszClass, lpwcx));
|
---|
273 |
|
---|
274 | wndclass = Win32WndClass::FindClass(hInstance, (LPSTR)lpszClass);
|
---|
275 | if(wndclass) {
|
---|
276 | wndclass->getClassInfo(lpwcx);
|
---|
277 | lpwcx->cbSize = sizeof(WNDCLASSEXA);
|
---|
278 | SetLastError(ERROR_SUCCESS);
|
---|
279 | return(TRUE);
|
---|
280 | }
|
---|
281 | SetLastError(ERROR_CLASS_DOES_NOT_EXIST);
|
---|
282 | return(FALSE);
|
---|
283 | }
|
---|
284 | /*****************************************************************************
|
---|
285 | * Name : BOOL WIN32API GetClassInfoExW
|
---|
286 | * Purpose : The GetClassInfoEx function retrieves information about a window
|
---|
287 | * class, including the handle of the small icon associated with the
|
---|
288 | * window class. GetClassInfo does not retrieve the handle of the small icon.
|
---|
289 | * Parameters: HINSTANCE hinst handle of application instance
|
---|
290 | * LPCWSTR lpszClass address of class name string
|
---|
291 | * LPWNDCLASSEX lpwcx address of structure for class data
|
---|
292 | * Variables :
|
---|
293 | * Result : If the function finds a matching class and successfully copies
|
---|
294 | * the data, the return value is TRUE;
|
---|
295 | * otherwise, it is FALSE.
|
---|
296 | * To get extended error information, call GetLastError.
|
---|
297 | * Remark : does not obtain handle of the small icon
|
---|
298 | *
|
---|
299 | *****************************************************************************/
|
---|
300 | BOOL WIN32API GetClassInfoExW(HINSTANCE hInstance,
|
---|
301 | LPCWSTR lpszClass,
|
---|
302 | LPWNDCLASSEXW lpwcx)
|
---|
303 | {
|
---|
304 | BOOL rc;
|
---|
305 | Win32WndClass *wndclass;
|
---|
306 | char *astring = NULL;
|
---|
307 |
|
---|
308 | dprintf(("USER32: GetClassInfoExW\n"));
|
---|
309 |
|
---|
310 | if(HIWORD(lpszClass) != 0) {
|
---|
311 | astring = UnicodeToAsciiString((LPWSTR)lpszClass);
|
---|
312 | }
|
---|
313 | else astring = (char *)lpszClass;
|
---|
314 |
|
---|
315 | wndclass = Win32WndClass::FindClass(hInstance, astring);
|
---|
316 | if(HIWORD(astring) != 0)
|
---|
317 | FreeAsciiString((char *)astring);
|
---|
318 |
|
---|
319 | if(wndclass) {
|
---|
320 | wndclass->getClassInfo(lpwcx);
|
---|
321 | lpwcx->cbSize = sizeof(WNDCLASSEXW);
|
---|
322 | SetLastError(ERROR_SUCCESS);
|
---|
323 | return(TRUE);
|
---|
324 | }
|
---|
325 | SetLastError(ERROR_CLASS_DOES_NOT_EXIST);
|
---|
326 | return(FALSE);
|
---|
327 | }
|
---|
328 | //******************************************************************************
|
---|
329 | //******************************************************************************
|
---|
330 | int WIN32API GetClassNameA(HWND hwnd, LPSTR lpszClassName, int cchClassName)
|
---|
331 | {
|
---|
332 | Win32BaseWindow *wnd;
|
---|
333 | int rc;
|
---|
334 |
|
---|
335 | wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
336 | if(!wnd) {
|
---|
337 | dprintf(("GetClassNameA wnd == NULL"));
|
---|
338 | return(0);
|
---|
339 | }
|
---|
340 | *lpszClassName = 0;
|
---|
341 | rc = (wnd->getClass())->getClassName(lpszClassName, cchClassName);
|
---|
342 | dprintf(("USER32: GetClassNameA %x %s (%d)", hwnd, lpszClassName, rc));
|
---|
343 | return rc;
|
---|
344 | }
|
---|
345 | //******************************************************************************
|
---|
346 | //******************************************************************************
|
---|
347 | int WIN32API GetClassNameW(HWND hwnd, LPWSTR lpszClassName, int cchClassName)
|
---|
348 | {
|
---|
349 | Win32BaseWindow *wnd;
|
---|
350 |
|
---|
351 | dprintf(("USER32: GetClassNameW\n"));
|
---|
352 | wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
353 | if(!wnd) {
|
---|
354 | dprintf(("GetClassNameA wnd == NULL"));
|
---|
355 | return(0);
|
---|
356 | }
|
---|
357 | return (wnd->getClass())->getClassName(lpszClassName, cchClassName);
|
---|
358 | }
|
---|
359 | //******************************************************************************
|
---|
360 | //******************************************************************************
|
---|
361 | LONG WIN32API SetClassLongA(HWND hwnd, int nIndex, LONG lNewVal)
|
---|
362 | {
|
---|
363 | Win32BaseWindow *wnd;
|
---|
364 |
|
---|
365 | wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
366 | if(!wnd) {
|
---|
367 | dprintf(("SetClassLongA %x %d %x wnd == NULL", hwnd, nIndex, lNewVal));
|
---|
368 | return(0);
|
---|
369 | }
|
---|
370 | return (wnd->getClass())->setClassLongA(nIndex, lNewVal);
|
---|
371 | }
|
---|
372 | //******************************************************************************
|
---|
373 | //******************************************************************************
|
---|
374 | LONG WIN32API SetClassLongW(HWND hwnd, int nIndex, LONG lNewVal)
|
---|
375 | {
|
---|
376 | Win32BaseWindow *wnd;
|
---|
377 |
|
---|
378 | wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
379 | if(!wnd) {
|
---|
380 | dprintf(("SetClassLongW %x %d %x wnd == NULL", hwnd, nIndex, lNewVal));
|
---|
381 | return(0);
|
---|
382 | }
|
---|
383 | return (wnd->getClass())->setClassLongW(nIndex, lNewVal);
|
---|
384 | }
|
---|
385 | //******************************************************************************
|
---|
386 | //******************************************************************************
|
---|
387 | WORD WIN32API SetClassWord(HWND hwnd, int nIndex, WORD wNewVal)
|
---|
388 | {
|
---|
389 | Win32BaseWindow *wnd;
|
---|
390 |
|
---|
391 | dprintf(("USER32: SetClassWord %x %d %x", hwnd, nIndex, (ULONG)wNewVal));
|
---|
392 | wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
393 | if(!wnd) {
|
---|
394 | dprintf(("SetClassWordA %x %d %x wnd == NULL", hwnd, nIndex, wNewVal));
|
---|
395 | return(0);
|
---|
396 | }
|
---|
397 | return (wnd->getClass())->setClassWord(nIndex, wNewVal);
|
---|
398 | }
|
---|
399 | //******************************************************************************
|
---|
400 | //******************************************************************************
|
---|
401 | WORD WIN32API GetClassWord(HWND hwnd, int nIndex)
|
---|
402 | {
|
---|
403 | Win32BaseWindow *wnd;
|
---|
404 | WORD ret;
|
---|
405 |
|
---|
406 | wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
407 | if(!wnd) {
|
---|
408 | dprintf(("GetClassWordA %x %d wnd == NULL", hwnd, nIndex));
|
---|
409 | return(0);
|
---|
410 | }
|
---|
411 | ret = (wnd->getClass())->getClassWord(nIndex);
|
---|
412 | dprintf(("USER32: GetClassWord %x %d returned %x", hwnd, nIndex, (ULONG)ret));
|
---|
413 | return ret;
|
---|
414 | }
|
---|
415 | //******************************************************************************
|
---|
416 | //******************************************************************************
|
---|
417 | LONG WIN32API GetClassLongA(HWND hwnd, int nIndex)
|
---|
418 | {
|
---|
419 | Win32BaseWindow *wnd;
|
---|
420 | LONG ret;
|
---|
421 |
|
---|
422 | wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
423 | if(!wnd) {
|
---|
424 | dprintf(("GetClassLongA %x %d wnd == NULL", hwnd, nIndex));
|
---|
425 | return(0);
|
---|
426 | }
|
---|
427 | ret = (wnd->getClass())->getClassLongA(nIndex);
|
---|
428 | dprintf(("USER32: GetClassLongA %x %d returned %x", hwnd, nIndex, ret));
|
---|
429 | return ret;
|
---|
430 | }
|
---|
431 | //******************************************************************************
|
---|
432 | //******************************************************************************
|
---|
433 | LONG WIN32API GetClassLongW(HWND hwnd, int nIndex)
|
---|
434 | {
|
---|
435 | Win32BaseWindow *wnd;
|
---|
436 | LONG ret;
|
---|
437 |
|
---|
438 | wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
439 | if(!wnd) {
|
---|
440 | dprintf(("GetClassLongW %x %d wnd == NULL", hwnd, nIndex));
|
---|
441 | return(0);
|
---|
442 | }
|
---|
443 | ret = (wnd->getClass())->getClassLongW(nIndex);
|
---|
444 | dprintf(("USER32: GetClassLongW %x %d returned %x", hwnd, nIndex, ret));
|
---|
445 | return ret;
|
---|
446 | }
|
---|
447 | //******************************************************************************
|
---|
448 | //******************************************************************************
|
---|