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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
34 #include "wine/winuser16.h"
35 #include "wine/unicode.h"
37 #include "user_private.h"
41 #include "wine/server.h"
42 #include "wine/list.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(class);
47 typedef struct tagCLASS
49 struct list entry; /* Entry in class list */
50 UINT style; /* Class style */
51 BOOL local; /* Local class? */
52 WNDPROC winprocA; /* Window procedure (ASCII) */
53 WNDPROC winprocW; /* Window procedure (Unicode) */
54 INT cbClsExtra; /* Class extra bytes */
55 INT cbWndExtra; /* Window extra bytes */
56 LPWSTR menuName; /* Default menu name (Unicode followed by ASCII) */
57 SEGPTR segMenuName; /* Default menu name as SEGPTR */
58 struct tagDCE *dce; /* Class DCE (if CS_CLASSDC) */
59 HINSTANCE hInstance; /* Module that created the task */
60 HICON hIcon; /* Default icon */
61 HICON hIconSm; /* Default small icon */
62 HCURSOR hCursor; /* Default cursor */
63 HBRUSH hbrBackground; /* Default background */
64 ATOM atomName; /* Name of the class */
67 static struct list class_list = LIST_INIT( class_list );
68 static CLASS *desktop_class;
70 #define CLASS_OTHER_PROCESS ((CLASS *)1)
72 /***********************************************************************
75 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
77 WND *ptr = WIN_GetPtr( hwnd );
81 if (ptr != WND_OTHER_PROCESS) return ptr->class;
82 if (write_access && IsWindow( hwnd )) /* check other processes */
84 /* modifying classes in other processes is not allowed */
85 SetLastError( ERROR_ACCESS_DENIED );
88 return CLASS_OTHER_PROCESS;
90 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
95 /***********************************************************************
98 inline static void release_class_ptr( CLASS *ptr )
104 /***********************************************************************
107 * Set class info with the wine server.
109 static BOOL set_server_info( HWND hwnd, INT offset, LONG newval )
113 SERVER_START_REQ( set_class_info )
116 req->extra_offset = -1;
120 req->flags = SET_CLASS_ATOM;
123 req->flags = SET_CLASS_STYLE;
127 req->flags = SET_CLASS_WINEXTRA;
128 req->win_extra = newval;
131 req->flags = SET_CLASS_INSTANCE;
132 req->instance = (void *)newval;
135 assert( offset >= 0 );
136 req->flags = SET_CLASS_EXTRA;
137 req->extra_offset = offset;
138 req->extra_size = sizeof(newval);
139 memcpy( &req->extra_value, &newval, sizeof(newval) );
142 ret = !wine_server_call_err( req );
149 /***********************************************************************
152 * Get the class winproc for a given proc type
154 static WNDPROC16 CLASS_GetProc( CLASS *classPtr, WINDOWPROCTYPE type )
156 WNDPROC proc = classPtr->winprocA;
158 if (classPtr->winprocW)
160 /* if we have a Unicode proc, use it if we have no ASCII proc
161 * or if we have both and Unicode was requested
163 if (!proc || type == WIN_PROC_32W) proc = classPtr->winprocW;
165 return WINPROC_GetProc( proc, type );
169 /***********************************************************************
172 * Set the class winproc for a given proc type.
173 * Returns the previous window proc.
175 static WNDPROC16 CLASS_SetProc( CLASS *classPtr, WNDPROC newproc, WINDOWPROCTYPE type )
177 WNDPROC *proc = &classPtr->winprocA;
180 if (classPtr->winprocW)
182 /* if we have a Unicode proc, use it if we have no ASCII proc
183 * or if we have both and Unicode was requested
185 if (!*proc || type == WIN_PROC_32W) proc = &classPtr->winprocW;
187 ret = WINPROC_GetProc( *proc, type );
188 *proc = WINPROC_AllocProc( newproc, type );
189 /* now clear the one that we didn't set */
190 if (classPtr->winprocA && classPtr->winprocW)
192 if (proc == &classPtr->winprocA)
193 classPtr->winprocW = 0;
195 classPtr->winprocA = 0;
201 /***********************************************************************
204 * Get the menu name as a ASCII string.
206 inline static LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
208 if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
209 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
213 /***********************************************************************
214 * CLASS_GetMenuName16
216 * Get the menu name as a SEGPTR.
218 inline static SEGPTR CLASS_GetMenuName16( CLASS *classPtr )
220 if (!HIWORD(classPtr->menuName)) return (SEGPTR)classPtr->menuName;
221 if (!classPtr->segMenuName)
222 classPtr->segMenuName = MapLS( CLASS_GetMenuNameA(classPtr) );
223 return classPtr->segMenuName;
227 /***********************************************************************
230 * Get the menu name as a Unicode string.
232 inline static LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
234 return classPtr->menuName;
238 /***********************************************************************
241 * Set the menu name in a class structure by copying the string.
243 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
245 UnMapLS( classPtr->segMenuName );
246 classPtr->segMenuName = 0;
247 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
250 DWORD lenA = strlen(name) + 1;
251 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
252 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
253 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
254 memcpy( classPtr->menuName + lenW, name, lenA );
256 else classPtr->menuName = (LPWSTR)name;
260 /***********************************************************************
263 * Set the menu name in a class structure by copying the string.
265 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
267 UnMapLS( classPtr->segMenuName );
268 classPtr->segMenuName = 0;
269 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
272 DWORD lenW = strlenW(name) + 1;
273 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
274 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
275 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
276 WideCharToMultiByte( CP_ACP, 0, name, lenW,
277 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
279 else classPtr->menuName = (LPWSTR)name;
283 /***********************************************************************
286 * Free a class structure.
288 static void CLASS_FreeClass( CLASS *classPtr )
290 TRACE("%p\n", classPtr);
294 list_remove( &classPtr->entry );
295 if (classPtr->dce) DCE_FreeDCE( classPtr->dce );
296 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
297 DeleteObject( classPtr->hbrBackground );
298 UnMapLS( classPtr->segMenuName );
299 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
300 HeapFree( GetProcessHeap(), 0, classPtr );
305 /***********************************************************************
306 * CLASS_FreeModuleClasses
308 void CLASS_FreeModuleClasses( HMODULE16 hModule )
310 struct list *ptr, *next;
312 TRACE("0x%08x\n", hModule);
315 for (ptr = list_head( &class_list ); ptr; ptr = next)
317 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
318 next = list_next( &class_list, ptr );
319 if (class->hInstance == HINSTANCE_32(hModule))
323 SERVER_START_REQ( destroy_class )
325 req->atom = class->atomName;
326 req->instance = class->hInstance;
327 ret = !wine_server_call_err( req );
330 if (ret) CLASS_FreeClass( class );
337 /***********************************************************************
338 * CLASS_FindClassByAtom
340 * Return a pointer to the class.
341 * hinstance has been normalized by the caller.
343 static CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE hinstance )
349 LIST_FOR_EACH( ptr, &class_list )
351 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
352 if (class->atomName != atom) continue;
353 if (!hinstance || !class->local || class->hInstance == hinstance)
355 TRACE("0x%04x %p -> %p\n", atom, hinstance, class);
360 TRACE("0x%04x %p -> not found\n", atom, hinstance);
365 /***********************************************************************
366 * CLASS_RegisterClass
368 * The real RegisterClass() functionality.
369 * The atom is deleted no matter what.
371 static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE hInstance, BOOL local,
372 DWORD style, INT classExtra, INT winExtra )
377 TRACE("atom=0x%x hinst=%p style=0x%lx clExtr=0x%x winExtr=0x%x\n",
378 atom, hInstance, style, classExtra, winExtra );
380 /* Fix the extra bytes value */
382 if (classExtra < 0 || winExtra < 0)
384 SetLastError( ERROR_INVALID_PARAMETER );
387 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
388 WARN("Class extra bytes %d is > 40\n", classExtra);
389 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
390 WARN("Win extra bytes %d is > 40\n", winExtra );
392 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
395 GlobalDeleteAtom( atom );
399 SERVER_START_REQ( create_class )
404 req->instance = hInstance;
405 req->extra = classExtra;
406 req->win_extra = winExtra;
407 req->client_ptr = classPtr;
408 ret = !wine_server_call_err( req );
411 GlobalDeleteAtom( atom ); /* the server increased the atom ref count */
414 HeapFree( GetProcessHeap(), 0, classPtr );
418 classPtr->style = style;
419 classPtr->local = local;
420 classPtr->cbWndExtra = winExtra;
421 classPtr->cbClsExtra = classExtra;
422 classPtr->hInstance = hInstance;
423 classPtr->atomName = atom;
424 classPtr->dce = (style & CS_CLASSDC) ? DCE_AllocDCE( 0, DCE_CLASS_DC ) : NULL;
426 /* Other non-null values must be set by caller */
429 if (local) list_add_head( &class_list, &classPtr->entry );
430 else list_add_tail( &class_list, &classPtr->entry );
435 /***********************************************************************
438 * Register a builtin control class.
439 * This allows having both ASCII and Unicode winprocs for the same class.
441 static CLASS *register_builtin( const struct builtin_class_descr *descr )
446 if (!(atom = GlobalAddAtomA( descr->name ))) return 0;
448 if (!(classPtr = CLASS_RegisterClass( atom, user32_module, FALSE,
449 descr->style, 0, descr->extra ))) return 0;
451 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
452 classPtr->hbrBackground = descr->brush;
454 if (descr->procA) classPtr->winprocA = WINPROC_AllocProc( descr->procA, WIN_PROC_32A );
455 if (descr->procW) classPtr->winprocW = WINPROC_AllocProc( descr->procW, WIN_PROC_32W );
456 release_class_ptr( classPtr );
461 /***********************************************************************
462 * CLASS_RegisterBuiltinClasses
464 void CLASS_RegisterBuiltinClasses(void)
466 extern const struct builtin_class_descr BUTTON_builtin_class;
467 extern const struct builtin_class_descr COMBO_builtin_class;
468 extern const struct builtin_class_descr COMBOLBOX_builtin_class;
469 extern const struct builtin_class_descr DIALOG_builtin_class;
470 extern const struct builtin_class_descr DESKTOP_builtin_class;
471 extern const struct builtin_class_descr EDIT_builtin_class;
472 extern const struct builtin_class_descr ICONTITLE_builtin_class;
473 extern const struct builtin_class_descr LISTBOX_builtin_class;
474 extern const struct builtin_class_descr MDICLIENT_builtin_class;
475 extern const struct builtin_class_descr MENU_builtin_class;
476 extern const struct builtin_class_descr SCROLL_builtin_class;
477 extern const struct builtin_class_descr STATIC_builtin_class;
479 desktop_class = register_builtin( &DESKTOP_builtin_class );
480 register_builtin( &BUTTON_builtin_class );
481 register_builtin( &COMBO_builtin_class );
482 register_builtin( &COMBOLBOX_builtin_class );
483 register_builtin( &DIALOG_builtin_class );
484 register_builtin( &EDIT_builtin_class );
485 register_builtin( &ICONTITLE_builtin_class );
486 register_builtin( &LISTBOX_builtin_class );
487 register_builtin( &MDICLIENT_builtin_class );
488 register_builtin( &MENU_builtin_class );
489 register_builtin( &SCROLL_builtin_class );
490 register_builtin( &STATIC_builtin_class );
494 /***********************************************************************
497 * Add a new window using this class, and set the necessary
498 * information inside the window structure.
500 void CLASS_AddWindow( CLASS *class, WND *win, WINDOWPROCTYPE type )
502 if (!class) class = desktop_class;
504 if (type == WIN_PROC_32W)
506 if (!(win->winproc = class->winprocW)) win->winproc = class->winprocA;
510 if (!(win->winproc = class->winprocA)) win->winproc = class->winprocW;
513 win->clsStyle = class->style;
514 win->dce = class->dce;
518 /***********************************************************************
519 * RegisterClassA (USER32.@)
521 * >0: Unique identifier
524 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
528 wcex.cbSize = sizeof(wcex);
529 wcex.style = wc->style;
530 wcex.lpfnWndProc = wc->lpfnWndProc;
531 wcex.cbClsExtra = wc->cbClsExtra;
532 wcex.cbWndExtra = wc->cbWndExtra;
533 wcex.hInstance = wc->hInstance;
534 wcex.hIcon = wc->hIcon;
535 wcex.hCursor = wc->hCursor;
536 wcex.hbrBackground = wc->hbrBackground;
537 wcex.lpszMenuName = wc->lpszMenuName;
538 wcex.lpszClassName = wc->lpszClassName;
540 return RegisterClassExA( &wcex );
544 /***********************************************************************
545 * RegisterClassW (USER32.@)
547 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
551 wcex.cbSize = sizeof(wcex);
552 wcex.style = wc->style;
553 wcex.lpfnWndProc = wc->lpfnWndProc;
554 wcex.cbClsExtra = wc->cbClsExtra;
555 wcex.cbWndExtra = wc->cbWndExtra;
556 wcex.hInstance = wc->hInstance;
557 wcex.hIcon = wc->hIcon;
558 wcex.hCursor = wc->hCursor;
559 wcex.hbrBackground = wc->hbrBackground;
560 wcex.lpszMenuName = wc->lpszMenuName;
561 wcex.lpszClassName = wc->lpszClassName;
563 return RegisterClassExW( &wcex );
567 /***********************************************************************
568 * RegisterClassExA (USER32.@)
570 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
576 if (wc->hInstance == user32_module)
578 /* we can't register a class for user32 */
579 SetLastError( ERROR_INVALID_PARAMETER );
582 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
584 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
586 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
587 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
590 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
591 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
592 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
594 classPtr->hIcon = wc->hIcon;
595 classPtr->hIconSm = wc->hIconSm;
596 classPtr->hCursor = wc->hCursor;
597 classPtr->hbrBackground = wc->hbrBackground;
598 classPtr->winprocA = WINPROC_AllocProc( wc->lpfnWndProc, WIN_PROC_32A );
599 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
600 release_class_ptr( classPtr );
605 /***********************************************************************
606 * RegisterClassExW (USER32.@)
608 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
614 if (wc->hInstance == user32_module)
616 /* we can't register a class for user32 */
617 SetLastError( ERROR_INVALID_PARAMETER );
620 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
622 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
624 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
625 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
628 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
629 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
630 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
632 classPtr->hIcon = wc->hIcon;
633 classPtr->hIconSm = wc->hIconSm;
634 classPtr->hCursor = wc->hCursor;
635 classPtr->hbrBackground = wc->hbrBackground;
636 classPtr->winprocW = WINPROC_AllocProc( wc->lpfnWndProc, WIN_PROC_32W );
637 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
638 release_class_ptr( classPtr );
643 /***********************************************************************
644 * UnregisterClassA (USER32.@)
646 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
648 ATOM atom = HIWORD(className) ? GlobalFindAtomA( className ) : LOWORD(className);
649 return UnregisterClassW( MAKEINTATOMW(atom), hInstance );
652 /***********************************************************************
653 * UnregisterClassW (USER32.@)
655 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
657 CLASS *classPtr = NULL;
658 ATOM atom = HIWORD(className) ? GlobalFindAtomW( className ) : LOWORD(className);
660 TRACE("%s %p %x\n",debugstr_w(className), hInstance, atom);
664 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
668 SERVER_START_REQ( destroy_class )
671 req->instance = hInstance;
672 if (!wine_server_call_err( req )) classPtr = reply->client_ptr;
676 if (classPtr) CLASS_FreeClass( classPtr );
677 return (classPtr != NULL);
681 /***********************************************************************
682 * GetClassWord (USER32.@)
684 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
689 if (offset < 0) return GetClassLongA( hwnd, offset );
691 TRACE("%p %x\n",hwnd, offset);
693 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
695 if (class == CLASS_OTHER_PROCESS)
697 SERVER_START_REQ( set_class_info )
701 req->extra_offset = offset;
702 req->extra_size = sizeof(retvalue);
703 if (!wine_server_call_err( req ))
704 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
710 if (offset <= class->cbClsExtra - sizeof(WORD))
711 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
713 SetLastError( ERROR_INVALID_INDEX );
714 release_class_ptr( class );
719 /***********************************************************************
720 * GetClassLong (USER.131)
722 LONG WINAPI GetClassLong16( HWND16 hwnd16, INT16 offset )
726 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
728 TRACE("%p %d\n",hwnd, offset);
733 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
734 if (class == CLASS_OTHER_PROCESS) break;
735 ret = (LONG)CLASS_GetProc( class, WIN_PROC_16 );
736 release_class_ptr( class );
739 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
740 if (class == CLASS_OTHER_PROCESS) break;
741 ret = (LONG)CLASS_GetMenuName16( class );
742 release_class_ptr( class );
745 return GetClassLongA( hwnd, offset );
747 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
748 SetLastError( ERROR_INVALID_HANDLE );
753 /***********************************************************************
754 * GetClassLongW (USER32.@)
756 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
761 TRACE("%p %d\n", hwnd, offset);
763 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
765 if (class == CLASS_OTHER_PROCESS)
767 SERVER_START_REQ( set_class_info )
771 req->extra_offset = (offset >= 0) ? offset : -1;
772 req->extra_size = (offset >= 0) ? sizeof(retvalue) : 0;
773 if (!wine_server_call_err( req ))
777 case GCLP_HBRBACKGROUND:
783 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
784 SetLastError( ERROR_INVALID_HANDLE );
787 retvalue = reply->old_style;
790 retvalue = reply->old_win_extra;
793 retvalue = reply->old_extra;
796 retvalue = (DWORD)reply->old_instance;
799 retvalue = reply->old_atom;
802 if (offset >= 0) memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
803 else SetLastError( ERROR_INVALID_INDEX );
814 if (offset <= class->cbClsExtra - sizeof(LONG))
815 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
817 SetLastError( ERROR_INVALID_INDEX );
818 release_class_ptr( class );
824 case GCLP_HBRBACKGROUND:
825 retvalue = (DWORD)class->hbrBackground;
828 retvalue = (DWORD)class->hCursor;
831 retvalue = (DWORD)class->hIcon;
834 retvalue = (DWORD)class->hIconSm;
837 retvalue = (DWORD)class->style;
840 retvalue = (DWORD)class->cbWndExtra;
843 retvalue = (DWORD)class->cbClsExtra;
846 retvalue = (DWORD)class->hInstance;
849 retvalue = (DWORD)CLASS_GetProc( class, WIN_PROC_32W );
852 retvalue = (DWORD)CLASS_GetMenuNameW( class );
855 retvalue = (DWORD)class->atomName;
858 SetLastError( ERROR_INVALID_INDEX );
861 release_class_ptr( class );
866 /***********************************************************************
867 * GetClassLongA (USER32.@)
869 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
874 if (offset != GCLP_WNDPROC && offset != GCLP_MENUNAME)
875 return GetClassLongW( hwnd, offset );
877 TRACE("%p %d\n", hwnd, offset);
879 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
881 if (class == CLASS_OTHER_PROCESS)
883 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
884 SetLastError( ERROR_INVALID_HANDLE );
888 if (offset == GCLP_WNDPROC)
889 retvalue = (DWORD)CLASS_GetProc( class, WIN_PROC_32A );
890 else /* GCL_MENUNAME */
891 retvalue = (DWORD)CLASS_GetMenuNameA( class );
893 release_class_ptr( class );
898 /***********************************************************************
899 * SetClassWord (USER32.@)
901 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
906 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
908 TRACE("%p %d %x\n", hwnd, offset, newval);
910 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
912 SERVER_START_REQ( set_class_info )
915 req->flags = SET_CLASS_EXTRA;
916 req->extra_offset = offset;
917 req->extra_size = sizeof(newval);
918 memcpy( &req->extra_value, &newval, sizeof(newval) );
919 if (!wine_server_call_err( req ))
921 void *ptr = (char *)(class + 1) + offset;
922 memcpy( &retval, ptr, sizeof(retval) );
923 memcpy( ptr, &newval, sizeof(newval) );
927 release_class_ptr( class );
932 /***********************************************************************
933 * SetClassLong (USER.132)
935 LONG WINAPI SetClassLong16( HWND16 hwnd16, INT16 offset, LONG newval )
939 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
941 TRACE("%p %d %lx\n", hwnd, offset, newval);
946 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
947 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_16 );
948 release_class_ptr( class );
951 newval = (LONG)MapSL( newval );
954 return SetClassLongA( hwnd, offset, newval );
959 /***********************************************************************
960 * SetClassLongW (USER32.@)
962 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
967 TRACE("%p %d %lx\n", hwnd, offset, newval);
969 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
973 if (set_server_info( hwnd, offset, newval ))
975 void *ptr = (char *)(class + 1) + offset;
976 memcpy( &retval, ptr, sizeof(retval) );
977 memcpy( ptr, &newval, sizeof(newval) );
983 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
984 retval = 0; /* Old value is now meaningless anyway */
987 retval = (DWORD)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32W );
989 case GCLP_HBRBACKGROUND:
990 retval = (DWORD)class->hbrBackground;
991 class->hbrBackground = (HBRUSH)newval;
994 retval = (DWORD)class->hCursor;
995 class->hCursor = (HCURSOR)newval;
998 retval = (DWORD)class->hIcon;
999 class->hIcon = (HICON)newval;
1002 retval = (DWORD)class->hIconSm;
1003 class->hIconSm = (HICON)newval;
1006 if (!set_server_info( hwnd, offset, newval )) break;
1007 retval = (DWORD)class->style;
1008 class->style = newval;
1010 case GCL_CBWNDEXTRA:
1011 if (!set_server_info( hwnd, offset, newval )) break;
1012 retval = (DWORD)class->cbWndExtra;
1013 class->cbWndExtra = newval;
1016 if (!set_server_info( hwnd, offset, newval )) break;
1017 retval = (DWORD)class->hInstance;
1018 class->hInstance = (HINSTANCE)newval;
1021 if (!set_server_info( hwnd, offset, newval )) break;
1022 retval = (DWORD)class->atomName;
1023 class->atomName = newval;
1025 case GCL_CBCLSEXTRA: /* cannot change this one */
1026 SetLastError( ERROR_INVALID_PARAMETER );
1029 SetLastError( ERROR_INVALID_INDEX );
1032 release_class_ptr( class );
1037 /***********************************************************************
1038 * SetClassLongA (USER32.@)
1040 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
1045 if (offset != GCLP_WNDPROC && offset != GCLP_MENUNAME)
1046 return SetClassLongW( hwnd, offset, newval );
1048 TRACE("%p %d %lx\n", hwnd, offset, newval);
1050 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
1052 if (offset == GCLP_WNDPROC)
1053 retval = (DWORD)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32A );
1054 else /* GCL_MENUNAME */
1056 CLASS_SetMenuNameA( class, (LPCSTR)newval );
1057 retval = 0; /* Old value is now meaningless anyway */
1059 release_class_ptr( class );
1064 /***********************************************************************
1065 * GetClassNameA (USER32.@)
1067 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
1069 INT ret = GlobalGetAtomNameA( GetClassLongA( hwnd, GCW_ATOM ), buffer, count );
1071 TRACE("%p %s %x\n",hwnd, debugstr_a(buffer), count);
1076 /***********************************************************************
1077 * GetClassNameW (USER32.@)
1079 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
1081 INT ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), buffer, count );
1083 TRACE("%p %s %x\n",hwnd, debugstr_w(buffer), count);
1088 /***********************************************************************
1089 * RealGetWindowClassA (USER32.@)
1091 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1093 return GetClassNameA( hwnd, buffer, count );
1097 /***********************************************************************
1098 * RealGetWindowClassW (USER32.@)
1100 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1102 return GetClassNameW( hwnd, buffer, count );
1106 /***********************************************************************
1107 * GetClassInfoA (USER32.@)
1109 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1112 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1116 wc->style = wcex.style;
1117 wc->lpfnWndProc = wcex.lpfnWndProc;
1118 wc->cbClsExtra = wcex.cbClsExtra;
1119 wc->cbWndExtra = wcex.cbWndExtra;
1120 wc->hInstance = wcex.hInstance;
1121 wc->hIcon = wcex.hIcon;
1122 wc->hCursor = wcex.hCursor;
1123 wc->hbrBackground = wcex.hbrBackground;
1124 wc->lpszMenuName = wcex.lpszMenuName;
1125 wc->lpszClassName = wcex.lpszClassName;
1131 /***********************************************************************
1132 * GetClassInfoW (USER32.@)
1134 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1137 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1141 wc->style = wcex.style;
1142 wc->lpfnWndProc = wcex.lpfnWndProc;
1143 wc->cbClsExtra = wcex.cbClsExtra;
1144 wc->cbWndExtra = wcex.cbWndExtra;
1145 wc->hInstance = wcex.hInstance;
1146 wc->hIcon = wcex.hIcon;
1147 wc->hCursor = wcex.hCursor;
1148 wc->hbrBackground = wcex.hbrBackground;
1149 wc->lpszMenuName = wcex.lpszMenuName;
1150 wc->lpszClassName = wcex.lpszClassName;
1156 /***********************************************************************
1157 * GetClassInfoExA (USER32.@)
1159 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1161 ATOM atom = HIWORD(name) ? GlobalFindAtomA( name ) : LOWORD(name);
1164 TRACE("%p %s %x %p\n", hInstance, debugstr_a(name), atom, wc);
1166 if (!hInstance) hInstance = user32_module;
1168 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1170 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1173 wc->style = classPtr->style;
1174 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32A );
1175 wc->cbClsExtra = classPtr->cbClsExtra;
1176 wc->cbWndExtra = classPtr->cbWndExtra;
1177 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1178 wc->hIcon = (HICON)classPtr->hIcon;
1179 wc->hIconSm = (HICON)classPtr->hIconSm;
1180 wc->hCursor = (HCURSOR)classPtr->hCursor;
1181 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1182 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1183 wc->lpszClassName = name;
1184 release_class_ptr( classPtr );
1186 /* We must return the atom of the class here instead of just TRUE. */
1191 /***********************************************************************
1192 * GetClassInfoExW (USER32.@)
1194 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1196 ATOM atom = HIWORD(name) ? GlobalFindAtomW( name ) : LOWORD(name);
1199 TRACE("%p %s %x %p\n", hInstance, debugstr_w(name), atom, wc);
1201 if (!hInstance) hInstance = user32_module;
1203 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1205 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1208 wc->style = classPtr->style;
1209 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32W );
1210 wc->cbClsExtra = classPtr->cbClsExtra;
1211 wc->cbWndExtra = classPtr->cbWndExtra;
1212 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1213 wc->hIcon = (HICON)classPtr->hIcon;
1214 wc->hIconSm = (HICON)classPtr->hIconSm;
1215 wc->hCursor = (HCURSOR)classPtr->hCursor;
1216 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1217 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1218 wc->lpszClassName = name;
1219 release_class_ptr( classPtr );
1221 /* We must return the atom of the class here instead of just TRUE. */
1226 #if 0 /* toolhelp is in kernel, so this cannot work */
1228 /***********************************************************************
1229 * ClassFirst (TOOLHELP.69)
1231 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1233 TRACE("%p\n",pClassEntry);
1234 pClassEntry->wNext = 1;
1235 return ClassNext16( pClassEntry );
1239 /***********************************************************************
1240 * ClassNext (TOOLHELP.70)
1242 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1245 CLASS *class = firstClass;
1247 TRACE("%p\n",pClassEntry);
1249 if (!pClassEntry->wNext) return FALSE;
1250 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1253 pClassEntry->wNext = 0;
1256 pClassEntry->hInst = class->hInstance;
1257 pClassEntry->wNext++;
1258 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1259 sizeof(pClassEntry->szClassName) );