1 /* $Id: window.c,v 1.12 2002/09/07 15:12:45 chorns Exp $
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS user32.dll
5 * FILE: lib/user32/windows/window.c
6 * PURPOSE: Window management
7 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
9 * 06-06-2001 CSH Created
12 /* INCLUDES ******************************************************************/
16 /* FUNCTIONS *****************************************************************/
19 User32SendNCCALCSIZEMessageForKernel(PVOID Arguments
, ULONG ArgumentLength
)
21 PSENDNCCALCSIZEMESSAGE_CALLBACK_ARGUMENTS CallbackArgs
;
22 SENDNCCALCSIZEMESSAGE_CALLBACK_RESULT Result
;
25 DbgPrint("User32SendNCCALCSIZEMessageForKernel.\n");
26 CallbackArgs
= (PSENDNCCALCSIZEMESSAGE_CALLBACK_ARGUMENTS
)Arguments
;
27 if (ArgumentLength
!= sizeof(SENDNCCALCSIZEMESSAGE_CALLBACK_ARGUMENTS
))
29 DbgPrint("Wrong length.\n");
30 return(STATUS_INFO_LENGTH_MISMATCH
);
32 Proc
= (WNDPROC
)GetWindowLongW(CallbackArgs
->Wnd
, GWL_WNDPROC
);
33 DbgPrint("Proc %X\n", Proc
);
34 /* Call the window procedure; notice kernel messages are always unicode. */
35 if (CallbackArgs
->Validate
)
37 Result
.Result
= CallWindowProcW(Proc
, CallbackArgs
->Wnd
, WM_NCCALCSIZE
,
39 (LPARAM
)&CallbackArgs
->Params
);
40 Result
.Params
= CallbackArgs
->Params
;
44 Result
.Result
= CallWindowProcW(Proc
, CallbackArgs
->Wnd
, WM_NCCALCSIZE
,
45 FALSE
, (LPARAM
)&CallbackArgs
->Rect
);
46 Result
.Rect
= CallbackArgs
->Rect
;
48 DbgPrint("Returning result %d.\n", Result
);
49 ZwCallbackReturn(&Result
, sizeof(Result
), STATUS_SUCCESS
);
54 User32SendGETMINMAXINFOMessageForKernel(PVOID Arguments
, ULONG ArgumentLength
)
56 PSENDGETMINMAXINFO_CALLBACK_ARGUMENTS CallbackArgs
;
57 SENDGETMINMAXINFO_CALLBACK_RESULT Result
;
60 DbgPrint("User32SendGETMINAXINFOMessageForKernel.\n");
61 CallbackArgs
= (PSENDGETMINMAXINFO_CALLBACK_ARGUMENTS
)Arguments
;
62 if (ArgumentLength
!= sizeof(SENDGETMINMAXINFO_CALLBACK_ARGUMENTS
))
64 DbgPrint("Wrong length.\n");
65 return(STATUS_INFO_LENGTH_MISMATCH
);
67 Proc
= (WNDPROC
)GetWindowLongW(CallbackArgs
->Wnd
, GWL_WNDPROC
);
68 DbgPrint("Proc %X\n", Proc
);
69 /* Call the window procedure; notice kernel messages are always unicode. */
70 Result
.Result
= CallWindowProcW(Proc
, CallbackArgs
->Wnd
, WM_GETMINMAXINFO
,
71 0, (LPARAM
)&CallbackArgs
->MinMaxInfo
);
72 Result
.MinMaxInfo
= CallbackArgs
->MinMaxInfo
;
73 DbgPrint("Returning result %d.\n", Result
);
74 ZwCallbackReturn(&Result
, sizeof(Result
), STATUS_SUCCESS
);
79 User32SendCREATEMessageForKernel(PVOID Arguments
, ULONG ArgumentLength
)
81 PSENDCREATEMESSAGE_CALLBACK_ARGUMENTS CallbackArgs
;
85 DbgPrint("User32SendCREATEMessageForKernel.\n");
86 CallbackArgs
= (PSENDCREATEMESSAGE_CALLBACK_ARGUMENTS
)Arguments
;
87 if (ArgumentLength
!= sizeof(SENDCREATEMESSAGE_CALLBACK_ARGUMENTS
))
89 DbgPrint("Wrong length.\n");
90 return(STATUS_INFO_LENGTH_MISMATCH
);
92 Proc
= (WNDPROC
)GetWindowLongW(CallbackArgs
->Wnd
, GWL_WNDPROC
);
93 DbgPrint("Proc %X\n", Proc
);
94 /* Call the window procedure; notice kernel messages are always unicode. */
95 Result
= CallWindowProcW(Proc
, CallbackArgs
->Wnd
, WM_CREATE
, 0,
96 (LPARAM
)&CallbackArgs
->CreateStruct
);
97 DbgPrint("Returning result %d.\n", Result
);
98 ZwCallbackReturn(&Result
, sizeof(LRESULT
), STATUS_SUCCESS
);
103 User32SendNCCREATEMessageForKernel(PVOID Arguments
, ULONG ArgumentLength
)
105 PSENDNCCREATEMESSAGE_CALLBACK_ARGUMENTS CallbackArgs
;
109 DbgPrint("User32SendNCCREATEMessageForKernel.\n");
110 CallbackArgs
= (PSENDNCCREATEMESSAGE_CALLBACK_ARGUMENTS
)Arguments
;
111 if (ArgumentLength
!= sizeof(SENDNCCREATEMESSAGE_CALLBACK_ARGUMENTS
))
113 DbgPrint("Wrong length.\n");
114 return(STATUS_INFO_LENGTH_MISMATCH
);
116 Proc
= (WNDPROC
)GetWindowLongW(CallbackArgs
->Wnd
, GWL_WNDPROC
);
117 DbgPrint("Proc %X\n", Proc
);
118 /* Call the window procedure; notice kernel messages are always unicode. */
119 Result
= CallWindowProcW(Proc
, CallbackArgs
->Wnd
, WM_NCCREATE
, 0,
120 (LPARAM
)&CallbackArgs
->CreateStruct
);
121 DbgPrint("Returning result %d.\n", Result
);
122 ZwCallbackReturn(&Result
, sizeof(LRESULT
), STATUS_SUCCESS
);
123 /* Doesn't return. */
127 User32CallSendAsyncProcForKernel(PVOID Arguments
, ULONG ArgumentLength
)
129 PSENDASYNCPROC_CALLBACK_ARGUMENTS CallbackArgs
;
131 DbgPrint("User32CallSendAsyncProcKernel()\n");
132 CallbackArgs
= (PSENDASYNCPROC_CALLBACK_ARGUMENTS
)Arguments
;
133 if (ArgumentLength
!= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
))
135 return(STATUS_INFO_LENGTH_MISMATCH
);
137 CallbackArgs
->Callback(CallbackArgs
->Wnd
, CallbackArgs
->Msg
,
138 CallbackArgs
->Context
, CallbackArgs
->Result
);
139 return(STATUS_SUCCESS
);
143 User32CallWindowProcFromKernel(PVOID Arguments
, ULONG ArgumentLength
)
145 PWINDOWPROC_CALLBACK_ARGUMENTS CallbackArgs
;
148 DbgPrint("User32CallWindowProcFromKernel()\n");
149 CallbackArgs
= (PWINDOWPROC_CALLBACK_ARGUMENTS
)Arguments
;
150 if (ArgumentLength
!= sizeof(WINDOWPROC_CALLBACK_ARGUMENTS
))
152 return(STATUS_INFO_LENGTH_MISMATCH
);
154 if (CallbackArgs
->Proc
== NULL
)
156 CallbackArgs
->Proc
= (WNDPROC
)GetWindowLong(CallbackArgs
->Wnd
,
159 DbgPrint("CallbackArgs->Proc %X\n", CallbackArgs
->Proc
);
160 Result
= CallWindowProcW(CallbackArgs
->Proc
, CallbackArgs
->Wnd
,
161 CallbackArgs
->Msg
, CallbackArgs
->wParam
,
162 CallbackArgs
->lParam
);
163 ZwCallbackReturn(&Result
, sizeof(LRESULT
), STATUS_SUCCESS
);
164 /* Doesn't return. */
168 AdjustWindowRect(LPRECT lpRect
,
172 return(AdjustWindowRectEx(lpRect
, dwStyle
, bMenu
, 0));
176 AdjustWindowRectEx(LPRECT lpRect
,
185 AllowSetForegroundWindow(DWORD dwProcessId
)
191 AnimateWindow(HWND hwnd
,
199 ArrangeIconicWindows(HWND hWnd
)
205 BeginDeferWindowPos(int nNumWindows
)
211 BringWindowToTop(HWND hWnd
)
217 CascadeWindows(HWND hwndParent
,
227 ChildWindowFromPoint(HWND hWndParent
,
234 ChildWindowFromPointEx(HWND hwndParent
,
242 CloseWindow(HWND hWnd
)
248 CreateWindowExA(DWORD dwExStyle
,
261 UNICODE_STRING WindowName
;
262 UNICODE_STRING ClassName
;
266 if (IS_ATOM(lpClassName
))
268 RtlInitUnicodeString(&ClassName
, NULL
);
269 ClassName
.Buffer
= (LPWSTR
)lpClassName
;
273 if (!RtlCreateUnicodeStringFromAsciiz(&(ClassName
), (PCSZ
)lpClassName
))
275 SetLastError(ERROR_OUTOFMEMORY
);
280 if (!RtlCreateUnicodeStringFromAsciiz(&WindowName
, (PCSZ
)lpWindowName
))
282 if (!IS_ATOM(lpClassName
))
284 RtlFreeUnicodeString(&ClassName
);
286 SetLastError(ERROR_OUTOFMEMORY
);
290 /* Fixup default coordinates. */
292 if (x
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT
)
294 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
296 if (x
== CW_USEDEFAULT
)
300 if (nWidth
== CW_USEDEFAULT
)
302 nWidth
= nHeight
= 0;
309 GetStartupInfoA(&info
);
311 if (x
== CW_USEDEFAULT
)
313 if (y
!= CW_USEDEFAULT
)
317 x
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwX
: 0;
318 y
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwY
: 0;
321 if (nWidth
== CW_USEDEFAULT
)
323 if (info
.dwFlags
& STARTF_USESIZE
)
325 nWidth
= info
.dwXSize
;
326 nHeight
= info
.dwYSize
;
332 SystemParametersInfoA(SPI_GETWORKAREA
, 0, &r
, 0);
333 nWidth
= (((r
.right
- r
.left
) * 3) / 4) - x
;
334 nHeight
= (((r
.bottom
- r
.top
) * 3) / 4) - y
;
340 Handle
= NtUserCreateWindowEx(dwExStyle
,
354 RtlFreeUnicodeString(&WindowName
);
356 if (!IS_ATOM(lpClassName
))
358 RtlFreeUnicodeString(&ClassName
);
365 CreateWindowExW(DWORD dwExStyle
,
367 LPCWSTR lpWindowName
,
378 UNICODE_STRING WindowName
;
379 UNICODE_STRING ClassName
;
383 if (IS_ATOM(lpClassName
))
385 RtlInitUnicodeString(&ClassName
, NULL
);
386 ClassName
.Buffer
= (LPWSTR
)lpClassName
;
390 RtlInitUnicodeString(&ClassName
, lpClassName
);
393 RtlInitUnicodeString(&WindowName
, lpWindowName
);
395 /* Fixup default coordinates. */
397 if (x
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT
)
399 if (dwStyle
& (WS_CHILD
| WS_POPUP
))
401 if (x
== CW_USEDEFAULT
)
405 if (nWidth
== CW_USEDEFAULT
)
407 nWidth
= nHeight
= 0;
414 GetStartupInfoW(&info
);
416 if (x
== CW_USEDEFAULT
)
418 if (y
!= CW_USEDEFAULT
)
422 x
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwX
: 0;
423 y
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwY
: 0;
426 if (nWidth
== CW_USEDEFAULT
)
428 if (info
.dwFlags
& STARTF_USESIZE
)
430 nWidth
= info
.dwXSize
;
431 nHeight
= info
.dwYSize
;
437 SystemParametersInfoW(SPI_GETWORKAREA
, 0, &r
, 0);
438 nWidth
= (((r
.right
- r
.left
) * 3) / 4) - x
;
439 nHeight
= (((r
.bottom
- r
.top
) * 3) / 4) - y
;
445 Handle
= NtUserCreateWindowEx(dwExStyle
,
463 DeferWindowPos(HDWP hWinPosInfo
,
465 HWND hWndInsertAfter
,
476 DestroyWindow(HWND hWnd
)
482 EndDeferWindowPos(HDWP hWinPosInfo
)
488 EnumChildWindows(HWND hWndParent
,
489 ENUMWINDOWSPROC lpEnumFunc
,
496 EnumThreadWindows(DWORD dwThreadId
,
497 ENUMWINDOWSPROC lpfn
,
504 EnumWindows(ENUMWINDOWSPROC lpEnumFunc
,
511 FindWindowA(LPCSTR lpClassName
, LPCSTR lpWindowName
)
513 //FIXME: FindWindow does not search children, but FindWindowEx does.
514 // what should we do about this?
515 return FindWindowExA (NULL
, NULL
, lpClassName
, lpWindowName
);
519 FindWindowExA(HWND hwndParent
,
528 FindWindowW(LPCWSTR lpClassName
, LPCWSTR lpWindowName
)
530 //FIXME: FindWindow does not search children, but FindWindowEx does.
531 // what should we do about this?
532 return FindWindowExW (NULL
, NULL
, lpClassName
, lpWindowName
);
536 FindWindowExW(HWND hwndParent
,
547 GetAltTabInfo(HWND hwnd
,
553 return GetAltTabInfoA(hwnd
,
561 GetAltTabInfoA(HWND hwnd
,
571 GetAltTabInfoW(HWND hwnd
,
581 GetAncestor(HWND hwnd
, UINT gaFlags
)
583 return(NtUserGetAncestor(hwnd
, gaFlags
));
587 GetClientRect(HWND hWnd
,
594 GetDesktopWindow(VOID
)
600 GetForegroundWindow(VOID
)
606 GetGUIThreadInfo(DWORD idThread
,
607 PGUITHREADINFO lpgui
)
613 GetLastActivePopup(HWND hWnd
)
625 GetProcessDefaultLayout(DWORD
*pdwDefaultLayout
)
631 GetTitleBarInfo(HWND hwnd
,
638 GetTopWindow(HWND hWnd
)
651 GetWindowInfo(HWND hwnd
,
657 #undef GetWindowModuleFileName
660 GetWindowModuleFileName(HWND hwnd
,
664 return GetWindowModuleFileNameA(hwnd
,
670 GetWindowModuleFileNameA(HWND hwnd
,
678 GetWindowModuleFileNameW(HWND hwnd
,
686 GetWindowPlacement(HWND hWnd
,
687 WINDOWPLACEMENT
*lpwndpl
)
693 GetWindowRect(HWND hWnd
,
696 return(NtUserGetWindowRect(hWnd
, lpRect
));
700 GetWindowTextA(HWND hWnd
, LPSTR lpString
, int nMaxCount
)
702 return(SendMessageA(hWnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
));
706 GetWindowTextLengthA(HWND hWnd
)
708 return(SendMessageA(hWnd
, WM_GETTEXTLENGTH
, 0, 0));
712 GetWindowTextLengthW(HWND hWnd
)
718 GetWindowTextW(HWND hWnd
,
726 GetWindowThreadProcessId(HWND hWnd
,
727 LPDWORD lpdwProcessId
)
733 IsChild(HWND hWndParent
,
752 IsWindowUnicode(HWND hWnd
)
758 IsWindowVisible(HWND hWnd
)
760 while (GetWindowLong(hWnd
, GWL_STYLE
) & WS_CHILD
)
762 if (!(GetWindowLong(hWnd
, GWL_STYLE
) & WS_VISIBLE
))
766 hWnd
= GetAncestor(hWnd
, GA_PARENT
);
768 return(GetWindowLong(hWnd
, GWL_STYLE
) & WS_VISIBLE
);
778 LockSetForegroundWindow(UINT uLockCode
)
784 MoveWindow(HWND hWnd
,
801 RealChildWindowFromPoint(HWND hwndParent
,
802 POINT ptParentClientCoords
)
808 RealGetWindowClass(HWND hwnd
,
816 SetForegroundWindow(HWND hWnd
)
822 SetLayeredWindowAttributes(HWND hwnd
,
831 SetParent(HWND hWndChild
,
838 SetProcessDefaultLayout(DWORD dwDefaultLayout
)
844 SetWindowPlacement(HWND hWnd
,
845 CONST WINDOWPLACEMENT
*lpwndpl
)
851 SetWindowPos(HWND hWnd
,
852 HWND hWndInsertAfter
,
863 SetWindowTextA(HWND hWnd
,
870 SetWindowTextW(HWND hWnd
,
877 ShowOwnedPopups(HWND hWnd
,
884 ShowWindow(HWND hWnd
,
887 return NtUserShowWindow(hWnd
, nCmdShow
);
891 ShowWindowAsync(HWND hWnd
,
898 TileWindows(HWND hwndParent
,
908 UpdateLayeredWindow(HWND hwnd
,
915 BLENDFUNCTION
*pblend
,
922 WindowFromPoint(POINT Point
)