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
)
88 ShowWindowAsync(hwnd
, SW_RESTORE
);
89 SetForegroundWindow(hwnd
);
93 hwndFG
= GetForegroundWindow();
94 ShowWindow(hwnd
, SW_RESTORE
| SW_SHOWNA
);
95 SetWindowPos(hwnd
, hwndFG
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
96 SetWindowPos(hwndFG
, hwnd
, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
);
105 ChildWindowFromPoint(HWND hWndParent
,
108 return (HWND
) NtUserChildWindowFromPointEx(hWndParent
, Point
.x
, Point
.y
, 0);
116 ChildWindowFromPointEx(HWND hwndParent
,
120 return (HWND
) NtUserChildWindowFromPointEx(hwndParent
, pt
.x
, pt
.y
, uFlags
);
128 CloseWindow(HWND hWnd
)
130 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
132 return HandleToUlong(hWnd
);
138 OUT PLARGE_STRING plstr
,
144 RtlInitLargeUnicodeString((PLARGE_UNICODE_STRING
)plstr
, (PWSTR
)psz
, 0);
148 RtlInitLargeAnsiString((PLARGE_ANSI_STRING
)plstr
, (PSTR
)psz
, 0);
155 IN PLARGE_STRING LargeString
)
157 if (LargeString
->Buffer
)
159 RtlFreeHeap(GetProcessHeap(), 0, LargeString
->Buffer
);
160 RtlZeroMemory(LargeString
, sizeof(LARGE_STRING
));
165 User32CreateWindowEx(DWORD dwExStyle
,
179 LARGE_STRING WindowName
;
180 LARGE_STRING lstrClassName
, *plstrClassName
;
181 LARGE_STRING lstrClassVersion
, *plstrClassVersion
;
182 UNICODE_STRING ClassName
;
183 UNICODE_STRING ClassVersion
;
186 HMODULE hLibModule
= NULL
;
188 BOOL Unicode
, ClassFound
= FALSE
;
190 LPCWSTR lpszClsVersion
;
191 LPCWSTR lpLibFileName
= NULL
;
195 DbgPrint("[window] User32CreateWindowEx style %d, exstyle %d, parent %d\n", dwStyle
, dwExStyle
, hWndParent
);
198 if (!RegisterDefaultClasses
)
200 TRACE("RegisterSystemControls\n");
201 RegisterSystemControls();
204 Unicode
= !(dwFlags
& NUCWE_ANSI
);
206 if (IS_ATOM(lpClassName
))
208 plstrClassName
= (PVOID
)lpClassName
;
214 RtlInitUnicodeString(&ClassName
, (PCWSTR
)lpClassName
);
218 if (!RtlCreateUnicodeStringFromAsciiz(&ClassName
, (PCSZ
)lpClassName
))
220 SetLastError(ERROR_OUTOFMEMORY
);
225 /* Copy it to a LARGE_STRING */
226 lstrClassName
.Buffer
= ClassName
.Buffer
;
227 lstrClassName
.Length
= ClassName
.Length
;
228 lstrClassName
.MaximumLength
= ClassName
.MaximumLength
;
229 plstrClassName
= &lstrClassName
;
232 /* Initialize a LARGE_STRING */
233 RtlInitLargeString(&WindowName
, lpWindowName
, Unicode
);
235 // HACK: The current implementation expects the Window name to be UNICODE
239 PSTR AnsiBuffer
= WindowName
.Buffer
;
240 ULONG AnsiLength
= WindowName
.Length
;
242 WindowName
.Length
= 0;
243 WindowName
.MaximumLength
= AnsiLength
* sizeof(WCHAR
);
244 WindowName
.Buffer
= RtlAllocateHeap(RtlGetProcessHeap(),
246 WindowName
.MaximumLength
);
247 if (!WindowName
.Buffer
)
249 SetLastError(ERROR_OUTOFMEMORY
);
253 Status
= RtlMultiByteToUnicodeN(WindowName
.Buffer
,
254 WindowName
.MaximumLength
,
258 if (!NT_SUCCESS(Status
))
264 if (!hMenu
&& (dwStyle
& (WS_OVERLAPPEDWINDOW
| WS_POPUP
)))
268 wceW
.cbSize
= sizeof(wceW
);
269 if (GetClassInfoExW(hInstance
, (LPCWSTR
)lpClassName
, &wceW
) && wceW
.lpszMenuName
)
271 hMenu
= LoadMenuW(hInstance
, wceW
.lpszMenuName
);
276 wceA
.cbSize
= sizeof(wceA
);
277 if (GetClassInfoExA(hInstance
, lpClassName
, &wceA
) && wceA
.lpszMenuName
)
279 hMenu
= LoadMenuA(hInstance
, wceA
.lpszMenuName
);
284 if (!Unicode
) dwExStyle
|= WS_EX_SETANSICREATOR
;
286 lpszClsVersion
= ClassNameToVersion(lpClassName
, NULL
, &lpLibFileName
, &pCtx
, !Unicode
);
289 plstrClassVersion
= plstrClassName
;
293 RtlInitUnicodeString(&ClassVersion
, lpszClsVersion
);
294 lstrClassVersion
.Buffer
= ClassVersion
.Buffer
;
295 lstrClassVersion
.Length
= ClassVersion
.Length
;
296 lstrClassVersion
.MaximumLength
= ClassVersion
.MaximumLength
;
297 plstrClassVersion
= &lstrClassVersion
;
302 Handle
= NtUserCreateWindowEx(dwExStyle
,
318 if (!lpLibFileName
) break;
321 dwLastError
= GetLastError();
322 if (dwLastError
== ERROR_CANNOT_FIND_WND_CLASS
)
324 ClassFound
= VersionRegisterClass(ClassName
.Buffer
, lpLibFileName
, pCtx
, &hLibModule
);
325 if (ClassFound
) continue;
330 dwLastError
= GetLastError();
331 FreeLibrary(hLibModule
);
332 SetLastError(dwLastError
);
339 DbgPrint("[window] NtUserCreateWindowEx() == %d\n", Handle
);
345 if (!IS_ATOM(lpClassName
))
346 RtlFreeUnicodeString(&ClassName
);
348 RtlFreeLargeString(&WindowName
);
361 CreateWindowExA(DWORD dwExStyle
,
374 MDICREATESTRUCTA mdi
;
377 if (!RegisterDefaultClasses
)
379 TRACE("CreateWindowExA RegisterSystemControls\n");
380 RegisterSystemControls();
383 if (dwExStyle
& WS_EX_MDICHILD
)
390 pWndParent
= ValidateHwnd(hWndParent
);
392 if (!pWndParent
) return NULL
;
394 if (pWndParent
->fnid
!= FNID_MDICLIENT
) // wine uses WIN_ISMDICLIENT
396 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
400 /* lpParams of WM_[NC]CREATE is different for MDI children.
401 * MDICREATESTRUCT members have the originally passed values.
403 mdi
.szClass
= lpClassName
;
404 mdi
.szTitle
= lpWindowName
;
405 mdi
.hOwner
= hInstance
;
411 mdi
.lParam
= (LPARAM
)lpParam
;
413 lpParam
= (LPVOID
)&mdi
;
415 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
417 if (dwStyle
& WS_POPUP
)
419 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
422 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
426 dwStyle
&= ~WS_POPUP
;
427 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
428 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
431 top_child
= GetWindow(hWndParent
, GW_CHILD
);
435 /* Restore current maximized child */
436 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
438 TRACE("Restoring current maximized child %p\n", top_child
);
439 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
440 ShowWindow(top_child
, SW_RESTORE
);
441 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
445 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
447 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
449 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
451 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
456 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
458 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
463 hwnd
= User32CreateWindowEx(dwExStyle
,
486 CreateWindowExW(DWORD dwExStyle
,
488 LPCWSTR lpWindowName
,
499 MDICREATESTRUCTW mdi
;
502 if (!RegisterDefaultClasses
)
504 ERR("CreateWindowExW RegisterSystemControls\n");
505 RegisterSystemControls();
508 if (dwExStyle
& WS_EX_MDICHILD
)
515 pWndParent
= ValidateHwnd(hWndParent
);
517 if (!pWndParent
) return NULL
;
519 if (pWndParent
->fnid
!= FNID_MDICLIENT
)
521 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
525 /* lpParams of WM_[NC]CREATE is different for MDI children.
526 * MDICREATESTRUCT members have the originally passed values.
528 mdi
.szClass
= lpClassName
;
529 mdi
.szTitle
= lpWindowName
;
530 mdi
.hOwner
= hInstance
;
536 mdi
.lParam
= (LPARAM
)lpParam
;
538 lpParam
= (LPVOID
)&mdi
;
540 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
542 if (dwStyle
& WS_POPUP
)
544 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
547 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
551 dwStyle
&= ~WS_POPUP
;
552 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
553 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
556 top_child
= GetWindow(hWndParent
, GW_CHILD
);
560 /* Restore current maximized child */
561 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
563 TRACE("Restoring current maximized child %p\n", top_child
);
564 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
565 ShowWindow(top_child
, SW_RESTORE
);
566 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
570 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
572 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
574 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
576 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
581 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
583 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
588 hwnd
= User32CreateWindowEx(dwExStyle
,
590 (LPCSTR
)lpWindowName
,
608 DeferWindowPos(HDWP hWinPosInfo
,
610 HWND hWndInsertAfter
,
617 return NtUserDeferWindowPos(hWinPosInfo
, hWnd
, hWndInsertAfter
, x
, y
, cx
, cy
, uFlags
);
625 EndDeferWindowPos(HDWP hWinPosInfo
)
627 return NtUserEndDeferWindowPosEx(hWinPosInfo
, 0);
635 GetDesktopWindow(VOID
)
642 Wnd
= GetThreadDesktopWnd();
644 Ret
= UserHMGetHandle(Wnd
);
646 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
657 User32EnumWindows(HDESK hDesktop
,
664 DWORD i
, dwCount
= 0;
671 SetLastError ( ERROR_INVALID_PARAMETER
);
675 /* FIXME instead of always making two calls, should we use some
676 sort of persistent buffer and only grow it ( requiring a 2nd
677 call ) when the buffer wasn't already big enough? */
678 /* first get how many window entries there are */
679 Status
= NtUserBuildHwndList(hDesktop
,
686 if (!NT_SUCCESS(Status
))
697 /* allocate buffer to receive HWND handles */
698 hHeap
= GetProcessHeap();
699 pHwnd
= HeapAlloc(hHeap
, 0, sizeof(HWND
)*(dwCount
+1));
702 SetLastError ( ERROR_NOT_ENOUGH_MEMORY
);
706 /* now call kernel again to fill the buffer this time */
707 Status
= NtUserBuildHwndList(hDesktop
,
714 if (!NT_SUCCESS(Status
))
717 HeapFree(hHeap
, 0, pHwnd
);
721 /* call the user's callback function until we're done or
722 they tell us to quit */
723 for ( i
= 0; i
< dwCount
; i
++ )
725 /* FIXME I'm only getting NULLs from Thread Enumeration, and it's
726 * probably because I'm not doing it right in NtUserBuildHwndList.
727 * Once that's fixed, we shouldn't have to check for a NULL HWND
729 * This is now fixed in revision 50205. (jt)
731 if (!pHwnd
[i
]) /* don't enumerate a NULL HWND */
733 if (!(*lpfn
)(pHwnd
[i
], lParam
))
735 HeapFree ( hHeap
, 0, pHwnd
);
740 HeapFree(hHeap
, 0, pHwnd
);
749 EnumChildWindows(HWND hWndParent
,
750 WNDENUMPROC lpEnumFunc
,
755 return EnumWindows(lpEnumFunc
, lParam
);
757 return User32EnumWindows(NULL
, hWndParent
, lpEnumFunc
, lParam
, 0, TRUE
);
765 EnumThreadWindows(DWORD dwThreadId
,
770 dwThreadId
= GetCurrentThreadId();
771 return User32EnumWindows(NULL
, NULL
, lpfn
, lParam
, dwThreadId
, FALSE
);
779 EnumWindows(WNDENUMPROC lpEnumFunc
,
782 return User32EnumWindows(NULL
, NULL
, lpEnumFunc
, lParam
, 0, FALSE
);
790 EnumDesktopWindows(HDESK hDesktop
,
794 return User32EnumWindows(hDesktop
, NULL
, lpfn
, lParam
, 0, FALSE
);
802 FindWindowExA(HWND hwndParent
,
807 LPWSTR titleW
= NULL
;
812 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, lpszWindow
, -1, NULL
, 0 );
813 if (!(titleW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
814 MultiByteToWideChar( CP_ACP
, 0, lpszWindow
, -1, titleW
, len
);
817 if (!IS_INTRESOURCE(lpszClass
))
820 if (MultiByteToWideChar( CP_ACP
, 0, lpszClass
, -1, classW
, sizeof(classW
)/sizeof(WCHAR
) ))
821 hwnd
= FindWindowExW( hwndParent
, hwndChildAfter
, classW
, titleW
);
825 hwnd
= FindWindowExW( hwndParent
, hwndChildAfter
, (LPCWSTR
)lpszClass
, titleW
);
828 HeapFree( GetProcessHeap(), 0, titleW
);
837 FindWindowExW(HWND hwndParent
,
842 UNICODE_STRING ucClassName
, *pucClassName
= NULL
;
843 UNICODE_STRING ucWindowName
, *pucWindowName
= NULL
;
845 if (IS_ATOM(lpszClass
))
847 ucClassName
.Length
= 0;
848 ucClassName
.Buffer
= (LPWSTR
)lpszClass
;
849 pucClassName
= &ucClassName
;
851 else if (lpszClass
!= NULL
)
853 RtlInitUnicodeString(&ucClassName
,
855 pucClassName
= &ucClassName
;
858 if (lpszWindow
!= NULL
)
860 RtlInitUnicodeString(&ucWindowName
,
862 pucWindowName
= &ucWindowName
;
865 return NtUserFindWindowEx(hwndParent
,
877 FindWindowA(LPCSTR lpClassName
, LPCSTR lpWindowName
)
879 //FIXME: FindWindow does not search children, but FindWindowEx does.
880 // what should we do about this?
881 return FindWindowExA (NULL
, NULL
, lpClassName
, lpWindowName
);
889 FindWindowW(LPCWSTR lpClassName
, LPCWSTR lpWindowName
)
893 There was a FIXME here earlier, but I think it is just a documentation unclarity.
895 FindWindow only searches top level windows. What they mean is that child
896 windows of other windows than the desktop can be searched.
897 FindWindowExW never does a recursive search.
902 return FindWindowExW(NULL
, NULL
, lpClassName
, lpWindowName
);
911 GetAltTabInfoA(HWND hwnd
,
917 return NtUserGetAltTabInfo(hwnd
,iItem
,pati
,(LPWSTR
)pszItemText
,cchItemText
,TRUE
);
925 GetAltTabInfoW(HWND hwnd
,
931 return NtUserGetAltTabInfo(hwnd
,iItem
,pati
,pszItemText
,cchItemText
,FALSE
);
939 GetAncestor(HWND hwnd
, UINT gaFlags
)
944 Wnd
= ValidateHwnd(hwnd
);
954 if (Wnd
->spwndParent
!= NULL
)
955 Ancestor
= DesktopPtrToUser(Wnd
->spwndParent
);
959 /* FIXME: Call win32k for now */
964 if (Ancestor
!= NULL
)
965 Ret
= UserHMGetHandle(Ancestor
);
967 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
973 if (!Wnd
) /* Fall back */
974 Ret
= NtUserGetAncestor(hwnd
, gaFlags
);
984 GetClientRect(HWND hWnd
, LPRECT lpRect
)
986 PWND Wnd
= ValidateHwnd(hWnd
);
988 if (!Wnd
) return FALSE
;
989 if (Wnd
->style
& WS_MINIMIZED
)
991 lpRect
->left
= lpRect
->top
= 0;
992 lpRect
->right
= GetSystemMetrics(SM_CXMINIMIZED
);
993 lpRect
->bottom
= GetSystemMetrics(SM_CYMINIMIZED
);
996 if ( hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
998 /* lpRect->left = lpRect->top = 0;
999 lpRect->right = Wnd->rcClient.right - Wnd->rcClient.left;
1000 lpRect->bottom = Wnd->rcClient.bottom - Wnd->rcClient.top;
1002 *lpRect
= Wnd
->rcClient
;
1003 OffsetRect(lpRect
, -Wnd
->rcClient
.left
, -Wnd
->rcClient
.top
);
1007 lpRect
->left
= lpRect
->top
= 0;
1008 lpRect
->right
= Wnd
->rcClient
.right
;
1009 lpRect
->bottom
= Wnd
->rcClient
.bottom
;
1010 /* Do this until Init bug is fixed. This sets 640x480, see InitMetrics.
1011 lpRect->right = GetSystemMetrics(SM_CXSCREEN);
1012 lpRect->bottom = GetSystemMetrics(SM_CYSCREEN);
1022 GetLastActivePopup(HWND hWnd
)
1027 Wnd
= ValidateHwnd(hWnd
);
1032 if (Wnd
->spwndLastActive
)
1034 PWND LastActive
= DesktopPtrToUser(Wnd
->spwndLastActive
);
1035 Ret
= UserHMGetHandle(LastActive
);
1038 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1052 GetParent(HWND hWnd
)
1054 PWND Wnd
, WndParent
;
1057 Wnd
= ValidateHwnd(hWnd
);
1063 if (Wnd
->style
& WS_POPUP
)
1065 if (Wnd
->spwndOwner
!= NULL
)
1066 WndParent
= DesktopPtrToUser(Wnd
->spwndOwner
);
1068 else if (Wnd
->style
& WS_CHILD
)
1070 if (Wnd
->spwndParent
!= NULL
)
1071 WndParent
= DesktopPtrToUser(Wnd
->spwndParent
);
1074 if (WndParent
!= NULL
)
1075 Ret
= UserHMGetHandle(WndParent
);
1077 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1092 GetProcessDefaultLayout(DWORD
*pdwDefaultLayout
)
1094 return (BOOL
)NtUserCallOneParam( (DWORD_PTR
)pdwDefaultLayout
, ONEPARAM_ROUTINE_GETPROCDEFLAYOUT
);
1102 GetWindow(HWND hWnd
,
1108 Wnd
= ValidateHwnd(hWnd
);
1118 if (Wnd
->spwndOwner
!= NULL
)
1119 FoundWnd
= DesktopPtrToUser(Wnd
->spwndOwner
);
1123 if(Wnd
->spwndParent
!= NULL
)
1125 FoundWnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1126 if (FoundWnd
->spwndChild
!= NULL
)
1127 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndChild
);
1131 if (Wnd
->spwndNext
!= NULL
)
1132 FoundWnd
= DesktopPtrToUser(Wnd
->spwndNext
);
1136 if (Wnd
->spwndPrev
!= NULL
)
1137 FoundWnd
= DesktopPtrToUser(Wnd
->spwndPrev
);
1141 if (Wnd
->spwndChild
!= NULL
)
1142 FoundWnd
= DesktopPtrToUser(Wnd
->spwndChild
);
1147 while ( FoundWnd
->spwndNext
!= NULL
)
1148 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndNext
);
1156 if (FoundWnd
!= NULL
)
1157 Ret
= UserHMGetHandle(FoundWnd
);
1159 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1173 GetTopWindow(HWND hWnd
)
1175 if (!hWnd
) hWnd
= GetDesktopWindow();
1176 return GetWindow(hWnd
, GW_CHILD
);
1186 GetWindowInfo(HWND hWnd
,
1194 if ( !pwi
|| pwi
->cbSize
!= sizeof(WINDOWINFO
))
1195 SetLastError(ERROR_INVALID_PARAMETER
); // Just set the error and go!
1197 pWnd
= ValidateHwnd(hWnd
);
1201 UserGetWindowBorders(pWnd
->style
, pWnd
->ExStyle
, &Size
, FALSE
);
1205 pCls
= DesktopPtrToUser(pWnd
->pcls
);
1206 pwi
->rcWindow
= pWnd
->rcWindow
;
1207 pwi
->rcClient
= pWnd
->rcClient
;
1208 pwi
->dwStyle
= pWnd
->style
;
1209 pwi
->dwExStyle
= pWnd
->ExStyle
;
1210 pwi
->cxWindowBorders
= Size
.cx
;
1211 pwi
->cyWindowBorders
= Size
.cy
;
1212 pwi
->dwWindowStatus
= 0;
1213 if (pWnd
->state
& WNDS_ACTIVEFRAME
|| (GetActiveWindow() == hWnd
))
1214 pwi
->dwWindowStatus
= WS_ACTIVECAPTION
;
1215 pwi
->atomWindowType
= (pCls
? pCls
->atomClassName
: 0 );
1217 if ( pWnd
->state2
& WNDS2_WIN50COMPAT
)
1219 pwi
->wCreatorVersion
= 0x500;
1221 else if ( pWnd
->state2
& WNDS2_WIN40COMPAT
)
1223 pwi
->wCreatorVersion
= 0x400;
1225 else if ( pWnd
->state2
& WNDS2_WIN31COMPAT
)
1227 pwi
->wCreatorVersion
= 0x30A;
1231 pwi
->wCreatorVersion
= 0x300;
1236 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1250 GetWindowModuleFileNameA(HWND hwnd
,
1252 UINT cchFileNameMax
)
1254 PWND Wnd
= ValidateHwnd(hwnd
);
1259 return GetModuleFileNameA(Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1267 GetWindowModuleFileNameW(HWND hwnd
,
1268 LPWSTR lpszFileName
,
1269 UINT cchFileNameMax
)
1271 PWND Wnd
= ValidateHwnd(hwnd
);
1276 return GetModuleFileNameW( Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1283 GetWindowRect(HWND hWnd
,
1286 PWND Wnd
= ValidateHwnd(hWnd
);
1288 if (!Wnd
) return FALSE
;
1289 if ( hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
1291 *lpRect
= Wnd
->rcWindow
;
1295 lpRect
->left
= lpRect
->top
= 0;
1296 lpRect
->right
= Wnd
->rcWindow
.right
;
1297 lpRect
->bottom
= Wnd
->rcWindow
.bottom
;
1298 /* Do this until Init bug is fixed. This sets 640x480, see InitMetrics.
1299 lpRect->right = GetSystemMetrics(SM_CXSCREEN);
1300 lpRect->bottom = GetSystemMetrics(SM_CYSCREEN);
1309 GetWindowTextA(HWND hWnd
, LPSTR lpString
, int nMaxCount
)
1314 if (lpString
== NULL
|| nMaxCount
== 0)
1317 Wnd
= ValidateHwnd(hWnd
);
1323 if (!TestWindowProcess(Wnd
))
1327 Length
= DefWindowProcA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1329 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1337 Length
= SendMessageA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1339 //ERR("GWTA Len %d : %s\n",Length,lpString);
1347 GetWindowTextLengthA(HWND hWnd
)
1351 Wnd
= ValidateHwnd(hWnd
);
1355 if (!TestWindowProcess(Wnd
))
1357 return DefWindowProcA(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1361 return SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1369 GetWindowTextLengthW(HWND hWnd
)
1373 Wnd
= ValidateHwnd(hWnd
);
1377 if (!TestWindowProcess(Wnd
))
1379 return DefWindowProcW(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1383 return SendMessageW(hWnd
, WM_GETTEXTLENGTH
, 0, 0);
1391 GetWindowTextW(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1396 if (lpString
== NULL
|| nMaxCount
== 0)
1399 Wnd
= ValidateHwnd(hWnd
);
1403 lpString
[0] = L
'\0';
1405 if (!TestWindowProcess(Wnd
))
1409 Length
= DefWindowProcW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1411 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1419 Length
= SendMessageW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1421 //ERR("GWTW Len %d : %S\n",Length,lpString);
1426 GetWindowThreadProcessId(HWND hWnd
,
1427 LPDWORD lpdwProcessId
)
1431 PWND pWnd
= ValidateHwnd(hWnd
);
1433 if (!pWnd
) return Ret
;
1435 ti
= pWnd
->head
.pti
;
1439 if (ti
== GetW32ThreadInfo())
1440 { // We are current.
1441 //FIXME("Current!\n");
1443 *lpdwProcessId
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueProcess
;
1444 Ret
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueThread
;
1447 { // Ask kernel for info.
1448 //FIXME("Kernel call!\n");
1450 *lpdwProcessId
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
);
1451 Ret
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_THREAD_ID
);
1462 IsChild(HWND hWndParent
,
1465 PWND WndParent
, DesktopWnd
, Wnd
;
1468 WndParent
= ValidateHwnd(hWndParent
);
1471 Wnd
= ValidateHwnd(hWnd
);
1475 DesktopWnd
= GetThreadDesktopWnd();
1481 while (Wnd
!= NULL
&& ((Wnd
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
1483 if (Wnd
->spwndParent
!= NULL
)
1485 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1487 if (Wnd
== WndParent
)
1497 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1513 PWND Wnd
= ValidateHwnd(hWnd
);
1516 return (Wnd
->style
& WS_MINIMIZE
) != 0;
1528 PWND Wnd
= ValidateHwndNoErr(hWnd
);
1531 if (Wnd
->state
& WNDS_DESTROYED
||
1532 Wnd
->state2
& WNDS2_INDESTROY
)
1545 IsWindowUnicode(HWND hWnd
)
1547 PWND Wnd
= ValidateHwnd(hWnd
);
1550 return Wnd
->Unicode
;
1560 IsWindowVisible(HWND hWnd
)
1563 PWND Wnd
= ValidateHwnd(hWnd
);
1573 if (!(Wnd
->style
& WS_VISIBLE
))
1579 if (Wnd
->spwndParent
!= NULL
)
1580 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1584 } while (Wnd
!= NULL
);
1586 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1601 IsWindowEnabled(HWND hWnd
)
1603 // AG: I don't know if child windows are affected if the parent is
1604 // disabled. I think they stop processing messages but stay appearing
1607 return !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_DISABLED
);
1617 return (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
1625 LockSetForegroundWindow(UINT uLockCode
)
1627 return NtUserxLockSetForegroundWindow(uLockCode
);
1635 AnimateWindow(HWND hwnd
,
1639 /* FIXME Add animation code */
1641 /* If trying to show/hide and it's already *
1642 * shown/hidden or invalid window, fail with *
1643 * invalid parameter */
1646 visible
= IsWindowVisible(hwnd
);
1647 if(!IsWindow(hwnd
) ||
1648 (visible
&& !(dwFlags
& AW_HIDE
)) ||
1649 (!visible
&& (dwFlags
& AW_HIDE
)))
1651 SetLastError(ERROR_INVALID_PARAMETER
);
1655 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1667 if (!(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1670 ShowWindow(hWnd
,SW_RESTORE
);
1679 RealChildWindowFromPoint(HWND hwndParent
,
1680 POINT ptParentClientCoords
)
1682 return NtUserRealChildWindowFromPoint(hwndParent
, ptParentClientCoords
.x
, ptParentClientCoords
.y
);
1689 SetForegroundWindow(HWND hWnd
)
1691 return NtUserxSetForegroundWindow(hWnd
);
1699 SetProcessDefaultLayout(DWORD dwDefaultLayout
)
1701 return NtUserCallOneParam( (DWORD_PTR
)dwDefaultLayout
, ONEPARAM_ROUTINE_SETPROCDEFLAYOUT
);
1711 SetWindowTextA(HWND hWnd
,
1716 pwnd
= ValidateHwnd(hWnd
);
1719 if (!TestWindowProcess(pwnd
))
1721 /* do not send WM_GETTEXT messages to other processes */
1722 return (DefWindowProcA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1724 return (SendMessageA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1736 SetWindowTextW(HWND hWnd
,
1741 pwnd
= ValidateHwnd(hWnd
);
1744 if (!TestWindowProcess(pwnd
))
1746 /* do not send WM_GETTEXT messages to other processes */
1747 return (DefWindowProcW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1749 return (SendMessageW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1759 ShowOwnedPopups(HWND hWnd
, BOOL fShow
)
1761 return NtUserxShowOwnedPopups(hWnd
, fShow
);
1769 UpdateLayeredWindow( HWND hwnd
,
1779 if (dwFlags
& ULW_EX_NORESIZE
) /* only valid for UpdateLayeredWindowIndirect */
1781 SetLastError( ERROR_INVALID_PARAMETER
);
1784 return NtUserUpdateLayeredWindow( hwnd
,
1800 UpdateLayeredWindowIndirect(HWND hwnd
,
1801 const UPDATELAYEREDWINDOWINFO
*info
)
1803 if (info
&& info
->cbSize
== sizeof(*info
))
1805 return NtUserUpdateLayeredWindow( hwnd
,
1807 (POINT
*)info
->pptDst
,
1808 (SIZE
*)info
->psize
,
1810 (POINT
*)info
->pptSrc
,
1812 (BLENDFUNCTION
*)info
->pblend
,
1814 (RECT
*)info
->prcDirty
);
1816 SetLastError(ERROR_INVALID_PARAMETER
);
1824 SetWindowContextHelpId(HWND hwnd
,
1825 DWORD dwContextHelpId
)
1827 return NtUserxSetWindowContextHelpId(hwnd
, dwContextHelpId
);
1834 GetWindowContextHelpId(HWND hwnd
)
1836 return NtUserxGetWindowContextHelpId(hwnd
);
1843 InternalGetWindowText(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1845 INT Ret
= NtUserInternalGetWindowText(hWnd
, lpString
, nMaxCount
);
1846 if (Ret
== 0 && lpString
)
1855 IsHungAppWindow(HWND hwnd
)
1857 return (NtUserQueryWindow(hwnd
, QUERY_WINDOW_ISHUNG
) != 0);
1864 SetLastErrorEx(DWORD dwErrCode
, DWORD dwType
)
1866 SetLastError(dwErrCode
);
1875 return (HWND
)NtUserGetThreadState(THREADSTATE_FOCUSWINDOW
);
1879 GetRealWindowOwner(HWND hwnd
)
1881 return NtUserQueryWindow(hwnd
, QUERY_WINDOW_REAL_ID
);
1888 SetTaskmanWindow(HWND hWnd
)
1890 return NtUserxSetTaskmanWindow(hWnd
);
1897 SetProgmanWindow(HWND hWnd
)
1899 return NtUserxSetProgmanWindow(hWnd
);
1906 GetProgmanWindow(VOID
)
1908 return (HWND
)NtUserGetThreadState(THREADSTATE_PROGMANWINDOW
);
1915 GetTaskmanWindow(VOID
)
1917 return (HWND
)NtUserGetThreadState(THREADSTATE_TASKMANWINDOW
);
1924 ScrollWindow(HWND hWnd
,
1928 CONST RECT
*prcClip
)
1930 return NtUserScrollWindowEx(hWnd
,
1937 (lpRect
? 0 : SW_SCROLLCHILDREN
) | (SW_ERASE
|SW_INVALIDATE
|SW_SCROLLWNDDCE
)) != ERROR
;
1940 /* ScrollWindow uses the window DC, ScrollWindowEx doesn't */
1946 ScrollWindowEx(HWND hWnd
,
1949 CONST RECT
*prcScroll
,
1950 CONST RECT
*prcClip
,
1955 if (flags
& SW_SMOOTHSCROLL
)
1957 FIXME("SW_SMOOTHSCROLL not supported.");
1960 return NtUserScrollWindowEx(hWnd
,
1978 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1980 if (!list
) return FALSE
;
1981 for (i
= 0; list
[i
]; i
++)
1983 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
1985 retvalue
= (list
[i
] != 0);
1986 HeapFree( GetProcessHeap(), 0, list
);
1994 IsWindowInDestroy(HWND hWnd
)
1997 pwnd
= ValidateHwnd(hWnd
);
2000 return ((pwnd
->state2
& WNDS2_INDESTROY
) == WNDS2_INDESTROY
);
2007 DisableProcessWindowsGhosting(VOID
)
2009 NtUserxEnableProcessWindowGhosting(FALSE
);