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

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

syscolor change + iconsm creation in RegisterClassA/W

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