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
23 #include "wine/port.h"
34 #include "wine/unicode.h"
36 #include "user_private.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 HCURSOR hCursor; /* Default cursor */
60 HBRUSH hbrBackground; /* Default background */
61 ATOM atomName; /* Name of the class */
62 WCHAR name[MAX_ATOM_LEN + 1];
65 static struct list class_list = LIST_INIT( class_list );
67 #define CLASS_OTHER_PROCESS ((CLASS *)1)
69 /***********************************************************************
72 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
74 WND *ptr = WIN_GetPtr( hwnd );
78 if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP) return ptr->class;
79 if (!write_access) return CLASS_OTHER_PROCESS;
81 /* modifying classes in other processes is not allowed */
82 if (ptr == WND_DESKTOP || IsWindow( hwnd ))
84 SetLastError( ERROR_ACCESS_DENIED );
88 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
93 /***********************************************************************
96 static inline void release_class_ptr( CLASS *ptr )
102 /***********************************************************************
105 ATOM get_int_atom_value( LPCWSTR name )
109 if (IS_INTRESOURCE(name)) return LOWORD(name);
110 if (*name++ != '#') return 0;
113 if (*name < '0' || *name > '9') return 0;
114 ret = ret * 10 + *name++ - '0';
115 if (ret > 0xffff) return 0;
121 /***********************************************************************
124 * Set class info with the wine server.
126 static BOOL set_server_info( HWND hwnd, INT offset, LONG_PTR newval, UINT size )
130 SERVER_START_REQ( set_class_info )
133 req->extra_offset = -1;
137 req->flags = SET_CLASS_ATOM;
140 req->flags = SET_CLASS_STYLE;
144 req->flags = SET_CLASS_WINEXTRA;
145 req->win_extra = newval;
148 req->flags = SET_CLASS_INSTANCE;
149 req->instance = (void *)newval;
152 assert( offset >= 0 );
153 req->flags = SET_CLASS_EXTRA;
154 req->extra_offset = offset;
155 req->extra_size = size;
156 if ( size == sizeof(LONG) )
158 LONG newlong = newval;
159 memcpy( &req->extra_value, &newlong, sizeof(LONG) );
162 memcpy( &req->extra_value, &newval, sizeof(LONG_PTR) );
165 ret = !wine_server_call_err( req );
172 /***********************************************************************
175 * Get the menu name as a ASCII string.
177 static inline LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
179 if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
180 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
184 /***********************************************************************
187 * Get the menu name as a Unicode string.
189 static inline LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
191 return classPtr->menuName;
195 /***********************************************************************
198 * Set the menu name in a class structure by copying the string.
200 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
202 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
205 DWORD lenA = strlen(name) + 1;
206 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
207 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
208 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
209 memcpy( classPtr->menuName + lenW, name, lenA );
211 else classPtr->menuName = (LPWSTR)name;
215 /***********************************************************************
218 * Set the menu name in a class structure by copying the string.
220 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
222 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
225 DWORD lenW = strlenW(name) + 1;
226 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
227 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
228 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
229 WideCharToMultiByte( CP_ACP, 0, name, lenW,
230 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
232 else classPtr->menuName = (LPWSTR)name;
236 /***********************************************************************
239 * Free a class structure.
241 static void CLASS_FreeClass( CLASS *classPtr )
243 TRACE("%p\n", classPtr);
247 if (classPtr->dce) free_dce( classPtr->dce, 0 );
248 list_remove( &classPtr->entry );
249 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
250 DeleteObject( classPtr->hbrBackground );
251 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
252 HeapFree( GetProcessHeap(), 0, classPtr );
257 /***********************************************************************
258 * CLASS_FreeModuleClasses
260 void CLASS_FreeModuleClasses( HMODULE16 hModule )
262 struct list *ptr, *next;
264 TRACE("0x%08x\n", hModule);
267 for (ptr = list_head( &class_list ); ptr; ptr = next)
269 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
270 next = list_next( &class_list, ptr );
271 if (class->hInstance == HINSTANCE_32(hModule))
275 SERVER_START_REQ( destroy_class )
277 req->atom = class->atomName;
278 req->instance = class->hInstance;
279 ret = !wine_server_call_err( req );
282 if (ret) CLASS_FreeClass( class );
289 /***********************************************************************
292 * Return a pointer to the class.
293 * hinstance has been normalized by the caller.
295 static CLASS *CLASS_FindClass( LPCWSTR name, HINSTANCE hinstance )
298 ATOM atom = get_int_atom_value( name );
302 LIST_FOR_EACH( ptr, &class_list )
304 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
307 if (class->atomName != atom) continue;
311 if (!name || strcmpiW( class->name, name )) continue;
313 if (!hinstance || !class->local || class->hInstance == hinstance)
315 TRACE("%s %p -> %p\n", debugstr_w(name), hinstance, class);
320 TRACE("%s %p -> not found\n", debugstr_w(name), hinstance);
325 /***********************************************************************
326 * CLASS_RegisterClass
328 * The real RegisterClass() functionality.
330 static CLASS *CLASS_RegisterClass( LPCWSTR name, HINSTANCE hInstance, BOOL local,
331 DWORD style, INT classExtra, INT winExtra )
336 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
337 debugstr_w(name), hInstance, style, classExtra, winExtra );
339 /* Fix the extra bytes value */
341 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
342 WARN("Class extra bytes %d is > 40\n", classExtra);
343 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
344 WARN("Win extra bytes %d is > 40\n", winExtra );
346 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
347 if (!classPtr) return NULL;
349 classPtr->atomName = get_int_atom_value( name );
350 if (!classPtr->atomName && name) strcpyW( classPtr->name, name );
351 else GlobalGetAtomNameW( classPtr->atomName, classPtr->name, sizeof(classPtr->name)/sizeof(WCHAR) );
353 SERVER_START_REQ( create_class )
357 req->instance = hInstance;
358 req->extra = classExtra;
359 req->win_extra = winExtra;
360 req->client_ptr = classPtr;
361 req->atom = classPtr->atomName;
362 if (!req->atom && name) wine_server_add_data( req, name, strlenW(name) * sizeof(WCHAR) );
363 ret = !wine_server_call_err( req );
364 classPtr->atomName = reply->atom;
369 HeapFree( GetProcessHeap(), 0, classPtr );
373 classPtr->style = style;
374 classPtr->local = local;
375 classPtr->cbWndExtra = winExtra;
376 classPtr->cbClsExtra = classExtra;
377 classPtr->hInstance = hInstance;
379 /* Other non-null values must be set by caller */
382 if (local) list_add_head( &class_list, &classPtr->entry );
383 else list_add_tail( &class_list, &classPtr->entry );
388 /***********************************************************************
391 * Register a builtin control class.
392 * This allows having both ASCII and Unicode winprocs for the same class.
394 static WNDPROC register_builtin( const struct builtin_class_descr *descr )
398 if (!(classPtr = CLASS_RegisterClass( descr->name, user32_module, FALSE,
399 descr->style, 0, descr->extra ))) return 0;
401 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
402 classPtr->hbrBackground = descr->brush;
403 classPtr->winproc = WINPROC_AllocProc( descr->procA, descr->procW );
404 release_class_ptr( classPtr );
405 return classPtr->winproc;
409 /***********************************************************************
410 * CLASS_RegisterBuiltinClasses
412 void CLASS_RegisterBuiltinClasses(void)
414 register_builtin( &DESKTOP_builtin_class );
415 register_builtin( &BUTTON_builtin_class );
416 register_builtin( &COMBO_builtin_class );
417 register_builtin( &COMBOLBOX_builtin_class );
418 register_builtin( &DIALOG_builtin_class );
419 EDIT_winproc_handle = register_builtin( &EDIT_builtin_class );
420 register_builtin( &ICONTITLE_builtin_class );
421 register_builtin( &LISTBOX_builtin_class );
422 register_builtin( &MDICLIENT_builtin_class );
423 register_builtin( &MENU_builtin_class );
424 register_builtin( &SCROLL_builtin_class );
425 register_builtin( &STATIC_builtin_class );
427 /* the DefWindowProc winprocs are magic too */
428 WINPROC_AllocProc( DefWindowProcA, DefWindowProcW );
432 /***********************************************************************
435 WNDPROC get_class_winproc( CLASS *class )
437 return class->winproc;
441 /***********************************************************************
444 struct dce *get_class_dce( CLASS *class )
450 /***********************************************************************
453 struct dce *set_class_dce( CLASS *class, struct dce *dce )
455 if (class->dce) return class->dce; /* already set, don't change it */
461 /***********************************************************************
462 * RegisterClassA (USER32.@)
464 * Register a window class.
467 * >0: Unique identifier
470 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
474 wcex.cbSize = sizeof(wcex);
475 wcex.style = wc->style;
476 wcex.lpfnWndProc = wc->lpfnWndProc;
477 wcex.cbClsExtra = wc->cbClsExtra;
478 wcex.cbWndExtra = wc->cbWndExtra;
479 wcex.hInstance = wc->hInstance;
480 wcex.hIcon = wc->hIcon;
481 wcex.hCursor = wc->hCursor;
482 wcex.hbrBackground = wc->hbrBackground;
483 wcex.lpszMenuName = wc->lpszMenuName;
484 wcex.lpszClassName = wc->lpszClassName;
486 return RegisterClassExA( &wcex );
490 /***********************************************************************
491 * RegisterClassW (USER32.@)
493 * See RegisterClassA.
495 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
499 wcex.cbSize = sizeof(wcex);
500 wcex.style = wc->style;
501 wcex.lpfnWndProc = wc->lpfnWndProc;
502 wcex.cbClsExtra = wc->cbClsExtra;
503 wcex.cbWndExtra = wc->cbWndExtra;
504 wcex.hInstance = wc->hInstance;
505 wcex.hIcon = wc->hIcon;
506 wcex.hCursor = wc->hCursor;
507 wcex.hbrBackground = wc->hbrBackground;
508 wcex.lpszMenuName = wc->lpszMenuName;
509 wcex.lpszClassName = wc->lpszClassName;
511 return RegisterClassExW( &wcex );
515 /***********************************************************************
516 * RegisterClassExA (USER32.@)
518 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
524 if (wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
525 wc->hInstance == user32_module) /* we can't register a class for user32 */
527 SetLastError( ERROR_INVALID_PARAMETER );
530 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
532 if (!IS_INTRESOURCE(wc->lpszClassName))
534 WCHAR name[MAX_ATOM_LEN + 1];
536 if (!MultiByteToWideChar( CP_ACP, 0, wc->lpszClassName, -1, name, MAX_ATOM_LEN + 1 )) return 0;
537 classPtr = CLASS_RegisterClass( name, instance, !(wc->style & CS_GLOBALCLASS),
538 wc->style, wc->cbClsExtra, wc->cbWndExtra );
542 classPtr = CLASS_RegisterClass( (LPCWSTR)wc->lpszClassName, instance,
543 !(wc->style & CS_GLOBALCLASS), wc->style,
544 wc->cbClsExtra, wc->cbWndExtra );
546 if (!classPtr) return 0;
547 atom = classPtr->atomName;
549 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
550 debugstr_a(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
551 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
553 classPtr->hIcon = wc->hIcon;
554 classPtr->hIconSm = wc->hIconSm;
555 classPtr->hCursor = wc->hCursor;
556 classPtr->hbrBackground = wc->hbrBackground;
557 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, NULL );
558 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
559 release_class_ptr( classPtr );
564 /***********************************************************************
565 * RegisterClassExW (USER32.@)
567 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
573 if (wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
574 wc->hInstance == user32_module) /* we can't register a class for user32 */
576 SetLastError( ERROR_INVALID_PARAMETER );
579 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
581 if (!(classPtr = CLASS_RegisterClass( wc->lpszClassName, instance, !(wc->style & CS_GLOBALCLASS),
582 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
585 atom = classPtr->atomName;
587 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
588 debugstr_w(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
589 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
591 classPtr->hIcon = wc->hIcon;
592 classPtr->hIconSm = wc->hIconSm;
593 classPtr->hCursor = wc->hCursor;
594 classPtr->hbrBackground = wc->hbrBackground;
595 classPtr->winproc = WINPROC_AllocProc( NULL, wc->lpfnWndProc );
596 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
597 release_class_ptr( classPtr );
602 /***********************************************************************
603 * UnregisterClassA (USER32.@)
605 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
607 if (!IS_INTRESOURCE(className))
609 WCHAR name[MAX_ATOM_LEN + 1];
611 if (!MultiByteToWideChar( CP_ACP, 0, className, -1, name, MAX_ATOM_LEN + 1 ))
613 return UnregisterClassW( name, hInstance );
615 return UnregisterClassW( (LPCWSTR)className, hInstance );
618 /***********************************************************************
619 * UnregisterClassW (USER32.@)
621 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
623 CLASS *classPtr = NULL;
625 SERVER_START_REQ( destroy_class )
627 req->instance = hInstance;
628 if (!(req->atom = get_int_atom_value(className)) && className)
629 wine_server_add_data( req, className, strlenW(className) * sizeof(WCHAR) );
630 if (!wine_server_call_err( req )) classPtr = reply->client_ptr;
634 if (classPtr) CLASS_FreeClass( classPtr );
635 return (classPtr != NULL);
639 /***********************************************************************
640 * GetClassWord (USER32.@)
642 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
647 if (offset < 0) return GetClassLongA( hwnd, offset );
649 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
651 if (class == CLASS_OTHER_PROCESS)
653 SERVER_START_REQ( set_class_info )
657 req->extra_offset = offset;
658 req->extra_size = sizeof(retvalue);
659 if (!wine_server_call_err( req ))
660 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
666 if (offset <= class->cbClsExtra - sizeof(WORD))
667 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
669 SetLastError( ERROR_INVALID_INDEX );
670 release_class_ptr( class );
675 /***********************************************************************
678 * Implementation of GetClassLong(Ptr)A/W
680 static ULONG_PTR CLASS_GetClassLong( HWND hwnd, INT offset, UINT size,
684 ULONG_PTR retvalue = 0;
686 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
688 if (class == CLASS_OTHER_PROCESS)
690 SERVER_START_REQ( set_class_info )
694 req->extra_offset = (offset >= 0) ? offset : -1;
695 req->extra_size = (offset >= 0) ? size : 0;
696 if (!wine_server_call_err( req ))
700 case GCLP_HBRBACKGROUND:
706 FIXME( "offset %d (%s) not supported on other process window %p\n",
707 offset, SPY_GetClassLongOffsetName(offset), hwnd );
708 SetLastError( ERROR_INVALID_HANDLE );
711 retvalue = reply->old_style;
714 retvalue = reply->old_win_extra;
717 retvalue = reply->old_extra;
720 retvalue = (ULONG_PTR)reply->old_instance;
723 retvalue = reply->old_atom;
728 if (size == sizeof(DWORD))
731 memcpy( &retdword, &reply->old_extra_value, sizeof(DWORD) );
735 memcpy( &retvalue, &reply->old_extra_value,
738 else SetLastError( ERROR_INVALID_INDEX );
749 if (offset <= class->cbClsExtra - size)
751 if (size == sizeof(DWORD))
754 memcpy( &retdword, (char *)(class + 1) + offset, sizeof(DWORD) );
758 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(ULONG_PTR) );
761 SetLastError( ERROR_INVALID_INDEX );
762 release_class_ptr( class );
768 case GCLP_HBRBACKGROUND:
769 retvalue = (ULONG_PTR)class->hbrBackground;
772 retvalue = (ULONG_PTR)class->hCursor;
775 retvalue = (ULONG_PTR)class->hIcon;
778 retvalue = (ULONG_PTR)class->hIconSm;
781 retvalue = class->style;
784 retvalue = class->cbWndExtra;
787 retvalue = class->cbClsExtra;
790 retvalue = (ULONG_PTR)class->hInstance;
793 retvalue = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
796 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
798 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
800 retvalue = (ULONG_PTR)CLASS_GetMenuNameA( class );
803 retvalue = class->atomName;
806 SetLastError( ERROR_INVALID_INDEX );
809 release_class_ptr( class );
814 /***********************************************************************
815 * GetClassLongW (USER32.@)
817 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
819 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), TRUE );
824 /***********************************************************************
825 * GetClassLongA (USER32.@)
827 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
829 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), FALSE );
833 /***********************************************************************
834 * SetClassWord (USER32.@)
836 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
841 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
843 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
845 SERVER_START_REQ( set_class_info )
848 req->flags = SET_CLASS_EXTRA;
849 req->extra_offset = offset;
850 req->extra_size = sizeof(newval);
851 memcpy( &req->extra_value, &newval, sizeof(newval) );
852 if (!wine_server_call_err( req ))
854 void *ptr = (char *)(class + 1) + offset;
855 memcpy( &retval, ptr, sizeof(retval) );
856 memcpy( ptr, &newval, sizeof(newval) );
860 release_class_ptr( class );
865 /***********************************************************************
868 * Implementation of SetClassLong(Ptr)A/W
870 static ULONG_PTR CLASS_SetClassLong( HWND hwnd, INT offset, LONG_PTR newval,
871 UINT size, BOOL unicode )
874 ULONG_PTR retval = 0;
876 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
880 if (set_server_info( hwnd, offset, newval, size ))
882 void *ptr = (char *)(class + 1) + offset;
883 if ( size == sizeof(LONG) )
886 LONG newlong = newval;
887 memcpy( &retdword, ptr, sizeof(DWORD) );
888 memcpy( ptr, &newlong, sizeof(LONG) );
893 memcpy( &retval, ptr, sizeof(ULONG_PTR) );
894 memcpy( ptr, &newval, sizeof(LONG_PTR) );
902 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
904 CLASS_SetMenuNameA( class, (LPCSTR)newval );
905 retval = 0; /* Old value is now meaningless anyway */
908 retval = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
909 class->winproc = WINPROC_AllocProc( unicode ? NULL : (WNDPROC)newval,
910 unicode ? (WNDPROC)newval : NULL );
912 case GCLP_HBRBACKGROUND:
913 retval = (ULONG_PTR)class->hbrBackground;
914 class->hbrBackground = (HBRUSH)newval;
917 retval = (ULONG_PTR)class->hCursor;
918 class->hCursor = (HCURSOR)newval;
921 retval = (ULONG_PTR)class->hIcon;
922 class->hIcon = (HICON)newval;
925 retval = (ULONG_PTR)class->hIconSm;
926 class->hIconSm = (HICON)newval;
929 if (!set_server_info( hwnd, offset, newval, size )) break;
930 retval = class->style;
931 class->style = newval;
934 if (!set_server_info( hwnd, offset, newval, size )) break;
935 retval = class->cbWndExtra;
936 class->cbWndExtra = newval;
939 if (!set_server_info( hwnd, offset, newval, size )) break;
940 retval = (ULONG_PTR)class->hInstance;
941 class->hInstance = (HINSTANCE)newval;
944 if (!set_server_info( hwnd, offset, newval, size )) break;
945 retval = class->atomName;
946 class->atomName = newval;
947 GlobalGetAtomNameW( newval, class->name, sizeof(class->name)/sizeof(WCHAR) );
949 case GCL_CBCLSEXTRA: /* cannot change this one */
950 SetLastError( ERROR_INVALID_PARAMETER );
953 SetLastError( ERROR_INVALID_INDEX );
956 release_class_ptr( class );
961 /***********************************************************************
962 * SetClassLongW (USER32.@)
964 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
966 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), TRUE );
970 /***********************************************************************
971 * SetClassLongA (USER32.@)
973 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
975 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), FALSE );
979 /***********************************************************************
980 * GetClassNameA (USER32.@)
982 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
984 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
987 if (count <= 0) return 0;
988 if (!GetClassNameW( hwnd, tmpbuf, sizeof(tmpbuf)/sizeof(WCHAR) )) return 0;
989 RtlUnicodeToMultiByteN( buffer, count - 1, &len, tmpbuf, strlenW(tmpbuf) * sizeof(WCHAR) );
995 /***********************************************************************
996 * GetClassNameW (USER32.@)
998 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
1003 TRACE("%p %p %d\n", hwnd, buffer, count);
1005 if (count <= 0) return 0;
1007 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
1009 if (class == CLASS_OTHER_PROCESS)
1011 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
1013 ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), tmpbuf, MAX_ATOM_LEN + 1 );
1016 ret = min(count - 1, ret);
1017 memcpy(buffer, tmpbuf, ret * sizeof(WCHAR));
1023 lstrcpynW( buffer, class->name, count );
1024 release_class_ptr( class );
1025 ret = strlenW( buffer );
1031 /***********************************************************************
1032 * RealGetWindowClassA (USER32.@)
1034 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1036 return GetClassNameA( hwnd, buffer, count );
1040 /***********************************************************************
1041 * RealGetWindowClassW (USER32.@)
1043 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1045 return GetClassNameW( hwnd, buffer, count );
1049 /***********************************************************************
1050 * GetClassInfoA (USER32.@)
1052 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1055 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1059 wc->style = wcex.style;
1060 wc->lpfnWndProc = wcex.lpfnWndProc;
1061 wc->cbClsExtra = wcex.cbClsExtra;
1062 wc->cbWndExtra = wcex.cbWndExtra;
1063 wc->hInstance = wcex.hInstance;
1064 wc->hIcon = wcex.hIcon;
1065 wc->hCursor = wcex.hCursor;
1066 wc->hbrBackground = wcex.hbrBackground;
1067 wc->lpszMenuName = wcex.lpszMenuName;
1068 wc->lpszClassName = wcex.lpszClassName;
1074 /***********************************************************************
1075 * GetClassInfoW (USER32.@)
1077 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1080 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1084 wc->style = wcex.style;
1085 wc->lpfnWndProc = wcex.lpfnWndProc;
1086 wc->cbClsExtra = wcex.cbClsExtra;
1087 wc->cbWndExtra = wcex.cbWndExtra;
1088 wc->hInstance = wcex.hInstance;
1089 wc->hIcon = wcex.hIcon;
1090 wc->hCursor = wcex.hCursor;
1091 wc->hbrBackground = wcex.hbrBackground;
1092 wc->lpszMenuName = wcex.lpszMenuName;
1093 wc->lpszClassName = wcex.lpszClassName;
1099 /***********************************************************************
1100 * GetClassInfoExA (USER32.@)
1102 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1107 TRACE("%p %s %p\n", hInstance, debugstr_a(name), wc);
1109 if (!hInstance) hInstance = user32_module;
1111 if (!IS_INTRESOURCE(name))
1113 WCHAR nameW[MAX_ATOM_LEN + 1];
1114 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, sizeof(nameW)/sizeof(WCHAR) ))
1116 classPtr = CLASS_FindClass( nameW, hInstance );
1118 else classPtr = CLASS_FindClass( (LPCWSTR)name, hInstance );
1122 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1125 wc->style = classPtr->style;
1126 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, FALSE );
1127 wc->cbClsExtra = classPtr->cbClsExtra;
1128 wc->cbWndExtra = classPtr->cbWndExtra;
1129 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1130 wc->hIcon = classPtr->hIcon;
1131 wc->hIconSm = classPtr->hIconSm;
1132 wc->hCursor = classPtr->hCursor;
1133 wc->hbrBackground = classPtr->hbrBackground;
1134 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1135 wc->lpszClassName = name;
1136 atom = classPtr->atomName;
1137 release_class_ptr( classPtr );
1139 /* We must return the atom of the class here instead of just TRUE. */
1144 /***********************************************************************
1145 * GetClassInfoExW (USER32.@)
1147 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1152 TRACE("%p %s %p\n", hInstance, debugstr_w(name), wc);
1154 if (!hInstance) hInstance = user32_module;
1156 if (!(classPtr = CLASS_FindClass( name, hInstance )))
1158 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1161 wc->style = classPtr->style;
1162 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, TRUE );
1163 wc->cbClsExtra = classPtr->cbClsExtra;
1164 wc->cbWndExtra = classPtr->cbWndExtra;
1165 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1166 wc->hIcon = (HICON)classPtr->hIcon;
1167 wc->hIconSm = (HICON)classPtr->hIconSm;
1168 wc->hCursor = (HCURSOR)classPtr->hCursor;
1169 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1170 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1171 wc->lpszClassName = name;
1172 atom = classPtr->atomName;
1173 release_class_ptr( classPtr );
1175 /* We must return the atom of the class here instead of just TRUE. */
1180 #if 0 /* toolhelp is in kernel, so this cannot work */
1182 /***********************************************************************
1183 * ClassFirst (TOOLHELP.69)
1185 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1187 TRACE("%p\n",pClassEntry);
1188 pClassEntry->wNext = 1;
1189 return ClassNext16( pClassEntry );
1193 /***********************************************************************
1194 * ClassNext (TOOLHELP.70)
1196 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1199 CLASS *class = firstClass;
1201 TRACE("%p\n",pClassEntry);
1203 if (!pClassEntry->wNext) return FALSE;
1204 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1207 pClassEntry->wNext = 0;
1210 pClassEntry->hInst = class->hInstance;
1211 pClassEntry->wNext++;
1212 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1213 sizeof(pClassEntry->szClassName) );
1218 /* 64bit versions */
1220 #ifdef GetClassLongPtrA
1221 #undef GetClassLongPtrA
1224 #ifdef GetClassLongPtrW
1225 #undef GetClassLongPtrW
1228 #ifdef SetClassLongPtrA
1229 #undef SetClassLongPtrA
1232 #ifdef SetClassLongPtrW
1233 #undef SetClassLongPtrW
1236 /***********************************************************************
1237 * GetClassLongPtrA (USER32.@)
1239 ULONG_PTR WINAPI GetClassLongPtrA( HWND hwnd, INT offset )
1241 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), FALSE );
1244 /***********************************************************************
1245 * GetClassLongPtrW (USER32.@)
1247 ULONG_PTR WINAPI GetClassLongPtrW( HWND hwnd, INT offset )
1249 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), TRUE );
1252 /***********************************************************************
1253 * SetClassLongPtrW (USER32.@)
1255 ULONG_PTR WINAPI SetClassLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
1257 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), TRUE );
1260 /***********************************************************************
1261 * SetClassLongPtrA (USER32.@)
1263 ULONG_PTR WINAPI SetClassLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
1265 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), FALSE );