2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
23 * FILE: subsys/win32k/ntuser/window.c
24 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 06-06-2001 CSH Created
29 /* INCLUDES ******************************************************************/
36 static WndProcHandle
*WndProcHandlesArray
= 0;
37 static WORD WndProcHandlesArraySize
= 0;
38 #define WPH_SIZE 0x40 /* the size to add to the WndProcHandle array each time */
40 /* dialog resources appear to pass this in 16 bits, handle them properly */
41 #define CW_USEDEFAULT16 (0x8000)
43 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
45 /* PRIVATE FUNCTIONS **********************************************************/
50 * Initialize windowing implementation.
56 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,WPH_SIZE
* sizeof(WndProcHandle
), TAG_WINPROCLST
);
57 WndProcHandlesArraySize
= WPH_SIZE
;
58 return STATUS_SUCCESS
;
64 * Cleanup windowing implementation.
68 CleanupWindowImpl(VOID
)
70 ExFreePool(WndProcHandlesArray
);
71 WndProcHandlesArray
= 0;
72 WndProcHandlesArraySize
= 0;
73 return STATUS_SUCCESS
;
76 /* HELPER FUNCTIONS ***********************************************************/
78 VOID FASTCALL
IntReleaseWindowObject(PWINDOW_OBJECT Window
)
82 ASSERT(USER_BODY_TO_HEADER(Window
)->RefCount
>= 1);
84 USER_BODY_TO_HEADER(Window
)->RefCount
--;
86 if (USER_BODY_TO_HEADER(Window
)->RefCount
== 0 && USER_BODY_TO_HEADER(Window
)->destroyed
)
93 PWINDOW_OBJECT FASTCALL
IntGetWindowObject(HWND hWnd
)
95 PWINDOW_OBJECT Window
= UserGetWindowObject(hWnd
);
98 ASSERT(USER_BODY_TO_HEADER(Window
)->RefCount
>= 0);
100 USER_BODY_TO_HEADER(Window
)->RefCount
++;
106 PWINDOW_OBJECT FASTCALL
UserGetWindowObject(HWND hWnd
)
108 PWINDOW_OBJECT Window
= (PWINDOW_OBJECT
)UserGetObject(&gHandleTable
, hWnd
, otWindow
);
111 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
115 ASSERT(USER_BODY_TO_HEADER(Window
)->RefCount
>= 0);
123 * The function determines whether the specified window handle identifies
124 * an existing window.
128 * Handle to the window to test.
131 * If the window handle identifies an existing window, the return value
132 * is TRUE. If the window handle does not identify an existing window,
133 * the return value is FALSE.
137 IntIsWindow(HWND hWnd
)
139 PWINDOW_OBJECT Window
;
141 if (!(Window
= IntGetWindowObject(hWnd
)))
144 IntReleaseWindowObject(Window
);
151 PWINDOW_OBJECT FASTCALL
152 IntGetParent(PWINDOW_OBJECT Wnd
)
156 if (Wnd
->Style
& WS_POPUP
)
159 return IntGetWindowObject(hWnd
);
161 else if (Wnd
->Style
& WS_CHILD
)
166 if (par
) IntReferenceWindowObject(par
);
168 //return IntGetWindowObject(hWnd);
174 PWINDOW_OBJECT FASTCALL
175 IntGetOwner(PWINDOW_OBJECT Wnd
)
181 return IntGetWindowObject(hWnd
);
184 PWINDOW_OBJECT FASTCALL
185 IntGetParentObject(PWINDOW_OBJECT Wnd
)
190 if (par
) IntReferenceWindowObject(par
);
197 * Compile a list of all child window handles from given window.
200 * This function is similar to Wine WIN_ListChildren. The caller
201 * must free the returned list with ExFreePool.
205 IntWinListChildren(PWINDOW_OBJECT Window
)
207 PWINDOW_OBJECT Child
;
209 UINT Index
, NumChildren
= 0;
211 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
214 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
217 DPRINT1("Failed to allocate memory for children array\n");
218 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
221 for (Child
= Window
->FirstChild
, Index
= 0;
223 Child
= Child
->NextSibling
, ++Index
)
224 List
[Index
] = Child
->hSelf
;
230 /***********************************************************************
233 static void IntSendDestroyMsg(HWND Wnd
)
236 PWINDOW_OBJECT Window
, Owner
, Parent
;
240 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
242 if (Wnd
== info
.hwndCaret
)
249 Window
= IntGetWindowObject(Wnd
);
251 Owner
= IntGetOwner(Window
);
253 Parent
= IntGetParent(Window
);
255 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) Wnd
);
257 IntReleaseWindowObject(Parent
);
259 IntReleaseWindowObject(Owner
);
262 IntReleaseWindowObject(Window
);
265 /* The window could already be destroyed here */
268 * Send the WM_DESTROY to the window.
271 co_IntSendMessage(Wnd
, WM_DESTROY
, 0, 0);
274 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
275 * make sure that the window still exists when we come back.
283 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
285 /* start from the end (FIXME: is this needed?) */
286 for (i
= 0; pWndArray
[i
]; i
++) ;
290 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
292 HeapFree(GetProcessHeap(), 0, pWndArray
);
296 DPRINT("destroyed itself while in WM_DESTROY!\n");
301 /***********************************************************************
304 * Destroy storage associated to a window. "Internals" p.358
306 static LRESULT
co_IntDestroyWindow(PWINDOW_OBJECT Window
,
307 PW32PROCESS ProcessData
,
308 PW32THREAD ThreadData
,
309 BOOLEAN SendMessages
)
313 PWINDOW_OBJECT Child
;
315 BOOLEAN BelongsToThreadData
;
319 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
321 DPRINT("Tried to call IntDestroyWindow() twice\n");
324 Window
->Status
|= WINDOWSTATUS_DESTROYING
;
325 Window
->Flags
&= ~WS_VISIBLE
;
326 /* remove the window already at this point from the thread window list so we
327 don't get into trouble when destroying the thread windows while we're still
328 in IntDestroyWindow() */
329 RemoveEntryList(&Window
->ThreadListEntry
);
331 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
333 IntDeRegisterShellHookWindow(Window
->hSelf
);
337 /* Send destroy messages */
338 IntSendDestroyMsg(Window
->hSelf
);
341 /* free child windows */
342 Children
= IntWinListChildren(Window
);
345 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
347 if ((Child
= IntGetWindowObject(*ChildHandle
)))
349 if(!IntWndBelongsToThread(Child
, ThreadData
))
351 /* send WM_DESTROY messages to windows not belonging to the same thread */
352 IntSendDestroyMsg(Child
->hSelf
);
355 co_IntDestroyWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
356 IntReleaseWindowObject(Child
);
359 ExFreePool(Children
);
365 * Clear the update region to make sure no WM_PAINT messages will be
366 * generated for this window while processing the WM_NCDESTROY.
368 co_UserRedrawWindow(Window
, NULL
, 0,
369 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
370 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
371 if(BelongsToThreadData
)
372 co_IntSendMessage(Window
->hSelf
, WM_NCDESTROY
, 0, 0);
374 MsqRemoveTimersWindow(ThreadData
->MessageQueue
, Window
->hSelf
);
376 /* flush the message queue */
377 MsqRemoveWindowMessagesFromQueue(Window
);
379 /* from now on no messages can be sent to this window anymore */
380 Window
->Status
|= WINDOWSTATUS_DESTROYED
;
381 /* don't remove the WINDOWSTATUS_DESTROYING bit */
383 /* reset shell window handles */
384 if(ThreadData
->Desktop
)
386 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellWindow
)
387 ThreadData
->Desktop
->WindowStation
->ShellWindow
= NULL
;
389 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellListView
)
390 ThreadData
->Desktop
->WindowStation
->ShellListView
= NULL
;
393 /* Unregister hot keys */
394 UnregisterWindowHotKeys (Window
);
396 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
399 WinPosCheckInternalPos(Window
->hSelf
);
400 if (Window
->hSelf
== GetCapture())
405 /* free resources associated with the window */
406 TIMER_RemoveWindowTimers(Window
->hSelf
);
409 if (!(Window
->Style
& WS_CHILD
) && Window
->IDMenu
410 && (Menu
= IntGetMenuObject((HMENU
)Window
->IDMenu
)))
412 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
414 IntReleaseMenuObject(Menu
);
417 if(Window
->SystemMenu
418 && (Menu
= IntGetMenuObject(Window
->SystemMenu
)))
420 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
421 Window
->SystemMenu
= (HMENU
)0;
422 IntReleaseMenuObject(Menu
);
425 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
427 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
428 CLASS_RemoveWindow(Window
->Class
);
431 IntUnlinkWindow(Window
);
433 IntReferenceWindowObject(Window
);
434 ObmDeleteObject(Window
->hSelf
, otWindow
);
436 IntDestroyScrollBars(Window
);
438 /* remove the window from the class object */
439 RemoveEntryList(&Window
->ClassListEntry
);
441 /* dereference the class */
442 ClassDereferenceObject(Window
->Class
);
443 Window
->Class
= NULL
;
445 if(Window
->WindowRegion
)
447 NtGdiDeleteObject(Window
->WindowRegion
);
450 RtlFreeUnicodeString(&Window
->WindowName
);
452 IntReleaseWindowObject(Window
);
458 IntGetWindowBorderMeasures(PWINDOW_OBJECT Window
, UINT
*cx
, UINT
*cy
)
460 if(HAS_DLGFRAME(Window
->Style
, Window
->ExStyle
) && !(Window
->Style
& WS_MINIMIZE
))
462 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
463 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
467 if(HAS_THICKFRAME(Window
->Style
, Window
->ExStyle
)&& !(Window
->Style
& WS_MINIMIZE
))
469 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
470 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
472 else if(HAS_THINFRAME(Window
->Style
, Window
->ExStyle
))
474 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
475 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
485 IntGetWindowInfo(PWINDOW_OBJECT Window
, PWINDOWINFO pwi
)
487 pwi
->cbSize
= sizeof(WINDOWINFO
);
488 pwi
->rcWindow
= Window
->WindowRect
;
489 pwi
->rcClient
= Window
->ClientRect
;
490 pwi
->dwStyle
= Window
->Style
;
491 pwi
->dwExStyle
= Window
->ExStyle
;
492 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Window
->hSelf
); /* WS_ACTIVECAPTION */
493 IntGetWindowBorderMeasures(Window
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
494 pwi
->atomWindowType
= (Window
->Class
? Window
->Class
->Atom
: 0);
495 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
501 PWINDOW_OBJECT Window
,
505 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
507 if ((Window
->Style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
509 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
513 *Changed
= (Window
->IDMenu
!= (UINT
) Menu
);
521 OldMenu
= IntGetMenuObject((HMENU
) Window
->IDMenu
);
522 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Window
->hSelf
);
531 NewMenu
= IntGetMenuObject(Menu
);
536 IntReleaseMenuObject(OldMenu
);
538 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
541 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
543 /* Can't use the same menu for two windows */
546 IntReleaseMenuObject(OldMenu
);
548 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
554 Window
->IDMenu
= (UINT
) Menu
;
557 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
558 IntReleaseMenuObject(NewMenu
);
562 OldMenu
->MenuInfo
.Wnd
= NULL
;
563 IntReleaseMenuObject(OldMenu
);
570 /* INTERNAL ******************************************************************/
574 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
577 PW32PROCESS Win32Process
;
578 PW32THREAD Win32Thread
;
579 PWINDOW_OBJECT
*List
, *pWnd
;
582 Win32Thread
= Thread
->Tcb
.Win32Thread
;
583 Win32Process
= (PW32PROCESS
)Thread
->ThreadsProcess
->Win32Process
;
585 Current
= Win32Thread
->WindowListHead
.Flink
;
586 while (Current
!= &(Win32Thread
->WindowListHead
))
589 Current
= Current
->Flink
;
594 List
= ExAllocatePool(PagedPool
, (Cnt
+ 1) * sizeof(PWINDOW_OBJECT
));
597 DPRINT("Not enough memory to allocate window handle list\n");
601 Current
= Win32Thread
->WindowListHead
.Flink
;
602 while (Current
!= &(Win32Thread
->WindowListHead
))
604 *pWnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
605 IntReferenceWindowObject(*pWnd
);
607 Current
= Current
->Flink
;
611 for(pWnd
= List
; *pWnd
; pWnd
++)
613 co_UserDestroyWindow(*pWnd
);
614 IntReleaseWindowObject(*pWnd
);
625 * Returns client window rectangle relative to the upper-left corner of client area.
627 * \note Does not check the validity of the parameters
630 IntGetClientRect(PWINDOW_OBJECT Window
, PRECT Rect
)
635 Rect
->left
= Rect
->top
= 0;
636 Rect
->right
= Window
->ClientRect
.right
- Window
->ClientRect
.left
;
637 Rect
->bottom
= Window
->ClientRect
.bottom
- Window
->ClientRect
.top
;
643 IntGetFocusWindow(VOID
)
645 PUSER_MESSAGE_QUEUE Queue
;
646 PDESKTOP_OBJECT pdo
= IntGetActiveDesktop();
651 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
656 return(Queue
->FocusWindow
);
660 PMENU_OBJECT FASTCALL
661 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
)
663 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
664 PW32THREAD W32Thread
;
665 HMENU hNewMenu
, hSysMenu
;
666 ROSMENUITEMINFO ItemInfo
;
670 W32Thread
= PsGetWin32Thread();
672 if(!W32Thread
->Desktop
)
675 if(Window
->SystemMenu
)
677 Menu
= IntGetMenuObject(Window
->SystemMenu
);
680 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
681 Window
->SystemMenu
= (HMENU
)0;
682 IntReleaseMenuObject(Menu
);
686 if(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
)
688 /* clone system menu */
689 Menu
= IntGetMenuObject(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
);
693 NewMenu
= IntCloneMenu(Menu
);
696 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
697 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
698 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
700 //IntReleaseMenuObject(NewMenuObject);
702 IntReleaseMenuObject(Menu
);
706 hSysMenu
= UserCreateMenu(FALSE
);
711 SysMenu
= IntGetMenuObject(hSysMenu
);
714 UserDestroyMenu(hSysMenu
);
717 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
718 SysMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
719 hNewMenu
= co_IntLoadSysMenuTemplate();
722 IntReleaseMenuObject(SysMenu
);
723 UserDestroyMenu(hSysMenu
);
726 Menu
= IntGetMenuObject(hNewMenu
);
729 IntReleaseMenuObject(SysMenu
);
730 UserDestroyMenu(hSysMenu
);
734 NewMenu
= IntCloneMenu(Menu
);
737 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
738 IntReleaseMenuObject(NewMenu
);
739 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
741 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
742 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
743 ItemInfo
.fType
= MF_POPUP
;
744 ItemInfo
.fState
= MFS_ENABLED
;
745 ItemInfo
.dwTypeData
= NULL
;
747 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
748 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
750 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
754 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
755 IntReleaseMenuObject(Menu
);
764 if(Window
->SystemMenu
)
765 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
773 IntIsChildWindow(HWND Parent
, HWND Child
)
775 PWINDOW_OBJECT BaseWindow
, Window
;
777 if(!(BaseWindow
= UserGetWindowObject(Child
)))
785 if (Window
->hSelf
== Parent
)
789 if(!(Window
->Style
& WS_CHILD
))
794 Window
= Window
->Parent
;
801 IntIsWindowVisible(HWND hWnd
)
803 PWINDOW_OBJECT BaseWindow
, Window
, Old
;
805 if(!(BaseWindow
= IntGetWindowObject(hWnd
)))
813 if(!(Window
->Style
& WS_CHILD
))
817 if(!(Window
->Style
& WS_VISIBLE
))
819 if(Window
!= BaseWindow
)
820 IntReleaseWindowObject(Window
);
821 IntReleaseWindowObject(BaseWindow
);
825 Window
= IntGetParentObject(Window
);
826 if(Old
!= BaseWindow
)
827 IntReleaseWindowObject(Old
);
832 if(Window
->Style
& WS_VISIBLE
)
834 if(Window
!= BaseWindow
)
835 IntReleaseWindowObject(Window
);
836 IntReleaseWindowObject(BaseWindow
);
839 if(Window
!= BaseWindow
)
840 IntReleaseWindowObject(Window
);
842 IntReleaseWindowObject(BaseWindow
);
847 /* link the window into siblings and parent. children are kept in place. */
851 PWINDOW_OBJECT WndParent
,
852 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
855 PWINDOW_OBJECT Parent
;
857 Wnd
->Parent
= WndParent
;
858 if ((Wnd
->PrevSibling
= WndPrevSibling
))
860 /* link after WndPrevSibling */
861 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
862 Wnd
->NextSibling
->PrevSibling
= Wnd
;
863 else if ((Parent
= Wnd
->Parent
))
865 if(Parent
->LastChild
== WndPrevSibling
)
866 Parent
->LastChild
= Wnd
;
868 Wnd
->PrevSibling
->NextSibling
= Wnd
;
873 Parent
= Wnd
->Parent
;
874 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
875 Wnd
->NextSibling
->PrevSibling
= Wnd
;
878 Parent
->LastChild
= Wnd
;
879 Parent
->FirstChild
= Wnd
;
884 Parent
->FirstChild
= Wnd
;
891 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
893 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
896 Wnd
= IntGetWindowObject(hWnd
);
900 WndOldOwner
= IntGetWindowObject(Wnd
->hOwner
);
903 ret
= WndOldOwner
->hSelf
;
904 IntReleaseWindowObject(WndOldOwner
);
911 if((WndNewOwner
= IntGetWindowObject(hWndNewOwner
)))
913 Wnd
->hOwner
= hWndNewOwner
;
914 IntReleaseWindowObject(WndNewOwner
);
919 IntReleaseWindowObject(Wnd
);
923 PWINDOW_OBJECT FASTCALL
924 co_IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
926 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
927 HWND hWnd
, hWndNewParent
, hWndOldParent
;
932 ASSERT(WndNewParent
);
934 ASSERT_REFS_CO(WndNewParent
);
937 hWndNewParent
= WndNewParent
->hSelf
;
940 * Windows hides the window first, then shows it again
941 * including the WM_SHOWWINDOW messages and all
943 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
945 /* Validate that window and parent still exist */
946 if (!IntIsWindow(hWnd
) || !IntIsWindow(hWndNewParent
))
949 /* Window must belong to current process */
950 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
953 WndOldParent
= IntGetParentObject(Wnd
);
954 hWndOldParent
= (WndOldParent
? WndOldParent
->hSelf
: NULL
);
956 if (WndNewParent
!= WndOldParent
)
958 IntUnlinkWindow(Wnd
);
960 if (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
))
962 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
963 Sibling
= WndNewParent
->FirstChild
;
964 while (NULL
!= Sibling
&& 0 != (Sibling
->ExStyle
& WS_EX_TOPMOST
))
966 InsertAfter
= Sibling
;
967 Sibling
= Sibling
->NextSibling
;
970 if (NULL
== InsertAfter
)
972 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
976 IntReferenceWindowObject(InsertAfter
);
977 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
978 IntReleaseWindowObject(InsertAfter
);
981 if (WndNewParent
->hSelf
!= IntGetDesktopWindow()) /* a child window */
983 if (!(Wnd
->Style
& WS_CHILD
))
985 //if ( Wnd->Menu ) DestroyMenu ( Wnd->menu );
986 IntSetMenu(Wnd
, NULL
, &MenuChanged
);
992 * SetParent additionally needs to make hwnd the top window
993 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
994 * WM_WINDOWPOSCHANGED notification messages.
996 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
997 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
998 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1001 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1002 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1006 * Validate that the old parent still exist, since it migth have been
1007 * destroyed during the last callbacks to user-mode
1011 if(!IntIsWindow(WndOldParent
->hSelf
))
1013 IntReleaseWindowObject(WndOldParent
);
1017 /* don't dereference the window object here, it must be done by the caller
1018 of IntSetParent() */
1019 return WndOldParent
;
1025 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
1027 PMENU_OBJECT OldMenu
;
1028 if(Window
->SystemMenu
)
1030 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1033 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1034 IntReleaseMenuObject(OldMenu
);
1040 /* FIXME check window style, propably return FALSE ? */
1041 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1042 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1045 Window
->SystemMenu
= (HMENU
)0;
1051 /* unlink the window from siblings and parent. children are kept in place. */
1053 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1055 PWINDOW_OBJECT WndParent
= Wnd
->Parent
;
1057 if (Wnd
->NextSibling
) Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1058 else if (WndParent
&& WndParent
->LastChild
== Wnd
) WndParent
->LastChild
= Wnd
->PrevSibling
;
1060 if (Wnd
->PrevSibling
) Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1061 else if (WndParent
&& WndParent
->FirstChild
== Wnd
) WndParent
->FirstChild
= Wnd
->NextSibling
;
1063 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1069 PWINDOW_OBJECT Window
, Child
;
1071 if(!(Window
= IntGetWindowObject(IntGetDesktopWindow())))
1073 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1077 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1079 if(Child
->hOwner
&& Child
->Style
& WS_VISIBLE
)
1082 * The desktop has a popup window if one of them has
1083 * an owner window and is visible
1085 IntReleaseWindowObject(Window
);
1090 IntReleaseWindowObject(Window
);
1095 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1097 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1100 /* FUNCTIONS *****************************************************************/
1106 NtUserAlterWindowStyle(DWORD Unknown0
,
1117 * As best as I can figure, this function is used by EnumWindows,
1118 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1120 * It's supposed to build a list of HWNDs to return to the caller.
1121 * We can figure out what kind of list by what parameters are
1129 NtUserBuildHwndList(
1141 /* FIXME handle bChildren */
1145 PWINDOW_OBJECT Window
, Child
;
1146 if(!(Window
= IntGetWindowObject(hwndParent
)))
1148 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1152 for(Child
= Window
->FirstChild
; Child
!= NULL
; Child
= Child
->NextSibling
)
1154 if(dwCount
++ < nBufSize
&& pWnd
)
1156 Status
= MmCopyToCaller(pWnd
++, &Child
->hSelf
, sizeof(HWND
));
1157 if(!NT_SUCCESS(Status
))
1159 SetLastNtError(Status
);
1165 IntReleaseWindowObject(Window
);
1170 PW32THREAD W32Thread
;
1171 PLIST_ENTRY Current
;
1172 PWINDOW_OBJECT Window
;
1174 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1175 if(!NT_SUCCESS(Status
))
1177 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1180 if(!(W32Thread
= Thread
->Tcb
.Win32Thread
))
1182 ObDereferenceObject(Thread
);
1183 DPRINT("Thread is not a GUI Thread!\n");
1184 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1188 Current
= W32Thread
->WindowListHead
.Flink
;
1189 while(Current
!= &(W32Thread
->WindowListHead
))
1191 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1194 if(dwCount
< nBufSize
&& pWnd
)
1196 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1197 if(!NT_SUCCESS(Status
))
1199 SetLastNtError(Status
);
1204 Current
= Current
->Flink
;
1207 ObDereferenceObject(Thread
);
1211 PDESKTOP_OBJECT Desktop
;
1212 PWINDOW_OBJECT Window
, Child
;
1214 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1216 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1222 Status
= IntValidateDesktopHandle(hDesktop
,
1226 if(!NT_SUCCESS(Status
))
1228 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1232 if(!(Window
= IntGetWindowObject(Desktop
->DesktopWindow
)))
1235 ObDereferenceObject(Desktop
);
1236 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1240 for(Child
= Window
->FirstChild
; Child
!= NULL
; Child
= Child
->NextSibling
)
1242 if(dwCount
++ < nBufSize
&& pWnd
)
1244 Status
= MmCopyToCaller(pWnd
++, &Child
->hSelf
, sizeof(HWND
));
1245 if(!NT_SUCCESS(Status
))
1247 SetLastNtError(Status
);
1253 IntReleaseWindowObject(Window
);
1255 ObDereferenceObject(Desktop
);
1266 NtUserChildWindowFromPointEx(HWND hwndParent
,
1271 PWINDOW_OBJECT Parent
;
1276 if(!(Parent
= IntGetWindowObject(hwndParent
)))
1278 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1285 if(Parent
->hSelf
!= IntGetDesktopWindow())
1287 Pt
.x
+= Parent
->ClientRect
.left
;
1288 Pt
.y
+= Parent
->ClientRect
.top
;
1291 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1293 IntReleaseWindowObject(Parent
);
1297 Ret
= Parent
->hSelf
;
1298 if((List
= IntWinListChildren(Parent
)))
1300 for(phWnd
= List
; *phWnd
; phWnd
++)
1302 PWINDOW_OBJECT Child
;
1303 if((Child
= IntGetWindowObject(*phWnd
)))
1305 if(!(Child
->Style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1307 IntReleaseWindowObject(Child
);
1310 if((Child
->Style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1312 IntReleaseWindowObject(Child
);
1315 if((Child
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1317 IntReleaseWindowObject(Child
);
1320 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1323 IntReleaseWindowObject(Child
);
1326 IntReleaseWindowObject(Child
);
1332 IntReleaseWindowObject(Parent
);
1338 * calculates the default position of a window
1341 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT Window
, RECT
*rc
, BOOL IncPos
)
1348 IntGdiIntersectRect(rc
, rc
, &Parent
->ClientRect
);
1352 Pos
.x
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1353 Pos
.y
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1354 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1355 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1357 /* reset counter and position */
1360 Parent
->TiledCounter
= 0;
1362 Parent
->TiledCounter
++;
1373 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1374 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1378 rc
->right
= rc
->left
+ Sz
.cx
;
1379 rc
->bottom
= rc
->top
+ Sz
.cy
;
1388 co_IntCreateWindowEx(DWORD dwExStyle
,
1389 PUNICODE_STRING ClassName
,
1390 PUNICODE_STRING WindowName
,
1398 HINSTANCE hInstance
,
1401 BOOL bUnicodeWindow
)
1403 PWINSTATION_OBJECT WinSta
;
1404 PWNDCLASS_OBJECT Class
;
1405 PWINDOW_OBJECT Window
= NULL
;
1406 PWINDOW_OBJECT ParentWindow
= NULL
, OwnerWindow
;
1407 HWND ParentWindowHandle
;
1408 HWND OwnerWindowHandle
;
1409 PMENU_OBJECT SystemMenu
;
1414 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1419 CBT_CREATEWNDW CbtCreate
;
1423 DECLARE_RETURN(HWND
);
1426 ParentWindowHandle
= PsGetWin32Thread()->Desktop
->DesktopWindow
;
1427 OwnerWindowHandle
= NULL
;
1429 if (hWndParent
== HWND_MESSAGE
)
1432 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1433 * message window (style: WS_POPUP|WS_DISABLED)
1435 DPRINT1("FIXME - Parent is HWND_MESSAGE\n");
1437 else if (hWndParent
)
1439 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1440 ParentWindowHandle
= hWndParent
;
1442 OwnerWindowHandle
= UserGetAncestor(hWndParent
, GA_ROOT
);
1444 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1446 RETURN( (HWND
)0); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1449 if (NULL
!= ParentWindowHandle
)
1451 ParentWindow
= UserGetWindowObject(ParentWindowHandle
);
1453 if (ParentWindow
) UserRefObjectCo(ParentWindow
);
1457 ParentWindow
= NULL
;
1460 /* FIXME: parent must belong to the current process */
1462 /* Check the class. */
1463 ClassFound
= ClassReferenceClassByNameOrAtom(&Class
, ClassName
->Buffer
, hInstance
);
1466 if (IS_ATOM(ClassName
->Buffer
))
1468 DPRINT1("Class 0x%x not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1472 DPRINT1("Class %wZ not found\n", ClassName
);
1475 SetLastWin32Error(ERROR_CANNOT_FIND_WND_CLASS
);
1479 /* Check the window station. */
1480 if (PsGetWin32Thread()->Desktop
== NULL
)
1482 ClassDereferenceObject(Class
);
1484 DPRINT("Thread is not attached to a desktop! Cannot create window!\n");
1487 WinSta
= PsGetWin32Thread()->Desktop
->WindowStation
;
1488 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1490 /* Create the window object. */
1491 Window
= (PWINDOW_OBJECT
)
1492 ObmCreateObject(&gHandleTable
, &Handle
,
1493 otWindow
, sizeof(WINDOW_OBJECT
) + Class
->cbWndExtra
1496 DPRINT("Created object with handle %X\n", Handle
);
1499 ObDereferenceObject(WinSta
);
1500 ClassDereferenceObject(Class
);
1501 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1505 UserRefObjectCo(Window
);
1508 ObDereferenceObject(WinSta
);
1510 if (NULL
== PsGetWin32Thread()->Desktop
->DesktopWindow
)
1512 /* If there is no desktop window yet, we must be creating it */
1513 PsGetWin32Thread()->Desktop
->DesktopWindow
= Handle
;
1517 * Fill out the structure describing it.
1519 Window
->Class
= Class
;
1521 InsertTailList(&Class
->ClassWindowsListHead
, &Window
->ClassListEntry
);
1523 Window
->ExStyle
= dwExStyle
;
1524 Window
->Style
= dwStyle
& ~WS_VISIBLE
;
1525 DPRINT("1: Style is now %lx\n", Window
->Style
);
1527 Window
->SystemMenu
= (HMENU
)0;
1528 Window
->ContextHelpId
= 0;
1530 Window
->Instance
= hInstance
;
1531 Window
->hSelf
= Handle
;
1532 if (0 != (dwStyle
& WS_CHILD
))
1534 Window
->IDMenu
= (UINT
) hMenu
;
1538 IntSetMenu(Window
, hMenu
, &MenuChanged
);
1540 Window
->MessageQueue
= PsGetWin32Thread()->MessageQueue
;
1541 IntReferenceMessageQueue(Window
->MessageQueue
);
1542 Window
->Parent
= ParentWindow
;
1543 if((OwnerWindow
= IntGetWindowObject(OwnerWindowHandle
)))
1545 Window
->hOwner
= OwnerWindowHandle
;
1546 IntReleaseWindowObject(OwnerWindow
);
1549 Window
->hOwner
= NULL
;
1552 Window
->UserData
= 0;
1553 if ((((DWORD
)Class
->lpfnWndProcA
& 0xFFFF0000) != 0xFFFF0000)
1554 && (((DWORD
)Class
->lpfnWndProcW
& 0xFFFF0000) != 0xFFFF0000))
1556 Window
->Unicode
= bUnicodeWindow
;
1560 Window
->Unicode
= Class
->Unicode
;
1562 Window
->WndProcA
= Class
->lpfnWndProcA
;
1563 Window
->WndProcW
= Class
->lpfnWndProcW
;
1564 Window
->OwnerThread
= PsGetCurrentThread();
1565 Window
->FirstChild
= NULL
;
1566 Window
->LastChild
= NULL
;
1567 Window
->PrevSibling
= NULL
;
1568 Window
->NextSibling
= NULL
;
1570 /* extra window data */
1571 if (Class
->cbWndExtra
!= 0)
1573 Window
->ExtraData
= (PCHAR
)(Window
+ 1);
1574 Window
->ExtraDataSize
= Class
->cbWndExtra
;
1575 RtlZeroMemory(Window
->ExtraData
, Window
->ExtraDataSize
);
1579 Window
->ExtraData
= NULL
;
1580 Window
->ExtraDataSize
= 0;
1583 InitializeListHead(&Window
->PropListHead
);
1584 InitializeListHead(&Window
->WndObjListHead
);
1586 if (NULL
!= WindowName
->Buffer
)
1588 Window
->WindowName
.MaximumLength
= WindowName
->MaximumLength
;
1589 Window
->WindowName
.Length
= WindowName
->Length
;
1590 Window
->WindowName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, WindowName
->MaximumLength
,
1592 if (NULL
== Window
->WindowName
.Buffer
)
1594 ClassDereferenceObject(Class
);
1595 DPRINT1("Failed to allocate mem for window name\n");
1596 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1599 RtlCopyMemory(Window
->WindowName
.Buffer
, WindowName
->Buffer
, WindowName
->MaximumLength
);
1603 RtlInitUnicodeString(&Window
->WindowName
, NULL
);
1608 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1609 * tested for WS_POPUP
1611 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1612 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1613 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1614 dwExStyle
|= WS_EX_WINDOWEDGE
;
1616 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1618 /* Correct the window style. */
1619 if (!(dwStyle
& WS_CHILD
))
1621 Window
->Style
|= WS_CLIPSIBLINGS
;
1622 DPRINT("3: Style is now %lx\n", Window
->Style
);
1623 if (!(dwStyle
& WS_POPUP
))
1625 Window
->Style
|= WS_CAPTION
;
1626 Window
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1627 DPRINT("4: Style is now %lx\n", Window
->Style
);
1631 /* create system menu */
1632 if((Window
->Style
& WS_SYSMENU
) &&
1633 (Window
->Style
& WS_CAPTION
) == WS_CAPTION
)
1635 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
1638 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1639 IntReleaseMenuObject(SystemMenu
);
1643 /* Insert the window into the thread's window list. */
1644 InsertTailList (&PsGetWin32Thread()->WindowListHead
, &Window
->ThreadListEntry
);
1646 /* Allocate a DCE for this window. */
1647 if (dwStyle
& CS_OWNDC
)
1649 Window
->Dce
= DceAllocDCE(Window
->hSelf
, DCE_WINDOW_DC
);
1651 /* FIXME: Handle "CS_CLASSDC" */
1659 Cs
.lpCreateParams
= lpParam
;
1660 Cs
.hInstance
= hInstance
;
1662 Cs
.hwndParent
= ParentWindowHandle
;
1668 Cs
.lpszName
= (LPCWSTR
) WindowName
;
1669 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
1670 Cs
.dwExStyle
= dwExStyle
;
1671 CbtCreate
.lpcs
= &Cs
;
1672 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1673 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) Handle
, (LPARAM
) &CbtCreate
))
1676 /* FIXME - Delete window object and remove it from the thread windows list */
1677 /* FIXME - delete allocated DCE */
1679 ClassDereferenceObject(Class
);
1680 DPRINT1("CBT-hook returned !0\n");
1681 RETURN( (HWND
) NULL
);
1689 /* default positioning for overlapped windows */
1690 if(!(Window
->Style
& (WS_POPUP
| WS_CHILD
)))
1693 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1694 BOOL CalculatedDefPosSize
= FALSE
;
1696 IntGetDesktopWorkArea(Window
->OwnerThread
->Tcb
.Win32Thread
->Desktop
, &WorkArea
);
1699 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1701 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1703 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, Window
, &rc
, TRUE
);
1705 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1707 ProcessParams
->WindowFlags
&= ~STARTF_USEPOSITION
;
1708 Pos
.x
= WorkArea
.left
+ ProcessParams
->StartingX
;
1709 Pos
.y
= WorkArea
.top
+ ProcessParams
->StartingY
;
1717 /* According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
1718 y is something else */
1719 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
1724 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1726 if(!CalculatedDefPosSize
)
1728 IntCalcDefPosSize(ParentWindow
, Window
, &rc
, FALSE
);
1730 if(ProcessParams
->WindowFlags
& STARTF_USESIZE
)
1732 ProcessParams
->WindowFlags
&= ~STARTF_USESIZE
;
1733 Size
.cx
= ProcessParams
->CountX
;
1734 Size
.cy
= ProcessParams
->CountY
;
1738 Size
.cx
= rc
.right
- rc
.left
;
1739 Size
.cy
= rc
.bottom
- rc
.top
;
1742 /* move the window if necessary */
1744 Pos
.x
= max(rc
.left
, 0);
1746 Pos
.y
= max(rc
.top
, 0);
1751 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
1752 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1757 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1764 /* Initialize the window dimensions. */
1765 Window
->WindowRect
.left
= Pos
.x
;
1766 Window
->WindowRect
.top
= Pos
.y
;
1767 Window
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1768 Window
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1769 if (0 != (Window
->Style
& WS_CHILD
) && ParentWindow
)
1771 IntGdiOffsetRect(&(Window
->WindowRect
), ParentWindow
->ClientRect
.left
,
1772 ParentWindow
->ClientRect
.top
);
1774 Window
->ClientRect
= Window
->WindowRect
;
1777 * Get the size and position of the window.
1779 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
1781 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1783 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
1784 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
,
1786 if (MaxSize
.x
< nWidth
) nWidth
= MaxSize
.x
;
1787 if (MaxSize
.y
< nHeight
) nHeight
= MaxSize
.y
;
1788 if (nWidth
< MinTrack
.x
) nWidth
= MinTrack
.x
;
1789 if (nHeight
< MinTrack
.y
) nHeight
= MinTrack
.y
;
1790 if (nWidth
< 0) nWidth
= 0;
1791 if (nHeight
< 0) nHeight
= 0;
1794 Window
->WindowRect
.left
= Pos
.x
;
1795 Window
->WindowRect
.top
= Pos
.y
;
1796 Window
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1797 Window
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1798 if (0 != (Window
->Style
& WS_CHILD
) && ParentWindow
)
1800 IntGdiOffsetRect(&(Window
->WindowRect
), ParentWindow
->ClientRect
.left
,
1801 ParentWindow
->ClientRect
.top
);
1803 Window
->ClientRect
= Window
->WindowRect
;
1805 /* FIXME: Initialize the window menu. */
1807 /* Send a NCCREATE message. */
1813 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
1814 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1815 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
1816 Result
= co_IntSendMessage(Window
->hSelf
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
1819 /* FIXME: Cleanup. */
1820 DPRINT("IntCreateWindowEx(): NCCREATE message failed.\n");
1824 /* Calculate the non-client size. */
1825 MaxPos
.x
= Window
->WindowRect
.left
;
1826 MaxPos
.y
= Window
->WindowRect
.top
;
1827 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
1828 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
1829 Result
= co_WinPosGetNonClientSize(Window
->hSelf
,
1830 &Window
->WindowRect
,
1831 &Window
->ClientRect
);
1832 IntGdiOffsetRect(&Window
->WindowRect
,
1833 MaxPos
.x
- Window
->WindowRect
.left
,
1834 MaxPos
.y
- Window
->WindowRect
.top
);
1836 if (NULL
!= ParentWindow
)
1838 /* link the window into the parent's child list */
1839 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
1841 PWINDOW_OBJECT PrevSibling
;
1842 if((PrevSibling
= ParentWindow
->LastChild
))
1843 IntReferenceWindowObject(PrevSibling
);
1844 /* link window as bottom sibling */
1845 IntLinkWindow(Window
, ParentWindow
, PrevSibling
/*prev sibling*/);
1847 IntReleaseWindowObject(PrevSibling
);
1851 /* link window as top sibling (but after topmost siblings) */
1852 PWINDOW_OBJECT InsertAfter
, Sibling
;
1853 if (0 == (dwExStyle
& WS_EX_TOPMOST
))
1856 Sibling
= ParentWindow
->FirstChild
;
1857 while (NULL
!= Sibling
&& 0 != (Sibling
->ExStyle
& WS_EX_TOPMOST
))
1859 InsertAfter
= Sibling
;
1860 Sibling
= Sibling
->NextSibling
;
1867 if (NULL
!= InsertAfter
)
1869 IntReferenceWindowObject(InsertAfter
);
1871 IntLinkWindow(Window
, ParentWindow
, InsertAfter
/* prev sibling */);
1872 if (NULL
!= InsertAfter
)
1874 IntReleaseWindowObject(InsertAfter
);
1879 /* Send the WM_CREATE message. */
1880 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
1881 Result
= co_IntSendMessage(Window
->hSelf
, WM_CREATE
, 0, (LPARAM
) &Cs
);
1882 if (Result
== (LRESULT
)-1)
1884 /* FIXME: Cleanup. */
1885 ClassDereferenceObject(Class
);
1886 DPRINT("IntCreateWindowEx(): send CREATE message failed.\n");
1890 /* Send move and size messages. */
1891 if (!(Window
->Flags
& WINDOWOBJECT_NEED_SIZE
))
1895 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
1897 if ((Window
->ClientRect
.right
- Window
->ClientRect
.left
) < 0 ||
1898 (Window
->ClientRect
.bottom
- Window
->ClientRect
.top
) < 0)
1900 DPRINT("Sending bogus WM_SIZE\n");
1903 lParam
= MAKE_LONG(Window
->ClientRect
.right
-
1904 Window
->ClientRect
.left
,
1905 Window
->ClientRect
.bottom
-
1906 Window
->ClientRect
.top
);
1907 co_IntSendMessage(Window
->hSelf
, WM_SIZE
, SIZE_RESTORED
,
1910 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
1912 if (0 != (Window
->Style
& WS_CHILD
) && ParentWindow
)
1914 lParam
= MAKE_LONG(Window
->ClientRect
.left
- ParentWindow
->ClientRect
.left
,
1915 Window
->ClientRect
.top
- ParentWindow
->ClientRect
.top
);
1919 lParam
= MAKE_LONG(Window
->ClientRect
.left
,
1920 Window
->ClientRect
.top
);
1922 co_IntSendMessage(Window
->hSelf
, WM_MOVE
, 0, lParam
);
1924 /* Call WNDOBJ change procs */
1925 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
1928 /* Show or maybe minimize or maximize the window. */
1929 if (Window
->Style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1934 SwFlag
= (Window
->Style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
1936 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
1938 ((Window
->Style
& WS_CHILD
) || UserGetActiveWindow()) ?
1939 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
1940 SWP_NOZORDER
| SWP_FRAMECHANGED
;
1941 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
1942 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
1943 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
1944 NewPos
.right
, NewPos
.bottom
, SwFlag
);
1947 /* Notify the parent window of a new child. */
1948 if ((Window
->Style
& WS_CHILD
) &&
1949 (!(Window
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
1951 DPRINT("IntCreateWindow(): About to notify parent\n");
1952 co_IntSendMessage(ParentWindow
->hSelf
,
1954 MAKEWPARAM(WM_CREATE
, Window
->IDMenu
),
1955 (LPARAM
)Window
->hSelf
);
1958 if ((!hWndParent
) && (!HasOwner
)) {
1959 DPRINT("Sending CREATED notify\n");
1960 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)Handle
);
1962 DPRINT("Not sending CREATED notify, %x %d\n", ParentWindow
, HasOwner
);
1965 /* Initialize and show the window's scrollbars */
1966 if (Window
->Style
& WS_VSCROLL
)
1968 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
1970 if (Window
->Style
& WS_HSCROLL
)
1972 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
1975 if (dwStyle
& WS_VISIBLE
)
1977 DPRINT("IntCreateWindow(): About to show window\n");
1978 co_WinPosShowWindow(Window
, dwShowMode
);
1981 DPRINT("IntCreateWindow(): = %X\n", Handle
);
1982 DPRINT("WindowObject->SystemMenu = 0x%x\n", Window
->SystemMenu
);
1983 RETURN((HWND
)Handle
);
1986 if (Window
) UserDerefObjectCo(Window
);
1987 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
1993 NtUserCreateWindowEx(DWORD dwExStyle
,
1994 PUNICODE_STRING UnsafeClassName
,
1995 PUNICODE_STRING UnsafeWindowName
,
2003 HINSTANCE hInstance
,
2006 BOOL bUnicodeWindow
)
2009 UNICODE_STRING WindowName
;
2010 UNICODE_STRING ClassName
;
2012 DECLARE_RETURN(HWND
);
2014 DPRINT("Enter NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2015 UserEnterExclusive();
2017 /* Get the class name (string or atom) */
2018 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
2019 if (! NT_SUCCESS(Status
))
2021 SetLastNtError(Status
);
2024 if (! IS_ATOM(ClassName
.Buffer
))
2026 Status
= IntSafeCopyUnicodeStringTerminateNULL(&ClassName
, UnsafeClassName
);
2027 if (! NT_SUCCESS(Status
))
2029 SetLastNtError(Status
);
2034 /* safely copy the window name */
2035 if (NULL
!= UnsafeWindowName
)
2037 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
2038 if (! NT_SUCCESS(Status
))
2040 if (! IS_ATOM(ClassName
.Buffer
))
2042 RtlFreeUnicodeString(&ClassName
);
2044 SetLastNtError(Status
);
2050 RtlInitUnicodeString(&WindowName
, NULL
);
2053 NewWindow
= co_IntCreateWindowEx(dwExStyle
, &ClassName
, &WindowName
, dwStyle
, x
, y
, nWidth
, nHeight
,
2054 hWndParent
, hMenu
, hInstance
, lpParam
, dwShowMode
, bUnicodeWindow
);
2056 RtlFreeUnicodeString(&WindowName
);
2057 if (! IS_ATOM(ClassName
.Buffer
))
2059 RtlFreeUnicodeString(&ClassName
);
2065 DPRINT("Leave NtUserCreateWindowEx, ret=%i\n",_ret_
);
2074 NtUserDeferWindowPos(HDWP WinPosInfo
,
2076 HWND WndInsertAfter
,
2089 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2093 ASSERT_REFS_CO(Window
);
2100 /* Check for owner thread and desktop window */
2101 if ((Window
->OwnerThread
!= PsGetCurrentThread()) || IntIsDesktopWindow(Window
))
2103 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2107 /* Look whether the focus is within the tree of windows we will
2110 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2112 if (UserGetActiveWindow() == Window
->hSelf
)
2114 co_WinPosActivateOtherWindow(Window
);
2118 if (Window
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2119 Window
->MessageQueue
->ActiveWindow
= NULL
;
2120 if (Window
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2121 Window
->MessageQueue
->FocusWindow
= NULL
;
2122 if (Window
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2123 Window
->MessageQueue
->CaptureWindow
= NULL
;
2125 IntDereferenceMessageQueue(Window
->MessageQueue
);
2128 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hwnd
, 0, TRUE
))
2134 IntEngWindowChanged(Window
, WOC_DELETE
);
2135 isChild
= (0 != (Window
->Style
& WS_CHILD
));
2140 if (! USER_IsExitingThread(GetCurrentThreadId()))
2142 send_parent_notify(hwnd
, WM_DESTROY
);
2145 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2147 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2148 /* FIXME: clean up palette - see "Internals" p.352 */
2152 if (!IntIsWindow(Window
->hSelf
))
2157 /* Recursively destroy owned windows */
2162 BOOL GotOne
= FALSE
;
2165 PWINDOW_OBJECT Child
, Desktop
;
2167 Desktop
= IntGetWindowObject(IntGetDesktopWindow());
2168 Children
= IntWinListChildren(Desktop
);
2169 IntReleaseWindowObject(Desktop
);
2172 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2174 Child
= IntGetWindowObject(*ChildHandle
);
2177 if (Child
->hOwner
!= Window
->hSelf
)
2179 IntReleaseWindowObject(Child
);
2183 if (IntWndBelongsToThread(Child
, PsGetWin32Thread()))
2185 co_UserDestroyWindow(Child
);
2186 IntReleaseWindowObject(Child
);
2191 if (Child
->hOwner
!= NULL
)
2193 Child
->hOwner
= NULL
;
2196 IntReleaseWindowObject(Child
);
2198 ExFreePool(Children
);
2207 if (!IntIsWindow(Window
->hSelf
))
2212 /* Destroy the window storage */
2213 co_IntDestroyWindow(Window
, PsGetWin32Process(), PsGetWin32Thread(), TRUE
);
2225 NtUserDestroyWindow(HWND Wnd
)
2227 PWINDOW_OBJECT Window
;
2228 DECLARE_RETURN(BOOLEAN
);
2230 DPRINT("Enter NtUserDestroyWindow\n");
2231 UserEnterExclusive();
2233 Window
= IntGetWindowObject(Wnd
);
2239 RETURN(co_UserDestroyWindow(Window
));
2242 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2254 NtUserDrawMenuBarTemp(
2261 /* we'll use this function just for caching the menu bar */
2271 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2284 NtUserFillWindow(DWORD Unknown0
,
2296 IntFindWindow(PWINDOW_OBJECT Parent
,
2297 PWINDOW_OBJECT ChildAfter
,
2299 PUNICODE_STRING WindowName
)
2301 BOOL CheckWindowName
;
2307 CheckWindowName
= (WindowName
&& (WindowName
->Length
> 0));
2309 if((List
= IntWinListChildren(Parent
)))
2314 /* skip handles before and including ChildAfter */
2315 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
));
2318 /* search children */
2321 PWINDOW_OBJECT Child
;
2322 if(!(Child
= IntGetWindowObject(*(phWnd
++))))
2327 /* Do not send WM_GETTEXT messages in the kernel mode version!
2328 The user mode version however calls GetWindowText() which will
2329 send WM_GETTEXT messages to windows belonging to its processes */
2330 if((!CheckWindowName
|| !RtlCompareUnicodeString(WindowName
, &(Child
->WindowName
), FALSE
)) &&
2331 (!ClassAtom
|| Child
->Class
->Atom
== ClassAtom
))
2334 IntReleaseWindowObject(Child
);
2338 IntReleaseWindowObject(Child
);
2348 * Searches a window's children for a window with the specified
2351 * hwndParent = The window whose childs are to be searched.
2353 * HWND_MESSAGE = message-only windows
2355 * hwndChildAfter = Search starts after this child window.
2356 * NULL = start from beginning
2358 * ucClassName = Class name to search for
2359 * Reguired parameter.
2361 * ucWindowName = Window name
2362 * ->Buffer == NULL = don't care
2365 * The HWND of the window if it was found, otherwise NULL
2371 NtUserFindWindowEx(HWND hwndParent
,
2372 HWND hwndChildAfter
,
2373 PUNICODE_STRING ucClassName
,
2374 PUNICODE_STRING ucWindowName
)
2376 PWINDOW_OBJECT Parent
, ChildAfter
;
2377 UNICODE_STRING ClassName
, WindowName
;
2379 HWND Desktop
, Ret
= NULL
;
2381 DECLARE_RETURN(HWND
);
2383 DPRINT("Enter NtUserFindWindowEx\n");
2386 Desktop
= IntGetCurrentThreadDesktopWindow();
2388 if(hwndParent
== NULL
)
2389 hwndParent
= Desktop
;
2391 else if(hwndParent == HWND_MESSAGE)
2393 hwndParent = IntGetMessageWindow();
2397 if(!(Parent
= IntGetWindowObject(hwndParent
)))
2399 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2404 if(hwndChildAfter
&& !(ChildAfter
= IntGetWindowObject(hwndChildAfter
)))
2406 IntReleaseWindowObject(Parent
);
2407 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2411 /* copy the window name */
2412 Status
= IntSafeCopyUnicodeString(&WindowName
, ucWindowName
);
2413 if(!NT_SUCCESS(Status
))
2415 SetLastNtError(Status
);
2419 /* safely copy the class name */
2420 Status
= MmCopyFromCaller(&ClassName
, ucClassName
, sizeof(UNICODE_STRING
));
2421 if(!NT_SUCCESS(Status
))
2423 SetLastNtError(Status
);
2426 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2429 /* safely copy the class name string (NULL terminated because class-lookup
2431 buf
= ExAllocatePoolWithTag(PagedPool
, ClassName
.Length
+ sizeof(WCHAR
), TAG_STRING
);
2434 SetLastWin32Error(STATUS_INSUFFICIENT_RESOURCES
);
2437 Status
= MmCopyFromCaller(buf
, ClassName
.Buffer
, ClassName
.Length
);
2438 if(!NT_SUCCESS(Status
))
2441 SetLastNtError(Status
);
2444 ClassName
.Buffer
= buf
;
2445 /* make sure the string is null-terminated */
2446 buf
+= ClassName
.Length
/ sizeof(WCHAR
);
2450 /* find the class object */
2451 if(ClassName
.Buffer
)
2453 PWINSTATION_OBJECT WinStaObject
;
2455 if (PsGetWin32Thread()->Desktop
== NULL
)
2457 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2461 WinStaObject
= PsGetWin32Thread()->Desktop
->WindowStation
;
2463 Status
= RtlLookupAtomInAtomTable(
2464 WinStaObject
->AtomTable
,
2468 if (!NT_SUCCESS(Status
))
2470 DPRINT1("Failed to lookup class atom!\n");
2471 SetLastWin32Error(ERROR_CLASS_DOES_NOT_EXIST
);
2476 if(Parent
->hSelf
== Desktop
)
2479 PWINDOW_OBJECT TopLevelWindow
;
2480 BOOLEAN CheckWindowName
;
2481 BOOLEAN CheckClassName
;
2482 BOOLEAN WindowMatches
;
2483 BOOLEAN ClassMatches
;
2485 /* windows searches through all top-level windows if the parent is the desktop
2488 if((List
= IntWinListChildren(Parent
)))
2494 /* skip handles before and including ChildAfter */
2495 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
));
2498 CheckWindowName
= WindowName
.Length
> 0;
2499 CheckClassName
= ClassName
.Buffer
!= NULL
;
2501 /* search children */
2504 if(!(TopLevelWindow
= IntGetWindowObject(*(phWnd
++))))
2509 /* Do not send WM_GETTEXT messages in the kernel mode version!
2510 The user mode version however calls GetWindowText() which will
2511 send WM_GETTEXT messages to windows belonging to its processes */
2512 WindowMatches
= !CheckWindowName
|| !RtlCompareUnicodeString(
2513 &WindowName
, &TopLevelWindow
->WindowName
, FALSE
);
2514 ClassMatches
= !CheckClassName
||
2515 ClassAtom
== TopLevelWindow
->Class
->Atom
;
2517 if (WindowMatches
&& ClassMatches
)
2519 Ret
= TopLevelWindow
->hSelf
;
2520 IntReleaseWindowObject(TopLevelWindow
);
2524 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2526 /* window returns the handle of the top-level window, in case it found
2528 Ret
= TopLevelWindow
->hSelf
;
2529 IntReleaseWindowObject(TopLevelWindow
);
2533 IntReleaseWindowObject(TopLevelWindow
);
2539 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2542 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2544 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2545 search the message-only windows. Should this also be done if
2546 Parent is the desktop window??? */
2547 PWINDOW_OBJECT MsgWindows
;
2549 if((MsgWindows
= IntGetWindowObject(IntGetMessageWindow())))
2551 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2552 IntReleaseWindowObject(MsgWindows
);
2558 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2559 ExFreePool(ClassName
.Buffer
);
2562 RtlFreeUnicodeString(&WindowName
);
2566 IntReleaseWindowObject(ChildAfter
);
2567 IntReleaseWindowObject(Parent
);
2572 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2582 NtUserFlashWindowEx(DWORD Unknown0
)
2593 HWND FASTCALL
UserGetAncestor(HWND hWnd
, UINT Type
)
2595 PWINDOW_OBJECT Wnd
, WndAncestor
, Parent
;
2598 if (hWnd
== IntGetDesktopWindow())
2603 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2605 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2613 WndAncestor
= IntGetParentObject(Wnd
);
2626 if(!(Parent
= IntGetParentObject(WndAncestor
)))
2630 if(IntIsDesktopWindow(Parent
))
2632 IntReleaseWindowObject(Parent
);
2636 IntReleaseWindowObject(tmp
);
2637 WndAncestor
= Parent
;
2645 IntReferenceWindowObject(WndAncestor
);
2650 Parent
= IntGetParent(WndAncestor
);
2651 IntReleaseWindowObject(Old
);
2656 WndAncestor
= Parent
;
2663 IntReleaseWindowObject(Wnd
);
2668 hWndAncestor
= (WndAncestor
? WndAncestor
->hSelf
: NULL
);
2669 IntReleaseWindowObject(Wnd
);
2671 if(WndAncestor
&& (WndAncestor
!= Wnd
))
2672 IntReleaseWindowObject(WndAncestor
);
2674 return hWndAncestor
;
2683 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2685 DECLARE_RETURN(HWND
);
2687 DPRINT("Enter NtUserGetAncestor\n");
2688 UserEnterExclusive();
2690 RETURN(UserGetAncestor(hWnd
, Type
));
2693 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
2699 * Returns client window rectangle relative to the upper-left corner of client area.
2701 * \param hWnd window handle.
2702 * \param Rect pointer to the buffer where the coordinates are returned.
2709 NtUserGetClientRect(HWND hWnd
, LPRECT Rect
)
2711 PWINDOW_OBJECT Window
;
2713 DECLARE_RETURN(BOOL
);
2715 DPRINT("Enter NtUserGetClientRect\n");
2718 if(!(Window
= IntGetWindowObject(hWnd
)))
2720 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2724 IntGetClientRect(Window
, &SafeRect
);
2725 IntReleaseWindowObject(Window
);
2727 if(!NT_SUCCESS(MmCopyToCaller(Rect
, &SafeRect
, sizeof(RECT
))))
2734 DPRINT("Leave NtUserGetClientRect, ret=%i\n",_ret_
);
2744 NtUserGetDesktopWindow()
2746 DECLARE_RETURN(HWND
);
2748 DPRINT("Enter NtUserGetDesktopWindow\n");
2751 RETURN( IntGetDesktopWindow());
2754 DPRINT("Leave NtUserGetDesktopWindow, ret=%i\n",_ret_
);
2764 NtUserGetInternalWindowPos(DWORD Unknown0
,
2778 NtUserGetLastActivePopup(HWND hWnd
)
2781 * This code can't work, because hWndLastPopup member of WINDOW_OBJECT is
2782 * not changed anywhere.
2783 * -- Filip, 01/nov/2003
2789 IntAcquireWinLockShared();
2791 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2793 IntReleaseWinLock();
2794 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2798 hWndLastPopup
= Wnd
->hWndLastPopup
;
2800 IntReleaseWinLock();
2802 return hWndLastPopup
;
2811 * The NtUserGetParent function retrieves a handle to the specified window's
2815 * Note that, despite its name, this function can return an owner window
2816 * instead of a parent window.
2823 NtUserGetParent(HWND hWnd
)
2825 PWINDOW_OBJECT Wnd
, WndParent
;
2826 HWND hWndParent
= NULL
;
2827 DECLARE_RETURN(HWND
);
2829 DPRINT("Enter NtUserGetParent\n");
2830 UserEnterExclusive();
2832 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2834 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2838 WndParent
= IntGetParent(Wnd
);
2841 hWndParent
= WndParent
->hSelf
;
2842 IntReleaseWindowObject(WndParent
);
2845 IntReleaseWindowObject(Wnd
);
2847 RETURN( hWndParent
);
2850 DPRINT("Leave NtUserGetParent, ret=%i\n",_ret_
);
2859 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2861 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
2862 HWND hWndOldParent
= NULL
;
2864 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
2866 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2870 if (hWndChild
== IntGetDesktopWindow())
2872 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2878 if (!(WndParent
= IntGetWindowObject(hWndNewParent
)))
2880 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2886 if (!(WndParent
= IntGetWindowObject(IntGetDesktopWindow())))
2888 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2893 if (!(Wnd
= IntGetWindowObject(hWndChild
)))
2895 IntReleaseWindowObject(WndParent
);
2896 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2900 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
2904 hWndOldParent
= WndOldParent
->hSelf
;
2905 IntReleaseWindowObject(WndOldParent
);
2908 IntReleaseWindowObject(Wnd
);
2909 IntReleaseWindowObject(WndParent
);
2911 return( hWndOldParent
);
2919 * The NtUserSetParent function changes the parent window of the specified
2923 * The new parent window and the child window must belong to the same
2924 * application. If the window identified by the hWndChild parameter is
2925 * visible, the system performs the appropriate redrawing and repainting.
2926 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
2927 * or WS_POPUP window styles of the window whose parent is being changed.
2934 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2936 DECLARE_RETURN(HWND
);
2938 DPRINT("Enter NtUserSetParent\n");
2939 UserEnterExclusive();
2941 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
2944 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
2952 HWND FASTCALL
UserGetShellWindow()
2954 PWINSTATION_OBJECT WinStaObject
;
2957 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
2962 if (!NT_SUCCESS(Status
))
2964 SetLastNtError(Status
);
2968 Ret
= (HWND
)WinStaObject
->ShellWindow
;
2970 ObDereferenceObject(WinStaObject
);
2976 * NtUserGetShellWindow
2978 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
2985 NtUserGetShellWindow()
2987 DECLARE_RETURN(HWND
);
2989 DPRINT("Enter NtUserGetShellWindow\n");
2992 RETURN( UserGetShellWindow() );
2995 DPRINT("Leave NtUserGetShellWindow, ret=%i\n",_ret_
);
3001 * NtUserSetShellWindowEx
3003 * This is undocumented function to set global shell window. The global
3004 * shell window has special handling of window position.
3011 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3013 PWINSTATION_OBJECT WinStaObject
;
3014 PWINDOW_OBJECT WndShell
;
3015 DECLARE_RETURN(BOOL
);
3017 DPRINT("Enter NtUserSetShellWindowEx\n");
3018 UserEnterExclusive();
3020 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3025 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3030 if (!NT_SUCCESS(Status
))
3032 SetLastNtError(Status
);
3037 * Test if we are permitted to change the shell window.
3039 if (WinStaObject
->ShellWindow
)
3041 ObDereferenceObject(WinStaObject
);
3046 * Move shell window into background.
3048 if (hwndListView
&& hwndListView
!= hwndShell
)
3051 * Disabled for now to get Explorer working.
3052 * -- Filip, 01/nov/2003
3055 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3058 if (UserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3060 ObDereferenceObject(WinStaObject
);
3065 if (UserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3067 ObDereferenceObject(WinStaObject
);
3071 UserRefObjectCo(WndShell
);
3072 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3074 WinStaObject
->ShellWindow
= hwndShell
;
3075 WinStaObject
->ShellListView
= hwndListView
;
3077 UserDerefObjectCo(WndShell
);
3079 ObDereferenceObject(WinStaObject
);
3083 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3089 * NtUserGetSystemMenu
3091 * The NtUserGetSystemMenu function allows the application to access the
3092 * window menu (also known as the system menu or the control menu) for
3093 * copying and modifying.
3097 * Handle to the window that will own a copy of the window menu.
3099 * Specifies the action to be taken. If this parameter is FALSE,
3100 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3101 * currently in use. The copy is initially identical to the window menu
3102 * but it can be modified.
3103 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3104 * to the default state. The previous window menu, if any, is destroyed.
3107 * If the bRevert parameter is FALSE, the return value is a handle to a
3108 * copy of the window menu. If the bRevert parameter is TRUE, the return
3116 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3118 PWINDOW_OBJECT Window
;
3120 DECLARE_RETURN(HMENU
);
3122 DPRINT("Enter NtUserGetSystemMenu\n");
3125 if (!(Window
= UserGetWindowObject(hWnd
)))
3130 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3135 RETURN(Menu
->MenuInfo
.Self
);
3138 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3144 * NtUserSetSystemMenu
3151 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3153 BOOL Result
= FALSE
;
3154 PWINDOW_OBJECT Window
;
3156 DECLARE_RETURN(BOOL
);
3158 DPRINT("Enter NtUserSetSystemMenu\n");
3159 UserEnterExclusive();
3161 if (!(Window
= IntGetWindowObject(hWnd
)))
3163 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3170 * Assign new menu handle.
3172 Menu
= IntGetMenuObject(hMenu
);
3175 IntReleaseWindowObject(Window
);
3176 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
3180 Result
= IntSetSystemMenu(Window
, Menu
);
3182 IntReleaseMenuObject(Menu
);
3185 IntReleaseWindowObject(Window
);
3190 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3199 UserGetWindow(HWND hWnd
, UINT Relationship
)
3201 PWINDOW_OBJECT Parent
, Window
;
3202 HWND hWndResult
= NULL
;
3204 if (!(Window
= UserGetWindowObject(hWnd
))) return NULL
;
3206 switch (Relationship
)
3209 if((Parent
= Window
->Parent
))
3211 if (Parent
->FirstChild
)
3212 hWndResult
= Parent
->FirstChild
->hSelf
;
3217 if((Parent
= Window
->Parent
))
3219 if (Parent
->LastChild
)
3220 hWndResult
= Parent
->LastChild
->hSelf
;
3225 if (Window
->NextSibling
)
3226 hWndResult
= Window
->NextSibling
->hSelf
;
3230 if (Window
->PrevSibling
)
3231 hWndResult
= Window
->PrevSibling
->hSelf
;
3235 if((Parent
= IntGetWindowObject(Window
->hOwner
)))
3237 hWndResult
= Parent
->hSelf
;
3238 IntReleaseWindowObject(Parent
);
3242 if (Window
->FirstChild
)
3243 hWndResult
= Window
->FirstChild
->hSelf
;
3255 * The NtUserGetWindow function retrieves a handle to a window that has the
3256 * specified relationship (Z order or owner) to the specified window.
3263 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3265 DECLARE_RETURN(HWND
);
3267 DPRINT("Enter NtUserGetWindow\n");
3270 RETURN(UserGetWindow(hWnd
, Relationship
));
3273 DPRINT("Leave NtUserGetWindow, ret=%i\n",_ret_
);
3282 * NtUserGetWindowLong
3284 * The NtUserGetWindowLong function retrieves information about the specified
3285 * window. The function also retrieves the 32-bit (long) value at the
3286 * specified offset into the extra window memory.
3293 UserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3295 PWINDOW_OBJECT Window
, Parent
;
3298 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3300 if (!(Window
= IntGetWindowObject(hWnd
)))
3302 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3307 * WndProc is only available to the owner process
3309 if (GWL_WNDPROC
== Index
3310 && Window
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3312 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3316 if ((INT
)Index
>= 0)
3318 if ((Index
+ sizeof(LONG
)) > Window
->ExtraDataSize
)
3320 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3323 Result
= *((LONG
*)(Window
->ExtraData
+ Index
));
3330 Result
= Window
->ExStyle
;
3334 Result
= Window
->Style
;
3339 Result
= (LONG
) Window
->WndProcA
;
3341 Result
= (LONG
) Window
->WndProcW
;
3345 Result
= (LONG
) Window
->Instance
;
3348 case GWL_HWNDPARENT
:
3349 Parent
= Window
->Parent
;
3352 if (Parent
&& Parent
->hSelf
== IntGetDesktopWindow())
3353 Result
= (LONG
) UserGetWindow(Window
->hSelf
, GW_OWNER
);
3355 Result
= (LONG
) Parent
->hSelf
;
3360 Result
= (LONG
) Window
->IDMenu
;
3364 Result
= Window
->UserData
;
3368 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3369 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3375 IntReleaseWindowObject(Window
);
3384 * NtUserGetWindowLong
3386 * The NtUserGetWindowLong function retrieves information about the specified
3387 * window. The function also retrieves the 32-bit (long) value at the
3388 * specified offset into the extra window memory.
3395 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3397 DECLARE_RETURN(LONG
);
3399 DPRINT("Enter NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3400 UserEnterExclusive();
3402 RETURN(UserGetWindowLong(hWnd
, Index
, Ansi
));
3405 DPRINT("Leave NtUserGetWindowLong, ret=%i\n",_ret_
);
3414 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3416 PWINDOW_OBJECT Window
, Parent
;
3417 PWINSTATION_OBJECT WindowStation
;
3421 if (hWnd
== IntGetDesktopWindow())
3423 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3427 if (!(Window
= IntGetWindowObject(hWnd
)))
3429 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3433 if ((INT
)Index
>= 0)
3435 if ((Index
+ sizeof(LONG
)) > Window
->ExtraDataSize
)
3437 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3438 IntReleaseWindowObject(Window
);
3441 OldValue
= *((LONG
*)(Window
->ExtraData
+ Index
));
3442 *((LONG
*)(Window
->ExtraData
+ Index
)) = NewValue
;
3449 OldValue
= (LONG
) Window
->ExStyle
;
3450 Style
.styleOld
= OldValue
;
3451 Style
.styleNew
= NewValue
;
3454 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3456 WindowStation
= Window
->OwnerThread
->Tcb
.Win32Thread
->Desktop
->WindowStation
;
3459 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3460 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3463 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3464 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3465 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3469 OldValue
= (LONG
) Window
->Style
;
3470 Style
.styleOld
= OldValue
;
3471 Style
.styleNew
= NewValue
;
3472 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3473 Window
->Style
= (DWORD
)Style
.styleNew
;
3474 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3478 /* FIXME: should check if window belongs to current process */
3481 OldValue
= (LONG
) Window
->WndProcA
;
3482 Window
->WndProcA
= (WNDPROC
) NewValue
;
3483 Window
->WndProcW
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,FALSE
);
3484 Window
->Unicode
= FALSE
;
3488 OldValue
= (LONG
) Window
->WndProcW
;
3489 Window
->WndProcW
= (WNDPROC
) NewValue
;
3490 Window
->WndProcA
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,TRUE
);
3491 Window
->Unicode
= TRUE
;
3496 OldValue
= (LONG
) Window
->Instance
;
3497 Window
->Instance
= (HINSTANCE
) NewValue
;
3500 case GWL_HWNDPARENT
:
3501 Parent
= IntGetParentObject(Window
);
3502 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
3503 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
3505 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
3507 IntReleaseWindowObject(Parent
);
3511 OldValue
= (LONG
) Window
->IDMenu
;
3512 Window
->IDMenu
= (UINT
) NewValue
;
3516 OldValue
= Window
->UserData
;
3517 Window
->UserData
= NewValue
;
3521 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3522 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3528 IntReleaseWindowObject(Window
);
3536 * NtUserSetWindowLong
3538 * The NtUserSetWindowLong function changes an attribute of the specified
3539 * window. The function also sets the 32-bit (long) value at the specified
3540 * offset into the extra window memory.
3547 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3549 DECLARE_RETURN(LONG
);
3551 DPRINT("Enter NtUserSetWindowLong\n");
3552 UserEnterExclusive();
3554 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3557 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3563 * NtUserSetWindowWord
3565 * Legacy function similar to NtUserSetWindowLong.
3572 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3574 PWINDOW_OBJECT Window
;
3576 DECLARE_RETURN(WORD
);
3578 DPRINT("Enter NtUserSetWindowWord\n");
3579 UserEnterExclusive();
3585 case GWL_HWNDPARENT
:
3586 RETURN( co_UserSetWindowLong(hWnd
, Index
, (UINT
)NewValue
, TRUE
));
3590 SetLastWin32Error(ERROR_INVALID_INDEX
);
3595 if (!(Window
= IntGetWindowObject(hWnd
)))
3597 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3601 if (Index
> Window
->ExtraDataSize
- sizeof(WORD
))
3603 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3604 IntReleaseWindowObject(Window
);
3608 OldValue
= *((WORD
*)(Window
->ExtraData
+ Index
));
3609 *((WORD
*)(Window
->ExtraData
+ Index
)) = NewValue
;
3611 IntReleaseWindowObject(Window
);
3616 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3625 NtUserGetWindowPlacement(HWND hWnd
,
3626 WINDOWPLACEMENT
*lpwndpl
)
3628 PWINDOW_OBJECT Window
;
3629 PINTERNALPOS InternalPos
;
3631 WINDOWPLACEMENT Safepl
;
3633 DECLARE_RETURN(BOOL
);
3635 DPRINT("Enter NtUserGetWindowPlacement\n");
3638 if (!(Window
= IntGetWindowObject(hWnd
)))
3640 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3644 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3645 if(!NT_SUCCESS(Status
))
3647 SetLastNtError(Status
);
3648 IntReleaseWindowObject(Window
);
3651 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3653 IntReleaseWindowObject(Window
);
3658 Safepl
.showCmd
= ((Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ? SW_MAXIMIZE
: SW_SHOWNORMAL
);
3660 Size
.x
= Window
->WindowRect
.left
;
3661 Size
.y
= Window
->WindowRect
.top
;
3662 InternalPos
= WinPosInitInternalPos(Window
, &Size
,
3663 &Window
->WindowRect
);
3666 Safepl
.rcNormalPosition
= InternalPos
->NormalRect
;
3667 Safepl
.ptMinPosition
= InternalPos
->IconPos
;
3668 Safepl
.ptMaxPosition
= InternalPos
->MaxPos
;
3672 IntReleaseWindowObject(Window
);
3676 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3677 if(!NT_SUCCESS(Status
))
3679 SetLastNtError(Status
);
3680 IntReleaseWindowObject(Window
);
3684 IntReleaseWindowObject(Window
);
3688 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
3695 * Return the dimension of the window in the screen coordinates.
3696 * \param hWnd window handle.
3697 * \param Rect pointer to the buffer where the coordinates are returned.
3703 NtUserGetWindowRect(HWND hWnd
, LPRECT Rect
)
3707 DECLARE_RETURN(BOOL
);
3709 DPRINT("Enter NtUserGetWindowRect\n");
3712 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3714 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3717 Status
= MmCopyToCaller(Rect
, &Wnd
->WindowRect
, sizeof(RECT
));
3718 if (!NT_SUCCESS(Status
))
3720 IntReleaseWindowObject(Wnd
);
3721 SetLastNtError(Status
);
3725 IntReleaseWindowObject(Wnd
);
3729 DPRINT("Leave NtUserGetWindowRect, ret=%i\n",_ret_
);
3739 NtUserGetWindowThreadProcessId(HWND hWnd
, LPDWORD UnsafePid
)
3743 DECLARE_RETURN(DWORD
);
3745 DPRINT("Enter NtUserGetWindowThreadProcessId\n");
3748 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3750 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3754 tid
= (DWORD
)IntGetWndThreadId(Wnd
);
3755 pid
= (DWORD
)IntGetWndProcessId(Wnd
);
3757 if (UnsafePid
) MmCopyToCaller(UnsafePid
, &pid
, sizeof(DWORD
));
3762 DPRINT("Leave NtUserGetWindowThreadProcessId, ret=%i\n",_ret_
);
3772 NtUserLockWindowUpdate(DWORD Unknown0
)
3792 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3793 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3794 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3798 QueryWindow based on KJK::Hyperion and James Tabor.
3800 0 = QWUniqueProcessId
3801 1 = QWUniqueThreadId
3802 4 = QWIsHung Implements IsHungAppWindow found
3805 9 = QWKillWindow When I called this with hWnd ==
3806 DesktopWindow, it shutdown the system
3813 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3815 PWINDOW_OBJECT Window
= IntGetWindowObject(hWnd
);
3817 DECLARE_RETURN(UINT
);
3819 DPRINT("Enter NtUserQueryWindow\n");
3824 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3830 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3831 Result
= (DWORD
)IntGetWndProcessId(Window
);
3834 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3835 Result
= (DWORD
)IntGetWndThreadId(Window
);
3838 case QUERY_WINDOW_ISHUNG
:
3839 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
3843 Result
= (DWORD
)NULL
;
3847 IntReleaseWindowObject(Window
);
3853 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3863 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3877 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3879 UNICODE_STRING SafeMessageName
;
3882 DECLARE_RETURN(UINT
);
3884 DPRINT("Enter NtUserRegisterWindowMessage\n");
3885 UserEnterExclusive();
3887 if(MessageNameUnsafe
== NULL
)
3889 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3893 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3894 if(!NT_SUCCESS(Status
))
3896 SetLastNtError(Status
);
3900 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3902 RtlFreeUnicodeString(&SafeMessageName
);
3906 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3916 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3929 NtUserSetInternalWindowPos(DWORD Unknown0
,
3945 NtUserSetLayeredWindowAttributes(DWORD Unknown0
,
3960 NtUserSetLogonNotifyWindow(DWORD Unknown0
)
3977 PWINDOW_OBJECT Window
;
3979 DECLARE_RETURN(BOOL
);
3981 DPRINT("Enter NtUserSetMenu\n");
3982 UserEnterExclusive();
3984 if (!(Window
= UserGetWindowObject(hWnd
)))
3989 if (! IntSetMenu(Window
, Menu
, &Changed
))
3994 if (Changed
&& Repaint
)
3996 UserRefObjectCo(Window
);
3997 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3998 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4000 UserDerefObjectCo(Window
);
4006 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4016 NtUserSetWindowFNID(DWORD Unknown0
,
4030 NtUserSetWindowPlacement(HWND hWnd
,
4031 WINDOWPLACEMENT
*lpwndpl
)
4033 PWINDOW_OBJECT Window
;
4034 WINDOWPLACEMENT Safepl
;
4036 DECLARE_RETURN(BOOL
);
4038 DPRINT("Enter NtUserSetWindowPlacement\n");
4039 UserEnterExclusive();
4041 if (!(Window
= IntGetWindowObject(hWnd
)))
4043 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4046 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4047 if(!NT_SUCCESS(Status
))
4049 SetLastNtError(Status
);
4050 IntReleaseWindowObject(Window
);
4053 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4055 IntReleaseWindowObject(Window
);
4059 if ((Window
->Style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4061 co_WinPosSetWindowPos(Window
, NULL
,
4062 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4063 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4064 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4065 SWP_NOZORDER
| SWP_NOACTIVATE
);
4068 /* FIXME - change window status */
4069 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
4071 if (Window
->InternalPos
== NULL
)
4072 Window
->InternalPos
= ExAllocatePoolWithTag(PagedPool
, sizeof(INTERNALPOS
), TAG_WININTLIST
);
4073 Window
->InternalPos
->NormalRect
= Safepl
.rcNormalPosition
;
4074 Window
->InternalPos
->IconPos
= Safepl
.ptMinPosition
;
4075 Window
->InternalPos
->MaxPos
= Safepl
.ptMaxPosition
;
4077 IntReleaseWindowObject(Window
);
4081 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4093 HWND hWndInsertAfter
,
4100 DECLARE_RETURN(BOOL
);
4101 PWINDOW_OBJECT Window
;
4104 DPRINT("Enter NtUserSetWindowPos\n");
4105 UserEnterExclusive();
4107 if (!(Window
= UserGetWindowObject(hWnd
)))
4112 UserRefObjectCo(Window
);
4113 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4114 UserDerefObjectCo(Window
);
4119 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4126 IntGetWindowRgn(HWND hWnd
, HRGN hRgn
)
4129 PWINDOW_OBJECT Window
;
4133 if(!(Window
= IntGetWindowObject(hWnd
)))
4135 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4140 IntReleaseWindowObject(Window
);
4144 /* Create a new window region using the window rectangle */
4145 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
4146 NtGdiOffsetRgn(VisRgn
, -Window
->WindowRect
.left
, -Window
->WindowRect
.top
);
4147 /* if there's a region assigned to the window, combine them both */
4148 if(Window
->WindowRegion
&& !(Window
->Style
& WS_MINIMIZE
))
4149 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4150 /* Copy the region into hRgn */
4151 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4153 if((pRgn
= RGNDATA_LockRgn(hRgn
)))
4155 Ret
= pRgn
->rdh
.iType
;
4156 RGNDATA_UnlockRgn(pRgn
);
4161 NtGdiDeleteObject(VisRgn
);
4163 IntReleaseWindowObject(Window
);
4168 IntGetWindowRgnBox(HWND hWnd
, RECT
*Rect
)
4171 PWINDOW_OBJECT Window
;
4175 if(!(Window
= IntGetWindowObject(hWnd
)))
4177 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4182 IntReleaseWindowObject(Window
);
4186 /* Create a new window region using the window rectangle */
4187 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
4188 NtGdiOffsetRgn(VisRgn
, -Window
->WindowRect
.left
, -Window
->WindowRect
.top
);
4189 /* if there's a region assigned to the window, combine them both */
4190 if(Window
->WindowRegion
&& !(Window
->Style
& WS_MINIMIZE
))
4191 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4193 if((pRgn
= RGNDATA_LockRgn(VisRgn
)))
4195 Ret
= pRgn
->rdh
.iType
;
4196 *Rect
= pRgn
->rdh
.rcBound
;
4197 RGNDATA_UnlockRgn(pRgn
);
4202 NtGdiDeleteObject(VisRgn
);
4204 IntReleaseWindowObject(Window
);
4218 PWINDOW_OBJECT Window
;
4219 DECLARE_RETURN(INT
);
4221 DPRINT("Enter NtUserSetWindowRgn\n");
4222 UserEnterExclusive();
4224 if (!(Window
= IntGetWindowObject(hWnd
)))
4226 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4230 /* FIXME - Verify if hRgn is a valid handle!!!!
4231 Propably make this operation thread-safe, but maybe it's not necessary */
4233 if(Window
->WindowRegion
)
4235 /* Delete no longer needed region handle */
4236 NtGdiDeleteObject(Window
->WindowRegion
);
4238 Window
->WindowRegion
= hRgn
;
4240 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4244 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4247 IntReleaseWindowObject(Window
);
4251 DPRINT("Leave NtUserSystemParametersInfo, ret=%i\n",_ret_
);
4261 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4263 PWINDOW_OBJECT Window
;
4265 DECLARE_RETURN(BOOL
);
4267 DPRINT("Enter NtUserShowWindow\n");
4268 UserEnterExclusive();
4270 if (!(Window
= UserGetWindowObject(hWnd
)))
4275 UserRefObjectCo(Window
);
4276 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4277 UserDerefObjectCo(Window
);
4282 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4292 NtUserShowWindowAsync(DWORD Unknown0
,
4305 NtUserUpdateLayeredWindow(DWORD Unknown0
,
4325 NtUserValidateRect(HWND hWnd
, const RECT
* Rect
)
4327 return (VOID
)NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
4335 NtUserWindowFromPoint(LONG X
, LONG Y
)
4339 PWINDOW_OBJECT DesktopWindow
, Window
= NULL
;
4340 DECLARE_RETURN(HWND
);
4342 DPRINT("Enter NtUserWindowFromPoint\n");
4343 UserEnterExclusive();
4345 if ((DesktopWindow
= IntGetWindowObject(IntGetDesktopWindow())))
4352 Hit
= co_WinPosWindowFromPoint(DesktopWindow
, PsGetWin32Thread()->MessageQueue
, &pt
, &Window
);
4356 Ret
= Window
->hSelf
;
4357 IntReleaseWindowObject(Window
);
4358 IntReleaseWindowObject(DesktopWindow
);
4362 IntReleaseWindowObject(DesktopWindow
);
4368 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4378 * Undocumented function that is called from DefWindowProc to set
4386 NtUserDefSetText(HWND hWnd
, PUNICODE_STRING WindowText
)
4388 PWINDOW_OBJECT Window
, Parent
, Owner
;
4389 UNICODE_STRING SafeText
;
4391 DECLARE_RETURN(INT
);
4393 DPRINT("Enter NtUserDefSetText\n");
4394 UserEnterExclusive();
4396 if(!(Window
= IntGetWindowObject(hWnd
)))
4398 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4404 Status
= IntSafeCopyUnicodeString(&SafeText
, WindowText
);
4405 if(!NT_SUCCESS(Status
))
4407 SetLastNtError(Status
);
4408 IntReleaseWindowObject(Window
);
4414 RtlInitUnicodeString(&SafeText
, NULL
);
4417 /* FIXME - do this thread-safe! otherwise one could crash here! */
4418 RtlFreeUnicodeString(&Window
->WindowName
);
4420 Window
->WindowName
= SafeText
;
4422 /* Send shell notifications */
4424 Owner
= IntGetOwner(Window
);
4425 Parent
= IntGetParent(Window
);
4427 if ((!Owner
) && (!Parent
))
4429 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4434 IntReleaseWindowObject(Owner
);
4439 IntReleaseWindowObject(Parent
);
4442 IntReleaseWindowObject(Window
);
4446 DPRINT("Leave NtUserDefSetText, ret=%i\n",_ret_
);
4452 * NtUserInternalGetWindowText
4459 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4461 PWINDOW_OBJECT Window
;
4464 DECLARE_RETURN(INT
);
4466 DPRINT("Enter NtUserInternalGetWindowText\n");
4469 if(lpString
&& (nMaxCount
<= 1))
4471 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4475 if(!(Window
= IntGetWindowObject(hWnd
)))
4477 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4481 /* FIXME - do this thread-safe! otherwise one could crash here! */
4482 Result
= Window
->WindowName
.Length
/ sizeof(WCHAR
);
4485 const WCHAR Terminator
= L
'\0';
4487 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4489 Copy
= min(nMaxCount
- 1, Result
);
4492 Status
= MmCopyToCaller(Buffer
, Window
->WindowName
.Buffer
, Copy
* sizeof(WCHAR
));
4493 if(!NT_SUCCESS(Status
))
4495 SetLastNtError(Status
);
4496 IntReleaseWindowObject(Window
);
4502 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4503 if(!NT_SUCCESS(Status
))
4505 SetLastNtError(Status
);
4506 IntReleaseWindowObject(Window
);
4513 IntReleaseWindowObject(Window
);
4517 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4523 NtUserDereferenceWndProcHandle(WNDPROC wpHandle
, WndProcHandle
*Data
)
4525 DECLARE_RETURN(DWORD
);
4527 DPRINT("Enter NtUserDereferenceWndProcHandle\n");
4530 WndProcHandle Entry
;
4531 if (((DWORD
)wpHandle
& 0xFFFF0000) == 0xFFFF0000)
4533 Entry
= WndProcHandlesArray
[(DWORD
)wpHandle
& 0x0000FFFF];
4534 Data
->WindowProc
= Entry
.WindowProc
;
4535 Data
->IsUnicode
= Entry
.IsUnicode
;
4536 Data
->ProcessID
= Entry
.ProcessID
;
4544 DPRINT("Leave NtUserDereferenceWndProcHandle, ret=%i\n",_ret_
);
4550 IntAddWndProcHandle(WNDPROC WindowProc
, BOOL IsUnicode
)
4555 WndProcHandle
*OldArray
;
4558 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4560 if (WndProcHandlesArray
[i
].WindowProc
== NULL
)
4568 OldArray
= WndProcHandlesArray
;
4569 OldArraySize
= WndProcHandlesArraySize
;
4570 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,(OldArraySize
+ WPH_SIZE
) * sizeof(WndProcHandle
), TAG_WINPROCLST
);
4571 WndProcHandlesArraySize
= OldArraySize
+ WPH_SIZE
;
4572 RtlCopyMemory(WndProcHandlesArray
,OldArray
,OldArraySize
* sizeof(WndProcHandle
));
4573 ExFreePool(OldArray
);
4574 FreeSpot
= OldArraySize
+ 1;
4576 WndProcHandlesArray
[FreeSpot
].WindowProc
= WindowProc
;
4577 WndProcHandlesArray
[FreeSpot
].IsUnicode
= IsUnicode
;
4578 WndProcHandlesArray
[FreeSpot
].ProcessID
= PsGetCurrentProcessId();
4579 return FreeSpot
+ 0xFFFF0000;
4583 IntRemoveWndProcHandle(WNDPROC Handle
)
4586 position
= (DWORD
)Handle
& 0x0000FFFF;
4587 if (position
> WndProcHandlesArraySize
)
4591 WndProcHandlesArray
[position
].WindowProc
= NULL
;
4592 WndProcHandlesArray
[position
].IsUnicode
= FALSE
;
4593 WndProcHandlesArray
[position
].ProcessID
= NULL
;
4598 IntRemoveProcessWndProcHandles(HANDLE ProcessID
)
4601 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4603 if (WndProcHandlesArray
[i
].ProcessID
== ProcessID
)
4605 WndProcHandlesArray
[i
].WindowProc
= NULL
;
4606 WndProcHandlesArray
[i
].IsUnicode
= FALSE
;
4607 WndProcHandlesArray
[i
].ProcessID
= NULL
;
4613 #define WIN_NEEDS_SHOW_OWNEDPOPUP (0x00000040)
4617 IntShowOwnedPopups( HWND owner
, BOOL fShow
)
4620 PWINDOW_OBJECT Window
, pWnd
;
4623 if(!(Window
= IntGetWindowObject(owner
)))
4625 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4629 win_array
= IntWinListChildren( Window
);
4630 IntReleaseWindowObject(Window
);
4632 if (!win_array
) return TRUE
;
4634 while (win_array
[count
]) count
++;
4635 while (--count
>= 0)
4637 if (UserGetWindow( win_array
[count
], GW_OWNER
) != owner
) continue;
4638 if (!(pWnd
= IntGetWindowObject( win_array
[count
] ))) continue;
4639 // if (pWnd == WND_OTHER_PROCESS) continue;
4643 if (pWnd
->Flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
)
4645 IntReleaseWindowObject( pWnd
);
4646 /* In Windows, ShowOwnedPopups(TRUE) generates
4647 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4648 * regardless of the state of the owner
4650 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4656 if (pWnd
->Style
& WS_VISIBLE
)
4658 IntReleaseWindowObject( pWnd
);
4659 /* In Windows, ShowOwnedPopups(FALSE) generates
4660 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4661 * regardless of the state of the owner
4663 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4667 IntReleaseWindowObject( pWnd
);
4669 ExFreePool( win_array
);