dsound: Allow mixing the same buffer multiple times if we are looping.
[wine.git] / dlls / user32 / class.c
blob4f6c7b52975c20edded36c4c4e1d6c3216134634
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/winuser16.h"
35 #include "wine/unicode.h"
36 #include "win.h"
37 #include "user_private.h"
38 #include "controls.h"
39 #include "winproc.h"
40 #include "wine/server.h"
41 #include "wine/list.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(class);
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 HINSTANCE hInstance; /* Module that created the task */
56 HICON hIcon; /* Default icon */
57 HICON hIconSm; /* Default small icon */
58 HCURSOR hCursor; /* Default cursor */
59 HBRUSH hbrBackground; /* Default background */
60 ATOM atomName; /* Name of the class */
61 } CLASS;
63 static struct list class_list = LIST_INIT( class_list );
65 #define CLASS_OTHER_PROCESS ((CLASS *)1)
66 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
68 /***********************************************************************
69 * get_class_ptr
71 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
73 WND *ptr = WIN_GetPtr( hwnd );
75 if (ptr)
77 if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP) return ptr->class;
78 if (!write_access) return CLASS_OTHER_PROCESS;
80 /* modifying classes in other processes is not allowed */
81 if (ptr == WND_DESKTOP || IsWindow( hwnd ))
83 SetLastError( ERROR_ACCESS_DENIED );
84 return NULL;
87 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
88 return NULL;
92 /***********************************************************************
93 * release_class_ptr
95 static inline void release_class_ptr( CLASS *ptr )
97 USER_Unlock();
101 /***********************************************************************
102 * set_server_info
104 * Set class info with the wine server.
106 static BOOL set_server_info( HWND hwnd, INT offset, LONG_PTR newval, UINT size )
108 BOOL ret;
110 SERVER_START_REQ( set_class_info )
112 req->window = hwnd;
113 req->extra_offset = -1;
114 switch(offset)
116 case GCW_ATOM:
117 req->flags = SET_CLASS_ATOM;
118 req->atom = newval;
119 case GCL_STYLE:
120 req->flags = SET_CLASS_STYLE;
121 req->style = newval;
122 break;
123 case GCL_CBWNDEXTRA:
124 req->flags = SET_CLASS_WINEXTRA;
125 req->win_extra = newval;
126 break;
127 case GCLP_HMODULE:
128 req->flags = SET_CLASS_INSTANCE;
129 req->instance = (void *)newval;
130 break;
131 default:
132 assert( offset >= 0 );
133 req->flags = SET_CLASS_EXTRA;
134 req->extra_offset = offset;
135 req->extra_size = size;
136 if ( size == sizeof(LONG) )
138 LONG newlong = newval;
139 memcpy( &req->extra_value, &newlong, sizeof(LONG) );
141 else
142 memcpy( &req->extra_value, &newval, sizeof(LONG_PTR) );
143 break;
145 ret = !wine_server_call_err( req );
147 SERVER_END_REQ;
148 return ret;
152 /***********************************************************************
153 * CLASS_GetMenuNameA
155 * Get the menu name as a ASCII string.
157 static inline LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
159 if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
160 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
164 /***********************************************************************
165 * CLASS_GetMenuNameW
167 * Get the menu name as a Unicode string.
169 static inline LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
171 return classPtr->menuName;
175 /***********************************************************************
176 * CLASS_SetMenuNameA
178 * Set the menu name in a class structure by copying the string.
180 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
182 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
183 if (HIWORD(name))
185 DWORD lenA = strlen(name) + 1;
186 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
187 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
188 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
189 memcpy( classPtr->menuName + lenW, name, lenA );
191 else classPtr->menuName = (LPWSTR)name;
195 /***********************************************************************
196 * CLASS_SetMenuNameW
198 * Set the menu name in a class structure by copying the string.
200 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
202 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
203 if (HIWORD(name))
205 DWORD lenW = strlenW(name) + 1;
206 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
207 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
208 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
209 WideCharToMultiByte( CP_ACP, 0, name, lenW,
210 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
212 else classPtr->menuName = (LPWSTR)name;
216 /***********************************************************************
217 * CLASS_FreeClass
219 * Free a class structure.
221 static void CLASS_FreeClass( CLASS *classPtr )
223 TRACE("%p\n", classPtr);
225 USER_Lock();
227 list_remove( &classPtr->entry );
228 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
229 DeleteObject( classPtr->hbrBackground );
230 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
231 HeapFree( GetProcessHeap(), 0, classPtr );
232 USER_Unlock();
236 /***********************************************************************
237 * CLASS_FreeModuleClasses
239 void CLASS_FreeModuleClasses( HMODULE16 hModule )
241 struct list *ptr, *next;
243 TRACE("0x%08x\n", hModule);
245 USER_Lock();
246 for (ptr = list_head( &class_list ); ptr; ptr = next)
248 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
249 next = list_next( &class_list, ptr );
250 if (class->hInstance == HINSTANCE_32(hModule))
252 BOOL ret;
254 SERVER_START_REQ( destroy_class )
256 req->atom = class->atomName;
257 req->instance = class->hInstance;
258 ret = !wine_server_call_err( req );
260 SERVER_END_REQ;
261 if (ret) CLASS_FreeClass( class );
264 USER_Unlock();
268 /***********************************************************************
269 * CLASS_FindClassByAtom
271 * Return a pointer to the class.
272 * hinstance has been normalized by the caller.
274 static CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE hinstance )
276 struct list *ptr;
278 USER_Lock();
280 LIST_FOR_EACH( ptr, &class_list )
282 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
283 if (class->atomName != atom) continue;
284 if (!hinstance || !class->local || class->hInstance == hinstance)
286 TRACE("0x%04x %p -> %p\n", atom, hinstance, class);
287 return class;
290 USER_Unlock();
291 TRACE("0x%04x %p -> not found\n", atom, hinstance);
292 return NULL;
296 /***********************************************************************
297 * CLASS_RegisterClass
299 * The real RegisterClass() functionality.
300 * The atom is deleted no matter what.
302 static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE hInstance, BOOL local,
303 DWORD style, INT classExtra, INT winExtra )
305 CLASS *classPtr;
306 BOOL ret;
308 TRACE("atom=0x%x hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
309 atom, hInstance, style, classExtra, winExtra );
311 /* Fix the extra bytes value */
313 if (classExtra < 0 || winExtra < 0)
315 SetLastError( ERROR_INVALID_PARAMETER );
316 return NULL;
318 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
319 WARN("Class extra bytes %d is > 40\n", classExtra);
320 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
321 WARN("Win extra bytes %d is > 40\n", winExtra );
323 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
324 if (!classPtr)
326 GlobalDeleteAtom( atom );
327 return NULL;
330 SERVER_START_REQ( create_class )
332 req->local = local;
333 req->atom = atom;
334 req->style = style;
335 req->instance = hInstance;
336 req->extra = classExtra;
337 req->win_extra = winExtra;
338 req->client_ptr = classPtr;
339 ret = !wine_server_call_err( req );
341 SERVER_END_REQ;
342 GlobalDeleteAtom( atom ); /* the server increased the atom ref count */
343 if (!ret)
345 HeapFree( GetProcessHeap(), 0, classPtr );
346 return NULL;
349 classPtr->style = style;
350 classPtr->local = local;
351 classPtr->cbWndExtra = winExtra;
352 classPtr->cbClsExtra = classExtra;
353 classPtr->hInstance = hInstance;
354 classPtr->atomName = atom;
356 /* Other non-null values must be set by caller */
358 USER_Lock();
359 if (local) list_add_head( &class_list, &classPtr->entry );
360 else list_add_tail( &class_list, &classPtr->entry );
361 return classPtr;
365 /***********************************************************************
366 * register_builtin
368 * Register a builtin control class.
369 * This allows having both ASCII and Unicode winprocs for the same class.
371 static CLASS *register_builtin( const struct builtin_class_descr *descr )
373 ATOM atom;
374 CLASS *classPtr;
376 if (!(atom = GlobalAddAtomA( descr->name ))) return 0;
378 if (!(classPtr = CLASS_RegisterClass( atom, user32_module, FALSE,
379 descr->style, 0, descr->extra ))) return 0;
381 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
382 classPtr->hbrBackground = descr->brush;
383 classPtr->winproc = WINPROC_AllocProc( descr->procA, descr->procW );
384 release_class_ptr( classPtr );
385 return classPtr;
389 /***********************************************************************
390 * CLASS_RegisterBuiltinClasses
392 void CLASS_RegisterBuiltinClasses(void)
394 extern const struct builtin_class_descr BUTTON_builtin_class;
395 extern const struct builtin_class_descr COMBO_builtin_class;
396 extern const struct builtin_class_descr COMBOLBOX_builtin_class;
397 extern const struct builtin_class_descr DIALOG_builtin_class;
398 extern const struct builtin_class_descr DESKTOP_builtin_class;
399 extern const struct builtin_class_descr EDIT_builtin_class;
400 extern const struct builtin_class_descr ICONTITLE_builtin_class;
401 extern const struct builtin_class_descr LISTBOX_builtin_class;
402 extern const struct builtin_class_descr MDICLIENT_builtin_class;
403 extern const struct builtin_class_descr MENU_builtin_class;
404 extern const struct builtin_class_descr SCROLL_builtin_class;
405 extern const struct builtin_class_descr STATIC_builtin_class;
407 register_builtin( &DESKTOP_builtin_class );
408 register_builtin( &BUTTON_builtin_class );
409 register_builtin( &COMBO_builtin_class );
410 register_builtin( &COMBOLBOX_builtin_class );
411 register_builtin( &DIALOG_builtin_class );
412 register_builtin( &EDIT_builtin_class );
413 register_builtin( &ICONTITLE_builtin_class );
414 register_builtin( &LISTBOX_builtin_class );
415 register_builtin( &MDICLIENT_builtin_class );
416 register_builtin( &MENU_builtin_class );
417 register_builtin( &SCROLL_builtin_class );
418 register_builtin( &STATIC_builtin_class );
420 /* the DefWindowProc winprocs are magic too */
421 WINPROC_AllocProc( DefWindowProcA, DefWindowProcW );
425 /***********************************************************************
426 * CLASS_AddWindow
428 * Add a new window using this class, and set the necessary
429 * information inside the window structure.
431 void CLASS_AddWindow( CLASS *class, WND *win, BOOL unicode )
433 win->class = class;
434 win->clsStyle = class->style;
435 win->winproc = class->winproc;
436 if (WINPROC_IsUnicode( win->winproc, unicode )) win->flags |= WIN_ISUNICODE;
440 /***********************************************************************
441 * RegisterClassA (USER32.@)
443 * Register a window class.
445 * RETURNS
446 * >0: Unique identifier
447 * 0: Failure
449 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
451 WNDCLASSEXA wcex;
453 wcex.cbSize = sizeof(wcex);
454 wcex.style = wc->style;
455 wcex.lpfnWndProc = wc->lpfnWndProc;
456 wcex.cbClsExtra = wc->cbClsExtra;
457 wcex.cbWndExtra = wc->cbWndExtra;
458 wcex.hInstance = wc->hInstance;
459 wcex.hIcon = wc->hIcon;
460 wcex.hCursor = wc->hCursor;
461 wcex.hbrBackground = wc->hbrBackground;
462 wcex.lpszMenuName = wc->lpszMenuName;
463 wcex.lpszClassName = wc->lpszClassName;
464 wcex.hIconSm = 0;
465 return RegisterClassExA( &wcex );
469 /***********************************************************************
470 * RegisterClassW (USER32.@)
472 * See RegisterClassA.
474 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
476 WNDCLASSEXW wcex;
478 wcex.cbSize = sizeof(wcex);
479 wcex.style = wc->style;
480 wcex.lpfnWndProc = wc->lpfnWndProc;
481 wcex.cbClsExtra = wc->cbClsExtra;
482 wcex.cbWndExtra = wc->cbWndExtra;
483 wcex.hInstance = wc->hInstance;
484 wcex.hIcon = wc->hIcon;
485 wcex.hCursor = wc->hCursor;
486 wcex.hbrBackground = wc->hbrBackground;
487 wcex.lpszMenuName = wc->lpszMenuName;
488 wcex.lpszClassName = wc->lpszClassName;
489 wcex.hIconSm = 0;
490 return RegisterClassExW( &wcex );
494 /***********************************************************************
495 * RegisterClassExA (USER32.@)
497 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
499 ATOM atom;
500 CLASS *classPtr;
501 HINSTANCE instance;
503 if (wc->hInstance == user32_module)
505 /* we can't register a class for user32 */
506 SetLastError( ERROR_INVALID_PARAMETER );
507 return 0;
509 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
511 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
513 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
514 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
515 return 0;
517 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
518 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
519 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
521 classPtr->hIcon = wc->hIcon;
522 classPtr->hIconSm = wc->hIconSm;
523 classPtr->hCursor = wc->hCursor;
524 classPtr->hbrBackground = wc->hbrBackground;
525 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, NULL );
526 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
527 release_class_ptr( classPtr );
528 return atom;
532 /***********************************************************************
533 * RegisterClassExW (USER32.@)
535 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
537 ATOM atom;
538 CLASS *classPtr;
539 HINSTANCE instance;
541 if (wc->hInstance == user32_module)
543 /* we can't register a class for user32 */
544 SetLastError( ERROR_INVALID_PARAMETER );
545 return 0;
547 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
549 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
551 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
552 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
553 return 0;
555 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
556 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
557 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
559 classPtr->hIcon = wc->hIcon;
560 classPtr->hIconSm = wc->hIconSm;
561 classPtr->hCursor = wc->hCursor;
562 classPtr->hbrBackground = wc->hbrBackground;
563 classPtr->winproc = WINPROC_AllocProc( NULL, wc->lpfnWndProc );
564 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
565 release_class_ptr( classPtr );
566 return atom;
570 /***********************************************************************
571 * UnregisterClassA (USER32.@)
573 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
575 ATOM atom = HIWORD(className) ? GlobalFindAtomA( className ) : LOWORD(className);
576 return UnregisterClassW( (LPCWSTR)MAKEINTATOM(atom), hInstance );
579 /***********************************************************************
580 * UnregisterClassW (USER32.@)
582 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
584 CLASS *classPtr = NULL;
585 ATOM atom = HIWORD(className) ? GlobalFindAtomW( className ) : LOWORD(className);
587 TRACE("%s %p %x\n",debugstr_w(className), hInstance, atom);
589 if (!atom)
591 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
592 return FALSE;
595 SERVER_START_REQ( destroy_class )
597 req->atom = atom;
598 req->instance = hInstance;
599 if (!wine_server_call_err( req )) classPtr = reply->client_ptr;
601 SERVER_END_REQ;
603 if (classPtr) CLASS_FreeClass( classPtr );
604 return (classPtr != NULL);
608 /***********************************************************************
609 * GetClassWord (USER32.@)
611 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
613 CLASS *class;
614 WORD retvalue = 0;
616 if (offset < 0) return GetClassLongA( hwnd, offset );
618 TRACE("%p %x\n",hwnd, offset);
620 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
622 if (class == CLASS_OTHER_PROCESS)
624 SERVER_START_REQ( set_class_info )
626 req->window = hwnd;
627 req->flags = 0;
628 req->extra_offset = offset;
629 req->extra_size = sizeof(retvalue);
630 if (!wine_server_call_err( req ))
631 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
633 SERVER_END_REQ;
634 return retvalue;
637 if (offset <= class->cbClsExtra - sizeof(WORD))
638 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
639 else
640 SetLastError( ERROR_INVALID_INDEX );
641 release_class_ptr( class );
642 return retvalue;
646 /***********************************************************************
647 * CLASS_GetClassLong
649 * Implementation of GetClassLong(Ptr)A/W
651 static ULONG_PTR CLASS_GetClassLong( HWND hwnd, INT offset, UINT size,
652 BOOL unicode )
654 CLASS *class;
655 ULONG_PTR retvalue = 0;
657 TRACE("%p %d\n", hwnd, offset);
659 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
661 if (class == CLASS_OTHER_PROCESS)
663 SERVER_START_REQ( set_class_info )
665 req->window = hwnd;
666 req->flags = 0;
667 req->extra_offset = (offset >= 0) ? offset : -1;
668 req->extra_size = (offset >= 0) ? size : 0;
669 if (!wine_server_call_err( req ))
671 switch(offset)
673 case GCLP_HBRBACKGROUND:
674 case GCLP_HCURSOR:
675 case GCLP_HICON:
676 case GCLP_HICONSM:
677 case GCLP_WNDPROC:
678 case GCLP_MENUNAME:
679 FIXME( "offset %d (%s) not supported on other process window %p\n",
680 offset, SPY_GetClassLongOffsetName(offset), hwnd );
681 SetLastError( ERROR_INVALID_HANDLE );
682 break;
683 case GCL_STYLE:
684 retvalue = reply->old_style;
685 break;
686 case GCL_CBWNDEXTRA:
687 retvalue = reply->old_win_extra;
688 break;
689 case GCL_CBCLSEXTRA:
690 retvalue = reply->old_extra;
691 break;
692 case GCLP_HMODULE:
693 retvalue = (ULONG_PTR)reply->old_instance;
694 break;
695 case GCW_ATOM:
696 retvalue = reply->old_atom;
697 break;
698 default:
699 if (offset >= 0)
701 if (size == sizeof(DWORD))
703 DWORD retdword;
704 memcpy( &retdword, &reply->old_extra_value, sizeof(DWORD) );
705 retvalue = retdword;
707 else
708 memcpy( &retvalue, &reply->old_extra_value,
709 sizeof(ULONG_PTR) );
711 else SetLastError( ERROR_INVALID_INDEX );
712 break;
716 SERVER_END_REQ;
717 return retvalue;
720 if (offset >= 0)
722 if (offset <= class->cbClsExtra - size)
724 if (size == sizeof(DWORD))
726 DWORD retdword;
727 memcpy( &retdword, (char *)(class + 1) + offset, sizeof(DWORD) );
728 retvalue = retdword;
730 else
731 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(ULONG_PTR) );
733 else
734 SetLastError( ERROR_INVALID_INDEX );
735 release_class_ptr( class );
736 return retvalue;
739 switch(offset)
741 case GCLP_HBRBACKGROUND:
742 retvalue = (ULONG_PTR)class->hbrBackground;
743 break;
744 case GCLP_HCURSOR:
745 retvalue = (ULONG_PTR)class->hCursor;
746 break;
747 case GCLP_HICON:
748 retvalue = (ULONG_PTR)class->hIcon;
749 break;
750 case GCLP_HICONSM:
751 retvalue = (ULONG_PTR)class->hIconSm;
752 break;
753 case GCL_STYLE:
754 retvalue = class->style;
755 break;
756 case GCL_CBWNDEXTRA:
757 retvalue = class->cbWndExtra;
758 break;
759 case GCL_CBCLSEXTRA:
760 retvalue = class->cbClsExtra;
761 break;
762 case GCLP_HMODULE:
763 retvalue = (ULONG_PTR)class->hInstance;
764 break;
765 case GCLP_WNDPROC:
766 retvalue = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
767 break;
768 case GCLP_MENUNAME:
769 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
770 if (unicode)
771 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
772 else
773 retvalue = (ULONG_PTR)CLASS_GetMenuNameA( class );
774 break;
775 case GCW_ATOM:
776 retvalue = class->atomName;
777 break;
778 default:
779 SetLastError( ERROR_INVALID_INDEX );
780 break;
782 release_class_ptr( class );
783 return retvalue;
787 /***********************************************************************
788 * GetClassLongW (USER32.@)
790 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
792 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), TRUE );
797 /***********************************************************************
798 * GetClassLongA (USER32.@)
800 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
802 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), FALSE );
806 /***********************************************************************
807 * SetClassWord (USER32.@)
809 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
811 CLASS *class;
812 WORD retval = 0;
814 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
816 TRACE("%p %d %x\n", hwnd, offset, newval);
818 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
820 SERVER_START_REQ( set_class_info )
822 req->window = hwnd;
823 req->flags = SET_CLASS_EXTRA;
824 req->extra_offset = offset;
825 req->extra_size = sizeof(newval);
826 memcpy( &req->extra_value, &newval, sizeof(newval) );
827 if (!wine_server_call_err( req ))
829 void *ptr = (char *)(class + 1) + offset;
830 memcpy( &retval, ptr, sizeof(retval) );
831 memcpy( ptr, &newval, sizeof(newval) );
834 SERVER_END_REQ;
835 release_class_ptr( class );
836 return retval;
840 /***********************************************************************
841 * CLASS_SetClassLong
843 * Implementation of SetClassLong(Ptr)A/W
845 static ULONG_PTR CLASS_SetClassLong( HWND hwnd, INT offset, LONG_PTR newval,
846 UINT size, BOOL unicode )
848 CLASS *class;
849 ULONG_PTR retval = 0;
851 TRACE("%p %d %lx\n", hwnd, offset, newval);
853 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
855 if (offset >= 0)
857 if (set_server_info( hwnd, offset, newval, size ))
859 void *ptr = (char *)(class + 1) + offset;
860 if ( size == sizeof(LONG) )
862 DWORD retdword;
863 LONG newlong = newval;
864 memcpy( &retdword, ptr, sizeof(DWORD) );
865 memcpy( ptr, &newlong, sizeof(LONG) );
866 retval = retdword;
868 else
870 memcpy( &retval, ptr, sizeof(ULONG_PTR) );
871 memcpy( ptr, &newval, sizeof(LONG_PTR) );
875 else switch(offset)
877 case GCLP_MENUNAME:
878 if ( unicode )
879 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
880 else
881 CLASS_SetMenuNameA( class, (LPCSTR)newval );
882 retval = 0; /* Old value is now meaningless anyway */
883 break;
884 case GCLP_WNDPROC:
885 retval = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
886 class->winproc = WINPROC_AllocProc( unicode ? NULL : (WNDPROC)newval,
887 unicode ? (WNDPROC)newval : NULL );
888 break;
889 case GCLP_HBRBACKGROUND:
890 retval = (ULONG_PTR)class->hbrBackground;
891 class->hbrBackground = (HBRUSH)newval;
892 break;
893 case GCLP_HCURSOR:
894 retval = (ULONG_PTR)class->hCursor;
895 class->hCursor = (HCURSOR)newval;
896 break;
897 case GCLP_HICON:
898 retval = (ULONG_PTR)class->hIcon;
899 class->hIcon = (HICON)newval;
900 break;
901 case GCLP_HICONSM:
902 retval = (ULONG_PTR)class->hIconSm;
903 class->hIconSm = (HICON)newval;
904 break;
905 case GCL_STYLE:
906 if (!set_server_info( hwnd, offset, newval, size )) break;
907 retval = class->style;
908 class->style = newval;
909 break;
910 case GCL_CBWNDEXTRA:
911 if (!set_server_info( hwnd, offset, newval, size )) break;
912 retval = class->cbWndExtra;
913 class->cbWndExtra = newval;
914 break;
915 case GCLP_HMODULE:
916 if (!set_server_info( hwnd, offset, newval, size )) break;
917 retval = (ULONG_PTR)class->hInstance;
918 class->hInstance = (HINSTANCE)newval;
919 break;
920 case GCW_ATOM:
921 if (!set_server_info( hwnd, offset, newval, size )) break;
922 retval = class->atomName;
923 class->atomName = newval;
924 break;
925 case GCL_CBCLSEXTRA: /* cannot change this one */
926 SetLastError( ERROR_INVALID_PARAMETER );
927 break;
928 default:
929 SetLastError( ERROR_INVALID_INDEX );
930 break;
932 release_class_ptr( class );
933 return retval;
937 /***********************************************************************
938 * SetClassLongW (USER32.@)
940 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
942 TRACE("%p %d %x\n", hwnd, offset, newval);
944 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), TRUE );
948 /***********************************************************************
949 * SetClassLongA (USER32.@)
951 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
953 TRACE("%p %d %x\n", hwnd, offset, newval);
955 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), FALSE );
959 /***********************************************************************
960 * GetClassNameA (USER32.@)
962 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
964 char tmpbuf[MAX_ATOM_LEN + 1];
965 INT ret;
967 TRACE("%p %p %d\n", hwnd, buffer, count);
969 if (count <= 0) return 0;
971 ret = GlobalGetAtomNameA( GetClassLongW( hwnd, GCW_ATOM ), tmpbuf, MAX_ATOM_LEN + 1 );
972 if (ret)
974 ret = min(count - 1, ret);
975 memcpy(buffer, tmpbuf, ret);
976 buffer[ret] = 0;
978 return ret;
982 /***********************************************************************
983 * GetClassNameW (USER32.@)
985 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
987 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
988 INT ret;
990 TRACE("%p %p %d\n", hwnd, buffer, count);
992 if (count <= 0) return 0;
994 ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), tmpbuf, MAX_ATOM_LEN + 1 );
995 if (ret)
997 ret = min(count - 1, ret);
998 memcpy(buffer, tmpbuf, ret * sizeof(WCHAR));
999 buffer[ret] = 0;
1001 return ret;
1005 /***********************************************************************
1006 * RealGetWindowClassA (USER32.@)
1008 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1010 return GetClassNameA( hwnd, buffer, count );
1014 /***********************************************************************
1015 * RealGetWindowClassW (USER32.@)
1017 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1019 return GetClassNameW( hwnd, buffer, count );
1023 /***********************************************************************
1024 * GetClassInfoA (USER32.@)
1026 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1028 WNDCLASSEXA wcex;
1029 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1031 if (ret)
1033 wc->style = wcex.style;
1034 wc->lpfnWndProc = wcex.lpfnWndProc;
1035 wc->cbClsExtra = wcex.cbClsExtra;
1036 wc->cbWndExtra = wcex.cbWndExtra;
1037 wc->hInstance = wcex.hInstance;
1038 wc->hIcon = wcex.hIcon;
1039 wc->hCursor = wcex.hCursor;
1040 wc->hbrBackground = wcex.hbrBackground;
1041 wc->lpszMenuName = wcex.lpszMenuName;
1042 wc->lpszClassName = wcex.lpszClassName;
1044 return ret;
1048 /***********************************************************************
1049 * GetClassInfoW (USER32.@)
1051 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1053 WNDCLASSEXW wcex;
1054 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1056 if (ret)
1058 wc->style = wcex.style;
1059 wc->lpfnWndProc = wcex.lpfnWndProc;
1060 wc->cbClsExtra = wcex.cbClsExtra;
1061 wc->cbWndExtra = wcex.cbWndExtra;
1062 wc->hInstance = wcex.hInstance;
1063 wc->hIcon = wcex.hIcon;
1064 wc->hCursor = wcex.hCursor;
1065 wc->hbrBackground = wcex.hbrBackground;
1066 wc->lpszMenuName = wcex.lpszMenuName;
1067 wc->lpszClassName = wcex.lpszClassName;
1069 return ret;
1073 /***********************************************************************
1074 * GetClassInfoExA (USER32.@)
1076 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1078 ATOM atom = HIWORD(name) ? GlobalFindAtomA( name ) : LOWORD(name);
1079 CLASS *classPtr;
1081 TRACE("%p %s %x %p\n", hInstance, debugstr_a(name), atom, wc);
1083 if (!hInstance) hInstance = user32_module;
1085 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1087 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1088 return FALSE;
1090 wc->style = classPtr->style;
1091 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, FALSE );
1092 wc->cbClsExtra = classPtr->cbClsExtra;
1093 wc->cbWndExtra = classPtr->cbWndExtra;
1094 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1095 wc->hIcon = (HICON)classPtr->hIcon;
1096 wc->hIconSm = (HICON)classPtr->hIconSm;
1097 wc->hCursor = (HCURSOR)classPtr->hCursor;
1098 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1099 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1100 wc->lpszClassName = name;
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 = HIWORD(name) ? GlobalFindAtomW( name ) : LOWORD(name);
1114 CLASS *classPtr;
1116 TRACE("%p %s %x %p\n", hInstance, debugstr_w(name), atom, wc);
1118 if (!hInstance) hInstance = user32_module;
1120 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, 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 = (HICON)classPtr->hIcon;
1131 wc->hIconSm = (HICON)classPtr->hIconSm;
1132 wc->hCursor = (HCURSOR)classPtr->hCursor;
1133 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1134 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1135 wc->lpszClassName = name;
1136 release_class_ptr( classPtr );
1138 /* We must return the atom of the class here instead of just TRUE. */
1139 return atom;
1143 #if 0 /* toolhelp is in kernel, so this cannot work */
1145 /***********************************************************************
1146 * ClassFirst (TOOLHELP.69)
1148 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1150 TRACE("%p\n",pClassEntry);
1151 pClassEntry->wNext = 1;
1152 return ClassNext16( pClassEntry );
1156 /***********************************************************************
1157 * ClassNext (TOOLHELP.70)
1159 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1161 int i;
1162 CLASS *class = firstClass;
1164 TRACE("%p\n",pClassEntry);
1166 if (!pClassEntry->wNext) return FALSE;
1167 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1168 if (!class)
1170 pClassEntry->wNext = 0;
1171 return FALSE;
1173 pClassEntry->hInst = class->hInstance;
1174 pClassEntry->wNext++;
1175 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1176 sizeof(pClassEntry->szClassName) );
1177 return TRUE;
1179 #endif
1181 /* 64bit versions */
1183 #ifdef GetClassLongPtrA
1184 #undef GetClassLongPtrA
1185 #endif
1187 #ifdef GetClassLongPtrW
1188 #undef GetClassLongPtrW
1189 #endif
1191 #ifdef SetClassLongPtrA
1192 #undef SetClassLongPtrA
1193 #endif
1195 #ifdef SetClassLongPtrW
1196 #undef SetClassLongPtrW
1197 #endif
1199 /***********************************************************************
1200 * GetClassLongPtrA (USER32.@)
1202 ULONG_PTR WINAPI GetClassLongPtrA( HWND hwnd, INT offset )
1204 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), FALSE );
1207 /***********************************************************************
1208 * GetClassLongPtrW (USER32.@)
1210 ULONG_PTR WINAPI GetClassLongPtrW( HWND hwnd, INT offset )
1212 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), TRUE );
1215 /***********************************************************************
1216 * SetClassLongPtrW (USER32.@)
1218 ULONG_PTR WINAPI SetClassLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
1220 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), TRUE );
1223 /***********************************************************************
1224 * SetClassLongPtrA (USER32.@)
1226 ULONG_PTR WINAPI SetClassLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
1228 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), FALSE );