2 * Window classes functions
4 * Copyright 1993, 1996, 2003 Alexandre Julliard
5 * Copyright 1998 Juergen Schmied (jsch)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
34 #include "wine/unicode.h"
36 #include "user_private.h"
38 #include "wine/server.h"
39 #include "wine/list.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(class);
44 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
46 typedef struct tagCLASS
48 struct list entry
; /* Entry in class list */
49 UINT style
; /* Class style */
50 BOOL local
; /* Local class? */
51 WNDPROC winproc
; /* Window procedure */
52 INT cbClsExtra
; /* Class extra bytes */
53 INT cbWndExtra
; /* Window extra bytes */
54 LPWSTR menuName
; /* Default menu name (Unicode followed by ASCII) */
55 struct dce
*dce
; /* Opaque pointer to class DCE */
56 HINSTANCE hInstance
; /* Module that created the task */
57 HICON hIcon
; /* Default icon */
58 HICON hIconSm
; /* Default small icon */
59 HICON hIconSmIntern
; /* Internal small icon, derived from hIcon */
60 HCURSOR hCursor
; /* Default cursor */
61 HBRUSH hbrBackground
; /* Default background */
62 ATOM atomName
; /* Name of the class */
63 WCHAR name
[MAX_ATOM_LEN
+ 1];
66 static struct list class_list
= LIST_INIT( class_list
);
67 static INIT_ONCE init_once
= INIT_ONCE_STATIC_INIT
;
69 #define CLASS_OTHER_PROCESS ((CLASS *)1)
71 /***********************************************************************
74 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
76 WND
*ptr
= WIN_GetPtr( hwnd
);
80 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
) return ptr
->class;
81 if (!write_access
) return CLASS_OTHER_PROCESS
;
83 /* modifying classes in other processes is not allowed */
84 if (ptr
== WND_DESKTOP
|| IsWindow( hwnd
))
86 SetLastError( ERROR_ACCESS_DENIED
);
90 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
95 /***********************************************************************
98 static inline void release_class_ptr( CLASS
*ptr
)
104 /***********************************************************************
107 ATOM
get_int_atom_value( LPCWSTR name
)
111 if (IS_INTRESOURCE(name
)) return LOWORD(name
);
112 if (*name
++ != '#') return 0;
115 if (*name
< '0' || *name
> '9') return 0;
116 ret
= ret
* 10 + *name
++ - '0';
117 if (ret
> 0xffff) return 0;
123 /***********************************************************************
126 static BOOL
is_comctl32_class( const WCHAR
*name
)
128 static const WCHAR classesW
[][20] =
130 {'C','o','m','b','o','B','o','x','E','x','3','2',0},
131 {'m','s','c','t','l','s','_','h','o','t','k','e','y','3','2',0},
132 {'m','s','c','t','l','s','_','p','r','o','g','r','e','s','s','3','2',0},
133 {'m','s','c','t','l','s','_','s','t','a','t','u','s','b','a','r','3','2',0},
134 {'m','s','c','t','l','s','_','t','r','a','c','k','b','a','r','3','2',0},
135 {'m','s','c','t','l','s','_','u','p','d','o','w','n','3','2',0},
136 {'N','a','t','i','v','e','F','o','n','t','C','t','l',0},
137 {'R','e','B','a','r','W','i','n','d','o','w','3','2',0},
138 {'S','y','s','A','n','i','m','a','t','e','3','2',0},
139 {'S','y','s','D','a','t','e','T','i','m','e','P','i','c','k','3','2',0},
140 {'S','y','s','H','e','a','d','e','r','3','2',0},
141 {'S','y','s','I','P','A','d','d','r','e','s','s','3','2',0},
142 {'S','y','s','L','i','s','t','V','i','e','w','3','2',0},
143 {'S','y','s','M','o','n','t','h','C','a','l','3','2',0},
144 {'S','y','s','P','a','g','e','r',0},
145 {'S','y','s','T','a','b','C','o','n','t','r','o','l','3','2',0},
146 {'S','y','s','T','r','e','e','V','i','e','w','3','2',0},
147 {'T','o','o','l','b','a','r','W','i','n','d','o','w','3','2',0},
148 {'t','o','o','l','t','i','p','s','_','c','l','a','s','s','3','2',0},
151 int min
= 0, max
= (sizeof(classesW
) / sizeof(classesW
[0])) - 1;
155 int res
, pos
= (min
+ max
) / 2;
156 if (!(res
= strcmpiW( name
, classesW
[pos
] ))) return TRUE
;
157 if (res
< 0) max
= pos
- 1;
164 /***********************************************************************
167 * Set class info with the wine server.
169 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG_PTR newval
, UINT size
)
173 SERVER_START_REQ( set_class_info
)
175 req
->window
= wine_server_user_handle( hwnd
);
176 req
->extra_offset
= -1;
180 req
->flags
= SET_CLASS_ATOM
;
181 req
->atom
= LOWORD(newval
);
184 req
->flags
= SET_CLASS_STYLE
;
188 req
->flags
= SET_CLASS_WINEXTRA
;
189 req
->win_extra
= newval
;
192 req
->flags
= SET_CLASS_INSTANCE
;
193 req
->instance
= wine_server_client_ptr( (void *)newval
);
196 assert( offset
>= 0 );
197 req
->flags
= SET_CLASS_EXTRA
;
198 req
->extra_offset
= offset
;
199 req
->extra_size
= size
;
200 if ( size
== sizeof(LONG
) )
202 LONG newlong
= newval
;
203 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
206 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
209 ret
= !wine_server_call_err( req
);
216 /***********************************************************************
219 * Get the menu name as a ASCII string.
221 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
223 if (IS_INTRESOURCE(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
224 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
228 /***********************************************************************
231 * Get the menu name as a Unicode string.
233 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
235 return classPtr
->menuName
;
239 /***********************************************************************
242 * Set the menu name in a class structure by copying the string.
244 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
246 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
247 if (!IS_INTRESOURCE(name
))
249 DWORD lenA
= strlen(name
) + 1;
250 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
251 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
252 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
253 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
255 else classPtr
->menuName
= (LPWSTR
)name
;
259 /***********************************************************************
262 * Set the menu name in a class structure by copying the string.
264 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
266 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
267 if (!IS_INTRESOURCE(name
))
269 DWORD lenW
= strlenW(name
) + 1;
270 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
271 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
272 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
273 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
274 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
276 else classPtr
->menuName
= (LPWSTR
)name
;
280 /***********************************************************************
283 * Free a class structure.
285 static void CLASS_FreeClass( CLASS
*classPtr
)
287 TRACE("%p\n", classPtr
);
291 if (classPtr
->dce
) free_dce( classPtr
->dce
, 0 );
292 list_remove( &classPtr
->entry
);
293 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
294 DeleteObject( classPtr
->hbrBackground
);
295 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
296 HeapFree( GetProcessHeap(), 0, classPtr
);
301 /***********************************************************************
304 * Return a pointer to the class.
306 static CLASS
*CLASS_FindClass( LPCWSTR name
, HINSTANCE hinstance
)
308 static const WCHAR comctl32W
[] = {'c','o','m','c','t','l','3','2','.','d','l','l',0};
310 ATOM atom
= get_int_atom_value( name
);
312 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
314 if (!name
) return NULL
;
320 LIST_FOR_EACH( ptr
, &class_list
)
322 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
325 if (class->atomName
!= atom
) continue;
329 if (strcmpiW( class->name
, name
)) continue;
331 if (!class->local
|| class->hInstance
== hinstance
)
333 TRACE("%s %p -> %p\n", debugstr_w(name
), hinstance
, class);
340 if (!is_comctl32_class( name
)) break;
341 if (GetModuleHandleW( comctl32W
)) break;
342 if (!LoadLibraryW( comctl32W
)) break;
343 TRACE( "%s retrying after loading comctl32\n", debugstr_w(name
) );
346 TRACE("%s %p -> not found\n", debugstr_w(name
), hinstance
);
351 /***********************************************************************
352 * CLASS_RegisterClass
354 * The real RegisterClass() functionality.
356 static CLASS
*CLASS_RegisterClass( LPCWSTR name
, HINSTANCE hInstance
, BOOL local
,
357 DWORD style
, INT classExtra
, INT winExtra
)
362 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
363 debugstr_w(name
), hInstance
, style
, classExtra
, winExtra
);
365 /* Fix the extra bytes value */
367 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
368 WARN("Class extra bytes %d is > 40\n", classExtra
);
369 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
370 WARN("Win extra bytes %d is > 40\n", winExtra
);
372 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
373 if (!classPtr
) return NULL
;
375 classPtr
->atomName
= get_int_atom_value( name
);
376 if (!classPtr
->atomName
&& name
) strcpyW( classPtr
->name
, name
);
377 else GlobalGetAtomNameW( classPtr
->atomName
, classPtr
->name
, sizeof(classPtr
->name
)/sizeof(WCHAR
) );
379 SERVER_START_REQ( create_class
)
383 req
->instance
= wine_server_client_ptr( hInstance
);
384 req
->extra
= classExtra
;
385 req
->win_extra
= winExtra
;
386 req
->client_ptr
= wine_server_client_ptr( classPtr
);
387 req
->atom
= classPtr
->atomName
;
388 if (!req
->atom
&& name
) wine_server_add_data( req
, name
, strlenW(name
) * sizeof(WCHAR
) );
389 ret
= !wine_server_call_err( req
);
390 classPtr
->atomName
= reply
->atom
;
395 HeapFree( GetProcessHeap(), 0, classPtr
);
399 classPtr
->style
= style
;
400 classPtr
->local
= local
;
401 classPtr
->cbWndExtra
= winExtra
;
402 classPtr
->cbClsExtra
= classExtra
;
403 classPtr
->hInstance
= hInstance
;
405 /* Other non-null values must be set by caller */
408 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
409 else list_add_tail( &class_list
, &classPtr
->entry
);
414 /***********************************************************************
417 * Register a builtin control class.
418 * This allows having both ASCII and Unicode winprocs for the same class.
420 static void register_builtin( const struct builtin_class_descr
*descr
)
424 if (!(classPtr
= CLASS_RegisterClass( descr
->name
, user32_module
, FALSE
,
425 descr
->style
, 0, descr
->extra
))) return;
427 if (descr
->cursor
) classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
428 classPtr
->hbrBackground
= descr
->brush
;
429 classPtr
->winproc
= BUILTIN_WINPROC( descr
->proc
);
430 release_class_ptr( classPtr
);
434 /***********************************************************************
437 static BOOL WINAPI
register_builtins( INIT_ONCE
*once
, void *param
, void **context
)
439 register_builtin( &BUTTON_builtin_class
);
440 register_builtin( &COMBO_builtin_class
);
441 register_builtin( &COMBOLBOX_builtin_class
);
442 register_builtin( &DIALOG_builtin_class
);
443 register_builtin( &EDIT_builtin_class
);
444 register_builtin( &ICONTITLE_builtin_class
);
445 register_builtin( &LISTBOX_builtin_class
);
446 register_builtin( &MDICLIENT_builtin_class
);
447 register_builtin( &MENU_builtin_class
);
448 register_builtin( &SCROLL_builtin_class
);
449 register_builtin( &STATIC_builtin_class
);
450 register_builtin( &IME_builtin_class
);
455 /***********************************************************************
456 * register_builtin_classes
458 void register_builtin_classes(void)
460 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
464 /***********************************************************************
465 * register_desktop_class
467 void register_desktop_class(void)
469 register_builtin( &DESKTOP_builtin_class
);
470 register_builtin( &MESSAGE_builtin_class
);
474 /***********************************************************************
477 WNDPROC
get_class_winproc( CLASS
*class )
479 return class->winproc
;
483 /***********************************************************************
486 struct dce
*get_class_dce( CLASS
*class )
492 /***********************************************************************
495 struct dce
*set_class_dce( CLASS
*class, struct dce
*dce
)
497 if (class->dce
) return class->dce
; /* already set, don't change it */
503 /***********************************************************************
504 * RegisterClassA (USER32.@)
506 * Register a window class.
509 * >0: Unique identifier
512 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
516 wcex
.cbSize
= sizeof(wcex
);
517 wcex
.style
= wc
->style
;
518 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
519 wcex
.cbClsExtra
= wc
->cbClsExtra
;
520 wcex
.cbWndExtra
= wc
->cbWndExtra
;
521 wcex
.hInstance
= wc
->hInstance
;
522 wcex
.hIcon
= wc
->hIcon
;
523 wcex
.hCursor
= wc
->hCursor
;
524 wcex
.hbrBackground
= wc
->hbrBackground
;
525 wcex
.lpszMenuName
= wc
->lpszMenuName
;
526 wcex
.lpszClassName
= wc
->lpszClassName
;
528 return RegisterClassExA( &wcex
);
532 /***********************************************************************
533 * RegisterClassW (USER32.@)
535 * See RegisterClassA.
537 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
541 wcex
.cbSize
= sizeof(wcex
);
542 wcex
.style
= wc
->style
;
543 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
544 wcex
.cbClsExtra
= wc
->cbClsExtra
;
545 wcex
.cbWndExtra
= wc
->cbWndExtra
;
546 wcex
.hInstance
= wc
->hInstance
;
547 wcex
.hIcon
= wc
->hIcon
;
548 wcex
.hCursor
= wc
->hCursor
;
549 wcex
.hbrBackground
= wc
->hbrBackground
;
550 wcex
.lpszMenuName
= wc
->lpszMenuName
;
551 wcex
.lpszClassName
= wc
->lpszClassName
;
553 return RegisterClassExW( &wcex
);
557 /***********************************************************************
558 * RegisterClassExA (USER32.@)
560 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
566 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
568 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
569 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
571 SetLastError( ERROR_INVALID_PARAMETER
);
574 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
576 if (!IS_INTRESOURCE(wc
->lpszClassName
))
578 WCHAR name
[MAX_ATOM_LEN
+ 1];
580 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
581 classPtr
= CLASS_RegisterClass( name
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
582 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
586 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, instance
,
587 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
588 wc
->cbClsExtra
, wc
->cbWndExtra
);
590 if (!classPtr
) return 0;
591 atom
= classPtr
->atomName
;
593 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
594 debugstr_a(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
595 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
597 classPtr
->hIcon
= wc
->hIcon
;
598 classPtr
->hIconSm
= wc
->hIconSm
;
599 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
600 CopyImage( wc
->hIcon
, IMAGE_ICON
,
601 GetSystemMetrics( SM_CXSMICON
),
602 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
603 classPtr
->hCursor
= wc
->hCursor
;
604 classPtr
->hbrBackground
= wc
->hbrBackground
;
605 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, FALSE
);
606 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
607 release_class_ptr( classPtr
);
612 /***********************************************************************
613 * RegisterClassExW (USER32.@)
615 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
621 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
623 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
624 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
626 SetLastError( ERROR_INVALID_PARAMETER
);
629 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
631 if (!(classPtr
= CLASS_RegisterClass( wc
->lpszClassName
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
632 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
635 atom
= classPtr
->atomName
;
637 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
638 debugstr_w(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
639 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
641 classPtr
->hIcon
= wc
->hIcon
;
642 classPtr
->hIconSm
= wc
->hIconSm
;
643 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
644 CopyImage( wc
->hIcon
, IMAGE_ICON
,
645 GetSystemMetrics( SM_CXSMICON
),
646 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
647 classPtr
->hCursor
= wc
->hCursor
;
648 classPtr
->hbrBackground
= wc
->hbrBackground
;
649 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, TRUE
);
650 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
651 release_class_ptr( classPtr
);
656 /***********************************************************************
657 * UnregisterClassA (USER32.@)
659 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
661 if (!IS_INTRESOURCE(className
))
663 WCHAR name
[MAX_ATOM_LEN
+ 1];
665 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
667 return UnregisterClassW( name
, hInstance
);
669 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
672 /***********************************************************************
673 * UnregisterClassW (USER32.@)
675 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
677 CLASS
*classPtr
= NULL
;
679 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
681 SERVER_START_REQ( destroy_class
)
683 req
->instance
= wine_server_client_ptr( hInstance
);
684 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
685 wine_server_add_data( req
, className
, strlenW(className
) * sizeof(WCHAR
) );
686 if (!wine_server_call_err( req
)) classPtr
= wine_server_get_ptr( reply
->client_ptr
);
690 if (classPtr
) CLASS_FreeClass( classPtr
);
691 return (classPtr
!= NULL
);
695 /***********************************************************************
696 * GetClassWord (USER32.@)
698 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
703 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
705 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
707 if (class == CLASS_OTHER_PROCESS
)
709 SERVER_START_REQ( set_class_info
)
711 req
->window
= wine_server_user_handle( hwnd
);
713 req
->extra_offset
= offset
;
714 req
->extra_size
= sizeof(retvalue
);
715 if (!wine_server_call_err( req
))
716 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
722 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
723 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
725 SetLastError( ERROR_INVALID_INDEX
);
726 release_class_ptr( class );
731 /***********************************************************************
734 * Implementation of GetClassLong(Ptr)A/W
736 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
740 ULONG_PTR retvalue
= 0;
742 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
744 if (class == CLASS_OTHER_PROCESS
)
746 SERVER_START_REQ( set_class_info
)
748 req
->window
= wine_server_user_handle( hwnd
);
750 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
751 req
->extra_size
= (offset
>= 0) ? size
: 0;
752 if (!wine_server_call_err( req
))
756 case GCLP_HBRBACKGROUND
:
762 FIXME( "offset %d (%s) not supported on other process window %p\n",
763 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
764 SetLastError( ERROR_INVALID_HANDLE
);
767 retvalue
= reply
->old_style
;
770 retvalue
= reply
->old_win_extra
;
773 retvalue
= reply
->old_extra
;
776 retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
779 retvalue
= reply
->old_atom
;
784 if (size
== sizeof(DWORD
))
787 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
791 memcpy( &retvalue
, &reply
->old_extra_value
,
794 else SetLastError( ERROR_INVALID_INDEX
);
805 if (offset
<= class->cbClsExtra
- size
)
807 if (size
== sizeof(DWORD
))
810 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
814 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
817 SetLastError( ERROR_INVALID_INDEX
);
818 release_class_ptr( class );
824 case GCLP_HBRBACKGROUND
:
825 retvalue
= (ULONG_PTR
)class->hbrBackground
;
828 retvalue
= (ULONG_PTR
)class->hCursor
;
831 retvalue
= (ULONG_PTR
)class->hIcon
;
834 retvalue
= (ULONG_PTR
)(class->hIconSm
? class->hIconSm
: class->hIconSmIntern
);
837 retvalue
= class->style
;
840 retvalue
= class->cbWndExtra
;
843 retvalue
= class->cbClsExtra
;
846 retvalue
= (ULONG_PTR
)class->hInstance
;
849 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
852 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
854 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
856 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
859 retvalue
= class->atomName
;
862 SetLastError( ERROR_INVALID_INDEX
);
865 release_class_ptr( class );
870 /***********************************************************************
871 * GetClassLongW (USER32.@)
873 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
875 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
880 /***********************************************************************
881 * GetClassLongA (USER32.@)
883 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
885 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
889 /***********************************************************************
890 * SetClassWord (USER32.@)
892 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
897 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
899 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
901 SERVER_START_REQ( set_class_info
)
903 req
->window
= wine_server_user_handle( hwnd
);
904 req
->flags
= SET_CLASS_EXTRA
;
905 req
->extra_offset
= offset
;
906 req
->extra_size
= sizeof(newval
);
907 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
908 if (!wine_server_call_err( req
))
910 void *ptr
= (char *)(class + 1) + offset
;
911 memcpy( &retval
, ptr
, sizeof(retval
) );
912 memcpy( ptr
, &newval
, sizeof(newval
) );
916 release_class_ptr( class );
921 /***********************************************************************
924 * Implementation of SetClassLong(Ptr)A/W
926 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
927 UINT size
, BOOL unicode
)
930 ULONG_PTR retval
= 0;
932 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
936 if (set_server_info( hwnd
, offset
, newval
, size
))
938 void *ptr
= (char *)(class + 1) + offset
;
939 if ( size
== sizeof(LONG
) )
942 LONG newlong
= newval
;
943 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
944 memcpy( ptr
, &newlong
, sizeof(LONG
) );
949 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
950 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
958 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
960 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
961 retval
= 0; /* Old value is now meaningless anyway */
964 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
965 class->winproc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
967 case GCLP_HBRBACKGROUND
:
968 retval
= (ULONG_PTR
)class->hbrBackground
;
969 class->hbrBackground
= (HBRUSH
)newval
;
972 retval
= (ULONG_PTR
)class->hCursor
;
973 class->hCursor
= (HCURSOR
)newval
;
976 retval
= (ULONG_PTR
)class->hIcon
;
977 if (retval
&& class->hIconSmIntern
)
979 DestroyIcon(class->hIconSmIntern
);
980 class->hIconSmIntern
= NULL
;
982 if (newval
&& !class->hIconSm
)
983 class->hIconSmIntern
= CopyImage( (HICON
)newval
, IMAGE_ICON
,
984 GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
), 0 );
985 class->hIcon
= (HICON
)newval
;
988 retval
= (ULONG_PTR
)class->hIconSm
;
989 if (retval
&& !newval
)
990 class->hIconSmIntern
= class->hIcon
? CopyImage( class->hIcon
, IMAGE_ICON
,
991 GetSystemMetrics( SM_CXSMICON
),
992 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
993 else if (!retval
&& newval
&& class->hIconSmIntern
)
995 DestroyIcon(class->hIconSmIntern
);
996 class->hIconSmIntern
= NULL
;
998 class->hIconSm
= (HICON
)newval
;
1001 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1002 retval
= class->style
;
1003 class->style
= newval
;
1005 case GCL_CBWNDEXTRA
:
1006 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1007 retval
= class->cbWndExtra
;
1008 class->cbWndExtra
= newval
;
1011 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1012 retval
= (ULONG_PTR
)class->hInstance
;
1013 class->hInstance
= (HINSTANCE
)newval
;
1016 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1017 retval
= class->atomName
;
1018 class->atomName
= newval
;
1019 GlobalGetAtomNameW( newval
, class->name
, sizeof(class->name
)/sizeof(WCHAR
) );
1021 case GCL_CBCLSEXTRA
: /* cannot change this one */
1022 SetLastError( ERROR_INVALID_PARAMETER
);
1025 SetLastError( ERROR_INVALID_INDEX
);
1028 release_class_ptr( class );
1033 /***********************************************************************
1034 * SetClassLongW (USER32.@)
1036 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
1038 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
1042 /***********************************************************************
1043 * SetClassLongA (USER32.@)
1045 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
1047 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
1051 /***********************************************************************
1052 * GetClassNameA (USER32.@)
1054 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
1056 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1059 if (count
<= 0) return 0;
1060 if (!GetClassNameW( hwnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
1061 RtlUnicodeToMultiByteN( buffer
, count
- 1, &len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
1067 /***********************************************************************
1068 * GetClassNameW (USER32.@)
1070 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
1075 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
1077 if (count
<= 0) return 0;
1079 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
1081 if (class == CLASS_OTHER_PROCESS
)
1083 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1085 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
1088 ret
= min(count
- 1, ret
);
1089 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1095 lstrcpynW( buffer
, class->name
, count
);
1096 release_class_ptr( class );
1097 ret
= strlenW( buffer
);
1103 /***********************************************************************
1104 * RealGetWindowClassA (USER32.@)
1106 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1108 return GetClassNameA( hwnd
, buffer
, count
);
1112 /***********************************************************************
1113 * RealGetWindowClassW (USER32.@)
1115 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1117 return GetClassNameW( hwnd
, buffer
, count
);
1121 /***********************************************************************
1122 * GetClassInfoA (USER32.@)
1124 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1127 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1131 wc
->style
= wcex
.style
;
1132 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1133 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1134 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1135 wc
->hInstance
= wcex
.hInstance
;
1136 wc
->hIcon
= wcex
.hIcon
;
1137 wc
->hCursor
= wcex
.hCursor
;
1138 wc
->hbrBackground
= wcex
.hbrBackground
;
1139 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1140 wc
->lpszClassName
= wcex
.lpszClassName
;
1146 /***********************************************************************
1147 * GetClassInfoW (USER32.@)
1149 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1152 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1156 wc
->style
= wcex
.style
;
1157 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1158 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1159 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1160 wc
->hInstance
= wcex
.hInstance
;
1161 wc
->hIcon
= wcex
.hIcon
;
1162 wc
->hCursor
= wcex
.hCursor
;
1163 wc
->hbrBackground
= wcex
.hbrBackground
;
1164 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1165 wc
->lpszClassName
= wcex
.lpszClassName
;
1171 /***********************************************************************
1172 * GetClassInfoExA (USER32.@)
1174 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1179 TRACE("%p %s %p\n", hInstance
, debugstr_a(name
), wc
);
1183 SetLastError( ERROR_NOACCESS
);
1187 if (!hInstance
) hInstance
= user32_module
;
1189 if (!IS_INTRESOURCE(name
))
1191 WCHAR nameW
[MAX_ATOM_LEN
+ 1];
1192 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, sizeof(nameW
)/sizeof(WCHAR
) ))
1194 classPtr
= CLASS_FindClass( nameW
, hInstance
);
1196 else classPtr
= CLASS_FindClass( (LPCWSTR
)name
, hInstance
);
1200 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1203 wc
->style
= classPtr
->style
;
1204 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1205 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1206 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1207 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1208 wc
->hIcon
= classPtr
->hIcon
;
1209 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1210 wc
->hCursor
= classPtr
->hCursor
;
1211 wc
->hbrBackground
= classPtr
->hbrBackground
;
1212 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1213 wc
->lpszClassName
= name
;
1214 atom
= classPtr
->atomName
;
1215 release_class_ptr( classPtr
);
1217 /* We must return the atom of the class here instead of just TRUE. */
1222 /***********************************************************************
1223 * GetClassInfoExW (USER32.@)
1225 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1230 TRACE("%p %s %p\n", hInstance
, debugstr_w(name
), wc
);
1234 SetLastError( ERROR_NOACCESS
);
1238 if (!hInstance
) hInstance
= user32_module
;
1240 if (!(classPtr
= CLASS_FindClass( name
, hInstance
)))
1242 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1245 wc
->style
= classPtr
->style
;
1246 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1247 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1248 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1249 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1250 wc
->hIcon
= classPtr
->hIcon
;
1251 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1252 wc
->hCursor
= classPtr
->hCursor
;
1253 wc
->hbrBackground
= classPtr
->hbrBackground
;
1254 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1255 wc
->lpszClassName
= name
;
1256 atom
= classPtr
->atomName
;
1257 release_class_ptr( classPtr
);
1259 /* We must return the atom of the class here instead of just TRUE. */
1264 #if 0 /* toolhelp is in kernel, so this cannot work */
1266 /***********************************************************************
1267 * ClassFirst (TOOLHELP.69)
1269 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1271 TRACE("%p\n",pClassEntry
);
1272 pClassEntry
->wNext
= 1;
1273 return ClassNext16( pClassEntry
);
1277 /***********************************************************************
1278 * ClassNext (TOOLHELP.70)
1280 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1283 CLASS
*class = firstClass
;
1285 TRACE("%p\n",pClassEntry
);
1287 if (!pClassEntry
->wNext
) return FALSE
;
1288 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1291 pClassEntry
->wNext
= 0;
1294 pClassEntry
->hInst
= class->hInstance
;
1295 pClassEntry
->wNext
++;
1296 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1297 sizeof(pClassEntry
->szClassName
) );
1302 /* 64bit versions */
1304 #ifdef GetClassLongPtrA
1305 #undef GetClassLongPtrA
1308 #ifdef GetClassLongPtrW
1309 #undef GetClassLongPtrW
1312 #ifdef SetClassLongPtrA
1313 #undef SetClassLongPtrA
1316 #ifdef SetClassLongPtrW
1317 #undef SetClassLongPtrW
1320 /***********************************************************************
1321 * GetClassLongPtrA (USER32.@)
1323 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1325 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1328 /***********************************************************************
1329 * GetClassLongPtrW (USER32.@)
1331 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1333 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1336 /***********************************************************************
1337 * SetClassLongPtrW (USER32.@)
1339 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1341 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1344 /***********************************************************************
1345 * SetClassLongPtrA (USER32.@)
1347 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1349 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);