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 bUnknown
)
84 NtUserxSwitchToThisWindow(hwnd
, bUnknown
);
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
));
152 User32CreateWindowEx(DWORD dwExStyle
,
166 LARGE_STRING WindowName
;
167 LARGE_STRING lstrClassName
, *plstrClassName
;
168 LARGE_STRING lstrClassVersion
, *plstrClassVersion
;
169 UNICODE_STRING ClassName
;
170 UNICODE_STRING ClassVersion
;
173 HMODULE hLibModule
= NULL
;
175 BOOL Unicode
, ClassFound
= FALSE
;
177 LPCWSTR lpszClsVersion
;
178 LPCWSTR lpLibFileName
= NULL
;
182 DbgPrint("[window] User32CreateWindowEx style %d, exstyle %d, parent %d\n", dwStyle
, dwExStyle
, hWndParent
);
185 if (!RegisterDefaultClasses
)
187 TRACE("RegisterSystemControls\n");
188 RegisterSystemControls();
191 Unicode
= !(dwFlags
& NUCWE_ANSI
);
193 if (IS_ATOM(lpClassName
))
195 plstrClassName
= (PVOID
)lpClassName
;
201 RtlInitUnicodeString(&ClassName
, (PCWSTR
)lpClassName
);
205 if (!RtlCreateUnicodeStringFromAsciiz(&ClassName
, (PCSZ
)lpClassName
))
207 SetLastError(ERROR_OUTOFMEMORY
);
212 /* Copy it to a LARGE_STRING */
213 lstrClassName
.Buffer
= ClassName
.Buffer
;
214 lstrClassName
.Length
= ClassName
.Length
;
215 lstrClassName
.MaximumLength
= ClassName
.MaximumLength
;
216 plstrClassName
= &lstrClassName
;
219 /* Initialize a LARGE_STRING */
220 RtlInitLargeString(&WindowName
, lpWindowName
, Unicode
);
222 // HACK: The current implementation expects the Window name to be UNICODE
226 PSTR AnsiBuffer
= WindowName
.Buffer
;
227 ULONG AnsiLength
= WindowName
.Length
;
229 WindowName
.Length
= 0;
230 WindowName
.MaximumLength
= AnsiLength
* sizeof(WCHAR
);
231 WindowName
.Buffer
= RtlAllocateHeap(RtlGetProcessHeap(),
233 WindowName
.MaximumLength
);
234 if (!WindowName
.Buffer
)
236 SetLastError(ERROR_OUTOFMEMORY
);
240 Status
= RtlMultiByteToUnicodeN(WindowName
.Buffer
,
241 WindowName
.MaximumLength
,
245 if (!NT_SUCCESS(Status
))
251 if (!hMenu
&& (dwStyle
& (WS_OVERLAPPEDWINDOW
| WS_POPUP
)))
255 wceW
.cbSize
= sizeof(wceW
);
256 if (GetClassInfoExW(hInstance
, (LPCWSTR
)lpClassName
, &wceW
) && wceW
.lpszMenuName
)
258 hMenu
= LoadMenuW(hInstance
, wceW
.lpszMenuName
);
263 wceA
.cbSize
= sizeof(wceA
);
264 if (GetClassInfoExA(hInstance
, lpClassName
, &wceA
) && wceA
.lpszMenuName
)
266 hMenu
= LoadMenuA(hInstance
, wceA
.lpszMenuName
);
271 if (!Unicode
) dwExStyle
|= WS_EX_SETANSICREATOR
;
273 lpszClsVersion
= ClassNameToVersion(lpClassName
, NULL
, &lpLibFileName
, &pCtx
, !Unicode
);
276 plstrClassVersion
= plstrClassName
;
280 RtlInitUnicodeString(&ClassVersion
, lpszClsVersion
);
281 lstrClassVersion
.Buffer
= ClassVersion
.Buffer
;
282 lstrClassVersion
.Length
= ClassVersion
.Length
;
283 lstrClassVersion
.MaximumLength
= ClassVersion
.MaximumLength
;
284 plstrClassVersion
= &lstrClassVersion
;
289 Handle
= NtUserCreateWindowEx(dwExStyle
,
305 if (!lpLibFileName
) break;
308 dwLastError
= GetLastError();
309 if (dwLastError
== ERROR_CANNOT_FIND_WND_CLASS
)
311 ClassFound
= VersionRegisterClass(ClassName
.Buffer
, lpLibFileName
, pCtx
, &hLibModule
);
312 if (ClassFound
) continue;
317 dwLastError
= GetLastError();
318 FreeLibrary(hLibModule
);
319 SetLastError(dwLastError
);
326 DbgPrint("[window] NtUserCreateWindowEx() == %d\n", Handle
);
332 if (!IS_ATOM(lpClassName
))
333 RtlFreeUnicodeString(&ClassName
);
335 RtlFreeLargeString(&WindowName
);
348 CreateWindowExA(DWORD dwExStyle
,
361 MDICREATESTRUCTA mdi
;
364 if (!RegisterDefaultClasses
)
366 TRACE("CreateWindowExA RegisterSystemControls\n");
367 RegisterSystemControls();
370 if (dwExStyle
& WS_EX_MDICHILD
)
377 pWndParent
= ValidateHwnd(hWndParent
);
379 if (!pWndParent
) return NULL
;
381 if (pWndParent
->fnid
!= FNID_MDICLIENT
) // wine uses WIN_ISMDICLIENT
383 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
387 /* lpParams of WM_[NC]CREATE is different for MDI children.
388 * MDICREATESTRUCT members have the originally passed values.
390 mdi
.szClass
= lpClassName
;
391 mdi
.szTitle
= lpWindowName
;
392 mdi
.hOwner
= hInstance
;
398 mdi
.lParam
= (LPARAM
)lpParam
;
400 lpParam
= (LPVOID
)&mdi
;
402 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
404 if (dwStyle
& WS_POPUP
)
406 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
409 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
413 dwStyle
&= ~WS_POPUP
;
414 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
415 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
418 top_child
= GetWindow(hWndParent
, GW_CHILD
);
422 /* Restore current maximized child */
423 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
425 TRACE("Restoring current maximized child %p\n", top_child
);
426 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
427 ShowWindow(top_child
, SW_RESTORE
);
428 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
432 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
434 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
436 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
438 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
443 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
445 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
450 hwnd
= User32CreateWindowEx(dwExStyle
,
473 CreateWindowExW(DWORD dwExStyle
,
475 LPCWSTR lpWindowName
,
486 MDICREATESTRUCTW mdi
;
489 if (!RegisterDefaultClasses
)
491 ERR("CreateWindowExW RegisterSystemControls\n");
492 RegisterSystemControls();
495 if (dwExStyle
& WS_EX_MDICHILD
)
502 pWndParent
= ValidateHwnd(hWndParent
);
504 if (!pWndParent
) return NULL
;
506 if (pWndParent
->fnid
!= FNID_MDICLIENT
)
508 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
512 /* lpParams of WM_[NC]CREATE is different for MDI children.
513 * MDICREATESTRUCT members have the originally passed values.
515 mdi
.szClass
= lpClassName
;
516 mdi
.szTitle
= lpWindowName
;
517 mdi
.hOwner
= hInstance
;
523 mdi
.lParam
= (LPARAM
)lpParam
;
525 lpParam
= (LPVOID
)&mdi
;
527 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
529 if (dwStyle
& WS_POPUP
)
531 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
534 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
538 dwStyle
&= ~WS_POPUP
;
539 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
540 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
543 top_child
= GetWindow(hWndParent
, GW_CHILD
);
547 /* Restore current maximized child */
548 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
550 TRACE("Restoring current maximized child %p\n", top_child
);
551 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
552 ShowWindow(top_child
, SW_RESTORE
);
553 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
557 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
559 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
561 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
563 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
568 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
570 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
575 hwnd
= User32CreateWindowEx(dwExStyle
,
577 (LPCSTR
)lpWindowName
,
595 DeferWindowPos(HDWP hWinPosInfo
,
597 HWND hWndInsertAfter
,
604 return NtUserDeferWindowPos(hWinPosInfo
, hWnd
, hWndInsertAfter
, x
, y
, cx
, cy
, uFlags
);
612 EndDeferWindowPos(HDWP hWinPosInfo
)
614 return NtUserEndDeferWindowPosEx(hWinPosInfo
, 0);
622 GetDesktopWindow(VOID
)
629 Wnd
= GetThreadDesktopWnd();
631 Ret
= UserHMGetHandle(Wnd
);
633 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
644 User32EnumWindows(HDESK hDesktop
,
651 DWORD i
, dwCount
= 0;
658 SetLastError ( ERROR_INVALID_PARAMETER
);
662 /* FIXME instead of always making two calls, should we use some
663 sort of persistent buffer and only grow it ( requiring a 2nd
664 call ) when the buffer wasn't already big enough? */
665 /* first get how many window entries there are */
666 Status
= NtUserBuildHwndList(hDesktop
,
673 if (!NT_SUCCESS(Status
))
684 /* allocate buffer to receive HWND handles */
685 hHeap
= GetProcessHeap();
686 pHwnd
= HeapAlloc(hHeap
, 0, sizeof(HWND
)*(dwCount
+1));
689 SetLastError ( ERROR_NOT_ENOUGH_MEMORY
);
693 /* now call kernel again to fill the buffer this time */
694 Status
= NtUserBuildHwndList(hDesktop
,
701 if (!NT_SUCCESS(Status
))
704 HeapFree(hHeap
, 0, pHwnd
);
708 /* call the user's callback function until we're done or
709 they tell us to quit */
710 for ( i
= 0; i
< dwCount
; i
++ )
712 /* FIXME I'm only getting NULLs from Thread Enumeration, and it's
713 * probably because I'm not doing it right in NtUserBuildHwndList.
714 * Once that's fixed, we shouldn't have to check for a NULL HWND
716 * This is now fixed in revision 50205. (jt)
718 if (!pHwnd
[i
]) /* don't enumerate a NULL HWND */
720 if (!(*lpfn
)(pHwnd
[i
], lParam
))
722 HeapFree ( hHeap
, 0, pHwnd
);
727 HeapFree(hHeap
, 0, pHwnd
);
736 EnumChildWindows(HWND hWndParent
,
737 WNDENUMPROC lpEnumFunc
,
742 return EnumWindows(lpEnumFunc
, lParam
);
744 return User32EnumWindows(NULL
, hWndParent
, lpEnumFunc
, lParam
, 0, TRUE
);
752 EnumThreadWindows(DWORD dwThreadId
,
757 dwThreadId
= GetCurrentThreadId();
758 return User32EnumWindows(NULL
, NULL
, lpfn
, lParam
, dwThreadId
, FALSE
);
766 EnumWindows(WNDENUMPROC lpEnumFunc
,
769 return User32EnumWindows(NULL
, NULL
, lpEnumFunc
, lParam
, 0, FALSE
);
777 EnumDesktopWindows(HDESK hDesktop
,
781 return User32EnumWindows(hDesktop
, NULL
, lpfn
, lParam
, 0, FALSE
);
789 FindWindowExA(HWND hwndParent
,
794 LPWSTR titleW
= NULL
;
799 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, lpszWindow
, -1, NULL
, 0 );
800 if (!(titleW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
801 MultiByteToWideChar( CP_ACP
, 0, lpszWindow
, -1, titleW
, len
);
804 if (!IS_INTRESOURCE(lpszClass
))
807 if (MultiByteToWideChar( CP_ACP
, 0, lpszClass
, -1, classW
, sizeof(classW
)/sizeof(WCHAR
) ))
808 hwnd
= FindWindowExW( hwndParent
, hwndChildAfter
, classW
, titleW
);
812 hwnd
= FindWindowExW( hwndParent
, hwndChildAfter
, (LPCWSTR
)lpszClass
, titleW
);
815 HeapFree( GetProcessHeap(), 0, titleW
);
824 FindWindowExW(HWND hwndParent
,
829 UNICODE_STRING ucClassName
, *pucClassName
= NULL
;
830 UNICODE_STRING ucWindowName
, *pucWindowName
= NULL
;
832 if (IS_ATOM(lpszClass
))
834 ucClassName
.Length
= 0;
835 ucClassName
.Buffer
= (LPWSTR
)lpszClass
;
836 pucClassName
= &ucClassName
;
838 else if (lpszClass
!= NULL
)
840 RtlInitUnicodeString(&ucClassName
,
842 pucClassName
= &ucClassName
;
845 if (lpszWindow
!= NULL
)
847 RtlInitUnicodeString(&ucWindowName
,
849 pucWindowName
= &ucWindowName
;
852 return NtUserFindWindowEx(hwndParent
,
864 FindWindowA(LPCSTR lpClassName
, LPCSTR lpWindowName
)
866 //FIXME: FindWindow does not search children, but FindWindowEx does.
867 // what should we do about this?
868 return FindWindowExA (NULL
, NULL
, lpClassName
, lpWindowName
);
876 FindWindowW(LPCWSTR lpClassName
, LPCWSTR lpWindowName
)
880 There was a FIXME here earlier, but I think it is just a documentation unclarity.
882 FindWindow only searches top level windows. What they mean is that child
883 windows of other windows than the desktop can be searched.
884 FindWindowExW never does a recursive search.
889 return FindWindowExW(NULL
, NULL
, lpClassName
, lpWindowName
);
898 GetAltTabInfoA(HWND hwnd
,
904 return NtUserGetAltTabInfo(hwnd
,iItem
,pati
,(LPWSTR
)pszItemText
,cchItemText
,TRUE
);
912 GetAltTabInfoW(HWND hwnd
,
918 return NtUserGetAltTabInfo(hwnd
,iItem
,pati
,pszItemText
,cchItemText
,FALSE
);
926 GetAncestor(HWND hwnd
, UINT gaFlags
)
931 Wnd
= ValidateHwnd(hwnd
);
941 if (Wnd
->spwndParent
!= NULL
)
942 Ancestor
= DesktopPtrToUser(Wnd
->spwndParent
);
946 /* FIXME: Call win32k for now */
951 if (Ancestor
!= NULL
)
952 Ret
= UserHMGetHandle(Ancestor
);
954 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
960 if (!Wnd
) /* Fall back */
961 Ret
= NtUserGetAncestor(hwnd
, gaFlags
);
971 GetClientRect(HWND hWnd
, LPRECT lpRect
)
973 PWND Wnd
= ValidateHwnd(hWnd
);
975 if (!Wnd
) return FALSE
;
976 if (Wnd
->style
& WS_MINIMIZED
)
978 lpRect
->left
= lpRect
->top
= 0;
979 lpRect
->right
= GetSystemMetrics(SM_CXMINIMIZED
);
980 lpRect
->bottom
= GetSystemMetrics(SM_CYMINIMIZED
);
983 if ( hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
985 /* lpRect->left = lpRect->top = 0;
986 lpRect->right = Wnd->rcClient.right - Wnd->rcClient.left;
987 lpRect->bottom = Wnd->rcClient.bottom - Wnd->rcClient.top;
989 *lpRect
= Wnd
->rcClient
;
990 OffsetRect(lpRect
, -Wnd
->rcClient
.left
, -Wnd
->rcClient
.top
);
994 lpRect
->left
= lpRect
->top
= 0;
995 lpRect
->right
= Wnd
->rcClient
.right
;
996 lpRect
->bottom
= Wnd
->rcClient
.bottom
;
997 /* Do this until Init bug is fixed. This sets 640x480, see InitMetrics.
998 lpRect->right = GetSystemMetrics(SM_CXSCREEN);
999 lpRect->bottom = GetSystemMetrics(SM_CYSCREEN);
1009 GetLastActivePopup(HWND hWnd
)
1014 Wnd
= ValidateHwnd(hWnd
);
1019 if (Wnd
->spwndLastActive
)
1021 PWND LastActive
= DesktopPtrToUser(Wnd
->spwndLastActive
);
1022 Ret
= UserHMGetHandle(LastActive
);
1025 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1039 GetParent(HWND hWnd
)
1041 PWND Wnd
, WndParent
;
1044 Wnd
= ValidateHwnd(hWnd
);
1050 if (Wnd
->style
& WS_POPUP
)
1052 if (Wnd
->spwndOwner
!= NULL
)
1053 WndParent
= DesktopPtrToUser(Wnd
->spwndOwner
);
1055 else if (Wnd
->style
& WS_CHILD
)
1057 if (Wnd
->spwndParent
!= NULL
)
1058 WndParent
= DesktopPtrToUser(Wnd
->spwndParent
);
1061 if (WndParent
!= NULL
)
1062 Ret
= UserHMGetHandle(WndParent
);
1064 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1079 GetProcessDefaultLayout(DWORD
*pdwDefaultLayout
)
1081 return (BOOL
)NtUserCallOneParam( (DWORD_PTR
)pdwDefaultLayout
, ONEPARAM_ROUTINE_GETPROCDEFLAYOUT
);
1089 GetWindow(HWND hWnd
,
1095 Wnd
= ValidateHwnd(hWnd
);
1105 if (Wnd
->spwndOwner
!= NULL
)
1106 FoundWnd
= DesktopPtrToUser(Wnd
->spwndOwner
);
1110 if(Wnd
->spwndParent
!= NULL
)
1112 FoundWnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1113 if (FoundWnd
->spwndChild
!= NULL
)
1114 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndChild
);
1118 if (Wnd
->spwndNext
!= NULL
)
1119 FoundWnd
= DesktopPtrToUser(Wnd
->spwndNext
);
1123 if (Wnd
->spwndPrev
!= NULL
)
1124 FoundWnd
= DesktopPtrToUser(Wnd
->spwndPrev
);
1128 if (Wnd
->spwndChild
!= NULL
)
1129 FoundWnd
= DesktopPtrToUser(Wnd
->spwndChild
);
1134 while ( FoundWnd
->spwndNext
!= NULL
)
1135 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndNext
);
1143 if (FoundWnd
!= NULL
)
1144 Ret
= UserHMGetHandle(FoundWnd
);
1146 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1160 GetTopWindow(HWND hWnd
)
1162 if (!hWnd
) hWnd
= GetDesktopWindow();
1163 return GetWindow(hWnd
, GW_CHILD
);
1173 GetWindowInfo(HWND hWnd
,
1181 if ( !pwi
|| pwi
->cbSize
!= sizeof(WINDOWINFO
))
1182 SetLastError(ERROR_INVALID_PARAMETER
); // Just set the error and go!
1184 pWnd
= ValidateHwnd(hWnd
);
1188 UserGetWindowBorders(pWnd
->style
, pWnd
->ExStyle
, &Size
, FALSE
);
1192 pCls
= DesktopPtrToUser(pWnd
->pcls
);
1193 pwi
->rcWindow
= pWnd
->rcWindow
;
1194 pwi
->rcClient
= pWnd
->rcClient
;
1195 pwi
->dwStyle
= pWnd
->style
;
1196 pwi
->dwExStyle
= pWnd
->ExStyle
;
1197 pwi
->cxWindowBorders
= Size
.cx
;
1198 pwi
->cyWindowBorders
= Size
.cy
;
1199 pwi
->dwWindowStatus
= 0;
1200 if (pWnd
->state
& WNDS_ACTIVEFRAME
|| (GetActiveWindow() == hWnd
))
1201 pwi
->dwWindowStatus
= WS_ACTIVECAPTION
;
1202 pwi
->atomWindowType
= (pCls
? pCls
->atomClassName
: 0 );
1204 if ( pWnd
->state2
& WNDS2_WIN50COMPAT
)
1206 pwi
->wCreatorVersion
= 0x500;
1208 else if ( pWnd
->state2
& WNDS2_WIN40COMPAT
)
1210 pwi
->wCreatorVersion
= 0x400;
1212 else if ( pWnd
->state2
& WNDS2_WIN31COMPAT
)
1214 pwi
->wCreatorVersion
= 0x30A;
1218 pwi
->wCreatorVersion
= 0x300;
1223 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1237 GetWindowModuleFileNameA(HWND hwnd
,
1239 UINT cchFileNameMax
)
1241 PWND Wnd
= ValidateHwnd(hwnd
);
1246 return GetModuleFileNameA(Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1254 GetWindowModuleFileNameW(HWND hwnd
,
1255 LPWSTR lpszFileName
,
1256 UINT cchFileNameMax
)
1258 PWND Wnd
= ValidateHwnd(hwnd
);
1263 return GetModuleFileNameW( Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1270 GetWindowRect(HWND hWnd
,
1273 PWND Wnd
= ValidateHwnd(hWnd
);
1275 if (!Wnd
) return FALSE
;
1276 if ( hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
1278 *lpRect
= Wnd
->rcWindow
;
1282 lpRect
->left
= lpRect
->top
= 0;
1283 lpRect
->right
= Wnd
->rcWindow
.right
;
1284 lpRect
->bottom
= Wnd
->rcWindow
.bottom
;
1285 /* Do this until Init bug is fixed. This sets 640x480, see InitMetrics.
1286 lpRect->right = GetSystemMetrics(SM_CXSCREEN);
1287 lpRect->bottom = GetSystemMetrics(SM_CYSCREEN);
1296 GetWindowTextA(HWND hWnd
, LPSTR lpString
, int nMaxCount
)
1301 if (lpString
== NULL
|| nMaxCount
== 0)
1304 Wnd
= ValidateHwnd(hWnd
);
1310 if (!TestWindowProcess(Wnd
))
1314 Length
= DefWindowProcA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1316 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1324 Length
= SendMessageA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1326 //ERR("GWTA Len %d : %s\n",Length,lpString);
1334 GetWindowTextLengthA(HWND hWnd
)
1338 Wnd
= ValidateHwnd(hWnd
);
1342 if (!TestWindowProcess(Wnd
))
1344 return DefWindowProcA(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1348 return SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1356 GetWindowTextLengthW(HWND hWnd
)
1360 Wnd
= ValidateHwnd(hWnd
);
1364 if (!TestWindowProcess(Wnd
))
1366 return DefWindowProcW(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1370 return SendMessageW(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1378 GetWindowTextW(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1383 if (lpString
== NULL
|| nMaxCount
== 0)
1386 Wnd
= ValidateHwnd(hWnd
);
1390 lpString
[0] = L
'\0';
1392 if (!TestWindowProcess(Wnd
))
1396 Length
= DefWindowProcW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1398 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1406 Length
= SendMessageW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1408 //ERR("GWTW Len %d : %S\n",Length,lpString);
1413 GetWindowThreadProcessId(HWND hWnd
,
1414 LPDWORD lpdwProcessId
)
1418 PWND pWnd
= ValidateHwnd(hWnd
);
1420 if (!pWnd
) return Ret
;
1422 ti
= pWnd
->head
.pti
;
1426 if (ti
== GetW32ThreadInfo())
1427 { // We are current.
1428 //FIXME("Current!\n");
1430 *lpdwProcessId
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueProcess
;
1431 Ret
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueThread
;
1434 { // Ask kernel for info.
1435 //FIXME("Kernel call!\n");
1437 *lpdwProcessId
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
);
1438 Ret
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_THREAD_ID
);
1449 IsChild(HWND hWndParent
,
1452 PWND WndParent
, DesktopWnd
, Wnd
;
1455 WndParent
= ValidateHwnd(hWndParent
);
1458 Wnd
= ValidateHwnd(hWnd
);
1462 DesktopWnd
= GetThreadDesktopWnd();
1468 while (Wnd
!= NULL
&& ((Wnd
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
1470 if (Wnd
->spwndParent
!= NULL
)
1472 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1474 if (Wnd
== WndParent
)
1484 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1500 PWND Wnd
= ValidateHwnd(hWnd
);
1503 return (Wnd
->style
& WS_MINIMIZE
) != 0;
1515 PWND Wnd
= ValidateHwndNoErr(hWnd
);
1518 if (Wnd
->state
& WNDS_DESTROYED
||
1519 Wnd
->state2
& WNDS2_INDESTROY
)
1532 IsWindowUnicode(HWND hWnd
)
1534 PWND Wnd
= ValidateHwnd(hWnd
);
1537 return Wnd
->Unicode
;
1547 IsWindowVisible(HWND hWnd
)
1550 PWND Wnd
= ValidateHwnd(hWnd
);
1560 if (!(Wnd
->style
& WS_VISIBLE
))
1566 if (Wnd
->spwndParent
!= NULL
)
1567 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1571 } while (Wnd
!= NULL
);
1573 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1588 IsWindowEnabled(HWND hWnd
)
1590 // AG: I don't know if child windows are affected if the parent is
1591 // disabled. I think they stop processing messages but stay appearing
1594 return !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_DISABLED
);
1604 return (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
1612 LockSetForegroundWindow(UINT uLockCode
)
1614 return NtUserxLockSetForegroundWindow(uLockCode
);
1622 AnimateWindow(HWND hwnd
,
1626 /* FIXME Add animation code */
1628 /* If trying to show/hide and it's already *
1629 * shown/hidden or invalid window, fail with *
1630 * invalid parameter */
1633 visible
= IsWindowVisible(hwnd
);
1634 if(!IsWindow(hwnd
) ||
1635 (visible
&& !(dwFlags
& AW_HIDE
)) ||
1636 (!visible
&& (dwFlags
& AW_HIDE
)))
1638 SetLastError(ERROR_INVALID_PARAMETER
);
1642 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1654 if (!(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1657 ShowWindow(hWnd
,SW_RESTORE
);
1666 RealChildWindowFromPoint(HWND hwndParent
,
1667 POINT ptParentClientCoords
)
1669 return NtUserRealChildWindowFromPoint(hwndParent
, ptParentClientCoords
.x
, ptParentClientCoords
.y
);
1676 SetForegroundWindow(HWND hWnd
)
1678 return NtUserxSetForegroundWindow(hWnd
);
1686 SetProcessDefaultLayout(DWORD dwDefaultLayout
)
1688 return NtUserCallOneParam( (DWORD_PTR
)dwDefaultLayout
, ONEPARAM_ROUTINE_SETPROCDEFLAYOUT
);
1698 SetWindowTextA(HWND hWnd
,
1703 pwnd
= ValidateHwnd(hWnd
);
1706 if (!TestWindowProcess(pwnd
))
1708 /* do not send WM_GETTEXT messages to other processes */
1709 return (DefWindowProcA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1711 return (SendMessageA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1723 SetWindowTextW(HWND hWnd
,
1728 pwnd
= ValidateHwnd(hWnd
);
1731 if (!TestWindowProcess(pwnd
))
1733 /* do not send WM_GETTEXT messages to other processes */
1734 return (DefWindowProcW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1736 return (SendMessageW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1746 ShowOwnedPopups(HWND hWnd
, BOOL fShow
)
1748 return NtUserxShowOwnedPopups(hWnd
, fShow
);
1756 UpdateLayeredWindow( HWND hwnd
,
1766 if (dwFlags
& ULW_EX_NORESIZE
) /* only valid for UpdateLayeredWindowIndirect */
1768 SetLastError( ERROR_INVALID_PARAMETER
);
1771 return NtUserUpdateLayeredWindow( hwnd
,
1787 UpdateLayeredWindowIndirect(HWND hwnd
,
1788 const UPDATELAYEREDWINDOWINFO
*info
)
1790 if (info
&& info
->cbSize
== sizeof(*info
))
1792 return NtUserUpdateLayeredWindow( hwnd
,
1794 (POINT
*)info
->pptDst
,
1795 (SIZE
*)info
->psize
,
1797 (POINT
*)info
->pptSrc
,
1799 (BLENDFUNCTION
*)info
->pblend
,
1801 (RECT
*)info
->prcDirty
);
1803 SetLastError(ERROR_INVALID_PARAMETER
);
1811 SetWindowContextHelpId(HWND hwnd
,
1812 DWORD dwContextHelpId
)
1814 return NtUserxSetWindowContextHelpId(hwnd
, dwContextHelpId
);
1821 GetWindowContextHelpId(HWND hwnd
)
1823 return NtUserxGetWindowContextHelpId(hwnd
);
1830 InternalGetWindowText(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1832 INT Ret
= NtUserInternalGetWindowText(hWnd
, lpString
, nMaxCount
);
1833 if (Ret
== 0 && lpString
)
1842 IsHungAppWindow(HWND hwnd
)
1844 return (NtUserQueryWindow(hwnd
, QUERY_WINDOW_ISHUNG
) != 0);
1851 SetLastErrorEx(DWORD dwErrCode
, DWORD dwType
)
1853 SetLastError(dwErrCode
);
1862 return (HWND
)NtUserGetThreadState(THREADSTATE_FOCUSWINDOW
);
1866 GetRealWindowOwner(HWND hwnd
)
1868 return NtUserQueryWindow(hwnd
, QUERY_WINDOW_REAL_ID
);
1875 SetTaskmanWindow(HWND hWnd
)
1877 return NtUserxSetTaskmanWindow(hWnd
);
1884 SetProgmanWindow(HWND hWnd
)
1886 return NtUserxSetProgmanWindow(hWnd
);
1893 GetProgmanWindow(VOID
)
1895 return (HWND
)NtUserGetThreadState(THREADSTATE_PROGMANWINDOW
);
1902 GetTaskmanWindow(VOID
)
1904 return (HWND
)NtUserGetThreadState(THREADSTATE_TASKMANWINDOW
);
1911 ScrollWindow(HWND hWnd
,
1915 CONST RECT
*prcClip
)
1917 return NtUserScrollWindowEx(hWnd
,
1924 (lpRect
? 0 : SW_SCROLLCHILDREN
) | (SW_ERASE
|SW_INVALIDATE
|SW_SCROLLWNDDCE
)) != ERROR
;
1927 /* ScrollWindow uses the window DC, ScrollWindowEx doesn't */
1933 ScrollWindowEx(HWND hWnd
,
1936 CONST RECT
*prcScroll
,
1937 CONST RECT
*prcClip
,
1942 if (flags
& SW_SMOOTHSCROLL
)
1944 FIXME("SW_SMOOTHSCROLL not supported.");
1947 return NtUserScrollWindowEx(hWnd
,
1965 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1967 if (!list
) return FALSE
;
1968 for (i
= 0; list
[i
]; i
++)
1970 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
1972 retvalue
= (list
[i
] != 0);
1973 HeapFree( GetProcessHeap(), 0, list
);
1981 IsWindowInDestroy(HWND hWnd
)
1984 pwnd
= ValidateHwnd(hWnd
);
1987 return ((pwnd
->state2
& WNDS2_INDESTROY
) == WNDS2_INDESTROY
);
1994 DisableProcessWindowsGhosting(VOID
)
1996 NtUserxEnableProcessWindowGhosting(FALSE
);