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
)
132 req
->window
= wine_server_user_handle( hwnd
);
133 req
->extra_offset
= -1;
137 req
->flags
= SET_CLASS_ATOM
;
138 req
->atom
= LOWORD(newval
);
141 req
->flags
= SET_CLASS_STYLE
;
145 req
->flags
= SET_CLASS_WINEXTRA
;
146 req
->win_extra
= newval
;
149 req
->flags
= SET_CLASS_INSTANCE
;
150 req
->instance
= wine_server_client_ptr( (void *)newval
);
153 assert( offset
>= 0 );
154 req
->flags
= SET_CLASS_EXTRA
;
155 req
->extra_offset
= offset
;
156 req
->extra_size
= size
;
157 if ( size
== sizeof(LONG
) )
159 LONG newlong
= newval
;
160 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
163 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
166 ret
= !wine_server_call_err( req
);
173 /***********************************************************************
176 * Get the menu name as a ASCII string.
178 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
180 if (IS_INTRESOURCE(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
181 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
185 /***********************************************************************
188 * Get the menu name as a Unicode string.
190 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
192 return classPtr
->menuName
;
196 /***********************************************************************
199 * Set the menu name in a class structure by copying the string.
201 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
203 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
204 if (!IS_INTRESOURCE(name
))
206 DWORD lenA
= strlen(name
) + 1;
207 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
208 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
209 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
210 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
212 else classPtr
->menuName
= (LPWSTR
)name
;
216 /***********************************************************************
219 * Set the menu name in a class structure by copying the string.
221 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
223 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
224 if (!IS_INTRESOURCE(name
))
226 DWORD lenW
= strlenW(name
) + 1;
227 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
228 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
229 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
230 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
231 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
233 else classPtr
->menuName
= (LPWSTR
)name
;
237 /***********************************************************************
240 * Free a class structure.
242 static void CLASS_FreeClass( CLASS
*classPtr
)
244 TRACE("%p\n", classPtr
);
248 if (classPtr
->dce
) free_dce( classPtr
->dce
, 0 );
249 list_remove( &classPtr
->entry
);
250 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
251 DeleteObject( classPtr
->hbrBackground
);
252 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
253 HeapFree( GetProcessHeap(), 0, classPtr
);
258 /***********************************************************************
261 * Return a pointer to the class.
262 * hinstance has been normalized by the caller.
264 static CLASS
*CLASS_FindClass( LPCWSTR name
, HINSTANCE hinstance
)
267 ATOM atom
= get_int_atom_value( name
);
271 LIST_FOR_EACH( ptr
, &class_list
)
273 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
276 if (class->atomName
!= atom
) continue;
280 if (!name
|| strcmpiW( class->name
, name
)) continue;
282 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
284 TRACE("%s %p -> %p\n", debugstr_w(name
), hinstance
, class);
289 TRACE("%s %p -> not found\n", debugstr_w(name
), hinstance
);
294 /***********************************************************************
295 * CLASS_RegisterClass
297 * The real RegisterClass() functionality.
299 static CLASS
*CLASS_RegisterClass( LPCWSTR name
, HINSTANCE hInstance
, BOOL local
,
300 DWORD style
, INT classExtra
, INT winExtra
)
305 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
306 debugstr_w(name
), hInstance
, style
, classExtra
, winExtra
);
308 /* Fix the extra bytes value */
310 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
311 WARN("Class extra bytes %d is > 40\n", classExtra
);
312 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
313 WARN("Win extra bytes %d is > 40\n", winExtra
);
315 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
316 if (!classPtr
) return NULL
;
318 classPtr
->atomName
= get_int_atom_value( name
);
319 if (!classPtr
->atomName
&& name
) strcpyW( classPtr
->name
, name
);
320 else GlobalGetAtomNameW( classPtr
->atomName
, classPtr
->name
, sizeof(classPtr
->name
)/sizeof(WCHAR
) );
322 SERVER_START_REQ( create_class
)
326 req
->instance
= wine_server_client_ptr( hInstance
);
327 req
->extra
= classExtra
;
328 req
->win_extra
= winExtra
;
329 req
->client_ptr
= wine_server_client_ptr( classPtr
);
330 req
->atom
= classPtr
->atomName
;
331 if (!req
->atom
&& name
) wine_server_add_data( req
, name
, strlenW(name
) * sizeof(WCHAR
) );
332 ret
= !wine_server_call_err( req
);
333 classPtr
->atomName
= reply
->atom
;
338 HeapFree( GetProcessHeap(), 0, classPtr
);
342 classPtr
->style
= style
;
343 classPtr
->local
= local
;
344 classPtr
->cbWndExtra
= winExtra
;
345 classPtr
->cbClsExtra
= classExtra
;
346 classPtr
->hInstance
= hInstance
;
348 /* Other non-null values must be set by caller */
351 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
352 else list_add_tail( &class_list
, &classPtr
->entry
);
357 /***********************************************************************
360 * Register a builtin control class.
361 * This allows having both ASCII and Unicode winprocs for the same class.
363 static void register_builtin( const struct builtin_class_descr
*descr
)
367 if (!(classPtr
= CLASS_RegisterClass( descr
->name
, user32_module
, FALSE
,
368 descr
->style
, 0, descr
->extra
))) return;
370 classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
371 classPtr
->hbrBackground
= descr
->brush
;
372 classPtr
->winproc
= BUILTIN_WINPROC( descr
->proc
);
373 release_class_ptr( classPtr
);
377 /***********************************************************************
378 * CLASS_RegisterBuiltinClasses
380 void CLASS_RegisterBuiltinClasses(void)
382 register_builtin( &DESKTOP_builtin_class
);
383 register_builtin( &BUTTON_builtin_class
);
384 register_builtin( &COMBO_builtin_class
);
385 register_builtin( &COMBOLBOX_builtin_class
);
386 register_builtin( &DIALOG_builtin_class
);
387 register_builtin( &EDIT_builtin_class
);
388 register_builtin( &ICONTITLE_builtin_class
);
389 register_builtin( &LISTBOX_builtin_class
);
390 register_builtin( &MDICLIENT_builtin_class
);
391 register_builtin( &MENU_builtin_class
);
392 register_builtin( &MESSAGE_builtin_class
);
393 register_builtin( &SCROLL_builtin_class
);
394 register_builtin( &STATIC_builtin_class
);
398 /***********************************************************************
401 WNDPROC
get_class_winproc( CLASS
*class )
403 return class->winproc
;
407 /***********************************************************************
410 struct dce
*get_class_dce( CLASS
*class )
416 /***********************************************************************
419 struct dce
*set_class_dce( CLASS
*class, struct dce
*dce
)
421 if (class->dce
) return class->dce
; /* already set, don't change it */
427 /***********************************************************************
428 * RegisterClassA (USER32.@)
430 * Register a window class.
433 * >0: Unique identifier
436 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
440 wcex
.cbSize
= sizeof(wcex
);
441 wcex
.style
= wc
->style
;
442 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
443 wcex
.cbClsExtra
= wc
->cbClsExtra
;
444 wcex
.cbWndExtra
= wc
->cbWndExtra
;
445 wcex
.hInstance
= wc
->hInstance
;
446 wcex
.hIcon
= wc
->hIcon
;
447 wcex
.hCursor
= wc
->hCursor
;
448 wcex
.hbrBackground
= wc
->hbrBackground
;
449 wcex
.lpszMenuName
= wc
->lpszMenuName
;
450 wcex
.lpszClassName
= wc
->lpszClassName
;
452 return RegisterClassExA( &wcex
);
456 /***********************************************************************
457 * RegisterClassW (USER32.@)
459 * See RegisterClassA.
461 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
465 wcex
.cbSize
= sizeof(wcex
);
466 wcex
.style
= wc
->style
;
467 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
468 wcex
.cbClsExtra
= wc
->cbClsExtra
;
469 wcex
.cbWndExtra
= wc
->cbWndExtra
;
470 wcex
.hInstance
= wc
->hInstance
;
471 wcex
.hIcon
= wc
->hIcon
;
472 wcex
.hCursor
= wc
->hCursor
;
473 wcex
.hbrBackground
= wc
->hbrBackground
;
474 wcex
.lpszMenuName
= wc
->lpszMenuName
;
475 wcex
.lpszClassName
= wc
->lpszClassName
;
477 return RegisterClassExW( &wcex
);
481 /***********************************************************************
482 * RegisterClassExA (USER32.@)
484 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
490 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
491 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
493 SetLastError( ERROR_INVALID_PARAMETER
);
496 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
498 if (!IS_INTRESOURCE(wc
->lpszClassName
))
500 WCHAR name
[MAX_ATOM_LEN
+ 1];
502 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
503 classPtr
= CLASS_RegisterClass( name
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
504 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
508 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, instance
,
509 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
510 wc
->cbClsExtra
, wc
->cbWndExtra
);
512 if (!classPtr
) return 0;
513 atom
= classPtr
->atomName
;
515 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
516 debugstr_a(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
517 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
519 classPtr
->hIcon
= wc
->hIcon
;
520 classPtr
->hIconSm
= wc
->hIconSm
;
521 classPtr
->hCursor
= wc
->hCursor
;
522 classPtr
->hbrBackground
= wc
->hbrBackground
;
523 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, FALSE
);
524 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
525 release_class_ptr( classPtr
);
530 /***********************************************************************
531 * RegisterClassExW (USER32.@)
533 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
539 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
540 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
542 SetLastError( ERROR_INVALID_PARAMETER
);
545 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
547 if (!(classPtr
= CLASS_RegisterClass( wc
->lpszClassName
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
548 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
551 atom
= classPtr
->atomName
;
553 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
554 debugstr_w(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
555 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
557 classPtr
->hIcon
= wc
->hIcon
;
558 classPtr
->hIconSm
= wc
->hIconSm
;
559 classPtr
->hCursor
= wc
->hCursor
;
560 classPtr
->hbrBackground
= wc
->hbrBackground
;
561 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, TRUE
);
562 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
563 release_class_ptr( classPtr
);
568 /***********************************************************************
569 * UnregisterClassA (USER32.@)
571 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
573 if (!IS_INTRESOURCE(className
))
575 WCHAR name
[MAX_ATOM_LEN
+ 1];
577 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
579 return UnregisterClassW( name
, hInstance
);
581 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
584 /***********************************************************************
585 * UnregisterClassW (USER32.@)
587 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
589 CLASS
*classPtr
= NULL
;
591 SERVER_START_REQ( destroy_class
)
593 req
->instance
= wine_server_client_ptr( hInstance
);
594 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
595 wine_server_add_data( req
, className
, strlenW(className
) * sizeof(WCHAR
) );
596 if (!wine_server_call_err( req
)) classPtr
= wine_server_get_ptr( reply
->client_ptr
);
600 if (classPtr
) CLASS_FreeClass( classPtr
);
601 return (classPtr
!= NULL
);
605 /***********************************************************************
606 * GetClassWord (USER32.@)
608 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
613 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
615 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
617 if (class == CLASS_OTHER_PROCESS
)
619 SERVER_START_REQ( set_class_info
)
621 req
->window
= wine_server_user_handle( hwnd
);
623 req
->extra_offset
= offset
;
624 req
->extra_size
= sizeof(retvalue
);
625 if (!wine_server_call_err( req
))
626 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
632 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
633 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
635 SetLastError( ERROR_INVALID_INDEX
);
636 release_class_ptr( class );
641 /***********************************************************************
644 * Implementation of GetClassLong(Ptr)A/W
646 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
650 ULONG_PTR retvalue
= 0;
652 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
654 if (class == CLASS_OTHER_PROCESS
)
656 SERVER_START_REQ( set_class_info
)
658 req
->window
= wine_server_user_handle( hwnd
);
660 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
661 req
->extra_size
= (offset
>= 0) ? size
: 0;
662 if (!wine_server_call_err( req
))
666 case GCLP_HBRBACKGROUND
:
672 FIXME( "offset %d (%s) not supported on other process window %p\n",
673 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
674 SetLastError( ERROR_INVALID_HANDLE
);
677 retvalue
= reply
->old_style
;
680 retvalue
= reply
->old_win_extra
;
683 retvalue
= reply
->old_extra
;
686 retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
689 retvalue
= reply
->old_atom
;
694 if (size
== sizeof(DWORD
))
697 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
701 memcpy( &retvalue
, &reply
->old_extra_value
,
704 else SetLastError( ERROR_INVALID_INDEX
);
715 if (offset
<= class->cbClsExtra
- size
)
717 if (size
== sizeof(DWORD
))
720 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
724 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
727 SetLastError( ERROR_INVALID_INDEX
);
728 release_class_ptr( class );
734 case GCLP_HBRBACKGROUND
:
735 retvalue
= (ULONG_PTR
)class->hbrBackground
;
738 retvalue
= (ULONG_PTR
)class->hCursor
;
741 retvalue
= (ULONG_PTR
)class->hIcon
;
744 retvalue
= (ULONG_PTR
)class->hIconSm
;
747 retvalue
= class->style
;
750 retvalue
= class->cbWndExtra
;
753 retvalue
= class->cbClsExtra
;
756 retvalue
= (ULONG_PTR
)class->hInstance
;
759 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
762 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
764 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
766 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
769 retvalue
= class->atomName
;
772 SetLastError( ERROR_INVALID_INDEX
);
775 release_class_ptr( class );
780 /***********************************************************************
781 * GetClassLongW (USER32.@)
783 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
785 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
790 /***********************************************************************
791 * GetClassLongA (USER32.@)
793 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
795 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
799 /***********************************************************************
800 * SetClassWord (USER32.@)
802 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
807 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
809 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
811 SERVER_START_REQ( set_class_info
)
813 req
->window
= wine_server_user_handle( hwnd
);
814 req
->flags
= SET_CLASS_EXTRA
;
815 req
->extra_offset
= offset
;
816 req
->extra_size
= sizeof(newval
);
817 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
818 if (!wine_server_call_err( req
))
820 void *ptr
= (char *)(class + 1) + offset
;
821 memcpy( &retval
, ptr
, sizeof(retval
) );
822 memcpy( ptr
, &newval
, sizeof(newval
) );
826 release_class_ptr( class );
831 /***********************************************************************
834 * Implementation of SetClassLong(Ptr)A/W
836 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
837 UINT size
, BOOL unicode
)
840 ULONG_PTR retval
= 0;
842 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
846 if (set_server_info( hwnd
, offset
, newval
, size
))
848 void *ptr
= (char *)(class + 1) + offset
;
849 if ( size
== sizeof(LONG
) )
852 LONG newlong
= newval
;
853 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
854 memcpy( ptr
, &newlong
, sizeof(LONG
) );
859 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
860 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
868 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
870 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
871 retval
= 0; /* Old value is now meaningless anyway */
874 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
875 class->winproc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
877 case GCLP_HBRBACKGROUND
:
878 retval
= (ULONG_PTR
)class->hbrBackground
;
879 class->hbrBackground
= (HBRUSH
)newval
;
882 retval
= (ULONG_PTR
)class->hCursor
;
883 class->hCursor
= (HCURSOR
)newval
;
886 retval
= (ULONG_PTR
)class->hIcon
;
887 class->hIcon
= (HICON
)newval
;
890 retval
= (ULONG_PTR
)class->hIconSm
;
891 class->hIconSm
= (HICON
)newval
;
894 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
895 retval
= class->style
;
896 class->style
= newval
;
899 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
900 retval
= class->cbWndExtra
;
901 class->cbWndExtra
= newval
;
904 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
905 retval
= (ULONG_PTR
)class->hInstance
;
906 class->hInstance
= (HINSTANCE
)newval
;
909 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
910 retval
= class->atomName
;
911 class->atomName
= newval
;
912 GlobalGetAtomNameW( newval
, class->name
, sizeof(class->name
)/sizeof(WCHAR
) );
914 case GCL_CBCLSEXTRA
: /* cannot change this one */
915 SetLastError( ERROR_INVALID_PARAMETER
);
918 SetLastError( ERROR_INVALID_INDEX
);
921 release_class_ptr( class );
926 /***********************************************************************
927 * SetClassLongW (USER32.@)
929 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
931 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
935 /***********************************************************************
936 * SetClassLongA (USER32.@)
938 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
940 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
944 /***********************************************************************
945 * GetClassNameA (USER32.@)
947 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
949 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
952 if (count
<= 0) return 0;
953 if (!GetClassNameW( hwnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
954 RtlUnicodeToMultiByteN( buffer
, count
- 1, &len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
960 /***********************************************************************
961 * GetClassNameW (USER32.@)
963 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
968 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
970 if (count
<= 0) return 0;
972 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
974 if (class == CLASS_OTHER_PROCESS
)
976 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
978 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
981 ret
= min(count
- 1, ret
);
982 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
988 lstrcpynW( buffer
, class->name
, count
);
989 release_class_ptr( class );
990 ret
= strlenW( buffer
);
996 /***********************************************************************
997 * RealGetWindowClassA (USER32.@)
999 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1001 return GetClassNameA( hwnd
, buffer
, count
);
1005 /***********************************************************************
1006 * RealGetWindowClassW (USER32.@)
1008 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1010 return GetClassNameW( hwnd
, buffer
, count
);
1014 /***********************************************************************
1015 * GetClassInfoA (USER32.@)
1017 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1020 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1024 wc
->style
= wcex
.style
;
1025 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1026 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1027 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1028 wc
->hInstance
= wcex
.hInstance
;
1029 wc
->hIcon
= wcex
.hIcon
;
1030 wc
->hCursor
= wcex
.hCursor
;
1031 wc
->hbrBackground
= wcex
.hbrBackground
;
1032 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1033 wc
->lpszClassName
= wcex
.lpszClassName
;
1039 /***********************************************************************
1040 * GetClassInfoW (USER32.@)
1042 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1045 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1049 wc
->style
= wcex
.style
;
1050 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1051 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1052 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1053 wc
->hInstance
= wcex
.hInstance
;
1054 wc
->hIcon
= wcex
.hIcon
;
1055 wc
->hCursor
= wcex
.hCursor
;
1056 wc
->hbrBackground
= wcex
.hbrBackground
;
1057 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1058 wc
->lpszClassName
= wcex
.lpszClassName
;
1064 /***********************************************************************
1065 * GetClassInfoExA (USER32.@)
1067 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1072 TRACE("%p %s %p\n", hInstance
, debugstr_a(name
), wc
);
1076 SetLastError( ERROR_NOACCESS
);
1080 if (!hInstance
) hInstance
= user32_module
;
1082 if (!IS_INTRESOURCE(name
))
1084 WCHAR nameW
[MAX_ATOM_LEN
+ 1];
1085 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, sizeof(nameW
)/sizeof(WCHAR
) ))
1087 classPtr
= CLASS_FindClass( nameW
, hInstance
);
1089 else classPtr
= CLASS_FindClass( (LPCWSTR
)name
, hInstance
);
1093 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1096 wc
->style
= classPtr
->style
;
1097 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1098 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1099 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1100 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1101 wc
->hIcon
= classPtr
->hIcon
;
1102 wc
->hIconSm
= classPtr
->hIconSm
;
1103 wc
->hCursor
= classPtr
->hCursor
;
1104 wc
->hbrBackground
= classPtr
->hbrBackground
;
1105 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1106 wc
->lpszClassName
= name
;
1107 atom
= classPtr
->atomName
;
1108 release_class_ptr( classPtr
);
1110 /* We must return the atom of the class here instead of just TRUE. */
1115 /***********************************************************************
1116 * GetClassInfoExW (USER32.@)
1118 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1123 TRACE("%p %s %p\n", hInstance
, debugstr_w(name
), wc
);
1127 SetLastError( ERROR_NOACCESS
);
1131 if (!hInstance
) hInstance
= user32_module
;
1133 if (!(classPtr
= CLASS_FindClass( name
, hInstance
)))
1135 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1138 wc
->style
= classPtr
->style
;
1139 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1140 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1141 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1142 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1143 wc
->hIcon
= classPtr
->hIcon
;
1144 wc
->hIconSm
= classPtr
->hIconSm
;
1145 wc
->hCursor
= classPtr
->hCursor
;
1146 wc
->hbrBackground
= classPtr
->hbrBackground
;
1147 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1148 wc
->lpszClassName
= name
;
1149 atom
= classPtr
->atomName
;
1150 release_class_ptr( classPtr
);
1152 /* We must return the atom of the class here instead of just TRUE. */
1157 #if 0 /* toolhelp is in kernel, so this cannot work */
1159 /***********************************************************************
1160 * ClassFirst (TOOLHELP.69)
1162 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1164 TRACE("%p\n",pClassEntry
);
1165 pClassEntry
->wNext
= 1;
1166 return ClassNext16( pClassEntry
);
1170 /***********************************************************************
1171 * ClassNext (TOOLHELP.70)
1173 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1176 CLASS
*class = firstClass
;
1178 TRACE("%p\n",pClassEntry
);
1180 if (!pClassEntry
->wNext
) return FALSE
;
1181 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1184 pClassEntry
->wNext
= 0;
1187 pClassEntry
->hInst
= class->hInstance
;
1188 pClassEntry
->wNext
++;
1189 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1190 sizeof(pClassEntry
->szClassName
) );
1195 /* 64bit versions */
1197 #ifdef GetClassLongPtrA
1198 #undef GetClassLongPtrA
1201 #ifdef GetClassLongPtrW
1202 #undef GetClassLongPtrW
1205 #ifdef SetClassLongPtrA
1206 #undef SetClassLongPtrA
1209 #ifdef SetClassLongPtrW
1210 #undef SetClassLongPtrW
1213 /***********************************************************************
1214 * GetClassLongPtrA (USER32.@)
1216 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1218 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1221 /***********************************************************************
1222 * GetClassLongPtrW (USER32.@)
1224 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1226 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1229 /***********************************************************************
1230 * SetClassLongPtrW (USER32.@)
1232 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1234 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1237 /***********************************************************************
1238 * SetClassLongPtrA (USER32.@)
1240 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1242 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);