blob: ddc7cb6edd58e277952db69039c62563540c944b [file] [log] [blame]
Alexandre Julliard401710d1993-09-04 10:09:32 +00001/*
2 * Window classes functions
3 *
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00004 * Copyright 1993, 1996 Alexandre Julliard
Alexandre Julliard767e6f61998-08-09 12:47:43 +00005 * 1998 Juergen Schmied (jsch)
Alexandre Julliard21979011997-03-05 08:22:35 +00006 *
7 * FIXME: In win32 all classes are local. They are registered at
8 * program start. Processes CANNOT share classes. (Source: some
9 * win31->NT migration book)
Alexandre Julliard767e6f61998-08-09 12:47:43 +000010 *
11 * FIXME: There seems to be a general problem with hInstance in WINE
Andreas Mohr1af53cb2000-12-09 03:15:32 +000012 * classes are getting registered with wrong hInstance.
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +000013 */
Alexandre Julliard401710d1993-09-04 10:09:32 +000014
François Gouget14259412001-11-06 20:57:11 +000015#include "config.h"
Francois Gouget386cf6e2001-10-14 16:25:47 +000016#include "wine/port.h"
17
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000018#include <stdlib.h>
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000019#include <string.h>
Francois Gouget386cf6e2001-10-14 16:25:47 +000020
Marcus Meissner317af321999-02-17 13:51:06 +000021#include "wine/winbase16.h"
Alexandre Julliardc7e7df82000-08-14 14:41:19 +000022#include "winerror.h"
23#include "windef.h"
24#include "wingdi.h"
25#include "wine/winuser16.h"
26#include "wine/unicode.h"
Alexandre Julliard1285c2f1996-05-06 16:06:24 +000027#include "heap.h"
Alexandre Julliard401710d1993-09-04 10:09:32 +000028#include "win.h"
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000029#include "user.h"
Alexandre Julliard91222da2000-12-10 23:01:33 +000030#include "controls.h"
Alexandre Julliard5f721f81994-01-04 20:14:34 +000031#include "dce.h"
Alexandre Julliard2d93d001996-05-21 15:01:41 +000032#include "winproc.h"
Alexandre Julliard359f497e1999-07-04 16:02:24 +000033#include "debugtools.h"
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000034
Alexandre Julliardc7e7df82000-08-14 14:41:19 +000035DEFAULT_DEBUG_CHANNEL(class);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000036
Alexandre Julliard98779062000-12-07 23:39:16 +000037typedef struct tagCLASS
38{
39 struct tagCLASS *next; /* Next class */
40 struct tagCLASS *prev; /* Prev class */
41 UINT cWindows; /* Count of existing windows */
42 UINT style; /* Class style */
43 HWINDOWPROC winprocA; /* Window procedure (ASCII) */
44 HWINDOWPROC winprocW; /* Window procedure (Unicode) */
45 INT cbClsExtra; /* Class extra bytes */
46 INT cbWndExtra; /* Window extra bytes */
47 LPWSTR menuName; /* Default menu name (Unicode followed by ASCII) */
48 struct tagDCE *dce; /* Class DCE (if CS_CLASSDC) */
49 HINSTANCE hInstance; /* Module that created the task */
50 HICON hIcon; /* Default icon */
51 HICON hIconSm; /* Default small icon */
52 HCURSOR hCursor; /* Default cursor */
53 HBRUSH hbrBackground; /* Default background */
54 ATOM atomName; /* Name of the class */
Alexandre Julliard98779062000-12-07 23:39:16 +000055} CLASS;
Alexandre Julliard401710d1993-09-04 10:09:32 +000056
Alexandre Julliard98779062000-12-07 23:39:16 +000057static CLASS *firstClass;
Alexandre Julliard401710d1993-09-04 10:09:32 +000058
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000059/***********************************************************************
60 * get_class_ptr
61 */
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000062static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000063{
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000064 WND *ptr = WIN_GetPtr( hwnd );
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000065
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000066 if (ptr)
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000067 {
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000068 if (ptr != WND_OTHER_PROCESS) return ptr->class;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000069 if (IsWindow( hwnd )) /* check other processes */
70 {
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000071 if (write_access)
72 {
73 /* modifying classes in other processes is not allowed */
74 SetLastError( ERROR_ACCESS_DENIED );
75 return NULL;
76 }
77 FIXME( "reading from class of other process window %04x\n", hwnd );
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000078 /* DbgBreakPoint(); */
79 }
80 }
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000081 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
82 return NULL;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000083}
84
85
86/***********************************************************************
87 * release_class_ptr
88 */
89inline static void release_class_ptr( CLASS *ptr )
90{
91 USER_Unlock();
92}
93
Alexandre Julliard401710d1993-09-04 10:09:32 +000094
95/***********************************************************************
Alexandre Julliard98779062000-12-07 23:39:16 +000096 * CLASS_GetProc
Alexandre Julliardb817f4f1996-03-14 18:08:34 +000097 *
Alexandre Julliard98779062000-12-07 23:39:16 +000098 * Get the class winproc for a given proc type
Alexandre Julliardb817f4f1996-03-14 18:08:34 +000099 */
Alexandre Julliard98779062000-12-07 23:39:16 +0000100static WNDPROC16 CLASS_GetProc( CLASS *classPtr, WINDOWPROCTYPE type )
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000101{
Alexandre Julliard98779062000-12-07 23:39:16 +0000102 HWINDOWPROC proc = classPtr->winprocA;
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000103
Alexandre Julliard98779062000-12-07 23:39:16 +0000104 if (classPtr->winprocW)
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000105 {
Alexandre Julliard98779062000-12-07 23:39:16 +0000106 /* if we have a Unicode proc, use it if we have no ASCII proc
107 * or if we have both and Unicode was requested
108 */
109 if (!proc || type == WIN_PROC_32W) proc = classPtr->winprocW;
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000110 }
Alexandre Julliard98779062000-12-07 23:39:16 +0000111 return WINPROC_GetProc( proc, type );
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000112}
113
114
115/***********************************************************************
Alexandre Julliard98779062000-12-07 23:39:16 +0000116 * CLASS_SetProc
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000117 *
Alexandre Julliard98779062000-12-07 23:39:16 +0000118 * Set the class winproc for a given proc type.
119 * Returns the previous window proc.
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000120 */
Alexandre Julliard98779062000-12-07 23:39:16 +0000121static WNDPROC16 CLASS_SetProc( CLASS *classPtr, WNDPROC newproc, WINDOWPROCTYPE type )
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000122{
Alexandre Julliard98779062000-12-07 23:39:16 +0000123 HWINDOWPROC *proc = &classPtr->winprocA;
124 WNDPROC16 ret;
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000125
Alexandre Julliard98779062000-12-07 23:39:16 +0000126 if (classPtr->winprocW)
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000127 {
Alexandre Julliard98779062000-12-07 23:39:16 +0000128 /* if we have a Unicode proc, use it if we have no ASCII proc
129 * or if we have both and Unicode was requested
130 */
131 if (!*proc || type == WIN_PROC_32W) proc = &classPtr->winprocW;
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000132 }
Alexandre Julliard98779062000-12-07 23:39:16 +0000133 ret = WINPROC_GetProc( *proc, type );
134 WINPROC_SetProc( proc, (HWINDOWPROC)newproc, type, WIN_PROC_CLASS );
135 /* now free the one that we didn't set */
136 if (classPtr->winprocA && classPtr->winprocW)
137 {
138 if (proc == &classPtr->winprocA)
139 {
140 WINPROC_FreeProc( classPtr->winprocW, WIN_PROC_CLASS );
141 classPtr->winprocW = 0;
142 }
143 else
144 {
145 WINPROC_FreeProc( classPtr->winprocA, WIN_PROC_CLASS );
146 classPtr->winprocA = 0;
147 }
148 }
149 return ret;
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000150}
151
152
153/***********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000154 * CLASS_GetMenuNameA
155 *
156 * Get the menu name as a ASCII string.
157 */
Alexandre Julliard98779062000-12-07 23:39:16 +0000158inline static LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000159{
Alexandre Julliard98779062000-12-07 23:39:16 +0000160 if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
161 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000162}
163
164
165/***********************************************************************
166 * CLASS_GetMenuNameW
167 *
168 * Get the menu name as a Unicode string.
169 */
Alexandre Julliard98779062000-12-07 23:39:16 +0000170inline static LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000171{
Alexandre Julliard98779062000-12-07 23:39:16 +0000172 return classPtr->menuName;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000173}
174
175
176/***********************************************************************
177 * CLASS_SetMenuNameA
178 *
179 * Set the menu name in a class structure by copying the string.
180 */
181static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
182{
Alexandre Julliard98779062000-12-07 23:39:16 +0000183 if (HIWORD(classPtr->menuName)) SEGPTR_FREE( classPtr->menuName );
184 if (HIWORD(name))
185 {
186 DWORD lenA = strlen(name) + 1;
187 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
188 classPtr->menuName = SEGPTR_ALLOC( lenA + lenW*sizeof(WCHAR) );
189 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
190 memcpy( classPtr->menuName + lenW, name, lenA );
191 }
192 else classPtr->menuName = (LPWSTR)name;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000193}
194
195
196/***********************************************************************
197 * CLASS_SetMenuNameW
198 *
199 * Set the menu name in a class structure by copying the string.
200 */
201static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
202{
Alexandre Julliard98779062000-12-07 23:39:16 +0000203 if (HIWORD(classPtr->menuName)) SEGPTR_FREE( classPtr->menuName );
204 if (HIWORD(name))
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000205 {
Alexandre Julliard98779062000-12-07 23:39:16 +0000206 DWORD lenW = strlenW(name) + 1;
207 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
208 classPtr->menuName = SEGPTR_ALLOC( lenA + lenW*sizeof(WCHAR) );
209 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
210 WideCharToMultiByte( CP_ACP, 0, name, lenW,
211 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000212 }
Alexandre Julliard98779062000-12-07 23:39:16 +0000213 else classPtr->menuName = (LPWSTR)name;
Gavriel Statec77c5921998-11-15 09:21:17 +0000214}
215
216
217/***********************************************************************
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000218 * CLASS_FreeClass
219 *
220 * Free a class structure.
221 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000222static BOOL CLASS_FreeClass( CLASS *classPtr )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000223{
Alexandre Julliard98779062000-12-07 23:39:16 +0000224 TRACE("%p\n", classPtr);
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000225
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000226 /* Check if we can remove this class */
227
Alexandre Julliard98779062000-12-07 23:39:16 +0000228 if (classPtr->cWindows > 0)
229 {
230 SetLastError( ERROR_CLASS_HAS_WINDOWS );
231 return FALSE;
232 }
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000233
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000234 /* Remove the class from the linked list */
235
Alexandre Julliard98779062000-12-07 23:39:16 +0000236 if (classPtr->next) classPtr->next->prev = classPtr->prev;
237 if (classPtr->prev) classPtr->prev->next = classPtr->next;
238 else firstClass = classPtr->next;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000239
240 /* Delete the class */
241
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000242 if (classPtr->dce) DCE_FreeDCE( classPtr->dce );
Huw D M Davies2f245af2000-09-12 23:38:33 +0000243 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
244 DeleteObject( classPtr->hbrBackground );
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000245 GlobalDeleteAtom( classPtr->atomName );
Alexandre Julliard98779062000-12-07 23:39:16 +0000246 WINPROC_FreeProc( classPtr->winprocA, WIN_PROC_CLASS );
247 WINPROC_FreeProc( classPtr->winprocW, WIN_PROC_CLASS );
248 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
249 HeapFree( GetProcessHeap(), 0, classPtr );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000250 return TRUE;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000251}
252
253
254/***********************************************************************
255 * CLASS_FreeModuleClasses
256 */
Alexandre Julliard3051b641996-07-05 17:14:13 +0000257void CLASS_FreeModuleClasses( HMODULE16 hModule )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000258{
259 CLASS *ptr, *next;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000260
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000261 TRACE("0x%08x\n", hModule);
262
263 USER_Lock();
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000264 for (ptr = firstClass; ptr; ptr = next)
265 {
266 next = ptr->next;
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000267 if (ptr->hInstance == hModule) CLASS_FreeClass( ptr );
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000268 }
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000269 USER_Unlock();
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000270}
271
272
273/***********************************************************************
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000274 * CLASS_FindClassByAtom
275 *
276 * Return a pointer to the class.
Alexandre Julliard77b99181997-09-14 17:17:23 +0000277 * hinstance has been normalized by the caller.
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000278 *
279 * NOTES
280 * 980805 a local class will be found now if registred with hInst=0
281 * and looed up with a hInst!=0. msmoney does it (jsch)
Joshua Thielend9ed57a2001-11-16 18:11:43 +0000282 *
283 * Local class registered with a USER instance handle are found as if
284 * they were global classes.
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000285 */
Alexandre Julliard98779062000-12-07 23:39:16 +0000286static CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE hinstance )
287{
Joshua Thielend9ed57a2001-11-16 18:11:43 +0000288 CLASS * class, *tclass = 0, *user_class = 0;
289 HINSTANCE16 hUser = GetModuleHandle16("USER");
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000290
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000291 TRACE("0x%08x 0x%08x\n", atom, hinstance);
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000292
Alexandre Julliard77b99181997-09-14 17:17:23 +0000293 /* First search task-specific classes */
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000294
295 for (class = firstClass; (class); class = class->next)
296 {
297 if (class->style & CS_GLOBALCLASS) continue;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000298 if (class->atomName == atom)
299 {
Joshua Thielend9ed57a2001-11-16 18:11:43 +0000300 if (hinstance==class->hInstance || hinstance==0xffff)
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000301 {
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000302 TRACE("-- found local %p\n", class);
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000303 return class;
304 }
Joshua Thielend9ed57a2001-11-16 18:11:43 +0000305 if (class->hInstance == 0) tclass = class;
306 else if(class->hInstance == hUser)
307 {
308 user_class = class;
309 }
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000310 }
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000311 }
312
Joshua Thielend9ed57a2001-11-16 18:11:43 +0000313 /* Then search global classes */
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000314
315 for (class = firstClass; (class); class = class->next)
316 {
317 if (!(class->style & CS_GLOBALCLASS)) continue;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000318 if (class->atomName == atom)
319 {
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000320 TRACE("-- found global %p\n", class);
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000321 return class;
322 }
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000323 }
324
Joshua Thielend9ed57a2001-11-16 18:11:43 +0000325 /* Check if there was a local class registered with USER */
326 if( user_class )
327 {
328 TRACE("--found local USER class %p\n", user_class);
329 return user_class;
330 }
331
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000332 /* Then check if there was a local class with hInst=0*/
333 if ( tclass )
334 {
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000335 WARN("-- found local Class registred with hInst=0\n");
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000336 return tclass;
337 }
338
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000339 TRACE("-- not found\n");
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000340 return 0;
341}
342
343
344/***********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000345 * CLASS_RegisterClass
346 *
347 * The real RegisterClass() functionality.
348 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000349static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE hInstance,
Alexandre Julliard98779062000-12-07 23:39:16 +0000350 DWORD style, INT classExtra, INT winExtra )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000351{
352 CLASS *classPtr;
353
Alexandre Julliard98779062000-12-07 23:39:16 +0000354 TRACE("atom=0x%x hinst=0x%x style=0x%lx clExtr=0x%x winExtr=0x%x\n",
355 atom, hInstance, style, classExtra, winExtra );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000356
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000357 /* Check if a class with this name already exists */
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000358 classPtr = CLASS_FindClassByAtom( atom, hInstance );
359 if (classPtr)
360 {
361 /* Class can be created only if it is local and */
362 /* if the class with the same name is global. */
363
Alexandre Julliard98779062000-12-07 23:39:16 +0000364 if ((style & CS_GLOBALCLASS) || !(classPtr->style & CS_GLOBALCLASS))
365 {
366 SetLastError( ERROR_CLASS_ALREADY_EXISTS );
367 return NULL;
368 }
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000369 }
370
371 /* Fix the extra bytes value */
372
373 if (classExtra < 0) classExtra = 0;
374 else if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000375 WARN("Class extra bytes %d is > 40\n", classExtra);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000376 if (winExtra < 0) winExtra = 0;
377 else if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000378 WARN("Win extra bytes %d is > 40\n", winExtra );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000379
380 /* Create the class */
381
Alexandre Julliardd44e4952001-08-20 18:09:39 +0000382 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000383 if (!classPtr) return NULL;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000384 classPtr->style = style;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000385 classPtr->cbWndExtra = winExtra;
386 classPtr->cbClsExtra = classExtra;
387 classPtr->hInstance = hInstance;
388 classPtr->atomName = atom;
Alexandre Julliard98779062000-12-07 23:39:16 +0000389 classPtr->dce = (style & CS_CLASSDC) ? DCE_AllocDCE( 0, DCE_CLASS_DC ) : NULL;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000390
Alexandre Julliard98779062000-12-07 23:39:16 +0000391 /* Other non-null values must be set by caller */
Alexandre Julliard3051b641996-07-05 17:14:13 +0000392
Alexandre Julliard98779062000-12-07 23:39:16 +0000393 if ((classPtr->next = firstClass)) firstClass->prev = classPtr;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000394 firstClass = classPtr;
395 return classPtr;
396}
397
398
399/***********************************************************************
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000400 * CLASS_UnregisterClass
401 *
402 * The real UnregisterClass() functionality.
403 */
404static BOOL CLASS_UnregisterClass( ATOM atom, HINSTANCE hInstance )
405{
406 CLASS *classPtr;
407 BOOL ret = FALSE;
408
409 USER_Lock();
410 if (atom &&
411 (classPtr = CLASS_FindClassByAtom( atom, hInstance )) &&
Bill Medland0ca07c92001-11-20 18:53:16 +0000412 (!hInstance || classPtr->hInstance == hInstance))
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000413 {
414 ret = CLASS_FreeClass( classPtr );
415 }
416 else SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
417
418 USER_Unlock();
419 return ret;
420}
421
422
423/***********************************************************************
Alexandre Julliard98779062000-12-07 23:39:16 +0000424 * CLASS_RegisterBuiltinClass
425 *
426 * Register a builtin control class.
427 * This allows having both ASCII and Unicode winprocs for the same class.
428 */
Alexandre Julliard91222da2000-12-10 23:01:33 +0000429ATOM CLASS_RegisterBuiltinClass( const struct builtin_class_descr *descr )
Alexandre Julliard98779062000-12-07 23:39:16 +0000430{
431 ATOM atom;
432 CLASS *classPtr;
433
Alexandre Julliard91222da2000-12-10 23:01:33 +0000434 if (!(atom = GlobalAddAtomA( descr->name ))) return 0;
Alexandre Julliard98779062000-12-07 23:39:16 +0000435
Alexandre Julliard91222da2000-12-10 23:01:33 +0000436 if (!(classPtr = CLASS_RegisterClass( atom, 0, descr->style, 0, descr->extra )))
Alexandre Julliard98779062000-12-07 23:39:16 +0000437 {
438 GlobalDeleteAtom( atom );
439 return 0;
440 }
441
Alexandre Julliard91222da2000-12-10 23:01:33 +0000442 classPtr->hCursor = LoadCursorA( 0, descr->cursor );
443 classPtr->hbrBackground = descr->brush;
Alexandre Julliard98779062000-12-07 23:39:16 +0000444
Alexandre Julliard91222da2000-12-10 23:01:33 +0000445 if (descr->procA) WINPROC_SetProc( &classPtr->winprocA, (HWINDOWPROC)descr->procA,
446 WIN_PROC_32A, WIN_PROC_CLASS );
447 if (descr->procW) WINPROC_SetProc( &classPtr->winprocW, (HWINDOWPROC)descr->procW,
448 WIN_PROC_32W, WIN_PROC_CLASS );
Alexandre Julliard98779062000-12-07 23:39:16 +0000449 return atom;
450}
451
452
453/***********************************************************************
454 * CLASS_AddWindow
455 *
456 * Add a new window using this class, and return the necessary
457 * information for creating the window.
458 */
459CLASS *CLASS_AddWindow( ATOM atom, HINSTANCE inst, WINDOWPROCTYPE type,
460 INT *winExtra, WNDPROC *winproc, DWORD *style, struct tagDCE **dce )
461{
462 CLASS *class;
463 if (type == WIN_PROC_16) inst = GetExePtr(inst);
464
465 if (!(class = CLASS_FindClassByAtom( atom, inst ))) return NULL;
466 class->cWindows++;
467
468 if (type == WIN_PROC_32W)
469 {
470 if (!(*winproc = class->winprocW)) *winproc = class->winprocA;
471 }
472 else
473 {
474 if (!(*winproc = class->winprocA)) *winproc = class->winprocW;
475 }
476 *winExtra = class->cbWndExtra;
477 *style = class->style;
478 *dce = class->dce;
479 return class;
480}
481
482
483/***********************************************************************
484 * CLASS_RemoveWindow
485 *
486 * Remove a window from the class window count.
487 */
488void CLASS_RemoveWindow( CLASS *cls )
489{
490 if (cls && cls->cWindows) cls->cWindows--;
491}
492
493
494/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000495 * RegisterClass (USER.57)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000496 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000497ATOM WINAPI RegisterClass16( const WNDCLASS16 *wc )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000498{
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000499 ATOM atom;
500 CLASS *classPtr;
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000501 int iSmIconWidth, iSmIconHeight;
Alexandre Julliard77b99181997-09-14 17:17:23 +0000502 HINSTANCE16 hInstance=GetExePtr(wc->hInstance);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000503
Alexandre Julliard982a2232000-12-13 20:20:09 +0000504 if (!(atom = GlobalAddAtomA( MapSL(wc->lpszClassName) ))) return 0;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000505 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
Alexandre Julliard98779062000-12-07 23:39:16 +0000506 wc->cbClsExtra, wc->cbWndExtra )))
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000507 {
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000508 GlobalDeleteAtom( atom );
509 return 0;
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000510 }
511
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000512 TRACE("atom=%04x wndproc=%08lx hinst=%04x "
Patrik Stridvalla9a671d1999-04-25 19:01:52 +0000513 "bg=%04x style=%08x clsExt=%d winExt=%d class=%p name='%s'\n",
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000514 atom, (DWORD)wc->lpfnWndProc, hInstance,
515 wc->hbrBackground, wc->style, wc->cbClsExtra,
Alexandre Julliard641ee761997-08-04 16:34:36 +0000516 wc->cbWndExtra, classPtr,
517 HIWORD(wc->lpszClassName) ?
Alexandre Julliard982a2232000-12-13 20:20:09 +0000518 (char *)MapSL(wc->lpszClassName) : "" );
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000519
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000520 iSmIconWidth = GetSystemMetrics(SM_CXSMICON);
521 iSmIconHeight = GetSystemMetrics(SM_CYSMICON);
522
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000523 classPtr->hIcon = wc->hIcon;
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000524 classPtr->hIconSm = CopyImage(wc->hIcon, IMAGE_ICON,
525 iSmIconWidth, iSmIconHeight,
526 LR_COPYFROMRESOURCE);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000527 classPtr->hCursor = wc->hCursor;
528 classPtr->hbrBackground = wc->hbrBackground;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000529
Alexandre Julliard98779062000-12-07 23:39:16 +0000530 WINPROC_SetProc( &classPtr->winprocA, (HWINDOWPROC)wc->lpfnWndProc,
531 WIN_PROC_16, WIN_PROC_CLASS );
Alexandre Julliard982a2232000-12-13 20:20:09 +0000532 CLASS_SetMenuNameA( classPtr, MapSL(wc->lpszMenuName) );
Gavriel Statec77c5921998-11-15 09:21:17 +0000533
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000534 return atom;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000535}
536
537
538/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000539 * RegisterClassA (USER32.@)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000540 * RETURNS
541 * >0: Unique identifier
542 * 0: Failure
Alexandre Julliard401710d1993-09-04 10:09:32 +0000543 */
Patrik Stridvall2b3aa612000-12-01 23:58:28 +0000544ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
Alexandre Julliardf681cd02000-08-23 19:18:44 +0000545{
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000546 ATOM atom;
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000547 int iSmIconWidth, iSmIconHeight;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000548 CLASS *classPtr;
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000549
Alexandre Julliardf681cd02000-08-23 19:18:44 +0000550 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
551
Alexandre Julliard77b99181997-09-14 17:17:23 +0000552 if (!(classPtr = CLASS_RegisterClass( atom, wc->hInstance, wc->style,
Alexandre Julliard98779062000-12-07 23:39:16 +0000553 wc->cbClsExtra, wc->cbWndExtra )))
554 {
555 GlobalDeleteAtom( atom );
556 return 0;
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000557 }
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000558
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000559 TRACE("atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p name='%s'\n",
Alexandre Julliard77b99181997-09-14 17:17:23 +0000560 atom, (DWORD)wc->lpfnWndProc, wc->hInstance,
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000561 wc->hbrBackground, wc->style, wc->cbClsExtra,
Alexandre Julliard641ee761997-08-04 16:34:36 +0000562 wc->cbWndExtra, classPtr,
563 HIWORD(wc->lpszClassName) ? wc->lpszClassName : "" );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000564
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000565 iSmIconWidth = GetSystemMetrics(SM_CXSMICON);
566 iSmIconHeight = GetSystemMetrics(SM_CYSMICON);
567
568 classPtr->hIcon = wc->hIcon;
569 classPtr->hIconSm = CopyImage(wc->hIcon, IMAGE_ICON,
570 iSmIconWidth, iSmIconHeight,
571 LR_COPYFROMRESOURCE);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000572 classPtr->hCursor = (HCURSOR16)wc->hCursor;
573 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
Alexandre Julliard98779062000-12-07 23:39:16 +0000574
575 WINPROC_SetProc( &classPtr->winprocA, (HWINDOWPROC)wc->lpfnWndProc,
576 WIN_PROC_32A, WIN_PROC_CLASS );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000577 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
578 return atom;
579}
580
581
582/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000583 * RegisterClassW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000584 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000585ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000586{
587 ATOM atom;
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000588 int iSmIconWidth, iSmIconHeight;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000589 CLASS *classPtr;
590
Alexandre Julliardf681cd02000-08-23 19:18:44 +0000591 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
592
Alexandre Julliard77b99181997-09-14 17:17:23 +0000593 if (!(classPtr = CLASS_RegisterClass( atom, wc->hInstance, wc->style,
Alexandre Julliard98779062000-12-07 23:39:16 +0000594 wc->cbClsExtra, wc->cbWndExtra )))
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000595 {
596 GlobalDeleteAtom( atom );
597 return 0;
598 }
599
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000600 TRACE("atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
Alexandre Julliard77b99181997-09-14 17:17:23 +0000601 atom, (DWORD)wc->lpfnWndProc, wc->hInstance,
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000602 wc->hbrBackground, wc->style, wc->cbClsExtra,
603 wc->cbWndExtra, classPtr );
604
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000605 iSmIconWidth = GetSystemMetrics(SM_CXSMICON);
606 iSmIconHeight = GetSystemMetrics(SM_CYSMICON);
607
608 classPtr->hIcon = wc->hIcon;
609 classPtr->hIconSm = CopyImage(wc->hIcon, IMAGE_ICON,
610 iSmIconWidth, iSmIconHeight,
611 LR_COPYFROMRESOURCE);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000612 classPtr->hCursor = (HCURSOR16)wc->hCursor;
613 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
Alexandre Julliard98779062000-12-07 23:39:16 +0000614
615 WINPROC_SetProc( &classPtr->winprocW, (HWINDOWPROC)wc->lpfnWndProc,
616 WIN_PROC_32W, WIN_PROC_CLASS );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000617 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
618 return atom;
619}
620
621
622/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000623 * RegisterClassEx (USER.397)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000624 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000625ATOM WINAPI RegisterClassEx16( const WNDCLASSEX16 *wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000626{
627 ATOM atom;
628 CLASS *classPtr;
Alexandre Julliard77b99181997-09-14 17:17:23 +0000629 HINSTANCE16 hInstance = GetExePtr( wc->hInstance );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000630
Alexandre Julliard982a2232000-12-13 20:20:09 +0000631 if (!(atom = GlobalAddAtomA( MapSL(wc->lpszClassName) ))) return 0;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000632 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
Alexandre Julliard98779062000-12-07 23:39:16 +0000633 wc->cbClsExtra, wc->cbWndExtra )))
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000634 {
635 GlobalDeleteAtom( atom );
636 return 0;
637 }
638
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000639 TRACE("atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000640 atom, (DWORD)wc->lpfnWndProc, hInstance,
641 wc->hbrBackground, wc->style, wc->cbClsExtra,
642 wc->cbWndExtra, classPtr );
643
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000644 classPtr->hIcon = wc->hIcon;
645 classPtr->hIconSm = wc->hIconSm;
646 classPtr->hCursor = wc->hCursor;
647 classPtr->hbrBackground = wc->hbrBackground;
648
Alexandre Julliard98779062000-12-07 23:39:16 +0000649 WINPROC_SetProc( &classPtr->winprocA, (HWINDOWPROC)wc->lpfnWndProc,
650 WIN_PROC_16, WIN_PROC_CLASS );
Alexandre Julliard982a2232000-12-13 20:20:09 +0000651 CLASS_SetMenuNameA( classPtr, MapSL(wc->lpszMenuName) );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000652 return atom;
653}
654
655
656/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000657 * RegisterClassExA (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000658 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000659ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000660{
661 ATOM atom;
662 CLASS *classPtr;
663
Alexandre Julliardf681cd02000-08-23 19:18:44 +0000664 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
665
Alexandre Julliard77b99181997-09-14 17:17:23 +0000666 if (!(classPtr = CLASS_RegisterClass( atom, wc->hInstance, wc->style,
Alexandre Julliard98779062000-12-07 23:39:16 +0000667 wc->cbClsExtra, wc->cbWndExtra )))
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000668 {
669 GlobalDeleteAtom( atom );
Alexandre Julliard98779062000-12-07 23:39:16 +0000670 return 0;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000671 }
672
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000673 TRACE("atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
Alexandre Julliard77b99181997-09-14 17:17:23 +0000674 atom, (DWORD)wc->lpfnWndProc, wc->hInstance,
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000675 wc->hbrBackground, wc->style, wc->cbClsExtra,
676 wc->cbWndExtra, classPtr );
677
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000678 classPtr->hIcon = (HICON16)wc->hIcon;
679 classPtr->hIconSm = (HICON16)wc->hIconSm;
680 classPtr->hCursor = (HCURSOR16)wc->hCursor;
681 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
Alexandre Julliard98779062000-12-07 23:39:16 +0000682 WINPROC_SetProc( &classPtr->winprocA, (HWINDOWPROC)wc->lpfnWndProc,
683 WIN_PROC_32A, WIN_PROC_CLASS );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000684 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
685 return atom;
686}
687
688
689/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000690 * RegisterClassExW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000691 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000692ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000693{
694 ATOM atom;
695 CLASS *classPtr;
696
Alexandre Julliardf681cd02000-08-23 19:18:44 +0000697 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
698
Alexandre Julliard77b99181997-09-14 17:17:23 +0000699 if (!(classPtr = CLASS_RegisterClass( atom, wc->hInstance, wc->style,
Alexandre Julliard98779062000-12-07 23:39:16 +0000700 wc->cbClsExtra, wc->cbWndExtra )))
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000701 {
702 GlobalDeleteAtom( atom );
703 return 0;
704 }
705
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000706 TRACE("atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
Alexandre Julliard77b99181997-09-14 17:17:23 +0000707 atom, (DWORD)wc->lpfnWndProc, wc->hInstance,
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000708 wc->hbrBackground, wc->style, wc->cbClsExtra,
709 wc->cbWndExtra, classPtr );
710
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000711 classPtr->hIcon = (HICON16)wc->hIcon;
712 classPtr->hIconSm = (HICON16)wc->hIconSm;
713 classPtr->hCursor = (HCURSOR16)wc->hCursor;
714 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
Alexandre Julliard98779062000-12-07 23:39:16 +0000715 WINPROC_SetProc( &classPtr->winprocW, (HWINDOWPROC)wc->lpfnWndProc,
716 WIN_PROC_32W, WIN_PROC_CLASS );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000717 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
718 return atom;
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000719}
720
721
722/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000723 * UnregisterClass (USER.403)
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000724 */
Alexandre Julliardb849d792000-02-13 13:56:13 +0000725BOOL16 WINAPI UnregisterClass16( LPCSTR className, HINSTANCE16 hInstance )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000726{
Alexandre Julliardb849d792000-02-13 13:56:13 +0000727 return UnregisterClassA( className, GetExePtr( hInstance ) );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000728}
729
Alexandre Julliard401710d1993-09-04 10:09:32 +0000730/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000731 * UnregisterClassA (USER32.@)
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000732 *
Alexandre Julliard401710d1993-09-04 10:09:32 +0000733 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000734BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
Alexandre Julliard98779062000-12-07 23:39:16 +0000735{
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000736 TRACE("%s %x\n",debugres_a(className), hInstance);
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000737 return CLASS_UnregisterClass( GlobalFindAtomA( className ), hInstance );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000738}
739
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000740/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000741 * UnregisterClassW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000742 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000743BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
Alexandre Julliard98779062000-12-07 23:39:16 +0000744{
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000745 TRACE("%s %x\n",debugres_w(className), hInstance);
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000746 return CLASS_UnregisterClass( GlobalFindAtomW( className ), hInstance );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000747}
748
Alexandre Julliard21979011997-03-05 08:22:35 +0000749
750/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000751 * GetClassWord (USER32.@)
Alexandre Julliard21979011997-03-05 08:22:35 +0000752 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000753WORD WINAPI GetClassWord( HWND hwnd, INT offset )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000754{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000755 CLASS *class;
Guy Albertelli2fa281f1999-04-24 11:54:40 +0000756 WORD retvalue = 0;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000757
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000758 if (offset < 0) return GetClassLongA( hwnd, offset );
759
760 TRACE("%x %x\n",hwnd, offset);
761
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000762 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000763
764 if (offset <= class->cbClsExtra - sizeof(WORD))
765 retvalue = GET_WORD((char *)(class + 1) + offset);
766 else
767 SetLastError( ERROR_INVALID_INDEX );
768 release_class_ptr( class );
Guy Albertelli2fa281f1999-04-24 11:54:40 +0000769 return retvalue;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000770}
771
772
773/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000774 * GetClassLong (USER.131)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000775 */
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000776LONG WINAPI GetClassLong16( HWND16 hwnd16, INT16 offset )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000777{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000778 CLASS *class;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000779 LONG ret;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000780 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000781
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000782 TRACE("%x %d\n",hwnd, offset);
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000783
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000784 switch( offset )
785 {
Alexandre Julliard3051b641996-07-05 17:14:13 +0000786 case GCL_WNDPROC:
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000787 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000788 ret = (LONG)CLASS_GetProc( class, WIN_PROC_16 );
789 release_class_ptr( class );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000790 return ret;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000791 case GCL_MENUNAME:
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000792 ret = GetClassLongA( hwnd, offset );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000793 return (LONG)SEGPTR_GET( (void *)ret );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000794 default:
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000795 return GetClassLongA( hwnd, offset );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000796 }
Alexandre Julliard401710d1993-09-04 10:09:32 +0000797}
798
799
800/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000801 * GetClassLongA (USER32.@)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000802 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000803LONG WINAPI GetClassLongA( HWND hwnd, INT offset )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000804{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000805 CLASS *class;
806 LONG retvalue = 0;
807
808 TRACE("%x %d\n", hwnd, offset);
809
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000810 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000811
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000812 if (offset >= 0)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000813 {
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000814 if (offset <= class->cbClsExtra - sizeof(LONG))
815 retvalue = GET_DWORD((char *)(class + 1) + offset);
816 else
817 SetLastError( ERROR_INVALID_INDEX );
818 release_class_ptr( class );
819 return retvalue;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000820 }
Alexandre Julliardd44e4952001-08-20 18:09:39 +0000821
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000822 switch(offset)
823 {
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000824 case GCL_HBRBACKGROUND:
825 retvalue = (LONG)class->hbrBackground;
826 break;
827 case GCL_HCURSOR:
828 retvalue = (LONG)class->hCursor;
829 break;
830 case GCL_HICON:
831 retvalue = (LONG)class->hIcon;
832 break;
833 case GCL_HICONSM:
834 retvalue = (LONG)class->hIconSm;
835 break;
836 case GCL_STYLE:
837 retvalue = (LONG)class->style;
838 break;
839 case GCL_CBWNDEXTRA:
840 retvalue = (LONG)class->cbWndExtra;
841 break;
842 case GCL_CBCLSEXTRA:
843 retvalue = (LONG)class->cbClsExtra;
844 break;
845 case GCL_HMODULE:
846 retvalue = (LONG)class->hInstance;
847 break;
848 case GCL_WNDPROC:
849 retvalue = (LONG)CLASS_GetProc( class, WIN_PROC_32A );
850 break;
851 case GCL_MENUNAME:
852 retvalue = (LONG)CLASS_GetMenuNameA( class );
853 break;
854 case GCW_ATOM:
855 retvalue = (DWORD)class->atomName;
856 break;
857 default:
858 SetLastError( ERROR_INVALID_INDEX );
859 break;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000860 }
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000861 release_class_ptr( class );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000862 return retvalue;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000863}
864
865
866/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000867 * GetClassLongW (USER32.@)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000868 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000869LONG WINAPI GetClassLongW( HWND hwnd, INT offset )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000870{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000871 CLASS *class;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000872 LONG retvalue;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000873
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000874 if (offset != GCL_WNDPROC && offset != GCL_MENUNAME)
Alexandre Julliarda3960291999-02-26 11:11:13 +0000875 return GetClassLongA( hwnd, offset );
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000876
877 TRACE("%x %d\n", hwnd, offset);
878
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000879 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000880
881 if (offset == GCL_WNDPROC)
882 retvalue = (LONG)CLASS_GetProc( class, WIN_PROC_32W );
883 else /* GCL_MENUNAME */
884 retvalue = (LONG)CLASS_GetMenuNameW( class );
885
886 release_class_ptr( class );
887 return retvalue;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000888}
889
890
891/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000892 * SetClassWord (USER32.@)
Alexandre Julliard21979011997-03-05 08:22:35 +0000893 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000894WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000895{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000896 CLASS *class;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000897 WORD retval = 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000898
899 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
900
901 TRACE("%x %d %x\n", hwnd, offset, newval);
902
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000903 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000904
905 if (offset <= class->cbClsExtra - sizeof(WORD))
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000906 {
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000907 void *ptr = (char *)(class + 1) + offset;
908 retval = GET_WORD(ptr);
909 PUT_WORD( ptr, newval );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000910 }
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000911 else SetLastError( ERROR_INVALID_INDEX );
912
913 release_class_ptr( class );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000914 return retval;
915}
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000916
917
918/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000919 * SetClassLong (USER.132)
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000920 */
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000921LONG WINAPI SetClassLong16( HWND16 hwnd16, INT16 offset, LONG newval )
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000922{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000923 CLASS *class;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000924 LONG retval;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000925 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000926
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000927 TRACE("%x %d %lx\n", hwnd, offset, newval);
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000928
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000929 switch(offset)
930 {
931 case GCL_WNDPROC:
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000932 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000933 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_16 );
934 release_class_ptr( class );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000935 return retval;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000936 case GCL_MENUNAME:
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000937 newval = (LONG)MapSL( newval );
938 /* fall through */
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000939 default:
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000940 return SetClassLongA( hwnd, offset, newval );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000941 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000942}
943
944
945/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000946 * SetClassLongA (USER32.@)
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000947 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000948LONG WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000949{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000950 CLASS *class;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000951 LONG retval = 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000952
953 TRACE("%x %d %lx\n", hwnd, offset, newval);
954
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000955 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000956
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000957 if (offset >= 0)
958 {
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000959 if (offset <= class->cbClsExtra - sizeof(LONG))
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000960 {
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000961 void *ptr = (char *)(class + 1) + offset;
962 retval = GET_DWORD(ptr);
963 PUT_DWORD( ptr, newval );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000964 }
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000965 else SetLastError( ERROR_INVALID_INDEX );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000966 }
967 else switch(offset)
968 {
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000969 case GCL_MENUNAME:
970 CLASS_SetMenuNameA( class, (LPCSTR)newval );
971 retval = 0; /* Old value is now meaningless anyway */
972 break;
973 case GCL_WNDPROC:
974 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32A );
975 break;
976 case GCL_HBRBACKGROUND:
977 retval = (LONG)class->hbrBackground;
978 class->hbrBackground = newval;
979 break;
980 case GCL_HCURSOR:
981 retval = (LONG)class->hCursor;
982 class->hCursor = newval;
983 break;
984 case GCL_HICON:
985 retval = (LONG)class->hIcon;
986 class->hIcon = newval;
987 break;
988 case GCL_HICONSM:
989 retval = (LONG)class->hIconSm;
990 class->hIconSm = newval;
991 break;
992 case GCL_STYLE:
993 retval = (LONG)class->style;
994 class->style = newval;
995 break;
996 case GCL_CBWNDEXTRA:
997 retval = (LONG)class->cbWndExtra;
998 class->cbWndExtra = newval;
999 break;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001000 case GCL_HMODULE:
1001 retval = (LONG)class->hInstance;
1002 class->hInstance = newval;
1003 break;
1004 case GCW_ATOM:
1005 retval = (DWORD)class->atomName;
1006 class->atomName = newval;
1007 break;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001008 case GCL_CBCLSEXTRA: /* cannot change this one */
1009 SetLastError( ERROR_INVALID_PARAMETER );
1010 break;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001011 default:
1012 SetLastError( ERROR_INVALID_INDEX );
1013 break;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001014 }
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001015 release_class_ptr( class );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001016 return retval;
1017}
1018
1019
1020/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001021 * SetClassLongW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001022 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001023LONG WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001024{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001025 CLASS *class;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001026 LONG retval;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001027
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001028 if (offset != GCL_WNDPROC && offset != GCL_MENUNAME)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001029 return SetClassLongA( hwnd, offset, newval );
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001030
1031 TRACE("%x %d %lx\n", hwnd, offset, newval);
1032
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001033 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001034
1035 if (offset == GCL_WNDPROC)
1036 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32W );
1037 else /* GCL_MENUNAME */
1038 {
1039 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
1040 retval = 0; /* Old value is now meaningless anyway */
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001041 }
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001042 release_class_ptr( class );
1043 return retval;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001044}
1045
1046
1047/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001048 * GetClassNameA (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001049 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001050INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001051{
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001052 INT ret = GlobalGetAtomNameA( GetClassLongA( hwnd, GCW_ATOM ), buffer, count );
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001053
1054 TRACE("%x %s %x\n",hwnd, debugstr_a(buffer), count);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001055 return ret;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001056}
1057
1058
1059/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001060 * GetClassNameW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001061 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001062INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001063{
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001064 INT ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), buffer, count );
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001065
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001066 TRACE("%x %s %x\n",hwnd, debugstr_w(buffer), count);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001067 return ret;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001068}
1069
1070
1071/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001072 * GetClassInfo (USER.404)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001073 */
Alexandre Julliard98779062000-12-07 23:39:16 +00001074BOOL16 WINAPI GetClassInfo16( HINSTANCE16 hInstance, SEGPTR name, WNDCLASS16 *wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001075{
1076 ATOM atom;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001077 CLASS *classPtr;
Alexandre Julliard3ed37e01994-11-07 18:20:42 +00001078
Alexandre Julliard982a2232000-12-13 20:20:09 +00001079 TRACE("%x %s %p\n",hInstance, debugres_a(MapSL(name)), wc);
Alexandre Julliard98779062000-12-07 23:39:16 +00001080
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001081 hInstance = GetExePtr( hInstance );
Alexandre Julliard982a2232000-12-13 20:20:09 +00001082 if (!(atom = GlobalFindAtomA( MapSL(name) )) ||
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001083 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1084 return FALSE;
1085 if ((hInstance != classPtr->hInstance) &&
1086 !(classPtr->style & CS_GLOBALCLASS)) /*BWCC likes to pass hInstance=0*/
1087 return FALSE;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001088 wc->style = (UINT16)classPtr->style;
Alexandre Julliard98779062000-12-07 23:39:16 +00001089 wc->lpfnWndProc = CLASS_GetProc( classPtr, WIN_PROC_16 );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001090 wc->cbClsExtra = (INT16)classPtr->cbClsExtra;
1091 wc->cbWndExtra = (INT16)classPtr->cbWndExtra;
Joshua Thielen40a35aa2001-11-05 23:49:54 +00001092 wc->hInstance = classPtr->style & CS_GLOBALCLASS ? GetModuleHandle16("USER") : (HINSTANCE16)classPtr->hInstance;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001093 wc->hIcon = classPtr->hIcon;
1094 wc->hCursor = classPtr->hCursor;
1095 wc->hbrBackground = classPtr->hbrBackground;
Alexandre Julliard98779062000-12-07 23:39:16 +00001096 wc->lpszClassName = name;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001097 wc->lpszMenuName = (SEGPTR)CLASS_GetMenuNameA( classPtr );
1098 if (HIWORD(wc->lpszMenuName)) /* Make it a SEGPTR */
1099 wc->lpszMenuName = SEGPTR_GET( (LPSTR)wc->lpszMenuName );
1100 return TRUE;
1101}
1102
1103
1104/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001105 * GetClassInfoA (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001106 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001107BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name,
1108 WNDCLASSA *wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001109{
1110 ATOM atom;
1111 CLASS *classPtr;
1112
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001113 TRACE("%x %p %p\n",hInstance, name, wc);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001114
1115 /* workaround: if hInstance=NULL you expect to get the system classes
1116 but this classes (as example from comctl32.dll SysListView) won't be
Andreas Mohr2caee712000-07-16 15:44:22 +00001117 registered with hInstance=NULL in WINE because of the late loading
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001118 of this dll. fixes file dialogs in WinWord95 (jsch)*/
1119
Alexandre Julliarda3960291999-02-26 11:11:13 +00001120 if (!(atom=GlobalFindAtomA(name)) || !(classPtr=CLASS_FindClassByAtom(atom,hInstance)))
Alexandre Julliard21979011997-03-05 08:22:35 +00001121 return FALSE;
1122
Noomen Hamza1040eaf2000-07-09 12:21:07 +00001123 if (!(classPtr->style & CS_GLOBALCLASS) &&
1124 classPtr->hInstance &&
1125 (hInstance != classPtr->hInstance))
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001126 {
1127 if (hInstance) return FALSE;
Noomen Hamza1040eaf2000-07-09 12:21:07 +00001128 WARN("systemclass %s (hInst=0) demanded but only class with hInst!=0 found\n",name);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001129 }
1130
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001131 wc->style = classPtr->style;
Alexandre Julliard98779062000-12-07 23:39:16 +00001132 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32A );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001133 wc->cbClsExtra = classPtr->cbClsExtra;
1134 wc->cbWndExtra = classPtr->cbWndExtra;
Noomen Hamza1040eaf2000-07-09 12:21:07 +00001135 wc->hInstance = hInstance;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001136 wc->hIcon = (HICON)classPtr->hIcon;
1137 wc->hCursor = (HCURSOR)classPtr->hCursor;
1138 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001139 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
Alexandre Julliard98779062000-12-07 23:39:16 +00001140 wc->lpszClassName = name;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001141 return TRUE;
1142}
1143
1144
1145/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001146 * GetClassInfoW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001147 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001148BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name,
1149 WNDCLASSW *wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001150{
1151 ATOM atom;
1152 CLASS *classPtr;
1153
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001154 TRACE("%x %p %p\n",hInstance, name, wc);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001155
Marcus Meissner438062171999-09-03 12:28:20 +00001156 if ( !(atom=GlobalFindAtomW(name)) ||
1157 !(classPtr=CLASS_FindClassByAtom(atom,hInstance))
1158 )
Alexandre Julliard21979011997-03-05 08:22:35 +00001159 return FALSE;
1160
Noomen Hamza1040eaf2000-07-09 12:21:07 +00001161 if (!(classPtr->style & CS_GLOBALCLASS) &&
1162 classPtr->hInstance &&
1163 (hInstance != classPtr->hInstance))
1164 {
1165 if (hInstance) return FALSE;
1166 WARN("systemclass %s (hInst=0) demanded but only class with hInst!=0 found\n",debugstr_w(name));
Marcus Meissner438062171999-09-03 12:28:20 +00001167 }
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001168 wc->style = classPtr->style;
Alexandre Julliard98779062000-12-07 23:39:16 +00001169 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32W );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001170 wc->cbClsExtra = classPtr->cbClsExtra;
1171 wc->cbWndExtra = classPtr->cbWndExtra;
Noomen Hamza1040eaf2000-07-09 12:21:07 +00001172 wc->hInstance = hInstance;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001173 wc->hIcon = (HICON)classPtr->hIcon;
1174 wc->hCursor = (HCURSOR)classPtr->hCursor;
1175 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001176 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
Alexandre Julliard98779062000-12-07 23:39:16 +00001177 wc->lpszClassName = name;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001178 return TRUE;
1179}
1180
1181
1182/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001183 * GetClassInfoEx (USER.398)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001184 *
1185 * FIXME: this is just a guess, I have no idea if GetClassInfoEx() is the
1186 * same in Win16 as in Win32. --AJ
1187 */
Alexandre Julliard98779062000-12-07 23:39:16 +00001188BOOL16 WINAPI GetClassInfoEx16( HINSTANCE16 hInstance, SEGPTR name, WNDCLASSEX16 *wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001189{
1190 ATOM atom;
1191 CLASS *classPtr;
Alexandre Julliard808cb041995-08-17 17:11:36 +00001192
Alexandre Julliard982a2232000-12-13 20:20:09 +00001193 TRACE("%x %s %p\n",hInstance,debugres_a( MapSL(name) ), wc);
Alexandre Julliard98779062000-12-07 23:39:16 +00001194
Alexandre Julliard808cb041995-08-17 17:11:36 +00001195 hInstance = GetExePtr( hInstance );
Alexandre Julliard982a2232000-12-13 20:20:09 +00001196 if (!(atom = GlobalFindAtomA( MapSL(name) )) ||
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001197 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
1198 (hInstance != classPtr->hInstance)) return FALSE;
1199 wc->style = classPtr->style;
Alexandre Julliard98779062000-12-07 23:39:16 +00001200 wc->lpfnWndProc = CLASS_GetProc( classPtr, WIN_PROC_16 );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001201 wc->cbClsExtra = (INT16)classPtr->cbClsExtra;
1202 wc->cbWndExtra = (INT16)classPtr->cbWndExtra;
1203 wc->hInstance = (HINSTANCE16)classPtr->hInstance;
1204 wc->hIcon = classPtr->hIcon;
1205 wc->hIconSm = classPtr->hIconSm;
1206 wc->hCursor = classPtr->hCursor;
1207 wc->hbrBackground = classPtr->hbrBackground;
1208 wc->lpszClassName = (SEGPTR)0;
1209 wc->lpszMenuName = (SEGPTR)CLASS_GetMenuNameA( classPtr );
1210 if (HIWORD(wc->lpszMenuName)) /* Make it a SEGPTR */
1211 wc->lpszMenuName = SEGPTR_GET( (LPSTR)wc->lpszMenuName );
Alexandre Julliard98779062000-12-07 23:39:16 +00001212 wc->lpszClassName = name;
James Hatheway9fa09e72000-06-18 17:19:38 +00001213
1214 /* We must return the atom of the class here instead of just TRUE. */
1215 return atom;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001216}
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001217
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00001218
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001219/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001220 * GetClassInfoExA (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001221 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001222BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name,
1223 WNDCLASSEXA *wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001224{
1225 ATOM atom;
1226 CLASS *classPtr;
1227
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001228 TRACE("%x %p %p\n",hInstance, name, wc);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001229
Alexandre Julliarda3960291999-02-26 11:11:13 +00001230 if (!(atom = GlobalFindAtomA( name )) ||
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001231 !(classPtr = CLASS_FindClassByAtom( atom, hInstance ))
1232 /*|| (hInstance != classPtr->hInstance) */ ) return FALSE;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001233 wc->style = classPtr->style;
Alexandre Julliard98779062000-12-07 23:39:16 +00001234 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32A );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001235 wc->cbClsExtra = classPtr->cbClsExtra;
1236 wc->cbWndExtra = classPtr->cbWndExtra;
1237 wc->hInstance = classPtr->hInstance;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001238 wc->hIcon = (HICON)classPtr->hIcon;
1239 wc->hIconSm = (HICON)classPtr->hIconSm;
1240 wc->hCursor = (HCURSOR)classPtr->hCursor;
1241 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001242 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
Alexandre Julliard98779062000-12-07 23:39:16 +00001243 wc->lpszClassName = name;
1244
James Hatheway9fa09e72000-06-18 17:19:38 +00001245 /* We must return the atom of the class here instead of just TRUE. */
1246 return atom;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001247}
1248
1249
1250/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001251 * GetClassInfoExW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001252 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001253BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name,
1254 WNDCLASSEXW *wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001255{
1256 ATOM atom;
1257 CLASS *classPtr;
1258
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001259 TRACE("%x %p %p\n",hInstance, name, wc);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001260
Alexandre Julliarda3960291999-02-26 11:11:13 +00001261 if (!(atom = GlobalFindAtomW( name )) ||
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001262 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
1263 (hInstance != classPtr->hInstance)) return FALSE;
1264 wc->style = classPtr->style;
Alexandre Julliard98779062000-12-07 23:39:16 +00001265 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32W );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001266 wc->cbClsExtra = classPtr->cbClsExtra;
1267 wc->cbWndExtra = classPtr->cbWndExtra;
1268 wc->hInstance = classPtr->hInstance;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001269 wc->hIcon = (HICON)classPtr->hIcon;
1270 wc->hIconSm = (HICON)classPtr->hIconSm;
1271 wc->hCursor = (HCURSOR)classPtr->hCursor;
1272 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001273 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
Alexandre Julliard98779062000-12-07 23:39:16 +00001274 wc->lpszClassName = name;
1275
James Hatheway9fa09e72000-06-18 17:19:38 +00001276 /* We must return the atom of the class here instead of just TRUE. */
1277 return atom;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001278}
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001279
1280
Alexandre Julliardf899ef02001-07-23 00:04:00 +00001281#if 0 /* toolhelp is in kernel, so this cannot work */
1282
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001283/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001284 * ClassFirst (TOOLHELP.69)
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001285 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001286BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001287{
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001288 TRACE("%p\n",pClassEntry);
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001289 pClassEntry->wNext = 1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001290 return ClassNext16( pClassEntry );
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001291}
1292
1293
1294/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001295 * ClassNext (TOOLHELP.70)
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001296 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001297BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001298{
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001299 int i;
1300 CLASS *class = firstClass;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001301
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001302 TRACE("%p\n",pClassEntry);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001303
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001304 if (!pClassEntry->wNext) return FALSE;
1305 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1306 if (!class)
1307 {
1308 pClassEntry->wNext = 0;
1309 return FALSE;
1310 }
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00001311 pClassEntry->hInst = class->hInstance;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001312 pClassEntry->wNext++;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001313 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001314 sizeof(pClassEntry->szClassName) );
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001315 return TRUE;
1316}
Alexandre Julliardf899ef02001-07-23 00:04:00 +00001317#endif