blob: 613b65577e757f15843ad3db0dac638faef99198 [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 *
Alexandre Julliard0799c1a2002-03-09 23:29:33 +00007 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
Alexandre Julliard21979011997-03-05 08:22:35 +000021 * FIXME: In win32 all classes are local. They are registered at
22 * program start. Processes CANNOT share classes. (Source: some
23 * win31->NT migration book)
Alexandre Julliard767e6f61998-08-09 12:47:43 +000024 *
25 * FIXME: There seems to be a general problem with hInstance in WINE
Andreas Mohr1af53cb2000-12-09 03:15:32 +000026 * classes are getting registered with wrong hInstance.
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +000027 */
Alexandre Julliard401710d1993-09-04 10:09:32 +000028
François Gouget14259412001-11-06 20:57:11 +000029#include "config.h"
Francois Gouget386cf6e2001-10-14 16:25:47 +000030#include "wine/port.h"
31
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000032#include <stdlib.h>
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000033#include <string.h>
Francois Gouget386cf6e2001-10-14 16:25:47 +000034
Marcus Meissner317af321999-02-17 13:51:06 +000035#include "wine/winbase16.h"
Alexandre Julliardc7e7df82000-08-14 14:41:19 +000036#include "winerror.h"
37#include "windef.h"
38#include "wingdi.h"
39#include "wine/winuser16.h"
40#include "wine/unicode.h"
Alexandre Julliard401710d1993-09-04 10:09:32 +000041#include "win.h"
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000042#include "user.h"
Alexandre Julliard91222da2000-12-10 23:01:33 +000043#include "controls.h"
Alexandre Julliard5f721f81994-01-04 20:14:34 +000044#include "dce.h"
Alexandre Julliard2d93d001996-05-21 15:01:41 +000045#include "winproc.h"
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000046#include "wine/debug.h"
Alexandre Julliard8d24ae61994-04-05 21:42:43 +000047
Alexandre Julliard0799c1a2002-03-09 23:29:33 +000048WINE_DEFAULT_DEBUG_CHANNEL(class);
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000049
Alexandre Julliard98779062000-12-07 23:39:16 +000050typedef struct tagCLASS
51{
52 struct tagCLASS *next; /* Next class */
53 struct tagCLASS *prev; /* Prev class */
54 UINT cWindows; /* Count of existing windows */
55 UINT style; /* Class style */
56 HWINDOWPROC winprocA; /* Window procedure (ASCII) */
57 HWINDOWPROC winprocW; /* Window procedure (Unicode) */
58 INT cbClsExtra; /* Class extra bytes */
59 INT cbWndExtra; /* Window extra bytes */
60 LPWSTR menuName; /* Default menu name (Unicode followed by ASCII) */
Alexandre Julliardd7b76822001-12-20 00:19:40 +000061 SEGPTR segMenuName; /* Default menu name as SEGPTR */
Alexandre Julliard98779062000-12-07 23:39:16 +000062 struct tagDCE *dce; /* Class DCE (if CS_CLASSDC) */
63 HINSTANCE hInstance; /* Module that created the task */
64 HICON hIcon; /* Default icon */
65 HICON hIconSm; /* Default small icon */
66 HCURSOR hCursor; /* Default cursor */
67 HBRUSH hbrBackground; /* Default background */
68 ATOM atomName; /* Name of the class */
Alexandre Julliard98779062000-12-07 23:39:16 +000069} CLASS;
Alexandre Julliard401710d1993-09-04 10:09:32 +000070
Alexandre Julliard98779062000-12-07 23:39:16 +000071static CLASS *firstClass;
Alexandre Julliard401710d1993-09-04 10:09:32 +000072
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000073/***********************************************************************
74 * get_class_ptr
75 */
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000076static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000077{
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000078 WND *ptr = WIN_GetPtr( hwnd );
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000079
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000080 if (ptr)
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000081 {
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000082 if (ptr != WND_OTHER_PROCESS) return ptr->class;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000083 if (IsWindow( hwnd )) /* check other processes */
84 {
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000085 if (write_access)
86 {
87 /* modifying classes in other processes is not allowed */
88 SetLastError( ERROR_ACCESS_DENIED );
89 return NULL;
90 }
91 FIXME( "reading from class of other process window %04x\n", hwnd );
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000092 /* DbgBreakPoint(); */
93 }
94 }
Alexandre Julliard8fd26b92001-10-15 17:56:45 +000095 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
96 return NULL;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +000097}
98
99
100/***********************************************************************
101 * release_class_ptr
102 */
103inline static void release_class_ptr( CLASS *ptr )
104{
105 USER_Unlock();
106}
107
Alexandre Julliard401710d1993-09-04 10:09:32 +0000108
109/***********************************************************************
Alexandre Julliard98779062000-12-07 23:39:16 +0000110 * CLASS_GetProc
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000111 *
Alexandre Julliard98779062000-12-07 23:39:16 +0000112 * Get the class winproc for a given proc type
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000113 */
Alexandre Julliard98779062000-12-07 23:39:16 +0000114static WNDPROC16 CLASS_GetProc( CLASS *classPtr, WINDOWPROCTYPE type )
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000115{
Alexandre Julliard98779062000-12-07 23:39:16 +0000116 HWINDOWPROC proc = classPtr->winprocA;
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000117
Alexandre Julliard98779062000-12-07 23:39:16 +0000118 if (classPtr->winprocW)
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000119 {
Alexandre Julliard98779062000-12-07 23:39:16 +0000120 /* if we have a Unicode proc, use it if we have no ASCII proc
121 * or if we have both and Unicode was requested
122 */
123 if (!proc || type == WIN_PROC_32W) proc = classPtr->winprocW;
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000124 }
Alexandre Julliard98779062000-12-07 23:39:16 +0000125 return WINPROC_GetProc( proc, type );
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000126}
127
128
129/***********************************************************************
Alexandre Julliard98779062000-12-07 23:39:16 +0000130 * CLASS_SetProc
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000131 *
Alexandre Julliard98779062000-12-07 23:39:16 +0000132 * Set the class winproc for a given proc type.
133 * Returns the previous window proc.
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000134 */
Alexandre Julliard98779062000-12-07 23:39:16 +0000135static WNDPROC16 CLASS_SetProc( CLASS *classPtr, WNDPROC newproc, WINDOWPROCTYPE type )
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000136{
Alexandre Julliard98779062000-12-07 23:39:16 +0000137 HWINDOWPROC *proc = &classPtr->winprocA;
138 WNDPROC16 ret;
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000139
Alexandre Julliard98779062000-12-07 23:39:16 +0000140 if (classPtr->winprocW)
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000141 {
Alexandre Julliard98779062000-12-07 23:39:16 +0000142 /* if we have a Unicode proc, use it if we have no ASCII proc
143 * or if we have both and Unicode was requested
144 */
145 if (!*proc || type == WIN_PROC_32W) proc = &classPtr->winprocW;
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000146 }
Alexandre Julliard98779062000-12-07 23:39:16 +0000147 ret = WINPROC_GetProc( *proc, type );
148 WINPROC_SetProc( proc, (HWINDOWPROC)newproc, type, WIN_PROC_CLASS );
149 /* now free the one that we didn't set */
150 if (classPtr->winprocA && classPtr->winprocW)
151 {
152 if (proc == &classPtr->winprocA)
153 {
154 WINPROC_FreeProc( classPtr->winprocW, WIN_PROC_CLASS );
155 classPtr->winprocW = 0;
156 }
157 else
158 {
159 WINPROC_FreeProc( classPtr->winprocA, WIN_PROC_CLASS );
160 classPtr->winprocA = 0;
161 }
162 }
163 return ret;
Alexandre Julliardb817f4f1996-03-14 18:08:34 +0000164}
165
166
167/***********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000168 * CLASS_GetMenuNameA
169 *
170 * Get the menu name as a ASCII string.
171 */
Alexandre Julliard98779062000-12-07 23:39:16 +0000172inline static LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000173{
Alexandre Julliard98779062000-12-07 23:39:16 +0000174 if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
175 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000176}
177
178
179/***********************************************************************
Alexandre Julliardd7b76822001-12-20 00:19:40 +0000180 * CLASS_GetMenuName16
181 *
182 * Get the menu name as a SEGPTR.
183 */
184inline static SEGPTR CLASS_GetMenuName16( CLASS *classPtr )
185{
186 if (!HIWORD(classPtr->menuName)) return (SEGPTR)classPtr->menuName;
187 if (!classPtr->segMenuName)
188 classPtr->segMenuName = MapLS( CLASS_GetMenuNameA(classPtr) );
189 return classPtr->segMenuName;
190}
191
192
193/***********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000194 * CLASS_GetMenuNameW
195 *
196 * Get the menu name as a Unicode string.
197 */
Alexandre Julliard98779062000-12-07 23:39:16 +0000198inline static LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000199{
Alexandre Julliard98779062000-12-07 23:39:16 +0000200 return classPtr->menuName;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000201}
202
203
204/***********************************************************************
205 * CLASS_SetMenuNameA
206 *
207 * Set the menu name in a class structure by copying the string.
208 */
209static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
210{
Alexandre Julliardd7b76822001-12-20 00:19:40 +0000211 UnMapLS( classPtr->segMenuName );
212 classPtr->segMenuName = 0;
213 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
Alexandre Julliard98779062000-12-07 23:39:16 +0000214 if (HIWORD(name))
215 {
216 DWORD lenA = strlen(name) + 1;
217 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
Alexandre Julliardd7b76822001-12-20 00:19:40 +0000218 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
Alexandre Julliard98779062000-12-07 23:39:16 +0000219 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
220 memcpy( classPtr->menuName + lenW, name, lenA );
221 }
222 else classPtr->menuName = (LPWSTR)name;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000223}
224
225
226/***********************************************************************
227 * CLASS_SetMenuNameW
228 *
229 * Set the menu name in a class structure by copying the string.
230 */
231static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
232{
Alexandre Julliardd7b76822001-12-20 00:19:40 +0000233 UnMapLS( classPtr->segMenuName );
234 classPtr->segMenuName = 0;
235 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
Alexandre Julliard98779062000-12-07 23:39:16 +0000236 if (HIWORD(name))
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000237 {
Alexandre Julliard98779062000-12-07 23:39:16 +0000238 DWORD lenW = strlenW(name) + 1;
239 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
Alexandre Julliardd7b76822001-12-20 00:19:40 +0000240 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
Alexandre Julliard98779062000-12-07 23:39:16 +0000241 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
242 WideCharToMultiByte( CP_ACP, 0, name, lenW,
243 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000244 }
Alexandre Julliard98779062000-12-07 23:39:16 +0000245 else classPtr->menuName = (LPWSTR)name;
Gavriel Statec77c5921998-11-15 09:21:17 +0000246}
247
248
249/***********************************************************************
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000250 * CLASS_FreeClass
251 *
252 * Free a class structure.
253 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000254static BOOL CLASS_FreeClass( CLASS *classPtr )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000255{
Alexandre Julliard98779062000-12-07 23:39:16 +0000256 TRACE("%p\n", classPtr);
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000257
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000258 /* Check if we can remove this class */
259
Alexandre Julliard98779062000-12-07 23:39:16 +0000260 if (classPtr->cWindows > 0)
261 {
262 SetLastError( ERROR_CLASS_HAS_WINDOWS );
263 return FALSE;
264 }
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000265
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000266 /* Remove the class from the linked list */
267
Alexandre Julliard98779062000-12-07 23:39:16 +0000268 if (classPtr->next) classPtr->next->prev = classPtr->prev;
269 if (classPtr->prev) classPtr->prev->next = classPtr->next;
270 else firstClass = classPtr->next;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000271
272 /* Delete the class */
273
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000274 if (classPtr->dce) DCE_FreeDCE( classPtr->dce );
Huw D M Davies2f245af2000-09-12 23:38:33 +0000275 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
276 DeleteObject( classPtr->hbrBackground );
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000277 GlobalDeleteAtom( classPtr->atomName );
Alexandre Julliard98779062000-12-07 23:39:16 +0000278 WINPROC_FreeProc( classPtr->winprocA, WIN_PROC_CLASS );
279 WINPROC_FreeProc( classPtr->winprocW, WIN_PROC_CLASS );
Alexandre Julliardd7b76822001-12-20 00:19:40 +0000280 UnMapLS( classPtr->segMenuName );
Alexandre Julliard98779062000-12-07 23:39:16 +0000281 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
282 HeapFree( GetProcessHeap(), 0, classPtr );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000283 return TRUE;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000284}
285
286
287/***********************************************************************
288 * CLASS_FreeModuleClasses
289 */
Alexandre Julliard3051b641996-07-05 17:14:13 +0000290void CLASS_FreeModuleClasses( HMODULE16 hModule )
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000291{
292 CLASS *ptr, *next;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000293
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000294 TRACE("0x%08x\n", hModule);
295
296 USER_Lock();
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000297 for (ptr = firstClass; ptr; ptr = next)
298 {
299 next = ptr->next;
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000300 if (ptr->hInstance == hModule) CLASS_FreeClass( ptr );
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000301 }
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000302 USER_Unlock();
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000303}
304
305
306/***********************************************************************
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000307 * CLASS_FindClassByAtom
308 *
309 * Return a pointer to the class.
Alexandre Julliard77b99181997-09-14 17:17:23 +0000310 * hinstance has been normalized by the caller.
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000311 *
312 * NOTES
313 * 980805 a local class will be found now if registred with hInst=0
314 * and looed up with a hInst!=0. msmoney does it (jsch)
Joshua Thielend9ed57a2001-11-16 18:11:43 +0000315 *
316 * Local class registered with a USER instance handle are found as if
317 * they were global classes.
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000318 */
Alexandre Julliard98779062000-12-07 23:39:16 +0000319static CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE hinstance )
320{
Joshua Thielend9ed57a2001-11-16 18:11:43 +0000321 CLASS * class, *tclass = 0, *user_class = 0;
322 HINSTANCE16 hUser = GetModuleHandle16("USER");
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000323
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000324 TRACE("0x%08x 0x%08x\n", atom, hinstance);
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000325
Alexandre Julliard77b99181997-09-14 17:17:23 +0000326 /* First search task-specific classes */
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000327
328 for (class = firstClass; (class); class = class->next)
329 {
330 if (class->style & CS_GLOBALCLASS) continue;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000331 if (class->atomName == atom)
332 {
Joshua Thielend9ed57a2001-11-16 18:11:43 +0000333 if (hinstance==class->hInstance || hinstance==0xffff)
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000334 {
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000335 TRACE("-- found local %p\n", class);
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000336 return class;
337 }
Joshua Thielend9ed57a2001-11-16 18:11:43 +0000338 if (class->hInstance == 0) tclass = class;
339 else if(class->hInstance == hUser)
340 {
341 user_class = class;
342 }
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000343 }
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000344 }
345
Joshua Thielend9ed57a2001-11-16 18:11:43 +0000346 /* Then search global classes */
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000347
348 for (class = firstClass; (class); class = class->next)
349 {
350 if (!(class->style & CS_GLOBALCLASS)) continue;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000351 if (class->atomName == atom)
352 {
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000353 TRACE("-- found global %p\n", class);
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000354 return class;
355 }
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000356 }
357
Joshua Thielend9ed57a2001-11-16 18:11:43 +0000358 /* Check if there was a local class registered with USER */
359 if( user_class )
360 {
361 TRACE("--found local USER class %p\n", user_class);
362 return user_class;
363 }
364
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000365 /* Then check if there was a local class with hInst=0*/
366 if ( tclass )
367 {
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000368 WARN("-- found local Class registred with hInst=0\n");
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000369 return tclass;
370 }
371
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000372 TRACE("-- not found\n");
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000373 return 0;
374}
375
376
377/***********************************************************************
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000378 * CLASS_RegisterClass
379 *
380 * The real RegisterClass() functionality.
381 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000382static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE hInstance,
Alexandre Julliard98779062000-12-07 23:39:16 +0000383 DWORD style, INT classExtra, INT winExtra )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000384{
385 CLASS *classPtr;
386
Alexandre Julliard98779062000-12-07 23:39:16 +0000387 TRACE("atom=0x%x hinst=0x%x style=0x%lx clExtr=0x%x winExtr=0x%x\n",
388 atom, hInstance, style, classExtra, winExtra );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000389
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000390 /* Check if a class with this name already exists */
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000391 classPtr = CLASS_FindClassByAtom( atom, hInstance );
392 if (classPtr)
393 {
394 /* Class can be created only if it is local and */
395 /* if the class with the same name is global. */
396
Alexandre Julliard98779062000-12-07 23:39:16 +0000397 if ((style & CS_GLOBALCLASS) || !(classPtr->style & CS_GLOBALCLASS))
398 {
399 SetLastError( ERROR_CLASS_ALREADY_EXISTS );
400 return NULL;
401 }
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000402 }
403
404 /* Fix the extra bytes value */
405
406 if (classExtra < 0) classExtra = 0;
407 else if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000408 WARN("Class extra bytes %d is > 40\n", classExtra);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000409 if (winExtra < 0) winExtra = 0;
410 else if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000411 WARN("Win extra bytes %d is > 40\n", winExtra );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000412
413 /* Create the class */
414
Alexandre Julliardd44e4952001-08-20 18:09:39 +0000415 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000416 if (!classPtr) return NULL;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000417 classPtr->style = style;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000418 classPtr->cbWndExtra = winExtra;
419 classPtr->cbClsExtra = classExtra;
420 classPtr->hInstance = hInstance;
421 classPtr->atomName = atom;
Alexandre Julliard98779062000-12-07 23:39:16 +0000422 classPtr->dce = (style & CS_CLASSDC) ? DCE_AllocDCE( 0, DCE_CLASS_DC ) : NULL;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000423
Alexandre Julliard98779062000-12-07 23:39:16 +0000424 /* Other non-null values must be set by caller */
Alexandre Julliard3051b641996-07-05 17:14:13 +0000425
Alexandre Julliard98779062000-12-07 23:39:16 +0000426 if ((classPtr->next = firstClass)) firstClass->prev = classPtr;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000427 firstClass = classPtr;
428 return classPtr;
429}
430
431
432/***********************************************************************
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000433 * CLASS_UnregisterClass
434 *
435 * The real UnregisterClass() functionality.
436 */
437static BOOL CLASS_UnregisterClass( ATOM atom, HINSTANCE hInstance )
438{
439 CLASS *classPtr;
440 BOOL ret = FALSE;
441
442 USER_Lock();
443 if (atom &&
444 (classPtr = CLASS_FindClassByAtom( atom, hInstance )) &&
Bill Medland0ca07c92001-11-20 18:53:16 +0000445 (!hInstance || classPtr->hInstance == hInstance))
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000446 {
447 ret = CLASS_FreeClass( classPtr );
448 }
449 else SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
450
451 USER_Unlock();
452 return ret;
453}
454
455
456/***********************************************************************
Alexandre Julliard98779062000-12-07 23:39:16 +0000457 * CLASS_RegisterBuiltinClass
458 *
459 * Register a builtin control class.
460 * This allows having both ASCII and Unicode winprocs for the same class.
461 */
Alexandre Julliard91222da2000-12-10 23:01:33 +0000462ATOM CLASS_RegisterBuiltinClass( const struct builtin_class_descr *descr )
Alexandre Julliard98779062000-12-07 23:39:16 +0000463{
464 ATOM atom;
465 CLASS *classPtr;
466
Alexandre Julliard91222da2000-12-10 23:01:33 +0000467 if (!(atom = GlobalAddAtomA( descr->name ))) return 0;
Alexandre Julliard98779062000-12-07 23:39:16 +0000468
Alexandre Julliard91222da2000-12-10 23:01:33 +0000469 if (!(classPtr = CLASS_RegisterClass( atom, 0, descr->style, 0, descr->extra )))
Alexandre Julliard98779062000-12-07 23:39:16 +0000470 {
471 GlobalDeleteAtom( atom );
472 return 0;
473 }
474
Alexandre Julliard91222da2000-12-10 23:01:33 +0000475 classPtr->hCursor = LoadCursorA( 0, descr->cursor );
476 classPtr->hbrBackground = descr->brush;
Alexandre Julliard98779062000-12-07 23:39:16 +0000477
Alexandre Julliard91222da2000-12-10 23:01:33 +0000478 if (descr->procA) WINPROC_SetProc( &classPtr->winprocA, (HWINDOWPROC)descr->procA,
479 WIN_PROC_32A, WIN_PROC_CLASS );
480 if (descr->procW) WINPROC_SetProc( &classPtr->winprocW, (HWINDOWPROC)descr->procW,
481 WIN_PROC_32W, WIN_PROC_CLASS );
Alexandre Julliard98779062000-12-07 23:39:16 +0000482 return atom;
483}
484
485
486/***********************************************************************
487 * CLASS_AddWindow
488 *
489 * Add a new window using this class, and return the necessary
490 * information for creating the window.
491 */
492CLASS *CLASS_AddWindow( ATOM atom, HINSTANCE inst, WINDOWPROCTYPE type,
493 INT *winExtra, WNDPROC *winproc, DWORD *style, struct tagDCE **dce )
494{
495 CLASS *class;
496 if (type == WIN_PROC_16) inst = GetExePtr(inst);
497
498 if (!(class = CLASS_FindClassByAtom( atom, inst ))) return NULL;
499 class->cWindows++;
500
501 if (type == WIN_PROC_32W)
502 {
503 if (!(*winproc = class->winprocW)) *winproc = class->winprocA;
504 }
505 else
506 {
507 if (!(*winproc = class->winprocA)) *winproc = class->winprocW;
508 }
509 *winExtra = class->cbWndExtra;
510 *style = class->style;
511 *dce = class->dce;
512 return class;
513}
514
515
516/***********************************************************************
517 * CLASS_RemoveWindow
518 *
519 * Remove a window from the class window count.
520 */
521void CLASS_RemoveWindow( CLASS *cls )
522{
523 if (cls && cls->cWindows) cls->cWindows--;
524}
525
526
527/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000528 * RegisterClass (USER.57)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000529 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000530ATOM WINAPI RegisterClass16( const WNDCLASS16 *wc )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000531{
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000532 ATOM atom;
533 CLASS *classPtr;
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000534 int iSmIconWidth, iSmIconHeight;
Alexandre Julliard77b99181997-09-14 17:17:23 +0000535 HINSTANCE16 hInstance=GetExePtr(wc->hInstance);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000536
Alexandre Julliard982a2232000-12-13 20:20:09 +0000537 if (!(atom = GlobalAddAtomA( MapSL(wc->lpszClassName) ))) return 0;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000538 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
Alexandre Julliard98779062000-12-07 23:39:16 +0000539 wc->cbClsExtra, wc->cbWndExtra )))
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000540 {
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000541 GlobalDeleteAtom( atom );
542 return 0;
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000543 }
544
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000545 TRACE("atom=%04x wndproc=%08lx hinst=%04x "
Patrik Stridvalla9a671d1999-04-25 19:01:52 +0000546 "bg=%04x style=%08x clsExt=%d winExt=%d class=%p name='%s'\n",
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000547 atom, (DWORD)wc->lpfnWndProc, hInstance,
548 wc->hbrBackground, wc->style, wc->cbClsExtra,
Alexandre Julliard641ee761997-08-04 16:34:36 +0000549 wc->cbWndExtra, classPtr,
550 HIWORD(wc->lpszClassName) ?
Alexandre Julliard982a2232000-12-13 20:20:09 +0000551 (char *)MapSL(wc->lpszClassName) : "" );
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000552
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000553 iSmIconWidth = GetSystemMetrics(SM_CXSMICON);
554 iSmIconHeight = GetSystemMetrics(SM_CYSMICON);
555
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000556 classPtr->hIcon = wc->hIcon;
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000557 classPtr->hIconSm = CopyImage(wc->hIcon, IMAGE_ICON,
558 iSmIconWidth, iSmIconHeight,
559 LR_COPYFROMRESOURCE);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000560 classPtr->hCursor = wc->hCursor;
561 classPtr->hbrBackground = wc->hbrBackground;
Alexandre Julliardf0b23541993-09-29 12:21:49 +0000562
Alexandre Julliard98779062000-12-07 23:39:16 +0000563 WINPROC_SetProc( &classPtr->winprocA, (HWINDOWPROC)wc->lpfnWndProc,
564 WIN_PROC_16, WIN_PROC_CLASS );
Alexandre Julliard982a2232000-12-13 20:20:09 +0000565 CLASS_SetMenuNameA( classPtr, MapSL(wc->lpszMenuName) );
Gavriel Statec77c5921998-11-15 09:21:17 +0000566
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000567 return atom;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000568}
569
570
571/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000572 * RegisterClassA (USER32.@)
Alexandre Julliarda69b88b1998-03-15 20:29:56 +0000573 * RETURNS
574 * >0: Unique identifier
575 * 0: Failure
Alexandre Julliard401710d1993-09-04 10:09:32 +0000576 */
Patrik Stridvall2b3aa612000-12-01 23:58:28 +0000577ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
Alexandre Julliardf681cd02000-08-23 19:18:44 +0000578{
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000579 ATOM atom;
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000580 int iSmIconWidth, iSmIconHeight;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000581 CLASS *classPtr;
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000582
Alexandre Julliardf681cd02000-08-23 19:18:44 +0000583 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
584
Alexandre Julliard77b99181997-09-14 17:17:23 +0000585 if (!(classPtr = CLASS_RegisterClass( atom, wc->hInstance, wc->style,
Alexandre Julliard98779062000-12-07 23:39:16 +0000586 wc->cbClsExtra, wc->cbWndExtra )))
587 {
588 GlobalDeleteAtom( atom );
589 return 0;
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000590 }
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000591
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000592 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 +0000593 atom, (DWORD)wc->lpfnWndProc, wc->hInstance,
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000594 wc->hbrBackground, wc->style, wc->cbClsExtra,
Alexandre Julliard641ee761997-08-04 16:34:36 +0000595 wc->cbWndExtra, classPtr,
596 HIWORD(wc->lpszClassName) ? wc->lpszClassName : "" );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000597
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000598 iSmIconWidth = GetSystemMetrics(SM_CXSMICON);
599 iSmIconHeight = GetSystemMetrics(SM_CYSMICON);
600
601 classPtr->hIcon = wc->hIcon;
602 classPtr->hIconSm = CopyImage(wc->hIcon, IMAGE_ICON,
603 iSmIconWidth, iSmIconHeight,
604 LR_COPYFROMRESOURCE);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000605 classPtr->hCursor = (HCURSOR16)wc->hCursor;
606 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
Alexandre Julliard98779062000-12-07 23:39:16 +0000607
608 WINPROC_SetProc( &classPtr->winprocA, (HWINDOWPROC)wc->lpfnWndProc,
609 WIN_PROC_32A, WIN_PROC_CLASS );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000610 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
611 return atom;
612}
613
614
615/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000616 * RegisterClassW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000617 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000618ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000619{
620 ATOM atom;
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000621 int iSmIconWidth, iSmIconHeight;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000622 CLASS *classPtr;
623
Alexandre Julliardf681cd02000-08-23 19:18:44 +0000624 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
625
Alexandre Julliard77b99181997-09-14 17:17:23 +0000626 if (!(classPtr = CLASS_RegisterClass( atom, wc->hInstance, wc->style,
Alexandre Julliard98779062000-12-07 23:39:16 +0000627 wc->cbClsExtra, wc->cbWndExtra )))
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000628 {
629 GlobalDeleteAtom( atom );
630 return 0;
631 }
632
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000633 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 +0000634 atom, (DWORD)wc->lpfnWndProc, wc->hInstance,
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000635 wc->hbrBackground, wc->style, wc->cbClsExtra,
636 wc->cbWndExtra, classPtr );
637
Pierre Mageau4ac8db71999-09-04 11:16:48 +0000638 iSmIconWidth = GetSystemMetrics(SM_CXSMICON);
639 iSmIconHeight = GetSystemMetrics(SM_CYSMICON);
640
641 classPtr->hIcon = wc->hIcon;
642 classPtr->hIconSm = CopyImage(wc->hIcon, IMAGE_ICON,
643 iSmIconWidth, iSmIconHeight,
644 LR_COPYFROMRESOURCE);
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000645 classPtr->hCursor = (HCURSOR16)wc->hCursor;
646 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
Alexandre Julliard98779062000-12-07 23:39:16 +0000647
648 WINPROC_SetProc( &classPtr->winprocW, (HWINDOWPROC)wc->lpfnWndProc,
649 WIN_PROC_32W, WIN_PROC_CLASS );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000650 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
651 return atom;
652}
653
654
655/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000656 * RegisterClassEx (USER.397)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000657 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000658ATOM WINAPI RegisterClassEx16( const WNDCLASSEX16 *wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000659{
660 ATOM atom;
661 CLASS *classPtr;
Alexandre Julliard77b99181997-09-14 17:17:23 +0000662 HINSTANCE16 hInstance = GetExePtr( wc->hInstance );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000663
Alexandre Julliard982a2232000-12-13 20:20:09 +0000664 if (!(atom = GlobalAddAtomA( MapSL(wc->lpszClassName) ))) return 0;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000665 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
Alexandre Julliard98779062000-12-07 23:39:16 +0000666 wc->cbClsExtra, wc->cbWndExtra )))
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000667 {
668 GlobalDeleteAtom( atom );
669 return 0;
670 }
671
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000672 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 +0000673 atom, (DWORD)wc->lpfnWndProc, hInstance,
674 wc->hbrBackground, wc->style, wc->cbClsExtra,
675 wc->cbWndExtra, classPtr );
676
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000677 classPtr->hIcon = wc->hIcon;
678 classPtr->hIconSm = wc->hIconSm;
679 classPtr->hCursor = wc->hCursor;
680 classPtr->hbrBackground = wc->hbrBackground;
681
Alexandre Julliard98779062000-12-07 23:39:16 +0000682 WINPROC_SetProc( &classPtr->winprocA, (HWINDOWPROC)wc->lpfnWndProc,
683 WIN_PROC_16, WIN_PROC_CLASS );
Alexandre Julliard982a2232000-12-13 20:20:09 +0000684 CLASS_SetMenuNameA( classPtr, MapSL(wc->lpszMenuName) );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000685 return atom;
686}
687
688
689/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000690 * RegisterClassExA (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000691 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000692ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* 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 = GlobalAddAtomA( 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 );
Alexandre Julliard98779062000-12-07 23:39:16 +0000703 return 0;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000704 }
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->winprocA, (HWINDOWPROC)wc->lpfnWndProc,
716 WIN_PROC_32A, WIN_PROC_CLASS );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000717 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
718 return atom;
719}
720
721
722/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000723 * RegisterClassExW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000724 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000725ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000726{
727 ATOM atom;
728 CLASS *classPtr;
729
Alexandre Julliardf681cd02000-08-23 19:18:44 +0000730 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
731
Alexandre Julliard77b99181997-09-14 17:17:23 +0000732 if (!(classPtr = CLASS_RegisterClass( atom, wc->hInstance, wc->style,
Alexandre Julliard98779062000-12-07 23:39:16 +0000733 wc->cbClsExtra, wc->cbWndExtra )))
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000734 {
735 GlobalDeleteAtom( atom );
736 return 0;
737 }
738
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000739 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 +0000740 atom, (DWORD)wc->lpfnWndProc, wc->hInstance,
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000741 wc->hbrBackground, wc->style, wc->cbClsExtra,
742 wc->cbWndExtra, classPtr );
743
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000744 classPtr->hIcon = (HICON16)wc->hIcon;
745 classPtr->hIconSm = (HICON16)wc->hIconSm;
746 classPtr->hCursor = (HCURSOR16)wc->hCursor;
747 classPtr->hbrBackground = (HBRUSH16)wc->hbrBackground;
Alexandre Julliard98779062000-12-07 23:39:16 +0000748 WINPROC_SetProc( &classPtr->winprocW, (HWINDOWPROC)wc->lpfnWndProc,
749 WIN_PROC_32W, WIN_PROC_CLASS );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000750 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
751 return atom;
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000752}
753
754
755/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000756 * UnregisterClass (USER.403)
Alexandre Julliard1285c2f1996-05-06 16:06:24 +0000757 */
Alexandre Julliardb849d792000-02-13 13:56:13 +0000758BOOL16 WINAPI UnregisterClass16( LPCSTR className, HINSTANCE16 hInstance )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000759{
Alexandre Julliardb849d792000-02-13 13:56:13 +0000760 return UnregisterClassA( className, GetExePtr( hInstance ) );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000761}
762
Alexandre Julliard401710d1993-09-04 10:09:32 +0000763/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000764 * UnregisterClassA (USER32.@)
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000765 *
Alexandre Julliard401710d1993-09-04 10:09:32 +0000766 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000767BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
Alexandre Julliard98779062000-12-07 23:39:16 +0000768{
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000769 TRACE("%s %x\n",debugres_a(className), hInstance);
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000770 return CLASS_UnregisterClass( GlobalFindAtomA( className ), hInstance );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000771}
772
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000773/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000774 * UnregisterClassW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000775 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000776BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
Alexandre Julliard98779062000-12-07 23:39:16 +0000777{
Alexandre Julliard359f497e1999-07-04 16:02:24 +0000778 TRACE("%s %x\n",debugres_w(className), hInstance);
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000779 return CLASS_UnregisterClass( GlobalFindAtomW( className ), hInstance );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000780}
781
Alexandre Julliard21979011997-03-05 08:22:35 +0000782
783/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000784 * GetClassWord (USER32.@)
Alexandre Julliard21979011997-03-05 08:22:35 +0000785 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000786WORD WINAPI GetClassWord( HWND hwnd, INT offset )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000787{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000788 CLASS *class;
Guy Albertelli2fa281f1999-04-24 11:54:40 +0000789 WORD retvalue = 0;
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000790
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000791 if (offset < 0) return GetClassLongA( hwnd, offset );
792
793 TRACE("%x %x\n",hwnd, offset);
794
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000795 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000796
797 if (offset <= class->cbClsExtra - sizeof(WORD))
798 retvalue = GET_WORD((char *)(class + 1) + offset);
799 else
800 SetLastError( ERROR_INVALID_INDEX );
801 release_class_ptr( class );
Guy Albertelli2fa281f1999-04-24 11:54:40 +0000802 return retvalue;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000803}
804
805
806/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000807 * GetClassLong (USER.131)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000808 */
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000809LONG WINAPI GetClassLong16( HWND16 hwnd16, INT16 offset )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000810{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000811 CLASS *class;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000812 LONG ret;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000813 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000814
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000815 TRACE("%x %d\n",hwnd, offset);
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000816
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000817 switch( offset )
818 {
Alexandre Julliard3051b641996-07-05 17:14:13 +0000819 case GCL_WNDPROC:
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000820 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000821 ret = (LONG)CLASS_GetProc( class, WIN_PROC_16 );
822 release_class_ptr( class );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000823 return ret;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000824 case GCL_MENUNAME:
Alexandre Julliardd7b76822001-12-20 00:19:40 +0000825 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
826 ret = (LONG)CLASS_GetMenuName16( class );
827 release_class_ptr( class );
828 return ret;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000829 default:
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000830 return GetClassLongA( hwnd, offset );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000831 }
Alexandre Julliard401710d1993-09-04 10:09:32 +0000832}
833
834
835/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000836 * GetClassLongA (USER32.@)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000837 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000838LONG WINAPI GetClassLongA( HWND hwnd, INT offset )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000839{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000840 CLASS *class;
841 LONG retvalue = 0;
842
843 TRACE("%x %d\n", hwnd, offset);
844
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000845 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000846
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000847 if (offset >= 0)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000848 {
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000849 if (offset <= class->cbClsExtra - sizeof(LONG))
850 retvalue = GET_DWORD((char *)(class + 1) + offset);
851 else
852 SetLastError( ERROR_INVALID_INDEX );
853 release_class_ptr( class );
854 return retvalue;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000855 }
Alexandre Julliardd44e4952001-08-20 18:09:39 +0000856
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000857 switch(offset)
858 {
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000859 case GCL_HBRBACKGROUND:
860 retvalue = (LONG)class->hbrBackground;
861 break;
862 case GCL_HCURSOR:
863 retvalue = (LONG)class->hCursor;
864 break;
865 case GCL_HICON:
866 retvalue = (LONG)class->hIcon;
867 break;
868 case GCL_HICONSM:
869 retvalue = (LONG)class->hIconSm;
870 break;
871 case GCL_STYLE:
872 retvalue = (LONG)class->style;
873 break;
874 case GCL_CBWNDEXTRA:
875 retvalue = (LONG)class->cbWndExtra;
876 break;
877 case GCL_CBCLSEXTRA:
878 retvalue = (LONG)class->cbClsExtra;
879 break;
880 case GCL_HMODULE:
881 retvalue = (LONG)class->hInstance;
882 break;
883 case GCL_WNDPROC:
884 retvalue = (LONG)CLASS_GetProc( class, WIN_PROC_32A );
885 break;
886 case GCL_MENUNAME:
887 retvalue = (LONG)CLASS_GetMenuNameA( class );
888 break;
889 case GCW_ATOM:
890 retvalue = (DWORD)class->atomName;
891 break;
892 default:
893 SetLastError( ERROR_INVALID_INDEX );
894 break;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +0000895 }
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000896 release_class_ptr( class );
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000897 return retvalue;
Alexandre Julliard401710d1993-09-04 10:09:32 +0000898}
899
900
901/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000902 * GetClassLongW (USER32.@)
Alexandre Julliard401710d1993-09-04 10:09:32 +0000903 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000904LONG WINAPI GetClassLongW( HWND hwnd, INT offset )
Alexandre Julliard401710d1993-09-04 10:09:32 +0000905{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000906 CLASS *class;
Francois Boisvert6b1b41c1999-03-14 17:25:32 +0000907 LONG retvalue;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000908
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000909 if (offset != GCL_WNDPROC && offset != GCL_MENUNAME)
Alexandre Julliarda3960291999-02-26 11:11:13 +0000910 return GetClassLongA( hwnd, offset );
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000911
912 TRACE("%x %d\n", hwnd, offset);
913
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000914 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000915
916 if (offset == GCL_WNDPROC)
917 retvalue = (LONG)CLASS_GetProc( class, WIN_PROC_32W );
918 else /* GCL_MENUNAME */
919 retvalue = (LONG)CLASS_GetMenuNameW( class );
920
921 release_class_ptr( class );
922 return retvalue;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000923}
924
925
926/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000927 * SetClassWord (USER32.@)
Alexandre Julliard21979011997-03-05 08:22:35 +0000928 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000929WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000930{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000931 CLASS *class;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000932 WORD retval = 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000933
934 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
935
936 TRACE("%x %d %x\n", hwnd, offset, newval);
937
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000938 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000939
940 if (offset <= class->cbClsExtra - sizeof(WORD))
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000941 {
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000942 void *ptr = (char *)(class + 1) + offset;
943 retval = GET_WORD(ptr);
944 PUT_WORD( ptr, newval );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000945 }
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000946 else SetLastError( ERROR_INVALID_INDEX );
947
948 release_class_ptr( class );
Alexandre Julliard401710d1993-09-04 10:09:32 +0000949 return retval;
950}
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000951
952
953/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000954 * SetClassLong (USER.132)
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000955 */
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000956LONG WINAPI SetClassLong16( HWND16 hwnd16, INT16 offset, LONG newval )
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000957{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000958 CLASS *class;
Alexandre Julliard3051b641996-07-05 17:14:13 +0000959 LONG retval;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000960 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000961
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000962 TRACE("%x %d %lx\n", hwnd, offset, newval);
Alexandre Julliard767e6f61998-08-09 12:47:43 +0000963
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000964 switch(offset)
965 {
966 case GCL_WNDPROC:
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000967 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000968 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_16 );
969 release_class_ptr( class );
Alexandre Julliard3051b641996-07-05 17:14:13 +0000970 return retval;
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000971 case GCL_MENUNAME:
Alexandre Julliardd23a82b2001-09-19 20:37:04 +0000972 newval = (LONG)MapSL( newval );
973 /* fall through */
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000974 default:
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000975 return SetClassLongA( hwnd, offset, newval );
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000976 }
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000977}
978
979
980/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +0000981 * SetClassLongA (USER32.@)
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000982 */
Alexandre Julliarda3960291999-02-26 11:11:13 +0000983LONG WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
Alexandre Julliard5f721f81994-01-04 20:14:34 +0000984{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000985 CLASS *class;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000986 LONG retval = 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000987
988 TRACE("%x %d %lx\n", hwnd, offset, newval);
989
Alexandre Julliard8fd26b92001-10-15 17:56:45 +0000990 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000991
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000992 if (offset >= 0)
993 {
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000994 if (offset <= class->cbClsExtra - sizeof(LONG))
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000995 {
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +0000996 void *ptr = (char *)(class + 1) + offset;
997 retval = GET_DWORD(ptr);
998 PUT_DWORD( ptr, newval );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +0000999 }
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001000 else SetLastError( ERROR_INVALID_INDEX );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001001 }
1002 else switch(offset)
1003 {
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001004 case GCL_MENUNAME:
1005 CLASS_SetMenuNameA( class, (LPCSTR)newval );
1006 retval = 0; /* Old value is now meaningless anyway */
1007 break;
1008 case GCL_WNDPROC:
1009 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32A );
1010 break;
1011 case GCL_HBRBACKGROUND:
1012 retval = (LONG)class->hbrBackground;
1013 class->hbrBackground = newval;
1014 break;
1015 case GCL_HCURSOR:
1016 retval = (LONG)class->hCursor;
1017 class->hCursor = newval;
1018 break;
1019 case GCL_HICON:
1020 retval = (LONG)class->hIcon;
1021 class->hIcon = newval;
1022 break;
1023 case GCL_HICONSM:
1024 retval = (LONG)class->hIconSm;
1025 class->hIconSm = newval;
1026 break;
1027 case GCL_STYLE:
1028 retval = (LONG)class->style;
1029 class->style = newval;
1030 break;
1031 case GCL_CBWNDEXTRA:
1032 retval = (LONG)class->cbWndExtra;
1033 class->cbWndExtra = newval;
1034 break;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001035 case GCL_HMODULE:
1036 retval = (LONG)class->hInstance;
1037 class->hInstance = newval;
1038 break;
1039 case GCW_ATOM:
1040 retval = (DWORD)class->atomName;
1041 class->atomName = newval;
1042 break;
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001043 case GCL_CBCLSEXTRA: /* cannot change this one */
1044 SetLastError( ERROR_INVALID_PARAMETER );
1045 break;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001046 default:
1047 SetLastError( ERROR_INVALID_INDEX );
1048 break;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001049 }
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001050 release_class_ptr( class );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001051 return retval;
1052}
1053
1054
1055/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001056 * SetClassLongW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001057 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001058LONG WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001059{
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001060 CLASS *class;
Alexandre Julliard3051b641996-07-05 17:14:13 +00001061 LONG retval;
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001062
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001063 if (offset != GCL_WNDPROC && offset != GCL_MENUNAME)
Alexandre Julliarda3960291999-02-26 11:11:13 +00001064 return SetClassLongA( hwnd, offset, newval );
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001065
1066 TRACE("%x %d %lx\n", hwnd, offset, newval);
1067
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001068 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001069
1070 if (offset == GCL_WNDPROC)
1071 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32W );
1072 else /* GCL_MENUNAME */
1073 {
1074 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
1075 retval = 0; /* Old value is now meaningless anyway */
Alexandre Julliard2d93d001996-05-21 15:01:41 +00001076 }
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001077 release_class_ptr( class );
1078 return retval;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001079}
1080
1081
1082/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001083 * GetClassNameA (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001084 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001085INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001086{
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001087 INT ret = GlobalGetAtomNameA( GetClassLongA( hwnd, GCW_ATOM ), buffer, count );
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001088
1089 TRACE("%x %s %x\n",hwnd, debugstr_a(buffer), count);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001090 return ret;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001091}
1092
1093
1094/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001095 * GetClassNameW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001096 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001097INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001098{
Alexandre Julliard8fd26b92001-10-15 17:56:45 +00001099 INT ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), buffer, count );
Alexandre Julliarde6d90ea2001-10-09 23:27:17 +00001100
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001101 TRACE("%x %s %x\n",hwnd, debugstr_w(buffer), count);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001102 return ret;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001103}
1104
1105
1106/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001107 * GetClassInfo (USER.404)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001108 */
Alexandre Julliard98779062000-12-07 23:39:16 +00001109BOOL16 WINAPI GetClassInfo16( HINSTANCE16 hInstance, SEGPTR name, WNDCLASS16 *wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001110{
1111 ATOM atom;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001112 CLASS *classPtr;
Alexandre Julliard3ed37e01994-11-07 18:20:42 +00001113
Alexandre Julliard982a2232000-12-13 20:20:09 +00001114 TRACE("%x %s %p\n",hInstance, debugres_a(MapSL(name)), wc);
Alexandre Julliard98779062000-12-07 23:39:16 +00001115
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001116 hInstance = GetExePtr( hInstance );
Alexandre Julliard982a2232000-12-13 20:20:09 +00001117 if (!(atom = GlobalFindAtomA( MapSL(name) )) ||
Alexandre Julliard670cdc41997-08-24 16:00:30 +00001118 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1119 return FALSE;
1120 if ((hInstance != classPtr->hInstance) &&
1121 !(classPtr->style & CS_GLOBALCLASS)) /*BWCC likes to pass hInstance=0*/
1122 return FALSE;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001123 wc->style = (UINT16)classPtr->style;
Alexandre Julliard98779062000-12-07 23:39:16 +00001124 wc->lpfnWndProc = CLASS_GetProc( classPtr, WIN_PROC_16 );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001125 wc->cbClsExtra = (INT16)classPtr->cbClsExtra;
1126 wc->cbWndExtra = (INT16)classPtr->cbWndExtra;
Joshua Thielen40a35aa2001-11-05 23:49:54 +00001127 wc->hInstance = classPtr->style & CS_GLOBALCLASS ? GetModuleHandle16("USER") : (HINSTANCE16)classPtr->hInstance;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001128 wc->hIcon = classPtr->hIcon;
1129 wc->hCursor = classPtr->hCursor;
1130 wc->hbrBackground = classPtr->hbrBackground;
Alexandre Julliard98779062000-12-07 23:39:16 +00001131 wc->lpszClassName = name;
Alexandre Julliardd7b76822001-12-20 00:19:40 +00001132 wc->lpszMenuName = CLASS_GetMenuName16( classPtr );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001133 return TRUE;
1134}
1135
1136
1137/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001138 * GetClassInfoA (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001139 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001140BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name,
1141 WNDCLASSA *wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001142{
1143 ATOM atom;
1144 CLASS *classPtr;
1145
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001146 TRACE("%x %p %p\n",hInstance, name, wc);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001147
1148 /* workaround: if hInstance=NULL you expect to get the system classes
1149 but this classes (as example from comctl32.dll SysListView) won't be
Andreas Mohr2caee712000-07-16 15:44:22 +00001150 registered with hInstance=NULL in WINE because of the late loading
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001151 of this dll. fixes file dialogs in WinWord95 (jsch)*/
1152
Alexandre Julliarda3960291999-02-26 11:11:13 +00001153 if (!(atom=GlobalFindAtomA(name)) || !(classPtr=CLASS_FindClassByAtom(atom,hInstance)))
Alexandre Julliard21979011997-03-05 08:22:35 +00001154 return FALSE;
1155
Noomen Hamza1040eaf2000-07-09 12:21:07 +00001156 if (!(classPtr->style & CS_GLOBALCLASS) &&
1157 classPtr->hInstance &&
1158 (hInstance != classPtr->hInstance))
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001159 {
1160 if (hInstance) return FALSE;
Noomen Hamza1040eaf2000-07-09 12:21:07 +00001161 WARN("systemclass %s (hInst=0) demanded but only class with hInst!=0 found\n",name);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001162 }
1163
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001164 wc->style = classPtr->style;
Alexandre Julliard98779062000-12-07 23:39:16 +00001165 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32A );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001166 wc->cbClsExtra = classPtr->cbClsExtra;
1167 wc->cbWndExtra = classPtr->cbWndExtra;
Noomen Hamza1040eaf2000-07-09 12:21:07 +00001168 wc->hInstance = hInstance;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001169 wc->hIcon = (HICON)classPtr->hIcon;
1170 wc->hCursor = (HCURSOR)classPtr->hCursor;
1171 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001172 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
Alexandre Julliard98779062000-12-07 23:39:16 +00001173 wc->lpszClassName = name;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001174 return TRUE;
1175}
1176
1177
1178/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001179 * GetClassInfoW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001180 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001181BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name,
1182 WNDCLASSW *wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001183{
1184 ATOM atom;
1185 CLASS *classPtr;
1186
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001187 TRACE("%x %p %p\n",hInstance, name, wc);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001188
Marcus Meissner438062171999-09-03 12:28:20 +00001189 if ( !(atom=GlobalFindAtomW(name)) ||
1190 !(classPtr=CLASS_FindClassByAtom(atom,hInstance))
1191 )
Alexandre Julliard21979011997-03-05 08:22:35 +00001192 return FALSE;
1193
Noomen Hamza1040eaf2000-07-09 12:21:07 +00001194 if (!(classPtr->style & CS_GLOBALCLASS) &&
1195 classPtr->hInstance &&
1196 (hInstance != classPtr->hInstance))
1197 {
1198 if (hInstance) return FALSE;
1199 WARN("systemclass %s (hInst=0) demanded but only class with hInst!=0 found\n",debugstr_w(name));
Marcus Meissner438062171999-09-03 12:28:20 +00001200 }
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001201 wc->style = classPtr->style;
Alexandre Julliard98779062000-12-07 23:39:16 +00001202 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32W );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001203 wc->cbClsExtra = classPtr->cbClsExtra;
1204 wc->cbWndExtra = classPtr->cbWndExtra;
Noomen Hamza1040eaf2000-07-09 12:21:07 +00001205 wc->hInstance = hInstance;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001206 wc->hIcon = (HICON)classPtr->hIcon;
1207 wc->hCursor = (HCURSOR)classPtr->hCursor;
1208 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001209 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
Alexandre Julliard98779062000-12-07 23:39:16 +00001210 wc->lpszClassName = name;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001211 return TRUE;
1212}
1213
1214
1215/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001216 * GetClassInfoEx (USER.398)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001217 *
1218 * FIXME: this is just a guess, I have no idea if GetClassInfoEx() is the
1219 * same in Win16 as in Win32. --AJ
1220 */
Alexandre Julliard98779062000-12-07 23:39:16 +00001221BOOL16 WINAPI GetClassInfoEx16( HINSTANCE16 hInstance, SEGPTR name, WNDCLASSEX16 *wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001222{
1223 ATOM atom;
1224 CLASS *classPtr;
Alexandre Julliard808cb041995-08-17 17:11:36 +00001225
Alexandre Julliard982a2232000-12-13 20:20:09 +00001226 TRACE("%x %s %p\n",hInstance,debugres_a( MapSL(name) ), wc);
Alexandre Julliard98779062000-12-07 23:39:16 +00001227
Alexandre Julliard808cb041995-08-17 17:11:36 +00001228 hInstance = GetExePtr( hInstance );
Alexandre Julliard982a2232000-12-13 20:20:09 +00001229 if (!(atom = GlobalFindAtomA( MapSL(name) )) ||
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001230 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
1231 (hInstance != classPtr->hInstance)) return FALSE;
1232 wc->style = classPtr->style;
Alexandre Julliard98779062000-12-07 23:39:16 +00001233 wc->lpfnWndProc = CLASS_GetProc( classPtr, WIN_PROC_16 );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001234 wc->cbClsExtra = (INT16)classPtr->cbClsExtra;
1235 wc->cbWndExtra = (INT16)classPtr->cbWndExtra;
1236 wc->hInstance = (HINSTANCE16)classPtr->hInstance;
1237 wc->hIcon = classPtr->hIcon;
1238 wc->hIconSm = classPtr->hIconSm;
1239 wc->hCursor = classPtr->hCursor;
1240 wc->hbrBackground = classPtr->hbrBackground;
1241 wc->lpszClassName = (SEGPTR)0;
Alexandre Julliardd7b76822001-12-20 00:19:40 +00001242 wc->lpszMenuName = CLASS_GetMenuName16( classPtr );
1243 wc->lpszClassName = name;
James Hatheway9fa09e72000-06-18 17:19:38 +00001244
1245 /* We must return the atom of the class here instead of just TRUE. */
1246 return atom;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001247}
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001248
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00001249
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001250/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001251 * GetClassInfoExA (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001252 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001253BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name,
1254 WNDCLASSEXA *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 = GlobalFindAtomA( name )) ||
Alexandre Julliarda0d77311998-09-13 16:32:00 +00001262 !(classPtr = CLASS_FindClassByAtom( atom, hInstance ))
1263 /*|| (hInstance != classPtr->hInstance) */ ) return FALSE;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001264 wc->style = classPtr->style;
Alexandre Julliard98779062000-12-07 23:39:16 +00001265 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32A );
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_GetMenuNameA( 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 Julliarde2bfa4c1996-05-16 18:21:06 +00001278}
1279
1280
1281/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001282 * GetClassInfoExW (USER32.@)
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001283 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001284BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name,
1285 WNDCLASSEXW *wc )
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001286{
1287 ATOM atom;
1288 CLASS *classPtr;
1289
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001290 TRACE("%x %p %p\n",hInstance, name, wc);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001291
Alexandre Julliarda3960291999-02-26 11:11:13 +00001292 if (!(atom = GlobalFindAtomW( name )) ||
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001293 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
1294 (hInstance != classPtr->hInstance)) return FALSE;
1295 wc->style = classPtr->style;
Alexandre Julliard98779062000-12-07 23:39:16 +00001296 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32W );
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001297 wc->cbClsExtra = classPtr->cbClsExtra;
1298 wc->cbWndExtra = classPtr->cbWndExtra;
1299 wc->hInstance = classPtr->hInstance;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001300 wc->hIcon = (HICON)classPtr->hIcon;
1301 wc->hIconSm = (HICON)classPtr->hIconSm;
1302 wc->hCursor = (HCURSOR)classPtr->hCursor;
1303 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001304 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
Alexandre Julliard98779062000-12-07 23:39:16 +00001305 wc->lpszClassName = name;
1306
James Hatheway9fa09e72000-06-18 17:19:38 +00001307 /* We must return the atom of the class here instead of just TRUE. */
1308 return atom;
Alexandre Julliard5f721f81994-01-04 20:14:34 +00001309}
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001310
1311
Alexandre Julliardf899ef02001-07-23 00:04:00 +00001312#if 0 /* toolhelp is in kernel, so this cannot work */
1313
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001314/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001315 * ClassFirst (TOOLHELP.69)
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001316 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001317BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001318{
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001319 TRACE("%p\n",pClassEntry);
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001320 pClassEntry->wNext = 1;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001321 return ClassNext16( pClassEntry );
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001322}
1323
1324
1325/***********************************************************************
Patrik Stridvall2ece70e2000-12-22 01:38:01 +00001326 * ClassNext (TOOLHELP.70)
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001327 */
Alexandre Julliarda3960291999-02-26 11:11:13 +00001328BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001329{
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001330 int i;
1331 CLASS *class = firstClass;
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001332
Alexandre Julliard359f497e1999-07-04 16:02:24 +00001333 TRACE("%p\n",pClassEntry);
Alexandre Julliard767e6f61998-08-09 12:47:43 +00001334
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001335 if (!pClassEntry->wNext) return FALSE;
1336 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1337 if (!class)
1338 {
1339 pClassEntry->wNext = 0;
1340 return FALSE;
1341 }
Alexandre Julliard1285c2f1996-05-06 16:06:24 +00001342 pClassEntry->hInst = class->hInstance;
Alexandre Julliard2ace16a1996-04-28 15:09:19 +00001343 pClassEntry->wNext++;
Alexandre Julliarda3960291999-02-26 11:11:13 +00001344 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
Alexandre Julliarde2bfa4c1996-05-16 18:21:06 +00001345 sizeof(pClassEntry->szClassName) );
Alexandre Julliarde2abbb11995-03-19 17:39:39 +00001346 return TRUE;
1347}
Alexandre Julliardf899ef02001-07-23 00:04:00 +00001348#endif