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 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
11 /* INCLUDES ******************************************************************/
15 #include <wine/debug.h>
16 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
18 void MDI_CalcDefaultChildPos( HWND hwndClient
, INT total
, LPPOINT lpPos
, INT delta
, UINT
*id
);
19 extern LPCWSTR FASTCALL
ClassNameToVersion(const void *lpszClass
, LPCWSTR lpszMenuName
, LPCWSTR
*plpLibFileName
, HANDLE
*pContext
, BOOL bAnsi
);
21 /* FUNCTIONS *****************************************************************/
25 User32CallSendAsyncProcForKernel(PVOID Arguments
, ULONG ArgumentLength
)
27 PSENDASYNCPROC_CALLBACK_ARGUMENTS CallbackArgs
;
29 TRACE("User32CallSendAsyncProcKernel()\n");
31 CallbackArgs
= (PSENDASYNCPROC_CALLBACK_ARGUMENTS
)Arguments
;
33 if (ArgumentLength
!= sizeof(SENDASYNCPROC_CALLBACK_ARGUMENTS
))
35 return(STATUS_INFO_LENGTH_MISMATCH
);
38 CallbackArgs
->Callback(CallbackArgs
->Wnd
,
40 CallbackArgs
->Context
,
41 CallbackArgs
->Result
);
42 return(STATUS_SUCCESS
);
50 AllowSetForegroundWindow(DWORD dwProcessId
)
52 return NtUserxAllowSetForegroundWindow(dwProcessId
);
60 BeginDeferWindowPos(int nNumWindows
)
62 return NtUserxBeginDeferWindowPos(nNumWindows
);
70 BringWindowToTop(HWND hWnd
)
72 return NtUserSetWindowPos(hWnd
,
78 SWP_NOSIZE
| SWP_NOMOVE
);
83 SwitchToThisWindow(HWND hwnd
, BOOL fUnknown
)
85 ShowWindow(hwnd
, SW_SHOW
);
93 ChildWindowFromPoint(HWND hWndParent
,
96 return (HWND
) NtUserChildWindowFromPointEx(hWndParent
, Point
.x
, Point
.y
, 0);
104 ChildWindowFromPointEx(HWND hwndParent
,
108 return (HWND
) NtUserChildWindowFromPointEx(hwndParent
, pt
.x
, pt
.y
, uFlags
);
116 CloseWindow(HWND hWnd
)
118 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
120 return HandleToUlong(hWnd
);
126 OUT PLARGE_STRING plstr
,
132 RtlInitLargeUnicodeString((PLARGE_UNICODE_STRING
)plstr
, (PWSTR
)psz
, 0);
136 RtlInitLargeAnsiString((PLARGE_ANSI_STRING
)plstr
, (PSTR
)psz
, 0);
143 IN PLARGE_STRING LargeString
)
145 if (LargeString
->Buffer
)
147 RtlFreeHeap(GetProcessHeap(), 0, LargeString
->Buffer
);
148 RtlZeroMemory(LargeString
, sizeof(LARGE_STRING
));
153 User32CreateWindowEx(DWORD dwExStyle
,
167 LARGE_STRING WindowName
;
168 LARGE_STRING lstrClassName
, *plstrClassName
;
169 LARGE_STRING lstrClassVersion
, *plstrClassVersion
;
170 UNICODE_STRING ClassName
;
171 UNICODE_STRING ClassVersion
;
174 HMODULE hLibModule
= NULL
;
176 BOOL Unicode
, ClassFound
= FALSE
;
178 LPCWSTR lpszClsVersion
;
180 LPCWSTR lpLibFileName
;
183 DbgPrint("[window] User32CreateWindowEx style %d, exstyle %d, parent %d\n", dwStyle
, dwExStyle
, hWndParent
);
186 if (!RegisterDefaultClasses
)
188 TRACE("RegisterSystemControls\n");
189 RegisterSystemControls();
192 Unicode
= !(dwFlags
& NUCWE_ANSI
);
194 if (IS_ATOM(lpClassName
))
196 plstrClassName
= (PVOID
)lpClassName
;
202 RtlInitUnicodeString(&ClassName
, (PCWSTR
)lpClassName
);
206 if (!RtlCreateUnicodeStringFromAsciiz(&ClassName
, (PCSZ
)lpClassName
))
208 SetLastError(ERROR_OUTOFMEMORY
);
213 /* Copy it to a LARGE_STRING */
214 lstrClassName
.Buffer
= ClassName
.Buffer
;
215 lstrClassName
.Length
= ClassName
.Length
;
216 lstrClassName
.MaximumLength
= ClassName
.MaximumLength
;
217 plstrClassName
= &lstrClassName
;
220 /* Initialize a LARGE_STRING */
221 RtlInitLargeString(&WindowName
, lpWindowName
, Unicode
);
223 // HACK: The current implementation expects the Window name to be UNICODE
227 PSTR AnsiBuffer
= WindowName
.Buffer
;
228 ULONG AnsiLength
= WindowName
.Length
;
230 WindowName
.Length
= 0;
231 WindowName
.MaximumLength
= AnsiLength
* sizeof(WCHAR
);
232 WindowName
.Buffer
= RtlAllocateHeap(RtlGetProcessHeap(),
234 WindowName
.MaximumLength
);
235 if (!WindowName
.Buffer
)
237 SetLastError(ERROR_OUTOFMEMORY
);
241 Status
= RtlMultiByteToUnicodeN(WindowName
.Buffer
,
242 WindowName
.MaximumLength
,
246 if (!NT_SUCCESS(Status
))
252 if (!hMenu
&& (dwStyle
& (WS_OVERLAPPEDWINDOW
| WS_POPUP
)))
256 wceW
.cbSize
= sizeof(wceW
);
257 if (GetClassInfoExW(hInstance
, (LPCWSTR
)lpClassName
, &wceW
) && wceW
.lpszMenuName
)
259 hMenu
= LoadMenuW(hInstance
, wceW
.lpszMenuName
);
264 wceA
.cbSize
= sizeof(wceA
);
265 if (GetClassInfoExA(hInstance
, lpClassName
, &wceA
) && wceA
.lpszMenuName
)
267 hMenu
= LoadMenuA(hInstance
, wceA
.lpszMenuName
);
272 if (!Unicode
) dwExStyle
|= WS_EX_SETANSICREATOR
;
274 lpszClsVersion
= ClassNameToVersion(lpClassName
, NULL
, &lpLibFileName
, &pCtx
, !Unicode
);
277 plstrClassVersion
= plstrClassName
;
281 RtlInitUnicodeString(&ClassVersion
, lpszClsVersion
);
282 lstrClassVersion
.Buffer
= ClassVersion
.Buffer
;
283 lstrClassVersion
.Length
= ClassVersion
.Length
;
284 lstrClassVersion
.MaximumLength
= ClassVersion
.MaximumLength
;
285 plstrClassVersion
= &lstrClassVersion
;
290 Handle
= NtUserCreateWindowEx(dwExStyle
,
306 if (!lpLibFileName
) break;
309 dwLastError
= GetLastError();
310 if (dwLastError
== ERROR_CANNOT_FIND_WND_CLASS
)
312 ClassFound
= VersionRegisterClass(ClassName
.Buffer
, lpLibFileName
, pCtx
, &hLibModule
);
313 if (ClassFound
) continue;
318 dwLastError
= GetLastError();
319 FreeLibrary(hLibModule
);
320 SetLastError(dwLastError
);
327 DbgPrint("[window] NtUserCreateWindowEx() == %d\n", Handle
);
333 if (!IS_ATOM(lpClassName
))
334 RtlFreeUnicodeString(&ClassName
);
336 RtlFreeLargeString(&WindowName
);
349 CreateWindowExA(DWORD dwExStyle
,
362 MDICREATESTRUCTA mdi
;
365 if (!RegisterDefaultClasses
)
367 TRACE("CreateWindowExA RegisterSystemControls\n");
368 RegisterSystemControls();
371 if (dwExStyle
& WS_EX_MDICHILD
)
378 pWndParent
= ValidateHwnd(hWndParent
);
380 if (!pWndParent
) return NULL
;
382 if (pWndParent
->fnid
!= FNID_MDICLIENT
) // wine uses WIN_ISMDICLIENT
384 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
388 /* lpParams of WM_[NC]CREATE is different for MDI children.
389 * MDICREATESTRUCT members have the originally passed values.
391 mdi
.szClass
= lpClassName
;
392 mdi
.szTitle
= lpWindowName
;
393 mdi
.hOwner
= hInstance
;
399 mdi
.lParam
= (LPARAM
)lpParam
;
401 lpParam
= (LPVOID
)&mdi
;
403 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
405 if (dwStyle
& WS_POPUP
)
407 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
410 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
414 dwStyle
&= ~WS_POPUP
;
415 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
416 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
419 top_child
= GetWindow(hWndParent
, GW_CHILD
);
423 /* Restore current maximized child */
424 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
426 TRACE("Restoring current maximized child %p\n", top_child
);
427 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
428 ShowWindow(top_child
, SW_RESTORE
);
429 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
433 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
435 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
437 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
439 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
444 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
446 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
451 hwnd
= User32CreateWindowEx(dwExStyle
,
474 CreateWindowExW(DWORD dwExStyle
,
476 LPCWSTR lpWindowName
,
487 MDICREATESTRUCTW mdi
;
490 if (!RegisterDefaultClasses
)
492 ERR("CreateWindowExW RegisterSystemControls\n");
493 RegisterSystemControls();
496 if (dwExStyle
& WS_EX_MDICHILD
)
503 pWndParent
= ValidateHwnd(hWndParent
);
505 if (!pWndParent
) return NULL
;
507 if (pWndParent
->fnid
!= FNID_MDICLIENT
)
509 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
513 /* lpParams of WM_[NC]CREATE is different for MDI children.
514 * MDICREATESTRUCT members have the originally passed values.
516 mdi
.szClass
= lpClassName
;
517 mdi
.szTitle
= lpWindowName
;
518 mdi
.hOwner
= hInstance
;
524 mdi
.lParam
= (LPARAM
)lpParam
;
526 lpParam
= (LPVOID
)&mdi
;
528 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
530 if (dwStyle
& WS_POPUP
)
532 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
535 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
539 dwStyle
&= ~WS_POPUP
;
540 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
541 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
544 top_child
= GetWindow(hWndParent
, GW_CHILD
);
548 /* Restore current maximized child */
549 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
551 TRACE("Restoring current maximized child %p\n", top_child
);
552 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
553 ShowWindow(top_child
, SW_RESTORE
);
554 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
558 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
560 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
562 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
564 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
569 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
571 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
576 hwnd
= User32CreateWindowEx(dwExStyle
,
578 (LPCSTR
)lpWindowName
,
596 DeferWindowPos(HDWP hWinPosInfo
,
598 HWND hWndInsertAfter
,
605 return NtUserDeferWindowPos(hWinPosInfo
, hWnd
, hWndInsertAfter
, x
, y
, cx
, cy
, uFlags
);
613 EndDeferWindowPos(HDWP hWinPosInfo
)
615 return NtUserEndDeferWindowPosEx(hWinPosInfo
, 0);
623 GetDesktopWindow(VOID
)
630 Wnd
= GetThreadDesktopWnd();
632 Ret
= UserHMGetHandle(Wnd
);
634 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
645 User32EnumWindows(HDESK hDesktop
,
652 DWORD i
, dwCount
= 0;
659 SetLastError ( ERROR_INVALID_PARAMETER
);
663 /* FIXME instead of always making two calls, should we use some
664 sort of persistent buffer and only grow it ( requiring a 2nd
665 call ) when the buffer wasn't already big enough? */
666 /* first get how many window entries there are */
667 Status
= NtUserBuildHwndList(hDesktop
,
674 if (!NT_SUCCESS(Status
))
677 /* allocate buffer to receive HWND handles */
678 hHeap
= GetProcessHeap();
679 pHwnd
= HeapAlloc(hHeap
, 0, sizeof(HWND
)*(dwCount
+1));
682 SetLastError ( ERROR_NOT_ENOUGH_MEMORY
);
686 /* now call kernel again to fill the buffer this time */
687 Status
= NtUserBuildHwndList(hDesktop
,
694 if (!NT_SUCCESS(Status
))
697 HeapFree(hHeap
, 0, pHwnd
);
709 /* call the user's callback function until we're done or
710 they tell us to quit */
711 for ( i
= 0; i
< dwCount
; i
++ )
713 /* FIXME I'm only getting NULLs from Thread Enumeration, and it's
714 * probably because I'm not doing it right in NtUserBuildHwndList.
715 * Once that's fixed, we shouldn't have to check for a NULL HWND
717 * This is now fixed in revision 50205. (jt)
719 if (!pHwnd
[i
]) /* don't enumerate a NULL HWND */
721 if (!(*lpfn
)(pHwnd
[i
], lParam
))
723 HeapFree ( hHeap
, 0, pHwnd
);
728 HeapFree(hHeap
, 0, pHwnd
);
737 EnumChildWindows(HWND hWndParent
,
738 WNDENUMPROC lpEnumFunc
,
743 return EnumWindows(lpEnumFunc
, lParam
);
745 return User32EnumWindows(NULL
, hWndParent
, lpEnumFunc
, lParam
, 0, TRUE
);
753 EnumThreadWindows(DWORD dwThreadId
,
758 dwThreadId
= GetCurrentThreadId();
759 return User32EnumWindows(NULL
, NULL
, lpfn
, lParam
, dwThreadId
, FALSE
);
767 EnumWindows(WNDENUMPROC lpEnumFunc
,
770 return User32EnumWindows(NULL
, NULL
, lpEnumFunc
, lParam
, 0, FALSE
);
778 EnumDesktopWindows(HDESK hDesktop
,
782 return User32EnumWindows(hDesktop
, NULL
, lpfn
, lParam
, 0, FALSE
);
790 FindWindowExA(HWND hwndParent
,
795 LPWSTR titleW
= NULL
;
800 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, lpszWindow
, -1, NULL
, 0 );
801 if (!(titleW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
802 MultiByteToWideChar( CP_ACP
, 0, lpszWindow
, -1, titleW
, len
);
805 if (!IS_INTRESOURCE(lpszClass
))
808 if (MultiByteToWideChar( CP_ACP
, 0, lpszClass
, -1, classW
, sizeof(classW
)/sizeof(WCHAR
) ))
809 hwnd
= FindWindowExW( hwndParent
, hwndChildAfter
, classW
, titleW
);
813 hwnd
= FindWindowExW( hwndParent
, hwndChildAfter
, (LPCWSTR
)lpszClass
, titleW
);
816 HeapFree( GetProcessHeap(), 0, titleW
);
825 FindWindowExW(HWND hwndParent
,
830 UNICODE_STRING ucClassName
, *pucClassName
= NULL
;
831 UNICODE_STRING ucWindowName
, *pucWindowName
= NULL
;
833 if (IS_ATOM(lpszClass
))
835 ucClassName
.Length
= 0;
836 ucClassName
.Buffer
= (LPWSTR
)lpszClass
;
837 pucClassName
= &ucClassName
;
839 else if (lpszClass
!= NULL
)
841 RtlInitUnicodeString(&ucClassName
,
843 pucClassName
= &ucClassName
;
846 if (lpszWindow
!= NULL
)
848 RtlInitUnicodeString(&ucWindowName
,
850 pucWindowName
= &ucWindowName
;
853 return NtUserFindWindowEx(hwndParent
,
865 FindWindowA(LPCSTR lpClassName
, LPCSTR lpWindowName
)
867 //FIXME: FindWindow does not search children, but FindWindowEx does.
868 // what should we do about this?
869 return FindWindowExA (NULL
, NULL
, lpClassName
, lpWindowName
);
877 FindWindowW(LPCWSTR lpClassName
, LPCWSTR lpWindowName
)
881 There was a FIXME here earlier, but I think it is just a documentation unclarity.
883 FindWindow only searches top level windows. What they mean is that child
884 windows of other windows than the desktop can be searched.
885 FindWindowExW never does a recursive search.
890 return FindWindowExW(NULL
, NULL
, lpClassName
, lpWindowName
);
899 GetAltTabInfoA(HWND hwnd
,
905 return NtUserGetAltTabInfo(hwnd
,iItem
,pati
,(LPWSTR
)pszItemText
,cchItemText
,TRUE
);
913 GetAltTabInfoW(HWND hwnd
,
919 return NtUserGetAltTabInfo(hwnd
,iItem
,pati
,pszItemText
,cchItemText
,FALSE
);
927 GetAncestor(HWND hwnd
, UINT gaFlags
)
932 Wnd
= ValidateHwnd(hwnd
);
942 if (Wnd
->spwndParent
!= NULL
)
943 Ancestor
= DesktopPtrToUser(Wnd
->spwndParent
);
947 /* FIXME: Call win32k for now */
952 if (Ancestor
!= NULL
)
953 Ret
= UserHMGetHandle(Ancestor
);
955 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
961 if (!Wnd
) /* Fall back */
962 Ret
= NtUserGetAncestor(hwnd
, gaFlags
);
972 GetClientRect(HWND hWnd
, LPRECT lpRect
)
974 PWND Wnd
= ValidateHwnd(hWnd
);
976 if (!Wnd
) return FALSE
;
977 if (Wnd
->style
& WS_MINIMIZED
)
979 lpRect
->left
= lpRect
->top
= 0;
980 lpRect
->right
= GetSystemMetrics(SM_CXMINIMIZED
);
981 lpRect
->bottom
= GetSystemMetrics(SM_CYMINIMIZED
);
984 if ( hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
986 /* lpRect->left = lpRect->top = 0;
987 lpRect->right = Wnd->rcClient.right - Wnd->rcClient.left;
988 lpRect->bottom = Wnd->rcClient.bottom - Wnd->rcClient.top;
990 *lpRect
= Wnd
->rcClient
;
991 OffsetRect(lpRect
, -Wnd
->rcClient
.left
, -Wnd
->rcClient
.top
);
995 lpRect
->left
= lpRect
->top
= 0;
996 lpRect
->right
= Wnd
->rcClient
.right
;
997 lpRect
->bottom
= Wnd
->rcClient
.bottom
;
998 /* Do this until Init bug is fixed. This sets 640x480, see InitMetrics.
999 lpRect->right = GetSystemMetrics(SM_CXSCREEN);
1000 lpRect->bottom = GetSystemMetrics(SM_CYSCREEN);
1010 GetLastActivePopup(HWND hWnd
)
1015 Wnd
= ValidateHwnd(hWnd
);
1020 if (Wnd
->spwndLastActive
)
1022 PWND LastActive
= DesktopPtrToUser(Wnd
->spwndLastActive
);
1023 Ret
= UserHMGetHandle(LastActive
);
1026 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1040 GetParent(HWND hWnd
)
1042 PWND Wnd
, WndParent
;
1045 Wnd
= ValidateHwnd(hWnd
);
1051 if (Wnd
->style
& WS_POPUP
)
1053 if (Wnd
->spwndOwner
!= NULL
)
1054 WndParent
= DesktopPtrToUser(Wnd
->spwndOwner
);
1056 else if (Wnd
->style
& WS_CHILD
)
1058 if (Wnd
->spwndParent
!= NULL
)
1059 WndParent
= DesktopPtrToUser(Wnd
->spwndParent
);
1062 if (WndParent
!= NULL
)
1063 Ret
= UserHMGetHandle(WndParent
);
1065 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1080 GetProcessDefaultLayout(DWORD
*pdwDefaultLayout
)
1082 return (BOOL
)NtUserCallOneParam( (DWORD_PTR
)pdwDefaultLayout
, ONEPARAM_ROUTINE_GETPROCDEFLAYOUT
);
1090 GetWindow(HWND hWnd
,
1096 Wnd
= ValidateHwnd(hWnd
);
1106 if (Wnd
->spwndOwner
!= NULL
)
1107 FoundWnd
= DesktopPtrToUser(Wnd
->spwndOwner
);
1111 if(Wnd
->spwndParent
!= NULL
)
1113 FoundWnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1114 if (FoundWnd
->spwndChild
!= NULL
)
1115 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndChild
);
1119 if (Wnd
->spwndNext
!= NULL
)
1120 FoundWnd
= DesktopPtrToUser(Wnd
->spwndNext
);
1124 if (Wnd
->spwndPrev
!= NULL
)
1125 FoundWnd
= DesktopPtrToUser(Wnd
->spwndPrev
);
1129 if (Wnd
->spwndChild
!= NULL
)
1130 FoundWnd
= DesktopPtrToUser(Wnd
->spwndChild
);
1135 while ( FoundWnd
->spwndNext
!= NULL
)
1136 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndNext
);
1144 if (FoundWnd
!= NULL
)
1145 Ret
= UserHMGetHandle(FoundWnd
);
1147 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1161 GetTopWindow(HWND hWnd
)
1163 if (!hWnd
) hWnd
= GetDesktopWindow();
1164 return GetWindow(hWnd
, GW_CHILD
);
1174 GetWindowInfo(HWND hWnd
,
1182 if ( !pwi
|| pwi
->cbSize
!= sizeof(WINDOWINFO
))
1183 SetLastError(ERROR_INVALID_PARAMETER
); // Just set the error and go!
1185 pWnd
= ValidateHwnd(hWnd
);
1189 UserGetWindowBorders(pWnd
->style
, pWnd
->ExStyle
, &Size
, FALSE
);
1193 pCls
= DesktopPtrToUser(pWnd
->pcls
);
1194 pwi
->rcWindow
= pWnd
->rcWindow
;
1195 pwi
->rcClient
= pWnd
->rcClient
;
1196 pwi
->dwStyle
= pWnd
->style
;
1197 pwi
->dwExStyle
= pWnd
->ExStyle
;
1198 pwi
->cxWindowBorders
= Size
.cx
;
1199 pwi
->cyWindowBorders
= Size
.cy
;
1200 pwi
->dwWindowStatus
= 0;
1201 if (pWnd
->state
& WNDS_ACTIVEFRAME
|| (GetActiveWindow() == hWnd
))
1202 pwi
->dwWindowStatus
= WS_ACTIVECAPTION
;
1203 pwi
->atomWindowType
= (pCls
? pCls
->atomClassName
: 0 );
1205 if ( pWnd
->state2
& WNDS2_WIN50COMPAT
)
1207 pwi
->wCreatorVersion
= 0x500;
1209 else if ( pWnd
->state2
& WNDS2_WIN40COMPAT
)
1211 pwi
->wCreatorVersion
= 0x400;
1213 else if ( pWnd
->state2
& WNDS2_WIN31COMPAT
)
1215 pwi
->wCreatorVersion
= 0x30A;
1219 pwi
->wCreatorVersion
= 0x300;
1224 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1238 GetWindowModuleFileNameA(HWND hwnd
,
1240 UINT cchFileNameMax
)
1242 PWND Wnd
= ValidateHwnd(hwnd
);
1247 return GetModuleFileNameA(Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1255 GetWindowModuleFileNameW(HWND hwnd
,
1256 LPWSTR lpszFileName
,
1257 UINT cchFileNameMax
)
1259 PWND Wnd
= ValidateHwnd(hwnd
);
1264 return GetModuleFileNameW( Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1271 GetWindowRect(HWND hWnd
,
1274 PWND Wnd
= ValidateHwnd(hWnd
);
1276 if (!Wnd
) return FALSE
;
1277 if ( hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
1279 *lpRect
= Wnd
->rcWindow
;
1283 lpRect
->left
= lpRect
->top
= 0;
1284 lpRect
->right
= Wnd
->rcWindow
.right
;
1285 lpRect
->bottom
= Wnd
->rcWindow
.bottom
;
1286 /* Do this until Init bug is fixed. This sets 640x480, see InitMetrics.
1287 lpRect->right = GetSystemMetrics(SM_CXSCREEN);
1288 lpRect->bottom = GetSystemMetrics(SM_CYSCREEN);
1297 GetWindowTextA(HWND hWnd
, LPSTR lpString
, int nMaxCount
)
1302 if (lpString
== NULL
|| nMaxCount
== 0)
1305 Wnd
= ValidateHwnd(hWnd
);
1311 if (!TestWindowProcess( Wnd
))
1315 Length
= DefWindowProcA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1317 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1324 Length
= SendMessageA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1325 //ERR("GWTA Len %d : %s\n",Length,lpString);
1333 GetWindowTextLengthA(HWND hWnd
)
1335 return(SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0));
1342 GetWindowTextLengthW(HWND hWnd
)
1344 return(SendMessageW(hWnd
, WM_GETTEXTLENGTH
, 0, 0));
1351 GetWindowTextW(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1356 if (lpString
== NULL
|| nMaxCount
== 0)
1359 Wnd
= ValidateHwnd(hWnd
);
1363 lpString
[0] = L
'\0';
1365 if (!TestWindowProcess( Wnd
))
1369 Length
= DefWindowProcW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1371 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1378 Length
= SendMessageW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1379 //ERR("GWTW Len %d : %S\n",Length,lpString);
1384 GetWindowThreadProcessId(HWND hWnd
,
1385 LPDWORD lpdwProcessId
)
1389 PWND pWnd
= ValidateHwnd(hWnd
);
1391 if (!pWnd
) return Ret
;
1393 ti
= pWnd
->head
.pti
;
1397 if (ti
== GetW32ThreadInfo())
1398 { // We are current.
1399 //FIXME("Current!\n");
1401 *lpdwProcessId
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueProcess
;
1402 Ret
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueThread
;
1405 { // Ask kernel for info.
1406 //FIXME("Kernel call!\n");
1408 *lpdwProcessId
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
);
1409 Ret
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_THREAD_ID
);
1420 IsChild(HWND hWndParent
,
1423 PWND WndParent
, DesktopWnd
, Wnd
;
1426 WndParent
= ValidateHwnd(hWndParent
);
1429 Wnd
= ValidateHwnd(hWnd
);
1433 DesktopWnd
= GetThreadDesktopWnd();
1439 while (Wnd
!= NULL
&& ((Wnd
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
1441 if (Wnd
->spwndParent
!= NULL
)
1443 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1445 if (Wnd
== WndParent
)
1455 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1471 PWND Wnd
= ValidateHwnd(hWnd
);
1474 return (Wnd
->style
& WS_MINIMIZE
) != 0;
1486 PWND Wnd
= ValidateHwndNoErr(hWnd
);
1489 if (Wnd
->state
& WNDS_DESTROYED
||
1490 Wnd
->state2
& WNDS2_INDESTROY
)
1503 IsWindowUnicode(HWND hWnd
)
1505 PWND Wnd
= ValidateHwnd(hWnd
);
1508 return Wnd
->Unicode
;
1518 IsWindowVisible(HWND hWnd
)
1521 PWND Wnd
= ValidateHwnd(hWnd
);
1531 if (!(Wnd
->style
& WS_VISIBLE
))
1537 if (Wnd
->spwndParent
!= NULL
)
1538 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1542 } while (Wnd
!= NULL
);
1544 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1559 IsWindowEnabled(HWND hWnd
)
1561 // AG: I don't know if child windows are affected if the parent is
1562 // disabled. I think they stop processing messages but stay appearing
1565 return !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_DISABLED
);
1575 return (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
1583 LockSetForegroundWindow(UINT uLockCode
)
1585 return NtUserxLockSetForegroundWindow(uLockCode
);
1593 AnimateWindow(HWND hwnd
,
1597 /* FIXME Add animation code */
1599 /* If trying to show/hide and it's already *
1600 * shown/hidden or invalid window, fail with *
1601 * invalid parameter */
1604 visible
= IsWindowVisible(hwnd
);
1605 if(!IsWindow(hwnd
) ||
1606 (visible
&& !(dwFlags
& AW_HIDE
)) ||
1607 (!visible
&& (dwFlags
& AW_HIDE
)))
1609 SetLastError(ERROR_INVALID_PARAMETER
);
1613 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1625 if (!(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1628 ShowWindow(hWnd
,SW_RESTORE
);
1637 RealChildWindowFromPoint(HWND hwndParent
,
1638 POINT ptParentClientCoords
)
1640 return NtUserRealChildWindowFromPoint(hwndParent
, ptParentClientCoords
.x
, ptParentClientCoords
.y
);
1647 SetForegroundWindow(HWND hWnd
)
1649 return NtUserxSetForegroundWindow(hWnd
);
1657 SetProcessDefaultLayout(DWORD dwDefaultLayout
)
1659 return NtUserCallOneParam( (DWORD_PTR
)dwDefaultLayout
, ONEPARAM_ROUTINE_SETPROCDEFLAYOUT
);
1669 SetWindowTextA(HWND hWnd
,
1674 pwnd
= ValidateHwnd(hWnd
);
1677 if (!TestWindowProcess(pwnd
))
1679 /* do not send WM_GETTEXT messages to other processes */
1680 return (DefWindowProcA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1682 return (SendMessageA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1694 SetWindowTextW(HWND hWnd
,
1699 pwnd
= ValidateHwnd(hWnd
);
1702 if (!TestWindowProcess(pwnd
))
1704 /* do not send WM_GETTEXT messages to other processes */
1705 return (DefWindowProcW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1707 return (SendMessageW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1717 ShowOwnedPopups(HWND hWnd
, BOOL fShow
)
1719 return NtUserxShowOwnedPopups(hWnd
, fShow
);
1727 UpdateLayeredWindow( HWND hwnd
,
1737 if (dwFlags
& ULW_EX_NORESIZE
) /* only valid for UpdateLayeredWindowIndirect */
1739 SetLastError( ERROR_INVALID_PARAMETER
);
1742 return NtUserUpdateLayeredWindow( hwnd
,
1758 UpdateLayeredWindowIndirect(HWND hwnd
,
1759 const UPDATELAYEREDWINDOWINFO
*info
)
1761 if (info
&& info
->cbSize
== sizeof(*info
))
1763 return NtUserUpdateLayeredWindow( hwnd
,
1765 (POINT
*)info
->pptDst
,
1766 (SIZE
*)info
->psize
,
1768 (POINT
*)info
->pptSrc
,
1770 (BLENDFUNCTION
*)info
->pblend
,
1772 (RECT
*)info
->prcDirty
);
1774 SetLastError(ERROR_INVALID_PARAMETER
);
1782 SetWindowContextHelpId(HWND hwnd
,
1783 DWORD dwContextHelpId
)
1785 return NtUserxSetWindowContextHelpId(hwnd
, dwContextHelpId
);
1792 GetWindowContextHelpId(HWND hwnd
)
1794 return NtUserxGetWindowContextHelpId(hwnd
);
1801 InternalGetWindowText(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1803 INT Ret
= NtUserInternalGetWindowText(hWnd
, lpString
, nMaxCount
);
1813 IsHungAppWindow(HWND hwnd
)
1815 return (NtUserQueryWindow(hwnd
, QUERY_WINDOW_ISHUNG
) != 0);
1822 SetLastErrorEx(DWORD dwErrCode
, DWORD dwType
)
1824 SetLastError(dwErrCode
);
1833 return (HWND
)NtUserGetThreadState(THREADSTATE_FOCUSWINDOW
);
1837 GetRealWindowOwner(HWND hwnd
)
1839 return NtUserQueryWindow(hwnd
, QUERY_WINDOW_REAL_ID
);
1846 SetTaskmanWindow(HWND hWnd
)
1848 return NtUserxSetTaskmanWindow(hWnd
);
1855 SetProgmanWindow(HWND hWnd
)
1857 return NtUserxSetProgmanWindow(hWnd
);
1864 GetProgmanWindow(VOID
)
1866 return (HWND
)NtUserGetThreadState(THREADSTATE_PROGMANWINDOW
);
1873 GetTaskmanWindow(VOID
)
1875 return (HWND
)NtUserGetThreadState(THREADSTATE_TASKMANWINDOW
);
1882 ScrollWindow(HWND hWnd
,
1886 CONST RECT
*prcClip
)
1888 return NtUserScrollWindowEx(hWnd
,
1895 (lpRect
? 0 : SW_SCROLLCHILDREN
) | (SW_ERASE
|SW_INVALIDATE
|SW_SCROLLWNDDCE
)) != ERROR
;
1898 /* ScrollWindow uses the window DC, ScrollWindowEx doesn't */
1904 ScrollWindowEx(HWND hWnd
,
1907 CONST RECT
*prcScroll
,
1908 CONST RECT
*prcClip
,
1913 if (flags
& SW_SMOOTHSCROLL
)
1915 FIXME("SW_SMOOTHSCROLL not supported.");
1918 return NtUserScrollWindowEx(hWnd
,
1936 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1938 if (!list
) return FALSE
;
1939 for (i
= 0; list
[i
]; i
++)
1941 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
1943 retvalue
= (list
[i
] != 0);
1944 HeapFree( GetProcessHeap(), 0, list
);
1952 IsWindowInDestroy(HWND hWnd
)
1955 pwnd
= ValidateHwnd(hWnd
);
1958 return ((pwnd
->state2
& WNDS2_INDESTROY
) == WNDS2_INDESTROY
);
1965 DisableProcessWindowsGhosting(VOID
)
1967 NtUserxEnableProcessWindowGhosting(FALSE
);