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"
35 #include "wine/winbase16.h"
39 #include "wine/winuser16.h"
40 #include "wine/unicode.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(class);
50 typedef struct tagCLASS
52 struct tagCLASS
*next
; /* Next class */
53 struct tagCLASS
*prev
; /* Prev class */
54 UINT cWindows
; /* Count of existing windows */
55 UINT style
; /* Class style */
56 HWINDOWPROC winprocA
; /* Window procedure (ASCII) */
57 HWINDOWPROC winprocW
; /* Window procedure (Unicode) */
58 INT cbClsExtra
; /* Class extra bytes */
59 INT cbWndExtra
; /* Window extra bytes */
60 LPWSTR menuName
; /* Default menu name (Unicode followed by ASCII) */
61 SEGPTR segMenuName
; /* Default menu name as SEGPTR */
62 struct tagDCE
*dce
; /* Class DCE (if CS_CLASSDC) */
63 HINSTANCE hInstance
; /* Module that created the task */
64 HICON hIcon
; /* Default icon */
65 HICON hIconSm
; /* Default small icon */
66 HCURSOR hCursor
; /* Default cursor */
67 HBRUSH hbrBackground
; /* Default background */
68 ATOM atomName
; /* Name of the class */
71 static CLASS
*firstClass
;
73 /***********************************************************************
76 static CLASS
*get_class_ptr( HWND hwnd
, BOOL write_access
)
78 WND
*ptr
= WIN_GetPtr( hwnd
);
82 if (ptr
!= WND_OTHER_PROCESS
) return ptr
->class;
83 if (IsWindow( hwnd
)) /* check other processes */
87 /* modifying classes in other processes is not allowed */
88 SetLastError( ERROR_ACCESS_DENIED
);
91 FIXME( "reading from class of other process window %04x\n", hwnd
);
92 /* DbgBreakPoint(); */
95 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
100 /***********************************************************************
103 inline static void release_class_ptr( CLASS
*ptr
)
109 /***********************************************************************
112 * Get the class winproc for a given proc type
114 static WNDPROC16
CLASS_GetProc( CLASS
*classPtr
, WINDOWPROCTYPE type
)
116 HWINDOWPROC proc
= classPtr
->winprocA
;
118 if (classPtr
->winprocW
)
120 /* if we have a Unicode proc, use it if we have no ASCII proc
121 * or if we have both and Unicode was requested
123 if (!proc
|| type
== WIN_PROC_32W
) proc
= classPtr
->winprocW
;
125 return WINPROC_GetProc( proc
, type
);
129 /***********************************************************************
132 * Set the class winproc for a given proc type.
133 * Returns the previous window proc.
135 static WNDPROC16
CLASS_SetProc( CLASS
*classPtr
, WNDPROC newproc
, WINDOWPROCTYPE type
)
137 HWINDOWPROC
*proc
= &classPtr
->winprocA
;
140 if (classPtr
->winprocW
)
142 /* if we have a Unicode proc, use it if we have no ASCII proc
143 * or if we have both and Unicode was requested
145 if (!*proc
|| type
== WIN_PROC_32W
) proc
= &classPtr
->winprocW
;
147 ret
= WINPROC_GetProc( *proc
, type
);
148 WINPROC_SetProc( proc
, (HWINDOWPROC
)newproc
, type
, WIN_PROC_CLASS
);
149 /* now free the one that we didn't set */
150 if (classPtr
->winprocA
&& classPtr
->winprocW
)
152 if (proc
== &classPtr
->winprocA
)
154 WINPROC_FreeProc( classPtr
->winprocW
, WIN_PROC_CLASS
);
155 classPtr
->winprocW
= 0;
159 WINPROC_FreeProc( classPtr
->winprocA
, WIN_PROC_CLASS
);
160 classPtr
->winprocA
= 0;
167 /***********************************************************************
170 * Get the menu name as a ASCII string.
172 inline static LPSTR
CLASS_GetMenuNameA( CLASS
*classPtr
)
174 if (!HIWORD(classPtr
->menuName
)) return (LPSTR
)classPtr
->menuName
;
175 return (LPSTR
)(classPtr
->menuName
+ strlenW(classPtr
->menuName
) + 1);
179 /***********************************************************************
180 * CLASS_GetMenuName16
182 * Get the menu name as a SEGPTR.
184 inline static SEGPTR
CLASS_GetMenuName16( CLASS
*classPtr
)
186 if (!HIWORD(classPtr
->menuName
)) return (SEGPTR
)classPtr
->menuName
;
187 if (!classPtr
->segMenuName
)
188 classPtr
->segMenuName
= MapLS( CLASS_GetMenuNameA(classPtr
) );
189 return classPtr
->segMenuName
;
193 /***********************************************************************
196 * Get the menu name as a Unicode string.
198 inline static LPWSTR
CLASS_GetMenuNameW( CLASS
*classPtr
)
200 return classPtr
->menuName
;
204 /***********************************************************************
207 * Set the menu name in a class structure by copying the string.
209 static void CLASS_SetMenuNameA( CLASS
*classPtr
, LPCSTR name
)
211 UnMapLS( classPtr
->segMenuName
);
212 classPtr
->segMenuName
= 0;
213 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
216 DWORD lenA
= strlen(name
) + 1;
217 DWORD lenW
= MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, NULL
, 0 );
218 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
219 MultiByteToWideChar( CP_ACP
, 0, name
, lenA
, classPtr
->menuName
, lenW
);
220 memcpy( classPtr
->menuName
+ lenW
, name
, lenA
);
222 else classPtr
->menuName
= (LPWSTR
)name
;
226 /***********************************************************************
229 * Set the menu name in a class structure by copying the string.
231 static void CLASS_SetMenuNameW( CLASS
*classPtr
, LPCWSTR name
)
233 UnMapLS( classPtr
->segMenuName
);
234 classPtr
->segMenuName
= 0;
235 if (HIWORD(classPtr
->menuName
)) HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
238 DWORD lenW
= strlenW(name
) + 1;
239 DWORD lenA
= WideCharToMultiByte( CP_ACP
, 0, name
, lenW
, NULL
, 0, NULL
, NULL
);
240 classPtr
->menuName
= HeapAlloc( GetProcessHeap(), 0, lenA
+ lenW
*sizeof(WCHAR
) );
241 memcpy( classPtr
->menuName
, name
, lenW
*sizeof(WCHAR
) );
242 WideCharToMultiByte( CP_ACP
, 0, name
, lenW
,
243 (char *)(classPtr
->menuName
+ lenW
), lenA
, NULL
, NULL
);
245 else classPtr
->menuName
= (LPWSTR
)name
;
249 /***********************************************************************
252 * Free a class structure.
254 static BOOL
CLASS_FreeClass( CLASS
*classPtr
)
256 TRACE("%p\n", classPtr
);
258 /* Check if we can remove this class */
260 if (classPtr
->cWindows
> 0)
262 SetLastError( ERROR_CLASS_HAS_WINDOWS
);
266 /* Remove the class from the linked list */
268 if (classPtr
->next
) classPtr
->next
->prev
= classPtr
->prev
;
269 if (classPtr
->prev
) classPtr
->prev
->next
= classPtr
->next
;
270 else firstClass
= classPtr
->next
;
272 /* Delete the class */
274 if (classPtr
->dce
) DCE_FreeDCE( classPtr
->dce
);
275 if (classPtr
->hbrBackground
> (HBRUSH
)(COLOR_GRADIENTINACTIVECAPTION
+ 1))
276 DeleteObject( classPtr
->hbrBackground
);
277 GlobalDeleteAtom( classPtr
->atomName
);
278 WINPROC_FreeProc( classPtr
->winprocA
, WIN_PROC_CLASS
);
279 WINPROC_FreeProc( classPtr
->winprocW
, WIN_PROC_CLASS
);
280 UnMapLS( classPtr
->segMenuName
);
281 HeapFree( GetProcessHeap(), 0, classPtr
->menuName
);
282 HeapFree( GetProcessHeap(), 0, classPtr
);
287 /***********************************************************************
288 * CLASS_FreeModuleClasses
290 void CLASS_FreeModuleClasses( HMODULE16 hModule
)
294 TRACE("0x%08x\n", hModule
);
297 for (ptr
= firstClass
; ptr
; ptr
= next
)
300 if (ptr
->hInstance
== hModule
) CLASS_FreeClass( ptr
);
306 /***********************************************************************
307 * CLASS_FindClassByAtom
309 * Return a pointer to the class.
310 * hinstance has been normalized by the caller.
313 * 980805 a local class will be found now if registred with hInst=0
314 * and looed up with a hInst!=0. msmoney does it (jsch)
316 * Local class registered with a USER instance handle are found as if
317 * they were global classes.
319 static CLASS
*CLASS_FindClassByAtom( ATOM atom
, HINSTANCE hinstance
)
321 CLASS
* class, *tclass
= 0, *user_class
= 0;
322 HINSTANCE16 hUser
= GetModuleHandle16("USER");
324 TRACE("0x%08x 0x%08x\n", atom
, hinstance
);
326 /* First search task-specific classes */
328 for (class = firstClass
; (class); class = class->next
)
330 if (class->style
& CS_GLOBALCLASS
) continue;
331 if (class->atomName
== atom
)
333 if (hinstance
==class->hInstance
|| hinstance
==0xffff)
335 TRACE("-- found local %p\n", class);
338 if (class->hInstance
== 0) tclass
= class;
339 else if(class->hInstance
== hUser
)
346 /* Then search global classes */
348 for (class = firstClass
; (class); class = class->next
)
350 if (!(class->style
& CS_GLOBALCLASS
)) continue;
351 if (class->atomName
== atom
)
353 TRACE("-- found global %p\n", class);
358 /* Check if there was a local class registered with USER */
361 TRACE("--found local USER class %p\n", user_class
);
365 /* Then check if there was a local class with hInst=0*/
368 WARN("-- found local Class registred with hInst=0\n");
372 TRACE("-- not found\n");
377 /***********************************************************************
378 * CLASS_RegisterClass
380 * The real RegisterClass() functionality.
382 static CLASS
*CLASS_RegisterClass( ATOM atom
, HINSTANCE hInstance
,
383 DWORD style
, INT classExtra
, INT winExtra
)
387 TRACE("atom=0x%x hinst=0x%x style=0x%lx clExtr=0x%x winExtr=0x%x\n",
388 atom
, hInstance
, style
, classExtra
, winExtra
);
390 /* Check if a class with this name already exists */
391 classPtr
= CLASS_FindClassByAtom( atom
, hInstance
);
394 /* Class can be created only if it is local and */
395 /* if the class with the same name is global. */
397 if ((style
& CS_GLOBALCLASS
) || !(classPtr
->style
& CS_GLOBALCLASS
))
399 SetLastError( ERROR_CLASS_ALREADY_EXISTS
);
404 /* Fix the extra bytes value */
406 if (classExtra
< 0) classExtra
= 0;
407 else if (classExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
408 WARN("Class extra bytes %d is > 40\n", classExtra
);
409 if (winExtra
< 0) winExtra
= 0;
410 else if (winExtra
> 40) /* Extra bytes are limited to 40 in Win32 */
411 WARN("Win extra bytes %d is > 40\n", winExtra
);
413 /* Create the class */
415 classPtr
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CLASS
) + classExtra
);
416 if (!classPtr
) return NULL
;
417 classPtr
->style
= style
;
418 classPtr
->cbWndExtra
= winExtra
;
419 classPtr
->cbClsExtra
= classExtra
;
420 classPtr
->hInstance
= hInstance
;
421 classPtr
->atomName
= atom
;
422 classPtr
->dce
= (style
& CS_CLASSDC
) ? DCE_AllocDCE( 0, DCE_CLASS_DC
) : NULL
;
424 /* Other non-null values must be set by caller */
426 if ((classPtr
->next
= firstClass
)) firstClass
->prev
= classPtr
;
427 firstClass
= classPtr
;
432 /***********************************************************************
433 * CLASS_UnregisterClass
435 * The real UnregisterClass() functionality.
437 static BOOL
CLASS_UnregisterClass( ATOM atom
, HINSTANCE hInstance
)
444 (classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) &&
445 (!hInstance
|| classPtr
->hInstance
== hInstance
))
447 ret
= CLASS_FreeClass( classPtr
);
449 else SetLastError( ERROR_CLASS_DOES_NOT_EXIST
);
456 /***********************************************************************
457 * CLASS_RegisterBuiltinClass
459 * Register a builtin control class.
460 * This allows having both ASCII and Unicode winprocs for the same class.
462 ATOM
CLASS_RegisterBuiltinClass( const struct builtin_class_descr
*descr
)
467 if (!(atom
= GlobalAddAtomA( descr
->name
))) return 0;
469 if (!(classPtr
= CLASS_RegisterClass( atom
, 0, descr
->style
, 0, descr
->extra
)))
471 GlobalDeleteAtom( atom
);
475 classPtr
->hCursor
= LoadCursorA( 0, descr
->cursor
);
476 classPtr
->hbrBackground
= descr
->brush
;
478 if (descr
->procA
) WINPROC_SetProc( &classPtr
->winprocA
, (HWINDOWPROC
)descr
->procA
,
479 WIN_PROC_32A
, WIN_PROC_CLASS
);
480 if (descr
->procW
) WINPROC_SetProc( &classPtr
->winprocW
, (HWINDOWPROC
)descr
->procW
,
481 WIN_PROC_32W
, WIN_PROC_CLASS
);
486 /***********************************************************************
489 * Add a new window using this class, and return the necessary
490 * information for creating the window.
492 CLASS
*CLASS_AddWindow( ATOM atom
, HINSTANCE inst
, WINDOWPROCTYPE type
,
493 INT
*winExtra
, WNDPROC
*winproc
, DWORD
*style
, struct tagDCE
**dce
)
496 if (type
== WIN_PROC_16
) inst
= GetExePtr(inst
);
498 if (!(class = CLASS_FindClassByAtom( atom
, inst
))) return NULL
;
501 if (type
== WIN_PROC_32W
)
503 if (!(*winproc
= class->winprocW
)) *winproc
= class->winprocA
;
507 if (!(*winproc
= class->winprocA
)) *winproc
= class->winprocW
;
509 *winExtra
= class->cbWndExtra
;
510 *style
= class->style
;
516 /***********************************************************************
519 * Remove a window from the class window count.
521 void CLASS_RemoveWindow( CLASS
*cls
)
523 if (cls
&& cls
->cWindows
) cls
->cWindows
--;
527 /***********************************************************************
528 * RegisterClass (USER.57)
530 ATOM WINAPI
RegisterClass16( const WNDCLASS16
*wc
)
534 int iSmIconWidth
, iSmIconHeight
;
535 HINSTANCE16 hInstance
=GetExePtr(wc
->hInstance
);
537 if (!(atom
= GlobalAddAtomA( MapSL(wc
->lpszClassName
) ))) return 0;
538 if (!(classPtr
= CLASS_RegisterClass( atom
, hInstance
, wc
->style
,
539 wc
->cbClsExtra
, wc
->cbWndExtra
)))
541 GlobalDeleteAtom( atom
);
545 TRACE("atom=%04x wndproc=%08lx hinst=%04x "
546 "bg=%04x style=%08x clsExt=%d winExt=%d class=%p name='%s'\n",
547 atom
, (DWORD
)wc
->lpfnWndProc
, hInstance
,
548 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
549 wc
->cbWndExtra
, classPtr
,
550 HIWORD(wc
->lpszClassName
) ?
551 (char *)MapSL(wc
->lpszClassName
) : "" );
553 iSmIconWidth
= GetSystemMetrics(SM_CXSMICON
);
554 iSmIconHeight
= GetSystemMetrics(SM_CYSMICON
);
556 classPtr
->hIcon
= wc
->hIcon
;
557 classPtr
->hIconSm
= CopyImage(wc
->hIcon
, IMAGE_ICON
,
558 iSmIconWidth
, iSmIconHeight
,
559 LR_COPYFROMRESOURCE
);
560 classPtr
->hCursor
= wc
->hCursor
;
561 classPtr
->hbrBackground
= wc
->hbrBackground
;
563 WINPROC_SetProc( &classPtr
->winprocA
, (HWINDOWPROC
)wc
->lpfnWndProc
,
564 WIN_PROC_16
, WIN_PROC_CLASS
);
565 CLASS_SetMenuNameA( classPtr
, MapSL(wc
->lpszMenuName
) );
571 /***********************************************************************
572 * RegisterClassA (USER32.@)
574 * >0: Unique identifier
577 ATOM WINAPI
RegisterClassA( const WNDCLASSA
* wc
) /* [in] Address of structure with class data */
580 int iSmIconWidth
, iSmIconHeight
;
583 if (!(atom
= GlobalAddAtomA( wc
->lpszClassName
))) return 0;
585 if (!(classPtr
= CLASS_RegisterClass( atom
, wc
->hInstance
, wc
->style
,
586 wc
->cbClsExtra
, wc
->cbWndExtra
)))
588 GlobalDeleteAtom( atom
);
592 TRACE("atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p name='%s'\n",
593 atom
, (DWORD
)wc
->lpfnWndProc
, wc
->hInstance
,
594 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
595 wc
->cbWndExtra
, classPtr
,
596 HIWORD(wc
->lpszClassName
) ? wc
->lpszClassName
: "" );
598 iSmIconWidth
= GetSystemMetrics(SM_CXSMICON
);
599 iSmIconHeight
= GetSystemMetrics(SM_CYSMICON
);
601 classPtr
->hIcon
= wc
->hIcon
;
602 classPtr
->hIconSm
= CopyImage(wc
->hIcon
, IMAGE_ICON
,
603 iSmIconWidth
, iSmIconHeight
,
604 LR_COPYFROMRESOURCE
);
605 classPtr
->hCursor
= (HCURSOR16
)wc
->hCursor
;
606 classPtr
->hbrBackground
= (HBRUSH16
)wc
->hbrBackground
;
608 WINPROC_SetProc( &classPtr
->winprocA
, (HWINDOWPROC
)wc
->lpfnWndProc
,
609 WIN_PROC_32A
, WIN_PROC_CLASS
);
610 CLASS_SetMenuNameA( classPtr
, wc
->lpszMenuName
);
615 /***********************************************************************
616 * RegisterClassW (USER32.@)
618 ATOM WINAPI
RegisterClassW( const WNDCLASSW
* wc
)
621 int iSmIconWidth
, iSmIconHeight
;
624 if (!(atom
= GlobalAddAtomW( wc
->lpszClassName
))) return 0;
626 if (!(classPtr
= CLASS_RegisterClass( atom
, wc
->hInstance
, wc
->style
,
627 wc
->cbClsExtra
, wc
->cbWndExtra
)))
629 GlobalDeleteAtom( atom
);
633 TRACE("atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
634 atom
, (DWORD
)wc
->lpfnWndProc
, wc
->hInstance
,
635 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
636 wc
->cbWndExtra
, classPtr
);
638 iSmIconWidth
= GetSystemMetrics(SM_CXSMICON
);
639 iSmIconHeight
= GetSystemMetrics(SM_CYSMICON
);
641 classPtr
->hIcon
= wc
->hIcon
;
642 classPtr
->hIconSm
= CopyImage(wc
->hIcon
, IMAGE_ICON
,
643 iSmIconWidth
, iSmIconHeight
,
644 LR_COPYFROMRESOURCE
);
645 classPtr
->hCursor
= (HCURSOR16
)wc
->hCursor
;
646 classPtr
->hbrBackground
= (HBRUSH16
)wc
->hbrBackground
;
648 WINPROC_SetProc( &classPtr
->winprocW
, (HWINDOWPROC
)wc
->lpfnWndProc
,
649 WIN_PROC_32W
, WIN_PROC_CLASS
);
650 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
655 /***********************************************************************
656 * RegisterClassEx (USER.397)
658 ATOM WINAPI
RegisterClassEx16( const WNDCLASSEX16
*wc
)
662 HINSTANCE16 hInstance
= GetExePtr( wc
->hInstance
);
664 if (!(atom
= GlobalAddAtomA( MapSL(wc
->lpszClassName
) ))) return 0;
665 if (!(classPtr
= CLASS_RegisterClass( atom
, hInstance
, wc
->style
,
666 wc
->cbClsExtra
, wc
->cbWndExtra
)))
668 GlobalDeleteAtom( atom
);
672 TRACE("atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
673 atom
, (DWORD
)wc
->lpfnWndProc
, hInstance
,
674 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
675 wc
->cbWndExtra
, classPtr
);
677 classPtr
->hIcon
= wc
->hIcon
;
678 classPtr
->hIconSm
= wc
->hIconSm
;
679 classPtr
->hCursor
= wc
->hCursor
;
680 classPtr
->hbrBackground
= wc
->hbrBackground
;
682 WINPROC_SetProc( &classPtr
->winprocA
, (HWINDOWPROC
)wc
->lpfnWndProc
,
683 WIN_PROC_16
, WIN_PROC_CLASS
);
684 CLASS_SetMenuNameA( classPtr
, MapSL(wc
->lpszMenuName
) );
689 /***********************************************************************
690 * RegisterClassExA (USER32.@)
692 ATOM WINAPI
RegisterClassExA( const WNDCLASSEXA
* wc
)
697 if (!(atom
= GlobalAddAtomA( wc
->lpszClassName
))) return 0;
699 if (!(classPtr
= CLASS_RegisterClass( atom
, wc
->hInstance
, wc
->style
,
700 wc
->cbClsExtra
, wc
->cbWndExtra
)))
702 GlobalDeleteAtom( atom
);
706 TRACE("atom=%04x wndproc=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
707 atom
, (DWORD
)wc
->lpfnWndProc
, wc
->hInstance
,
708 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
709 wc
->cbWndExtra
, classPtr
);
711 classPtr
->hIcon
= (HICON16
)wc
->hIcon
;
712 classPtr
->hIconSm
= (HICON16
)wc
->hIconSm
;
713 classPtr
->hCursor
= (HCURSOR16
)wc
->hCursor
;
714 classPtr
->hbrBackground
= (HBRUSH16
)wc
->hbrBackground
;
715 WINPROC_SetProc( &classPtr
->winprocA
, (HWINDOWPROC
)wc
->lpfnWndProc
,
716 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=%08lx hinst=%04x bg=%04x style=%08x clsExt=%d winExt=%d class=%p\n",
740 atom
, (DWORD
)wc
->lpfnWndProc
, wc
->hInstance
,
741 wc
->hbrBackground
, wc
->style
, wc
->cbClsExtra
,
742 wc
->cbWndExtra
, classPtr
);
744 classPtr
->hIcon
= (HICON16
)wc
->hIcon
;
745 classPtr
->hIconSm
= (HICON16
)wc
->hIconSm
;
746 classPtr
->hCursor
= (HCURSOR16
)wc
->hCursor
;
747 classPtr
->hbrBackground
= (HBRUSH16
)wc
->hbrBackground
;
748 WINPROC_SetProc( &classPtr
->winprocW
, (HWINDOWPROC
)wc
->lpfnWndProc
,
749 WIN_PROC_32W
, WIN_PROC_CLASS
);
750 CLASS_SetMenuNameW( classPtr
, wc
->lpszMenuName
);
755 /***********************************************************************
756 * UnregisterClass (USER.403)
758 BOOL16 WINAPI
UnregisterClass16( LPCSTR className
, HINSTANCE16 hInstance
)
760 return UnregisterClassA( className
, GetExePtr( hInstance
) );
763 /***********************************************************************
764 * UnregisterClassA (USER32.@)
767 BOOL WINAPI
UnregisterClassA( LPCSTR className
, HINSTANCE hInstance
)
769 TRACE("%s %x\n",debugres_a(className
), hInstance
);
770 return CLASS_UnregisterClass( GlobalFindAtomA( className
), hInstance
);
773 /***********************************************************************
774 * UnregisterClassW (USER32.@)
776 BOOL WINAPI
UnregisterClassW( LPCWSTR className
, HINSTANCE hInstance
)
778 TRACE("%s %x\n",debugres_w(className
), hInstance
);
779 return CLASS_UnregisterClass( GlobalFindAtomW( className
), hInstance
);
783 /***********************************************************************
784 * GetClassWord (USER32.@)
786 WORD WINAPI
GetClassWord( HWND hwnd
, INT offset
)
791 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
793 TRACE("%x %x\n",hwnd
, offset
);
795 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
797 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
798 retvalue
= GET_WORD((char *)(class + 1) + offset
);
800 SetLastError( ERROR_INVALID_INDEX
);
801 release_class_ptr( class );
806 /***********************************************************************
807 * GetClassLong (USER.131)
809 LONG WINAPI
GetClassLong16( HWND16 hwnd16
, INT16 offset
)
813 HWND hwnd
= (HWND
)(ULONG_PTR
)hwnd16
; /* no need for full handle */
815 TRACE("%x %d\n",hwnd
, offset
);
820 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
821 ret
= (LONG
)CLASS_GetProc( class, WIN_PROC_16
);
822 release_class_ptr( class );
825 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
826 ret
= (LONG
)CLASS_GetMenuName16( class );
827 release_class_ptr( class );
830 return GetClassLongA( hwnd
, offset
);
835 /***********************************************************************
836 * GetClassLongA (USER32.@)
838 LONG WINAPI
GetClassLongA( HWND hwnd
, INT offset
)
843 TRACE("%x %d\n", hwnd
, offset
);
845 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
849 if (offset
<= class->cbClsExtra
- sizeof(LONG
))
850 retvalue
= GET_DWORD((char *)(class + 1) + offset
);
852 SetLastError( ERROR_INVALID_INDEX
);
853 release_class_ptr( class );
859 case GCL_HBRBACKGROUND
:
860 retvalue
= (LONG
)class->hbrBackground
;
863 retvalue
= (LONG
)class->hCursor
;
866 retvalue
= (LONG
)class->hIcon
;
869 retvalue
= (LONG
)class->hIconSm
;
872 retvalue
= (LONG
)class->style
;
875 retvalue
= (LONG
)class->cbWndExtra
;
878 retvalue
= (LONG
)class->cbClsExtra
;
881 retvalue
= (LONG
)class->hInstance
;
884 retvalue
= (LONG
)CLASS_GetProc( class, WIN_PROC_32A
);
887 retvalue
= (LONG
)CLASS_GetMenuNameA( class );
890 retvalue
= (DWORD
)class->atomName
;
893 SetLastError( ERROR_INVALID_INDEX
);
896 release_class_ptr( class );
901 /***********************************************************************
902 * GetClassLongW (USER32.@)
904 LONG WINAPI
GetClassLongW( HWND hwnd
, INT offset
)
909 if (offset
!= GCL_WNDPROC
&& offset
!= GCL_MENUNAME
)
910 return GetClassLongA( hwnd
, offset
);
912 TRACE("%x %d\n", hwnd
, offset
);
914 if (!(class = get_class_ptr( hwnd
, FALSE
))) return 0;
916 if (offset
== GCL_WNDPROC
)
917 retvalue
= (LONG
)CLASS_GetProc( class, WIN_PROC_32W
);
918 else /* GCL_MENUNAME */
919 retvalue
= (LONG
)CLASS_GetMenuNameW( class );
921 release_class_ptr( class );
926 /***********************************************************************
927 * SetClassWord (USER32.@)
929 WORD WINAPI
SetClassWord( HWND hwnd
, INT offset
, WORD newval
)
934 if (offset
< 0) return SetClassLongA( hwnd
, offset
, (DWORD
)newval
);
936 TRACE("%x %d %x\n", hwnd
, offset
, newval
);
938 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
940 if (offset
<= class->cbClsExtra
- sizeof(WORD
))
942 void *ptr
= (char *)(class + 1) + offset
;
943 retval
= GET_WORD(ptr
);
944 PUT_WORD( ptr
, newval
);
946 else SetLastError( ERROR_INVALID_INDEX
);
948 release_class_ptr( class );
953 /***********************************************************************
954 * SetClassLong (USER.132)
956 LONG WINAPI
SetClassLong16( HWND16 hwnd16
, INT16 offset
, LONG newval
)
960 HWND hwnd
= (HWND
)(ULONG_PTR
)hwnd16
; /* no need for full handle */
962 TRACE("%x %d %lx\n", hwnd
, offset
, newval
);
967 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
968 retval
= (LONG
)CLASS_SetProc( class, (WNDPROC
)newval
, WIN_PROC_16
);
969 release_class_ptr( class );
972 newval
= (LONG
)MapSL( newval
);
975 return SetClassLongA( hwnd
, offset
, newval
);
980 /***********************************************************************
981 * SetClassLongA (USER32.@)
983 LONG WINAPI
SetClassLongA( HWND hwnd
, INT offset
, LONG newval
)
988 TRACE("%x %d %lx\n", hwnd
, offset
, newval
);
990 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
994 if (offset
<= class->cbClsExtra
- sizeof(LONG
))
996 void *ptr
= (char *)(class + 1) + offset
;
997 retval
= GET_DWORD(ptr
);
998 PUT_DWORD( ptr
, newval
);
1000 else SetLastError( ERROR_INVALID_INDEX
);
1005 CLASS_SetMenuNameA( class, (LPCSTR
)newval
);
1006 retval
= 0; /* Old value is now meaningless anyway */
1009 retval
= (LONG
)CLASS_SetProc( class, (WNDPROC
)newval
, WIN_PROC_32A
);
1011 case GCL_HBRBACKGROUND
:
1012 retval
= (LONG
)class->hbrBackground
;
1013 class->hbrBackground
= newval
;
1016 retval
= (LONG
)class->hCursor
;
1017 class->hCursor
= newval
;
1020 retval
= (LONG
)class->hIcon
;
1021 class->hIcon
= newval
;
1024 retval
= (LONG
)class->hIconSm
;
1025 class->hIconSm
= newval
;
1028 retval
= (LONG
)class->style
;
1029 class->style
= newval
;
1031 case GCL_CBWNDEXTRA
:
1032 retval
= (LONG
)class->cbWndExtra
;
1033 class->cbWndExtra
= newval
;
1036 retval
= (LONG
)class->hInstance
;
1037 class->hInstance
= newval
;
1040 retval
= (DWORD
)class->atomName
;
1041 class->atomName
= newval
;
1043 case GCL_CBCLSEXTRA
: /* cannot change this one */
1044 SetLastError( ERROR_INVALID_PARAMETER
);
1047 SetLastError( ERROR_INVALID_INDEX
);
1050 release_class_ptr( class );
1055 /***********************************************************************
1056 * SetClassLongW (USER32.@)
1058 LONG WINAPI
SetClassLongW( HWND hwnd
, INT offset
, LONG newval
)
1063 if (offset
!= GCL_WNDPROC
&& offset
!= GCL_MENUNAME
)
1064 return SetClassLongA( hwnd
, offset
, newval
);
1066 TRACE("%x %d %lx\n", hwnd
, offset
, newval
);
1068 if (!(class = get_class_ptr( hwnd
, TRUE
))) return 0;
1070 if (offset
== GCL_WNDPROC
)
1071 retval
= (LONG
)CLASS_SetProc( class, (WNDPROC
)newval
, WIN_PROC_32W
);
1072 else /* GCL_MENUNAME */
1074 CLASS_SetMenuNameW( class, (LPCWSTR
)newval
);
1075 retval
= 0; /* Old value is now meaningless anyway */
1077 release_class_ptr( class );
1082 /***********************************************************************
1083 * GetClassNameA (USER32.@)
1085 INT WINAPI
GetClassNameA( HWND hwnd
, LPSTR buffer
, INT count
)
1087 INT ret
= GlobalGetAtomNameA( GetClassLongA( hwnd
, GCW_ATOM
), buffer
, count
);
1089 TRACE("%x %s %x\n",hwnd
, debugstr_a(buffer
), count
);
1094 /***********************************************************************
1095 * GetClassNameW (USER32.@)
1097 INT WINAPI
GetClassNameW( HWND hwnd
, LPWSTR buffer
, INT count
)
1099 INT ret
= GlobalGetAtomNameW( GetClassLongW( hwnd
, GCW_ATOM
), buffer
, count
);
1101 TRACE("%x %s %x\n",hwnd
, debugstr_w(buffer
), count
);
1106 /***********************************************************************
1107 * GetClassInfo (USER.404)
1109 BOOL16 WINAPI
GetClassInfo16( HINSTANCE16 hInstance
, SEGPTR name
, WNDCLASS16
*wc
)
1114 TRACE("%x %s %p\n",hInstance
, debugres_a(MapSL(name
)), wc
);
1116 hInstance
= GetExePtr( hInstance
);
1117 if (!(atom
= GlobalFindAtomA( MapSL(name
) )) ||
1118 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)))
1120 if ((hInstance
!= classPtr
->hInstance
) &&
1121 !(classPtr
->style
& CS_GLOBALCLASS
)) /*BWCC likes to pass hInstance=0*/
1123 wc
->style
= (UINT16
)classPtr
->style
;
1124 wc
->lpfnWndProc
= CLASS_GetProc( classPtr
, WIN_PROC_16
);
1125 wc
->cbClsExtra
= (INT16
)classPtr
->cbClsExtra
;
1126 wc
->cbWndExtra
= (INT16
)classPtr
->cbWndExtra
;
1127 wc
->hInstance
= classPtr
->style
& CS_GLOBALCLASS
? GetModuleHandle16("USER") : (HINSTANCE16
)classPtr
->hInstance
;
1128 wc
->hIcon
= classPtr
->hIcon
;
1129 wc
->hCursor
= classPtr
->hCursor
;
1130 wc
->hbrBackground
= classPtr
->hbrBackground
;
1131 wc
->lpszClassName
= name
;
1132 wc
->lpszMenuName
= CLASS_GetMenuName16( classPtr
);
1137 /***********************************************************************
1138 * GetClassInfoA (USER32.@)
1140 BOOL WINAPI
GetClassInfoA( HINSTANCE hInstance
, LPCSTR name
,
1146 TRACE("%x %p %p\n",hInstance
, name
, wc
);
1148 /* workaround: if hInstance=NULL you expect to get the system classes
1149 but this classes (as example from comctl32.dll SysListView) won't be
1150 registered with hInstance=NULL in WINE because of the late loading
1151 of this dll. fixes file dialogs in WinWord95 (jsch)*/
1153 if (!(atom
=GlobalFindAtomA(name
)) || !(classPtr
=CLASS_FindClassByAtom(atom
,hInstance
)))
1156 if (!(classPtr
->style
& CS_GLOBALCLASS
) &&
1157 classPtr
->hInstance
&&
1158 (hInstance
!= classPtr
->hInstance
))
1160 if (hInstance
) return FALSE
;
1161 WARN("systemclass %s (hInst=0) demanded but only class with hInst!=0 found\n",name
);
1164 wc
->style
= classPtr
->style
;
1165 wc
->lpfnWndProc
= (WNDPROC
)CLASS_GetProc( classPtr
, WIN_PROC_32A
);
1166 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1167 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1168 wc
->hInstance
= hInstance
;
1169 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1170 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1171 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1172 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1173 wc
->lpszClassName
= name
;
1178 /***********************************************************************
1179 * GetClassInfoW (USER32.@)
1181 BOOL WINAPI
GetClassInfoW( HINSTANCE hInstance
, LPCWSTR name
,
1187 TRACE("%x %p %p\n",hInstance
, name
, wc
);
1189 if ( !(atom
=GlobalFindAtomW(name
)) ||
1190 !(classPtr
=CLASS_FindClassByAtom(atom
,hInstance
))
1194 if (!(classPtr
->style
& CS_GLOBALCLASS
) &&
1195 classPtr
->hInstance
&&
1196 (hInstance
!= classPtr
->hInstance
))
1198 if (hInstance
) return FALSE
;
1199 WARN("systemclass %s (hInst=0) demanded but only class with hInst!=0 found\n",debugstr_w(name
));
1201 wc
->style
= classPtr
->style
;
1202 wc
->lpfnWndProc
= (WNDPROC
)CLASS_GetProc( classPtr
, WIN_PROC_32W
);
1203 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1204 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1205 wc
->hInstance
= hInstance
;
1206 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1207 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1208 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1209 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1210 wc
->lpszClassName
= name
;
1215 /***********************************************************************
1216 * GetClassInfoEx (USER.398)
1218 * FIXME: this is just a guess, I have no idea if GetClassInfoEx() is the
1219 * same in Win16 as in Win32. --AJ
1221 BOOL16 WINAPI
GetClassInfoEx16( HINSTANCE16 hInstance
, SEGPTR name
, WNDCLASSEX16
*wc
)
1226 TRACE("%x %s %p\n",hInstance
,debugres_a( MapSL(name
) ), wc
);
1228 hInstance
= GetExePtr( hInstance
);
1229 if (!(atom
= GlobalFindAtomA( MapSL(name
) )) ||
1230 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
1231 (hInstance
!= classPtr
->hInstance
)) return FALSE
;
1232 wc
->style
= classPtr
->style
;
1233 wc
->lpfnWndProc
= CLASS_GetProc( classPtr
, WIN_PROC_16
);
1234 wc
->cbClsExtra
= (INT16
)classPtr
->cbClsExtra
;
1235 wc
->cbWndExtra
= (INT16
)classPtr
->cbWndExtra
;
1236 wc
->hInstance
= (HINSTANCE16
)classPtr
->hInstance
;
1237 wc
->hIcon
= classPtr
->hIcon
;
1238 wc
->hIconSm
= classPtr
->hIconSm
;
1239 wc
->hCursor
= classPtr
->hCursor
;
1240 wc
->hbrBackground
= classPtr
->hbrBackground
;
1241 wc
->lpszClassName
= (SEGPTR
)0;
1242 wc
->lpszMenuName
= CLASS_GetMenuName16( classPtr
);
1243 wc
->lpszClassName
= name
;
1245 /* We must return the atom of the class here instead of just TRUE. */
1250 /***********************************************************************
1251 * GetClassInfoExA (USER32.@)
1253 BOOL WINAPI
GetClassInfoExA( HINSTANCE hInstance
, LPCSTR name
,
1259 TRACE("%x %p %p\n",hInstance
, name
, wc
);
1261 if (!(atom
= GlobalFindAtomA( name
)) ||
1262 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
))
1263 /*|| (hInstance != classPtr->hInstance) */ ) return FALSE
;
1264 wc
->style
= classPtr
->style
;
1265 wc
->lpfnWndProc
= (WNDPROC
)CLASS_GetProc( classPtr
, WIN_PROC_32A
);
1266 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1267 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1268 wc
->hInstance
= classPtr
->hInstance
;
1269 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1270 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1271 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1272 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1273 wc
->lpszMenuName
= CLASS_GetMenuNameA( classPtr
);
1274 wc
->lpszClassName
= name
;
1276 /* We must return the atom of the class here instead of just TRUE. */
1281 /***********************************************************************
1282 * GetClassInfoExW (USER32.@)
1284 BOOL WINAPI
GetClassInfoExW( HINSTANCE hInstance
, LPCWSTR name
,
1290 TRACE("%x %p %p\n",hInstance
, name
, wc
);
1292 if (!(atom
= GlobalFindAtomW( name
)) ||
1293 !(classPtr
= CLASS_FindClassByAtom( atom
, hInstance
)) ||
1294 (hInstance
!= classPtr
->hInstance
)) return FALSE
;
1295 wc
->style
= classPtr
->style
;
1296 wc
->lpfnWndProc
= (WNDPROC
)CLASS_GetProc( classPtr
, WIN_PROC_32W
);
1297 wc
->cbClsExtra
= classPtr
->cbClsExtra
;
1298 wc
->cbWndExtra
= classPtr
->cbWndExtra
;
1299 wc
->hInstance
= classPtr
->hInstance
;
1300 wc
->hIcon
= (HICON
)classPtr
->hIcon
;
1301 wc
->hIconSm
= (HICON
)classPtr
->hIconSm
;
1302 wc
->hCursor
= (HCURSOR
)classPtr
->hCursor
;
1303 wc
->hbrBackground
= (HBRUSH
)classPtr
->hbrBackground
;
1304 wc
->lpszMenuName
= CLASS_GetMenuNameW( classPtr
);
1305 wc
->lpszClassName
= name
;
1307 /* We must return the atom of the class here instead of just TRUE. */
1312 #if 0 /* toolhelp is in kernel, so this cannot work */
1314 /***********************************************************************
1315 * ClassFirst (TOOLHELP.69)
1317 BOOL16 WINAPI
ClassFirst16( CLASSENTRY
*pClassEntry
)
1319 TRACE("%p\n",pClassEntry
);
1320 pClassEntry
->wNext
= 1;
1321 return ClassNext16( pClassEntry
);
1325 /***********************************************************************
1326 * ClassNext (TOOLHELP.70)
1328 BOOL16 WINAPI
ClassNext16( CLASSENTRY
*pClassEntry
)
1331 CLASS
*class = firstClass
;
1333 TRACE("%p\n",pClassEntry
);
1335 if (!pClassEntry
->wNext
) return FALSE
;
1336 for (i
= 1; (i
< pClassEntry
->wNext
) && class; i
++) class = class->next
;
1339 pClassEntry
->wNext
= 0;
1342 pClassEntry
->hInst
= class->hInstance
;
1343 pClassEntry
->wNext
++;
1344 GlobalGetAtomNameA( class->atomName
, pClassEntry
->szClassName
,
1345 sizeof(pClassEntry
->szClassName
) );