setupapi: Store pointer to an interface's device in the interface instance.
[wine/hacks.git] / dlls / user32 / class.c
blob6be4cadd3cb019ac151f4b8cb10c24557412cbb7
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 typedef struct tagCLASS
46 struct list entry; /* Entry in class list */
47 UINT style; /* Class style */
48 BOOL local; /* Local class? */
49 WNDPROC winproc; /* Window procedure */
50 INT cbClsExtra; /* Class extra bytes */
51 INT cbWndExtra; /* Window extra bytes */
52 LPWSTR menuName; /* Default menu name (Unicode followed by ASCII) */
53 HINSTANCE hInstance; /* Module that created the task */
54 HICON hIcon; /* Default icon */
55 HICON hIconSm; /* Default small icon */
56 HCURSOR hCursor; /* Default cursor */
57 HBRUSH hbrBackground; /* Default background */
58 ATOM atomName; /* Name of the class */
59 } CLASS;
61 static struct list class_list = LIST_INIT( class_list );
63 #define CLASS_OTHER_PROCESS ((CLASS *)1)
64 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
66 /***********************************************************************
67 * get_class_ptr
69 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
71 WND *ptr = WIN_GetPtr( hwnd );
73 if (ptr)
75 if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP) return ptr->class;
76 if (!write_access) return CLASS_OTHER_PROCESS;
78 /* modifying classes in other processes is not allowed */
79 if (ptr == WND_DESKTOP || IsWindow( hwnd ))
81 SetLastError( ERROR_ACCESS_DENIED );
82 return NULL;
85 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
86 return NULL;
90 /***********************************************************************
91 * release_class_ptr
93 static inline void release_class_ptr( CLASS *ptr )
95 USER_Unlock();
99 /***********************************************************************
100 * set_server_info
102 * Set class info with the wine server.
104 static BOOL set_server_info( HWND hwnd, INT offset, LONG_PTR newval, UINT size )
106 BOOL ret;
108 SERVER_START_REQ( set_class_info )
110 req->window = hwnd;
111 req->extra_offset = -1;
112 switch(offset)
114 case GCW_ATOM:
115 req->flags = SET_CLASS_ATOM;
116 req->atom = newval;
117 case GCL_STYLE:
118 req->flags = SET_CLASS_STYLE;
119 req->style = newval;
120 break;
121 case GCL_CBWNDEXTRA:
122 req->flags = SET_CLASS_WINEXTRA;
123 req->win_extra = newval;
124 break;
125 case GCLP_HMODULE:
126 req->flags = SET_CLASS_INSTANCE;
127 req->instance = (void *)newval;
128 break;
129 default:
130 assert( offset >= 0 );
131 req->flags = SET_CLASS_EXTRA;
132 req->extra_offset = offset;
133 req->extra_size = size;
134 if ( size == sizeof(LONG) )
136 LONG newlong = newval;
137 memcpy( &req->extra_value, &newlong, sizeof(LONG) );
139 else
140 memcpy( &req->extra_value, &newval, sizeof(LONG_PTR) );
141 break;
143 ret = !wine_server_call_err( req );
145 SERVER_END_REQ;
146 return ret;
150 /***********************************************************************
151 * CLASS_GetMenuNameA
153 * Get the menu name as a ASCII string.
155 static inline LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
157 if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
158 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
162 /***********************************************************************
163 * CLASS_GetMenuNameW
165 * Get the menu name as a Unicode string.
167 static inline LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
169 return classPtr->menuName;
173 /***********************************************************************
174 * CLASS_SetMenuNameA
176 * Set the menu name in a class structure by copying the string.
178 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
180 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
181 if (HIWORD(name))
183 DWORD lenA = strlen(name) + 1;
184 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
185 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
186 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
187 memcpy( classPtr->menuName + lenW, name, lenA );
189 else classPtr->menuName = (LPWSTR)name;
193 /***********************************************************************
194 * CLASS_SetMenuNameW
196 * Set the menu name in a class structure by copying the string.
198 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
200 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
201 if (HIWORD(name))
203 DWORD lenW = strlenW(name) + 1;
204 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
205 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
206 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
207 WideCharToMultiByte( CP_ACP, 0, name, lenW,
208 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
210 else classPtr->menuName = (LPWSTR)name;
214 /***********************************************************************
215 * CLASS_FreeClass
217 * Free a class structure.
219 static void CLASS_FreeClass( CLASS *classPtr )
221 TRACE("%p\n", classPtr);
223 USER_Lock();
225 list_remove( &classPtr->entry );
226 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
227 DeleteObject( classPtr->hbrBackground );
228 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
229 HeapFree( GetProcessHeap(), 0, classPtr );
230 USER_Unlock();
234 /***********************************************************************
235 * CLASS_FreeModuleClasses
237 void CLASS_FreeModuleClasses( HMODULE16 hModule )
239 struct list *ptr, *next;
241 TRACE("0x%08x\n", hModule);
243 USER_Lock();
244 for (ptr = list_head( &class_list ); ptr; ptr = next)
246 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
247 next = list_next( &class_list, ptr );
248 if (class->hInstance == HINSTANCE_32(hModule))
250 BOOL ret;
252 SERVER_START_REQ( destroy_class )
254 req->atom = class->atomName;
255 req->instance = class->hInstance;
256 ret = !wine_server_call_err( req );
258 SERVER_END_REQ;
259 if (ret) CLASS_FreeClass( class );
262 USER_Unlock();
266 /***********************************************************************
267 * CLASS_FindClassByAtom
269 * Return a pointer to the class.
270 * hinstance has been normalized by the caller.
272 static CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE hinstance )
274 struct list *ptr;
276 USER_Lock();
278 LIST_FOR_EACH( ptr, &class_list )
280 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
281 if (class->atomName != atom) continue;
282 if (!hinstance || !class->local || class->hInstance == hinstance)
284 TRACE("0x%04x %p -> %p\n", atom, hinstance, class);
285 return class;
288 USER_Unlock();
289 TRACE("0x%04x %p -> not found\n", atom, hinstance);
290 return NULL;
294 /***********************************************************************
295 * CLASS_RegisterClass
297 * The real RegisterClass() functionality.
298 * The atom is deleted no matter what.
300 static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE hInstance, BOOL local,
301 DWORD style, INT classExtra, INT winExtra )
303 CLASS *classPtr;
304 BOOL ret;
306 TRACE("atom=0x%x hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
307 atom, hInstance, style, classExtra, winExtra );
309 /* Fix the extra bytes value */
311 if (classExtra < 0 || winExtra < 0)
313 SetLastError( ERROR_INVALID_PARAMETER );
314 return NULL;
316 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
317 WARN("Class extra bytes %d is > 40\n", classExtra);
318 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
319 WARN("Win extra bytes %d is > 40\n", winExtra );
321 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
322 if (!classPtr)
324 GlobalDeleteAtom( atom );
325 return NULL;
328 SERVER_START_REQ( create_class )
330 req->local = local;
331 req->atom = atom;
332 req->style = style;
333 req->instance = hInstance;
334 req->extra = classExtra;
335 req->win_extra = winExtra;
336 req->client_ptr = classPtr;
337 ret = !wine_server_call_err( req );
339 SERVER_END_REQ;
340 GlobalDeleteAtom( atom ); /* the server increased the atom ref count */
341 if (!ret)
343 HeapFree( GetProcessHeap(), 0, classPtr );
344 return NULL;
347 classPtr->style = style;
348 classPtr->local = local;
349 classPtr->cbWndExtra = winExtra;
350 classPtr->cbClsExtra = classExtra;
351 classPtr->hInstance = hInstance;
352 classPtr->atomName = atom;
354 /* Other non-null values must be set by caller */
356 USER_Lock();
357 if (local) list_add_head( &class_list, &classPtr->entry );
358 else list_add_tail( &class_list, &classPtr->entry );
359 return classPtr;
363 /***********************************************************************
364 * register_builtin
366 * Register a builtin control class.
367 * This allows having both ASCII and Unicode winprocs for the same class.
369 static CLASS *register_builtin( const struct builtin_class_descr *descr )
371 ATOM atom;
372 CLASS *classPtr;
374 if (!(atom = GlobalAddAtomA( descr->name ))) return 0;
376 if (!(classPtr = CLASS_RegisterClass( atom, user32_module, FALSE,
377 descr->style, 0, descr->extra ))) return 0;
379 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
380 classPtr->hbrBackground = descr->brush;
381 classPtr->winproc = WINPROC_AllocProc( descr->procA, descr->procW );
382 release_class_ptr( classPtr );
383 return classPtr;
387 /***********************************************************************
388 * CLASS_RegisterBuiltinClasses
390 void CLASS_RegisterBuiltinClasses(void)
392 extern const struct builtin_class_descr BUTTON_builtin_class;
393 extern const struct builtin_class_descr COMBO_builtin_class;
394 extern const struct builtin_class_descr COMBOLBOX_builtin_class;
395 extern const struct builtin_class_descr DIALOG_builtin_class;
396 extern const struct builtin_class_descr DESKTOP_builtin_class;
397 extern const struct builtin_class_descr EDIT_builtin_class;
398 extern const struct builtin_class_descr ICONTITLE_builtin_class;
399 extern const struct builtin_class_descr LISTBOX_builtin_class;
400 extern const struct builtin_class_descr MDICLIENT_builtin_class;
401 extern const struct builtin_class_descr MENU_builtin_class;
402 extern const struct builtin_class_descr SCROLL_builtin_class;
403 extern const struct builtin_class_descr STATIC_builtin_class;
405 register_builtin( &DESKTOP_builtin_class );
406 register_builtin( &BUTTON_builtin_class );
407 register_builtin( &COMBO_builtin_class );
408 register_builtin( &COMBOLBOX_builtin_class );
409 register_builtin( &DIALOG_builtin_class );
410 register_builtin( &EDIT_builtin_class );
411 register_builtin( &ICONTITLE_builtin_class );
412 register_builtin( &LISTBOX_builtin_class );
413 register_builtin( &MDICLIENT_builtin_class );
414 register_builtin( &MENU_builtin_class );
415 register_builtin( &SCROLL_builtin_class );
416 register_builtin( &STATIC_builtin_class );
418 /* the DefWindowProc winprocs are magic too */
419 WINPROC_AllocProc( DefWindowProcA, DefWindowProcW );
423 /***********************************************************************
424 * CLASS_AddWindow
426 * Add a new window using this class, and set the necessary
427 * information inside the window structure.
429 void CLASS_AddWindow( CLASS *class, WND *win, BOOL unicode )
431 win->class = class;
432 win->clsStyle = class->style;
433 win->winproc = class->winproc;
434 if (WINPROC_IsUnicode( win->winproc, unicode )) win->flags |= WIN_ISUNICODE;
438 /***********************************************************************
439 * RegisterClassA (USER32.@)
441 * Register a window class.
443 * RETURNS
444 * >0: Unique identifier
445 * 0: Failure
447 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
449 WNDCLASSEXA wcex;
451 wcex.cbSize = sizeof(wcex);
452 wcex.style = wc->style;
453 wcex.lpfnWndProc = wc->lpfnWndProc;
454 wcex.cbClsExtra = wc->cbClsExtra;
455 wcex.cbWndExtra = wc->cbWndExtra;
456 wcex.hInstance = wc->hInstance;
457 wcex.hIcon = wc->hIcon;
458 wcex.hCursor = wc->hCursor;
459 wcex.hbrBackground = wc->hbrBackground;
460 wcex.lpszMenuName = wc->lpszMenuName;
461 wcex.lpszClassName = wc->lpszClassName;
462 wcex.hIconSm = 0;
463 return RegisterClassExA( &wcex );
467 /***********************************************************************
468 * RegisterClassW (USER32.@)
470 * See RegisterClassA.
472 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
474 WNDCLASSEXW wcex;
476 wcex.cbSize = sizeof(wcex);
477 wcex.style = wc->style;
478 wcex.lpfnWndProc = wc->lpfnWndProc;
479 wcex.cbClsExtra = wc->cbClsExtra;
480 wcex.cbWndExtra = wc->cbWndExtra;
481 wcex.hInstance = wc->hInstance;
482 wcex.hIcon = wc->hIcon;
483 wcex.hCursor = wc->hCursor;
484 wcex.hbrBackground = wc->hbrBackground;
485 wcex.lpszMenuName = wc->lpszMenuName;
486 wcex.lpszClassName = wc->lpszClassName;
487 wcex.hIconSm = 0;
488 return RegisterClassExW( &wcex );
492 /***********************************************************************
493 * RegisterClassExA (USER32.@)
495 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
497 ATOM atom;
498 CLASS *classPtr;
499 HINSTANCE instance;
501 if (wc->hInstance == user32_module)
503 /* we can't register a class for user32 */
504 SetLastError( ERROR_INVALID_PARAMETER );
505 return 0;
507 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
509 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
511 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
512 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
513 return 0;
515 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
516 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, NULL );
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->hInstance == user32_module)
541 /* 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 (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
549 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
550 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
551 return 0;
553 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
554 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( NULL, wc->lpfnWndProc );
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 ATOM atom = HIWORD(className) ? GlobalFindAtomA( className ) : LOWORD(className);
574 return UnregisterClassW( (LPCWSTR)MAKEINTATOM(atom), hInstance );
577 /***********************************************************************
578 * UnregisterClassW (USER32.@)
580 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
582 CLASS *classPtr = NULL;
583 ATOM atom = HIWORD(className) ? GlobalFindAtomW( className ) : LOWORD(className);
585 TRACE("%s %p %x\n",debugstr_w(className), hInstance, atom);
587 if (!atom)
589 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
590 return FALSE;
593 SERVER_START_REQ( destroy_class )
595 req->atom = atom;
596 req->instance = hInstance;
597 if (!wine_server_call_err( req )) classPtr = reply->client_ptr;
599 SERVER_END_REQ;
601 if (classPtr) CLASS_FreeClass( classPtr );
602 return (classPtr != NULL);
606 /***********************************************************************
607 * GetClassWord (USER32.@)
609 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
611 CLASS *class;
612 WORD retvalue = 0;
614 if (offset < 0) return GetClassLongA( hwnd, offset );
616 TRACE("%p %x\n",hwnd, offset);
618 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
620 if (class == CLASS_OTHER_PROCESS)
622 SERVER_START_REQ( set_class_info )
624 req->window = hwnd;
625 req->flags = 0;
626 req->extra_offset = offset;
627 req->extra_size = sizeof(retvalue);
628 if (!wine_server_call_err( req ))
629 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
631 SERVER_END_REQ;
632 return retvalue;
635 if (offset <= class->cbClsExtra - sizeof(WORD))
636 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
637 else
638 SetLastError( ERROR_INVALID_INDEX );
639 release_class_ptr( class );
640 return retvalue;
644 /***********************************************************************
645 * CLASS_GetClassLong
647 * Implementation of GetClassLong(Ptr)A/W
649 static ULONG_PTR CLASS_GetClassLong( HWND hwnd, INT offset, UINT size,
650 BOOL unicode )
652 CLASS *class;
653 ULONG_PTR retvalue = 0;
655 TRACE("%p %d\n", hwnd, offset);
657 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
659 if (class == CLASS_OTHER_PROCESS)
661 SERVER_START_REQ( set_class_info )
663 req->window = hwnd;
664 req->flags = 0;
665 req->extra_offset = (offset >= 0) ? offset : -1;
666 req->extra_size = (offset >= 0) ? size : 0;
667 if (!wine_server_call_err( req ))
669 switch(offset)
671 case GCLP_HBRBACKGROUND:
672 case GCLP_HCURSOR:
673 case GCLP_HICON:
674 case GCLP_HICONSM:
675 case GCLP_WNDPROC:
676 case GCLP_MENUNAME:
677 FIXME( "offset %d (%s) not supported on other process window %p\n",
678 offset, SPY_GetClassLongOffsetName(offset), hwnd );
679 SetLastError( ERROR_INVALID_HANDLE );
680 break;
681 case GCL_STYLE:
682 retvalue = reply->old_style;
683 break;
684 case GCL_CBWNDEXTRA:
685 retvalue = reply->old_win_extra;
686 break;
687 case GCL_CBCLSEXTRA:
688 retvalue = reply->old_extra;
689 break;
690 case GCLP_HMODULE:
691 retvalue = (ULONG_PTR)reply->old_instance;
692 break;
693 case GCW_ATOM:
694 retvalue = reply->old_atom;
695 break;
696 default:
697 if (offset >= 0)
699 if (size == sizeof(DWORD))
701 DWORD retdword;
702 memcpy( &retdword, &reply->old_extra_value, sizeof(DWORD) );
703 retvalue = retdword;
705 else
706 memcpy( &retvalue, &reply->old_extra_value,
707 sizeof(ULONG_PTR) );
709 else SetLastError( ERROR_INVALID_INDEX );
710 break;
714 SERVER_END_REQ;
715 return retvalue;
718 if (offset >= 0)
720 if (offset <= class->cbClsExtra - size)
722 if (size == sizeof(DWORD))
724 DWORD retdword;
725 memcpy( &retdword, (char *)(class + 1) + offset, sizeof(DWORD) );
726 retvalue = retdword;
728 else
729 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(ULONG_PTR) );
731 else
732 SetLastError( ERROR_INVALID_INDEX );
733 release_class_ptr( class );
734 return retvalue;
737 switch(offset)
739 case GCLP_HBRBACKGROUND:
740 retvalue = (ULONG_PTR)class->hbrBackground;
741 break;
742 case GCLP_HCURSOR:
743 retvalue = (ULONG_PTR)class->hCursor;
744 break;
745 case GCLP_HICON:
746 retvalue = (ULONG_PTR)class->hIcon;
747 break;
748 case GCLP_HICONSM:
749 retvalue = (ULONG_PTR)class->hIconSm;
750 break;
751 case GCL_STYLE:
752 retvalue = class->style;
753 break;
754 case GCL_CBWNDEXTRA:
755 retvalue = class->cbWndExtra;
756 break;
757 case GCL_CBCLSEXTRA:
758 retvalue = class->cbClsExtra;
759 break;
760 case GCLP_HMODULE:
761 retvalue = (ULONG_PTR)class->hInstance;
762 break;
763 case GCLP_WNDPROC:
764 retvalue = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
765 break;
766 case GCLP_MENUNAME:
767 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
768 if (unicode)
769 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
770 else
771 retvalue = (ULONG_PTR)CLASS_GetMenuNameA( class );
772 break;
773 case GCW_ATOM:
774 retvalue = class->atomName;
775 break;
776 default:
777 SetLastError( ERROR_INVALID_INDEX );
778 break;
780 release_class_ptr( class );
781 return retvalue;
785 /***********************************************************************
786 * GetClassLongW (USER32.@)
788 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
790 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), TRUE );
795 /***********************************************************************
796 * GetClassLongA (USER32.@)
798 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
800 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), FALSE );
804 /***********************************************************************
805 * SetClassWord (USER32.@)
807 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
809 CLASS *class;
810 WORD retval = 0;
812 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
814 TRACE("%p %d %x\n", hwnd, offset, newval);
816 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
818 SERVER_START_REQ( set_class_info )
820 req->window = hwnd;
821 req->flags = SET_CLASS_EXTRA;
822 req->extra_offset = offset;
823 req->extra_size = sizeof(newval);
824 memcpy( &req->extra_value, &newval, sizeof(newval) );
825 if (!wine_server_call_err( req ))
827 void *ptr = (char *)(class + 1) + offset;
828 memcpy( &retval, ptr, sizeof(retval) );
829 memcpy( ptr, &newval, sizeof(newval) );
832 SERVER_END_REQ;
833 release_class_ptr( class );
834 return retval;
838 /***********************************************************************
839 * CLASS_SetClassLong
841 * Implementation of SetClassLong(Ptr)A/W
843 static ULONG_PTR CLASS_SetClassLong( HWND hwnd, INT offset, LONG_PTR newval,
844 UINT size, BOOL unicode )
846 CLASS *class;
847 ULONG_PTR retval = 0;
849 TRACE("%p %d %lx\n", hwnd, offset, newval);
851 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
853 if (offset >= 0)
855 if (set_server_info( hwnd, offset, newval, size ))
857 void *ptr = (char *)(class + 1) + offset;
858 if ( size == sizeof(LONG) )
860 DWORD retdword;
861 LONG newlong = newval;
862 memcpy( &retdword, ptr, sizeof(DWORD) );
863 memcpy( ptr, &newlong, sizeof(LONG) );
864 retval = retdword;
866 else
868 memcpy( &retval, ptr, sizeof(ULONG_PTR) );
869 memcpy( ptr, &newval, sizeof(LONG_PTR) );
873 else switch(offset)
875 case GCLP_MENUNAME:
876 if ( unicode )
877 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
878 else
879 CLASS_SetMenuNameA( class, (LPCSTR)newval );
880 retval = 0; /* Old value is now meaningless anyway */
881 break;
882 case GCLP_WNDPROC:
883 retval = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
884 class->winproc = WINPROC_AllocProc( unicode ? NULL : (WNDPROC)newval,
885 unicode ? (WNDPROC)newval : NULL );
886 break;
887 case GCLP_HBRBACKGROUND:
888 retval = (ULONG_PTR)class->hbrBackground;
889 class->hbrBackground = (HBRUSH)newval;
890 break;
891 case GCLP_HCURSOR:
892 retval = (ULONG_PTR)class->hCursor;
893 class->hCursor = (HCURSOR)newval;
894 break;
895 case GCLP_HICON:
896 retval = (ULONG_PTR)class->hIcon;
897 class->hIcon = (HICON)newval;
898 break;
899 case GCLP_HICONSM:
900 retval = (ULONG_PTR)class->hIconSm;
901 class->hIconSm = (HICON)newval;
902 break;
903 case GCL_STYLE:
904 if (!set_server_info( hwnd, offset, newval, size )) break;
905 retval = class->style;
906 class->style = newval;
907 break;
908 case GCL_CBWNDEXTRA:
909 if (!set_server_info( hwnd, offset, newval, size )) break;
910 retval = class->cbWndExtra;
911 class->cbWndExtra = newval;
912 break;
913 case GCLP_HMODULE:
914 if (!set_server_info( hwnd, offset, newval, size )) break;
915 retval = (ULONG_PTR)class->hInstance;
916 class->hInstance = (HINSTANCE)newval;
917 break;
918 case GCW_ATOM:
919 if (!set_server_info( hwnd, offset, newval, size )) break;
920 retval = class->atomName;
921 class->atomName = newval;
922 break;
923 case GCL_CBCLSEXTRA: /* cannot change this one */
924 SetLastError( ERROR_INVALID_PARAMETER );
925 break;
926 default:
927 SetLastError( ERROR_INVALID_INDEX );
928 break;
930 release_class_ptr( class );
931 return retval;
935 /***********************************************************************
936 * SetClassLongW (USER32.@)
938 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
940 TRACE("%p %d %x\n", hwnd, offset, newval);
942 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), TRUE );
946 /***********************************************************************
947 * SetClassLongA (USER32.@)
949 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
951 TRACE("%p %d %x\n", hwnd, offset, newval);
953 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), FALSE );
957 /***********************************************************************
958 * GetClassNameA (USER32.@)
960 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
962 char tmpbuf[MAX_ATOM_LEN + 1];
963 INT ret;
965 TRACE("%p %p %d\n", hwnd, buffer, count);
967 if (count <= 0) return 0;
969 ret = GlobalGetAtomNameA( GetClassLongW( hwnd, GCW_ATOM ), tmpbuf, MAX_ATOM_LEN + 1 );
970 if (ret)
972 ret = min(count - 1, ret);
973 memcpy(buffer, tmpbuf, ret);
974 buffer[ret] = 0;
976 return ret;
980 /***********************************************************************
981 * GetClassNameW (USER32.@)
983 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
985 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
986 INT ret;
988 TRACE("%p %p %d\n", hwnd, buffer, count);
990 if (count <= 0) return 0;
992 ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), tmpbuf, MAX_ATOM_LEN + 1 );
993 if (ret)
995 ret = min(count - 1, ret);
996 memcpy(buffer, tmpbuf, ret * sizeof(WCHAR));
997 buffer[ret] = 0;
999 return ret;
1003 /***********************************************************************
1004 * RealGetWindowClassA (USER32.@)
1006 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1008 return GetClassNameA( hwnd, buffer, count );
1012 /***********************************************************************
1013 * RealGetWindowClassW (USER32.@)
1015 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1017 return GetClassNameW( hwnd, buffer, count );
1021 /***********************************************************************
1022 * GetClassInfoA (USER32.@)
1024 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1026 WNDCLASSEXA wcex;
1027 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1029 if (ret)
1031 wc->style = wcex.style;
1032 wc->lpfnWndProc = wcex.lpfnWndProc;
1033 wc->cbClsExtra = wcex.cbClsExtra;
1034 wc->cbWndExtra = wcex.cbWndExtra;
1035 wc->hInstance = wcex.hInstance;
1036 wc->hIcon = wcex.hIcon;
1037 wc->hCursor = wcex.hCursor;
1038 wc->hbrBackground = wcex.hbrBackground;
1039 wc->lpszMenuName = wcex.lpszMenuName;
1040 wc->lpszClassName = wcex.lpszClassName;
1042 return ret;
1046 /***********************************************************************
1047 * GetClassInfoW (USER32.@)
1049 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1051 WNDCLASSEXW wcex;
1052 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1054 if (ret)
1056 wc->style = wcex.style;
1057 wc->lpfnWndProc = wcex.lpfnWndProc;
1058 wc->cbClsExtra = wcex.cbClsExtra;
1059 wc->cbWndExtra = wcex.cbWndExtra;
1060 wc->hInstance = wcex.hInstance;
1061 wc->hIcon = wcex.hIcon;
1062 wc->hCursor = wcex.hCursor;
1063 wc->hbrBackground = wcex.hbrBackground;
1064 wc->lpszMenuName = wcex.lpszMenuName;
1065 wc->lpszClassName = wcex.lpszClassName;
1067 return ret;
1071 /***********************************************************************
1072 * GetClassInfoExA (USER32.@)
1074 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1076 ATOM atom = HIWORD(name) ? GlobalFindAtomA( name ) : LOWORD(name);
1077 CLASS *classPtr;
1079 TRACE("%p %s %x %p\n", hInstance, debugstr_a(name), atom, wc);
1081 if (!hInstance) hInstance = user32_module;
1083 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1085 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1086 return FALSE;
1088 wc->style = classPtr->style;
1089 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, FALSE );
1090 wc->cbClsExtra = classPtr->cbClsExtra;
1091 wc->cbWndExtra = classPtr->cbWndExtra;
1092 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1093 wc->hIcon = (HICON)classPtr->hIcon;
1094 wc->hIconSm = (HICON)classPtr->hIconSm;
1095 wc->hCursor = (HCURSOR)classPtr->hCursor;
1096 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1097 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1098 wc->lpszClassName = name;
1099 release_class_ptr( classPtr );
1101 /* We must return the atom of the class here instead of just TRUE. */
1102 return atom;
1106 /***********************************************************************
1107 * GetClassInfoExW (USER32.@)
1109 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1111 ATOM atom = HIWORD(name) ? GlobalFindAtomW( name ) : LOWORD(name);
1112 CLASS *classPtr;
1114 TRACE("%p %s %x %p\n", hInstance, debugstr_w(name), atom, wc);
1116 if (!hInstance) hInstance = user32_module;
1118 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1120 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1121 return FALSE;
1123 wc->style = classPtr->style;
1124 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, TRUE );
1125 wc->cbClsExtra = classPtr->cbClsExtra;
1126 wc->cbWndExtra = classPtr->cbWndExtra;
1127 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1128 wc->hIcon = (HICON)classPtr->hIcon;
1129 wc->hIconSm = (HICON)classPtr->hIconSm;
1130 wc->hCursor = (HCURSOR)classPtr->hCursor;
1131 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1132 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1133 wc->lpszClassName = name;
1134 release_class_ptr( classPtr );
1136 /* We must return the atom of the class here instead of just TRUE. */
1137 return atom;
1141 #if 0 /* toolhelp is in kernel, so this cannot work */
1143 /***********************************************************************
1144 * ClassFirst (TOOLHELP.69)
1146 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1148 TRACE("%p\n",pClassEntry);
1149 pClassEntry->wNext = 1;
1150 return ClassNext16( pClassEntry );
1154 /***********************************************************************
1155 * ClassNext (TOOLHELP.70)
1157 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1159 int i;
1160 CLASS *class = firstClass;
1162 TRACE("%p\n",pClassEntry);
1164 if (!pClassEntry->wNext) return FALSE;
1165 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1166 if (!class)
1168 pClassEntry->wNext = 0;
1169 return FALSE;
1171 pClassEntry->hInst = class->hInstance;
1172 pClassEntry->wNext++;
1173 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1174 sizeof(pClassEntry->szClassName) );
1175 return TRUE;
1177 #endif
1179 /* 64bit versions */
1181 #ifdef GetClassLongPtrA
1182 #undef GetClassLongPtrA
1183 #endif
1185 #ifdef GetClassLongPtrW
1186 #undef GetClassLongPtrW
1187 #endif
1189 #ifdef SetClassLongPtrA
1190 #undef SetClassLongPtrA
1191 #endif
1193 #ifdef SetClassLongPtrW
1194 #undef SetClassLongPtrW
1195 #endif
1197 /***********************************************************************
1198 * GetClassLongPtrA (USER32.@)
1200 ULONG_PTR WINAPI GetClassLongPtrA( HWND hwnd, INT offset )
1202 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), FALSE );
1205 /***********************************************************************
1206 * GetClassLongPtrW (USER32.@)
1208 ULONG_PTR WINAPI GetClassLongPtrW( HWND hwnd, INT offset )
1210 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), TRUE );
1213 /***********************************************************************
1214 * SetClassLongPtrW (USER32.@)
1216 ULONG_PTR WINAPI SetClassLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
1218 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), TRUE );
1221 /***********************************************************************
1222 * SetClassLongPtrA (USER32.@)
1224 ULONG_PTR WINAPI SetClassLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
1226 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), FALSE );