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_comctl32_class( pszClass
))
244 hLibModule
= GetModuleHandleW( comctl32W
);
245 if (!hLibModule
) hLibModule
= LoadLibraryW(comctl32W
);
248 if ((pRegisterClassNameW
= (void*) GetProcAddress(hLibModule
, "RegisterClassNameW")))
250 if (IS_ATOM(pszClass
))
252 ClassName
.Buffer
= (LPWSTR
)&ClassNameBuf
;
253 ClassName
.MaximumLength
= sizeof(ClassNameBuf
);
254 if (!NtUserGetAtomName(LOWORD((DWORD_PTR
)pszClass
), &ClassName
))
256 ERR("Error while verifying ATOM\n");
257 _SEH2_YIELD(goto Error_Exit
);
259 pszClass
= (PCWSTR
)&ClassNameBuf
;
261 Ret
= pRegisterClassNameW(pszClass
);
265 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
271 if ( Ret
|| !hLibModule
)
273 if ( phLibModule
) *phLibModule
= hLibModule
;
277 DWORD save_error
= GetLastError();
278 FreeLibrary(hLibModule
);
279 SetLastError(save_error
);
281 TRACE( "%s retrying after loading comctl32\n", debugstr_w(pszClass
) );
284 TRACE("NO ComCtl32 Class %S!\n",pszClass
);
301 UNICODE_STRING ClassName
= {0};
305 BOOL Ret
, ClassFound
= FALSE
;
307 TRACE("%p class/atom: %s/%04x %p\n", hInstance
,
308 IS_ATOM(lpszClass
) ? NULL
: lpszClass
,
309 IS_ATOM(lpszClass
) ? lpszClass
: 0,
314 SetLastError( ERROR_NOACCESS
);
318 if (hInstance
== User32Instance
)
323 if (lpszClass
== NULL
)
325 SetLastError(ERROR_INVALID_PARAMETER
);
329 if (IS_ATOM(lpszClass
))
331 ClassName
.Buffer
= (PWSTR
)((ULONG_PTR
)lpszClass
);
335 if (!RtlCreateUnicodeStringFromAsciiz(&ClassName
,
338 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
343 if (!RegisterDefaultClasses
)
345 TRACE("RegisterSystemControls\n");
346 RegisterSystemControls();
351 Ret
= NtUserGetClassInfo( hInstance
,
353 (LPWNDCLASSEXW
)lpwcx
,
354 (LPWSTR
*)&pszMenuName
,
359 save_error
= GetLastError();
360 if ( save_error
== ERROR_CANNOT_FIND_WND_CLASS
||
361 save_error
== ERROR_CLASS_DOES_NOT_EXIST
)
363 ClassFound
= VersionRegisterClass(ClassName
.Buffer
, NULL
, NULL
, &hLibModule
);
364 if (ClassFound
) continue;
369 save_error
= GetLastError();
370 FreeLibrary(hLibModule
);
371 SetLastError(save_error
);
379 lpwcx
->lpszClassName
= lpszClass
;
380 // lpwcx->lpszMenuName = pszMenuName;
383 if (!IS_ATOM(lpszClass
))
385 RtlFreeUnicodeString(&ClassName
);
402 UNICODE_STRING ClassName
= {0};
406 BOOL Ret
, ClassFound
= FALSE
;
408 TRACE("%p class/atom: %S/%04x %p\n", hInstance
,
409 IS_ATOM(lpszClass
) ? NULL
: lpszClass
,
410 IS_ATOM(lpszClass
) ? lpszClass
: 0,
413 /* From wine, for speed only, ReactOS supports the correct return in
414 * Win32k. cbSize is ignored.
418 SetLastError( ERROR_NOACCESS
);
422 if (hInstance
== User32Instance
)
427 if (lpszClass
== NULL
)
429 SetLastError(ERROR_INVALID_PARAMETER
);
433 if (IS_ATOM(lpszClass
))
435 ClassName
.Buffer
= (PWSTR
)((ULONG_PTR
)lpszClass
);
439 RtlInitUnicodeString(&ClassName
,
443 if (!RegisterDefaultClasses
)
445 TRACE("RegisterSystemControls\n");
446 RegisterSystemControls();
451 Ret
= NtUserGetClassInfo( hInstance
,
459 save_error
= GetLastError();
460 if ( save_error
== ERROR_CANNOT_FIND_WND_CLASS
||
461 save_error
== ERROR_CLASS_DOES_NOT_EXIST
)
463 ClassFound
= VersionRegisterClass(ClassName
.Buffer
, NULL
, NULL
, &hLibModule
);
464 if (ClassFound
) continue;
469 save_error
= GetLastError();
470 FreeLibrary(hLibModule
);
471 SetLastError(save_error
);
479 lpwcx
->lpszClassName
= lpszClass
;
480 // lpwcx->lpszMenuName = pszMenuName;
494 LPWNDCLASSA lpWndClass
)
499 retval
= GetClassInfoExA(hInstance
, lpClassName
, &wcex
);
502 lpWndClass
->style
= wcex
.style
;
503 lpWndClass
->lpfnWndProc
= wcex
.lpfnWndProc
;
504 lpWndClass
->cbClsExtra
= wcex
.cbClsExtra
;
505 lpWndClass
->cbWndExtra
= wcex
.cbWndExtra
;
506 lpWndClass
->hInstance
= wcex
.hInstance
;
507 lpWndClass
->hIcon
= wcex
.hIcon
;
508 lpWndClass
->hCursor
= wcex
.hCursor
;
509 lpWndClass
->hbrBackground
= wcex
.hbrBackground
;
510 lpWndClass
->lpszMenuName
= wcex
.lpszMenuName
;
511 lpWndClass
->lpszClassName
= wcex
.lpszClassName
;
525 LPWNDCLASSW lpWndClass
)
530 retval
= GetClassInfoExW(hInstance
, lpClassName
, &wcex
);
533 lpWndClass
->style
= wcex
.style
;
534 lpWndClass
->lpfnWndProc
= wcex
.lpfnWndProc
;
535 lpWndClass
->cbClsExtra
= wcex
.cbClsExtra
;
536 lpWndClass
->cbWndExtra
= wcex
.cbWndExtra
;
537 lpWndClass
->hInstance
= wcex
.hInstance
;
538 lpWndClass
->hIcon
= wcex
.hIcon
;
539 lpWndClass
->hCursor
= wcex
.hCursor
;
540 lpWndClass
->hbrBackground
= wcex
.hbrBackground
;
541 lpWndClass
->lpszMenuName
= wcex
.lpszMenuName
;
542 lpWndClass
->lpszClassName
= wcex
.lpszClassName
;
548 // Based on find_winproc... Fixes many whine tests......
551 IntGetClsWndProc(PWND pWnd
, PCLS Class
, BOOL Ansi
)
554 ULONG_PTR gcpd
, Ret
= 0;
555 // If server side, sweep through proc list and return the client side proc.
556 if (Class
->CSF_flags
& CSF_SERVERSIDEPROC
)
557 { // Always scan through the list due to wine class "deftest".
558 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
560 if (GETPFNSERVER(i
) == Class
->lpfnWndProc
)
563 Ret
= (ULONG_PTR
)GETPFNCLIENTA(i
);
565 Ret
= (ULONG_PTR
)GETPFNCLIENTW(i
);
571 Ret
= (ULONG_PTR
)Class
->lpfnWndProc
;
572 // Return the proc if one of the FnId default class type.
573 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
576 { // If match return the right proc by type.
577 if (GETPFNCLIENTW(Class
->fnid
) == Class
->lpfnWndProc
)
578 Ret
= (ULONG_PTR
)GETPFNCLIENTA(Class
->fnid
);
582 if (GETPFNCLIENTA(Class
->fnid
) == Class
->lpfnWndProc
)
583 Ret
= (ULONG_PTR
)GETPFNCLIENTW(Class
->fnid
);
586 // Return on change or Ansi/Unicode proc equal.
587 if ( Ret
!= (ULONG_PTR
)Class
->lpfnWndProc
||
588 Ansi
== !!(Class
->CSF_flags
& CSF_ANSIPROC
) )
591 /* We have an Ansi and Unicode swap! If Ansi create Unicode proc handle.
592 This will force CallWindowProc to deal with it. */
593 gcpd
= NtUserGetCPD( UserHMGetHandle(pWnd
),
594 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWndtoCls
,
597 return (gcpd
? gcpd
: Ret
);
601 // Based on IntGetClsWndProc
604 IntGetWndProc(PWND pWnd
, BOOL Ansi
)
607 WNDPROC gcpd
, Ret
= 0;
608 PCLS Class
= DesktopPtrToUser(pWnd
->pcls
);
610 if (!Class
) return Ret
;
612 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
614 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
616 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
619 Ret
= GETPFNCLIENTA(i
);
621 Ret
= GETPFNCLIENTW(i
);
627 /* Edit controls are special - they return a wndproc handle when
628 GetWindowLongPtr is called with a different A/W.
629 On the other hand there is no W->A->W conversion so this control
630 is treated specially.
632 if (Class
->fnid
== FNID_EDIT
)
633 Ret
= pWnd
->lpfnWndProc
;
637 Ret
= pWnd
->lpfnWndProc
;
639 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
643 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
644 Ret
= GETPFNCLIENTA(Class
->fnid
);
648 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
649 Ret
= GETPFNCLIENTW(Class
->fnid
);
652 // Return on the change.
653 if ( Ret
!= pWnd
->lpfnWndProc
)
657 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
660 gcpd
= (WNDPROC
)NtUserGetCPD( UserHMGetHandle(pWnd
),
661 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
664 return (gcpd
? gcpd
: Ret
);
667 static ULONG_PTR FASTCALL
668 IntGetClassLongA(PWND Wnd
, PCLS Class
, int nIndex
)
674 if (nIndex
+ sizeof(ULONG_PTR
) < nIndex
||
675 nIndex
+ sizeof(ULONG_PTR
) > Class
->cbclsExtra
)
677 SetLastError(ERROR_INVALID_PARAMETER
);
680 Ret
= *(PULONG_PTR
)((ULONG_PTR
)(Class
+ 1) + nIndex
);
687 Ret
= (ULONG_PTR
)Class
->cbwndExtra
;
691 Ret
= (ULONG_PTR
)Class
->cbclsExtra
;
694 case GCL_HBRBACKGROUND
:
695 Ret
= (ULONG_PTR
)Class
->hbrBackground
;
696 if (Ret
!= 0 && Ret
< 0x4000)
697 Ret
= (ULONG_PTR
)GetSysColorBrush((ULONG
)Ret
- 1);
701 //ERR("Cls 0x%x GCL_HMODULE 0x%x\n", Wnd->pcls, Class->hModule);
702 Ret
= (ULONG_PTR
)Class
->hModule
;
706 Ret
= (ULONG_PTR
)Class
->lpszClientAnsiMenuName
;
710 Ret
= (ULONG_PTR
)Class
->style
;
714 Ret
= (ULONG_PTR
)Class
->atomClassName
;
718 /* FIXME - get handle from pointer to CURSOR object */
719 Ret
= (ULONG_PTR
)Class
->hCursor
;
723 /* FIXME - get handle from pointer to ICON object */
724 Ret
= (ULONG_PTR
)Class
->hIcon
;
728 /* FIXME - get handle from pointer to ICON object */
729 Ret
= (ULONG_PTR
)(Class
->hIconSm
? Class
->hIconSm
: Class
->hIconSmIntern
);
733 Ret
= IntGetClsWndProc(Wnd
, Class
, TRUE
);
737 SetLastError(ERROR_INVALID_INDEX
);
745 static ULONG_PTR FASTCALL
746 IntGetClassLongW (PWND Wnd
, PCLS Class
, int nIndex
)
752 if (nIndex
+ sizeof(ULONG_PTR
) < nIndex
||
753 nIndex
+ sizeof(ULONG_PTR
) > Class
->cbclsExtra
)
755 SetLastError(ERROR_INVALID_PARAMETER
);
758 Ret
= *(PULONG_PTR
)((ULONG_PTR
)(Class
+ 1) + nIndex
);
765 Ret
= (ULONG_PTR
)Class
->cbwndExtra
;
769 Ret
= (ULONG_PTR
)Class
->cbclsExtra
;
772 case GCLP_HBRBACKGROUND
:
773 Ret
= (ULONG_PTR
)Class
->hbrBackground
;
774 if (Ret
!= 0 && Ret
< 0x4000)
775 Ret
= (ULONG_PTR
)GetSysColorBrush((ULONG
)Ret
- 1);
779 Ret
= (ULONG_PTR
)Class
->hModule
;
783 Ret
= (ULONG_PTR
)Class
->lpszClientUnicodeMenuName
;
787 Ret
= (ULONG_PTR
)Class
->style
;
791 Ret
= (ULONG_PTR
)Class
->atomClassName
;
795 /* FIXME - get handle from pointer to CURSOR object */
796 Ret
= (ULONG_PTR
)Class
->hCursor
;
800 /* FIXME - get handle from pointer to ICON object */
801 Ret
= (ULONG_PTR
)Class
->hIcon
;
805 /* FIXME - get handle from pointer to ICON object */
806 Ret
= (ULONG_PTR
)(Class
->hIconSm
? Class
->hIconSm
: Class
->hIconSmIntern
);
810 Ret
= IntGetClsWndProc(Wnd
, Class
, FALSE
);
814 SetLastError(ERROR_INVALID_INDEX
);
826 GetClassLongA(HWND hWnd
, int nIndex
)
832 TRACE("%p %d\n", hWnd
, nIndex
);
834 Wnd
= ValidateHwnd(hWnd
);
840 Class
= DesktopPtrToUser(Wnd
->pcls
);
846 case GCLP_HBRBACKGROUND
:
853 SetLastError(ERROR_INVALID_INDEX
);
857 Ret
= IntGetClassLongA(Wnd
, Class
, nIndex
);
861 Ret
= IntGetClassLongA(Wnd
, Class
, nIndex
);
866 WARN("Invalid class for hwnd 0x%p!\n", hWnd
);
869 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
882 GetClassLongW ( HWND hWnd
, int nIndex
)
888 TRACE("%p %d\n", hWnd
, nIndex
);
890 Wnd
= ValidateHwnd(hWnd
);
896 Class
= DesktopPtrToUser(Wnd
->pcls
);
902 case GCLP_HBRBACKGROUND
:
909 SetLastError(ERROR_INVALID_INDEX
);
913 Ret
= IntGetClassLongW(Wnd
, Class
, nIndex
);
917 Ret
= IntGetClassLongW(Wnd
, Class
, nIndex
);
922 WARN("Invalid class for hwnd 0x%p!\n", hWnd
);
925 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
940 GetClassLongPtrA(HWND hWnd
,
947 TRACE("%p %d\n", hWnd
, nIndex
);
949 Wnd
= ValidateHwnd(hWnd
);
955 Class
= DesktopPtrToUser(Wnd
->pcls
);
958 Ret
= IntGetClassLongA(Wnd
, Class
, nIndex
);
962 WARN("Invalid class for hwnd 0x%p!\n", hWnd
);
965 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
979 GetClassLongPtrW(HWND hWnd
,
986 TRACE("%p %d\n", hWnd
, nIndex
);
988 Wnd
= ValidateHwnd(hWnd
);
994 Class
= DesktopPtrToUser(Wnd
->pcls
);
997 Ret
= IntGetClassLongW(Wnd
, Class
, nIndex
);
1001 WARN("Invalid class for hwnd 0x%p!\n", hWnd
);
1004 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1024 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1027 if (nMaxCount
<= 0) return 0;
1028 if (!GetClassNameW( hWnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
1029 RtlUnicodeToMultiByteN( lpClassName
, nMaxCount
- 1, (PULONG
)&len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
1030 lpClassName
[len
] = 0;
1032 TRACE("%p class/atom: %s/%04x %x\n", hWnd
,
1033 IS_ATOM(lpClassName
) ? NULL
: lpClassName
,
1034 IS_ATOM(lpClassName
) ? lpClassName
: 0,
1051 UNICODE_STRING ClassName
;
1054 ClassName
.MaximumLength
= nMaxCount
* sizeof(WCHAR
);
1055 ClassName
.Buffer
= lpClassName
;
1057 Result
= NtUserGetClassName(hWnd
,
1061 TRACE("%p class/atom: %S/%04x %x\n", hWnd
,
1062 IS_ATOM(lpClassName
) ? NULL
: lpClassName
,
1063 IS_ATOM(lpClassName
) ? lpClassName
: 0,
1083 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
1085 Wnd
= ValidateHwnd(hwnd
);
1089 class = DesktopPtrToUser(Wnd
->pcls
);
1090 if (class == NULL
) return 0;
1092 if (offset
<= class->cbclsExtra
- sizeof(WORD
))
1093 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
1095 SetLastError( ERROR_INVALID_INDEX
);
1101 LONG_PTR
IntGetWindowLong( HWND hwnd
, INT offset
, UINT size
, BOOL unicode
)
1103 LONG_PTR retvalue
= 0;
1106 if (offset
== GWLP_HWNDPARENT
)
1108 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
1109 if (parent
== GetDesktopWindow()) parent
= GetWindow( hwnd
, GW_OWNER
);
1110 return (ULONG_PTR
)parent
;
1113 if (!(wndPtr
= ValidateHwnd( hwnd
)))
1115 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1121 if (offset
> (int)(wndPtr
->cbwndExtra
- size
))
1123 WARN("Invalid offset %d\n", offset
);
1124 SetLastError( ERROR_INVALID_INDEX
);
1127 retvalue
= *((LONG_PTR
*)((PCHAR
)(wndPtr
+ 1) + offset
));
1129 /* WINE: special case for dialog window procedure */
1130 //if ((offset == DWLP_DLGPROC) && (size == sizeof(LONG_PTR)) && (wndPtr->flags & WIN_ISDIALOG))
1131 // retvalue = (LONG_PTR)IntGetWndProc( (WNDPROC)retvalue, unicode );
1137 case GWLP_USERDATA
: retvalue
= wndPtr
->dwUserData
; break;
1138 case GWL_STYLE
: retvalue
= wndPtr
->style
; break;
1139 case GWL_EXSTYLE
: retvalue
= wndPtr
->ExStyle
; break;
1140 case GWLP_ID
: retvalue
= wndPtr
->IDMenu
; break;
1141 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wndPtr
->hModule
; break;
1144 if (!TestWindowProcess(wndPtr
))
1146 SetLastError(ERROR_ACCESS_DENIED
);
1149 retvalue
= (ULONG_PTR
)IntGetWndProc(wndPtr
, !unicode
);
1153 WARN("Unknown offset %d\n", offset
);
1154 SetLastError( ERROR_INVALID_INDEX
);
1165 GetWindowLongA ( HWND hWnd
, int nIndex
)
1167 return IntGetWindowLong( hWnd
, nIndex
, sizeof(LONG
), FALSE
);
1175 GetWindowLongW(HWND hWnd
, int nIndex
)
1177 return IntGetWindowLong( hWnd
, nIndex
, sizeof(LONG
), TRUE
);
1186 GetWindowLongPtrA(HWND hWnd
,
1189 return IntGetWindowLong( hWnd
, nIndex
, sizeof(LONG_PTR
), FALSE
);
1197 GetWindowLongPtrW(HWND hWnd
,
1200 return IntGetWindowLong( hWnd
, nIndex
, sizeof(LONG_PTR
), TRUE
);
1210 GetWindowWord(HWND hWnd
, int nIndex
)
1215 case GWLP_HINSTANCE
:
1216 case GWLP_HWNDPARENT
:
1221 WARN("Invalid offset %d\n", nIndex
);
1222 SetLastError( ERROR_INVALID_INDEX
);
1227 return IntGetWindowLong( hWnd
, nIndex
, sizeof(WORD
), FALSE
);
1235 RealGetWindowClassW(
1240 UNICODE_STRING ClassName
;
1241 ClassName
.MaximumLength
= cchType
* sizeof(WCHAR
);
1242 ClassName
.Buffer
= (PWSTR
)pszType
;
1244 return NtUserGetClassName(hwnd
,TRUE
,&ClassName
);
1253 RealGetWindowClassA(
1258 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1261 if ((INT
)cchType
<= 0) return 0;
1262 if (!RealGetWindowClassW( hwnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
1263 RtlUnicodeToMultiByteN( pszType
, cchType
- 1, (PULONG
)&len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
1269 * Create a small icon based on a standard icon
1271 #if 0 // Keep vintage code from revision 18764 by GvG!
1273 CreateSmallIcon(HICON StdIcon
)
1275 HICON SmallIcon
= NULL
;
1278 int SmallIconHeight
;
1279 BITMAP StdBitmapInfo
;
1280 HDC hSourceDc
= NULL
;
1283 HBITMAP OldSourceBitmap
= NULL
;
1284 HBITMAP OldDestBitmap
= NULL
;
1286 SmallInfo
.hbmColor
= NULL
;
1287 SmallInfo
.hbmMask
= NULL
;
1289 /* We need something to work with... */
1290 if (NULL
== StdIcon
)
1295 SmallIconWidth
= GetSystemMetrics(SM_CXSMICON
);
1296 SmallIconHeight
= GetSystemMetrics(SM_CYSMICON
);
1297 if (! GetIconInfo(StdIcon
, &StdInfo
))
1299 ERR("Failed to get icon info for icon 0x%x\n", StdIcon
);
1302 if (! GetObjectW(StdInfo
.hbmMask
, sizeof(BITMAP
), &StdBitmapInfo
))
1304 ERR("Failed to get bitmap info for icon 0x%x bitmap 0x%x\n",
1305 StdIcon
, StdInfo
.hbmColor
);
1308 if (StdBitmapInfo
.bmWidth
== SmallIconWidth
&&
1309 StdBitmapInfo
.bmHeight
== SmallIconHeight
)
1311 /* Icon already has the correct dimensions */
1315 hSourceDc
= CreateCompatibleDC(NULL
);
1316 if (NULL
== hSourceDc
)
1318 ERR("Failed to create source DC\n");
1321 hDestDc
= CreateCompatibleDC(NULL
);
1322 if (NULL
== hDestDc
)
1324 ERR("Failed to create dest DC\n");
1328 OldSourceBitmap
= SelectObject(hSourceDc
, StdInfo
.hbmColor
);
1329 if (NULL
== OldSourceBitmap
)
1331 ERR("Failed to select source color bitmap\n");
1334 SmallInfo
.hbmColor
= CreateCompatibleBitmap(hSourceDc
, SmallIconWidth
,
1336 if (NULL
== SmallInfo
.hbmColor
)
1338 ERR("Failed to create color bitmap\n");
1341 OldDestBitmap
= SelectObject(hDestDc
, SmallInfo
.hbmColor
);
1342 if (NULL
== OldDestBitmap
)
1344 ERR("Failed to select dest color bitmap\n");
1347 if (! StretchBlt(hDestDc
, 0, 0, SmallIconWidth
, SmallIconHeight
,
1348 hSourceDc
, 0, 0, StdBitmapInfo
.bmWidth
,
1349 StdBitmapInfo
.bmHeight
, SRCCOPY
))
1351 ERR("Failed to stretch color bitmap\n");
1355 if (NULL
== SelectObject(hSourceDc
, StdInfo
.hbmMask
))
1357 ERR("Failed to select source mask bitmap\n");
1360 SmallInfo
.hbmMask
= CreateCompatibleBitmap(hSourceDc
, SmallIconWidth
, SmallIconHeight
);
1361 if (NULL
== SmallInfo
.hbmMask
)
1363 ERR("Failed to create mask bitmap\n");
1366 if (NULL
== SelectObject(hDestDc
, SmallInfo
.hbmMask
))
1368 ERR("Failed to select dest mask bitmap\n");
1371 if (! StretchBlt(hDestDc
, 0, 0, SmallIconWidth
, SmallIconHeight
,
1372 hSourceDc
, 0, 0, StdBitmapInfo
.bmWidth
,
1373 StdBitmapInfo
.bmHeight
, SRCCOPY
))
1375 ERR("Failed to stretch mask bitmap\n");
1379 SmallInfo
.fIcon
= TRUE
;
1380 SmallInfo
.xHotspot
= SmallIconWidth
/ 2;
1381 SmallInfo
.yHotspot
= SmallIconHeight
/ 2;
1382 SmallIcon
= CreateIconIndirect(&SmallInfo
);
1383 if (NULL
== SmallIcon
)
1385 ERR("Failed to create icon\n");
1390 if (NULL
!= SmallInfo
.hbmMask
)
1392 DeleteObject(SmallInfo
.hbmMask
);
1394 if (NULL
!= OldDestBitmap
)
1396 SelectObject(hDestDc
, OldDestBitmap
);
1398 if (NULL
!= SmallInfo
.hbmColor
)
1400 DeleteObject(SmallInfo
.hbmColor
);
1402 if (NULL
!= hDestDc
)
1406 if (NULL
!= OldSourceBitmap
)
1408 SelectObject(hSourceDc
, OldSourceBitmap
);
1410 if (NULL
!= hSourceDc
)
1412 DeleteDC(hSourceDc
);
1420 RegisterClassExWOWW(WNDCLASSEXW
*lpwcx
,
1427 WNDCLASSEXW WndClass
;
1428 UNICODE_STRING ClassName
;
1429 UNICODE_STRING MenuName
= {0};
1430 CLSMENUNAME clsMenuName
;
1431 ANSI_STRING AnsiMenuName
;
1434 BOOL ClassFound
= FALSE
;
1436 if (lpwcx
== NULL
|| lpwcx
->cbSize
!= sizeof(WNDCLASSEXW
) ||
1437 lpwcx
->cbClsExtra
< 0 || lpwcx
->cbWndExtra
< 0 ||
1438 lpwcx
->lpszClassName
== NULL
)
1440 TRACE("RegisterClassExWOWW Invalid Parameter Error!\n");
1441 SetLastError(ERROR_INVALID_PARAMETER
);
1447 if (!RegisterDefaultClasses
) RegisterSystemControls();
1450 * On real Windows this looks more like:
1451 * if (lpwcx->hInstance == User32Instance &&
1452 * *(PULONG)((ULONG_PTR)NtCurrentTeb() + 0x6D4) & 0x400)
1453 * But since I have no idea what the magic field in the
1454 * TEB structure means, I rather decided to omit that.
1457 GetWin32ClientInfo()->dwExpWinVer & (WINVER == 0x400)
1459 if (lpwcx
->hInstance
== User32Instance
)
1461 TRACE("RegisterClassExWOWW User32Instance!\n");
1462 SetLastError(ERROR_INVALID_PARAMETER
);
1465 /* Yes, this is correct. We should modify the passed structure. */
1466 if (lpwcx
->hInstance
== NULL
)
1467 ((WNDCLASSEXW
*)lpwcx
)->hInstance
= GetModuleHandleW(NULL
);
1469 RtlCopyMemory(&WndClass
, lpwcx
, sizeof(WNDCLASSEXW
));
1471 if (NULL == WndClass.hIconSm)
1473 WndClass.hIconSm = CreateSmallIcon(WndClass.hIcon);
1476 if (WndClass
.lpszMenuName
!= NULL
)
1478 if (!IS_INTRESOURCE(WndClass
.lpszMenuName
))
1480 if (WndClass
.lpszMenuName
[0])
1482 RtlInitUnicodeString(&MenuName
, WndClass
.lpszMenuName
);
1483 RtlUnicodeStringToAnsiString( &AnsiMenuName
, &MenuName
, TRUE
);
1488 MenuName
.Buffer
= (LPWSTR
)WndClass
.lpszMenuName
;
1489 AnsiMenuName
.Buffer
= (PCHAR
)WndClass
.lpszMenuName
;
1493 if (IS_ATOM(WndClass
.lpszClassName
))
1496 ClassName
.MaximumLength
= 0;
1497 ClassName
.Buffer
= (LPWSTR
)WndClass
.lpszClassName
;
1501 RtlInitUnicodeString(&ClassName
, WndClass
.lpszClassName
);
1504 clsMenuName
.pszClientAnsiMenuName
= AnsiMenuName
.Buffer
;
1505 clsMenuName
.pwszClientUnicodeMenuName
= MenuName
.Buffer
;
1506 clsMenuName
.pusMenuName
= &MenuName
;
1510 Atom
= NtUserRegisterClassExWOW( &WndClass
,
1512 NULL
, //PUNICODE_STRING ClsNVersion,
1521 save_error
= GetLastError();
1522 if ( save_error
== ERROR_CANNOT_FIND_WND_CLASS
||
1523 save_error
== ERROR_CLASS_DOES_NOT_EXIST
)
1525 ClassFound
= VersionRegisterClass(ClassName
.Buffer
, NULL
, NULL
, &hLibModule
);
1526 if (ClassFound
) continue;
1531 save_error
= GetLastError();
1532 FreeLibrary(hLibModule
);
1533 SetLastError(save_error
);
1539 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
1540 Atom
, lpwcx
->lpfnWndProc
, lpwcx
->hInstance
, lpwcx
->hbrBackground
,
1541 lpwcx
->style
, lpwcx
->cbClsExtra
, lpwcx
->cbWndExtra
, WndClass
);
1550 RegisterClassExA(CONST WNDCLASSEXA
*lpwcx
)
1553 WNDCLASSEXW WndClass
;
1554 WCHAR mname
[MAX_BUFFER_LEN
];
1555 WCHAR cname
[MAX_BUFFER_LEN
];
1557 RtlCopyMemory(&WndClass
, lpwcx
, sizeof(WNDCLASSEXA
));
1559 if (WndClass
.lpszMenuName
!= NULL
)
1561 if (!IS_INTRESOURCE(WndClass
.lpszMenuName
))
1563 if (WndClass
.lpszMenuName
[0])
1565 if (!MultiByteToWideChar( CP_ACP
, 0, lpwcx
->lpszMenuName
, -1, mname
, MAX_ATOM_LEN
+ 1 )) return 0;
1567 WndClass
.lpszMenuName
= mname
;
1572 if (!IS_ATOM(WndClass
.lpszClassName
))
1574 if (!MultiByteToWideChar( CP_ACP
, 0, lpwcx
->lpszClassName
, -1, cname
, MAX_ATOM_LEN
+ 1 )) return 0;
1576 WndClass
.lpszClassName
= cname
;
1579 Atom
= RegisterClassExWOWW( &WndClass
,
1585 TRACE("A atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
1586 Atom
, lpwcx
->lpfnWndProc
, lpwcx
->hInstance
, lpwcx
->hbrBackground
,
1587 lpwcx
->style
, lpwcx
->cbClsExtra
, lpwcx
->cbWndExtra
, WndClass
);
1596 RegisterClassExW(CONST WNDCLASSEXW
*lpwcx
)
1600 Atom
= RegisterClassExWOWW( (WNDCLASSEXW
*)lpwcx
, 0, 0, 0, TRUE
);
1602 TRACE("W atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d\n",
1603 Atom
, lpwcx
->lpfnWndProc
, lpwcx
->hInstance
, lpwcx
->hbrBackground
,
1604 lpwcx
->style
, lpwcx
->cbClsExtra
, lpwcx
->cbWndExtra
);
1613 RegisterClassA(CONST WNDCLASSA
*lpWndClass
)
1617 if (lpWndClass
== NULL
)
1620 RtlCopyMemory(&Class
.style
, lpWndClass
, sizeof(WNDCLASSA
));
1621 Class
.cbSize
= sizeof(WNDCLASSEXA
);
1622 Class
.hIconSm
= NULL
;
1624 return RegisterClassExA(&Class
);
1631 RegisterClassW(CONST WNDCLASSW
*lpWndClass
)
1635 if (lpWndClass
== NULL
)
1638 RtlCopyMemory(&Class
.style
, lpWndClass
, sizeof(WNDCLASSW
));
1639 Class
.cbSize
= sizeof(WNDCLASSEXW
);
1640 Class
.hIconSm
= NULL
;
1642 return RegisterClassExW(&Class
);
1650 SetClassLongA (HWND hWnd
,
1654 PSTR lpStr
= (PSTR
)(ULONG_PTR
)dwNewLong
;
1655 UNICODE_STRING Value
= {0};
1656 BOOL Allocated
= FALSE
;
1659 /* FIXME - portability!!!! */
1661 if (nIndex
== GCL_MENUNAME
&& lpStr
!= NULL
)
1663 if (!IS_INTRESOURCE(lpStr
))
1665 if (!RtlCreateUnicodeStringFromAsciiz(&Value
,
1668 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1675 Value
.Buffer
= (PWSTR
)lpStr
;
1677 dwNewLong
= (LONG_PTR
)&Value
;
1679 else if (nIndex
== GCW_ATOM
&& lpStr
!= NULL
)
1681 if (!IS_ATOM(lpStr
))
1683 if (!RtlCreateUnicodeStringFromAsciiz(&Value
,
1686 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1693 Value
.Buffer
= (PWSTR
)lpStr
;
1695 dwNewLong
= (LONG_PTR
)&Value
;
1698 Ret
= (DWORD
)NtUserSetClassLong(hWnd
,
1705 RtlFreeUnicodeString(&Value
);
1717 SetClassLongW(HWND hWnd
,
1721 PWSTR lpStr
= (PWSTR
)(ULONG_PTR
)dwNewLong
;
1722 UNICODE_STRING Value
= {0};
1724 TRACE("%p %d %lx\n", hWnd
, nIndex
, dwNewLong
);
1726 /* FIXME - portability!!!! */
1728 if (nIndex
== GCL_MENUNAME
&& lpStr
!= NULL
)
1730 if (!IS_INTRESOURCE(lpStr
))
1732 RtlInitUnicodeString(&Value
,
1736 Value
.Buffer
= lpStr
;
1738 dwNewLong
= (LONG_PTR
)&Value
;
1740 else if (nIndex
== GCW_ATOM
&& lpStr
!= NULL
)
1742 if (!IS_ATOM(lpStr
))
1744 RtlInitUnicodeString(&Value
,
1748 Value
.Buffer
= lpStr
;
1750 dwNewLong
= (LONG_PTR
)&Value
;
1753 return (DWORD
)NtUserSetClassLong(hWnd
,
1765 SetClassLongPtrA(HWND hWnd
,
1778 SetClassLongPtrW(HWND hWnd
,
1797 * NOTE: Obsoleted in 32-bit windows
1800 if ((nIndex
< 0) && (nIndex
!= GCW_ATOM
))
1803 return (WORD
) SetClassLongW ( hWnd
, nIndex
, wNewWord
);
1811 SetWindowWord ( HWND hWnd
,int nIndex
,WORD wNewWord
)
1816 case GWLP_HINSTANCE
:
1817 case GWLP_HWNDPARENT
:
1822 WARN("Invalid offset %d\n", nIndex
);
1823 SetLastError( ERROR_INVALID_INDEX
);
1828 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
,