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

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

create dialog controls with CreateWindowExW; use correct SendMessage during CreateWindow

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