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

Last change on this file since 3702 was 3702, checked in by sandervl, 25 years ago

when registering a class, check if it already exists and return error

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