Return a true boolean value (0 or 1).
[wine/wine64.git] / windows / class.c
blobb2cfe214e12862c5b1002c170c44c3c0aee23764
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "dce.h"
40 #include "winproc.h"
41 #include "wine/server.h"
42 #include "wine/list.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(class);
47 typedef struct tagCLASS
49 struct list entry; /* Entry in class list */
50 UINT style; /* Class style */
51 BOOL local; /* Local class? */
52 WNDPROC winprocA; /* Window procedure (ASCII) */
53 WNDPROC winprocW; /* Window procedure (Unicode) */
54 INT cbClsExtra; /* Class extra bytes */
55 INT cbWndExtra; /* Window extra bytes */
56 LPWSTR menuName; /* Default menu name (Unicode followed by ASCII) */
57 SEGPTR segMenuName; /* Default menu name as SEGPTR */
58 struct tagDCE *dce; /* Class DCE (if CS_CLASSDC) */
59 HINSTANCE hInstance; /* Module that created the task */
60 HICON hIcon; /* Default icon */
61 HICON hIconSm; /* Default small icon */
62 HCURSOR hCursor; /* Default cursor */
63 HBRUSH hbrBackground; /* Default background */
64 ATOM atomName; /* Name of the class */
65 } CLASS;
67 static struct list class_list = LIST_INIT( class_list );
68 static CLASS *desktop_class;
70 #define CLASS_OTHER_PROCESS ((CLASS *)1)
72 /***********************************************************************
73 * get_class_ptr
75 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
77 WND *ptr = WIN_GetPtr( hwnd );
79 if (ptr)
81 if (ptr != WND_OTHER_PROCESS) return ptr->class;
82 if (write_access && IsWindow( hwnd )) /* check other processes */
84 /* modifying classes in other processes is not allowed */
85 SetLastError( ERROR_ACCESS_DENIED );
86 return NULL;
88 return CLASS_OTHER_PROCESS;
90 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
91 return NULL;
95 /***********************************************************************
96 * release_class_ptr
98 inline static void release_class_ptr( CLASS *ptr )
100 USER_Unlock();
104 /***********************************************************************
105 * set_server_info
107 * Set class info with the wine server.
109 static BOOL set_server_info( HWND hwnd, INT offset, LONG newval )
111 BOOL ret;
113 SERVER_START_REQ( set_class_info )
115 req->window = hwnd;
116 req->extra_offset = -1;
117 switch(offset)
119 case GCW_ATOM:
120 req->flags = SET_CLASS_ATOM;
121 req->atom = newval;
122 case GCL_STYLE:
123 req->flags = SET_CLASS_STYLE;
124 req->style = newval;
125 break;
126 case GCL_CBWNDEXTRA:
127 req->flags = SET_CLASS_WINEXTRA;
128 req->win_extra = newval;
129 break;
130 case GCL_HMODULE:
131 req->flags = SET_CLASS_INSTANCE;
132 req->instance = (void *)newval;
133 break;
134 default:
135 assert( offset >= 0 );
136 req->flags = SET_CLASS_EXTRA;
137 req->extra_offset = offset;
138 req->extra_size = sizeof(newval);
139 memcpy( &req->extra_value, &newval, sizeof(newval) );
140 break;
142 ret = !wine_server_call_err( req );
144 SERVER_END_REQ;
145 return ret;
149 /***********************************************************************
150 * CLASS_GetProc
152 * Get the class winproc for a given proc type
154 static WNDPROC16 CLASS_GetProc( CLASS *classPtr, WINDOWPROCTYPE type )
156 WNDPROC proc = classPtr->winprocA;
158 if (classPtr->winprocW)
160 /* if we have a Unicode proc, use it if we have no ASCII proc
161 * or if we have both and Unicode was requested
163 if (!proc || type == WIN_PROC_32W) proc = classPtr->winprocW;
165 return WINPROC_GetProc( proc, type );
169 /***********************************************************************
170 * CLASS_SetProc
172 * Set the class winproc for a given proc type.
173 * Returns the previous window proc.
175 static WNDPROC16 CLASS_SetProc( CLASS *classPtr, WNDPROC newproc, WINDOWPROCTYPE type )
177 WNDPROC *proc = &classPtr->winprocA;
178 WNDPROC16 ret;
180 if (classPtr->winprocW)
182 /* if we have a Unicode proc, use it if we have no ASCII proc
183 * or if we have both and Unicode was requested
185 if (!*proc || type == WIN_PROC_32W) proc = &classPtr->winprocW;
187 ret = WINPROC_GetProc( *proc, type );
188 *proc = WINPROC_AllocProc( newproc, type );
189 /* now clear the one that we didn't set */
190 if (classPtr->winprocA && classPtr->winprocW)
192 if (proc == &classPtr->winprocA)
193 classPtr->winprocW = 0;
194 else
195 classPtr->winprocA = 0;
197 return ret;
201 /***********************************************************************
202 * CLASS_GetMenuNameA
204 * Get the menu name as a ASCII string.
206 inline static LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
208 if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
209 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
213 /***********************************************************************
214 * CLASS_GetMenuName16
216 * Get the menu name as a SEGPTR.
218 inline static SEGPTR CLASS_GetMenuName16( CLASS *classPtr )
220 if (!HIWORD(classPtr->menuName)) return (SEGPTR)classPtr->menuName;
221 if (!classPtr->segMenuName)
222 classPtr->segMenuName = MapLS( CLASS_GetMenuNameA(classPtr) );
223 return classPtr->segMenuName;
227 /***********************************************************************
228 * CLASS_GetMenuNameW
230 * Get the menu name as a Unicode string.
232 inline static LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
234 return classPtr->menuName;
238 /***********************************************************************
239 * CLASS_SetMenuNameA
241 * Set the menu name in a class structure by copying the string.
243 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
245 UnMapLS( classPtr->segMenuName );
246 classPtr->segMenuName = 0;
247 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
248 if (HIWORD(name))
250 DWORD lenA = strlen(name) + 1;
251 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
252 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
253 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
254 memcpy( classPtr->menuName + lenW, name, lenA );
256 else classPtr->menuName = (LPWSTR)name;
260 /***********************************************************************
261 * CLASS_SetMenuNameW
263 * Set the menu name in a class structure by copying the string.
265 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
267 UnMapLS( classPtr->segMenuName );
268 classPtr->segMenuName = 0;
269 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
270 if (HIWORD(name))
272 DWORD lenW = strlenW(name) + 1;
273 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
274 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
275 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
276 WideCharToMultiByte( CP_ACP, 0, name, lenW,
277 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
279 else classPtr->menuName = (LPWSTR)name;
283 /***********************************************************************
284 * CLASS_FreeClass
286 * Free a class structure.
288 static void CLASS_FreeClass( CLASS *classPtr )
290 TRACE("%p\n", classPtr);
292 USER_Lock();
294 list_remove( &classPtr->entry );
295 if (classPtr->dce) DCE_FreeDCE( classPtr->dce );
296 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
297 DeleteObject( classPtr->hbrBackground );
298 UnMapLS( classPtr->segMenuName );
299 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
300 HeapFree( GetProcessHeap(), 0, classPtr );
301 USER_Unlock();
305 /***********************************************************************
306 * CLASS_FreeModuleClasses
308 void CLASS_FreeModuleClasses( HMODULE16 hModule )
310 struct list *ptr, *next;
312 TRACE("0x%08x\n", hModule);
314 USER_Lock();
315 for (ptr = list_head( &class_list ); ptr; ptr = next)
317 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
318 next = list_next( &class_list, ptr );
319 if (class->hInstance == HINSTANCE_32(hModule))
321 BOOL ret;
323 SERVER_START_REQ( destroy_class )
325 req->atom = class->atomName;
326 req->instance = class->hInstance;
327 ret = !wine_server_call_err( req );
329 SERVER_END_REQ;
330 if (ret) CLASS_FreeClass( class );
333 USER_Unlock();
337 /***********************************************************************
338 * CLASS_FindClassByAtom
340 * Return a pointer to the class.
341 * hinstance has been normalized by the caller.
343 static CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE hinstance )
345 struct list *ptr;
347 USER_Lock();
349 LIST_FOR_EACH( ptr, &class_list )
351 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
352 if (class->atomName != atom) continue;
353 if (!hinstance || !class->local || class->hInstance == hinstance)
355 TRACE("0x%04x %p -> %p\n", atom, hinstance, class);
356 return class;
359 USER_Unlock();
360 TRACE("0x%04x %p -> not found\n", atom, hinstance);
361 return NULL;
365 /***********************************************************************
366 * CLASS_RegisterClass
368 * The real RegisterClass() functionality.
369 * The atom is deleted no matter what.
371 static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE hInstance, BOOL local,
372 DWORD style, INT classExtra, INT winExtra )
374 CLASS *classPtr;
375 BOOL ret;
377 TRACE("atom=0x%x hinst=%p style=0x%lx clExtr=0x%x winExtr=0x%x\n",
378 atom, hInstance, style, classExtra, winExtra );
380 /* Fix the extra bytes value */
382 if (classExtra < 0) classExtra = 0;
383 else if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
384 WARN("Class extra bytes %d is > 40\n", classExtra);
385 if (winExtra < 0) winExtra = 0;
386 else if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
387 WARN("Win extra bytes %d is > 40\n", winExtra );
389 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
390 if (!classPtr)
392 GlobalDeleteAtom( atom );
393 return NULL;
396 SERVER_START_REQ( create_class )
398 req->local = local;
399 req->atom = atom;
400 req->style = style;
401 req->instance = hInstance;
402 req->extra = classExtra;
403 req->win_extra = winExtra;
404 req->client_ptr = classPtr;
405 ret = !wine_server_call_err( req );
407 SERVER_END_REQ;
408 GlobalDeleteAtom( atom ); /* the server increased the atom ref count */
409 if (!ret)
411 HeapFree( GetProcessHeap(), 0, classPtr );
412 return NULL;
415 classPtr->style = style;
416 classPtr->local = local;
417 classPtr->cbWndExtra = winExtra;
418 classPtr->cbClsExtra = classExtra;
419 classPtr->hInstance = hInstance;
420 classPtr->atomName = atom;
421 classPtr->dce = (style & CS_CLASSDC) ? DCE_AllocDCE( 0, DCE_CLASS_DC ) : NULL;
423 /* Other non-null values must be set by caller */
425 USER_Lock();
426 if (local) list_add_head( &class_list, &classPtr->entry );
427 else list_add_tail( &class_list, &classPtr->entry );
428 return classPtr;
432 /***********************************************************************
433 * register_builtin
435 * Register a builtin control class.
436 * This allows having both ASCII and Unicode winprocs for the same class.
438 static CLASS *register_builtin( const struct builtin_class_descr *descr )
440 ATOM atom;
441 CLASS *classPtr;
443 if (!(atom = GlobalAddAtomA( descr->name ))) return 0;
445 if (!(classPtr = CLASS_RegisterClass( atom, user32_module, FALSE,
446 descr->style, 0, descr->extra ))) return 0;
448 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
449 classPtr->hbrBackground = descr->brush;
451 if (descr->procA) classPtr->winprocA = WINPROC_AllocProc( descr->procA, WIN_PROC_32A );
452 if (descr->procW) classPtr->winprocW = WINPROC_AllocProc( descr->procW, WIN_PROC_32W );
453 release_class_ptr( classPtr );
454 return classPtr;
458 /***********************************************************************
459 * CLASS_RegisterBuiltinClasses
461 void CLASS_RegisterBuiltinClasses(void)
463 extern const struct builtin_class_descr BUTTON_builtin_class;
464 extern const struct builtin_class_descr COMBO_builtin_class;
465 extern const struct builtin_class_descr COMBOLBOX_builtin_class;
466 extern const struct builtin_class_descr DIALOG_builtin_class;
467 extern const struct builtin_class_descr DESKTOP_builtin_class;
468 extern const struct builtin_class_descr EDIT_builtin_class;
469 extern const struct builtin_class_descr ICONTITLE_builtin_class;
470 extern const struct builtin_class_descr LISTBOX_builtin_class;
471 extern const struct builtin_class_descr MDICLIENT_builtin_class;
472 extern const struct builtin_class_descr MENU_builtin_class;
473 extern const struct builtin_class_descr SCROLL_builtin_class;
474 extern const struct builtin_class_descr STATIC_builtin_class;
476 desktop_class = register_builtin( &DESKTOP_builtin_class );
477 register_builtin( &BUTTON_builtin_class );
478 register_builtin( &COMBO_builtin_class );
479 register_builtin( &COMBOLBOX_builtin_class );
480 register_builtin( &DIALOG_builtin_class );
481 register_builtin( &EDIT_builtin_class );
482 register_builtin( &ICONTITLE_builtin_class );
483 register_builtin( &LISTBOX_builtin_class );
484 register_builtin( &MDICLIENT_builtin_class );
485 register_builtin( &MENU_builtin_class );
486 register_builtin( &SCROLL_builtin_class );
487 register_builtin( &STATIC_builtin_class );
491 /***********************************************************************
492 * CLASS_AddWindow
494 * Add a new window using this class, and set the necessary
495 * information inside the window structure.
497 void CLASS_AddWindow( CLASS *class, WND *win, WINDOWPROCTYPE type )
499 if (!class) class = desktop_class;
501 if (type == WIN_PROC_32W)
503 if (!(win->winproc = class->winprocW)) win->winproc = class->winprocA;
505 else
507 if (!(win->winproc = class->winprocA)) win->winproc = class->winprocW;
509 win->class = class;
510 win->clsStyle = class->style;
511 win->dce = class->dce;
515 /***********************************************************************
516 * RegisterClassA (USER32.@)
517 * RETURNS
518 * >0: Unique identifier
519 * 0: Failure
521 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
523 WNDCLASSEXA wcex;
525 wcex.cbSize = sizeof(wcex);
526 wcex.style = wc->style;
527 wcex.lpfnWndProc = wc->lpfnWndProc;
528 wcex.cbClsExtra = wc->cbClsExtra;
529 wcex.cbWndExtra = wc->cbWndExtra;
530 wcex.hInstance = wc->hInstance;
531 wcex.hIcon = wc->hIcon;
532 wcex.hCursor = wc->hCursor;
533 wcex.hbrBackground = wc->hbrBackground;
534 wcex.lpszMenuName = wc->lpszMenuName;
535 wcex.lpszClassName = wc->lpszClassName;
536 wcex.hIconSm = 0;
537 return RegisterClassExA( &wcex );
541 /***********************************************************************
542 * RegisterClassW (USER32.@)
544 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
546 WNDCLASSEXW wcex;
548 wcex.cbSize = sizeof(wcex);
549 wcex.style = wc->style;
550 wcex.lpfnWndProc = wc->lpfnWndProc;
551 wcex.cbClsExtra = wc->cbClsExtra;
552 wcex.cbWndExtra = wc->cbWndExtra;
553 wcex.hInstance = wc->hInstance;
554 wcex.hIcon = wc->hIcon;
555 wcex.hCursor = wc->hCursor;
556 wcex.hbrBackground = wc->hbrBackground;
557 wcex.lpszMenuName = wc->lpszMenuName;
558 wcex.lpszClassName = wc->lpszClassName;
559 wcex.hIconSm = 0;
560 return RegisterClassExW( &wcex );
564 /***********************************************************************
565 * RegisterClassExA (USER32.@)
567 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
569 ATOM atom;
570 CLASS *classPtr;
571 HINSTANCE instance;
573 if (wc->hInstance == user32_module)
575 /* we can't register a class for user32 */
576 SetLastError( ERROR_INVALID_PARAMETER );
577 return 0;
579 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
581 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
583 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
584 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
585 return 0;
587 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
588 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
589 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
591 classPtr->hIcon = wc->hIcon;
592 classPtr->hIconSm = wc->hIconSm;
593 classPtr->hCursor = wc->hCursor;
594 classPtr->hbrBackground = wc->hbrBackground;
595 classPtr->winprocA = WINPROC_AllocProc( wc->lpfnWndProc, WIN_PROC_32A );
596 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
597 release_class_ptr( classPtr );
598 return atom;
602 /***********************************************************************
603 * RegisterClassExW (USER32.@)
605 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
607 ATOM atom;
608 CLASS *classPtr;
609 HINSTANCE instance;
611 if (wc->hInstance == user32_module)
613 /* we can't register a class for user32 */
614 SetLastError( ERROR_INVALID_PARAMETER );
615 return 0;
617 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
619 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
621 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
622 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
623 return 0;
625 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
626 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
627 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
629 classPtr->hIcon = wc->hIcon;
630 classPtr->hIconSm = wc->hIconSm;
631 classPtr->hCursor = wc->hCursor;
632 classPtr->hbrBackground = wc->hbrBackground;
633 classPtr->winprocW = WINPROC_AllocProc( wc->lpfnWndProc, WIN_PROC_32W );
634 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
635 release_class_ptr( classPtr );
636 return atom;
640 /***********************************************************************
641 * UnregisterClassA (USER32.@)
643 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
645 ATOM atom = HIWORD(className) ? GlobalFindAtomA( className ) : LOWORD(className);
646 return UnregisterClassW( MAKEINTATOMW(atom), hInstance );
649 /***********************************************************************
650 * UnregisterClassW (USER32.@)
652 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
654 CLASS *classPtr = NULL;
655 ATOM atom = HIWORD(className) ? GlobalFindAtomW( className ) : LOWORD(className);
657 TRACE("%s %p %x\n",debugstr_w(className), hInstance, atom);
659 if (!atom)
661 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
662 return FALSE;
665 SERVER_START_REQ( destroy_class )
667 req->atom = atom;
668 req->instance = hInstance;
669 if (!wine_server_call_err( req )) classPtr = reply->client_ptr;
671 SERVER_END_REQ;
673 if (classPtr) CLASS_FreeClass( classPtr );
674 return (classPtr != NULL);
678 /***********************************************************************
679 * GetClassWord (USER32.@)
681 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
683 CLASS *class;
684 WORD retvalue = 0;
686 if (offset < 0) return GetClassLongA( hwnd, offset );
688 TRACE("%p %x\n",hwnd, offset);
690 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
692 if (class == CLASS_OTHER_PROCESS)
694 SERVER_START_REQ( set_class_info )
696 req->window = hwnd;
697 req->flags = 0;
698 req->extra_offset = offset;
699 req->extra_size = sizeof(retvalue);
700 if (!wine_server_call_err( req ))
701 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
703 SERVER_END_REQ;
704 return retvalue;
707 if (offset <= class->cbClsExtra - sizeof(WORD))
708 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
709 else
710 SetLastError( ERROR_INVALID_INDEX );
711 release_class_ptr( class );
712 return retvalue;
716 /***********************************************************************
717 * GetClassLong (USER.131)
719 LONG WINAPI GetClassLong16( HWND16 hwnd16, INT16 offset )
721 CLASS *class;
722 LONG ret;
723 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
725 TRACE("%p %d\n",hwnd, offset);
727 switch( offset )
729 case GCL_WNDPROC:
730 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
731 if (class == CLASS_OTHER_PROCESS) break;
732 ret = (LONG)CLASS_GetProc( class, WIN_PROC_16 );
733 release_class_ptr( class );
734 return ret;
735 case GCL_MENUNAME:
736 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
737 if (class == CLASS_OTHER_PROCESS) break;
738 ret = (LONG)CLASS_GetMenuName16( class );
739 release_class_ptr( class );
740 return ret;
741 default:
742 return GetClassLongA( hwnd, offset );
744 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
745 SetLastError( ERROR_INVALID_HANDLE );
746 return 0;
750 /***********************************************************************
751 * GetClassLongW (USER32.@)
753 LONG WINAPI GetClassLongW( HWND hwnd, INT offset )
755 CLASS *class;
756 LONG retvalue = 0;
758 TRACE("%p %d\n", hwnd, offset);
760 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
762 if (class == CLASS_OTHER_PROCESS)
764 SERVER_START_REQ( set_class_info )
766 req->window = hwnd;
767 req->flags = 0;
768 req->extra_offset = (offset >= 0) ? offset : -1;
769 req->extra_size = (offset >= 0) ? sizeof(retvalue) : 0;
770 if (!wine_server_call_err( req ))
772 switch(offset)
774 case GCL_HBRBACKGROUND:
775 case GCL_HCURSOR:
776 case GCL_HICON:
777 case GCL_HICONSM:
778 case GCL_WNDPROC:
779 case GCL_MENUNAME:
780 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
781 SetLastError( ERROR_INVALID_HANDLE );
782 break;
783 case GCL_STYLE:
784 retvalue = reply->old_style;
785 break;
786 case GCL_CBWNDEXTRA:
787 retvalue = reply->old_win_extra;
788 break;
789 case GCL_CBCLSEXTRA:
790 retvalue = reply->old_extra;
791 break;
792 case GCL_HMODULE:
793 retvalue = (LONG)reply->old_instance;
794 break;
795 case GCW_ATOM:
796 retvalue = reply->old_atom;
797 break;
798 default:
799 if (offset >= 0) memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
800 else SetLastError( ERROR_INVALID_INDEX );
801 break;
805 SERVER_END_REQ;
806 return retvalue;
809 if (offset >= 0)
811 if (offset <= class->cbClsExtra - sizeof(LONG))
812 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
813 else
814 SetLastError( ERROR_INVALID_INDEX );
815 release_class_ptr( class );
816 return retvalue;
819 switch(offset)
821 case GCL_HBRBACKGROUND:
822 retvalue = (LONG)class->hbrBackground;
823 break;
824 case GCL_HCURSOR:
825 retvalue = (LONG)class->hCursor;
826 break;
827 case GCL_HICON:
828 retvalue = (LONG)class->hIcon;
829 break;
830 case GCL_HICONSM:
831 retvalue = (LONG)class->hIconSm;
832 break;
833 case GCL_STYLE:
834 retvalue = (LONG)class->style;
835 break;
836 case GCL_CBWNDEXTRA:
837 retvalue = (LONG)class->cbWndExtra;
838 break;
839 case GCL_CBCLSEXTRA:
840 retvalue = (LONG)class->cbClsExtra;
841 break;
842 case GCL_HMODULE:
843 retvalue = (LONG)class->hInstance;
844 break;
845 case GCL_WNDPROC:
846 retvalue = (LONG)CLASS_GetProc( class, WIN_PROC_32W );
847 break;
848 case GCL_MENUNAME:
849 retvalue = (LONG)CLASS_GetMenuNameW( class );
850 break;
851 case GCW_ATOM:
852 retvalue = (DWORD)class->atomName;
853 break;
854 default:
855 SetLastError( ERROR_INVALID_INDEX );
856 break;
858 release_class_ptr( class );
859 return retvalue;
863 /***********************************************************************
864 * GetClassLongA (USER32.@)
866 LONG WINAPI GetClassLongA( HWND hwnd, INT offset )
868 CLASS *class;
869 LONG retvalue;
871 if (offset != GCL_WNDPROC && offset != GCL_MENUNAME)
872 return GetClassLongW( hwnd, offset );
874 TRACE("%p %d\n", hwnd, offset);
876 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
878 if (class == CLASS_OTHER_PROCESS)
880 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
881 SetLastError( ERROR_INVALID_HANDLE );
882 return 0;
885 if (offset == GCL_WNDPROC)
886 retvalue = (LONG)CLASS_GetProc( class, WIN_PROC_32A );
887 else /* GCL_MENUNAME */
888 retvalue = (LONG)CLASS_GetMenuNameA( class );
890 release_class_ptr( class );
891 return retvalue;
895 /***********************************************************************
896 * SetClassWord (USER32.@)
898 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
900 CLASS *class;
901 WORD retval = 0;
903 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
905 TRACE("%p %d %x\n", hwnd, offset, newval);
907 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
909 SERVER_START_REQ( set_class_info )
911 req->window = hwnd;
912 req->flags = SET_CLASS_EXTRA;
913 req->extra_offset = offset;
914 req->extra_size = sizeof(newval);
915 memcpy( &req->extra_value, &newval, sizeof(newval) );
916 if (!wine_server_call_err( req ))
918 void *ptr = (char *)(class + 1) + offset;
919 memcpy( &retval, ptr, sizeof(retval) );
920 memcpy( ptr, &newval, sizeof(newval) );
923 SERVER_END_REQ;
924 release_class_ptr( class );
925 return retval;
929 /***********************************************************************
930 * SetClassLong (USER.132)
932 LONG WINAPI SetClassLong16( HWND16 hwnd16, INT16 offset, LONG newval )
934 CLASS *class;
935 LONG retval;
936 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
938 TRACE("%p %d %lx\n", hwnd, offset, newval);
940 switch(offset)
942 case GCL_WNDPROC:
943 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
944 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_16 );
945 release_class_ptr( class );
946 return retval;
947 case GCL_MENUNAME:
948 newval = (LONG)MapSL( newval );
949 /* fall through */
950 default:
951 return SetClassLongA( hwnd, offset, newval );
956 /***********************************************************************
957 * SetClassLongW (USER32.@)
959 LONG WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
961 CLASS *class;
962 LONG retval = 0;
964 TRACE("%p %d %lx\n", hwnd, offset, newval);
966 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
968 if (offset >= 0)
970 if (set_server_info( hwnd, offset, newval ))
972 void *ptr = (char *)(class + 1) + offset;
973 memcpy( &retval, ptr, sizeof(retval) );
974 memcpy( ptr, &newval, sizeof(newval) );
977 else switch(offset)
979 case GCL_MENUNAME:
980 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
981 retval = 0; /* Old value is now meaningless anyway */
982 break;
983 case GCL_WNDPROC:
984 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32W );
985 break;
986 case GCL_HBRBACKGROUND:
987 retval = (LONG)class->hbrBackground;
988 class->hbrBackground = (HBRUSH)newval;
989 break;
990 case GCL_HCURSOR:
991 retval = (LONG)class->hCursor;
992 class->hCursor = (HCURSOR)newval;
993 break;
994 case GCL_HICON:
995 retval = (LONG)class->hIcon;
996 class->hIcon = (HICON)newval;
997 break;
998 case GCL_HICONSM:
999 retval = (LONG)class->hIconSm;
1000 class->hIconSm = (HICON)newval;
1001 break;
1002 case GCL_STYLE:
1003 if (!set_server_info( hwnd, offset, newval )) break;
1004 retval = (LONG)class->style;
1005 class->style = newval;
1006 break;
1007 case GCL_CBWNDEXTRA:
1008 if (!set_server_info( hwnd, offset, newval )) break;
1009 retval = (LONG)class->cbWndExtra;
1010 class->cbWndExtra = newval;
1011 break;
1012 case GCL_HMODULE:
1013 if (!set_server_info( hwnd, offset, newval )) break;
1014 retval = (LONG)class->hInstance;
1015 class->hInstance = (HINSTANCE)newval;
1016 break;
1017 case GCW_ATOM:
1018 if (!set_server_info( hwnd, offset, newval )) break;
1019 retval = (DWORD)class->atomName;
1020 class->atomName = newval;
1021 break;
1022 case GCL_CBCLSEXTRA: /* cannot change this one */
1023 SetLastError( ERROR_INVALID_PARAMETER );
1024 break;
1025 default:
1026 SetLastError( ERROR_INVALID_INDEX );
1027 break;
1029 release_class_ptr( class );
1030 return retval;
1034 /***********************************************************************
1035 * SetClassLongA (USER32.@)
1037 LONG WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
1039 CLASS *class;
1040 LONG retval;
1042 if (offset != GCL_WNDPROC && offset != GCL_MENUNAME)
1043 return SetClassLongW( hwnd, offset, newval );
1045 TRACE("%p %d %lx\n", hwnd, offset, newval);
1047 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
1049 if (offset == GCL_WNDPROC)
1050 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32A );
1051 else /* GCL_MENUNAME */
1053 CLASS_SetMenuNameA( class, (LPCSTR)newval );
1054 retval = 0; /* Old value is now meaningless anyway */
1056 release_class_ptr( class );
1057 return retval;
1061 /***********************************************************************
1062 * GetClassNameA (USER32.@)
1064 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
1066 INT ret = GlobalGetAtomNameA( GetClassLongA( hwnd, GCW_ATOM ), buffer, count );
1068 TRACE("%p %s %x\n",hwnd, debugstr_a(buffer), count);
1069 return ret;
1073 /***********************************************************************
1074 * GetClassNameW (USER32.@)
1076 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
1078 INT ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), buffer, count );
1080 TRACE("%p %s %x\n",hwnd, debugstr_w(buffer), count);
1081 return ret;
1085 /***********************************************************************
1086 * RealGetWindowClassA (USER32.@)
1088 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1090 return GetClassNameA( hwnd, buffer, count );
1094 /***********************************************************************
1095 * RealGetWindowClassW (USER32.@)
1097 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1099 return GetClassNameW( hwnd, buffer, count );
1103 /***********************************************************************
1104 * GetClassInfoA (USER32.@)
1106 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1108 WNDCLASSEXA wcex;
1109 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1111 if (ret)
1113 wc->style = wcex.style;
1114 wc->lpfnWndProc = wcex.lpfnWndProc;
1115 wc->cbClsExtra = wcex.cbClsExtra;
1116 wc->cbWndExtra = wcex.cbWndExtra;
1117 wc->hInstance = wcex.hInstance;
1118 wc->hIcon = wcex.hIcon;
1119 wc->hCursor = wcex.hCursor;
1120 wc->hbrBackground = wcex.hbrBackground;
1121 wc->lpszMenuName = wcex.lpszMenuName;
1122 wc->lpszClassName = wcex.lpszClassName;
1124 return ret;
1128 /***********************************************************************
1129 * GetClassInfoW (USER32.@)
1131 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1133 WNDCLASSEXW wcex;
1134 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1136 if (ret)
1138 wc->style = wcex.style;
1139 wc->lpfnWndProc = wcex.lpfnWndProc;
1140 wc->cbClsExtra = wcex.cbClsExtra;
1141 wc->cbWndExtra = wcex.cbWndExtra;
1142 wc->hInstance = wcex.hInstance;
1143 wc->hIcon = wcex.hIcon;
1144 wc->hCursor = wcex.hCursor;
1145 wc->hbrBackground = wcex.hbrBackground;
1146 wc->lpszMenuName = wcex.lpszMenuName;
1147 wc->lpszClassName = wcex.lpszClassName;
1149 return ret;
1153 /***********************************************************************
1154 * GetClassInfoExA (USER32.@)
1156 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1158 ATOM atom = HIWORD(name) ? GlobalFindAtomA( name ) : LOWORD(name);
1159 CLASS *classPtr;
1161 TRACE("%p %s %x %p\n", hInstance, debugstr_a(name), atom, wc);
1163 if (!hInstance) hInstance = user32_module;
1165 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1167 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1168 return FALSE;
1170 wc->style = classPtr->style;
1171 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32A );
1172 wc->cbClsExtra = classPtr->cbClsExtra;
1173 wc->cbWndExtra = classPtr->cbWndExtra;
1174 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1175 wc->hIcon = (HICON)classPtr->hIcon;
1176 wc->hIconSm = (HICON)classPtr->hIconSm;
1177 wc->hCursor = (HCURSOR)classPtr->hCursor;
1178 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1179 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1180 wc->lpszClassName = name;
1181 release_class_ptr( classPtr );
1183 /* We must return the atom of the class here instead of just TRUE. */
1184 return atom;
1188 /***********************************************************************
1189 * GetClassInfoExW (USER32.@)
1191 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1193 ATOM atom = HIWORD(name) ? GlobalFindAtomW( name ) : LOWORD(name);
1194 CLASS *classPtr;
1196 TRACE("%p %s %x %p\n", hInstance, debugstr_w(name), atom, wc);
1198 if (!hInstance) hInstance = user32_module;
1200 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1202 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1203 return FALSE;
1205 wc->style = classPtr->style;
1206 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32W );
1207 wc->cbClsExtra = classPtr->cbClsExtra;
1208 wc->cbWndExtra = classPtr->cbWndExtra;
1209 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1210 wc->hIcon = (HICON)classPtr->hIcon;
1211 wc->hIconSm = (HICON)classPtr->hIconSm;
1212 wc->hCursor = (HCURSOR)classPtr->hCursor;
1213 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1214 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1215 wc->lpszClassName = name;
1216 release_class_ptr( classPtr );
1218 /* We must return the atom of the class here instead of just TRUE. */
1219 return atom;
1223 #if 0 /* toolhelp is in kernel, so this cannot work */
1225 /***********************************************************************
1226 * ClassFirst (TOOLHELP.69)
1228 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1230 TRACE("%p\n",pClassEntry);
1231 pClassEntry->wNext = 1;
1232 return ClassNext16( pClassEntry );
1236 /***********************************************************************
1237 * ClassNext (TOOLHELP.70)
1239 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1241 int i;
1242 CLASS *class = firstClass;
1244 TRACE("%p\n",pClassEntry);
1246 if (!pClassEntry->wNext) return FALSE;
1247 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1248 if (!class)
1250 pClassEntry->wNext = 0;
1251 return FALSE;
1253 pClassEntry->hInst = class->hInstance;
1254 pClassEntry->wNext++;
1255 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1256 sizeof(pClassEntry->szClassName) );
1257 return TRUE;
1259 #endif