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)
66 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
68 /***********************************************************************
71 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
73 WND
*ptr
= WIN_GetPtr( hwnd
);
77 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
) return ptr
->class;
78 if (!write_access
) return CLASS_OTHER_PROCESS
;
80 /* modifying classes in other processes is not allowed */
81 if (ptr
== WND_DESKTOP
|| IsWindow( hwnd
))
83 SetLastError( ERROR_ACCESS_DENIED
);
87 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
92 /***********************************************************************
95 static inline void release_class_ptr( CLASS
*ptr
)
101 /***********************************************************************
104 * Set class info with the wine server.
106 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG_PTR newval
, UINT size
)
110 SERVER_START_REQ( set_class_info
)
113 req
->extra_offset
= -1;
117 req
->flags
= SET_CLASS_ATOM
;
120 req
->flags
= SET_CLASS_STYLE
;
124 req
->flags
= SET_CLASS_WINEXTRA
;
125 req
->win_extra
= newval
;
128 req
->flags
= SET_CLASS_INSTANCE
;
129 req
->instance
= (void *)newval
;
132 assert( offset
>= 0 );
133 req
->flags
= SET_CLASS_EXTRA
;
134 req
->extra_offset
= offset
;
135 req
->extra_size
= size
;
136 if ( size
== sizeof(LONG
) )
138 LONG newlong
= newval
;
139 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
142 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
145 ret
= !wine_server_call_err( req
);
152 /***********************************************************************
155 * Get the menu name as a ASCII string.
157 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
159 if (!HIWORD(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
160 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
164 /***********************************************************************
167 * Get the menu name as a Unicode string.
169 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
171 return classPtr
->menuName
;
175 /***********************************************************************
178 * Set the menu name in a class structure by copying the string.
180 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
182 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
185 DWORD lenA
= strlen(name
) + 1;
186 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
187 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
188 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
189 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
191 else classPtr
->menuName
= (LPWSTR
)name
;
195 /***********************************************************************
198 * Set the menu name in a class structure by copying the string.
200 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
202 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
205 DWORD lenW
= strlenW(name
) + 1;
206 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
207 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
208 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
209 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
210 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
212 else classPtr
->menuName
= (LPWSTR
)name
;
216 /***********************************************************************
219 * Free a class structure.
221 static void CLASS_FreeClass( CLASS
*classPtr
)
223 TRACE("%p\n", classPtr
);
227 list_remove( &classPtr
->entry
);
228 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
229 DeleteObject( classPtr
->hbrBackground
);
230 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
231 HeapFree( GetProcessHeap(), 0, classPtr
);
236 /***********************************************************************
237 * CLASS_FreeModuleClasses
239 void CLASS_FreeModuleClasses( HMODULE16 hModule
)
241 struct list
*ptr
, *next
;
243 TRACE("0x%08x\n", hModule
);
246 for (ptr
= list_head( &class_list
); ptr
; ptr
= next
)
248 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
249 next
= list_next( &class_list
, ptr
);
250 if (class->hInstance
== HINSTANCE_32(hModule
))
254 SERVER_START_REQ( destroy_class
)
256 req
->atom
= class->atomName
;
257 req
->instance
= class->hInstance
;
258 ret
= !wine_server_call_err( req
);
261 if (ret
) CLASS_FreeClass( class );
268 /***********************************************************************
269 * CLASS_FindClassByAtom
271 * Return a pointer to the class.
272 * hinstance has been normalized by the caller.
274 static CLASS
*CLASS_FindClassByAtom( ATOM atom
, HINSTANCE hinstance
)
280 LIST_FOR_EACH( ptr
, &class_list
)
282 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
283 if (class->atomName
!= atom
) continue;
284 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
286 TRACE("0x%04x %p -> %p\n", atom
, hinstance
, class);
291 TRACE("0x%04x %p -> not found\n", atom
, hinstance
);
296 /***********************************************************************
297 * CLASS_RegisterClass
299 * The real RegisterClass() functionality.
300 * The atom is deleted no matter what.
302 static CLASS
*CLASS_RegisterClass( ATOM atom
, HINSTANCE hInstance
, BOOL local
,
303 DWORD style
, INT classExtra
, INT winExtra
)
308 TRACE("atom=0x%x hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
309 atom
, hInstance
, style
, classExtra
, winExtra
);
311 /* Fix the extra bytes value */
313 if (classExtra
< 0 || winExtra
< 0)
315 SetLastError( ERROR_INVALID_PARAMETER
);
318 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
319 WARN("Class extra bytes %d is > 40\n", classExtra
);
320 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
321 WARN("Win extra bytes %d is > 40\n", winExtra
);
323 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
326 GlobalDeleteAtom( atom
);
330 SERVER_START_REQ( create_class
)
335 req
->instance
= hInstance
;
336 req
->extra
= classExtra
;
337 req
->win_extra
= winExtra
;
338 req
->client_ptr
= classPtr
;
339 ret
= !wine_server_call_err( req
);
342 GlobalDeleteAtom( atom
); /* the server increased the atom ref count */
345 HeapFree( GetProcessHeap(), 0, classPtr
);
349 classPtr
->style
= style
;
350 classPtr
->local
= local
;
351 classPtr
->cbWndExtra
= winExtra
;
352 classPtr
->cbClsExtra
= classExtra
;
353 classPtr
->hInstance
= hInstance
;
354 classPtr
->atomName
= atom
;
356 /* Other non-null values must be set by caller */
359 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
360 else list_add_tail( &class_list
, &classPtr
->entry
);
365 /***********************************************************************
368 * Register a builtin control class.
369 * This allows having both ASCII and Unicode winprocs for the same class.
371 static CLASS
*register_builtin( const struct builtin_class_descr
*descr
)
376 if (!(atom
= GlobalAddAtomA( descr
->name
))) return 0;
378 if (!(classPtr
= CLASS_RegisterClass( atom
, user32_module
, FALSE
,
379 descr
->style
, 0, descr
->extra
))) return 0;
381 classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
382 classPtr
->hbrBackground
= descr
->brush
;
383 classPtr
->winproc
= WINPROC_AllocProc( descr
->procA
, descr
->procW
);
384 release_class_ptr( classPtr
);
389 /***********************************************************************
390 * CLASS_RegisterBuiltinClasses
392 void CLASS_RegisterBuiltinClasses(void)
394 extern const struct builtin_class_descr BUTTON_builtin_class
;
395 extern const struct builtin_class_descr COMBO_builtin_class
;
396 extern const struct builtin_class_descr COMBOLBOX_builtin_class
;
397 extern const struct builtin_class_descr DIALOG_builtin_class
;
398 extern const struct builtin_class_descr DESKTOP_builtin_class
;
399 extern const struct builtin_class_descr EDIT_builtin_class
;
400 extern const struct builtin_class_descr ICONTITLE_builtin_class
;
401 extern const struct builtin_class_descr LISTBOX_builtin_class
;
402 extern const struct builtin_class_descr MDICLIENT_builtin_class
;
403 extern const struct builtin_class_descr MENU_builtin_class
;
404 extern const struct builtin_class_descr SCROLL_builtin_class
;
405 extern const struct builtin_class_descr STATIC_builtin_class
;
407 register_builtin( &DESKTOP_builtin_class
);
408 register_builtin( &BUTTON_builtin_class
);
409 register_builtin( &COMBO_builtin_class
);
410 register_builtin( &COMBOLBOX_builtin_class
);
411 register_builtin( &DIALOG_builtin_class
);
412 register_builtin( &EDIT_builtin_class
);
413 register_builtin( &ICONTITLE_builtin_class
);
414 register_builtin( &LISTBOX_builtin_class
);
415 register_builtin( &MDICLIENT_builtin_class
);
416 register_builtin( &MENU_builtin_class
);
417 register_builtin( &SCROLL_builtin_class
);
418 register_builtin( &STATIC_builtin_class
);
422 /***********************************************************************
425 * Add a new window using this class, and set the necessary
426 * information inside the window structure.
428 void CLASS_AddWindow( CLASS
*class, WND
*win
, BOOL unicode
)
431 win
->clsStyle
= class->style
;
432 win
->winproc
= class->winproc
;
433 if (WINPROC_IsUnicode( win
->winproc
, unicode
)) win
->flags
|= WIN_ISUNICODE
;
437 /***********************************************************************
438 * RegisterClassA (USER32.@)
440 * Register a window class.
443 * >0: Unique identifier
446 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
450 wcex
.cbSize
= sizeof(wcex
);
451 wcex
.style
= wc
->style
;
452 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
453 wcex
.cbClsExtra
= wc
->cbClsExtra
;
454 wcex
.cbWndExtra
= wc
->cbWndExtra
;
455 wcex
.hInstance
= wc
->hInstance
;
456 wcex
.hIcon
= wc
->hIcon
;
457 wcex
.hCursor
= wc
->hCursor
;
458 wcex
.hbrBackground
= wc
->hbrBackground
;
459 wcex
.lpszMenuName
= wc
->lpszMenuName
;
460 wcex
.lpszClassName
= wc
->lpszClassName
;
462 return RegisterClassExA( &wcex
);
466 /***********************************************************************
467 * RegisterClassW (USER32.@)
469 * See RegisterClassA.
471 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
475 wcex
.cbSize
= sizeof(wcex
);
476 wcex
.style
= wc
->style
;
477 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
478 wcex
.cbClsExtra
= wc
->cbClsExtra
;
479 wcex
.cbWndExtra
= wc
->cbWndExtra
;
480 wcex
.hInstance
= wc
->hInstance
;
481 wcex
.hIcon
= wc
->hIcon
;
482 wcex
.hCursor
= wc
->hCursor
;
483 wcex
.hbrBackground
= wc
->hbrBackground
;
484 wcex
.lpszMenuName
= wc
->lpszMenuName
;
485 wcex
.lpszClassName
= wc
->lpszClassName
;
487 return RegisterClassExW( &wcex
);
491 /***********************************************************************
492 * RegisterClassExA (USER32.@)
494 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
500 if (wc
->hInstance
== user32_module
)
502 /* we can't register a class for user32 */
503 SetLastError( ERROR_INVALID_PARAMETER
);
506 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
508 if (!(atom
= GlobalAddAtomA( wc
->lpszClassName
))) return 0;
510 if (!(classPtr
= CLASS_RegisterClass( atom
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
511 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
514 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
515 atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
516 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
518 classPtr
->hIcon
= wc
->hIcon
;
519 classPtr
->hIconSm
= wc
->hIconSm
;
520 classPtr
->hCursor
= wc
->hCursor
;
521 classPtr
->hbrBackground
= wc
->hbrBackground
;
522 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, NULL
);
523 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
524 release_class_ptr( classPtr
);
529 /***********************************************************************
530 * RegisterClassExW (USER32.@)
532 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
538 if (wc
->hInstance
== user32_module
)
540 /* we can't register a class for user32 */
541 SetLastError( ERROR_INVALID_PARAMETER
);
544 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
546 if (!(atom
= GlobalAddAtomW( wc
->lpszClassName
))) return 0;
548 if (!(classPtr
= CLASS_RegisterClass( atom
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
549 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
552 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
553 atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
554 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
556 classPtr
->hIcon
= wc
->hIcon
;
557 classPtr
->hIconSm
= wc
->hIconSm
;
558 classPtr
->hCursor
= wc
->hCursor
;
559 classPtr
->hbrBackground
= wc
->hbrBackground
;
560 classPtr
->winproc
= WINPROC_AllocProc( NULL
, wc
->lpfnWndProc
);
561 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
562 release_class_ptr( classPtr
);
567 /***********************************************************************
568 * UnregisterClassA (USER32.@)
570 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
572 ATOM atom
= HIWORD(className
) ? GlobalFindAtomA( className
) : LOWORD(className
);
573 return UnregisterClassW( (LPCWSTR
)MAKEINTATOM(atom
), hInstance
);
576 /***********************************************************************
577 * UnregisterClassW (USER32.@)
579 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
581 CLASS
*classPtr
= NULL
;
582 ATOM atom
= HIWORD(className
) ? GlobalFindAtomW( className
) : LOWORD(className
);
584 TRACE("%s %p %x\n",debugstr_w(className
), hInstance
, atom
);
588 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
592 SERVER_START_REQ( destroy_class
)
595 req
->instance
= hInstance
;
596 if (!wine_server_call_err( req
)) classPtr
= reply
->client_ptr
;
600 if (classPtr
) CLASS_FreeClass( classPtr
);
601 return (classPtr
!= NULL
);
605 /***********************************************************************
606 * GetClassWord (USER32.@)
608 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
613 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
615 TRACE("%p %x\n",hwnd
, offset
);
617 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
619 if (class == CLASS_OTHER_PROCESS
)
621 SERVER_START_REQ( set_class_info
)
625 req
->extra_offset
= offset
;
626 req
->extra_size
= sizeof(retvalue
);
627 if (!wine_server_call_err( req
))
628 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
634 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
635 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
637 SetLastError( ERROR_INVALID_INDEX
);
638 release_class_ptr( class );
643 /***********************************************************************
646 * Implementation of GetClassLong(Ptr)A/W
648 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
652 ULONG_PTR retvalue
= 0;
654 TRACE("%p %d\n", hwnd
, offset
);
656 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
658 if (class == CLASS_OTHER_PROCESS
)
660 SERVER_START_REQ( set_class_info
)
664 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
665 req
->extra_size
= (offset
>= 0) ? size
: 0;
666 if (!wine_server_call_err( req
))
670 case GCLP_HBRBACKGROUND
:
676 FIXME( "offset %d (%s) not supported on other process window %p\n",
677 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
678 SetLastError( ERROR_INVALID_HANDLE
);
681 retvalue
= reply
->old_style
;
684 retvalue
= reply
->old_win_extra
;
687 retvalue
= reply
->old_extra
;
690 retvalue
= (ULONG_PTR
)reply
->old_instance
;
693 retvalue
= reply
->old_atom
;
698 if (size
== sizeof(DWORD
))
701 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
705 memcpy( &retvalue
, &reply
->old_extra_value
,
708 else SetLastError( ERROR_INVALID_INDEX
);
719 if (offset
<= class->cbClsExtra
- size
)
721 if (size
== sizeof(DWORD
))
724 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
728 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
731 SetLastError( ERROR_INVALID_INDEX
);
732 release_class_ptr( class );
738 case GCLP_HBRBACKGROUND
:
739 retvalue
= (ULONG_PTR
)class->hbrBackground
;
742 retvalue
= (ULONG_PTR
)class->hCursor
;
745 retvalue
= (ULONG_PTR
)class->hIcon
;
748 retvalue
= (ULONG_PTR
)class->hIconSm
;
751 retvalue
= class->style
;
754 retvalue
= class->cbWndExtra
;
757 retvalue
= class->cbClsExtra
;
760 retvalue
= (ULONG_PTR
)class->hInstance
;
763 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
766 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
768 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
770 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
773 retvalue
= class->atomName
;
776 SetLastError( ERROR_INVALID_INDEX
);
779 release_class_ptr( class );
784 /***********************************************************************
785 * GetClassLongW (USER32.@)
787 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
789 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
794 /***********************************************************************
795 * GetClassLongA (USER32.@)
797 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
799 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
803 /***********************************************************************
804 * SetClassWord (USER32.@)
806 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
811 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
813 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
815 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
817 SERVER_START_REQ( set_class_info
)
820 req
->flags
= SET_CLASS_EXTRA
;
821 req
->extra_offset
= offset
;
822 req
->extra_size
= sizeof(newval
);
823 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
824 if (!wine_server_call_err( req
))
826 void *ptr
= (char *)(class + 1) + offset
;
827 memcpy( &retval
, ptr
, sizeof(retval
) );
828 memcpy( ptr
, &newval
, sizeof(newval
) );
832 release_class_ptr( class );
837 /***********************************************************************
840 * Implementation of SetClassLong(Ptr)A/W
842 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
843 UINT size
, BOOL unicode
)
846 ULONG_PTR retval
= 0;
848 TRACE("%p %d %lx\n", hwnd
, offset
, newval
);
850 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
854 if (set_server_info( hwnd
, offset
, newval
, size
))
856 void *ptr
= (char *)(class + 1) + offset
;
857 if ( size
== sizeof(LONG
) )
860 LONG newlong
= newval
;
861 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
862 memcpy( ptr
, &newlong
, sizeof(LONG
) );
867 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
868 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
876 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
878 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
879 retval
= 0; /* Old value is now meaningless anyway */
882 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
883 class->winproc
= WINPROC_AllocProc( unicode
? NULL
: (WNDPROC
)newval
,
884 unicode
? (WNDPROC
)newval
: NULL
);
886 case GCLP_HBRBACKGROUND
:
887 retval
= (ULONG_PTR
)class->hbrBackground
;
888 class->hbrBackground
= (HBRUSH
)newval
;
891 retval
= (ULONG_PTR
)class->hCursor
;
892 class->hCursor
= (HCURSOR
)newval
;
895 retval
= (ULONG_PTR
)class->hIcon
;
896 class->hIcon
= (HICON
)newval
;
899 retval
= (ULONG_PTR
)class->hIconSm
;
900 class->hIconSm
= (HICON
)newval
;
903 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
904 retval
= class->style
;
905 class->style
= newval
;
908 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
909 retval
= class->cbWndExtra
;
910 class->cbWndExtra
= newval
;
913 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
914 retval
= (ULONG_PTR
)class->hInstance
;
915 class->hInstance
= (HINSTANCE
)newval
;
918 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
919 retval
= class->atomName
;
920 class->atomName
= newval
;
922 case GCL_CBCLSEXTRA
: /* cannot change this one */
923 SetLastError( ERROR_INVALID_PARAMETER
);
926 SetLastError( ERROR_INVALID_INDEX
);
929 release_class_ptr( class );
934 /***********************************************************************
935 * SetClassLongW (USER32.@)
937 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
939 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
941 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
945 /***********************************************************************
946 * SetClassLongA (USER32.@)
948 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
950 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
952 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
956 /***********************************************************************
957 * GetClassNameA (USER32.@)
959 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
961 char tmpbuf
[MAX_ATOM_LEN
+ 1];
964 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
966 if (count
<= 0) return 0;
968 ret
= GlobalGetAtomNameA( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
971 ret
= min(count
- 1, ret
);
972 memcpy(buffer
, tmpbuf
, ret
);
979 /***********************************************************************
980 * GetClassNameW (USER32.@)
982 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
984 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
987 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
989 if (count
<= 0) return 0;
991 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
994 ret
= min(count
- 1, ret
);
995 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1002 /***********************************************************************
1003 * RealGetWindowClassA (USER32.@)
1005 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1007 return GetClassNameA( hwnd
, buffer
, count
);
1011 /***********************************************************************
1012 * RealGetWindowClassW (USER32.@)
1014 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1016 return GetClassNameW( hwnd
, buffer
, count
);
1020 /***********************************************************************
1021 * GetClassInfoA (USER32.@)
1023 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1026 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1030 wc
->style
= wcex
.style
;
1031 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1032 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1033 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1034 wc
->hInstance
= wcex
.hInstance
;
1035 wc
->hIcon
= wcex
.hIcon
;
1036 wc
->hCursor
= wcex
.hCursor
;
1037 wc
->hbrBackground
= wcex
.hbrBackground
;
1038 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1039 wc
->lpszClassName
= wcex
.lpszClassName
;
1045 /***********************************************************************
1046 * GetClassInfoW (USER32.@)
1048 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1051 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1055 wc
->style
= wcex
.style
;
1056 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1057 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1058 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1059 wc
->hInstance
= wcex
.hInstance
;
1060 wc
->hIcon
= wcex
.hIcon
;
1061 wc
->hCursor
= wcex
.hCursor
;
1062 wc
->hbrBackground
= wcex
.hbrBackground
;
1063 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1064 wc
->lpszClassName
= wcex
.lpszClassName
;
1070 /***********************************************************************
1071 * GetClassInfoExA (USER32.@)
1073 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1075 ATOM atom
= HIWORD(name
) ? GlobalFindAtomA( name
) : LOWORD(name
);
1078 TRACE("%p %s %x %p\n", hInstance
, debugstr_a(name
), atom
, wc
);
1080 if (!hInstance
) hInstance
= user32_module
;
1082 if (!atom
|| !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
1084 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1087 wc
->style
= classPtr
->style
;
1088 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1089 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1090 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1091 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1092 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1093 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1094 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1095 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1096 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1097 wc
->lpszClassName
= name
;
1098 release_class_ptr( classPtr
);
1100 /* We must return the atom of the class here instead of just TRUE. */
1105 /***********************************************************************
1106 * GetClassInfoExW (USER32.@)
1108 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1110 ATOM atom
= HIWORD(name
) ? GlobalFindAtomW( name
) : LOWORD(name
);
1113 TRACE("%p %s %x %p\n", hInstance
, debugstr_w(name
), atom
, wc
);
1115 if (!hInstance
) hInstance
= user32_module
;
1117 if (!atom
|| !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
1119 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1122 wc
->style
= classPtr
->style
;
1123 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1124 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1125 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1126 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1127 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1128 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1129 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1130 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1131 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1132 wc
->lpszClassName
= name
;
1133 release_class_ptr( classPtr
);
1135 /* We must return the atom of the class here instead of just TRUE. */
1140 #if 0 /* toolhelp is in kernel, so this cannot work */
1142 /***********************************************************************
1143 * ClassFirst (TOOLHELP.69)
1145 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1147 TRACE("%p\n",pClassEntry
);
1148 pClassEntry
->wNext
= 1;
1149 return ClassNext16( pClassEntry
);
1153 /***********************************************************************
1154 * ClassNext (TOOLHELP.70)
1156 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1159 CLASS
*class = firstClass
;
1161 TRACE("%p\n",pClassEntry
);
1163 if (!pClassEntry
->wNext
) return FALSE
;
1164 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1167 pClassEntry
->wNext
= 0;
1170 pClassEntry
->hInst
= class->hInstance
;
1171 pClassEntry
->wNext
++;
1172 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1173 sizeof(pClassEntry
->szClassName
) );
1178 /* 64bit versions */
1180 #ifdef GetClassLongPtrA
1181 #undef GetClassLongPtrA
1184 #ifdef GetClassLongPtrW
1185 #undef GetClassLongPtrW
1188 #ifdef SetClassLongPtrA
1189 #undef SetClassLongPtrA
1192 #ifdef SetClassLongPtrW
1193 #undef SetClassLongPtrW
1196 /***********************************************************************
1197 * GetClassLongPtrA (USER32.@)
1199 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1201 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1204 /***********************************************************************
1205 * GetClassLongPtrW (USER32.@)
1207 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1209 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1212 /***********************************************************************
1213 * SetClassLongPtrW (USER32.@)
1215 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1217 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1220 /***********************************************************************
1221 * SetClassLongPtrA (USER32.@)
1223 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1225 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);