source: trunk/src/user32/windowclass.cpp@ 5472

Last change on this file since 5472 was 5472, checked in by sandervl, 24 years ago

compile fix

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