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"
40 #include "wine/server.h"
41 #include "wine/list.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(class);
46 typedef struct tagCLASS
48 struct list entry; /* Entry in class list */
49 UINT style; /* Class style */
50 BOOL local; /* Local class? */
51 WNDPROC winprocA; /* Window procedure (ASCII) */
52 WNDPROC winprocW; /* Window procedure (Unicode) */
53 INT cbClsExtra; /* Class extra bytes */
54 INT cbWndExtra; /* Window extra bytes */
55 LPWSTR menuName; /* Default menu name (Unicode followed by ASCII) */
56 SEGPTR segMenuName; /* Default menu name as SEGPTR */
57 HINSTANCE hInstance; /* Module that created the task */
58 HICON hIcon; /* Default icon */
59 HICON hIconSm; /* Default small icon */
60 HCURSOR hCursor; /* Default cursor */
61 HBRUSH hbrBackground; /* Default background */
62 ATOM atomName; /* Name of the class */
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 inline static void release_class_ptr( CLASS *ptr )
102 /***********************************************************************
105 * Set class info with the wine server.
107 static BOOL set_server_info( HWND hwnd, INT offset, LONG newval )
111 SERVER_START_REQ( set_class_info )
114 req->extra_offset = -1;
118 req->flags = SET_CLASS_ATOM;
121 req->flags = SET_CLASS_STYLE;
125 req->flags = SET_CLASS_WINEXTRA;
126 req->win_extra = newval;
129 req->flags = SET_CLASS_INSTANCE;
130 req->instance = (void *)newval;
133 assert( offset >= 0 );
134 req->flags = SET_CLASS_EXTRA;
135 req->extra_offset = offset;
136 req->extra_size = sizeof(newval);
137 memcpy( &req->extra_value, &newval, sizeof(newval) );
140 ret = !wine_server_call_err( req );
147 /***********************************************************************
150 * Get the class winproc for a given proc type
152 static WNDPROC16 CLASS_GetProc16( CLASS *classPtr )
154 if (classPtr->winprocA) return WINPROC_GetProc16( classPtr->winprocA, FALSE );
155 else return WINPROC_GetProc16( classPtr->winprocW, TRUE );
159 /***********************************************************************
162 * Get the class winproc for a given proc type
164 static WNDPROC CLASS_GetProc( CLASS *classPtr, BOOL unicode )
166 WNDPROC proc = classPtr->winprocA;
168 if (classPtr->winprocW)
170 /* if we have a Unicode proc, use it if we have no ASCII proc
171 * or if we have both and Unicode was requested
173 if (!proc || unicode) proc = classPtr->winprocW;
175 return WINPROC_GetProc( proc, unicode );
179 /***********************************************************************
182 * Set the class winproc for a given proc type.
183 * Returns the previous window proc.
185 static void CLASS_SetProc16( CLASS *classPtr, WNDPROC16 newproc )
187 WNDPROC proc = WINPROC_AllocProc16( newproc );
189 if (WINPROC_IsUnicode( proc, FALSE ))
191 classPtr->winprocA = 0;
192 classPtr->winprocW = proc;
196 classPtr->winprocA = proc;
197 classPtr->winprocW = 0;
202 /***********************************************************************
205 * Set the class winproc for a given proc type.
206 * Returns the previous window proc.
208 static void CLASS_SetProc( CLASS *classPtr, WNDPROC newproc, BOOL unicode )
210 WNDPROC proc = WINPROC_AllocProc( newproc, unicode );
212 if (WINPROC_IsUnicode( proc, unicode ))
214 classPtr->winprocA = 0;
215 classPtr->winprocW = proc;
219 classPtr->winprocA = proc;
220 classPtr->winprocW = 0;
225 /***********************************************************************
228 * Get the menu name as a ASCII string.
230 inline static LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
232 if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
233 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
237 /***********************************************************************
238 * CLASS_GetMenuName16
240 * Get the menu name as a SEGPTR.
242 inline static SEGPTR CLASS_GetMenuName16( CLASS *classPtr )
244 if (!HIWORD(classPtr->menuName)) return (SEGPTR)classPtr->menuName;
245 if (!classPtr->segMenuName)
246 classPtr->segMenuName = MapLS( CLASS_GetMenuNameA(classPtr) );
247 return classPtr->segMenuName;
251 /***********************************************************************
254 * Get the menu name as a Unicode string.
256 inline static LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
258 return classPtr->menuName;
262 /***********************************************************************
265 * Set the menu name in a class structure by copying the string.
267 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
269 UnMapLS( classPtr->segMenuName );
270 classPtr->segMenuName = 0;
271 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
274 DWORD lenA = strlen(name) + 1;
275 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
276 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
277 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
278 memcpy( classPtr->menuName + lenW, name, lenA );
280 else classPtr->menuName = (LPWSTR)name;
284 /***********************************************************************
287 * Set the menu name in a class structure by copying the string.
289 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
291 UnMapLS( classPtr->segMenuName );
292 classPtr->segMenuName = 0;
293 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
296 DWORD lenW = strlenW(name) + 1;
297 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
298 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
299 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
300 WideCharToMultiByte( CP_ACP, 0, name, lenW,
301 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
303 else classPtr->menuName = (LPWSTR)name;
307 /***********************************************************************
310 * Free a class structure.
312 static void CLASS_FreeClass( CLASS *classPtr )
314 TRACE("%p\n", classPtr);
318 list_remove( &classPtr->entry );
319 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
320 DeleteObject( classPtr->hbrBackground );
321 UnMapLS( classPtr->segMenuName );
322 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
323 HeapFree( GetProcessHeap(), 0, classPtr );
328 /***********************************************************************
329 * CLASS_FreeModuleClasses
331 void CLASS_FreeModuleClasses( HMODULE16 hModule )
333 struct list *ptr, *next;
335 TRACE("0x%08x\n", hModule);
338 for (ptr = list_head( &class_list ); ptr; ptr = next)
340 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
341 next = list_next( &class_list, ptr );
342 if (class->hInstance == HINSTANCE_32(hModule))
346 SERVER_START_REQ( destroy_class )
348 req->atom = class->atomName;
349 req->instance = class->hInstance;
350 ret = !wine_server_call_err( req );
353 if (ret) CLASS_FreeClass( class );
360 /***********************************************************************
361 * CLASS_FindClassByAtom
363 * Return a pointer to the class.
364 * hinstance has been normalized by the caller.
366 static CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE hinstance )
372 LIST_FOR_EACH( ptr, &class_list )
374 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
375 if (class->atomName != atom) continue;
376 if (!hinstance || !class->local || class->hInstance == hinstance)
378 TRACE("0x%04x %p -> %p\n", atom, hinstance, class);
383 TRACE("0x%04x %p -> not found\n", atom, hinstance);
388 /***********************************************************************
389 * CLASS_RegisterClass
391 * The real RegisterClass() functionality.
392 * The atom is deleted no matter what.
394 static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE hInstance, BOOL local,
395 DWORD style, INT classExtra, INT winExtra )
400 TRACE("atom=0x%x hinst=%p style=0x%lx clExtr=0x%x winExtr=0x%x\n",
401 atom, hInstance, style, classExtra, winExtra );
403 /* Fix the extra bytes value */
405 if (classExtra < 0 || winExtra < 0)
407 SetLastError( ERROR_INVALID_PARAMETER );
410 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
411 WARN("Class extra bytes %d is > 40\n", classExtra);
412 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
413 WARN("Win extra bytes %d is > 40\n", winExtra );
415 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
418 GlobalDeleteAtom( atom );
422 SERVER_START_REQ( create_class )
427 req->instance = hInstance;
428 req->extra = classExtra;
429 req->win_extra = winExtra;
430 req->client_ptr = classPtr;
431 ret = !wine_server_call_err( req );
434 GlobalDeleteAtom( atom ); /* the server increased the atom ref count */
437 HeapFree( GetProcessHeap(), 0, classPtr );
441 classPtr->style = style;
442 classPtr->local = local;
443 classPtr->cbWndExtra = winExtra;
444 classPtr->cbClsExtra = classExtra;
445 classPtr->hInstance = hInstance;
446 classPtr->atomName = atom;
448 /* Other non-null values must be set by caller */
451 if (local) list_add_head( &class_list, &classPtr->entry );
452 else list_add_tail( &class_list, &classPtr->entry );
457 /***********************************************************************
460 * Register a builtin control class.
461 * This allows having both ASCII and Unicode winprocs for the same class.
463 static CLASS *register_builtin( const struct builtin_class_descr *descr )
468 if (!(atom = GlobalAddAtomA( descr->name ))) return 0;
470 if (!(classPtr = CLASS_RegisterClass( atom, user32_module, FALSE,
471 descr->style, 0, descr->extra ))) return 0;
473 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
474 classPtr->hbrBackground = descr->brush;
476 if (descr->procA) classPtr->winprocA = WINPROC_AllocProc( descr->procA, FALSE );
477 if (descr->procW) classPtr->winprocW = WINPROC_AllocProc( descr->procW, TRUE );
478 release_class_ptr( classPtr );
483 /***********************************************************************
484 * CLASS_RegisterBuiltinClasses
486 void CLASS_RegisterBuiltinClasses(void)
488 extern const struct builtin_class_descr BUTTON_builtin_class;
489 extern const struct builtin_class_descr COMBO_builtin_class;
490 extern const struct builtin_class_descr COMBOLBOX_builtin_class;
491 extern const struct builtin_class_descr DIALOG_builtin_class;
492 extern const struct builtin_class_descr DESKTOP_builtin_class;
493 extern const struct builtin_class_descr EDIT_builtin_class;
494 extern const struct builtin_class_descr ICONTITLE_builtin_class;
495 extern const struct builtin_class_descr LISTBOX_builtin_class;
496 extern const struct builtin_class_descr MDICLIENT_builtin_class;
497 extern const struct builtin_class_descr MENU_builtin_class;
498 extern const struct builtin_class_descr SCROLL_builtin_class;
499 extern const struct builtin_class_descr STATIC_builtin_class;
501 register_builtin( &DESKTOP_builtin_class );
502 register_builtin( &BUTTON_builtin_class );
503 register_builtin( &COMBO_builtin_class );
504 register_builtin( &COMBOLBOX_builtin_class );
505 register_builtin( &DIALOG_builtin_class );
506 register_builtin( &EDIT_builtin_class );
507 register_builtin( &ICONTITLE_builtin_class );
508 register_builtin( &LISTBOX_builtin_class );
509 register_builtin( &MDICLIENT_builtin_class );
510 register_builtin( &MENU_builtin_class );
511 register_builtin( &SCROLL_builtin_class );
512 register_builtin( &STATIC_builtin_class );
516 /***********************************************************************
519 * Add a new window using this class, and set the necessary
520 * information inside the window structure.
522 void CLASS_AddWindow( CLASS *class, WND *win, BOOL unicode )
526 if (!(win->winproc = class->winprocW)) win->winproc = class->winprocA;
530 if (!(win->winproc = class->winprocA)) win->winproc = class->winprocW;
533 win->clsStyle = class->style;
534 if (WINPROC_IsUnicode( win->winproc, unicode )) win->flags |= WIN_ISUNICODE;
538 /***********************************************************************
539 * RegisterClassA (USER32.@)
541 * Register a window class.
544 * >0: Unique identifier
547 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
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 RegisterClassExA( &wcex );
567 /***********************************************************************
568 * RegisterClassW (USER32.@)
570 * See RegisterClassA.
572 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
576 wcex.cbSize = sizeof(wcex);
577 wcex.style = wc->style;
578 wcex.lpfnWndProc = wc->lpfnWndProc;
579 wcex.cbClsExtra = wc->cbClsExtra;
580 wcex.cbWndExtra = wc->cbWndExtra;
581 wcex.hInstance = wc->hInstance;
582 wcex.hIcon = wc->hIcon;
583 wcex.hCursor = wc->hCursor;
584 wcex.hbrBackground = wc->hbrBackground;
585 wcex.lpszMenuName = wc->lpszMenuName;
586 wcex.lpszClassName = wc->lpszClassName;
588 return RegisterClassExW( &wcex );
592 /***********************************************************************
593 * RegisterClassExA (USER32.@)
595 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
601 if (wc->hInstance == user32_module)
603 /* we can't register a class for user32 */
604 SetLastError( ERROR_INVALID_PARAMETER );
607 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
609 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
611 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
612 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
615 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
616 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
617 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
619 classPtr->hIcon = wc->hIcon;
620 classPtr->hIconSm = wc->hIconSm;
621 classPtr->hCursor = wc->hCursor;
622 classPtr->hbrBackground = wc->hbrBackground;
623 classPtr->winprocA = WINPROC_AllocProc( wc->lpfnWndProc, FALSE );
624 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
625 release_class_ptr( classPtr );
630 /***********************************************************************
631 * RegisterClassExW (USER32.@)
633 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
639 if (wc->hInstance == user32_module)
641 /* we can't register a class for user32 */
642 SetLastError( ERROR_INVALID_PARAMETER );
645 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
647 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
649 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
650 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
653 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
654 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
655 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
657 classPtr->hIcon = wc->hIcon;
658 classPtr->hIconSm = wc->hIconSm;
659 classPtr->hCursor = wc->hCursor;
660 classPtr->hbrBackground = wc->hbrBackground;
661 classPtr->winprocW = WINPROC_AllocProc( wc->lpfnWndProc, TRUE );
662 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
663 release_class_ptr( classPtr );
668 /***********************************************************************
669 * UnregisterClassA (USER32.@)
671 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
673 ATOM atom = HIWORD(className) ? GlobalFindAtomA( className ) : LOWORD(className);
674 return UnregisterClassW( MAKEINTATOMW(atom), hInstance );
677 /***********************************************************************
678 * UnregisterClassW (USER32.@)
680 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
682 CLASS *classPtr = NULL;
683 ATOM atom = HIWORD(className) ? GlobalFindAtomW( className ) : LOWORD(className);
685 TRACE("%s %p %x\n",debugstr_w(className), hInstance, atom);
689 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
693 SERVER_START_REQ( destroy_class )
696 req->instance = hInstance;
697 if (!wine_server_call_err( req )) classPtr = reply->client_ptr;
701 if (classPtr) CLASS_FreeClass( classPtr );
702 return (classPtr != NULL);
706 /***********************************************************************
707 * GetClassWord (USER32.@)
709 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
714 if (offset < 0) return GetClassLongA( hwnd, offset );
716 TRACE("%p %x\n",hwnd, offset);
718 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
720 if (class == CLASS_OTHER_PROCESS)
722 SERVER_START_REQ( set_class_info )
726 req->extra_offset = offset;
727 req->extra_size = sizeof(retvalue);
728 if (!wine_server_call_err( req ))
729 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
735 if (offset <= class->cbClsExtra - sizeof(WORD))
736 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
738 SetLastError( ERROR_INVALID_INDEX );
739 release_class_ptr( class );
744 /***********************************************************************
745 * GetClassLong (USER.131)
747 LONG WINAPI GetClassLong16( HWND16 hwnd16, INT16 offset )
751 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
753 TRACE("%p %d\n",hwnd, offset);
758 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
759 if (class == CLASS_OTHER_PROCESS) break;
760 ret = (LONG)CLASS_GetProc16( class );
761 release_class_ptr( class );
764 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
765 if (class == CLASS_OTHER_PROCESS) break;
766 ret = (LONG)CLASS_GetMenuName16( class );
767 release_class_ptr( class );
770 return GetClassLongA( hwnd, offset );
772 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
773 SetLastError( ERROR_INVALID_HANDLE );
778 /***********************************************************************
779 * GetClassLongW (USER32.@)
781 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
786 TRACE("%p %d\n", hwnd, offset);
788 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
790 if (class == CLASS_OTHER_PROCESS)
792 SERVER_START_REQ( set_class_info )
796 req->extra_offset = (offset >= 0) ? offset : -1;
797 req->extra_size = (offset >= 0) ? sizeof(retvalue) : 0;
798 if (!wine_server_call_err( req ))
802 case GCLP_HBRBACKGROUND:
808 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
809 SetLastError( ERROR_INVALID_HANDLE );
812 retvalue = reply->old_style;
815 retvalue = reply->old_win_extra;
818 retvalue = reply->old_extra;
821 retvalue = (DWORD)reply->old_instance;
824 retvalue = reply->old_atom;
827 if (offset >= 0) memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
828 else SetLastError( ERROR_INVALID_INDEX );
839 if (offset <= class->cbClsExtra - sizeof(LONG))
840 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
842 SetLastError( ERROR_INVALID_INDEX );
843 release_class_ptr( class );
849 case GCLP_HBRBACKGROUND:
850 retvalue = (DWORD)class->hbrBackground;
853 retvalue = (DWORD)class->hCursor;
856 retvalue = (DWORD)class->hIcon;
859 retvalue = (DWORD)class->hIconSm;
862 retvalue = (DWORD)class->style;
865 retvalue = (DWORD)class->cbWndExtra;
868 retvalue = (DWORD)class->cbClsExtra;
871 retvalue = (DWORD)class->hInstance;
874 retvalue = (DWORD)CLASS_GetProc( class, TRUE );
877 retvalue = (DWORD)CLASS_GetMenuNameW( class );
880 retvalue = (DWORD)class->atomName;
883 SetLastError( ERROR_INVALID_INDEX );
886 release_class_ptr( class );
891 /***********************************************************************
892 * GetClassLongA (USER32.@)
894 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
899 if (offset != GCLP_WNDPROC && offset != GCLP_MENUNAME)
900 return GetClassLongW( hwnd, offset );
902 TRACE("%p %d\n", hwnd, offset);
904 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
906 if (class == CLASS_OTHER_PROCESS)
908 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
909 SetLastError( ERROR_INVALID_HANDLE );
913 if (offset == GCLP_WNDPROC)
914 retvalue = (DWORD)CLASS_GetProc( class, FALSE );
915 else /* GCL_MENUNAME */
916 retvalue = (DWORD)CLASS_GetMenuNameA( class );
918 release_class_ptr( class );
923 /***********************************************************************
924 * SetClassWord (USER32.@)
926 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
931 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
933 TRACE("%p %d %x\n", hwnd, offset, newval);
935 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
937 SERVER_START_REQ( set_class_info )
940 req->flags = SET_CLASS_EXTRA;
941 req->extra_offset = offset;
942 req->extra_size = sizeof(newval);
943 memcpy( &req->extra_value, &newval, sizeof(newval) );
944 if (!wine_server_call_err( req ))
946 void *ptr = (char *)(class + 1) + offset;
947 memcpy( &retval, ptr, sizeof(retval) );
948 memcpy( ptr, &newval, sizeof(newval) );
952 release_class_ptr( class );
957 /***********************************************************************
958 * SetClassLong (USER.132)
960 LONG WINAPI SetClassLong16( HWND16 hwnd16, INT16 offset, LONG newval )
964 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
966 TRACE("%p %d %lx\n", hwnd, offset, newval);
971 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
972 retval = (LONG)CLASS_GetProc16( class );
973 CLASS_SetProc16( class, (WNDPROC16)newval );
974 release_class_ptr( class );
977 newval = (LONG)MapSL( newval );
980 return SetClassLongA( hwnd, offset, newval );
985 /***********************************************************************
986 * SetClassLongW (USER32.@)
988 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
993 TRACE("%p %d %lx\n", hwnd, offset, newval);
995 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
999 if (set_server_info( hwnd, offset, newval ))
1001 void *ptr = (char *)(class + 1) + offset;
1002 memcpy( &retval, ptr, sizeof(retval) );
1003 memcpy( ptr, &newval, sizeof(newval) );
1009 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
1010 retval = 0; /* Old value is now meaningless anyway */
1013 retval = (DWORD)CLASS_GetProc( class, TRUE );
1014 CLASS_SetProc( class, (WNDPROC)newval, TRUE );
1016 case GCLP_HBRBACKGROUND:
1017 retval = (DWORD)class->hbrBackground;
1018 class->hbrBackground = (HBRUSH)newval;
1021 retval = (DWORD)class->hCursor;
1022 class->hCursor = (HCURSOR)newval;
1025 retval = (DWORD)class->hIcon;
1026 class->hIcon = (HICON)newval;
1029 retval = (DWORD)class->hIconSm;
1030 class->hIconSm = (HICON)newval;
1033 if (!set_server_info( hwnd, offset, newval )) break;
1034 retval = (DWORD)class->style;
1035 class->style = newval;
1037 case GCL_CBWNDEXTRA:
1038 if (!set_server_info( hwnd, offset, newval )) break;
1039 retval = (DWORD)class->cbWndExtra;
1040 class->cbWndExtra = newval;
1043 if (!set_server_info( hwnd, offset, newval )) break;
1044 retval = (DWORD)class->hInstance;
1045 class->hInstance = (HINSTANCE)newval;
1048 if (!set_server_info( hwnd, offset, newval )) break;
1049 retval = (DWORD)class->atomName;
1050 class->atomName = newval;
1052 case GCL_CBCLSEXTRA: /* cannot change this one */
1053 SetLastError( ERROR_INVALID_PARAMETER );
1056 SetLastError( ERROR_INVALID_INDEX );
1059 release_class_ptr( class );
1064 /***********************************************************************
1065 * SetClassLongA (USER32.@)
1067 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
1072 if (offset != GCLP_WNDPROC && offset != GCLP_MENUNAME)
1073 return SetClassLongW( hwnd, offset, newval );
1075 TRACE("%p %d %lx\n", hwnd, offset, newval);
1077 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
1079 if (offset == GCLP_WNDPROC)
1081 retval = (DWORD)CLASS_GetProc( class, FALSE );
1082 CLASS_SetProc( class, (WNDPROC)newval, FALSE );
1084 else /* GCL_MENUNAME */
1086 CLASS_SetMenuNameA( class, (LPCSTR)newval );
1087 retval = 0; /* Old value is now meaningless anyway */
1089 release_class_ptr( class );
1094 /***********************************************************************
1095 * GetClassNameA (USER32.@)
1097 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
1099 INT ret = GlobalGetAtomNameA( GetClassLongA( hwnd, GCW_ATOM ), buffer, count );
1101 TRACE("%p %s %x\n",hwnd, debugstr_a(buffer), count);
1106 /***********************************************************************
1107 * GetClassNameW (USER32.@)
1109 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
1111 INT ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), buffer, count );
1113 TRACE("%p %s %x\n",hwnd, debugstr_w(buffer), count);
1118 /***********************************************************************
1119 * RealGetWindowClassA (USER32.@)
1121 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1123 return GetClassNameA( hwnd, buffer, count );
1127 /***********************************************************************
1128 * RealGetWindowClassW (USER32.@)
1130 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1132 return GetClassNameW( hwnd, buffer, count );
1136 /***********************************************************************
1137 * GetClassInfoA (USER32.@)
1139 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1142 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1146 wc->style = wcex.style;
1147 wc->lpfnWndProc = wcex.lpfnWndProc;
1148 wc->cbClsExtra = wcex.cbClsExtra;
1149 wc->cbWndExtra = wcex.cbWndExtra;
1150 wc->hInstance = wcex.hInstance;
1151 wc->hIcon = wcex.hIcon;
1152 wc->hCursor = wcex.hCursor;
1153 wc->hbrBackground = wcex.hbrBackground;
1154 wc->lpszMenuName = wcex.lpszMenuName;
1155 wc->lpszClassName = wcex.lpszClassName;
1161 /***********************************************************************
1162 * GetClassInfoW (USER32.@)
1164 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1167 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1171 wc->style = wcex.style;
1172 wc->lpfnWndProc = wcex.lpfnWndProc;
1173 wc->cbClsExtra = wcex.cbClsExtra;
1174 wc->cbWndExtra = wcex.cbWndExtra;
1175 wc->hInstance = wcex.hInstance;
1176 wc->hIcon = wcex.hIcon;
1177 wc->hCursor = wcex.hCursor;
1178 wc->hbrBackground = wcex.hbrBackground;
1179 wc->lpszMenuName = wcex.lpszMenuName;
1180 wc->lpszClassName = wcex.lpszClassName;
1186 /***********************************************************************
1187 * GetClassInfoExA (USER32.@)
1189 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1191 ATOM atom = HIWORD(name) ? GlobalFindAtomA( name ) : LOWORD(name);
1194 TRACE("%p %s %x %p\n", hInstance, debugstr_a(name), atom, wc);
1196 if (!hInstance) hInstance = user32_module;
1198 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1200 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1203 wc->style = classPtr->style;
1204 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, FALSE );
1205 wc->cbClsExtra = classPtr->cbClsExtra;
1206 wc->cbWndExtra = classPtr->cbWndExtra;
1207 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1208 wc->hIcon = (HICON)classPtr->hIcon;
1209 wc->hIconSm = (HICON)classPtr->hIconSm;
1210 wc->hCursor = (HCURSOR)classPtr->hCursor;
1211 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1212 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1213 wc->lpszClassName = name;
1214 release_class_ptr( classPtr );
1216 /* We must return the atom of the class here instead of just TRUE. */
1221 /***********************************************************************
1222 * GetClassInfoExW (USER32.@)
1224 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1226 ATOM atom = HIWORD(name) ? GlobalFindAtomW( name ) : LOWORD(name);
1229 TRACE("%p %s %x %p\n", hInstance, debugstr_w(name), atom, wc);
1231 if (!hInstance) hInstance = user32_module;
1233 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1235 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1238 wc->style = classPtr->style;
1239 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, TRUE );
1240 wc->cbClsExtra = classPtr->cbClsExtra;
1241 wc->cbWndExtra = classPtr->cbWndExtra;
1242 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1243 wc->hIcon = (HICON)classPtr->hIcon;
1244 wc->hIconSm = (HICON)classPtr->hIconSm;
1245 wc->hCursor = (HCURSOR)classPtr->hCursor;
1246 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1247 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1248 wc->lpszClassName = name;
1249 release_class_ptr( classPtr );
1251 /* We must return the atom of the class here instead of just TRUE. */
1256 #if 0 /* toolhelp is in kernel, so this cannot work */
1258 /***********************************************************************
1259 * ClassFirst (TOOLHELP.69)
1261 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1263 TRACE("%p\n",pClassEntry);
1264 pClassEntry->wNext = 1;
1265 return ClassNext16( pClassEntry );
1269 /***********************************************************************
1270 * ClassNext (TOOLHELP.70)
1272 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1275 CLASS *class = firstClass;
1277 TRACE("%p\n",pClassEntry);
1279 if (!pClassEntry->wNext) return FALSE;
1280 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1283 pClassEntry->wNext = 0;
1286 pClassEntry->hInst = class->hInstance;
1287 pClassEntry->wNext++;
1288 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1289 sizeof(pClassEntry->szClassName) );