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
33 #include "user_private.h"
35 #include "wine/server.h"
36 #include "wine/list.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(class);
41 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
43 typedef struct tagCLASS
45 struct list entry
; /* Entry in class list */
46 UINT style
; /* Class style */
47 BOOL local
; /* Local class? */
48 WNDPROC winproc
; /* Window procedure */
49 INT cbClsExtra
; /* Class extra bytes */
50 INT cbWndExtra
; /* Window extra bytes */
51 LPWSTR menuName
; /* Default menu name (Unicode followed by ASCII) */
52 struct dce
*dce
; /* Opaque pointer to class DCE */
53 HINSTANCE hInstance
; /* Module that created the task */
54 HICON hIcon
; /* Default icon */
55 HICON hIconSm
; /* Default small icon */
56 HICON hIconSmIntern
; /* Internal small icon, derived from hIcon */
57 HCURSOR hCursor
; /* Default cursor */
58 HBRUSH hbrBackground
; /* Default background */
59 ATOM atomName
; /* Name of the class */
60 WCHAR name
[MAX_ATOM_LEN
+ 1];
61 WCHAR
*basename
; /* Base name for redirected classes, pointer within 'name'. */
64 static struct list class_list
= LIST_INIT( class_list
);
65 static INIT_ONCE init_once
= INIT_ONCE_STATIC_INIT
;
67 #define CLASS_OTHER_PROCESS ((CLASS *)1)
69 /***********************************************************************
72 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
74 WND
*ptr
= WIN_GetPtr( hwnd
);
78 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
) return ptr
->class;
79 if (!write_access
) return CLASS_OTHER_PROCESS
;
81 /* modifying classes in other processes is not allowed */
82 if (ptr
== WND_DESKTOP
|| IsWindow( hwnd
))
84 SetLastError( ERROR_ACCESS_DENIED
);
88 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
93 /***********************************************************************
96 static inline void release_class_ptr( CLASS
*ptr
)
102 /***********************************************************************
105 ATOM
get_int_atom_value( LPCWSTR name
)
109 if (IS_INTRESOURCE(name
)) return LOWORD(name
);
110 if (*name
++ != '#') return 0;
113 if (*name
< '0' || *name
> '9') return 0;
114 ret
= ret
* 10 + *name
++ - '0';
115 if (ret
> 0xffff) return 0;
121 /***********************************************************************
124 static BOOL
is_comctl32_class( const WCHAR
*name
)
126 static const WCHAR
*classesW
[] =
130 L
"msctls_progress32",
131 L
"msctls_statusbar32",
132 L
"msctls_trackbar32",
137 L
"SysDateTimePick32",
150 int min
= 0, max
= ARRAY_SIZE( classesW
) - 1;
154 int res
, pos
= (min
+ max
) / 2;
155 if (!(res
= wcsicmp( name
, classesW
[pos
] ))) return TRUE
;
156 if (res
< 0) max
= pos
- 1;
162 static BOOL
is_builtin_class( const WCHAR
*name
)
164 static const WCHAR
*classesW
[] =
171 int min
= 0, max
= ARRAY_SIZE( classesW
) - 1;
175 int res
, pos
= (min
+ max
) / 2;
176 if (!(res
= wcsicmp( name
, classesW
[pos
] ))) return TRUE
;
177 if (res
< 0) max
= pos
- 1;
183 /***********************************************************************
186 * Set class info with the wine server.
188 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG_PTR newval
, UINT size
)
192 SERVER_START_REQ( set_class_info
)
194 req
->window
= wine_server_user_handle( hwnd
);
195 req
->extra_offset
= -1;
199 req
->flags
= SET_CLASS_ATOM
;
200 req
->atom
= LOWORD(newval
);
203 req
->flags
= SET_CLASS_STYLE
;
207 req
->flags
= SET_CLASS_WINEXTRA
;
208 req
->win_extra
= newval
;
211 req
->flags
= SET_CLASS_INSTANCE
;
212 req
->instance
= wine_server_client_ptr( (void *)newval
);
215 assert( offset
>= 0 );
216 req
->flags
= SET_CLASS_EXTRA
;
217 req
->extra_offset
= offset
;
218 req
->extra_size
= size
;
219 if ( size
== sizeof(LONG
) )
221 LONG newlong
= newval
;
222 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
225 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
228 ret
= !wine_server_call_err( req
);
235 /***********************************************************************
238 * Get the menu name as an ANSI string.
240 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
242 if (IS_INTRESOURCE(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
243 return (LPSTR
)(classPtr
->menuName
+ lstrlenW(classPtr
->menuName
) + 1);
247 /***********************************************************************
250 * Get the menu name as a Unicode string.
252 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
254 return classPtr
->menuName
;
258 /***********************************************************************
261 * Set the menu name in a class structure by copying the string.
263 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
265 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
266 if (!IS_INTRESOURCE(name
))
268 DWORD lenA
= strlen(name
) + 1;
269 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
270 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
271 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
272 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
274 else classPtr
->menuName
= (LPWSTR
)name
;
278 /***********************************************************************
281 * Set the menu name in a class structure by copying the string.
283 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
285 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
286 if (!IS_INTRESOURCE(name
))
288 DWORD lenW
= lstrlenW(name
) + 1;
289 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
290 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
291 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
292 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
293 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
295 else classPtr
->menuName
= (LPWSTR
)name
;
299 /***********************************************************************
302 * Free a class structure.
304 static void CLASS_FreeClass( CLASS
*classPtr
)
306 TRACE("%p\n", classPtr
);
310 if (classPtr
->dce
) free_dce( classPtr
->dce
, 0 );
311 list_remove( &classPtr
->entry
);
312 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
313 DeleteObject( classPtr
->hbrBackground
);
314 DestroyIcon( classPtr
->hIconSmIntern
);
315 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
316 HeapFree( GetProcessHeap(), 0, classPtr
);
320 const WCHAR
*CLASS_GetVersionedName( const WCHAR
*name
, UINT
*basename_offset
, WCHAR
*combined
, BOOL register_class
)
322 ACTCTX_SECTION_KEYED_DATA data
;
323 struct wndclass_redirect_data
332 const WCHAR
*module
, *ret
;
333 UNICODE_STRING name_us
;
337 if (!basename_offset
)
338 basename_offset
= &offset
;
340 *basename_offset
= 0;
342 if (IS_INTRESOURCE( name
))
345 if (is_comctl32_class( name
) || is_builtin_class( name
))
348 data
.cbSize
= sizeof(data
);
349 RtlInitUnicodeString(&name_us
, name
);
350 if (RtlFindActivationContextSectionString(0, NULL
, ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
,
354 wndclass
= (struct wndclass_redirect_data
*)data
.lpData
;
355 *basename_offset
= wndclass
->name_len
/ sizeof(WCHAR
) - lstrlenW(name
);
357 module
= (const WCHAR
*)((BYTE
*)data
.lpSectionBase
+ wndclass
->module_offset
);
358 if (!(hmod
= GetModuleHandleW( module
)))
359 hmod
= LoadLibraryW( module
);
361 /* Combined name is used to register versioned class name. Base name part will match exactly
362 original class name and won't be reused from context data. */
363 ret
= (const WCHAR
*)((BYTE
*)wndclass
+ wndclass
->name_offset
);
366 memcpy(combined
, ret
, *basename_offset
* sizeof(WCHAR
));
367 lstrcpyW(&combined
[*basename_offset
], name
);
371 if (register_class
&& hmod
)
378 LIST_FOR_EACH( ptr
, &class_list
)
380 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
381 if (wcsicmp( class->name
, ret
)) continue;
382 if (!class->local
|| class->hInstance
== hmod
)
393 BOOL (WINAPI
*pRegisterClassNameW
)(const WCHAR
*class);
395 pRegisterClassNameW
= (void *)GetProcAddress(hmod
, "RegisterClassNameW");
396 if (pRegisterClassNameW
)
397 pRegisterClassNameW(name
);
404 /***********************************************************************
407 * Return a pointer to the class.
409 static CLASS
*CLASS_FindClass( LPCWSTR name
, HINSTANCE hinstance
)
412 ATOM atom
= get_int_atom_value( name
);
414 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
416 if (!name
) return NULL
;
418 name
= CLASS_GetVersionedName( name
, NULL
, NULL
, TRUE
);
424 LIST_FOR_EACH( ptr
, &class_list
)
426 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
429 if (class->atomName
!= atom
) continue;
433 if (wcsicmp( class->name
, name
)) continue;
435 if (!class->local
|| class->hInstance
== hinstance
)
437 TRACE("%s %p -> %p\n", debugstr_w(name
), hinstance
, class);
444 if (!is_comctl32_class( name
)) break;
445 if (GetModuleHandleW( L
"comctl32.dll" )) break;
446 if (!LoadLibraryW( L
"comctl32.dll" )) break;
447 TRACE( "%s retrying after loading comctl32\n", debugstr_w(name
) );
450 TRACE("%s %p -> not found\n", debugstr_w(name
), hinstance
);
454 /***********************************************************************
455 * CLASS_RegisterClass
457 * The real RegisterClass() functionality.
459 static CLASS
*CLASS_RegisterClass( LPCWSTR name
, UINT basename_offset
, HINSTANCE hInstance
, BOOL local
,
460 DWORD style
, INT classExtra
, INT winExtra
)
465 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
466 debugstr_w(name
), hInstance
, style
, classExtra
, winExtra
);
468 /* Fix the extra bytes value */
470 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
471 WARN("Class extra bytes %d is > 40\n", classExtra
);
472 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
473 WARN("Win extra bytes %d is > 40\n", winExtra
);
475 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
476 if (!classPtr
) return NULL
;
478 classPtr
->atomName
= get_int_atom_value( name
);
479 classPtr
->basename
= classPtr
->name
;
480 if (!classPtr
->atomName
&& name
)
482 lstrcpyW( classPtr
->name
, name
);
483 classPtr
->basename
+= basename_offset
;
485 else GlobalGetAtomNameW( classPtr
->atomName
, classPtr
->name
, ARRAY_SIZE( classPtr
->name
));
487 SERVER_START_REQ( create_class
)
491 req
->instance
= wine_server_client_ptr( hInstance
);
492 req
->extra
= classExtra
;
493 req
->win_extra
= winExtra
;
494 req
->client_ptr
= wine_server_client_ptr( classPtr
);
495 req
->atom
= classPtr
->atomName
;
496 req
->name_offset
= basename_offset
;
497 if (!req
->atom
&& name
) wine_server_add_data( req
, name
, lstrlenW(name
) * sizeof(WCHAR
) );
498 ret
= !wine_server_call_err( req
);
499 classPtr
->atomName
= reply
->atom
;
504 HeapFree( GetProcessHeap(), 0, classPtr
);
508 classPtr
->style
= style
;
509 classPtr
->local
= local
;
510 classPtr
->cbWndExtra
= winExtra
;
511 classPtr
->cbClsExtra
= classExtra
;
512 classPtr
->hInstance
= hInstance
;
514 /* Other non-null values must be set by caller */
517 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
518 else list_add_tail( &class_list
, &classPtr
->entry
);
523 /***********************************************************************
526 * Register a builtin control class.
527 * This allows having both ANSI and Unicode winprocs for the same class.
529 static void register_builtin( const struct builtin_class_descr
*descr
)
534 if (descr
->cursor
) cursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
536 if (!(classPtr
= CLASS_RegisterClass( descr
->name
, 0, user32_module
, FALSE
,
537 descr
->style
, 0, descr
->extra
)))
539 if (cursor
) DestroyCursor( cursor
);
543 classPtr
->hCursor
= cursor
;
544 classPtr
->hbrBackground
= descr
->brush
;
545 classPtr
->winproc
= BUILTIN_WINPROC( descr
->proc
);
546 release_class_ptr( classPtr
);
549 static void load_uxtheme(void)
551 BOOL (WINAPI
* pIsThemeActive
)(void);
554 uxtheme
= LoadLibraryA("uxtheme.dll");
557 pIsThemeActive
= (void *)GetProcAddress(uxtheme
, "IsThemeActive");
558 if (!pIsThemeActive
|| !pIsThemeActive())
559 FreeLibrary(uxtheme
);
563 /***********************************************************************
566 static BOOL WINAPI
register_builtins( INIT_ONCE
*once
, void *param
, void **context
)
568 register_builtin( &BUTTON_builtin_class
);
569 register_builtin( &COMBO_builtin_class
);
570 register_builtin( &COMBOLBOX_builtin_class
);
571 register_builtin( &DIALOG_builtin_class
);
572 register_builtin( &EDIT_builtin_class
);
573 register_builtin( &ICONTITLE_builtin_class
);
574 register_builtin( &LISTBOX_builtin_class
);
575 register_builtin( &MDICLIENT_builtin_class
);
576 register_builtin( &MENU_builtin_class
);
577 register_builtin( &SCROLL_builtin_class
);
578 register_builtin( &STATIC_builtin_class
);
579 register_builtin( &IME_builtin_class
);
581 /* Load uxtheme.dll so that standard scrollbars and dialogs are hooked for theming support */
587 /***********************************************************************
588 * register_builtin_classes
590 void register_builtin_classes(void)
592 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
596 /***********************************************************************
597 * register_desktop_class
599 void register_desktop_class(void)
601 register_builtin( &DESKTOP_builtin_class
);
602 register_builtin( &MESSAGE_builtin_class
);
606 /***********************************************************************
609 WNDPROC
get_class_winproc( CLASS
*class )
611 return class->winproc
;
615 /***********************************************************************
618 struct dce
*get_class_dce( CLASS
*class )
624 /***********************************************************************
627 struct dce
*set_class_dce( CLASS
*class, struct dce
*dce
)
629 if (class->dce
) return class->dce
; /* already set, don't change it */
635 /***********************************************************************
636 * RegisterClassA (USER32.@)
638 * Register a window class.
641 * >0: Unique identifier
644 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
648 wcex
.cbSize
= sizeof(wcex
);
649 wcex
.style
= wc
->style
;
650 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
651 wcex
.cbClsExtra
= wc
->cbClsExtra
;
652 wcex
.cbWndExtra
= wc
->cbWndExtra
;
653 wcex
.hInstance
= wc
->hInstance
;
654 wcex
.hIcon
= wc
->hIcon
;
655 wcex
.hCursor
= wc
->hCursor
;
656 wcex
.hbrBackground
= wc
->hbrBackground
;
657 wcex
.lpszMenuName
= wc
->lpszMenuName
;
658 wcex
.lpszClassName
= wc
->lpszClassName
;
660 return RegisterClassExA( &wcex
);
664 /***********************************************************************
665 * RegisterClassW (USER32.@)
667 * See RegisterClassA.
669 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
673 wcex
.cbSize
= sizeof(wcex
);
674 wcex
.style
= wc
->style
;
675 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
676 wcex
.cbClsExtra
= wc
->cbClsExtra
;
677 wcex
.cbWndExtra
= wc
->cbWndExtra
;
678 wcex
.hInstance
= wc
->hInstance
;
679 wcex
.hIcon
= wc
->hIcon
;
680 wcex
.hCursor
= wc
->hCursor
;
681 wcex
.hbrBackground
= wc
->hbrBackground
;
682 wcex
.lpszMenuName
= wc
->lpszMenuName
;
683 wcex
.lpszClassName
= wc
->lpszClassName
;
685 return RegisterClassExW( &wcex
);
689 /***********************************************************************
690 * RegisterClassExA (USER32.@)
692 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
694 WCHAR name
[MAX_ATOM_LEN
+ 1], combined
[MAX_ATOM_LEN
+ 1];
695 const WCHAR
*classname
= NULL
;
700 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
702 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
703 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
705 SetLastError( ERROR_INVALID_PARAMETER
);
708 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
710 if (!IS_INTRESOURCE(wc
->lpszClassName
))
712 UINT basename_offset
;
713 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
714 classname
= CLASS_GetVersionedName( name
, &basename_offset
, combined
, FALSE
);
715 classPtr
= CLASS_RegisterClass( classname
, basename_offset
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
716 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
720 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, 0, instance
,
721 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
722 wc
->cbClsExtra
, wc
->cbWndExtra
);
724 if (!classPtr
) return 0;
725 atom
= classPtr
->atomName
;
727 TRACE("name=%s%s%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
728 debugstr_a(wc
->lpszClassName
), classname
!= name
? "->" : "", classname
!= name
? debugstr_w(classname
) : "",
729 atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
731 classPtr
->hIcon
= wc
->hIcon
;
732 classPtr
->hIconSm
= wc
->hIconSm
;
733 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
734 CopyImage( wc
->hIcon
, IMAGE_ICON
,
735 GetSystemMetrics( SM_CXSMICON
),
736 GetSystemMetrics( SM_CYSMICON
),
737 LR_COPYFROMRESOURCE
) : NULL
;
738 classPtr
->hCursor
= wc
->hCursor
;
739 classPtr
->hbrBackground
= wc
->hbrBackground
;
740 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, FALSE
);
741 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
742 release_class_ptr( classPtr
);
747 /***********************************************************************
748 * RegisterClassExW (USER32.@)
750 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
752 WCHAR name
[MAX_ATOM_LEN
+ 1];
753 const WCHAR
*classname
;
754 UINT basename_offset
;
759 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
761 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
762 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
764 SetLastError( ERROR_INVALID_PARAMETER
);
767 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
769 classname
= CLASS_GetVersionedName( wc
->lpszClassName
, &basename_offset
, name
, FALSE
);
770 if (!(classPtr
= CLASS_RegisterClass( classname
, basename_offset
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
771 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
774 atom
= classPtr
->atomName
;
776 TRACE("name=%s%s%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
777 debugstr_w(wc
->lpszClassName
), classname
!= wc
->lpszClassName
? "->" : "",
778 classname
!= wc
->lpszClassName
? debugstr_w(classname
) : "", atom
, wc
->lpfnWndProc
, instance
,
779 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
781 classPtr
->hIcon
= wc
->hIcon
;
782 classPtr
->hIconSm
= wc
->hIconSm
;
783 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
784 CopyImage( wc
->hIcon
, IMAGE_ICON
,
785 GetSystemMetrics( SM_CXSMICON
),
786 GetSystemMetrics( SM_CYSMICON
),
787 LR_COPYFROMRESOURCE
) : NULL
;
788 classPtr
->hCursor
= wc
->hCursor
;
789 classPtr
->hbrBackground
= wc
->hbrBackground
;
790 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, TRUE
);
791 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
792 release_class_ptr( classPtr
);
797 /***********************************************************************
798 * UnregisterClassA (USER32.@)
800 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
802 if (!IS_INTRESOURCE(className
))
804 WCHAR name
[MAX_ATOM_LEN
+ 1];
806 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
808 return UnregisterClassW( name
, hInstance
);
810 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
813 /***********************************************************************
814 * UnregisterClassW (USER32.@)
816 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
818 CLASS
*classPtr
= NULL
;
820 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
822 className
= CLASS_GetVersionedName( className
, NULL
, NULL
, FALSE
);
823 SERVER_START_REQ( destroy_class
)
825 req
->instance
= wine_server_client_ptr( hInstance
);
826 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
827 wine_server_add_data( req
, className
, lstrlenW(className
) * sizeof(WCHAR
) );
828 if (!wine_server_call_err( req
)) classPtr
= wine_server_get_ptr( reply
->client_ptr
);
832 if (classPtr
) CLASS_FreeClass( classPtr
);
833 return (classPtr
!= NULL
);
837 /***********************************************************************
838 * GetClassWord (USER32.@)
840 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
845 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
847 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
849 if (class == CLASS_OTHER_PROCESS
)
851 SERVER_START_REQ( set_class_info
)
853 req
->window
= wine_server_user_handle( hwnd
);
855 req
->extra_offset
= offset
;
856 req
->extra_size
= sizeof(retvalue
);
857 if (!wine_server_call_err( req
))
858 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
864 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
865 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
867 SetLastError( ERROR_INVALID_INDEX
);
868 release_class_ptr( class );
873 /***********************************************************************
876 * Implementation of GetClassLong(Ptr)A/W
878 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
882 ULONG_PTR retvalue
= 0;
884 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
886 if (class == CLASS_OTHER_PROCESS
)
888 SERVER_START_REQ( set_class_info
)
890 req
->window
= wine_server_user_handle( hwnd
);
892 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
893 req
->extra_size
= (offset
>= 0) ? size
: 0;
894 if (!wine_server_call_err( req
))
898 case GCLP_HBRBACKGROUND
:
904 FIXME( "offset %d (%s) not supported on other process window %p\n",
905 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
906 SetLastError( ERROR_INVALID_HANDLE
);
909 retvalue
= reply
->old_style
;
912 retvalue
= reply
->old_win_extra
;
915 retvalue
= reply
->old_extra
;
918 retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
921 retvalue
= reply
->old_atom
;
926 if (size
== sizeof(DWORD
))
929 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
933 memcpy( &retvalue
, &reply
->old_extra_value
,
936 else SetLastError( ERROR_INVALID_INDEX
);
947 if (offset
<= class->cbClsExtra
- size
)
949 if (size
== sizeof(DWORD
))
952 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
956 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
959 SetLastError( ERROR_INVALID_INDEX
);
960 release_class_ptr( class );
966 case GCLP_HBRBACKGROUND
:
967 retvalue
= (ULONG_PTR
)class->hbrBackground
;
970 retvalue
= (ULONG_PTR
)class->hCursor
;
973 retvalue
= (ULONG_PTR
)class->hIcon
;
976 retvalue
= (ULONG_PTR
)(class->hIconSm
? class->hIconSm
: class->hIconSmIntern
);
979 retvalue
= class->style
;
982 retvalue
= class->cbWndExtra
;
985 retvalue
= class->cbClsExtra
;
988 retvalue
= (ULONG_PTR
)class->hInstance
;
991 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
994 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
996 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
998 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
1001 retvalue
= class->atomName
;
1004 SetLastError( ERROR_INVALID_INDEX
);
1007 release_class_ptr( class );
1012 /***********************************************************************
1013 * GetClassLongW (USER32.@)
1015 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
1017 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
1022 /***********************************************************************
1023 * GetClassLongA (USER32.@)
1025 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
1027 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
1031 /***********************************************************************
1032 * SetClassWord (USER32.@)
1034 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
1039 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
1041 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
1043 SERVER_START_REQ( set_class_info
)
1045 req
->window
= wine_server_user_handle( hwnd
);
1046 req
->flags
= SET_CLASS_EXTRA
;
1047 req
->extra_offset
= offset
;
1048 req
->extra_size
= sizeof(newval
);
1049 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
1050 if (!wine_server_call_err( req
))
1052 void *ptr
= (char *)(class + 1) + offset
;
1053 memcpy( &retval
, ptr
, sizeof(retval
) );
1054 memcpy( ptr
, &newval
, sizeof(newval
) );
1058 release_class_ptr( class );
1063 /***********************************************************************
1064 * CLASS_SetClassLong
1066 * Implementation of SetClassLong(Ptr)A/W
1068 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
1069 UINT size
, BOOL unicode
)
1072 ULONG_PTR retval
= 0;
1074 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
1078 if (set_server_info( hwnd
, offset
, newval
, size
))
1080 void *ptr
= (char *)(class + 1) + offset
;
1081 if ( size
== sizeof(LONG
) )
1084 LONG newlong
= newval
;
1085 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
1086 memcpy( ptr
, &newlong
, sizeof(LONG
) );
1091 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
1092 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
1100 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
1102 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
1103 retval
= 0; /* Old value is now meaningless anyway */
1106 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
1107 class->winproc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
1109 case GCLP_HBRBACKGROUND
:
1110 retval
= (ULONG_PTR
)class->hbrBackground
;
1111 class->hbrBackground
= (HBRUSH
)newval
;
1114 retval
= (ULONG_PTR
)class->hCursor
;
1115 class->hCursor
= (HCURSOR
)newval
;
1118 retval
= (ULONG_PTR
)class->hIcon
;
1119 if (class->hIconSmIntern
)
1121 DestroyIcon(class->hIconSmIntern
);
1122 class->hIconSmIntern
= NULL
;
1124 if (newval
&& !class->hIconSm
)
1125 class->hIconSmIntern
= CopyImage( (HICON
)newval
, IMAGE_ICON
,
1126 GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
),
1127 LR_COPYFROMRESOURCE
);
1128 class->hIcon
= (HICON
)newval
;
1131 retval
= (ULONG_PTR
)class->hIconSm
;
1132 if (retval
&& !newval
&& class->hIcon
)
1133 class->hIconSmIntern
= CopyImage( class->hIcon
, IMAGE_ICON
,
1134 GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
),
1135 LR_COPYFROMRESOURCE
);
1136 else if (newval
&& class->hIconSmIntern
)
1138 DestroyIcon(class->hIconSmIntern
);
1139 class->hIconSmIntern
= NULL
;
1141 class->hIconSm
= (HICON
)newval
;
1144 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1145 retval
= class->style
;
1146 class->style
= newval
;
1148 case GCL_CBWNDEXTRA
:
1149 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1150 retval
= class->cbWndExtra
;
1151 class->cbWndExtra
= newval
;
1154 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1155 retval
= (ULONG_PTR
)class->hInstance
;
1156 class->hInstance
= (HINSTANCE
)newval
;
1159 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1160 retval
= class->atomName
;
1161 class->atomName
= newval
;
1162 GlobalGetAtomNameW( newval
, class->name
, ARRAY_SIZE( class->name
));
1164 case GCL_CBCLSEXTRA
: /* cannot change this one */
1165 SetLastError( ERROR_INVALID_PARAMETER
);
1168 SetLastError( ERROR_INVALID_INDEX
);
1171 release_class_ptr( class );
1176 /***********************************************************************
1177 * SetClassLongW (USER32.@)
1179 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
1181 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
1185 /***********************************************************************
1186 * SetClassLongA (USER32.@)
1188 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
1190 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
1194 /***********************************************************************
1195 * GetClassNameA (USER32.@)
1197 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
1199 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1202 if (count
<= 0) return 0;
1203 if (!GetClassNameW( hwnd
, tmpbuf
, ARRAY_SIZE( tmpbuf
))) return 0;
1204 RtlUnicodeToMultiByteN( buffer
, count
- 1, &len
, tmpbuf
, lstrlenW(tmpbuf
) * sizeof(WCHAR
) );
1210 /***********************************************************************
1211 * GetClassNameW (USER32.@)
1213 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
1218 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
1220 if (count
<= 0) return 0;
1222 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
1224 if (class == CLASS_OTHER_PROCESS
)
1226 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1229 SERVER_START_REQ( set_class_info
)
1231 req
->window
= wine_server_user_handle( hwnd
);
1233 req
->extra_offset
= -1;
1234 req
->extra_size
= 0;
1235 if (!wine_server_call_err( req
))
1236 atom
= reply
->base_atom
;
1240 ret
= GlobalGetAtomNameW( atom
, tmpbuf
, MAX_ATOM_LEN
+ 1 );
1243 ret
= min(count
- 1, ret
);
1244 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1250 /* Return original name class was registered with. */
1251 lstrcpynW( buffer
, class->basename
, count
);
1252 release_class_ptr( class );
1253 ret
= lstrlenW( buffer
);
1259 /***********************************************************************
1260 * RealGetWindowClassA (USER32.@)
1262 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1264 return GetClassNameA( hwnd
, buffer
, count
);
1268 /***********************************************************************
1269 * RealGetWindowClassW (USER32.@)
1271 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1273 return GetClassNameW( hwnd
, buffer
, count
);
1277 /***********************************************************************
1278 * GetClassInfoA (USER32.@)
1280 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1283 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1287 wc
->style
= wcex
.style
;
1288 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1289 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1290 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1291 wc
->hInstance
= wcex
.hInstance
;
1292 wc
->hIcon
= wcex
.hIcon
;
1293 wc
->hCursor
= wcex
.hCursor
;
1294 wc
->hbrBackground
= wcex
.hbrBackground
;
1295 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1296 wc
->lpszClassName
= wcex
.lpszClassName
;
1302 /***********************************************************************
1303 * GetClassInfoW (USER32.@)
1305 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1308 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1312 wc
->style
= wcex
.style
;
1313 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1314 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1315 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1316 wc
->hInstance
= wcex
.hInstance
;
1317 wc
->hIcon
= wcex
.hIcon
;
1318 wc
->hCursor
= wcex
.hCursor
;
1319 wc
->hbrBackground
= wcex
.hbrBackground
;
1320 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1321 wc
->lpszClassName
= wcex
.lpszClassName
;
1327 /***********************************************************************
1328 * GetClassInfoExA (USER32.@)
1330 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1335 TRACE("%p %s %p\n", hInstance
, debugstr_a(name
), wc
);
1339 SetLastError( ERROR_NOACCESS
);
1343 if (!hInstance
) hInstance
= user32_module
;
1345 if (!IS_INTRESOURCE(name
))
1347 WCHAR nameW
[MAX_ATOM_LEN
+ 1];
1348 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, ARRAY_SIZE( nameW
)))
1350 classPtr
= CLASS_FindClass( nameW
, hInstance
);
1352 else classPtr
= CLASS_FindClass( (LPCWSTR
)name
, hInstance
);
1356 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1359 wc
->style
= classPtr
->style
;
1360 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1361 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1362 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1363 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1364 wc
->hIcon
= classPtr
->hIcon
;
1365 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1366 wc
->hCursor
= classPtr
->hCursor
;
1367 wc
->hbrBackground
= classPtr
->hbrBackground
;
1368 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1369 wc
->lpszClassName
= name
;
1370 atom
= classPtr
->atomName
;
1371 release_class_ptr( classPtr
);
1373 /* We must return the atom of the class here instead of just TRUE. */
1378 /***********************************************************************
1379 * GetClassInfoExW (USER32.@)
1381 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1386 TRACE("%p %s %p\n", hInstance
, debugstr_w(name
), wc
);
1390 SetLastError( ERROR_NOACCESS
);
1394 if (!hInstance
) hInstance
= user32_module
;
1396 if (!(classPtr
= CLASS_FindClass( name
, hInstance
)))
1398 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1401 wc
->style
= classPtr
->style
;
1402 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1403 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1404 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1405 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1406 wc
->hIcon
= classPtr
->hIcon
;
1407 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1408 wc
->hCursor
= classPtr
->hCursor
;
1409 wc
->hbrBackground
= classPtr
->hbrBackground
;
1410 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1411 wc
->lpszClassName
= name
;
1412 atom
= classPtr
->atomName
;
1413 release_class_ptr( classPtr
);
1415 /* We must return the atom of the class here instead of just TRUE. */
1420 #if 0 /* toolhelp is in kernel, so this cannot work */
1422 /***********************************************************************
1423 * ClassFirst (TOOLHELP.69)
1425 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1427 TRACE("%p\n",pClassEntry
);
1428 pClassEntry
->wNext
= 1;
1429 return ClassNext16( pClassEntry
);
1433 /***********************************************************************
1434 * ClassNext (TOOLHELP.70)
1436 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1439 CLASS
*class = firstClass
;
1441 TRACE("%p\n",pClassEntry
);
1443 if (!pClassEntry
->wNext
) return FALSE
;
1444 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1447 pClassEntry
->wNext
= 0;
1450 pClassEntry
->hInst
= class->hInstance
;
1451 pClassEntry
->wNext
++;
1452 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1453 sizeof(pClassEntry
->szClassName
) );
1458 /* 64bit versions */
1460 #ifdef GetClassLongPtrA
1461 #undef GetClassLongPtrA
1464 #ifdef GetClassLongPtrW
1465 #undef GetClassLongPtrW
1468 #ifdef SetClassLongPtrA
1469 #undef SetClassLongPtrA
1472 #ifdef SetClassLongPtrW
1473 #undef SetClassLongPtrW
1476 /***********************************************************************
1477 * GetClassLongPtrA (USER32.@)
1479 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1481 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1484 /***********************************************************************
1485 * GetClassLongPtrW (USER32.@)
1487 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1489 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1492 /***********************************************************************
1493 * SetClassLongPtrW (USER32.@)
1495 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1497 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1500 /***********************************************************************
1501 * SetClassLongPtrA (USER32.@)
1503 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1505 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);