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
);
68 #define CLASS_OTHER_PROCESS ((CLASS *)1)
70 /***********************************************************************
73 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
75 WND
*ptr
= WIN_GetPtr( hwnd
);
79 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
) return ptr
->class;
80 if (!write_access
) return CLASS_OTHER_PROCESS
;
82 /* modifying classes in other processes is not allowed */
83 if (ptr
== WND_DESKTOP
|| IsWindow( hwnd
))
85 SetLastError( ERROR_ACCESS_DENIED
);
89 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
94 /***********************************************************************
97 static inline void release_class_ptr( CLASS
*ptr
)
103 /***********************************************************************
106 ATOM
get_int_atom_value( LPCWSTR name
)
110 if (IS_INTRESOURCE(name
)) return LOWORD(name
);
111 if (*name
++ != '#') return 0;
114 if (*name
< '0' || *name
> '9') return 0;
115 ret
= ret
* 10 + *name
++ - '0';
116 if (ret
> 0xffff) return 0;
122 /***********************************************************************
125 * Set class info with the wine server.
127 static BOOL
set_server_info( HWND hwnd
, INT offset
, LONG_PTR newval
, UINT size
)
131 SERVER_START_REQ( set_class_info
)
133 req
->window
= wine_server_user_handle( hwnd
);
134 req
->extra_offset
= -1;
138 req
->flags
= SET_CLASS_ATOM
;
139 req
->atom
= LOWORD(newval
);
142 req
->flags
= SET_CLASS_STYLE
;
146 req
->flags
= SET_CLASS_WINEXTRA
;
147 req
->win_extra
= newval
;
150 req
->flags
= SET_CLASS_INSTANCE
;
151 req
->instance
= wine_server_client_ptr( (void *)newval
);
154 assert( offset
>= 0 );
155 req
->flags
= SET_CLASS_EXTRA
;
156 req
->extra_offset
= offset
;
157 req
->extra_size
= size
;
158 if ( size
== sizeof(LONG
) )
160 LONG newlong
= newval
;
161 memcpy( &req
->extra_value
, &newlong
, sizeof(LONG
) );
164 memcpy( &req
->extra_value
, &newval
, sizeof(LONG_PTR
) );
167 ret
= !wine_server_call_err( req
);
174 /***********************************************************************
177 * Get the menu name as a ASCII string.
179 static inline LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
181 if (IS_INTRESOURCE(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
182 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
186 /***********************************************************************
189 * Get the menu name as a Unicode string.
191 static inline LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
193 return classPtr
->menuName
;
197 /***********************************************************************
200 * Set the menu name in a class structure by copying the string.
202 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
204 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
205 if (!IS_INTRESOURCE(name
))
207 DWORD lenA
= strlen(name
) + 1;
208 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
209 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
210 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
211 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
213 else classPtr
->menuName
= (LPWSTR
)name
;
217 /***********************************************************************
220 * Set the menu name in a class structure by copying the string.
222 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
224 if (!IS_INTRESOURCE(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
225 if (!IS_INTRESOURCE(name
))
227 DWORD lenW
= strlenW(name
) + 1;
228 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
229 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
230 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
231 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
232 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
234 else classPtr
->menuName
= (LPWSTR
)name
;
238 /***********************************************************************
241 * Free a class structure.
243 static void CLASS_FreeClass( CLASS
*classPtr
)
245 TRACE("%p\n", classPtr
);
249 if (classPtr
->dce
) free_dce( classPtr
->dce
, 0 );
250 list_remove( &classPtr
->entry
);
251 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
252 DeleteObject( classPtr
->hbrBackground
);
253 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
254 HeapFree( GetProcessHeap(), 0, classPtr
);
259 /***********************************************************************
262 * Return a pointer to the class.
263 * hinstance has been normalized by the caller.
265 static CLASS
*CLASS_FindClass( LPCWSTR name
, HINSTANCE hinstance
)
268 ATOM atom
= get_int_atom_value( name
);
272 LIST_FOR_EACH( ptr
, &class_list
)
274 CLASS
*class = LIST_ENTRY( ptr
, CLASS
, entry
);
277 if (class->atomName
!= atom
) continue;
281 if (!name
|| strcmpiW( class->name
, name
)) continue;
283 if (!hinstance
|| !class->local
|| class->hInstance
== hinstance
)
285 TRACE("%s %p -> %p\n", debugstr_w(name
), hinstance
, class);
290 TRACE("%s %p -> not found\n", debugstr_w(name
), hinstance
);
295 /***********************************************************************
296 * CLASS_RegisterClass
298 * The real RegisterClass() functionality.
300 static CLASS
*CLASS_RegisterClass( LPCWSTR name
, HINSTANCE hInstance
, BOOL local
,
301 DWORD style
, INT classExtra
, INT winExtra
)
306 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
307 debugstr_w(name
), hInstance
, style
, classExtra
, winExtra
);
309 /* Fix the extra bytes value */
311 if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
312 WARN("Class extra bytes %d is > 40\n", classExtra
);
313 if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
314 WARN("Win extra bytes %d is > 40\n", winExtra
);
316 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
317 if (!classPtr
) return NULL
;
319 classPtr
->atomName
= get_int_atom_value( name
);
320 if (!classPtr
->atomName
&& name
) strcpyW( classPtr
->name
, name
);
321 else GlobalGetAtomNameW( classPtr
->atomName
, classPtr
->name
, sizeof(classPtr
->name
)/sizeof(WCHAR
) );
323 SERVER_START_REQ( create_class
)
327 req
->instance
= wine_server_client_ptr( hInstance
);
328 req
->extra
= classExtra
;
329 req
->win_extra
= winExtra
;
330 req
->client_ptr
= wine_server_client_ptr( classPtr
);
331 req
->atom
= classPtr
->atomName
;
332 if (!req
->atom
&& name
) wine_server_add_data( req
, name
, strlenW(name
) * sizeof(WCHAR
) );
333 ret
= !wine_server_call_err( req
);
334 classPtr
->atomName
= reply
->atom
;
339 HeapFree( GetProcessHeap(), 0, classPtr
);
343 classPtr
->style
= style
;
344 classPtr
->local
= local
;
345 classPtr
->cbWndExtra
= winExtra
;
346 classPtr
->cbClsExtra
= classExtra
;
347 classPtr
->hInstance
= hInstance
;
349 /* Other non-null values must be set by caller */
352 if (local
) list_add_head( &class_list
, &classPtr
->entry
);
353 else list_add_tail( &class_list
, &classPtr
->entry
);
358 /***********************************************************************
361 * Register a builtin control class.
362 * This allows having both ASCII and Unicode winprocs for the same class.
364 static void register_builtin( const struct builtin_class_descr
*descr
)
368 if (!(classPtr
= CLASS_RegisterClass( descr
->name
, user32_module
, FALSE
,
369 descr
->style
, 0, descr
->extra
))) return;
371 classPtr
->hCursor
= LoadCursorA( 0, (LPSTR
)descr
->cursor
);
372 classPtr
->hbrBackground
= descr
->brush
;
373 classPtr
->winproc
= BUILTIN_WINPROC( descr
->proc
);
374 release_class_ptr( classPtr
);
378 /***********************************************************************
379 * CLASS_RegisterBuiltinClasses
381 void CLASS_RegisterBuiltinClasses(void)
383 register_builtin( &DESKTOP_builtin_class
);
384 register_builtin( &BUTTON_builtin_class
);
385 register_builtin( &COMBO_builtin_class
);
386 register_builtin( &COMBOLBOX_builtin_class
);
387 register_builtin( &DIALOG_builtin_class
);
388 register_builtin( &EDIT_builtin_class
);
389 register_builtin( &ICONTITLE_builtin_class
);
390 register_builtin( &LISTBOX_builtin_class
);
391 register_builtin( &MDICLIENT_builtin_class
);
392 register_builtin( &MENU_builtin_class
);
393 register_builtin( &MESSAGE_builtin_class
);
394 register_builtin( &SCROLL_builtin_class
);
395 register_builtin( &STATIC_builtin_class
);
399 /***********************************************************************
402 WNDPROC
get_class_winproc( CLASS
*class )
404 return class->winproc
;
408 /***********************************************************************
411 struct dce
*get_class_dce( CLASS
*class )
417 /***********************************************************************
420 struct dce
*set_class_dce( CLASS
*class, struct dce
*dce
)
422 if (class->dce
) return class->dce
; /* already set, don't change it */
428 /***********************************************************************
429 * RegisterClassA (USER32.@)
431 * Register a window class.
434 * >0: Unique identifier
437 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
441 wcex
.cbSize
= sizeof(wcex
);
442 wcex
.style
= wc
->style
;
443 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
444 wcex
.cbClsExtra
= wc
->cbClsExtra
;
445 wcex
.cbWndExtra
= wc
->cbWndExtra
;
446 wcex
.hInstance
= wc
->hInstance
;
447 wcex
.hIcon
= wc
->hIcon
;
448 wcex
.hCursor
= wc
->hCursor
;
449 wcex
.hbrBackground
= wc
->hbrBackground
;
450 wcex
.lpszMenuName
= wc
->lpszMenuName
;
451 wcex
.lpszClassName
= wc
->lpszClassName
;
453 return RegisterClassExA( &wcex
);
457 /***********************************************************************
458 * RegisterClassW (USER32.@)
460 * See RegisterClassA.
462 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
466 wcex
.cbSize
= sizeof(wcex
);
467 wcex
.style
= wc
->style
;
468 wcex
.lpfnWndProc
= wc
->lpfnWndProc
;
469 wcex
.cbClsExtra
= wc
->cbClsExtra
;
470 wcex
.cbWndExtra
= wc
->cbWndExtra
;
471 wcex
.hInstance
= wc
->hInstance
;
472 wcex
.hIcon
= wc
->hIcon
;
473 wcex
.hCursor
= wc
->hCursor
;
474 wcex
.hbrBackground
= wc
->hbrBackground
;
475 wcex
.lpszMenuName
= wc
->lpszMenuName
;
476 wcex
.lpszClassName
= wc
->lpszClassName
;
478 return RegisterClassExW( &wcex
);
482 /***********************************************************************
483 * RegisterClassExA (USER32.@)
485 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
491 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
492 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
494 SetLastError( ERROR_INVALID_PARAMETER
);
497 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
499 if (!IS_INTRESOURCE(wc
->lpszClassName
))
501 WCHAR name
[MAX_ATOM_LEN
+ 1];
503 if (!MultiByteToWideChar( CP_ACP
, 0, wc
->lpszClassName
, -1, name
, MAX_ATOM_LEN
+ 1 )) return 0;
504 classPtr
= CLASS_RegisterClass( name
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
505 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
);
509 classPtr
= CLASS_RegisterClass( (LPCWSTR
)wc
->lpszClassName
, instance
,
510 !(wc
->style
& CS_GLOBALCLASS
), wc
->style
,
511 wc
->cbClsExtra
, wc
->cbWndExtra
);
513 if (!classPtr
) return 0;
514 atom
= classPtr
->atomName
;
516 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
517 debugstr_a(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
518 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
520 classPtr
->hIcon
= wc
->hIcon
;
521 classPtr
->hIconSm
= wc
->hIconSm
;
522 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
523 CopyImage( wc
->hIcon
, IMAGE_ICON
,
524 GetSystemMetrics( SM_CXSMICON
),
525 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
526 classPtr
->hCursor
= wc
->hCursor
;
527 classPtr
->hbrBackground
= wc
->hbrBackground
;
528 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, FALSE
);
529 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
530 release_class_ptr( classPtr
);
535 /***********************************************************************
536 * RegisterClassExW (USER32.@)
538 ATOM WINAPI
RegisterClassExW( const WNDCLASSEXW
* wc
)
544 if (wc
->cbSize
!= sizeof(*wc
) || wc
->cbClsExtra
< 0 || wc
->cbWndExtra
< 0 ||
545 wc
->hInstance
== user32_module
) /* we can't register a class for user32 */
547 SetLastError( ERROR_INVALID_PARAMETER
);
550 if (!(instance
= wc
->hInstance
)) instance
= GetModuleHandleW( NULL
);
552 if (!(classPtr
= CLASS_RegisterClass( wc
->lpszClassName
, instance
, !(wc
->style
& CS_GLOBALCLASS
),
553 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
)))
556 atom
= classPtr
->atomName
;
558 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
559 debugstr_w(wc
->lpszClassName
), atom
, wc
->lpfnWndProc
, instance
, wc
->hbrBackground
,
560 wc
->style
, wc
->cbClsExtra
, wc
->cbWndExtra
, classPtr
);
562 classPtr
->hIcon
= wc
->hIcon
;
563 classPtr
->hIconSm
= wc
->hIconSm
;
564 classPtr
->hIconSmIntern
= wc
->hIcon
&& !wc
->hIconSm
?
565 CopyImage( wc
->hIcon
, IMAGE_ICON
,
566 GetSystemMetrics( SM_CXSMICON
),
567 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
568 classPtr
->hCursor
= wc
->hCursor
;
569 classPtr
->hbrBackground
= wc
->hbrBackground
;
570 classPtr
->winproc
= WINPROC_AllocProc( wc
->lpfnWndProc
, TRUE
);
571 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
572 release_class_ptr( classPtr
);
577 /***********************************************************************
578 * UnregisterClassA (USER32.@)
580 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
582 if (!IS_INTRESOURCE(className
))
584 WCHAR name
[MAX_ATOM_LEN
+ 1];
586 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, name
, MAX_ATOM_LEN
+ 1 ))
588 return UnregisterClassW( name
, hInstance
);
590 return UnregisterClassW( (LPCWSTR
)className
, hInstance
);
593 /***********************************************************************
594 * UnregisterClassW (USER32.@)
596 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
598 CLASS
*classPtr
= NULL
;
600 SERVER_START_REQ( destroy_class
)
602 req
->instance
= wine_server_client_ptr( hInstance
);
603 if (!(req
->atom
= get_int_atom_value(className
)) && className
)
604 wine_server_add_data( req
, className
, strlenW(className
) * sizeof(WCHAR
) );
605 if (!wine_server_call_err( req
)) classPtr
= wine_server_get_ptr( reply
->client_ptr
);
609 if (classPtr
) CLASS_FreeClass( classPtr
);
610 return (classPtr
!= NULL
);
614 /***********************************************************************
615 * GetClassWord (USER32.@)
617 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
622 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
624 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
626 if (class == CLASS_OTHER_PROCESS
)
628 SERVER_START_REQ( set_class_info
)
630 req
->window
= wine_server_user_handle( hwnd
);
632 req
->extra_offset
= offset
;
633 req
->extra_size
= sizeof(retvalue
);
634 if (!wine_server_call_err( req
))
635 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
641 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
642 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
644 SetLastError( ERROR_INVALID_INDEX
);
645 release_class_ptr( class );
650 /***********************************************************************
653 * Implementation of GetClassLong(Ptr)A/W
655 static ULONG_PTR
CLASS_GetClassLong( HWND hwnd
, INT offset
, UINT size
,
659 ULONG_PTR retvalue
= 0;
661 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
663 if (class == CLASS_OTHER_PROCESS
)
665 SERVER_START_REQ( set_class_info
)
667 req
->window
= wine_server_user_handle( hwnd
);
669 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
670 req
->extra_size
= (offset
>= 0) ? size
: 0;
671 if (!wine_server_call_err( req
))
675 case GCLP_HBRBACKGROUND
:
681 FIXME( "offset %d (%s) not supported on other process window %p\n",
682 offset
, SPY_GetClassLongOffsetName(offset
), hwnd
);
683 SetLastError( ERROR_INVALID_HANDLE
);
686 retvalue
= reply
->old_style
;
689 retvalue
= reply
->old_win_extra
;
692 retvalue
= reply
->old_extra
;
695 retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
698 retvalue
= reply
->old_atom
;
703 if (size
== sizeof(DWORD
))
706 memcpy( &retdword
, &reply
->old_extra_value
, sizeof(DWORD
) );
710 memcpy( &retvalue
, &reply
->old_extra_value
,
713 else SetLastError( ERROR_INVALID_INDEX
);
724 if (offset
<= class->cbClsExtra
- size
)
726 if (size
== sizeof(DWORD
))
729 memcpy( &retdword
, (char *)(class + 1) + offset
, sizeof(DWORD
) );
733 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(ULONG_PTR
) );
736 SetLastError( ERROR_INVALID_INDEX
);
737 release_class_ptr( class );
743 case GCLP_HBRBACKGROUND
:
744 retvalue
= (ULONG_PTR
)class->hbrBackground
;
747 retvalue
= (ULONG_PTR
)class->hCursor
;
750 retvalue
= (ULONG_PTR
)class->hIcon
;
753 retvalue
= (ULONG_PTR
)(class->hIconSm
? class->hIconSm
: class->hIconSmIntern
);
756 retvalue
= class->style
;
759 retvalue
= class->cbWndExtra
;
762 retvalue
= class->cbClsExtra
;
765 retvalue
= (ULONG_PTR
)class->hInstance
;
768 retvalue
= (ULONG_PTR
)WINPROC_GetProc( class->winproc
, unicode
);
771 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
773 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameW( class );
775 retvalue
= (ULONG_PTR
)CLASS_GetMenuNameA( class );
778 retvalue
= class->atomName
;
781 SetLastError( ERROR_INVALID_INDEX
);
784 release_class_ptr( class );
789 /***********************************************************************
790 * GetClassLongW (USER32.@)
792 DWORD WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
794 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), TRUE
);
799 /***********************************************************************
800 * GetClassLongA (USER32.@)
802 DWORD WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
804 return CLASS_GetClassLong( hwnd
, offset
, sizeof(DWORD
), FALSE
);
808 /***********************************************************************
809 * SetClassWord (USER32.@)
811 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
816 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
818 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
820 SERVER_START_REQ( set_class_info
)
822 req
->window
= wine_server_user_handle( hwnd
);
823 req
->flags
= SET_CLASS_EXTRA
;
824 req
->extra_offset
= offset
;
825 req
->extra_size
= sizeof(newval
);
826 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
827 if (!wine_server_call_err( req
))
829 void *ptr
= (char *)(class + 1) + offset
;
830 memcpy( &retval
, ptr
, sizeof(retval
) );
831 memcpy( ptr
, &newval
, sizeof(newval
) );
835 release_class_ptr( class );
840 /***********************************************************************
843 * Implementation of SetClassLong(Ptr)A/W
845 static ULONG_PTR
CLASS_SetClassLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
846 UINT size
, BOOL unicode
)
849 ULONG_PTR retval
= 0;
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( (WNDPROC
)newval
, unicode
);
886 case GCLP_HBRBACKGROUND
:
887 retval
= (ULONG_PTR
)class->hbrBackground
;
888 class->hbrBackground
= (HBRUSH
)newval
;
891 retval
= (ULONG_PTR
)class->hCursor
;
892 class->hCursor
= (HCURSOR
)newval
;
895 retval
= (ULONG_PTR
)class->hIcon
;
896 if (retval
&& class->hIconSmIntern
)
898 DestroyIcon(class->hIconSmIntern
);
899 class->hIconSmIntern
= NULL
;
901 if (newval
&& !class->hIconSm
)
902 class->hIconSmIntern
= CopyImage( (HICON
)newval
, IMAGE_ICON
,
903 GetSystemMetrics( SM_CXSMICON
), GetSystemMetrics( SM_CYSMICON
), 0 );
904 class->hIcon
= (HICON
)newval
;
907 retval
= (ULONG_PTR
)class->hIconSm
;
908 if (retval
&& !newval
)
909 class->hIconSmIntern
= class->hIcon
? CopyImage( class->hIcon
, IMAGE_ICON
,
910 GetSystemMetrics( SM_CXSMICON
),
911 GetSystemMetrics( SM_CYSMICON
), 0 ) : NULL
;
912 else if (!retval
&& newval
&& class->hIconSmIntern
)
914 DestroyIcon(class->hIconSmIntern
);
915 class->hIconSmIntern
= NULL
;
917 class->hIconSm
= (HICON
)newval
;
920 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
921 retval
= class->style
;
922 class->style
= newval
;
925 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
926 retval
= class->cbWndExtra
;
927 class->cbWndExtra
= newval
;
930 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
931 retval
= (ULONG_PTR
)class->hInstance
;
932 class->hInstance
= (HINSTANCE
)newval
;
935 if (!set_server_info( hwnd
, offset
, newval
, size
)) break;
936 retval
= class->atomName
;
937 class->atomName
= newval
;
938 GlobalGetAtomNameW( newval
, class->name
, sizeof(class->name
)/sizeof(WCHAR
) );
940 case GCL_CBCLSEXTRA
: /* cannot change this one */
941 SetLastError( ERROR_INVALID_PARAMETER
);
944 SetLastError( ERROR_INVALID_INDEX
);
947 release_class_ptr( class );
952 /***********************************************************************
953 * SetClassLongW (USER32.@)
955 DWORD WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
957 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), TRUE
);
961 /***********************************************************************
962 * SetClassLongA (USER32.@)
964 DWORD WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
966 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG
), FALSE
);
970 /***********************************************************************
971 * GetClassNameA (USER32.@)
973 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
975 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
978 if (count
<= 0) return 0;
979 if (!GetClassNameW( hwnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
980 RtlUnicodeToMultiByteN( buffer
, count
- 1, &len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
986 /***********************************************************************
987 * GetClassNameW (USER32.@)
989 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
994 TRACE("%p %p %d\n", hwnd
, buffer
, count
);
996 if (count
<= 0) return 0;
998 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
1000 if (class == CLASS_OTHER_PROCESS
)
1002 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1004 ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), tmpbuf
, MAX_ATOM_LEN
+ 1 );
1007 ret
= min(count
- 1, ret
);
1008 memcpy(buffer
, tmpbuf
, ret
* sizeof(WCHAR
));
1014 lstrcpynW( buffer
, class->name
, count
);
1015 release_class_ptr( class );
1016 ret
= strlenW( buffer
);
1022 /***********************************************************************
1023 * RealGetWindowClassA (USER32.@)
1025 UINT WINAPI
RealGetWindowClassA( HWND hwnd
, LPSTR buffer
, UINT count
)
1027 return GetClassNameA( hwnd
, buffer
, count
);
1031 /***********************************************************************
1032 * RealGetWindowClassW (USER32.@)
1034 UINT WINAPI
RealGetWindowClassW( HWND hwnd
, LPWSTR buffer
, UINT count
)
1036 return GetClassNameW( hwnd
, buffer
, count
);
1040 /***********************************************************************
1041 * GetClassInfoA (USER32.@)
1043 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSA
*wc
)
1046 UINT ret
= GetClassInfoExA( hInstance
, name
, &wcex
);
1050 wc
->style
= wcex
.style
;
1051 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1052 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1053 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1054 wc
->hInstance
= wcex
.hInstance
;
1055 wc
->hIcon
= wcex
.hIcon
;
1056 wc
->hCursor
= wcex
.hCursor
;
1057 wc
->hbrBackground
= wcex
.hbrBackground
;
1058 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1059 wc
->lpszClassName
= wcex
.lpszClassName
;
1065 /***********************************************************************
1066 * GetClassInfoW (USER32.@)
1068 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSW
*wc
)
1071 UINT ret
= GetClassInfoExW( hInstance
, name
, &wcex
);
1075 wc
->style
= wcex
.style
;
1076 wc
->lpfnWndProc
= wcex
.lpfnWndProc
;
1077 wc
->cbClsExtra
= wcex
.cbClsExtra
;
1078 wc
->cbWndExtra
= wcex
.cbWndExtra
;
1079 wc
->hInstance
= wcex
.hInstance
;
1080 wc
->hIcon
= wcex
.hIcon
;
1081 wc
->hCursor
= wcex
.hCursor
;
1082 wc
->hbrBackground
= wcex
.hbrBackground
;
1083 wc
->lpszMenuName
= wcex
.lpszMenuName
;
1084 wc
->lpszClassName
= wcex
.lpszClassName
;
1090 /***********************************************************************
1091 * GetClassInfoExA (USER32.@)
1093 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
, WNDCLASSEXA
*wc
)
1098 TRACE("%p %s %p\n", hInstance
, debugstr_a(name
), wc
);
1102 SetLastError( ERROR_NOACCESS
);
1106 if (!hInstance
) hInstance
= user32_module
;
1108 if (!IS_INTRESOURCE(name
))
1110 WCHAR nameW
[MAX_ATOM_LEN
+ 1];
1111 if (!MultiByteToWideChar( CP_ACP
, 0, name
, -1, nameW
, sizeof(nameW
)/sizeof(WCHAR
) ))
1113 classPtr
= CLASS_FindClass( nameW
, hInstance
);
1115 else classPtr
= CLASS_FindClass( (LPCWSTR
)name
, hInstance
);
1119 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1122 wc
->style
= classPtr
->style
;
1123 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, FALSE
);
1124 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1125 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1126 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1127 wc
->hIcon
= classPtr
->hIcon
;
1128 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1129 wc
->hCursor
= classPtr
->hCursor
;
1130 wc
->hbrBackground
= classPtr
->hbrBackground
;
1131 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1132 wc
->lpszClassName
= name
;
1133 atom
= classPtr
->atomName
;
1134 release_class_ptr( classPtr
);
1136 /* We must return the atom of the class here instead of just TRUE. */
1141 /***********************************************************************
1142 * GetClassInfoExW (USER32.@)
1144 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
, WNDCLASSEXW
*wc
)
1149 TRACE("%p %s %p\n", hInstance
, debugstr_w(name
), wc
);
1153 SetLastError( ERROR_NOACCESS
);
1157 if (!hInstance
) hInstance
= user32_module
;
1159 if (!(classPtr
= CLASS_FindClass( name
, hInstance
)))
1161 SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
1164 wc
->style
= classPtr
->style
;
1165 wc
->lpfnWndProc
= WINPROC_GetProc( classPtr
->winproc
, TRUE
);
1166 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1167 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1168 wc
->hInstance
= (hInstance
== user32_module
) ? 0 : hInstance
;
1169 wc
->hIcon
= classPtr
->hIcon
;
1170 wc
->hIconSm
= classPtr
->hIconSm
? classPtr
->hIconSm
: classPtr
->hIconSmIntern
;
1171 wc
->hCursor
= classPtr
->hCursor
;
1172 wc
->hbrBackground
= classPtr
->hbrBackground
;
1173 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1174 wc
->lpszClassName
= name
;
1175 atom
= classPtr
->atomName
;
1176 release_class_ptr( classPtr
);
1178 /* We must return the atom of the class here instead of just TRUE. */
1183 #if 0 /* toolhelp is in kernel, so this cannot work */
1185 /***********************************************************************
1186 * ClassFirst (TOOLHELP.69)
1188 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1190 TRACE("%p\n",pClassEntry
);
1191 pClassEntry
->wNext
= 1;
1192 return ClassNext16( pClassEntry
);
1196 /***********************************************************************
1197 * ClassNext (TOOLHELP.70)
1199 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1202 CLASS
*class = firstClass
;
1204 TRACE("%p\n",pClassEntry
);
1206 if (!pClassEntry
->wNext
) return FALSE
;
1207 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1210 pClassEntry
->wNext
= 0;
1213 pClassEntry
->hInst
= class->hInstance
;
1214 pClassEntry
->wNext
++;
1215 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1216 sizeof(pClassEntry
->szClassName
) );
1221 /* 64bit versions */
1223 #ifdef GetClassLongPtrA
1224 #undef GetClassLongPtrA
1227 #ifdef GetClassLongPtrW
1228 #undef GetClassLongPtrW
1231 #ifdef SetClassLongPtrA
1232 #undef SetClassLongPtrA
1235 #ifdef SetClassLongPtrW
1236 #undef SetClassLongPtrW
1239 /***********************************************************************
1240 * GetClassLongPtrA (USER32.@)
1242 ULONG_PTR WINAPI
GetClassLongPtrA( HWND hwnd
, INT offset
)
1244 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), FALSE
);
1247 /***********************************************************************
1248 * GetClassLongPtrW (USER32.@)
1250 ULONG_PTR WINAPI
GetClassLongPtrW( HWND hwnd
, INT offset
)
1252 return CLASS_GetClassLong( hwnd
, offset
, sizeof(ULONG_PTR
), TRUE
);
1255 /***********************************************************************
1256 * SetClassLongPtrW (USER32.@)
1258 ULONG_PTR WINAPI
SetClassLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
1260 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), TRUE
);
1263 /***********************************************************************
1264 * SetClassLongPtrA (USER32.@)
1266 ULONG_PTR WINAPI
SetClassLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
1268 return CLASS_SetClassLong( hwnd
, offset
, newval
, sizeof(LONG_PTR
), FALSE
);