ntoskrnl.exe/tests: Fix path buffer allocation size.
[wine.git] / dlls / user32 / class.c
blob5383b6771fbfc12e3f9794c0a3a9438731cc519c
1 /*
2 * Window classes functions
4 * Copyright 1993, 1996, 2003 Alexandre Julliard
5 * Copyright 1998 Juergen Schmied (jsch)
7 * 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.
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.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <string.h>
30 #include "winerror.h"
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "wine/unicode.h"
35 #include "win.h"
36 #include "user_private.h"
37 #include "controls.h"
38 #include "wine/server.h"
39 #include "wine/list.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(class);
44 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
46 typedef struct tagCLASS
48 struct list entry; /* Entry in class list */
49 UINT style; /* Class style */
50 BOOL local; /* Local class? */
51 WNDPROC winproc; /* Window procedure */
52 INT cbClsExtra; /* Class extra bytes */
53 INT cbWndExtra; /* Window extra bytes */
54 LPWSTR menuName; /* Default menu name (Unicode followed by ASCII) */
55 struct dce *dce; /* Opaque pointer to class DCE */
56 HINSTANCE hInstance; /* Module that created the task */
57 HICON hIcon; /* Default icon */
58 HICON hIconSm; /* Default small icon */
59 HICON hIconSmIntern; /* Internal small icon, derived from hIcon */
60 HCURSOR hCursor; /* Default cursor */
61 HBRUSH hbrBackground; /* Default background */
62 ATOM atomName; /* Name of the class */
63 WCHAR name[MAX_ATOM_LEN + 1];
64 WCHAR *basename; /* Base name for redirected classes, pointer within 'name'. */
65 } CLASS;
67 static struct list class_list = LIST_INIT( class_list );
68 static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
70 #define CLASS_OTHER_PROCESS ((CLASS *)1)
72 /***********************************************************************
73 * get_class_ptr
75 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
77 WND *ptr = WIN_GetPtr( hwnd );
79 if (ptr)
81 if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP) return ptr->class;
82 if (!write_access) return CLASS_OTHER_PROCESS;
84 /* modifying classes in other processes is not allowed */
85 if (ptr == WND_DESKTOP || IsWindow( hwnd ))
87 SetLastError( ERROR_ACCESS_DENIED );
88 return NULL;
91 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
92 return NULL;
96 /***********************************************************************
97 * release_class_ptr
99 static inline void release_class_ptr( CLASS *ptr )
101 USER_Unlock();
105 /***********************************************************************
106 * get_int_atom_value
108 ATOM get_int_atom_value( LPCWSTR name )
110 UINT ret = 0;
112 if (IS_INTRESOURCE(name)) return LOWORD(name);
113 if (*name++ != '#') return 0;
114 while (*name)
116 if (*name < '0' || *name > '9') return 0;
117 ret = ret * 10 + *name++ - '0';
118 if (ret > 0xffff) return 0;
120 return ret;
124 /***********************************************************************
125 * is_comctl32_class
127 static BOOL is_comctl32_class( const WCHAR *name )
129 static const WCHAR classesW[][20] =
131 {'C','o','m','b','o','B','o','x','E','x','3','2',0},
132 {'m','s','c','t','l','s','_','h','o','t','k','e','y','3','2',0},
133 {'m','s','c','t','l','s','_','p','r','o','g','r','e','s','s','3','2',0},
134 {'m','s','c','t','l','s','_','s','t','a','t','u','s','b','a','r','3','2',0},
135 {'m','s','c','t','l','s','_','t','r','a','c','k','b','a','r','3','2',0},
136 {'m','s','c','t','l','s','_','u','p','d','o','w','n','3','2',0},
137 {'N','a','t','i','v','e','F','o','n','t','C','t','l',0},
138 {'R','e','B','a','r','W','i','n','d','o','w','3','2',0},
139 {'S','y','s','A','n','i','m','a','t','e','3','2',0},
140 {'S','y','s','D','a','t','e','T','i','m','e','P','i','c','k','3','2',0},
141 {'S','y','s','H','e','a','d','e','r','3','2',0},
142 {'S','y','s','I','P','A','d','d','r','e','s','s','3','2',0},
143 {'S','y','s','L','i','n','k',0},
144 {'S','y','s','L','i','s','t','V','i','e','w','3','2',0},
145 {'S','y','s','M','o','n','t','h','C','a','l','3','2',0},
146 {'S','y','s','P','a','g','e','r',0},
147 {'S','y','s','T','a','b','C','o','n','t','r','o','l','3','2',0},
148 {'S','y','s','T','r','e','e','V','i','e','w','3','2',0},
149 {'T','o','o','l','b','a','r','W','i','n','d','o','w','3','2',0},
150 {'t','o','o','l','t','i','p','s','_','c','l','a','s','s','3','2',0},
153 int min = 0, max = ARRAY_SIZE( classesW ) - 1;
155 while (min <= max)
157 int res, pos = (min + max) / 2;
158 if (!(res = strcmpiW( name, classesW[pos] ))) return TRUE;
159 if (res < 0) max = pos - 1;
160 else min = pos + 1;
162 return FALSE;
165 static BOOL is_builtin_class( const WCHAR *name )
167 static const WCHAR classesW[][20] =
169 {'I','M','E',0},
170 {'M','D','I','C','l','i','e','n','t',0},
171 {'S','c','r','o','l','l','b','a','r',0},
174 int min = 0, max = ARRAY_SIZE( classesW ) - 1;
176 while (min <= max)
178 int res, pos = (min + max) / 2;
179 if (!(res = strcmpiW( name, classesW[pos] ))) return TRUE;
180 if (res < 0) max = pos - 1;
181 else min = pos + 1;
183 return FALSE;
186 /***********************************************************************
187 * set_server_info
189 * Set class info with the wine server.
191 static BOOL set_server_info( HWND hwnd, INT offset, LONG_PTR newval, UINT size )
193 BOOL ret;
195 SERVER_START_REQ( set_class_info )
197 req->window = wine_server_user_handle( hwnd );
198 req->extra_offset = -1;
199 switch(offset)
201 case GCW_ATOM:
202 req->flags = SET_CLASS_ATOM;
203 req->atom = LOWORD(newval);
204 break;
205 case GCL_STYLE:
206 req->flags = SET_CLASS_STYLE;
207 req->style = newval;
208 break;
209 case GCL_CBWNDEXTRA:
210 req->flags = SET_CLASS_WINEXTRA;
211 req->win_extra = newval;
212 break;
213 case GCLP_HMODULE:
214 req->flags = SET_CLASS_INSTANCE;
215 req->instance = wine_server_client_ptr( (void *)newval );
216 break;
217 default:
218 assert( offset >= 0 );
219 req->flags = SET_CLASS_EXTRA;
220 req->extra_offset = offset;
221 req->extra_size = size;
222 if ( size == sizeof(LONG) )
224 LONG newlong = newval;
225 memcpy( &req->extra_value, &newlong, sizeof(LONG) );
227 else
228 memcpy( &req->extra_value, &newval, sizeof(LONG_PTR) );
229 break;
231 ret = !wine_server_call_err( req );
233 SERVER_END_REQ;
234 return ret;
238 /***********************************************************************
239 * CLASS_GetMenuNameA
241 * Get the menu name as a ASCII string.
243 static inline LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
245 if (IS_INTRESOURCE(classPtr->menuName)) return (LPSTR)classPtr->menuName;
246 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
250 /***********************************************************************
251 * CLASS_GetMenuNameW
253 * Get the menu name as a Unicode string.
255 static inline LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
257 return classPtr->menuName;
261 /***********************************************************************
262 * CLASS_SetMenuNameA
264 * Set the menu name in a class structure by copying the string.
266 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
268 if (!IS_INTRESOURCE(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
269 if (!IS_INTRESOURCE(name))
271 DWORD lenA = strlen(name) + 1;
272 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
273 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
274 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
275 memcpy( classPtr->menuName + lenW, name, lenA );
277 else classPtr->menuName = (LPWSTR)name;
281 /***********************************************************************
282 * CLASS_SetMenuNameW
284 * Set the menu name in a class structure by copying the string.
286 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
288 if (!IS_INTRESOURCE(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
289 if (!IS_INTRESOURCE(name))
291 DWORD lenW = strlenW(name) + 1;
292 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
293 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
294 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
295 WideCharToMultiByte( CP_ACP, 0, name, lenW,
296 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
298 else classPtr->menuName = (LPWSTR)name;
302 /***********************************************************************
303 * CLASS_FreeClass
305 * Free a class structure.
307 static void CLASS_FreeClass( CLASS *classPtr )
309 TRACE("%p\n", classPtr);
311 USER_Lock();
313 if (classPtr->dce) free_dce( classPtr->dce, 0 );
314 list_remove( &classPtr->entry );
315 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
316 DeleteObject( classPtr->hbrBackground );
317 DestroyIcon( classPtr->hIconSmIntern );
318 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
319 HeapFree( GetProcessHeap(), 0, classPtr );
320 USER_Unlock();
323 const WCHAR *CLASS_GetVersionedName( const WCHAR *name, UINT *basename_offset, WCHAR *combined, BOOL register_class )
325 ACTCTX_SECTION_KEYED_DATA data;
326 struct wndclass_redirect_data
328 ULONG size;
329 DWORD res;
330 ULONG name_len;
331 ULONG name_offset;
332 ULONG module_len;
333 ULONG module_offset;
334 } *wndclass;
335 const WCHAR *module, *ret;
336 UNICODE_STRING name_us;
337 HMODULE hmod;
338 UINT offset;
340 if (!basename_offset)
341 basename_offset = &offset;
343 *basename_offset = 0;
345 if (IS_INTRESOURCE( name ))
346 return name;
348 if (is_comctl32_class( name ) || is_builtin_class( name ))
349 return name;
351 data.cbSize = sizeof(data);
352 RtlInitUnicodeString(&name_us, name);
353 if (RtlFindActivationContextSectionString(0, NULL, ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION,
354 &name_us, &data))
355 return name;
357 wndclass = (struct wndclass_redirect_data *)data.lpData;
358 *basename_offset = wndclass->name_len / sizeof(WCHAR) - strlenW(name);
360 module = (const WCHAR *)((BYTE *)data.lpSectionBase + wndclass->module_offset);
361 if (!(hmod = GetModuleHandleW( module )))
362 hmod = LoadLibraryW( module );
364 /* Combined name is used to register versioned class name. Base name part will match exactly
365 original class name and won't be reused from context data. */
366 ret = (const WCHAR *)((BYTE *)wndclass + wndclass->name_offset);
367 if (combined)
369 memcpy(combined, ret, *basename_offset * sizeof(WCHAR));
370 strcpyW(&combined[*basename_offset], name);
371 ret = combined;
374 if (register_class && hmod)
376 BOOL found = FALSE;
377 struct list *ptr;
379 USER_Lock();
381 LIST_FOR_EACH( ptr, &class_list )
383 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
384 if (strcmpiW( class->name, ret )) continue;
385 if (!class->local || class->hInstance == hmod)
387 found = TRUE;
388 break;
392 USER_Unlock();
394 if (!found)
396 BOOL (WINAPI *pRegisterClassNameW)(const WCHAR *class);
398 pRegisterClassNameW = (void *)GetProcAddress(hmod, "RegisterClassNameW");
399 if (pRegisterClassNameW)
400 pRegisterClassNameW(name);
404 return ret;
407 /***********************************************************************
408 * CLASS_FindClass
410 * Return a pointer to the class.
412 static CLASS *CLASS_FindClass( LPCWSTR name, HINSTANCE hinstance )
414 static const WCHAR comctl32W[] = {'c','o','m','c','t','l','3','2','.','d','l','l',0};
415 struct list *ptr;
416 ATOM atom = get_int_atom_value( name );
418 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
420 if (!name) return NULL;
422 name = CLASS_GetVersionedName( name, NULL, NULL, TRUE );
424 for (;;)
426 USER_Lock();
428 LIST_FOR_EACH( ptr, &class_list )
430 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
431 if (atom)
433 if (class->atomName != atom) continue;
435 else
437 if (strcmpiW( class->name, name )) continue;
439 if (!class->local || class->hInstance == hinstance)
441 TRACE("%s %p -> %p\n", debugstr_w(name), hinstance, class);
442 return class;
445 USER_Unlock();
447 if (atom) break;
448 if (!is_comctl32_class( name )) break;
449 if (GetModuleHandleW( comctl32W )) break;
450 if (!LoadLibraryW( comctl32W )) break;
451 TRACE( "%s retrying after loading comctl32\n", debugstr_w(name) );
454 TRACE("%s %p -> not found\n", debugstr_w(name), hinstance);
455 return NULL;
458 /***********************************************************************
459 * CLASS_RegisterClass
461 * The real RegisterClass() functionality.
463 static CLASS *CLASS_RegisterClass( LPCWSTR name, UINT basename_offset, HINSTANCE hInstance, BOOL local,
464 DWORD style, INT classExtra, INT winExtra )
466 CLASS *classPtr;
467 BOOL ret;
469 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
470 debugstr_w(name), hInstance, style, classExtra, winExtra );
472 /* Fix the extra bytes value */
474 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
475 WARN("Class extra bytes %d is > 40\n", classExtra);
476 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
477 WARN("Win extra bytes %d is > 40\n", winExtra );
479 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
480 if (!classPtr) return NULL;
482 classPtr->atomName = get_int_atom_value( name );
483 classPtr->basename = classPtr->name;
484 if (!classPtr->atomName && name)
486 strcpyW( classPtr->name, name );
487 classPtr->basename += basename_offset;
489 else GlobalGetAtomNameW( classPtr->atomName, classPtr->name, ARRAY_SIZE( classPtr->name ));
491 SERVER_START_REQ( create_class )
493 req->local = local;
494 req->style = style;
495 req->instance = wine_server_client_ptr( hInstance );
496 req->extra = classExtra;
497 req->win_extra = winExtra;
498 req->client_ptr = wine_server_client_ptr( classPtr );
499 req->atom = classPtr->atomName;
500 req->name_offset = basename_offset;
501 if (!req->atom && name) wine_server_add_data( req, name, strlenW(name) * sizeof(WCHAR) );
502 ret = !wine_server_call_err( req );
503 classPtr->atomName = reply->atom;
505 SERVER_END_REQ;
506 if (!ret)
508 HeapFree( GetProcessHeap(), 0, classPtr );
509 return NULL;
512 classPtr->style = style;
513 classPtr->local = local;
514 classPtr->cbWndExtra = winExtra;
515 classPtr->cbClsExtra = classExtra;
516 classPtr->hInstance = hInstance;
518 /* Other non-null values must be set by caller */
520 USER_Lock();
521 if (local) list_add_head( &class_list, &classPtr->entry );
522 else list_add_tail( &class_list, &classPtr->entry );
523 return classPtr;
527 /***********************************************************************
528 * register_builtin
530 * Register a builtin control class.
531 * This allows having both ASCII and Unicode winprocs for the same class.
533 static void register_builtin( const struct builtin_class_descr *descr )
535 CLASS *classPtr;
537 if (!(classPtr = CLASS_RegisterClass( descr->name, 0, user32_module, FALSE,
538 descr->style, 0, descr->extra ))) return;
540 if (descr->cursor) classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
541 classPtr->hbrBackground = descr->brush;
542 classPtr->winproc = BUILTIN_WINPROC( descr->proc );
543 release_class_ptr( classPtr );
547 /***********************************************************************
548 * register_builtins
550 static BOOL WINAPI register_builtins( INIT_ONCE *once, void *param, void **context )
552 register_builtin( &BUTTON_builtin_class );
553 register_builtin( &COMBO_builtin_class );
554 register_builtin( &COMBOLBOX_builtin_class );
555 register_builtin( &DIALOG_builtin_class );
556 register_builtin( &EDIT_builtin_class );
557 register_builtin( &ICONTITLE_builtin_class );
558 register_builtin( &LISTBOX_builtin_class );
559 register_builtin( &MDICLIENT_builtin_class );
560 register_builtin( &MENU_builtin_class );
561 register_builtin( &SCROLL_builtin_class );
562 register_builtin( &STATIC_builtin_class );
563 register_builtin( &IME_builtin_class );
564 return TRUE;
568 /***********************************************************************
569 * register_builtin_classes
571 void register_builtin_classes(void)
573 InitOnceExecuteOnce( &init_once, register_builtins, NULL, NULL );
577 /***********************************************************************
578 * register_desktop_class
580 void register_desktop_class(void)
582 register_builtin( &DESKTOP_builtin_class );
583 register_builtin( &MESSAGE_builtin_class );
587 /***********************************************************************
588 * get_class_winproc
590 WNDPROC get_class_winproc( CLASS *class )
592 return class->winproc;
596 /***********************************************************************
597 * get_class_dce
599 struct dce *get_class_dce( CLASS *class )
601 return class->dce;
605 /***********************************************************************
606 * set_class_dce
608 struct dce *set_class_dce( CLASS *class, struct dce *dce )
610 if (class->dce) return class->dce; /* already set, don't change it */
611 class->dce = dce;
612 return dce;
616 /***********************************************************************
617 * RegisterClassA (USER32.@)
619 * Register a window class.
621 * RETURNS
622 * >0: Unique identifier
623 * 0: Failure
625 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
627 WNDCLASSEXA wcex;
629 wcex.cbSize = sizeof(wcex);
630 wcex.style = wc->style;
631 wcex.lpfnWndProc = wc->lpfnWndProc;
632 wcex.cbClsExtra = wc->cbClsExtra;
633 wcex.cbWndExtra = wc->cbWndExtra;
634 wcex.hInstance = wc->hInstance;
635 wcex.hIcon = wc->hIcon;
636 wcex.hCursor = wc->hCursor;
637 wcex.hbrBackground = wc->hbrBackground;
638 wcex.lpszMenuName = wc->lpszMenuName;
639 wcex.lpszClassName = wc->lpszClassName;
640 wcex.hIconSm = 0;
641 return RegisterClassExA( &wcex );
645 /***********************************************************************
646 * RegisterClassW (USER32.@)
648 * See RegisterClassA.
650 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
652 WNDCLASSEXW wcex;
654 wcex.cbSize = sizeof(wcex);
655 wcex.style = wc->style;
656 wcex.lpfnWndProc = wc->lpfnWndProc;
657 wcex.cbClsExtra = wc->cbClsExtra;
658 wcex.cbWndExtra = wc->cbWndExtra;
659 wcex.hInstance = wc->hInstance;
660 wcex.hIcon = wc->hIcon;
661 wcex.hCursor = wc->hCursor;
662 wcex.hbrBackground = wc->hbrBackground;
663 wcex.lpszMenuName = wc->lpszMenuName;
664 wcex.lpszClassName = wc->lpszClassName;
665 wcex.hIconSm = 0;
666 return RegisterClassExW( &wcex );
670 /***********************************************************************
671 * RegisterClassExA (USER32.@)
673 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
675 WCHAR name[MAX_ATOM_LEN + 1], combined[MAX_ATOM_LEN + 1];
676 const WCHAR *classname = NULL;
677 ATOM atom;
678 CLASS *classPtr;
679 HINSTANCE instance;
681 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
683 if (wc->cbSize != sizeof(*wc) || wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
684 wc->hInstance == user32_module) /* we can't register a class for user32 */
686 SetLastError( ERROR_INVALID_PARAMETER );
687 return 0;
689 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
691 if (!IS_INTRESOURCE(wc->lpszClassName))
693 UINT basename_offset;
694 if (!MultiByteToWideChar( CP_ACP, 0, wc->lpszClassName, -1, name, MAX_ATOM_LEN + 1 )) return 0;
695 classname = CLASS_GetVersionedName( name, &basename_offset, combined, FALSE );
696 classPtr = CLASS_RegisterClass( classname, basename_offset, instance, !(wc->style & CS_GLOBALCLASS),
697 wc->style, wc->cbClsExtra, wc->cbWndExtra );
699 else
701 classPtr = CLASS_RegisterClass( (LPCWSTR)wc->lpszClassName, 0, instance,
702 !(wc->style & CS_GLOBALCLASS), wc->style,
703 wc->cbClsExtra, wc->cbWndExtra );
705 if (!classPtr) return 0;
706 atom = classPtr->atomName;
708 TRACE("name=%s%s%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
709 debugstr_a(wc->lpszClassName), classname != name ? "->" : "", classname != name ? debugstr_w(classname) : "",
710 atom, wc->lpfnWndProc, instance, wc->hbrBackground, wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
712 classPtr->hIcon = wc->hIcon;
713 classPtr->hIconSm = wc->hIconSm;
714 classPtr->hIconSmIntern = wc->hIcon && !wc->hIconSm ?
715 CopyImage( wc->hIcon, IMAGE_ICON,
716 GetSystemMetrics( SM_CXSMICON ),
717 GetSystemMetrics( SM_CYSMICON ),
718 LR_COPYFROMRESOURCE ) : NULL;
719 classPtr->hCursor = wc->hCursor;
720 classPtr->hbrBackground = wc->hbrBackground;
721 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, FALSE );
722 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
723 release_class_ptr( classPtr );
724 return atom;
728 /***********************************************************************
729 * RegisterClassExW (USER32.@)
731 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
733 WCHAR name[MAX_ATOM_LEN + 1];
734 const WCHAR *classname;
735 UINT basename_offset;
736 ATOM atom;
737 CLASS *classPtr;
738 HINSTANCE instance;
740 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
742 if (wc->cbSize != sizeof(*wc) || wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
743 wc->hInstance == user32_module) /* we can't register a class for user32 */
745 SetLastError( ERROR_INVALID_PARAMETER );
746 return 0;
748 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
750 classname = CLASS_GetVersionedName( wc->lpszClassName, &basename_offset, name, FALSE );
751 if (!(classPtr = CLASS_RegisterClass( classname, basename_offset, instance, !(wc->style & CS_GLOBALCLASS),
752 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
753 return 0;
755 atom = classPtr->atomName;
757 TRACE("name=%s%s%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
758 debugstr_w(wc->lpszClassName), classname != wc->lpszClassName ? "->" : "",
759 classname != wc->lpszClassName ? debugstr_w(classname) : "", atom, wc->lpfnWndProc, instance,
760 wc->hbrBackground, wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
762 classPtr->hIcon = wc->hIcon;
763 classPtr->hIconSm = wc->hIconSm;
764 classPtr->hIconSmIntern = wc->hIcon && !wc->hIconSm ?
765 CopyImage( wc->hIcon, IMAGE_ICON,
766 GetSystemMetrics( SM_CXSMICON ),
767 GetSystemMetrics( SM_CYSMICON ),
768 LR_COPYFROMRESOURCE ) : NULL;
769 classPtr->hCursor = wc->hCursor;
770 classPtr->hbrBackground = wc->hbrBackground;
771 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, TRUE );
772 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
773 release_class_ptr( classPtr );
774 return atom;
778 /***********************************************************************
779 * UnregisterClassA (USER32.@)
781 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
783 if (!IS_INTRESOURCE(className))
785 WCHAR name[MAX_ATOM_LEN + 1];
787 if (!MultiByteToWideChar( CP_ACP, 0, className, -1, name, MAX_ATOM_LEN + 1 ))
788 return FALSE;
789 return UnregisterClassW( name, hInstance );
791 return UnregisterClassW( (LPCWSTR)className, hInstance );
794 /***********************************************************************
795 * UnregisterClassW (USER32.@)
797 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
799 CLASS *classPtr = NULL;
801 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
803 className = CLASS_GetVersionedName( className, NULL, NULL, FALSE );
804 SERVER_START_REQ( destroy_class )
806 req->instance = wine_server_client_ptr( hInstance );
807 if (!(req->atom = get_int_atom_value(className)) && className)
808 wine_server_add_data( req, className, strlenW(className) * sizeof(WCHAR) );
809 if (!wine_server_call_err( req )) classPtr = wine_server_get_ptr( reply->client_ptr );
811 SERVER_END_REQ;
813 if (classPtr) CLASS_FreeClass( classPtr );
814 return (classPtr != NULL);
818 /***********************************************************************
819 * GetClassWord (USER32.@)
821 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
823 CLASS *class;
824 WORD retvalue = 0;
826 if (offset < 0) return GetClassLongA( hwnd, offset );
828 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
830 if (class == CLASS_OTHER_PROCESS)
832 SERVER_START_REQ( set_class_info )
834 req->window = wine_server_user_handle( hwnd );
835 req->flags = 0;
836 req->extra_offset = offset;
837 req->extra_size = sizeof(retvalue);
838 if (!wine_server_call_err( req ))
839 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
841 SERVER_END_REQ;
842 return retvalue;
845 if (offset <= class->cbClsExtra - sizeof(WORD))
846 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
847 else
848 SetLastError( ERROR_INVALID_INDEX );
849 release_class_ptr( class );
850 return retvalue;
854 /***********************************************************************
855 * CLASS_GetClassLong
857 * Implementation of GetClassLong(Ptr)A/W
859 static ULONG_PTR CLASS_GetClassLong( HWND hwnd, INT offset, UINT size,
860 BOOL unicode )
862 CLASS *class;
863 ULONG_PTR retvalue = 0;
865 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
867 if (class == CLASS_OTHER_PROCESS)
869 SERVER_START_REQ( set_class_info )
871 req->window = wine_server_user_handle( hwnd );
872 req->flags = 0;
873 req->extra_offset = (offset >= 0) ? offset : -1;
874 req->extra_size = (offset >= 0) ? size : 0;
875 if (!wine_server_call_err( req ))
877 switch(offset)
879 case GCLP_HBRBACKGROUND:
880 case GCLP_HCURSOR:
881 case GCLP_HICON:
882 case GCLP_HICONSM:
883 case GCLP_WNDPROC:
884 case GCLP_MENUNAME:
885 FIXME( "offset %d (%s) not supported on other process window %p\n",
886 offset, SPY_GetClassLongOffsetName(offset), hwnd );
887 SetLastError( ERROR_INVALID_HANDLE );
888 break;
889 case GCL_STYLE:
890 retvalue = reply->old_style;
891 break;
892 case GCL_CBWNDEXTRA:
893 retvalue = reply->old_win_extra;
894 break;
895 case GCL_CBCLSEXTRA:
896 retvalue = reply->old_extra;
897 break;
898 case GCLP_HMODULE:
899 retvalue = (ULONG_PTR)wine_server_get_ptr( reply->old_instance );
900 break;
901 case GCW_ATOM:
902 retvalue = reply->old_atom;
903 break;
904 default:
905 if (offset >= 0)
907 if (size == sizeof(DWORD))
909 DWORD retdword;
910 memcpy( &retdword, &reply->old_extra_value, sizeof(DWORD) );
911 retvalue = retdword;
913 else
914 memcpy( &retvalue, &reply->old_extra_value,
915 sizeof(ULONG_PTR) );
917 else SetLastError( ERROR_INVALID_INDEX );
918 break;
922 SERVER_END_REQ;
923 return retvalue;
926 if (offset >= 0)
928 if (offset <= class->cbClsExtra - size)
930 if (size == sizeof(DWORD))
932 DWORD retdword;
933 memcpy( &retdword, (char *)(class + 1) + offset, sizeof(DWORD) );
934 retvalue = retdword;
936 else
937 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(ULONG_PTR) );
939 else
940 SetLastError( ERROR_INVALID_INDEX );
941 release_class_ptr( class );
942 return retvalue;
945 switch(offset)
947 case GCLP_HBRBACKGROUND:
948 retvalue = (ULONG_PTR)class->hbrBackground;
949 break;
950 case GCLP_HCURSOR:
951 retvalue = (ULONG_PTR)class->hCursor;
952 break;
953 case GCLP_HICON:
954 retvalue = (ULONG_PTR)class->hIcon;
955 break;
956 case GCLP_HICONSM:
957 retvalue = (ULONG_PTR)(class->hIconSm ? class->hIconSm : class->hIconSmIntern);
958 break;
959 case GCL_STYLE:
960 retvalue = class->style;
961 break;
962 case GCL_CBWNDEXTRA:
963 retvalue = class->cbWndExtra;
964 break;
965 case GCL_CBCLSEXTRA:
966 retvalue = class->cbClsExtra;
967 break;
968 case GCLP_HMODULE:
969 retvalue = (ULONG_PTR)class->hInstance;
970 break;
971 case GCLP_WNDPROC:
972 retvalue = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
973 break;
974 case GCLP_MENUNAME:
975 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
976 if (unicode)
977 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
978 else
979 retvalue = (ULONG_PTR)CLASS_GetMenuNameA( class );
980 break;
981 case GCW_ATOM:
982 retvalue = class->atomName;
983 break;
984 default:
985 SetLastError( ERROR_INVALID_INDEX );
986 break;
988 release_class_ptr( class );
989 return retvalue;
993 /***********************************************************************
994 * GetClassLongW (USER32.@)
996 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
998 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), TRUE );
1003 /***********************************************************************
1004 * GetClassLongA (USER32.@)
1006 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
1008 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), FALSE );
1012 /***********************************************************************
1013 * SetClassWord (USER32.@)
1015 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
1017 CLASS *class;
1018 WORD retval = 0;
1020 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
1022 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
1024 SERVER_START_REQ( set_class_info )
1026 req->window = wine_server_user_handle( hwnd );
1027 req->flags = SET_CLASS_EXTRA;
1028 req->extra_offset = offset;
1029 req->extra_size = sizeof(newval);
1030 memcpy( &req->extra_value, &newval, sizeof(newval) );
1031 if (!wine_server_call_err( req ))
1033 void *ptr = (char *)(class + 1) + offset;
1034 memcpy( &retval, ptr, sizeof(retval) );
1035 memcpy( ptr, &newval, sizeof(newval) );
1038 SERVER_END_REQ;
1039 release_class_ptr( class );
1040 return retval;
1044 /***********************************************************************
1045 * CLASS_SetClassLong
1047 * Implementation of SetClassLong(Ptr)A/W
1049 static ULONG_PTR CLASS_SetClassLong( HWND hwnd, INT offset, LONG_PTR newval,
1050 UINT size, BOOL unicode )
1052 CLASS *class;
1053 ULONG_PTR retval = 0;
1055 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
1057 if (offset >= 0)
1059 if (set_server_info( hwnd, offset, newval, size ))
1061 void *ptr = (char *)(class + 1) + offset;
1062 if ( size == sizeof(LONG) )
1064 DWORD retdword;
1065 LONG newlong = newval;
1066 memcpy( &retdword, ptr, sizeof(DWORD) );
1067 memcpy( ptr, &newlong, sizeof(LONG) );
1068 retval = retdword;
1070 else
1072 memcpy( &retval, ptr, sizeof(ULONG_PTR) );
1073 memcpy( ptr, &newval, sizeof(LONG_PTR) );
1077 else switch(offset)
1079 case GCLP_MENUNAME:
1080 if ( unicode )
1081 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
1082 else
1083 CLASS_SetMenuNameA( class, (LPCSTR)newval );
1084 retval = 0; /* Old value is now meaningless anyway */
1085 break;
1086 case GCLP_WNDPROC:
1087 retval = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
1088 class->winproc = WINPROC_AllocProc( (WNDPROC)newval, unicode );
1089 break;
1090 case GCLP_HBRBACKGROUND:
1091 retval = (ULONG_PTR)class->hbrBackground;
1092 class->hbrBackground = (HBRUSH)newval;
1093 break;
1094 case GCLP_HCURSOR:
1095 retval = (ULONG_PTR)class->hCursor;
1096 class->hCursor = (HCURSOR)newval;
1097 break;
1098 case GCLP_HICON:
1099 retval = (ULONG_PTR)class->hIcon;
1100 if (class->hIconSmIntern)
1102 DestroyIcon(class->hIconSmIntern);
1103 class->hIconSmIntern = NULL;
1105 if (newval && !class->hIconSm)
1106 class->hIconSmIntern = CopyImage( (HICON)newval, IMAGE_ICON,
1107 GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ),
1108 LR_COPYFROMRESOURCE );
1109 class->hIcon = (HICON)newval;
1110 break;
1111 case GCLP_HICONSM:
1112 retval = (ULONG_PTR)class->hIconSm;
1113 if (retval && !newval && class->hIcon)
1114 class->hIconSmIntern = CopyImage( class->hIcon, IMAGE_ICON,
1115 GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ),
1116 LR_COPYFROMRESOURCE );
1117 else if (newval && class->hIconSmIntern)
1119 DestroyIcon(class->hIconSmIntern);
1120 class->hIconSmIntern = NULL;
1122 class->hIconSm = (HICON)newval;
1123 break;
1124 case GCL_STYLE:
1125 if (!set_server_info( hwnd, offset, newval, size )) break;
1126 retval = class->style;
1127 class->style = newval;
1128 break;
1129 case GCL_CBWNDEXTRA:
1130 if (!set_server_info( hwnd, offset, newval, size )) break;
1131 retval = class->cbWndExtra;
1132 class->cbWndExtra = newval;
1133 break;
1134 case GCLP_HMODULE:
1135 if (!set_server_info( hwnd, offset, newval, size )) break;
1136 retval = (ULONG_PTR)class->hInstance;
1137 class->hInstance = (HINSTANCE)newval;
1138 break;
1139 case GCW_ATOM:
1140 if (!set_server_info( hwnd, offset, newval, size )) break;
1141 retval = class->atomName;
1142 class->atomName = newval;
1143 GlobalGetAtomNameW( newval, class->name, ARRAY_SIZE( class->name ));
1144 break;
1145 case GCL_CBCLSEXTRA: /* cannot change this one */
1146 SetLastError( ERROR_INVALID_PARAMETER );
1147 break;
1148 default:
1149 SetLastError( ERROR_INVALID_INDEX );
1150 break;
1152 release_class_ptr( class );
1153 return retval;
1157 /***********************************************************************
1158 * SetClassLongW (USER32.@)
1160 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
1162 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), TRUE );
1166 /***********************************************************************
1167 * SetClassLongA (USER32.@)
1169 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
1171 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), FALSE );
1175 /***********************************************************************
1176 * GetClassNameA (USER32.@)
1178 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
1180 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
1181 DWORD len;
1183 if (count <= 0) return 0;
1184 if (!GetClassNameW( hwnd, tmpbuf, ARRAY_SIZE( tmpbuf ))) return 0;
1185 RtlUnicodeToMultiByteN( buffer, count - 1, &len, tmpbuf, strlenW(tmpbuf) * sizeof(WCHAR) );
1186 buffer[len] = 0;
1187 return len;
1191 /***********************************************************************
1192 * GetClassNameW (USER32.@)
1194 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
1196 CLASS *class;
1197 INT ret;
1199 TRACE("%p %p %d\n", hwnd, buffer, count);
1201 if (count <= 0) return 0;
1203 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
1205 if (class == CLASS_OTHER_PROCESS)
1207 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
1208 ATOM atom = 0;
1210 SERVER_START_REQ( set_class_info )
1212 req->window = wine_server_user_handle( hwnd );
1213 req->flags = 0;
1214 req->extra_offset = -1;
1215 req->extra_size = 0;
1216 if (!wine_server_call_err( req ))
1217 atom = reply->base_atom;
1219 SERVER_END_REQ;
1221 ret = GlobalGetAtomNameW( atom, tmpbuf, MAX_ATOM_LEN + 1 );
1222 if (ret)
1224 ret = min(count - 1, ret);
1225 memcpy(buffer, tmpbuf, ret * sizeof(WCHAR));
1226 buffer[ret] = 0;
1229 else
1231 /* Return original name class was registered with. */
1232 lstrcpynW( buffer, class->basename, count );
1233 release_class_ptr( class );
1234 ret = strlenW( buffer );
1236 return ret;
1240 /***********************************************************************
1241 * RealGetWindowClassA (USER32.@)
1243 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1245 return GetClassNameA( hwnd, buffer, count );
1249 /***********************************************************************
1250 * RealGetWindowClassW (USER32.@)
1252 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1254 return GetClassNameW( hwnd, buffer, count );
1258 /***********************************************************************
1259 * GetClassInfoA (USER32.@)
1261 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1263 WNDCLASSEXA wcex;
1264 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1266 if (ret)
1268 wc->style = wcex.style;
1269 wc->lpfnWndProc = wcex.lpfnWndProc;
1270 wc->cbClsExtra = wcex.cbClsExtra;
1271 wc->cbWndExtra = wcex.cbWndExtra;
1272 wc->hInstance = wcex.hInstance;
1273 wc->hIcon = wcex.hIcon;
1274 wc->hCursor = wcex.hCursor;
1275 wc->hbrBackground = wcex.hbrBackground;
1276 wc->lpszMenuName = wcex.lpszMenuName;
1277 wc->lpszClassName = wcex.lpszClassName;
1279 return ret;
1283 /***********************************************************************
1284 * GetClassInfoW (USER32.@)
1286 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1288 WNDCLASSEXW wcex;
1289 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1291 if (ret)
1293 wc->style = wcex.style;
1294 wc->lpfnWndProc = wcex.lpfnWndProc;
1295 wc->cbClsExtra = wcex.cbClsExtra;
1296 wc->cbWndExtra = wcex.cbWndExtra;
1297 wc->hInstance = wcex.hInstance;
1298 wc->hIcon = wcex.hIcon;
1299 wc->hCursor = wcex.hCursor;
1300 wc->hbrBackground = wcex.hbrBackground;
1301 wc->lpszMenuName = wcex.lpszMenuName;
1302 wc->lpszClassName = wcex.lpszClassName;
1304 return ret;
1308 /***********************************************************************
1309 * GetClassInfoExA (USER32.@)
1311 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1313 ATOM atom;
1314 CLASS *classPtr;
1316 TRACE("%p %s %p\n", hInstance, debugstr_a(name), wc);
1318 if (!wc)
1320 SetLastError( ERROR_NOACCESS );
1321 return FALSE;
1324 if (!hInstance) hInstance = user32_module;
1326 if (!IS_INTRESOURCE(name))
1328 WCHAR nameW[MAX_ATOM_LEN + 1];
1329 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, ARRAY_SIZE( nameW )))
1330 return FALSE;
1331 classPtr = CLASS_FindClass( nameW, hInstance );
1333 else classPtr = CLASS_FindClass( (LPCWSTR)name, hInstance );
1335 if (!classPtr)
1337 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1338 return FALSE;
1340 wc->style = classPtr->style;
1341 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, FALSE );
1342 wc->cbClsExtra = classPtr->cbClsExtra;
1343 wc->cbWndExtra = classPtr->cbWndExtra;
1344 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1345 wc->hIcon = classPtr->hIcon;
1346 wc->hIconSm = classPtr->hIconSm ? classPtr->hIconSm : classPtr->hIconSmIntern;
1347 wc->hCursor = classPtr->hCursor;
1348 wc->hbrBackground = classPtr->hbrBackground;
1349 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1350 wc->lpszClassName = name;
1351 atom = classPtr->atomName;
1352 release_class_ptr( classPtr );
1354 /* We must return the atom of the class here instead of just TRUE. */
1355 return atom;
1359 /***********************************************************************
1360 * GetClassInfoExW (USER32.@)
1362 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1364 ATOM atom;
1365 CLASS *classPtr;
1367 TRACE("%p %s %p\n", hInstance, debugstr_w(name), wc);
1369 if (!wc)
1371 SetLastError( ERROR_NOACCESS );
1372 return FALSE;
1375 if (!hInstance) hInstance = user32_module;
1377 if (!(classPtr = CLASS_FindClass( name, hInstance )))
1379 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1380 return FALSE;
1382 wc->style = classPtr->style;
1383 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, TRUE );
1384 wc->cbClsExtra = classPtr->cbClsExtra;
1385 wc->cbWndExtra = classPtr->cbWndExtra;
1386 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1387 wc->hIcon = classPtr->hIcon;
1388 wc->hIconSm = classPtr->hIconSm ? classPtr->hIconSm : classPtr->hIconSmIntern;
1389 wc->hCursor = classPtr->hCursor;
1390 wc->hbrBackground = classPtr->hbrBackground;
1391 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1392 wc->lpszClassName = name;
1393 atom = classPtr->atomName;
1394 release_class_ptr( classPtr );
1396 /* We must return the atom of the class here instead of just TRUE. */
1397 return atom;
1401 #if 0 /* toolhelp is in kernel, so this cannot work */
1403 /***********************************************************************
1404 * ClassFirst (TOOLHELP.69)
1406 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1408 TRACE("%p\n",pClassEntry);
1409 pClassEntry->wNext = 1;
1410 return ClassNext16( pClassEntry );
1414 /***********************************************************************
1415 * ClassNext (TOOLHELP.70)
1417 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1419 int i;
1420 CLASS *class = firstClass;
1422 TRACE("%p\n",pClassEntry);
1424 if (!pClassEntry->wNext) return FALSE;
1425 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1426 if (!class)
1428 pClassEntry->wNext = 0;
1429 return FALSE;
1431 pClassEntry->hInst = class->hInstance;
1432 pClassEntry->wNext++;
1433 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1434 sizeof(pClassEntry->szClassName) );
1435 return TRUE;
1437 #endif
1439 /* 64bit versions */
1441 #ifdef GetClassLongPtrA
1442 #undef GetClassLongPtrA
1443 #endif
1445 #ifdef GetClassLongPtrW
1446 #undef GetClassLongPtrW
1447 #endif
1449 #ifdef SetClassLongPtrA
1450 #undef SetClassLongPtrA
1451 #endif
1453 #ifdef SetClassLongPtrW
1454 #undef SetClassLongPtrW
1455 #endif
1457 /***********************************************************************
1458 * GetClassLongPtrA (USER32.@)
1460 ULONG_PTR WINAPI GetClassLongPtrA( HWND hwnd, INT offset )
1462 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), FALSE );
1465 /***********************************************************************
1466 * GetClassLongPtrW (USER32.@)
1468 ULONG_PTR WINAPI GetClassLongPtrW( HWND hwnd, INT offset )
1470 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), TRUE );
1473 /***********************************************************************
1474 * SetClassLongPtrW (USER32.@)
1476 ULONG_PTR WINAPI SetClassLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
1478 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), TRUE );
1481 /***********************************************************************
1482 * SetClassLongPtrA (USER32.@)
1484 ULONG_PTR WINAPI SetClassLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
1486 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), FALSE );