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 ******************************************************************/
18 #include <user32/callback.h>
20 /* FUNCTIONS *****************************************************************/
23 User32SendNCCALCSIZEMessageForKernel(PVOID Arguments, ULONG ArgumentLength)
25 PSENDNCCALCSIZEMESSAGE_CALLBACK_ARGUMENTS CallbackArgs;
26 SENDNCCALCSIZEMESSAGE_CALLBACK_RESULT Result;
29 DbgPrint("User32SendNCCALCSIZEMessageForKernel.\n");
30 CallbackArgs = (PSENDNCCALCSIZEMESSAGE_CALLBACK_ARGUMENTS)Arguments;
31 if (ArgumentLength != sizeof(SENDNCCALCSIZEMESSAGE_CALLBACK_ARGUMENTS))
33 DbgPrint("Wrong length.\n");
34 return(STATUS_INFO_LENGTH_MISMATCH);
36 Proc = (WNDPROC)GetWindowLongW(CallbackArgs->Wnd, GWL_WNDPROC);
37 DbgPrint("Proc %X\n", Proc);
38 /* Call the window procedure; notice kernel messages are always unicode. */
39 if (CallbackArgs->Validate)
41 Result.Result = CallWindowProcW(Proc, CallbackArgs->Wnd, WM_NCCALCSIZE,
43 (LPARAM)&CallbackArgs->Params);
44 Result.Params = CallbackArgs->Params;
48 Result.Result = CallWindowProcW(Proc, CallbackArgs->Wnd, WM_NCCALCSIZE,
49 FALSE, (LPARAM)&CallbackArgs->Rect);
50 Result.Rect = CallbackArgs->Rect;
52 DbgPrint("Returning result %d.\n", Result);
53 return(ZwCallbackReturn(&Result, sizeof(Result), STATUS_SUCCESS));
57 User32SendGETMINMAXINFOMessageForKernel(PVOID Arguments, ULONG ArgumentLength)
59 PSENDGETMINMAXINFO_CALLBACK_ARGUMENTS CallbackArgs;
60 SENDGETMINMAXINFO_CALLBACK_RESULT Result;
63 DbgPrint("User32SendGETMINAXINFOMessageForKernel.\n");
64 CallbackArgs = (PSENDGETMINMAXINFO_CALLBACK_ARGUMENTS)Arguments;
65 if (ArgumentLength != sizeof(SENDGETMINMAXINFO_CALLBACK_ARGUMENTS))
67 DbgPrint("Wrong length.\n");
68 return(STATUS_INFO_LENGTH_MISMATCH);
70 Proc = (WNDPROC)GetWindowLongW(CallbackArgs->Wnd, GWL_WNDPROC);
71 DbgPrint("Proc %X\n", Proc);
72 /* Call the window procedure; notice kernel messages are always unicode. */
73 Result.Result = CallWindowProcW(Proc, CallbackArgs->Wnd, WM_GETMINMAXINFO,
74 0, (LPARAM)&CallbackArgs->MinMaxInfo);
75 Result.MinMaxInfo = CallbackArgs->MinMaxInfo;
76 DbgPrint("Returning result %d.\n", Result);
77 return(ZwCallbackReturn(&Result, sizeof(Result), STATUS_SUCCESS));
81 User32SendCREATEMessageForKernel(PVOID Arguments, ULONG ArgumentLength)
83 PSENDCREATEMESSAGE_CALLBACK_ARGUMENTS CallbackArgs;
87 DbgPrint("User32SendCREATEMessageForKernel.\n");
88 CallbackArgs = (PSENDCREATEMESSAGE_CALLBACK_ARGUMENTS)Arguments;
89 if (ArgumentLength != sizeof(SENDCREATEMESSAGE_CALLBACK_ARGUMENTS))
91 DbgPrint("Wrong length.\n");
92 return(STATUS_INFO_LENGTH_MISMATCH);
94 Proc = (WNDPROC)GetWindowLongW(CallbackArgs->Wnd, GWL_WNDPROC);
95 DbgPrint("Proc %X\n", Proc);
96 /* Call the window procedure; notice kernel messages are always unicode. */
97 Result = CallWindowProcW(Proc, CallbackArgs->Wnd, WM_CREATE, 0,
98 (LPARAM)&CallbackArgs->CreateStruct);
99 DbgPrint("Returning result %d.\n", Result);
100 return(ZwCallbackReturn(&Result, sizeof(LRESULT), STATUS_SUCCESS));
104 User32SendNCCREATEMessageForKernel(PVOID Arguments, ULONG ArgumentLength)
106 PSENDNCCREATEMESSAGE_CALLBACK_ARGUMENTS CallbackArgs;
110 DbgPrint("User32SendNCCREATEMessageForKernel.\n");
111 CallbackArgs = (PSENDNCCREATEMESSAGE_CALLBACK_ARGUMENTS)Arguments;
112 if (ArgumentLength != sizeof(SENDNCCREATEMESSAGE_CALLBACK_ARGUMENTS))
114 DbgPrint("Wrong length.\n");
115 return(STATUS_INFO_LENGTH_MISMATCH);
117 Proc = (WNDPROC)GetWindowLongW(CallbackArgs->Wnd, GWL_WNDPROC);
118 DbgPrint("Proc %X\n", Proc);
119 /* Call the window procedure; notice kernel messages are always unicode. */
120 Result = CallWindowProcW(Proc, CallbackArgs->Wnd, WM_NCCREATE, 0,
121 (LPARAM)&CallbackArgs->CreateStruct);
122 DbgPrint("Returning result %d.\n", Result);
123 return(ZwCallbackReturn(&Result, sizeof(LRESULT), STATUS_SUCCESS));
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 CallbackArgs = (PWINDOWPROC_CALLBACK_ARGUMENTS)Arguments;
149 if (ArgumentLength != sizeof(WINDOWPROC_CALLBACK_ARGUMENTS))
151 return(STATUS_INFO_LENGTH_MISMATCH);
153 if (CallbackArgs->Proc == NULL)
155 CallbackArgs->Proc = (WNDPROC)GetWindowLong(CallbackArgs->Wnd,
158 Result = CallWindowProcW(CallbackArgs->Proc, CallbackArgs->Wnd,
159 CallbackArgs->Msg, CallbackArgs->wParam,
160 CallbackArgs->lParam);
161 return(ZwCallbackReturn(&Result, sizeof(LRESULT), STATUS_SUCCESS));
165 AdjustWindowRect(LPRECT lpRect,
169 return(AdjustWindowRectEx(lpRect, dwStyle, bMenu, 0));
173 AdjustWindowRectEx(LPRECT lpRect,
182 AllowSetForegroundWindow(DWORD dwProcessId)
188 AnimateWindow(HWND hwnd,
196 ArrangeIconicWindows(HWND hWnd)
202 BeginDeferWindowPos(int nNumWindows)
208 BringWindowToTop(HWND hWnd)
214 CascadeWindows(HWND hwndParent,
224 ChildWindowFromPoint(HWND hWndParent,
231 ChildWindowFromPointEx(HWND hwndParent,
239 CloseWindow(HWND hWnd)
245 CreateWindowExA(DWORD dwExStyle,
258 UNICODE_STRING WindowName;
259 UNICODE_STRING ClassName;
263 if (IS_ATOM(lpClassName))
265 RtlInitUnicodeString(&ClassName, NULL);
266 ClassName.Buffer = (LPWSTR)lpClassName;
270 if (!RtlCreateUnicodeStringFromAsciiz(&(ClassName), (PCSZ)lpClassName))
272 SetLastError(ERROR_OUTOFMEMORY);
277 if (!RtlCreateUnicodeStringFromAsciiz(&WindowName, (PCSZ)lpWindowName))
279 if (!IS_ATOM(lpClassName))
281 RtlFreeUnicodeString(&ClassName);
283 SetLastError(ERROR_OUTOFMEMORY);
287 /* Fixup default coordinates. */
289 if (x == (LONG) CW_USEDEFAULT || nWidth == (LONG) CW_USEDEFAULT)
291 if (dwStyle & (WS_CHILD | WS_POPUP))
293 if (x == (LONG) CW_USEDEFAULT)
297 if (nWidth == (LONG) CW_USEDEFAULT)
299 nWidth = nHeight = 0;
306 GetStartupInfoA(&info);
308 if (x == (LONG) CW_USEDEFAULT)
310 if (y != (LONG) CW_USEDEFAULT)
314 x = (info.dwFlags & STARTF_USEPOSITION) ? info.dwX : 0;
315 y = (info.dwFlags & STARTF_USEPOSITION) ? info.dwY : 0;
318 if (nWidth == (LONG) CW_USEDEFAULT)
320 if (info.dwFlags & STARTF_USESIZE)
322 nWidth = info.dwXSize;
323 nHeight = info.dwYSize;
329 SystemParametersInfoA(SPI_GETWORKAREA, 0, &r, 0);
330 nWidth = (((r.right - r.left) * 3) / 4) - x;
331 nHeight = (((r.bottom - r.top) * 3) / 4) - y;
337 Handle = NtUserCreateWindowEx(dwExStyle,
351 RtlFreeUnicodeString(&WindowName);
353 if (!IS_ATOM(lpClassName))
355 RtlFreeUnicodeString(&ClassName);
362 CreateWindowExW(DWORD dwExStyle,
364 LPCWSTR lpWindowName,
375 UNICODE_STRING WindowName;
376 UNICODE_STRING ClassName;
380 if (IS_ATOM(lpClassName))
382 RtlInitUnicodeString(&ClassName, NULL);
383 ClassName.Buffer = (LPWSTR)lpClassName;
387 RtlInitUnicodeString(&ClassName, lpClassName);
390 RtlInitUnicodeString(&WindowName, lpWindowName);
392 /* Fixup default coordinates. */
394 if (x == (LONG) CW_USEDEFAULT || nWidth == (LONG) CW_USEDEFAULT)
396 if (dwStyle & (WS_CHILD | WS_POPUP))
398 if (x == (LONG) CW_USEDEFAULT)
402 if (nWidth == (LONG) CW_USEDEFAULT)
404 nWidth = nHeight = 0;
411 GetStartupInfoW(&info);
413 if (x == (LONG) CW_USEDEFAULT)
415 if (y != (LONG) CW_USEDEFAULT)
419 x = (info.dwFlags & STARTF_USEPOSITION) ? info.dwX : 0;
420 y = (info.dwFlags & STARTF_USEPOSITION) ? info.dwY : 0;
423 if (nWidth == (LONG) CW_USEDEFAULT)
425 if (info.dwFlags & STARTF_USESIZE)
427 nWidth = info.dwXSize;
428 nHeight = info.dwYSize;
434 SystemParametersInfoW(SPI_GETWORKAREA, 0, &r, 0);
435 nWidth = (((r.right - r.left) * 3) / 4) - x;
436 nHeight = (((r.bottom - r.top) * 3) / 4) - y;
442 Handle = NtUserCreateWindowEx(dwExStyle,
460 DeferWindowPos(HDWP hWinPosInfo,
462 HWND hWndInsertAfter,
473 DestroyWindow(HWND hWnd)
479 EndDeferWindowPos(HDWP hWinPosInfo)
485 EnumChildWindows(HWND hWndParent,
486 ENUMWINDOWSPROC lpEnumFunc,
493 EnumThreadWindows(DWORD dwThreadId,
494 ENUMWINDOWSPROC lpfn,
501 EnumWindows(ENUMWINDOWSPROC lpEnumFunc,
508 FindWindowA(LPCSTR lpClassName, LPCSTR lpWindowName)
510 //FIXME: FindWindow does not search children, but FindWindowEx does.
511 // what should we do about this?
512 return FindWindowExA (NULL, NULL, lpClassName, lpWindowName);
516 FindWindowExA(HWND hwndParent,
525 FindWindowW(LPCWSTR lpClassName, LPCWSTR lpWindowName)
527 //FIXME: FindWindow does not search children, but FindWindowEx does.
528 // what should we do about this?
529 return FindWindowExW (NULL, NULL, lpClassName, lpWindowName);
533 FindWindowExW(HWND hwndParent,
542 GetAltTabInfo(HWND hwnd,
552 GetAltTabInfoA(HWND hwnd,
562 GetAltTabInfoW(HWND hwnd,
572 GetAncestor(HWND hwnd, UINT gaFlags)
574 return(NtUserGetAncestor(hwnd, gaFlags));
578 GetClientRect(HWND hWnd, LPRECT lpRect)
584 GetDesktopWindow(VOID)
590 GetForegroundWindow(VOID)
596 GetGUIThreadInfo(DWORD idThread,
597 LPGUITHREADINFO lpgui)
603 GetLastActivePopup(HWND hWnd)
615 GetProcessDefaultLayout(DWORD *pdwDefaultLayout)
621 GetTitleBarInfo(HWND hwnd,
628 GetTopWindow(HWND hWnd)
641 GetWindowInfo(HWND hwnd,
648 GetWindowModuleFileName(HWND hwnd,
656 GetWindowModuleFileNameA(HWND hwnd,
664 GetWindowModuleFileNameW(HWND hwnd,
672 GetWindowPlacement(HWND hWnd,
673 WINDOWPLACEMENT *lpwndpl)
679 GetWindowRect(HWND hWnd,
682 return(NtUserGetWindowRect(hWnd, lpRect));
686 GetWindowTextA(HWND hWnd, LPSTR lpString, int nMaxCount)
688 return(SendMessageA(hWnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString));
692 GetWindowTextLengthA(HWND hWnd)
694 return(SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0));
698 GetWindowTextLengthW(HWND hWnd)
704 GetWindowTextW(HWND hWnd,
712 GetWindowThreadProcessId(HWND hWnd,
713 LPDWORD lpdwProcessId)
719 IsChild(HWND hWndParent,
738 IsWindowUnicode(HWND hWnd)
744 IsWindowVisible(HWND hWnd)
746 while (GetWindowLong(hWnd, GWL_STYLE) & WS_CHILD)
748 if (!(GetWindowLong(hWnd, GWL_STYLE) & WS_VISIBLE))
752 hWnd = GetAncestor(hWnd, GA_PARENT);
754 return(GetWindowLong(hWnd, GWL_STYLE) & WS_VISIBLE);
764 LockSetForegroundWindow(UINT uLockCode)
770 MoveWindow(HWND hWnd,
787 RealChildWindowFromPoint(HWND hwndParent,
788 POINT ptParentClientCoords)
794 RealGetWindowClass(HWND hwnd,
802 SetForegroundWindow(HWND hWnd)
808 SetLayeredWindowAttributes(HWND hwnd,
817 SetParent(HWND hWndChild,
824 SetProcessDefaultLayout(DWORD dwDefaultLayout)
830 SetWindowPlacement(HWND hWnd,
831 CONST WINDOWPLACEMENT *lpwndpl)
837 SetWindowPos(HWND hWnd,
838 HWND hWndInsertAfter,
849 SetWindowTextA(HWND hWnd,
856 SetWindowTextW(HWND hWnd,
863 ShowOwnedPopups(HWND hWnd,
870 ShowWindow(HWND hWnd,
873 return NtUserShowWindow(hWnd, nCmdShow);
877 ShowWindowAsync(HWND hWnd,
884 TileWindows(HWND hwndParent,
894 UpdateLayeredWindow(HWND hwnd,
901 BLENDFUNCTION *pblend,
908 WindowFromPoint(POINT Point)
914 MapWindowPoints(HWND hWndFrom, HWND hWndTo, LPPOINT lpPoints, UINT cPoints)
916 POINT FromOffset, ToOffset;
920 NtUserGetClientOrigin(hWndFrom, &FromOffset);
921 NtUserGetClientOrigin(hWndTo, &ToOffset);
922 XMove = ToOffset.x - FromOffset.x;
923 YMove = ToOffset.y - FromOffset.y;
924 for (i = 0; i < cPoints; i++)
926 lpPoints[i].x += XMove;
927 lpPoints[i].y += YMove;
929 return(MAKELONG(LOWORD(XMove), LOWORD(YMove)));
934 ScreenToClient(HWND hWnd, LPPOINT lpPoint)
936 return(MapWindowPoints(NULL, hWnd, lpPoint, 1));