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
);
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
= wine_server_client_ptr( (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 (IS_INTRESOURCE(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 (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
203 if (!IS_INTRESOURCE(name
))
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 (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
223 if (!IS_INTRESOURCE(name
))
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 /***********************************************************************
260 * Return a pointer to the class.
261 * hinstance has been normalized by the caller.
263 static CLASS
*CLASS_FindClass( LPCWSTR name
, HINSTANCE hinstance
)
266 ATOM atom
= get_int_atom_value( name
);
270 LIST_FOR_EACH( ptr
, &class_list
)
272 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
275 if (class->atomName
!= atom
) continue;
279 if (!name
|| strcmpiW( class->name
, name
)) continue;
281 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
283 TRACE("%s %p -> %p\n", debugstr_w(name
), hinstance
, class);
288 TRACE("%s %p -> not found\n", debugstr_w(name
), hinstance
);
293 /***********************************************************************
294 * CLASS_RegisterClass
296 * The real RegisterClass() functionality.
298 static CLASS
*CLASS_RegisterClass( LPCWSTR name
, HINSTANCE hInstance
, BOOL local
,
299 DWORD style
, INT classExtra
, INT winExtra
)
304 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
305 debugstr_w(name
), hInstance
, style
, classExtra
, winExtra
);
307 /* Fix the extra bytes value */
309 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
310 WARN("Class extra bytes %d is > 40\n", classExtra
);
311 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
312 WARN("Win extra bytes %d is > 40\n", winExtra
);
314 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
315 if (!classPtr
) return NULL
;
317 classPtr
->atomName
= get_int_atom_value( name
);
318 if (!classPtr
->atomName
&& name
) strcpyW( classPtr
->name
, name
);
319 else GlobalGetAtomNameW( classPtr
->atomName
, classPtr
->name
, sizeof(classPtr
->name
)/sizeof(WCHAR
) );
321 SERVER_START_REQ( create_class
)
325 req
->instance
= wine_server_client_ptr( hInstance
);
326 req
->extra
= classExtra
;
327 req
->win_extra
= winExtra
;
328 req
->client_ptr
= wine_server_client_ptr( classPtr
);
329 req
->atom
= classPtr
->atomName
;
330 if (!req
->atom
&& name
) wine_server_add_data( req
, name
, strlenW(name
) * sizeof(WCHAR
) );
331 ret
= !wine_server_call_err( req
);
332 classPtr
->atomName
= reply
->atom
;
337 HeapFree( GetProcessHeap(), 0, classPtr
);
341 classPtr
->style
= style
;
342 classPtr
->local
= local
;
343 classPtr
->cbWndExtra
= winExtra
;
344 classPtr
->cbClsExtra
= classExtra
;
345 classPtr
->hInstance
= hInstance
;
347 /* Other non-null values must be set by caller */
350 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
351 else list_add_tail( &class_list
, &classPtr
->entry
);
356 /***********************************************************************
359 * Register a builtin control class.
360 * This allows having both ASCII and Unicode winprocs for the same class.
362 static void register_builtin( const struct builtin_class_descr
*descr
)
366 if (!(classPtr
= CLASS_RegisterClass( descr
->name
, user32_module
, FALSE
,
367 descr
->style
, 0, descr
->extra
))) return;
369 classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
370 classPtr
->hbrBackground
= descr
->brush
;
371 classPtr
->winproc
= BUILTIN_WINPROC( descr
->proc
);
372 release_class_ptr( classPtr
);
376 /***********************************************************************
377 * CLASS_RegisterBuiltinClasses
379 void CLASS_RegisterBuiltinClasses(void)
381 register_builtin( &DESKTOP_builtin_class
);
382 register_builtin( &BUTTON_builtin_class
);
383 register_builtin( &COMBO_builtin_class
);
384 register_builtin( &COMBOLBOX_builtin_class
);
385 register_builtin( &DIALOG_builtin_class
);
386 register_builtin( &EDIT_builtin_class
);
387 register_builtin( &ICONTITLE_builtin_class
);
388 register_builtin( &LISTBOX_builtin_class
);
389 register_builtin( &MDICLIENT_builtin_class
);
390 register_builtin( &MENU_builtin_class
);
391 register_builtin( &MESSAGE_builtin_class
);
392 register_builtin( &SCROLL_builtin_class
);
393 register_builtin( &STATIC_builtin_class
);
397 /***********************************************************************
400 WNDPROC
get_class_winproc( CLASS
*class )
402 return class->winproc
;
406 /***********************************************************************
409 struct dce
*get_class_dce( CLASS
*class )
415 /***********************************************************************
418 struct dce
*set_class_dce( CLASS
*class, struct dce
*dce
)
420 if (class->dce
) return class->dce
; /* already set, don't change it */
426 /***********************************************************************
427 * RegisterClassA (USER32.@)
429 * Register a window class.
432 * >0: Unique identifier
435 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
439 wcex
.cbSize
= sizeof(wcex
);
440 wcex
.style
= wc
->style
;
441 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
442 wcex
.cbClsExtra
= wc
->cbClsExtra
;
443 wcex
.cbWndExtra
= wc
->cbWndExtra
;
444 wcex
.hInstance
= wc
->hInstance
;
445 wcex
.hIcon
= wc
->hIcon
;
446 wcex
.hCursor
= wc
->hCursor
;
447 wcex
.hbrBackground
= wc
->hbrBackground
;
448 wcex
.lpszMenuName
= wc
->lpszMenuName
;
449 wcex
.lpszClassName
= wc
->lpszClassName
;
451 return RegisterClassExA( &wcex
);
455 /***********************************************************************
456 * RegisterClassW (USER32.@)
458 * See RegisterClassA.
460 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
464 wcex
.cbSize
= sizeof(wcex
);
465 wcex
.style
= wc
->style
;
466 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
467 wcex
.cbClsExtra
= wc
->cbClsExtra
;
468 wcex
.cbWndExtra
= wc
->cbWndExtra
;
469 wcex
.hInstance
= wc
->hInstance
;
470 wcex
.hIcon
= wc
->hIcon
;
471 wcex
.hCursor
= wc
->hCursor
;
472 wcex
.hbrBackground
= wc
->hbrBackground
;
473 wcex
.lpszMenuName
= wc
->lpszMenuName
;
474 wcex
.lpszClassName
= wc
->lpszClassName
;
476 return RegisterClassExW( &wcex
);
480 /***********************************************************************
481 * RegisterClassExA (USER32.@)
483 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
489 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
490 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
492 SetLastError( ERROR_INVALID_PARAMETER
);
495 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
497 if (!IS_INTRESOURCE(wc
->lpszClassName
))
499 WCHAR name
[MAX_ATOM_LEN
+ 1];
501 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
502 classPtr
= CLASS_RegisterClass( name
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
503 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
507 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, instance
,
508 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
509 wc
->cbClsExtra
, wc
->cbWndExtra
);
511 if (!classPtr
) return 0;
512 atom
= classPtr
->atomName
;
514 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
515 debugstr_a(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
516 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
518 classPtr
->hIcon
= wc
->hIcon
;
519 classPtr
->hIconSm
= wc
->hIconSm
;
520 classPtr
->hCursor
= wc
->hCursor
;
521 classPtr
->hbrBackground
= wc
->hbrBackground
;
522 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, FALSE
);
523 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
524 release_class_ptr( classPtr
);
529 /***********************************************************************
530 * RegisterClassExW (USER32.@)
532 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
538 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
539 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
541 SetLastError( ERROR_INVALID_PARAMETER
);
544 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
546 if (!(classPtr
= CLASS_RegisterClass( wc
->lpszClassName
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
547 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
550 atom
= classPtr
->atomName
;
552 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
553 debugstr_w(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
554 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
556 classPtr
->hIcon
= wc
->hIcon
;
557 classPtr
->hIconSm
= wc
->hIconSm
;
558 classPtr
->hCursor
= wc
->hCursor
;
559 classPtr
->hbrBackground
= wc
->hbrBackground
;
560 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, TRUE
);
561 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
562 release_class_ptr( classPtr
);
567 /***********************************************************************
568 * UnregisterClassA (USER32.@)
570 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
572 if (!IS_INTRESOURCE(className
))
574 WCHAR name
[MAX_ATOM_LEN
+ 1];
576 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
578 return UnregisterClassW( name
, hInstance
);
580 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
583 /***********************************************************************
584 * UnregisterClassW (USER32.@)
586 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
588 CLASS
*classPtr
= NULL
;
590 SERVER_START_REQ( destroy_class
)
592 req
->instance
= wine_server_client_ptr( hInstance
);
593 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
594 wine_server_add_data( req
, className
, strlenW(className
) * sizeof(WCHAR
) );
595 if (!wine_server_call_err( req
)) classPtr
= wine_server_get_ptr( reply
->client_ptr
);
599 if (classPtr
) CLASS_FreeClass( classPtr
);
600 return (classPtr
!= NULL
);
604 /***********************************************************************
605 * GetClassWord (USER32.@)
607 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
612 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
614 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
616 if (class == CLASS_OTHER_PROCESS
)
618 SERVER_START_REQ( set_class_info
)
620 req
->window
= wine_server_user_handle( hwnd
);
622 req
->extra_offset
= offset
;
623 req
->extra_size
= sizeof(retvalue
);
624 if (!wine_server_call_err( req
))
625 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
631 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
632 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
634 SetLastError( ERROR_INVALID_INDEX
);
635 release_class_ptr( class );
640 /***********************************************************************
643 * Implementation of GetClassLong(Ptr)A/W
645 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
649 ULONG_PTR retvalue
= 0;
651 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
653 if (class == CLASS_OTHER_PROCESS
)
655 SERVER_START_REQ( set_class_info
)
657 req
->window
= wine_server_user_handle( hwnd
);
659 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
660 req
->extra_size
= (offset
>= 0) ? size
: 0;
661 if (!wine_server_call_err( req
))
665 case GCLP_HBRBACKGROUND
:
671 FIXME( "offset %d (%s) not supported on other process window %p\n",
672 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
673 SetLastError( ERROR_INVALID_HANDLE
);
676 retvalue
= reply
->old_style
;
679 retvalue
= reply
->old_win_extra
;
682 retvalue
= reply
->old_extra
;
685 retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
688 retvalue
= reply
->old_atom
;
693 if (size
== sizeof(DWORD
))
696 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
700 memcpy( &retvalue
, &reply
->old_extra_value
,
703 else SetLastError( ERROR_INVALID_INDEX
);
714 if (offset
<= class->cbClsExtra
- size
)
716 if (size
== sizeof(DWORD
))
719 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
723 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
726 SetLastError( ERROR_INVALID_INDEX
);
727 release_class_ptr( class );
733 case GCLP_HBRBACKGROUND
:
734 retvalue
= (ULONG_PTR
)class->hbrBackground
;
737 retvalue
= (ULONG_PTR
)class->hCursor
;
740 retvalue
= (ULONG_PTR
)class->hIcon
;
743 retvalue
= (ULONG_PTR
)class->hIconSm
;
746 retvalue
= class->style
;
749 retvalue
= class->cbWndExtra
;
752 retvalue
= class->cbClsExtra
;
755 retvalue
= (ULONG_PTR
)class->hInstance
;
758 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
761 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
763 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
765 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
768 retvalue
= class->atomName
;
771 SetLastError( ERROR_INVALID_INDEX
);
774 release_class_ptr( class );
779 /***********************************************************************
780 * GetClassLongW (USER32.@)
782 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
784 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
789 /***********************************************************************
790 * GetClassLongA (USER32.@)
792 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
794 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
798 /***********************************************************************
799 * SetClassWord (USER32.@)
801 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
806 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
808 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
810 SERVER_START_REQ( set_class_info
)
812 req
->window
= wine_server_user_handle( hwnd
);
813 req
->flags
= SET_CLASS_EXTRA
;
814 req
->extra_offset
= offset
;
815 req
->extra_size
= sizeof(newval
);
816 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
817 if (!wine_server_call_err( req
))
819 void *ptr
= (char *)(class + 1) + offset
;
820 memcpy( &retval
, ptr
, sizeof(retval
) );
821 memcpy( ptr
, &newval
, sizeof(newval
) );
825 release_class_ptr( class );
830 /***********************************************************************
833 * Implementation of SetClassLong(Ptr)A/W
835 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
836 UINT size
, BOOL unicode
)
839 ULONG_PTR retval
= 0;
841 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
845 if (set_server_info( hwnd
, offset
, newval
, size
))
847 void *ptr
= (char *)(class + 1) + offset
;
848 if ( size
== sizeof(LONG
) )
851 LONG newlong
= newval
;
852 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
853 memcpy( ptr
, &newlong
, sizeof(LONG
) );
858 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
859 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
867 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
869 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
870 retval
= 0; /* Old value is now meaningless anyway */
873 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
874 class->winproc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
876 case GCLP_HBRBACKGROUND
:
877 retval
= (ULONG_PTR
)class->hbrBackground
;
878 class->hbrBackground
= (HBRUSH
)newval
;
881 retval
= (ULONG_PTR
)class->hCursor
;
882 class->hCursor
= (HCURSOR
)newval
;
885 retval
= (ULONG_PTR
)class->hIcon
;
886 class->hIcon
= (HICON
)newval
;
889 retval
= (ULONG_PTR
)class->hIconSm
;
890 class->hIconSm
= (HICON
)newval
;
893 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
894 retval
= class->style
;
895 class->style
= newval
;
898 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
899 retval
= class->cbWndExtra
;
900 class->cbWndExtra
= newval
;
903 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
904 retval
= (ULONG_PTR
)class->hInstance
;
905 class->hInstance
= (HINSTANCE
)newval
;
908 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
909 retval
= class->atomName
;
910 class->atomName
= newval
;
911 GlobalGetAtomNameW( newval
, class->name
, sizeof(class->name
)/sizeof(WCHAR
) );
913 case GCL_CBCLSEXTRA
: /* cannot change this one */
914 SetLastError( ERROR_INVALID_PARAMETER
);
917 SetLastError( ERROR_INVALID_INDEX
);
920 release_class_ptr( class );
925 /***********************************************************************
926 * SetClassLongW (USER32.@)
928 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
930 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
934 /***********************************************************************
935 * SetClassLongA (USER32.@)
937 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
939 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
943 /***********************************************************************
944 * GetClassNameA (USER32.@)
946 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
948 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
951 if (count
<= 0) return 0;
952 if (!GetClassNameW( hwnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
953 RtlUnicodeToMultiByteN( buffer
, count
- 1, &len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
959 /***********************************************************************
960 * GetClassNameW (USER32.@)
962 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
967 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
969 if (count
<= 0) return 0;
971 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
973 if (class == CLASS_OTHER_PROCESS
)
975 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
977 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
980 ret
= min(count
- 1, ret
);
981 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
987 lstrcpynW( buffer
, class->name
, count
);
988 release_class_ptr( class );
989 ret
= strlenW( buffer
);
995 /***********************************************************************
996 * RealGetWindowClassA (USER32.@)
998 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1000 return GetClassNameA( hwnd
, buffer
, count
);
1004 /***********************************************************************
1005 * RealGetWindowClassW (USER32.@)
1007 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1009 return GetClassNameW( hwnd
, buffer
, count
);
1013 /***********************************************************************
1014 * GetClassInfoA (USER32.@)
1016 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1019 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1023 wc
->style
= wcex
.style
;
1024 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1025 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1026 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1027 wc
->hInstance
= wcex
.hInstance
;
1028 wc
->hIcon
= wcex
.hIcon
;
1029 wc
->hCursor
= wcex
.hCursor
;
1030 wc
->hbrBackground
= wcex
.hbrBackground
;
1031 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1032 wc
->lpszClassName
= wcex
.lpszClassName
;
1038 /***********************************************************************
1039 * GetClassInfoW (USER32.@)
1041 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1044 UINT ret
= GetClassInfoExW( 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 * GetClassInfoExA (USER32.@)
1066 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1071 TRACE("%p %s %p\n", hInstance
, debugstr_a(name
), wc
);
1075 SetLastError( ERROR_NOACCESS
);
1079 if (!hInstance
) hInstance
= user32_module
;
1081 if (!IS_INTRESOURCE(name
))
1083 WCHAR nameW
[MAX_ATOM_LEN
+ 1];
1084 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, sizeof(nameW
)/sizeof(WCHAR
) ))
1086 classPtr
= CLASS_FindClass( nameW
, hInstance
);
1088 else classPtr
= CLASS_FindClass( (LPCWSTR
)name
, hInstance
);
1092 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1095 wc
->style
= classPtr
->style
;
1096 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1097 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1098 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1099 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1100 wc
->hIcon
= classPtr
->hIcon
;
1101 wc
->hIconSm
= classPtr
->hIconSm
;
1102 wc
->hCursor
= classPtr
->hCursor
;
1103 wc
->hbrBackground
= classPtr
->hbrBackground
;
1104 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1105 wc
->lpszClassName
= name
;
1106 atom
= classPtr
->atomName
;
1107 release_class_ptr( classPtr
);
1109 /* We must return the atom of the class here instead of just TRUE. */
1114 /***********************************************************************
1115 * GetClassInfoExW (USER32.@)
1117 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1122 TRACE("%p %s %p\n", hInstance
, debugstr_w(name
), wc
);
1126 SetLastError( ERROR_NOACCESS
);
1130 if (!hInstance
) hInstance
= user32_module
;
1132 if (!(classPtr
= CLASS_FindClass( name
, hInstance
)))
1134 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1137 wc
->style
= classPtr
->style
;
1138 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1139 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1140 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1141 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1142 wc
->hIcon
= classPtr
->hIcon
;
1143 wc
->hIconSm
= classPtr
->hIconSm
;
1144 wc
->hCursor
= classPtr
->hCursor
;
1145 wc
->hbrBackground
= classPtr
->hbrBackground
;
1146 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1147 wc
->lpszClassName
= name
;
1148 atom
= classPtr
->atomName
;
1149 release_class_ptr( classPtr
);
1151 /* We must return the atom of the class here instead of just TRUE. */
1156 #if 0 /* toolhelp is in kernel, so this cannot work */
1158 /***********************************************************************
1159 * ClassFirst (TOOLHELP.69)
1161 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1163 TRACE("%p\n",pClassEntry
);
1164 pClassEntry
->wNext
= 1;
1165 return ClassNext16( pClassEntry
);
1169 /***********************************************************************
1170 * ClassNext (TOOLHELP.70)
1172 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1175 CLASS
*class = firstClass
;
1177 TRACE("%p\n",pClassEntry
);
1179 if (!pClassEntry
->wNext
) return FALSE
;
1180 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1183 pClassEntry
->wNext
= 0;
1186 pClassEntry
->hInst
= class->hInstance
;
1187 pClassEntry
->wNext
++;
1188 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1189 sizeof(pClassEntry
->szClassName
) );
1194 /* 64bit versions */
1196 #ifdef GetClassLongPtrA
1197 #undef GetClassLongPtrA
1200 #ifdef GetClassLongPtrW
1201 #undef GetClassLongPtrW
1204 #ifdef SetClassLongPtrA
1205 #undef SetClassLongPtrA
1208 #ifdef SetClassLongPtrW
1209 #undef SetClassLongPtrW
1212 /***********************************************************************
1213 * GetClassLongPtrA (USER32.@)
1215 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1217 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1220 /***********************************************************************
1221 * GetClassLongPtrW (USER32.@)
1223 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1225 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1228 /***********************************************************************
1229 * SetClassLongPtrW (USER32.@)
1231 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1233 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1236 /***********************************************************************
1237 * SetClassLongPtrA (USER32.@)
1239 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1241 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);