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 Ret
= Class
->spcur
? (ULONG_PTR
)((PPROCMARKHEAD
)SharedPtrToUser(Class
->spcur
))->h
: 0;
721 Ret
= Class
->spicn
? (ULONG_PTR
)((PPROCMARKHEAD
)SharedPtrToUser(Class
->spicn
))->h
: 0;
725 Ret
= Class
->spicnSm
? (ULONG_PTR
)((PPROCMARKHEAD
)SharedPtrToUser(Class
->spicnSm
))->h
: 0;
729 Ret
= IntGetClsWndProc(Wnd
, Class
, TRUE
);
733 SetLastError(ERROR_INVALID_INDEX
);
741 static ULONG_PTR FASTCALL
742 IntGetClassLongW (PWND Wnd
, PCLS Class
, int nIndex
)
748 if (nIndex
+ sizeof(ULONG_PTR
) < nIndex
||
749 nIndex
+ sizeof(ULONG_PTR
) > Class
->cbclsExtra
)
751 SetLastError(ERROR_INVALID_PARAMETER
);
754 Ret
= *(PULONG_PTR
)((ULONG_PTR
)(Class
+ 1) + nIndex
);
761 Ret
= (ULONG_PTR
)Class
->cbwndExtra
;
765 Ret
= (ULONG_PTR
)Class
->cbclsExtra
;
768 case GCLP_HBRBACKGROUND
:
769 Ret
= (ULONG_PTR
)Class
->hbrBackground
;
770 if (Ret
!= 0 && Ret
< 0x4000)
771 Ret
= (ULONG_PTR
)GetSysColorBrush((ULONG
)Ret
- 1);
775 Ret
= (ULONG_PTR
)Class
->hModule
;
779 Ret
= (ULONG_PTR
)Class
->lpszClientUnicodeMenuName
;
783 Ret
= (ULONG_PTR
)Class
->style
;
787 Ret
= (ULONG_PTR
)Class
->atomClassName
;
791 Ret
= Class
->spcur
? (ULONG_PTR
)((PPROCMARKHEAD
)SharedPtrToUser(Class
->spcur
))->h
: 0;
795 Ret
= Class
->spicn
? (ULONG_PTR
)((PPROCMARKHEAD
)SharedPtrToUser(Class
->spicn
))->h
: 0;
799 Ret
= Class
->spicnSm
? (ULONG_PTR
)((PPROCMARKHEAD
)SharedPtrToUser(Class
->spicnSm
))->h
: 0;
803 Ret
= IntGetClsWndProc(Wnd
, Class
, FALSE
);
807 SetLastError(ERROR_INVALID_INDEX
);
819 GetClassLongA(HWND hWnd
, int nIndex
)
825 TRACE("%p %d\n", hWnd
, nIndex
);
827 Wnd
= ValidateHwnd(hWnd
);
833 Class
= DesktopPtrToUser(Wnd
->pcls
);
839 case GCLP_HBRBACKGROUND
:
846 SetLastError(ERROR_INVALID_INDEX
);
850 Ret
= IntGetClassLongA(Wnd
, Class
, nIndex
);
854 Ret
= IntGetClassLongA(Wnd
, Class
, nIndex
);
859 WARN("Invalid class for hwnd 0x%p!\n", hWnd
);
862 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
875 GetClassLongW ( HWND hWnd
, int nIndex
)
881 TRACE("%p %d\n", hWnd
, nIndex
);
883 Wnd
= ValidateHwnd(hWnd
);
889 Class
= DesktopPtrToUser(Wnd
->pcls
);
895 case GCLP_HBRBACKGROUND
:
902 SetLastError(ERROR_INVALID_INDEX
);
906 Ret
= IntGetClassLongW(Wnd
, Class
, nIndex
);
910 Ret
= IntGetClassLongW(Wnd
, Class
, nIndex
);
915 WARN("Invalid class for hwnd 0x%p!\n", hWnd
);
918 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
933 GetClassLongPtrA(HWND hWnd
,
940 TRACE("%p %d\n", hWnd
, nIndex
);
942 Wnd
= ValidateHwnd(hWnd
);
948 Class
= DesktopPtrToUser(Wnd
->pcls
);
951 Ret
= IntGetClassLongA(Wnd
, Class
, nIndex
);
955 WARN("Invalid class for hwnd 0x%p!\n", hWnd
);
958 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
972 GetClassLongPtrW(HWND hWnd
,
979 TRACE("%p %d\n", hWnd
, nIndex
);
981 Wnd
= ValidateHwnd(hWnd
);
987 Class
= DesktopPtrToUser(Wnd
->pcls
);
990 Ret
= IntGetClassLongW(Wnd
, Class
, nIndex
);
994 WARN("Invalid class for hwnd 0x%p!\n", hWnd
);
997 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1017 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1020 if (nMaxCount
<= 0) return 0;
1021 if (!GetClassNameW( hWnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
1022 RtlUnicodeToMultiByteN( lpClassName
, nMaxCount
- 1, (PULONG
)&len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
1023 lpClassName
[len
] = 0;
1025 TRACE("%p class/atom: %s/%04x %x\n", hWnd
,
1026 IS_ATOM(lpClassName
) ? NULL
: lpClassName
,
1027 IS_ATOM(lpClassName
) ? lpClassName
: 0,
1044 UNICODE_STRING ClassName
;
1047 ClassName
.MaximumLength
= nMaxCount
* sizeof(WCHAR
);
1048 ClassName
.Buffer
= lpClassName
;
1050 Result
= NtUserGetClassName(hWnd
,
1054 TRACE("%p class/atom: %S/%04x %x\n", hWnd
,
1055 IS_ATOM(lpClassName
) ? NULL
: lpClassName
,
1056 IS_ATOM(lpClassName
) ? lpClassName
: 0,
1076 if (offset
< 0) return GetClassLongA( hwnd
, offset
);
1078 Wnd
= ValidateHwnd(hwnd
);
1082 class = DesktopPtrToUser(Wnd
->pcls
);
1083 if (class == NULL
) return 0;
1085 if (offset
<= class->cbclsExtra
- sizeof(WORD
))
1086 memcpy( &retvalue
, (char *)(class + 1) + offset
, sizeof(retvalue
) );
1088 SetLastError( ERROR_INVALID_INDEX
);
1094 LONG_PTR
IntGetWindowLong( HWND hwnd
, INT offset
, UINT size
, BOOL unicode
)
1096 LONG_PTR retvalue
= 0;
1099 if (offset
== GWLP_HWNDPARENT
)
1101 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
1102 if (parent
== GetDesktopWindow()) parent
= GetWindow( hwnd
, GW_OWNER
);
1103 return (ULONG_PTR
)parent
;
1106 if (!(wndPtr
= ValidateHwnd( hwnd
)))
1108 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1114 if (offset
> (int)(wndPtr
->cbwndExtra
- size
))
1116 WARN("Invalid offset %d\n", offset
);
1117 SetLastError( ERROR_INVALID_INDEX
);
1120 retvalue
= *((LONG_PTR
*)((PCHAR
)(wndPtr
+ 1) + offset
));
1122 /* WINE: special case for dialog window procedure */
1123 //if ((offset == DWLP_DLGPROC) && (size == sizeof(LONG_PTR)) && (wndPtr->flags & WIN_ISDIALOG))
1124 // retvalue = (LONG_PTR)IntGetWndProc( (WNDPROC)retvalue, unicode );
1130 case GWLP_USERDATA
: retvalue
= wndPtr
->dwUserData
; break;
1131 case GWL_STYLE
: retvalue
= wndPtr
->style
; break;
1132 case GWL_EXSTYLE
: retvalue
= wndPtr
->ExStyle
; break;
1133 case GWLP_ID
: retvalue
= wndPtr
->IDMenu
; break;
1134 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wndPtr
->hModule
; break;
1137 if (!TestWindowProcess(wndPtr
))
1139 SetLastError(ERROR_ACCESS_DENIED
);
1142 retvalue
= (ULONG_PTR
)IntGetWndProc(wndPtr
, !unicode
);
1146 WARN("Unknown offset %d\n", offset
);
1147 SetLastError( ERROR_INVALID_INDEX
);
1158 GetWindowLongA ( HWND hWnd
, int nIndex
)
1160 return IntGetWindowLong( hWnd
, nIndex
, sizeof(LONG
), FALSE
);
1168 GetWindowLongW(HWND hWnd
, int nIndex
)
1170 return IntGetWindowLong( hWnd
, nIndex
, sizeof(LONG
), TRUE
);
1179 GetWindowLongPtrA(HWND hWnd
,
1182 return IntGetWindowLong( hWnd
, nIndex
, sizeof(LONG_PTR
), FALSE
);
1190 GetWindowLongPtrW(HWND hWnd
,
1193 return IntGetWindowLong( hWnd
, nIndex
, sizeof(LONG_PTR
), TRUE
);
1203 GetWindowWord(HWND hWnd
, int nIndex
)
1208 case GWLP_HINSTANCE
:
1209 case GWLP_HWNDPARENT
:
1214 WARN("Invalid offset %d\n", nIndex
);
1215 SetLastError( ERROR_INVALID_INDEX
);
1220 return IntGetWindowLong( hWnd
, nIndex
, sizeof(WORD
), FALSE
);
1228 RealGetWindowClassW(
1233 UNICODE_STRING ClassName
;
1234 ClassName
.MaximumLength
= cchType
* sizeof(WCHAR
);
1235 ClassName
.Buffer
= (PWSTR
)pszType
;
1237 return NtUserGetClassName(hwnd
,TRUE
,&ClassName
);
1246 RealGetWindowClassA(
1251 WCHAR tmpbuf
[MAX_ATOM_LEN
+ 1];
1254 if ((INT
)cchType
<= 0) return 0;
1255 if (!RealGetWindowClassW( hwnd
, tmpbuf
, sizeof(tmpbuf
)/sizeof(WCHAR
) )) return 0;
1256 RtlUnicodeToMultiByteN( pszType
, cchType
- 1, (PULONG
)&len
, tmpbuf
, strlenW(tmpbuf
) * sizeof(WCHAR
) );
1262 * Create a small icon based on a standard icon
1264 #if 0 // Keep vintage code from revision 18764 by GvG!
1266 CreateSmallIcon(HICON StdIcon
)
1268 HICON SmallIcon
= NULL
;
1271 int SmallIconHeight
;
1272 BITMAP StdBitmapInfo
;
1273 HDC hSourceDc
= NULL
;
1276 HBITMAP OldSourceBitmap
= NULL
;
1277 HBITMAP OldDestBitmap
= NULL
;
1279 SmallInfo
.hbmColor
= NULL
;
1280 SmallInfo
.hbmMask
= NULL
;
1282 /* We need something to work with... */
1283 if (NULL
== StdIcon
)
1288 SmallIconWidth
= GetSystemMetrics(SM_CXSMICON
);
1289 SmallIconHeight
= GetSystemMetrics(SM_CYSMICON
);
1290 if (! GetIconInfo(StdIcon
, &StdInfo
))
1292 ERR("Failed to get icon info for icon 0x%x\n", StdIcon
);
1295 if (! GetObjectW(StdInfo
.hbmMask
, sizeof(BITMAP
), &StdBitmapInfo
))
1297 ERR("Failed to get bitmap info for icon 0x%x bitmap 0x%x\n",
1298 StdIcon
, StdInfo
.hbmColor
);
1301 if (StdBitmapInfo
.bmWidth
== SmallIconWidth
&&
1302 StdBitmapInfo
.bmHeight
== SmallIconHeight
)
1304 /* Icon already has the correct dimensions */
1308 hSourceDc
= CreateCompatibleDC(NULL
);
1309 if (NULL
== hSourceDc
)
1311 ERR("Failed to create source DC\n");
1314 hDestDc
= CreateCompatibleDC(NULL
);
1315 if (NULL
== hDestDc
)
1317 ERR("Failed to create dest DC\n");
1321 OldSourceBitmap
= SelectObject(hSourceDc
, StdInfo
.hbmColor
);
1322 if (NULL
== OldSourceBitmap
)
1324 ERR("Failed to select source color bitmap\n");
1327 SmallInfo
.hbmColor
= CreateCompatibleBitmap(hSourceDc
, SmallIconWidth
,
1329 if (NULL
== SmallInfo
.hbmColor
)
1331 ERR("Failed to create color bitmap\n");
1334 OldDestBitmap
= SelectObject(hDestDc
, SmallInfo
.hbmColor
);
1335 if (NULL
== OldDestBitmap
)
1337 ERR("Failed to select dest color bitmap\n");
1340 if (! StretchBlt(hDestDc
, 0, 0, SmallIconWidth
, SmallIconHeight
,
1341 hSourceDc
, 0, 0, StdBitmapInfo
.bmWidth
,
1342 StdBitmapInfo
.bmHeight
, SRCCOPY
))
1344 ERR("Failed to stretch color bitmap\n");
1348 if (NULL
== SelectObject(hSourceDc
, StdInfo
.hbmMask
))
1350 ERR("Failed to select source mask bitmap\n");
1353 SmallInfo
.hbmMask
= CreateCompatibleBitmap(hSourceDc
, SmallIconWidth
, SmallIconHeight
);
1354 if (NULL
== SmallInfo
.hbmMask
)
1356 ERR("Failed to create mask bitmap\n");
1359 if (NULL
== SelectObject(hDestDc
, SmallInfo
.hbmMask
))
1361 ERR("Failed to select dest mask bitmap\n");
1364 if (! StretchBlt(hDestDc
, 0, 0, SmallIconWidth
, SmallIconHeight
,
1365 hSourceDc
, 0, 0, StdBitmapInfo
.bmWidth
,
1366 StdBitmapInfo
.bmHeight
, SRCCOPY
))
1368 ERR("Failed to stretch mask bitmap\n");
1372 SmallInfo
.fIcon
= TRUE
;
1373 SmallInfo
.xHotspot
= SmallIconWidth
/ 2;
1374 SmallInfo
.yHotspot
= SmallIconHeight
/ 2;
1375 SmallIcon
= CreateIconIndirect(&SmallInfo
);
1376 if (NULL
== SmallIcon
)
1378 ERR("Failed to create icon\n");
1383 if (NULL
!= SmallInfo
.hbmMask
)
1385 DeleteObject(SmallInfo
.hbmMask
);
1387 if (NULL
!= OldDestBitmap
)
1389 SelectObject(hDestDc
, OldDestBitmap
);
1391 if (NULL
!= SmallInfo
.hbmColor
)
1393 DeleteObject(SmallInfo
.hbmColor
);
1395 if (NULL
!= hDestDc
)
1399 if (NULL
!= OldSourceBitmap
)
1401 SelectObject(hSourceDc
, OldSourceBitmap
);
1403 if (NULL
!= hSourceDc
)
1405 DeleteDC(hSourceDc
);
1413 RegisterClassExWOWW(WNDCLASSEXW
*lpwcx
,
1420 WNDCLASSEXW WndClass
;
1421 UNICODE_STRING ClassName
;
1422 UNICODE_STRING MenuName
= {0};
1423 CLSMENUNAME clsMenuName
;
1424 ANSI_STRING AnsiMenuName
;
1425 HMODULE hLibModule
= NULL
;
1427 BOOL ClassFound
= FALSE
;
1429 if (lpwcx
== NULL
|| lpwcx
->cbSize
!= sizeof(WNDCLASSEXW
) ||
1430 lpwcx
->cbClsExtra
< 0 || lpwcx
->cbWndExtra
< 0 ||
1431 lpwcx
->lpszClassName
== NULL
)
1433 TRACE("RegisterClassExWOWW Invalid Parameter Error!\n");
1434 SetLastError(ERROR_INVALID_PARAMETER
);
1440 if (!RegisterDefaultClasses
) RegisterSystemControls();
1443 * On real Windows this looks more like:
1444 * if (lpwcx->hInstance == User32Instance &&
1445 * *(PULONG)((ULONG_PTR)NtCurrentTeb() + 0x6D4) & 0x400)
1446 * But since I have no idea what the magic field in the
1447 * TEB structure means, I rather decided to omit that.
1450 GetWin32ClientInfo()->dwExpWinVer & (WINVER == 0x400)
1452 if (lpwcx
->hInstance
== User32Instance
)
1454 TRACE("RegisterClassExWOWW User32Instance!\n");
1455 SetLastError(ERROR_INVALID_PARAMETER
);
1458 /* Yes, this is correct. We should modify the passed structure. */
1459 if (lpwcx
->hInstance
== NULL
)
1460 ((WNDCLASSEXW
*)lpwcx
)->hInstance
= GetModuleHandleW(NULL
);
1462 RtlCopyMemory(&WndClass
, lpwcx
, sizeof(WNDCLASSEXW
));
1464 if (NULL == WndClass.hIconSm)
1466 WndClass.hIconSm = CreateSmallIcon(WndClass.hIcon);
1469 RtlInitEmptyAnsiString(&AnsiMenuName
, NULL
, 0);
1470 if (WndClass
.lpszMenuName
!= NULL
)
1472 if (!IS_INTRESOURCE(WndClass
.lpszMenuName
))
1474 if (WndClass
.lpszMenuName
[0])
1476 RtlInitUnicodeString(&MenuName
, WndClass
.lpszMenuName
);
1477 RtlUnicodeStringToAnsiString( &AnsiMenuName
, &MenuName
, TRUE
);
1482 MenuName
.Buffer
= (LPWSTR
)WndClass
.lpszMenuName
;
1483 AnsiMenuName
.Buffer
= (PCHAR
)WndClass
.lpszMenuName
;
1487 if (IS_ATOM(WndClass
.lpszClassName
))
1490 ClassName
.MaximumLength
= 0;
1491 ClassName
.Buffer
= (LPWSTR
)WndClass
.lpszClassName
;
1495 RtlInitUnicodeString(&ClassName
, WndClass
.lpszClassName
);
1498 clsMenuName
.pszClientAnsiMenuName
= AnsiMenuName
.Buffer
;
1499 clsMenuName
.pwszClientUnicodeMenuName
= MenuName
.Buffer
;
1500 clsMenuName
.pusMenuName
= &MenuName
;
1504 Atom
= NtUserRegisterClassExWOW( &WndClass
,
1506 NULL
, //PUNICODE_STRING ClsNVersion,
1515 save_error
= GetLastError();
1516 if ( save_error
== ERROR_CANNOT_FIND_WND_CLASS
||
1517 save_error
== ERROR_CLASS_DOES_NOT_EXIST
)
1519 ClassFound
= VersionRegisterClass(ClassName
.Buffer
, NULL
, NULL
, &hLibModule
);
1520 if (ClassFound
) continue;
1525 save_error
= GetLastError();
1526 FreeLibrary(hLibModule
);
1527 SetLastError(save_error
);
1533 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
1534 Atom
, lpwcx
->lpfnWndProc
, lpwcx
->hInstance
, lpwcx
->hbrBackground
,
1535 lpwcx
->style
, lpwcx
->cbClsExtra
, lpwcx
->cbWndExtra
, WndClass
);
1544 RegisterClassExA(CONST WNDCLASSEXA
*lpwcx
)
1547 WNDCLASSEXW WndClass
;
1548 WCHAR mname
[MAX_BUFFER_LEN
];
1549 WCHAR cname
[MAX_BUFFER_LEN
];
1551 RtlCopyMemory(&WndClass
, lpwcx
, sizeof(WNDCLASSEXA
));
1553 if (WndClass
.lpszMenuName
!= NULL
)
1555 if (!IS_INTRESOURCE(WndClass
.lpszMenuName
))
1557 if (WndClass
.lpszMenuName
[0])
1559 if (!MultiByteToWideChar( CP_ACP
, 0, lpwcx
->lpszMenuName
, -1, mname
, MAX_ATOM_LEN
+ 1 )) return 0;
1561 WndClass
.lpszMenuName
= mname
;
1566 if (!IS_ATOM(WndClass
.lpszClassName
))
1568 if (!MultiByteToWideChar( CP_ACP
, 0, lpwcx
->lpszClassName
, -1, cname
, MAX_ATOM_LEN
+ 1 )) return 0;
1570 WndClass
.lpszClassName
= cname
;
1573 Atom
= RegisterClassExWOWW( &WndClass
,
1579 TRACE("A atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
1580 Atom
, lpwcx
->lpfnWndProc
, lpwcx
->hInstance
, lpwcx
->hbrBackground
,
1581 lpwcx
->style
, lpwcx
->cbClsExtra
, lpwcx
->cbWndExtra
, WndClass
);
1590 RegisterClassExW(CONST WNDCLASSEXW
*lpwcx
)
1594 Atom
= RegisterClassExWOWW( (WNDCLASSEXW
*)lpwcx
, 0, 0, 0, TRUE
);
1596 TRACE("W atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d\n",
1597 Atom
, lpwcx
->lpfnWndProc
, lpwcx
->hInstance
, lpwcx
->hbrBackground
,
1598 lpwcx
->style
, lpwcx
->cbClsExtra
, lpwcx
->cbWndExtra
);
1607 RegisterClassA(CONST WNDCLASSA
*lpWndClass
)
1611 if (lpWndClass
== NULL
)
1614 RtlCopyMemory(&Class
.style
, lpWndClass
, sizeof(WNDCLASSA
));
1615 Class
.cbSize
= sizeof(WNDCLASSEXA
);
1616 Class
.hIconSm
= NULL
;
1618 return RegisterClassExA(&Class
);
1625 RegisterClassW(CONST WNDCLASSW
*lpWndClass
)
1629 if (lpWndClass
== NULL
)
1632 RtlCopyMemory(&Class
.style
, lpWndClass
, sizeof(WNDCLASSW
));
1633 Class
.cbSize
= sizeof(WNDCLASSEXW
);
1634 Class
.hIconSm
= NULL
;
1636 return RegisterClassExW(&Class
);
1644 SetClassLongA (HWND hWnd
,
1648 PSTR lpStr
= (PSTR
)(ULONG_PTR
)dwNewLong
;
1649 UNICODE_STRING Value
= {0};
1650 BOOL Allocated
= FALSE
;
1653 /* FIXME - portability!!!! */
1655 if (nIndex
== GCL_MENUNAME
&& lpStr
!= NULL
)
1657 if (!IS_INTRESOURCE(lpStr
))
1659 if (!RtlCreateUnicodeStringFromAsciiz(&Value
,
1662 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1669 Value
.Buffer
= (PWSTR
)lpStr
;
1671 dwNewLong
= (LONG_PTR
)&Value
;
1673 else if (nIndex
== GCW_ATOM
&& lpStr
!= NULL
)
1675 if (!IS_ATOM(lpStr
))
1677 if (!RtlCreateUnicodeStringFromAsciiz(&Value
,
1680 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1687 Value
.Buffer
= (PWSTR
)lpStr
;
1689 dwNewLong
= (LONG_PTR
)&Value
;
1692 Ret
= (DWORD
)NtUserSetClassLong(hWnd
,
1699 RtlFreeUnicodeString(&Value
);
1711 SetClassLongW(HWND hWnd
,
1715 PWSTR lpStr
= (PWSTR
)(ULONG_PTR
)dwNewLong
;
1716 UNICODE_STRING Value
= {0};
1718 TRACE("%p %d %lx\n", hWnd
, nIndex
, dwNewLong
);
1720 /* FIXME - portability!!!! */
1722 if (nIndex
== GCL_MENUNAME
&& lpStr
!= NULL
)
1724 if (!IS_INTRESOURCE(lpStr
))
1726 RtlInitUnicodeString(&Value
,
1730 Value
.Buffer
= lpStr
;
1732 dwNewLong
= (LONG_PTR
)&Value
;
1734 else if (nIndex
== GCW_ATOM
&& lpStr
!= NULL
)
1736 if (!IS_ATOM(lpStr
))
1738 RtlInitUnicodeString(&Value
,
1742 Value
.Buffer
= lpStr
;
1744 dwNewLong
= (LONG_PTR
)&Value
;
1747 return (DWORD
)NtUserSetClassLong(hWnd
,
1759 SetClassLongPtrA(HWND hWnd
,
1772 SetClassLongPtrW(HWND hWnd
,
1791 * NOTE: Obsoleted in 32-bit windows
1794 if ((nIndex
< 0) && (nIndex
!= GCW_ATOM
))
1797 return (WORD
) SetClassLongW ( hWnd
, nIndex
, wNewWord
);
1805 SetWindowWord ( HWND hWnd
,int nIndex
,WORD wNewWord
)
1810 case GWLP_HINSTANCE
:
1811 case GWLP_HWNDPARENT
:
1816 WARN("Invalid offset %d\n", nIndex
);
1817 SetLastError( ERROR_INVALID_INDEX
);
1822 return NtUserSetWindowLong( hWnd
, nIndex
, wNewWord
, FALSE
);
1836 return NtUserSetWindowLong(hWnd
, nIndex
, dwNewLong
, TRUE
);
1849 return NtUserSetWindowLong(hWnd
, nIndex
, dwNewLong
, FALSE
);
1858 SetWindowLongPtrA(HWND hWnd
,
1862 return NtUserSetWindowLong(hWnd
, nIndex
, dwNewLong
, FALSE
);
1870 SetWindowLongPtrW(HWND hWnd
,
1874 return NtUserSetWindowLong(hWnd
, nIndex
, dwNewLong
, FALSE
);
1885 HINSTANCE hInstance
)
1887 UNICODE_STRING ClassName
= {0};
1890 TRACE("class/atom: %s/%04x %p\n",
1891 IS_ATOM(lpClassName
) ? NULL
: lpClassName
,
1892 IS_ATOM(lpClassName
) ? lpClassName
: 0,
1895 if (!IS_ATOM(lpClassName
))
1897 if (!RtlCreateUnicodeStringFromAsciiz(&ClassName
,
1900 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1905 ClassName
.Buffer
= (PWSTR
)((ULONG_PTR
)lpClassName
);
1907 Ret
= NtUserUnregisterClass(&ClassName
,
1911 if (!IS_ATOM(lpClassName
))
1912 RtlFreeUnicodeString(&ClassName
);
1924 LPCWSTR lpClassName
,
1925 HINSTANCE hInstance
)
1927 UNICODE_STRING ClassName
= {0};
1929 TRACE("class/atom: %S/%04x %p\n",
1930 IS_ATOM(lpClassName
) ? NULL
: lpClassName
,
1931 IS_ATOM(lpClassName
) ? lpClassName
: 0,
1934 if (!IS_ATOM(lpClassName
))
1936 RtlInitUnicodeString(&ClassName
,
1940 ClassName
.Buffer
= (PWSTR
)((ULONG_PTR
)lpClassName
);
1942 return NtUserUnregisterClass(&ClassName
,