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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
34 #include "wine/winuser16.h"
35 #include "wine/unicode.h"
37 #include "user_private.h"
41 #include "wine/server.h"
42 #include "wine/list.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(class);
47 typedef struct tagCLASS
49 struct list entry
; /* Entry in class list */
50 UINT style
; /* Class style */
51 BOOL local
; /* Local class? */
52 WNDPROC winprocA
; /* Window procedure (ASCII) */
53 WNDPROC winprocW
; /* Window procedure (Unicode) */
54 INT cbClsExtra
; /* Class extra bytes */
55 INT cbWndExtra
; /* Window extra bytes */
56 LPWSTR menuName
; /* Default menu name (Unicode followed by ASCII) */
57 SEGPTR segMenuName
; /* Default menu name as SEGPTR */
58 struct tagDCE
*dce
; /* Class DCE (if CS_CLASSDC) */
59 HINSTANCE hInstance
; /* Module that created the task */
60 HICON hIcon
; /* Default icon */
61 HICON hIconSm
; /* Default small icon */
62 HCURSOR hCursor
; /* Default cursor */
63 HBRUSH hbrBackground
; /* Default background */
64 ATOM atomName
; /* Name of the class */
67 static struct list class_list
= LIST_INIT( class_list
);
68 static CLASS
*desktop_class
;
70 #define CLASS_OTHER_PROCESS ((CLASS *)1)
72 /***********************************************************************
75 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
77 WND
*ptr
= WIN_GetPtr( hwnd
);
81 if (ptr
!= WND_OTHER_PROCESS
) return ptr
->class;
82 if (write_access
&& IsWindow( hwnd
)) /* check other processes */
84 /* modifying classes in other processes is not allowed */
85 SetLastError( ERROR_ACCESS_DENIED
);
88 return CLASS_OTHER_PROCESS
;
90 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
95 /***********************************************************************
98 inline static void release_class_ptr( CLASS
*ptr
)
104 /***********************************************************************
107 * Set class info with the wine server.
109 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG newval
)
113 SERVER_START_REQ( set_class_info
)
116 req
->extra_offset
= -1;
120 req
->flags
= SET_CLASS_ATOM
;
123 req
->flags
= SET_CLASS_STYLE
;
127 req
->flags
= SET_CLASS_WINEXTRA
;
128 req
->win_extra
= newval
;
131 req
->flags
= SET_CLASS_INSTANCE
;
132 req
->instance
= (void *)newval
;
135 assert( offset
>= 0 );
136 req
->flags
= SET_CLASS_EXTRA
;
137 req
->extra_offset
= offset
;
138 req
->extra_size
= sizeof(newval
);
139 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
142 ret
= !wine_server_call_err( req
);
149 /***********************************************************************
152 * Get the class winproc for a given proc type
154 static WNDPROC16
CLASS_GetProc( CLASS
*classPtr
, WINDOWPROCTYPE type
)
156 WNDPROC proc
= classPtr
->winprocA
;
158 if (classPtr
->winprocW
)
160 /* if we have a Unicode proc, use it if we have no ASCII proc
161 * or if we have both and Unicode was requested
163 if (!proc
|| type
== WIN_PROC_32W
) proc
= classPtr
->winprocW
;
165 return WINPROC_GetProc( proc
, type
);
169 /***********************************************************************
172 * Set the class winproc for a given proc type.
173 * Returns the previous window proc.
175 static WNDPROC16
CLASS_SetProc( CLASS
*classPtr
, WNDPROC newproc
, WINDOWPROCTYPE type
)
177 WNDPROC
*proc
= &classPtr
->winprocA
;
180 if (classPtr
->winprocW
)
182 /* if we have a Unicode proc, use it if we have no ASCII proc
183 * or if we have both and Unicode was requested
185 if (!*proc
|| type
== WIN_PROC_32W
) proc
= &classPtr
->winprocW
;
187 ret
= WINPROC_GetProc( *proc
, type
);
188 *proc
= WINPROC_AllocProc( newproc
, type
);
189 /* now clear the one that we didn't set */
190 if (classPtr
->winprocA
&& classPtr
->winprocW
)
192 if (proc
== &classPtr
->winprocA
)
193 classPtr
->winprocW
= 0;
195 classPtr
->winprocA
= 0;
201 /***********************************************************************
204 * Get the menu name as a ASCII string.
206 inline static LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
208 if (!HIWORD(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
209 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
213 /***********************************************************************
214 * CLASS_GetMenuName16
216 * Get the menu name as a SEGPTR.
218 inline static SEGPTR
CLASS_GetMenuName16( CLASS
*classPtr
)
220 if (!HIWORD(classPtr
->menuName
)) return (SEGPTR
)classPtr
->menuName
;
221 if (!classPtr
->segMenuName
)
222 classPtr
->segMenuName
= MapLS( CLASS_GetMenuNameA(classPtr
) );
223 return classPtr
->segMenuName
;
227 /***********************************************************************
230 * Get the menu name as a Unicode string.
232 inline static LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
234 return classPtr
->menuName
;
238 /***********************************************************************
241 * Set the menu name in a class structure by copying the string.
243 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
245 UnMapLS( classPtr
->segMenuName
);
246 classPtr
->segMenuName
= 0;
247 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
250 DWORD lenA
= strlen(name
) + 1;
251 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
252 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
253 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
254 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
256 else classPtr
->menuName
= (LPWSTR
)name
;
260 /***********************************************************************
263 * Set the menu name in a class structure by copying the string.
265 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
267 UnMapLS( classPtr
->segMenuName
);
268 classPtr
->segMenuName
= 0;
269 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
272 DWORD lenW
= strlenW(name
) + 1;
273 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
274 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
275 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
276 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
277 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
279 else classPtr
->menuName
= (LPWSTR
)name
;
283 /***********************************************************************
286 * Free a class structure.
288 static void CLASS_FreeClass( CLASS
*classPtr
)
290 TRACE("%p\n", classPtr
);
294 list_remove( &classPtr
->entry
);
295 if (classPtr
->dce
) DCE_FreeDCE( classPtr
->dce
);
296 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
297 DeleteObject( classPtr
->hbrBackground
);
298 UnMapLS( classPtr
->segMenuName
);
299 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
300 HeapFree( GetProcessHeap(), 0, classPtr
);
305 /***********************************************************************
306 * CLASS_FreeModuleClasses
308 void CLASS_FreeModuleClasses( HMODULE16 hModule
)
310 struct list
*ptr
, *next
;
312 TRACE("0x%08x\n", hModule
);
315 for (ptr
= list_head( &class_list
); ptr
; ptr
= next
)
317 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
318 next
= list_next( &class_list
, ptr
);
319 if (class->hInstance
== HINSTANCE_32(hModule
))
323 SERVER_START_REQ( destroy_class
)
325 req
->atom
= class->atomName
;
326 req
->instance
= class->hInstance
;
327 ret
= !wine_server_call_err( req
);
330 if (ret
) CLASS_FreeClass( class );
337 /***********************************************************************
338 * CLASS_FindClassByAtom
340 * Return a pointer to the class.
341 * hinstance has been normalized by the caller.
343 static CLASS
*CLASS_FindClassByAtom( ATOM atom
, HINSTANCE hinstance
)
349 LIST_FOR_EACH( ptr
, &class_list
)
351 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
352 if (class->atomName
!= atom
) continue;
353 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
355 TRACE("0x%04x %p -> %p\n", atom
, hinstance
, class);
360 TRACE("0x%04x %p -> not found\n", atom
, hinstance
);
365 /***********************************************************************
366 * CLASS_RegisterClass
368 * The real RegisterClass() functionality.
369 * The atom is deleted no matter what.
371 static CLASS
*CLASS_RegisterClass( ATOM atom
, HINSTANCE hInstance
, BOOL local
,
372 DWORD style
, INT classExtra
, INT winExtra
)
377 TRACE("atom=0x%x hinst=%p style=0x%lx clExtr=0x%x winExtr=0x%x\n",
378 atom
, hInstance
, style
, classExtra
, winExtra
);
380 /* Fix the extra bytes value */
382 if (classExtra
< 0) classExtra
= 0;
383 else if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
384 WARN("Class extra bytes %d is > 40\n", classExtra
);
385 if (winExtra
< 0) winExtra
= 0;
386 else if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
387 WARN("Win extra bytes %d is > 40\n", winExtra
);
389 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
392 GlobalDeleteAtom( atom
);
396 SERVER_START_REQ( create_class
)
401 req
->instance
= hInstance
;
402 req
->extra
= classExtra
;
403 req
->win_extra
= winExtra
;
404 req
->client_ptr
= classPtr
;
405 ret
= !wine_server_call_err( req
);
408 GlobalDeleteAtom( atom
); /* the server increased the atom ref count */
411 HeapFree( GetProcessHeap(), 0, classPtr
);
415 classPtr
->style
= style
;
416 classPtr
->local
= local
;
417 classPtr
->cbWndExtra
= winExtra
;
418 classPtr
->cbClsExtra
= classExtra
;
419 classPtr
->hInstance
= hInstance
;
420 classPtr
->atomName
= atom
;
421 classPtr
->dce
= (style
& CS_CLASSDC
) ? DCE_AllocDCE( 0, DCE_CLASS_DC
) : NULL
;
423 /* Other non-null values must be set by caller */
426 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
427 else list_add_tail( &class_list
, &classPtr
->entry
);
432 /***********************************************************************
435 * Register a builtin control class.
436 * This allows having both ASCII and Unicode winprocs for the same class.
438 static CLASS
*register_builtin( const struct builtin_class_descr
*descr
)
443 if (!(atom
= GlobalAddAtomA( descr
->name
))) return 0;
445 if (!(classPtr
= CLASS_RegisterClass( atom
, user32_module
, FALSE
,
446 descr
->style
, 0, descr
->extra
))) return 0;
448 classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
449 classPtr
->hbrBackground
= descr
->brush
;
451 if (descr
->procA
) classPtr
->winprocA
= WINPROC_AllocProc( descr
->procA
, WIN_PROC_32A
);
452 if (descr
->procW
) classPtr
->winprocW
= WINPROC_AllocProc( descr
->procW
, WIN_PROC_32W
);
453 release_class_ptr( classPtr
);
458 /***********************************************************************
459 * CLASS_RegisterBuiltinClasses
461 void CLASS_RegisterBuiltinClasses(void)
463 extern const struct builtin_class_descr BUTTON_builtin_class
;
464 extern const struct builtin_class_descr COMBO_builtin_class
;
465 extern const struct builtin_class_descr COMBOLBOX_builtin_class
;
466 extern const struct builtin_class_descr DIALOG_builtin_class
;
467 extern const struct builtin_class_descr DESKTOP_builtin_class
;
468 extern const struct builtin_class_descr EDIT_builtin_class
;
469 extern const struct builtin_class_descr ICONTITLE_builtin_class
;
470 extern const struct builtin_class_descr LISTBOX_builtin_class
;
471 extern const struct builtin_class_descr MDICLIENT_builtin_class
;
472 extern const struct builtin_class_descr MENU_builtin_class
;
473 extern const struct builtin_class_descr SCROLL_builtin_class
;
474 extern const struct builtin_class_descr STATIC_builtin_class
;
476 desktop_class
= register_builtin( &DESKTOP_builtin_class
);
477 register_builtin( &BUTTON_builtin_class
);
478 register_builtin( &COMBO_builtin_class
);
479 register_builtin( &COMBOLBOX_builtin_class
);
480 register_builtin( &DIALOG_builtin_class
);
481 register_builtin( &EDIT_builtin_class
);
482 register_builtin( &ICONTITLE_builtin_class
);
483 register_builtin( &LISTBOX_builtin_class
);
484 register_builtin( &MDICLIENT_builtin_class
);
485 register_builtin( &MENU_builtin_class
);
486 register_builtin( &SCROLL_builtin_class
);
487 register_builtin( &STATIC_builtin_class
);
491 /***********************************************************************
494 * Add a new window using this class, and set the necessary
495 * information inside the window structure.
497 void CLASS_AddWindow( CLASS
*class, WND
*win
, WINDOWPROCTYPE type
)
499 if (!class) class = desktop_class
;
501 if (type
== WIN_PROC_32W
)
503 if (!(win
->winproc
= class->winprocW
)) win
->winproc
= class->winprocA
;
507 if (!(win
->winproc
= class->winprocA
)) win
->winproc
= class->winprocW
;
510 win
->clsStyle
= class->style
;
511 win
->dce
= class->dce
;
515 /***********************************************************************
516 * RegisterClassA (USER32.@)
518 * >0: Unique identifier
521 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
525 wcex
.cbSize
= sizeof(wcex
);
526 wcex
.style
= wc
->style
;
527 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
528 wcex
.cbClsExtra
= wc
->cbClsExtra
;
529 wcex
.cbWndExtra
= wc
->cbWndExtra
;
530 wcex
.hInstance
= wc
->hInstance
;
531 wcex
.hIcon
= wc
->hIcon
;
532 wcex
.hCursor
= wc
->hCursor
;
533 wcex
.hbrBackground
= wc
->hbrBackground
;
534 wcex
.lpszMenuName
= wc
->lpszMenuName
;
535 wcex
.lpszClassName
= wc
->lpszClassName
;
537 return RegisterClassExA( &wcex
);
541 /***********************************************************************
542 * RegisterClassW (USER32.@)
544 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
548 wcex
.cbSize
= sizeof(wcex
);
549 wcex
.style
= wc
->style
;
550 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
551 wcex
.cbClsExtra
= wc
->cbClsExtra
;
552 wcex
.cbWndExtra
= wc
->cbWndExtra
;
553 wcex
.hInstance
= wc
->hInstance
;
554 wcex
.hIcon
= wc
->hIcon
;
555 wcex
.hCursor
= wc
->hCursor
;
556 wcex
.hbrBackground
= wc
->hbrBackground
;
557 wcex
.lpszMenuName
= wc
->lpszMenuName
;
558 wcex
.lpszClassName
= wc
->lpszClassName
;
560 return RegisterClassExW( &wcex
);
564 /***********************************************************************
565 * RegisterClassExA (USER32.@)
567 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
573 if (wc
->hInstance
== user32_module
)
575 /* we can't register a class for user32 */
576 SetLastError( ERROR_INVALID_PARAMETER
);
579 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
581 if (!(atom
= GlobalAddAtomA( wc
->lpszClassName
))) return 0;
583 if (!(classPtr
= CLASS_RegisterClass( atom
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
584 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
587 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
588 atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
589 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
591 classPtr
->hIcon
= wc
->hIcon
;
592 classPtr
->hIconSm
= wc
->hIconSm
;
593 classPtr
->hCursor
= wc
->hCursor
;
594 classPtr
->hbrBackground
= wc
->hbrBackground
;
595 classPtr
->winprocA
= WINPROC_AllocProc( wc
->lpfnWndProc
, WIN_PROC_32A
);
596 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
597 release_class_ptr( classPtr
);
602 /***********************************************************************
603 * RegisterClassExW (USER32.@)
605 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
611 if (wc
->hInstance
== user32_module
)
613 /* we can't register a class for user32 */
614 SetLastError( ERROR_INVALID_PARAMETER
);
617 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
619 if (!(atom
= GlobalAddAtomW( wc
->lpszClassName
))) return 0;
621 if (!(classPtr
= CLASS_RegisterClass( atom
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
622 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
625 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
626 atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
627 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
629 classPtr
->hIcon
= wc
->hIcon
;
630 classPtr
->hIconSm
= wc
->hIconSm
;
631 classPtr
->hCursor
= wc
->hCursor
;
632 classPtr
->hbrBackground
= wc
->hbrBackground
;
633 classPtr
->winprocW
= WINPROC_AllocProc( wc
->lpfnWndProc
, WIN_PROC_32W
);
634 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
635 release_class_ptr( classPtr
);
640 /***********************************************************************
641 * UnregisterClassA (USER32.@)
643 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
645 ATOM atom
= HIWORD(className
) ? GlobalFindAtomA( className
) : LOWORD(className
);
646 return UnregisterClassW( MAKEINTATOMW(atom
), hInstance
);
649 /***********************************************************************
650 * UnregisterClassW (USER32.@)
652 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
654 CLASS
*classPtr
= NULL
;
655 ATOM atom
= HIWORD(className
) ? GlobalFindAtomW( className
) : LOWORD(className
);
657 TRACE("%s %p %x\n",debugstr_w(className
), hInstance
, atom
);
661 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
665 SERVER_START_REQ( destroy_class
)
668 req
->instance
= hInstance
;
669 if (!wine_server_call_err( req
)) classPtr
= reply
->client_ptr
;
673 if (classPtr
) CLASS_FreeClass( classPtr
);
674 return (classPtr
!= NULL
);
678 /***********************************************************************
679 * GetClassWord (USER32.@)
681 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
686 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
688 TRACE("%p %x\n",hwnd
, offset
);
690 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
692 if (class == CLASS_OTHER_PROCESS
)
694 SERVER_START_REQ( set_class_info
)
698 req
->extra_offset
= offset
;
699 req
->extra_size
= sizeof(retvalue
);
700 if (!wine_server_call_err( req
))
701 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
707 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
708 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
710 SetLastError( ERROR_INVALID_INDEX
);
711 release_class_ptr( class );
716 /***********************************************************************
717 * GetClassLong (USER.131)
719 LONG WINAPI
GetClassLong16( HWND16 hwnd16
, INT16 offset
)
723 HWND hwnd
= (HWND
)(ULONG_PTR
)hwnd16
; /* no need for full handle */
725 TRACE("%p %d\n",hwnd
, offset
);
730 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
731 if (class == CLASS_OTHER_PROCESS
) break;
732 ret
= (LONG
)CLASS_GetProc( class, WIN_PROC_16
);
733 release_class_ptr( class );
736 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
737 if (class == CLASS_OTHER_PROCESS
) break;
738 ret
= (LONG
)CLASS_GetMenuName16( class );
739 release_class_ptr( class );
742 return GetClassLongA( hwnd
, offset
);
744 FIXME( "offset %d not supported on other process window %p\n", offset
, hwnd
);
745 SetLastError( ERROR_INVALID_HANDLE
);
750 /***********************************************************************
751 * GetClassLongW (USER32.@)
753 LONG WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
758 TRACE("%p %d\n", hwnd
, offset
);
760 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
762 if (class == CLASS_OTHER_PROCESS
)
764 SERVER_START_REQ( set_class_info
)
768 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
769 req
->extra_size
= (offset
>= 0) ? sizeof(retvalue
) : 0;
770 if (!wine_server_call_err( req
))
774 case GCL_HBRBACKGROUND
:
780 FIXME( "offset %d not supported on other process window %p\n", offset
, hwnd
);
781 SetLastError( ERROR_INVALID_HANDLE
);
784 retvalue
= reply
->old_style
;
787 retvalue
= reply
->old_win_extra
;
790 retvalue
= reply
->old_extra
;
793 retvalue
= (LONG
)reply
->old_instance
;
796 retvalue
= reply
->old_atom
;
799 if (offset
>= 0) memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
800 else SetLastError( ERROR_INVALID_INDEX
);
811 if (offset
<= class->cbClsExtra
- sizeof(LONG
))
812 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
814 SetLastError( ERROR_INVALID_INDEX
);
815 release_class_ptr( class );
821 case GCL_HBRBACKGROUND
:
822 retvalue
= (LONG
)class->hbrBackground
;
825 retvalue
= (LONG
)class->hCursor
;
828 retvalue
= (LONG
)class->hIcon
;
831 retvalue
= (LONG
)class->hIconSm
;
834 retvalue
= (LONG
)class->style
;
837 retvalue
= (LONG
)class->cbWndExtra
;
840 retvalue
= (LONG
)class->cbClsExtra
;
843 retvalue
= (LONG
)class->hInstance
;
846 retvalue
= (LONG
)CLASS_GetProc( class, WIN_PROC_32W
);
849 retvalue
= (LONG
)CLASS_GetMenuNameW( class );
852 retvalue
= (DWORD
)class->atomName
;
855 SetLastError( ERROR_INVALID_INDEX
);
858 release_class_ptr( class );
863 /***********************************************************************
864 * GetClassLongA (USER32.@)
866 LONG WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
871 if (offset
!= GCL_WNDPROC
&& offset
!= GCL_MENUNAME
)
872 return GetClassLongW( hwnd
, offset
);
874 TRACE("%p %d\n", hwnd
, offset
);
876 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
878 if (class == CLASS_OTHER_PROCESS
)
880 FIXME( "offset %d not supported on other process window %p\n", offset
, hwnd
);
881 SetLastError( ERROR_INVALID_HANDLE
);
885 if (offset
== GCL_WNDPROC
)
886 retvalue
= (LONG
)CLASS_GetProc( class, WIN_PROC_32A
);
887 else /* GCL_MENUNAME */
888 retvalue
= (LONG
)CLASS_GetMenuNameA( class );
890 release_class_ptr( class );
895 /***********************************************************************
896 * SetClassWord (USER32.@)
898 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
903 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
905 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
907 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
909 SERVER_START_REQ( set_class_info
)
912 req
->flags
= SET_CLASS_EXTRA
;
913 req
->extra_offset
= offset
;
914 req
->extra_size
= sizeof(newval
);
915 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
916 if (!wine_server_call_err( req
))
918 void *ptr
= (char *)(class + 1) + offset
;
919 memcpy( &retval
, ptr
, sizeof(retval
) );
920 memcpy( ptr
, &newval
, sizeof(newval
) );
924 release_class_ptr( class );
929 /***********************************************************************
930 * SetClassLong (USER.132)
932 LONG WINAPI
SetClassLong16( HWND16 hwnd16
, INT16 offset
, LONG newval
)
936 HWND hwnd
= (HWND
)(ULONG_PTR
)hwnd16
; /* no need for full handle */
938 TRACE("%p %d %lx\n", hwnd
, offset
, newval
);
943 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
944 retval
= (LONG
)CLASS_SetProc( class, (WNDPROC
)newval
, WIN_PROC_16
);
945 release_class_ptr( class );
948 newval
= (LONG
)MapSL( newval
);
951 return SetClassLongA( hwnd
, offset
, newval
);
956 /***********************************************************************
957 * SetClassLongW (USER32.@)
959 LONG WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
964 TRACE("%p %d %lx\n", hwnd
, offset
, newval
);
966 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
970 if (set_server_info( hwnd
, offset
, newval
))
972 void *ptr
= (char *)(class + 1) + offset
;
973 memcpy( &retval
, ptr
, sizeof(retval
) );
974 memcpy( ptr
, &newval
, sizeof(newval
) );
980 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
981 retval
= 0; /* Old value is now meaningless anyway */
984 retval
= (LONG
)CLASS_SetProc( class, (WNDPROC
)newval
, WIN_PROC_32W
);
986 case GCL_HBRBACKGROUND
:
987 retval
= (LONG
)class->hbrBackground
;
988 class->hbrBackground
= (HBRUSH
)newval
;
991 retval
= (LONG
)class->hCursor
;
992 class->hCursor
= (HCURSOR
)newval
;
995 retval
= (LONG
)class->hIcon
;
996 class->hIcon
= (HICON
)newval
;
999 retval
= (LONG
)class->hIconSm
;
1000 class->hIconSm
= (HICON
)newval
;
1003 if (!set_server_info( hwnd
, offset
, newval
)) break;
1004 retval
= (LONG
)class->style
;
1005 class->style
= newval
;
1007 case GCL_CBWNDEXTRA
:
1008 if (!set_server_info( hwnd
, offset
, newval
)) break;
1009 retval
= (LONG
)class->cbWndExtra
;
1010 class->cbWndExtra
= newval
;
1013 if (!set_server_info( hwnd
, offset
, newval
)) break;
1014 retval
= (LONG
)class->hInstance
;
1015 class->hInstance
= (HINSTANCE
)newval
;
1018 if (!set_server_info( hwnd
, offset
, newval
)) break;
1019 retval
= (DWORD
)class->atomName
;
1020 class->atomName
= newval
;
1022 case GCL_CBCLSEXTRA
: /* cannot change this one */
1023 SetLastError( ERROR_INVALID_PARAMETER
);
1026 SetLastError( ERROR_INVALID_INDEX
);
1029 release_class_ptr( class );
1034 /***********************************************************************
1035 * SetClassLongA (USER32.@)
1037 LONG WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
1042 if (offset
!= GCL_WNDPROC
&& offset
!= GCL_MENUNAME
)
1043 return SetClassLongW( hwnd
, offset
, newval
);
1045 TRACE("%p %d %lx\n", hwnd
, offset
, newval
);
1047 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
1049 if (offset
== GCL_WNDPROC
)
1050 retval
= (LONG
)CLASS_SetProc( class, (WNDPROC
)newval
, WIN_PROC_32A
);
1051 else /* GCL_MENUNAME */
1053 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
1054 retval
= 0; /* Old value is now meaningless anyway */
1056 release_class_ptr( class );
1061 /***********************************************************************
1062 * GetClassNameA (USER32.@)
1064 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
1066 INT ret
= GlobalGetAtomNameA( GetClassLongA( hwnd
, GCW_ATOM
), buffer
, count
);
1068 TRACE("%p %s %x\n",hwnd
, debugstr_a(buffer
), count
);
1073 /***********************************************************************
1074 * GetClassNameW (USER32.@)
1076 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
1078 INT ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), buffer
, count
);
1080 TRACE("%p %s %x\n",hwnd
, debugstr_w(buffer
), count
);
1085 /***********************************************************************
1086 * RealGetWindowClassA (USER32.@)
1088 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1090 return GetClassNameA( hwnd
, buffer
, count
);
1094 /***********************************************************************
1095 * RealGetWindowClassW (USER32.@)
1097 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1099 return GetClassNameW( hwnd
, buffer
, count
);
1103 /***********************************************************************
1104 * GetClassInfoA (USER32.@)
1106 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1109 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1113 wc
->style
= wcex
.style
;
1114 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1115 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1116 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1117 wc
->hInstance
= wcex
.hInstance
;
1118 wc
->hIcon
= wcex
.hIcon
;
1119 wc
->hCursor
= wcex
.hCursor
;
1120 wc
->hbrBackground
= wcex
.hbrBackground
;
1121 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1122 wc
->lpszClassName
= wcex
.lpszClassName
;
1128 /***********************************************************************
1129 * GetClassInfoW (USER32.@)
1131 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1134 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1138 wc
->style
= wcex
.style
;
1139 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1140 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1141 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1142 wc
->hInstance
= wcex
.hInstance
;
1143 wc
->hIcon
= wcex
.hIcon
;
1144 wc
->hCursor
= wcex
.hCursor
;
1145 wc
->hbrBackground
= wcex
.hbrBackground
;
1146 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1147 wc
->lpszClassName
= wcex
.lpszClassName
;
1153 /***********************************************************************
1154 * GetClassInfoExA (USER32.@)
1156 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1158 ATOM atom
= HIWORD(name
) ? GlobalFindAtomA( name
) : LOWORD(name
);
1161 TRACE("%p %s %x %p\n", hInstance
, debugstr_a(name
), atom
, wc
);
1163 if (!hInstance
) hInstance
= user32_module
;
1165 if (!atom
|| !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
1167 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1170 wc
->style
= classPtr
->style
;
1171 wc
->lpfnWndProc
= (WNDPROC
)CLASS_GetProc( classPtr
, WIN_PROC_32A
);
1172 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1173 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1174 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1175 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1176 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1177 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1178 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1179 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1180 wc
->lpszClassName
= name
;
1181 release_class_ptr( classPtr
);
1183 /* We must return the atom of the class here instead of just TRUE. */
1188 /***********************************************************************
1189 * GetClassInfoExW (USER32.@)
1191 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1193 ATOM atom
= HIWORD(name
) ? GlobalFindAtomW( name
) : LOWORD(name
);
1196 TRACE("%p %s %x %p\n", hInstance
, debugstr_w(name
), atom
, wc
);
1198 if (!hInstance
) hInstance
= user32_module
;
1200 if (!atom
|| !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
1202 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1205 wc
->style
= classPtr
->style
;
1206 wc
->lpfnWndProc
= (WNDPROC
)CLASS_GetProc( classPtr
, WIN_PROC_32W
);
1207 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1208 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1209 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1210 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1211 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1212 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1213 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1214 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1215 wc
->lpszClassName
= name
;
1216 release_class_ptr( classPtr
);
1218 /* We must return the atom of the class here instead of just TRUE. */
1223 #if 0 /* toolhelp is in kernel, so this cannot work */
1225 /***********************************************************************
1226 * ClassFirst (TOOLHELP.69)
1228 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1230 TRACE("%p\n",pClassEntry
);
1231 pClassEntry
->wNext
= 1;
1232 return ClassNext16( pClassEntry
);
1236 /***********************************************************************
1237 * ClassNext (TOOLHELP.70)
1239 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1242 CLASS
*class = firstClass
;
1244 TRACE("%p\n",pClassEntry
);
1246 if (!pClassEntry
->wNext
) return FALSE
;
1247 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1250 pClassEntry
->wNext
= 0;
1253 pClassEntry
->hInst
= class->hInstance
;
1254 pClassEntry
->wNext
++;
1255 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1256 sizeof(pClassEntry
->szClassName
) );