push 87b6981010d7405c33b14cddcceec21b47729eba
[wine/hacks.git] / dlls / user32 / class.c
blob72cafc793bc7c6eafcf5e67b19f9f53374e9d479
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 case GCL_STYLE:
140 req->flags = SET_CLASS_STYLE;
141 req->style = newval;
142 break;
143 case GCL_CBWNDEXTRA:
144 req->flags = SET_CLASS_WINEXTRA;
145 req->win_extra = newval;
146 break;
147 case GCLP_HMODULE:
148 req->flags = SET_CLASS_INSTANCE;
149 req->instance = wine_server_client_ptr( (void *)newval );
150 break;
151 default:
152 assert( offset >= 0 );
153 req->flags = SET_CLASS_EXTRA;
154 req->extra_offset = offset;
155 req->extra_size = size;
156 if ( size == sizeof(LONG) )
158 LONG newlong = newval;
159 memcpy( &req->extra_value, &newlong, sizeof(LONG) );
161 else
162 memcpy( &req->extra_value, &newval, sizeof(LONG_PTR) );
163 break;
165 ret = !wine_server_call_err( req );
167 SERVER_END_REQ;
168 return ret;
172 /***********************************************************************
173 * CLASS_GetMenuNameA
175 * Get the menu name as a ASCII string.
177 static inline LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
179 if (IS_INTRESOURCE(classPtr->menuName)) return (LPSTR)classPtr->menuName;
180 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
184 /***********************************************************************
185 * CLASS_GetMenuNameW
187 * Get the menu name as a Unicode string.
189 static inline LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
191 return classPtr->menuName;
195 /***********************************************************************
196 * CLASS_SetMenuNameA
198 * Set the menu name in a class structure by copying the string.
200 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
202 if (!IS_INTRESOURCE(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
203 if (!IS_INTRESOURCE(name))
205 DWORD lenA = strlen(name) + 1;
206 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
207 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
208 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
209 memcpy( classPtr->menuName + lenW, name, lenA );
211 else classPtr->menuName = (LPWSTR)name;
215 /***********************************************************************
216 * CLASS_SetMenuNameW
218 * Set the menu name in a class structure by copying the string.
220 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
222 if (!IS_INTRESOURCE(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
223 if (!IS_INTRESOURCE(name))
225 DWORD lenW = strlenW(name) + 1;
226 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
227 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
228 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
229 WideCharToMultiByte( CP_ACP, 0, name, lenW,
230 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
232 else classPtr->menuName = (LPWSTR)name;
236 /***********************************************************************
237 * CLASS_FreeClass
239 * Free a class structure.
241 static void CLASS_FreeClass( CLASS *classPtr )
243 TRACE("%p\n", classPtr);
245 USER_Lock();
247 if (classPtr->dce) free_dce( classPtr->dce, 0 );
248 list_remove( &classPtr->entry );
249 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
250 DeleteObject( classPtr->hbrBackground );
251 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
252 HeapFree( GetProcessHeap(), 0, classPtr );
253 USER_Unlock();
257 /***********************************************************************
258 * CLASS_FindClass
260 * Return a pointer to the class.
261 * hinstance has been normalized by the caller.
263 static CLASS *CLASS_FindClass( LPCWSTR name, HINSTANCE hinstance )
265 struct list *ptr;
266 ATOM atom = get_int_atom_value( name );
268 USER_Lock();
270 LIST_FOR_EACH( ptr, &class_list )
272 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
273 if (atom)
275 if (class->atomName != atom) continue;
277 else
279 if (!name || strcmpiW( class->name, name )) continue;
281 if (!hinstance || !class->local || class->hInstance == hinstance)
283 TRACE("%s %p -> %p\n", debugstr_w(name), hinstance, class);
284 return class;
287 USER_Unlock();
288 TRACE("%s %p -> not found\n", debugstr_w(name), hinstance);
289 return NULL;
293 /***********************************************************************
294 * CLASS_RegisterClass
296 * The real RegisterClass() functionality.
298 static CLASS *CLASS_RegisterClass( LPCWSTR name, HINSTANCE hInstance, BOOL local,
299 DWORD style, INT classExtra, INT winExtra )
301 CLASS *classPtr;
302 BOOL ret;
304 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
305 debugstr_w(name), hInstance, style, classExtra, winExtra );
307 /* Fix the extra bytes value */
309 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
310 WARN("Class extra bytes %d is > 40\n", classExtra);
311 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
312 WARN("Win extra bytes %d is > 40\n", winExtra );
314 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
315 if (!classPtr) return NULL;
317 classPtr->atomName = get_int_atom_value( name );
318 if (!classPtr->atomName && name) strcpyW( classPtr->name, name );
319 else GlobalGetAtomNameW( classPtr->atomName, classPtr->name, sizeof(classPtr->name)/sizeof(WCHAR) );
321 SERVER_START_REQ( create_class )
323 req->local = local;
324 req->style = style;
325 req->instance = wine_server_client_ptr( hInstance );
326 req->extra = classExtra;
327 req->win_extra = winExtra;
328 req->client_ptr = wine_server_client_ptr( classPtr );
329 req->atom = classPtr->atomName;
330 if (!req->atom && name) wine_server_add_data( req, name, strlenW(name) * sizeof(WCHAR) );
331 ret = !wine_server_call_err( req );
332 classPtr->atomName = reply->atom;
334 SERVER_END_REQ;
335 if (!ret)
337 HeapFree( GetProcessHeap(), 0, classPtr );
338 return NULL;
341 classPtr->style = style;
342 classPtr->local = local;
343 classPtr->cbWndExtra = winExtra;
344 classPtr->cbClsExtra = classExtra;
345 classPtr->hInstance = hInstance;
347 /* Other non-null values must be set by caller */
349 USER_Lock();
350 if (local) list_add_head( &class_list, &classPtr->entry );
351 else list_add_tail( &class_list, &classPtr->entry );
352 return classPtr;
356 /***********************************************************************
357 * register_builtin
359 * Register a builtin control class.
360 * This allows having both ASCII and Unicode winprocs for the same class.
362 static void register_builtin( const struct builtin_class_descr *descr )
364 CLASS *classPtr;
366 if (!(classPtr = CLASS_RegisterClass( descr->name, user32_module, FALSE,
367 descr->style, 0, descr->extra ))) return;
369 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
370 classPtr->hbrBackground = descr->brush;
371 classPtr->winproc = BUILTIN_WINPROC( descr->proc );
372 release_class_ptr( classPtr );
376 /***********************************************************************
377 * CLASS_RegisterBuiltinClasses
379 void CLASS_RegisterBuiltinClasses(void)
381 register_builtin( &DESKTOP_builtin_class );
382 register_builtin( &BUTTON_builtin_class );
383 register_builtin( &COMBO_builtin_class );
384 register_builtin( &COMBOLBOX_builtin_class );
385 register_builtin( &DIALOG_builtin_class );
386 register_builtin( &EDIT_builtin_class );
387 register_builtin( &ICONTITLE_builtin_class );
388 register_builtin( &LISTBOX_builtin_class );
389 register_builtin( &MDICLIENT_builtin_class );
390 register_builtin( &MENU_builtin_class );
391 register_builtin( &MESSAGE_builtin_class );
392 register_builtin( &SCROLL_builtin_class );
393 register_builtin( &STATIC_builtin_class );
397 /***********************************************************************
398 * get_class_winproc
400 WNDPROC get_class_winproc( CLASS *class )
402 return class->winproc;
406 /***********************************************************************
407 * get_class_dce
409 struct dce *get_class_dce( CLASS *class )
411 return class->dce;
415 /***********************************************************************
416 * set_class_dce
418 struct dce *set_class_dce( CLASS *class, struct dce *dce )
420 if (class->dce) return class->dce; /* already set, don't change it */
421 class->dce = dce;
422 return dce;
426 /***********************************************************************
427 * RegisterClassA (USER32.@)
429 * Register a window class.
431 * RETURNS
432 * >0: Unique identifier
433 * 0: Failure
435 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
437 WNDCLASSEXA wcex;
439 wcex.cbSize = sizeof(wcex);
440 wcex.style = wc->style;
441 wcex.lpfnWndProc = wc->lpfnWndProc;
442 wcex.cbClsExtra = wc->cbClsExtra;
443 wcex.cbWndExtra = wc->cbWndExtra;
444 wcex.hInstance = wc->hInstance;
445 wcex.hIcon = wc->hIcon;
446 wcex.hCursor = wc->hCursor;
447 wcex.hbrBackground = wc->hbrBackground;
448 wcex.lpszMenuName = wc->lpszMenuName;
449 wcex.lpszClassName = wc->lpszClassName;
450 wcex.hIconSm = 0;
451 return RegisterClassExA( &wcex );
455 /***********************************************************************
456 * RegisterClassW (USER32.@)
458 * See RegisterClassA.
460 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
462 WNDCLASSEXW wcex;
464 wcex.cbSize = sizeof(wcex);
465 wcex.style = wc->style;
466 wcex.lpfnWndProc = wc->lpfnWndProc;
467 wcex.cbClsExtra = wc->cbClsExtra;
468 wcex.cbWndExtra = wc->cbWndExtra;
469 wcex.hInstance = wc->hInstance;
470 wcex.hIcon = wc->hIcon;
471 wcex.hCursor = wc->hCursor;
472 wcex.hbrBackground = wc->hbrBackground;
473 wcex.lpszMenuName = wc->lpszMenuName;
474 wcex.lpszClassName = wc->lpszClassName;
475 wcex.hIconSm = 0;
476 return RegisterClassExW( &wcex );
480 /***********************************************************************
481 * RegisterClassExA (USER32.@)
483 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
485 ATOM atom;
486 CLASS *classPtr;
487 HINSTANCE instance;
489 if (wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
490 wc->hInstance == user32_module) /* we can't register a class for user32 */
492 SetLastError( ERROR_INVALID_PARAMETER );
493 return 0;
495 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
497 if (!IS_INTRESOURCE(wc->lpszClassName))
499 WCHAR name[MAX_ATOM_LEN + 1];
501 if (!MultiByteToWideChar( CP_ACP, 0, wc->lpszClassName, -1, name, MAX_ATOM_LEN + 1 )) return 0;
502 classPtr = CLASS_RegisterClass( name, instance, !(wc->style & CS_GLOBALCLASS),
503 wc->style, wc->cbClsExtra, wc->cbWndExtra );
505 else
507 classPtr = CLASS_RegisterClass( (LPCWSTR)wc->lpszClassName, instance,
508 !(wc->style & CS_GLOBALCLASS), wc->style,
509 wc->cbClsExtra, wc->cbWndExtra );
511 if (!classPtr) return 0;
512 atom = classPtr->atomName;
514 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
515 debugstr_a(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
516 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
518 classPtr->hIcon = wc->hIcon;
519 classPtr->hIconSm = wc->hIconSm;
520 classPtr->hCursor = wc->hCursor;
521 classPtr->hbrBackground = wc->hbrBackground;
522 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, FALSE );
523 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
524 release_class_ptr( classPtr );
525 return atom;
529 /***********************************************************************
530 * RegisterClassExW (USER32.@)
532 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
534 ATOM atom;
535 CLASS *classPtr;
536 HINSTANCE instance;
538 if (wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
539 wc->hInstance == user32_module) /* we can't register a class for user32 */
541 SetLastError( ERROR_INVALID_PARAMETER );
542 return 0;
544 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
546 if (!(classPtr = CLASS_RegisterClass( wc->lpszClassName, instance, !(wc->style & CS_GLOBALCLASS),
547 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
548 return 0;
550 atom = classPtr->atomName;
552 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
553 debugstr_w(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
554 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
556 classPtr->hIcon = wc->hIcon;
557 classPtr->hIconSm = wc->hIconSm;
558 classPtr->hCursor = wc->hCursor;
559 classPtr->hbrBackground = wc->hbrBackground;
560 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, TRUE );
561 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
562 release_class_ptr( classPtr );
563 return atom;
567 /***********************************************************************
568 * UnregisterClassA (USER32.@)
570 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
572 if (!IS_INTRESOURCE(className))
574 WCHAR name[MAX_ATOM_LEN + 1];
576 if (!MultiByteToWideChar( CP_ACP, 0, className, -1, name, MAX_ATOM_LEN + 1 ))
577 return FALSE;
578 return UnregisterClassW( name, hInstance );
580 return UnregisterClassW( (LPCWSTR)className, hInstance );
583 /***********************************************************************
584 * UnregisterClassW (USER32.@)
586 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
588 CLASS *classPtr = NULL;
590 SERVER_START_REQ( destroy_class )
592 req->instance = wine_server_client_ptr( hInstance );
593 if (!(req->atom = get_int_atom_value(className)) && className)
594 wine_server_add_data( req, className, strlenW(className) * sizeof(WCHAR) );
595 if (!wine_server_call_err( req )) classPtr = wine_server_get_ptr( reply->client_ptr );
597 SERVER_END_REQ;
599 if (classPtr) CLASS_FreeClass( classPtr );
600 return (classPtr != NULL);
604 /***********************************************************************
605 * GetClassWord (USER32.@)
607 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
609 CLASS *class;
610 WORD retvalue = 0;
612 if (offset < 0) return GetClassLongA( hwnd, offset );
614 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
616 if (class == CLASS_OTHER_PROCESS)
618 SERVER_START_REQ( set_class_info )
620 req->window = wine_server_user_handle( hwnd );
621 req->flags = 0;
622 req->extra_offset = offset;
623 req->extra_size = sizeof(retvalue);
624 if (!wine_server_call_err( req ))
625 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
627 SERVER_END_REQ;
628 return retvalue;
631 if (offset <= class->cbClsExtra - sizeof(WORD))
632 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
633 else
634 SetLastError( ERROR_INVALID_INDEX );
635 release_class_ptr( class );
636 return retvalue;
640 /***********************************************************************
641 * CLASS_GetClassLong
643 * Implementation of GetClassLong(Ptr)A/W
645 static ULONG_PTR CLASS_GetClassLong( HWND hwnd, INT offset, UINT size,
646 BOOL unicode )
648 CLASS *class;
649 ULONG_PTR retvalue = 0;
651 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
653 if (class == CLASS_OTHER_PROCESS)
655 SERVER_START_REQ( set_class_info )
657 req->window = wine_server_user_handle( hwnd );
658 req->flags = 0;
659 req->extra_offset = (offset >= 0) ? offset : -1;
660 req->extra_size = (offset >= 0) ? size : 0;
661 if (!wine_server_call_err( req ))
663 switch(offset)
665 case GCLP_HBRBACKGROUND:
666 case GCLP_HCURSOR:
667 case GCLP_HICON:
668 case GCLP_HICONSM:
669 case GCLP_WNDPROC:
670 case GCLP_MENUNAME:
671 FIXME( "offset %d (%s) not supported on other process window %p\n",
672 offset, SPY_GetClassLongOffsetName(offset), hwnd );
673 SetLastError( ERROR_INVALID_HANDLE );
674 break;
675 case GCL_STYLE:
676 retvalue = reply->old_style;
677 break;
678 case GCL_CBWNDEXTRA:
679 retvalue = reply->old_win_extra;
680 break;
681 case GCL_CBCLSEXTRA:
682 retvalue = reply->old_extra;
683 break;
684 case GCLP_HMODULE:
685 retvalue = (ULONG_PTR)wine_server_get_ptr( reply->old_instance );
686 break;
687 case GCW_ATOM:
688 retvalue = reply->old_atom;
689 break;
690 default:
691 if (offset >= 0)
693 if (size == sizeof(DWORD))
695 DWORD retdword;
696 memcpy( &retdword, &reply->old_extra_value, sizeof(DWORD) );
697 retvalue = retdword;
699 else
700 memcpy( &retvalue, &reply->old_extra_value,
701 sizeof(ULONG_PTR) );
703 else SetLastError( ERROR_INVALID_INDEX );
704 break;
708 SERVER_END_REQ;
709 return retvalue;
712 if (offset >= 0)
714 if (offset <= class->cbClsExtra - size)
716 if (size == sizeof(DWORD))
718 DWORD retdword;
719 memcpy( &retdword, (char *)(class + 1) + offset, sizeof(DWORD) );
720 retvalue = retdword;
722 else
723 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(ULONG_PTR) );
725 else
726 SetLastError( ERROR_INVALID_INDEX );
727 release_class_ptr( class );
728 return retvalue;
731 switch(offset)
733 case GCLP_HBRBACKGROUND:
734 retvalue = (ULONG_PTR)class->hbrBackground;
735 break;
736 case GCLP_HCURSOR:
737 retvalue = (ULONG_PTR)class->hCursor;
738 break;
739 case GCLP_HICON:
740 retvalue = (ULONG_PTR)class->hIcon;
741 break;
742 case GCLP_HICONSM:
743 retvalue = (ULONG_PTR)class->hIconSm;
744 break;
745 case GCL_STYLE:
746 retvalue = class->style;
747 break;
748 case GCL_CBWNDEXTRA:
749 retvalue = class->cbWndExtra;
750 break;
751 case GCL_CBCLSEXTRA:
752 retvalue = class->cbClsExtra;
753 break;
754 case GCLP_HMODULE:
755 retvalue = (ULONG_PTR)class->hInstance;
756 break;
757 case GCLP_WNDPROC:
758 retvalue = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
759 break;
760 case GCLP_MENUNAME:
761 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
762 if (unicode)
763 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
764 else
765 retvalue = (ULONG_PTR)CLASS_GetMenuNameA( class );
766 break;
767 case GCW_ATOM:
768 retvalue = class->atomName;
769 break;
770 default:
771 SetLastError( ERROR_INVALID_INDEX );
772 break;
774 release_class_ptr( class );
775 return retvalue;
779 /***********************************************************************
780 * GetClassLongW (USER32.@)
782 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
784 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), TRUE );
789 /***********************************************************************
790 * GetClassLongA (USER32.@)
792 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
794 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), FALSE );
798 /***********************************************************************
799 * SetClassWord (USER32.@)
801 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
803 CLASS *class;
804 WORD retval = 0;
806 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
808 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
810 SERVER_START_REQ( set_class_info )
812 req->window = wine_server_user_handle( hwnd );
813 req->flags = SET_CLASS_EXTRA;
814 req->extra_offset = offset;
815 req->extra_size = sizeof(newval);
816 memcpy( &req->extra_value, &newval, sizeof(newval) );
817 if (!wine_server_call_err( req ))
819 void *ptr = (char *)(class + 1) + offset;
820 memcpy( &retval, ptr, sizeof(retval) );
821 memcpy( ptr, &newval, sizeof(newval) );
824 SERVER_END_REQ;
825 release_class_ptr( class );
826 return retval;
830 /***********************************************************************
831 * CLASS_SetClassLong
833 * Implementation of SetClassLong(Ptr)A/W
835 static ULONG_PTR CLASS_SetClassLong( HWND hwnd, INT offset, LONG_PTR newval,
836 UINT size, BOOL unicode )
838 CLASS *class;
839 ULONG_PTR retval = 0;
841 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
843 if (offset >= 0)
845 if (set_server_info( hwnd, offset, newval, size ))
847 void *ptr = (char *)(class + 1) + offset;
848 if ( size == sizeof(LONG) )
850 DWORD retdword;
851 LONG newlong = newval;
852 memcpy( &retdword, ptr, sizeof(DWORD) );
853 memcpy( ptr, &newlong, sizeof(LONG) );
854 retval = retdword;
856 else
858 memcpy( &retval, ptr, sizeof(ULONG_PTR) );
859 memcpy( ptr, &newval, sizeof(LONG_PTR) );
863 else switch(offset)
865 case GCLP_MENUNAME:
866 if ( unicode )
867 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
868 else
869 CLASS_SetMenuNameA( class, (LPCSTR)newval );
870 retval = 0; /* Old value is now meaningless anyway */
871 break;
872 case GCLP_WNDPROC:
873 retval = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
874 class->winproc = WINPROC_AllocProc( (WNDPROC)newval, unicode );
875 break;
876 case GCLP_HBRBACKGROUND:
877 retval = (ULONG_PTR)class->hbrBackground;
878 class->hbrBackground = (HBRUSH)newval;
879 break;
880 case GCLP_HCURSOR:
881 retval = (ULONG_PTR)class->hCursor;
882 class->hCursor = (HCURSOR)newval;
883 break;
884 case GCLP_HICON:
885 retval = (ULONG_PTR)class->hIcon;
886 class->hIcon = (HICON)newval;
887 break;
888 case GCLP_HICONSM:
889 retval = (ULONG_PTR)class->hIconSm;
890 class->hIconSm = (HICON)newval;
891 break;
892 case GCL_STYLE:
893 if (!set_server_info( hwnd, offset, newval, size )) break;
894 retval = class->style;
895 class->style = newval;
896 break;
897 case GCL_CBWNDEXTRA:
898 if (!set_server_info( hwnd, offset, newval, size )) break;
899 retval = class->cbWndExtra;
900 class->cbWndExtra = newval;
901 break;
902 case GCLP_HMODULE:
903 if (!set_server_info( hwnd, offset, newval, size )) break;
904 retval = (ULONG_PTR)class->hInstance;
905 class->hInstance = (HINSTANCE)newval;
906 break;
907 case GCW_ATOM:
908 if (!set_server_info( hwnd, offset, newval, size )) break;
909 retval = class->atomName;
910 class->atomName = newval;
911 GlobalGetAtomNameW( newval, class->name, sizeof(class->name)/sizeof(WCHAR) );
912 break;
913 case GCL_CBCLSEXTRA: /* cannot change this one */
914 SetLastError( ERROR_INVALID_PARAMETER );
915 break;
916 default:
917 SetLastError( ERROR_INVALID_INDEX );
918 break;
920 release_class_ptr( class );
921 return retval;
925 /***********************************************************************
926 * SetClassLongW (USER32.@)
928 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
930 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), TRUE );
934 /***********************************************************************
935 * SetClassLongA (USER32.@)
937 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
939 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), FALSE );
943 /***********************************************************************
944 * GetClassNameA (USER32.@)
946 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
948 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
949 DWORD len;
951 if (count <= 0) return 0;
952 if (!GetClassNameW( hwnd, tmpbuf, sizeof(tmpbuf)/sizeof(WCHAR) )) return 0;
953 RtlUnicodeToMultiByteN( buffer, count - 1, &len, tmpbuf, strlenW(tmpbuf) * sizeof(WCHAR) );
954 buffer[len] = 0;
955 return len;
959 /***********************************************************************
960 * GetClassNameW (USER32.@)
962 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
964 CLASS *class;
965 INT ret;
967 TRACE("%p %p %d\n", hwnd, buffer, count);
969 if (count <= 0) return 0;
971 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
973 if (class == CLASS_OTHER_PROCESS)
975 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
977 ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), tmpbuf, MAX_ATOM_LEN + 1 );
978 if (ret)
980 ret = min(count - 1, ret);
981 memcpy(buffer, tmpbuf, ret * sizeof(WCHAR));
982 buffer[ret] = 0;
985 else
987 lstrcpynW( buffer, class->name, count );
988 release_class_ptr( class );
989 ret = strlenW( buffer );
991 return ret;
995 /***********************************************************************
996 * RealGetWindowClassA (USER32.@)
998 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1000 return GetClassNameA( hwnd, buffer, count );
1004 /***********************************************************************
1005 * RealGetWindowClassW (USER32.@)
1007 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1009 return GetClassNameW( hwnd, buffer, count );
1013 /***********************************************************************
1014 * GetClassInfoA (USER32.@)
1016 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1018 WNDCLASSEXA wcex;
1019 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1021 if (ret)
1023 wc->style = wcex.style;
1024 wc->lpfnWndProc = wcex.lpfnWndProc;
1025 wc->cbClsExtra = wcex.cbClsExtra;
1026 wc->cbWndExtra = wcex.cbWndExtra;
1027 wc->hInstance = wcex.hInstance;
1028 wc->hIcon = wcex.hIcon;
1029 wc->hCursor = wcex.hCursor;
1030 wc->hbrBackground = wcex.hbrBackground;
1031 wc->lpszMenuName = wcex.lpszMenuName;
1032 wc->lpszClassName = wcex.lpszClassName;
1034 return ret;
1038 /***********************************************************************
1039 * GetClassInfoW (USER32.@)
1041 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1043 WNDCLASSEXW wcex;
1044 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1046 if (ret)
1048 wc->style = wcex.style;
1049 wc->lpfnWndProc = wcex.lpfnWndProc;
1050 wc->cbClsExtra = wcex.cbClsExtra;
1051 wc->cbWndExtra = wcex.cbWndExtra;
1052 wc->hInstance = wcex.hInstance;
1053 wc->hIcon = wcex.hIcon;
1054 wc->hCursor = wcex.hCursor;
1055 wc->hbrBackground = wcex.hbrBackground;
1056 wc->lpszMenuName = wcex.lpszMenuName;
1057 wc->lpszClassName = wcex.lpszClassName;
1059 return ret;
1063 /***********************************************************************
1064 * GetClassInfoExA (USER32.@)
1066 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1068 ATOM atom;
1069 CLASS *classPtr;
1071 TRACE("%p %s %p\n", hInstance, debugstr_a(name), wc);
1073 if (!hInstance) hInstance = user32_module;
1075 if (!IS_INTRESOURCE(name))
1077 WCHAR nameW[MAX_ATOM_LEN + 1];
1078 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, sizeof(nameW)/sizeof(WCHAR) ))
1079 return FALSE;
1080 classPtr = CLASS_FindClass( nameW, hInstance );
1082 else classPtr = CLASS_FindClass( (LPCWSTR)name, hInstance );
1084 if (!classPtr)
1086 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1087 return FALSE;
1089 wc->style = classPtr->style;
1090 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, FALSE );
1091 wc->cbClsExtra = classPtr->cbClsExtra;
1092 wc->cbWndExtra = classPtr->cbWndExtra;
1093 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1094 wc->hIcon = classPtr->hIcon;
1095 wc->hIconSm = classPtr->hIconSm;
1096 wc->hCursor = classPtr->hCursor;
1097 wc->hbrBackground = classPtr->hbrBackground;
1098 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1099 wc->lpszClassName = name;
1100 atom = classPtr->atomName;
1101 release_class_ptr( classPtr );
1103 /* We must return the atom of the class here instead of just TRUE. */
1104 return atom;
1108 /***********************************************************************
1109 * GetClassInfoExW (USER32.@)
1111 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1113 ATOM atom;
1114 CLASS *classPtr;
1116 TRACE("%p %s %p\n", hInstance, debugstr_w(name), wc);
1118 if (!hInstance) hInstance = user32_module;
1120 if (!(classPtr = CLASS_FindClass( name, hInstance )))
1122 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1123 return FALSE;
1125 wc->style = classPtr->style;
1126 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, TRUE );
1127 wc->cbClsExtra = classPtr->cbClsExtra;
1128 wc->cbWndExtra = classPtr->cbWndExtra;
1129 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1130 wc->hIcon = classPtr->hIcon;
1131 wc->hIconSm = classPtr->hIconSm;
1132 wc->hCursor = classPtr->hCursor;
1133 wc->hbrBackground = classPtr->hbrBackground;
1134 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1135 wc->lpszClassName = name;
1136 atom = classPtr->atomName;
1137 release_class_ptr( classPtr );
1139 /* We must return the atom of the class here instead of just TRUE. */
1140 return atom;
1144 #if 0 /* toolhelp is in kernel, so this cannot work */
1146 /***********************************************************************
1147 * ClassFirst (TOOLHELP.69)
1149 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1151 TRACE("%p\n",pClassEntry);
1152 pClassEntry->wNext = 1;
1153 return ClassNext16( pClassEntry );
1157 /***********************************************************************
1158 * ClassNext (TOOLHELP.70)
1160 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1162 int i;
1163 CLASS *class = firstClass;
1165 TRACE("%p\n",pClassEntry);
1167 if (!pClassEntry->wNext) return FALSE;
1168 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1169 if (!class)
1171 pClassEntry->wNext = 0;
1172 return FALSE;
1174 pClassEntry->hInst = class->hInstance;
1175 pClassEntry->wNext++;
1176 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1177 sizeof(pClassEntry->szClassName) );
1178 return TRUE;
1180 #endif
1182 /* 64bit versions */
1184 #ifdef GetClassLongPtrA
1185 #undef GetClassLongPtrA
1186 #endif
1188 #ifdef GetClassLongPtrW
1189 #undef GetClassLongPtrW
1190 #endif
1192 #ifdef SetClassLongPtrA
1193 #undef SetClassLongPtrA
1194 #endif
1196 #ifdef SetClassLongPtrW
1197 #undef SetClassLongPtrW
1198 #endif
1200 /***********************************************************************
1201 * GetClassLongPtrA (USER32.@)
1203 ULONG_PTR WINAPI GetClassLongPtrA( HWND hwnd, INT offset )
1205 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), FALSE );
1208 /***********************************************************************
1209 * GetClassLongPtrW (USER32.@)
1211 ULONG_PTR WINAPI GetClassLongPtrW( HWND hwnd, INT offset )
1213 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), TRUE );
1216 /***********************************************************************
1217 * SetClassLongPtrW (USER32.@)
1219 ULONG_PTR WINAPI SetClassLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
1221 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), TRUE );
1224 /***********************************************************************
1225 * SetClassLongPtrA (USER32.@)
1227 ULONG_PTR WINAPI SetClassLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
1229 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), FALSE );