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 * Set class info with the wine server.
104 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG_PTR newval
, UINT size
)
108 SERVER_START_REQ( set_class_info
)
111 req
->extra_offset
= -1;
115 req
->flags
= SET_CLASS_ATOM
;
118 req
->flags
= SET_CLASS_STYLE
;
122 req
->flags
= SET_CLASS_WINEXTRA
;
123 req
->win_extra
= newval
;
126 req
->flags
= SET_CLASS_INSTANCE
;
127 req
->instance
= (void *)newval
;
130 assert( offset
>= 0 );
131 req
->flags
= SET_CLASS_EXTRA
;
132 req
->extra_offset
= offset
;
133 req
->extra_size
= size
;
134 if ( size
== sizeof(LONG
) )
136 LONG newlong
= newval
;
137 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
140 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
143 ret
= !wine_server_call_err( req
);
150 /***********************************************************************
153 * Get the menu name as a ASCII string.
155 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
157 if (!HIWORD(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
158 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
162 /***********************************************************************
165 * Get the menu name as a Unicode string.
167 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
169 return classPtr
->menuName
;
173 /***********************************************************************
176 * Set the menu name in a class structure by copying the string.
178 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
180 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
183 DWORD lenA
= strlen(name
) + 1;
184 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
185 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
186 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
187 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
189 else classPtr
->menuName
= (LPWSTR
)name
;
193 /***********************************************************************
196 * Set the menu name in a class structure by copying the string.
198 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
200 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
203 DWORD lenW
= strlenW(name
) + 1;
204 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
205 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
206 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
207 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
208 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
210 else classPtr
->menuName
= (LPWSTR
)name
;
214 /***********************************************************************
217 * Free a class structure.
219 static void CLASS_FreeClass( CLASS
*classPtr
)
221 TRACE("%p\n", classPtr
);
225 list_remove( &classPtr
->entry
);
226 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
227 DeleteObject( classPtr
->hbrBackground
);
228 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
229 HeapFree( GetProcessHeap(), 0, classPtr
);
234 /***********************************************************************
235 * CLASS_FreeModuleClasses
237 void CLASS_FreeModuleClasses( HMODULE16 hModule
)
239 struct list
*ptr
, *next
;
241 TRACE("0x%08x\n", hModule
);
244 for (ptr
= list_head( &class_list
); ptr
; ptr
= next
)
246 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
247 next
= list_next( &class_list
, ptr
);
248 if (class->hInstance
== HINSTANCE_32(hModule
))
252 SERVER_START_REQ( destroy_class
)
254 req
->atom
= class->atomName
;
255 req
->instance
= class->hInstance
;
256 ret
= !wine_server_call_err( req
);
259 if (ret
) CLASS_FreeClass( class );
266 /***********************************************************************
267 * CLASS_FindClassByAtom
269 * Return a pointer to the class.
270 * hinstance has been normalized by the caller.
272 static CLASS
*CLASS_FindClassByAtom( ATOM atom
, HINSTANCE hinstance
)
278 LIST_FOR_EACH( ptr
, &class_list
)
280 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
281 if (class->atomName
!= atom
) continue;
282 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
284 TRACE("0x%04x %p -> %p\n", atom
, hinstance
, class);
289 TRACE("0x%04x %p -> not found\n", atom
, hinstance
);
294 /***********************************************************************
295 * CLASS_RegisterClass
297 * The real RegisterClass() functionality.
298 * The atom is deleted no matter what.
300 static CLASS
*CLASS_RegisterClass( ATOM atom
, HINSTANCE hInstance
, BOOL local
,
301 DWORD style
, INT classExtra
, INT winExtra
)
306 TRACE("atom=0x%x hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
307 atom
, hInstance
, style
, classExtra
, winExtra
);
309 /* Fix the extra bytes value */
311 if (classExtra
< 0 || winExtra
< 0)
313 SetLastError( ERROR_INVALID_PARAMETER
);
316 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
317 WARN("Class extra bytes %d is > 40\n", classExtra
);
318 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
319 WARN("Win extra bytes %d is > 40\n", winExtra
);
321 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
324 GlobalDeleteAtom( atom
);
328 SERVER_START_REQ( create_class
)
333 req
->instance
= hInstance
;
334 req
->extra
= classExtra
;
335 req
->win_extra
= winExtra
;
336 req
->client_ptr
= classPtr
;
337 ret
= !wine_server_call_err( req
);
340 GlobalDeleteAtom( atom
); /* the server increased the atom ref count */
343 HeapFree( GetProcessHeap(), 0, classPtr
);
347 classPtr
->style
= style
;
348 classPtr
->local
= local
;
349 classPtr
->cbWndExtra
= winExtra
;
350 classPtr
->cbClsExtra
= classExtra
;
351 classPtr
->hInstance
= hInstance
;
352 classPtr
->atomName
= atom
;
354 /* Other non-null values must be set by caller */
357 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
358 else list_add_tail( &class_list
, &classPtr
->entry
);
363 /***********************************************************************
366 * Register a builtin control class.
367 * This allows having both ASCII and Unicode winprocs for the same class.
369 static CLASS
*register_builtin( const struct builtin_class_descr
*descr
)
374 if (!(atom
= GlobalAddAtomA( descr
->name
))) return 0;
376 if (!(classPtr
= CLASS_RegisterClass( atom
, user32_module
, FALSE
,
377 descr
->style
, 0, descr
->extra
))) return 0;
379 classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
380 classPtr
->hbrBackground
= descr
->brush
;
381 classPtr
->winproc
= WINPROC_AllocProc( descr
->procA
, descr
->procW
);
382 release_class_ptr( classPtr
);
387 /***********************************************************************
388 * CLASS_RegisterBuiltinClasses
390 void CLASS_RegisterBuiltinClasses(void)
392 extern const struct builtin_class_descr BUTTON_builtin_class
;
393 extern const struct builtin_class_descr COMBO_builtin_class
;
394 extern const struct builtin_class_descr COMBOLBOX_builtin_class
;
395 extern const struct builtin_class_descr DIALOG_builtin_class
;
396 extern const struct builtin_class_descr DESKTOP_builtin_class
;
397 extern const struct builtin_class_descr EDIT_builtin_class
;
398 extern const struct builtin_class_descr ICONTITLE_builtin_class
;
399 extern const struct builtin_class_descr LISTBOX_builtin_class
;
400 extern const struct builtin_class_descr MDICLIENT_builtin_class
;
401 extern const struct builtin_class_descr MENU_builtin_class
;
402 extern const struct builtin_class_descr SCROLL_builtin_class
;
403 extern const struct builtin_class_descr STATIC_builtin_class
;
405 register_builtin( &DESKTOP_builtin_class
);
406 register_builtin( &BUTTON_builtin_class
);
407 register_builtin( &COMBO_builtin_class
);
408 register_builtin( &COMBOLBOX_builtin_class
);
409 register_builtin( &DIALOG_builtin_class
);
410 register_builtin( &EDIT_builtin_class
);
411 register_builtin( &ICONTITLE_builtin_class
);
412 register_builtin( &LISTBOX_builtin_class
);
413 register_builtin( &MDICLIENT_builtin_class
);
414 register_builtin( &MENU_builtin_class
);
415 register_builtin( &SCROLL_builtin_class
);
416 register_builtin( &STATIC_builtin_class
);
418 /* the DefWindowProc winprocs are magic too */
419 WINPROC_AllocProc( DefWindowProcA
, DefWindowProcW
);
423 /***********************************************************************
426 * Add a new window using this class, and set the necessary
427 * information inside the window structure.
429 void CLASS_AddWindow( CLASS
*class, WND
*win
, BOOL unicode
)
432 win
->clsStyle
= class->style
;
433 win
->winproc
= class->winproc
;
434 if (WINPROC_IsUnicode( win
->winproc
, unicode
)) win
->flags
|= WIN_ISUNICODE
;
438 /***********************************************************************
439 * RegisterClassA (USER32.@)
441 * Register a window class.
444 * >0: Unique identifier
447 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
451 wcex
.cbSize
= sizeof(wcex
);
452 wcex
.style
= wc
->style
;
453 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
454 wcex
.cbClsExtra
= wc
->cbClsExtra
;
455 wcex
.cbWndExtra
= wc
->cbWndExtra
;
456 wcex
.hInstance
= wc
->hInstance
;
457 wcex
.hIcon
= wc
->hIcon
;
458 wcex
.hCursor
= wc
->hCursor
;
459 wcex
.hbrBackground
= wc
->hbrBackground
;
460 wcex
.lpszMenuName
= wc
->lpszMenuName
;
461 wcex
.lpszClassName
= wc
->lpszClassName
;
463 return RegisterClassExA( &wcex
);
467 /***********************************************************************
468 * RegisterClassW (USER32.@)
470 * See RegisterClassA.
472 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
476 wcex
.cbSize
= sizeof(wcex
);
477 wcex
.style
= wc
->style
;
478 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
479 wcex
.cbClsExtra
= wc
->cbClsExtra
;
480 wcex
.cbWndExtra
= wc
->cbWndExtra
;
481 wcex
.hInstance
= wc
->hInstance
;
482 wcex
.hIcon
= wc
->hIcon
;
483 wcex
.hCursor
= wc
->hCursor
;
484 wcex
.hbrBackground
= wc
->hbrBackground
;
485 wcex
.lpszMenuName
= wc
->lpszMenuName
;
486 wcex
.lpszClassName
= wc
->lpszClassName
;
488 return RegisterClassExW( &wcex
);
492 /***********************************************************************
493 * RegisterClassExA (USER32.@)
495 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
501 if (wc
->hInstance
== user32_module
)
503 /* we can't register a class for user32 */
504 SetLastError( ERROR_INVALID_PARAMETER
);
507 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
509 if (!(atom
= GlobalAddAtomA( wc
->lpszClassName
))) return 0;
511 if (!(classPtr
= CLASS_RegisterClass( atom
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
512 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
515 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
516 atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
517 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
519 classPtr
->hIcon
= wc
->hIcon
;
520 classPtr
->hIconSm
= wc
->hIconSm
;
521 classPtr
->hCursor
= wc
->hCursor
;
522 classPtr
->hbrBackground
= wc
->hbrBackground
;
523 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, NULL
);
524 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
525 release_class_ptr( classPtr
);
530 /***********************************************************************
531 * RegisterClassExW (USER32.@)
533 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
539 if (wc
->hInstance
== user32_module
)
541 /* we can't register a class for user32 */
542 SetLastError( ERROR_INVALID_PARAMETER
);
545 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
547 if (!(atom
= GlobalAddAtomW( wc
->lpszClassName
))) return 0;
549 if (!(classPtr
= CLASS_RegisterClass( atom
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
550 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
553 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
554 atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
555 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
557 classPtr
->hIcon
= wc
->hIcon
;
558 classPtr
->hIconSm
= wc
->hIconSm
;
559 classPtr
->hCursor
= wc
->hCursor
;
560 classPtr
->hbrBackground
= wc
->hbrBackground
;
561 classPtr
->winproc
= WINPROC_AllocProc( NULL
, wc
->lpfnWndProc
);
562 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
563 release_class_ptr( classPtr
);
568 /***********************************************************************
569 * UnregisterClassA (USER32.@)
571 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
573 ATOM atom
= HIWORD(className
) ? GlobalFindAtomA( className
) : LOWORD(className
);
574 return UnregisterClassW( (LPCWSTR
)MAKEINTATOM(atom
), hInstance
);
577 /***********************************************************************
578 * UnregisterClassW (USER32.@)
580 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
582 CLASS
*classPtr
= NULL
;
583 ATOM atom
= HIWORD(className
) ? GlobalFindAtomW( className
) : LOWORD(className
);
585 TRACE("%s %p %x\n",debugstr_w(className
), hInstance
, atom
);
589 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
593 SERVER_START_REQ( destroy_class
)
596 req
->instance
= hInstance
;
597 if (!wine_server_call_err( req
)) classPtr
= reply
->client_ptr
;
601 if (classPtr
) CLASS_FreeClass( classPtr
);
602 return (classPtr
!= NULL
);
606 /***********************************************************************
607 * GetClassWord (USER32.@)
609 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
614 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
616 TRACE("%p %x\n",hwnd
, offset
);
618 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
620 if (class == CLASS_OTHER_PROCESS
)
622 SERVER_START_REQ( set_class_info
)
626 req
->extra_offset
= offset
;
627 req
->extra_size
= sizeof(retvalue
);
628 if (!wine_server_call_err( req
))
629 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
635 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
636 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
638 SetLastError( ERROR_INVALID_INDEX
);
639 release_class_ptr( class );
644 /***********************************************************************
647 * Implementation of GetClassLong(Ptr)A/W
649 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
653 ULONG_PTR retvalue
= 0;
655 TRACE("%p %d\n", hwnd
, offset
);
657 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
659 if (class == CLASS_OTHER_PROCESS
)
661 SERVER_START_REQ( set_class_info
)
665 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
666 req
->extra_size
= (offset
>= 0) ? size
: 0;
667 if (!wine_server_call_err( req
))
671 case GCLP_HBRBACKGROUND
:
677 FIXME( "offset %d (%s) not supported on other process window %p\n",
678 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
679 SetLastError( ERROR_INVALID_HANDLE
);
682 retvalue
= reply
->old_style
;
685 retvalue
= reply
->old_win_extra
;
688 retvalue
= reply
->old_extra
;
691 retvalue
= (ULONG_PTR
)reply
->old_instance
;
694 retvalue
= reply
->old_atom
;
699 if (size
== sizeof(DWORD
))
702 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
706 memcpy( &retvalue
, &reply
->old_extra_value
,
709 else SetLastError( ERROR_INVALID_INDEX
);
720 if (offset
<= class->cbClsExtra
- size
)
722 if (size
== sizeof(DWORD
))
725 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
729 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
732 SetLastError( ERROR_INVALID_INDEX
);
733 release_class_ptr( class );
739 case GCLP_HBRBACKGROUND
:
740 retvalue
= (ULONG_PTR
)class->hbrBackground
;
743 retvalue
= (ULONG_PTR
)class->hCursor
;
746 retvalue
= (ULONG_PTR
)class->hIcon
;
749 retvalue
= (ULONG_PTR
)class->hIconSm
;
752 retvalue
= class->style
;
755 retvalue
= class->cbWndExtra
;
758 retvalue
= class->cbClsExtra
;
761 retvalue
= (ULONG_PTR
)class->hInstance
;
764 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
767 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
769 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
771 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
774 retvalue
= class->atomName
;
777 SetLastError( ERROR_INVALID_INDEX
);
780 release_class_ptr( class );
785 /***********************************************************************
786 * GetClassLongW (USER32.@)
788 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
790 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
795 /***********************************************************************
796 * GetClassLongA (USER32.@)
798 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
800 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
804 /***********************************************************************
805 * SetClassWord (USER32.@)
807 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
812 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
814 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
816 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
818 SERVER_START_REQ( set_class_info
)
821 req
->flags
= SET_CLASS_EXTRA
;
822 req
->extra_offset
= offset
;
823 req
->extra_size
= sizeof(newval
);
824 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
825 if (!wine_server_call_err( req
))
827 void *ptr
= (char *)(class + 1) + offset
;
828 memcpy( &retval
, ptr
, sizeof(retval
) );
829 memcpy( ptr
, &newval
, sizeof(newval
) );
833 release_class_ptr( class );
838 /***********************************************************************
841 * Implementation of SetClassLong(Ptr)A/W
843 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
844 UINT size
, BOOL unicode
)
847 ULONG_PTR retval
= 0;
849 TRACE("%p %d %lx\n", hwnd
, offset
, newval
);
851 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
855 if (set_server_info( hwnd
, offset
, newval
, size
))
857 void *ptr
= (char *)(class + 1) + offset
;
858 if ( size
== sizeof(LONG
) )
861 LONG newlong
= newval
;
862 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
863 memcpy( ptr
, &newlong
, sizeof(LONG
) );
868 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
869 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
877 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
879 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
880 retval
= 0; /* Old value is now meaningless anyway */
883 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
884 class->winproc
= WINPROC_AllocProc( unicode
? NULL
: (WNDPROC
)newval
,
885 unicode
? (WNDPROC
)newval
: NULL
);
887 case GCLP_HBRBACKGROUND
:
888 retval
= (ULONG_PTR
)class->hbrBackground
;
889 class->hbrBackground
= (HBRUSH
)newval
;
892 retval
= (ULONG_PTR
)class->hCursor
;
893 class->hCursor
= (HCURSOR
)newval
;
896 retval
= (ULONG_PTR
)class->hIcon
;
897 class->hIcon
= (HICON
)newval
;
900 retval
= (ULONG_PTR
)class->hIconSm
;
901 class->hIconSm
= (HICON
)newval
;
904 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
905 retval
= class->style
;
906 class->style
= newval
;
909 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
910 retval
= class->cbWndExtra
;
911 class->cbWndExtra
= newval
;
914 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
915 retval
= (ULONG_PTR
)class->hInstance
;
916 class->hInstance
= (HINSTANCE
)newval
;
919 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
920 retval
= class->atomName
;
921 class->atomName
= newval
;
923 case GCL_CBCLSEXTRA
: /* cannot change this one */
924 SetLastError( ERROR_INVALID_PARAMETER
);
927 SetLastError( ERROR_INVALID_INDEX
);
930 release_class_ptr( class );
935 /***********************************************************************
936 * SetClassLongW (USER32.@)
938 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
940 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
942 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
946 /***********************************************************************
947 * SetClassLongA (USER32.@)
949 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
951 TRACE("%p %d %x\n", hwnd
, offset
, newval
);
953 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
957 /***********************************************************************
958 * GetClassNameA (USER32.@)
960 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
962 char tmpbuf
[MAX_ATOM_LEN
+ 1];
965 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
967 if (count
<= 0) return 0;
969 ret
= GlobalGetAtomNameA( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
972 ret
= min(count
- 1, ret
);
973 memcpy(buffer
, tmpbuf
, ret
);
980 /***********************************************************************
981 * GetClassNameW (USER32.@)
983 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
985 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
988 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
990 if (count
<= 0) return 0;
992 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
995 ret
= min(count
- 1, ret
);
996 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1003 /***********************************************************************
1004 * RealGetWindowClassA (USER32.@)
1006 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1008 return GetClassNameA( hwnd
, buffer
, count
);
1012 /***********************************************************************
1013 * RealGetWindowClassW (USER32.@)
1015 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1017 return GetClassNameW( hwnd
, buffer
, count
);
1021 /***********************************************************************
1022 * GetClassInfoA (USER32.@)
1024 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1027 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1031 wc
->style
= wcex
.style
;
1032 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1033 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1034 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1035 wc
->hInstance
= wcex
.hInstance
;
1036 wc
->hIcon
= wcex
.hIcon
;
1037 wc
->hCursor
= wcex
.hCursor
;
1038 wc
->hbrBackground
= wcex
.hbrBackground
;
1039 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1040 wc
->lpszClassName
= wcex
.lpszClassName
;
1046 /***********************************************************************
1047 * GetClassInfoW (USER32.@)
1049 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1052 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1056 wc
->style
= wcex
.style
;
1057 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1058 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1059 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1060 wc
->hInstance
= wcex
.hInstance
;
1061 wc
->hIcon
= wcex
.hIcon
;
1062 wc
->hCursor
= wcex
.hCursor
;
1063 wc
->hbrBackground
= wcex
.hbrBackground
;
1064 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1065 wc
->lpszClassName
= wcex
.lpszClassName
;
1071 /***********************************************************************
1072 * GetClassInfoExA (USER32.@)
1074 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1076 ATOM atom
= HIWORD(name
) ? GlobalFindAtomA( name
) : LOWORD(name
);
1079 TRACE("%p %s %x %p\n", hInstance
, debugstr_a(name
), atom
, wc
);
1081 if (!hInstance
) hInstance
= user32_module
;
1083 if (!atom
|| !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
1085 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1088 wc
->style
= classPtr
->style
;
1089 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1090 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1091 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1092 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1093 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1094 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1095 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1096 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1097 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1098 wc
->lpszClassName
= name
;
1099 release_class_ptr( classPtr
);
1101 /* We must return the atom of the class here instead of just TRUE. */
1106 /***********************************************************************
1107 * GetClassInfoExW (USER32.@)
1109 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1111 ATOM atom
= HIWORD(name
) ? GlobalFindAtomW( name
) : LOWORD(name
);
1114 TRACE("%p %s %x %p\n", hInstance
, debugstr_w(name
), atom
, wc
);
1116 if (!hInstance
) hInstance
= user32_module
;
1118 if (!atom
|| !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
1120 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1123 wc
->style
= classPtr
->style
;
1124 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1125 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1126 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1127 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1128 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1129 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1130 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1131 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1132 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1133 wc
->lpszClassName
= name
;
1134 release_class_ptr( classPtr
);
1136 /* We must return the atom of the class here instead of just TRUE. */
1141 #if 0 /* toolhelp is in kernel, so this cannot work */
1143 /***********************************************************************
1144 * ClassFirst (TOOLHELP.69)
1146 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1148 TRACE("%p\n",pClassEntry
);
1149 pClassEntry
->wNext
= 1;
1150 return ClassNext16( pClassEntry
);
1154 /***********************************************************************
1155 * ClassNext (TOOLHELP.70)
1157 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1160 CLASS
*class = firstClass
;
1162 TRACE("%p\n",pClassEntry
);
1164 if (!pClassEntry
->wNext
) return FALSE
;
1165 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1168 pClassEntry
->wNext
= 0;
1171 pClassEntry
->hInst
= class->hInstance
;
1172 pClassEntry
->wNext
++;
1173 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1174 sizeof(pClassEntry
->szClassName
) );
1179 /* 64bit versions */
1181 #ifdef GetClassLongPtrA
1182 #undef GetClassLongPtrA
1185 #ifdef GetClassLongPtrW
1186 #undef GetClassLongPtrW
1189 #ifdef SetClassLongPtrA
1190 #undef SetClassLongPtrA
1193 #ifdef SetClassLongPtrW
1194 #undef SetClassLongPtrW
1197 /***********************************************************************
1198 * GetClassLongPtrA (USER32.@)
1200 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1202 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1205 /***********************************************************************
1206 * GetClassLongPtrW (USER32.@)
1208 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1210 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1213 /***********************************************************************
1214 * SetClassLongPtrW (USER32.@)
1216 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1218 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1221 /***********************************************************************
1222 * SetClassLongPtrA (USER32.@)
1224 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1226 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);