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 HINSTANCE hInstance
; /* Module that created the task */
56 HICON hIcon
; /* Default icon */
57 HICON hIconSm
; /* Default small icon */
58 HCURSOR hCursor
; /* Default cursor */
59 HBRUSH hbrBackground
; /* Default background */
60 ATOM atomName
; /* Name of the class */
61 WCHAR name
[MAX_ATOM_LEN
+ 1];
64 static struct list class_list
= LIST_INIT( class_list
);
66 #define CLASS_OTHER_PROCESS ((CLASS *)1)
68 /***********************************************************************
71 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
73 WND
*ptr
= WIN_GetPtr( hwnd
);
77 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
) return ptr
->class;
78 if (!write_access
) return CLASS_OTHER_PROCESS
;
80 /* modifying classes in other processes is not allowed */
81 if (ptr
== WND_DESKTOP
|| IsWindow( hwnd
))
83 SetLastError( ERROR_ACCESS_DENIED
);
87 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
92 /***********************************************************************
95 static inline void release_class_ptr( CLASS
*ptr
)
101 /***********************************************************************
104 ATOM
get_int_atom_value( LPCWSTR name
)
108 if (IS_INTRESOURCE(name
)) return LOWORD(name
);
109 if (*name
++ != '#') return 0;
112 if (*name
< '0' || *name
> '9') return 0;
113 ret
= ret
* 10 + *name
++ - '0';
114 if (ret
> 0xffff) return 0;
120 /***********************************************************************
123 * Set class info with the wine server.
125 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG_PTR newval
, UINT size
)
129 SERVER_START_REQ( set_class_info
)
132 req
->extra_offset
= -1;
136 req
->flags
= SET_CLASS_ATOM
;
139 req
->flags
= SET_CLASS_STYLE
;
143 req
->flags
= SET_CLASS_WINEXTRA
;
144 req
->win_extra
= newval
;
147 req
->flags
= SET_CLASS_INSTANCE
;
148 req
->instance
= (void *)newval
;
151 assert( offset
>= 0 );
152 req
->flags
= SET_CLASS_EXTRA
;
153 req
->extra_offset
= offset
;
154 req
->extra_size
= size
;
155 if ( size
== sizeof(LONG
) )
157 LONG newlong
= newval
;
158 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
161 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
164 ret
= !wine_server_call_err( req
);
171 /***********************************************************************
174 * Get the menu name as a ASCII string.
176 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
178 if (!HIWORD(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
179 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
183 /***********************************************************************
186 * Get the menu name as a Unicode string.
188 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
190 return classPtr
->menuName
;
194 /***********************************************************************
197 * Set the menu name in a class structure by copying the string.
199 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
201 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
204 DWORD lenA
= strlen(name
) + 1;
205 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
206 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
207 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
208 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
210 else classPtr
->menuName
= (LPWSTR
)name
;
214 /***********************************************************************
217 * Set the menu name in a class structure by copying the string.
219 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
221 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
224 DWORD lenW
= strlenW(name
) + 1;
225 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
226 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
227 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
228 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
229 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
231 else classPtr
->menuName
= (LPWSTR
)name
;
235 /***********************************************************************
238 * Free a class structure.
240 static void CLASS_FreeClass( CLASS
*classPtr
)
242 TRACE("%p\n", classPtr
);
246 list_remove( &classPtr
->entry
);
247 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
248 DeleteObject( classPtr
->hbrBackground
);
249 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
250 HeapFree( GetProcessHeap(), 0, classPtr
);
255 /***********************************************************************
256 * CLASS_FreeModuleClasses
258 void CLASS_FreeModuleClasses( HMODULE16 hModule
)
260 struct list
*ptr
, *next
;
262 TRACE("0x%08x\n", hModule
);
265 for (ptr
= list_head( &class_list
); ptr
; ptr
= next
)
267 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
268 next
= list_next( &class_list
, ptr
);
269 if (class->hInstance
== HINSTANCE_32(hModule
))
273 SERVER_START_REQ( destroy_class
)
275 req
->atom
= class->atomName
;
276 req
->instance
= class->hInstance
;
277 ret
= !wine_server_call_err( req
);
280 if (ret
) CLASS_FreeClass( class );
287 /***********************************************************************
290 * Return a pointer to the class.
291 * hinstance has been normalized by the caller.
293 static CLASS
*CLASS_FindClass( LPCWSTR name
, HINSTANCE hinstance
)
296 ATOM atom
= get_int_atom_value( name
);
300 LIST_FOR_EACH( ptr
, &class_list
)
302 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
305 if (class->atomName
!= atom
) continue;
309 if (!name
|| strcmpiW( class->name
, name
)) continue;
311 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
313 TRACE("%s %p -> %p\n", debugstr_w(name
), hinstance
, class);
318 TRACE("%s %p -> not found\n", debugstr_w(name
), hinstance
);
323 /***********************************************************************
324 * CLASS_RegisterClass
326 * The real RegisterClass() functionality.
328 static CLASS
*CLASS_RegisterClass( LPCWSTR name
, HINSTANCE hInstance
, BOOL local
,
329 DWORD style
, INT classExtra
, INT winExtra
)
334 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
335 debugstr_w(name
), hInstance
, style
, classExtra
, winExtra
);
337 /* Fix the extra bytes value */
339 if (classExtra
< 0 || winExtra
< 0)
341 SetLastError( ERROR_INVALID_PARAMETER
);
344 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
345 WARN("Class extra bytes %d is > 40\n", classExtra
);
346 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
347 WARN("Win extra bytes %d is > 40\n", winExtra
);
349 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
350 if (!classPtr
) return NULL
;
352 classPtr
->atomName
= get_int_atom_value( name
);
353 if (!classPtr
->atomName
&& name
) strcpyW( classPtr
->name
, name
);
354 else GlobalGetAtomNameW( classPtr
->atomName
, classPtr
->name
, sizeof(classPtr
->name
)/sizeof(WCHAR
) );
356 SERVER_START_REQ( create_class
)
360 req
->instance
= hInstance
;
361 req
->extra
= classExtra
;
362 req
->win_extra
= winExtra
;
363 req
->client_ptr
= classPtr
;
364 req
->atom
= classPtr
->atomName
;
365 if (!req
->atom
&& name
) wine_server_add_data( req
, name
, strlenW(name
) * sizeof(WCHAR
) );
366 ret
= !wine_server_call_err( req
);
367 classPtr
->atomName
= reply
->atom
;
372 HeapFree( GetProcessHeap(), 0, classPtr
);
376 classPtr
->style
= style
;
377 classPtr
->local
= local
;
378 classPtr
->cbWndExtra
= winExtra
;
379 classPtr
->cbClsExtra
= classExtra
;
380 classPtr
->hInstance
= hInstance
;
382 /* Other non-null values must be set by caller */
385 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
386 else list_add_tail( &class_list
, &classPtr
->entry
);
391 /***********************************************************************
394 * Register a builtin control class.
395 * This allows having both ASCII and Unicode winprocs for the same class.
397 static WNDPROC
register_builtin( const struct builtin_class_descr
*descr
)
401 if (!(classPtr
= CLASS_RegisterClass( descr
->name
, user32_module
, FALSE
,
402 descr
->style
, 0, descr
->extra
))) return 0;
404 classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
405 classPtr
->hbrBackground
= descr
->brush
;
406 classPtr
->winproc
= WINPROC_AllocProc( descr
->procA
, descr
->procW
);
407 release_class_ptr( classPtr
);
408 return classPtr
->winproc
;
412 /***********************************************************************
413 * CLASS_RegisterBuiltinClasses
415 void CLASS_RegisterBuiltinClasses(void)
417 register_builtin( &DESKTOP_builtin_class
);
418 register_builtin( &BUTTON_builtin_class
);
419 register_builtin( &COMBO_builtin_class
);
420 register_builtin( &COMBOLBOX_builtin_class
);
421 register_builtin( &DIALOG_builtin_class
);
422 EDIT_winproc_handle
= register_builtin( &EDIT_builtin_class
);
423 register_builtin( &ICONTITLE_builtin_class
);
424 register_builtin( &LISTBOX_builtin_class
);
425 register_builtin( &MDICLIENT_builtin_class
);
426 register_builtin( &MENU_builtin_class
);
427 register_builtin( &SCROLL_builtin_class
);
428 register_builtin( &STATIC_builtin_class
);
430 /* the DefWindowProc winprocs are magic too */
431 WINPROC_AllocProc( DefWindowProcA
, DefWindowProcW
);
435 /***********************************************************************
438 * Add a new window using this class, and set the necessary
439 * information inside the window structure.
441 void CLASS_AddWindow( CLASS
*class, WND
*win
, BOOL unicode
)
444 win
->clsStyle
= class->style
;
445 win
->winproc
= class->winproc
;
446 if (WINPROC_IsUnicode( win
->winproc
, unicode
)) win
->flags
|= WIN_ISUNICODE
;
450 /***********************************************************************
451 * RegisterClassA (USER32.@)
453 * Register a window class.
456 * >0: Unique identifier
459 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
463 wcex
.cbSize
= sizeof(wcex
);
464 wcex
.style
= wc
->style
;
465 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
466 wcex
.cbClsExtra
= wc
->cbClsExtra
;
467 wcex
.cbWndExtra
= wc
->cbWndExtra
;
468 wcex
.hInstance
= wc
->hInstance
;
469 wcex
.hIcon
= wc
->hIcon
;
470 wcex
.hCursor
= wc
->hCursor
;
471 wcex
.hbrBackground
= wc
->hbrBackground
;
472 wcex
.lpszMenuName
= wc
->lpszMenuName
;
473 wcex
.lpszClassName
= wc
->lpszClassName
;
475 return RegisterClassExA( &wcex
);
479 /***********************************************************************
480 * RegisterClassW (USER32.@)
482 * See RegisterClassA.
484 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
488 wcex
.cbSize
= sizeof(wcex
);
489 wcex
.style
= wc
->style
;
490 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
491 wcex
.cbClsExtra
= wc
->cbClsExtra
;
492 wcex
.cbWndExtra
= wc
->cbWndExtra
;
493 wcex
.hInstance
= wc
->hInstance
;
494 wcex
.hIcon
= wc
->hIcon
;
495 wcex
.hCursor
= wc
->hCursor
;
496 wcex
.hbrBackground
= wc
->hbrBackground
;
497 wcex
.lpszMenuName
= wc
->lpszMenuName
;
498 wcex
.lpszClassName
= wc
->lpszClassName
;
500 return RegisterClassExW( &wcex
);
504 /***********************************************************************
505 * RegisterClassExA (USER32.@)
507 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
513 if (wc
->hInstance
== user32_module
)
515 /* we can't register a class for user32 */
516 SetLastError( ERROR_INVALID_PARAMETER
);
519 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
521 if (!IS_INTRESOURCE(wc
->lpszClassName
))
523 WCHAR name
[MAX_ATOM_LEN
+ 1];
525 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
526 classPtr
= CLASS_RegisterClass( name
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
527 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
531 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, instance
,
532 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
533 wc
->cbClsExtra
, wc
->cbWndExtra
);
535 if (!classPtr
) return 0;
536 atom
= classPtr
->atomName
;
538 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
539 debugstr_a(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
540 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
542 classPtr
->hIcon
= wc
->hIcon
;
543 classPtr
->hIconSm
= wc
->hIconSm
;
544 classPtr
->hCursor
= wc
->hCursor
;
545 classPtr
->hbrBackground
= wc
->hbrBackground
;
546 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, NULL
);
547 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
548 release_class_ptr( classPtr
);
553 /***********************************************************************
554 * RegisterClassExW (USER32.@)
556 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
562 if (wc
->hInstance
== user32_module
)
564 /* we can't register a class for user32 */
565 SetLastError( ERROR_INVALID_PARAMETER
);
568 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
570 if (!(classPtr
= CLASS_RegisterClass( wc
->lpszClassName
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
571 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
574 atom
= classPtr
->atomName
;
576 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
577 debugstr_w(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
578 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
580 classPtr
->hIcon
= wc
->hIcon
;
581 classPtr
->hIconSm
= wc
->hIconSm
;
582 classPtr
->hCursor
= wc
->hCursor
;
583 classPtr
->hbrBackground
= wc
->hbrBackground
;
584 classPtr
->winproc
= WINPROC_AllocProc( NULL
, wc
->lpfnWndProc
);
585 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
586 release_class_ptr( classPtr
);
591 /***********************************************************************
592 * UnregisterClassA (USER32.@)
594 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
596 if (!IS_INTRESOURCE(className
))
598 WCHAR name
[MAX_ATOM_LEN
+ 1];
600 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
602 return UnregisterClassW( name
, hInstance
);
604 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
607 /***********************************************************************
608 * UnregisterClassW (USER32.@)
610 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
612 CLASS
*classPtr
= NULL
;
614 SERVER_START_REQ( destroy_class
)
616 req
->instance
= hInstance
;
617 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
618 wine_server_add_data( req
, className
, strlenW(className
) * sizeof(WCHAR
) );
619 if (!wine_server_call_err( req
)) classPtr
= reply
->client_ptr
;
623 if (classPtr
) CLASS_FreeClass( classPtr
);
624 return (classPtr
!= NULL
);
628 /***********************************************************************
629 * GetClassWord (USER32.@)
631 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
636 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
638 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
640 if (class == CLASS_OTHER_PROCESS
)
642 SERVER_START_REQ( set_class_info
)
646 req
->extra_offset
= offset
;
647 req
->extra_size
= sizeof(retvalue
);
648 if (!wine_server_call_err( req
))
649 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
655 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
656 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
658 SetLastError( ERROR_INVALID_INDEX
);
659 release_class_ptr( class );
664 /***********************************************************************
667 * Implementation of GetClassLong(Ptr)A/W
669 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
673 ULONG_PTR retvalue
= 0;
675 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
677 if (class == CLASS_OTHER_PROCESS
)
679 SERVER_START_REQ( set_class_info
)
683 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
684 req
->extra_size
= (offset
>= 0) ? size
: 0;
685 if (!wine_server_call_err( req
))
689 case GCLP_HBRBACKGROUND
:
695 FIXME( "offset %d (%s) not supported on other process window %p\n",
696 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
697 SetLastError( ERROR_INVALID_HANDLE
);
700 retvalue
= reply
->old_style
;
703 retvalue
= reply
->old_win_extra
;
706 retvalue
= reply
->old_extra
;
709 retvalue
= (ULONG_PTR
)reply
->old_instance
;
712 retvalue
= reply
->old_atom
;
717 if (size
== sizeof(DWORD
))
720 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
724 memcpy( &retvalue
, &reply
->old_extra_value
,
727 else SetLastError( ERROR_INVALID_INDEX
);
738 if (offset
<= class->cbClsExtra
- size
)
740 if (size
== sizeof(DWORD
))
743 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
747 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
750 SetLastError( ERROR_INVALID_INDEX
);
751 release_class_ptr( class );
757 case GCLP_HBRBACKGROUND
:
758 retvalue
= (ULONG_PTR
)class->hbrBackground
;
761 retvalue
= (ULONG_PTR
)class->hCursor
;
764 retvalue
= (ULONG_PTR
)class->hIcon
;
767 retvalue
= (ULONG_PTR
)class->hIconSm
;
770 retvalue
= class->style
;
773 retvalue
= class->cbWndExtra
;
776 retvalue
= class->cbClsExtra
;
779 retvalue
= (ULONG_PTR
)class->hInstance
;
782 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
785 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
787 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
789 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
792 retvalue
= class->atomName
;
795 SetLastError( ERROR_INVALID_INDEX
);
798 release_class_ptr( class );
803 /***********************************************************************
804 * GetClassLongW (USER32.@)
806 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
808 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
813 /***********************************************************************
814 * GetClassLongA (USER32.@)
816 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
818 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
822 /***********************************************************************
823 * SetClassWord (USER32.@)
825 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
830 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
832 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
834 SERVER_START_REQ( set_class_info
)
837 req
->flags
= SET_CLASS_EXTRA
;
838 req
->extra_offset
= offset
;
839 req
->extra_size
= sizeof(newval
);
840 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
841 if (!wine_server_call_err( req
))
843 void *ptr
= (char *)(class + 1) + offset
;
844 memcpy( &retval
, ptr
, sizeof(retval
) );
845 memcpy( ptr
, &newval
, sizeof(newval
) );
849 release_class_ptr( class );
854 /***********************************************************************
857 * Implementation of SetClassLong(Ptr)A/W
859 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
860 UINT size
, BOOL unicode
)
863 ULONG_PTR retval
= 0;
865 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
869 if (set_server_info( hwnd
, offset
, newval
, size
))
871 void *ptr
= (char *)(class + 1) + offset
;
872 if ( size
== sizeof(LONG
) )
875 LONG newlong
= newval
;
876 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
877 memcpy( ptr
, &newlong
, sizeof(LONG
) );
882 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
883 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
891 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
893 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
894 retval
= 0; /* Old value is now meaningless anyway */
897 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
898 class->winproc
= WINPROC_AllocProc( unicode
? NULL
: (WNDPROC
)newval
,
899 unicode
? (WNDPROC
)newval
: NULL
);
901 case GCLP_HBRBACKGROUND
:
902 retval
= (ULONG_PTR
)class->hbrBackground
;
903 class->hbrBackground
= (HBRUSH
)newval
;
906 retval
= (ULONG_PTR
)class->hCursor
;
907 class->hCursor
= (HCURSOR
)newval
;
910 retval
= (ULONG_PTR
)class->hIcon
;
911 class->hIcon
= (HICON
)newval
;
914 retval
= (ULONG_PTR
)class->hIconSm
;
915 class->hIconSm
= (HICON
)newval
;
918 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
919 retval
= class->style
;
920 class->style
= newval
;
923 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
924 retval
= class->cbWndExtra
;
925 class->cbWndExtra
= newval
;
928 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
929 retval
= (ULONG_PTR
)class->hInstance
;
930 class->hInstance
= (HINSTANCE
)newval
;
933 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
934 retval
= class->atomName
;
935 class->atomName
= newval
;
936 GlobalGetAtomNameW( newval
, class->name
, sizeof(class->name
)/sizeof(WCHAR
) );
938 case GCL_CBCLSEXTRA
: /* cannot change this one */
939 SetLastError( ERROR_INVALID_PARAMETER
);
942 SetLastError( ERROR_INVALID_INDEX
);
945 release_class_ptr( class );
950 /***********************************************************************
951 * SetClassLongW (USER32.@)
953 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
955 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
959 /***********************************************************************
960 * SetClassLongA (USER32.@)
962 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
964 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
968 /***********************************************************************
969 * GetClassNameA (USER32.@)
971 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
973 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
976 if (count
<= 0) return 0;
977 if (!GetClassNameW( hwnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
978 RtlUnicodeToMultiByteN( buffer
, count
- 1, &len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
984 /***********************************************************************
985 * GetClassNameW (USER32.@)
987 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
992 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
994 if (count
<= 0) return 0;
996 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
998 if (class == CLASS_OTHER_PROCESS
)
1000 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1002 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
1005 ret
= min(count
- 1, ret
);
1006 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1012 lstrcpynW( buffer
, class->name
, count
);
1013 release_class_ptr( class );
1014 ret
= strlenW( buffer
);
1020 /***********************************************************************
1021 * RealGetWindowClassA (USER32.@)
1023 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1025 return GetClassNameA( hwnd
, buffer
, count
);
1029 /***********************************************************************
1030 * RealGetWindowClassW (USER32.@)
1032 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1034 return GetClassNameW( hwnd
, buffer
, count
);
1038 /***********************************************************************
1039 * GetClassInfoA (USER32.@)
1041 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1044 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1048 wc
->style
= wcex
.style
;
1049 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1050 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1051 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1052 wc
->hInstance
= wcex
.hInstance
;
1053 wc
->hIcon
= wcex
.hIcon
;
1054 wc
->hCursor
= wcex
.hCursor
;
1055 wc
->hbrBackground
= wcex
.hbrBackground
;
1056 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1057 wc
->lpszClassName
= wcex
.lpszClassName
;
1063 /***********************************************************************
1064 * GetClassInfoW (USER32.@)
1066 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1069 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1073 wc
->style
= wcex
.style
;
1074 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1075 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1076 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1077 wc
->hInstance
= wcex
.hInstance
;
1078 wc
->hIcon
= wcex
.hIcon
;
1079 wc
->hCursor
= wcex
.hCursor
;
1080 wc
->hbrBackground
= wcex
.hbrBackground
;
1081 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1082 wc
->lpszClassName
= wcex
.lpszClassName
;
1088 /***********************************************************************
1089 * GetClassInfoExA (USER32.@)
1091 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1096 TRACE("%p %s %p\n", hInstance
, debugstr_a(name
), wc
);
1098 if (!hInstance
) hInstance
= user32_module
;
1100 if (!IS_INTRESOURCE(name
))
1102 WCHAR nameW
[MAX_ATOM_LEN
+ 1];
1103 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, sizeof(nameW
)/sizeof(WCHAR
) ))
1105 classPtr
= CLASS_FindClass( nameW
, hInstance
);
1107 else classPtr
= CLASS_FindClass( (LPCWSTR
)name
, hInstance
);
1111 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1114 wc
->style
= classPtr
->style
;
1115 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1116 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1117 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1118 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1119 wc
->hIcon
= classPtr
->hIcon
;
1120 wc
->hIconSm
= classPtr
->hIconSm
;
1121 wc
->hCursor
= classPtr
->hCursor
;
1122 wc
->hbrBackground
= classPtr
->hbrBackground
;
1123 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1124 wc
->lpszClassName
= name
;
1125 atom
= classPtr
->atomName
;
1126 release_class_ptr( classPtr
);
1128 /* We must return the atom of the class here instead of just TRUE. */
1133 /***********************************************************************
1134 * GetClassInfoExW (USER32.@)
1136 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1141 TRACE("%p %s %p\n", hInstance
, debugstr_w(name
), wc
);
1143 if (!hInstance
) hInstance
= user32_module
;
1145 if (!(classPtr
= CLASS_FindClass( name
, hInstance
)))
1147 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1150 wc
->style
= classPtr
->style
;
1151 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1152 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1153 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1154 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1155 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1156 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1157 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1158 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1159 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1160 wc
->lpszClassName
= name
;
1161 atom
= classPtr
->atomName
;
1162 release_class_ptr( classPtr
);
1164 /* We must return the atom of the class here instead of just TRUE. */
1169 #if 0 /* toolhelp is in kernel, so this cannot work */
1171 /***********************************************************************
1172 * ClassFirst (TOOLHELP.69)
1174 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1176 TRACE("%p\n",pClassEntry
);
1177 pClassEntry
->wNext
= 1;
1178 return ClassNext16( pClassEntry
);
1182 /***********************************************************************
1183 * ClassNext (TOOLHELP.70)
1185 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1188 CLASS
*class = firstClass
;
1190 TRACE("%p\n",pClassEntry
);
1192 if (!pClassEntry
->wNext
) return FALSE
;
1193 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1196 pClassEntry
->wNext
= 0;
1199 pClassEntry
->hInst
= class->hInstance
;
1200 pClassEntry
->wNext
++;
1201 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1202 sizeof(pClassEntry
->szClassName
) );
1207 /* 64bit versions */
1209 #ifdef GetClassLongPtrA
1210 #undef GetClassLongPtrA
1213 #ifdef GetClassLongPtrW
1214 #undef GetClassLongPtrW
1217 #ifdef SetClassLongPtrA
1218 #undef SetClassLongPtrA
1221 #ifdef SetClassLongPtrW
1222 #undef SetClassLongPtrW
1225 /***********************************************************************
1226 * GetClassLongPtrA (USER32.@)
1228 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1230 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1233 /***********************************************************************
1234 * GetClassLongPtrW (USER32.@)
1236 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1238 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1241 /***********************************************************************
1242 * SetClassLongPtrW (USER32.@)
1244 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1246 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1249 /***********************************************************************
1250 * SetClassLongPtrA (USER32.@)
1252 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1254 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);