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];
64 WCHAR
*basename
; /* Base name for redirected classes, pointer within 'name'. */
67 static struct list class_list
= LIST_INIT( class_list
);
68 static INIT_ONCE init_once
= INIT_ONCE_STATIC_INIT
;
70 #define CLASS_OTHER_PROCESS ((CLASS *)1)
72 /***********************************************************************
75 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
77 WND
*ptr
= WIN_GetPtr( hwnd
);
81 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
) return ptr
->class;
82 if (!write_access
) return CLASS_OTHER_PROCESS
;
84 /* modifying classes in other processes is not allowed */
85 if (ptr
== WND_DESKTOP
|| IsWindow( hwnd
))
87 SetLastError( ERROR_ACCESS_DENIED
);
91 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
96 /***********************************************************************
99 static inline void release_class_ptr( CLASS
*ptr
)
105 /***********************************************************************
108 ATOM
get_int_atom_value( LPCWSTR name
)
112 if (IS_INTRESOURCE(name
)) return LOWORD(name
);
113 if (*name
++ != '#') return 0;
116 if (*name
< '0' || *name
> '9') return 0;
117 ret
= ret
* 10 + *name
++ - '0';
118 if (ret
> 0xffff) return 0;
124 /***********************************************************************
127 static BOOL
is_comctl32_class( const WCHAR
*name
)
129 static const WCHAR classesW
[][20] =
131 {'C','o','m','b','o','B','o','x','E','x','3','2',0},
132 {'m','s','c','t','l','s','_','h','o','t','k','e','y','3','2',0},
133 {'m','s','c','t','l','s','_','p','r','o','g','r','e','s','s','3','2',0},
134 {'m','s','c','t','l','s','_','s','t','a','t','u','s','b','a','r','3','2',0},
135 {'m','s','c','t','l','s','_','t','r','a','c','k','b','a','r','3','2',0},
136 {'m','s','c','t','l','s','_','u','p','d','o','w','n','3','2',0},
137 {'N','a','t','i','v','e','F','o','n','t','C','t','l',0},
138 {'R','e','B','a','r','W','i','n','d','o','w','3','2',0},
139 {'S','y','s','A','n','i','m','a','t','e','3','2',0},
140 {'S','y','s','D','a','t','e','T','i','m','e','P','i','c','k','3','2',0},
141 {'S','y','s','H','e','a','d','e','r','3','2',0},
142 {'S','y','s','I','P','A','d','d','r','e','s','s','3','2',0},
143 {'S','y','s','L','i','n','k',0},
144 {'S','y','s','L','i','s','t','V','i','e','w','3','2',0},
145 {'S','y','s','M','o','n','t','h','C','a','l','3','2',0},
146 {'S','y','s','P','a','g','e','r',0},
147 {'S','y','s','T','a','b','C','o','n','t','r','o','l','3','2',0},
148 {'S','y','s','T','r','e','e','V','i','e','w','3','2',0},
149 {'T','o','o','l','b','a','r','W','i','n','d','o','w','3','2',0},
150 {'t','o','o','l','t','i','p','s','_','c','l','a','s','s','3','2',0},
153 int min
= 0, max
= ARRAY_SIZE( classesW
) - 1;
157 int res
, pos
= (min
+ max
) / 2;
158 if (!(res
= strcmpiW( name
, classesW
[pos
] ))) return TRUE
;
159 if (res
< 0) max
= pos
- 1;
165 static BOOL
is_builtin_class( const WCHAR
*name
)
167 static const WCHAR classesW
[][20] =
170 {'M','D','I','C','l','i','e','n','t',0},
171 {'S','c','r','o','l','l','b','a','r',0},
174 int min
= 0, max
= ARRAY_SIZE( classesW
) - 1;
178 int res
, pos
= (min
+ max
) / 2;
179 if (!(res
= strcmpiW( name
, classesW
[pos
] ))) return TRUE
;
180 if (res
< 0) max
= pos
- 1;
186 /***********************************************************************
189 * Set class info with the wine server.
191 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG_PTR newval
, UINT size
)
195 SERVER_START_REQ( set_class_info
)
197 req
->window
= wine_server_user_handle( hwnd
);
198 req
->extra_offset
= -1;
202 req
->flags
= SET_CLASS_ATOM
;
203 req
->atom
= LOWORD(newval
);
206 req
->flags
= SET_CLASS_STYLE
;
210 req
->flags
= SET_CLASS_WINEXTRA
;
211 req
->win_extra
= newval
;
214 req
->flags
= SET_CLASS_INSTANCE
;
215 req
->instance
= wine_server_client_ptr( (void *)newval
);
218 assert( offset
>= 0 );
219 req
->flags
= SET_CLASS_EXTRA
;
220 req
->extra_offset
= offset
;
221 req
->extra_size
= size
;
222 if ( size
== sizeof(LONG
) )
224 LONG newlong
= newval
;
225 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
228 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
231 ret
= !wine_server_call_err( req
);
238 /***********************************************************************
241 * Get the menu name as a ASCII string.
243 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
245 if (IS_INTRESOURCE(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
246 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
250 /***********************************************************************
253 * Get the menu name as a Unicode string.
255 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
257 return classPtr
->menuName
;
261 /***********************************************************************
264 * Set the menu name in a class structure by copying the string.
266 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
268 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
269 if (!IS_INTRESOURCE(name
))
271 DWORD lenA
= strlen(name
) + 1;
272 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
273 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
274 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
275 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
277 else classPtr
->menuName
= (LPWSTR
)name
;
281 /***********************************************************************
284 * Set the menu name in a class structure by copying the string.
286 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
288 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
289 if (!IS_INTRESOURCE(name
))
291 DWORD lenW
= strlenW(name
) + 1;
292 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
293 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
294 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
295 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
296 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
298 else classPtr
->menuName
= (LPWSTR
)name
;
302 /***********************************************************************
305 * Free a class structure.
307 static void CLASS_FreeClass( CLASS
*classPtr
)
309 TRACE("%p\n", classPtr
);
313 if (classPtr
->dce
) free_dce( classPtr
->dce
, 0 );
314 list_remove( &classPtr
->entry
);
315 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
316 DeleteObject( classPtr
->hbrBackground
);
317 DestroyIcon( classPtr
->hIconSmIntern
);
318 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
319 HeapFree( GetProcessHeap(), 0, classPtr
);
323 const WCHAR
*CLASS_GetVersionedName( const WCHAR
*name
, UINT
*basename_offset
, BOOL register_class
)
325 ACTCTX_SECTION_KEYED_DATA data
;
326 struct wndclass_redirect_data
335 const WCHAR
*module
, *ret
;
339 *basename_offset
= 0;
341 if (IS_INTRESOURCE( name
))
344 if (is_comctl32_class( name
) || is_builtin_class( name
))
347 data
.cbSize
= sizeof(data
);
348 if (!FindActCtxSectionStringW(0, NULL
, ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
, name
, &data
))
351 wndclass
= (struct wndclass_redirect_data
*)data
.lpData
;
353 *basename_offset
= wndclass
->name_len
/ sizeof(WCHAR
) - strlenW(name
);
355 module
= (const WCHAR
*)((BYTE
*)data
.lpSectionBase
+ wndclass
->module_offset
);
356 if (!(hmod
= GetModuleHandleW( module
)))
357 hmod
= LoadLibraryW( module
);
359 ret
= (const WCHAR
*)((BYTE
*)wndclass
+ wndclass
->name_offset
);
361 if (register_class
&& hmod
)
368 LIST_FOR_EACH( ptr
, &class_list
)
370 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
371 if (strcmpiW( class->name
, ret
)) continue;
372 if (!class->local
|| class->hInstance
== hmod
)
383 BOOL (WINAPI
*pRegisterClassNameW
)(const WCHAR
*class);
385 pRegisterClassNameW
= (void *)GetProcAddress(hmod
, "RegisterClassNameW");
386 if (pRegisterClassNameW
)
387 pRegisterClassNameW(name
);
394 /***********************************************************************
397 * Return a pointer to the class.
399 static CLASS
*CLASS_FindClass( LPCWSTR name
, HINSTANCE hinstance
)
401 static const WCHAR comctl32W
[] = {'c','o','m','c','t','l','3','2','.','d','l','l',0};
403 ATOM atom
= get_int_atom_value( name
);
405 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
407 if (!name
) return NULL
;
409 name
= CLASS_GetVersionedName( name
, NULL
, TRUE
);
415 LIST_FOR_EACH( ptr
, &class_list
)
417 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
420 if (class->atomName
!= atom
) continue;
424 if (strcmpiW( class->name
, name
)) continue;
426 if (!class->local
|| class->hInstance
== hinstance
)
428 TRACE("%s %p -> %p\n", debugstr_w(name
), hinstance
, class);
435 if (!is_comctl32_class( name
)) break;
436 if (GetModuleHandleW( comctl32W
)) break;
437 if (!LoadLibraryW( comctl32W
)) break;
438 TRACE( "%s retrying after loading comctl32\n", debugstr_w(name
) );
441 TRACE("%s %p -> not found\n", debugstr_w(name
), hinstance
);
445 /***********************************************************************
446 * CLASS_RegisterClass
448 * The real RegisterClass() functionality.
450 static CLASS
*CLASS_RegisterClass( LPCWSTR name
, UINT basename_offset
, HINSTANCE hInstance
, BOOL local
,
451 DWORD style
, INT classExtra
, INT winExtra
)
456 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
457 debugstr_w(name
), hInstance
, style
, classExtra
, winExtra
);
459 /* Fix the extra bytes value */
461 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
462 WARN("Class extra bytes %d is > 40\n", classExtra
);
463 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
464 WARN("Win extra bytes %d is > 40\n", winExtra
);
466 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
467 if (!classPtr
) return NULL
;
469 classPtr
->atomName
= get_int_atom_value( name
);
470 classPtr
->basename
= classPtr
->name
;
471 if (!classPtr
->atomName
&& name
)
473 strcpyW( classPtr
->name
, name
);
474 classPtr
->basename
+= basename_offset
;
476 else GlobalGetAtomNameW( classPtr
->atomName
, classPtr
->name
, ARRAY_SIZE( classPtr
->name
));
478 SERVER_START_REQ( create_class
)
482 req
->instance
= wine_server_client_ptr( hInstance
);
483 req
->extra
= classExtra
;
484 req
->win_extra
= winExtra
;
485 req
->client_ptr
= wine_server_client_ptr( classPtr
);
486 req
->atom
= classPtr
->atomName
;
487 if (!req
->atom
&& name
) wine_server_add_data( req
, name
, strlenW(name
) * sizeof(WCHAR
) );
488 ret
= !wine_server_call_err( req
);
489 classPtr
->atomName
= reply
->atom
;
494 HeapFree( GetProcessHeap(), 0, classPtr
);
498 classPtr
->style
= style
;
499 classPtr
->local
= local
;
500 classPtr
->cbWndExtra
= winExtra
;
501 classPtr
->cbClsExtra
= classExtra
;
502 classPtr
->hInstance
= hInstance
;
504 /* Other non-null values must be set by caller */
507 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
508 else list_add_tail( &class_list
, &classPtr
->entry
);
513 /***********************************************************************
516 * Register a builtin control class.
517 * This allows having both ASCII and Unicode winprocs for the same class.
519 static void register_builtin( const struct builtin_class_descr
*descr
)
523 if (!(classPtr
= CLASS_RegisterClass( descr
->name
, 0, user32_module
, FALSE
,
524 descr
->style
, 0, descr
->extra
))) return;
526 if (descr
->cursor
) classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
527 classPtr
->hbrBackground
= descr
->brush
;
528 classPtr
->winproc
= BUILTIN_WINPROC( descr
->proc
);
529 release_class_ptr( classPtr
);
533 /***********************************************************************
536 static BOOL WINAPI
register_builtins( INIT_ONCE
*once
, void *param
, void **context
)
538 register_builtin( &BUTTON_builtin_class
);
539 register_builtin( &COMBO_builtin_class
);
540 register_builtin( &COMBOLBOX_builtin_class
);
541 register_builtin( &DIALOG_builtin_class
);
542 register_builtin( &EDIT_builtin_class
);
543 register_builtin( &ICONTITLE_builtin_class
);
544 register_builtin( &LISTBOX_builtin_class
);
545 register_builtin( &MDICLIENT_builtin_class
);
546 register_builtin( &MENU_builtin_class
);
547 register_builtin( &SCROLL_builtin_class
);
548 register_builtin( &STATIC_builtin_class
);
549 register_builtin( &IME_builtin_class
);
554 /***********************************************************************
555 * register_builtin_classes
557 void register_builtin_classes(void)
559 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
563 /***********************************************************************
564 * register_desktop_class
566 void register_desktop_class(void)
568 register_builtin( &DESKTOP_builtin_class
);
569 register_builtin( &MESSAGE_builtin_class
);
573 /***********************************************************************
576 WNDPROC
get_class_winproc( CLASS
*class )
578 return class->winproc
;
582 /***********************************************************************
585 struct dce
*get_class_dce( CLASS
*class )
591 /***********************************************************************
594 struct dce
*set_class_dce( CLASS
*class, struct dce
*dce
)
596 if (class->dce
) return class->dce
; /* already set, don't change it */
602 /***********************************************************************
603 * RegisterClassA (USER32.@)
605 * Register a window class.
608 * >0: Unique identifier
611 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
615 wcex
.cbSize
= sizeof(wcex
);
616 wcex
.style
= wc
->style
;
617 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
618 wcex
.cbClsExtra
= wc
->cbClsExtra
;
619 wcex
.cbWndExtra
= wc
->cbWndExtra
;
620 wcex
.hInstance
= wc
->hInstance
;
621 wcex
.hIcon
= wc
->hIcon
;
622 wcex
.hCursor
= wc
->hCursor
;
623 wcex
.hbrBackground
= wc
->hbrBackground
;
624 wcex
.lpszMenuName
= wc
->lpszMenuName
;
625 wcex
.lpszClassName
= wc
->lpszClassName
;
627 return RegisterClassExA( &wcex
);
631 /***********************************************************************
632 * RegisterClassW (USER32.@)
634 * See RegisterClassA.
636 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
640 wcex
.cbSize
= sizeof(wcex
);
641 wcex
.style
= wc
->style
;
642 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
643 wcex
.cbClsExtra
= wc
->cbClsExtra
;
644 wcex
.cbWndExtra
= wc
->cbWndExtra
;
645 wcex
.hInstance
= wc
->hInstance
;
646 wcex
.hIcon
= wc
->hIcon
;
647 wcex
.hCursor
= wc
->hCursor
;
648 wcex
.hbrBackground
= wc
->hbrBackground
;
649 wcex
.lpszMenuName
= wc
->lpszMenuName
;
650 wcex
.lpszClassName
= wc
->lpszClassName
;
652 return RegisterClassExW( &wcex
);
656 /***********************************************************************
657 * RegisterClassExA (USER32.@)
659 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
661 const WCHAR
*classname
= NULL
;
662 WCHAR name
[MAX_ATOM_LEN
+ 1];
667 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
669 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
670 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
672 SetLastError( ERROR_INVALID_PARAMETER
);
675 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
677 if (!IS_INTRESOURCE(wc
->lpszClassName
))
679 UINT basename_offset
;
680 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
681 classname
= CLASS_GetVersionedName( name
, &basename_offset
, FALSE
);
682 classPtr
= CLASS_RegisterClass( classname
, basename_offset
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
683 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
687 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, 0, instance
,
688 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
689 wc
->cbClsExtra
, wc
->cbWndExtra
);
691 if (!classPtr
) return 0;
692 atom
= classPtr
->atomName
;
694 TRACE("name=%s%s%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
695 debugstr_a(wc
->lpszClassName
), classname
!= name
? "->" : "", classname
!= name
? debugstr_w(classname
) : "",
696 atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
698 classPtr
->hIcon
= wc
->hIcon
;
699 classPtr
->hIconSm
= wc
->hIconSm
;
700 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
701 CopyImage( wc
->hIcon
, IMAGE_ICON
,
702 GetSystemMetrics( SM_CXSMICON
),
703 GetSystemMetrics( SM_CYSMICON
),
704 LR_COPYFROMRESOURCE
) : NULL
;
705 classPtr
->hCursor
= wc
->hCursor
;
706 classPtr
->hbrBackground
= wc
->hbrBackground
;
707 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, FALSE
);
708 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
709 release_class_ptr( classPtr
);
714 /***********************************************************************
715 * RegisterClassExW (USER32.@)
717 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
719 const WCHAR
*classname
;
720 UINT basename_offset
;
725 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
727 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
728 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
730 SetLastError( ERROR_INVALID_PARAMETER
);
733 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
735 classname
= CLASS_GetVersionedName( wc
->lpszClassName
, &basename_offset
, FALSE
);
736 if (!(classPtr
= CLASS_RegisterClass( classname
, basename_offset
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
737 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
740 atom
= classPtr
->atomName
;
742 TRACE("name=%s%s%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
743 debugstr_w(wc
->lpszClassName
), classname
!= wc
->lpszClassName
? "->" : "",
744 classname
!= wc
->lpszClassName
? debugstr_w(classname
) : "", atom
, wc
->lpfnWndProc
, instance
,
745 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
747 classPtr
->hIcon
= wc
->hIcon
;
748 classPtr
->hIconSm
= wc
->hIconSm
;
749 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
750 CopyImage( wc
->hIcon
, IMAGE_ICON
,
751 GetSystemMetrics( SM_CXSMICON
),
752 GetSystemMetrics( SM_CYSMICON
),
753 LR_COPYFROMRESOURCE
) : NULL
;
754 classPtr
->hCursor
= wc
->hCursor
;
755 classPtr
->hbrBackground
= wc
->hbrBackground
;
756 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, TRUE
);
757 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
758 release_class_ptr( classPtr
);
763 /***********************************************************************
764 * UnregisterClassA (USER32.@)
766 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
768 if (!IS_INTRESOURCE(className
))
770 WCHAR name
[MAX_ATOM_LEN
+ 1];
772 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
774 return UnregisterClassW( name
, hInstance
);
776 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
779 /***********************************************************************
780 * UnregisterClassW (USER32.@)
782 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
784 CLASS
*classPtr
= NULL
;
786 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
788 className
= CLASS_GetVersionedName( className
, NULL
, FALSE
);
789 SERVER_START_REQ( destroy_class
)
791 req
->instance
= wine_server_client_ptr( hInstance
);
792 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
793 wine_server_add_data( req
, className
, strlenW(className
) * sizeof(WCHAR
) );
794 if (!wine_server_call_err( req
)) classPtr
= wine_server_get_ptr( reply
->client_ptr
);
798 if (classPtr
) CLASS_FreeClass( classPtr
);
799 return (classPtr
!= NULL
);
803 /***********************************************************************
804 * GetClassWord (USER32.@)
806 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
811 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
813 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
815 if (class == CLASS_OTHER_PROCESS
)
817 SERVER_START_REQ( set_class_info
)
819 req
->window
= wine_server_user_handle( hwnd
);
821 req
->extra_offset
= offset
;
822 req
->extra_size
= sizeof(retvalue
);
823 if (!wine_server_call_err( req
))
824 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
830 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
831 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
833 SetLastError( ERROR_INVALID_INDEX
);
834 release_class_ptr( class );
839 /***********************************************************************
842 * Implementation of GetClassLong(Ptr)A/W
844 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
848 ULONG_PTR retvalue
= 0;
850 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
852 if (class == CLASS_OTHER_PROCESS
)
854 SERVER_START_REQ( set_class_info
)
856 req
->window
= wine_server_user_handle( hwnd
);
858 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
859 req
->extra_size
= (offset
>= 0) ? size
: 0;
860 if (!wine_server_call_err( req
))
864 case GCLP_HBRBACKGROUND
:
870 FIXME( "offset %d (%s) not supported on other process window %p\n",
871 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
872 SetLastError( ERROR_INVALID_HANDLE
);
875 retvalue
= reply
->old_style
;
878 retvalue
= reply
->old_win_extra
;
881 retvalue
= reply
->old_extra
;
884 retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
887 retvalue
= reply
->old_atom
;
892 if (size
== sizeof(DWORD
))
895 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
899 memcpy( &retvalue
, &reply
->old_extra_value
,
902 else SetLastError( ERROR_INVALID_INDEX
);
913 if (offset
<= class->cbClsExtra
- size
)
915 if (size
== sizeof(DWORD
))
918 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
922 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
925 SetLastError( ERROR_INVALID_INDEX
);
926 release_class_ptr( class );
932 case GCLP_HBRBACKGROUND
:
933 retvalue
= (ULONG_PTR
)class->hbrBackground
;
936 retvalue
= (ULONG_PTR
)class->hCursor
;
939 retvalue
= (ULONG_PTR
)class->hIcon
;
942 retvalue
= (ULONG_PTR
)(class->hIconSm
? class->hIconSm
: class->hIconSmIntern
);
945 retvalue
= class->style
;
948 retvalue
= class->cbWndExtra
;
951 retvalue
= class->cbClsExtra
;
954 retvalue
= (ULONG_PTR
)class->hInstance
;
957 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
960 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
962 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
964 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
967 retvalue
= class->atomName
;
970 SetLastError( ERROR_INVALID_INDEX
);
973 release_class_ptr( class );
978 /***********************************************************************
979 * GetClassLongW (USER32.@)
981 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
983 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
988 /***********************************************************************
989 * GetClassLongA (USER32.@)
991 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
993 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
997 /***********************************************************************
998 * SetClassWord (USER32.@)
1000 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
1005 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
1007 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
1009 SERVER_START_REQ( set_class_info
)
1011 req
->window
= wine_server_user_handle( hwnd
);
1012 req
->flags
= SET_CLASS_EXTRA
;
1013 req
->extra_offset
= offset
;
1014 req
->extra_size
= sizeof(newval
);
1015 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
1016 if (!wine_server_call_err( req
))
1018 void *ptr
= (char *)(class + 1) + offset
;
1019 memcpy( &retval
, ptr
, sizeof(retval
) );
1020 memcpy( ptr
, &newval
, sizeof(newval
) );
1024 release_class_ptr( class );
1029 /***********************************************************************
1030 * CLASS_SetClassLong
1032 * Implementation of SetClassLong(Ptr)A/W
1034 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
1035 UINT size
, BOOL unicode
)
1038 ULONG_PTR retval
= 0;
1040 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
1044 if (set_server_info( hwnd
, offset
, newval
, size
))
1046 void *ptr
= (char *)(class + 1) + offset
;
1047 if ( size
== sizeof(LONG
) )
1050 LONG newlong
= newval
;
1051 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
1052 memcpy( ptr
, &newlong
, sizeof(LONG
) );
1057 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
1058 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
1066 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
1068 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
1069 retval
= 0; /* Old value is now meaningless anyway */
1072 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
1073 class->winproc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
1075 case GCLP_HBRBACKGROUND
:
1076 retval
= (ULONG_PTR
)class->hbrBackground
;
1077 class->hbrBackground
= (HBRUSH
)newval
;
1080 retval
= (ULONG_PTR
)class->hCursor
;
1081 class->hCursor
= (HCURSOR
)newval
;
1084 retval
= (ULONG_PTR
)class->hIcon
;
1085 if (class->hIconSmIntern
)
1087 DestroyIcon(class->hIconSmIntern
);
1088 class->hIconSmIntern
= NULL
;
1090 if (newval
&& !class->hIconSm
)
1091 class->hIconSmIntern
= CopyImage( (HICON
)newval
, IMAGE_ICON
,
1092 GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
),
1093 LR_COPYFROMRESOURCE
);
1094 class->hIcon
= (HICON
)newval
;
1097 retval
= (ULONG_PTR
)class->hIconSm
;
1098 if (retval
&& !newval
&& class->hIcon
)
1099 class->hIconSmIntern
= CopyImage( class->hIcon
, IMAGE_ICON
,
1100 GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
),
1101 LR_COPYFROMRESOURCE
);
1102 else if (newval
&& class->hIconSmIntern
)
1104 DestroyIcon(class->hIconSmIntern
);
1105 class->hIconSmIntern
= NULL
;
1107 class->hIconSm
= (HICON
)newval
;
1110 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1111 retval
= class->style
;
1112 class->style
= newval
;
1114 case GCL_CBWNDEXTRA
:
1115 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1116 retval
= class->cbWndExtra
;
1117 class->cbWndExtra
= newval
;
1120 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1121 retval
= (ULONG_PTR
)class->hInstance
;
1122 class->hInstance
= (HINSTANCE
)newval
;
1125 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1126 retval
= class->atomName
;
1127 class->atomName
= newval
;
1128 GlobalGetAtomNameW( newval
, class->name
, ARRAY_SIZE( class->name
));
1130 case GCL_CBCLSEXTRA
: /* cannot change this one */
1131 SetLastError( ERROR_INVALID_PARAMETER
);
1134 SetLastError( ERROR_INVALID_INDEX
);
1137 release_class_ptr( class );
1142 /***********************************************************************
1143 * SetClassLongW (USER32.@)
1145 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
1147 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
1151 /***********************************************************************
1152 * SetClassLongA (USER32.@)
1154 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
1156 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
1160 /***********************************************************************
1161 * GetClassNameA (USER32.@)
1163 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
1165 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1168 if (count
<= 0) return 0;
1169 if (!GetClassNameW( hwnd
, tmpbuf
, ARRAY_SIZE( tmpbuf
))) return 0;
1170 RtlUnicodeToMultiByteN( buffer
, count
- 1, &len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
1176 /***********************************************************************
1177 * GetClassNameW (USER32.@)
1179 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
1184 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
1186 if (count
<= 0) return 0;
1188 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
1190 if (class == CLASS_OTHER_PROCESS
)
1192 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1194 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
1197 ret
= min(count
- 1, ret
);
1198 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1204 /* Return original name class was registered with. */
1205 lstrcpynW( buffer
, class->basename
, count
);
1206 release_class_ptr( class );
1207 ret
= strlenW( buffer
);
1213 /***********************************************************************
1214 * RealGetWindowClassA (USER32.@)
1216 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1218 return GetClassNameA( hwnd
, buffer
, count
);
1222 /***********************************************************************
1223 * RealGetWindowClassW (USER32.@)
1225 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1227 return GetClassNameW( hwnd
, buffer
, count
);
1231 /***********************************************************************
1232 * GetClassInfoA (USER32.@)
1234 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1237 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1241 wc
->style
= wcex
.style
;
1242 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1243 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1244 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1245 wc
->hInstance
= wcex
.hInstance
;
1246 wc
->hIcon
= wcex
.hIcon
;
1247 wc
->hCursor
= wcex
.hCursor
;
1248 wc
->hbrBackground
= wcex
.hbrBackground
;
1249 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1250 wc
->lpszClassName
= wcex
.lpszClassName
;
1256 /***********************************************************************
1257 * GetClassInfoW (USER32.@)
1259 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1262 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1266 wc
->style
= wcex
.style
;
1267 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1268 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1269 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1270 wc
->hInstance
= wcex
.hInstance
;
1271 wc
->hIcon
= wcex
.hIcon
;
1272 wc
->hCursor
= wcex
.hCursor
;
1273 wc
->hbrBackground
= wcex
.hbrBackground
;
1274 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1275 wc
->lpszClassName
= wcex
.lpszClassName
;
1281 /***********************************************************************
1282 * GetClassInfoExA (USER32.@)
1284 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1289 TRACE("%p %s %p\n", hInstance
, debugstr_a(name
), wc
);
1293 SetLastError( ERROR_NOACCESS
);
1297 if (!hInstance
) hInstance
= user32_module
;
1299 if (!IS_INTRESOURCE(name
))
1301 WCHAR nameW
[MAX_ATOM_LEN
+ 1];
1302 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, ARRAY_SIZE( nameW
)))
1304 classPtr
= CLASS_FindClass( nameW
, hInstance
);
1306 else classPtr
= CLASS_FindClass( (LPCWSTR
)name
, hInstance
);
1310 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1313 wc
->style
= classPtr
->style
;
1314 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1315 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1316 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1317 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1318 wc
->hIcon
= classPtr
->hIcon
;
1319 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1320 wc
->hCursor
= classPtr
->hCursor
;
1321 wc
->hbrBackground
= classPtr
->hbrBackground
;
1322 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1323 wc
->lpszClassName
= name
;
1324 atom
= classPtr
->atomName
;
1325 release_class_ptr( classPtr
);
1327 /* We must return the atom of the class here instead of just TRUE. */
1332 /***********************************************************************
1333 * GetClassInfoExW (USER32.@)
1335 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1340 TRACE("%p %s %p\n", hInstance
, debugstr_w(name
), wc
);
1344 SetLastError( ERROR_NOACCESS
);
1348 if (!hInstance
) hInstance
= user32_module
;
1350 if (!(classPtr
= CLASS_FindClass( name
, hInstance
)))
1352 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1355 wc
->style
= classPtr
->style
;
1356 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1357 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1358 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1359 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1360 wc
->hIcon
= classPtr
->hIcon
;
1361 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1362 wc
->hCursor
= classPtr
->hCursor
;
1363 wc
->hbrBackground
= classPtr
->hbrBackground
;
1364 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1365 wc
->lpszClassName
= name
;
1366 atom
= classPtr
->atomName
;
1367 release_class_ptr( classPtr
);
1369 /* We must return the atom of the class here instead of just TRUE. */
1374 #if 0 /* toolhelp is in kernel, so this cannot work */
1376 /***********************************************************************
1377 * ClassFirst (TOOLHELP.69)
1379 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1381 TRACE("%p\n",pClassEntry
);
1382 pClassEntry
->wNext
= 1;
1383 return ClassNext16( pClassEntry
);
1387 /***********************************************************************
1388 * ClassNext (TOOLHELP.70)
1390 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1393 CLASS
*class = firstClass
;
1395 TRACE("%p\n",pClassEntry
);
1397 if (!pClassEntry
->wNext
) return FALSE
;
1398 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1401 pClassEntry
->wNext
= 0;
1404 pClassEntry
->hInst
= class->hInstance
;
1405 pClassEntry
->wNext
++;
1406 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1407 sizeof(pClassEntry
->szClassName
) );
1412 /* 64bit versions */
1414 #ifdef GetClassLongPtrA
1415 #undef GetClassLongPtrA
1418 #ifdef GetClassLongPtrW
1419 #undef GetClassLongPtrW
1422 #ifdef SetClassLongPtrA
1423 #undef SetClassLongPtrA
1426 #ifdef SetClassLongPtrW
1427 #undef SetClassLongPtrW
1430 /***********************************************************************
1431 * GetClassLongPtrA (USER32.@)
1433 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1435 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1438 /***********************************************************************
1439 * GetClassLongPtrW (USER32.@)
1441 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1443 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1446 /***********************************************************************
1447 * SetClassLongPtrW (USER32.@)
1449 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1451 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1454 /***********************************************************************
1455 * SetClassLongPtrA (USER32.@)
1457 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1459 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);