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
);
454 /***********************************************************************
455 * register_builtin_classes
457 void register_builtin_classes(void)
459 InitOnceExecuteOnce( &init_once
, register_builtins
, NULL
, NULL
);
463 /***********************************************************************
464 * register_desktop_class
466 void register_desktop_class(void)
468 register_builtin( &DESKTOP_builtin_class
);
469 register_builtin( &MESSAGE_builtin_class
);
473 /***********************************************************************
476 WNDPROC
get_class_winproc( CLASS
*class )
478 return class->winproc
;
482 /***********************************************************************
485 struct dce
*get_class_dce( CLASS
*class )
491 /***********************************************************************
494 struct dce
*set_class_dce( CLASS
*class, struct dce
*dce
)
496 if (class->dce
) return class->dce
; /* already set, don't change it */
502 /***********************************************************************
503 * RegisterClassA (USER32.@)
505 * Register a window class.
508 * >0: Unique identifier
511 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
515 wcex
.cbSize
= sizeof(wcex
);
516 wcex
.style
= wc
->style
;
517 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
518 wcex
.cbClsExtra
= wc
->cbClsExtra
;
519 wcex
.cbWndExtra
= wc
->cbWndExtra
;
520 wcex
.hInstance
= wc
->hInstance
;
521 wcex
.hIcon
= wc
->hIcon
;
522 wcex
.hCursor
= wc
->hCursor
;
523 wcex
.hbrBackground
= wc
->hbrBackground
;
524 wcex
.lpszMenuName
= wc
->lpszMenuName
;
525 wcex
.lpszClassName
= wc
->lpszClassName
;
527 return RegisterClassExA( &wcex
);
531 /***********************************************************************
532 * RegisterClassW (USER32.@)
534 * See RegisterClassA.
536 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
540 wcex
.cbSize
= sizeof(wcex
);
541 wcex
.style
= wc
->style
;
542 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
543 wcex
.cbClsExtra
= wc
->cbClsExtra
;
544 wcex
.cbWndExtra
= wc
->cbWndExtra
;
545 wcex
.hInstance
= wc
->hInstance
;
546 wcex
.hIcon
= wc
->hIcon
;
547 wcex
.hCursor
= wc
->hCursor
;
548 wcex
.hbrBackground
= wc
->hbrBackground
;
549 wcex
.lpszMenuName
= wc
->lpszMenuName
;
550 wcex
.lpszClassName
= wc
->lpszClassName
;
552 return RegisterClassExW( &wcex
);
556 /***********************************************************************
557 * RegisterClassExA (USER32.@)
559 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
565 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
567 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
568 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
570 SetLastError( ERROR_INVALID_PARAMETER
);
573 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
575 if (!IS_INTRESOURCE(wc
->lpszClassName
))
577 WCHAR name
[MAX_ATOM_LEN
+ 1];
579 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
580 classPtr
= CLASS_RegisterClass( name
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
581 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
585 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, instance
,
586 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
587 wc
->cbClsExtra
, wc
->cbWndExtra
);
589 if (!classPtr
) return 0;
590 atom
= classPtr
->atomName
;
592 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
593 debugstr_a(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
594 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
596 classPtr
->hIcon
= wc
->hIcon
;
597 classPtr
->hIconSm
= wc
->hIconSm
;
598 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
599 CopyImage( wc
->hIcon
, IMAGE_ICON
,
600 GetSystemMetrics( SM_CXSMICON
),
601 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
602 classPtr
->hCursor
= wc
->hCursor
;
603 classPtr
->hbrBackground
= wc
->hbrBackground
;
604 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, FALSE
);
605 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
606 release_class_ptr( classPtr
);
611 /***********************************************************************
612 * RegisterClassExW (USER32.@)
614 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
620 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
622 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
623 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
625 SetLastError( ERROR_INVALID_PARAMETER
);
628 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
630 if (!(classPtr
= CLASS_RegisterClass( wc
->lpszClassName
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
631 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
634 atom
= classPtr
->atomName
;
636 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
637 debugstr_w(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
638 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
640 classPtr
->hIcon
= wc
->hIcon
;
641 classPtr
->hIconSm
= wc
->hIconSm
;
642 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
643 CopyImage( wc
->hIcon
, IMAGE_ICON
,
644 GetSystemMetrics( SM_CXSMICON
),
645 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
646 classPtr
->hCursor
= wc
->hCursor
;
647 classPtr
->hbrBackground
= wc
->hbrBackground
;
648 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, TRUE
);
649 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
650 release_class_ptr( classPtr
);
655 /***********************************************************************
656 * UnregisterClassA (USER32.@)
658 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
660 if (!IS_INTRESOURCE(className
))
662 WCHAR name
[MAX_ATOM_LEN
+ 1];
664 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
666 return UnregisterClassW( name
, hInstance
);
668 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
671 /***********************************************************************
672 * UnregisterClassW (USER32.@)
674 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
676 CLASS
*classPtr
= NULL
;
678 GetDesktopWindow(); /* create the desktop window to trigger builtin class registration */
680 SERVER_START_REQ( destroy_class
)
682 req
->instance
= wine_server_client_ptr( hInstance
);
683 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
684 wine_server_add_data( req
, className
, strlenW(className
) * sizeof(WCHAR
) );
685 if (!wine_server_call_err( req
)) classPtr
= wine_server_get_ptr( reply
->client_ptr
);
689 if (classPtr
) CLASS_FreeClass( classPtr
);
690 return (classPtr
!= NULL
);
694 /***********************************************************************
695 * GetClassWord (USER32.@)
697 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
702 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
704 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
706 if (class == CLASS_OTHER_PROCESS
)
708 SERVER_START_REQ( set_class_info
)
710 req
->window
= wine_server_user_handle( hwnd
);
712 req
->extra_offset
= offset
;
713 req
->extra_size
= sizeof(retvalue
);
714 if (!wine_server_call_err( req
))
715 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
721 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
722 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
724 SetLastError( ERROR_INVALID_INDEX
);
725 release_class_ptr( class );
730 /***********************************************************************
733 * Implementation of GetClassLong(Ptr)A/W
735 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
739 ULONG_PTR retvalue
= 0;
741 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
743 if (class == CLASS_OTHER_PROCESS
)
745 SERVER_START_REQ( set_class_info
)
747 req
->window
= wine_server_user_handle( hwnd
);
749 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
750 req
->extra_size
= (offset
>= 0) ? size
: 0;
751 if (!wine_server_call_err( req
))
755 case GCLP_HBRBACKGROUND
:
761 FIXME( "offset %d (%s) not supported on other process window %p\n",
762 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
763 SetLastError( ERROR_INVALID_HANDLE
);
766 retvalue
= reply
->old_style
;
769 retvalue
= reply
->old_win_extra
;
772 retvalue
= reply
->old_extra
;
775 retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
778 retvalue
= reply
->old_atom
;
783 if (size
== sizeof(DWORD
))
786 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
790 memcpy( &retvalue
, &reply
->old_extra_value
,
793 else SetLastError( ERROR_INVALID_INDEX
);
804 if (offset
<= class->cbClsExtra
- size
)
806 if (size
== sizeof(DWORD
))
809 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
813 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
816 SetLastError( ERROR_INVALID_INDEX
);
817 release_class_ptr( class );
823 case GCLP_HBRBACKGROUND
:
824 retvalue
= (ULONG_PTR
)class->hbrBackground
;
827 retvalue
= (ULONG_PTR
)class->hCursor
;
830 retvalue
= (ULONG_PTR
)class->hIcon
;
833 retvalue
= (ULONG_PTR
)(class->hIconSm
? class->hIconSm
: class->hIconSmIntern
);
836 retvalue
= class->style
;
839 retvalue
= class->cbWndExtra
;
842 retvalue
= class->cbClsExtra
;
845 retvalue
= (ULONG_PTR
)class->hInstance
;
848 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
851 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
853 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
855 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
858 retvalue
= class->atomName
;
861 SetLastError( ERROR_INVALID_INDEX
);
864 release_class_ptr( class );
869 /***********************************************************************
870 * GetClassLongW (USER32.@)
872 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
874 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
879 /***********************************************************************
880 * GetClassLongA (USER32.@)
882 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
884 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
888 /***********************************************************************
889 * SetClassWord (USER32.@)
891 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
896 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
898 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
900 SERVER_START_REQ( set_class_info
)
902 req
->window
= wine_server_user_handle( hwnd
);
903 req
->flags
= SET_CLASS_EXTRA
;
904 req
->extra_offset
= offset
;
905 req
->extra_size
= sizeof(newval
);
906 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
907 if (!wine_server_call_err( req
))
909 void *ptr
= (char *)(class + 1) + offset
;
910 memcpy( &retval
, ptr
, sizeof(retval
) );
911 memcpy( ptr
, &newval
, sizeof(newval
) );
915 release_class_ptr( class );
920 /***********************************************************************
923 * Implementation of SetClassLong(Ptr)A/W
925 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
926 UINT size
, BOOL unicode
)
929 ULONG_PTR retval
= 0;
931 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
935 if (set_server_info( hwnd
, offset
, newval
, size
))
937 void *ptr
= (char *)(class + 1) + offset
;
938 if ( size
== sizeof(LONG
) )
941 LONG newlong
= newval
;
942 memcpy( &retdword
, ptr
, sizeof(DWORD
) );
943 memcpy( ptr
, &newlong
, sizeof(LONG
) );
948 memcpy( &retval
, ptr
, sizeof(ULONG_PTR
) );
949 memcpy( ptr
, &newval
, sizeof(LONG_PTR
) );
957 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
959 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
960 retval
= 0; /* Old value is now meaningless anyway */
963 retval
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
964 class->winproc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
966 case GCLP_HBRBACKGROUND
:
967 retval
= (ULONG_PTR
)class->hbrBackground
;
968 class->hbrBackground
= (HBRUSH
)newval
;
971 retval
= (ULONG_PTR
)class->hCursor
;
972 class->hCursor
= (HCURSOR
)newval
;
975 retval
= (ULONG_PTR
)class->hIcon
;
976 if (retval
&& class->hIconSmIntern
)
978 DestroyIcon(class->hIconSmIntern
);
979 class->hIconSmIntern
= NULL
;
981 if (newval
&& !class->hIconSm
)
982 class->hIconSmIntern
= CopyImage( (HICON
)newval
, IMAGE_ICON
,
983 GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
), 0 );
984 class->hIcon
= (HICON
)newval
;
987 retval
= (ULONG_PTR
)class->hIconSm
;
988 if (retval
&& !newval
)
989 class->hIconSmIntern
= class->hIcon
? CopyImage( class->hIcon
, IMAGE_ICON
,
990 GetSystemMetrics( SM_CXSMICON
),
991 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
992 else if (!retval
&& newval
&& class->hIconSmIntern
)
994 DestroyIcon(class->hIconSmIntern
);
995 class->hIconSmIntern
= NULL
;
997 class->hIconSm
= (HICON
)newval
;
1000 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1001 retval
= class->style
;
1002 class->style
= newval
;
1004 case GCL_CBWNDEXTRA
:
1005 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1006 retval
= class->cbWndExtra
;
1007 class->cbWndExtra
= newval
;
1010 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1011 retval
= (ULONG_PTR
)class->hInstance
;
1012 class->hInstance
= (HINSTANCE
)newval
;
1015 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
1016 retval
= class->atomName
;
1017 class->atomName
= newval
;
1018 GlobalGetAtomNameW( newval
, class->name
, sizeof(class->name
)/sizeof(WCHAR
) );
1020 case GCL_CBCLSEXTRA
: /* cannot change this one */
1021 SetLastError( ERROR_INVALID_PARAMETER
);
1024 SetLastError( ERROR_INVALID_INDEX
);
1027 release_class_ptr( class );
1032 /***********************************************************************
1033 * SetClassLongW (USER32.@)
1035 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
1037 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
1041 /***********************************************************************
1042 * SetClassLongA (USER32.@)
1044 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
1046 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
1050 /***********************************************************************
1051 * GetClassNameA (USER32.@)
1053 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
1055 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1058 if (count
<= 0) return 0;
1059 if (!GetClassNameW( hwnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
1060 RtlUnicodeToMultiByteN( buffer
, count
- 1, &len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
1066 /***********************************************************************
1067 * GetClassNameW (USER32.@)
1069 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
1074 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
1076 if (count
<= 0) return 0;
1078 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
1080 if (class == CLASS_OTHER_PROCESS
)
1082 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1084 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
1087 ret
= min(count
- 1, ret
);
1088 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1094 lstrcpynW( buffer
, class->name
, count
);
1095 release_class_ptr( class );
1096 ret
= strlenW( buffer
);
1102 /***********************************************************************
1103 * RealGetWindowClassA (USER32.@)
1105 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1107 return GetClassNameA( hwnd
, buffer
, count
);
1111 /***********************************************************************
1112 * RealGetWindowClassW (USER32.@)
1114 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1116 return GetClassNameW( hwnd
, buffer
, count
);
1120 /***********************************************************************
1121 * GetClassInfoA (USER32.@)
1123 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1126 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1130 wc
->style
= wcex
.style
;
1131 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1132 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1133 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1134 wc
->hInstance
= wcex
.hInstance
;
1135 wc
->hIcon
= wcex
.hIcon
;
1136 wc
->hCursor
= wcex
.hCursor
;
1137 wc
->hbrBackground
= wcex
.hbrBackground
;
1138 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1139 wc
->lpszClassName
= wcex
.lpszClassName
;
1145 /***********************************************************************
1146 * GetClassInfoW (USER32.@)
1148 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1151 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1155 wc
->style
= wcex
.style
;
1156 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1157 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1158 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1159 wc
->hInstance
= wcex
.hInstance
;
1160 wc
->hIcon
= wcex
.hIcon
;
1161 wc
->hCursor
= wcex
.hCursor
;
1162 wc
->hbrBackground
= wcex
.hbrBackground
;
1163 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1164 wc
->lpszClassName
= wcex
.lpszClassName
;
1170 /***********************************************************************
1171 * GetClassInfoExA (USER32.@)
1173 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1178 TRACE("%p %s %p\n", hInstance
, debugstr_a(name
), wc
);
1182 SetLastError( ERROR_NOACCESS
);
1186 if (!hInstance
) hInstance
= user32_module
;
1188 if (!IS_INTRESOURCE(name
))
1190 WCHAR nameW
[MAX_ATOM_LEN
+ 1];
1191 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, sizeof(nameW
)/sizeof(WCHAR
) ))
1193 classPtr
= CLASS_FindClass( nameW
, hInstance
);
1195 else classPtr
= CLASS_FindClass( (LPCWSTR
)name
, hInstance
);
1199 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1202 wc
->style
= classPtr
->style
;
1203 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1204 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1205 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1206 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1207 wc
->hIcon
= classPtr
->hIcon
;
1208 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1209 wc
->hCursor
= classPtr
->hCursor
;
1210 wc
->hbrBackground
= classPtr
->hbrBackground
;
1211 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1212 wc
->lpszClassName
= name
;
1213 atom
= classPtr
->atomName
;
1214 release_class_ptr( classPtr
);
1216 /* We must return the atom of the class here instead of just TRUE. */
1221 /***********************************************************************
1222 * GetClassInfoExW (USER32.@)
1224 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1229 TRACE("%p %s %p\n", hInstance
, debugstr_w(name
), wc
);
1233 SetLastError( ERROR_NOACCESS
);
1237 if (!hInstance
) hInstance
= user32_module
;
1239 if (!(classPtr
= CLASS_FindClass( name
, hInstance
)))
1241 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1244 wc
->style
= classPtr
->style
;
1245 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1246 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1247 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1248 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1249 wc
->hIcon
= classPtr
->hIcon
;
1250 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1251 wc
->hCursor
= classPtr
->hCursor
;
1252 wc
->hbrBackground
= classPtr
->hbrBackground
;
1253 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1254 wc
->lpszClassName
= name
;
1255 atom
= classPtr
->atomName
;
1256 release_class_ptr( classPtr
);
1258 /* We must return the atom of the class here instead of just TRUE. */
1263 #if 0 /* toolhelp is in kernel, so this cannot work */
1265 /***********************************************************************
1266 * ClassFirst (TOOLHELP.69)
1268 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1270 TRACE("%p\n",pClassEntry
);
1271 pClassEntry
->wNext
= 1;
1272 return ClassNext16( pClassEntry
);
1276 /***********************************************************************
1277 * ClassNext (TOOLHELP.70)
1279 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1282 CLASS
*class = firstClass
;
1284 TRACE("%p\n",pClassEntry
);
1286 if (!pClassEntry
->wNext
) return FALSE
;
1287 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1290 pClassEntry
->wNext
= 0;
1293 pClassEntry
->hInst
= class->hInstance
;
1294 pClassEntry
->wNext
++;
1295 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1296 sizeof(pClassEntry
->szClassName
) );
1301 /* 64bit versions */
1303 #ifdef GetClassLongPtrA
1304 #undef GetClassLongPtrA
1307 #ifdef GetClassLongPtrW
1308 #undef GetClassLongPtrW
1311 #ifdef SetClassLongPtrA
1312 #undef SetClassLongPtrA
1315 #ifdef SetClassLongPtrW
1316 #undef SetClassLongPtrW
1319 /***********************************************************************
1320 * GetClassLongPtrA (USER32.@)
1322 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1324 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1327 /***********************************************************************
1328 * GetClassLongPtrW (USER32.@)
1330 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1332 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1335 /***********************************************************************
1336 * SetClassLongPtrW (USER32.@)
1338 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1340 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1343 /***********************************************************************
1344 * SetClassLongPtrA (USER32.@)
1346 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1348 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);