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 WNDPROC proc = classPtr->winprocA;
155 if (!proc) proc = classPtr->winprocW;
156 return WINPROC_GetProc16( proc );
160 /***********************************************************************
163 * Get the class winproc for a given proc type
165 static WNDPROC CLASS_GetProc( CLASS *classPtr, WINDOWPROCTYPE type )
167 WNDPROC proc = classPtr->winprocA;
169 if (classPtr->winprocW)
171 /* if we have a Unicode proc, use it if we have no ASCII proc
172 * or if we have both and Unicode was requested
174 if (!proc || type == WIN_PROC_32W) proc = classPtr->winprocW;
176 return WINPROC_GetProc( proc, type );
180 /***********************************************************************
183 * Set the class winproc for a given proc type.
184 * Returns the previous window proc.
186 static void CLASS_SetProc16( CLASS *classPtr, WNDPROC16 newproc )
188 classPtr->winprocA = WINPROC_AllocProc16( newproc );
189 classPtr->winprocW = 0;
193 /***********************************************************************
196 * Set the class winproc for a given proc type.
197 * Returns the previous window proc.
199 static void CLASS_SetProc( CLASS *classPtr, WNDPROC newproc, WINDOWPROCTYPE type )
201 WNDPROC *proc = &classPtr->winprocA;
203 if (classPtr->winprocW)
205 /* if we have a Unicode proc, use it if we have no ASCII proc
206 * or if we have both and Unicode was requested
208 if (!*proc || type == WIN_PROC_32W) proc = &classPtr->winprocW;
210 *proc = WINPROC_AllocProc( newproc, type );
211 /* now clear the one that we didn't set */
212 if (classPtr->winprocA && classPtr->winprocW)
214 if (proc == &classPtr->winprocA)
215 classPtr->winprocW = 0;
217 classPtr->winprocA = 0;
222 /***********************************************************************
225 * Get the menu name as a ASCII string.
227 inline static LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
229 if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
230 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
234 /***********************************************************************
235 * CLASS_GetMenuName16
237 * Get the menu name as a SEGPTR.
239 inline static SEGPTR CLASS_GetMenuName16( CLASS *classPtr )
241 if (!HIWORD(classPtr->menuName)) return (SEGPTR)classPtr->menuName;
242 if (!classPtr->segMenuName)
243 classPtr->segMenuName = MapLS( CLASS_GetMenuNameA(classPtr) );
244 return classPtr->segMenuName;
248 /***********************************************************************
251 * Get the menu name as a Unicode string.
253 inline static LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
255 return classPtr->menuName;
259 /***********************************************************************
262 * Set the menu name in a class structure by copying the string.
264 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
266 UnMapLS( classPtr->segMenuName );
267 classPtr->segMenuName = 0;
268 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
271 DWORD lenA = strlen(name) + 1;
272 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
273 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
274 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
275 memcpy( classPtr->menuName + lenW, name, lenA );
277 else classPtr->menuName = (LPWSTR)name;
281 /***********************************************************************
284 * Set the menu name in a class structure by copying the string.
286 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
288 UnMapLS( classPtr->segMenuName );
289 classPtr->segMenuName = 0;
290 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
293 DWORD lenW = strlenW(name) + 1;
294 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
295 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
296 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
297 WideCharToMultiByte( CP_ACP, 0, name, lenW,
298 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
300 else classPtr->menuName = (LPWSTR)name;
304 /***********************************************************************
307 * Free a class structure.
309 static void CLASS_FreeClass( CLASS *classPtr )
311 TRACE("%p\n", classPtr);
315 list_remove( &classPtr->entry );
316 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
317 DeleteObject( classPtr->hbrBackground );
318 UnMapLS( classPtr->segMenuName );
319 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
320 HeapFree( GetProcessHeap(), 0, classPtr );
325 /***********************************************************************
326 * CLASS_FreeModuleClasses
328 void CLASS_FreeModuleClasses( HMODULE16 hModule )
330 struct list *ptr, *next;
332 TRACE("0x%08x\n", hModule);
335 for (ptr = list_head( &class_list ); ptr; ptr = next)
337 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
338 next = list_next( &class_list, ptr );
339 if (class->hInstance == HINSTANCE_32(hModule))
343 SERVER_START_REQ( destroy_class )
345 req->atom = class->atomName;
346 req->instance = class->hInstance;
347 ret = !wine_server_call_err( req );
350 if (ret) CLASS_FreeClass( class );
357 /***********************************************************************
358 * CLASS_FindClassByAtom
360 * Return a pointer to the class.
361 * hinstance has been normalized by the caller.
363 static CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE hinstance )
369 LIST_FOR_EACH( ptr, &class_list )
371 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
372 if (class->atomName != atom) continue;
373 if (!hinstance || !class->local || class->hInstance == hinstance)
375 TRACE("0x%04x %p -> %p\n", atom, hinstance, class);
380 TRACE("0x%04x %p -> not found\n", atom, hinstance);
385 /***********************************************************************
386 * CLASS_RegisterClass
388 * The real RegisterClass() functionality.
389 * The atom is deleted no matter what.
391 static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE hInstance, BOOL local,
392 DWORD style, INT classExtra, INT winExtra )
397 TRACE("atom=0x%x hinst=%p style=0x%lx clExtr=0x%x winExtr=0x%x\n",
398 atom, hInstance, style, classExtra, winExtra );
400 /* Fix the extra bytes value */
402 if (classExtra < 0 || winExtra < 0)
404 SetLastError( ERROR_INVALID_PARAMETER );
407 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
408 WARN("Class extra bytes %d is > 40\n", classExtra);
409 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
410 WARN("Win extra bytes %d is > 40\n", winExtra );
412 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
415 GlobalDeleteAtom( atom );
419 SERVER_START_REQ( create_class )
424 req->instance = hInstance;
425 req->extra = classExtra;
426 req->win_extra = winExtra;
427 req->client_ptr = classPtr;
428 ret = !wine_server_call_err( req );
431 GlobalDeleteAtom( atom ); /* the server increased the atom ref count */
434 HeapFree( GetProcessHeap(), 0, classPtr );
438 classPtr->style = style;
439 classPtr->local = local;
440 classPtr->cbWndExtra = winExtra;
441 classPtr->cbClsExtra = classExtra;
442 classPtr->hInstance = hInstance;
443 classPtr->atomName = atom;
445 /* Other non-null values must be set by caller */
448 if (local) list_add_head( &class_list, &classPtr->entry );
449 else list_add_tail( &class_list, &classPtr->entry );
454 /***********************************************************************
457 * Register a builtin control class.
458 * This allows having both ASCII and Unicode winprocs for the same class.
460 static CLASS *register_builtin( const struct builtin_class_descr *descr )
465 if (!(atom = GlobalAddAtomA( descr->name ))) return 0;
467 if (!(classPtr = CLASS_RegisterClass( atom, user32_module, FALSE,
468 descr->style, 0, descr->extra ))) return 0;
470 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
471 classPtr->hbrBackground = descr->brush;
473 if (descr->procA) classPtr->winprocA = WINPROC_AllocProc( descr->procA, WIN_PROC_32A );
474 if (descr->procW) classPtr->winprocW = WINPROC_AllocProc( descr->procW, WIN_PROC_32W );
475 release_class_ptr( classPtr );
480 /***********************************************************************
481 * CLASS_RegisterBuiltinClasses
483 void CLASS_RegisterBuiltinClasses(void)
485 extern const struct builtin_class_descr BUTTON_builtin_class;
486 extern const struct builtin_class_descr COMBO_builtin_class;
487 extern const struct builtin_class_descr COMBOLBOX_builtin_class;
488 extern const struct builtin_class_descr DIALOG_builtin_class;
489 extern const struct builtin_class_descr DESKTOP_builtin_class;
490 extern const struct builtin_class_descr EDIT_builtin_class;
491 extern const struct builtin_class_descr ICONTITLE_builtin_class;
492 extern const struct builtin_class_descr LISTBOX_builtin_class;
493 extern const struct builtin_class_descr MDICLIENT_builtin_class;
494 extern const struct builtin_class_descr MENU_builtin_class;
495 extern const struct builtin_class_descr SCROLL_builtin_class;
496 extern const struct builtin_class_descr STATIC_builtin_class;
498 register_builtin( &DESKTOP_builtin_class );
499 register_builtin( &BUTTON_builtin_class );
500 register_builtin( &COMBO_builtin_class );
501 register_builtin( &COMBOLBOX_builtin_class );
502 register_builtin( &DIALOG_builtin_class );
503 register_builtin( &EDIT_builtin_class );
504 register_builtin( &ICONTITLE_builtin_class );
505 register_builtin( &LISTBOX_builtin_class );
506 register_builtin( &MDICLIENT_builtin_class );
507 register_builtin( &MENU_builtin_class );
508 register_builtin( &SCROLL_builtin_class );
509 register_builtin( &STATIC_builtin_class );
513 /***********************************************************************
516 * Add a new window using this class, and set the necessary
517 * information inside the window structure.
519 void CLASS_AddWindow( CLASS *class, WND *win, WINDOWPROCTYPE type )
521 if (type == WIN_PROC_32W)
523 if (!(win->winproc = class->winprocW)) win->winproc = class->winprocA;
527 if (!(win->winproc = class->winprocA)) win->winproc = class->winprocW;
530 win->clsStyle = class->style;
534 /***********************************************************************
535 * RegisterClassA (USER32.@)
537 * Register a window class.
540 * >0: Unique identifier
543 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
547 wcex.cbSize = sizeof(wcex);
548 wcex.style = wc->style;
549 wcex.lpfnWndProc = wc->lpfnWndProc;
550 wcex.cbClsExtra = wc->cbClsExtra;
551 wcex.cbWndExtra = wc->cbWndExtra;
552 wcex.hInstance = wc->hInstance;
553 wcex.hIcon = wc->hIcon;
554 wcex.hCursor = wc->hCursor;
555 wcex.hbrBackground = wc->hbrBackground;
556 wcex.lpszMenuName = wc->lpszMenuName;
557 wcex.lpszClassName = wc->lpszClassName;
559 return RegisterClassExA( &wcex );
563 /***********************************************************************
564 * RegisterClassW (USER32.@)
566 * See RegisterClassA.
568 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
572 wcex.cbSize = sizeof(wcex);
573 wcex.style = wc->style;
574 wcex.lpfnWndProc = wc->lpfnWndProc;
575 wcex.cbClsExtra = wc->cbClsExtra;
576 wcex.cbWndExtra = wc->cbWndExtra;
577 wcex.hInstance = wc->hInstance;
578 wcex.hIcon = wc->hIcon;
579 wcex.hCursor = wc->hCursor;
580 wcex.hbrBackground = wc->hbrBackground;
581 wcex.lpszMenuName = wc->lpszMenuName;
582 wcex.lpszClassName = wc->lpszClassName;
584 return RegisterClassExW( &wcex );
588 /***********************************************************************
589 * RegisterClassExA (USER32.@)
591 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
597 if (wc->hInstance == user32_module)
599 /* we can't register a class for user32 */
600 SetLastError( ERROR_INVALID_PARAMETER );
603 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
605 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
607 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
608 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
611 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
612 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
613 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
615 classPtr->hIcon = wc->hIcon;
616 classPtr->hIconSm = wc->hIconSm;
617 classPtr->hCursor = wc->hCursor;
618 classPtr->hbrBackground = wc->hbrBackground;
619 classPtr->winprocA = WINPROC_AllocProc( wc->lpfnWndProc, WIN_PROC_32A );
620 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
621 release_class_ptr( classPtr );
626 /***********************************************************************
627 * RegisterClassExW (USER32.@)
629 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
635 if (wc->hInstance == user32_module)
637 /* we can't register a class for user32 */
638 SetLastError( ERROR_INVALID_PARAMETER );
641 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
643 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
645 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
646 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
649 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
650 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
651 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
653 classPtr->hIcon = wc->hIcon;
654 classPtr->hIconSm = wc->hIconSm;
655 classPtr->hCursor = wc->hCursor;
656 classPtr->hbrBackground = wc->hbrBackground;
657 classPtr->winprocW = WINPROC_AllocProc( wc->lpfnWndProc, WIN_PROC_32W );
658 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
659 release_class_ptr( classPtr );
664 /***********************************************************************
665 * UnregisterClassA (USER32.@)
667 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
669 ATOM atom = HIWORD(className) ? GlobalFindAtomA( className ) : LOWORD(className);
670 return UnregisterClassW( MAKEINTATOMW(atom), hInstance );
673 /***********************************************************************
674 * UnregisterClassW (USER32.@)
676 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
678 CLASS *classPtr = NULL;
679 ATOM atom = HIWORD(className) ? GlobalFindAtomW( className ) : LOWORD(className);
681 TRACE("%s %p %x\n",debugstr_w(className), hInstance, atom);
685 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
689 SERVER_START_REQ( destroy_class )
692 req->instance = hInstance;
693 if (!wine_server_call_err( req )) classPtr = reply->client_ptr;
697 if (classPtr) CLASS_FreeClass( classPtr );
698 return (classPtr != NULL);
702 /***********************************************************************
703 * GetClassWord (USER32.@)
705 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
710 if (offset < 0) return GetClassLongA( hwnd, offset );
712 TRACE("%p %x\n",hwnd, offset);
714 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
716 if (class == CLASS_OTHER_PROCESS)
718 SERVER_START_REQ( set_class_info )
722 req->extra_offset = offset;
723 req->extra_size = sizeof(retvalue);
724 if (!wine_server_call_err( req ))
725 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
731 if (offset <= class->cbClsExtra - sizeof(WORD))
732 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
734 SetLastError( ERROR_INVALID_INDEX );
735 release_class_ptr( class );
740 /***********************************************************************
741 * GetClassLong (USER.131)
743 LONG WINAPI GetClassLong16( HWND16 hwnd16, INT16 offset )
747 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
749 TRACE("%p %d\n",hwnd, offset);
754 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
755 if (class == CLASS_OTHER_PROCESS) break;
756 ret = (LONG)CLASS_GetProc16( class );
757 release_class_ptr( class );
760 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
761 if (class == CLASS_OTHER_PROCESS) break;
762 ret = (LONG)CLASS_GetMenuName16( class );
763 release_class_ptr( class );
766 return GetClassLongA( hwnd, offset );
768 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
769 SetLastError( ERROR_INVALID_HANDLE );
774 /***********************************************************************
775 * GetClassLongW (USER32.@)
777 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
782 TRACE("%p %d\n", hwnd, offset);
784 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
786 if (class == CLASS_OTHER_PROCESS)
788 SERVER_START_REQ( set_class_info )
792 req->extra_offset = (offset >= 0) ? offset : -1;
793 req->extra_size = (offset >= 0) ? sizeof(retvalue) : 0;
794 if (!wine_server_call_err( req ))
798 case GCLP_HBRBACKGROUND:
804 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
805 SetLastError( ERROR_INVALID_HANDLE );
808 retvalue = reply->old_style;
811 retvalue = reply->old_win_extra;
814 retvalue = reply->old_extra;
817 retvalue = (DWORD)reply->old_instance;
820 retvalue = reply->old_atom;
823 if (offset >= 0) memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
824 else SetLastError( ERROR_INVALID_INDEX );
835 if (offset <= class->cbClsExtra - sizeof(LONG))
836 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
838 SetLastError( ERROR_INVALID_INDEX );
839 release_class_ptr( class );
845 case GCLP_HBRBACKGROUND:
846 retvalue = (DWORD)class->hbrBackground;
849 retvalue = (DWORD)class->hCursor;
852 retvalue = (DWORD)class->hIcon;
855 retvalue = (DWORD)class->hIconSm;
858 retvalue = (DWORD)class->style;
861 retvalue = (DWORD)class->cbWndExtra;
864 retvalue = (DWORD)class->cbClsExtra;
867 retvalue = (DWORD)class->hInstance;
870 retvalue = (DWORD)CLASS_GetProc( class, WIN_PROC_32W );
873 retvalue = (DWORD)CLASS_GetMenuNameW( class );
876 retvalue = (DWORD)class->atomName;
879 SetLastError( ERROR_INVALID_INDEX );
882 release_class_ptr( class );
887 /***********************************************************************
888 * GetClassLongA (USER32.@)
890 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
895 if (offset != GCLP_WNDPROC && offset != GCLP_MENUNAME)
896 return GetClassLongW( hwnd, offset );
898 TRACE("%p %d\n", hwnd, offset);
900 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
902 if (class == CLASS_OTHER_PROCESS)
904 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
905 SetLastError( ERROR_INVALID_HANDLE );
909 if (offset == GCLP_WNDPROC)
910 retvalue = (DWORD)CLASS_GetProc( class, WIN_PROC_32A );
911 else /* GCL_MENUNAME */
912 retvalue = (DWORD)CLASS_GetMenuNameA( class );
914 release_class_ptr( class );
919 /***********************************************************************
920 * SetClassWord (USER32.@)
922 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
927 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
929 TRACE("%p %d %x\n", hwnd, offset, newval);
931 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
933 SERVER_START_REQ( set_class_info )
936 req->flags = SET_CLASS_EXTRA;
937 req->extra_offset = offset;
938 req->extra_size = sizeof(newval);
939 memcpy( &req->extra_value, &newval, sizeof(newval) );
940 if (!wine_server_call_err( req ))
942 void *ptr = (char *)(class + 1) + offset;
943 memcpy( &retval, ptr, sizeof(retval) );
944 memcpy( ptr, &newval, sizeof(newval) );
948 release_class_ptr( class );
953 /***********************************************************************
954 * SetClassLong (USER.132)
956 LONG WINAPI SetClassLong16( HWND16 hwnd16, INT16 offset, LONG newval )
960 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
962 TRACE("%p %d %lx\n", hwnd, offset, newval);
967 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
968 retval = (LONG)CLASS_GetProc16( class );
969 CLASS_SetProc16( class, (WNDPROC16)newval );
970 release_class_ptr( class );
973 newval = (LONG)MapSL( newval );
976 return SetClassLongA( hwnd, offset, newval );
981 /***********************************************************************
982 * SetClassLongW (USER32.@)
984 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
989 TRACE("%p %d %lx\n", hwnd, offset, newval);
991 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
995 if (set_server_info( hwnd, offset, newval ))
997 void *ptr = (char *)(class + 1) + offset;
998 memcpy( &retval, ptr, sizeof(retval) );
999 memcpy( ptr, &newval, sizeof(newval) );
1005 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
1006 retval = 0; /* Old value is now meaningless anyway */
1009 retval = (DWORD)CLASS_GetProc( class, WIN_PROC_32W );
1010 CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32W );
1012 case GCLP_HBRBACKGROUND:
1013 retval = (DWORD)class->hbrBackground;
1014 class->hbrBackground = (HBRUSH)newval;
1017 retval = (DWORD)class->hCursor;
1018 class->hCursor = (HCURSOR)newval;
1021 retval = (DWORD)class->hIcon;
1022 class->hIcon = (HICON)newval;
1025 retval = (DWORD)class->hIconSm;
1026 class->hIconSm = (HICON)newval;
1029 if (!set_server_info( hwnd, offset, newval )) break;
1030 retval = (DWORD)class->style;
1031 class->style = newval;
1033 case GCL_CBWNDEXTRA:
1034 if (!set_server_info( hwnd, offset, newval )) break;
1035 retval = (DWORD)class->cbWndExtra;
1036 class->cbWndExtra = newval;
1039 if (!set_server_info( hwnd, offset, newval )) break;
1040 retval = (DWORD)class->hInstance;
1041 class->hInstance = (HINSTANCE)newval;
1044 if (!set_server_info( hwnd, offset, newval )) break;
1045 retval = (DWORD)class->atomName;
1046 class->atomName = newval;
1048 case GCL_CBCLSEXTRA: /* cannot change this one */
1049 SetLastError( ERROR_INVALID_PARAMETER );
1052 SetLastError( ERROR_INVALID_INDEX );
1055 release_class_ptr( class );
1060 /***********************************************************************
1061 * SetClassLongA (USER32.@)
1063 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
1068 if (offset != GCLP_WNDPROC && offset != GCLP_MENUNAME)
1069 return SetClassLongW( hwnd, offset, newval );
1071 TRACE("%p %d %lx\n", hwnd, offset, newval);
1073 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
1075 if (offset == GCLP_WNDPROC)
1077 retval = (DWORD)CLASS_GetProc( class, WIN_PROC_32A );
1078 CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32A );
1080 else /* GCL_MENUNAME */
1082 CLASS_SetMenuNameA( class, (LPCSTR)newval );
1083 retval = 0; /* Old value is now meaningless anyway */
1085 release_class_ptr( class );
1090 /***********************************************************************
1091 * GetClassNameA (USER32.@)
1093 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
1095 INT ret = GlobalGetAtomNameA( GetClassLongA( hwnd, GCW_ATOM ), buffer, count );
1097 TRACE("%p %s %x\n",hwnd, debugstr_a(buffer), count);
1102 /***********************************************************************
1103 * GetClassNameW (USER32.@)
1105 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
1107 INT ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), buffer, count );
1109 TRACE("%p %s %x\n",hwnd, debugstr_w(buffer), count);
1114 /***********************************************************************
1115 * RealGetWindowClassA (USER32.@)
1117 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1119 return GetClassNameA( hwnd, buffer, count );
1123 /***********************************************************************
1124 * RealGetWindowClassW (USER32.@)
1126 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1128 return GetClassNameW( hwnd, buffer, count );
1132 /***********************************************************************
1133 * GetClassInfoA (USER32.@)
1135 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1138 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1142 wc->style = wcex.style;
1143 wc->lpfnWndProc = wcex.lpfnWndProc;
1144 wc->cbClsExtra = wcex.cbClsExtra;
1145 wc->cbWndExtra = wcex.cbWndExtra;
1146 wc->hInstance = wcex.hInstance;
1147 wc->hIcon = wcex.hIcon;
1148 wc->hCursor = wcex.hCursor;
1149 wc->hbrBackground = wcex.hbrBackground;
1150 wc->lpszMenuName = wcex.lpszMenuName;
1151 wc->lpszClassName = wcex.lpszClassName;
1157 /***********************************************************************
1158 * GetClassInfoW (USER32.@)
1160 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1163 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1167 wc->style = wcex.style;
1168 wc->lpfnWndProc = wcex.lpfnWndProc;
1169 wc->cbClsExtra = wcex.cbClsExtra;
1170 wc->cbWndExtra = wcex.cbWndExtra;
1171 wc->hInstance = wcex.hInstance;
1172 wc->hIcon = wcex.hIcon;
1173 wc->hCursor = wcex.hCursor;
1174 wc->hbrBackground = wcex.hbrBackground;
1175 wc->lpszMenuName = wcex.lpszMenuName;
1176 wc->lpszClassName = wcex.lpszClassName;
1182 /***********************************************************************
1183 * GetClassInfoExA (USER32.@)
1185 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1187 ATOM atom = HIWORD(name) ? GlobalFindAtomA( name ) : LOWORD(name);
1190 TRACE("%p %s %x %p\n", hInstance, debugstr_a(name), atom, wc);
1192 if (!hInstance) hInstance = user32_module;
1194 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1196 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1199 wc->style = classPtr->style;
1200 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32A );
1201 wc->cbClsExtra = classPtr->cbClsExtra;
1202 wc->cbWndExtra = classPtr->cbWndExtra;
1203 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1204 wc->hIcon = (HICON)classPtr->hIcon;
1205 wc->hIconSm = (HICON)classPtr->hIconSm;
1206 wc->hCursor = (HCURSOR)classPtr->hCursor;
1207 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1208 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1209 wc->lpszClassName = name;
1210 release_class_ptr( classPtr );
1212 /* We must return the atom of the class here instead of just TRUE. */
1217 /***********************************************************************
1218 * GetClassInfoExW (USER32.@)
1220 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1222 ATOM atom = HIWORD(name) ? GlobalFindAtomW( name ) : LOWORD(name);
1225 TRACE("%p %s %x %p\n", hInstance, debugstr_w(name), atom, wc);
1227 if (!hInstance) hInstance = user32_module;
1229 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1231 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1234 wc->style = classPtr->style;
1235 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32W );
1236 wc->cbClsExtra = classPtr->cbClsExtra;
1237 wc->cbWndExtra = classPtr->cbWndExtra;
1238 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1239 wc->hIcon = (HICON)classPtr->hIcon;
1240 wc->hIconSm = (HICON)classPtr->hIconSm;
1241 wc->hCursor = (HCURSOR)classPtr->hCursor;
1242 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1243 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1244 wc->lpszClassName = name;
1245 release_class_ptr( classPtr );
1247 /* We must return the atom of the class here instead of just TRUE. */
1252 #if 0 /* toolhelp is in kernel, so this cannot work */
1254 /***********************************************************************
1255 * ClassFirst (TOOLHELP.69)
1257 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1259 TRACE("%p\n",pClassEntry);
1260 pClassEntry->wNext = 1;
1261 return ClassNext16( pClassEntry );
1265 /***********************************************************************
1266 * ClassNext (TOOLHELP.70)
1268 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1271 CLASS *class = firstClass;
1273 TRACE("%p\n",pClassEntry);
1275 if (!pClassEntry->wNext) return FALSE;
1276 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1279 pClassEntry->wNext = 0;
1282 pClassEntry->hInst = class->hInstance;
1283 pClassEntry->wNext++;
1284 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1285 sizeof(pClassEntry->szClassName) );