2 * Window classes functions
4 * Copyright 1993, 1996 Alexandre Julliard
5 * 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
21 * FIXME: In win32 all classes are local. They are registered at
22 * program start. Processes CANNOT share classes. (Source: some
23 * win31->NT migration book)
25 * FIXME: There seems to be a general problem with hInstance in WINE
26 * classes are getting registered with wrong hInstance.
30 #include "wine/port.h"
36 #include "wine/winbase16.h"
41 #include "wine/winuser16.h"
43 #include "wine/unicode.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(class);
53 typedef struct tagCLASS
55 struct tagCLASS *next; /* Next class */
56 struct tagCLASS *prev; /* Prev class */
57 UINT cWindows; /* Count of existing windows */
58 UINT style; /* Class style */
59 WNDPROC winprocA; /* Window procedure (ASCII) */
60 WNDPROC winprocW; /* Window procedure (Unicode) */
61 INT cbClsExtra; /* Class extra bytes */
62 INT cbWndExtra; /* Window extra bytes */
63 LPWSTR menuName; /* Default menu name (Unicode followed by ASCII) */
64 SEGPTR segMenuName; /* Default menu name as SEGPTR */
65 struct tagDCE *dce; /* Class DCE (if CS_CLASSDC) */
66 HINSTANCE hInstance; /* Module that created the task */
67 HICON hIcon; /* Default icon */
68 HICON hIconSm; /* Default small icon */
69 HCURSOR hCursor; /* Default cursor */
70 HBRUSH hbrBackground; /* Default background */
71 ATOM atomName; /* Name of the class */
74 static CLASS *firstClass;
76 /***********************************************************************
79 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
81 WND *ptr = WIN_GetPtr( hwnd );
85 if (ptr != WND_OTHER_PROCESS) return ptr->class;
86 if (IsWindow( hwnd )) /* check other processes */
90 /* modifying classes in other processes is not allowed */
91 SetLastError( ERROR_ACCESS_DENIED );
94 FIXME( "reading from class of other process window %p\n", hwnd );
95 /* DbgBreakPoint(); */
98 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
103 /***********************************************************************
106 inline static void release_class_ptr( CLASS *ptr )
112 /***********************************************************************
115 * Get the class winproc for a given proc type
117 static WNDPROC16 CLASS_GetProc( CLASS *classPtr, WINDOWPROCTYPE type )
119 WNDPROC proc = classPtr->winprocA;
121 if (classPtr->winprocW)
123 /* if we have a Unicode proc, use it if we have no ASCII proc
124 * or if we have both and Unicode was requested
126 if (!proc || type == WIN_PROC_32W) proc = classPtr->winprocW;
128 return WINPROC_GetProc( proc, type );
132 /***********************************************************************
135 * Set the class winproc for a given proc type.
136 * Returns the previous window proc.
138 static WNDPROC16 CLASS_SetProc( CLASS *classPtr, WNDPROC newproc, WINDOWPROCTYPE type )
140 WNDPROC *proc = &classPtr->winprocA;
143 if (classPtr->winprocW)
145 /* if we have a Unicode proc, use it if we have no ASCII proc
146 * or if we have both and Unicode was requested
148 if (!*proc || type == WIN_PROC_32W) proc = &classPtr->winprocW;
150 ret = WINPROC_GetProc( *proc, type );
151 WINPROC_SetProc( proc, newproc, type, WIN_PROC_CLASS );
152 /* now free the one that we didn't set */
153 if (classPtr->winprocA && classPtr->winprocW)
155 if (proc == &classPtr->winprocA)
157 WINPROC_FreeProc( classPtr->winprocW, WIN_PROC_CLASS );
158 classPtr->winprocW = 0;
162 WINPROC_FreeProc( classPtr->winprocA, WIN_PROC_CLASS );
163 classPtr->winprocA = 0;
170 /***********************************************************************
173 * Get the menu name as a ASCII string.
175 inline static LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
177 if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
178 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
182 /***********************************************************************
183 * CLASS_GetMenuName16
185 * Get the menu name as a SEGPTR.
187 inline static SEGPTR CLASS_GetMenuName16( CLASS *classPtr )
189 if (!HIWORD(classPtr->menuName)) return (SEGPTR)classPtr->menuName;
190 if (!classPtr->segMenuName)
191 classPtr->segMenuName = MapLS( CLASS_GetMenuNameA(classPtr) );
192 return classPtr->segMenuName;
196 /***********************************************************************
199 * Get the menu name as a Unicode string.
201 inline static LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
203 return classPtr->menuName;
207 /***********************************************************************
210 * Set the menu name in a class structure by copying the string.
212 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
214 UnMapLS( classPtr->segMenuName );
215 classPtr->segMenuName = 0;
216 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
219 DWORD lenA = strlen(name) + 1;
220 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
221 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
222 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
223 memcpy( classPtr->menuName + lenW, name, lenA );
225 else classPtr->menuName = (LPWSTR)name;
229 /***********************************************************************
232 * Set the menu name in a class structure by copying the string.
234 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
236 UnMapLS( classPtr->segMenuName );
237 classPtr->segMenuName = 0;
238 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
241 DWORD lenW = strlenW(name) + 1;
242 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
243 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
244 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
245 WideCharToMultiByte( CP_ACP, 0, name, lenW,
246 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
248 else classPtr->menuName = (LPWSTR)name;
252 /***********************************************************************
255 * Free a class structure.
257 static BOOL CLASS_FreeClass( CLASS *classPtr )
259 TRACE("%p\n", classPtr);
261 /* Check if we can remove this class */
263 if (classPtr->cWindows > 0)
265 SetLastError( ERROR_CLASS_HAS_WINDOWS );
269 /* Remove the class from the linked list */
271 if (classPtr->next) classPtr->next->prev = classPtr->prev;
272 if (classPtr->prev) classPtr->prev->next = classPtr->next;
273 else firstClass = classPtr->next;
275 /* Delete the class */
277 if (classPtr->dce) DCE_FreeDCE( classPtr->dce );
278 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
279 DeleteObject( classPtr->hbrBackground );
280 GlobalDeleteAtom( classPtr->atomName );
281 WINPROC_FreeProc( classPtr->winprocA, WIN_PROC_CLASS );
282 WINPROC_FreeProc( classPtr->winprocW, WIN_PROC_CLASS );
283 UnMapLS( classPtr->segMenuName );
284 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
285 HeapFree( GetProcessHeap(), 0, classPtr );
290 /***********************************************************************
291 * CLASS_FreeModuleClasses
293 void CLASS_FreeModuleClasses( HMODULE16 hModule )
297 TRACE("0x%08x\n", hModule);
300 for (ptr = firstClass; ptr; ptr = next)
303 if (ptr->hInstance == HINSTANCE_32(hModule)) CLASS_FreeClass( ptr );
309 /***********************************************************************
310 * CLASS_FindClassByAtom
312 * Return a pointer to the class.
313 * hinstance has been normalized by the caller.
316 * 980805 a local class will be found now if registred with hInst=0
317 * and looed up with a hInst!=0. msmoney does it (jsch)
319 * Local class registered with a USER instance handle are found as if
320 * they were global classes.
322 static CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE hinstance )
324 CLASS * class, *tclass = 0, *user_class = 0;
325 HINSTANCE16 hUser = GetModuleHandle16("USER");
327 TRACE("0x%08x %p\n", atom, hinstance);
329 /* First search task-specific classes */
331 for (class = firstClass; (class); class = class->next)
333 if (class->style & CS_GLOBALCLASS) continue;
334 if (class->atomName == atom)
336 if (hinstance==class->hInstance || hinstance == (HINSTANCE)0xffff)
338 TRACE("-- found local %p\n", class);
341 if (class->hInstance == 0) tclass = class;
342 else if(class->hInstance == HINSTANCE_32(hUser))
349 /* Then search global classes */
351 for (class = firstClass; (class); class = class->next)
353 if (!(class->style & CS_GLOBALCLASS)) continue;
354 if (class->atomName == atom)
356 TRACE("-- found global %p\n", class);
361 /* Check if there was a local class registered with USER */
364 TRACE("--found local USER class %p\n", user_class);
368 /* Then check if there was a local class with hInst=0*/
371 WARN("-- found local Class registred with hInst=0\n");
375 TRACE("-- not found\n");
380 /***********************************************************************
381 * CLASS_RegisterClass
383 * The real RegisterClass() functionality.
385 static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE hInstance,
386 DWORD style, INT classExtra, INT winExtra )
390 TRACE("atom=0x%x hinst=%p style=0x%lx clExtr=0x%x winExtr=0x%x\n",
391 atom, hInstance, style, classExtra, winExtra );
393 /* Check if a class with this name already exists */
394 classPtr = CLASS_FindClassByAtom( atom, hInstance );
397 /* Class can be created only if it is local and */
398 /* if the class with the same name is global. */
400 if ((style & CS_GLOBALCLASS) || !(classPtr->style & CS_GLOBALCLASS))
402 SetLastError( ERROR_CLASS_ALREADY_EXISTS );
407 /* Fix the extra bytes value */
409 if (classExtra < 0) classExtra = 0;
410 else if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
411 WARN("Class extra bytes %d is > 40\n", classExtra);
412 if (winExtra < 0) winExtra = 0;
413 else if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
414 WARN("Win extra bytes %d is > 40\n", winExtra );
416 /* Create the class */
418 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
419 if (!classPtr) return NULL;
420 classPtr->style = style;
421 classPtr->cbWndExtra = winExtra;
422 classPtr->cbClsExtra = classExtra;
423 classPtr->hInstance = hInstance;
424 classPtr->atomName = atom;
425 classPtr->dce = (style & CS_CLASSDC) ? DCE_AllocDCE( 0, DCE_CLASS_DC ) : NULL;
427 /* Other non-null values must be set by caller */
429 if ((classPtr->next = firstClass)) firstClass->prev = classPtr;
430 firstClass = classPtr;
435 /***********************************************************************
436 * CLASS_UnregisterClass
438 * The real UnregisterClass() functionality.
440 static BOOL CLASS_UnregisterClass( ATOM atom, HINSTANCE hInstance )
447 (classPtr = CLASS_FindClassByAtom( atom, hInstance )) &&
448 (!hInstance || classPtr->hInstance == hInstance))
450 ret = CLASS_FreeClass( classPtr );
452 else SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
459 /***********************************************************************
460 * CLASS_RegisterBuiltinClass
462 * Register a builtin control class.
463 * This allows having both ASCII and Unicode winprocs for the same class.
465 ATOM CLASS_RegisterBuiltinClass( const struct builtin_class_descr *descr )
470 if (!(atom = GlobalAddAtomA( descr->name ))) return 0;
472 if (!(classPtr = CLASS_RegisterClass( atom, 0, descr->style, 0, descr->extra )))
474 GlobalDeleteAtom( atom );
478 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
479 classPtr->hbrBackground = descr->brush;
481 if (descr->procA) WINPROC_SetProc( &classPtr->winprocA, descr->procA,
482 WIN_PROC_32A, WIN_PROC_CLASS );
483 if (descr->procW) WINPROC_SetProc( &classPtr->winprocW, descr->procW,
484 WIN_PROC_32W, WIN_PROC_CLASS );
489 /***********************************************************************
492 * Add a new window using this class, and return the necessary
493 * information for creating the window.
495 CLASS *CLASS_AddWindow( ATOM atom, HINSTANCE inst, WINDOWPROCTYPE type,
496 INT *winExtra, WNDPROC *winproc, DWORD *style, struct tagDCE **dce )
499 if (type == WIN_PROC_16) inst = HINSTANCE_32(GetExePtr(HINSTANCE_16(inst)));
501 if (!(class = CLASS_FindClassByAtom( atom, inst ))) return NULL;
504 if (type == WIN_PROC_32W)
506 if (!(*winproc = class->winprocW)) *winproc = class->winprocA;
510 if (!(*winproc = class->winprocA)) *winproc = class->winprocW;
512 *winExtra = class->cbWndExtra;
513 *style = class->style;
519 /***********************************************************************
522 * Remove a window from the class window count.
524 void CLASS_RemoveWindow( CLASS *cls )
526 if (cls && cls->cWindows) cls->cWindows--;
530 /***********************************************************************
531 * RegisterClass (USER.57)
533 ATOM WINAPI RegisterClass16( const WNDCLASS16 *wc )
537 wcex.cbSize = sizeof(wcex);
538 wcex.style = wc->style;
539 wcex.lpfnWndProc = wc->lpfnWndProc;
540 wcex.cbClsExtra = wc->cbClsExtra;
541 wcex.cbWndExtra = wc->cbWndExtra;
542 wcex.hInstance = wc->hInstance;
543 wcex.hIcon = wc->hIcon;
544 wcex.hCursor = wc->hCursor;
545 wcex.hbrBackground = wc->hbrBackground;
546 wcex.lpszMenuName = wc->lpszMenuName;
547 wcex.lpszClassName = wc->lpszClassName;
549 return RegisterClassEx16( &wcex );
553 /***********************************************************************
554 * RegisterClassA (USER32.@)
556 * >0: Unique identifier
559 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
563 wcex.cbSize = sizeof(wcex);
564 wcex.style = wc->style;
565 wcex.lpfnWndProc = wc->lpfnWndProc;
566 wcex.cbClsExtra = wc->cbClsExtra;
567 wcex.cbWndExtra = wc->cbWndExtra;
568 wcex.hInstance = wc->hInstance;
569 wcex.hIcon = wc->hIcon;
570 wcex.hCursor = wc->hCursor;
571 wcex.hbrBackground = wc->hbrBackground;
572 wcex.lpszMenuName = wc->lpszMenuName;
573 wcex.lpszClassName = wc->lpszClassName;
575 return RegisterClassExA( &wcex );
579 /***********************************************************************
580 * RegisterClassW (USER32.@)
582 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
586 wcex.cbSize = sizeof(wcex);
587 wcex.style = wc->style;
588 wcex.lpfnWndProc = wc->lpfnWndProc;
589 wcex.cbClsExtra = wc->cbClsExtra;
590 wcex.cbWndExtra = wc->cbWndExtra;
591 wcex.hInstance = wc->hInstance;
592 wcex.hIcon = wc->hIcon;
593 wcex.hCursor = wc->hCursor;
594 wcex.hbrBackground = wc->hbrBackground;
595 wcex.lpszMenuName = wc->lpszMenuName;
596 wcex.lpszClassName = wc->lpszClassName;
598 return RegisterClassExW( &wcex );
602 /***********************************************************************
603 * RegisterClassEx (USER.397)
605 ATOM WINAPI RegisterClassEx16( const WNDCLASSEX16 *wc )
609 HINSTANCE hInstance = HINSTANCE_32(GetExePtr( wc->hInstance ));
611 if (!(atom = GlobalAddAtomA( MapSL(wc->lpszClassName) ))) return 0;
612 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
613 wc->cbClsExtra, wc->cbWndExtra )))
615 GlobalDeleteAtom( atom );
619 TRACE("atom=%04x wndproc=%p hinst=%p bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
620 atom, wc->lpfnWndProc, hInstance,
621 wc->hbrBackground, wc->style, wc->cbClsExtra,
622 wc->cbWndExtra, classPtr );
624 classPtr->hIcon = HICON_32(wc->hIcon);
625 classPtr->hIconSm = HICON_32(wc->hIconSm);
626 classPtr->hCursor = HCURSOR_32(wc->hCursor);
627 classPtr->hbrBackground = HBRUSH_32(wc->hbrBackground);
629 WINPROC_SetProc( &classPtr->winprocA, (WNDPROC)wc->lpfnWndProc,
630 WIN_PROC_16, WIN_PROC_CLASS );
631 CLASS_SetMenuNameA( classPtr, MapSL(wc->lpszMenuName) );
636 /***********************************************************************
637 * RegisterClassExA (USER32.@)
639 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
644 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
646 if (!(classPtr = CLASS_RegisterClass( atom, wc->hInstance, wc->style,
647 wc->cbClsExtra, wc->cbWndExtra )))
649 GlobalDeleteAtom( atom );
653 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
654 atom, wc->lpfnWndProc, wc->hInstance,
655 wc->hbrBackground, wc->style, wc->cbClsExtra,
656 wc->cbWndExtra, classPtr );
658 classPtr->hIcon = wc->hIcon;
659 classPtr->hIconSm = wc->hIconSm;
660 classPtr->hCursor = wc->hCursor;
661 classPtr->hbrBackground = wc->hbrBackground;
662 WINPROC_SetProc( &classPtr->winprocA, wc->lpfnWndProc, WIN_PROC_32A, WIN_PROC_CLASS );
663 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
668 /***********************************************************************
669 * RegisterClassExW (USER32.@)
671 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
676 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
678 if (!(classPtr = CLASS_RegisterClass( atom, wc->hInstance, wc->style,
679 wc->cbClsExtra, wc->cbWndExtra )))
681 GlobalDeleteAtom( atom );
685 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
686 atom, wc->lpfnWndProc, wc->hInstance,
687 wc->hbrBackground, wc->style, wc->cbClsExtra,
688 wc->cbWndExtra, classPtr );
690 classPtr->hIcon = wc->hIcon;
691 classPtr->hIconSm = wc->hIconSm;
692 classPtr->hCursor = wc->hCursor;
693 classPtr->hbrBackground = wc->hbrBackground;
694 WINPROC_SetProc( &classPtr->winprocW, wc->lpfnWndProc, WIN_PROC_32W, WIN_PROC_CLASS );
695 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
700 /***********************************************************************
701 * UnregisterClass (USER.403)
703 BOOL16 WINAPI UnregisterClass16( LPCSTR className, HINSTANCE16 hInstance )
705 return UnregisterClassA( className, HINSTANCE_32(GetExePtr( hInstance )) );
708 /***********************************************************************
709 * UnregisterClassA (USER32.@)
712 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
714 TRACE("%s %p\n",debugstr_a(className), hInstance);
715 return CLASS_UnregisterClass( GlobalFindAtomA( className ), hInstance );
718 /***********************************************************************
719 * UnregisterClassW (USER32.@)
721 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
723 TRACE("%s %p\n",debugstr_w(className), hInstance);
724 return CLASS_UnregisterClass( GlobalFindAtomW( className ), hInstance );
728 /***********************************************************************
729 * GetClassWord (USER32.@)
731 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
736 if (offset < 0) return GetClassLongA( hwnd, offset );
738 TRACE("%p %x\n",hwnd, offset);
740 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
742 if (offset <= class->cbClsExtra - sizeof(WORD))
743 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
745 SetLastError( ERROR_INVALID_INDEX );
746 release_class_ptr( class );
751 /***********************************************************************
752 * GetClassLong (USER.131)
754 LONG WINAPI GetClassLong16( HWND16 hwnd16, INT16 offset )
758 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
760 TRACE("%p %d\n",hwnd, offset);
765 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
766 ret = (LONG)CLASS_GetProc( class, WIN_PROC_16 );
767 release_class_ptr( class );
770 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
771 ret = (LONG)CLASS_GetMenuName16( class );
772 release_class_ptr( class );
775 return GetClassLongA( hwnd, offset );
780 /***********************************************************************
781 * GetClassLongW (USER32.@)
783 LONG WINAPI GetClassLongW( HWND hwnd, INT offset )
788 TRACE("%p %d\n", hwnd, offset);
790 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
794 if (offset <= class->cbClsExtra - sizeof(LONG))
795 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
797 SetLastError( ERROR_INVALID_INDEX );
798 release_class_ptr( class );
804 case GCL_HBRBACKGROUND:
805 retvalue = (LONG)class->hbrBackground;
808 retvalue = (LONG)class->hCursor;
811 retvalue = (LONG)class->hIcon;
814 retvalue = (LONG)class->hIconSm;
817 retvalue = (LONG)class->style;
820 retvalue = (LONG)class->cbWndExtra;
823 retvalue = (LONG)class->cbClsExtra;
826 retvalue = (LONG)class->hInstance;
829 retvalue = (LONG)CLASS_GetProc( class, WIN_PROC_32W );
832 retvalue = (LONG)CLASS_GetMenuNameW( class );
835 retvalue = (DWORD)class->atomName;
838 SetLastError( ERROR_INVALID_INDEX );
841 release_class_ptr( class );
846 /***********************************************************************
847 * GetClassLongA (USER32.@)
849 LONG WINAPI GetClassLongA( HWND hwnd, INT offset )
854 if (offset != GCL_WNDPROC && offset != GCL_MENUNAME)
855 return GetClassLongW( hwnd, offset );
857 TRACE("%p %d\n", hwnd, offset);
859 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
861 if (offset == GCL_WNDPROC)
862 retvalue = (LONG)CLASS_GetProc( class, WIN_PROC_32A );
863 else /* GCL_MENUNAME */
864 retvalue = (LONG)CLASS_GetMenuNameA( class );
866 release_class_ptr( class );
871 /***********************************************************************
872 * SetClassWord (USER32.@)
874 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
879 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
881 TRACE("%p %d %x\n", hwnd, offset, newval);
883 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
885 if (offset <= class->cbClsExtra - sizeof(WORD))
887 void *ptr = (char *)(class + 1) + offset;
888 memcpy( &retval, ptr, sizeof(retval) );
889 memcpy( ptr, &newval, sizeof(newval) );
891 else SetLastError( ERROR_INVALID_INDEX );
893 release_class_ptr( class );
898 /***********************************************************************
899 * SetClassLong (USER.132)
901 LONG WINAPI SetClassLong16( HWND16 hwnd16, INT16 offset, LONG newval )
905 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
907 TRACE("%p %d %lx\n", hwnd, offset, newval);
912 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
913 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_16 );
914 release_class_ptr( class );
917 newval = (LONG)MapSL( newval );
920 return SetClassLongA( hwnd, offset, newval );
925 /***********************************************************************
926 * SetClassLongW (USER32.@)
928 LONG WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
933 TRACE("%p %d %lx\n", hwnd, offset, newval);
935 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
939 if (offset <= class->cbClsExtra - sizeof(LONG))
941 void *ptr = (char *)(class + 1) + offset;
942 memcpy( &retval, ptr, sizeof(retval) );
943 memcpy( ptr, &newval, sizeof(newval) );
945 else SetLastError( ERROR_INVALID_INDEX );
950 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
951 retval = 0; /* Old value is now meaningless anyway */
954 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32W );
956 case GCL_HBRBACKGROUND:
957 retval = (LONG)class->hbrBackground;
958 class->hbrBackground = (HBRUSH)newval;
961 retval = (LONG)class->hCursor;
962 class->hCursor = (HCURSOR)newval;
965 retval = (LONG)class->hIcon;
966 class->hIcon = (HICON)newval;
969 retval = (LONG)class->hIconSm;
970 class->hIconSm = (HICON)newval;
973 retval = (LONG)class->style;
974 class->style = newval;
977 retval = (LONG)class->cbWndExtra;
978 class->cbWndExtra = newval;
981 retval = (LONG)class->hInstance;
982 class->hInstance = (HINSTANCE)newval;
985 retval = (DWORD)class->atomName;
986 class->atomName = newval;
988 case GCL_CBCLSEXTRA: /* cannot change this one */
989 SetLastError( ERROR_INVALID_PARAMETER );
992 SetLastError( ERROR_INVALID_INDEX );
995 release_class_ptr( class );
1000 /***********************************************************************
1001 * SetClassLongA (USER32.@)
1003 LONG WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
1008 if (offset != GCL_WNDPROC && offset != GCL_MENUNAME)
1009 return SetClassLongW( hwnd, offset, newval );
1011 TRACE("%p %d %lx\n", hwnd, offset, newval);
1013 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
1015 if (offset == GCL_WNDPROC)
1016 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32A );
1017 else /* GCL_MENUNAME */
1019 CLASS_SetMenuNameA( class, (LPCSTR)newval );
1020 retval = 0; /* Old value is now meaningless anyway */
1022 release_class_ptr( class );
1027 /***********************************************************************
1028 * GetClassNameA (USER32.@)
1030 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
1032 INT ret = GlobalGetAtomNameA( GetClassLongA( hwnd, GCW_ATOM ), buffer, count );
1034 TRACE("%p %s %x\n",hwnd, debugstr_a(buffer), count);
1039 /***********************************************************************
1040 * GetClassNameW (USER32.@)
1042 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
1044 INT ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), buffer, count );
1046 TRACE("%p %s %x\n",hwnd, debugstr_w(buffer), count);
1051 /***********************************************************************
1052 * RealGetWindowClassA (USER32.@)
1054 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1056 return GetClassNameA( hwnd, buffer, count );
1060 /***********************************************************************
1061 * RealGetWindowClassW (USER32.@)
1063 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1065 return GetClassNameW( hwnd, buffer, count );
1069 /***********************************************************************
1070 * GetClassInfo (USER.404)
1072 BOOL16 WINAPI GetClassInfo16( HINSTANCE16 hInst16, SEGPTR name, WNDCLASS16 *wc )
1075 UINT16 ret = GetClassInfoEx16( hInst16, name, &wcex );
1079 wc->style = wcex.style;
1080 wc->lpfnWndProc = wcex.lpfnWndProc;
1081 wc->cbClsExtra = wcex.cbClsExtra;
1082 wc->cbWndExtra = wcex.cbWndExtra;
1083 wc->hInstance = wcex.hInstance;
1084 wc->hIcon = wcex.hIcon;
1085 wc->hCursor = wcex.hCursor;
1086 wc->hbrBackground = wcex.hbrBackground;
1087 wc->lpszMenuName = wcex.lpszMenuName;
1088 wc->lpszClassName = wcex.lpszClassName;
1094 /***********************************************************************
1095 * GetClassInfoA (USER32.@)
1097 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1100 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1104 wc->style = wcex.style;
1105 wc->lpfnWndProc = wcex.lpfnWndProc;
1106 wc->cbClsExtra = wcex.cbClsExtra;
1107 wc->cbWndExtra = wcex.cbWndExtra;
1108 wc->hInstance = wcex.hInstance;
1109 wc->hIcon = wcex.hIcon;
1110 wc->hCursor = wcex.hCursor;
1111 wc->hbrBackground = wcex.hbrBackground;
1112 wc->lpszMenuName = wcex.lpszMenuName;
1113 wc->lpszClassName = wcex.lpszClassName;
1119 /***********************************************************************
1120 * GetClassInfoW (USER32.@)
1122 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1125 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1129 wc->style = wcex.style;
1130 wc->lpfnWndProc = wcex.lpfnWndProc;
1131 wc->cbClsExtra = wcex.cbClsExtra;
1132 wc->cbWndExtra = wcex.cbWndExtra;
1133 wc->hInstance = wcex.hInstance;
1134 wc->hIcon = wcex.hIcon;
1135 wc->hCursor = wcex.hCursor;
1136 wc->hbrBackground = wcex.hbrBackground;
1137 wc->lpszMenuName = wcex.lpszMenuName;
1138 wc->lpszClassName = wcex.lpszClassName;
1144 /***********************************************************************
1145 * GetClassInfoEx (USER.398)
1147 * FIXME: this is just a guess, I have no idea if GetClassInfoEx() is the
1148 * same in Win16 as in Win32. --AJ
1150 BOOL16 WINAPI GetClassInfoEx16( HINSTANCE16 hInst16, SEGPTR name, WNDCLASSEX16 *wc )
1154 HINSTANCE hInstance = HINSTANCE_32(GetExePtr( hInst16 ));
1156 TRACE("%p %s %p\n",hInstance,debugstr_a( MapSL(name) ), wc);
1158 if (!(atom = GlobalFindAtomA( MapSL(name) )) ||
1159 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
1160 (hInstance != classPtr->hInstance)) return FALSE;
1161 wc->style = classPtr->style;
1162 wc->lpfnWndProc = CLASS_GetProc( classPtr, WIN_PROC_16 );
1163 wc->cbClsExtra = (INT16)classPtr->cbClsExtra;
1164 wc->cbWndExtra = (INT16)classPtr->cbWndExtra;
1165 wc->hInstance = HINSTANCE_16(classPtr->hInstance);
1166 wc->hIcon = HICON_16(classPtr->hIcon);
1167 wc->hIconSm = HICON_16(classPtr->hIconSm);
1168 wc->hCursor = HCURSOR_16(classPtr->hCursor);
1169 wc->hbrBackground = HBRUSH_16(classPtr->hbrBackground);
1170 wc->lpszClassName = (SEGPTR)0;
1171 wc->lpszMenuName = CLASS_GetMenuName16( classPtr );
1172 wc->lpszClassName = name;
1174 /* We must return the atom of the class here instead of just TRUE. */
1179 /***********************************************************************
1180 * GetClassInfoExA (USER32.@)
1182 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name,
1188 TRACE("%p %p %p\n",hInstance, name, wc);
1190 if (!(atom = GlobalFindAtomA( name )) ||
1191 !(classPtr = CLASS_FindClassByAtom( atom, hInstance ))
1192 /*|| (hInstance != classPtr->hInstance) */ ) return FALSE;
1193 wc->style = classPtr->style;
1194 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32A );
1195 wc->cbClsExtra = classPtr->cbClsExtra;
1196 wc->cbWndExtra = classPtr->cbWndExtra;
1197 wc->hInstance = classPtr->hInstance;
1198 wc->hIcon = (HICON)classPtr->hIcon;
1199 wc->hIconSm = (HICON)classPtr->hIconSm;
1200 wc->hCursor = (HCURSOR)classPtr->hCursor;
1201 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1202 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1203 wc->lpszClassName = name;
1205 /* We must return the atom of the class here instead of just TRUE. */
1210 /***********************************************************************
1211 * GetClassInfoExW (USER32.@)
1213 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name,
1219 TRACE("%p %p %p\n",hInstance, name, wc);
1221 if (!(atom = GlobalFindAtomW( name )) ||
1222 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
1223 (hInstance != classPtr->hInstance)) return FALSE;
1224 wc->style = classPtr->style;
1225 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32W );
1226 wc->cbClsExtra = classPtr->cbClsExtra;
1227 wc->cbWndExtra = classPtr->cbWndExtra;
1228 wc->hInstance = classPtr->hInstance;
1229 wc->hIcon = (HICON)classPtr->hIcon;
1230 wc->hIconSm = (HICON)classPtr->hIconSm;
1231 wc->hCursor = (HCURSOR)classPtr->hCursor;
1232 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1233 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1234 wc->lpszClassName = name;
1236 /* We must return the atom of the class here instead of just TRUE. */
1241 #if 0 /* toolhelp is in kernel, so this cannot work */
1243 /***********************************************************************
1244 * ClassFirst (TOOLHELP.69)
1246 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1248 TRACE("%p\n",pClassEntry);
1249 pClassEntry->wNext = 1;
1250 return ClassNext16( pClassEntry );
1254 /***********************************************************************
1255 * ClassNext (TOOLHELP.70)
1257 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1260 CLASS *class = firstClass;
1262 TRACE("%p\n",pClassEntry);
1264 if (!pClassEntry->wNext) return FALSE;
1265 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1268 pClassEntry->wNext = 0;
1271 pClassEntry->hInst = class->hInstance;
1272 pClassEntry->wNext++;
1273 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1274 sizeof(pClassEntry->szClassName) );