2 * Window classes functions
4 * Copyright 1993, 1996, 2003 Alexandre Julliard
5 * Copyright 1998 Juergen Schmied (jsch)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
34 #include "wine/unicode.h"
36 #include "user_private.h"
38 #include "wine/server.h"
39 #include "wine/list.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(class);
44 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
46 typedef struct tagCLASS
48 struct list entry
; /* Entry in class list */
49 UINT style
; /* Class style */
50 BOOL local
; /* Local class? */
51 WNDPROC winproc
; /* Window procedure */
52 INT cbClsExtra
; /* Class extra bytes */
53 INT cbWndExtra
; /* Window extra bytes */
54 LPWSTR menuName
; /* Default menu name (Unicode followed by ASCII) */
55 struct dce
*dce
; /* Opaque pointer to class DCE */
56 HINSTANCE hInstance
; /* Module that created the task */
57 HICON hIcon
; /* Default icon */
58 HICON hIconSm
; /* Default small icon */
59 HICON hIconSmIntern
; /* Internal small icon, derived from hIcon */
60 HCURSOR hCursor
; /* Default cursor */
61 HBRUSH hbrBackground
; /* Default background */
62 ATOM atomName
; /* Name of the class */
63 WCHAR name
[MAX_ATOM_LEN
+ 1];
66 static struct list class_list
= LIST_INIT( class_list
);
67 static INIT_ONCE init_once
= INIT_ONCE_STATIC_INIT
;
69 #define CLASS_OTHER_PROCESS ((CLASS *)1)
71 /***********************************************************************
74 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
76 WND
*ptr
= WIN_GetPtr( hwnd
);
80 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
) return ptr
->class;
81 if (!write_access
) return CLASS_OTHER_PROCESS
;
83 /* modifying classes in other processes is not allowed */
84 if (ptr
== WND_DESKTOP
|| IsWindow( hwnd
))
86 SetLastError( ERROR_ACCESS_DENIED
);
90 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
95 /***********************************************************************
98 static inline void release_class_ptr( CLASS
*ptr
)
104 /***********************************************************************
107 ATOM
get_int_atom_value( LPCWSTR name
)
111 if (IS_INTRESOURCE(name
)) return LOWORD(name
);
112 if (*name
++ != '#') return 0;
115 if (*name
< '0' || *name
> '9') return 0;
116 ret
= ret
* 10 + *name
++ - '0';
117 if (ret
> 0xffff) return 0;
123 /***********************************************************************
126 * Set class info with the wine server.
128 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG_PTR newval
, UINT size
)
132 SERVER_START_REQ( set_class_info
)
134 req
->window
= wine_server_user_handle( hwnd
);
135 req
->extra_offset
= -1;
139 req
->flags
= SET_CLASS_ATOM
;
140 req
->atom
= LOWORD(newval
);
143 req
->flags
= SET_CLASS_STYLE
;
147 req
->flags
= SET_CLASS_WINEXTRA
;
148 req
->win_extra
= newval
;
151 req
->flags
= SET_CLASS_INSTANCE
;
152 req
->instance
= wine_server_client_ptr( (void *)newval
);
155 assert( offset
>= 0 );
156 req
->flags
= SET_CLASS_EXTRA
;
157 req
->extra_offset
= offset
;
158 req
->extra_size
= size
;
159 if ( size
== sizeof(LONG
) )
161 LONG newlong
= newval
;
162 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
165 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
168 ret
= !wine_server_call_err( req
);
175 /***********************************************************************
178 * Get the menu name as a ASCII string.
180 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
182 if (IS_INTRESOURCE(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
183 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
187 /***********************************************************************
190 * Get the menu name as a Unicode string.
192 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
194 return classPtr
->menuName
;
198 /***********************************************************************
201 * Set the menu name in a class structure by copying the string.
203 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
205 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
206 if (!IS_INTRESOURCE(name
))
208 DWORD lenA
= strlen(name
) + 1;
209 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
210 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
211 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
212 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
214 else classPtr
->menuName
= (LPWSTR
)name
;
218 /***********************************************************************
221 * Set the menu name in a class structure by copying the string.
223 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
225 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
226 if (!IS_INTRESOURCE(name
))
228 DWORD lenW
= strlenW(name
) + 1;
229 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
230 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
231 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
232 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
233 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
235 else classPtr
->menuName
= (LPWSTR
)name
;
239 /***********************************************************************
242 * Free a class structure.
244 static void CLASS_FreeClass( CLASS
*classPtr
)
246 TRACE("%p\n", classPtr
);
250 if (classPtr
->dce
) free_dce( classPtr
->dce
, 0 );
251 list_remove( &classPtr
->entry
);
252 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
253 DeleteObject( classPtr
->hbrBackground
);
254 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
255 HeapFree( GetProcessHeap(), 0, classPtr
);
260 /***********************************************************************
263 * Return a pointer to the class.
264 * hinstance has been normalized by the caller.
266 static CLASS
*CLASS_FindClass( LPCWSTR name
, HINSTANCE hinstance
)
269 ATOM atom
= get_int_atom_value( name
);
273 LIST_FOR_EACH( ptr
, &class_list
)
275 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
278 if (class->atomName
!= atom
) continue;
282 if (!name
|| strcmpiW( class->name
, name
)) continue;
284 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
286 TRACE("%s %p -> %p\n", debugstr_w(name
), hinstance
, class);
291 TRACE("%s %p -> not found\n", debugstr_w(name
), hinstance
);
296 /***********************************************************************
297 * CLASS_RegisterClass
299 * The real RegisterClass() functionality.
301 static CLASS
*CLASS_RegisterClass( LPCWSTR name
, HINSTANCE hInstance
, BOOL local
,
302 DWORD style
, INT classExtra
, INT winExtra
)
307 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
308 debugstr_w(name
), hInstance
, style
, classExtra
, winExtra
);
310 /* Fix the extra bytes value */
312 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
313 WARN("Class extra bytes %d is > 40\n", classExtra
);
314 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
315 WARN("Win extra bytes %d is > 40\n", winExtra
);
317 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
318 if (!classPtr
) return NULL
;
320 classPtr
->atomName
= get_int_atom_value( name
);
321 if (!classPtr
->atomName
&& name
) strcpyW( classPtr
->name
, name
);
322 else GlobalGetAtomNameW( classPtr
->atomName
, classPtr
->name
, sizeof(classPtr
->name
)/sizeof(WCHAR
) );
324 SERVER_START_REQ( create_class
)
328 req
->instance
= wine_server_client_ptr( hInstance
);
329 req
->extra
= classExtra
;
330 req
->win_extra
= winExtra
;
331 req
->client_ptr
= wine_server_client_ptr( classPtr
);
332 req
->atom
= classPtr
->atomName
;
333 if (!req
->atom
&& name
) wine_server_add_data( req
, name
, strlenW(name
) * sizeof(WCHAR
) );
334 ret
= !wine_server_call_err( req
);
335 classPtr
->atomName
= reply
->atom
;
340 HeapFree( GetProcessHeap(), 0, classPtr
);
344 classPtr
->style
= style
;
345 classPtr
->local
= local
;
346 classPtr
->cbWndExtra
= winExtra
;
347 classPtr
->cbClsExtra
= classExtra
;
348 classPtr
->hInstance
= hInstance
;
350 /* Other non-null values must be set by caller */
353 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
354 else list_add_tail( &class_list
, &classPtr
->entry
);
359 /***********************************************************************
362 * Register a builtin control class.
363 * This allows having both ASCII and Unicode winprocs for the same class.
365 static void register_builtin( const struct builtin_class_descr
*descr
)
369 if (!(classPtr
= CLASS_RegisterClass( descr
->name
, user32_module
, FALSE
,
370 descr
->style
, 0, descr
->extra
))) return;
372 classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
373 classPtr
->hbrBackground
= descr
->brush
;
374 classPtr
->winproc
= BUILTIN_WINPROC( descr
->proc
);
375 release_class_ptr( classPtr
);
379 /***********************************************************************
382 static BOOL WINAPI
register_builtins( INIT_ONCE
*once
, void *param
, void **context
)
384 register_builtin( &DESKTOP_builtin_class
);
385 register_builtin( &BUTTON_builtin_class
);
386 register_builtin( &COMBO_builtin_class
);
387 register_builtin( &COMBOLBOX_builtin_class
);
388 register_builtin( &DIALOG_builtin_class
);
389 register_builtin( &EDIT_builtin_class
);
390 register_builtin( &ICONTITLE_builtin_class
);
391 register_builtin( &LISTBOX_builtin_class
);
392 register_builtin( &MDICLIENT_builtin_class
);
393 register_builtin( &MENU_builtin_class
);
394 register_builtin( &MESSAGE_builtin_class
);
395 register_builtin( &SCROLL_builtin_class
);
396 register_builtin( &STATIC_builtin_class
);
401 /***********************************************************************
402 * CLASS_RegisterBuiltinClasses
404 void CLASS_RegisterBuiltinClasses(void)
406 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
410 /***********************************************************************
413 WNDPROC
get_class_winproc( CLASS
*class )
415 return class->winproc
;
419 /***********************************************************************
422 struct dce
*get_class_dce( CLASS
*class )
428 /***********************************************************************
431 struct dce
*set_class_dce( CLASS
*class, struct dce
*dce
)
433 if (class->dce
) return class->dce
; /* already set, don't change it */
439 /***********************************************************************
440 * RegisterClassA (USER32.@)
442 * Register a window class.
445 * >0: Unique identifier
448 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
452 wcex
.cbSize
= sizeof(wcex
);
453 wcex
.style
= wc
->style
;
454 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
455 wcex
.cbClsExtra
= wc
->cbClsExtra
;
456 wcex
.cbWndExtra
= wc
->cbWndExtra
;
457 wcex
.hInstance
= wc
->hInstance
;
458 wcex
.hIcon
= wc
->hIcon
;
459 wcex
.hCursor
= wc
->hCursor
;
460 wcex
.hbrBackground
= wc
->hbrBackground
;
461 wcex
.lpszMenuName
= wc
->lpszMenuName
;
462 wcex
.lpszClassName
= wc
->lpszClassName
;
464 return RegisterClassExA( &wcex
);
468 /***********************************************************************
469 * RegisterClassW (USER32.@)
471 * See RegisterClassA.
473 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
477 wcex
.cbSize
= sizeof(wcex
);
478 wcex
.style
= wc
->style
;
479 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
480 wcex
.cbClsExtra
= wc
->cbClsExtra
;
481 wcex
.cbWndExtra
= wc
->cbWndExtra
;
482 wcex
.hInstance
= wc
->hInstance
;
483 wcex
.hIcon
= wc
->hIcon
;
484 wcex
.hCursor
= wc
->hCursor
;
485 wcex
.hbrBackground
= wc
->hbrBackground
;
486 wcex
.lpszMenuName
= wc
->lpszMenuName
;
487 wcex
.lpszClassName
= wc
->lpszClassName
;
489 return RegisterClassExW( &wcex
);
493 /***********************************************************************
494 * RegisterClassExA (USER32.@)
496 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
502 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
504 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
505 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
507 SetLastError( ERROR_INVALID_PARAMETER
);
510 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
512 if (!IS_INTRESOURCE(wc
->lpszClassName
))
514 WCHAR name
[MAX_ATOM_LEN
+ 1];
516 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
517 classPtr
= CLASS_RegisterClass( name
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
518 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
522 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, instance
,
523 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
524 wc
->cbClsExtra
, wc
->cbWndExtra
);
526 if (!classPtr
) return 0;
527 atom
= classPtr
->atomName
;
529 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
530 debugstr_a(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
531 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
533 classPtr
->hIcon
= wc
->hIcon
;
534 classPtr
->hIconSm
= wc
->hIconSm
;
535 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
536 CopyImage( wc
->hIcon
, IMAGE_ICON
,
537 GetSystemMetrics( SM_CXSMICON
),
538 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
539 classPtr
->hCursor
= wc
->hCursor
;
540 classPtr
->hbrBackground
= wc
->hbrBackground
;
541 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, FALSE
);
542 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
543 release_class_ptr( classPtr
);
548 /***********************************************************************
549 * RegisterClassExW (USER32.@)
551 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
557 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
559 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
560 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
562 SetLastError( ERROR_INVALID_PARAMETER
);
565 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
567 if (!(classPtr
= CLASS_RegisterClass( wc
->lpszClassName
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
568 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
571 atom
= classPtr
->atomName
;
573 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
574 debugstr_w(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
575 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
577 classPtr
->hIcon
= wc
->hIcon
;
578 classPtr
->hIconSm
= wc
->hIconSm
;
579 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
580 CopyImage( wc
->hIcon
, IMAGE_ICON
,
581 GetSystemMetrics( SM_CXSMICON
),
582 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
583 classPtr
->hCursor
= wc
->hCursor
;
584 classPtr
->hbrBackground
= wc
->hbrBackground
;
585 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, TRUE
);
586 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
587 release_class_ptr( classPtr
);
592 /***********************************************************************
593 * UnregisterClassA (USER32.@)
595 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
597 if (!IS_INTRESOURCE(className
))
599 WCHAR name
[MAX_ATOM_LEN
+ 1];
601 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
603 return UnregisterClassW( name
, hInstance
);
605 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
608 /***********************************************************************
609 * UnregisterClassW (USER32.@)
611 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
613 CLASS
*classPtr
= NULL
;
615 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
617 SERVER_START_REQ( destroy_class
)
619 req
->instance
= wine_server_client_ptr( hInstance
);
620 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
621 wine_server_add_data( req
, className
, strlenW(className
) * sizeof(WCHAR
) );
622 if (!wine_server_call_err( req
)) classPtr
= wine_server_get_ptr( reply
->client_ptr
);
626 if (classPtr
) CLASS_FreeClass( classPtr
);
627 return (classPtr
!= NULL
);
631 /***********************************************************************
632 * GetClassWord (USER32.@)
634 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
639 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
641 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
643 if (class == CLASS_OTHER_PROCESS
)
645 SERVER_START_REQ( set_class_info
)
647 req
->window
= wine_server_user_handle( hwnd
);
649 req
->extra_offset
= offset
;
650 req
->extra_size
= sizeof(retvalue
);
651 if (!wine_server_call_err( req
))
652 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
658 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
659 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
661 SetLastError( ERROR_INVALID_INDEX
);
662 release_class_ptr( class );
667 /***********************************************************************
670 * Implementation of GetClassLong(Ptr)A/W
672 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
676 ULONG_PTR retvalue
= 0;
678 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
680 if (class == CLASS_OTHER_PROCESS
)
682 SERVER_START_REQ( set_class_info
)
684 req
->window
= wine_server_user_handle( hwnd
);
686 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
687 req
->extra_size
= (offset
>= 0) ? size
: 0;
688 if (!wine_server_call_err( req
))
692 case GCLP_HBRBACKGROUND
:
698 FIXME( "offset %d (%s) not supported on other process window %p\n",
699 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
700 SetLastError( ERROR_INVALID_HANDLE
);
703 retvalue
= reply
->old_style
;
706 retvalue
= reply
->old_win_extra
;
709 retvalue
= reply
->old_extra
;
712 retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
715 retvalue
= reply
->old_atom
;
720 if (size
== sizeof(DWORD
))
723 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
727 memcpy( &retvalue
, &reply
->old_extra_value
,
730 else SetLastError( ERROR_INVALID_INDEX
);
741 if (offset
<= class->cbClsExtra
- size
)
743 if (size
== sizeof(DWORD
))
746 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
750 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
753 SetLastError( ERROR_INVALID_INDEX
);
754 release_class_ptr( class );
760 case GCLP_HBRBACKGROUND
:
761 retvalue
= (ULONG_PTR
)class->hbrBackground
;
764 retvalue
= (ULONG_PTR
)class->hCursor
;
767 retvalue
= (ULONG_PTR
)class->hIcon
;
770 retvalue
= (ULONG_PTR
)(class->hIconSm
? class->hIconSm
: class->hIconSmIntern
);
773 retvalue
= class->style
;
776 retvalue
= class->cbWndExtra
;
779 retvalue
= class->cbClsExtra
;
782 retvalue
= (ULONG_PTR
)class->hInstance
;
785 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
788 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
790 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
792 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
795 retvalue
= class->atomName
;
798 SetLastError( ERROR_INVALID_INDEX
);
801 release_class_ptr( class );
806 /***********************************************************************
807 * GetClassLongW (USER32.@)
809 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
811 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
816 /***********************************************************************
817 * GetClassLongA (USER32.@)
819 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
821 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
825 /***********************************************************************
826 * SetClassWord (USER32.@)
828 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
833 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
835 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
837 SERVER_START_REQ( set_class_info
)
839 req
->window
= wine_server_user_handle( hwnd
);
840 req
->flags
= SET_CLASS_EXTRA
;
841 req
->extra_offset
= offset
;
842 req
->extra_size
= sizeof(newval
);
843 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
844 if (!wine_server_call_err( req
))
846 void *ptr
= (char *)(class + 1) + offset
;
847 memcpy( &retval
, ptr
, sizeof(retval
) );
848 memcpy( ptr
, &newval
, sizeof(newval
) );
852 release_class_ptr( class );
857 /***********************************************************************
860 * Implementation of SetClassLong(Ptr)A/W
862 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
863 UINT size
, BOOL unicode
)
866 ULONG_PTR retval
= 0;
868 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
872 if (set_server_info( hwnd
, offset
, newval
, size
))
874 void *ptr
= (char *)(class + 1) + offset
;
875 if ( size
== sizeof(LONG
) )
878 LONG newlong
= newval
;
879 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
880 memcpy( ptr
, &newlong
, sizeof(LONG
) );
885 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
886 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
894 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
896 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
897 retval
= 0; /* Old value is now meaningless anyway */
900 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
901 class->winproc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
903 case GCLP_HBRBACKGROUND
:
904 retval
= (ULONG_PTR
)class->hbrBackground
;
905 class->hbrBackground
= (HBRUSH
)newval
;
908 retval
= (ULONG_PTR
)class->hCursor
;
909 class->hCursor
= (HCURSOR
)newval
;
912 retval
= (ULONG_PTR
)class->hIcon
;
913 if (retval
&& class->hIconSmIntern
)
915 DestroyIcon(class->hIconSmIntern
);
916 class->hIconSmIntern
= NULL
;
918 if (newval
&& !class->hIconSm
)
919 class->hIconSmIntern
= CopyImage( (HICON
)newval
, IMAGE_ICON
,
920 GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
), 0 );
921 class->hIcon
= (HICON
)newval
;
924 retval
= (ULONG_PTR
)class->hIconSm
;
925 if (retval
&& !newval
)
926 class->hIconSmIntern
= class->hIcon
? CopyImage( class->hIcon
, IMAGE_ICON
,
927 GetSystemMetrics( SM_CXSMICON
),
928 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
929 else if (!retval
&& newval
&& class->hIconSmIntern
)
931 DestroyIcon(class->hIconSmIntern
);
932 class->hIconSmIntern
= NULL
;
934 class->hIconSm
= (HICON
)newval
;
937 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
938 retval
= class->style
;
939 class->style
= newval
;
942 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
943 retval
= class->cbWndExtra
;
944 class->cbWndExtra
= newval
;
947 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
948 retval
= (ULONG_PTR
)class->hInstance
;
949 class->hInstance
= (HINSTANCE
)newval
;
952 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
953 retval
= class->atomName
;
954 class->atomName
= newval
;
955 GlobalGetAtomNameW( newval
, class->name
, sizeof(class->name
)/sizeof(WCHAR
) );
957 case GCL_CBCLSEXTRA
: /* cannot change this one */
958 SetLastError( ERROR_INVALID_PARAMETER
);
961 SetLastError( ERROR_INVALID_INDEX
);
964 release_class_ptr( class );
969 /***********************************************************************
970 * SetClassLongW (USER32.@)
972 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
974 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
978 /***********************************************************************
979 * SetClassLongA (USER32.@)
981 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
983 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
987 /***********************************************************************
988 * GetClassNameA (USER32.@)
990 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
992 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
995 if (count
<= 0) return 0;
996 if (!GetClassNameW( hwnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
997 RtlUnicodeToMultiByteN( buffer
, count
- 1, &len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
1003 /***********************************************************************
1004 * GetClassNameW (USER32.@)
1006 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
1011 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
1013 if (count
<= 0) return 0;
1015 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
1017 if (class == CLASS_OTHER_PROCESS
)
1019 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1021 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
1024 ret
= min(count
- 1, ret
);
1025 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1031 lstrcpynW( buffer
, class->name
, count
);
1032 release_class_ptr( class );
1033 ret
= strlenW( buffer
);
1039 /***********************************************************************
1040 * RealGetWindowClassA (USER32.@)
1042 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1044 return GetClassNameA( hwnd
, buffer
, count
);
1048 /***********************************************************************
1049 * RealGetWindowClassW (USER32.@)
1051 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1053 return GetClassNameW( hwnd
, buffer
, count
);
1057 /***********************************************************************
1058 * GetClassInfoA (USER32.@)
1060 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1063 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1067 wc
->style
= wcex
.style
;
1068 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1069 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1070 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1071 wc
->hInstance
= wcex
.hInstance
;
1072 wc
->hIcon
= wcex
.hIcon
;
1073 wc
->hCursor
= wcex
.hCursor
;
1074 wc
->hbrBackground
= wcex
.hbrBackground
;
1075 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1076 wc
->lpszClassName
= wcex
.lpszClassName
;
1082 /***********************************************************************
1083 * GetClassInfoW (USER32.@)
1085 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1088 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1092 wc
->style
= wcex
.style
;
1093 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1094 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1095 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1096 wc
->hInstance
= wcex
.hInstance
;
1097 wc
->hIcon
= wcex
.hIcon
;
1098 wc
->hCursor
= wcex
.hCursor
;
1099 wc
->hbrBackground
= wcex
.hbrBackground
;
1100 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1101 wc
->lpszClassName
= wcex
.lpszClassName
;
1107 /***********************************************************************
1108 * GetClassInfoExA (USER32.@)
1110 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1115 TRACE("%p %s %p\n", hInstance
, debugstr_a(name
), wc
);
1117 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
1121 SetLastError( ERROR_NOACCESS
);
1125 if (!hInstance
) hInstance
= user32_module
;
1127 if (!IS_INTRESOURCE(name
))
1129 WCHAR nameW
[MAX_ATOM_LEN
+ 1];
1130 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, sizeof(nameW
)/sizeof(WCHAR
) ))
1132 classPtr
= CLASS_FindClass( nameW
, hInstance
);
1134 else classPtr
= CLASS_FindClass( (LPCWSTR
)name
, hInstance
);
1138 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1141 wc
->style
= classPtr
->style
;
1142 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1143 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1144 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1145 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1146 wc
->hIcon
= classPtr
->hIcon
;
1147 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1148 wc
->hCursor
= classPtr
->hCursor
;
1149 wc
->hbrBackground
= classPtr
->hbrBackground
;
1150 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1151 wc
->lpszClassName
= name
;
1152 atom
= classPtr
->atomName
;
1153 release_class_ptr( classPtr
);
1155 /* We must return the atom of the class here instead of just TRUE. */
1160 /***********************************************************************
1161 * GetClassInfoExW (USER32.@)
1163 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1168 TRACE("%p %s %p\n", hInstance
, debugstr_w(name
), wc
);
1170 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
1174 SetLastError( ERROR_NOACCESS
);
1178 if (!hInstance
) hInstance
= user32_module
;
1180 if (!(classPtr
= CLASS_FindClass( name
, hInstance
)))
1182 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1185 wc
->style
= classPtr
->style
;
1186 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1187 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1188 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1189 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1190 wc
->hIcon
= classPtr
->hIcon
;
1191 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1192 wc
->hCursor
= classPtr
->hCursor
;
1193 wc
->hbrBackground
= classPtr
->hbrBackground
;
1194 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1195 wc
->lpszClassName
= name
;
1196 atom
= classPtr
->atomName
;
1197 release_class_ptr( classPtr
);
1199 /* We must return the atom of the class here instead of just TRUE. */
1204 #if 0 /* toolhelp is in kernel, so this cannot work */
1206 /***********************************************************************
1207 * ClassFirst (TOOLHELP.69)
1209 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1211 TRACE("%p\n",pClassEntry
);
1212 pClassEntry
->wNext
= 1;
1213 return ClassNext16( pClassEntry
);
1217 /***********************************************************************
1218 * ClassNext (TOOLHELP.70)
1220 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1223 CLASS
*class = firstClass
;
1225 TRACE("%p\n",pClassEntry
);
1227 if (!pClassEntry
->wNext
) return FALSE
;
1228 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1231 pClassEntry
->wNext
= 0;
1234 pClassEntry
->hInst
= class->hInstance
;
1235 pClassEntry
->wNext
++;
1236 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1237 sizeof(pClassEntry
->szClassName
) );
1242 /* 64bit versions */
1244 #ifdef GetClassLongPtrA
1245 #undef GetClassLongPtrA
1248 #ifdef GetClassLongPtrW
1249 #undef GetClassLongPtrW
1252 #ifdef SetClassLongPtrA
1253 #undef SetClassLongPtrA
1256 #ifdef SetClassLongPtrW
1257 #undef SetClassLongPtrW
1260 /***********************************************************************
1261 * GetClassLongPtrA (USER32.@)
1263 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1265 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1268 /***********************************************************************
1269 * GetClassLongPtrW (USER32.@)
1271 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1273 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1276 /***********************************************************************
1277 * SetClassLongPtrW (USER32.@)
1279 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1281 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1284 /***********************************************************************
1285 * SetClassLongPtrA (USER32.@)
1287 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1289 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);