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 typedef struct tagCLASS
46 struct list entry
; /* Entry in class list */
47 UINT style
; /* Class style */
48 BOOL local
; /* Local class? */
49 WNDPROC winproc
; /* Window procedure */
50 INT cbClsExtra
; /* Class extra bytes */
51 INT cbWndExtra
; /* Window extra bytes */
52 LPWSTR menuName
; /* Default menu name (Unicode followed by ASCII) */
53 HINSTANCE hInstance
; /* Module that created the task */
54 HICON hIcon
; /* Default icon */
55 HICON hIconSm
; /* Default small icon */
56 HCURSOR hCursor
; /* Default cursor */
57 HBRUSH hbrBackground
; /* Default background */
58 ATOM atomName
; /* Name of the class */
61 static struct list class_list
= LIST_INIT( class_list
);
63 #define CLASS_OTHER_PROCESS ((CLASS *)1)
64 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
66 /***********************************************************************
69 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
71 WND
*ptr
= WIN_GetPtr( hwnd
);
75 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
) return ptr
->class;
76 if (!write_access
) return CLASS_OTHER_PROCESS
;
78 /* modifying classes in other processes is not allowed */
79 if (ptr
== WND_DESKTOP
|| IsWindow( hwnd
))
81 SetLastError( ERROR_ACCESS_DENIED
);
85 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
90 /***********************************************************************
93 static inline void release_class_ptr( CLASS
*ptr
)
99 /***********************************************************************
102 static ATOM
get_int_atom_value( LPCWSTR name
)
106 if (IS_INTRESOURCE(name
)) return LOWORD(name
);
107 if (*name
++ != '#') return 0;
110 if (*name
< '0' || *name
> '9') return 0;
111 ret
= ret
* 10 + *name
++ - '0';
112 if (ret
> 0xffff) return 0;
118 /***********************************************************************
121 * Set class info with the wine server.
123 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG_PTR newval
, UINT size
)
127 SERVER_START_REQ( set_class_info
)
130 req
->extra_offset
= -1;
134 req
->flags
= SET_CLASS_ATOM
;
137 req
->flags
= SET_CLASS_STYLE
;
141 req
->flags
= SET_CLASS_WINEXTRA
;
142 req
->win_extra
= newval
;
145 req
->flags
= SET_CLASS_INSTANCE
;
146 req
->instance
= (void *)newval
;
149 assert( offset
>= 0 );
150 req
->flags
= SET_CLASS_EXTRA
;
151 req
->extra_offset
= offset
;
152 req
->extra_size
= size
;
153 if ( size
== sizeof(LONG
) )
155 LONG newlong
= newval
;
156 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
159 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
162 ret
= !wine_server_call_err( req
);
169 /***********************************************************************
172 * Get the menu name as a ASCII string.
174 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
176 if (!HIWORD(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
177 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
181 /***********************************************************************
184 * Get the menu name as a Unicode string.
186 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
188 return classPtr
->menuName
;
192 /***********************************************************************
195 * Set the menu name in a class structure by copying the string.
197 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
199 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
202 DWORD lenA
= strlen(name
) + 1;
203 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
204 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
205 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
206 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
208 else classPtr
->menuName
= (LPWSTR
)name
;
212 /***********************************************************************
215 * Set the menu name in a class structure by copying the string.
217 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
219 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
222 DWORD lenW
= strlenW(name
) + 1;
223 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
224 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
225 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
226 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
227 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
229 else classPtr
->menuName
= (LPWSTR
)name
;
233 /***********************************************************************
236 * Free a class structure.
238 static void CLASS_FreeClass( CLASS
*classPtr
)
240 TRACE("%p\n", classPtr
);
244 list_remove( &classPtr
->entry
);
245 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
246 DeleteObject( classPtr
->hbrBackground
);
247 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
248 HeapFree( GetProcessHeap(), 0, classPtr
);
253 /***********************************************************************
254 * CLASS_FreeModuleClasses
256 void CLASS_FreeModuleClasses( HMODULE16 hModule
)
258 struct list
*ptr
, *next
;
260 TRACE("0x%08x\n", hModule
);
263 for (ptr
= list_head( &class_list
); ptr
; ptr
= next
)
265 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
266 next
= list_next( &class_list
, ptr
);
267 if (class->hInstance
== HINSTANCE_32(hModule
))
271 SERVER_START_REQ( destroy_class
)
273 req
->atom
= class->atomName
;
274 req
->instance
= class->hInstance
;
275 ret
= !wine_server_call_err( req
);
278 if (ret
) CLASS_FreeClass( class );
285 /***********************************************************************
286 * CLASS_FindClassByAtom
288 * Return a pointer to the class.
289 * hinstance has been normalized by the caller.
291 static CLASS
*CLASS_FindClassByAtom( ATOM atom
, HINSTANCE hinstance
)
297 LIST_FOR_EACH( ptr
, &class_list
)
299 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
300 if (class->atomName
!= atom
) continue;
301 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
303 TRACE("0x%04x %p -> %p\n", atom
, hinstance
, class);
308 TRACE("0x%04x %p -> not found\n", atom
, hinstance
);
313 /***********************************************************************
314 * CLASS_RegisterClass
316 * The real RegisterClass() functionality.
318 static CLASS
*CLASS_RegisterClass( LPCWSTR name
, HINSTANCE hInstance
, BOOL local
,
319 DWORD style
, INT classExtra
, INT winExtra
)
324 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
325 debugstr_w(name
), hInstance
, style
, classExtra
, winExtra
);
327 /* Fix the extra bytes value */
329 if (classExtra
< 0 || winExtra
< 0)
331 SetLastError( ERROR_INVALID_PARAMETER
);
334 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
335 WARN("Class extra bytes %d is > 40\n", classExtra
);
336 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
337 WARN("Win extra bytes %d is > 40\n", winExtra
);
339 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
340 if (!classPtr
) return NULL
;
342 SERVER_START_REQ( create_class
)
346 req
->instance
= hInstance
;
347 req
->extra
= classExtra
;
348 req
->win_extra
= winExtra
;
349 req
->client_ptr
= classPtr
;
350 if (!(req
->atom
= get_int_atom_value(name
)) && name
)
351 wine_server_add_data( req
, name
, strlenW(name
) * sizeof(WCHAR
) );
352 ret
= !wine_server_call_err( req
);
353 classPtr
->atomName
= reply
->atom
;
358 HeapFree( GetProcessHeap(), 0, classPtr
);
362 classPtr
->style
= style
;
363 classPtr
->local
= local
;
364 classPtr
->cbWndExtra
= winExtra
;
365 classPtr
->cbClsExtra
= classExtra
;
366 classPtr
->hInstance
= hInstance
;
368 /* Other non-null values must be set by caller */
371 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
372 else list_add_tail( &class_list
, &classPtr
->entry
);
377 /***********************************************************************
380 * Register a builtin control class.
381 * This allows having both ASCII and Unicode winprocs for the same class.
383 static WNDPROC
register_builtin( const struct builtin_class_descr
*descr
)
387 if (!(classPtr
= CLASS_RegisterClass( descr
->name
, user32_module
, FALSE
,
388 descr
->style
, 0, descr
->extra
))) return 0;
390 classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
391 classPtr
->hbrBackground
= descr
->brush
;
392 classPtr
->winproc
= WINPROC_AllocProc( descr
->procA
, descr
->procW
);
393 release_class_ptr( classPtr
);
394 return classPtr
->winproc
;
398 /***********************************************************************
399 * CLASS_RegisterBuiltinClasses
401 void CLASS_RegisterBuiltinClasses(void)
403 extern const struct builtin_class_descr BUTTON_builtin_class
;
404 extern const struct builtin_class_descr COMBO_builtin_class
;
405 extern const struct builtin_class_descr COMBOLBOX_builtin_class
;
406 extern const struct builtin_class_descr DIALOG_builtin_class
;
407 extern const struct builtin_class_descr DESKTOP_builtin_class
;
408 extern const struct builtin_class_descr EDIT_builtin_class
;
409 extern const struct builtin_class_descr ICONTITLE_builtin_class
;
410 extern const struct builtin_class_descr LISTBOX_builtin_class
;
411 extern const struct builtin_class_descr MDICLIENT_builtin_class
;
412 extern const struct builtin_class_descr MENU_builtin_class
;
413 extern const struct builtin_class_descr SCROLL_builtin_class
;
414 extern const struct builtin_class_descr STATIC_builtin_class
;
416 register_builtin( &DESKTOP_builtin_class
);
417 register_builtin( &BUTTON_builtin_class
);
418 register_builtin( &COMBO_builtin_class
);
419 register_builtin( &COMBOLBOX_builtin_class
);
420 register_builtin( &DIALOG_builtin_class
);
421 EDIT_winproc_handle
= register_builtin( &EDIT_builtin_class
);
422 register_builtin( &ICONTITLE_builtin_class
);
423 register_builtin( &LISTBOX_builtin_class
);
424 register_builtin( &MDICLIENT_builtin_class
);
425 register_builtin( &MENU_builtin_class
);
426 register_builtin( &SCROLL_builtin_class
);
427 register_builtin( &STATIC_builtin_class
);
429 /* the DefWindowProc winprocs are magic too */
430 WINPROC_AllocProc( DefWindowProcA
, DefWindowProcW
);
434 /***********************************************************************
437 * Add a new window using this class, and set the necessary
438 * information inside the window structure.
440 void CLASS_AddWindow( CLASS
*class, WND
*win
, BOOL unicode
)
443 win
->clsStyle
= class->style
;
444 win
->winproc
= class->winproc
;
445 if (WINPROC_IsUnicode( win
->winproc
, unicode
)) win
->flags
|= WIN_ISUNICODE
;
449 /***********************************************************************
450 * RegisterClassA (USER32.@)
452 * Register a window class.
455 * >0: Unique identifier
458 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
462 wcex
.cbSize
= sizeof(wcex
);
463 wcex
.style
= wc
->style
;
464 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
465 wcex
.cbClsExtra
= wc
->cbClsExtra
;
466 wcex
.cbWndExtra
= wc
->cbWndExtra
;
467 wcex
.hInstance
= wc
->hInstance
;
468 wcex
.hIcon
= wc
->hIcon
;
469 wcex
.hCursor
= wc
->hCursor
;
470 wcex
.hbrBackground
= wc
->hbrBackground
;
471 wcex
.lpszMenuName
= wc
->lpszMenuName
;
472 wcex
.lpszClassName
= wc
->lpszClassName
;
474 return RegisterClassExA( &wcex
);
478 /***********************************************************************
479 * RegisterClassW (USER32.@)
481 * See RegisterClassA.
483 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
487 wcex
.cbSize
= sizeof(wcex
);
488 wcex
.style
= wc
->style
;
489 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
490 wcex
.cbClsExtra
= wc
->cbClsExtra
;
491 wcex
.cbWndExtra
= wc
->cbWndExtra
;
492 wcex
.hInstance
= wc
->hInstance
;
493 wcex
.hIcon
= wc
->hIcon
;
494 wcex
.hCursor
= wc
->hCursor
;
495 wcex
.hbrBackground
= wc
->hbrBackground
;
496 wcex
.lpszMenuName
= wc
->lpszMenuName
;
497 wcex
.lpszClassName
= wc
->lpszClassName
;
499 return RegisterClassExW( &wcex
);
503 /***********************************************************************
504 * RegisterClassExA (USER32.@)
506 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
512 if (wc
->hInstance
== user32_module
)
514 /* we can't register a class for user32 */
515 SetLastError( ERROR_INVALID_PARAMETER
);
518 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
520 if (!IS_INTRESOURCE(wc
->lpszClassName
))
522 WCHAR name
[MAX_ATOM_LEN
+ 1];
524 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
525 classPtr
= CLASS_RegisterClass( name
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
526 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
530 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, instance
,
531 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
532 wc
->cbClsExtra
, wc
->cbWndExtra
);
534 if (!classPtr
) return 0;
535 atom
= classPtr
->atomName
;
537 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
538 debugstr_a(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
539 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
541 classPtr
->hIcon
= wc
->hIcon
;
542 classPtr
->hIconSm
= wc
->hIconSm
;
543 classPtr
->hCursor
= wc
->hCursor
;
544 classPtr
->hbrBackground
= wc
->hbrBackground
;
545 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, NULL
);
546 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
547 release_class_ptr( classPtr
);
552 /***********************************************************************
553 * RegisterClassExW (USER32.@)
555 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
561 if (wc
->hInstance
== user32_module
)
563 /* we can't register a class for user32 */
564 SetLastError( ERROR_INVALID_PARAMETER
);
567 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
569 if (!(classPtr
= CLASS_RegisterClass( wc
->lpszClassName
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
570 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
573 atom
= classPtr
->atomName
;
575 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
576 debugstr_w(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
577 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
579 classPtr
->hIcon
= wc
->hIcon
;
580 classPtr
->hIconSm
= wc
->hIconSm
;
581 classPtr
->hCursor
= wc
->hCursor
;
582 classPtr
->hbrBackground
= wc
->hbrBackground
;
583 classPtr
->winproc
= WINPROC_AllocProc( NULL
, wc
->lpfnWndProc
);
584 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
585 release_class_ptr( classPtr
);
590 /***********************************************************************
591 * UnregisterClassA (USER32.@)
593 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
595 if (!IS_INTRESOURCE(className
))
597 WCHAR name
[MAX_ATOM_LEN
+ 1];
599 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
601 return UnregisterClassW( name
, hInstance
);
603 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
606 /***********************************************************************
607 * UnregisterClassW (USER32.@)
609 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
611 CLASS
*classPtr
= NULL
;
613 TRACE("%s %p\n",debugstr_w(className
), hInstance
);
615 SERVER_START_REQ( destroy_class
)
617 req
->instance
= hInstance
;
618 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
619 wine_server_add_data( req
, className
, strlenW(className
) * sizeof(WCHAR
) );
620 if (!wine_server_call_err( req
)) classPtr
= reply
->client_ptr
;
624 if (classPtr
) CLASS_FreeClass( classPtr
);
625 return (classPtr
!= NULL
);
629 /***********************************************************************
630 * GetClassWord (USER32.@)
632 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
637 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
639 TRACE("%p %x\n",hwnd
, offset
);
641 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
643 if (class == CLASS_OTHER_PROCESS
)
645 SERVER_START_REQ( set_class_info
)
649 req
->extra_offset
= offset
;
650 req
->extra_size
= sizeof(retvalue
);
651 if (!wine_server_call_err( req
))
652 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
658 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
659 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
661 SetLastError( ERROR_INVALID_INDEX
);
662 release_class_ptr( class );
667 /***********************************************************************
670 * Implementation of GetClassLong(Ptr)A/W
672 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
676 ULONG_PTR retvalue
= 0;
678 TRACE("%p %d\n", hwnd
, offset
);
680 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
682 if (class == CLASS_OTHER_PROCESS
)
684 SERVER_START_REQ( set_class_info
)
688 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
689 req
->extra_size
= (offset
>= 0) ? size
: 0;
690 if (!wine_server_call_err( req
))
694 case GCLP_HBRBACKGROUND
:
700 FIXME( "offset %d (%s) not supported on other process window %p\n",
701 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
702 SetLastError( ERROR_INVALID_HANDLE
);
705 retvalue
= reply
->old_style
;
708 retvalue
= reply
->old_win_extra
;
711 retvalue
= reply
->old_extra
;
714 retvalue
= (ULONG_PTR
)reply
->old_instance
;
717 retvalue
= reply
->old_atom
;
722 if (size
== sizeof(DWORD
))
725 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
729 memcpy( &retvalue
, &reply
->old_extra_value
,
732 else SetLastError( ERROR_INVALID_INDEX
);
743 if (offset
<= class->cbClsExtra
- size
)
745 if (size
== sizeof(DWORD
))
748 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
752 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
755 SetLastError( ERROR_INVALID_INDEX
);
756 release_class_ptr( class );
762 case GCLP_HBRBACKGROUND
:
763 retvalue
= (ULONG_PTR
)class->hbrBackground
;
766 retvalue
= (ULONG_PTR
)class->hCursor
;
769 retvalue
= (ULONG_PTR
)class->hIcon
;
772 retvalue
= (ULONG_PTR
)class->hIconSm
;
775 retvalue
= class->style
;
778 retvalue
= class->cbWndExtra
;
781 retvalue
= class->cbClsExtra
;
784 retvalue
= (ULONG_PTR
)class->hInstance
;
787 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
790 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
792 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
794 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
797 retvalue
= class->atomName
;
800 SetLastError( ERROR_INVALID_INDEX
);
803 release_class_ptr( class );
808 /***********************************************************************
809 * GetClassLongW (USER32.@)
811 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
813 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
818 /***********************************************************************
819 * GetClassLongA (USER32.@)
821 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
823 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
827 /***********************************************************************
828 * SetClassWord (USER32.@)
830 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
835 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
837 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
839 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
841 SERVER_START_REQ( set_class_info
)
844 req
->flags
= SET_CLASS_EXTRA
;
845 req
->extra_offset
= offset
;
846 req
->extra_size
= sizeof(newval
);
847 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
848 if (!wine_server_call_err( req
))
850 void *ptr
= (char *)(class + 1) + offset
;
851 memcpy( &retval
, ptr
, sizeof(retval
) );
852 memcpy( ptr
, &newval
, sizeof(newval
) );
856 release_class_ptr( class );
861 /***********************************************************************
864 * Implementation of SetClassLong(Ptr)A/W
866 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
867 UINT size
, BOOL unicode
)
870 ULONG_PTR retval
= 0;
872 TRACE("%p %d %lx\n", hwnd
, offset
, newval
);
874 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
878 if (set_server_info( hwnd
, offset
, newval
, size
))
880 void *ptr
= (char *)(class + 1) + offset
;
881 if ( size
== sizeof(LONG
) )
884 LONG newlong
= newval
;
885 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
886 memcpy( ptr
, &newlong
, sizeof(LONG
) );
891 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
892 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
900 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
902 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
903 retval
= 0; /* Old value is now meaningless anyway */
906 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
907 class->winproc
= WINPROC_AllocProc( unicode
? NULL
: (WNDPROC
)newval
,
908 unicode
? (WNDPROC
)newval
: NULL
);
910 case GCLP_HBRBACKGROUND
:
911 retval
= (ULONG_PTR
)class->hbrBackground
;
912 class->hbrBackground
= (HBRUSH
)newval
;
915 retval
= (ULONG_PTR
)class->hCursor
;
916 class->hCursor
= (HCURSOR
)newval
;
919 retval
= (ULONG_PTR
)class->hIcon
;
920 class->hIcon
= (HICON
)newval
;
923 retval
= (ULONG_PTR
)class->hIconSm
;
924 class->hIconSm
= (HICON
)newval
;
927 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
928 retval
= class->style
;
929 class->style
= newval
;
932 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
933 retval
= class->cbWndExtra
;
934 class->cbWndExtra
= newval
;
937 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
938 retval
= (ULONG_PTR
)class->hInstance
;
939 class->hInstance
= (HINSTANCE
)newval
;
942 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
943 retval
= class->atomName
;
944 class->atomName
= newval
;
946 case GCL_CBCLSEXTRA
: /* cannot change this one */
947 SetLastError( ERROR_INVALID_PARAMETER
);
950 SetLastError( ERROR_INVALID_INDEX
);
953 release_class_ptr( class );
958 /***********************************************************************
959 * SetClassLongW (USER32.@)
961 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
963 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
965 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
969 /***********************************************************************
970 * SetClassLongA (USER32.@)
972 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
974 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
976 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
980 /***********************************************************************
981 * GetClassNameA (USER32.@)
983 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
985 char tmpbuf
[MAX_ATOM_LEN
+ 1];
988 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
990 if (count
<= 0) return 0;
992 ret
= GlobalGetAtomNameA( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
995 ret
= min(count
- 1, ret
);
996 memcpy(buffer
, tmpbuf
, ret
);
1003 /***********************************************************************
1004 * GetClassNameW (USER32.@)
1006 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
1008 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1011 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
1013 if (count
<= 0) return 0;
1015 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
1018 ret
= min(count
- 1, ret
);
1019 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1026 /***********************************************************************
1027 * RealGetWindowClassA (USER32.@)
1029 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1031 return GetClassNameA( hwnd
, buffer
, count
);
1035 /***********************************************************************
1036 * RealGetWindowClassW (USER32.@)
1038 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1040 return GetClassNameW( hwnd
, buffer
, count
);
1044 /***********************************************************************
1045 * GetClassInfoA (USER32.@)
1047 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1050 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1054 wc
->style
= wcex
.style
;
1055 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1056 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1057 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1058 wc
->hInstance
= wcex
.hInstance
;
1059 wc
->hIcon
= wcex
.hIcon
;
1060 wc
->hCursor
= wcex
.hCursor
;
1061 wc
->hbrBackground
= wcex
.hbrBackground
;
1062 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1063 wc
->lpszClassName
= wcex
.lpszClassName
;
1069 /***********************************************************************
1070 * GetClassInfoW (USER32.@)
1072 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1075 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1079 wc
->style
= wcex
.style
;
1080 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1081 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1082 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1083 wc
->hInstance
= wcex
.hInstance
;
1084 wc
->hIcon
= wcex
.hIcon
;
1085 wc
->hCursor
= wcex
.hCursor
;
1086 wc
->hbrBackground
= wcex
.hbrBackground
;
1087 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1088 wc
->lpszClassName
= wcex
.lpszClassName
;
1094 /***********************************************************************
1095 * GetClassInfoExA (USER32.@)
1097 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1099 ATOM atom
= HIWORD(name
) ? GlobalFindAtomA( name
) : LOWORD(name
);
1102 TRACE("%p %s %x %p\n", hInstance
, debugstr_a(name
), atom
, wc
);
1104 if (!hInstance
) hInstance
= user32_module
;
1106 if (!atom
|| !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
1108 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1111 wc
->style
= classPtr
->style
;
1112 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1113 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1114 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1115 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1116 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1117 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1118 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1119 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1120 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1121 wc
->lpszClassName
= name
;
1122 release_class_ptr( classPtr
);
1124 /* We must return the atom of the class here instead of just TRUE. */
1129 /***********************************************************************
1130 * GetClassInfoExW (USER32.@)
1132 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1134 ATOM atom
= HIWORD(name
) ? GlobalFindAtomW( name
) : LOWORD(name
);
1137 TRACE("%p %s %x %p\n", hInstance
, debugstr_w(name
), atom
, wc
);
1139 if (!hInstance
) hInstance
= user32_module
;
1141 if (!atom
|| !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
1143 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1146 wc
->style
= classPtr
->style
;
1147 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1148 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1149 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1150 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1151 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1152 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1153 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1154 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1155 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1156 wc
->lpszClassName
= name
;
1157 release_class_ptr( classPtr
);
1159 /* We must return the atom of the class here instead of just TRUE. */
1164 #if 0 /* toolhelp is in kernel, so this cannot work */
1166 /***********************************************************************
1167 * ClassFirst (TOOLHELP.69)
1169 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1171 TRACE("%p\n",pClassEntry
);
1172 pClassEntry
->wNext
= 1;
1173 return ClassNext16( pClassEntry
);
1177 /***********************************************************************
1178 * ClassNext (TOOLHELP.70)
1180 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1183 CLASS
*class = firstClass
;
1185 TRACE("%p\n",pClassEntry
);
1187 if (!pClassEntry
->wNext
) return FALSE
;
1188 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1191 pClassEntry
->wNext
= 0;
1194 pClassEntry
->hInst
= class->hInstance
;
1195 pClassEntry
->wNext
++;
1196 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1197 sizeof(pClassEntry
->szClassName
) );
1202 /* 64bit versions */
1204 #ifdef GetClassLongPtrA
1205 #undef GetClassLongPtrA
1208 #ifdef GetClassLongPtrW
1209 #undef GetClassLongPtrW
1212 #ifdef SetClassLongPtrA
1213 #undef SetClassLongPtrA
1216 #ifdef SetClassLongPtrW
1217 #undef SetClassLongPtrW
1220 /***********************************************************************
1221 * GetClassLongPtrA (USER32.@)
1223 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1225 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1228 /***********************************************************************
1229 * GetClassLongPtrW (USER32.@)
1231 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1233 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1236 /***********************************************************************
1237 * SetClassLongPtrW (USER32.@)
1239 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1241 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1244 /***********************************************************************
1245 * SetClassLongPtrA (USER32.@)
1247 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1249 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);