2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS user32.dll
4 * FILE: win32ss/user/user32/windows/window.c
5 * PURPOSE: Window management
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
9 * 06-06-2001 CSH Created
15 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
17 void MDI_CalcDefaultChildPos( HWND hwndClient
, INT total
, LPPOINT lpPos
, INT delta
, UINT
*id
);
18 extern LPCWSTR FASTCALL
ClassNameToVersion(const void *lpszClass
, LPCWSTR lpszMenuName
, LPCWSTR
*plpLibFileName
, HANDLE
*pContext
, BOOL bAnsi
);
20 /* FUNCTIONS *****************************************************************/
24 User32CallSendAsyncProcForKernel(PVOID Arguments
, ULONG ArgumentLength
)
26 PSENDASYNCPROC_CALLBACK_ARGUMENTS CallbackArgs
;
28 TRACE("User32CallSendAsyncProcKernel()\n");
30 CallbackArgs
= (PSENDASYNCPROC_CALLBACK_ARGUMENTS
)Arguments
;
32 if (ArgumentLength
!= sizeof(SENDASYNCPROC_CALLBACK_ARGUMENTS
))
34 return(STATUS_INFO_LENGTH_MISMATCH
);
37 CallbackArgs
->Callback(CallbackArgs
->Wnd
,
39 CallbackArgs
->Context
,
40 CallbackArgs
->Result
);
41 return(STATUS_SUCCESS
);
49 AllowSetForegroundWindow(DWORD dwProcessId
)
51 return NtUserxAllowSetForegroundWindow(dwProcessId
);
59 BeginDeferWindowPos(int nNumWindows
)
61 return NtUserxBeginDeferWindowPos(nNumWindows
);
69 BringWindowToTop(HWND hWnd
)
71 return NtUserSetWindowPos(hWnd
,
77 SWP_NOSIZE
| SWP_NOMOVE
);
82 SwitchToThisWindow(HWND hwnd
, BOOL fAltTab
)
84 NtUserxSwitchToThisWindow(hwnd
, fAltTab
);
92 ChildWindowFromPoint(HWND hWndParent
,
95 return (HWND
) NtUserChildWindowFromPointEx(hWndParent
, Point
.x
, Point
.y
, 0);
103 ChildWindowFromPointEx(HWND hwndParent
,
107 return (HWND
) NtUserChildWindowFromPointEx(hwndParent
, pt
.x
, pt
.y
, uFlags
);
115 CloseWindow(HWND hWnd
)
117 /* NOTE: CloseWindow does minimizes, and doesn't close. */
118 SetActiveWindow(hWnd
);
119 return ShowWindow(hWnd
, SW_SHOWMINIMIZED
);
125 OUT PLARGE_STRING plstr
,
131 RtlInitLargeUnicodeString((PLARGE_UNICODE_STRING
)plstr
, (PWSTR
)psz
, 0);
135 RtlInitLargeAnsiString((PLARGE_ANSI_STRING
)plstr
, (PSTR
)psz
, 0);
142 IN PLARGE_STRING LargeString
)
144 if (LargeString
->Buffer
)
146 RtlFreeHeap(GetProcessHeap(), 0, LargeString
->Buffer
);
147 RtlZeroMemory(LargeString
, sizeof(LARGE_STRING
));
153 RtlGetExpWinVer( HMODULE hModule
)
155 DWORD dwMajorVersion
= 3; // Set default to Windows 3.10.
156 DWORD dwMinorVersion
= 10;
157 PIMAGE_NT_HEADERS pinth
;
159 if ( hModule
&& !((ULONG_PTR
)hModule
>> 16))
161 pinth
= RtlImageNtHeader( hModule
);
164 dwMajorVersion
= pinth
->OptionalHeader
.MajorSubsystemVersion
;
166 if ( dwMajorVersion
== 1 )
172 dwMinorVersion
= pinth
->OptionalHeader
.MinorSubsystemVersion
;
176 return MAKELONG(MAKEWORD(dwMinorVersion
, dwMajorVersion
), 0);
180 User32CreateWindowEx(DWORD dwExStyle
,
194 LARGE_STRING WindowName
;
195 LARGE_STRING lstrClassName
, *plstrClassName
;
196 LARGE_STRING lstrClassVersion
, *plstrClassVersion
;
197 UNICODE_STRING ClassName
;
198 UNICODE_STRING ClassVersion
;
201 HMODULE hLibModule
= NULL
;
203 BOOL Unicode
, ClassFound
= FALSE
;
205 LPCWSTR lpszClsVersion
;
206 LPCWSTR lpLibFileName
= NULL
;
211 DbgPrint("[window] User32CreateWindowEx style %d, exstyle %d, parent %d\n", dwStyle
, dwExStyle
, hWndParent
);
214 dwFlagsVer
= RtlGetExpWinVer( hInstance
? hInstance
: GetModuleHandleW(NULL
) );
215 TRACE("Module Version %x\n",dwFlagsVer
);
217 if (!RegisterDefaultClasses
)
219 TRACE("RegisterSystemControls\n");
220 RegisterSystemControls();
223 Unicode
= !(dwFlags
& NUCWE_ANSI
);
225 if (IS_ATOM(lpClassName
))
227 plstrClassName
= (PVOID
)lpClassName
;
233 RtlInitUnicodeString(&ClassName
, (PCWSTR
)lpClassName
);
237 if (!RtlCreateUnicodeStringFromAsciiz(&ClassName
, (PCSZ
)lpClassName
))
239 SetLastError(ERROR_OUTOFMEMORY
);
244 /* Copy it to a LARGE_STRING */
245 lstrClassName
.Buffer
= ClassName
.Buffer
;
246 lstrClassName
.Length
= ClassName
.Length
;
247 lstrClassName
.MaximumLength
= ClassName
.MaximumLength
;
248 plstrClassName
= &lstrClassName
;
251 /* Initialize a LARGE_STRING */
252 RtlInitLargeString(&WindowName
, lpWindowName
, Unicode
);
254 // HACK: The current implementation expects the Window name to be UNICODE
258 PSTR AnsiBuffer
= WindowName
.Buffer
;
259 ULONG AnsiLength
= WindowName
.Length
;
261 WindowName
.Length
= 0;
262 WindowName
.MaximumLength
= AnsiLength
* sizeof(WCHAR
);
263 WindowName
.Buffer
= RtlAllocateHeap(RtlGetProcessHeap(),
265 WindowName
.MaximumLength
);
266 if (!WindowName
.Buffer
)
268 SetLastError(ERROR_OUTOFMEMORY
);
272 Status
= RtlMultiByteToUnicodeN(WindowName
.Buffer
,
273 WindowName
.MaximumLength
,
277 if (!NT_SUCCESS(Status
))
283 if (!hMenu
&& (dwStyle
& (WS_OVERLAPPEDWINDOW
| WS_POPUP
)))
287 wceW
.cbSize
= sizeof(wceW
);
288 if (GetClassInfoExW(hInstance
, (LPCWSTR
)lpClassName
, &wceW
) && wceW
.lpszMenuName
)
290 hMenu
= LoadMenuW(hInstance
, wceW
.lpszMenuName
);
295 wceA
.cbSize
= sizeof(wceA
);
296 if (GetClassInfoExA(hInstance
, lpClassName
, &wceA
) && wceA
.lpszMenuName
)
298 hMenu
= LoadMenuA(hInstance
, wceA
.lpszMenuName
);
303 if (!Unicode
) dwExStyle
|= WS_EX_SETANSICREATOR
;
305 lpszClsVersion
= ClassNameToVersion(lpClassName
, NULL
, &lpLibFileName
, &pCtx
, !Unicode
);
308 plstrClassVersion
= plstrClassName
;
312 RtlInitUnicodeString(&ClassVersion
, lpszClsVersion
);
313 lstrClassVersion
.Buffer
= ClassVersion
.Buffer
;
314 lstrClassVersion
.Length
= ClassVersion
.Length
;
315 lstrClassVersion
.MaximumLength
= ClassVersion
.MaximumLength
;
316 plstrClassVersion
= &lstrClassVersion
;
321 Handle
= NtUserCreateWindowEx(dwExStyle
,
337 if (!lpLibFileName
) break;
340 dwLastError
= GetLastError();
341 if (dwLastError
== ERROR_CANNOT_FIND_WND_CLASS
)
343 ClassFound
= VersionRegisterClass(ClassName
.Buffer
, lpLibFileName
, pCtx
, &hLibModule
);
344 if (ClassFound
) continue;
349 dwLastError
= GetLastError();
350 FreeLibrary(hLibModule
);
351 SetLastError(dwLastError
);
358 DbgPrint("[window] NtUserCreateWindowEx() == %d\n", Handle
);
364 if (!IS_ATOM(lpClassName
))
365 RtlFreeUnicodeString(&ClassName
);
367 RtlFreeLargeString(&WindowName
);
380 CreateWindowExA(DWORD dwExStyle
,
393 MDICREATESTRUCTA mdi
;
396 if (!RegisterDefaultClasses
)
398 TRACE("CreateWindowExA RegisterSystemControls\n");
399 RegisterSystemControls();
402 if (dwExStyle
& WS_EX_MDICHILD
)
409 pWndParent
= ValidateHwnd(hWndParent
);
411 if (!pWndParent
) return NULL
;
413 if (pWndParent
->fnid
!= FNID_MDICLIENT
) // wine uses WIN_ISMDICLIENT
415 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
419 /* lpParams of WM_[NC]CREATE is different for MDI children.
420 * MDICREATESTRUCT members have the originally passed values.
422 mdi
.szClass
= lpClassName
;
423 mdi
.szTitle
= lpWindowName
;
424 mdi
.hOwner
= hInstance
;
430 mdi
.lParam
= (LPARAM
)lpParam
;
432 lpParam
= (LPVOID
)&mdi
;
434 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
436 if (dwStyle
& WS_POPUP
)
438 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
441 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
445 dwStyle
&= ~WS_POPUP
;
446 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
447 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
450 top_child
= GetWindow(hWndParent
, GW_CHILD
);
454 /* Restore current maximized child */
455 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
457 TRACE("Restoring current maximized child %p\n", top_child
);
458 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
459 ShowWindow(top_child
, SW_RESTORE
);
460 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
464 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
466 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
468 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
470 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
475 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
477 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
483 hwnd
= User32CreateWindowEx(dwExStyle
,
506 CreateWindowExW(DWORD dwExStyle
,
508 LPCWSTR lpWindowName
,
519 MDICREATESTRUCTW mdi
;
522 if (!RegisterDefaultClasses
)
524 ERR("CreateWindowExW RegisterSystemControls\n");
525 RegisterSystemControls();
528 if (dwExStyle
& WS_EX_MDICHILD
)
535 pWndParent
= ValidateHwnd(hWndParent
);
537 if (!pWndParent
) return NULL
;
539 if (pWndParent
->fnid
!= FNID_MDICLIENT
)
541 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
545 /* lpParams of WM_[NC]CREATE is different for MDI children.
546 * MDICREATESTRUCT members have the originally passed values.
548 mdi
.szClass
= lpClassName
;
549 mdi
.szTitle
= lpWindowName
;
550 mdi
.hOwner
= hInstance
;
556 mdi
.lParam
= (LPARAM
)lpParam
;
558 lpParam
= (LPVOID
)&mdi
;
560 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
562 if (dwStyle
& WS_POPUP
)
564 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
567 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
571 dwStyle
&= ~WS_POPUP
;
572 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
573 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
576 top_child
= GetWindow(hWndParent
, GW_CHILD
);
580 /* Restore current maximized child */
581 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
583 TRACE("Restoring current maximized child %p\n", top_child
);
584 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
585 ShowWindow(top_child
, SW_RESTORE
);
586 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
590 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
592 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
594 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
596 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
601 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
603 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
609 hwnd
= User32CreateWindowEx(dwExStyle
,
611 (LPCSTR
)lpWindowName
,
629 DeferWindowPos(HDWP hWinPosInfo
,
631 HWND hWndInsertAfter
,
638 return NtUserDeferWindowPos(hWinPosInfo
, hWnd
, hWndInsertAfter
, x
, y
, cx
, cy
, uFlags
);
646 EndDeferWindowPos(HDWP hWinPosInfo
)
648 return NtUserEndDeferWindowPosEx(hWinPosInfo
, 0);
656 GetDesktopWindow(VOID
)
663 Wnd
= GetThreadDesktopWnd();
665 Ret
= UserHMGetHandle(Wnd
);
667 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
678 User32EnumWindows(HDESK hDesktop
,
685 DWORD i
, dwCount
= 0;
692 SetLastError ( ERROR_INVALID_PARAMETER
);
696 /* FIXME instead of always making two calls, should we use some
697 sort of persistent buffer and only grow it ( requiring a 2nd
698 call ) when the buffer wasn't already big enough? */
699 /* first get how many window entries there are */
700 Status
= NtUserBuildHwndList(hDesktop
,
707 if (!NT_SUCCESS(Status
))
718 /* allocate buffer to receive HWND handles */
719 hHeap
= GetProcessHeap();
720 pHwnd
= HeapAlloc(hHeap
, 0, sizeof(HWND
)*(dwCount
+1));
723 SetLastError ( ERROR_NOT_ENOUGH_MEMORY
);
727 /* now call kernel again to fill the buffer this time */
728 Status
= NtUserBuildHwndList(hDesktop
,
735 if (!NT_SUCCESS(Status
))
738 HeapFree(hHeap
, 0, pHwnd
);
742 /* call the user's callback function until we're done or
743 they tell us to quit */
744 for ( i
= 0; i
< dwCount
; i
++ )
746 /* FIXME I'm only getting NULLs from Thread Enumeration, and it's
747 * probably because I'm not doing it right in NtUserBuildHwndList.
748 * Once that's fixed, we shouldn't have to check for a NULL HWND
750 * This is now fixed in revision 50205. (jt)
752 if (!pHwnd
[i
]) /* don't enumerate a NULL HWND */
754 if (!(*lpfn
)(pHwnd
[i
], lParam
))
756 HeapFree ( hHeap
, 0, pHwnd
);
761 HeapFree(hHeap
, 0, pHwnd
);
770 EnumChildWindows(HWND hWndParent
,
771 WNDENUMPROC lpEnumFunc
,
776 return EnumWindows(lpEnumFunc
, lParam
);
778 return User32EnumWindows(NULL
, hWndParent
, lpEnumFunc
, lParam
, 0, TRUE
);
786 EnumThreadWindows(DWORD dwThreadId
,
791 dwThreadId
= GetCurrentThreadId();
792 return User32EnumWindows(NULL
, NULL
, lpfn
, lParam
, dwThreadId
, FALSE
);
800 EnumWindows(WNDENUMPROC lpEnumFunc
,
803 return User32EnumWindows(NULL
, NULL
, lpEnumFunc
, lParam
, 0, FALSE
);
811 EnumDesktopWindows(HDESK hDesktop
,
815 return User32EnumWindows(hDesktop
, NULL
, lpfn
, lParam
, 0, FALSE
);
823 FindWindowExA(HWND hwndParent
,
828 LPWSTR titleW
= NULL
;
833 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, lpszWindow
, -1, NULL
, 0 );
834 if (!(titleW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
835 MultiByteToWideChar( CP_ACP
, 0, lpszWindow
, -1, titleW
, len
);
838 if (!IS_INTRESOURCE(lpszClass
))
841 if (MultiByteToWideChar( CP_ACP
, 0, lpszClass
, -1, classW
, sizeof(classW
)/sizeof(WCHAR
) ))
842 hwnd
= FindWindowExW( hwndParent
, hwndChildAfter
, classW
, titleW
);
846 hwnd
= FindWindowExW( hwndParent
, hwndChildAfter
, (LPCWSTR
)lpszClass
, titleW
);
849 HeapFree( GetProcessHeap(), 0, titleW
);
858 FindWindowExW(HWND hwndParent
,
863 UNICODE_STRING ucClassName
, *pucClassName
= NULL
;
864 UNICODE_STRING ucWindowName
, *pucWindowName
= NULL
;
866 if (IS_ATOM(lpszClass
))
868 ucClassName
.Length
= 0;
869 ucClassName
.Buffer
= (LPWSTR
)lpszClass
;
870 pucClassName
= &ucClassName
;
872 else if (lpszClass
!= NULL
)
874 RtlInitUnicodeString(&ucClassName
,
876 pucClassName
= &ucClassName
;
879 if (lpszWindow
!= NULL
)
881 RtlInitUnicodeString(&ucWindowName
,
883 pucWindowName
= &ucWindowName
;
886 return NtUserFindWindowEx(hwndParent
,
898 FindWindowA(LPCSTR lpClassName
, LPCSTR lpWindowName
)
900 //FIXME: FindWindow does not search children, but FindWindowEx does.
901 // what should we do about this?
902 return FindWindowExA (NULL
, NULL
, lpClassName
, lpWindowName
);
910 FindWindowW(LPCWSTR lpClassName
, LPCWSTR lpWindowName
)
914 There was a FIXME here earlier, but I think it is just a documentation unclarity.
916 FindWindow only searches top level windows. What they mean is that child
917 windows of other windows than the desktop can be searched.
918 FindWindowExW never does a recursive search.
923 return FindWindowExW(NULL
, NULL
, lpClassName
, lpWindowName
);
932 GetAltTabInfoA(HWND hwnd
,
938 return NtUserGetAltTabInfo(hwnd
,iItem
,pati
,(LPWSTR
)pszItemText
,cchItemText
,TRUE
);
946 GetAltTabInfoW(HWND hwnd
,
952 return NtUserGetAltTabInfo(hwnd
,iItem
,pati
,pszItemText
,cchItemText
,FALSE
);
960 GetAncestor(HWND hwnd
, UINT gaFlags
)
965 Wnd
= ValidateHwnd(hwnd
);
975 if (Wnd
->spwndParent
!= NULL
)
976 Ancestor
= DesktopPtrToUser(Wnd
->spwndParent
);
980 /* FIXME: Call win32k for now */
985 if (Ancestor
!= NULL
)
986 Ret
= UserHMGetHandle(Ancestor
);
988 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
994 if (!Wnd
) /* Fall back */
995 Ret
= NtUserGetAncestor(hwnd
, gaFlags
);
1005 GetClientRect(HWND hWnd
, LPRECT lpRect
)
1007 PWND Wnd
= ValidateHwnd(hWnd
);
1009 if (!Wnd
) return FALSE
;
1010 if (Wnd
->style
& WS_MINIMIZED
)
1012 lpRect
->left
= lpRect
->top
= 0;
1013 lpRect
->right
= GetSystemMetrics(SM_CXMINIMIZED
);
1014 lpRect
->bottom
= GetSystemMetrics(SM_CYMINIMIZED
);
1017 if ( hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
1019 /* lpRect->left = lpRect->top = 0;
1020 lpRect->right = Wnd->rcClient.right - Wnd->rcClient.left;
1021 lpRect->bottom = Wnd->rcClient.bottom - Wnd->rcClient.top;
1023 *lpRect
= Wnd
->rcClient
;
1024 OffsetRect(lpRect
, -Wnd
->rcClient
.left
, -Wnd
->rcClient
.top
);
1028 lpRect
->left
= lpRect
->top
= 0;
1029 lpRect
->right
= Wnd
->rcClient
.right
;
1030 lpRect
->bottom
= Wnd
->rcClient
.bottom
;
1031 /* Do this until Init bug is fixed. This sets 640x480, see InitMetrics.
1032 lpRect->right = GetSystemMetrics(SM_CXSCREEN);
1033 lpRect->bottom = GetSystemMetrics(SM_CYSCREEN);
1043 GetLastActivePopup(HWND hWnd
)
1048 Wnd
= ValidateHwnd(hWnd
);
1053 if (Wnd
->spwndLastActive
)
1055 PWND LastActive
= DesktopPtrToUser(Wnd
->spwndLastActive
);
1056 Ret
= UserHMGetHandle(LastActive
);
1059 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1073 GetParent(HWND hWnd
)
1075 PWND Wnd
, WndParent
;
1078 Wnd
= ValidateHwnd(hWnd
);
1084 if (Wnd
->style
& WS_POPUP
)
1086 if (Wnd
->spwndOwner
!= NULL
)
1087 WndParent
= DesktopPtrToUser(Wnd
->spwndOwner
);
1089 else if (Wnd
->style
& WS_CHILD
)
1091 if (Wnd
->spwndParent
!= NULL
)
1092 WndParent
= DesktopPtrToUser(Wnd
->spwndParent
);
1095 if (WndParent
!= NULL
)
1096 Ret
= UserHMGetHandle(WndParent
);
1098 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1113 GetProcessDefaultLayout(DWORD
*pdwDefaultLayout
)
1115 return (BOOL
)NtUserCallOneParam( (DWORD_PTR
)pdwDefaultLayout
, ONEPARAM_ROUTINE_GETPROCDEFLAYOUT
);
1123 GetWindow(HWND hWnd
,
1129 Wnd
= ValidateHwnd(hWnd
);
1139 if (Wnd
->spwndOwner
!= NULL
)
1140 FoundWnd
= DesktopPtrToUser(Wnd
->spwndOwner
);
1144 if(Wnd
->spwndParent
!= NULL
)
1146 FoundWnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1147 if (FoundWnd
->spwndChild
!= NULL
)
1148 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndChild
);
1152 if (Wnd
->spwndNext
!= NULL
)
1153 FoundWnd
= DesktopPtrToUser(Wnd
->spwndNext
);
1157 if (Wnd
->spwndPrev
!= NULL
)
1158 FoundWnd
= DesktopPtrToUser(Wnd
->spwndPrev
);
1162 if (Wnd
->spwndChild
!= NULL
)
1163 FoundWnd
= DesktopPtrToUser(Wnd
->spwndChild
);
1168 while ( FoundWnd
->spwndNext
!= NULL
)
1169 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndNext
);
1177 if (FoundWnd
!= NULL
)
1178 Ret
= UserHMGetHandle(FoundWnd
);
1180 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1194 GetTopWindow(HWND hWnd
)
1196 if (!hWnd
) hWnd
= GetDesktopWindow();
1197 return GetWindow(hWnd
, GW_CHILD
);
1207 GetWindowInfo(HWND hWnd
,
1215 if ( !pwi
|| pwi
->cbSize
!= sizeof(WINDOWINFO
))
1216 SetLastError(ERROR_INVALID_PARAMETER
); // Just set the error and go!
1218 pWnd
= ValidateHwnd(hWnd
);
1222 UserGetWindowBorders(pWnd
->style
, pWnd
->ExStyle
, &Size
, FALSE
);
1226 pCls
= DesktopPtrToUser(pWnd
->pcls
);
1227 pwi
->rcWindow
= pWnd
->rcWindow
;
1228 pwi
->rcClient
= pWnd
->rcClient
;
1229 pwi
->dwStyle
= pWnd
->style
;
1230 pwi
->dwExStyle
= pWnd
->ExStyle
;
1231 pwi
->cxWindowBorders
= Size
.cx
;
1232 pwi
->cyWindowBorders
= Size
.cy
;
1233 pwi
->dwWindowStatus
= 0;
1234 if (pWnd
->state
& WNDS_ACTIVEFRAME
|| (GetActiveWindow() == hWnd
))
1235 pwi
->dwWindowStatus
= WS_ACTIVECAPTION
;
1236 pwi
->atomWindowType
= (pCls
? pCls
->atomClassName
: 0 );
1238 if ( pWnd
->state2
& WNDS2_WIN50COMPAT
)
1240 pwi
->wCreatorVersion
= 0x500;
1242 else if ( pWnd
->state2
& WNDS2_WIN40COMPAT
)
1244 pwi
->wCreatorVersion
= 0x400;
1246 else if ( pWnd
->state2
& WNDS2_WIN31COMPAT
)
1248 pwi
->wCreatorVersion
= 0x30A;
1252 pwi
->wCreatorVersion
= 0x300;
1257 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1271 GetWindowModuleFileNameA(HWND hwnd
,
1273 UINT cchFileNameMax
)
1275 PWND Wnd
= ValidateHwnd(hwnd
);
1280 return GetModuleFileNameA(Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1288 GetWindowModuleFileNameW(HWND hwnd
,
1289 LPWSTR lpszFileName
,
1290 UINT cchFileNameMax
)
1292 PWND Wnd
= ValidateHwnd(hwnd
);
1297 return GetModuleFileNameW( Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1304 GetWindowRect(HWND hWnd
,
1307 PWND Wnd
= ValidateHwnd(hWnd
);
1309 if (!Wnd
) return FALSE
;
1310 if ( hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
1312 *lpRect
= Wnd
->rcWindow
;
1316 lpRect
->left
= lpRect
->top
= 0;
1317 lpRect
->right
= Wnd
->rcWindow
.right
;
1318 lpRect
->bottom
= Wnd
->rcWindow
.bottom
;
1319 /* Do this until Init bug is fixed. This sets 640x480, see InitMetrics.
1320 lpRect->right = GetSystemMetrics(SM_CXSCREEN);
1321 lpRect->bottom = GetSystemMetrics(SM_CYSCREEN);
1330 GetWindowTextA(HWND hWnd
, LPSTR lpString
, int nMaxCount
)
1335 if (lpString
== NULL
|| nMaxCount
== 0)
1338 Wnd
= ValidateHwnd(hWnd
);
1344 if (!TestWindowProcess(Wnd
))
1348 Length
= DefWindowProcA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1350 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1358 Length
= SendMessageA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1360 //ERR("GWTA Len %d : %s\n",Length,lpString);
1368 GetWindowTextLengthA(HWND hWnd
)
1372 Wnd
= ValidateHwnd(hWnd
);
1376 if (!TestWindowProcess(Wnd
))
1378 return DefWindowProcA(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1382 return SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1390 GetWindowTextLengthW(HWND hWnd
)
1394 Wnd
= ValidateHwnd(hWnd
);
1398 if (!TestWindowProcess(Wnd
))
1400 return DefWindowProcW(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1404 return SendMessageW(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1412 GetWindowTextW(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1417 if (lpString
== NULL
|| nMaxCount
== 0)
1420 Wnd
= ValidateHwnd(hWnd
);
1424 lpString
[0] = L
'\0';
1426 if (!TestWindowProcess(Wnd
))
1430 Length
= DefWindowProcW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1432 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1440 Length
= SendMessageW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1442 //ERR("GWTW Len %d : %S\n",Length,lpString);
1447 GetWindowThreadProcessId(HWND hWnd
,
1448 LPDWORD lpdwProcessId
)
1452 PWND pWnd
= ValidateHwnd(hWnd
);
1454 if (!pWnd
) return Ret
;
1456 ti
= pWnd
->head
.pti
;
1460 if (ti
== GetW32ThreadInfo())
1461 { // We are current.
1462 //FIXME("Current!\n");
1464 *lpdwProcessId
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueProcess
;
1465 Ret
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueThread
;
1468 { // Ask kernel for info.
1469 //FIXME("Kernel call!\n");
1471 *lpdwProcessId
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
);
1472 Ret
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_THREAD_ID
);
1483 IsChild(HWND hWndParent
,
1486 PWND WndParent
, DesktopWnd
, Wnd
;
1489 WndParent
= ValidateHwnd(hWndParent
);
1492 Wnd
= ValidateHwnd(hWnd
);
1496 DesktopWnd
= GetThreadDesktopWnd();
1502 while (Wnd
!= NULL
&& ((Wnd
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
1504 if (Wnd
->spwndParent
!= NULL
)
1506 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1508 if (Wnd
== WndParent
)
1518 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1534 PWND Wnd
= ValidateHwnd(hWnd
);
1537 return (Wnd
->style
& WS_MINIMIZE
) != 0;
1549 PWND Wnd
= ValidateHwndNoErr(hWnd
);
1552 if (Wnd
->state
& WNDS_DESTROYED
||
1553 Wnd
->state2
& WNDS2_INDESTROY
)
1566 IsWindowUnicode(HWND hWnd
)
1568 PWND Wnd
= ValidateHwnd(hWnd
);
1571 return Wnd
->Unicode
;
1581 IsWindowVisible(HWND hWnd
)
1584 PWND Wnd
= ValidateHwnd(hWnd
);
1594 if (!(Wnd
->style
& WS_VISIBLE
))
1600 if (Wnd
->spwndParent
!= NULL
)
1601 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1605 } while (Wnd
!= NULL
);
1607 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1622 IsWindowEnabled(HWND hWnd
)
1624 // AG: I don't know if child windows are affected if the parent is
1625 // disabled. I think they stop processing messages but stay appearing
1628 return !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_DISABLED
);
1638 return (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
1646 LockSetForegroundWindow(UINT uLockCode
)
1648 return NtUserxLockSetForegroundWindow(uLockCode
);
1656 AnimateWindow(HWND hwnd
,
1660 /* FIXME Add animation code */
1662 /* If trying to show/hide and it's already *
1663 * shown/hidden or invalid window, fail with *
1664 * invalid parameter */
1667 visible
= IsWindowVisible(hwnd
);
1668 if(!IsWindow(hwnd
) ||
1669 (visible
&& !(dwFlags
& AW_HIDE
)) ||
1670 (!visible
&& (dwFlags
& AW_HIDE
)))
1672 SetLastError(ERROR_INVALID_PARAMETER
);
1676 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1688 if (!(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1691 ShowWindow(hWnd
,SW_RESTORE
);
1700 RealChildWindowFromPoint(HWND hwndParent
,
1701 POINT ptParentClientCoords
)
1703 return NtUserRealChildWindowFromPoint(hwndParent
, ptParentClientCoords
.x
, ptParentClientCoords
.y
);
1710 SetForegroundWindow(HWND hWnd
)
1712 return NtUserxSetForegroundWindow(hWnd
);
1720 SetProcessDefaultLayout(DWORD dwDefaultLayout
)
1722 return NtUserCallOneParam( (DWORD_PTR
)dwDefaultLayout
, ONEPARAM_ROUTINE_SETPROCDEFLAYOUT
);
1732 SetWindowTextA(HWND hWnd
,
1737 pwnd
= ValidateHwnd(hWnd
);
1740 if (!TestWindowProcess(pwnd
))
1742 /* do not send WM_GETTEXT messages to other processes */
1743 return (DefWindowProcA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1745 return (SendMessageA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1757 SetWindowTextW(HWND hWnd
,
1762 pwnd
= ValidateHwnd(hWnd
);
1765 if (!TestWindowProcess(pwnd
))
1767 /* do not send WM_GETTEXT messages to other processes */
1768 return (DefWindowProcW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1770 return (SendMessageW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1780 ShowOwnedPopups(HWND hWnd
, BOOL fShow
)
1782 return NtUserxShowOwnedPopups(hWnd
, fShow
);
1790 UpdateLayeredWindow( HWND hwnd
,
1800 if (dwFlags
& ULW_EX_NORESIZE
) /* only valid for UpdateLayeredWindowIndirect */
1802 SetLastError( ERROR_INVALID_PARAMETER
);
1805 return NtUserUpdateLayeredWindow( hwnd
,
1821 UpdateLayeredWindowIndirect(HWND hwnd
,
1822 const UPDATELAYEREDWINDOWINFO
*info
)
1824 if (info
&& info
->cbSize
== sizeof(*info
))
1826 return NtUserUpdateLayeredWindow( hwnd
,
1828 (POINT
*)info
->pptDst
,
1829 (SIZE
*)info
->psize
,
1831 (POINT
*)info
->pptSrc
,
1833 (BLENDFUNCTION
*)info
->pblend
,
1835 (RECT
*)info
->prcDirty
);
1837 SetLastError(ERROR_INVALID_PARAMETER
);
1845 SetWindowContextHelpId(HWND hwnd
,
1846 DWORD dwContextHelpId
)
1848 return NtUserxSetWindowContextHelpId(hwnd
, dwContextHelpId
);
1855 GetWindowContextHelpId(HWND hwnd
)
1857 return NtUserxGetWindowContextHelpId(hwnd
);
1864 InternalGetWindowText(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1866 INT Ret
= NtUserInternalGetWindowText(hWnd
, lpString
, nMaxCount
);
1867 if (Ret
== 0 && lpString
)
1876 IsHungAppWindow(HWND hwnd
)
1879 UNICODE_STRING ClassName
;
1881 static const UNICODE_STRING GhostClass
= RTL_CONSTANT_STRING(L
"Ghost");
1883 /* Ghost is a hung window */
1884 RtlInitEmptyUnicodeString(&ClassName
, szClass
, sizeof(szClass
));
1885 Window
= ValidateHwnd(hwnd
);
1886 if (Window
&& Window
->fnid
== FNID_GHOST
&&
1887 NtUserGetClassName(hwnd
, FALSE
, &ClassName
) &&
1888 RtlEqualUnicodeString(&ClassName
, &GhostClass
, TRUE
))
1893 return (NtUserQueryWindow(hwnd
, QUERY_WINDOW_ISHUNG
) != 0);
1900 SetLastErrorEx(DWORD dwErrCode
, DWORD dwType
)
1902 SetLastError(dwErrCode
);
1911 return (HWND
)NtUserGetThreadState(THREADSTATE_FOCUSWINDOW
);
1915 GetRealWindowOwner(HWND hwnd
)
1917 return NtUserQueryWindow(hwnd
, QUERY_WINDOW_REAL_ID
);
1924 SetTaskmanWindow(HWND hWnd
)
1926 return NtUserxSetTaskmanWindow(hWnd
);
1933 SetProgmanWindow(HWND hWnd
)
1935 return NtUserxSetProgmanWindow(hWnd
);
1942 GetProgmanWindow(VOID
)
1944 return (HWND
)NtUserGetThreadState(THREADSTATE_PROGMANWINDOW
);
1951 GetTaskmanWindow(VOID
)
1953 return (HWND
)NtUserGetThreadState(THREADSTATE_TASKMANWINDOW
);
1960 ScrollWindow(HWND hWnd
,
1964 CONST RECT
*prcClip
)
1966 return NtUserScrollWindowEx(hWnd
,
1973 (lpRect
? 0 : SW_SCROLLCHILDREN
) | (SW_ERASE
|SW_INVALIDATE
|SW_SCROLLWNDDCE
)) != ERROR
;
1976 /* ScrollWindow uses the window DC, ScrollWindowEx doesn't */
1982 ScrollWindowEx(HWND hWnd
,
1985 CONST RECT
*prcScroll
,
1986 CONST RECT
*prcClip
,
1991 if (flags
& SW_SMOOTHSCROLL
)
1993 FIXME("SW_SMOOTHSCROLL not supported.");
1996 return NtUserScrollWindowEx(hWnd
,
2014 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
2016 if (!list
) return FALSE
;
2017 for (i
= 0; list
[i
]; i
++)
2019 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
2021 retvalue
= (list
[i
] != 0);
2022 HeapFree( GetProcessHeap(), 0, list
);
2030 IsWindowInDestroy(HWND hWnd
)
2033 pwnd
= ValidateHwnd(hWnd
);
2036 return ((pwnd
->state2
& WNDS2_INDESTROY
) == WNDS2_INDESTROY
);
2043 DisableProcessWindowsGhosting(VOID
)
2045 NtUserxEnableProcessWindowGhosting(FALSE
);