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 HCURSOR hCursor
; /* Default cursor */
60 HBRUSH hbrBackground
; /* Default background */
61 ATOM atomName
; /* Name of the class */
62 WCHAR name
[MAX_ATOM_LEN
+ 1];
65 static struct list class_list
= LIST_INIT( class_list
);
67 #define CLASS_OTHER_PROCESS ((CLASS *)1)
69 /***********************************************************************
72 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
74 WND
*ptr
= WIN_GetPtr( hwnd
);
78 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
) return ptr
->class;
79 if (!write_access
) return CLASS_OTHER_PROCESS
;
81 /* modifying classes in other processes is not allowed */
82 if (ptr
== WND_DESKTOP
|| IsWindow( hwnd
))
84 SetLastError( ERROR_ACCESS_DENIED
);
88 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
93 /***********************************************************************
96 static inline void release_class_ptr( CLASS
*ptr
)
102 /***********************************************************************
105 ATOM
get_int_atom_value( LPCWSTR name
)
109 if (IS_INTRESOURCE(name
)) return LOWORD(name
);
110 if (*name
++ != '#') return 0;
113 if (*name
< '0' || *name
> '9') return 0;
114 ret
= ret
* 10 + *name
++ - '0';
115 if (ret
> 0xffff) return 0;
121 /***********************************************************************
124 * Set class info with the wine server.
126 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG_PTR newval
, UINT size
)
130 SERVER_START_REQ( set_class_info
)
133 req
->extra_offset
= -1;
137 req
->flags
= SET_CLASS_ATOM
;
140 req
->flags
= SET_CLASS_STYLE
;
144 req
->flags
= SET_CLASS_WINEXTRA
;
145 req
->win_extra
= newval
;
148 req
->flags
= SET_CLASS_INSTANCE
;
149 req
->instance
= (void *)newval
;
152 assert( offset
>= 0 );
153 req
->flags
= SET_CLASS_EXTRA
;
154 req
->extra_offset
= offset
;
155 req
->extra_size
= size
;
156 if ( size
== sizeof(LONG
) )
158 LONG newlong
= newval
;
159 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
162 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
165 ret
= !wine_server_call_err( req
);
172 /***********************************************************************
175 * Get the menu name as a ASCII string.
177 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
179 if (!HIWORD(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
180 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
184 /***********************************************************************
187 * Get the menu name as a Unicode string.
189 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
191 return classPtr
->menuName
;
195 /***********************************************************************
198 * Set the menu name in a class structure by copying the string.
200 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
202 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
205 DWORD lenA
= strlen(name
) + 1;
206 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
207 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
208 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
209 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
211 else classPtr
->menuName
= (LPWSTR
)name
;
215 /***********************************************************************
218 * Set the menu name in a class structure by copying the string.
220 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
222 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
225 DWORD lenW
= strlenW(name
) + 1;
226 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
227 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
228 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
229 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
230 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
232 else classPtr
->menuName
= (LPWSTR
)name
;
236 /***********************************************************************
239 * Free a class structure.
241 static void CLASS_FreeClass( CLASS
*classPtr
)
243 TRACE("%p\n", classPtr
);
247 if (classPtr
->dce
) free_dce( classPtr
->dce
, 0 );
248 list_remove( &classPtr
->entry
);
249 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
250 DeleteObject( classPtr
->hbrBackground
);
251 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
252 HeapFree( GetProcessHeap(), 0, classPtr
);
257 /***********************************************************************
258 * CLASS_FreeModuleClasses
260 void CLASS_FreeModuleClasses( HMODULE16 hModule
)
262 struct list
*ptr
, *next
;
264 TRACE("0x%08x\n", hModule
);
267 for (ptr
= list_head( &class_list
); ptr
; ptr
= next
)
269 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
270 next
= list_next( &class_list
, ptr
);
271 if (class->hInstance
== HINSTANCE_32(hModule
))
275 SERVER_START_REQ( destroy_class
)
277 req
->atom
= class->atomName
;
278 req
->instance
= class->hInstance
;
279 ret
= !wine_server_call_err( req
);
282 if (ret
) CLASS_FreeClass( class );
289 /***********************************************************************
292 * Return a pointer to the class.
293 * hinstance has been normalized by the caller.
295 static CLASS
*CLASS_FindClass( LPCWSTR name
, HINSTANCE hinstance
)
298 ATOM atom
= get_int_atom_value( name
);
302 LIST_FOR_EACH( ptr
, &class_list
)
304 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
307 if (class->atomName
!= atom
) continue;
311 if (!name
|| strcmpiW( class->name
, name
)) continue;
313 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
315 TRACE("%s %p -> %p\n", debugstr_w(name
), hinstance
, class);
320 TRACE("%s %p -> not found\n", debugstr_w(name
), hinstance
);
325 /***********************************************************************
326 * CLASS_RegisterClass
328 * The real RegisterClass() functionality.
330 static CLASS
*CLASS_RegisterClass( LPCWSTR name
, HINSTANCE hInstance
, BOOL local
,
331 DWORD style
, INT classExtra
, INT winExtra
)
336 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
337 debugstr_w(name
), hInstance
, style
, classExtra
, winExtra
);
339 /* Fix the extra bytes value */
341 if (classExtra
< 0 || winExtra
< 0)
343 SetLastError( ERROR_INVALID_PARAMETER
);
346 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
347 WARN("Class extra bytes %d is > 40\n", classExtra
);
348 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
349 WARN("Win extra bytes %d is > 40\n", winExtra
);
351 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
352 if (!classPtr
) return NULL
;
354 classPtr
->atomName
= get_int_atom_value( name
);
355 if (!classPtr
->atomName
&& name
) strcpyW( classPtr
->name
, name
);
356 else GlobalGetAtomNameW( classPtr
->atomName
, classPtr
->name
, sizeof(classPtr
->name
)/sizeof(WCHAR
) );
358 SERVER_START_REQ( create_class
)
362 req
->instance
= hInstance
;
363 req
->extra
= classExtra
;
364 req
->win_extra
= winExtra
;
365 req
->client_ptr
= classPtr
;
366 req
->atom
= classPtr
->atomName
;
367 if (!req
->atom
&& name
) wine_server_add_data( req
, name
, strlenW(name
) * sizeof(WCHAR
) );
368 ret
= !wine_server_call_err( req
);
369 classPtr
->atomName
= reply
->atom
;
374 HeapFree( GetProcessHeap(), 0, classPtr
);
378 classPtr
->style
= style
;
379 classPtr
->local
= local
;
380 classPtr
->cbWndExtra
= winExtra
;
381 classPtr
->cbClsExtra
= classExtra
;
382 classPtr
->hInstance
= hInstance
;
384 /* Other non-null values must be set by caller */
387 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
388 else list_add_tail( &class_list
, &classPtr
->entry
);
393 /***********************************************************************
396 * Register a builtin control class.
397 * This allows having both ASCII and Unicode winprocs for the same class.
399 static WNDPROC
register_builtin( const struct builtin_class_descr
*descr
)
403 if (!(classPtr
= CLASS_RegisterClass( descr
->name
, user32_module
, FALSE
,
404 descr
->style
, 0, descr
->extra
))) return 0;
406 classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
407 classPtr
->hbrBackground
= descr
->brush
;
408 classPtr
->winproc
= WINPROC_AllocProc( descr
->procA
, descr
->procW
);
409 release_class_ptr( classPtr
);
410 return classPtr
->winproc
;
414 /***********************************************************************
415 * CLASS_RegisterBuiltinClasses
417 void CLASS_RegisterBuiltinClasses(void)
419 register_builtin( &DESKTOP_builtin_class
);
420 register_builtin( &BUTTON_builtin_class
);
421 register_builtin( &COMBO_builtin_class
);
422 register_builtin( &COMBOLBOX_builtin_class
);
423 register_builtin( &DIALOG_builtin_class
);
424 EDIT_winproc_handle
= register_builtin( &EDIT_builtin_class
);
425 register_builtin( &ICONTITLE_builtin_class
);
426 register_builtin( &LISTBOX_builtin_class
);
427 register_builtin( &MDICLIENT_builtin_class
);
428 register_builtin( &MENU_builtin_class
);
429 register_builtin( &SCROLL_builtin_class
);
430 register_builtin( &STATIC_builtin_class
);
432 /* the DefWindowProc winprocs are magic too */
433 WINPROC_AllocProc( DefWindowProcA
, DefWindowProcW
);
437 /***********************************************************************
440 WNDPROC
get_class_winproc( CLASS
*class )
442 return class->winproc
;
446 /***********************************************************************
449 struct dce
*get_class_dce( CLASS
*class )
455 /***********************************************************************
458 struct dce
*set_class_dce( CLASS
*class, struct dce
*dce
)
460 if (class->dce
) return class->dce
; /* already set, don't change it */
466 /***********************************************************************
467 * RegisterClassA (USER32.@)
469 * Register a window class.
472 * >0: Unique identifier
475 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
479 wcex
.cbSize
= sizeof(wcex
);
480 wcex
.style
= wc
->style
;
481 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
482 wcex
.cbClsExtra
= wc
->cbClsExtra
;
483 wcex
.cbWndExtra
= wc
->cbWndExtra
;
484 wcex
.hInstance
= wc
->hInstance
;
485 wcex
.hIcon
= wc
->hIcon
;
486 wcex
.hCursor
= wc
->hCursor
;
487 wcex
.hbrBackground
= wc
->hbrBackground
;
488 wcex
.lpszMenuName
= wc
->lpszMenuName
;
489 wcex
.lpszClassName
= wc
->lpszClassName
;
491 return RegisterClassExA( &wcex
);
495 /***********************************************************************
496 * RegisterClassW (USER32.@)
498 * See RegisterClassA.
500 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
504 wcex
.cbSize
= sizeof(wcex
);
505 wcex
.style
= wc
->style
;
506 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
507 wcex
.cbClsExtra
= wc
->cbClsExtra
;
508 wcex
.cbWndExtra
= wc
->cbWndExtra
;
509 wcex
.hInstance
= wc
->hInstance
;
510 wcex
.hIcon
= wc
->hIcon
;
511 wcex
.hCursor
= wc
->hCursor
;
512 wcex
.hbrBackground
= wc
->hbrBackground
;
513 wcex
.lpszMenuName
= wc
->lpszMenuName
;
514 wcex
.lpszClassName
= wc
->lpszClassName
;
516 return RegisterClassExW( &wcex
);
520 /***********************************************************************
521 * RegisterClassExA (USER32.@)
523 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
529 if (wc
->hInstance
== user32_module
)
531 /* we can't register a class for user32 */
532 SetLastError( ERROR_INVALID_PARAMETER
);
535 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
537 if (!IS_INTRESOURCE(wc
->lpszClassName
))
539 WCHAR name
[MAX_ATOM_LEN
+ 1];
541 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
542 classPtr
= CLASS_RegisterClass( name
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
543 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
547 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, instance
,
548 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
549 wc
->cbClsExtra
, wc
->cbWndExtra
);
551 if (!classPtr
) return 0;
552 atom
= classPtr
->atomName
;
554 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
555 debugstr_a(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
556 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
558 classPtr
->hIcon
= wc
->hIcon
;
559 classPtr
->hIconSm
= wc
->hIconSm
;
560 classPtr
->hCursor
= wc
->hCursor
;
561 classPtr
->hbrBackground
= wc
->hbrBackground
;
562 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, NULL
);
563 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
564 release_class_ptr( classPtr
);
569 /***********************************************************************
570 * RegisterClassExW (USER32.@)
572 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
578 if (wc
->hInstance
== user32_module
)
580 /* we can't register a class for user32 */
581 SetLastError( ERROR_INVALID_PARAMETER
);
584 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
586 if (!(classPtr
= CLASS_RegisterClass( wc
->lpszClassName
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
587 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
590 atom
= classPtr
->atomName
;
592 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
593 debugstr_w(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
594 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
596 classPtr
->hIcon
= wc
->hIcon
;
597 classPtr
->hIconSm
= wc
->hIconSm
;
598 classPtr
->hCursor
= wc
->hCursor
;
599 classPtr
->hbrBackground
= wc
->hbrBackground
;
600 classPtr
->winproc
= WINPROC_AllocProc( NULL
, wc
->lpfnWndProc
);
601 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
602 release_class_ptr( classPtr
);
607 /***********************************************************************
608 * UnregisterClassA (USER32.@)
610 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
612 if (!IS_INTRESOURCE(className
))
614 WCHAR name
[MAX_ATOM_LEN
+ 1];
616 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
618 return UnregisterClassW( name
, hInstance
);
620 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
623 /***********************************************************************
624 * UnregisterClassW (USER32.@)
626 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
628 CLASS
*classPtr
= NULL
;
630 SERVER_START_REQ( destroy_class
)
632 req
->instance
= hInstance
;
633 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
634 wine_server_add_data( req
, className
, strlenW(className
) * sizeof(WCHAR
) );
635 if (!wine_server_call_err( req
)) classPtr
= reply
->client_ptr
;
639 if (classPtr
) CLASS_FreeClass( classPtr
);
640 return (classPtr
!= NULL
);
644 /***********************************************************************
645 * GetClassWord (USER32.@)
647 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
652 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
654 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
656 if (class == CLASS_OTHER_PROCESS
)
658 SERVER_START_REQ( set_class_info
)
662 req
->extra_offset
= offset
;
663 req
->extra_size
= sizeof(retvalue
);
664 if (!wine_server_call_err( req
))
665 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
671 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
672 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
674 SetLastError( ERROR_INVALID_INDEX
);
675 release_class_ptr( class );
680 /***********************************************************************
683 * Implementation of GetClassLong(Ptr)A/W
685 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
689 ULONG_PTR retvalue
= 0;
691 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
693 if (class == CLASS_OTHER_PROCESS
)
695 SERVER_START_REQ( set_class_info
)
699 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
700 req
->extra_size
= (offset
>= 0) ? size
: 0;
701 if (!wine_server_call_err( req
))
705 case GCLP_HBRBACKGROUND
:
711 FIXME( "offset %d (%s) not supported on other process window %p\n",
712 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
713 SetLastError( ERROR_INVALID_HANDLE
);
716 retvalue
= reply
->old_style
;
719 retvalue
= reply
->old_win_extra
;
722 retvalue
= reply
->old_extra
;
725 retvalue
= (ULONG_PTR
)reply
->old_instance
;
728 retvalue
= reply
->old_atom
;
733 if (size
== sizeof(DWORD
))
736 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
740 memcpy( &retvalue
, &reply
->old_extra_value
,
743 else SetLastError( ERROR_INVALID_INDEX
);
754 if (offset
<= class->cbClsExtra
- size
)
756 if (size
== sizeof(DWORD
))
759 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
763 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
766 SetLastError( ERROR_INVALID_INDEX
);
767 release_class_ptr( class );
773 case GCLP_HBRBACKGROUND
:
774 retvalue
= (ULONG_PTR
)class->hbrBackground
;
777 retvalue
= (ULONG_PTR
)class->hCursor
;
780 retvalue
= (ULONG_PTR
)class->hIcon
;
783 retvalue
= (ULONG_PTR
)class->hIconSm
;
786 retvalue
= class->style
;
789 retvalue
= class->cbWndExtra
;
792 retvalue
= class->cbClsExtra
;
795 retvalue
= (ULONG_PTR
)class->hInstance
;
798 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
801 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
803 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
805 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
808 retvalue
= class->atomName
;
811 SetLastError( ERROR_INVALID_INDEX
);
814 release_class_ptr( class );
819 /***********************************************************************
820 * GetClassLongW (USER32.@)
822 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
824 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
829 /***********************************************************************
830 * GetClassLongA (USER32.@)
832 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
834 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
838 /***********************************************************************
839 * SetClassWord (USER32.@)
841 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
846 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
848 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
850 SERVER_START_REQ( set_class_info
)
853 req
->flags
= SET_CLASS_EXTRA
;
854 req
->extra_offset
= offset
;
855 req
->extra_size
= sizeof(newval
);
856 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
857 if (!wine_server_call_err( req
))
859 void *ptr
= (char *)(class + 1) + offset
;
860 memcpy( &retval
, ptr
, sizeof(retval
) );
861 memcpy( ptr
, &newval
, sizeof(newval
) );
865 release_class_ptr( class );
870 /***********************************************************************
873 * Implementation of SetClassLong(Ptr)A/W
875 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
876 UINT size
, BOOL unicode
)
879 ULONG_PTR retval
= 0;
881 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
885 if (set_server_info( hwnd
, offset
, newval
, size
))
887 void *ptr
= (char *)(class + 1) + offset
;
888 if ( size
== sizeof(LONG
) )
891 LONG newlong
= newval
;
892 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
893 memcpy( ptr
, &newlong
, sizeof(LONG
) );
898 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
899 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
907 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
909 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
910 retval
= 0; /* Old value is now meaningless anyway */
913 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
914 class->winproc
= WINPROC_AllocProc( unicode
? NULL
: (WNDPROC
)newval
,
915 unicode
? (WNDPROC
)newval
: NULL
);
917 case GCLP_HBRBACKGROUND
:
918 retval
= (ULONG_PTR
)class->hbrBackground
;
919 class->hbrBackground
= (HBRUSH
)newval
;
922 retval
= (ULONG_PTR
)class->hCursor
;
923 class->hCursor
= (HCURSOR
)newval
;
926 retval
= (ULONG_PTR
)class->hIcon
;
927 class->hIcon
= (HICON
)newval
;
930 retval
= (ULONG_PTR
)class->hIconSm
;
931 class->hIconSm
= (HICON
)newval
;
934 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
935 retval
= class->style
;
936 class->style
= newval
;
939 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
940 retval
= class->cbWndExtra
;
941 class->cbWndExtra
= newval
;
944 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
945 retval
= (ULONG_PTR
)class->hInstance
;
946 class->hInstance
= (HINSTANCE
)newval
;
949 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
950 retval
= class->atomName
;
951 class->atomName
= newval
;
952 GlobalGetAtomNameW( newval
, class->name
, sizeof(class->name
)/sizeof(WCHAR
) );
954 case GCL_CBCLSEXTRA
: /* cannot change this one */
955 SetLastError( ERROR_INVALID_PARAMETER
);
958 SetLastError( ERROR_INVALID_INDEX
);
961 release_class_ptr( class );
966 /***********************************************************************
967 * SetClassLongW (USER32.@)
969 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
971 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
975 /***********************************************************************
976 * SetClassLongA (USER32.@)
978 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
980 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
984 /***********************************************************************
985 * GetClassNameA (USER32.@)
987 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
989 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
992 if (count
<= 0) return 0;
993 if (!GetClassNameW( hwnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
994 RtlUnicodeToMultiByteN( buffer
, count
- 1, &len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
1000 /***********************************************************************
1001 * GetClassNameW (USER32.@)
1003 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
1008 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
1010 if (count
<= 0) return 0;
1012 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
1014 if (class == CLASS_OTHER_PROCESS
)
1016 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1018 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
1021 ret
= min(count
- 1, ret
);
1022 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1028 lstrcpynW( buffer
, class->name
, count
);
1029 release_class_ptr( class );
1030 ret
= strlenW( buffer
);
1036 /***********************************************************************
1037 * RealGetWindowClassA (USER32.@)
1039 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1041 return GetClassNameA( hwnd
, buffer
, count
);
1045 /***********************************************************************
1046 * RealGetWindowClassW (USER32.@)
1048 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1050 return GetClassNameW( hwnd
, buffer
, count
);
1054 /***********************************************************************
1055 * GetClassInfoA (USER32.@)
1057 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1060 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1064 wc
->style
= wcex
.style
;
1065 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1066 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1067 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1068 wc
->hInstance
= wcex
.hInstance
;
1069 wc
->hIcon
= wcex
.hIcon
;
1070 wc
->hCursor
= wcex
.hCursor
;
1071 wc
->hbrBackground
= wcex
.hbrBackground
;
1072 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1073 wc
->lpszClassName
= wcex
.lpszClassName
;
1079 /***********************************************************************
1080 * GetClassInfoW (USER32.@)
1082 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1085 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1089 wc
->style
= wcex
.style
;
1090 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1091 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1092 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1093 wc
->hInstance
= wcex
.hInstance
;
1094 wc
->hIcon
= wcex
.hIcon
;
1095 wc
->hCursor
= wcex
.hCursor
;
1096 wc
->hbrBackground
= wcex
.hbrBackground
;
1097 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1098 wc
->lpszClassName
= wcex
.lpszClassName
;
1104 /***********************************************************************
1105 * GetClassInfoExA (USER32.@)
1107 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1112 TRACE("%p %s %p\n", hInstance
, debugstr_a(name
), wc
);
1114 if (!hInstance
) hInstance
= user32_module
;
1116 if (!IS_INTRESOURCE(name
))
1118 WCHAR nameW
[MAX_ATOM_LEN
+ 1];
1119 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, sizeof(nameW
)/sizeof(WCHAR
) ))
1121 classPtr
= CLASS_FindClass( nameW
, hInstance
);
1123 else classPtr
= CLASS_FindClass( (LPCWSTR
)name
, hInstance
);
1127 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1130 wc
->style
= classPtr
->style
;
1131 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1132 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1133 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1134 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1135 wc
->hIcon
= classPtr
->hIcon
;
1136 wc
->hIconSm
= classPtr
->hIconSm
;
1137 wc
->hCursor
= classPtr
->hCursor
;
1138 wc
->hbrBackground
= classPtr
->hbrBackground
;
1139 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1140 wc
->lpszClassName
= name
;
1141 atom
= classPtr
->atomName
;
1142 release_class_ptr( classPtr
);
1144 /* We must return the atom of the class here instead of just TRUE. */
1149 /***********************************************************************
1150 * GetClassInfoExW (USER32.@)
1152 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1157 TRACE("%p %s %p\n", hInstance
, debugstr_w(name
), wc
);
1159 if (!hInstance
) hInstance
= user32_module
;
1161 if (!(classPtr
= CLASS_FindClass( name
, hInstance
)))
1163 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1166 wc
->style
= classPtr
->style
;
1167 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1168 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1169 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1170 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1171 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1172 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1173 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1174 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1175 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1176 wc
->lpszClassName
= name
;
1177 atom
= classPtr
->atomName
;
1178 release_class_ptr( classPtr
);
1180 /* We must return the atom of the class here instead of just TRUE. */
1185 #if 0 /* toolhelp is in kernel, so this cannot work */
1187 /***********************************************************************
1188 * ClassFirst (TOOLHELP.69)
1190 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1192 TRACE("%p\n",pClassEntry
);
1193 pClassEntry
->wNext
= 1;
1194 return ClassNext16( pClassEntry
);
1198 /***********************************************************************
1199 * ClassNext (TOOLHELP.70)
1201 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1204 CLASS
*class = firstClass
;
1206 TRACE("%p\n",pClassEntry
);
1208 if (!pClassEntry
->wNext
) return FALSE
;
1209 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1212 pClassEntry
->wNext
= 0;
1215 pClassEntry
->hInst
= class->hInstance
;
1216 pClassEntry
->wNext
++;
1217 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1218 sizeof(pClassEntry
->szClassName
) );
1223 /* 64bit versions */
1225 #ifdef GetClassLongPtrA
1226 #undef GetClassLongPtrA
1229 #ifdef GetClassLongPtrW
1230 #undef GetClassLongPtrW
1233 #ifdef SetClassLongPtrA
1234 #undef SetClassLongPtrA
1237 #ifdef SetClassLongPtrW
1238 #undef SetClassLongPtrW
1241 /***********************************************************************
1242 * GetClassLongPtrA (USER32.@)
1244 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1246 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1249 /***********************************************************************
1250 * GetClassLongPtrW (USER32.@)
1252 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1254 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1257 /***********************************************************************
1258 * SetClassLongPtrW (USER32.@)
1260 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1262 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1265 /***********************************************************************
1266 * SetClassLongPtrA (USER32.@)
1268 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1270 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);