2 * Window classes functions
4 * Copyright 1993, 1996, 2003 Alexandre Julliard
5 * Copyright 1998 Juergen Schmied (jsch)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
34 #include "wine/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 winproc
; /* Window procedure */
52 INT cbClsExtra
; /* Class extra bytes */
53 INT cbWndExtra
; /* Window extra bytes */
54 LPWSTR menuName
; /* Default menu name (Unicode followed by ASCII) */
55 HINSTANCE hInstance
; /* Module that created the task */
56 HICON hIcon
; /* Default icon */
57 HICON hIconSm
; /* Default small icon */
58 HCURSOR hCursor
; /* Default cursor */
59 HBRUSH hbrBackground
; /* Default background */
60 ATOM atomName
; /* Name of the class */
63 static struct list class_list
= LIST_INIT( class_list
);
65 #define CLASS_OTHER_PROCESS ((CLASS *)1)
67 /***********************************************************************
70 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
72 WND
*ptr
= WIN_GetPtr( hwnd
);
76 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
) return ptr
->class;
77 if (!write_access
) return CLASS_OTHER_PROCESS
;
79 /* modifying classes in other processes is not allowed */
80 if (ptr
== WND_DESKTOP
|| IsWindow( hwnd
))
82 SetLastError( ERROR_ACCESS_DENIED
);
86 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
91 /***********************************************************************
94 inline static void release_class_ptr( CLASS
*ptr
)
100 /***********************************************************************
103 * Set class info with the wine server.
105 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG newval
)
109 SERVER_START_REQ( set_class_info
)
112 req
->extra_offset
= -1;
116 req
->flags
= SET_CLASS_ATOM
;
119 req
->flags
= SET_CLASS_STYLE
;
123 req
->flags
= SET_CLASS_WINEXTRA
;
124 req
->win_extra
= newval
;
127 req
->flags
= SET_CLASS_INSTANCE
;
128 req
->instance
= (void *)newval
;
131 assert( offset
>= 0 );
132 req
->flags
= SET_CLASS_EXTRA
;
133 req
->extra_offset
= offset
;
134 req
->extra_size
= sizeof(newval
);
135 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
138 ret
= !wine_server_call_err( req
);
145 /***********************************************************************
148 * Get the menu name as a ASCII string.
150 inline static LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
152 if (!HIWORD(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
153 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
157 /***********************************************************************
160 * Get the menu name as a Unicode string.
162 inline static LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
164 return classPtr
->menuName
;
168 /***********************************************************************
171 * Set the menu name in a class structure by copying the string.
173 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
175 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
178 DWORD lenA
= strlen(name
) + 1;
179 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
180 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
181 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
182 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
184 else classPtr
->menuName
= (LPWSTR
)name
;
188 /***********************************************************************
191 * Set the menu name in a class structure by copying the string.
193 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
195 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
198 DWORD lenW
= strlenW(name
) + 1;
199 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
200 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
201 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
202 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
203 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
205 else classPtr
->menuName
= (LPWSTR
)name
;
209 /***********************************************************************
212 * Free a class structure.
214 static void CLASS_FreeClass( CLASS
*classPtr
)
216 TRACE("%p\n", classPtr
);
220 list_remove( &classPtr
->entry
);
221 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
222 DeleteObject( classPtr
->hbrBackground
);
223 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
224 HeapFree( GetProcessHeap(), 0, classPtr
);
229 /***********************************************************************
230 * CLASS_FreeModuleClasses
232 void CLASS_FreeModuleClasses( HMODULE16 hModule
)
234 struct list
*ptr
, *next
;
236 TRACE("0x%08x\n", hModule
);
239 for (ptr
= list_head( &class_list
); ptr
; ptr
= next
)
241 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
242 next
= list_next( &class_list
, ptr
);
243 if (class->hInstance
== HINSTANCE_32(hModule
))
247 SERVER_START_REQ( destroy_class
)
249 req
->atom
= class->atomName
;
250 req
->instance
= class->hInstance
;
251 ret
= !wine_server_call_err( req
);
254 if (ret
) CLASS_FreeClass( class );
261 /***********************************************************************
262 * CLASS_FindClassByAtom
264 * Return a pointer to the class.
265 * hinstance has been normalized by the caller.
267 static CLASS
*CLASS_FindClassByAtom( ATOM atom
, HINSTANCE hinstance
)
273 LIST_FOR_EACH( ptr
, &class_list
)
275 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
276 if (class->atomName
!= atom
) continue;
277 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
279 TRACE("0x%04x %p -> %p\n", atom
, hinstance
, class);
284 TRACE("0x%04x %p -> not found\n", atom
, hinstance
);
289 /***********************************************************************
290 * CLASS_RegisterClass
292 * The real RegisterClass() functionality.
293 * The atom is deleted no matter what.
295 static CLASS
*CLASS_RegisterClass( ATOM atom
, HINSTANCE hInstance
, BOOL local
,
296 DWORD style
, INT classExtra
, INT winExtra
)
301 TRACE("atom=0x%x hinst=%p style=0x%lx clExtr=0x%x winExtr=0x%x\n",
302 atom
, hInstance
, style
, classExtra
, winExtra
);
304 /* Fix the extra bytes value */
306 if (classExtra
< 0 || winExtra
< 0)
308 SetLastError( ERROR_INVALID_PARAMETER
);
311 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
312 WARN("Class extra bytes %d is > 40\n", classExtra
);
313 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
314 WARN("Win extra bytes %d is > 40\n", winExtra
);
316 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
319 GlobalDeleteAtom( atom
);
323 SERVER_START_REQ( create_class
)
328 req
->instance
= hInstance
;
329 req
->extra
= classExtra
;
330 req
->win_extra
= winExtra
;
331 req
->client_ptr
= classPtr
;
332 ret
= !wine_server_call_err( req
);
335 GlobalDeleteAtom( atom
); /* the server increased the atom ref count */
338 HeapFree( GetProcessHeap(), 0, classPtr
);
342 classPtr
->style
= style
;
343 classPtr
->local
= local
;
344 classPtr
->cbWndExtra
= winExtra
;
345 classPtr
->cbClsExtra
= classExtra
;
346 classPtr
->hInstance
= hInstance
;
347 classPtr
->atomName
= atom
;
349 /* Other non-null values must be set by caller */
352 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
353 else list_add_tail( &class_list
, &classPtr
->entry
);
358 /***********************************************************************
361 * Register a builtin control class.
362 * This allows having both ASCII and Unicode winprocs for the same class.
364 static CLASS
*register_builtin( const struct builtin_class_descr
*descr
)
369 if (!(atom
= GlobalAddAtomA( descr
->name
))) return 0;
371 if (!(classPtr
= CLASS_RegisterClass( atom
, user32_module
, FALSE
,
372 descr
->style
, 0, descr
->extra
))) return 0;
374 classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
375 classPtr
->hbrBackground
= descr
->brush
;
376 classPtr
->winproc
= WINPROC_AllocProc( descr
->procA
, descr
->procW
);
377 release_class_ptr( classPtr
);
382 /***********************************************************************
383 * CLASS_RegisterBuiltinClasses
385 void CLASS_RegisterBuiltinClasses(void)
387 extern const struct builtin_class_descr BUTTON_builtin_class
;
388 extern const struct builtin_class_descr COMBO_builtin_class
;
389 extern const struct builtin_class_descr COMBOLBOX_builtin_class
;
390 extern const struct builtin_class_descr DIALOG_builtin_class
;
391 extern const struct builtin_class_descr DESKTOP_builtin_class
;
392 extern const struct builtin_class_descr EDIT_builtin_class
;
393 extern const struct builtin_class_descr ICONTITLE_builtin_class
;
394 extern const struct builtin_class_descr LISTBOX_builtin_class
;
395 extern const struct builtin_class_descr MDICLIENT_builtin_class
;
396 extern const struct builtin_class_descr MENU_builtin_class
;
397 extern const struct builtin_class_descr SCROLL_builtin_class
;
398 extern const struct builtin_class_descr STATIC_builtin_class
;
400 register_builtin( &DESKTOP_builtin_class
);
401 register_builtin( &BUTTON_builtin_class
);
402 register_builtin( &COMBO_builtin_class
);
403 register_builtin( &COMBOLBOX_builtin_class
);
404 register_builtin( &DIALOG_builtin_class
);
405 register_builtin( &EDIT_builtin_class
);
406 register_builtin( &ICONTITLE_builtin_class
);
407 register_builtin( &LISTBOX_builtin_class
);
408 register_builtin( &MDICLIENT_builtin_class
);
409 register_builtin( &MENU_builtin_class
);
410 register_builtin( &SCROLL_builtin_class
);
411 register_builtin( &STATIC_builtin_class
);
415 /***********************************************************************
418 * Add a new window using this class, and set the necessary
419 * information inside the window structure.
421 void CLASS_AddWindow( CLASS
*class, WND
*win
, BOOL unicode
)
424 win
->clsStyle
= class->style
;
425 win
->winproc
= class->winproc
;
426 if (WINPROC_IsUnicode( win
->winproc
, unicode
)) win
->flags
|= WIN_ISUNICODE
;
430 /***********************************************************************
431 * RegisterClassA (USER32.@)
433 * Register a window class.
436 * >0: Unique identifier
439 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
443 wcex
.cbSize
= sizeof(wcex
);
444 wcex
.style
= wc
->style
;
445 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
446 wcex
.cbClsExtra
= wc
->cbClsExtra
;
447 wcex
.cbWndExtra
= wc
->cbWndExtra
;
448 wcex
.hInstance
= wc
->hInstance
;
449 wcex
.hIcon
= wc
->hIcon
;
450 wcex
.hCursor
= wc
->hCursor
;
451 wcex
.hbrBackground
= wc
->hbrBackground
;
452 wcex
.lpszMenuName
= wc
->lpszMenuName
;
453 wcex
.lpszClassName
= wc
->lpszClassName
;
455 return RegisterClassExA( &wcex
);
459 /***********************************************************************
460 * RegisterClassW (USER32.@)
462 * See RegisterClassA.
464 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
468 wcex
.cbSize
= sizeof(wcex
);
469 wcex
.style
= wc
->style
;
470 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
471 wcex
.cbClsExtra
= wc
->cbClsExtra
;
472 wcex
.cbWndExtra
= wc
->cbWndExtra
;
473 wcex
.hInstance
= wc
->hInstance
;
474 wcex
.hIcon
= wc
->hIcon
;
475 wcex
.hCursor
= wc
->hCursor
;
476 wcex
.hbrBackground
= wc
->hbrBackground
;
477 wcex
.lpszMenuName
= wc
->lpszMenuName
;
478 wcex
.lpszClassName
= wc
->lpszClassName
;
480 return RegisterClassExW( &wcex
);
484 /***********************************************************************
485 * RegisterClassExA (USER32.@)
487 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
493 if (wc
->hInstance
== user32_module
)
495 /* we can't register a class for user32 */
496 SetLastError( ERROR_INVALID_PARAMETER
);
499 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
501 if (!(atom
= GlobalAddAtomA( wc
->lpszClassName
))) return 0;
503 if (!(classPtr
= CLASS_RegisterClass( atom
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
504 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
507 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
508 atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
509 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
511 classPtr
->hIcon
= wc
->hIcon
;
512 classPtr
->hIconSm
= wc
->hIconSm
;
513 classPtr
->hCursor
= wc
->hCursor
;
514 classPtr
->hbrBackground
= wc
->hbrBackground
;
515 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, NULL
);
516 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
517 release_class_ptr( classPtr
);
522 /***********************************************************************
523 * RegisterClassExW (USER32.@)
525 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
531 if (wc
->hInstance
== user32_module
)
533 /* we can't register a class for user32 */
534 SetLastError( ERROR_INVALID_PARAMETER
);
537 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
539 if (!(atom
= GlobalAddAtomW( wc
->lpszClassName
))) return 0;
541 if (!(classPtr
= CLASS_RegisterClass( atom
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
542 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
545 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
546 atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
547 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
549 classPtr
->hIcon
= wc
->hIcon
;
550 classPtr
->hIconSm
= wc
->hIconSm
;
551 classPtr
->hCursor
= wc
->hCursor
;
552 classPtr
->hbrBackground
= wc
->hbrBackground
;
553 classPtr
->winproc
= WINPROC_AllocProc( NULL
, wc
->lpfnWndProc
);
554 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
555 release_class_ptr( classPtr
);
560 /***********************************************************************
561 * UnregisterClassA (USER32.@)
563 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
565 ATOM atom
= HIWORD(className
) ? GlobalFindAtomA( className
) : LOWORD(className
);
566 return UnregisterClassW( MAKEINTATOMW(atom
), hInstance
);
569 /***********************************************************************
570 * UnregisterClassW (USER32.@)
572 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
574 CLASS
*classPtr
= NULL
;
575 ATOM atom
= HIWORD(className
) ? GlobalFindAtomW( className
) : LOWORD(className
);
577 TRACE("%s %p %x\n",debugstr_w(className
), hInstance
, atom
);
581 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
585 SERVER_START_REQ( destroy_class
)
588 req
->instance
= hInstance
;
589 if (!wine_server_call_err( req
)) classPtr
= reply
->client_ptr
;
593 if (classPtr
) CLASS_FreeClass( classPtr
);
594 return (classPtr
!= NULL
);
598 /***********************************************************************
599 * GetClassWord (USER32.@)
601 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
606 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
608 TRACE("%p %x\n",hwnd
, offset
);
610 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
612 if (class == CLASS_OTHER_PROCESS
)
614 SERVER_START_REQ( set_class_info
)
618 req
->extra_offset
= offset
;
619 req
->extra_size
= sizeof(retvalue
);
620 if (!wine_server_call_err( req
))
621 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
627 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
628 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
630 SetLastError( ERROR_INVALID_INDEX
);
631 release_class_ptr( class );
636 /***********************************************************************
637 * GetClassLongW (USER32.@)
639 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
644 TRACE("%p %d\n", hwnd
, offset
);
646 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
648 if (class == CLASS_OTHER_PROCESS
)
650 SERVER_START_REQ( set_class_info
)
654 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
655 req
->extra_size
= (offset
>= 0) ? sizeof(retvalue
) : 0;
656 if (!wine_server_call_err( req
))
660 case GCLP_HBRBACKGROUND
:
666 FIXME( "offset %d not supported on other process window %p\n", offset
, hwnd
);
667 SetLastError( ERROR_INVALID_HANDLE
);
670 retvalue
= reply
->old_style
;
673 retvalue
= reply
->old_win_extra
;
676 retvalue
= reply
->old_extra
;
679 retvalue
= (DWORD
)reply
->old_instance
;
682 retvalue
= reply
->old_atom
;
685 if (offset
>= 0) memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
686 else SetLastError( ERROR_INVALID_INDEX
);
697 if (offset
<= class->cbClsExtra
- sizeof(LONG
))
698 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
700 SetLastError( ERROR_INVALID_INDEX
);
701 release_class_ptr( class );
707 case GCLP_HBRBACKGROUND
:
708 retvalue
= (DWORD
)class->hbrBackground
;
711 retvalue
= (DWORD
)class->hCursor
;
714 retvalue
= (DWORD
)class->hIcon
;
717 retvalue
= (DWORD
)class->hIconSm
;
720 retvalue
= (DWORD
)class->style
;
723 retvalue
= (DWORD
)class->cbWndExtra
;
726 retvalue
= (DWORD
)class->cbClsExtra
;
729 retvalue
= (DWORD
)class->hInstance
;
732 retvalue
= (DWORD
)WINPROC_GetProc( class->winproc
, TRUE
);
735 retvalue
= (DWORD
)CLASS_GetMenuNameW( class );
738 retvalue
= (DWORD
)class->atomName
;
741 SetLastError( ERROR_INVALID_INDEX
);
744 release_class_ptr( class );
749 /***********************************************************************
750 * GetClassLongA (USER32.@)
752 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
757 if (offset
!= GCLP_WNDPROC
&& offset
!= GCLP_MENUNAME
)
758 return GetClassLongW( hwnd
, offset
);
760 TRACE("%p %d\n", hwnd
, offset
);
762 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
764 if (class == CLASS_OTHER_PROCESS
)
766 FIXME( "offset %d not supported on other process window %p\n", offset
, hwnd
);
767 SetLastError( ERROR_INVALID_HANDLE
);
771 if (offset
== GCLP_WNDPROC
)
772 retvalue
= (DWORD
)WINPROC_GetProc( class->winproc
, FALSE
);
773 else /* GCL_MENUNAME */
774 retvalue
= (DWORD
)CLASS_GetMenuNameA( class );
776 release_class_ptr( class );
781 /***********************************************************************
782 * SetClassWord (USER32.@)
784 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
789 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
791 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
793 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
795 SERVER_START_REQ( set_class_info
)
798 req
->flags
= SET_CLASS_EXTRA
;
799 req
->extra_offset
= offset
;
800 req
->extra_size
= sizeof(newval
);
801 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
802 if (!wine_server_call_err( req
))
804 void *ptr
= (char *)(class + 1) + offset
;
805 memcpy( &retval
, ptr
, sizeof(retval
) );
806 memcpy( ptr
, &newval
, sizeof(newval
) );
810 release_class_ptr( class );
815 /***********************************************************************
816 * SetClassLongW (USER32.@)
818 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
823 TRACE("%p %d %lx\n", hwnd
, offset
, newval
);
825 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
829 if (set_server_info( hwnd
, offset
, newval
))
831 void *ptr
= (char *)(class + 1) + offset
;
832 memcpy( &retval
, ptr
, sizeof(retval
) );
833 memcpy( ptr
, &newval
, sizeof(newval
) );
839 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
840 retval
= 0; /* Old value is now meaningless anyway */
843 retval
= (DWORD
)WINPROC_GetProc( class->winproc
, TRUE
);
844 class->winproc
= WINPROC_AllocProc( NULL
, (WNDPROC
)newval
);
846 case GCLP_HBRBACKGROUND
:
847 retval
= (DWORD
)class->hbrBackground
;
848 class->hbrBackground
= (HBRUSH
)newval
;
851 retval
= (DWORD
)class->hCursor
;
852 class->hCursor
= (HCURSOR
)newval
;
855 retval
= (DWORD
)class->hIcon
;
856 class->hIcon
= (HICON
)newval
;
859 retval
= (DWORD
)class->hIconSm
;
860 class->hIconSm
= (HICON
)newval
;
863 if (!set_server_info( hwnd
, offset
, newval
)) break;
864 retval
= (DWORD
)class->style
;
865 class->style
= newval
;
868 if (!set_server_info( hwnd
, offset
, newval
)) break;
869 retval
= (DWORD
)class->cbWndExtra
;
870 class->cbWndExtra
= newval
;
873 if (!set_server_info( hwnd
, offset
, newval
)) break;
874 retval
= (DWORD
)class->hInstance
;
875 class->hInstance
= (HINSTANCE
)newval
;
878 if (!set_server_info( hwnd
, offset
, newval
)) break;
879 retval
= (DWORD
)class->atomName
;
880 class->atomName
= newval
;
882 case GCL_CBCLSEXTRA
: /* cannot change this one */
883 SetLastError( ERROR_INVALID_PARAMETER
);
886 SetLastError( ERROR_INVALID_INDEX
);
889 release_class_ptr( class );
894 /***********************************************************************
895 * SetClassLongA (USER32.@)
897 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
902 if (offset
!= GCLP_WNDPROC
&& offset
!= GCLP_MENUNAME
)
903 return SetClassLongW( hwnd
, offset
, newval
);
905 TRACE("%p %d %lx\n", hwnd
, offset
, newval
);
907 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
909 if (offset
== GCLP_WNDPROC
)
911 retval
= (DWORD
)WINPROC_GetProc( class->winproc
, FALSE
);
912 class->winproc
= WINPROC_AllocProc( (WNDPROC
)newval
, NULL
);
914 else /* GCL_MENUNAME */
916 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
917 retval
= 0; /* Old value is now meaningless anyway */
919 release_class_ptr( class );
924 /***********************************************************************
925 * GetClassNameA (USER32.@)
927 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
929 INT ret
= GlobalGetAtomNameA( GetClassLongA( hwnd
, GCW_ATOM
), buffer
, count
);
931 TRACE("%p %s %x\n",hwnd
, debugstr_a(buffer
), count
);
936 /***********************************************************************
937 * GetClassNameW (USER32.@)
939 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
941 INT ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), buffer
, count
);
943 TRACE("%p %s %x\n",hwnd
, debugstr_w(buffer
), count
);
948 /***********************************************************************
949 * RealGetWindowClassA (USER32.@)
951 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
953 return GetClassNameA( hwnd
, buffer
, count
);
957 /***********************************************************************
958 * RealGetWindowClassW (USER32.@)
960 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
962 return GetClassNameW( hwnd
, buffer
, count
);
966 /***********************************************************************
967 * GetClassInfoA (USER32.@)
969 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
972 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
976 wc
->style
= wcex
.style
;
977 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
978 wc
->cbClsExtra
= wcex
.cbClsExtra
;
979 wc
->cbWndExtra
= wcex
.cbWndExtra
;
980 wc
->hInstance
= wcex
.hInstance
;
981 wc
->hIcon
= wcex
.hIcon
;
982 wc
->hCursor
= wcex
.hCursor
;
983 wc
->hbrBackground
= wcex
.hbrBackground
;
984 wc
->lpszMenuName
= wcex
.lpszMenuName
;
985 wc
->lpszClassName
= wcex
.lpszClassName
;
991 /***********************************************************************
992 * GetClassInfoW (USER32.@)
994 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
997 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1001 wc
->style
= wcex
.style
;
1002 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1003 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1004 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1005 wc
->hInstance
= wcex
.hInstance
;
1006 wc
->hIcon
= wcex
.hIcon
;
1007 wc
->hCursor
= wcex
.hCursor
;
1008 wc
->hbrBackground
= wcex
.hbrBackground
;
1009 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1010 wc
->lpszClassName
= wcex
.lpszClassName
;
1016 /***********************************************************************
1017 * GetClassInfoExA (USER32.@)
1019 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1021 ATOM atom
= HIWORD(name
) ? GlobalFindAtomA( name
) : LOWORD(name
);
1024 TRACE("%p %s %x %p\n", hInstance
, debugstr_a(name
), atom
, wc
);
1026 if (!hInstance
) hInstance
= user32_module
;
1028 if (!atom
|| !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
1030 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1033 wc
->style
= classPtr
->style
;
1034 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1035 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1036 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1037 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1038 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1039 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1040 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1041 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1042 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1043 wc
->lpszClassName
= name
;
1044 release_class_ptr( classPtr
);
1046 /* We must return the atom of the class here instead of just TRUE. */
1051 /***********************************************************************
1052 * GetClassInfoExW (USER32.@)
1054 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1056 ATOM atom
= HIWORD(name
) ? GlobalFindAtomW( name
) : LOWORD(name
);
1059 TRACE("%p %s %x %p\n", hInstance
, debugstr_w(name
), atom
, wc
);
1061 if (!hInstance
) hInstance
= user32_module
;
1063 if (!atom
|| !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
1065 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1068 wc
->style
= classPtr
->style
;
1069 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1070 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1071 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1072 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1073 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1074 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1075 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1076 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1077 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1078 wc
->lpszClassName
= name
;
1079 release_class_ptr( classPtr
);
1081 /* We must return the atom of the class here instead of just TRUE. */
1086 #if 0 /* toolhelp is in kernel, so this cannot work */
1088 /***********************************************************************
1089 * ClassFirst (TOOLHELP.69)
1091 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1093 TRACE("%p\n",pClassEntry
);
1094 pClassEntry
->wNext
= 1;
1095 return ClassNext16( pClassEntry
);
1099 /***********************************************************************
1100 * ClassNext (TOOLHELP.70)
1102 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1105 CLASS
*class = firstClass
;
1107 TRACE("%p\n",pClassEntry
);
1109 if (!pClassEntry
->wNext
) return FALSE
;
1110 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1113 pClassEntry
->wNext
= 0;
1116 pClassEntry
->hInst
= class->hInstance
;
1117 pClassEntry
->wNext
++;
1118 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1119 sizeof(pClassEntry
->szClassName
) );
1124 /* 64bit versions */
1126 #ifdef GetClassLongPtrA
1127 #undef GetClassLongPtrA
1130 #ifdef GetClassLongPtrW
1131 #undef GetClassLongPtrW
1134 #ifdef SetClassLongPtrA
1135 #undef SetClassLongPtrA
1138 #ifdef SetClassLongPtrW
1139 #undef SetClassLongPtrW
1142 /***********************************************************************
1143 * GetClassLongPtrA (USER32.@)
1145 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1151 /***********************************************************************
1152 * GetClassLongPtrW (USER32.@)
1154 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1160 /***********************************************************************
1161 * SetClassLongPtrW (USER32.@)
1163 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1169 /***********************************************************************
1170 * SetClassLongPtrA (USER32.@)
1172 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)