2 * Window classes functions
4 * Copyright 1993, 1996, 2003 Alexandre Julliard
5 * Copyright 1998 Juergen Schmied (jsch)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
34 #include "wine/unicode.h"
36 #include "user_private.h"
38 #include "wine/server.h"
39 #include "wine/list.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(class);
44 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
46 typedef struct tagCLASS
48 struct list entry
; /* Entry in class list */
49 UINT style
; /* Class style */
50 BOOL local
; /* Local class? */
51 WNDPROC winproc
; /* Window procedure */
52 INT cbClsExtra
; /* Class extra bytes */
53 INT cbWndExtra
; /* Window extra bytes */
54 LPWSTR menuName
; /* Default menu name (Unicode followed by ASCII) */
55 struct dce
*dce
; /* Opaque pointer to class DCE */
56 HINSTANCE hInstance
; /* Module that created the task */
57 HICON hIcon
; /* Default icon */
58 HICON hIconSm
; /* Default small icon */
59 HICON hIconSmIntern
; /* Internal small icon, derived from hIcon */
60 HCURSOR hCursor
; /* Default cursor */
61 HBRUSH hbrBackground
; /* Default background */
62 ATOM atomName
; /* Name of the class */
63 WCHAR name
[MAX_ATOM_LEN
+ 1];
66 static struct list class_list
= LIST_INIT( class_list
);
67 static INIT_ONCE init_once
= INIT_ONCE_STATIC_INIT
;
69 #define CLASS_OTHER_PROCESS ((CLASS *)1)
71 /***********************************************************************
74 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
76 WND
*ptr
= WIN_GetPtr( hwnd
);
80 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
) return ptr
->class;
81 if (!write_access
) return CLASS_OTHER_PROCESS
;
83 /* modifying classes in other processes is not allowed */
84 if (ptr
== WND_DESKTOP
|| IsWindow( hwnd
))
86 SetLastError( ERROR_ACCESS_DENIED
);
90 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
95 /***********************************************************************
98 static inline void release_class_ptr( CLASS
*ptr
)
104 /***********************************************************************
107 ATOM
get_int_atom_value( LPCWSTR name
)
111 if (IS_INTRESOURCE(name
)) return LOWORD(name
);
112 if (*name
++ != '#') return 0;
115 if (*name
< '0' || *name
> '9') return 0;
116 ret
= ret
* 10 + *name
++ - '0';
117 if (ret
> 0xffff) return 0;
123 /***********************************************************************
126 * Set class info with the wine server.
128 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG_PTR newval
, UINT size
)
132 SERVER_START_REQ( set_class_info
)
134 req
->window
= wine_server_user_handle( hwnd
);
135 req
->extra_offset
= -1;
139 req
->flags
= SET_CLASS_ATOM
;
140 req
->atom
= LOWORD(newval
);
143 req
->flags
= SET_CLASS_STYLE
;
147 req
->flags
= SET_CLASS_WINEXTRA
;
148 req
->win_extra
= newval
;
151 req
->flags
= SET_CLASS_INSTANCE
;
152 req
->instance
= wine_server_client_ptr( (void *)newval
);
155 assert( offset
>= 0 );
156 req
->flags
= SET_CLASS_EXTRA
;
157 req
->extra_offset
= offset
;
158 req
->extra_size
= size
;
159 if ( size
== sizeof(LONG
) )
161 LONG newlong
= newval
;
162 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
165 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
168 ret
= !wine_server_call_err( req
);
175 /***********************************************************************
178 * Get the menu name as a ASCII string.
180 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
182 if (IS_INTRESOURCE(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
183 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
187 /***********************************************************************
190 * Get the menu name as a Unicode string.
192 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
194 return classPtr
->menuName
;
198 /***********************************************************************
201 * Set the menu name in a class structure by copying the string.
203 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
205 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
206 if (!IS_INTRESOURCE(name
))
208 DWORD lenA
= strlen(name
) + 1;
209 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
210 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
211 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
212 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
214 else classPtr
->menuName
= (LPWSTR
)name
;
218 /***********************************************************************
221 * Set the menu name in a class structure by copying the string.
223 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
225 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
226 if (!IS_INTRESOURCE(name
))
228 DWORD lenW
= strlenW(name
) + 1;
229 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
230 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
231 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
232 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
233 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
235 else classPtr
->menuName
= (LPWSTR
)name
;
239 /***********************************************************************
242 * Free a class structure.
244 static void CLASS_FreeClass( CLASS
*classPtr
)
246 TRACE("%p\n", classPtr
);
250 if (classPtr
->dce
) free_dce( classPtr
->dce
, 0 );
251 list_remove( &classPtr
->entry
);
252 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
253 DeleteObject( classPtr
->hbrBackground
);
254 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
255 HeapFree( GetProcessHeap(), 0, classPtr
);
260 /***********************************************************************
263 * Return a pointer to the class.
264 * hinstance has been normalized by the caller.
266 static CLASS
*CLASS_FindClass( LPCWSTR name
, HINSTANCE hinstance
)
269 ATOM atom
= get_int_atom_value( name
);
271 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
275 LIST_FOR_EACH( ptr
, &class_list
)
277 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
280 if (class->atomName
!= atom
) continue;
284 if (!name
|| strcmpiW( class->name
, name
)) continue;
286 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
288 TRACE("%s %p -> %p\n", debugstr_w(name
), hinstance
, class);
293 TRACE("%s %p -> not found\n", debugstr_w(name
), hinstance
);
298 /***********************************************************************
299 * CLASS_RegisterClass
301 * The real RegisterClass() functionality.
303 static CLASS
*CLASS_RegisterClass( LPCWSTR name
, HINSTANCE hInstance
, BOOL local
,
304 DWORD style
, INT classExtra
, INT winExtra
)
309 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
310 debugstr_w(name
), hInstance
, style
, classExtra
, winExtra
);
312 /* Fix the extra bytes value */
314 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
315 WARN("Class extra bytes %d is > 40\n", classExtra
);
316 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
317 WARN("Win extra bytes %d is > 40\n", winExtra
);
319 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
320 if (!classPtr
) return NULL
;
322 classPtr
->atomName
= get_int_atom_value( name
);
323 if (!classPtr
->atomName
&& name
) strcpyW( classPtr
->name
, name
);
324 else GlobalGetAtomNameW( classPtr
->atomName
, classPtr
->name
, sizeof(classPtr
->name
)/sizeof(WCHAR
) );
326 SERVER_START_REQ( create_class
)
330 req
->instance
= wine_server_client_ptr( hInstance
);
331 req
->extra
= classExtra
;
332 req
->win_extra
= winExtra
;
333 req
->client_ptr
= wine_server_client_ptr( classPtr
);
334 req
->atom
= classPtr
->atomName
;
335 if (!req
->atom
&& name
) wine_server_add_data( req
, name
, strlenW(name
) * sizeof(WCHAR
) );
336 ret
= !wine_server_call_err( req
);
337 classPtr
->atomName
= reply
->atom
;
342 HeapFree( GetProcessHeap(), 0, classPtr
);
346 classPtr
->style
= style
;
347 classPtr
->local
= local
;
348 classPtr
->cbWndExtra
= winExtra
;
349 classPtr
->cbClsExtra
= classExtra
;
350 classPtr
->hInstance
= hInstance
;
352 /* Other non-null values must be set by caller */
355 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
356 else list_add_tail( &class_list
, &classPtr
->entry
);
361 /***********************************************************************
364 * Register a builtin control class.
365 * This allows having both ASCII and Unicode winprocs for the same class.
367 static void register_builtin( const struct builtin_class_descr
*descr
)
371 if (!(classPtr
= CLASS_RegisterClass( descr
->name
, user32_module
, FALSE
,
372 descr
->style
, 0, descr
->extra
))) return;
374 if (descr
->cursor
) classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
375 classPtr
->hbrBackground
= descr
->brush
;
376 classPtr
->winproc
= BUILTIN_WINPROC( descr
->proc
);
377 release_class_ptr( classPtr
);
381 /***********************************************************************
384 static BOOL WINAPI
register_builtins( INIT_ONCE
*once
, void *param
, void **context
)
386 register_builtin( &BUTTON_builtin_class
);
387 register_builtin( &COMBO_builtin_class
);
388 register_builtin( &COMBOLBOX_builtin_class
);
389 register_builtin( &DIALOG_builtin_class
);
390 register_builtin( &EDIT_builtin_class
);
391 register_builtin( &ICONTITLE_builtin_class
);
392 register_builtin( &LISTBOX_builtin_class
);
393 register_builtin( &MDICLIENT_builtin_class
);
394 register_builtin( &MENU_builtin_class
);
395 register_builtin( &SCROLL_builtin_class
);
396 register_builtin( &STATIC_builtin_class
);
401 /***********************************************************************
402 * register_builtin_classes
404 void register_builtin_classes(void)
406 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
410 /***********************************************************************
411 * register_desktop_class
413 void register_desktop_class(void)
415 register_builtin( &DESKTOP_builtin_class
);
416 register_builtin( &MESSAGE_builtin_class
);
420 /***********************************************************************
423 WNDPROC
get_class_winproc( CLASS
*class )
425 return class->winproc
;
429 /***********************************************************************
432 struct dce
*get_class_dce( CLASS
*class )
438 /***********************************************************************
441 struct dce
*set_class_dce( CLASS
*class, struct dce
*dce
)
443 if (class->dce
) return class->dce
; /* already set, don't change it */
449 /***********************************************************************
450 * RegisterClassA (USER32.@)
452 * Register a window class.
455 * >0: Unique identifier
458 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
462 wcex
.cbSize
= sizeof(wcex
);
463 wcex
.style
= wc
->style
;
464 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
465 wcex
.cbClsExtra
= wc
->cbClsExtra
;
466 wcex
.cbWndExtra
= wc
->cbWndExtra
;
467 wcex
.hInstance
= wc
->hInstance
;
468 wcex
.hIcon
= wc
->hIcon
;
469 wcex
.hCursor
= wc
->hCursor
;
470 wcex
.hbrBackground
= wc
->hbrBackground
;
471 wcex
.lpszMenuName
= wc
->lpszMenuName
;
472 wcex
.lpszClassName
= wc
->lpszClassName
;
474 return RegisterClassExA( &wcex
);
478 /***********************************************************************
479 * RegisterClassW (USER32.@)
481 * See RegisterClassA.
483 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
487 wcex
.cbSize
= sizeof(wcex
);
488 wcex
.style
= wc
->style
;
489 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
490 wcex
.cbClsExtra
= wc
->cbClsExtra
;
491 wcex
.cbWndExtra
= wc
->cbWndExtra
;
492 wcex
.hInstance
= wc
->hInstance
;
493 wcex
.hIcon
= wc
->hIcon
;
494 wcex
.hCursor
= wc
->hCursor
;
495 wcex
.hbrBackground
= wc
->hbrBackground
;
496 wcex
.lpszMenuName
= wc
->lpszMenuName
;
497 wcex
.lpszClassName
= wc
->lpszClassName
;
499 return RegisterClassExW( &wcex
);
503 /***********************************************************************
504 * RegisterClassExA (USER32.@)
506 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
512 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
514 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
515 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
517 SetLastError( ERROR_INVALID_PARAMETER
);
520 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
522 if (!IS_INTRESOURCE(wc
->lpszClassName
))
524 WCHAR name
[MAX_ATOM_LEN
+ 1];
526 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
527 classPtr
= CLASS_RegisterClass( name
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
528 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
532 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, instance
,
533 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
534 wc
->cbClsExtra
, wc
->cbWndExtra
);
536 if (!classPtr
) return 0;
537 atom
= classPtr
->atomName
;
539 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
540 debugstr_a(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
541 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
543 classPtr
->hIcon
= wc
->hIcon
;
544 classPtr
->hIconSm
= wc
->hIconSm
;
545 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
546 CopyImage( wc
->hIcon
, IMAGE_ICON
,
547 GetSystemMetrics( SM_CXSMICON
),
548 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
549 classPtr
->hCursor
= wc
->hCursor
;
550 classPtr
->hbrBackground
= wc
->hbrBackground
;
551 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, FALSE
);
552 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
553 release_class_ptr( classPtr
);
558 /***********************************************************************
559 * RegisterClassExW (USER32.@)
561 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
567 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
569 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
570 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
572 SetLastError( ERROR_INVALID_PARAMETER
);
575 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
577 if (!(classPtr
= CLASS_RegisterClass( wc
->lpszClassName
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
578 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
581 atom
= classPtr
->atomName
;
583 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
584 debugstr_w(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
585 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
587 classPtr
->hIcon
= wc
->hIcon
;
588 classPtr
->hIconSm
= wc
->hIconSm
;
589 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
590 CopyImage( wc
->hIcon
, IMAGE_ICON
,
591 GetSystemMetrics( SM_CXSMICON
),
592 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
593 classPtr
->hCursor
= wc
->hCursor
;
594 classPtr
->hbrBackground
= wc
->hbrBackground
;
595 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, TRUE
);
596 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
597 release_class_ptr( classPtr
);
602 /***********************************************************************
603 * UnregisterClassA (USER32.@)
605 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
607 if (!IS_INTRESOURCE(className
))
609 WCHAR name
[MAX_ATOM_LEN
+ 1];
611 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
613 return UnregisterClassW( name
, hInstance
);
615 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
618 /***********************************************************************
619 * UnregisterClassW (USER32.@)
621 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
623 CLASS
*classPtr
= NULL
;
625 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
627 SERVER_START_REQ( destroy_class
)
629 req
->instance
= wine_server_client_ptr( hInstance
);
630 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
631 wine_server_add_data( req
, className
, strlenW(className
) * sizeof(WCHAR
) );
632 if (!wine_server_call_err( req
)) classPtr
= wine_server_get_ptr( reply
->client_ptr
);
636 if (classPtr
) CLASS_FreeClass( classPtr
);
637 return (classPtr
!= NULL
);
641 /***********************************************************************
642 * GetClassWord (USER32.@)
644 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
649 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
651 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
653 if (class == CLASS_OTHER_PROCESS
)
655 SERVER_START_REQ( set_class_info
)
657 req
->window
= wine_server_user_handle( hwnd
);
659 req
->extra_offset
= offset
;
660 req
->extra_size
= sizeof(retvalue
);
661 if (!wine_server_call_err( req
))
662 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
668 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
669 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
671 SetLastError( ERROR_INVALID_INDEX
);
672 release_class_ptr( class );
677 /***********************************************************************
680 * Implementation of GetClassLong(Ptr)A/W
682 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
686 ULONG_PTR retvalue
= 0;
688 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
690 if (class == CLASS_OTHER_PROCESS
)
692 SERVER_START_REQ( set_class_info
)
694 req
->window
= wine_server_user_handle( hwnd
);
696 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
697 req
->extra_size
= (offset
>= 0) ? size
: 0;
698 if (!wine_server_call_err( req
))
702 case GCLP_HBRBACKGROUND
:
708 FIXME( "offset %d (%s) not supported on other process window %p\n",
709 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
710 SetLastError( ERROR_INVALID_HANDLE
);
713 retvalue
= reply
->old_style
;
716 retvalue
= reply
->old_win_extra
;
719 retvalue
= reply
->old_extra
;
722 retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
725 retvalue
= reply
->old_atom
;
730 if (size
== sizeof(DWORD
))
733 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
737 memcpy( &retvalue
, &reply
->old_extra_value
,
740 else SetLastError( ERROR_INVALID_INDEX
);
751 if (offset
<= class->cbClsExtra
- size
)
753 if (size
== sizeof(DWORD
))
756 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
760 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
763 SetLastError( ERROR_INVALID_INDEX
);
764 release_class_ptr( class );
770 case GCLP_HBRBACKGROUND
:
771 retvalue
= (ULONG_PTR
)class->hbrBackground
;
774 retvalue
= (ULONG_PTR
)class->hCursor
;
777 retvalue
= (ULONG_PTR
)class->hIcon
;
780 retvalue
= (ULONG_PTR
)(class->hIconSm
? class->hIconSm
: class->hIconSmIntern
);
783 retvalue
= class->style
;
786 retvalue
= class->cbWndExtra
;
789 retvalue
= class->cbClsExtra
;
792 retvalue
= (ULONG_PTR
)class->hInstance
;
795 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
798 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
800 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
802 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
805 retvalue
= class->atomName
;
808 SetLastError( ERROR_INVALID_INDEX
);
811 release_class_ptr( class );
816 /***********************************************************************
817 * GetClassLongW (USER32.@)
819 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
821 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
826 /***********************************************************************
827 * GetClassLongA (USER32.@)
829 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
831 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
835 /***********************************************************************
836 * SetClassWord (USER32.@)
838 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
843 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
845 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
847 SERVER_START_REQ( set_class_info
)
849 req
->window
= wine_server_user_handle( hwnd
);
850 req
->flags
= SET_CLASS_EXTRA
;
851 req
->extra_offset
= offset
;
852 req
->extra_size
= sizeof(newval
);
853 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
854 if (!wine_server_call_err( req
))
856 void *ptr
= (char *)(class + 1) + offset
;
857 memcpy( &retval
, ptr
, sizeof(retval
) );
858 memcpy( ptr
, &newval
, sizeof(newval
) );
862 release_class_ptr( class );
867 /***********************************************************************
870 * Implementation of SetClassLong(Ptr)A/W
872 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
873 UINT size
, BOOL unicode
)
876 ULONG_PTR retval
= 0;
878 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
882 if (set_server_info( hwnd
, offset
, newval
, size
))
884 void *ptr
= (char *)(class + 1) + offset
;
885 if ( size
== sizeof(LONG
) )
888 LONG newlong
= newval
;
889 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
890 memcpy( ptr
, &newlong
, sizeof(LONG
) );
895 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
896 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
904 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
906 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
907 retval
= 0; /* Old value is now meaningless anyway */
910 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
911 class->winproc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
913 case GCLP_HBRBACKGROUND
:
914 retval
= (ULONG_PTR
)class->hbrBackground
;
915 class->hbrBackground
= (HBRUSH
)newval
;
918 retval
= (ULONG_PTR
)class->hCursor
;
919 class->hCursor
= (HCURSOR
)newval
;
922 retval
= (ULONG_PTR
)class->hIcon
;
923 if (retval
&& class->hIconSmIntern
)
925 DestroyIcon(class->hIconSmIntern
);
926 class->hIconSmIntern
= NULL
;
928 if (newval
&& !class->hIconSm
)
929 class->hIconSmIntern
= CopyImage( (HICON
)newval
, IMAGE_ICON
,
930 GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
), 0 );
931 class->hIcon
= (HICON
)newval
;
934 retval
= (ULONG_PTR
)class->hIconSm
;
935 if (retval
&& !newval
)
936 class->hIconSmIntern
= class->hIcon
? CopyImage( class->hIcon
, IMAGE_ICON
,
937 GetSystemMetrics( SM_CXSMICON
),
938 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
939 else if (!retval
&& newval
&& class->hIconSmIntern
)
941 DestroyIcon(class->hIconSmIntern
);
942 class->hIconSmIntern
= NULL
;
944 class->hIconSm
= (HICON
)newval
;
947 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
948 retval
= class->style
;
949 class->style
= newval
;
952 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
953 retval
= class->cbWndExtra
;
954 class->cbWndExtra
= newval
;
957 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
958 retval
= (ULONG_PTR
)class->hInstance
;
959 class->hInstance
= (HINSTANCE
)newval
;
962 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
963 retval
= class->atomName
;
964 class->atomName
= newval
;
965 GlobalGetAtomNameW( newval
, class->name
, sizeof(class->name
)/sizeof(WCHAR
) );
967 case GCL_CBCLSEXTRA
: /* cannot change this one */
968 SetLastError( ERROR_INVALID_PARAMETER
);
971 SetLastError( ERROR_INVALID_INDEX
);
974 release_class_ptr( class );
979 /***********************************************************************
980 * SetClassLongW (USER32.@)
982 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
984 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
988 /***********************************************************************
989 * SetClassLongA (USER32.@)
991 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
993 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
997 /***********************************************************************
998 * GetClassNameA (USER32.@)
1000 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
1002 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1005 if (count
<= 0) return 0;
1006 if (!GetClassNameW( hwnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
1007 RtlUnicodeToMultiByteN( buffer
, count
- 1, &len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
1013 /***********************************************************************
1014 * GetClassNameW (USER32.@)
1016 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
1021 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
1023 if (count
<= 0) return 0;
1025 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
1027 if (class == CLASS_OTHER_PROCESS
)
1029 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1031 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
1034 ret
= min(count
- 1, ret
);
1035 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1041 lstrcpynW( buffer
, class->name
, count
);
1042 release_class_ptr( class );
1043 ret
= strlenW( buffer
);
1049 /***********************************************************************
1050 * RealGetWindowClassA (USER32.@)
1052 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1054 return GetClassNameA( hwnd
, buffer
, count
);
1058 /***********************************************************************
1059 * RealGetWindowClassW (USER32.@)
1061 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1063 return GetClassNameW( hwnd
, buffer
, count
);
1067 /***********************************************************************
1068 * GetClassInfoA (USER32.@)
1070 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1073 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1077 wc
->style
= wcex
.style
;
1078 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1079 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1080 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1081 wc
->hInstance
= wcex
.hInstance
;
1082 wc
->hIcon
= wcex
.hIcon
;
1083 wc
->hCursor
= wcex
.hCursor
;
1084 wc
->hbrBackground
= wcex
.hbrBackground
;
1085 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1086 wc
->lpszClassName
= wcex
.lpszClassName
;
1092 /***********************************************************************
1093 * GetClassInfoW (USER32.@)
1095 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1098 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1102 wc
->style
= wcex
.style
;
1103 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1104 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1105 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1106 wc
->hInstance
= wcex
.hInstance
;
1107 wc
->hIcon
= wcex
.hIcon
;
1108 wc
->hCursor
= wcex
.hCursor
;
1109 wc
->hbrBackground
= wcex
.hbrBackground
;
1110 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1111 wc
->lpszClassName
= wcex
.lpszClassName
;
1117 /***********************************************************************
1118 * GetClassInfoExA (USER32.@)
1120 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1125 TRACE("%p %s %p\n", hInstance
, debugstr_a(name
), wc
);
1129 SetLastError( ERROR_NOACCESS
);
1133 if (!hInstance
) hInstance
= user32_module
;
1135 if (!IS_INTRESOURCE(name
))
1137 WCHAR nameW
[MAX_ATOM_LEN
+ 1];
1138 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, sizeof(nameW
)/sizeof(WCHAR
) ))
1140 classPtr
= CLASS_FindClass( nameW
, hInstance
);
1142 else classPtr
= CLASS_FindClass( (LPCWSTR
)name
, hInstance
);
1146 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1149 wc
->style
= classPtr
->style
;
1150 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1151 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1152 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1153 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1154 wc
->hIcon
= classPtr
->hIcon
;
1155 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1156 wc
->hCursor
= classPtr
->hCursor
;
1157 wc
->hbrBackground
= classPtr
->hbrBackground
;
1158 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1159 wc
->lpszClassName
= name
;
1160 atom
= classPtr
->atomName
;
1161 release_class_ptr( classPtr
);
1163 /* We must return the atom of the class here instead of just TRUE. */
1168 /***********************************************************************
1169 * GetClassInfoExW (USER32.@)
1171 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1176 TRACE("%p %s %p\n", hInstance
, debugstr_w(name
), wc
);
1180 SetLastError( ERROR_NOACCESS
);
1184 if (!hInstance
) hInstance
= user32_module
;
1186 if (!(classPtr
= CLASS_FindClass( name
, hInstance
)))
1188 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1191 wc
->style
= classPtr
->style
;
1192 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1193 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1194 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1195 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1196 wc
->hIcon
= classPtr
->hIcon
;
1197 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1198 wc
->hCursor
= classPtr
->hCursor
;
1199 wc
->hbrBackground
= classPtr
->hbrBackground
;
1200 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1201 wc
->lpszClassName
= name
;
1202 atom
= classPtr
->atomName
;
1203 release_class_ptr( classPtr
);
1205 /* We must return the atom of the class here instead of just TRUE. */
1210 #if 0 /* toolhelp is in kernel, so this cannot work */
1212 /***********************************************************************
1213 * ClassFirst (TOOLHELP.69)
1215 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1217 TRACE("%p\n",pClassEntry
);
1218 pClassEntry
->wNext
= 1;
1219 return ClassNext16( pClassEntry
);
1223 /***********************************************************************
1224 * ClassNext (TOOLHELP.70)
1226 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1229 CLASS
*class = firstClass
;
1231 TRACE("%p\n",pClassEntry
);
1233 if (!pClassEntry
->wNext
) return FALSE
;
1234 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1237 pClassEntry
->wNext
= 0;
1240 pClassEntry
->hInst
= class->hInstance
;
1241 pClassEntry
->wNext
++;
1242 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1243 sizeof(pClassEntry
->szClassName
) );
1248 /* 64bit versions */
1250 #ifdef GetClassLongPtrA
1251 #undef GetClassLongPtrA
1254 #ifdef GetClassLongPtrW
1255 #undef GetClassLongPtrW
1258 #ifdef SetClassLongPtrA
1259 #undef SetClassLongPtrA
1262 #ifdef SetClassLongPtrW
1263 #undef SetClassLongPtrW
1266 /***********************************************************************
1267 * GetClassLongPtrA (USER32.@)
1269 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1271 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1274 /***********************************************************************
1275 * GetClassLongPtrW (USER32.@)
1277 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1279 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1282 /***********************************************************************
1283 * SetClassLongPtrW (USER32.@)
1285 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1287 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1290 /***********************************************************************
1291 * SetClassLongPtrA (USER32.@)
1293 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1295 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);