winemenubuilder: silence an err
[wine/multimedia.git] / dlls / user32 / class.c
blob8b5060a628b6111b33b11f3e64e8e6c38697a2e8
1 /*
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
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <string.h>
30 #include "winerror.h"
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "wine/unicode.h"
35 #include "win.h"
36 #include "user_private.h"
37 #include "controls.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 HCURSOR hCursor; /* Default cursor */
60 HBRUSH hbrBackground; /* Default background */
61 ATOM atomName; /* Name of the class */
62 WCHAR name[MAX_ATOM_LEN + 1];
63 } CLASS;
65 static struct list class_list = LIST_INIT( class_list );
67 #define CLASS_OTHER_PROCESS ((CLASS *)1)
69 /***********************************************************************
70 * get_class_ptr
72 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
74 WND *ptr = WIN_GetPtr( hwnd );
76 if (ptr)
78 if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP) return ptr->class;
79 if (!write_access) return CLASS_OTHER_PROCESS;
81 /* modifying classes in other processes is not allowed */
82 if (ptr == WND_DESKTOP || IsWindow( hwnd ))
84 SetLastError( ERROR_ACCESS_DENIED );
85 return NULL;
88 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
89 return NULL;
93 /***********************************************************************
94 * release_class_ptr
96 static inline void release_class_ptr( CLASS *ptr )
98 USER_Unlock();
102 /***********************************************************************
103 * get_int_atom_value
105 ATOM get_int_atom_value( LPCWSTR name )
107 UINT ret = 0;
109 if (IS_INTRESOURCE(name)) return LOWORD(name);
110 if (*name++ != '#') return 0;
111 while (*name)
113 if (*name < '0' || *name > '9') return 0;
114 ret = ret * 10 + *name++ - '0';
115 if (ret > 0xffff) return 0;
117 return ret;
121 /***********************************************************************
122 * set_server_info
124 * Set class info with the wine server.
126 static BOOL set_server_info( HWND hwnd, INT offset, LONG_PTR newval, UINT size )
128 BOOL ret;
130 SERVER_START_REQ( set_class_info )
132 req->window = wine_server_user_handle( hwnd );
133 req->extra_offset = -1;
134 switch(offset)
136 case GCW_ATOM:
137 req->flags = SET_CLASS_ATOM;
138 req->atom = LOWORD(newval);
139 break;
140 case GCL_STYLE:
141 req->flags = SET_CLASS_STYLE;
142 req->style = newval;
143 break;
144 case GCL_CBWNDEXTRA:
145 req->flags = SET_CLASS_WINEXTRA;
146 req->win_extra = newval;
147 break;
148 case GCLP_HMODULE:
149 req->flags = SET_CLASS_INSTANCE;
150 req->instance = wine_server_client_ptr( (void *)newval );
151 break;
152 default:
153 assert( offset >= 0 );
154 req->flags = SET_CLASS_EXTRA;
155 req->extra_offset = offset;
156 req->extra_size = size;
157 if ( size == sizeof(LONG) )
159 LONG newlong = newval;
160 memcpy( &req->extra_value, &newlong, sizeof(LONG) );
162 else
163 memcpy( &req->extra_value, &newval, sizeof(LONG_PTR) );
164 break;
166 ret = !wine_server_call_err( req );
168 SERVER_END_REQ;
169 return ret;
173 /***********************************************************************
174 * CLASS_GetMenuNameA
176 * Get the menu name as a ASCII string.
178 static inline LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
180 if (IS_INTRESOURCE(classPtr->menuName)) return (LPSTR)classPtr->menuName;
181 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
185 /***********************************************************************
186 * CLASS_GetMenuNameW
188 * Get the menu name as a Unicode string.
190 static inline LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
192 return classPtr->menuName;
196 /***********************************************************************
197 * CLASS_SetMenuNameA
199 * Set the menu name in a class structure by copying the string.
201 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
203 if (!IS_INTRESOURCE(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
204 if (!IS_INTRESOURCE(name))
206 DWORD lenA = strlen(name) + 1;
207 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
208 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
209 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
210 memcpy( classPtr->menuName + lenW, name, lenA );
212 else classPtr->menuName = (LPWSTR)name;
216 /***********************************************************************
217 * CLASS_SetMenuNameW
219 * Set the menu name in a class structure by copying the string.
221 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
223 if (!IS_INTRESOURCE(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
224 if (!IS_INTRESOURCE(name))
226 DWORD lenW = strlenW(name) + 1;
227 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
228 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
229 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
230 WideCharToMultiByte( CP_ACP, 0, name, lenW,
231 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
233 else classPtr->menuName = (LPWSTR)name;
237 /***********************************************************************
238 * CLASS_FreeClass
240 * Free a class structure.
242 static void CLASS_FreeClass( CLASS *classPtr )
244 TRACE("%p\n", classPtr);
246 USER_Lock();
248 if (classPtr->dce) free_dce( classPtr->dce, 0 );
249 list_remove( &classPtr->entry );
250 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
251 DeleteObject( classPtr->hbrBackground );
252 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
253 HeapFree( GetProcessHeap(), 0, classPtr );
254 USER_Unlock();
258 /***********************************************************************
259 * CLASS_FindClass
261 * Return a pointer to the class.
262 * hinstance has been normalized by the caller.
264 static CLASS *CLASS_FindClass( LPCWSTR name, HINSTANCE hinstance )
266 struct list *ptr;
267 ATOM atom = get_int_atom_value( name );
269 USER_Lock();
271 LIST_FOR_EACH( ptr, &class_list )
273 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
274 if (atom)
276 if (class->atomName != atom) continue;
278 else
280 if (!name || strcmpiW( class->name, name )) continue;
282 if (!hinstance || !class->local || class->hInstance == hinstance)
284 TRACE("%s %p -> %p\n", debugstr_w(name), hinstance, class);
285 return class;
288 USER_Unlock();
289 TRACE("%s %p -> not found\n", debugstr_w(name), hinstance);
290 return NULL;
294 /***********************************************************************
295 * CLASS_RegisterClass
297 * The real RegisterClass() functionality.
299 static CLASS *CLASS_RegisterClass( LPCWSTR name, HINSTANCE hInstance, BOOL local,
300 DWORD style, INT classExtra, INT winExtra )
302 CLASS *classPtr;
303 BOOL ret;
305 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
306 debugstr_w(name), hInstance, style, classExtra, winExtra );
308 /* Fix the extra bytes value */
310 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
311 WARN("Class extra bytes %d is > 40\n", classExtra);
312 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
313 WARN("Win extra bytes %d is > 40\n", winExtra );
315 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
316 if (!classPtr) return NULL;
318 classPtr->atomName = get_int_atom_value( name );
319 if (!classPtr->atomName && name) strcpyW( classPtr->name, name );
320 else GlobalGetAtomNameW( classPtr->atomName, classPtr->name, sizeof(classPtr->name)/sizeof(WCHAR) );
322 SERVER_START_REQ( create_class )
324 req->local = local;
325 req->style = style;
326 req->instance = wine_server_client_ptr( hInstance );
327 req->extra = classExtra;
328 req->win_extra = winExtra;
329 req->client_ptr = wine_server_client_ptr( classPtr );
330 req->atom = classPtr->atomName;
331 if (!req->atom && name) wine_server_add_data( req, name, strlenW(name) * sizeof(WCHAR) );
332 ret = !wine_server_call_err( req );
333 classPtr->atomName = reply->atom;
335 SERVER_END_REQ;
336 if (!ret)
338 HeapFree( GetProcessHeap(), 0, classPtr );
339 return NULL;
342 classPtr->style = style;
343 classPtr->local = local;
344 classPtr->cbWndExtra = winExtra;
345 classPtr->cbClsExtra = classExtra;
346 classPtr->hInstance = hInstance;
348 /* Other non-null values must be set by caller */
350 USER_Lock();
351 if (local) list_add_head( &class_list, &classPtr->entry );
352 else list_add_tail( &class_list, &classPtr->entry );
353 return classPtr;
357 /***********************************************************************
358 * register_builtin
360 * Register a builtin control class.
361 * This allows having both ASCII and Unicode winprocs for the same class.
363 static void register_builtin( const struct builtin_class_descr *descr )
365 CLASS *classPtr;
367 if (!(classPtr = CLASS_RegisterClass( descr->name, user32_module, FALSE,
368 descr->style, 0, descr->extra ))) return;
370 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
371 classPtr->hbrBackground = descr->brush;
372 classPtr->winproc = BUILTIN_WINPROC( descr->proc );
373 release_class_ptr( classPtr );
377 /***********************************************************************
378 * CLASS_RegisterBuiltinClasses
380 void CLASS_RegisterBuiltinClasses(void)
382 register_builtin( &DESKTOP_builtin_class );
383 register_builtin( &BUTTON_builtin_class );
384 register_builtin( &COMBO_builtin_class );
385 register_builtin( &COMBOLBOX_builtin_class );
386 register_builtin( &DIALOG_builtin_class );
387 register_builtin( &EDIT_builtin_class );
388 register_builtin( &ICONTITLE_builtin_class );
389 register_builtin( &LISTBOX_builtin_class );
390 register_builtin( &MDICLIENT_builtin_class );
391 register_builtin( &MENU_builtin_class );
392 register_builtin( &MESSAGE_builtin_class );
393 register_builtin( &SCROLL_builtin_class );
394 register_builtin( &STATIC_builtin_class );
398 /***********************************************************************
399 * get_class_winproc
401 WNDPROC get_class_winproc( CLASS *class )
403 return class->winproc;
407 /***********************************************************************
408 * get_class_dce
410 struct dce *get_class_dce( CLASS *class )
412 return class->dce;
416 /***********************************************************************
417 * set_class_dce
419 struct dce *set_class_dce( CLASS *class, struct dce *dce )
421 if (class->dce) return class->dce; /* already set, don't change it */
422 class->dce = dce;
423 return dce;
427 /***********************************************************************
428 * RegisterClassA (USER32.@)
430 * Register a window class.
432 * RETURNS
433 * >0: Unique identifier
434 * 0: Failure
436 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
438 WNDCLASSEXA wcex;
440 wcex.cbSize = sizeof(wcex);
441 wcex.style = wc->style;
442 wcex.lpfnWndProc = wc->lpfnWndProc;
443 wcex.cbClsExtra = wc->cbClsExtra;
444 wcex.cbWndExtra = wc->cbWndExtra;
445 wcex.hInstance = wc->hInstance;
446 wcex.hIcon = wc->hIcon;
447 wcex.hCursor = wc->hCursor;
448 wcex.hbrBackground = wc->hbrBackground;
449 wcex.lpszMenuName = wc->lpszMenuName;
450 wcex.lpszClassName = wc->lpszClassName;
451 wcex.hIconSm = 0;
452 return RegisterClassExA( &wcex );
456 /***********************************************************************
457 * RegisterClassW (USER32.@)
459 * See RegisterClassA.
461 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
463 WNDCLASSEXW wcex;
465 wcex.cbSize = sizeof(wcex);
466 wcex.style = wc->style;
467 wcex.lpfnWndProc = wc->lpfnWndProc;
468 wcex.cbClsExtra = wc->cbClsExtra;
469 wcex.cbWndExtra = wc->cbWndExtra;
470 wcex.hInstance = wc->hInstance;
471 wcex.hIcon = wc->hIcon;
472 wcex.hCursor = wc->hCursor;
473 wcex.hbrBackground = wc->hbrBackground;
474 wcex.lpszMenuName = wc->lpszMenuName;
475 wcex.lpszClassName = wc->lpszClassName;
476 wcex.hIconSm = 0;
477 return RegisterClassExW( &wcex );
481 /***********************************************************************
482 * RegisterClassExA (USER32.@)
484 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
486 ATOM atom;
487 CLASS *classPtr;
488 HINSTANCE instance;
490 if (wc->cbSize != sizeof(*wc) || wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
491 wc->hInstance == user32_module) /* we can't register a class for user32 */
493 SetLastError( ERROR_INVALID_PARAMETER );
494 return 0;
496 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
498 if (!IS_INTRESOURCE(wc->lpszClassName))
500 WCHAR name[MAX_ATOM_LEN + 1];
502 if (!MultiByteToWideChar( CP_ACP, 0, wc->lpszClassName, -1, name, MAX_ATOM_LEN + 1 )) return 0;
503 classPtr = CLASS_RegisterClass( name, instance, !(wc->style & CS_GLOBALCLASS),
504 wc->style, wc->cbClsExtra, wc->cbWndExtra );
506 else
508 classPtr = CLASS_RegisterClass( (LPCWSTR)wc->lpszClassName, instance,
509 !(wc->style & CS_GLOBALCLASS), wc->style,
510 wc->cbClsExtra, wc->cbWndExtra );
512 if (!classPtr) return 0;
513 atom = classPtr->atomName;
515 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
516 debugstr_a(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
517 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
519 classPtr->hIcon = wc->hIcon;
520 classPtr->hIconSm = wc->hIconSm;
521 classPtr->hCursor = wc->hCursor;
522 classPtr->hbrBackground = wc->hbrBackground;
523 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, FALSE );
524 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
525 release_class_ptr( classPtr );
526 return atom;
530 /***********************************************************************
531 * RegisterClassExW (USER32.@)
533 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
535 ATOM atom;
536 CLASS *classPtr;
537 HINSTANCE instance;
539 if (wc->cbSize != sizeof(*wc) || wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
540 wc->hInstance == user32_module) /* we can't register a class for user32 */
542 SetLastError( ERROR_INVALID_PARAMETER );
543 return 0;
545 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
547 if (!(classPtr = CLASS_RegisterClass( wc->lpszClassName, instance, !(wc->style & CS_GLOBALCLASS),
548 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
549 return 0;
551 atom = classPtr->atomName;
553 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
554 debugstr_w(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
555 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
557 classPtr->hIcon = wc->hIcon;
558 classPtr->hIconSm = wc->hIconSm;
559 classPtr->hCursor = wc->hCursor;
560 classPtr->hbrBackground = wc->hbrBackground;
561 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, TRUE );
562 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
563 release_class_ptr( classPtr );
564 return atom;
568 /***********************************************************************
569 * UnregisterClassA (USER32.@)
571 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
573 if (!IS_INTRESOURCE(className))
575 WCHAR name[MAX_ATOM_LEN + 1];
577 if (!MultiByteToWideChar( CP_ACP, 0, className, -1, name, MAX_ATOM_LEN + 1 ))
578 return FALSE;
579 return UnregisterClassW( name, hInstance );
581 return UnregisterClassW( (LPCWSTR)className, hInstance );
584 /***********************************************************************
585 * UnregisterClassW (USER32.@)
587 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
589 CLASS *classPtr = NULL;
591 SERVER_START_REQ( destroy_class )
593 req->instance = wine_server_client_ptr( hInstance );
594 if (!(req->atom = get_int_atom_value(className)) && className)
595 wine_server_add_data( req, className, strlenW(className) * sizeof(WCHAR) );
596 if (!wine_server_call_err( req )) classPtr = wine_server_get_ptr( reply->client_ptr );
598 SERVER_END_REQ;
600 if (classPtr) CLASS_FreeClass( classPtr );
601 return (classPtr != NULL);
605 /***********************************************************************
606 * GetClassWord (USER32.@)
608 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
610 CLASS *class;
611 WORD retvalue = 0;
613 if (offset < 0) return GetClassLongA( hwnd, offset );
615 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
617 if (class == CLASS_OTHER_PROCESS)
619 SERVER_START_REQ( set_class_info )
621 req->window = wine_server_user_handle( hwnd );
622 req->flags = 0;
623 req->extra_offset = offset;
624 req->extra_size = sizeof(retvalue);
625 if (!wine_server_call_err( req ))
626 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
628 SERVER_END_REQ;
629 return retvalue;
632 if (offset <= class->cbClsExtra - sizeof(WORD))
633 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
634 else
635 SetLastError( ERROR_INVALID_INDEX );
636 release_class_ptr( class );
637 return retvalue;
641 /***********************************************************************
642 * CLASS_GetClassLong
644 * Implementation of GetClassLong(Ptr)A/W
646 static ULONG_PTR CLASS_GetClassLong( HWND hwnd, INT offset, UINT size,
647 BOOL unicode )
649 CLASS *class;
650 ULONG_PTR retvalue = 0;
652 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
654 if (class == CLASS_OTHER_PROCESS)
656 SERVER_START_REQ( set_class_info )
658 req->window = wine_server_user_handle( hwnd );
659 req->flags = 0;
660 req->extra_offset = (offset >= 0) ? offset : -1;
661 req->extra_size = (offset >= 0) ? size : 0;
662 if (!wine_server_call_err( req ))
664 switch(offset)
666 case GCLP_HBRBACKGROUND:
667 case GCLP_HCURSOR:
668 case GCLP_HICON:
669 case GCLP_HICONSM:
670 case GCLP_WNDPROC:
671 case GCLP_MENUNAME:
672 FIXME( "offset %d (%s) not supported on other process window %p\n",
673 offset, SPY_GetClassLongOffsetName(offset), hwnd );
674 SetLastError( ERROR_INVALID_HANDLE );
675 break;
676 case GCL_STYLE:
677 retvalue = reply->old_style;
678 break;
679 case GCL_CBWNDEXTRA:
680 retvalue = reply->old_win_extra;
681 break;
682 case GCL_CBCLSEXTRA:
683 retvalue = reply->old_extra;
684 break;
685 case GCLP_HMODULE:
686 retvalue = (ULONG_PTR)wine_server_get_ptr( reply->old_instance );
687 break;
688 case GCW_ATOM:
689 retvalue = reply->old_atom;
690 break;
691 default:
692 if (offset >= 0)
694 if (size == sizeof(DWORD))
696 DWORD retdword;
697 memcpy( &retdword, &reply->old_extra_value, sizeof(DWORD) );
698 retvalue = retdword;
700 else
701 memcpy( &retvalue, &reply->old_extra_value,
702 sizeof(ULONG_PTR) );
704 else SetLastError( ERROR_INVALID_INDEX );
705 break;
709 SERVER_END_REQ;
710 return retvalue;
713 if (offset >= 0)
715 if (offset <= class->cbClsExtra - size)
717 if (size == sizeof(DWORD))
719 DWORD retdword;
720 memcpy( &retdword, (char *)(class + 1) + offset, sizeof(DWORD) );
721 retvalue = retdword;
723 else
724 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(ULONG_PTR) );
726 else
727 SetLastError( ERROR_INVALID_INDEX );
728 release_class_ptr( class );
729 return retvalue;
732 switch(offset)
734 case GCLP_HBRBACKGROUND:
735 retvalue = (ULONG_PTR)class->hbrBackground;
736 break;
737 case GCLP_HCURSOR:
738 retvalue = (ULONG_PTR)class->hCursor;
739 break;
740 case GCLP_HICON:
741 retvalue = (ULONG_PTR)class->hIcon;
742 break;
743 case GCLP_HICONSM:
744 retvalue = (ULONG_PTR)class->hIconSm;
745 break;
746 case GCL_STYLE:
747 retvalue = class->style;
748 break;
749 case GCL_CBWNDEXTRA:
750 retvalue = class->cbWndExtra;
751 break;
752 case GCL_CBCLSEXTRA:
753 retvalue = class->cbClsExtra;
754 break;
755 case GCLP_HMODULE:
756 retvalue = (ULONG_PTR)class->hInstance;
757 break;
758 case GCLP_WNDPROC:
759 retvalue = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
760 break;
761 case GCLP_MENUNAME:
762 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
763 if (unicode)
764 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
765 else
766 retvalue = (ULONG_PTR)CLASS_GetMenuNameA( class );
767 break;
768 case GCW_ATOM:
769 retvalue = class->atomName;
770 break;
771 default:
772 SetLastError( ERROR_INVALID_INDEX );
773 break;
775 release_class_ptr( class );
776 return retvalue;
780 /***********************************************************************
781 * GetClassLongW (USER32.@)
783 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
785 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), TRUE );
790 /***********************************************************************
791 * GetClassLongA (USER32.@)
793 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
795 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), FALSE );
799 /***********************************************************************
800 * SetClassWord (USER32.@)
802 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
804 CLASS *class;
805 WORD retval = 0;
807 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
809 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
811 SERVER_START_REQ( set_class_info )
813 req->window = wine_server_user_handle( hwnd );
814 req->flags = SET_CLASS_EXTRA;
815 req->extra_offset = offset;
816 req->extra_size = sizeof(newval);
817 memcpy( &req->extra_value, &newval, sizeof(newval) );
818 if (!wine_server_call_err( req ))
820 void *ptr = (char *)(class + 1) + offset;
821 memcpy( &retval, ptr, sizeof(retval) );
822 memcpy( ptr, &newval, sizeof(newval) );
825 SERVER_END_REQ;
826 release_class_ptr( class );
827 return retval;
831 /***********************************************************************
832 * CLASS_SetClassLong
834 * Implementation of SetClassLong(Ptr)A/W
836 static ULONG_PTR CLASS_SetClassLong( HWND hwnd, INT offset, LONG_PTR newval,
837 UINT size, BOOL unicode )
839 CLASS *class;
840 ULONG_PTR retval = 0;
842 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
844 if (offset >= 0)
846 if (set_server_info( hwnd, offset, newval, size ))
848 void *ptr = (char *)(class + 1) + offset;
849 if ( size == sizeof(LONG) )
851 DWORD retdword;
852 LONG newlong = newval;
853 memcpy( &retdword, ptr, sizeof(DWORD) );
854 memcpy( ptr, &newlong, sizeof(LONG) );
855 retval = retdword;
857 else
859 memcpy( &retval, ptr, sizeof(ULONG_PTR) );
860 memcpy( ptr, &newval, sizeof(LONG_PTR) );
864 else switch(offset)
866 case GCLP_MENUNAME:
867 if ( unicode )
868 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
869 else
870 CLASS_SetMenuNameA( class, (LPCSTR)newval );
871 retval = 0; /* Old value is now meaningless anyway */
872 break;
873 case GCLP_WNDPROC:
874 retval = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
875 class->winproc = WINPROC_AllocProc( (WNDPROC)newval, unicode );
876 break;
877 case GCLP_HBRBACKGROUND:
878 retval = (ULONG_PTR)class->hbrBackground;
879 class->hbrBackground = (HBRUSH)newval;
880 break;
881 case GCLP_HCURSOR:
882 retval = (ULONG_PTR)class->hCursor;
883 class->hCursor = (HCURSOR)newval;
884 break;
885 case GCLP_HICON:
886 retval = (ULONG_PTR)class->hIcon;
887 class->hIcon = (HICON)newval;
888 break;
889 case GCLP_HICONSM:
890 retval = (ULONG_PTR)class->hIconSm;
891 class->hIconSm = (HICON)newval;
892 break;
893 case GCL_STYLE:
894 if (!set_server_info( hwnd, offset, newval, size )) break;
895 retval = class->style;
896 class->style = newval;
897 break;
898 case GCL_CBWNDEXTRA:
899 if (!set_server_info( hwnd, offset, newval, size )) break;
900 retval = class->cbWndExtra;
901 class->cbWndExtra = newval;
902 break;
903 case GCLP_HMODULE:
904 if (!set_server_info( hwnd, offset, newval, size )) break;
905 retval = (ULONG_PTR)class->hInstance;
906 class->hInstance = (HINSTANCE)newval;
907 break;
908 case GCW_ATOM:
909 if (!set_server_info( hwnd, offset, newval, size )) break;
910 retval = class->atomName;
911 class->atomName = newval;
912 GlobalGetAtomNameW( newval, class->name, sizeof(class->name)/sizeof(WCHAR) );
913 break;
914 case GCL_CBCLSEXTRA: /* cannot change this one */
915 SetLastError( ERROR_INVALID_PARAMETER );
916 break;
917 default:
918 SetLastError( ERROR_INVALID_INDEX );
919 break;
921 release_class_ptr( class );
922 return retval;
926 /***********************************************************************
927 * SetClassLongW (USER32.@)
929 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
931 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), TRUE );
935 /***********************************************************************
936 * SetClassLongA (USER32.@)
938 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
940 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), FALSE );
944 /***********************************************************************
945 * GetClassNameA (USER32.@)
947 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
949 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
950 DWORD len;
952 if (count <= 0) return 0;
953 if (!GetClassNameW( hwnd, tmpbuf, sizeof(tmpbuf)/sizeof(WCHAR) )) return 0;
954 RtlUnicodeToMultiByteN( buffer, count - 1, &len, tmpbuf, strlenW(tmpbuf) * sizeof(WCHAR) );
955 buffer[len] = 0;
956 return len;
960 /***********************************************************************
961 * GetClassNameW (USER32.@)
963 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
965 CLASS *class;
966 INT ret;
968 TRACE("%p %p %d\n", hwnd, buffer, count);
970 if (count <= 0) return 0;
972 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
974 if (class == CLASS_OTHER_PROCESS)
976 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
978 ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), tmpbuf, MAX_ATOM_LEN + 1 );
979 if (ret)
981 ret = min(count - 1, ret);
982 memcpy(buffer, tmpbuf, ret * sizeof(WCHAR));
983 buffer[ret] = 0;
986 else
988 lstrcpynW( buffer, class->name, count );
989 release_class_ptr( class );
990 ret = strlenW( buffer );
992 return ret;
996 /***********************************************************************
997 * RealGetWindowClassA (USER32.@)
999 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1001 return GetClassNameA( hwnd, buffer, count );
1005 /***********************************************************************
1006 * RealGetWindowClassW (USER32.@)
1008 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1010 return GetClassNameW( hwnd, buffer, count );
1014 /***********************************************************************
1015 * GetClassInfoA (USER32.@)
1017 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1019 WNDCLASSEXA wcex;
1020 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1022 if (ret)
1024 wc->style = wcex.style;
1025 wc->lpfnWndProc = wcex.lpfnWndProc;
1026 wc->cbClsExtra = wcex.cbClsExtra;
1027 wc->cbWndExtra = wcex.cbWndExtra;
1028 wc->hInstance = wcex.hInstance;
1029 wc->hIcon = wcex.hIcon;
1030 wc->hCursor = wcex.hCursor;
1031 wc->hbrBackground = wcex.hbrBackground;
1032 wc->lpszMenuName = wcex.lpszMenuName;
1033 wc->lpszClassName = wcex.lpszClassName;
1035 return ret;
1039 /***********************************************************************
1040 * GetClassInfoW (USER32.@)
1042 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1044 WNDCLASSEXW wcex;
1045 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1047 if (ret)
1049 wc->style = wcex.style;
1050 wc->lpfnWndProc = wcex.lpfnWndProc;
1051 wc->cbClsExtra = wcex.cbClsExtra;
1052 wc->cbWndExtra = wcex.cbWndExtra;
1053 wc->hInstance = wcex.hInstance;
1054 wc->hIcon = wcex.hIcon;
1055 wc->hCursor = wcex.hCursor;
1056 wc->hbrBackground = wcex.hbrBackground;
1057 wc->lpszMenuName = wcex.lpszMenuName;
1058 wc->lpszClassName = wcex.lpszClassName;
1060 return ret;
1064 /***********************************************************************
1065 * GetClassInfoExA (USER32.@)
1067 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1069 ATOM atom;
1070 CLASS *classPtr;
1072 TRACE("%p %s %p\n", hInstance, debugstr_a(name), wc);
1074 if (!wc)
1076 SetLastError( ERROR_NOACCESS );
1077 return FALSE;
1080 if (!hInstance) hInstance = user32_module;
1082 if (!IS_INTRESOURCE(name))
1084 WCHAR nameW[MAX_ATOM_LEN + 1];
1085 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, sizeof(nameW)/sizeof(WCHAR) ))
1086 return FALSE;
1087 classPtr = CLASS_FindClass( nameW, hInstance );
1089 else classPtr = CLASS_FindClass( (LPCWSTR)name, hInstance );
1091 if (!classPtr)
1093 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1094 return FALSE;
1096 wc->style = classPtr->style;
1097 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, FALSE );
1098 wc->cbClsExtra = classPtr->cbClsExtra;
1099 wc->cbWndExtra = classPtr->cbWndExtra;
1100 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1101 wc->hIcon = classPtr->hIcon;
1102 wc->hIconSm = classPtr->hIconSm;
1103 wc->hCursor = classPtr->hCursor;
1104 wc->hbrBackground = classPtr->hbrBackground;
1105 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1106 wc->lpszClassName = name;
1107 atom = classPtr->atomName;
1108 release_class_ptr( classPtr );
1110 /* We must return the atom of the class here instead of just TRUE. */
1111 return atom;
1115 /***********************************************************************
1116 * GetClassInfoExW (USER32.@)
1118 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1120 ATOM atom;
1121 CLASS *classPtr;
1123 TRACE("%p %s %p\n", hInstance, debugstr_w(name), wc);
1125 if (!wc)
1127 SetLastError( ERROR_NOACCESS );
1128 return FALSE;
1131 if (!hInstance) hInstance = user32_module;
1133 if (!(classPtr = CLASS_FindClass( name, hInstance )))
1135 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1136 return FALSE;
1138 wc->style = classPtr->style;
1139 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, TRUE );
1140 wc->cbClsExtra = classPtr->cbClsExtra;
1141 wc->cbWndExtra = classPtr->cbWndExtra;
1142 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1143 wc->hIcon = classPtr->hIcon;
1144 wc->hIconSm = classPtr->hIconSm;
1145 wc->hCursor = classPtr->hCursor;
1146 wc->hbrBackground = classPtr->hbrBackground;
1147 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1148 wc->lpszClassName = name;
1149 atom = classPtr->atomName;
1150 release_class_ptr( classPtr );
1152 /* We must return the atom of the class here instead of just TRUE. */
1153 return atom;
1157 #if 0 /* toolhelp is in kernel, so this cannot work */
1159 /***********************************************************************
1160 * ClassFirst (TOOLHELP.69)
1162 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1164 TRACE("%p\n",pClassEntry);
1165 pClassEntry->wNext = 1;
1166 return ClassNext16( pClassEntry );
1170 /***********************************************************************
1171 * ClassNext (TOOLHELP.70)
1173 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1175 int i;
1176 CLASS *class = firstClass;
1178 TRACE("%p\n",pClassEntry);
1180 if (!pClassEntry->wNext) return FALSE;
1181 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1182 if (!class)
1184 pClassEntry->wNext = 0;
1185 return FALSE;
1187 pClassEntry->hInst = class->hInstance;
1188 pClassEntry->wNext++;
1189 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1190 sizeof(pClassEntry->szClassName) );
1191 return TRUE;
1193 #endif
1195 /* 64bit versions */
1197 #ifdef GetClassLongPtrA
1198 #undef GetClassLongPtrA
1199 #endif
1201 #ifdef GetClassLongPtrW
1202 #undef GetClassLongPtrW
1203 #endif
1205 #ifdef SetClassLongPtrA
1206 #undef SetClassLongPtrA
1207 #endif
1209 #ifdef SetClassLongPtrW
1210 #undef SetClassLongPtrW
1211 #endif
1213 /***********************************************************************
1214 * GetClassLongPtrA (USER32.@)
1216 ULONG_PTR WINAPI GetClassLongPtrA( HWND hwnd, INT offset )
1218 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), FALSE );
1221 /***********************************************************************
1222 * GetClassLongPtrW (USER32.@)
1224 ULONG_PTR WINAPI GetClassLongPtrW( HWND hwnd, INT offset )
1226 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), TRUE );
1229 /***********************************************************************
1230 * SetClassLongPtrW (USER32.@)
1232 ULONG_PTR WINAPI SetClassLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
1234 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), TRUE );
1237 /***********************************************************************
1238 * SetClassLongPtrA (USER32.@)
1240 ULONG_PTR WINAPI SetClassLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
1242 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), FALSE );