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 a ASCII 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 ASCII and Unicode winprocs for the same class.
529 static void register_builtin( const struct builtin_class_descr
*descr
)
533 if (!(classPtr
= CLASS_RegisterClass( descr
->name
, 0, user32_module
, FALSE
,
534 descr
->style
, 0, descr
->extra
))) return;
536 if (descr
->cursor
) classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
537 classPtr
->hbrBackground
= descr
->brush
;
538 classPtr
->winproc
= BUILTIN_WINPROC( descr
->proc
);
539 release_class_ptr( classPtr
);
543 /***********************************************************************
546 static BOOL WINAPI
register_builtins( INIT_ONCE
*once
, void *param
, void **context
)
548 register_builtin( &BUTTON_builtin_class
);
549 register_builtin( &COMBO_builtin_class
);
550 register_builtin( &COMBOLBOX_builtin_class
);
551 register_builtin( &DIALOG_builtin_class
);
552 register_builtin( &EDIT_builtin_class
);
553 register_builtin( &ICONTITLE_builtin_class
);
554 register_builtin( &LISTBOX_builtin_class
);
555 register_builtin( &MDICLIENT_builtin_class
);
556 register_builtin( &MENU_builtin_class
);
557 register_builtin( &SCROLL_builtin_class
);
558 register_builtin( &STATIC_builtin_class
);
559 register_builtin( &IME_builtin_class
);
564 /***********************************************************************
565 * register_builtin_classes
567 void register_builtin_classes(void)
569 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
573 /***********************************************************************
574 * register_desktop_class
576 void register_desktop_class(void)
578 register_builtin( &DESKTOP_builtin_class
);
579 register_builtin( &MESSAGE_builtin_class
);
583 /***********************************************************************
586 WNDPROC
get_class_winproc( CLASS
*class )
588 return class->winproc
;
592 /***********************************************************************
595 struct dce
*get_class_dce( CLASS
*class )
601 /***********************************************************************
604 struct dce
*set_class_dce( CLASS
*class, struct dce
*dce
)
606 if (class->dce
) return class->dce
; /* already set, don't change it */
612 /***********************************************************************
613 * RegisterClassA (USER32.@)
615 * Register a window class.
618 * >0: Unique identifier
621 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
625 wcex
.cbSize
= sizeof(wcex
);
626 wcex
.style
= wc
->style
;
627 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
628 wcex
.cbClsExtra
= wc
->cbClsExtra
;
629 wcex
.cbWndExtra
= wc
->cbWndExtra
;
630 wcex
.hInstance
= wc
->hInstance
;
631 wcex
.hIcon
= wc
->hIcon
;
632 wcex
.hCursor
= wc
->hCursor
;
633 wcex
.hbrBackground
= wc
->hbrBackground
;
634 wcex
.lpszMenuName
= wc
->lpszMenuName
;
635 wcex
.lpszClassName
= wc
->lpszClassName
;
637 return RegisterClassExA( &wcex
);
641 /***********************************************************************
642 * RegisterClassW (USER32.@)
644 * See RegisterClassA.
646 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
650 wcex
.cbSize
= sizeof(wcex
);
651 wcex
.style
= wc
->style
;
652 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
653 wcex
.cbClsExtra
= wc
->cbClsExtra
;
654 wcex
.cbWndExtra
= wc
->cbWndExtra
;
655 wcex
.hInstance
= wc
->hInstance
;
656 wcex
.hIcon
= wc
->hIcon
;
657 wcex
.hCursor
= wc
->hCursor
;
658 wcex
.hbrBackground
= wc
->hbrBackground
;
659 wcex
.lpszMenuName
= wc
->lpszMenuName
;
660 wcex
.lpszClassName
= wc
->lpszClassName
;
662 return RegisterClassExW( &wcex
);
666 /***********************************************************************
667 * RegisterClassExA (USER32.@)
669 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
671 WCHAR name
[MAX_ATOM_LEN
+ 1], combined
[MAX_ATOM_LEN
+ 1];
672 const WCHAR
*classname
= NULL
;
677 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
679 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
680 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
682 SetLastError( ERROR_INVALID_PARAMETER
);
685 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
687 if (!IS_INTRESOURCE(wc
->lpszClassName
))
689 UINT basename_offset
;
690 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
691 classname
= CLASS_GetVersionedName( name
, &basename_offset
, combined
, FALSE
);
692 classPtr
= CLASS_RegisterClass( classname
, basename_offset
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
693 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
697 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, 0, instance
,
698 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
699 wc
->cbClsExtra
, wc
->cbWndExtra
);
701 if (!classPtr
) return 0;
702 atom
= classPtr
->atomName
;
704 TRACE("name=%s%s%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
705 debugstr_a(wc
->lpszClassName
), classname
!= name
? "->" : "", classname
!= name
? debugstr_w(classname
) : "",
706 atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
708 classPtr
->hIcon
= wc
->hIcon
;
709 classPtr
->hIconSm
= wc
->hIconSm
;
710 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
711 CopyImage( wc
->hIcon
, IMAGE_ICON
,
712 GetSystemMetrics( SM_CXSMICON
),
713 GetSystemMetrics( SM_CYSMICON
),
714 LR_COPYFROMRESOURCE
) : NULL
;
715 classPtr
->hCursor
= wc
->hCursor
;
716 classPtr
->hbrBackground
= wc
->hbrBackground
;
717 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, FALSE
);
718 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
719 release_class_ptr( classPtr
);
724 /***********************************************************************
725 * RegisterClassExW (USER32.@)
727 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
729 WCHAR name
[MAX_ATOM_LEN
+ 1];
730 const WCHAR
*classname
;
731 UINT basename_offset
;
736 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
738 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
739 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
741 SetLastError( ERROR_INVALID_PARAMETER
);
744 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
746 classname
= CLASS_GetVersionedName( wc
->lpszClassName
, &basename_offset
, name
, FALSE
);
747 if (!(classPtr
= CLASS_RegisterClass( classname
, basename_offset
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
748 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
751 atom
= classPtr
->atomName
;
753 TRACE("name=%s%s%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
754 debugstr_w(wc
->lpszClassName
), classname
!= wc
->lpszClassName
? "->" : "",
755 classname
!= wc
->lpszClassName
? debugstr_w(classname
) : "", atom
, wc
->lpfnWndProc
, instance
,
756 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
758 classPtr
->hIcon
= wc
->hIcon
;
759 classPtr
->hIconSm
= wc
->hIconSm
;
760 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
761 CopyImage( wc
->hIcon
, IMAGE_ICON
,
762 GetSystemMetrics( SM_CXSMICON
),
763 GetSystemMetrics( SM_CYSMICON
),
764 LR_COPYFROMRESOURCE
) : NULL
;
765 classPtr
->hCursor
= wc
->hCursor
;
766 classPtr
->hbrBackground
= wc
->hbrBackground
;
767 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, TRUE
);
768 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
769 release_class_ptr( classPtr
);
774 /***********************************************************************
775 * UnregisterClassA (USER32.@)
777 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
779 if (!IS_INTRESOURCE(className
))
781 WCHAR name
[MAX_ATOM_LEN
+ 1];
783 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
785 return UnregisterClassW( name
, hInstance
);
787 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
790 /***********************************************************************
791 * UnregisterClassW (USER32.@)
793 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
795 CLASS
*classPtr
= NULL
;
797 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
799 className
= CLASS_GetVersionedName( className
, NULL
, NULL
, FALSE
);
800 SERVER_START_REQ( destroy_class
)
802 req
->instance
= wine_server_client_ptr( hInstance
);
803 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
804 wine_server_add_data( req
, className
, lstrlenW(className
) * sizeof(WCHAR
) );
805 if (!wine_server_call_err( req
)) classPtr
= wine_server_get_ptr( reply
->client_ptr
);
809 if (classPtr
) CLASS_FreeClass( classPtr
);
810 return (classPtr
!= NULL
);
814 /***********************************************************************
815 * GetClassWord (USER32.@)
817 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
822 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
824 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
826 if (class == CLASS_OTHER_PROCESS
)
828 SERVER_START_REQ( set_class_info
)
830 req
->window
= wine_server_user_handle( hwnd
);
832 req
->extra_offset
= offset
;
833 req
->extra_size
= sizeof(retvalue
);
834 if (!wine_server_call_err( req
))
835 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
841 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
842 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
844 SetLastError( ERROR_INVALID_INDEX
);
845 release_class_ptr( class );
850 /***********************************************************************
853 * Implementation of GetClassLong(Ptr)A/W
855 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
859 ULONG_PTR retvalue
= 0;
861 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
863 if (class == CLASS_OTHER_PROCESS
)
865 SERVER_START_REQ( set_class_info
)
867 req
->window
= wine_server_user_handle( hwnd
);
869 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
870 req
->extra_size
= (offset
>= 0) ? size
: 0;
871 if (!wine_server_call_err( req
))
875 case GCLP_HBRBACKGROUND
:
881 FIXME( "offset %d (%s) not supported on other process window %p\n",
882 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
883 SetLastError( ERROR_INVALID_HANDLE
);
886 retvalue
= reply
->old_style
;
889 retvalue
= reply
->old_win_extra
;
892 retvalue
= reply
->old_extra
;
895 retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
898 retvalue
= reply
->old_atom
;
903 if (size
== sizeof(DWORD
))
906 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
910 memcpy( &retvalue
, &reply
->old_extra_value
,
913 else SetLastError( ERROR_INVALID_INDEX
);
924 if (offset
<= class->cbClsExtra
- size
)
926 if (size
== sizeof(DWORD
))
929 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
933 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
936 SetLastError( ERROR_INVALID_INDEX
);
937 release_class_ptr( class );
943 case GCLP_HBRBACKGROUND
:
944 retvalue
= (ULONG_PTR
)class->hbrBackground
;
947 retvalue
= (ULONG_PTR
)class->hCursor
;
950 retvalue
= (ULONG_PTR
)class->hIcon
;
953 retvalue
= (ULONG_PTR
)(class->hIconSm
? class->hIconSm
: class->hIconSmIntern
);
956 retvalue
= class->style
;
959 retvalue
= class->cbWndExtra
;
962 retvalue
= class->cbClsExtra
;
965 retvalue
= (ULONG_PTR
)class->hInstance
;
968 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
971 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
973 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
975 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
978 retvalue
= class->atomName
;
981 SetLastError( ERROR_INVALID_INDEX
);
984 release_class_ptr( class );
989 /***********************************************************************
990 * GetClassLongW (USER32.@)
992 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
994 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
999 /***********************************************************************
1000 * GetClassLongA (USER32.@)
1002 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
1004 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
1008 /***********************************************************************
1009 * SetClassWord (USER32.@)
1011 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
1016 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
1018 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
1020 SERVER_START_REQ( set_class_info
)
1022 req
->window
= wine_server_user_handle( hwnd
);
1023 req
->flags
= SET_CLASS_EXTRA
;
1024 req
->extra_offset
= offset
;
1025 req
->extra_size
= sizeof(newval
);
1026 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
1027 if (!wine_server_call_err( req
))
1029 void *ptr
= (char *)(class + 1) + offset
;
1030 memcpy( &retval
, ptr
, sizeof(retval
) );
1031 memcpy( ptr
, &newval
, sizeof(newval
) );
1035 release_class_ptr( class );
1040 /***********************************************************************
1041 * CLASS_SetClassLong
1043 * Implementation of SetClassLong(Ptr)A/W
1045 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
1046 UINT size
, BOOL unicode
)
1049 ULONG_PTR retval
= 0;
1051 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
1055 if (set_server_info( hwnd
, offset
, newval
, size
))
1057 void *ptr
= (char *)(class + 1) + offset
;
1058 if ( size
== sizeof(LONG
) )
1061 LONG newlong
= newval
;
1062 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
1063 memcpy( ptr
, &newlong
, sizeof(LONG
) );
1068 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
1069 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
1077 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
1079 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
1080 retval
= 0; /* Old value is now meaningless anyway */
1083 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
1084 class->winproc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
1086 case GCLP_HBRBACKGROUND
:
1087 retval
= (ULONG_PTR
)class->hbrBackground
;
1088 class->hbrBackground
= (HBRUSH
)newval
;
1091 retval
= (ULONG_PTR
)class->hCursor
;
1092 class->hCursor
= (HCURSOR
)newval
;
1095 retval
= (ULONG_PTR
)class->hIcon
;
1096 if (class->hIconSmIntern
)
1098 DestroyIcon(class->hIconSmIntern
);
1099 class->hIconSmIntern
= NULL
;
1101 if (newval
&& !class->hIconSm
)
1102 class->hIconSmIntern
= CopyImage( (HICON
)newval
, IMAGE_ICON
,
1103 GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
),
1104 LR_COPYFROMRESOURCE
);
1105 class->hIcon
= (HICON
)newval
;
1108 retval
= (ULONG_PTR
)class->hIconSm
;
1109 if (retval
&& !newval
&& class->hIcon
)
1110 class->hIconSmIntern
= CopyImage( class->hIcon
, IMAGE_ICON
,
1111 GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
),
1112 LR_COPYFROMRESOURCE
);
1113 else if (newval
&& class->hIconSmIntern
)
1115 DestroyIcon(class->hIconSmIntern
);
1116 class->hIconSmIntern
= NULL
;
1118 class->hIconSm
= (HICON
)newval
;
1121 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1122 retval
= class->style
;
1123 class->style
= newval
;
1125 case GCL_CBWNDEXTRA
:
1126 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1127 retval
= class->cbWndExtra
;
1128 class->cbWndExtra
= newval
;
1131 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1132 retval
= (ULONG_PTR
)class->hInstance
;
1133 class->hInstance
= (HINSTANCE
)newval
;
1136 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1137 retval
= class->atomName
;
1138 class->atomName
= newval
;
1139 GlobalGetAtomNameW( newval
, class->name
, ARRAY_SIZE( class->name
));
1141 case GCL_CBCLSEXTRA
: /* cannot change this one */
1142 SetLastError( ERROR_INVALID_PARAMETER
);
1145 SetLastError( ERROR_INVALID_INDEX
);
1148 release_class_ptr( class );
1153 /***********************************************************************
1154 * SetClassLongW (USER32.@)
1156 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
1158 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
1162 /***********************************************************************
1163 * SetClassLongA (USER32.@)
1165 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
1167 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
1171 /***********************************************************************
1172 * GetClassNameA (USER32.@)
1174 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
1176 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1179 if (count
<= 0) return 0;
1180 if (!GetClassNameW( hwnd
, tmpbuf
, ARRAY_SIZE( tmpbuf
))) return 0;
1181 RtlUnicodeToMultiByteN( buffer
, count
- 1, &len
, tmpbuf
, lstrlenW(tmpbuf
) * sizeof(WCHAR
) );
1187 /***********************************************************************
1188 * GetClassNameW (USER32.@)
1190 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
1195 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
1197 if (count
<= 0) return 0;
1199 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
1201 if (class == CLASS_OTHER_PROCESS
)
1203 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1206 SERVER_START_REQ( set_class_info
)
1208 req
->window
= wine_server_user_handle( hwnd
);
1210 req
->extra_offset
= -1;
1211 req
->extra_size
= 0;
1212 if (!wine_server_call_err( req
))
1213 atom
= reply
->base_atom
;
1217 ret
= GlobalGetAtomNameW( atom
, tmpbuf
, MAX_ATOM_LEN
+ 1 );
1220 ret
= min(count
- 1, ret
);
1221 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1227 /* Return original name class was registered with. */
1228 lstrcpynW( buffer
, class->basename
, count
);
1229 release_class_ptr( class );
1230 ret
= lstrlenW( buffer
);
1236 /***********************************************************************
1237 * RealGetWindowClassA (USER32.@)
1239 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1241 return GetClassNameA( hwnd
, buffer
, count
);
1245 /***********************************************************************
1246 * RealGetWindowClassW (USER32.@)
1248 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1250 return GetClassNameW( hwnd
, buffer
, count
);
1254 /***********************************************************************
1255 * GetClassInfoA (USER32.@)
1257 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1260 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1264 wc
->style
= wcex
.style
;
1265 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1266 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1267 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1268 wc
->hInstance
= wcex
.hInstance
;
1269 wc
->hIcon
= wcex
.hIcon
;
1270 wc
->hCursor
= wcex
.hCursor
;
1271 wc
->hbrBackground
= wcex
.hbrBackground
;
1272 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1273 wc
->lpszClassName
= wcex
.lpszClassName
;
1279 /***********************************************************************
1280 * GetClassInfoW (USER32.@)
1282 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1285 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1289 wc
->style
= wcex
.style
;
1290 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1291 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1292 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1293 wc
->hInstance
= wcex
.hInstance
;
1294 wc
->hIcon
= wcex
.hIcon
;
1295 wc
->hCursor
= wcex
.hCursor
;
1296 wc
->hbrBackground
= wcex
.hbrBackground
;
1297 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1298 wc
->lpszClassName
= wcex
.lpszClassName
;
1304 /***********************************************************************
1305 * GetClassInfoExA (USER32.@)
1307 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1312 TRACE("%p %s %p\n", hInstance
, debugstr_a(name
), wc
);
1316 SetLastError( ERROR_NOACCESS
);
1320 if (!hInstance
) hInstance
= user32_module
;
1322 if (!IS_INTRESOURCE(name
))
1324 WCHAR nameW
[MAX_ATOM_LEN
+ 1];
1325 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, ARRAY_SIZE( nameW
)))
1327 classPtr
= CLASS_FindClass( nameW
, hInstance
);
1329 else classPtr
= CLASS_FindClass( (LPCWSTR
)name
, hInstance
);
1333 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1336 wc
->style
= classPtr
->style
;
1337 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1338 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1339 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1340 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1341 wc
->hIcon
= classPtr
->hIcon
;
1342 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1343 wc
->hCursor
= classPtr
->hCursor
;
1344 wc
->hbrBackground
= classPtr
->hbrBackground
;
1345 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1346 wc
->lpszClassName
= name
;
1347 atom
= classPtr
->atomName
;
1348 release_class_ptr( classPtr
);
1350 /* We must return the atom of the class here instead of just TRUE. */
1355 /***********************************************************************
1356 * GetClassInfoExW (USER32.@)
1358 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1363 TRACE("%p %s %p\n", hInstance
, debugstr_w(name
), wc
);
1367 SetLastError( ERROR_NOACCESS
);
1371 if (!hInstance
) hInstance
= user32_module
;
1373 if (!(classPtr
= CLASS_FindClass( name
, hInstance
)))
1375 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1378 wc
->style
= classPtr
->style
;
1379 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1380 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1381 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1382 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1383 wc
->hIcon
= classPtr
->hIcon
;
1384 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1385 wc
->hCursor
= classPtr
->hCursor
;
1386 wc
->hbrBackground
= classPtr
->hbrBackground
;
1387 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1388 wc
->lpszClassName
= name
;
1389 atom
= classPtr
->atomName
;
1390 release_class_ptr( classPtr
);
1392 /* We must return the atom of the class here instead of just TRUE. */
1397 #if 0 /* toolhelp is in kernel, so this cannot work */
1399 /***********************************************************************
1400 * ClassFirst (TOOLHELP.69)
1402 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1404 TRACE("%p\n",pClassEntry
);
1405 pClassEntry
->wNext
= 1;
1406 return ClassNext16( pClassEntry
);
1410 /***********************************************************************
1411 * ClassNext (TOOLHELP.70)
1413 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1416 CLASS
*class = firstClass
;
1418 TRACE("%p\n",pClassEntry
);
1420 if (!pClassEntry
->wNext
) return FALSE
;
1421 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1424 pClassEntry
->wNext
= 0;
1427 pClassEntry
->hInst
= class->hInstance
;
1428 pClassEntry
->wNext
++;
1429 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1430 sizeof(pClassEntry
->szClassName
) );
1435 /* 64bit versions */
1437 #ifdef GetClassLongPtrA
1438 #undef GetClassLongPtrA
1441 #ifdef GetClassLongPtrW
1442 #undef GetClassLongPtrW
1445 #ifdef SetClassLongPtrA
1446 #undef SetClassLongPtrA
1449 #ifdef SetClassLongPtrW
1450 #undef SetClassLongPtrW
1453 /***********************************************************************
1454 * GetClassLongPtrA (USER32.@)
1456 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1458 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1461 /***********************************************************************
1462 * GetClassLongPtrW (USER32.@)
1464 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1466 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1469 /***********************************************************************
1470 * SetClassLongPtrW (USER32.@)
1472 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1474 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1477 /***********************************************************************
1478 * SetClassLongPtrA (USER32.@)
1480 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1482 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);