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/winuser16.h"
35 #include "wine/unicode.h"
37 #include "user_private.h"
39 #include "wine/server.h"
40 #include "wine/list.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(class);
45 typedef struct tagCLASS
47 struct list entry
; /* Entry in class list */
48 UINT style
; /* Class style */
49 BOOL local
; /* Local class? */
50 WNDPROC winproc
; /* Window procedure */
51 INT cbClsExtra
; /* Class extra bytes */
52 INT cbWndExtra
; /* Window extra bytes */
53 LPWSTR menuName
; /* Default menu name (Unicode followed by ASCII) */
54 HINSTANCE hInstance
; /* Module that created the task */
55 HICON hIcon
; /* Default icon */
56 HICON hIconSm
; /* Default small icon */
57 HCURSOR hCursor
; /* Default cursor */
58 HBRUSH hbrBackground
; /* Default background */
59 ATOM atomName
; /* Name of the class */
62 static struct list class_list
= LIST_INIT( class_list
);
64 #define CLASS_OTHER_PROCESS ((CLASS *)1)
65 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
67 /***********************************************************************
70 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
72 WND
*ptr
= WIN_GetPtr( hwnd
);
76 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
) return ptr
->class;
77 if (!write_access
) return CLASS_OTHER_PROCESS
;
79 /* modifying classes in other processes is not allowed */
80 if (ptr
== WND_DESKTOP
|| IsWindow( hwnd
))
82 SetLastError( ERROR_ACCESS_DENIED
);
86 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
91 /***********************************************************************
94 static inline void release_class_ptr( CLASS
*ptr
)
100 /***********************************************************************
103 * Set class info with the wine server.
105 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG_PTR newval
, UINT size
)
109 SERVER_START_REQ( set_class_info
)
112 req
->extra_offset
= -1;
116 req
->flags
= SET_CLASS_ATOM
;
119 req
->flags
= SET_CLASS_STYLE
;
123 req
->flags
= SET_CLASS_WINEXTRA
;
124 req
->win_extra
= newval
;
127 req
->flags
= SET_CLASS_INSTANCE
;
128 req
->instance
= (void *)newval
;
131 assert( offset
>= 0 );
132 req
->flags
= SET_CLASS_EXTRA
;
133 req
->extra_offset
= offset
;
134 req
->extra_size
= size
;
135 if ( size
== sizeof(LONG
) )
137 LONG newlong
= newval
;
138 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
141 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
144 ret
= !wine_server_call_err( req
);
151 /***********************************************************************
154 * Get the menu name as a ASCII string.
156 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
158 if (!HIWORD(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
159 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
163 /***********************************************************************
166 * Get the menu name as a Unicode string.
168 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
170 return classPtr
->menuName
;
174 /***********************************************************************
177 * Set the menu name in a class structure by copying the string.
179 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
181 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
184 DWORD lenA
= strlen(name
) + 1;
185 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
186 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
187 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
188 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
190 else classPtr
->menuName
= (LPWSTR
)name
;
194 /***********************************************************************
197 * Set the menu name in a class structure by copying the string.
199 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
201 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
204 DWORD lenW
= strlenW(name
) + 1;
205 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
206 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
207 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
208 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
209 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
211 else classPtr
->menuName
= (LPWSTR
)name
;
215 /***********************************************************************
218 * Free a class structure.
220 static void CLASS_FreeClass( CLASS
*classPtr
)
222 TRACE("%p\n", classPtr
);
226 list_remove( &classPtr
->entry
);
227 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
228 DeleteObject( classPtr
->hbrBackground
);
229 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
230 HeapFree( GetProcessHeap(), 0, classPtr
);
235 /***********************************************************************
236 * CLASS_FreeModuleClasses
238 void CLASS_FreeModuleClasses( HMODULE16 hModule
)
240 struct list
*ptr
, *next
;
242 TRACE("0x%08x\n", hModule
);
245 for (ptr
= list_head( &class_list
); ptr
; ptr
= next
)
247 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
248 next
= list_next( &class_list
, ptr
);
249 if (class->hInstance
== HINSTANCE_32(hModule
))
253 SERVER_START_REQ( destroy_class
)
255 req
->atom
= class->atomName
;
256 req
->instance
= class->hInstance
;
257 ret
= !wine_server_call_err( req
);
260 if (ret
) CLASS_FreeClass( class );
267 /***********************************************************************
268 * CLASS_FindClassByAtom
270 * Return a pointer to the class.
271 * hinstance has been normalized by the caller.
273 static CLASS
*CLASS_FindClassByAtom( ATOM atom
, HINSTANCE hinstance
)
279 LIST_FOR_EACH( ptr
, &class_list
)
281 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
282 if (class->atomName
!= atom
) continue;
283 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
285 TRACE("0x%04x %p -> %p\n", atom
, hinstance
, class);
290 TRACE("0x%04x %p -> not found\n", atom
, hinstance
);
295 /***********************************************************************
296 * CLASS_RegisterClass
298 * The real RegisterClass() functionality.
299 * The atom is deleted no matter what.
301 static CLASS
*CLASS_RegisterClass( ATOM atom
, HINSTANCE hInstance
, BOOL local
,
302 DWORD style
, INT classExtra
, INT winExtra
)
307 TRACE("atom=0x%x hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
308 atom
, hInstance
, style
, classExtra
, winExtra
);
310 /* Fix the extra bytes value */
312 if (classExtra
< 0 || winExtra
< 0)
314 SetLastError( ERROR_INVALID_PARAMETER
);
317 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
318 WARN("Class extra bytes %d is > 40\n", classExtra
);
319 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
320 WARN("Win extra bytes %d is > 40\n", winExtra
);
322 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
325 GlobalDeleteAtom( atom
);
329 SERVER_START_REQ( create_class
)
334 req
->instance
= hInstance
;
335 req
->extra
= classExtra
;
336 req
->win_extra
= winExtra
;
337 req
->client_ptr
= classPtr
;
338 ret
= !wine_server_call_err( req
);
341 GlobalDeleteAtom( atom
); /* the server increased the atom ref count */
344 HeapFree( GetProcessHeap(), 0, classPtr
);
348 classPtr
->style
= style
;
349 classPtr
->local
= local
;
350 classPtr
->cbWndExtra
= winExtra
;
351 classPtr
->cbClsExtra
= classExtra
;
352 classPtr
->hInstance
= hInstance
;
353 classPtr
->atomName
= atom
;
355 /* Other non-null values must be set by caller */
358 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
359 else list_add_tail( &class_list
, &classPtr
->entry
);
364 /***********************************************************************
367 * Register a builtin control class.
368 * This allows having both ASCII and Unicode winprocs for the same class.
370 static CLASS
*register_builtin( const struct builtin_class_descr
*descr
)
375 if (!(atom
= GlobalAddAtomA( descr
->name
))) return 0;
377 if (!(classPtr
= CLASS_RegisterClass( atom
, user32_module
, FALSE
,
378 descr
->style
, 0, descr
->extra
))) return 0;
380 classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
381 classPtr
->hbrBackground
= descr
->brush
;
382 classPtr
->winproc
= WINPROC_AllocProc( descr
->procA
, descr
->procW
);
383 release_class_ptr( classPtr
);
388 /***********************************************************************
389 * CLASS_RegisterBuiltinClasses
391 void CLASS_RegisterBuiltinClasses(void)
393 extern const struct builtin_class_descr BUTTON_builtin_class
;
394 extern const struct builtin_class_descr COMBO_builtin_class
;
395 extern const struct builtin_class_descr COMBOLBOX_builtin_class
;
396 extern const struct builtin_class_descr DIALOG_builtin_class
;
397 extern const struct builtin_class_descr DESKTOP_builtin_class
;
398 extern const struct builtin_class_descr EDIT_builtin_class
;
399 extern const struct builtin_class_descr ICONTITLE_builtin_class
;
400 extern const struct builtin_class_descr LISTBOX_builtin_class
;
401 extern const struct builtin_class_descr MDICLIENT_builtin_class
;
402 extern const struct builtin_class_descr MENU_builtin_class
;
403 extern const struct builtin_class_descr SCROLL_builtin_class
;
404 extern const struct builtin_class_descr STATIC_builtin_class
;
406 register_builtin( &DESKTOP_builtin_class
);
407 register_builtin( &BUTTON_builtin_class
);
408 register_builtin( &COMBO_builtin_class
);
409 register_builtin( &COMBOLBOX_builtin_class
);
410 register_builtin( &DIALOG_builtin_class
);
411 register_builtin( &EDIT_builtin_class
);
412 register_builtin( &ICONTITLE_builtin_class
);
413 register_builtin( &LISTBOX_builtin_class
);
414 register_builtin( &MDICLIENT_builtin_class
);
415 register_builtin( &MENU_builtin_class
);
416 register_builtin( &SCROLL_builtin_class
);
417 register_builtin( &STATIC_builtin_class
);
419 /* the DefWindowProc winprocs are magic too */
420 WINPROC_AllocProc( DefWindowProcA
, DefWindowProcW
);
424 /***********************************************************************
427 * Add a new window using this class, and set the necessary
428 * information inside the window structure.
430 void CLASS_AddWindow( CLASS
*class, WND
*win
, BOOL unicode
)
433 win
->clsStyle
= class->style
;
434 win
->winproc
= class->winproc
;
435 if (WINPROC_IsUnicode( win
->winproc
, unicode
)) win
->flags
|= WIN_ISUNICODE
;
439 /***********************************************************************
440 * RegisterClassA (USER32.@)
442 * Register a window class.
445 * >0: Unique identifier
448 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
452 wcex
.cbSize
= sizeof(wcex
);
453 wcex
.style
= wc
->style
;
454 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
455 wcex
.cbClsExtra
= wc
->cbClsExtra
;
456 wcex
.cbWndExtra
= wc
->cbWndExtra
;
457 wcex
.hInstance
= wc
->hInstance
;
458 wcex
.hIcon
= wc
->hIcon
;
459 wcex
.hCursor
= wc
->hCursor
;
460 wcex
.hbrBackground
= wc
->hbrBackground
;
461 wcex
.lpszMenuName
= wc
->lpszMenuName
;
462 wcex
.lpszClassName
= wc
->lpszClassName
;
464 return RegisterClassExA( &wcex
);
468 /***********************************************************************
469 * RegisterClassW (USER32.@)
471 * See RegisterClassA.
473 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
477 wcex
.cbSize
= sizeof(wcex
);
478 wcex
.style
= wc
->style
;
479 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
480 wcex
.cbClsExtra
= wc
->cbClsExtra
;
481 wcex
.cbWndExtra
= wc
->cbWndExtra
;
482 wcex
.hInstance
= wc
->hInstance
;
483 wcex
.hIcon
= wc
->hIcon
;
484 wcex
.hCursor
= wc
->hCursor
;
485 wcex
.hbrBackground
= wc
->hbrBackground
;
486 wcex
.lpszMenuName
= wc
->lpszMenuName
;
487 wcex
.lpszClassName
= wc
->lpszClassName
;
489 return RegisterClassExW( &wcex
);
493 /***********************************************************************
494 * RegisterClassExA (USER32.@)
496 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
502 if (wc
->hInstance
== user32_module
)
504 /* we can't register a class for user32 */
505 SetLastError( ERROR_INVALID_PARAMETER
);
508 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
510 if (!(atom
= GlobalAddAtomA( wc
->lpszClassName
))) return 0;
512 if (!(classPtr
= CLASS_RegisterClass( atom
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
513 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
516 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
517 atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
518 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
520 classPtr
->hIcon
= wc
->hIcon
;
521 classPtr
->hIconSm
= wc
->hIconSm
;
522 classPtr
->hCursor
= wc
->hCursor
;
523 classPtr
->hbrBackground
= wc
->hbrBackground
;
524 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, NULL
);
525 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
526 release_class_ptr( classPtr
);
531 /***********************************************************************
532 * RegisterClassExW (USER32.@)
534 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
540 if (wc
->hInstance
== user32_module
)
542 /* we can't register a class for user32 */
543 SetLastError( ERROR_INVALID_PARAMETER
);
546 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
548 if (!(atom
= GlobalAddAtomW( wc
->lpszClassName
))) return 0;
550 if (!(classPtr
= CLASS_RegisterClass( atom
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
551 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
554 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
555 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( NULL
, wc
->lpfnWndProc
);
563 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
564 release_class_ptr( classPtr
);
569 /***********************************************************************
570 * UnregisterClassA (USER32.@)
572 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
574 ATOM atom
= HIWORD(className
) ? GlobalFindAtomA( className
) : LOWORD(className
);
575 return UnregisterClassW( (LPCWSTR
)MAKEINTATOM(atom
), hInstance
);
578 /***********************************************************************
579 * UnregisterClassW (USER32.@)
581 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
583 CLASS
*classPtr
= NULL
;
584 ATOM atom
= HIWORD(className
) ? GlobalFindAtomW( className
) : LOWORD(className
);
586 TRACE("%s %p %x\n",debugstr_w(className
), hInstance
, atom
);
590 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
594 SERVER_START_REQ( destroy_class
)
597 req
->instance
= hInstance
;
598 if (!wine_server_call_err( req
)) classPtr
= reply
->client_ptr
;
602 if (classPtr
) CLASS_FreeClass( classPtr
);
603 return (classPtr
!= NULL
);
607 /***********************************************************************
608 * GetClassWord (USER32.@)
610 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
615 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
617 TRACE("%p %x\n",hwnd
, offset
);
619 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
621 if (class == CLASS_OTHER_PROCESS
)
623 SERVER_START_REQ( set_class_info
)
627 req
->extra_offset
= offset
;
628 req
->extra_size
= sizeof(retvalue
);
629 if (!wine_server_call_err( req
))
630 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
636 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
637 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
639 SetLastError( ERROR_INVALID_INDEX
);
640 release_class_ptr( class );
645 /***********************************************************************
648 * Implementation of GetClassLong(Ptr)A/W
650 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
654 ULONG_PTR retvalue
= 0;
656 TRACE("%p %d\n", hwnd
, offset
);
658 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
660 if (class == CLASS_OTHER_PROCESS
)
662 SERVER_START_REQ( set_class_info
)
666 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
667 req
->extra_size
= (offset
>= 0) ? size
: 0;
668 if (!wine_server_call_err( req
))
672 case GCLP_HBRBACKGROUND
:
678 FIXME( "offset %d (%s) not supported on other process window %p\n",
679 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
680 SetLastError( ERROR_INVALID_HANDLE
);
683 retvalue
= reply
->old_style
;
686 retvalue
= reply
->old_win_extra
;
689 retvalue
= reply
->old_extra
;
692 retvalue
= (ULONG_PTR
)reply
->old_instance
;
695 retvalue
= reply
->old_atom
;
700 if (size
== sizeof(DWORD
))
703 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
707 memcpy( &retvalue
, &reply
->old_extra_value
,
710 else SetLastError( ERROR_INVALID_INDEX
);
721 if (offset
<= class->cbClsExtra
- size
)
723 if (size
== sizeof(DWORD
))
726 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
730 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
733 SetLastError( ERROR_INVALID_INDEX
);
734 release_class_ptr( class );
740 case GCLP_HBRBACKGROUND
:
741 retvalue
= (ULONG_PTR
)class->hbrBackground
;
744 retvalue
= (ULONG_PTR
)class->hCursor
;
747 retvalue
= (ULONG_PTR
)class->hIcon
;
750 retvalue
= (ULONG_PTR
)class->hIconSm
;
753 retvalue
= class->style
;
756 retvalue
= class->cbWndExtra
;
759 retvalue
= class->cbClsExtra
;
762 retvalue
= (ULONG_PTR
)class->hInstance
;
765 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
768 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
770 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
772 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
775 retvalue
= class->atomName
;
778 SetLastError( ERROR_INVALID_INDEX
);
781 release_class_ptr( class );
786 /***********************************************************************
787 * GetClassLongW (USER32.@)
789 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
791 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
796 /***********************************************************************
797 * GetClassLongA (USER32.@)
799 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
801 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
805 /***********************************************************************
806 * SetClassWord (USER32.@)
808 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
813 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
815 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
817 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
819 SERVER_START_REQ( set_class_info
)
822 req
->flags
= SET_CLASS_EXTRA
;
823 req
->extra_offset
= offset
;
824 req
->extra_size
= sizeof(newval
);
825 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
826 if (!wine_server_call_err( req
))
828 void *ptr
= (char *)(class + 1) + offset
;
829 memcpy( &retval
, ptr
, sizeof(retval
) );
830 memcpy( ptr
, &newval
, sizeof(newval
) );
834 release_class_ptr( class );
839 /***********************************************************************
842 * Implementation of SetClassLong(Ptr)A/W
844 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
845 UINT size
, BOOL unicode
)
848 ULONG_PTR retval
= 0;
850 TRACE("%p %d %lx\n", hwnd
, offset
, newval
);
852 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
856 if (set_server_info( hwnd
, offset
, newval
, size
))
858 void *ptr
= (char *)(class + 1) + offset
;
859 if ( size
== sizeof(LONG
) )
862 LONG newlong
= newval
;
863 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
864 memcpy( ptr
, &newlong
, sizeof(LONG
) );
869 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
870 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
878 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
880 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
881 retval
= 0; /* Old value is now meaningless anyway */
884 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
885 class->winproc
= WINPROC_AllocProc( unicode
? NULL
: (WNDPROC
)newval
,
886 unicode
? (WNDPROC
)newval
: NULL
);
888 case GCLP_HBRBACKGROUND
:
889 retval
= (ULONG_PTR
)class->hbrBackground
;
890 class->hbrBackground
= (HBRUSH
)newval
;
893 retval
= (ULONG_PTR
)class->hCursor
;
894 class->hCursor
= (HCURSOR
)newval
;
897 retval
= (ULONG_PTR
)class->hIcon
;
898 class->hIcon
= (HICON
)newval
;
901 retval
= (ULONG_PTR
)class->hIconSm
;
902 class->hIconSm
= (HICON
)newval
;
905 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
906 retval
= class->style
;
907 class->style
= newval
;
910 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
911 retval
= class->cbWndExtra
;
912 class->cbWndExtra
= newval
;
915 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
916 retval
= (ULONG_PTR
)class->hInstance
;
917 class->hInstance
= (HINSTANCE
)newval
;
920 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
921 retval
= class->atomName
;
922 class->atomName
= newval
;
924 case GCL_CBCLSEXTRA
: /* cannot change this one */
925 SetLastError( ERROR_INVALID_PARAMETER
);
928 SetLastError( ERROR_INVALID_INDEX
);
931 release_class_ptr( class );
936 /***********************************************************************
937 * SetClassLongW (USER32.@)
939 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
941 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
943 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
947 /***********************************************************************
948 * SetClassLongA (USER32.@)
950 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
952 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
954 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
958 /***********************************************************************
959 * GetClassNameA (USER32.@)
961 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
963 char tmpbuf
[MAX_ATOM_LEN
+ 1];
966 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
968 if (count
<= 0) return 0;
970 ret
= GlobalGetAtomNameA( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
973 ret
= min(count
- 1, ret
);
974 memcpy(buffer
, tmpbuf
, ret
);
981 /***********************************************************************
982 * GetClassNameW (USER32.@)
984 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
986 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
989 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
991 if (count
<= 0) return 0;
993 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
996 ret
= min(count
- 1, ret
);
997 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1004 /***********************************************************************
1005 * RealGetWindowClassA (USER32.@)
1007 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1009 return GetClassNameA( hwnd
, buffer
, count
);
1013 /***********************************************************************
1014 * RealGetWindowClassW (USER32.@)
1016 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1018 return GetClassNameW( hwnd
, buffer
, count
);
1022 /***********************************************************************
1023 * GetClassInfoA (USER32.@)
1025 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1028 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1032 wc
->style
= wcex
.style
;
1033 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1034 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1035 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1036 wc
->hInstance
= wcex
.hInstance
;
1037 wc
->hIcon
= wcex
.hIcon
;
1038 wc
->hCursor
= wcex
.hCursor
;
1039 wc
->hbrBackground
= wcex
.hbrBackground
;
1040 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1041 wc
->lpszClassName
= wcex
.lpszClassName
;
1047 /***********************************************************************
1048 * GetClassInfoW (USER32.@)
1050 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1053 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1057 wc
->style
= wcex
.style
;
1058 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1059 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1060 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1061 wc
->hInstance
= wcex
.hInstance
;
1062 wc
->hIcon
= wcex
.hIcon
;
1063 wc
->hCursor
= wcex
.hCursor
;
1064 wc
->hbrBackground
= wcex
.hbrBackground
;
1065 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1066 wc
->lpszClassName
= wcex
.lpszClassName
;
1072 /***********************************************************************
1073 * GetClassInfoExA (USER32.@)
1075 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1077 ATOM atom
= HIWORD(name
) ? GlobalFindAtomA( name
) : LOWORD(name
);
1080 TRACE("%p %s %x %p\n", hInstance
, debugstr_a(name
), atom
, wc
);
1082 if (!hInstance
) hInstance
= user32_module
;
1084 if (!atom
|| !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
1086 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1089 wc
->style
= classPtr
->style
;
1090 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1091 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1092 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1093 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1094 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1095 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1096 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1097 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1098 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1099 wc
->lpszClassName
= name
;
1100 release_class_ptr( classPtr
);
1102 /* We must return the atom of the class here instead of just TRUE. */
1107 /***********************************************************************
1108 * GetClassInfoExW (USER32.@)
1110 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1112 ATOM atom
= HIWORD(name
) ? GlobalFindAtomW( name
) : LOWORD(name
);
1115 TRACE("%p %s %x %p\n", hInstance
, debugstr_w(name
), atom
, wc
);
1117 if (!hInstance
) hInstance
= user32_module
;
1119 if (!atom
|| !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
1121 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1124 wc
->style
= classPtr
->style
;
1125 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1126 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1127 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1128 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1129 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1130 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1131 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1132 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1133 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1134 wc
->lpszClassName
= name
;
1135 release_class_ptr( classPtr
);
1137 /* We must return the atom of the class here instead of just TRUE. */
1142 #if 0 /* toolhelp is in kernel, so this cannot work */
1144 /***********************************************************************
1145 * ClassFirst (TOOLHELP.69)
1147 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1149 TRACE("%p\n",pClassEntry
);
1150 pClassEntry
->wNext
= 1;
1151 return ClassNext16( pClassEntry
);
1155 /***********************************************************************
1156 * ClassNext (TOOLHELP.70)
1158 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1161 CLASS
*class = firstClass
;
1163 TRACE("%p\n",pClassEntry
);
1165 if (!pClassEntry
->wNext
) return FALSE
;
1166 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1169 pClassEntry
->wNext
= 0;
1172 pClassEntry
->hInst
= class->hInstance
;
1173 pClassEntry
->wNext
++;
1174 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1175 sizeof(pClassEntry
->szClassName
) );
1180 /* 64bit versions */
1182 #ifdef GetClassLongPtrA
1183 #undef GetClassLongPtrA
1186 #ifdef GetClassLongPtrW
1187 #undef GetClassLongPtrW
1190 #ifdef SetClassLongPtrA
1191 #undef SetClassLongPtrA
1194 #ifdef SetClassLongPtrW
1195 #undef SetClassLongPtrW
1198 /***********************************************************************
1199 * GetClassLongPtrA (USER32.@)
1201 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1203 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1206 /***********************************************************************
1207 * GetClassLongPtrW (USER32.@)
1209 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1211 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1214 /***********************************************************************
1215 * SetClassLongPtrW (USER32.@)
1217 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1219 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1222 /***********************************************************************
1223 * SetClassLongPtrA (USER32.@)
1225 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1227 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);