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/unicode.h"
36 #include "user_private.h"
38 #include "wine/server.h"
39 #include "wine/list.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(class);
44 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
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 struct dce
*dce
; /* Opaque pointer to class DCE */
56 HINSTANCE hInstance
; /* Module that created the task */
57 HICON hIcon
; /* Default icon */
58 HICON hIconSm
; /* Default small icon */
59 HICON hIconSmIntern
; /* Internal small icon, derived from hIcon */
60 HCURSOR hCursor
; /* Default cursor */
61 HBRUSH hbrBackground
; /* Default background */
62 ATOM atomName
; /* Name of the class */
63 WCHAR name
[MAX_ATOM_LEN
+ 1];
66 static struct list class_list
= LIST_INIT( class_list
);
67 static INIT_ONCE init_once
= INIT_ONCE_STATIC_INIT
;
69 #define CLASS_OTHER_PROCESS ((CLASS *)1)
71 /***********************************************************************
74 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
76 WND
*ptr
= WIN_GetPtr( hwnd
);
80 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
) return ptr
->class;
81 if (!write_access
) return CLASS_OTHER_PROCESS
;
83 /* modifying classes in other processes is not allowed */
84 if (ptr
== WND_DESKTOP
|| IsWindow( hwnd
))
86 SetLastError( ERROR_ACCESS_DENIED
);
90 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
95 /***********************************************************************
98 static inline void release_class_ptr( CLASS
*ptr
)
104 /***********************************************************************
107 ATOM
get_int_atom_value( LPCWSTR name
)
111 if (IS_INTRESOURCE(name
)) return LOWORD(name
);
112 if (*name
++ != '#') return 0;
115 if (*name
< '0' || *name
> '9') return 0;
116 ret
= ret
* 10 + *name
++ - '0';
117 if (ret
> 0xffff) return 0;
123 /***********************************************************************
126 * Set class info with the wine server.
128 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG_PTR newval
, UINT size
)
132 SERVER_START_REQ( set_class_info
)
134 req
->window
= wine_server_user_handle( hwnd
);
135 req
->extra_offset
= -1;
139 req
->flags
= SET_CLASS_ATOM
;
140 req
->atom
= LOWORD(newval
);
143 req
->flags
= SET_CLASS_STYLE
;
147 req
->flags
= SET_CLASS_WINEXTRA
;
148 req
->win_extra
= newval
;
151 req
->flags
= SET_CLASS_INSTANCE
;
152 req
->instance
= wine_server_client_ptr( (void *)newval
);
155 assert( offset
>= 0 );
156 req
->flags
= SET_CLASS_EXTRA
;
157 req
->extra_offset
= offset
;
158 req
->extra_size
= size
;
159 if ( size
== sizeof(LONG
) )
161 LONG newlong
= newval
;
162 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
165 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
168 ret
= !wine_server_call_err( req
);
175 /***********************************************************************
178 * Get the menu name as a ASCII string.
180 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
182 if (IS_INTRESOURCE(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
183 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
187 /***********************************************************************
190 * Get the menu name as a Unicode string.
192 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
194 return classPtr
->menuName
;
198 /***********************************************************************
201 * Set the menu name in a class structure by copying the string.
203 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
205 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
206 if (!IS_INTRESOURCE(name
))
208 DWORD lenA
= strlen(name
) + 1;
209 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
210 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
211 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
212 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
214 else classPtr
->menuName
= (LPWSTR
)name
;
218 /***********************************************************************
221 * Set the menu name in a class structure by copying the string.
223 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
225 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
226 if (!IS_INTRESOURCE(name
))
228 DWORD lenW
= strlenW(name
) + 1;
229 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
230 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
231 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
232 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
233 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
235 else classPtr
->menuName
= (LPWSTR
)name
;
239 /***********************************************************************
242 * Free a class structure.
244 static void CLASS_FreeClass( CLASS
*classPtr
)
246 TRACE("%p\n", classPtr
);
250 if (classPtr
->dce
) free_dce( classPtr
->dce
, 0 );
251 list_remove( &classPtr
->entry
);
252 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
253 DeleteObject( classPtr
->hbrBackground
);
254 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
255 HeapFree( GetProcessHeap(), 0, classPtr
);
260 /***********************************************************************
263 * Return a pointer to the class.
264 * hinstance has been normalized by the caller.
266 static CLASS
*CLASS_FindClass( LPCWSTR name
, HINSTANCE hinstance
)
269 ATOM atom
= get_int_atom_value( name
);
273 LIST_FOR_EACH( ptr
, &class_list
)
275 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
278 if (class->atomName
!= atom
) continue;
282 if (!name
|| strcmpiW( class->name
, name
)) continue;
284 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
286 TRACE("%s %p -> %p\n", debugstr_w(name
), hinstance
, class);
291 TRACE("%s %p -> not found\n", debugstr_w(name
), hinstance
);
296 /***********************************************************************
297 * CLASS_RegisterClass
299 * The real RegisterClass() functionality.
301 static CLASS
*CLASS_RegisterClass( LPCWSTR name
, HINSTANCE hInstance
, BOOL local
,
302 DWORD style
, INT classExtra
, INT winExtra
)
307 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
308 debugstr_w(name
), hInstance
, style
, classExtra
, winExtra
);
310 /* Fix the extra bytes value */
312 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
313 WARN("Class extra bytes %d is > 40\n", classExtra
);
314 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
315 WARN("Win extra bytes %d is > 40\n", winExtra
);
317 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
318 if (!classPtr
) return NULL
;
320 classPtr
->atomName
= get_int_atom_value( name
);
321 if (!classPtr
->atomName
&& name
) strcpyW( classPtr
->name
, name
);
322 else GlobalGetAtomNameW( classPtr
->atomName
, classPtr
->name
, sizeof(classPtr
->name
)/sizeof(WCHAR
) );
324 SERVER_START_REQ( create_class
)
328 req
->instance
= wine_server_client_ptr( hInstance
);
329 req
->extra
= classExtra
;
330 req
->win_extra
= winExtra
;
331 req
->client_ptr
= wine_server_client_ptr( classPtr
);
332 req
->atom
= classPtr
->atomName
;
333 if (!req
->atom
&& name
) wine_server_add_data( req
, name
, strlenW(name
) * sizeof(WCHAR
) );
334 ret
= !wine_server_call_err( req
);
335 classPtr
->atomName
= reply
->atom
;
340 HeapFree( GetProcessHeap(), 0, classPtr
);
344 classPtr
->style
= style
;
345 classPtr
->local
= local
;
346 classPtr
->cbWndExtra
= winExtra
;
347 classPtr
->cbClsExtra
= classExtra
;
348 classPtr
->hInstance
= hInstance
;
350 /* Other non-null values must be set by caller */
353 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
354 else list_add_tail( &class_list
, &classPtr
->entry
);
359 /***********************************************************************
362 * Register a builtin control class.
363 * This allows having both ASCII and Unicode winprocs for the same class.
365 static void register_builtin( const struct builtin_class_descr
*descr
)
369 if (!(classPtr
= CLASS_RegisterClass( descr
->name
, user32_module
, FALSE
,
370 descr
->style
, 0, descr
->extra
))) return;
372 if (descr
->cursor
) classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
373 classPtr
->hbrBackground
= descr
->brush
;
374 classPtr
->winproc
= BUILTIN_WINPROC( descr
->proc
);
375 release_class_ptr( classPtr
);
379 /***********************************************************************
382 static BOOL WINAPI
register_builtins( INIT_ONCE
*once
, void *param
, void **context
)
384 register_builtin( &BUTTON_builtin_class
);
385 register_builtin( &COMBO_builtin_class
);
386 register_builtin( &COMBOLBOX_builtin_class
);
387 register_builtin( &DIALOG_builtin_class
);
388 register_builtin( &EDIT_builtin_class
);
389 register_builtin( &ICONTITLE_builtin_class
);
390 register_builtin( &LISTBOX_builtin_class
);
391 register_builtin( &MDICLIENT_builtin_class
);
392 register_builtin( &MENU_builtin_class
);
393 register_builtin( &SCROLL_builtin_class
);
394 register_builtin( &STATIC_builtin_class
);
399 /***********************************************************************
400 * register_builtin_classes
402 void register_builtin_classes(void)
404 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
408 /***********************************************************************
409 * register_desktop_class
411 void register_desktop_class(void)
413 register_builtin( &DESKTOP_builtin_class
);
414 register_builtin( &MESSAGE_builtin_class
);
418 /***********************************************************************
421 WNDPROC
get_class_winproc( CLASS
*class )
423 return class->winproc
;
427 /***********************************************************************
430 struct dce
*get_class_dce( CLASS
*class )
436 /***********************************************************************
439 struct dce
*set_class_dce( CLASS
*class, struct dce
*dce
)
441 if (class->dce
) return class->dce
; /* already set, don't change it */
447 /***********************************************************************
448 * RegisterClassA (USER32.@)
450 * Register a window class.
453 * >0: Unique identifier
456 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
460 wcex
.cbSize
= sizeof(wcex
);
461 wcex
.style
= wc
->style
;
462 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
463 wcex
.cbClsExtra
= wc
->cbClsExtra
;
464 wcex
.cbWndExtra
= wc
->cbWndExtra
;
465 wcex
.hInstance
= wc
->hInstance
;
466 wcex
.hIcon
= wc
->hIcon
;
467 wcex
.hCursor
= wc
->hCursor
;
468 wcex
.hbrBackground
= wc
->hbrBackground
;
469 wcex
.lpszMenuName
= wc
->lpszMenuName
;
470 wcex
.lpszClassName
= wc
->lpszClassName
;
472 return RegisterClassExA( &wcex
);
476 /***********************************************************************
477 * RegisterClassW (USER32.@)
479 * See RegisterClassA.
481 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
485 wcex
.cbSize
= sizeof(wcex
);
486 wcex
.style
= wc
->style
;
487 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
488 wcex
.cbClsExtra
= wc
->cbClsExtra
;
489 wcex
.cbWndExtra
= wc
->cbWndExtra
;
490 wcex
.hInstance
= wc
->hInstance
;
491 wcex
.hIcon
= wc
->hIcon
;
492 wcex
.hCursor
= wc
->hCursor
;
493 wcex
.hbrBackground
= wc
->hbrBackground
;
494 wcex
.lpszMenuName
= wc
->lpszMenuName
;
495 wcex
.lpszClassName
= wc
->lpszClassName
;
497 return RegisterClassExW( &wcex
);
501 /***********************************************************************
502 * RegisterClassExA (USER32.@)
504 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
510 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
512 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
513 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
515 SetLastError( ERROR_INVALID_PARAMETER
);
518 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
520 if (!IS_INTRESOURCE(wc
->lpszClassName
))
522 WCHAR name
[MAX_ATOM_LEN
+ 1];
524 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
525 classPtr
= CLASS_RegisterClass( name
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
526 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
530 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, instance
,
531 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
532 wc
->cbClsExtra
, wc
->cbWndExtra
);
534 if (!classPtr
) return 0;
535 atom
= classPtr
->atomName
;
537 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
538 debugstr_a(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
539 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
541 classPtr
->hIcon
= wc
->hIcon
;
542 classPtr
->hIconSm
= wc
->hIconSm
;
543 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
544 CopyImage( wc
->hIcon
, IMAGE_ICON
,
545 GetSystemMetrics( SM_CXSMICON
),
546 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
547 classPtr
->hCursor
= wc
->hCursor
;
548 classPtr
->hbrBackground
= wc
->hbrBackground
;
549 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, FALSE
);
550 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
551 release_class_ptr( classPtr
);
556 /***********************************************************************
557 * RegisterClassExW (USER32.@)
559 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
565 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
567 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
568 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
570 SetLastError( ERROR_INVALID_PARAMETER
);
573 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
575 if (!(classPtr
= CLASS_RegisterClass( wc
->lpszClassName
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
576 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
579 atom
= classPtr
->atomName
;
581 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
582 debugstr_w(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
583 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
585 classPtr
->hIcon
= wc
->hIcon
;
586 classPtr
->hIconSm
= wc
->hIconSm
;
587 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
588 CopyImage( wc
->hIcon
, IMAGE_ICON
,
589 GetSystemMetrics( SM_CXSMICON
),
590 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
591 classPtr
->hCursor
= wc
->hCursor
;
592 classPtr
->hbrBackground
= wc
->hbrBackground
;
593 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, TRUE
);
594 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
595 release_class_ptr( classPtr
);
600 /***********************************************************************
601 * UnregisterClassA (USER32.@)
603 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
605 if (!IS_INTRESOURCE(className
))
607 WCHAR name
[MAX_ATOM_LEN
+ 1];
609 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
611 return UnregisterClassW( name
, hInstance
);
613 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
616 /***********************************************************************
617 * UnregisterClassW (USER32.@)
619 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
621 CLASS
*classPtr
= NULL
;
623 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
625 SERVER_START_REQ( destroy_class
)
627 req
->instance
= wine_server_client_ptr( hInstance
);
628 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
629 wine_server_add_data( req
, className
, strlenW(className
) * sizeof(WCHAR
) );
630 if (!wine_server_call_err( req
)) classPtr
= wine_server_get_ptr( reply
->client_ptr
);
634 if (classPtr
) CLASS_FreeClass( classPtr
);
635 return (classPtr
!= NULL
);
639 /***********************************************************************
640 * GetClassWord (USER32.@)
642 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
647 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
649 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
651 if (class == CLASS_OTHER_PROCESS
)
653 SERVER_START_REQ( set_class_info
)
655 req
->window
= wine_server_user_handle( hwnd
);
657 req
->extra_offset
= offset
;
658 req
->extra_size
= sizeof(retvalue
);
659 if (!wine_server_call_err( req
))
660 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
666 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
667 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
669 SetLastError( ERROR_INVALID_INDEX
);
670 release_class_ptr( class );
675 /***********************************************************************
678 * Implementation of GetClassLong(Ptr)A/W
680 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
684 ULONG_PTR retvalue
= 0;
686 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
688 if (class == CLASS_OTHER_PROCESS
)
690 SERVER_START_REQ( set_class_info
)
692 req
->window
= wine_server_user_handle( hwnd
);
694 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
695 req
->extra_size
= (offset
>= 0) ? size
: 0;
696 if (!wine_server_call_err( req
))
700 case GCLP_HBRBACKGROUND
:
706 FIXME( "offset %d (%s) not supported on other process window %p\n",
707 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
708 SetLastError( ERROR_INVALID_HANDLE
);
711 retvalue
= reply
->old_style
;
714 retvalue
= reply
->old_win_extra
;
717 retvalue
= reply
->old_extra
;
720 retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
723 retvalue
= reply
->old_atom
;
728 if (size
== sizeof(DWORD
))
731 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
735 memcpy( &retvalue
, &reply
->old_extra_value
,
738 else SetLastError( ERROR_INVALID_INDEX
);
749 if (offset
<= class->cbClsExtra
- size
)
751 if (size
== sizeof(DWORD
))
754 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
758 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
761 SetLastError( ERROR_INVALID_INDEX
);
762 release_class_ptr( class );
768 case GCLP_HBRBACKGROUND
:
769 retvalue
= (ULONG_PTR
)class->hbrBackground
;
772 retvalue
= (ULONG_PTR
)class->hCursor
;
775 retvalue
= (ULONG_PTR
)class->hIcon
;
778 retvalue
= (ULONG_PTR
)(class->hIconSm
? class->hIconSm
: class->hIconSmIntern
);
781 retvalue
= class->style
;
784 retvalue
= class->cbWndExtra
;
787 retvalue
= class->cbClsExtra
;
790 retvalue
= (ULONG_PTR
)class->hInstance
;
793 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
796 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
798 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
800 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
803 retvalue
= class->atomName
;
806 SetLastError( ERROR_INVALID_INDEX
);
809 release_class_ptr( class );
814 /***********************************************************************
815 * GetClassLongW (USER32.@)
817 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
819 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
824 /***********************************************************************
825 * GetClassLongA (USER32.@)
827 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
829 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
833 /***********************************************************************
834 * SetClassWord (USER32.@)
836 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
841 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
843 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
845 SERVER_START_REQ( set_class_info
)
847 req
->window
= wine_server_user_handle( hwnd
);
848 req
->flags
= SET_CLASS_EXTRA
;
849 req
->extra_offset
= offset
;
850 req
->extra_size
= sizeof(newval
);
851 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
852 if (!wine_server_call_err( req
))
854 void *ptr
= (char *)(class + 1) + offset
;
855 memcpy( &retval
, ptr
, sizeof(retval
) );
856 memcpy( ptr
, &newval
, sizeof(newval
) );
860 release_class_ptr( class );
865 /***********************************************************************
868 * Implementation of SetClassLong(Ptr)A/W
870 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
871 UINT size
, BOOL unicode
)
874 ULONG_PTR retval
= 0;
876 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
880 if (set_server_info( hwnd
, offset
, newval
, size
))
882 void *ptr
= (char *)(class + 1) + offset
;
883 if ( size
== sizeof(LONG
) )
886 LONG newlong
= newval
;
887 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
888 memcpy( ptr
, &newlong
, sizeof(LONG
) );
893 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
894 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
902 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
904 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
905 retval
= 0; /* Old value is now meaningless anyway */
908 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
909 class->winproc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
911 case GCLP_HBRBACKGROUND
:
912 retval
= (ULONG_PTR
)class->hbrBackground
;
913 class->hbrBackground
= (HBRUSH
)newval
;
916 retval
= (ULONG_PTR
)class->hCursor
;
917 class->hCursor
= (HCURSOR
)newval
;
920 retval
= (ULONG_PTR
)class->hIcon
;
921 if (retval
&& class->hIconSmIntern
)
923 DestroyIcon(class->hIconSmIntern
);
924 class->hIconSmIntern
= NULL
;
926 if (newval
&& !class->hIconSm
)
927 class->hIconSmIntern
= CopyImage( (HICON
)newval
, IMAGE_ICON
,
928 GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
), 0 );
929 class->hIcon
= (HICON
)newval
;
932 retval
= (ULONG_PTR
)class->hIconSm
;
933 if (retval
&& !newval
)
934 class->hIconSmIntern
= class->hIcon
? CopyImage( class->hIcon
, IMAGE_ICON
,
935 GetSystemMetrics( SM_CXSMICON
),
936 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
937 else if (!retval
&& newval
&& class->hIconSmIntern
)
939 DestroyIcon(class->hIconSmIntern
);
940 class->hIconSmIntern
= NULL
;
942 class->hIconSm
= (HICON
)newval
;
945 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
946 retval
= class->style
;
947 class->style
= newval
;
950 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
951 retval
= class->cbWndExtra
;
952 class->cbWndExtra
= newval
;
955 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
956 retval
= (ULONG_PTR
)class->hInstance
;
957 class->hInstance
= (HINSTANCE
)newval
;
960 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
961 retval
= class->atomName
;
962 class->atomName
= newval
;
963 GlobalGetAtomNameW( newval
, class->name
, sizeof(class->name
)/sizeof(WCHAR
) );
965 case GCL_CBCLSEXTRA
: /* cannot change this one */
966 SetLastError( ERROR_INVALID_PARAMETER
);
969 SetLastError( ERROR_INVALID_INDEX
);
972 release_class_ptr( class );
977 /***********************************************************************
978 * SetClassLongW (USER32.@)
980 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
982 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
986 /***********************************************************************
987 * SetClassLongA (USER32.@)
989 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
991 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
995 /***********************************************************************
996 * GetClassNameA (USER32.@)
998 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
1000 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1003 if (count
<= 0) return 0;
1004 if (!GetClassNameW( hwnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
1005 RtlUnicodeToMultiByteN( buffer
, count
- 1, &len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
1011 /***********************************************************************
1012 * GetClassNameW (USER32.@)
1014 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
1019 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
1021 if (count
<= 0) return 0;
1023 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
1025 if (class == CLASS_OTHER_PROCESS
)
1027 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1029 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
1032 ret
= min(count
- 1, ret
);
1033 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1039 lstrcpynW( buffer
, class->name
, count
);
1040 release_class_ptr( class );
1041 ret
= strlenW( buffer
);
1047 /***********************************************************************
1048 * RealGetWindowClassA (USER32.@)
1050 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1052 return GetClassNameA( hwnd
, buffer
, count
);
1056 /***********************************************************************
1057 * RealGetWindowClassW (USER32.@)
1059 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1061 return GetClassNameW( hwnd
, buffer
, count
);
1065 /***********************************************************************
1066 * GetClassInfoA (USER32.@)
1068 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1071 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1075 wc
->style
= wcex
.style
;
1076 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1077 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1078 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1079 wc
->hInstance
= wcex
.hInstance
;
1080 wc
->hIcon
= wcex
.hIcon
;
1081 wc
->hCursor
= wcex
.hCursor
;
1082 wc
->hbrBackground
= wcex
.hbrBackground
;
1083 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1084 wc
->lpszClassName
= wcex
.lpszClassName
;
1090 /***********************************************************************
1091 * GetClassInfoW (USER32.@)
1093 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1096 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1100 wc
->style
= wcex
.style
;
1101 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1102 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1103 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1104 wc
->hInstance
= wcex
.hInstance
;
1105 wc
->hIcon
= wcex
.hIcon
;
1106 wc
->hCursor
= wcex
.hCursor
;
1107 wc
->hbrBackground
= wcex
.hbrBackground
;
1108 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1109 wc
->lpszClassName
= wcex
.lpszClassName
;
1115 /***********************************************************************
1116 * GetClassInfoExA (USER32.@)
1118 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1123 TRACE("%p %s %p\n", hInstance
, debugstr_a(name
), wc
);
1125 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
1129 SetLastError( ERROR_NOACCESS
);
1133 if (!hInstance
) hInstance
= user32_module
;
1135 if (!IS_INTRESOURCE(name
))
1137 WCHAR nameW
[MAX_ATOM_LEN
+ 1];
1138 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, sizeof(nameW
)/sizeof(WCHAR
) ))
1140 classPtr
= CLASS_FindClass( nameW
, hInstance
);
1142 else classPtr
= CLASS_FindClass( (LPCWSTR
)name
, hInstance
);
1146 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1149 wc
->style
= classPtr
->style
;
1150 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1151 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1152 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1153 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1154 wc
->hIcon
= classPtr
->hIcon
;
1155 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1156 wc
->hCursor
= classPtr
->hCursor
;
1157 wc
->hbrBackground
= classPtr
->hbrBackground
;
1158 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1159 wc
->lpszClassName
= name
;
1160 atom
= classPtr
->atomName
;
1161 release_class_ptr( classPtr
);
1163 /* We must return the atom of the class here instead of just TRUE. */
1168 /***********************************************************************
1169 * GetClassInfoExW (USER32.@)
1171 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1176 TRACE("%p %s %p\n", hInstance
, debugstr_w(name
), wc
);
1178 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
1182 SetLastError( ERROR_NOACCESS
);
1186 if (!hInstance
) hInstance
= user32_module
;
1188 if (!(classPtr
= CLASS_FindClass( name
, hInstance
)))
1190 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1193 wc
->style
= classPtr
->style
;
1194 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1195 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1196 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1197 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1198 wc
->hIcon
= classPtr
->hIcon
;
1199 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1200 wc
->hCursor
= classPtr
->hCursor
;
1201 wc
->hbrBackground
= classPtr
->hbrBackground
;
1202 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1203 wc
->lpszClassName
= name
;
1204 atom
= classPtr
->atomName
;
1205 release_class_ptr( classPtr
);
1207 /* We must return the atom of the class here instead of just TRUE. */
1212 #if 0 /* toolhelp is in kernel, so this cannot work */
1214 /***********************************************************************
1215 * ClassFirst (TOOLHELP.69)
1217 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1219 TRACE("%p\n",pClassEntry
);
1220 pClassEntry
->wNext
= 1;
1221 return ClassNext16( pClassEntry
);
1225 /***********************************************************************
1226 * ClassNext (TOOLHELP.70)
1228 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1231 CLASS
*class = firstClass
;
1233 TRACE("%p\n",pClassEntry
);
1235 if (!pClassEntry
->wNext
) return FALSE
;
1236 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1239 pClassEntry
->wNext
= 0;
1242 pClassEntry
->hInst
= class->hInstance
;
1243 pClassEntry
->wNext
++;
1244 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1245 sizeof(pClassEntry
->szClassName
) );
1250 /* 64bit versions */
1252 #ifdef GetClassLongPtrA
1253 #undef GetClassLongPtrA
1256 #ifdef GetClassLongPtrW
1257 #undef GetClassLongPtrW
1260 #ifdef SetClassLongPtrA
1261 #undef SetClassLongPtrA
1264 #ifdef SetClassLongPtrW
1265 #undef SetClassLongPtrW
1268 /***********************************************************************
1269 * GetClassLongPtrA (USER32.@)
1271 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1273 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1276 /***********************************************************************
1277 * GetClassLongPtrW (USER32.@)
1279 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1281 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1284 /***********************************************************************
1285 * SetClassLongPtrW (USER32.@)
1287 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1289 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1292 /***********************************************************************
1293 * SetClassLongPtrA (USER32.@)
1295 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1297 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);