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, 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 int iSmIconWidth, iSmIconHeight;
538 HINSTANCE hInstance = HINSTANCE_32(GetExePtr(wc->hInstance));
540 if (!(atom = GlobalAddAtomA( MapSL(wc->lpszClassName) ))) return 0;
541 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
542 wc->cbClsExtra, wc->cbWndExtra )))
544 GlobalDeleteAtom( atom );
548 TRACE("atom=%04x wndproc=%08lx hinst=%p bg=%04x style=%08x clsExt=%d winExt=%d class=%p name='%s'\n",
549 atom, (DWORD)wc->lpfnWndProc, hInstance,
550 wc->hbrBackground, wc->style, wc->cbClsExtra,
551 wc->cbWndExtra, classPtr,
552 HIWORD(wc->lpszClassName) ? (char *)MapSL(wc->lpszClassName) : "" );
554 iSmIconWidth = GetSystemMetrics(SM_CXSMICON);
555 iSmIconHeight = GetSystemMetrics(SM_CYSMICON);
557 classPtr->hIcon = HICON_32(wc->hIcon);
558 classPtr->hIconSm = CopyImage(classPtr->hIcon, IMAGE_ICON,
559 iSmIconWidth, iSmIconHeight,
560 LR_COPYFROMRESOURCE);
561 classPtr->hCursor = HCURSOR_32(wc->hCursor);
562 classPtr->hbrBackground = HBRUSH_32(wc->hbrBackground);
564 WINPROC_SetProc( &classPtr->winprocA, (WNDPROC)wc->lpfnWndProc,
565 WIN_PROC_16, WIN_PROC_CLASS );
566 CLASS_SetMenuNameA( classPtr, MapSL(wc->lpszMenuName) );
572 /***********************************************************************
573 * RegisterClassA (USER32.@)
575 * >0: Unique identifier
578 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
581 int iSmIconWidth, iSmIconHeight;
584 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
586 if (!(classPtr = CLASS_RegisterClass( atom, wc->hInstance, wc->style,
587 wc->cbClsExtra, wc->cbWndExtra )))
589 GlobalDeleteAtom( atom );
593 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p name='%s'\n",
594 atom, wc->lpfnWndProc, wc->hInstance,
595 wc->hbrBackground, wc->style, wc->cbClsExtra,
596 wc->cbWndExtra, classPtr,
597 HIWORD(wc->lpszClassName) ? wc->lpszClassName : "" );
599 iSmIconWidth = GetSystemMetrics(SM_CXSMICON);
600 iSmIconHeight = GetSystemMetrics(SM_CYSMICON);
602 classPtr->hIcon = wc->hIcon;
603 classPtr->hIconSm = CopyImage(wc->hIcon, IMAGE_ICON,
604 iSmIconWidth, iSmIconHeight,
605 LR_COPYFROMRESOURCE);
606 classPtr->hCursor = wc->hCursor;
607 classPtr->hbrBackground = wc->hbrBackground;
609 WINPROC_SetProc( &classPtr->winprocA, wc->lpfnWndProc,
610 WIN_PROC_32A, WIN_PROC_CLASS );
611 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
616 /***********************************************************************
617 * RegisterClassW (USER32.@)
619 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
622 int iSmIconWidth, iSmIconHeight;
625 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
627 if (!(classPtr = CLASS_RegisterClass( atom, wc->hInstance, wc->style,
628 wc->cbClsExtra, wc->cbWndExtra )))
630 GlobalDeleteAtom( atom );
634 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
635 atom, wc->lpfnWndProc, wc->hInstance,
636 wc->hbrBackground, wc->style, wc->cbClsExtra,
637 wc->cbWndExtra, classPtr );
639 iSmIconWidth = GetSystemMetrics(SM_CXSMICON);
640 iSmIconHeight = GetSystemMetrics(SM_CYSMICON);
642 classPtr->hIcon = wc->hIcon;
643 classPtr->hIconSm = CopyImage(wc->hIcon, IMAGE_ICON,
644 iSmIconWidth, iSmIconHeight,
645 LR_COPYFROMRESOURCE);
646 classPtr->hCursor = wc->hCursor;
647 classPtr->hbrBackground = wc->hbrBackground;
649 WINPROC_SetProc( &classPtr->winprocW, wc->lpfnWndProc,
650 WIN_PROC_32W, WIN_PROC_CLASS );
651 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
656 /***********************************************************************
657 * RegisterClassEx (USER.397)
659 ATOM WINAPI RegisterClassEx16( const WNDCLASSEX16 *wc )
663 HINSTANCE hInstance = HINSTANCE_32(GetExePtr( wc->hInstance ));
665 if (!(atom = GlobalAddAtomA( MapSL(wc->lpszClassName) ))) return 0;
666 if (!(classPtr = CLASS_RegisterClass( atom, hInstance, wc->style,
667 wc->cbClsExtra, wc->cbWndExtra )))
669 GlobalDeleteAtom( atom );
673 TRACE("atom=%04x wndproc=%p hinst=%p bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
674 atom, wc->lpfnWndProc, hInstance,
675 wc->hbrBackground, wc->style, wc->cbClsExtra,
676 wc->cbWndExtra, classPtr );
678 classPtr->hIcon = HICON_32(wc->hIcon);
679 classPtr->hIconSm = HICON_32(wc->hIconSm);
680 classPtr->hCursor = HCURSOR_32(wc->hCursor);
681 classPtr->hbrBackground = HBRUSH_32(wc->hbrBackground);
683 WINPROC_SetProc( &classPtr->winprocA, (WNDPROC)wc->lpfnWndProc,
684 WIN_PROC_16, WIN_PROC_CLASS );
685 CLASS_SetMenuNameA( classPtr, MapSL(wc->lpszMenuName) );
690 /***********************************************************************
691 * RegisterClassExA (USER32.@)
693 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
698 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
700 if (!(classPtr = CLASS_RegisterClass( atom, wc->hInstance, wc->style,
701 wc->cbClsExtra, wc->cbWndExtra )))
703 GlobalDeleteAtom( atom );
707 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
708 atom, wc->lpfnWndProc, wc->hInstance,
709 wc->hbrBackground, wc->style, wc->cbClsExtra,
710 wc->cbWndExtra, classPtr );
712 classPtr->hIcon = wc->hIcon;
713 classPtr->hIconSm = wc->hIconSm;
714 classPtr->hCursor = wc->hCursor;
715 classPtr->hbrBackground = wc->hbrBackground;
716 WINPROC_SetProc( &classPtr->winprocA, wc->lpfnWndProc, WIN_PROC_32A, WIN_PROC_CLASS );
717 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
722 /***********************************************************************
723 * RegisterClassExW (USER32.@)
725 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
730 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
732 if (!(classPtr = CLASS_RegisterClass( atom, wc->hInstance, wc->style,
733 wc->cbClsExtra, wc->cbWndExtra )))
735 GlobalDeleteAtom( atom );
739 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
740 atom, wc->lpfnWndProc, wc->hInstance,
741 wc->hbrBackground, wc->style, wc->cbClsExtra,
742 wc->cbWndExtra, classPtr );
744 classPtr->hIcon = wc->hIcon;
745 classPtr->hIconSm = wc->hIconSm;
746 classPtr->hCursor = wc->hCursor;
747 classPtr->hbrBackground = wc->hbrBackground;
748 WINPROC_SetProc( &classPtr->winprocW, wc->lpfnWndProc, WIN_PROC_32W, WIN_PROC_CLASS );
749 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
754 /***********************************************************************
755 * UnregisterClass (USER.403)
757 BOOL16 WINAPI UnregisterClass16( LPCSTR className, HINSTANCE16 hInstance )
759 return UnregisterClassA( className, HINSTANCE_32(GetExePtr( hInstance )) );
762 /***********************************************************************
763 * UnregisterClassA (USER32.@)
766 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
768 TRACE("%s %p\n",debugstr_a(className), hInstance);
769 return CLASS_UnregisterClass( GlobalFindAtomA( className ), hInstance );
772 /***********************************************************************
773 * UnregisterClassW (USER32.@)
775 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
777 TRACE("%s %p\n",debugstr_w(className), hInstance);
778 return CLASS_UnregisterClass( GlobalFindAtomW( className ), hInstance );
782 /***********************************************************************
783 * GetClassWord (USER32.@)
785 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
790 if (offset < 0) return GetClassLongA( hwnd, offset );
792 TRACE("%p %x\n",hwnd, offset);
794 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
796 if (offset <= class->cbClsExtra - sizeof(WORD))
797 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
799 SetLastError( ERROR_INVALID_INDEX );
800 release_class_ptr( class );
805 /***********************************************************************
806 * GetClassLong (USER.131)
808 LONG WINAPI GetClassLong16( HWND16 hwnd16, INT16 offset )
812 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
814 TRACE("%p %d\n",hwnd, offset);
819 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
820 ret = (LONG)CLASS_GetProc( class, WIN_PROC_16 );
821 release_class_ptr( class );
824 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
825 ret = (LONG)CLASS_GetMenuName16( class );
826 release_class_ptr( class );
829 return GetClassLongA( hwnd, offset );
834 /***********************************************************************
835 * GetClassLongW (USER32.@)
837 LONG WINAPI GetClassLongW( HWND hwnd, INT offset )
842 TRACE("%p %d\n", hwnd, offset);
844 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
848 if (offset <= class->cbClsExtra - sizeof(LONG))
849 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
851 SetLastError( ERROR_INVALID_INDEX );
852 release_class_ptr( class );
858 case GCL_HBRBACKGROUND:
859 retvalue = (LONG)class->hbrBackground;
862 retvalue = (LONG)class->hCursor;
865 retvalue = (LONG)class->hIcon;
868 retvalue = (LONG)class->hIconSm;
871 retvalue = (LONG)class->style;
874 retvalue = (LONG)class->cbWndExtra;
877 retvalue = (LONG)class->cbClsExtra;
880 retvalue = (LONG)class->hInstance;
883 retvalue = (LONG)CLASS_GetProc( class, WIN_PROC_32W );
886 retvalue = (LONG)CLASS_GetMenuNameW( class );
889 retvalue = (DWORD)class->atomName;
892 SetLastError( ERROR_INVALID_INDEX );
895 release_class_ptr( class );
900 /***********************************************************************
901 * GetClassLongA (USER32.@)
903 LONG WINAPI GetClassLongA( HWND hwnd, INT offset )
908 if (offset != GCL_WNDPROC && offset != GCL_MENUNAME)
909 return GetClassLongW( hwnd, offset );
911 TRACE("%p %d\n", hwnd, offset);
913 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
915 if (offset == GCL_WNDPROC)
916 retvalue = (LONG)CLASS_GetProc( class, WIN_PROC_32A );
917 else /* GCL_MENUNAME */
918 retvalue = (LONG)CLASS_GetMenuNameA( class );
920 release_class_ptr( class );
925 /***********************************************************************
926 * SetClassWord (USER32.@)
928 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
933 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
935 TRACE("%p %d %x\n", hwnd, offset, newval);
937 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
939 if (offset <= class->cbClsExtra - sizeof(WORD))
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 );
947 release_class_ptr( class );
952 /***********************************************************************
953 * SetClassLong (USER.132)
955 LONG WINAPI SetClassLong16( HWND16 hwnd16, INT16 offset, LONG newval )
959 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
961 TRACE("%p %d %lx\n", hwnd, offset, newval);
966 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
967 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_16 );
968 release_class_ptr( class );
971 newval = (LONG)MapSL( newval );
974 return SetClassLongA( hwnd, offset, newval );
979 /***********************************************************************
980 * SetClassLongW (USER32.@)
982 LONG WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
987 TRACE("%p %d %lx\n", hwnd, offset, newval);
989 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
993 if (offset <= class->cbClsExtra - sizeof(LONG))
995 void *ptr = (char *)(class + 1) + offset;
996 memcpy( &retval, ptr, sizeof(retval) );
997 memcpy( ptr, &newval, sizeof(newval) );
999 else SetLastError( ERROR_INVALID_INDEX );
1004 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
1005 retval = 0; /* Old value is now meaningless anyway */
1008 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32W );
1010 case GCL_HBRBACKGROUND:
1011 retval = (LONG)class->hbrBackground;
1012 class->hbrBackground = (HBRUSH)newval;
1015 retval = (LONG)class->hCursor;
1016 class->hCursor = (HCURSOR)newval;
1019 retval = (LONG)class->hIcon;
1020 class->hIcon = (HICON)newval;
1023 retval = (LONG)class->hIconSm;
1024 class->hIconSm = (HICON)newval;
1027 retval = (LONG)class->style;
1028 class->style = newval;
1030 case GCL_CBWNDEXTRA:
1031 retval = (LONG)class->cbWndExtra;
1032 class->cbWndExtra = newval;
1035 retval = (LONG)class->hInstance;
1036 class->hInstance = (HINSTANCE)newval;
1039 retval = (DWORD)class->atomName;
1040 class->atomName = newval;
1042 case GCL_CBCLSEXTRA: /* cannot change this one */
1043 SetLastError( ERROR_INVALID_PARAMETER );
1046 SetLastError( ERROR_INVALID_INDEX );
1049 release_class_ptr( class );
1054 /***********************************************************************
1055 * SetClassLongA (USER32.@)
1057 LONG WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
1062 if (offset != GCL_WNDPROC && offset != GCL_MENUNAME)
1063 return SetClassLongW( hwnd, offset, newval );
1065 TRACE("%p %d %lx\n", hwnd, offset, newval);
1067 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
1069 if (offset == GCL_WNDPROC)
1070 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32A );
1071 else /* GCL_MENUNAME */
1073 CLASS_SetMenuNameA( class, (LPCSTR)newval );
1074 retval = 0; /* Old value is now meaningless anyway */
1076 release_class_ptr( class );
1081 /***********************************************************************
1082 * GetClassNameA (USER32.@)
1084 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
1086 INT ret = GlobalGetAtomNameA( GetClassLongA( hwnd, GCW_ATOM ), buffer, count );
1088 TRACE("%p %s %x\n",hwnd, debugstr_a(buffer), count);
1093 /***********************************************************************
1094 * GetClassNameW (USER32.@)
1096 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
1098 INT ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), buffer, count );
1100 TRACE("%p %s %x\n",hwnd, debugstr_w(buffer), count);
1105 /***********************************************************************
1106 * GetClassInfo (USER.404)
1108 BOOL16 WINAPI GetClassInfo16( HINSTANCE16 hInst16, SEGPTR name, WNDCLASS16 *wc )
1112 HINSTANCE hInstance = HINSTANCE_32(GetExePtr( hInst16 ));
1114 TRACE("%p %s %p\n",hInstance, debugstr_a(MapSL(name)), wc);
1116 if (!(atom = GlobalFindAtomA( MapSL(name) )) ||
1117 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1119 if ((hInstance != classPtr->hInstance) &&
1120 !(classPtr->style & CS_GLOBALCLASS)) /*BWCC likes to pass hInstance=0*/
1122 wc->style = (UINT16)classPtr->style;
1123 wc->lpfnWndProc = CLASS_GetProc( classPtr, WIN_PROC_16 );
1124 wc->cbClsExtra = (INT16)classPtr->cbClsExtra;
1125 wc->cbWndExtra = (INT16)classPtr->cbWndExtra;
1126 wc->hInstance = classPtr->style & CS_GLOBALCLASS ? GetModuleHandle16("USER") : HINSTANCE_16(classPtr->hInstance);
1127 wc->hIcon = HICON_16(classPtr->hIcon);
1128 wc->hCursor = HCURSOR_16(classPtr->hCursor);
1129 wc->hbrBackground = HBRUSH_16(classPtr->hbrBackground);
1130 wc->lpszClassName = name;
1131 wc->lpszMenuName = CLASS_GetMenuName16( classPtr );
1133 /* We must return the atom of the class here instead of just TRUE. */
1138 /***********************************************************************
1139 * GetClassInfoA (USER32.@)
1141 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name,
1147 TRACE("%p %p %p\n",hInstance, name, wc);
1149 /* workaround: if hInstance=NULL you expect to get the system classes
1150 but this classes (as example from comctl32.dll SysListView) won't be
1151 registered with hInstance=NULL in WINE because of the late loading
1152 of this dll. fixes file dialogs in WinWord95 (jsch)*/
1154 if (!(atom=GlobalFindAtomA(name)) || !(classPtr=CLASS_FindClassByAtom(atom,hInstance)))
1157 if (!(classPtr->style & CS_GLOBALCLASS) &&
1158 classPtr->hInstance &&
1159 (hInstance != classPtr->hInstance))
1161 if (hInstance) return FALSE;
1162 WARN("systemclass %s (hInst=0) demanded but only class with hInst!=0 found\n",name);
1165 wc->style = classPtr->style;
1166 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32A );
1167 wc->cbClsExtra = classPtr->cbClsExtra;
1168 wc->cbWndExtra = classPtr->cbWndExtra;
1169 wc->hInstance = hInstance;
1170 wc->hIcon = (HICON)classPtr->hIcon;
1171 wc->hCursor = (HCURSOR)classPtr->hCursor;
1172 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1173 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1174 wc->lpszClassName = name;
1176 /* We must return the atom of the class here instead of just TRUE. */
1181 /***********************************************************************
1182 * GetClassInfoW (USER32.@)
1184 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name,
1190 TRACE("%p %p %p\n",hInstance, name, wc);
1192 if ( !(atom=GlobalFindAtomW(name)) ||
1193 !(classPtr=CLASS_FindClassByAtom(atom,hInstance))
1197 if (!(classPtr->style & CS_GLOBALCLASS) &&
1198 classPtr->hInstance &&
1199 (hInstance != classPtr->hInstance))
1201 if (hInstance) return FALSE;
1202 WARN("systemclass %s (hInst=0) demanded but only class with hInst!=0 found\n",debugstr_w(name));
1204 wc->style = classPtr->style;
1205 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32W );
1206 wc->cbClsExtra = classPtr->cbClsExtra;
1207 wc->cbWndExtra = classPtr->cbWndExtra;
1208 wc->hInstance = hInstance;
1209 wc->hIcon = (HICON)classPtr->hIcon;
1210 wc->hCursor = (HCURSOR)classPtr->hCursor;
1211 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1212 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1213 wc->lpszClassName = name;
1215 /* We must return the atom of the class here instead of just TRUE. */
1220 /***********************************************************************
1221 * GetClassInfoEx (USER.398)
1223 * FIXME: this is just a guess, I have no idea if GetClassInfoEx() is the
1224 * same in Win16 as in Win32. --AJ
1226 BOOL16 WINAPI GetClassInfoEx16( HINSTANCE16 hInst16, SEGPTR name, WNDCLASSEX16 *wc )
1230 HINSTANCE hInstance = HINSTANCE_32(GetExePtr( hInst16 ));
1232 TRACE("%p %s %p\n",hInstance,debugstr_a( MapSL(name) ), wc);
1234 if (!(atom = GlobalFindAtomA( MapSL(name) )) ||
1235 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
1236 (hInstance != classPtr->hInstance)) return FALSE;
1237 wc->style = classPtr->style;
1238 wc->lpfnWndProc = CLASS_GetProc( classPtr, WIN_PROC_16 );
1239 wc->cbClsExtra = (INT16)classPtr->cbClsExtra;
1240 wc->cbWndExtra = (INT16)classPtr->cbWndExtra;
1241 wc->hInstance = HINSTANCE_16(classPtr->hInstance);
1242 wc->hIcon = HICON_16(classPtr->hIcon);
1243 wc->hIconSm = HICON_16(classPtr->hIconSm);
1244 wc->hCursor = HCURSOR_16(classPtr->hCursor);
1245 wc->hbrBackground = HBRUSH_16(classPtr->hbrBackground);
1246 wc->lpszClassName = (SEGPTR)0;
1247 wc->lpszMenuName = CLASS_GetMenuName16( classPtr );
1248 wc->lpszClassName = name;
1250 /* We must return the atom of the class here instead of just TRUE. */
1255 /***********************************************************************
1256 * GetClassInfoExA (USER32.@)
1258 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name,
1264 TRACE("%p %p %p\n",hInstance, name, wc);
1266 if (!(atom = GlobalFindAtomA( name )) ||
1267 !(classPtr = CLASS_FindClassByAtom( atom, hInstance ))
1268 /*|| (hInstance != classPtr->hInstance) */ ) return FALSE;
1269 wc->style = classPtr->style;
1270 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32A );
1271 wc->cbClsExtra = classPtr->cbClsExtra;
1272 wc->cbWndExtra = classPtr->cbWndExtra;
1273 wc->hInstance = classPtr->hInstance;
1274 wc->hIcon = (HICON)classPtr->hIcon;
1275 wc->hIconSm = (HICON)classPtr->hIconSm;
1276 wc->hCursor = (HCURSOR)classPtr->hCursor;
1277 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1278 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1279 wc->lpszClassName = name;
1281 /* We must return the atom of the class here instead of just TRUE. */
1286 /***********************************************************************
1287 * GetClassInfoExW (USER32.@)
1289 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name,
1295 TRACE("%p %p %p\n",hInstance, name, wc);
1297 if (!(atom = GlobalFindAtomW( name )) ||
1298 !(classPtr = CLASS_FindClassByAtom( atom, hInstance )) ||
1299 (hInstance != classPtr->hInstance)) return FALSE;
1300 wc->style = classPtr->style;
1301 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32W );
1302 wc->cbClsExtra = classPtr->cbClsExtra;
1303 wc->cbWndExtra = classPtr->cbWndExtra;
1304 wc->hInstance = classPtr->hInstance;
1305 wc->hIcon = (HICON)classPtr->hIcon;
1306 wc->hIconSm = (HICON)classPtr->hIconSm;
1307 wc->hCursor = (HCURSOR)classPtr->hCursor;
1308 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1309 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1310 wc->lpszClassName = name;
1312 /* We must return the atom of the class here instead of just TRUE. */
1317 #if 0 /* toolhelp is in kernel, so this cannot work */
1319 /***********************************************************************
1320 * ClassFirst (TOOLHELP.69)
1322 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1324 TRACE("%p\n",pClassEntry);
1325 pClassEntry->wNext = 1;
1326 return ClassNext16( pClassEntry );
1330 /***********************************************************************
1331 * ClassNext (TOOLHELP.70)
1333 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1336 CLASS *class = firstClass;
1338 TRACE("%p\n",pClassEntry);
1340 if (!pClassEntry->wNext) return FALSE;
1341 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1344 pClassEntry->wNext = 0;
1347 pClassEntry->hInst = class->hInstance;
1348 pClassEntry->wNext++;
1349 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1350 sizeof(pClassEntry->szClassName) );