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 #define CW_USEDEFAULT16 0x00008000
23 /* FUNCTIONS *****************************************************************/
27 User32CallSendAsyncProcForKernel(PVOID Arguments
, ULONG ArgumentLength
)
29 PSENDASYNCPROC_CALLBACK_ARGUMENTS CallbackArgs
;
31 TRACE("User32CallSendAsyncProcKernel()\n");
33 CallbackArgs
= (PSENDASYNCPROC_CALLBACK_ARGUMENTS
)Arguments
;
35 if (ArgumentLength
!= sizeof(SENDASYNCPROC_CALLBACK_ARGUMENTS
))
37 return(STATUS_INFO_LENGTH_MISMATCH
);
40 CallbackArgs
->Callback(CallbackArgs
->Wnd
,
42 CallbackArgs
->Context
,
43 CallbackArgs
->Result
);
44 return(STATUS_SUCCESS
);
52 AllowSetForegroundWindow(DWORD dwProcessId
)
54 static BOOL show_message
= TRUE
;
68 BeginDeferWindowPos(int nNumWindows
)
72 SetLastError(ERROR_INVALID_PARAMETER
);
88 BringWindowToTop(HWND hWnd
)
90 return NtUserSetWindowPos(hWnd
,
96 SWP_NOSIZE
| SWP_NOMOVE
);
101 SwitchToThisWindow(HWND hwnd
, BOOL fUnknown
)
103 ShowWindow(hwnd
, SW_SHOW
);
111 ChildWindowFromPoint(HWND hWndParent
,
114 return (HWND
) NtUserChildWindowFromPointEx(hWndParent
, Point
.x
, Point
.y
, 0);
122 ChildWindowFromPointEx(HWND hwndParent
,
126 return (HWND
) NtUserChildWindowFromPointEx(hwndParent
, pt
.x
, pt
.y
, uFlags
);
134 CloseWindow(HWND hWnd
)
136 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
138 return HandleToUlong(hWnd
);
144 OUT PLARGE_STRING plstr
,
150 RtlInitLargeUnicodeString((PLARGE_UNICODE_STRING
)plstr
, (PWSTR
)psz
, 0);
154 RtlInitLargeAnsiString((PLARGE_ANSI_STRING
)plstr
, (PSTR
)psz
, 0);
161 IN PLARGE_STRING LargeString
)
163 if (LargeString
->Buffer
)
165 RtlFreeHeap(GetProcessHeap(), 0, LargeString
->Buffer
);
166 RtlZeroMemory(LargeString
, sizeof(LARGE_STRING
));
171 User32CreateWindowEx(DWORD dwExStyle
,
185 LARGE_STRING WindowName
;
186 LARGE_STRING lstrClassName
, *plstrClassName
;
187 UNICODE_STRING ClassName
;
193 DbgPrint("[window] User32CreateWindowEx style %d, exstyle %d, parent %d\n", dwStyle
, dwExStyle
, hWndParent
);
196 if (!RegisterDefaultClasses
)
198 ERR("User32CreateWindowEx RegisterSystemControls\n");
199 RegisterSystemControls();
202 if (IS_ATOM(lpClassName
))
204 plstrClassName
= (PVOID
)lpClassName
;
209 RtlInitUnicodeString(&ClassName
, (PCWSTR
)lpClassName
);
212 if (!RtlCreateUnicodeStringFromAsciiz(&ClassName
, (PCSZ
)lpClassName
))
214 SetLastError(ERROR_OUTOFMEMORY
);
219 /* Copy it to a LARGE_STRING */
220 lstrClassName
.Buffer
= ClassName
.Buffer
;
221 lstrClassName
.Length
= ClassName
.Length
;
222 lstrClassName
.MaximumLength
= ClassName
.MaximumLength
;
223 plstrClassName
= &lstrClassName
;
226 /* Initialize a LARGE_STRING */
227 RtlInitLargeString(&WindowName
, lpWindowName
, Unicode
);
229 // HACK: The current implementation expects the Window name to be UNICODE
233 PSTR AnsiBuffer
= WindowName
.Buffer
;
234 ULONG AnsiLength
= WindowName
.Length
;
236 WindowName
.Length
= 0;
237 WindowName
.MaximumLength
= AnsiLength
* sizeof(WCHAR
);
238 WindowName
.Buffer
= RtlAllocateHeap(RtlGetProcessHeap(),
240 WindowName
.MaximumLength
);
241 if (!WindowName
.Buffer
)
243 SetLastError(ERROR_OUTOFMEMORY
);
247 Status
= RtlMultiByteToUnicodeN(WindowName
.Buffer
,
248 WindowName
.MaximumLength
,
252 if (!NT_SUCCESS(Status
))
258 if(!hMenu
&& (dwStyle
& (WS_OVERLAPPEDWINDOW
| WS_POPUP
)))
262 wceW
.cbSize
= sizeof(WNDCLASSEXW
);
263 if(GetClassInfoExW(hInstance
, (LPCWSTR
)lpClassName
, &wceW
) && wceW
.lpszMenuName
)
265 hMenu
= LoadMenuW(hInstance
, wceW
.lpszMenuName
);
270 wceA
.cbSize
= sizeof(WNDCLASSEXA
);
271 if(GetClassInfoExA(hInstance
, lpClassName
, &wceA
) && wceA
.lpszMenuName
)
273 hMenu
= LoadMenuA(hInstance
, wceA
.lpszMenuName
);
278 if (!Unicode
) dwExStyle
|= WS_EX_SETANSICREATOR
;
280 Handle
= NtUserCreateWindowEx(dwExStyle
,
297 DbgPrint("[window] NtUserCreateWindowEx() == %d\n", Handle
);
302 if (!IS_ATOM(lpClassName
))
304 RtlFreeUnicodeString(&ClassName
);
307 RtlFreeLargeString(&WindowName
);
318 CreateWindowExA(DWORD dwExStyle
,
331 MDICREATESTRUCTA mdi
;
334 if (!RegisterDefaultClasses
)
336 ERR("CreateWindowExA RegisterSystemControls\n");
337 RegisterSystemControls();
340 if (dwExStyle
& WS_EX_MDICHILD
)
346 /* lpParams of WM_[NC]CREATE is different for MDI children.
347 * MDICREATESTRUCT members have the originally passed values.
349 mdi
.szClass
= lpClassName
;
350 mdi
.szTitle
= lpWindowName
;
351 mdi
.hOwner
= hInstance
;
357 mdi
.lParam
= (LPARAM
)lpParam
;
359 lpParam
= (LPVOID
)&mdi
;
361 if (GetWindowLongPtrW(hWndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
363 if (dwStyle
& WS_POPUP
)
365 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
368 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
372 dwStyle
&= ~WS_POPUP
;
373 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
374 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
377 top_child
= GetWindow(hWndParent
, GW_CHILD
);
381 /* Restore current maximized child */
382 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
384 TRACE("Restoring current maximized child %p\n", top_child
);
385 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
386 ShowWindow(top_child
, SW_RESTORE
);
387 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
391 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
393 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
395 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
397 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
402 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
404 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
409 hwnd
= User32CreateWindowEx(dwExStyle
,
430 CreateWindowExW(DWORD dwExStyle
,
432 LPCWSTR lpWindowName
,
443 MDICREATESTRUCTW mdi
;
446 if (!RegisterDefaultClasses
)
448 ERR("CreateWindowExW RegisterSystemControls\n");
449 RegisterSystemControls();
452 if (dwExStyle
& WS_EX_MDICHILD
)
458 /* lpParams of WM_[NC]CREATE is different for MDI children.
459 * MDICREATESTRUCT members have the originally passed values.
461 mdi
.szClass
= lpClassName
;
462 mdi
.szTitle
= lpWindowName
;
463 mdi
.hOwner
= hInstance
;
469 mdi
.lParam
= (LPARAM
)lpParam
;
471 lpParam
= (LPVOID
)&mdi
;
473 if (GetWindowLongPtrW(hWndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
475 if (dwStyle
& WS_POPUP
)
477 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
480 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
484 dwStyle
&= ~WS_POPUP
;
485 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
486 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
489 top_child
= GetWindow(hWndParent
, GW_CHILD
);
493 /* Restore current maximized child */
494 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
496 TRACE("Restoring current maximized child %p\n", top_child
);
497 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
498 ShowWindow(top_child
, SW_RESTORE
);
499 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
503 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
505 if (!(dwStyle
& WS_POPUP
)) hMenu
= UlongToHandle(id
);
507 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
509 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
514 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
516 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
521 hwnd
= User32CreateWindowEx(dwExStyle
,
522 (LPCSTR
) lpClassName
,
523 (LPCSTR
) lpWindowName
,
541 DeferWindowPos(HDWP hWinPosInfo
,
543 HWND hWndInsertAfter
,
551 return NtUserDeferWindowPos(hWinPosInfo
, hWnd
, hWndInsertAfter
, x
, y
, cx
, cy
, uFlags
);
553 SetWindowPos(hWnd
, hWndInsertAfter
, x
, y
, cx
, cy
, uFlags
);
563 EndDeferWindowPos(HDWP hWinPosInfo
)
578 GetDesktopWindow(VOID
)
585 Wnd
= GetThreadDesktopWnd();
587 Ret
= UserHMGetHandle(Wnd
);
589 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
600 User32EnumWindows(HDESK hDesktop
,
607 DWORD i
, dwCount
= 0;
614 SetLastError ( ERROR_INVALID_PARAMETER
);
618 /* FIXME instead of always making two calls, should we use some
619 sort of persistent buffer and only grow it ( requiring a 2nd
620 call ) when the buffer wasn't already big enough? */
621 /* first get how many window entries there are */
622 Status
= NtUserBuildHwndList(hDesktop
,
629 if (!NT_SUCCESS(Status
))
632 /* allocate buffer to receive HWND handles */
633 hHeap
= GetProcessHeap();
634 pHwnd
= HeapAlloc(hHeap
, 0, sizeof(HWND
)*(dwCount
+1));
637 SetLastError ( ERROR_NOT_ENOUGH_MEMORY
);
641 /* now call kernel again to fill the buffer this time */
642 Status
= NtUserBuildHwndList(hDesktop
,
649 if (!NT_SUCCESS(Status
))
652 HeapFree(hHeap
, 0, pHwnd
);
664 /* call the user's callback function until we're done or
665 they tell us to quit */
666 for ( i
= 0; i
< dwCount
; i
++ )
668 /* FIXME I'm only getting NULLs from Thread Enumeration, and it's
669 * probably because I'm not doing it right in NtUserBuildHwndList.
670 * Once that's fixed, we shouldn't have to check for a NULL HWND
672 * This is now fixed in revision 50205. (jt)
674 if (!pHwnd
[i
]) /* don't enumerate a NULL HWND */
676 if (!(*lpfn
)(pHwnd
[i
], lParam
))
678 HeapFree ( hHeap
, 0, pHwnd
);
683 HeapFree(hHeap
, 0, pHwnd
);
692 EnumChildWindows(HWND hWndParent
,
693 WNDENUMPROC lpEnumFunc
,
698 return EnumWindows(lpEnumFunc
, lParam
);
700 return User32EnumWindows(NULL
, hWndParent
, lpEnumFunc
, lParam
, 0, TRUE
);
708 EnumThreadWindows(DWORD dwThreadId
,
713 dwThreadId
= GetCurrentThreadId();
714 return User32EnumWindows(NULL
, NULL
, lpfn
, lParam
, dwThreadId
, FALSE
);
722 EnumWindows(WNDENUMPROC lpEnumFunc
,
725 return User32EnumWindows(NULL
, NULL
, lpEnumFunc
, lParam
, 0, FALSE
);
733 EnumDesktopWindows(HDESK hDesktop
,
737 return User32EnumWindows(hDesktop
, NULL
, lpfn
, lParam
, 0, FALSE
);
745 FindWindowExA(HWND hwndParent
,
750 UNICODE_STRING ucClassName
, *pucClassName
= NULL
;
751 UNICODE_STRING ucWindowName
, *pucWindowName
= NULL
;
754 if (IS_ATOM(lpszClass
))
756 ucClassName
.Buffer
= (LPWSTR
)lpszClass
;
757 ucClassName
.Length
= 0;
758 pucClassName
= &ucClassName
;
760 else if (lpszClass
!= NULL
)
762 if (!RtlCreateUnicodeStringFromAsciiz(&ucClassName
,
765 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
768 pucClassName
= &ucClassName
;
771 if (lpszWindow
!= NULL
)
773 if (!RtlCreateUnicodeStringFromAsciiz(&ucWindowName
,
776 if (!IS_ATOM(lpszClass
) && lpszClass
!= NULL
)
777 RtlFreeUnicodeString(&ucWindowName
);
779 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
783 pucWindowName
= &ucWindowName
;
786 Result
= NtUserFindWindowEx(hwndParent
,
792 if (!IS_ATOM(lpszClass
) && lpszClass
!= NULL
)
793 RtlFreeUnicodeString(&ucClassName
);
794 if (lpszWindow
!= NULL
)
795 RtlFreeUnicodeString(&ucWindowName
);
805 FindWindowExW(HWND hwndParent
,
810 UNICODE_STRING ucClassName
, *pucClassName
= NULL
;
811 UNICODE_STRING ucWindowName
, *pucWindowName
= NULL
;
813 if (IS_ATOM(lpszClass
))
815 ucClassName
.Length
= 0;
816 ucClassName
.Buffer
= (LPWSTR
)lpszClass
;
817 pucClassName
= &ucClassName
;
819 else if (lpszClass
!= NULL
)
821 RtlInitUnicodeString(&ucClassName
,
823 pucClassName
= &ucClassName
;
826 if (lpszWindow
!= NULL
)
828 RtlInitUnicodeString(&ucWindowName
,
830 pucWindowName
= &ucWindowName
;
833 return NtUserFindWindowEx(hwndParent
,
845 FindWindowA(LPCSTR lpClassName
, LPCSTR lpWindowName
)
847 //FIXME: FindWindow does not search children, but FindWindowEx does.
848 // what should we do about this?
849 return FindWindowExA (NULL
, NULL
, lpClassName
, lpWindowName
);
857 FindWindowW(LPCWSTR lpClassName
, LPCWSTR lpWindowName
)
861 There was a FIXME here earlier, but I think it is just a documentation unclarity.
863 FindWindow only searches top level windows. What they mean is that child
864 windows of other windows than the desktop can be searched.
865 FindWindowExW never does a recursive search.
870 return FindWindowExW(NULL
, NULL
, lpClassName
, lpWindowName
);
879 GetAltTabInfoA(HWND hwnd
,
894 GetAltTabInfoW(HWND hwnd
,
909 GetAncestor(HWND hwnd
, UINT gaFlags
)
914 Wnd
= ValidateHwnd(hwnd
);
924 if (Wnd
->spwndParent
!= NULL
)
925 Ancestor
= DesktopPtrToUser(Wnd
->spwndParent
);
929 /* FIXME: Call win32k for now */
934 if (Ancestor
!= NULL
)
935 Ret
= UserHMGetHandle(Ancestor
);
937 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
943 if (!Wnd
) /* Fall back */
944 Ret
= NtUserGetAncestor(hwnd
, gaFlags
);
954 GetClientRect(HWND hWnd
, LPRECT lpRect
)
956 PWND Wnd
= ValidateHwnd(hWnd
);
960 lpRect
->left
= lpRect
->top
= 0;
961 lpRect
->right
= Wnd
->rcClient
.right
- Wnd
->rcClient
.left
;
962 lpRect
->bottom
= Wnd
->rcClient
.bottom
- Wnd
->rcClient
.top
;
974 GetLastActivePopup(HWND hWnd
)
979 Wnd
= ValidateHwnd(hWnd
);
984 if (Wnd
->hWndLastActive
)
985 Ret
= Wnd
->hWndLastActive
;
987 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1001 GetParent(HWND hWnd
)
1003 PWND Wnd
, WndParent
;
1006 Wnd
= ValidateHwnd(hWnd
);
1012 if (Wnd
->style
& WS_POPUP
)
1014 if (Wnd
->spwndOwner
!= NULL
)
1015 WndParent
= DesktopPtrToUser(Wnd
->spwndOwner
);
1017 else if (Wnd
->style
& WS_CHILD
)
1019 if (Wnd
->spwndParent
!= NULL
)
1020 WndParent
= DesktopPtrToUser(Wnd
->spwndParent
);
1023 if (WndParent
!= NULL
)
1024 Ret
= UserHMGetHandle(WndParent
);
1026 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1041 GetProcessDefaultLayout(DWORD
*pdwDefaultLayout
)
1043 if (!pdwDefaultLayout
)
1045 SetLastError(ERROR_INVALID_PARAMETER
);
1051 *pdwDefaultLayout
= 0;
1060 GetWindow(HWND hWnd
,
1066 Wnd
= ValidateHwnd(hWnd
);
1076 if (Wnd
->spwndOwner
!= NULL
)
1077 FoundWnd
= DesktopPtrToUser(Wnd
->spwndOwner
);
1081 if(Wnd
->spwndParent
!= NULL
)
1083 FoundWnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1084 if (FoundWnd
->spwndChild
!= NULL
)
1085 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndChild
);
1089 if (Wnd
->spwndNext
!= NULL
)
1090 FoundWnd
= DesktopPtrToUser(Wnd
->spwndNext
);
1094 if (Wnd
->spwndPrev
!= NULL
)
1095 FoundWnd
= DesktopPtrToUser(Wnd
->spwndPrev
);
1099 if (Wnd
->spwndChild
!= NULL
)
1100 FoundWnd
= DesktopPtrToUser(Wnd
->spwndChild
);
1105 while ( FoundWnd
->spwndNext
!= NULL
)
1106 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndNext
);
1114 if (FoundWnd
!= NULL
)
1115 Ret
= UserHMGetHandle(FoundWnd
);
1117 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1131 GetTopWindow(HWND hWnd
)
1133 if (!hWnd
) hWnd
= GetDesktopWindow();
1134 return GetWindow(hWnd
, GW_CHILD
);
1142 GetWindowInfo(HWND hWnd
,
1150 if ( !pwi
|| pwi
->cbSize
!= sizeof(WINDOWINFO
))
1151 SetLastError(ERROR_INVALID_PARAMETER
); // Just set the error and go!
1153 pWnd
= ValidateHwnd(hWnd
);
1157 UserGetWindowBorders(pWnd
->style
, pWnd
->ExStyle
, &Size
, FALSE
);
1161 pCls
= DesktopPtrToUser(pWnd
->pcls
);
1162 pwi
->rcWindow
= pWnd
->rcWindow
;
1163 pwi
->rcClient
= pWnd
->rcClient
;
1164 pwi
->dwStyle
= pWnd
->style
;
1165 pwi
->dwExStyle
= pWnd
->ExStyle
;
1166 pwi
->cxWindowBorders
= Size
.cx
;
1167 pwi
->cyWindowBorders
= Size
.cy
;
1168 pwi
->dwWindowStatus
= 0;
1169 if (pWnd
->state
& WNDS_ACTIVEFRAME
)
1170 pwi
->dwWindowStatus
= WS_ACTIVECAPTION
;
1171 pwi
->atomWindowType
= (pCls
? pCls
->atomClassName
: 0 );
1173 if ( pWnd
->state2
& WNDS2_WIN50COMPAT
)
1175 pwi
->wCreatorVersion
= 0x500;
1177 else if ( pWnd
->state2
& WNDS2_WIN40COMPAT
)
1179 pwi
->wCreatorVersion
= 0x400;
1181 else if ( pWnd
->state2
& WNDS2_WIN31COMPAT
)
1183 pwi
->wCreatorVersion
= 0x30A;
1187 pwi
->wCreatorVersion
= 0x300;
1192 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1206 GetWindowModuleFileNameA(HWND hwnd
,
1208 UINT cchFileNameMax
)
1210 PWND Wnd
= ValidateHwnd(hwnd
);
1215 return GetModuleFileNameA(Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1223 GetWindowModuleFileNameW(HWND hwnd
,
1224 LPWSTR lpszFileName
,
1225 UINT cchFileNameMax
)
1227 PWND Wnd
= ValidateHwnd(hwnd
);
1232 return GetModuleFileNameW( Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1240 GetWindowRect(HWND hWnd
,
1243 PWND Wnd
= ValidateHwnd(hWnd
);
1247 *lpRect
= Wnd
->rcWindow
;
1259 GetWindowTextA(HWND hWnd
, LPSTR lpString
, int nMaxCount
)
1265 if (lpString
== NULL
)
1268 Wnd
= ValidateHwnd(hWnd
);
1274 if (!TestWindowProcess( Wnd
))
1278 /* do not send WM_GETTEXT messages to other processes */
1279 Length
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
1282 Buffer
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1285 if (!WideCharToMultiByte(CP_ACP
,
1294 lpString
[nMaxCount
- 1] = '\0';
1307 Wnd
= NULL
; /* Don't send a message */
1310 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1314 Wnd
= NULL
; /* Don't send a message */
1319 Length
= SendMessageA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1329 GetWindowTextLengthA(HWND hWnd
)
1331 return(SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0));
1339 GetWindowTextLengthW(HWND hWnd
)
1341 return(SendMessageW(hWnd
, WM_GETTEXTLENGTH
, 0, 0));
1349 GetWindowTextW(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1355 if (lpString
== NULL
)
1358 Wnd
= ValidateHwnd(hWnd
);
1364 if (!TestWindowProcess( Wnd
))
1368 /* do not send WM_GETTEXT messages to other processes */
1369 Length
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
1372 Buffer
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1375 RtlCopyMemory(lpString
,
1377 (Length
+ 1) * sizeof(WCHAR
));
1389 Wnd
= NULL
; /* Don't send a message */
1392 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1396 Wnd
= NULL
; /* Don't send a message */
1401 Length
= SendMessageW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1407 GetWindowThreadProcessId(HWND hWnd
,
1408 LPDWORD lpdwProcessId
)
1412 PWND pWnd
= ValidateHwnd(hWnd
);
1414 if (!pWnd
) return Ret
;
1416 ti
= pWnd
->head
.pti
;
1420 if (ti
== GetW32ThreadInfo())
1421 { // We are current.
1422 //FIXME("Current!\n");
1424 *lpdwProcessId
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueProcess
;
1425 Ret
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueThread
;
1428 { // Ask kernel for info.
1429 //FIXME("Kernel call!\n");
1431 *lpdwProcessId
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
);
1432 Ret
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_THREAD_ID
);
1443 IsChild(HWND hWndParent
,
1446 PWND WndParent
, DesktopWnd
, Wnd
;
1449 WndParent
= ValidateHwnd(hWndParent
);
1452 Wnd
= ValidateHwnd(hWnd
);
1456 DesktopWnd
= GetThreadDesktopWnd();
1462 while (Wnd
!= NULL
&& ((Wnd
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
1464 if (Wnd
->spwndParent
!= NULL
)
1466 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1468 if (Wnd
== WndParent
)
1478 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1494 PWND Wnd
= ValidateHwnd(hWnd
);
1497 return (Wnd
->style
& WS_MINIMIZE
) != 0;
1509 PWND Wnd
= ValidateHwndNoErr(hWnd
);
1512 /* FIXME: If window is being destroyed return FALSE! */
1524 IsWindowUnicode(HWND hWnd
)
1526 PWND Wnd
= ValidateHwnd(hWnd
);
1529 return Wnd
->Unicode
;
1539 IsWindowVisible(HWND hWnd
)
1542 PWND Wnd
= ValidateHwnd(hWnd
);
1552 if (!(Wnd
->style
& WS_VISIBLE
))
1558 if (Wnd
->spwndParent
!= NULL
)
1559 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1563 } while (Wnd
!= NULL
);
1565 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1580 IsWindowEnabled(HWND hWnd
)
1582 // AG: I don't know if child windows are affected if the parent is
1583 // disabled. I think they stop processing messages but stay appearing
1586 return !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_DISABLED
);
1596 return (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
1604 LockSetForegroundWindow(UINT uLockCode
)
1615 AnimateWindow(HWND hwnd
,
1619 /* FIXME Add animation code */
1621 /* If trying to show/hide and it's already *
1622 * shown/hidden or invalid window, fail with *
1623 * invalid parameter */
1626 visible
= IsWindowVisible(hwnd
);
1627 if(!IsWindow(hwnd
) ||
1628 (visible
&& !(dwFlags
& AW_HIDE
)) ||
1629 (!visible
&& (dwFlags
& AW_HIDE
)))
1631 SetLastError(ERROR_INVALID_PARAMETER
);
1635 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1647 if (!(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1650 ShowWindow(hWnd
,SW_RESTORE
);
1659 RealChildWindowFromPoint(HWND hwndParent
,
1660 POINT ptParentClientCoords
)
1662 return ChildWindowFromPointEx(hwndParent
, ptParentClientCoords
, CWP_SKIPTRANSPARENT
);
1669 SetForegroundWindow(HWND hWnd
)
1671 return NtUserCallHwndLock(hWnd
, HWNDLOCK_ROUTINE_SETFOREGROUNDWINDOW
);
1679 SetProcessDefaultLayout(DWORD dwDefaultLayout
)
1681 if (dwDefaultLayout
== 0)
1693 SetWindowTextA(HWND hWnd
,
1697 if(!GetWindowThreadProcessId(hWnd
, &ProcessId
))
1702 if(ProcessId
!= GetCurrentProcessId())
1704 /* do not send WM_GETTEXT messages to other processes */
1706 DefSetText(hWnd
, (PCWSTR
)lpString
, TRUE
);
1708 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1710 DefWndNCPaint(hWnd
, (HRGN
)1, -1);
1715 return SendMessageA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1723 SetWindowTextW(HWND hWnd
,
1727 if(!GetWindowThreadProcessId(hWnd
, &ProcessId
))
1732 if(ProcessId
!= GetCurrentProcessId())
1734 /* do not send WM_GETTEXT messages to other processes */
1736 DefSetText(hWnd
, lpString
, FALSE
);
1738 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1740 DefWndNCPaint(hWnd
, (HRGN
)1, -1);
1745 return SendMessageW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1753 ShowOwnedPopups(HWND hWnd
,
1756 return (BOOL
)NtUserCallTwoParam((DWORD_PTR
)hWnd
, fShow
, TWOPARAM_ROUTINE_SHOWOWNEDPOPUPS
);
1764 UpdateLayeredWindow( HWND hwnd
,
1774 if ( dwFlags
& ULW_EX_NORESIZE
)
1775 dwFlags
= ~(ULW_EX_NORESIZE
|ULW_OPAQUE
|ULW_ALPHA
|ULW_COLORKEY
);
1776 return NtUserUpdateLayeredWindow( hwnd
,
1792 UpdateLayeredWindowIndirect(HWND hwnd
,
1793 const UPDATELAYEREDWINDOWINFO
*info
)
1795 if (info
&& info
->cbSize
== sizeof(info
))
1797 return NtUserUpdateLayeredWindow( hwnd
,
1799 (POINT
*)info
->pptDst
,
1800 (SIZE
*)info
->psize
,
1802 (POINT
*)info
->pptSrc
,
1804 (BLENDFUNCTION
*)info
->pblend
,
1806 (RECT
*)info
->prcDirty
);
1808 SetLastError(ERROR_INVALID_PARAMETER
);
1817 WindowFromPoint(POINT Point
)
1819 //TODO: Determine what the actual parameters to
1820 // NtUserWindowFromPoint are.
1821 return NtUserWindowFromPoint(Point
.x
, Point
.y
);
1829 MapWindowPoints(HWND hWndFrom
, HWND hWndTo
, LPPOINT lpPoints
, UINT cPoints
)
1831 PWND FromWnd
, ToWnd
;
1835 FromWnd
= ValidateHwndOrDesk(hWndFrom
);
1839 ToWnd
= ValidateHwndOrDesk(hWndTo
);
1843 Delta
.x
= FromWnd
->rcClient
.left
- ToWnd
->rcClient
.left
;
1844 Delta
.y
= FromWnd
->rcClient
.top
- ToWnd
->rcClient
.top
;
1846 for (i
= 0; i
!= cPoints
; i
++)
1848 lpPoints
[i
].x
+= Delta
.x
;
1849 lpPoints
[i
].y
+= Delta
.y
;
1852 return MAKELONG(LOWORD(Delta
.x
), LOWORD(Delta
.y
));
1860 ScreenToClient(HWND hWnd
, LPPOINT lpPoint
)
1862 PWND Wnd
, DesktopWnd
;
1864 Wnd
= ValidateHwnd(hWnd
);
1868 DesktopWnd
= GetThreadDesktopWnd();
1870 lpPoint
->x
+= DesktopWnd
->rcClient
.left
- Wnd
->rcClient
.left
;
1871 lpPoint
->y
+= DesktopWnd
->rcClient
.top
- Wnd
->rcClient
.top
;
1881 ClientToScreen(HWND hWnd
, LPPOINT lpPoint
)
1883 PWND Wnd
, DesktopWnd
;
1885 Wnd
= ValidateHwnd(hWnd
);
1889 DesktopWnd
= GetThreadDesktopWnd();
1891 lpPoint
->x
+= Wnd
->rcClient
.left
- DesktopWnd
->rcClient
.left
;
1892 lpPoint
->y
+= Wnd
->rcClient
.top
- DesktopWnd
->rcClient
.top
;
1902 SetWindowContextHelpId(HWND hwnd
,
1903 DWORD dwContextHelpId
)
1905 return NtUserSetWindowContextHelpId(hwnd
, dwContextHelpId
);
1913 GetWindowContextHelpId(HWND hwnd
)
1915 return NtUserCallHwnd(hwnd
, HWND_ROUTINE_GETWNDCONTEXTHLPID
);
1922 InternalGetWindowText(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1924 INT Ret
= NtUserInternalGetWindowText(hWnd
, lpString
, nMaxCount
);
1934 IsHungAppWindow(HWND hwnd
)
1936 return (NtUserQueryWindow(hwnd
, QUERY_WINDOW_ISHUNG
) != 0);
1943 SetLastErrorEx(DWORD dwErrCode
, DWORD dwType
)
1945 SetLastError(dwErrCode
);
1954 return (HWND
)NtUserGetThreadState(THREADSTATE_FOCUSWINDOW
);
1958 GetRealWindowOwner(HWND hwnd
)
1960 return NtUserQueryWindow(hwnd
, QUERY_WINDOW_REAL_ID
);
1967 SetTaskmanWindow(HWND hWnd
)
1969 return NtUserCallHwndOpt(hWnd
, HWNDOPT_ROUTINE_SETTASKMANWINDOW
);
1976 SetProgmanWindow(HWND hWnd
)
1978 return NtUserCallHwndOpt(hWnd
, HWNDOPT_ROUTINE_SETPROGMANWINDOW
);
1985 GetProgmanWindow(VOID
)
1987 return (HWND
)NtUserGetThreadState(THREADSTATE_PROGMANWINDOW
);
1994 GetTaskmanWindow(VOID
)
1996 return (HWND
)NtUserGetThreadState(THREADSTATE_TASKMANWINDOW
);
2003 ScrollWindow(HWND hWnd
,
2007 CONST RECT
*prcClip
)
2009 return NtUserScrollWindowEx(hWnd
,
2016 (lpRect
? 0 : SW_SCROLLCHILDREN
) | SW_INVALIDATE
) != ERROR
;
2024 ScrollWindowEx(HWND hWnd
,
2027 CONST RECT
*prcScroll
,
2028 CONST RECT
*prcClip
,
2033 return NtUserScrollWindowEx(hWnd
,
2051 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
2053 if (!list
) return FALSE
;
2054 for (i
= 0; list
[i
]; i
++)
2056 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
2058 retvalue
= (list
[i
] != 0);
2059 HeapFree( GetProcessHeap(), 0, list
);
2067 IsWindowInDestroy(HWND hWnd
)
2070 pwnd
= ValidateHwnd(hWnd
);
2073 return ((pwnd
->state2
& WNDS2_INDESTROY
) == WNDS2_INDESTROY
);
2080 DisableProcessWindowsGhosting(VOID
)
2082 NtUserEnableProcessWindowGhosting(FALSE
);