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
);
656 /* call the user's callback function until we're done or
657 they tell us to quit */
658 for ( i
= 0; i
< dwCount
; i
++ )
660 /* FIXME I'm only getting NULLs from Thread Enumeration, and it's
661 * probably because I'm not doing it right in NtUserBuildHwndList.
662 * Once that's fixed, we shouldn't have to check for a NULL HWND
665 if (!pHwnd
[i
]) /* don't enumerate a NULL HWND */
667 if (!(*lpfn
)(pHwnd
[i
], lParam
))
669 HeapFree ( hHeap
, 0, pHwnd
);
674 HeapFree(hHeap
, 0, pHwnd
);
683 EnumChildWindows(HWND hWndParent
,
684 WNDENUMPROC lpEnumFunc
,
689 return EnumWindows(lpEnumFunc
, lParam
);
691 return User32EnumWindows(NULL
, hWndParent
, lpEnumFunc
, lParam
, 0, TRUE
);
699 EnumThreadWindows(DWORD dwThreadId
,
704 dwThreadId
= GetCurrentThreadId();
705 return User32EnumWindows(NULL
, NULL
, lpfn
, lParam
, dwThreadId
, FALSE
);
713 EnumWindows(WNDENUMPROC lpEnumFunc
,
716 return User32EnumWindows(NULL
, NULL
, lpEnumFunc
, lParam
, 0, FALSE
);
724 EnumDesktopWindows(HDESK hDesktop
,
728 return User32EnumWindows(hDesktop
, NULL
, lpfn
, lParam
, 0, FALSE
);
736 FindWindowExA(HWND hwndParent
,
741 UNICODE_STRING ucClassName
, *pucClassName
= NULL
;
742 UNICODE_STRING ucWindowName
, *pucWindowName
= NULL
;
745 if (IS_ATOM(lpszClass
))
747 ucClassName
.Buffer
= (LPWSTR
)lpszClass
;
748 ucClassName
.Length
= 0;
749 pucClassName
= &ucClassName
;
751 else if (lpszClass
!= NULL
)
753 if (!RtlCreateUnicodeStringFromAsciiz(&ucClassName
,
756 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
759 pucClassName
= &ucClassName
;
762 if (lpszWindow
!= NULL
)
764 if (!RtlCreateUnicodeStringFromAsciiz(&ucWindowName
,
767 if (!IS_ATOM(lpszClass
) && lpszClass
!= NULL
)
768 RtlFreeUnicodeString(&ucWindowName
);
770 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
774 pucWindowName
= &ucWindowName
;
777 Result
= NtUserFindWindowEx(hwndParent
,
783 if (!IS_ATOM(lpszClass
) && lpszClass
!= NULL
)
784 RtlFreeUnicodeString(&ucClassName
);
785 if (lpszWindow
!= NULL
)
786 RtlFreeUnicodeString(&ucWindowName
);
796 FindWindowExW(HWND hwndParent
,
801 UNICODE_STRING ucClassName
, *pucClassName
= NULL
;
802 UNICODE_STRING ucWindowName
, *pucWindowName
= NULL
;
804 if (IS_ATOM(lpszClass
))
806 ucClassName
.Length
= 0;
807 ucClassName
.Buffer
= (LPWSTR
)lpszClass
;
808 pucClassName
= &ucClassName
;
810 else if (lpszClass
!= NULL
)
812 RtlInitUnicodeString(&ucClassName
,
814 pucClassName
= &ucClassName
;
817 if (lpszWindow
!= NULL
)
819 RtlInitUnicodeString(&ucWindowName
,
821 pucWindowName
= &ucWindowName
;
824 return NtUserFindWindowEx(hwndParent
,
836 FindWindowA(LPCSTR lpClassName
, LPCSTR lpWindowName
)
838 //FIXME: FindWindow does not search children, but FindWindowEx does.
839 // what should we do about this?
840 return FindWindowExA (NULL
, NULL
, lpClassName
, lpWindowName
);
848 FindWindowW(LPCWSTR lpClassName
, LPCWSTR lpWindowName
)
852 There was a FIXME here earlier, but I think it is just a documentation unclarity.
854 FindWindow only searches top level windows. What they mean is that child
855 windows of other windows than the desktop can be searched.
856 FindWindowExW never does a recursive search.
861 return FindWindowExW(NULL
, NULL
, lpClassName
, lpWindowName
);
870 GetAltTabInfoA(HWND hwnd
,
885 GetAltTabInfoW(HWND hwnd
,
900 GetAncestor(HWND hwnd
, UINT gaFlags
)
905 Wnd
= ValidateHwnd(hwnd
);
915 if (Wnd
->spwndParent
!= NULL
)
916 Ancestor
= DesktopPtrToUser(Wnd
->spwndParent
);
920 /* FIXME: Call win32k for now */
925 if (Ancestor
!= NULL
)
926 Ret
= UserHMGetHandle(Ancestor
);
928 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
934 if (!Wnd
) /* Fall back */
935 Ret
= NtUserGetAncestor(hwnd
, gaFlags
);
945 GetClientRect(HWND hWnd
, LPRECT lpRect
)
947 PWND Wnd
= ValidateHwnd(hWnd
);
951 lpRect
->left
= lpRect
->top
= 0;
952 lpRect
->right
= Wnd
->rcClient
.right
- Wnd
->rcClient
.left
;
953 lpRect
->bottom
= Wnd
->rcClient
.bottom
- Wnd
->rcClient
.top
;
965 GetLastActivePopup(HWND hWnd
)
970 Wnd
= ValidateHwnd(hWnd
);
975 if (Wnd
->hWndLastActive
)
976 Ret
= Wnd
->hWndLastActive
;
978 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
997 Wnd
= ValidateHwnd(hWnd
);
1003 if (Wnd
->style
& WS_POPUP
)
1005 if (Wnd
->spwndOwner
!= NULL
)
1006 WndParent
= DesktopPtrToUser(Wnd
->spwndOwner
);
1008 else if (Wnd
->style
& WS_CHILD
)
1010 if (Wnd
->spwndParent
!= NULL
)
1011 WndParent
= DesktopPtrToUser(Wnd
->spwndParent
);
1014 if (WndParent
!= NULL
)
1015 Ret
= UserHMGetHandle(WndParent
);
1017 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1032 GetProcessDefaultLayout(DWORD
*pdwDefaultLayout
)
1034 if (!pdwDefaultLayout
)
1036 SetLastError(ERROR_INVALID_PARAMETER
);
1042 *pdwDefaultLayout
= 0;
1051 GetWindow(HWND hWnd
,
1057 Wnd
= ValidateHwnd(hWnd
);
1067 if (Wnd
->spwndOwner
!= NULL
)
1068 FoundWnd
= DesktopPtrToUser(Wnd
->spwndOwner
);
1072 if(Wnd
->spwndParent
!= NULL
)
1074 FoundWnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1075 if (FoundWnd
->spwndChild
!= NULL
)
1076 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndChild
);
1080 if (Wnd
->spwndNext
!= NULL
)
1081 FoundWnd
= DesktopPtrToUser(Wnd
->spwndNext
);
1085 if (Wnd
->spwndPrev
!= NULL
)
1086 FoundWnd
= DesktopPtrToUser(Wnd
->spwndPrev
);
1090 if (Wnd
->spwndChild
!= NULL
)
1091 FoundWnd
= DesktopPtrToUser(Wnd
->spwndChild
);
1096 while ( FoundWnd
->spwndNext
!= NULL
)
1097 FoundWnd
= DesktopPtrToUser(FoundWnd
->spwndNext
);
1105 if (FoundWnd
!= NULL
)
1106 Ret
= UserHMGetHandle(FoundWnd
);
1108 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1122 GetTopWindow(HWND hWnd
)
1124 if (!hWnd
) hWnd
= GetDesktopWindow();
1125 return GetWindow(hWnd
, GW_CHILD
);
1133 GetWindowInfo(HWND hWnd
,
1141 if ( !pwi
|| pwi
->cbSize
!= sizeof(WINDOWINFO
))
1142 SetLastError(ERROR_INVALID_PARAMETER
); // Just set the error and go!
1144 pWnd
= ValidateHwnd(hWnd
);
1148 UserGetWindowBorders(pWnd
->style
, pWnd
->ExStyle
, &Size
, FALSE
);
1152 pCls
= DesktopPtrToUser(pWnd
->pcls
);
1153 pwi
->rcWindow
= pWnd
->rcWindow
;
1154 pwi
->rcClient
= pWnd
->rcClient
;
1155 pwi
->dwStyle
= pWnd
->style
;
1156 pwi
->dwExStyle
= pWnd
->ExStyle
;
1157 pwi
->cxWindowBorders
= Size
.cx
;
1158 pwi
->cyWindowBorders
= Size
.cy
;
1159 pwi
->dwWindowStatus
= 0;
1160 if (pWnd
->state
& WNDS_ACTIVEFRAME
)
1161 pwi
->dwWindowStatus
= WS_ACTIVECAPTION
;
1162 pwi
->atomWindowType
= (pCls
? pCls
->atomClassName
: 0 );
1164 if ( pWnd
->state2
& WNDS2_WIN50COMPAT
)
1166 pwi
->wCreatorVersion
= 0x500;
1168 else if ( pWnd
->state2
& WNDS2_WIN40COMPAT
)
1170 pwi
->wCreatorVersion
= 0x400;
1172 else if ( pWnd
->state2
& WNDS2_WIN31COMPAT
)
1174 pwi
->wCreatorVersion
= 0x30A;
1178 pwi
->wCreatorVersion
= 0x300;
1183 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1197 GetWindowModuleFileNameA(HWND hwnd
,
1199 UINT cchFileNameMax
)
1201 PWND Wnd
= ValidateHwnd(hwnd
);
1206 return GetModuleFileNameA(Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1214 GetWindowModuleFileNameW(HWND hwnd
,
1215 LPWSTR lpszFileName
,
1216 UINT cchFileNameMax
)
1218 PWND Wnd
= ValidateHwnd(hwnd
);
1223 return GetModuleFileNameW( Wnd
->hModule
, lpszFileName
, cchFileNameMax
);
1231 GetWindowRect(HWND hWnd
,
1234 PWND Wnd
= ValidateHwnd(hWnd
);
1238 *lpRect
= Wnd
->rcWindow
;
1250 GetWindowTextA(HWND hWnd
, LPSTR lpString
, int nMaxCount
)
1256 if (lpString
== NULL
)
1259 Wnd
= ValidateHwnd(hWnd
);
1265 if (!TestWindowProcess( Wnd
))
1269 /* do not send WM_GETTEXT messages to other processes */
1270 Length
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
1273 Buffer
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1276 if (!WideCharToMultiByte(CP_ACP
,
1285 lpString
[nMaxCount
- 1] = '\0';
1298 Wnd
= NULL
; /* Don't send a message */
1301 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1305 Wnd
= NULL
; /* Don't send a message */
1310 Length
= SendMessageA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1320 GetWindowTextLengthA(HWND hWnd
)
1322 return(SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0));
1330 GetWindowTextLengthW(HWND hWnd
)
1332 return(SendMessageW(hWnd
, WM_GETTEXTLENGTH
, 0, 0));
1340 GetWindowTextW(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1346 if (lpString
== NULL
)
1349 Wnd
= ValidateHwnd(hWnd
);
1355 if (!TestWindowProcess( Wnd
))
1359 /* do not send WM_GETTEXT messages to other processes */
1360 Length
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
1363 Buffer
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1366 RtlCopyMemory(lpString
,
1368 (Length
+ 1) * sizeof(WCHAR
));
1380 Wnd
= NULL
; /* Don't send a message */
1383 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1387 Wnd
= NULL
; /* Don't send a message */
1392 Length
= SendMessageW(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
1398 GetWindowThreadProcessId(HWND hWnd
,
1399 LPDWORD lpdwProcessId
)
1403 PWND pWnd
= ValidateHwnd(hWnd
);
1405 if (!pWnd
) return Ret
;
1407 ti
= pWnd
->head
.pti
;
1411 if (ti
== GetW32ThreadInfo())
1412 { // We are current.
1413 //FIXME("Current!\n");
1415 *lpdwProcessId
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueProcess
;
1416 Ret
= (DWORD_PTR
)NtCurrentTeb()->ClientId
.UniqueThread
;
1419 { // Ask kernel for info.
1420 //FIXME("Kernel call!\n");
1422 *lpdwProcessId
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_PROCESS_ID
);
1423 Ret
= NtUserQueryWindow(hWnd
, QUERY_WINDOW_UNIQUE_THREAD_ID
);
1434 IsChild(HWND hWndParent
,
1437 PWND WndParent
, DesktopWnd
, Wnd
;
1440 WndParent
= ValidateHwnd(hWndParent
);
1443 Wnd
= ValidateHwnd(hWnd
);
1447 DesktopWnd
= GetThreadDesktopWnd();
1453 while (Wnd
!= NULL
&& ((Wnd
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
1455 if (Wnd
->spwndParent
!= NULL
)
1457 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1459 if (Wnd
== WndParent
)
1469 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1485 PWND Wnd
= ValidateHwnd(hWnd
);
1488 return (Wnd
->style
& WS_MINIMIZE
) != 0;
1500 PWND Wnd
= ValidateHwndNoErr(hWnd
);
1503 /* FIXME: If window is being destroyed return FALSE! */
1515 IsWindowUnicode(HWND hWnd
)
1517 PWND Wnd
= ValidateHwnd(hWnd
);
1520 return Wnd
->Unicode
;
1530 IsWindowVisible(HWND hWnd
)
1533 PWND Wnd
= ValidateHwnd(hWnd
);
1543 if (!(Wnd
->style
& WS_VISIBLE
))
1549 if (Wnd
->spwndParent
!= NULL
)
1550 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1554 } while (Wnd
!= NULL
);
1556 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1571 IsWindowEnabled(HWND hWnd
)
1573 // AG: I don't know if child windows are affected if the parent is
1574 // disabled. I think they stop processing messages but stay appearing
1577 return !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_DISABLED
);
1587 return (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
1595 LockSetForegroundWindow(UINT uLockCode
)
1606 AnimateWindow(HWND hwnd
,
1610 /* FIXME Add animation code */
1612 /* If trying to show/hide and it's already *
1613 * shown/hidden or invalid window, fail with *
1614 * invalid parameter */
1617 visible
= IsWindowVisible(hwnd
);
1618 if(!IsWindow(hwnd
) ||
1619 (visible
&& !(dwFlags
& AW_HIDE
)) ||
1620 (!visible
&& (dwFlags
& AW_HIDE
)))
1622 SetLastError(ERROR_INVALID_PARAMETER
);
1626 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1638 if (!(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1641 ShowWindow(hWnd
,SW_RESTORE
);
1650 RealChildWindowFromPoint(HWND hwndParent
,
1651 POINT ptParentClientCoords
)
1653 return ChildWindowFromPointEx(hwndParent
, ptParentClientCoords
, CWP_SKIPTRANSPARENT
);
1660 SetForegroundWindow(HWND hWnd
)
1662 return NtUserCallHwndLock(hWnd
, HWNDLOCK_ROUTINE_SETFOREGROUNDWINDOW
);
1670 SetProcessDefaultLayout(DWORD dwDefaultLayout
)
1672 if (dwDefaultLayout
== 0)
1684 SetWindowTextA(HWND hWnd
,
1688 if(!GetWindowThreadProcessId(hWnd
, &ProcessId
))
1693 if(ProcessId
!= GetCurrentProcessId())
1695 /* do not send WM_GETTEXT messages to other processes */
1697 DefSetText(hWnd
, (PCWSTR
)lpString
, TRUE
);
1699 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1701 DefWndNCPaint(hWnd
, (HRGN
)1, -1);
1706 return SendMessageA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1714 SetWindowTextW(HWND hWnd
,
1718 if(!GetWindowThreadProcessId(hWnd
, &ProcessId
))
1723 if(ProcessId
!= GetCurrentProcessId())
1725 /* do not send WM_GETTEXT messages to other processes */
1727 DefSetText(hWnd
, lpString
, FALSE
);
1729 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1731 DefWndNCPaint(hWnd
, (HRGN
)1, -1);
1736 return SendMessageW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1744 ShowOwnedPopups(HWND hWnd
,
1747 return (BOOL
)NtUserCallTwoParam((DWORD_PTR
)hWnd
, fShow
, TWOPARAM_ROUTINE_SHOWOWNEDPOPUPS
);
1755 UpdateLayeredWindow( HWND hwnd
,
1765 if ( dwFlags
& ULW_EX_NORESIZE
)
1766 dwFlags
= ~(ULW_EX_NORESIZE
|ULW_OPAQUE
|ULW_ALPHA
|ULW_COLORKEY
);
1767 return NtUserUpdateLayeredWindow( hwnd
,
1783 UpdateLayeredWindowIndirect(HWND hwnd
,
1784 const UPDATELAYEREDWINDOWINFO
*info
)
1786 if (info
&& info
->cbSize
== sizeof(info
))
1788 return NtUserUpdateLayeredWindow( hwnd
,
1790 (POINT
*)info
->pptDst
,
1791 (SIZE
*)info
->psize
,
1793 (POINT
*)info
->pptSrc
,
1795 (BLENDFUNCTION
*)info
->pblend
,
1797 (RECT
*)info
->prcDirty
);
1799 SetLastError(ERROR_INVALID_PARAMETER
);
1808 WindowFromPoint(POINT Point
)
1810 //TODO: Determine what the actual parameters to
1811 // NtUserWindowFromPoint are.
1812 return NtUserWindowFromPoint(Point
.x
, Point
.y
);
1820 MapWindowPoints(HWND hWndFrom
, HWND hWndTo
, LPPOINT lpPoints
, UINT cPoints
)
1822 PWND FromWnd
, ToWnd
;
1826 FromWnd
= ValidateHwndOrDesk(hWndFrom
);
1830 ToWnd
= ValidateHwndOrDesk(hWndTo
);
1834 Delta
.x
= FromWnd
->rcClient
.left
- ToWnd
->rcClient
.left
;
1835 Delta
.y
= FromWnd
->rcClient
.top
- ToWnd
->rcClient
.top
;
1837 for (i
= 0; i
!= cPoints
; i
++)
1839 lpPoints
[i
].x
+= Delta
.x
;
1840 lpPoints
[i
].y
+= Delta
.y
;
1843 return MAKELONG(LOWORD(Delta
.x
), LOWORD(Delta
.y
));
1851 ScreenToClient(HWND hWnd
, LPPOINT lpPoint
)
1853 PWND Wnd
, DesktopWnd
;
1855 Wnd
= ValidateHwnd(hWnd
);
1859 DesktopWnd
= GetThreadDesktopWnd();
1861 lpPoint
->x
+= DesktopWnd
->rcClient
.left
- Wnd
->rcClient
.left
;
1862 lpPoint
->y
+= DesktopWnd
->rcClient
.top
- Wnd
->rcClient
.top
;
1872 ClientToScreen(HWND hWnd
, LPPOINT lpPoint
)
1874 PWND Wnd
, DesktopWnd
;
1876 Wnd
= ValidateHwnd(hWnd
);
1880 DesktopWnd
= GetThreadDesktopWnd();
1882 lpPoint
->x
+= Wnd
->rcClient
.left
- DesktopWnd
->rcClient
.left
;
1883 lpPoint
->y
+= Wnd
->rcClient
.top
- DesktopWnd
->rcClient
.top
;
1893 SetWindowContextHelpId(HWND hwnd
,
1894 DWORD dwContextHelpId
)
1896 return NtUserSetWindowContextHelpId(hwnd
, dwContextHelpId
);
1904 GetWindowContextHelpId(HWND hwnd
)
1906 return NtUserCallHwnd(hwnd
, HWND_ROUTINE_GETWNDCONTEXTHLPID
);
1913 InternalGetWindowText(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1915 INT Ret
= NtUserInternalGetWindowText(hWnd
, lpString
, nMaxCount
);
1925 IsHungAppWindow(HWND hwnd
)
1927 return (NtUserQueryWindow(hwnd
, QUERY_WINDOW_ISHUNG
) != 0);
1934 SetLastErrorEx(DWORD dwErrCode
, DWORD dwType
)
1936 SetLastError(dwErrCode
);
1945 return (HWND
)NtUserGetThreadState(THREADSTATE_FOCUSWINDOW
);
1949 GetRealWindowOwner(HWND hwnd
)
1951 return NtUserQueryWindow(hwnd
, QUERY_WINDOW_REAL_ID
);
1958 SetTaskmanWindow(HWND hWnd
)
1960 return NtUserCallHwndOpt(hWnd
, HWNDOPT_ROUTINE_SETTASKMANWINDOW
);
1967 SetProgmanWindow(HWND hWnd
)
1969 return NtUserCallHwndOpt(hWnd
, HWNDOPT_ROUTINE_SETPROGMANWINDOW
);
1976 GetProgmanWindow(VOID
)
1978 return (HWND
)NtUserGetThreadState(THREADSTATE_PROGMANWINDOW
);
1985 GetTaskmanWindow(VOID
)
1987 return (HWND
)NtUserGetThreadState(THREADSTATE_TASKMANWINDOW
);
1994 ScrollWindow(HWND hWnd
,
1998 CONST RECT
*prcClip
)
2000 return NtUserScrollWindowEx(hWnd
,
2007 (lpRect
? 0 : SW_SCROLLCHILDREN
) | SW_INVALIDATE
) != ERROR
;
2015 ScrollWindowEx(HWND hWnd
,
2018 CONST RECT
*prcScroll
,
2019 CONST RECT
*prcClip
,
2024 return NtUserScrollWindowEx(hWnd
,
2042 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
2044 if (!list
) return FALSE
;
2045 for (i
= 0; list
[i
]; i
++)
2047 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
2049 retvalue
= (list
[i
] != 0);
2050 HeapFree( GetProcessHeap(), 0, list
);
2058 IsWindowInDestroy(HWND hWnd
)
2061 pwnd
= ValidateHwnd(hWnd
);
2064 return ((pwnd
->state2
& WNDS2_INDESTROY
) == WNDS2_INDESTROY
);
2071 DisableProcessWindowsGhosting(VOID
)
2073 NtUserEnableProcessWindowGhosting(FALSE
);