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");
32 CallbackArgs
= (PSENDASYNCPROC_CALLBACK_ARGUMENTS
)Arguments
;
34 if (ArgumentLength
!= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
))
36 return(STATUS_INFO_LENGTH_MISMATCH
);
39 CallbackArgs
->Callback(CallbackArgs
->Wnd
,
41 CallbackArgs
->Context
,
42 CallbackArgs
->Result
);
43 return(STATUS_SUCCESS
);
51 AllowSetForegroundWindow(DWORD dwProcessId
)
53 static BOOL show_message
= TRUE
;
67 BeginDeferWindowPos(int nNumWindows
)
71 SetLastError(ERROR_INVALID_PARAMETER
);
87 BringWindowToTop(HWND hWnd
)
89 return NtUserSetWindowPos(hWnd
,
95 SWP_NOSIZE
| SWP_NOMOVE
);
100 SwitchToThisWindow(HWND hwnd
, BOOL fUnknown
)
102 ShowWindow(hwnd
, SW_SHOW
);
110 ChildWindowFromPoint(HWND hWndParent
,
113 return (HWND
) NtUserChildWindowFromPointEx(hWndParent
, Point
.x
, Point
.y
, 0);
121 ChildWindowFromPointEx(HWND hwndParent
,
125 return (HWND
) NtUserChildWindowFromPointEx(hwndParent
, pt
.x
, pt
.y
, uFlags
);
133 CloseWindow(HWND hWnd
)
135 SendMessageA(hWnd
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
143 OUT PLARGE_STRING plstr
,
149 RtlInitLargeUnicodeString((PLARGE_UNICODE_STRING
)plstr
, (PWSTR
)psz
, 0);
153 RtlInitLargeAnsiString((PLARGE_ANSI_STRING
)plstr
, (PSTR
)psz
, 0);
160 IN PLARGE_STRING LargeString
)
162 if (LargeString
->Buffer
)
164 RtlFreeHeap(GetProcessHeap(), 0, LargeString
->Buffer
);
165 RtlZeroMemory(LargeString
, sizeof(LARGE_STRING
));
170 User32CreateWindowEx(DWORD dwExStyle
,
184 LARGE_STRING WindowName
;
185 LARGE_STRING lstrClassName
, *plstrClassName
;
186 UNICODE_STRING ClassName
;
192 DbgPrint("[window] User32CreateWindowEx style %d, exstyle %d, parent %d\n", dwStyle
, dwExStyle
, hWndParent
);
195 if (!RegisterDefaultClasses
)
197 ERR("User32CreateWindowEx RegisterSystemControls\n");
198 RegisterSystemControls();
201 if (IS_ATOM(lpClassName
))
203 plstrClassName
= (PVOID
)lpClassName
;
208 RtlInitUnicodeString(&ClassName
, (PCWSTR
)lpClassName
);
211 if (!RtlCreateUnicodeStringFromAsciiz(&ClassName
, (PCSZ
)lpClassName
))
213 SetLastError(ERROR_OUTOFMEMORY
);
218 /* Copy it to a LARGE_STRING */
219 lstrClassName
.Buffer
= ClassName
.Buffer
;
220 lstrClassName
.Length
= ClassName
.Length
;
221 lstrClassName
.MaximumLength
= ClassName
.MaximumLength
;
222 plstrClassName
= &lstrClassName
;
225 /* Initialize a LARGE_STRING */
226 RtlInitLargeString(&WindowName
, lpWindowName
, Unicode
);
228 // HACK: The current implementation expects the Window name to be UNICODE
232 PSTR AnsiBuffer
= WindowName
.Buffer
;
233 ULONG AnsiLength
= WindowName
.Length
;
235 WindowName
.Length
= 0;
236 WindowName
.MaximumLength
= AnsiLength
* sizeof(WCHAR
);
237 WindowName
.Buffer
= RtlAllocateHeap(RtlGetProcessHeap(),
239 WindowName
.MaximumLength
);
240 if (!WindowName
.Buffer
)
242 SetLastError(ERROR_OUTOFMEMORY
);
246 Status
= RtlMultiByteToUnicodeN(WindowName
.Buffer
,
247 WindowName
.MaximumLength
,
251 if (!NT_SUCCESS(Status
))
257 if(!hMenu
&& (dwStyle
& (WS_OVERLAPPEDWINDOW
| WS_POPUP
)))
261 wceW
.cbSize
= sizeof(WNDCLASSEXW
);
262 if(GetClassInfoExW(hInstance
, (LPCWSTR
)lpClassName
, &wceW
) && wceW
.lpszMenuName
)
264 hMenu
= LoadMenuW(hInstance
, wceW
.lpszMenuName
);
269 wceA
.cbSize
= sizeof(WNDCLASSEXA
);
270 if(GetClassInfoExA(hInstance
, lpClassName
, &wceA
) && wceA
.lpszMenuName
)
272 hMenu
= LoadMenuA(hInstance
, wceA
.lpszMenuName
);
277 if (!Unicode
) dwExStyle
|= WS_EX_SETANSICREATOR
;
279 Handle
= NtUserCreateWindowEx(dwExStyle
,
296 DbgPrint("[window] NtUserCreateWindowEx() == %d\n", Handle
);
301 if (!IS_ATOM(lpClassName
))
303 RtlFreeUnicodeString(&ClassName
);
306 RtlFreeLargeString(&WindowName
);
317 CreateWindowExA(DWORD dwExStyle
,
330 MDICREATESTRUCTA mdi
;
333 if (!RegisterDefaultClasses
)
335 ERR("CreateWindowExA RegisterSystemControls\n");
336 RegisterSystemControls();
339 if (dwExStyle
& WS_EX_MDICHILD
)
347 if(!(WndParent
= ValidateHwnd(hWndParent
)) ||
348 !(pcls
= DesktopPtrToUser(WndParent
->pcls
)))
351 if (pcls
->fnid
!= FNID_MDICLIENT
)
353 ERR("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
357 /* lpParams of WM_[NC]CREATE is different for MDI children.
358 * MDICREATESTRUCT members have the originally passed values.
360 mdi
.szClass
= lpClassName
;
361 mdi
.szTitle
= lpWindowName
;
362 mdi
.hOwner
= hInstance
;
368 mdi
.lParam
= (LPARAM
)lpParam
;
370 lpParam
= (LPVOID
)&mdi
;
372 if (GetWindowLongPtrW(hWndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
374 if (dwStyle
& WS_POPUP
)
376 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
379 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
383 dwStyle
&= ~WS_POPUP
;
384 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
385 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
388 top_child
= GetWindow(hWndParent
, GW_CHILD
);
392 /* Restore current maximized child */
393 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
395 TRACE("Restoring current maximized child %p\n", top_child
);
396 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
397 ShowWindow(top_child
, SW_RESTORE
);
398 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
402 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
404 if (!(dwStyle
& WS_POPUP
)) hMenu
= (HMENU
)id
;
406 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
408 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
413 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
415 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
420 hwnd
= User32CreateWindowEx(dwExStyle
,
441 CreateWindowExW(DWORD dwExStyle
,
443 LPCWSTR lpWindowName
,
454 MDICREATESTRUCTW mdi
;
457 if (!RegisterDefaultClasses
)
459 ERR("CreateWindowExW RegisterSystemControls\n");
460 RegisterSystemControls();
463 if (dwExStyle
& WS_EX_MDICHILD
)
471 WndParent
= ValidateHwnd(hWndParent
);
476 pcls
= DesktopPtrToUser(WndParent
->pcls
);
481 if (pcls
->fnid
!= FNID_MDICLIENT
)
483 ERR("WS_EX_MDICHILD, but parent %p is not MDIClient\n", hWndParent
);
487 /* lpParams of WM_[NC]CREATE is different for MDI children.
488 * MDICREATESTRUCT members have the originally passed values.
490 mdi
.szClass
= lpClassName
;
491 mdi
.szTitle
= lpWindowName
;
492 mdi
.hOwner
= hInstance
;
498 mdi
.lParam
= (LPARAM
)lpParam
;
500 lpParam
= (LPVOID
)&mdi
;
502 if (GetWindowLongPtrW(hWndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
504 if (dwStyle
& WS_POPUP
)
506 WARN("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
509 dwStyle
|= (WS_CHILD
| WS_CLIPSIBLINGS
);
513 dwStyle
&= ~WS_POPUP
;
514 dwStyle
|= (WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
515 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
);
518 top_child
= GetWindow(hWndParent
, GW_CHILD
);
522 /* Restore current maximized child */
523 if((dwStyle
& WS_VISIBLE
) && IsZoomed(top_child
))
525 TRACE("Restoring current maximized child %p\n", top_child
);
526 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
527 ShowWindow(top_child
, SW_RESTORE
);
528 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
532 MDI_CalcDefaultChildPos(hWndParent
, -1, mPos
, 0, &id
);
534 if (!(dwStyle
& WS_POPUP
)) hMenu
= (HMENU
)id
;
536 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
538 if (x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
543 if (nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
|| !nWidth
)
545 if (nHeight
== CW_USEDEFAULT
|| nHeight
== CW_USEDEFAULT16
|| !nHeight
)
550 hwnd
= User32CreateWindowEx(dwExStyle
,
551 (LPCSTR
) lpClassName
,
552 (LPCSTR
) lpWindowName
,
570 DeferWindowPos(HDWP hWinPosInfo
,
572 HWND hWndInsertAfter
,
580 return NtUserDeferWindowPos(hWinPosInfo
, hWnd
, hWndInsertAfter
, x
, y
, cx
, cy
, uFlags
);
582 SetWindowPos(hWnd
, hWndInsertAfter
, x
, y
, cx
, cy
, uFlags
);
592 EndDeferWindowPos(HDWP hWinPosInfo
)
607 GetDesktopWindow(VOID
)
614 Wnd
= GetThreadDesktopWnd();
616 Ret
= UserHMGetHandle(Wnd
);
618 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
629 User32EnumWindows(HDESK hDesktop
,
636 DWORD i
, dwCount
= 0;
643 SetLastError ( ERROR_INVALID_PARAMETER
);
647 /* FIXME instead of always making two calls, should we use some
648 sort of persistent buffer and only grow it ( requiring a 2nd
649 call ) when the buffer wasn't already big enough? */
650 /* first get how many window entries there are */
651 Status
= NtUserBuildHwndList(hDesktop
,
658 if (!NT_SUCCESS(Status
))
661 /* allocate buffer to receive HWND handles */
662 hHeap
= GetProcessHeap();
663 pHwnd
= HeapAlloc(hHeap
, 0, sizeof(HWND
)*(dwCount
+1));
666 SetLastError ( ERROR_NOT_ENOUGH_MEMORY
);
670 /* now call kernel again to fill the buffer this time */
671 Status
= NtUserBuildHwndList(hDesktop
,
678 if (!NT_SUCCESS(Status
))
681 HeapFree(hHeap
, 0, pHwnd
);
685 /* call the user's callback function until we're done or
686 they tell us to quit */
687 for ( i
= 0; i
< dwCount
; i
++ )
689 /* FIXME I'm only getting NULLs from Thread Enumeration, and it's
690 * probably because I'm not doing it right in NtUserBuildHwndList.
691 * Once that's fixed, we shouldn't have to check for a NULL HWND
694 if (!(ULONG
)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_CHILD
)
1034 if (Wnd
->spwndParent
!= NULL
)
1035 WndParent
= DesktopPtrToUser(Wnd
->spwndParent
);
1037 else if (Wnd
->style
& WS_POPUP
)
1039 if (Wnd
->spwndOwner
!= NULL
)
1040 WndParent
= DesktopPtrToUser(Wnd
->spwndOwner
);
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
)NtCurrentTeb()->ClientId
.UniqueProcess
;
1445 Ret
= (DWORD
)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
, Wnd
;
1469 WndParent
= ValidateHwnd(hWndParent
);
1472 Wnd
= ValidateHwnd(hWnd
);
1480 if (Wnd
->spwndParent
!= NULL
)
1482 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1483 if (Wnd
== WndParent
)
1493 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1509 PWND Wnd
= ValidateHwnd(hWnd
);
1512 return (Wnd
->style
& WS_MINIMIZE
) != 0;
1524 PWND Wnd
= ValidateHwndNoErr(hWnd
);
1527 /* FIXME: If window is being destroyed return FALSE! */
1539 IsWindowUnicode(HWND hWnd
)
1541 PWND Wnd
= ValidateHwnd(hWnd
);
1544 return Wnd
->Unicode
;
1554 IsWindowVisible(HWND hWnd
)
1557 PWND Wnd
= ValidateHwnd(hWnd
);
1567 if (!(Wnd
->style
& WS_VISIBLE
))
1573 if (Wnd
->spwndParent
!= NULL
)
1574 Wnd
= DesktopPtrToUser(Wnd
->spwndParent
);
1578 } while (Wnd
!= NULL
);
1580 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1595 IsWindowEnabled(HWND hWnd
)
1597 // AG: I don't know if child windows are affected if the parent is
1598 // disabled. I think they stop processing messages but stay appearing
1601 return !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_DISABLED
);
1611 return (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
1619 LockSetForegroundWindow(UINT uLockCode
)
1630 AnimateWindow(HWND hwnd
,
1634 /* FIXME Add animation code */
1636 /* If trying to show/hide and it's already *
1637 * shown/hidden or invalid window, fail with *
1638 * invalid parameter */
1641 visible
= IsWindowVisible(hwnd
);
1642 if(!IsWindow(hwnd
) ||
1643 (visible
&& !(dwFlags
& AW_HIDE
)) ||
1644 (!visible
&& (dwFlags
& AW_HIDE
)))
1646 SetLastError(ERROR_INVALID_PARAMETER
);
1650 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1662 if (!(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1665 ShowWindow(hWnd
,SW_RESTORE
);
1674 RealChildWindowFromPoint(HWND hwndParent
,
1675 POINT ptParentClientCoords
)
1677 return ChildWindowFromPointEx(hwndParent
, ptParentClientCoords
, CWP_SKIPTRANSPARENT
);
1684 SetForegroundWindow(HWND hWnd
)
1686 return NtUserCallHwndLock(hWnd
, HWNDLOCK_ROUTINE_SETFOREGROUNDWINDOW
);
1694 SetProcessDefaultLayout(DWORD dwDefaultLayout
)
1696 if (dwDefaultLayout
== 0)
1708 SetWindowTextA(HWND hWnd
,
1712 if(!GetWindowThreadProcessId(hWnd
, &ProcessId
))
1717 if(ProcessId
!= GetCurrentProcessId())
1719 /* do not send WM_GETTEXT messages to other processes */
1721 DefSetText(hWnd
, (PCWSTR
)lpString
, TRUE
);
1723 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1725 DefWndNCPaint(hWnd
, (HRGN
)1, -1);
1730 return SendMessageA(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1738 SetWindowTextW(HWND hWnd
,
1742 if(!GetWindowThreadProcessId(hWnd
, &ProcessId
))
1747 if(ProcessId
!= GetCurrentProcessId())
1749 /* do not send WM_GETTEXT messages to other processes */
1751 DefSetText(hWnd
, lpString
, FALSE
);
1753 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1755 DefWndNCPaint(hWnd
, (HRGN
)1, -1);
1760 return SendMessageW(hWnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
1768 ShowOwnedPopups(HWND hWnd
,
1771 return (BOOL
)NtUserCallTwoParam((DWORD_PTR
)hWnd
, fShow
, TWOPARAM_ROUTINE_SHOWOWNEDPOPUPS
);
1779 UpdateLayeredWindow( HWND hwnd
,
1789 if ( dwFlags
& ULW_EX_NORESIZE
)
1790 dwFlags
= ~(ULW_EX_NORESIZE
|ULW_OPAQUE
|ULW_ALPHA
|ULW_COLORKEY
);
1791 return NtUserUpdateLayeredWindow( hwnd
,
1807 UpdateLayeredWindowIndirect(HWND hwnd
,
1808 const UPDATELAYEREDWINDOWINFO
*info
)
1810 if (info
&& info
->cbSize
== sizeof(info
))
1812 return NtUserUpdateLayeredWindow( hwnd
,
1814 (POINT
*)info
->pptDst
,
1815 (SIZE
*)info
->psize
,
1817 (POINT
*)info
->pptSrc
,
1819 (BLENDFUNCTION
*)info
->pblend
,
1821 (RECT
*)info
->prcDirty
);
1823 SetLastError(ERROR_INVALID_PARAMETER
);
1832 WindowFromPoint(POINT Point
)
1834 //TODO: Determine what the actual parameters to
1835 // NtUserWindowFromPoint are.
1836 return NtUserWindowFromPoint(Point
.x
, Point
.y
);
1844 MapWindowPoints(HWND hWndFrom
, HWND hWndTo
, LPPOINT lpPoints
, UINT cPoints
)
1846 PWND FromWnd
, ToWnd
;
1850 FromWnd
= ValidateHwndOrDesk(hWndFrom
);
1854 ToWnd
= ValidateHwndOrDesk(hWndTo
);
1858 Delta
.x
= FromWnd
->rcClient
.left
- ToWnd
->rcClient
.left
;
1859 Delta
.y
= FromWnd
->rcClient
.top
- ToWnd
->rcClient
.top
;
1861 for (i
= 0; i
!= cPoints
; i
++)
1863 lpPoints
[i
].x
+= Delta
.x
;
1864 lpPoints
[i
].y
+= Delta
.y
;
1867 return MAKELONG(LOWORD(Delta
.x
), LOWORD(Delta
.y
));
1875 ScreenToClient(HWND hWnd
, LPPOINT lpPoint
)
1877 PWND Wnd
, DesktopWnd
;
1879 Wnd
= ValidateHwnd(hWnd
);
1883 DesktopWnd
= GetThreadDesktopWnd();
1885 lpPoint
->x
+= DesktopWnd
->rcClient
.left
- Wnd
->rcClient
.left
;
1886 lpPoint
->y
+= DesktopWnd
->rcClient
.top
- Wnd
->rcClient
.top
;
1896 ClientToScreen(HWND hWnd
, LPPOINT lpPoint
)
1898 PWND Wnd
, DesktopWnd
;
1900 Wnd
= ValidateHwnd(hWnd
);
1904 DesktopWnd
= GetThreadDesktopWnd();
1906 lpPoint
->x
+= Wnd
->rcClient
.left
- DesktopWnd
->rcClient
.left
;
1907 lpPoint
->y
+= Wnd
->rcClient
.top
- DesktopWnd
->rcClient
.top
;
1917 SetWindowContextHelpId(HWND hwnd
,
1918 DWORD dwContextHelpId
)
1920 return NtUserSetWindowContextHelpId(hwnd
, dwContextHelpId
);
1928 GetWindowContextHelpId(HWND hwnd
)
1930 return NtUserCallHwnd(hwnd
, HWND_ROUTINE_GETWNDCONTEXTHLPID
);
1937 InternalGetWindowText(HWND hWnd
, LPWSTR lpString
, int nMaxCount
)
1939 INT Ret
= NtUserInternalGetWindowText(hWnd
, lpString
, nMaxCount
);
1949 IsHungAppWindow(HWND hwnd
)
1951 return (NtUserQueryWindow(hwnd
, QUERY_WINDOW_ISHUNG
) != 0);
1958 SetLastErrorEx(DWORD dwErrCode
, DWORD dwType
)
1960 SetLastError(dwErrCode
);
1969 return (HWND
)NtUserGetThreadState(THREADSTATE_FOCUSWINDOW
);
1973 GetRealWindowOwner(HWND hwnd
)
1975 return NtUserQueryWindow(hwnd
, QUERY_WINDOW_REAL_ID
);
1982 SetTaskmanWindow(HWND hWnd
)
1984 return NtUserCallHwndOpt(hWnd
, HWNDOPT_ROUTINE_SETTASKMANWINDOW
);
1991 SetProgmanWindow(HWND hWnd
)
1993 return NtUserCallHwndOpt(hWnd
, HWNDOPT_ROUTINE_SETPROGMANWINDOW
);
2000 GetProgmanWindow(VOID
)
2002 return (HWND
)NtUserGetThreadState(THREADSTATE_PROGMANWINDOW
);
2009 GetTaskmanWindow(VOID
)
2011 return (HWND
)NtUserGetThreadState(THREADSTATE_TASKMANWINDOW
);
2018 ScrollWindow(HWND hWnd
,
2022 CONST RECT
*prcClip
)
2024 return NtUserScrollWindowEx(hWnd
,
2031 (lpRect
? 0 : SW_SCROLLCHILDREN
) | SW_INVALIDATE
) != ERROR
;
2039 ScrollWindowEx(HWND hWnd
,
2042 CONST RECT
*prcScroll
,
2043 CONST RECT
*prcClip
,
2048 return NtUserScrollWindowEx(hWnd
,
2064 return NtUserAnyPopup();
2071 IsWindowInDestroy(HWND hWnd
)
2073 return NtUserIsWindowInDestroy(hWnd
);
2080 DisableProcessWindowsGhosting(VOID
)
2082 NtUserEnableProcessWindowGhosting(FALSE
);