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 static BOOL show_message
= TRUE
;
66 BeginDeferWindowPos(int nNumWindows
)
70 SetLastError(ERROR_INVALID_PARAMETER
);
86 BringWindowToTop(HWND hWnd
)
88 return NtUserSetWindowPos(hWnd
,
94 SWP_NOSIZE
| SWP_NOMOVE
);
99 SwitchToThisWindow(HWND hwnd
, BOOL fUnknown
)
101 ShowWindow(hwnd
, SW_SHOW
);
109 ChildWindowFromPoint(HWND hWndParent
,
112 return (HWND
) NtUserChildWindowFromPointEx(hWndParent
, Point
.x
, Point
.y
, 0);
120 ChildWindowFromPointEx(HWND hwndParent
,
124 return (HWND
) NtUserChildWindowFromPointEx(hwndParent
, pt
.x
, pt
.y
, uFlags
);
132 CloseWindow(HWND hWnd
)
134 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
136 return HandleToUlong(hWnd
);
142 OUT PLARGE_STRING plstr
,
148 RtlInitLargeUnicodeString((PLARGE_UNICODE_STRING
)plstr
, (PWSTR
)psz
, 0);
152 RtlInitLargeAnsiString((PLARGE_ANSI_STRING
)plstr
, (PSTR
)psz
, 0);
159 IN PLARGE_STRING LargeString
)
161 if (LargeString
->Buffer
)
163 RtlFreeHeap(GetProcessHeap(), 0, LargeString
->Buffer
);
164 RtlZeroMemory(LargeString
, sizeof(LARGE_STRING
));
169 User32CreateWindowEx(DWORD dwExStyle
,
183 LARGE_STRING WindowName
;
184 LARGE_STRING lstrClassName
, *plstrClassName
;
185 UNICODE_STRING ClassName
;
191 DbgPrint("[window] User32CreateWindowEx style %d, exstyle %d, parent %d\n", dwStyle
, dwExStyle
, hWndParent
);
194 if (!RegisterDefaultClasses
)
196 ERR("User32CreateWindowEx RegisterSystemControls\n");
197 RegisterSystemControls();
200 if (IS_ATOM(lpClassName
))
202 plstrClassName
= (PVOID
)lpClassName
;
207 RtlInitUnicodeString(&ClassName
, (PCWSTR
)lpClassName
);
210 if (!RtlCreateUnicodeStringFromAsciiz(&ClassName
, (PCSZ
)lpClassName
))
212 SetLastError(ERROR_OUTOFMEMORY
);
217 /* Copy it to a LARGE_STRING */
218 lstrClassName
.Buffer
= ClassName
.Buffer
;
219 lstrClassName
.Length
= ClassName
.Length
;
220 lstrClassName
.MaximumLength
= ClassName
.MaximumLength
;
221 plstrClassName
= &lstrClassName
;
224 /* Initialize a LARGE_STRING */
225 RtlInitLargeString(&WindowName
, lpWindowName
, Unicode
);
227 // HACK: The current implementation expects the Window name to be UNICODE
231 PSTR AnsiBuffer
= WindowName
.Buffer
;
232 ULONG AnsiLength
= WindowName
.Length
;
234 WindowName
.Length
= 0;
235 WindowName
.MaximumLength
= AnsiLength
* sizeof(WCHAR
);
236 WindowName
.Buffer
= RtlAllocateHeap(RtlGetProcessHeap(),
238 WindowName
.MaximumLength
);
239 if (!WindowName
.Buffer
)
241 SetLastError(ERROR_OUTOFMEMORY
);
245 Status
= RtlMultiByteToUnicodeN(WindowName
.Buffer
,
246 WindowName
.MaximumLength
,
250 if (!NT_SUCCESS(Status
))
256 if(!hMenu
&& (dwStyle
& (WS_OVERLAPPEDWINDOW
| WS_POPUP
)))
260 wceW
.cbSize
= sizeof(WNDCLASSEXW
);
261 if(GetClassInfoExW(hInstance
, (LPCWSTR
)lpClassName
, &wceW
) && wceW
.lpszMenuName
)
263 hMenu
= LoadMenuW(hInstance
, wceW
.lpszMenuName
);
268 wceA
.cbSize
= sizeof(WNDCLASSEXA
);
269 if(GetClassInfoExA(hInstance
, lpClassName
, &wceA
) && wceA
.lpszMenuName
)
271 hMenu
= LoadMenuA(hInstance
, wceA
.lpszMenuName
);
276 if (!Unicode
) dwExStyle
|= WS_EX_SETANSICREATOR
;
278 Handle
= NtUserCreateWindowEx(dwExStyle
,
295 DbgPrint("[window] NtUserCreateWindowEx() == %d\n", Handle
);
300 if (!IS_ATOM(lpClassName
))
302 RtlFreeUnicodeString(&ClassName
);
305 RtlFreeLargeString(&WindowName
);
316 CreateWindowExA(DWORD dwExStyle
,
329 MDICREATESTRUCTA mdi
;
332 if (!RegisterDefaultClasses
)
334 ERR("CreateWindowExA RegisterSystemControls\n");
335 RegisterSystemControls();
338 if (dwExStyle
& WS_EX_MDICHILD
)
345 pWndParent
= ValidateHwnd(hWndParent
);
347 if (!pWndParent
) return NULL
;
349 if (pWndParent
->fnid
!= FNID_MDICLIENT
) // wine uses WIN_ISMDICLIENT
351 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
355 /* lpParams of WM_[NC]CREATE is different for MDI children.
356 * MDICREATESTRUCT members have the originally passed values.
358 mdi
.szClass
= lpClassName
;
359 mdi
.szTitle
= lpWindowName
;
360 mdi
.hOwner
= hInstance
;
366 mdi
.lParam
= (LPARAM
)lpParam
;
368 lpParam
= (LPVOID
)&mdi
;
370 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
372 if (dwStyle
& WS_POPUP
)
374 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
377 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
381 dwStyle
&= ~WS_POPUP
;
382 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
383 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
386 top_child
= GetWindow(hWndParent
, GW_CHILD
);
390 /* Restore current maximized child */
391 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
393 TRACE("Restoring current maximized child %p\n", top_child
);
394 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
395 ShowWindow(top_child
, SW_RESTORE
);
396 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
400 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
402 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
404 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
406 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
411 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
413 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
418 hwnd
= User32CreateWindowEx(dwExStyle
,
439 CreateWindowExW(DWORD dwExStyle
,
441 LPCWSTR lpWindowName
,
452 MDICREATESTRUCTW mdi
;
455 if (!RegisterDefaultClasses
)
457 ERR("CreateWindowExW RegisterSystemControls\n");
458 RegisterSystemControls();
461 if (dwExStyle
& WS_EX_MDICHILD
)
468 pWndParent
= ValidateHwnd(hWndParent
);
470 if (!pWndParent
) return NULL
;
472 if (pWndParent
->fnid
!= FNID_MDICLIENT
)
474 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
478 /* lpParams of WM_[NC]CREATE is different for MDI children.
479 * MDICREATESTRUCT members have the originally passed values.
481 mdi
.szClass
= lpClassName
;
482 mdi
.szTitle
= lpWindowName
;
483 mdi
.hOwner
= hInstance
;
489 mdi
.lParam
= (LPARAM
)lpParam
;
491 lpParam
= (LPVOID
)&mdi
;
493 if (pWndParent
->style
& MDIS_ALLCHILDSTYLES
)
495 if (dwStyle
& WS_POPUP
)
497 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
500 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
504 dwStyle
&= ~WS_POPUP
;
505 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
506 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
509 top_child
= GetWindow(hWndParent
, GW_CHILD
);
513 /* Restore current maximized child */
514 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
516 TRACE("Restoring current maximized child %p\n", top_child
);
517 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
518 ShowWindow(top_child
, SW_RESTORE
);
519 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
523 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
525 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
527 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
529 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
534 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
536 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
541 hwnd
= User32CreateWindowEx(dwExStyle
,
542 (LPCSTR
) lpClassName
,
543 (LPCSTR
) lpWindowName
,
561 DeferWindowPos(HDWP hWinPosInfo
,
563 HWND hWndInsertAfter
,
571 return NtUserDeferWindowPos(hWinPosInfo
, hWnd
, hWndInsertAfter
, x
, y
, cx
, cy
, uFlags
);
573 SetWindowPos(hWnd
, hWndInsertAfter
, x
, y
, cx
, cy
, uFlags
);
583 EndDeferWindowPos(HDWP hWinPosInfo
)
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 UNICODE_STRING ucClassName
, *pucClassName
= NULL
;
771 UNICODE_STRING ucWindowName
, *pucWindowName
= NULL
;
774 if (IS_ATOM(lpszClass
))
776 ucClassName
.Buffer
= (LPWSTR
)lpszClass
;
777 ucClassName
.Length
= 0;
778 pucClassName
= &ucClassName
;
780 else if (lpszClass
!= NULL
)
782 if (!RtlCreateUnicodeStringFromAsciiz(&ucClassName
,
785 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
788 pucClassName
= &ucClassName
;
791 if (lpszWindow
!= NULL
)
793 if (!RtlCreateUnicodeStringFromAsciiz(&ucWindowName
,
796 if (!IS_ATOM(lpszClass
) && lpszClass
!= NULL
)
797 RtlFreeUnicodeString(&ucWindowName
);
799 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
803 pucWindowName
= &ucWindowName
;
806 Result
= NtUserFindWindowEx(hwndParent
,
812 if (!IS_ATOM(lpszClass
) && lpszClass
!= NULL
)
813 RtlFreeUnicodeString(&ucClassName
);
814 if (lpszWindow
!= NULL
)
815 RtlFreeUnicodeString(&ucWindowName
);
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
,
914 GetAltTabInfoW(HWND hwnd
,
929 GetAncestor(HWND hwnd
, UINT gaFlags
)
934 Wnd
= ValidateHwnd(hwnd
);
944 if (Wnd
->spwndParent
!= NULL
)
945 Ancestor
= DesktopPtrToUser(Wnd
->spwndParent
);
949 /* FIXME: Call win32k for now */
954 if (Ancestor
!= NULL
)
955 Ret
= UserHMGetHandle(Ancestor
);
957 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
963 if (!Wnd
) /* Fall back */
964 Ret
= NtUserGetAncestor(hwnd
, gaFlags
);
974 GetClientRect(HWND hWnd
, LPRECT lpRect
)
976 PWND Wnd
= ValidateHwnd(hWnd
);
980 lpRect
->left
= lpRect
->top
= 0;
981 lpRect
->right
= Wnd
->rcClient
.right
- Wnd
->rcClient
.left
;
982 lpRect
->bottom
= Wnd
->rcClient
.bottom
- Wnd
->rcClient
.top
;
994 GetLastActivePopup(HWND hWnd
)
999 Wnd
= ValidateHwnd(hWnd
);
1004 if (Wnd
->hWndLastActive
)
1005 Ret
= Wnd
->hWndLastActive
;
1007 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1021 GetParent(HWND hWnd
)
1023 PWND Wnd
, WndParent
;
1026 Wnd
= ValidateHwnd(hWnd
);
1032 if (Wnd
->style
& WS_POPUP
)
1034 if (Wnd
->spwndOwner
!= NULL
)
1035 WndParent
= DesktopPtrToUser(Wnd
->spwndOwner
);
1037 else if (Wnd
->style
& WS_CHILD
)
1039 if (Wnd
->spwndParent
!= NULL
)
1040 WndParent
= DesktopPtrToUser(Wnd
->spwndParent
);
1043 if (WndParent
!= NULL
)
1044 Ret
= UserHMGetHandle(WndParent
);
1046 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1061 GetProcessDefaultLayout(DWORD
*pdwDefaultLayout
)
1063 if (!pdwDefaultLayout
)
1065 SetLastError(ERROR_INVALID_PARAMETER
);
1071 *pdwDefaultLayout
= 0;
1080 GetWindow(HWND hWnd
,
1086 Wnd
= ValidateHwnd(hWnd
);
1096 if (Wnd
->spwndOwner
!= NULL
)
1097 FoundWnd
= DesktopPtrToUser(Wnd
->spwndOwner
);
1101 if(Wnd
->spwndParent
!= NULL
)
1103 FoundWnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1104 if (FoundWnd
->spwndChild
!= NULL
)
1105 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndChild
);
1109 if (Wnd
->spwndNext
!= NULL
)
1110 FoundWnd
= DesktopPtrToUser(Wnd
->spwndNext
);
1114 if (Wnd
->spwndPrev
!= NULL
)
1115 FoundWnd
= DesktopPtrToUser(Wnd
->spwndPrev
);
1119 if (Wnd
->spwndChild
!= NULL
)
1120 FoundWnd
= DesktopPtrToUser(Wnd
->spwndChild
);
1125 while ( FoundWnd
->spwndNext
!= NULL
)
1126 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndNext
);
1134 if (FoundWnd
!= NULL
)
1135 Ret
= UserHMGetHandle(FoundWnd
);
1137 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1151 GetTopWindow(HWND hWnd
)
1153 if (!hWnd
) hWnd
= GetDesktopWindow();
1154 return GetWindow(hWnd
, GW_CHILD
);
1162 GetWindowInfo(HWND hWnd
,
1170 if ( !pwi
|| pwi
->cbSize
!= sizeof(WINDOWINFO
))
1171 SetLastError(ERROR_INVALID_PARAMETER
); // Just set the error and go!
1173 pWnd
= ValidateHwnd(hWnd
);
1177 UserGetWindowBorders(pWnd
->style
, pWnd
->ExStyle
, &Size
, FALSE
);
1181 pCls
= DesktopPtrToUser(pWnd
->pcls
);
1182 pwi
->rcWindow
= pWnd
->rcWindow
;
1183 pwi
->rcClient
= pWnd
->rcClient
;
1184 pwi
->dwStyle
= pWnd
->style
;
1185 pwi
->dwExStyle
= pWnd
->ExStyle
;
1186 pwi
->cxWindowBorders
= Size
.cx
;
1187 pwi
->cyWindowBorders
= Size
.cy
;
1188 pwi
->dwWindowStatus
= 0;
1189 if (pWnd
->state
& WNDS_ACTIVEFRAME
)
1190 pwi
->dwWindowStatus
= WS_ACTIVECAPTION
;
1191 pwi
->atomWindowType
= (pCls
? pCls
->atomClassName
: 0 );
1193 if ( pWnd
->state2
& WNDS2_WIN50COMPAT
)
1195 pwi
->wCreatorVersion
= 0x500;
1197 else if ( pWnd
->state2
& WNDS2_WIN40COMPAT
)
1199 pwi
->wCreatorVersion
= 0x400;
1201 else if ( pWnd
->state2
& WNDS2_WIN31COMPAT
)
1203 pwi
->wCreatorVersion
= 0x30A;
1207 pwi
->wCreatorVersion
= 0x300;
1212 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1226 GetWindowModuleFileNameA(HWND hwnd
,
1228 UINT cchFileNameMax
)
1230 PWND Wnd
= ValidateHwnd(hwnd
);
1235 return GetModuleFileNameA(Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1243 GetWindowModuleFileNameW(HWND hwnd
,
1244 LPWSTR lpszFileName
,
1245 UINT cchFileNameMax
)
1247 PWND Wnd
= ValidateHwnd(hwnd
);
1252 return GetModuleFileNameW( Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1260 GetWindowRect(HWND hWnd
,
1263 PWND Wnd
= ValidateHwnd(hWnd
);
1267 *lpRect
= Wnd
->rcWindow
;
1279 GetWindowTextA(HWND hWnd
, LPSTR lpString
, int nMaxCount
)
1285 if (lpString
== NULL
)
1288 Wnd
= ValidateHwnd(hWnd
);
1294 if (!TestWindowProcess( Wnd
))
1298 /* do not send WM_GETTEXT messages to other processes */
1299 Length
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
1302 Buffer
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1305 if (!WideCharToMultiByte(CP_ACP
,
1314 lpString
[nMaxCount
- 1] = '\0';
1327 Wnd
= NULL
; /* Don't send a message */
1330 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1334 Wnd
= NULL
; /* Don't send a message */
1339 Length
= SendMessageA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1349 GetWindowTextLengthA(HWND hWnd
)
1351 return(SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0));
1359 GetWindowTextLengthW(HWND hWnd
)
1361 return(SendMessageW(hWnd
, WM_GETTEXTLENGTH
, 0, 0));
1369 GetWindowTextW(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1375 if (lpString
== NULL
)
1378 Wnd
= ValidateHwnd(hWnd
);
1384 if (!TestWindowProcess( Wnd
))
1388 /* do not send WM_GETTEXT messages to other processes */
1389 Length
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
1392 Buffer
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1395 RtlCopyMemory(lpString
,
1397 (Length
+ 1) * sizeof(WCHAR
));
1409 Wnd
= NULL
; /* Don't send a message */
1412 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1416 Wnd
= NULL
; /* Don't send a message */
1421 Length
= SendMessageW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1427 GetWindowThreadProcessId(HWND hWnd
,
1428 LPDWORD lpdwProcessId
)
1432 PWND pWnd
= ValidateHwnd(hWnd
);
1434 if (!pWnd
) return Ret
;
1436 ti
= pWnd
->head
.pti
;
1440 if (ti
== GetW32ThreadInfo())
1441 { // We are current.
1442 //FIXME("Current!\n");
1444 *lpdwProcessId
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueProcess
;
1445 Ret
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueThread
;
1448 { // Ask kernel for info.
1449 //FIXME("Kernel call!\n");
1451 *lpdwProcessId
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
);
1452 Ret
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_THREAD_ID
);
1463 IsChild(HWND hWndParent
,
1466 PWND WndParent
, DesktopWnd
, Wnd
;
1469 WndParent
= ValidateHwnd(hWndParent
);
1472 Wnd
= ValidateHwnd(hWnd
);
1476 DesktopWnd
= GetThreadDesktopWnd();
1482 while (Wnd
!= NULL
&& ((Wnd
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
1484 if (Wnd
->spwndParent
!= NULL
)
1486 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1488 if (Wnd
== WndParent
)
1498 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1514 PWND Wnd
= ValidateHwnd(hWnd
);
1517 return (Wnd
->style
& WS_MINIMIZE
) != 0;
1529 PWND Wnd
= ValidateHwndNoErr(hWnd
);
1532 /* FIXME: If window is being destroyed return FALSE! */
1544 IsWindowUnicode(HWND hWnd
)
1546 PWND Wnd
= ValidateHwnd(hWnd
);
1549 return Wnd
->Unicode
;
1559 IsWindowVisible(HWND hWnd
)
1562 PWND Wnd
= ValidateHwnd(hWnd
);
1572 if (!(Wnd
->style
& WS_VISIBLE
))
1578 if (Wnd
->spwndParent
!= NULL
)
1579 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1583 } while (Wnd
!= NULL
);
1585 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1600 IsWindowEnabled(HWND hWnd
)
1602 // AG: I don't know if child windows are affected if the parent is
1603 // disabled. I think they stop processing messages but stay appearing
1606 return !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_DISABLED
);
1616 return (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
1624 LockSetForegroundWindow(UINT 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 ChildWindowFromPointEx(hwndParent
, ptParentClientCoords
, CWP_SKIPTRANSPARENT
);
1689 SetForegroundWindow(HWND hWnd
)
1691 return NtUserCallHwndLock(hWnd
, HWNDLOCK_ROUTINE_SETFOREGROUNDWINDOW
);
1699 SetProcessDefaultLayout(DWORD dwDefaultLayout
)
1701 if (dwDefaultLayout
== 0)
1713 SetWindowTextA(HWND hWnd
,
1717 if(!GetWindowThreadProcessId(hWnd
, &ProcessId
))
1722 if(ProcessId
!= GetCurrentProcessId())
1724 /* do not send WM_GETTEXT messages to other processes */
1726 DefSetText(hWnd
, (PCWSTR
)lpString
, TRUE
);
1728 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1730 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
1735 return SendMessageA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1743 SetWindowTextW(HWND hWnd
,
1747 if(!GetWindowThreadProcessId(hWnd
, &ProcessId
))
1752 if(ProcessId
!= GetCurrentProcessId())
1754 /* do not send WM_GETTEXT messages to other processes */
1756 DefSetText(hWnd
, lpString
, FALSE
);
1758 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1760 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
1765 return SendMessageW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1773 ShowOwnedPopups(HWND hWnd
,
1776 return (BOOL
)NtUserCallTwoParam((DWORD_PTR
)hWnd
, fShow
, TWOPARAM_ROUTINE_SHOWOWNEDPOPUPS
);
1784 UpdateLayeredWindow( HWND hwnd
,
1794 if ( dwFlags
& ULW_EX_NORESIZE
)
1795 dwFlags
= ~(ULW_EX_NORESIZE
|ULW_OPAQUE
|ULW_ALPHA
|ULW_COLORKEY
);
1796 return NtUserUpdateLayeredWindow( hwnd
,
1812 UpdateLayeredWindowIndirect(HWND hwnd
,
1813 const UPDATELAYEREDWINDOWINFO
*info
)
1815 if (info
&& info
->cbSize
== sizeof(info
))
1817 return NtUserUpdateLayeredWindow( hwnd
,
1819 (POINT
*)info
->pptDst
,
1820 (SIZE
*)info
->psize
,
1822 (POINT
*)info
->pptSrc
,
1824 (BLENDFUNCTION
*)info
->pblend
,
1826 (RECT
*)info
->prcDirty
);
1828 SetLastError(ERROR_INVALID_PARAMETER
);
1836 SetWindowContextHelpId(HWND hwnd
,
1837 DWORD dwContextHelpId
)
1839 return NtUserSetWindowContextHelpId(hwnd
, dwContextHelpId
);
1846 GetWindowContextHelpId(HWND hwnd
)
1848 return NtUserCallHwnd(hwnd
, HWND_ROUTINE_GETWNDCONTEXTHLPID
);
1855 InternalGetWindowText(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1857 INT Ret
= NtUserInternalGetWindowText(hWnd
, lpString
, nMaxCount
);
1867 IsHungAppWindow(HWND hwnd
)
1869 return (NtUserQueryWindow(hwnd
, QUERY_WINDOW_ISHUNG
) != 0);
1876 SetLastErrorEx(DWORD dwErrCode
, DWORD dwType
)
1878 SetLastError(dwErrCode
);
1887 return (HWND
)NtUserGetThreadState(THREADSTATE_FOCUSWINDOW
);
1891 GetRealWindowOwner(HWND hwnd
)
1893 return NtUserQueryWindow(hwnd
, QUERY_WINDOW_REAL_ID
);
1900 SetTaskmanWindow(HWND hWnd
)
1902 return NtUserCallHwndOpt(hWnd
, HWNDOPT_ROUTINE_SETTASKMANWINDOW
);
1909 SetProgmanWindow(HWND hWnd
)
1911 return NtUserCallHwndOpt(hWnd
, HWNDOPT_ROUTINE_SETPROGMANWINDOW
);
1918 GetProgmanWindow(VOID
)
1920 return (HWND
)NtUserGetThreadState(THREADSTATE_PROGMANWINDOW
);
1927 GetTaskmanWindow(VOID
)
1929 return (HWND
)NtUserGetThreadState(THREADSTATE_TASKMANWINDOW
);
1936 ScrollWindow(HWND hWnd
,
1940 CONST RECT
*prcClip
)
1942 return NtUserScrollWindowEx(hWnd
,
1949 (lpRect
? 0 : SW_SCROLLCHILDREN
) | SW_INVALIDATE
) != ERROR
;
1957 ScrollWindowEx(HWND hWnd
,
1960 CONST RECT
*prcScroll
,
1961 CONST RECT
*prcClip
,
1966 return NtUserScrollWindowEx(hWnd
,
1984 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1986 if (!list
) return FALSE
;
1987 for (i
= 0; list
[i
]; i
++)
1989 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
1991 retvalue
= (list
[i
] != 0);
1992 HeapFree( GetProcessHeap(), 0, list
);
2000 IsWindowInDestroy(HWND hWnd
)
2003 pwnd
= ValidateHwnd(hWnd
);
2006 return ((pwnd
->state2
& WNDS2_INDESTROY
) == WNDS2_INDESTROY
);
2013 DisableProcessWindowsGhosting(VOID
)
2015 NtUserEnableProcessWindowGhosting(FALSE
);