2 * PROJECT: ReactOS user32.dll
3 * COPYRIGHT: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/user32/windows/class.c
5 * PURPOSE: Window classes
6 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 09-05-2001 CSH Created
13 #include <wine/debug.h>
14 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
16 /* From rtl/actctx.c and must match! */
19 DWORD kind
; // Activation context type
20 WCHAR
*name
; // Class name
21 WCHAR
*clsid
; // Not supported yet but needed for menu name.
26 WCHAR
*name
; // Dll name
36 LPCWSTR
*plpLibFileName
,
41 UNICODE_STRING SectionName
;
42 WCHAR SeactionNameBuf
[MAX_PATH
] = {0};
43 ACTCTX_SECTION_KEYED_DATA KeyedData
= { sizeof(KeyedData
) };
45 if (IS_ATOM(lpszClass
))
47 SectionName
.Buffer
= (LPWSTR
)&SeactionNameBuf
;
48 SectionName
.MaximumLength
= sizeof(SeactionNameBuf
);
49 if(!NtUserGetAtomName(LOWORD((DWORD_PTR
)lpszClass
), &SectionName
))
58 RtlCreateUnicodeStringFromAsciiz(&SectionName
, (LPSTR
)lpszClass
);
62 RtlInitUnicodeString(&SectionName
, lpszClass
);
65 Status
= RtlFindActivationContextSectionString( FIND_ACTCTX_SECTION_KEY_RETURN_HACTCTX
,
67 ACTIVATION_CONTEXT_SECTION_WINDOW_CLASS_REDIRECTION
,
71 if (NT_SUCCESS(Status
) && KeyedData
.ulDataFormatVersion
== 1)
73 struct dll_redirect
*dll
= KeyedData
.lpSectionBase
;
75 if (plpLibFileName
) *plpLibFileName
= dll
->name
;
83 struct entity
*entity
= KeyedData
.lpData
;
85 FIXME("actctx: Needs to support menu name from redirected class!");
89 mnubuf
= entity
->clsid
;
92 mnuNameA
= (LPSTR
)lpszMenuName
;
93 RtlUnicodeToMultiByteN( mnuNameA
, 255, (PULONG
)&len
, mnubuf
, strlenW(mnubuf
) * sizeof(WCHAR
) );
98 mnuNameW
= (LPWSTR
)lpszMenuName
;
99 len
= strlenW(mnubuf
) * sizeof(WCHAR
);
100 RtlCopyMemory((void *)mnuNameW
, mnubuf
, len
);
105 if (pContext
) *pContext
= KeyedData
.hActCtx
;
108 if (!IS_ATOM(lpszClass
) && bAnsi
)
109 RtlFreeUnicodeString(&SectionName
);
110 if (KeyedData
.hActCtx
)
111 RtlReleaseActivationContext(KeyedData
.hActCtx
);
117 // Ref: http://yvs-it.blogspot.com/2010/04/initcommoncontrolsex.html
121 Real_VersionRegisterClass(
123 LPCWSTR lpLibFileName
,
125 HMODULE
* phLibModule
)
129 PREGISTERCLASSNAMEW pRegisterClassNameW
;
130 UNICODE_STRING ClassName
;
131 WCHAR ClassNameBuf
[MAX_PATH
] = {0};
132 RTL_CALLER_ALLOCATED_ACTIVATION_CONTEXT_STACK_FRAME_EXTENDED Frame
= { sizeof(Frame
), 1 };
134 RtlActivateActivationContextUnsafeFast(&Frame
, Contex
);
141 hLibModule
= LoadLibraryW(lpLibFileName
);
144 if ((pRegisterClassNameW
= (void*) GetProcAddress(hLibModule
, "RegisterClassNameW")))
146 if (IS_ATOM(pszClass
))
148 ClassName
.Buffer
= (LPWSTR
)&ClassNameBuf
;
149 ClassName
.MaximumLength
= sizeof(ClassNameBuf
);
150 if (!NtUserGetAtomName(LOWORD((DWORD_PTR
)pszClass
), &ClassName
))
152 _SEH2_YIELD(goto Error_Exit
);
154 pszClass
= (PCWSTR
)&ClassNameBuf
;
156 Ret
= pRegisterClassNameW(pszClass
);
160 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
166 if ( Ret
|| !hLibModule
)
168 if ( phLibModule
) *phLibModule
= hLibModule
;
172 DWORD save_error
= GetLastError();
173 FreeLibrary(hLibModule
);
174 SetLastError(save_error
);
181 // Use wine hack to process extened context classes.
183 /***********************************************************************
186 static BOOL
is_comctl32_class( const WCHAR
*name
)
188 static const WCHAR classesW
[][20] =
190 {'C','o','m','b','o','B','o','x','E','x','3','2',0},
191 {'m','s','c','t','l','s','_','h','o','t','k','e','y','3','2',0},
192 {'m','s','c','t','l','s','_','p','r','o','g','r','e','s','s','3','2',0},
193 {'m','s','c','t','l','s','_','s','t','a','t','u','s','b','a','r','3','2',0},
194 {'m','s','c','t','l','s','_','t','r','a','c','k','b','a','r','3','2',0},
195 {'m','s','c','t','l','s','_','u','p','d','o','w','n','3','2',0},
196 {'N','a','t','i','v','e','F','o','n','t','C','t','l',0},
197 {'R','e','B','a','r','W','i','n','d','o','w','3','2',0},
198 {'S','y','s','A','n','i','m','a','t','e','3','2',0},
199 {'S','y','s','D','a','t','e','T','i','m','e','P','i','c','k','3','2',0},
200 {'S','y','s','H','e','a','d','e','r','3','2',0},
201 {'S','y','s','I','P','A','d','d','r','e','s','s','3','2',0},
202 {'S','y','s','L','i','s','t','V','i','e','w','3','2',0},
203 {'S','y','s','M','o','n','t','h','C','a','l','3','2',0},
204 {'S','y','s','P','a','g','e','r',0},
205 {'S','y','s','T','a','b','C','o','n','t','r','o','l','3','2',0},
206 {'S','y','s','T','r','e','e','V','i','e','w','3','2',0},
207 {'T','o','o','l','b','a','r','W','i','n','d','o','w','3','2',0},
208 {'t','o','o','l','t','i','p','s','_','c','l','a','s','s','3','2',0},
211 int min
= 0, max
= (sizeof(classesW
) / sizeof(classesW
[0])) - 1;
215 int res
, pos
= (min
+ max
) / 2;
216 if (!(res
= strcmpiW( name
, classesW
[pos
] ))) return TRUE
;
217 if (res
< 0) max
= pos
- 1;
225 VersionRegisterClass(
227 LPCWSTR lpLibFileName
,
229 HMODULE
* phLibModule
)
231 // Should be lpLibFileName.....
232 static const WCHAR comctl32W
[] = {'c','o','m','c','t','l','3','2','.','d','l','l',0};
234 PREGISTERCLASSNAMEW pRegisterClassNameW
;
235 UNICODE_STRING ClassName
;
236 WCHAR ClassNameBuf
[MAX_PATH
] = {0};
238 HMODULE hLibModule
= NULL
;
240 if (!IS_ATOM(pszClass
) && is_comctl32_class( pszClass
))
244 hLibModule
= LoadLibraryW(comctl32W
);
247 if ((pRegisterClassNameW
= (void*) GetProcAddress(hLibModule
, "RegisterClassNameW")))
249 if (IS_ATOM(pszClass
))
251 ClassName
.Buffer
= (LPWSTR
)&ClassNameBuf
;
252 ClassName
.MaximumLength
= sizeof(ClassNameBuf
);
253 if (!NtUserGetAtomName(LOWORD((DWORD_PTR
)pszClass
), &ClassName
))
255 ERR("Error while verifying ATOM\n");
256 _SEH2_YIELD(goto Error_Exit
);
258 pszClass
= (PCWSTR
)&ClassNameBuf
;
260 Ret
= pRegisterClassNameW(pszClass
);
264 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
270 if ( Ret
|| !hLibModule
)
272 if ( phLibModule
) *phLibModule
= hLibModule
;
276 DWORD save_error
= GetLastError();
277 FreeLibrary(hLibModule
);
278 SetLastError(save_error
);
280 TRACE( "%s retrying after loading comctl32\n", debugstr_w(pszClass
) );
283 TRACE("NO ComCtl32 Class %S!\n",pszClass
);
300 UNICODE_STRING ClassName
= {0};
302 HMODULE hLibModule
= NULL
;
304 BOOL Ret
, ClassFound
= FALSE
;
306 TRACE("%p class/atom: %s/%04x %p\n", hInstance
,
307 IS_ATOM(lpszClass
) ? NULL
: lpszClass
,
308 IS_ATOM(lpszClass
) ? lpszClass
: 0,
313 SetLastError( ERROR_NOACCESS
);
317 if (hInstance
== User32Instance
)
322 if (lpszClass
== NULL
)
324 SetLastError(ERROR_INVALID_PARAMETER
);
328 if (IS_ATOM(lpszClass
))
330 ClassName
.Buffer
= (PWSTR
)((ULONG_PTR
)lpszClass
);
334 if (!RtlCreateUnicodeStringFromAsciiz(&ClassName
,
337 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
342 if (!RegisterDefaultClasses
)
344 TRACE("RegisterSystemControls\n");
345 RegisterSystemControls();
350 Ret
= NtUserGetClassInfo( hInstance
,
352 (LPWNDCLASSEXW
)lpwcx
,
353 (LPWSTR
*)&pszMenuName
,
358 save_error
= GetLastError();
359 if ( save_error
== ERROR_CANNOT_FIND_WND_CLASS
||
360 save_error
== ERROR_CLASS_DOES_NOT_EXIST
)
362 ClassFound
= VersionRegisterClass(ClassName
.Buffer
, NULL
, NULL
, &hLibModule
);
363 if (ClassFound
) continue;
368 save_error
= GetLastError();
369 FreeLibrary(hLibModule
);
370 SetLastError(save_error
);
378 lpwcx
->lpszClassName
= lpszClass
;
379 // lpwcx->lpszMenuName = pszMenuName;
382 if (!IS_ATOM(lpszClass
))
384 RtlFreeUnicodeString(&ClassName
);
401 UNICODE_STRING ClassName
= {0};
403 HMODULE hLibModule
= NULL
;
405 BOOL Ret
, ClassFound
= FALSE
;
407 TRACE("%p class/atom: %S/%04x %p\n", hInstance
,
408 IS_ATOM(lpszClass
) ? NULL
: lpszClass
,
409 IS_ATOM(lpszClass
) ? lpszClass
: 0,
412 /* From wine, for speed only, ReactOS supports the correct return in
413 * Win32k. cbSize is ignored.
417 SetLastError( ERROR_NOACCESS
);
421 if (hInstance
== User32Instance
)
426 if (lpszClass
== NULL
)
428 SetLastError(ERROR_INVALID_PARAMETER
);
432 if (IS_ATOM(lpszClass
))
434 ClassName
.Buffer
= (PWSTR
)((ULONG_PTR
)lpszClass
);
438 RtlInitUnicodeString(&ClassName
,
442 if (!RegisterDefaultClasses
)
444 TRACE("RegisterSystemControls\n");
445 RegisterSystemControls();
450 Ret
= NtUserGetClassInfo( hInstance
,
458 save_error
= GetLastError();
459 if ( save_error
== ERROR_CANNOT_FIND_WND_CLASS
||
460 save_error
== ERROR_CLASS_DOES_NOT_EXIST
)
462 ClassFound
= VersionRegisterClass(ClassName
.Buffer
, NULL
, NULL
, &hLibModule
);
463 if (ClassFound
) continue;
468 save_error
= GetLastError();
469 FreeLibrary(hLibModule
);
470 SetLastError(save_error
);
478 lpwcx
->lpszClassName
= lpszClass
;
479 // lpwcx->lpszMenuName = pszMenuName;
493 LPWNDCLASSA lpWndClass
)
498 retval
= GetClassInfoExA(hInstance
, lpClassName
, &wcex
);
501 lpWndClass
->style
= wcex
.style
;
502 lpWndClass
->lpfnWndProc
= wcex
.lpfnWndProc
;
503 lpWndClass
->cbClsExtra
= wcex
.cbClsExtra
;
504 lpWndClass
->cbWndExtra
= wcex
.cbWndExtra
;
505 lpWndClass
->hInstance
= wcex
.hInstance
;
506 lpWndClass
->hIcon
= wcex
.hIcon
;
507 lpWndClass
->hCursor
= wcex
.hCursor
;
508 lpWndClass
->hbrBackground
= wcex
.hbrBackground
;
509 lpWndClass
->lpszMenuName
= wcex
.lpszMenuName
;
510 lpWndClass
->lpszClassName
= wcex
.lpszClassName
;
524 LPWNDCLASSW lpWndClass
)
529 retval
= GetClassInfoExW(hInstance
, lpClassName
, &wcex
);
532 lpWndClass
->style
= wcex
.style
;
533 lpWndClass
->lpfnWndProc
= wcex
.lpfnWndProc
;
534 lpWndClass
->cbClsExtra
= wcex
.cbClsExtra
;
535 lpWndClass
->cbWndExtra
= wcex
.cbWndExtra
;
536 lpWndClass
->hInstance
= wcex
.hInstance
;
537 lpWndClass
->hIcon
= wcex
.hIcon
;
538 lpWndClass
->hCursor
= wcex
.hCursor
;
539 lpWndClass
->hbrBackground
= wcex
.hbrBackground
;
540 lpWndClass
->lpszMenuName
= wcex
.lpszMenuName
;
541 lpWndClass
->lpszClassName
= wcex
.lpszClassName
;
547 // Based on find_winproc... Fixes many whine tests......
550 IntGetClsWndProc(PWND pWnd
, PCLS Class
, BOOL Ansi
)
553 ULONG_PTR gcpd
, Ret
= 0;
554 // If server side, sweep through proc list and return the client side proc.
555 if (Class
->CSF_flags
& CSF_SERVERSIDEPROC
)
556 { // Always scan through the list due to wine class "deftest".
557 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
559 if (GETPFNSERVER(i
) == Class
->lpfnWndProc
)
562 Ret
= (ULONG_PTR
)GETPFNCLIENTA(i
);
564 Ret
= (ULONG_PTR
)GETPFNCLIENTW(i
);
570 Ret
= (ULONG_PTR
)Class
->lpfnWndProc
;
571 // Return the proc if one of the FnId default class type.
572 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
575 { // If match return the right proc by type.
576 if (GETPFNCLIENTW(Class
->fnid
) == Class
->lpfnWndProc
)
577 Ret
= (ULONG_PTR
)GETPFNCLIENTA(Class
->fnid
);
581 if (GETPFNCLIENTA(Class
->fnid
) == Class
->lpfnWndProc
)
582 Ret
= (ULONG_PTR
)GETPFNCLIENTW(Class
->fnid
);
585 // Return on change or Ansi/Unicode proc equal.
586 if ( Ret
!= (ULONG_PTR
)Class
->lpfnWndProc
||
587 Ansi
== !!(Class
->CSF_flags
& CSF_ANSIPROC
) )
590 /* We have an Ansi and Unicode swap! If Ansi create Unicode proc handle.
591 This will force CallWindowProc to deal with it. */
592 gcpd
= NtUserGetCPD( UserHMGetHandle(pWnd
),
593 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWndtoCls
,
596 return (gcpd
? gcpd
: Ret
);
600 // Based on IntGetClsWndProc
603 IntGetWndProc(PWND pWnd
, BOOL Ansi
)
606 WNDPROC gcpd
, Ret
= 0;
607 PCLS Class
= DesktopPtrToUser(pWnd
->pcls
);
609 if (!Class
) return Ret
;
611 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
613 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
615 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
618 Ret
= GETPFNCLIENTA(i
);
620 Ret
= GETPFNCLIENTW(i
);
626 /* Edit controls are special - they return a wndproc handle when
627 GetWindowLongPtr is called with a different A/W.
628 On the other hand there is no W->A->W conversion so this control
629 is treated specially.
631 if (Class
->fnid
== FNID_EDIT
)
632 Ret
= pWnd
->lpfnWndProc
;
636 Ret
= pWnd
->lpfnWndProc
;
638 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
642 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
643 Ret
= GETPFNCLIENTA(Class
->fnid
);
647 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
648 Ret
= GETPFNCLIENTW(Class
->fnid
);
651 // Return on the change.
652 if ( Ret
!= pWnd
->lpfnWndProc
)
656 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
659 gcpd
= (WNDPROC
)NtUserGetCPD( UserHMGetHandle(pWnd
),
660 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
663 return (gcpd
? gcpd
: Ret
);
666 static ULONG_PTR FASTCALL
667 IntGetClassLongA(PWND Wnd
, PCLS Class
, int nIndex
)
673 if (nIndex
+ sizeof(ULONG_PTR
) < nIndex
||
674 nIndex
+ sizeof(ULONG_PTR
) > Class
->cbclsExtra
)
676 SetLastError(ERROR_INVALID_PARAMETER
);
679 Ret
= *(PULONG_PTR
)((ULONG_PTR
)(Class
+ 1) + nIndex
);
686 Ret
= (ULONG_PTR
)Class
->cbwndExtra
;
690 Ret
= (ULONG_PTR
)Class
->cbclsExtra
;
693 case GCL_HBRBACKGROUND
:
694 Ret
= (ULONG_PTR
)Class
->hbrBackground
;
695 if (Ret
!= 0 && Ret
< 0x4000)
696 Ret
= (ULONG_PTR
)GetSysColorBrush((ULONG
)Ret
- 1);
700 //ERR("Cls 0x%x GCL_HMODULE 0x%x\n", Wnd->pcls, Class->hModule);
701 Ret
= (ULONG_PTR
)Class
->hModule
;
705 Ret
= (ULONG_PTR
)Class
->lpszClientAnsiMenuName
;
709 Ret
= (ULONG_PTR
)Class
->style
;
713 Ret
= (ULONG_PTR
)Class
->atomClassName
;
717 /* FIXME - get handle from pointer to CURSOR object */
718 Ret
= (ULONG_PTR
)Class
->hCursor
;
722 /* FIXME - get handle from pointer to ICON object */
723 Ret
= (ULONG_PTR
)Class
->hIcon
;
727 /* FIXME - get handle from pointer to ICON object */
728 Ret
= (ULONG_PTR
)(Class
->hIconSm
? Class
->hIconSm
: Class
->hIconSmIntern
);
732 Ret
= IntGetClsWndProc(Wnd
, Class
, TRUE
);
736 SetLastError(ERROR_INVALID_INDEX
);
744 static ULONG_PTR FASTCALL
745 IntGetClassLongW (PWND Wnd
, PCLS Class
, int nIndex
)
751 if (nIndex
+ sizeof(ULONG_PTR
) < nIndex
||
752 nIndex
+ sizeof(ULONG_PTR
) > Class
->cbclsExtra
)
754 SetLastError(ERROR_INVALID_PARAMETER
);
757 Ret
= *(PULONG_PTR
)((ULONG_PTR
)(Class
+ 1) + nIndex
);
764 Ret
= (ULONG_PTR
)Class
->cbwndExtra
;
768 Ret
= (ULONG_PTR
)Class
->cbclsExtra
;
771 case GCLP_HBRBACKGROUND
:
772 Ret
= (ULONG_PTR
)Class
->hbrBackground
;
773 if (Ret
!= 0 && Ret
< 0x4000)
774 Ret
= (ULONG_PTR
)GetSysColorBrush((ULONG
)Ret
- 1);
778 Ret
= (ULONG_PTR
)Class
->hModule
;
782 Ret
= (ULONG_PTR
)Class
->lpszClientUnicodeMenuName
;
786 Ret
= (ULONG_PTR
)Class
->style
;
790 Ret
= (ULONG_PTR
)Class
->atomClassName
;
794 /* FIXME - get handle from pointer to CURSOR object */
795 Ret
= (ULONG_PTR
)Class
->hCursor
;
799 /* FIXME - get handle from pointer to ICON object */
800 Ret
= (ULONG_PTR
)Class
->hIcon
;
804 /* FIXME - get handle from pointer to ICON object */
805 Ret
= (ULONG_PTR
)(Class
->hIconSm
? Class
->hIconSm
: Class
->hIconSmIntern
);
809 Ret
= IntGetClsWndProc(Wnd
, Class
, FALSE
);
813 SetLastError(ERROR_INVALID_INDEX
);
825 GetClassLongA(HWND hWnd
, int nIndex
)
831 TRACE("%p %d\n", hWnd
, nIndex
);
833 Wnd
= ValidateHwnd(hWnd
);
839 Class
= DesktopPtrToUser(Wnd
->pcls
);
845 case GCLP_HBRBACKGROUND
:
852 SetLastError(ERROR_INVALID_INDEX
);
856 Ret
= IntGetClassLongA(Wnd
, Class
, nIndex
);
860 Ret
= IntGetClassLongA(Wnd
, Class
, nIndex
);
865 WARN("Invalid class for hwnd 0x%p!\n", hWnd
);
868 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
881 GetClassLongW ( HWND hWnd
, int nIndex
)
887 TRACE("%p %d\n", hWnd
, nIndex
);
889 Wnd
= ValidateHwnd(hWnd
);
895 Class
= DesktopPtrToUser(Wnd
->pcls
);
901 case GCLP_HBRBACKGROUND
:
908 SetLastError(ERROR_INVALID_INDEX
);
912 Ret
= IntGetClassLongW(Wnd
, Class
, nIndex
);
916 Ret
= IntGetClassLongW(Wnd
, Class
, nIndex
);
921 WARN("Invalid class for hwnd 0x%p!\n", hWnd
);
924 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
939 GetClassLongPtrA(HWND hWnd
,
946 TRACE("%p %d\n", hWnd
, nIndex
);
948 Wnd
= ValidateHwnd(hWnd
);
954 Class
= DesktopPtrToUser(Wnd
->pcls
);
957 Ret
= IntGetClassLongA(Wnd
, Class
, nIndex
);
961 WARN("Invalid class for hwnd 0x%p!\n", hWnd
);
964 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
978 GetClassLongPtrW(HWND hWnd
,
985 TRACE("%p %d\n", hWnd
, nIndex
);
987 Wnd
= ValidateHwnd(hWnd
);
993 Class
= DesktopPtrToUser(Wnd
->pcls
);
996 Ret
= IntGetClassLongW(Wnd
, Class
, nIndex
);
1000 WARN("Invalid class for hwnd 0x%p!\n", hWnd
);
1003 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1023 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1026 if (nMaxCount
<= 0) return 0;
1027 if (!GetClassNameW( hWnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
1028 RtlUnicodeToMultiByteN( lpClassName
, nMaxCount
- 1, (PULONG
)&len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
1029 lpClassName
[len
] = 0;
1031 TRACE("%p class/atom: %s/%04x %x\n", hWnd
,
1032 IS_ATOM(lpClassName
) ? NULL
: lpClassName
,
1033 IS_ATOM(lpClassName
) ? lpClassName
: 0,
1050 UNICODE_STRING ClassName
;
1053 ClassName
.MaximumLength
= nMaxCount
* sizeof(WCHAR
);
1054 ClassName
.Buffer
= lpClassName
;
1056 Result
= NtUserGetClassName(hWnd
,
1060 TRACE("%p class/atom: %S/%04x %x\n", hWnd
,
1061 IS_ATOM(lpClassName
) ? NULL
: lpClassName
,
1062 IS_ATOM(lpClassName
) ? lpClassName
: 0,
1082 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
1084 Wnd
= ValidateHwnd(hwnd
);
1088 class = DesktopPtrToUser(Wnd
->pcls
);
1089 if (class == NULL
) return 0;
1091 if (offset
<= class->cbclsExtra
- sizeof(WORD
))
1092 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
1094 SetLastError( ERROR_INVALID_INDEX
);
1100 LONG_PTR
IntGetWindowLong( HWND hwnd
, INT offset
, UINT size
, BOOL unicode
)
1102 LONG_PTR retvalue
= 0;
1105 if (offset
== GWLP_HWNDPARENT
)
1107 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
1108 if (parent
== GetDesktopWindow()) parent
= GetWindow( hwnd
, GW_OWNER
);
1109 return (ULONG_PTR
)parent
;
1112 if (!(wndPtr
= ValidateHwnd( hwnd
)))
1114 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1120 if (offset
> (int)(wndPtr
->cbwndExtra
- size
))
1122 WARN("Invalid offset %d\n", offset
);
1123 SetLastError( ERROR_INVALID_INDEX
);
1126 retvalue
= *((LONG_PTR
*)((PCHAR
)(wndPtr
+ 1) + offset
));
1128 /* WINE: special case for dialog window procedure */
1129 //if ((offset == DWLP_DLGPROC) && (size == sizeof(LONG_PTR)) && (wndPtr->flags & WIN_ISDIALOG))
1130 // retvalue = (LONG_PTR)IntGetWndProc( (WNDPROC)retvalue, unicode );
1136 case GWLP_USERDATA
: retvalue
= wndPtr
->dwUserData
; break;
1137 case GWL_STYLE
: retvalue
= wndPtr
->style
; break;
1138 case GWL_EXSTYLE
: retvalue
= wndPtr
->ExStyle
; break;
1139 case GWLP_ID
: retvalue
= wndPtr
->IDMenu
; break;
1140 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wndPtr
->hModule
; break;
1143 if (!TestWindowProcess(wndPtr
))
1145 SetLastError(ERROR_ACCESS_DENIED
);
1148 retvalue
= (ULONG_PTR
)IntGetWndProc(wndPtr
, !unicode
);
1152 WARN("Unknown offset %d\n", offset
);
1153 SetLastError( ERROR_INVALID_INDEX
);
1164 GetWindowLongA ( HWND hWnd
, int nIndex
)
1166 return IntGetWindowLong( hWnd
, nIndex
, sizeof(LONG
), FALSE
);
1174 GetWindowLongW(HWND hWnd
, int nIndex
)
1176 return IntGetWindowLong( hWnd
, nIndex
, sizeof(LONG
), TRUE
);
1185 GetWindowLongPtrA(HWND hWnd
,
1188 return IntGetWindowLong( hWnd
, nIndex
, sizeof(LONG_PTR
), FALSE
);
1196 GetWindowLongPtrW(HWND hWnd
,
1199 return IntGetWindowLong( hWnd
, nIndex
, sizeof(LONG_PTR
), TRUE
);
1209 GetWindowWord(HWND hWnd
, int nIndex
)
1214 case GWLP_HINSTANCE
:
1215 case GWLP_HWNDPARENT
:
1220 WARN("Invalid offset %d\n", nIndex
);
1221 SetLastError( ERROR_INVALID_INDEX
);
1226 return IntGetWindowLong( hWnd
, nIndex
, sizeof(WORD
), FALSE
);
1234 RealGetWindowClassW(
1239 UNICODE_STRING ClassName
;
1240 ClassName
.MaximumLength
= cchType
* sizeof(WCHAR
);
1241 ClassName
.Buffer
= (PWSTR
)pszType
;
1243 return NtUserGetClassName(hwnd
,TRUE
,&ClassName
);
1252 RealGetWindowClassA(
1257 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1260 if ((INT
)cchType
<= 0) return 0;
1261 if (!RealGetWindowClassW( hwnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
1262 RtlUnicodeToMultiByteN( pszType
, cchType
- 1, (PULONG
)&len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
1268 * Create a small icon based on a standard icon
1270 #if 0 // Keep vintage code from revision 18764 by GvG!
1272 CreateSmallIcon(HICON StdIcon
)
1274 HICON SmallIcon
= NULL
;
1277 int SmallIconHeight
;
1278 BITMAP StdBitmapInfo
;
1279 HDC hSourceDc
= NULL
;
1282 HBITMAP OldSourceBitmap
= NULL
;
1283 HBITMAP OldDestBitmap
= NULL
;
1285 SmallInfo
.hbmColor
= NULL
;
1286 SmallInfo
.hbmMask
= NULL
;
1288 /* We need something to work with... */
1289 if (NULL
== StdIcon
)
1294 SmallIconWidth
= GetSystemMetrics(SM_CXSMICON
);
1295 SmallIconHeight
= GetSystemMetrics(SM_CYSMICON
);
1296 if (! GetIconInfo(StdIcon
, &StdInfo
))
1298 ERR("Failed to get icon info for icon 0x%x\n", StdIcon
);
1301 if (! GetObjectW(StdInfo
.hbmMask
, sizeof(BITMAP
), &StdBitmapInfo
))
1303 ERR("Failed to get bitmap info for icon 0x%x bitmap 0x%x\n",
1304 StdIcon
, StdInfo
.hbmColor
);
1307 if (StdBitmapInfo
.bmWidth
== SmallIconWidth
&&
1308 StdBitmapInfo
.bmHeight
== SmallIconHeight
)
1310 /* Icon already has the correct dimensions */
1314 hSourceDc
= CreateCompatibleDC(NULL
);
1315 if (NULL
== hSourceDc
)
1317 ERR("Failed to create source DC\n");
1320 hDestDc
= CreateCompatibleDC(NULL
);
1321 if (NULL
== hDestDc
)
1323 ERR("Failed to create dest DC\n");
1327 OldSourceBitmap
= SelectObject(hSourceDc
, StdInfo
.hbmColor
);
1328 if (NULL
== OldSourceBitmap
)
1330 ERR("Failed to select source color bitmap\n");
1333 SmallInfo
.hbmColor
= CreateCompatibleBitmap(hSourceDc
, SmallIconWidth
,
1335 if (NULL
== SmallInfo
.hbmColor
)
1337 ERR("Failed to create color bitmap\n");
1340 OldDestBitmap
= SelectObject(hDestDc
, SmallInfo
.hbmColor
);
1341 if (NULL
== OldDestBitmap
)
1343 ERR("Failed to select dest color bitmap\n");
1346 if (! StretchBlt(hDestDc
, 0, 0, SmallIconWidth
, SmallIconHeight
,
1347 hSourceDc
, 0, 0, StdBitmapInfo
.bmWidth
,
1348 StdBitmapInfo
.bmHeight
, SRCCOPY
))
1350 ERR("Failed to stretch color bitmap\n");
1354 if (NULL
== SelectObject(hSourceDc
, StdInfo
.hbmMask
))
1356 ERR("Failed to select source mask bitmap\n");
1359 SmallInfo
.hbmMask
= CreateCompatibleBitmap(hSourceDc
, SmallIconWidth
, SmallIconHeight
);
1360 if (NULL
== SmallInfo
.hbmMask
)
1362 ERR("Failed to create mask bitmap\n");
1365 if (NULL
== SelectObject(hDestDc
, SmallInfo
.hbmMask
))
1367 ERR("Failed to select dest mask bitmap\n");
1370 if (! StretchBlt(hDestDc
, 0, 0, SmallIconWidth
, SmallIconHeight
,
1371 hSourceDc
, 0, 0, StdBitmapInfo
.bmWidth
,
1372 StdBitmapInfo
.bmHeight
, SRCCOPY
))
1374 ERR("Failed to stretch mask bitmap\n");
1378 SmallInfo
.fIcon
= TRUE
;
1379 SmallInfo
.xHotspot
= SmallIconWidth
/ 2;
1380 SmallInfo
.yHotspot
= SmallIconHeight
/ 2;
1381 SmallIcon
= CreateIconIndirect(&SmallInfo
);
1382 if (NULL
== SmallIcon
)
1384 ERR("Failed to create icon\n");
1389 if (NULL
!= SmallInfo
.hbmMask
)
1391 DeleteObject(SmallInfo
.hbmMask
);
1393 if (NULL
!= OldDestBitmap
)
1395 SelectObject(hDestDc
, OldDestBitmap
);
1397 if (NULL
!= SmallInfo
.hbmColor
)
1399 DeleteObject(SmallInfo
.hbmColor
);
1401 if (NULL
!= hDestDc
)
1405 if (NULL
!= OldSourceBitmap
)
1407 SelectObject(hSourceDc
, OldSourceBitmap
);
1409 if (NULL
!= hSourceDc
)
1411 DeleteDC(hSourceDc
);
1419 RegisterClassExWOWW(WNDCLASSEXW
*lpwcx
,
1426 WNDCLASSEXW WndClass
;
1427 UNICODE_STRING ClassName
;
1428 UNICODE_STRING MenuName
= {0};
1429 CLSMENUNAME clsMenuName
;
1430 ANSI_STRING AnsiMenuName
;
1431 HMODULE hLibModule
= NULL
;
1433 BOOL ClassFound
= FALSE
;
1435 if (lpwcx
== NULL
|| lpwcx
->cbSize
!= sizeof(WNDCLASSEXW
) ||
1436 lpwcx
->cbClsExtra
< 0 || lpwcx
->cbWndExtra
< 0 ||
1437 lpwcx
->lpszClassName
== NULL
)
1439 TRACE("RegisterClassExWOWW Invalid Parameter Error!\n");
1440 SetLastError(ERROR_INVALID_PARAMETER
);
1446 if (!RegisterDefaultClasses
) RegisterSystemControls();
1449 * On real Windows this looks more like:
1450 * if (lpwcx->hInstance == User32Instance &&
1451 * *(PULONG)((ULONG_PTR)NtCurrentTeb() + 0x6D4) & 0x400)
1452 * But since I have no idea what the magic field in the
1453 * TEB structure means, I rather decided to omit that.
1456 GetWin32ClientInfo()->dwExpWinVer & (WINVER == 0x400)
1458 if (lpwcx
->hInstance
== User32Instance
)
1460 TRACE("RegisterClassExWOWW User32Instance!\n");
1461 SetLastError(ERROR_INVALID_PARAMETER
);
1464 /* Yes, this is correct. We should modify the passed structure. */
1465 if (lpwcx
->hInstance
== NULL
)
1466 ((WNDCLASSEXW
*)lpwcx
)->hInstance
= GetModuleHandleW(NULL
);
1468 RtlCopyMemory(&WndClass
, lpwcx
, sizeof(WNDCLASSEXW
));
1470 if (NULL == WndClass.hIconSm)
1472 WndClass.hIconSm = CreateSmallIcon(WndClass.hIcon);
1475 if (WndClass
.lpszMenuName
!= NULL
)
1477 if (!IS_INTRESOURCE(WndClass
.lpszMenuName
))
1479 if (WndClass
.lpszMenuName
[0])
1481 RtlInitUnicodeString(&MenuName
, WndClass
.lpszMenuName
);
1482 RtlUnicodeStringToAnsiString( &AnsiMenuName
, &MenuName
, TRUE
);
1487 MenuName
.Buffer
= (LPWSTR
)WndClass
.lpszMenuName
;
1488 AnsiMenuName
.Buffer
= (PCHAR
)WndClass
.lpszMenuName
;
1492 if (IS_ATOM(WndClass
.lpszClassName
))
1495 ClassName
.MaximumLength
= 0;
1496 ClassName
.Buffer
= (LPWSTR
)WndClass
.lpszClassName
;
1500 RtlInitUnicodeString(&ClassName
, WndClass
.lpszClassName
);
1503 clsMenuName
.pszClientAnsiMenuName
= AnsiMenuName
.Buffer
;
1504 clsMenuName
.pwszClientUnicodeMenuName
= MenuName
.Buffer
;
1505 clsMenuName
.pusMenuName
= &MenuName
;
1509 Atom
= NtUserRegisterClassExWOW( &WndClass
,
1511 NULL
, //PUNICODE_STRING ClsNVersion,
1520 save_error
= GetLastError();
1521 if ( save_error
== ERROR_CANNOT_FIND_WND_CLASS
||
1522 save_error
== ERROR_CLASS_DOES_NOT_EXIST
)
1524 ClassFound
= VersionRegisterClass(ClassName
.Buffer
, NULL
, NULL
, &hLibModule
);
1525 if (ClassFound
) continue;
1530 save_error
= GetLastError();
1531 FreeLibrary(hLibModule
);
1532 SetLastError(save_error
);
1538 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
1539 Atom
, lpwcx
->lpfnWndProc
, lpwcx
->hInstance
, lpwcx
->hbrBackground
,
1540 lpwcx
->style
, lpwcx
->cbClsExtra
, lpwcx
->cbWndExtra
, WndClass
);
1549 RegisterClassExA(CONST WNDCLASSEXA
*lpwcx
)
1552 WNDCLASSEXW WndClass
;
1553 WCHAR mname
[MAX_BUFFER_LEN
];
1554 WCHAR cname
[MAX_BUFFER_LEN
];
1556 RtlCopyMemory(&WndClass
, lpwcx
, sizeof(WNDCLASSEXA
));
1558 if (WndClass
.lpszMenuName
!= NULL
)
1560 if (!IS_INTRESOURCE(WndClass
.lpszMenuName
))
1562 if (WndClass
.lpszMenuName
[0])
1564 if (!MultiByteToWideChar( CP_ACP
, 0, lpwcx
->lpszMenuName
, -1, mname
, MAX_ATOM_LEN
+ 1 )) return 0;
1566 WndClass
.lpszMenuName
= mname
;
1571 if (!IS_ATOM(WndClass
.lpszClassName
))
1573 if (!MultiByteToWideChar( CP_ACP
, 0, lpwcx
->lpszClassName
, -1, cname
, MAX_ATOM_LEN
+ 1 )) return 0;
1575 WndClass
.lpszClassName
= cname
;
1578 Atom
= RegisterClassExWOWW( &WndClass
,
1584 TRACE("A atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
1585 Atom
, lpwcx
->lpfnWndProc
, lpwcx
->hInstance
, lpwcx
->hbrBackground
,
1586 lpwcx
->style
, lpwcx
->cbClsExtra
, lpwcx
->cbWndExtra
, WndClass
);
1595 RegisterClassExW(CONST WNDCLASSEXW
*lpwcx
)
1599 Atom
= RegisterClassExWOWW( (WNDCLASSEXW
*)lpwcx
, 0, 0, 0, TRUE
);
1601 TRACE("W atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d\n",
1602 Atom
, lpwcx
->lpfnWndProc
, lpwcx
->hInstance
, lpwcx
->hbrBackground
,
1603 lpwcx
->style
, lpwcx
->cbClsExtra
, lpwcx
->cbWndExtra
);
1612 RegisterClassA(CONST WNDCLASSA
*lpWndClass
)
1616 if (lpWndClass
== NULL
)
1619 RtlCopyMemory(&Class
.style
, lpWndClass
, sizeof(WNDCLASSA
));
1620 Class
.cbSize
= sizeof(WNDCLASSEXA
);
1621 Class
.hIconSm
= NULL
;
1623 return RegisterClassExA(&Class
);
1630 RegisterClassW(CONST WNDCLASSW
*lpWndClass
)
1634 if (lpWndClass
== NULL
)
1637 RtlCopyMemory(&Class
.style
, lpWndClass
, sizeof(WNDCLASSW
));
1638 Class
.cbSize
= sizeof(WNDCLASSEXW
);
1639 Class
.hIconSm
= NULL
;
1641 return RegisterClassExW(&Class
);
1649 SetClassLongA (HWND hWnd
,
1653 PSTR lpStr
= (PSTR
)(ULONG_PTR
)dwNewLong
;
1654 UNICODE_STRING Value
= {0};
1655 BOOL Allocated
= FALSE
;
1658 /* FIXME - portability!!!! */
1660 if (nIndex
== GCL_MENUNAME
&& lpStr
!= NULL
)
1662 if (!IS_INTRESOURCE(lpStr
))
1664 if (!RtlCreateUnicodeStringFromAsciiz(&Value
,
1667 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1674 Value
.Buffer
= (PWSTR
)lpStr
;
1676 dwNewLong
= (LONG_PTR
)&Value
;
1678 else if (nIndex
== GCW_ATOM
&& lpStr
!= NULL
)
1680 if (!IS_ATOM(lpStr
))
1682 if (!RtlCreateUnicodeStringFromAsciiz(&Value
,
1685 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1692 Value
.Buffer
= (PWSTR
)lpStr
;
1694 dwNewLong
= (LONG_PTR
)&Value
;
1697 Ret
= (DWORD
)NtUserSetClassLong(hWnd
,
1704 RtlFreeUnicodeString(&Value
);
1716 SetClassLongW(HWND hWnd
,
1720 PWSTR lpStr
= (PWSTR
)(ULONG_PTR
)dwNewLong
;
1721 UNICODE_STRING Value
= {0};
1723 TRACE("%p %d %lx\n", hWnd
, nIndex
, dwNewLong
);
1725 /* FIXME - portability!!!! */
1727 if (nIndex
== GCL_MENUNAME
&& lpStr
!= NULL
)
1729 if (!IS_INTRESOURCE(lpStr
))
1731 RtlInitUnicodeString(&Value
,
1735 Value
.Buffer
= lpStr
;
1737 dwNewLong
= (LONG_PTR
)&Value
;
1739 else if (nIndex
== GCW_ATOM
&& lpStr
!= NULL
)
1741 if (!IS_ATOM(lpStr
))
1743 RtlInitUnicodeString(&Value
,
1747 Value
.Buffer
= lpStr
;
1749 dwNewLong
= (LONG_PTR
)&Value
;
1752 return (DWORD
)NtUserSetClassLong(hWnd
,
1764 SetClassLongPtrA(HWND hWnd
,
1777 SetClassLongPtrW(HWND hWnd
,
1796 * NOTE: Obsoleted in 32-bit windows
1799 if ((nIndex
< 0) && (nIndex
!= GCW_ATOM
))
1802 return (WORD
) SetClassLongW ( hWnd
, nIndex
, wNewWord
);
1810 SetWindowWord ( HWND hWnd
,int nIndex
,WORD wNewWord
)
1815 case GWLP_HINSTANCE
:
1816 case GWLP_HWNDPARENT
:
1821 WARN("Invalid offset %d\n", nIndex
);
1822 SetLastError( ERROR_INVALID_INDEX
);
1827 return NtUserSetWindowLong( hWnd
, nIndex
, wNewWord
, FALSE
);
1841 return NtUserSetWindowLong(hWnd
, nIndex
, dwNewLong
, TRUE
);
1854 return NtUserSetWindowLong(hWnd
, nIndex
, dwNewLong
, FALSE
);
1863 SetWindowLongPtrA(HWND hWnd
,
1867 return NtUserSetWindowLong(hWnd
, nIndex
, dwNewLong
, FALSE
);
1875 SetWindowLongPtrW(HWND hWnd
,
1879 return NtUserSetWindowLong(hWnd
, nIndex
, dwNewLong
, FALSE
);
1890 HINSTANCE hInstance
)
1892 UNICODE_STRING ClassName
= {0};
1895 TRACE("class/atom: %s/%04x %p\n",
1896 IS_ATOM(lpClassName
) ? NULL
: lpClassName
,
1897 IS_ATOM(lpClassName
) ? lpClassName
: 0,
1900 if (!IS_ATOM(lpClassName
))
1902 if (!RtlCreateUnicodeStringFromAsciiz(&ClassName
,
1905 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1910 ClassName
.Buffer
= (PWSTR
)((ULONG_PTR
)lpClassName
);
1912 Ret
= NtUserUnregisterClass(&ClassName
,
1916 if (!IS_ATOM(lpClassName
))
1917 RtlFreeUnicodeString(&ClassName
);
1929 LPCWSTR lpClassName
,
1930 HINSTANCE hInstance
)
1932 UNICODE_STRING ClassName
= {0};
1934 TRACE("class/atom: %S/%04x %p\n",
1935 IS_ATOM(lpClassName
) ? NULL
: lpClassName
,
1936 IS_ATOM(lpClassName
) ? lpClassName
: 0,
1939 if (!IS_ATOM(lpClassName
))
1941 RtlInitUnicodeString(&ClassName
,
1945 ClassName
.Buffer
= (PWSTR
)((ULONG_PTR
)lpClassName
);
1947 return NtUserUnregisterClass(&ClassName
,