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
);
326 CreateWindowExA(DWORD dwExStyle
,
339 MDICREATESTRUCTA mdi
;
342 if (!RegisterDefaultClasses
)
344 ERR("CreateWindowExA RegisterSystemControls\n");
345 RegisterSystemControls();
348 if (dwExStyle
& WS_EX_MDICHILD
)
355 pWndParent
= ValidateHwnd(hWndParent
);
357 if (!pWndParent
) return NULL
;
359 if (pWndParent
->fnid
!= FNID_MDICLIENT
) // wine uses WIN_ISMDICLIENT
361 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
365 /* lpParams of WM_[NC]CREATE is different for MDI children.
366 * MDICREATESTRUCT members have the originally passed values.
368 mdi
.szClass
= lpClassName
;
369 mdi
.szTitle
= lpWindowName
;
370 mdi
.hOwner
= hInstance
;
376 mdi
.lParam
= (LPARAM
)lpParam
;
378 lpParam
= (LPVOID
)&mdi
;
380 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
382 if (dwStyle
& WS_POPUP
)
384 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
387 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
391 dwStyle
&= ~WS_POPUP
;
392 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
393 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
396 top_child
= GetWindow(hWndParent
, GW_CHILD
);
400 /* Restore current maximized child */
401 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
403 TRACE("Restoring current maximized child %p\n", top_child
);
404 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
405 ShowWindow(top_child
, SW_RESTORE
);
406 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
410 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
412 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
414 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
416 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
421 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
423 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
428 hwnd
= User32CreateWindowEx(dwExStyle
,
449 CreateWindowExW(DWORD dwExStyle
,
451 LPCWSTR lpWindowName
,
462 MDICREATESTRUCTW mdi
;
465 if (!RegisterDefaultClasses
)
467 ERR("CreateWindowExW RegisterSystemControls\n");
468 RegisterSystemControls();
471 if (dwExStyle
& WS_EX_MDICHILD
)
478 pWndParent
= ValidateHwnd(hWndParent
);
480 if (!pWndParent
) return NULL
;
482 if (pWndParent
->fnid
!= FNID_MDICLIENT
)
484 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
488 /* lpParams of WM_[NC]CREATE is different for MDI children.
489 * MDICREATESTRUCT members have the originally passed values.
491 mdi
.szClass
= lpClassName
;
492 mdi
.szTitle
= lpWindowName
;
493 mdi
.hOwner
= hInstance
;
499 mdi
.lParam
= (LPARAM
)lpParam
;
501 lpParam
= (LPVOID
)&mdi
;
503 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
505 if (dwStyle
& WS_POPUP
)
507 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
510 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
514 dwStyle
&= ~WS_POPUP
;
515 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
516 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
519 top_child
= GetWindow(hWndParent
, GW_CHILD
);
523 /* Restore current maximized child */
524 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
526 TRACE("Restoring current maximized child %p\n", top_child
);
527 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
528 ShowWindow(top_child
, SW_RESTORE
);
529 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
533 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
535 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
537 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
539 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
544 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
546 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
551 hwnd
= User32CreateWindowEx(dwExStyle
,
552 (LPCSTR
) lpClassName
,
553 (LPCSTR
) lpWindowName
,
571 DeferWindowPos(HDWP hWinPosInfo
,
573 HWND hWndInsertAfter
,
580 return NtUserDeferWindowPos(hWinPosInfo
, hWnd
, hWndInsertAfter
, x
, y
, cx
, cy
, uFlags
);
588 EndDeferWindowPos(HDWP hWinPosInfo
)
590 return NtUserEndDeferWindowPosEx(hWinPosInfo
, 0);
598 GetDesktopWindow(VOID
)
605 Wnd
= GetThreadDesktopWnd();
607 Ret
= UserHMGetHandle(Wnd
);
609 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
620 User32EnumWindows(HDESK hDesktop
,
627 DWORD i
, dwCount
= 0;
634 SetLastError ( ERROR_INVALID_PARAMETER
);
638 /* FIXME instead of always making two calls, should we use some
639 sort of persistent buffer and only grow it ( requiring a 2nd
640 call ) when the buffer wasn't already big enough? */
641 /* first get how many window entries there are */
642 Status
= NtUserBuildHwndList(hDesktop
,
649 if (!NT_SUCCESS(Status
))
652 /* allocate buffer to receive HWND handles */
653 hHeap
= GetProcessHeap();
654 pHwnd
= HeapAlloc(hHeap
, 0, sizeof(HWND
)*(dwCount
+1));
657 SetLastError ( ERROR_NOT_ENOUGH_MEMORY
);
661 /* now call kernel again to fill the buffer this time */
662 Status
= NtUserBuildHwndList(hDesktop
,
669 if (!NT_SUCCESS(Status
))
672 HeapFree(hHeap
, 0, pHwnd
);
684 /* call the user's callback function until we're done or
685 they tell us to quit */
686 for ( i
= 0; i
< dwCount
; i
++ )
688 /* FIXME I'm only getting NULLs from Thread Enumeration, and it's
689 * probably because I'm not doing it right in NtUserBuildHwndList.
690 * Once that's fixed, we shouldn't have to check for a NULL HWND
692 * This is now fixed in revision 50205. (jt)
694 if (!pHwnd
[i
]) /* don't enumerate a NULL HWND */
696 if (!(*lpfn
)(pHwnd
[i
], lParam
))
698 HeapFree ( hHeap
, 0, pHwnd
);
703 HeapFree(hHeap
, 0, pHwnd
);
712 EnumChildWindows(HWND hWndParent
,
713 WNDENUMPROC lpEnumFunc
,
718 return EnumWindows(lpEnumFunc
, lParam
);
720 return User32EnumWindows(NULL
, hWndParent
, lpEnumFunc
, lParam
, 0, TRUE
);
728 EnumThreadWindows(DWORD dwThreadId
,
733 dwThreadId
= GetCurrentThreadId();
734 return User32EnumWindows(NULL
, NULL
, lpfn
, lParam
, dwThreadId
, FALSE
);
742 EnumWindows(WNDENUMPROC lpEnumFunc
,
745 return User32EnumWindows(NULL
, NULL
, lpEnumFunc
, lParam
, 0, FALSE
);
753 EnumDesktopWindows(HDESK hDesktop
,
757 return User32EnumWindows(hDesktop
, NULL
, lpfn
, lParam
, 0, FALSE
);
765 FindWindowExA(HWND hwndParent
,
770 LPWSTR titleW
= NULL
;
775 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, lpszWindow
, -1, NULL
, 0 );
776 if (!(titleW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
777 MultiByteToWideChar( CP_ACP
, 0, lpszWindow
, -1, titleW
, len
);
780 if (!IS_INTRESOURCE(lpszClass
))
783 if (MultiByteToWideChar( CP_ACP
, 0, lpszClass
, -1, classW
, sizeof(classW
)/sizeof(WCHAR
) ))
784 hwnd
= FindWindowExW( hwndParent
, hwndChildAfter
, classW
, titleW
);
788 hwnd
= FindWindowExW( hwndParent
, hwndChildAfter
, (LPCWSTR
)lpszClass
, titleW
);
791 HeapFree( GetProcessHeap(), 0, titleW
);
800 FindWindowExW(HWND hwndParent
,
805 UNICODE_STRING ucClassName
, *pucClassName
= NULL
;
806 UNICODE_STRING ucWindowName
, *pucWindowName
= NULL
;
808 if (IS_ATOM(lpszClass
))
810 ucClassName
.Length
= 0;
811 ucClassName
.Buffer
= (LPWSTR
)lpszClass
;
812 pucClassName
= &ucClassName
;
814 else if (lpszClass
!= NULL
)
816 RtlInitUnicodeString(&ucClassName
,
818 pucClassName
= &ucClassName
;
821 if (lpszWindow
!= NULL
)
823 RtlInitUnicodeString(&ucWindowName
,
825 pucWindowName
= &ucWindowName
;
828 return NtUserFindWindowEx(hwndParent
,
840 FindWindowA(LPCSTR lpClassName
, LPCSTR lpWindowName
)
842 //FIXME: FindWindow does not search children, but FindWindowEx does.
843 // what should we do about this?
844 return FindWindowExA (NULL
, NULL
, lpClassName
, lpWindowName
);
852 FindWindowW(LPCWSTR lpClassName
, LPCWSTR lpWindowName
)
856 There was a FIXME here earlier, but I think it is just a documentation unclarity.
858 FindWindow only searches top level windows. What they mean is that child
859 windows of other windows than the desktop can be searched.
860 FindWindowExW never does a recursive search.
865 return FindWindowExW(NULL
, NULL
, lpClassName
, lpWindowName
);
874 GetAltTabInfoA(HWND hwnd
,
880 return NtUserGetAltTabInfo(hwnd
,iItem
,pati
,(LPWSTR
)pszItemText
,cchItemText
,TRUE
);
888 GetAltTabInfoW(HWND hwnd
,
894 return NtUserGetAltTabInfo(hwnd
,iItem
,pati
,pszItemText
,cchItemText
,FALSE
);
902 GetAncestor(HWND hwnd
, UINT gaFlags
)
907 Wnd
= ValidateHwnd(hwnd
);
917 if (Wnd
->spwndParent
!= NULL
)
918 Ancestor
= DesktopPtrToUser(Wnd
->spwndParent
);
922 /* FIXME: Call win32k for now */
927 if (Ancestor
!= NULL
)
928 Ret
= UserHMGetHandle(Ancestor
);
930 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
936 if (!Wnd
) /* Fall back */
937 Ret
= NtUserGetAncestor(hwnd
, gaFlags
);
947 GetClientRect(HWND hWnd
, LPRECT lpRect
)
949 PWND Wnd
= ValidateHwnd(hWnd
);
951 if (!Wnd
) return FALSE
;
952 if (Wnd
->style
& WS_MINIMIZED
)
954 lpRect
->left
= lpRect
->top
= 0;
955 lpRect
->right
= GetSystemMetrics(SM_CXMINIMIZED
);
956 lpRect
->bottom
= GetSystemMetrics(SM_CYMINIMIZED
);
959 if ( hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
961 /* lpRect->left = lpRect->top = 0;
962 lpRect->right = Wnd->rcClient.right - Wnd->rcClient.left;
963 lpRect->bottom = Wnd->rcClient.bottom - Wnd->rcClient.top;
965 *lpRect
= Wnd
->rcClient
;
966 OffsetRect(lpRect
, -Wnd
->rcClient
.left
, -Wnd
->rcClient
.top
);
970 lpRect
->left
= lpRect
->top
= 0;
971 lpRect
->right
= Wnd
->rcClient
.right
;
972 lpRect
->bottom
= Wnd
->rcClient
.bottom
;
973 /* Do this until Init bug is fixed. This sets 640x480, see InitMetrics.
974 lpRect->right = GetSystemMetrics(SM_CXSCREEN);
975 lpRect->bottom = GetSystemMetrics(SM_CYSCREEN);
985 GetLastActivePopup(HWND hWnd
)
990 Wnd
= ValidateHwnd(hWnd
);
995 if (Wnd
->spwndLastActive
)
997 PWND LastActive
= DesktopPtrToUser(Wnd
->spwndLastActive
);
998 Ret
= UserHMGetHandle(LastActive
);
1001 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1015 GetParent(HWND hWnd
)
1017 PWND Wnd
, WndParent
;
1020 Wnd
= ValidateHwnd(hWnd
);
1026 if (Wnd
->style
& WS_POPUP
)
1028 if (Wnd
->spwndOwner
!= NULL
)
1029 WndParent
= DesktopPtrToUser(Wnd
->spwndOwner
);
1031 else if (Wnd
->style
& WS_CHILD
)
1033 if (Wnd
->spwndParent
!= NULL
)
1034 WndParent
= DesktopPtrToUser(Wnd
->spwndParent
);
1037 if (WndParent
!= NULL
)
1038 Ret
= UserHMGetHandle(WndParent
);
1040 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1055 GetProcessDefaultLayout(DWORD
*pdwDefaultLayout
)
1057 return (BOOL
)NtUserCallOneParam( (DWORD_PTR
)pdwDefaultLayout
, ONEPARAM_ROUTINE_GETPROCDEFLAYOUT
);
1065 GetWindow(HWND hWnd
,
1071 Wnd
= ValidateHwnd(hWnd
);
1081 if (Wnd
->spwndOwner
!= NULL
)
1082 FoundWnd
= DesktopPtrToUser(Wnd
->spwndOwner
);
1086 if(Wnd
->spwndParent
!= NULL
)
1088 FoundWnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1089 if (FoundWnd
->spwndChild
!= NULL
)
1090 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndChild
);
1094 if (Wnd
->spwndNext
!= NULL
)
1095 FoundWnd
= DesktopPtrToUser(Wnd
->spwndNext
);
1099 if (Wnd
->spwndPrev
!= NULL
)
1100 FoundWnd
= DesktopPtrToUser(Wnd
->spwndPrev
);
1104 if (Wnd
->spwndChild
!= NULL
)
1105 FoundWnd
= DesktopPtrToUser(Wnd
->spwndChild
);
1110 while ( FoundWnd
->spwndNext
!= NULL
)
1111 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndNext
);
1119 if (FoundWnd
!= NULL
)
1120 Ret
= UserHMGetHandle(FoundWnd
);
1122 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1136 GetTopWindow(HWND hWnd
)
1138 if (!hWnd
) hWnd
= GetDesktopWindow();
1139 return GetWindow(hWnd
, GW_CHILD
);
1147 GetWindowInfo(HWND hWnd
,
1155 if ( !pwi
|| pwi
->cbSize
!= sizeof(WINDOWINFO
))
1156 SetLastError(ERROR_INVALID_PARAMETER
); // Just set the error and go!
1158 pWnd
= ValidateHwnd(hWnd
);
1162 UserGetWindowBorders(pWnd
->style
, pWnd
->ExStyle
, &Size
, FALSE
);
1166 pCls
= DesktopPtrToUser(pWnd
->pcls
);
1167 pwi
->rcWindow
= pWnd
->rcWindow
;
1168 pwi
->rcClient
= pWnd
->rcClient
;
1169 pwi
->dwStyle
= pWnd
->style
;
1170 pwi
->dwExStyle
= pWnd
->ExStyle
;
1171 pwi
->cxWindowBorders
= Size
.cx
;
1172 pwi
->cyWindowBorders
= Size
.cy
;
1173 pwi
->dwWindowStatus
= 0;
1174 if (pWnd
->state
& WNDS_ACTIVEFRAME
|| (GetActiveWindow() == hWnd
))
1175 pwi
->dwWindowStatus
= WS_ACTIVECAPTION
;
1176 pwi
->atomWindowType
= (pCls
? pCls
->atomClassName
: 0 );
1178 if ( pWnd
->state2
& WNDS2_WIN50COMPAT
)
1180 pwi
->wCreatorVersion
= 0x500;
1182 else if ( pWnd
->state2
& WNDS2_WIN40COMPAT
)
1184 pwi
->wCreatorVersion
= 0x400;
1186 else if ( pWnd
->state2
& WNDS2_WIN31COMPAT
)
1188 pwi
->wCreatorVersion
= 0x30A;
1192 pwi
->wCreatorVersion
= 0x300;
1197 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1211 GetWindowModuleFileNameA(HWND hwnd
,
1213 UINT cchFileNameMax
)
1215 PWND Wnd
= ValidateHwnd(hwnd
);
1220 return GetModuleFileNameA(Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1228 GetWindowModuleFileNameW(HWND hwnd
,
1229 LPWSTR lpszFileName
,
1230 UINT cchFileNameMax
)
1232 PWND Wnd
= ValidateHwnd(hwnd
);
1237 return GetModuleFileNameW( Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1244 GetWindowRect(HWND hWnd
,
1247 PWND Wnd
= ValidateHwnd(hWnd
);
1249 if (!Wnd
) return FALSE
;
1250 if ( hWnd
!= GetDesktopWindow()) // Wnd->fnid != FNID_DESKTOP )
1252 *lpRect
= Wnd
->rcWindow
;
1256 lpRect
->left
= lpRect
->top
= 0;
1257 lpRect
->right
= Wnd
->rcWindow
.right
;
1258 lpRect
->bottom
= Wnd
->rcWindow
.bottom
;
1259 /* Do this until Init bug is fixed. This sets 640x480, see InitMetrics.
1260 lpRect->right = GetSystemMetrics(SM_CXSCREEN);
1261 lpRect->bottom = GetSystemMetrics(SM_CYSCREEN);
1270 GetWindowTextA(HWND hWnd
, LPSTR lpString
, int nMaxCount
)
1275 if (lpString
== NULL
|| nMaxCount
== 0)
1278 Wnd
= ValidateHwnd(hWnd
);
1284 if (!TestWindowProcess( Wnd
))
1288 Length
= DefWindowProcA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1290 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1297 Length
= SendMessageA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1298 //ERR("GWTA Len %d : %s\n",Length,lpString);
1306 GetWindowTextLengthA(HWND hWnd
)
1308 return(SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0));
1315 GetWindowTextLengthW(HWND hWnd
)
1317 return(SendMessageW(hWnd
, WM_GETTEXTLENGTH
, 0, 0));
1324 GetWindowTextW(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1329 if (lpString
== NULL
|| nMaxCount
== 0)
1332 Wnd
= ValidateHwnd(hWnd
);
1336 lpString
[0] = L
'\0';
1338 if (!TestWindowProcess( Wnd
))
1342 Length
= DefWindowProcW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1344 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1351 Length
= SendMessageW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1352 //ERR("GWTW Len %d : %S\n",Length,lpString);
1357 GetWindowThreadProcessId(HWND hWnd
,
1358 LPDWORD lpdwProcessId
)
1362 PWND pWnd
= ValidateHwnd(hWnd
);
1364 if (!pWnd
) return Ret
;
1366 ti
= pWnd
->head
.pti
;
1370 if (ti
== GetW32ThreadInfo())
1371 { // We are current.
1372 //FIXME("Current!\n");
1374 *lpdwProcessId
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueProcess
;
1375 Ret
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueThread
;
1378 { // Ask kernel for info.
1379 //FIXME("Kernel call!\n");
1381 *lpdwProcessId
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
);
1382 Ret
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_THREAD_ID
);
1393 IsChild(HWND hWndParent
,
1396 PWND WndParent
, DesktopWnd
, Wnd
;
1399 WndParent
= ValidateHwnd(hWndParent
);
1402 Wnd
= ValidateHwnd(hWnd
);
1406 DesktopWnd
= GetThreadDesktopWnd();
1412 while (Wnd
!= NULL
&& ((Wnd
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
1414 if (Wnd
->spwndParent
!= NULL
)
1416 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1418 if (Wnd
== WndParent
)
1428 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1444 PWND Wnd
= ValidateHwnd(hWnd
);
1447 return (Wnd
->style
& WS_MINIMIZE
) != 0;
1459 PWND Wnd
= ValidateHwndNoErr(hWnd
);
1462 if (Wnd
->state
& WNDS_DESTROYED
||
1463 Wnd
->state2
& WNDS2_INDESTROY
)
1476 IsWindowUnicode(HWND hWnd
)
1478 PWND Wnd
= ValidateHwnd(hWnd
);
1481 return Wnd
->Unicode
;
1491 IsWindowVisible(HWND hWnd
)
1494 PWND Wnd
= ValidateHwnd(hWnd
);
1504 if (!(Wnd
->style
& WS_VISIBLE
))
1510 if (Wnd
->spwndParent
!= NULL
)
1511 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1515 } while (Wnd
!= NULL
);
1517 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1532 IsWindowEnabled(HWND hWnd
)
1534 // AG: I don't know if child windows are affected if the parent is
1535 // disabled. I think they stop processing messages but stay appearing
1538 return !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_DISABLED
);
1548 return (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
1556 LockSetForegroundWindow(UINT uLockCode
)
1558 return NtUserxLockSetForegroundWindow(uLockCode
);
1566 AnimateWindow(HWND hwnd
,
1570 /* FIXME Add animation code */
1572 /* If trying to show/hide and it's already *
1573 * shown/hidden or invalid window, fail with *
1574 * invalid parameter */
1577 visible
= IsWindowVisible(hwnd
);
1578 if(!IsWindow(hwnd
) ||
1579 (visible
&& !(dwFlags
& AW_HIDE
)) ||
1580 (!visible
&& (dwFlags
& AW_HIDE
)))
1582 SetLastError(ERROR_INVALID_PARAMETER
);
1586 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1598 if (!(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1601 ShowWindow(hWnd
,SW_RESTORE
);
1610 RealChildWindowFromPoint(HWND hwndParent
,
1611 POINT ptParentClientCoords
)
1613 return NtUserRealChildWindowFromPoint(hwndParent
, ptParentClientCoords
.x
, ptParentClientCoords
.y
);
1620 SetForegroundWindow(HWND hWnd
)
1622 return NtUserxSetForegroundWindow(hWnd
);
1630 SetProcessDefaultLayout(DWORD dwDefaultLayout
)
1632 return NtUserCallOneParam( (DWORD_PTR
)dwDefaultLayout
, ONEPARAM_ROUTINE_SETPROCDEFLAYOUT
);
1640 SetWindowTextA(HWND hWnd
,
1645 pwnd
= ValidateHwnd(hWnd
);
1648 if (!TestWindowProcess(pwnd
))
1650 /* do not send WM_GETTEXT messages to other processes */
1651 return (DefWindowProcA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1653 return (SendMessageA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1663 SetWindowTextW(HWND hWnd
,
1668 pwnd
= ValidateHwnd(hWnd
);
1671 if (!TestWindowProcess(pwnd
))
1673 /* do not send WM_GETTEXT messages to other processes */
1674 return (DefWindowProcW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1676 return (SendMessageW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
) >= 0);
1686 ShowOwnedPopups(HWND hWnd
, BOOL fShow
)
1688 return NtUserxShowOwnedPopups(hWnd
, fShow
);
1696 UpdateLayeredWindow( HWND hwnd
,
1706 if ( dwFlags
& ULW_EX_NORESIZE
)
1707 dwFlags
= ~(ULW_EX_NORESIZE
|ULW_OPAQUE
|ULW_ALPHA
|ULW_COLORKEY
);
1708 return NtUserUpdateLayeredWindow( hwnd
,
1724 UpdateLayeredWindowIndirect(HWND hwnd
,
1725 const UPDATELAYEREDWINDOWINFO
*info
)
1727 if (info
&& info
->cbSize
== sizeof(*info
))
1729 return NtUserUpdateLayeredWindow( hwnd
,
1731 (POINT
*)info
->pptDst
,
1732 (SIZE
*)info
->psize
,
1734 (POINT
*)info
->pptSrc
,
1736 (BLENDFUNCTION
*)info
->pblend
,
1738 (RECT
*)info
->prcDirty
);
1740 SetLastError(ERROR_INVALID_PARAMETER
);
1748 SetWindowContextHelpId(HWND hwnd
,
1749 DWORD dwContextHelpId
)
1751 return NtUserxSetWindowContextHelpId(hwnd
, dwContextHelpId
);
1758 GetWindowContextHelpId(HWND hwnd
)
1760 return NtUserxGetWindowContextHelpId(hwnd
);
1767 InternalGetWindowText(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1769 INT Ret
= NtUserInternalGetWindowText(hWnd
, lpString
, nMaxCount
);
1779 IsHungAppWindow(HWND hwnd
)
1781 return (NtUserQueryWindow(hwnd
, QUERY_WINDOW_ISHUNG
) != 0);
1788 SetLastErrorEx(DWORD dwErrCode
, DWORD dwType
)
1790 SetLastError(dwErrCode
);
1799 return (HWND
)NtUserGetThreadState(THREADSTATE_FOCUSWINDOW
);
1803 GetRealWindowOwner(HWND hwnd
)
1805 return NtUserQueryWindow(hwnd
, QUERY_WINDOW_REAL_ID
);
1812 SetTaskmanWindow(HWND hWnd
)
1814 return NtUserxSetTaskmanWindow(hWnd
);
1821 SetProgmanWindow(HWND hWnd
)
1823 return NtUserxSetProgmanWindow(hWnd
);
1830 GetProgmanWindow(VOID
)
1832 return (HWND
)NtUserGetThreadState(THREADSTATE_PROGMANWINDOW
);
1839 GetTaskmanWindow(VOID
)
1841 return (HWND
)NtUserGetThreadState(THREADSTATE_TASKMANWINDOW
);
1848 ScrollWindow(HWND hWnd
,
1852 CONST RECT
*prcClip
)
1854 return NtUserScrollWindowEx(hWnd
,
1861 (lpRect
? 0 : SW_SCROLLCHILDREN
) | (SW_ERASE
|SW_INVALIDATE
|SW_SCROLLWNDDCE
)) != ERROR
;
1864 /* ScrollWindow uses the window DC, ScrollWindowEx doesn't */
1870 ScrollWindowEx(HWND hWnd
,
1873 CONST RECT
*prcScroll
,
1874 CONST RECT
*prcClip
,
1879 if (flags
& SW_SMOOTHSCROLL
)
1881 FIXME("SW_SMOOTHSCROLL not supported.");
1884 return NtUserScrollWindowEx(hWnd
,
1902 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1904 if (!list
) return FALSE
;
1905 for (i
= 0; list
[i
]; i
++)
1907 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
1909 retvalue
= (list
[i
] != 0);
1910 HeapFree( GetProcessHeap(), 0, list
);
1918 IsWindowInDestroy(HWND hWnd
)
1921 pwnd
= ValidateHwnd(hWnd
);
1924 return ((pwnd
->state2
& WNDS2_INDESTROY
) == WNDS2_INDESTROY
);
1931 DisableProcessWindowsGhosting(VOID
)
1933 NtUserxEnableProcessWindowGhosting(FALSE
);