2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS user32.dll
4 * FILE: lib/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 LRESULT
DefWndNCPaint(HWND hWnd
, HRGN hRgn
, BOOL Active
);
19 void MDI_CalcDefaultChildPos( HWND hwndClient
, INT total
, LPPOINT lpPos
, INT delta
, UINT
*id
);
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 UNICODE_STRING ClassName
;
172 HMODULE hLibModule
= NULL
;
174 BOOL Unicode
, ClassFound
= FALSE
;
178 DbgPrint("[window] User32CreateWindowEx style %d, exstyle %d, parent %d\n", dwStyle
, dwExStyle
, hWndParent
);
181 if (!RegisterDefaultClasses
)
183 TRACE("RegisterSystemControls\n");
184 RegisterSystemControls();
187 Unicode
= !(dwFlags
& NUCWE_ANSI
);
189 if (IS_ATOM(lpClassName
))
191 plstrClassName
= (PVOID
)lpClassName
;
196 RtlInitUnicodeString(&ClassName
, (PCWSTR
)lpClassName
);
199 if (!RtlCreateUnicodeStringFromAsciiz(&ClassName
, (PCSZ
)lpClassName
))
201 SetLastError(ERROR_OUTOFMEMORY
);
206 /* Copy it to a LARGE_STRING */
207 lstrClassName
.Buffer
= ClassName
.Buffer
;
208 lstrClassName
.Length
= ClassName
.Length
;
209 lstrClassName
.MaximumLength
= ClassName
.MaximumLength
;
210 plstrClassName
= &lstrClassName
;
213 /* Initialize a LARGE_STRING */
214 RtlInitLargeString(&WindowName
, lpWindowName
, Unicode
);
216 // HACK: The current implementation expects the Window name to be UNICODE
220 PSTR AnsiBuffer
= WindowName
.Buffer
;
221 ULONG AnsiLength
= WindowName
.Length
;
223 WindowName
.Length
= 0;
224 WindowName
.MaximumLength
= AnsiLength
* sizeof(WCHAR
);
225 WindowName
.Buffer
= RtlAllocateHeap(RtlGetProcessHeap(),
227 WindowName
.MaximumLength
);
228 if (!WindowName
.Buffer
)
230 SetLastError(ERROR_OUTOFMEMORY
);
234 Status
= RtlMultiByteToUnicodeN(WindowName
.Buffer
,
235 WindowName
.MaximumLength
,
239 if (!NT_SUCCESS(Status
))
245 if(!hMenu
&& (dwStyle
& (WS_OVERLAPPEDWINDOW
| WS_POPUP
)))
249 wceW
.cbSize
= sizeof(WNDCLASSEXW
);
250 if(GetClassInfoExW(hInstance
, (LPCWSTR
)lpClassName
, &wceW
) && wceW
.lpszMenuName
)
252 hMenu
= LoadMenuW(hInstance
, wceW
.lpszMenuName
);
257 wceA
.cbSize
= sizeof(WNDCLASSEXA
);
258 if(GetClassInfoExA(hInstance
, lpClassName
, &wceA
) && wceA
.lpszMenuName
)
260 hMenu
= LoadMenuA(hInstance
, wceA
.lpszMenuName
);
265 if (!Unicode
) dwExStyle
|= WS_EX_SETANSICREATOR
;
269 Handle
= NtUserCreateWindowEx(dwExStyle
,
287 save_error
= GetLastError();
288 if ( save_error
== ERROR_CANNOT_FIND_WND_CLASS
)
290 ClassFound
= VersionRegisterClass(ClassName
.Buffer
, NULL
, NULL
, &hLibModule
);
291 if (ClassFound
) continue;
296 save_error
= GetLastError();
297 FreeLibrary(hLibModule
);
298 SetLastError(save_error
);
305 DbgPrint("[window] NtUserCreateWindowEx() == %d\n", Handle
);
310 if (!IS_ATOM(lpClassName
))
312 RtlFreeUnicodeString(&ClassName
);
315 RtlFreeLargeString(&WindowName
);
328 CreateWindowExA(DWORD dwExStyle
,
341 MDICREATESTRUCTA mdi
;
344 if (!RegisterDefaultClasses
)
346 TRACE("CreateWindowExA RegisterSystemControls\n");
347 RegisterSystemControls();
350 if (dwExStyle
& WS_EX_MDICHILD
)
357 pWndParent
= ValidateHwnd(hWndParent
);
359 if (!pWndParent
) return NULL
;
361 if (pWndParent
->fnid
!= FNID_MDICLIENT
) // wine uses WIN_ISMDICLIENT
363 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
367 /* lpParams of WM_[NC]CREATE is different for MDI children.
368 * MDICREATESTRUCT members have the originally passed values.
370 mdi
.szClass
= lpClassName
;
371 mdi
.szTitle
= lpWindowName
;
372 mdi
.hOwner
= hInstance
;
378 mdi
.lParam
= (LPARAM
)lpParam
;
380 lpParam
= (LPVOID
)&mdi
;
382 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
384 if (dwStyle
& WS_POPUP
)
386 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
389 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
393 dwStyle
&= ~WS_POPUP
;
394 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
395 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
398 top_child
= GetWindow(hWndParent
, GW_CHILD
);
402 /* Restore current maximized child */
403 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
405 TRACE("Restoring current maximized child %p\n", top_child
);
406 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
407 ShowWindow(top_child
, SW_RESTORE
);
408 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
412 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
414 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
416 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
418 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
423 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
425 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
430 hwnd
= User32CreateWindowEx(dwExStyle
,
453 CreateWindowExW(DWORD dwExStyle
,
455 LPCWSTR lpWindowName
,
466 MDICREATESTRUCTW mdi
;
469 if (!RegisterDefaultClasses
)
471 ERR("CreateWindowExW RegisterSystemControls\n");
472 RegisterSystemControls();
475 if (dwExStyle
& WS_EX_MDICHILD
)
482 pWndParent
= ValidateHwnd(hWndParent
);
484 if (!pWndParent
) return NULL
;
486 if (pWndParent
->fnid
!= FNID_MDICLIENT
)
488 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
492 /* lpParams of WM_[NC]CREATE is different for MDI children.
493 * MDICREATESTRUCT members have the originally passed values.
495 mdi
.szClass
= lpClassName
;
496 mdi
.szTitle
= lpWindowName
;
497 mdi
.hOwner
= hInstance
;
503 mdi
.lParam
= (LPARAM
)lpParam
;
505 lpParam
= (LPVOID
)&mdi
;
507 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
509 if (dwStyle
& WS_POPUP
)
511 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
514 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
518 dwStyle
&= ~WS_POPUP
;
519 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
520 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
523 top_child
= GetWindow(hWndParent
, GW_CHILD
);
527 /* Restore current maximized child */
528 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
530 TRACE("Restoring current maximized child %p\n", top_child
);
531 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
532 ShowWindow(top_child
, SW_RESTORE
);
533 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
537 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
539 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
541 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
543 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
548 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
550 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
555 hwnd
= User32CreateWindowEx(dwExStyle
,
556 (LPCSTR
) lpClassName
,
557 (LPCSTR
) lpWindowName
,
575 DeferWindowPos(HDWP hWinPosInfo
,
577 HWND hWndInsertAfter
,
584 return NtUserDeferWindowPos(hWinPosInfo
, hWnd
, hWndInsertAfter
, x
, y
, cx
, cy
, uFlags
);
592 EndDeferWindowPos(HDWP hWinPosInfo
)
594 return NtUserEndDeferWindowPosEx(hWinPosInfo
, 0);
602 GetDesktopWindow(VOID
)
609 Wnd
= GetThreadDesktopWnd();
611 Ret
= UserHMGetHandle(Wnd
);
613 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
624 User32EnumWindows(HDESK hDesktop
,
631 DWORD i
, dwCount
= 0;
638 SetLastError ( ERROR_INVALID_PARAMETER
);
642 /* FIXME instead of always making two calls, should we use some
643 sort of persistent buffer and only grow it ( requiring a 2nd
644 call ) when the buffer wasn't already big enough? */
645 /* first get how many window entries there are */
646 Status
= NtUserBuildHwndList(hDesktop
,
653 if (!NT_SUCCESS(Status
))
656 /* allocate buffer to receive HWND handles */
657 hHeap
= GetProcessHeap();
658 pHwnd
= HeapAlloc(hHeap
, 0, sizeof(HWND
)*(dwCount
+1));
661 SetLastError ( ERROR_NOT_ENOUGH_MEMORY
);
665 /* now call kernel again to fill the buffer this time */
666 Status
= NtUserBuildHwndList(hDesktop
,
673 if (!NT_SUCCESS(Status
))
676 HeapFree(hHeap
, 0, pHwnd
);
688 /* call the user's callback function until we're done or
689 they tell us to quit */
690 for ( i
= 0; i
< dwCount
; i
++ )
692 /* FIXME I'm only getting NULLs from Thread Enumeration, and it's
693 * probably because I'm not doing it right in NtUserBuildHwndList.
694 * Once that's fixed, we shouldn't have to check for a NULL HWND
696 * This is now fixed in revision 50205. (jt)
698 if (!pHwnd
[i
]) /* don't enumerate a NULL HWND */
700 if (!(*lpfn
)(pHwnd
[i
], lParam
))
702 HeapFree ( hHeap
, 0, pHwnd
);
707 HeapFree(hHeap
, 0, pHwnd
);
716 EnumChildWindows(HWND hWndParent
,
717 WNDENUMPROC lpEnumFunc
,
722 return EnumWindows(lpEnumFunc
, lParam
);
724 return User32EnumWindows(NULL
, hWndParent
, lpEnumFunc
, lParam
, 0, TRUE
);
732 EnumThreadWindows(DWORD dwThreadId
,
737 dwThreadId
= GetCurrentThreadId();
738 return User32EnumWindows(NULL
, NULL
, lpfn
, lParam
, dwThreadId
, FALSE
);
746 EnumWindows(WNDENUMPROC lpEnumFunc
,
749 return User32EnumWindows(NULL
, NULL
, lpEnumFunc
, lParam
, 0, FALSE
);
757 EnumDesktopWindows(HDESK hDesktop
,
761 return User32EnumWindows(hDesktop
, NULL
, lpfn
, lParam
, 0, FALSE
);
769 FindWindowExA(HWND hwndParent
,
774 LPWSTR titleW
= NULL
;
779 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, lpszWindow
, -1, NULL
, 0 );
780 if (!(titleW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
781 MultiByteToWideChar( CP_ACP
, 0, lpszWindow
, -1, titleW
, len
);
784 if (!IS_INTRESOURCE(lpszClass
))
787 if (MultiByteToWideChar( CP_ACP
, 0, lpszClass
, -1, classW
, sizeof(classW
)/sizeof(WCHAR
) ))
788 hwnd
= FindWindowExW( hwndParent
, hwndChildAfter
, classW
, titleW
);
792 hwnd
= FindWindowExW( hwndParent
, hwndChildAfter
, (LPCWSTR
)lpszClass
, titleW
);
795 HeapFree( GetProcessHeap(), 0, titleW
);
804 FindWindowExW(HWND hwndParent
,
809 UNICODE_STRING ucClassName
, *pucClassName
= NULL
;
810 UNICODE_STRING ucWindowName
, *pucWindowName
= NULL
;
812 if (IS_ATOM(lpszClass
))
814 ucClassName
.Length
= 0;
815 ucClassName
.Buffer
= (LPWSTR
)lpszClass
;
816 pucClassName
= &ucClassName
;
818 else if (lpszClass
!= NULL
)
820 RtlInitUnicodeString(&ucClassName
,
822 pucClassName
= &ucClassName
;
825 if (lpszWindow
!= NULL
)
827 RtlInitUnicodeString(&ucWindowName
,
829 pucWindowName
= &ucWindowName
;
832 return NtUserFindWindowEx(hwndParent
,
844 FindWindowA(LPCSTR lpClassName
, LPCSTR lpWindowName
)
846 //FIXME: FindWindow does not search children, but FindWindowEx does.
847 // what should we do about this?
848 return FindWindowExA (NULL
, NULL
, lpClassName
, lpWindowName
);
856 FindWindowW(LPCWSTR lpClassName
, LPCWSTR lpWindowName
)
860 There was a FIXME here earlier, but I think it is just a documentation unclarity.
862 FindWindow only searches top level windows. What they mean is that child
863 windows of other windows than the desktop can be searched.
864 FindWindowExW never does a recursive search.
869 return FindWindowExW(NULL
, NULL
, lpClassName
, lpWindowName
);
878 GetAltTabInfoA(HWND hwnd
,
884 return NtUserGetAltTabInfo(hwnd
,iItem
,pati
,(LPWSTR
)pszItemText
,cchItemText
,TRUE
);
892 GetAltTabInfoW(HWND hwnd
,
898 return NtUserGetAltTabInfo(hwnd
,iItem
,pati
,pszItemText
,cchItemText
,FALSE
);
906 GetAncestor(HWND hwnd
, UINT gaFlags
)
911 Wnd
= ValidateHwnd(hwnd
);
921 if (Wnd
->spwndParent
!= NULL
)
922 Ancestor
= DesktopPtrToUser(Wnd
->spwndParent
);
926 /* FIXME: Call win32k for now */
931 if (Ancestor
!= NULL
)
932 Ret
= UserHMGetHandle(Ancestor
);
934 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
940 if (!Wnd
) /* Fall back */
941 Ret
= NtUserGetAncestor(hwnd
, gaFlags
);
951 GetClientRect(HWND hWnd
, LPRECT lpRect
)
953 PWND Wnd
= ValidateHwnd(hWnd
);
955 if (!Wnd
) return FALSE
;
956 if (Wnd
->style
& WS_MINIMIZED
)
958 lpRect
->left
= lpRect
->top
= 0;
959 lpRect
->right
= GetSystemMetrics(SM_CXMINIMIZED
);
960 lpRect
->bottom
= GetSystemMetrics(SM_CYMINIMIZED
);
963 if ( hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
965 /* lpRect->left = lpRect->top = 0;
966 lpRect->right = Wnd->rcClient.right - Wnd->rcClient.left;
967 lpRect->bottom = Wnd->rcClient.bottom - Wnd->rcClient.top;
969 *lpRect
= Wnd
->rcClient
;
970 OffsetRect(lpRect
, -Wnd
->rcClient
.left
, -Wnd
->rcClient
.top
);
974 lpRect
->left
= lpRect
->top
= 0;
975 lpRect
->right
= Wnd
->rcClient
.right
;
976 lpRect
->bottom
= Wnd
->rcClient
.bottom
;
977 /* Do this until Init bug is fixed. This sets 640x480, see InitMetrics.
978 lpRect->right = GetSystemMetrics(SM_CXSCREEN);
979 lpRect->bottom = GetSystemMetrics(SM_CYSCREEN);
989 GetLastActivePopup(HWND hWnd
)
994 Wnd
= ValidateHwnd(hWnd
);
999 if (Wnd
->spwndLastActive
)
1001 PWND LastActive
= DesktopPtrToUser(Wnd
->spwndLastActive
);
1002 Ret
= UserHMGetHandle(LastActive
);
1005 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1019 GetParent(HWND hWnd
)
1021 PWND Wnd
, WndParent
;
1024 Wnd
= ValidateHwnd(hWnd
);
1030 if (Wnd
->style
& WS_POPUP
)
1032 if (Wnd
->spwndOwner
!= NULL
)
1033 WndParent
= DesktopPtrToUser(Wnd
->spwndOwner
);
1035 else if (Wnd
->style
& WS_CHILD
)
1037 if (Wnd
->spwndParent
!= NULL
)
1038 WndParent
= DesktopPtrToUser(Wnd
->spwndParent
);
1041 if (WndParent
!= NULL
)
1042 Ret
= UserHMGetHandle(WndParent
);
1044 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1059 GetProcessDefaultLayout(DWORD
*pdwDefaultLayout
)
1061 return (BOOL
)NtUserCallOneParam( (DWORD_PTR
)pdwDefaultLayout
, ONEPARAM_ROUTINE_GETPROCDEFLAYOUT
);
1069 GetWindow(HWND hWnd
,
1075 Wnd
= ValidateHwnd(hWnd
);
1085 if (Wnd
->spwndOwner
!= NULL
)
1086 FoundWnd
= DesktopPtrToUser(Wnd
->spwndOwner
);
1090 if(Wnd
->spwndParent
!= NULL
)
1092 FoundWnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1093 if (FoundWnd
->spwndChild
!= NULL
)
1094 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndChild
);
1098 if (Wnd
->spwndNext
!= NULL
)
1099 FoundWnd
= DesktopPtrToUser(Wnd
->spwndNext
);
1103 if (Wnd
->spwndPrev
!= NULL
)
1104 FoundWnd
= DesktopPtrToUser(Wnd
->spwndPrev
);
1108 if (Wnd
->spwndChild
!= NULL
)
1109 FoundWnd
= DesktopPtrToUser(Wnd
->spwndChild
);
1114 while ( FoundWnd
->spwndNext
!= NULL
)
1115 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndNext
);
1123 if (FoundWnd
!= NULL
)
1124 Ret
= UserHMGetHandle(FoundWnd
);
1126 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1140 GetTopWindow(HWND hWnd
)
1142 if (!hWnd
) hWnd
= GetDesktopWindow();
1143 return GetWindow(hWnd
, GW_CHILD
);
1153 GetWindowInfo(HWND hWnd
,
1161 if ( !pwi
|| pwi
->cbSize
!= sizeof(WINDOWINFO
))
1162 SetLastError(ERROR_INVALID_PARAMETER
); // Just set the error and go!
1164 pWnd
= ValidateHwnd(hWnd
);
1168 UserGetWindowBorders(pWnd
->style
, pWnd
->ExStyle
, &Size
, FALSE
);
1172 pCls
= DesktopPtrToUser(pWnd
->pcls
);
1173 pwi
->rcWindow
= pWnd
->rcWindow
;
1174 pwi
->rcClient
= pWnd
->rcClient
;
1175 pwi
->dwStyle
= pWnd
->style
;
1176 pwi
->dwExStyle
= pWnd
->ExStyle
;
1177 pwi
->cxWindowBorders
= Size
.cx
;
1178 pwi
->cyWindowBorders
= Size
.cy
;
1179 pwi
->dwWindowStatus
= 0;
1180 if (pWnd
->state
& WNDS_ACTIVEFRAME
|| (GetActiveWindow() == hWnd
))
1181 pwi
->dwWindowStatus
= WS_ACTIVECAPTION
;
1182 pwi
->atomWindowType
= (pCls
? pCls
->atomClassName
: 0 );
1184 if ( pWnd
->state2
& WNDS2_WIN50COMPAT
)
1186 pwi
->wCreatorVersion
= 0x500;
1188 else if ( pWnd
->state2
& WNDS2_WIN40COMPAT
)
1190 pwi
->wCreatorVersion
= 0x400;
1192 else if ( pWnd
->state2
& WNDS2_WIN31COMPAT
)
1194 pwi
->wCreatorVersion
= 0x30A;
1198 pwi
->wCreatorVersion
= 0x300;
1203 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1217 GetWindowModuleFileNameA(HWND hwnd
,
1219 UINT cchFileNameMax
)
1221 PWND Wnd
= ValidateHwnd(hwnd
);
1226 return GetModuleFileNameA(Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1234 GetWindowModuleFileNameW(HWND hwnd
,
1235 LPWSTR lpszFileName
,
1236 UINT cchFileNameMax
)
1238 PWND Wnd
= ValidateHwnd(hwnd
);
1243 return GetModuleFileNameW( Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1250 GetWindowRect(HWND hWnd
,
1253 PWND Wnd
= ValidateHwnd(hWnd
);
1255 if (!Wnd
) return FALSE
;
1256 if ( hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
1258 *lpRect
= Wnd
->rcWindow
;
1262 lpRect
->left
= lpRect
->top
= 0;
1263 lpRect
->right
= Wnd
->rcWindow
.right
;
1264 lpRect
->bottom
= Wnd
->rcWindow
.bottom
;
1265 /* Do this until Init bug is fixed. This sets 640x480, see InitMetrics.
1266 lpRect->right = GetSystemMetrics(SM_CXSCREEN);
1267 lpRect->bottom = GetSystemMetrics(SM_CYSCREEN);
1276 GetWindowTextA(HWND hWnd
, LPSTR lpString
, int nMaxCount
)
1281 if (lpString
== NULL
|| nMaxCount
== 0)
1284 Wnd
= ValidateHwnd(hWnd
);
1290 if (!TestWindowProcess( Wnd
))
1294 Length
= DefWindowProcA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1296 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1303 Length
= SendMessageA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1304 //ERR("GWTA Len %d : %s\n",Length,lpString);
1312 GetWindowTextLengthA(HWND hWnd
)
1314 return(SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0));
1321 GetWindowTextLengthW(HWND hWnd
)
1323 return(SendMessageW(hWnd
, WM_GETTEXTLENGTH
, 0, 0));
1330 GetWindowTextW(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1335 if (lpString
== NULL
|| nMaxCount
== 0)
1338 Wnd
= ValidateHwnd(hWnd
);
1342 lpString
[0] = L
'\0';
1344 if (!TestWindowProcess( Wnd
))
1348 Length
= DefWindowProcW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1350 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1357 Length
= SendMessageW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1358 //ERR("GWTW Len %d : %S\n",Length,lpString);
1363 GetWindowThreadProcessId(HWND hWnd
,
1364 LPDWORD lpdwProcessId
)
1368 PWND pWnd
= ValidateHwnd(hWnd
);
1370 if (!pWnd
) return Ret
;
1372 ti
= pWnd
->head
.pti
;
1376 if (ti
== GetW32ThreadInfo())
1377 { // We are current.
1378 //FIXME("Current!\n");
1380 *lpdwProcessId
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueProcess
;
1381 Ret
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueThread
;
1384 { // Ask kernel for info.
1385 //FIXME("Kernel call!\n");
1387 *lpdwProcessId
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
);
1388 Ret
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_THREAD_ID
);
1399 IsChild(HWND hWndParent
,
1402 PWND WndParent
, DesktopWnd
, Wnd
;
1405 WndParent
= ValidateHwnd(hWndParent
);
1408 Wnd
= ValidateHwnd(hWnd
);
1412 DesktopWnd
= GetThreadDesktopWnd();
1418 while (Wnd
!= NULL
&& ((Wnd
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
1420 if (Wnd
->spwndParent
!= NULL
)
1422 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1424 if (Wnd
== WndParent
)
1434 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1450 PWND Wnd
= ValidateHwnd(hWnd
);
1453 return (Wnd
->style
& WS_MINIMIZE
) != 0;
1465 PWND Wnd
= ValidateHwndNoErr(hWnd
);
1468 if (Wnd
->state
& WNDS_DESTROYED
||
1469 Wnd
->state2
& WNDS2_INDESTROY
)
1482 IsWindowUnicode(HWND hWnd
)
1484 PWND Wnd
= ValidateHwnd(hWnd
);
1487 return Wnd
->Unicode
;
1497 IsWindowVisible(HWND hWnd
)
1500 PWND Wnd
= ValidateHwnd(hWnd
);
1510 if (!(Wnd
->style
& WS_VISIBLE
))
1516 if (Wnd
->spwndParent
!= NULL
)
1517 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1521 } while (Wnd
!= NULL
);
1523 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1538 IsWindowEnabled(HWND hWnd
)
1540 // AG: I don't know if child windows are affected if the parent is
1541 // disabled. I think they stop processing messages but stay appearing
1544 return !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_DISABLED
);
1554 return (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
1562 LockSetForegroundWindow(UINT uLockCode
)
1564 return NtUserxLockSetForegroundWindow(uLockCode
);
1572 AnimateWindow(HWND hwnd
,
1576 /* FIXME Add animation code */
1578 /* If trying to show/hide and it's already *
1579 * shown/hidden or invalid window, fail with *
1580 * invalid parameter */
1583 visible
= IsWindowVisible(hwnd
);
1584 if(!IsWindow(hwnd
) ||
1585 (visible
&& !(dwFlags
& AW_HIDE
)) ||
1586 (!visible
&& (dwFlags
& AW_HIDE
)))
1588 SetLastError(ERROR_INVALID_PARAMETER
);
1592 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1604 if (!(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1607 ShowWindow(hWnd
,SW_RESTORE
);
1616 RealChildWindowFromPoint(HWND hwndParent
,
1617 POINT ptParentClientCoords
)
1619 return NtUserRealChildWindowFromPoint(hwndParent
, ptParentClientCoords
.x
, ptParentClientCoords
.y
);
1626 SetForegroundWindow(HWND hWnd
)
1628 return NtUserxSetForegroundWindow(hWnd
);
1636 SetProcessDefaultLayout(DWORD dwDefaultLayout
)
1638 return NtUserCallOneParam( (DWORD_PTR
)dwDefaultLayout
, ONEPARAM_ROUTINE_SETPROCDEFLAYOUT
);
1648 SetWindowTextA(HWND hWnd
,
1653 pwnd
= ValidateHwnd(hWnd
);
1656 if (!TestWindowProcess(pwnd
))
1658 /* do not send WM_GETTEXT messages to other processes */
1659 return (DefWindowProcA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1661 return (SendMessageA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1673 SetWindowTextW(HWND hWnd
,
1678 pwnd
= ValidateHwnd(hWnd
);
1681 if (!TestWindowProcess(pwnd
))
1683 /* do not send WM_GETTEXT messages to other processes */
1684 return (DefWindowProcW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1686 return (SendMessageW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1696 ShowOwnedPopups(HWND hWnd
, BOOL fShow
)
1698 return NtUserxShowOwnedPopups(hWnd
, fShow
);
1706 UpdateLayeredWindow( HWND hwnd
,
1716 if (dwFlags
& ULW_EX_NORESIZE
) /* only valid for UpdateLayeredWindowIndirect */
1718 SetLastError( ERROR_INVALID_PARAMETER
);
1721 return NtUserUpdateLayeredWindow( hwnd
,
1737 UpdateLayeredWindowIndirect(HWND hwnd
,
1738 const UPDATELAYEREDWINDOWINFO
*info
)
1740 if (info
&& info
->cbSize
== sizeof(*info
))
1742 return NtUserUpdateLayeredWindow( hwnd
,
1744 (POINT
*)info
->pptDst
,
1745 (SIZE
*)info
->psize
,
1747 (POINT
*)info
->pptSrc
,
1749 (BLENDFUNCTION
*)info
->pblend
,
1751 (RECT
*)info
->prcDirty
);
1753 SetLastError(ERROR_INVALID_PARAMETER
);
1761 SetWindowContextHelpId(HWND hwnd
,
1762 DWORD dwContextHelpId
)
1764 return NtUserxSetWindowContextHelpId(hwnd
, dwContextHelpId
);
1771 GetWindowContextHelpId(HWND hwnd
)
1773 return NtUserxGetWindowContextHelpId(hwnd
);
1780 InternalGetWindowText(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1782 INT Ret
= NtUserInternalGetWindowText(hWnd
, lpString
, nMaxCount
);
1792 IsHungAppWindow(HWND hwnd
)
1794 return (NtUserQueryWindow(hwnd
, QUERY_WINDOW_ISHUNG
) != 0);
1801 SetLastErrorEx(DWORD dwErrCode
, DWORD dwType
)
1803 SetLastError(dwErrCode
);
1812 return (HWND
)NtUserGetThreadState(THREADSTATE_FOCUSWINDOW
);
1816 GetRealWindowOwner(HWND hwnd
)
1818 return NtUserQueryWindow(hwnd
, QUERY_WINDOW_REAL_ID
);
1825 SetTaskmanWindow(HWND hWnd
)
1827 return NtUserxSetTaskmanWindow(hWnd
);
1834 SetProgmanWindow(HWND hWnd
)
1836 return NtUserxSetProgmanWindow(hWnd
);
1843 GetProgmanWindow(VOID
)
1845 return (HWND
)NtUserGetThreadState(THREADSTATE_PROGMANWINDOW
);
1852 GetTaskmanWindow(VOID
)
1854 return (HWND
)NtUserGetThreadState(THREADSTATE_TASKMANWINDOW
);
1861 ScrollWindow(HWND hWnd
,
1865 CONST RECT
*prcClip
)
1867 return NtUserScrollWindowEx(hWnd
,
1874 (lpRect
? 0 : SW_SCROLLCHILDREN
) | (SW_ERASE
|SW_INVALIDATE
|SW_SCROLLWNDDCE
)) != ERROR
;
1877 /* ScrollWindow uses the window DC, ScrollWindowEx doesn't */
1883 ScrollWindowEx(HWND hWnd
,
1886 CONST RECT
*prcScroll
,
1887 CONST RECT
*prcClip
,
1892 if (flags
& SW_SMOOTHSCROLL
)
1894 FIXME("SW_SMOOTHSCROLL not supported.");
1897 return NtUserScrollWindowEx(hWnd
,
1915 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1917 if (!list
) return FALSE
;
1918 for (i
= 0; list
[i
]; i
++)
1920 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
1922 retvalue
= (list
[i
] != 0);
1923 HeapFree( GetProcessHeap(), 0, list
);
1931 IsWindowInDestroy(HWND hWnd
)
1934 pwnd
= ValidateHwnd(hWnd
);
1937 return ((pwnd
->state2
& WNDS2_INDESTROY
) == WNDS2_INDESTROY
);
1944 DisableProcessWindowsGhosting(VOID
)
1946 NtUserxEnableProcessWindowGhosting(FALSE
);