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.
19 /* $Id: window.c,v 1.255 2004/12/12 23:08:11 navaraf Exp $
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
24 * FILE: subsys/win32k/ntuser/window.c
25 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
27 * 06-06-2001 CSH Created
29 /* INCLUDES ******************************************************************/
32 static WndProcHandle
*WndProcHandlesArray
= 0;
33 static WORD WndProcHandlesArraySize
= 0;
34 #define WPH_SIZE 0x40 /* the size to add to the WndProcHandle array each time */
36 /* dialog resources appear to pass this in 16 bits, handle them properly */
37 #define CW_USEDEFAULT16 (0x8000)
39 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
41 /* PRIVATE FUNCTIONS **********************************************************/
46 * Initialize windowing implementation.
52 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,WPH_SIZE
* sizeof(WndProcHandle
), TAG_WINPROCLST
);
53 WndProcHandlesArraySize
= WPH_SIZE
;
54 return STATUS_SUCCESS
;
60 * Cleanup windowing implementation.
64 CleanupWindowImpl(VOID
)
66 ExFreePool(WndProcHandlesArray
);
67 WndProcHandlesArray
= 0;
68 WndProcHandlesArraySize
= 0;
69 return STATUS_SUCCESS
;
72 /* HELPER FUNCTIONS ***********************************************************/
77 * The function determines whether the specified window handle identifies
82 * Handle to the window to test.
85 * If the window handle identifies an existing window, the return value
86 * is TRUE. If the window handle does not identify an existing window,
87 * the return value is FALSE.
91 IntIsWindow(HWND hWnd
)
93 PWINDOW_OBJECT Window
;
95 if (!(Window
= IntGetWindowObject(hWnd
)))
98 IntReleaseWindowObject(Window
);
103 * IntGetProcessWindowObject
105 * Get window object from handle of specified process.
108 PWINDOW_OBJECT FASTCALL
109 IntGetProcessWindowObject(PW32THREAD Thread
, HWND hWnd
)
111 PWINDOW_OBJECT WindowObject
;
114 if(Thread
->Desktop
!= NULL
)
116 Status
= ObmReferenceObjectByHandle(Thread
->Desktop
->WindowStation
->HandleTable
,
117 hWnd
, otWindow
, (PVOID
*)&WindowObject
);
118 if (NT_SUCCESS(Status
))
127 PWINDOW_OBJECT FASTCALL
128 IntGetParent(PWINDOW_OBJECT Wnd
)
132 if (Wnd
->Style
& WS_POPUP
)
134 IntLockRelatives(Wnd
);
136 IntUnLockRelatives(Wnd
);
137 return IntGetWindowObject(hWnd
);
139 else if (Wnd
->Style
& WS_CHILD
)
141 IntLockRelatives(Wnd
);
143 IntUnLockRelatives(Wnd
);
144 return IntGetWindowObject(hWnd
);
151 PWINDOW_OBJECT FASTCALL
152 IntGetParentObject(PWINDOW_OBJECT Wnd
)
156 IntLockRelatives(Wnd
);
157 hParent
= Wnd
->Parent
;
158 IntUnLockRelatives(Wnd
);
159 return IntGetWindowObject(hParent
);
165 * Compile a list of all child window handles from given window.
168 * This function is similar to Wine WIN_ListChildren. The caller
169 * must free the returned list with ExFreePool.
173 IntWinListChildren(PWINDOW_OBJECT Window
)
175 PWINDOW_OBJECT Child
;
177 UINT Index
, NumChildren
= 0;
179 IntLockRelatives(Window
);
181 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
184 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
187 DPRINT1("Failed to allocate memory for children array\n");
188 IntUnLockRelatives(Window
);
189 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
192 for (Child
= Window
->FirstChild
, Index
= 0;
194 Child
= Child
->NextSibling
, ++Index
)
195 List
[Index
] = Child
->Self
;
198 IntUnLockRelatives(Window
);
203 /***********************************************************************
206 static void IntSendDestroyMsg(HWND Wnd
)
211 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
213 if (Wnd
== info
.hwndCaret
)
221 * Send the WM_DESTROY to the window.
223 IntSendMessage(Wnd
, WM_DESTROY
, 0, 0);
226 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
227 * make sure that the window still exists when we come back.
235 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
237 /* start from the end (FIXME: is this needed?) */
238 for (i
= 0; pWndArray
[i
]; i
++) ;
242 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
244 HeapFree(GetProcessHeap(), 0, pWndArray
);
248 DPRINT("destroyed itself while in WM_DESTROY!\n");
253 /***********************************************************************
256 * Destroy storage associated to a window. "Internals" p.358
258 static LRESULT
IntDestroyWindow(PWINDOW_OBJECT Window
,
259 PW32PROCESS ProcessData
,
260 PW32THREAD ThreadData
,
261 BOOLEAN SendMessages
)
265 PWINDOW_OBJECT Child
;
267 BOOL BelongsToThreadData
;
271 RemoveTimersWindow(Window
->Self
);
273 IntLockThreadWindows(Window
->OwnerThread
->Tcb
.Win32Thread
);
274 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
276 IntUnLockThreadWindows(Window
->OwnerThread
->Tcb
.Win32Thread
);
277 DPRINT("Tried to call IntDestroyWindow() twice\n");
280 Window
->Status
|= WINDOWSTATUS_DESTROYING
;
281 Window
->Flags
&= ~WS_VISIBLE
;
282 /* remove the window already at this point from the thread window list so we
283 don't get into trouble when destroying the thread windows while we're still
284 in IntDestroyWindow() */
285 RemoveEntryList(&Window
->ThreadListEntry
);
286 IntUnLockThreadWindows(Window
->OwnerThread
->Tcb
.Win32Thread
);
288 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
292 /* Send destroy messages */
293 IntSendDestroyMsg(Window
->Self
);
294 if(BelongsToThreadData
)
295 IntSendMessage(Window
->Self
, WM_NCDESTROY
, 0, 0);
298 /* from now on no messages can be sent to this window anymore */
299 IntLockThreadWindows(Window
->OwnerThread
->Tcb
.Win32Thread
);
300 Window
->Status
|= WINDOWSTATUS_DESTROYED
;
301 /* don't remove the WINDOWSTATUS_DESTROYING bit */
302 IntUnLockThreadWindows(Window
->OwnerThread
->Tcb
.Win32Thread
);
304 /* flush the message queue */
305 MsqRemoveWindowMessagesFromQueue(Window
);
307 /* free child windows */
308 Children
= IntWinListChildren(Window
);
311 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
313 if ((Child
= IntGetWindowObject(*ChildHandle
)))
315 if(!IntWndBelongsToThread(Child
, ThreadData
))
317 /* send WM_DESTROY messages to windows not belonging to the same thread */
318 IntSendDestroyMsg(Child
->Self
);
321 IntDestroyWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
322 IntReleaseWindowObject(Child
);
325 ExFreePool(Children
);
328 /* reset shell window handles */
329 if(ThreadData
->Desktop
)
331 if (Window
->Self
== ThreadData
->Desktop
->WindowStation
->ShellWindow
)
332 ThreadData
->Desktop
->WindowStation
->ShellWindow
= NULL
;
334 if (Window
->Self
== ThreadData
->Desktop
->WindowStation
->ShellListView
)
335 ThreadData
->Desktop
->WindowStation
->ShellListView
= NULL
;
338 /* Unregister hot keys */
339 UnregisterWindowHotKeys (Window
);
341 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
344 WinPosCheckInternalPos(Window
->Self
);
345 if (Window
->Self
== GetCapture())
350 /* free resources associated with the window */
351 TIMER_RemoveWindowTimers(Window
->Self
);
354 if (!(Window
->Style
& WS_CHILD
) && Window
->IDMenu
355 && (Menu
= IntGetMenuObject((HMENU
)Window
->IDMenu
)))
357 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
359 IntReleaseMenuObject(Menu
);
362 if(Window
->SystemMenu
363 && (Menu
= IntGetMenuObject(Window
->SystemMenu
)))
365 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
366 Window
->SystemMenu
= (HMENU
)0;
367 IntReleaseMenuObject(Menu
);
370 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
372 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
373 CLASS_RemoveWindow(Window
->Class
);
376 IntUnlinkWindow(Window
);
378 IntReferenceWindowObject(Window
);
379 ObmCloseHandle(ThreadData
->Desktop
->WindowStation
->HandleTable
, Window
->Self
);
381 IntDestroyScrollBars(Window
);
383 /* remove the window from the class object */
384 IntLockClassWindows(Window
->Class
);
385 RemoveEntryList(&Window
->ClassListEntry
);
386 IntUnLockClassWindows(Window
->Class
);
388 /* dereference the class */
389 ClassDereferenceObject(Window
->Class
);
390 Window
->Class
= NULL
;
392 if(Window
->WindowRegion
)
394 NtGdiDeleteObject(Window
->WindowRegion
);
397 RtlFreeUnicodeString(&Window
->WindowName
);
399 IntReleaseWindowObject(Window
);
405 IntGetWindowBorderMeasures(PWINDOW_OBJECT WindowObject
, UINT
*cx
, UINT
*cy
)
407 if(HAS_DLGFRAME(WindowObject
->Style
, WindowObject
->ExStyle
) && !(WindowObject
->Style
& WS_MINIMIZE
))
409 *cx
= NtUserGetSystemMetrics(SM_CXDLGFRAME
);
410 *cy
= NtUserGetSystemMetrics(SM_CYDLGFRAME
);
414 if(HAS_THICKFRAME(WindowObject
->Style
, WindowObject
->ExStyle
)&& !(WindowObject
->Style
& WS_MINIMIZE
))
416 *cx
= NtUserGetSystemMetrics(SM_CXFRAME
);
417 *cy
= NtUserGetSystemMetrics(SM_CYFRAME
);
419 else if(HAS_THINFRAME(WindowObject
->Style
, WindowObject
->ExStyle
))
421 *cx
= NtUserGetSystemMetrics(SM_CXBORDER
);
422 *cy
= NtUserGetSystemMetrics(SM_CYBORDER
);
432 IntGetWindowInfo(PWINDOW_OBJECT WindowObject
, PWINDOWINFO pwi
)
434 pwi
->cbSize
= sizeof(WINDOWINFO
);
435 pwi
->rcWindow
= WindowObject
->WindowRect
;
436 pwi
->rcClient
= WindowObject
->ClientRect
;
437 pwi
->dwStyle
= WindowObject
->Style
;
438 pwi
->dwExStyle
= WindowObject
->ExStyle
;
439 pwi
->dwWindowStatus
= (NtUserGetForegroundWindow() == WindowObject
->Self
); /* WS_ACTIVECAPTION */
440 IntGetWindowBorderMeasures(WindowObject
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
441 pwi
->atomWindowType
= (WindowObject
->Class
? WindowObject
->Class
->Atom
: 0);
442 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
448 PWINDOW_OBJECT WindowObject
,
452 PMENU_OBJECT OldMenuObject
, NewMenuObject
= NULL
;
454 *Changed
= (WindowObject
->IDMenu
!= (UINT
) Menu
);
460 if (0 != WindowObject
->IDMenu
)
462 OldMenuObject
= IntGetMenuObject((HMENU
) WindowObject
->IDMenu
);
463 ASSERT(NULL
== OldMenuObject
|| OldMenuObject
->MenuInfo
.Wnd
== WindowObject
->Self
);
467 OldMenuObject
= NULL
;
472 NewMenuObject
= IntGetMenuObject(Menu
);
473 if (NULL
== NewMenuObject
)
475 if (NULL
!= OldMenuObject
)
477 IntReleaseMenuObject(OldMenuObject
);
479 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
482 if (NULL
!= NewMenuObject
->MenuInfo
.Wnd
)
484 /* Can't use the same menu for two windows */
485 if (NULL
!= OldMenuObject
)
487 IntReleaseMenuObject(OldMenuObject
);
489 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
495 WindowObject
->IDMenu
= (UINT
) Menu
;
496 if (NULL
!= NewMenuObject
)
498 NewMenuObject
->MenuInfo
.Wnd
= WindowObject
->Self
;
499 IntReleaseMenuObject(NewMenuObject
);
501 if (NULL
!= OldMenuObject
)
503 OldMenuObject
->MenuInfo
.Wnd
= NULL
;
504 IntReleaseMenuObject(OldMenuObject
);
511 /* INTERNAL ******************************************************************/
515 DestroyThreadWindows(struct _ETHREAD
*Thread
)
518 PW32PROCESS Win32Process
;
519 PW32THREAD Win32Thread
;
520 PWINDOW_OBJECT
*List
, *pWnd
;
523 Win32Thread
= Thread
->Tcb
.Win32Thread
;
524 Win32Process
= Thread
->ThreadsProcess
->Win32Process
;
526 IntLockThreadWindows(Win32Thread
);
527 Current
= Win32Thread
->WindowListHead
.Flink
;
528 while (Current
!= &(Win32Thread
->WindowListHead
))
531 Current
= Current
->Flink
;
536 List
= ExAllocatePool(PagedPool
, (Cnt
+ 1) * sizeof(PWINDOW_OBJECT
));
539 DPRINT("Not enough memory to allocate window handle list\n");
540 IntUnLockThreadWindows(Win32Thread
);
544 Current
= Win32Thread
->WindowListHead
.Flink
;
545 while (Current
!= &(Win32Thread
->WindowListHead
))
547 *pWnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
548 IntReferenceWindowObject(*pWnd
);
550 Current
= Current
->Flink
;
552 IntUnLockThreadWindows(Win32Thread
);
555 for(pWnd
= List
; *pWnd
; pWnd
++)
557 NtUserDestroyWindow((*pWnd
)->Self
);
558 IntReleaseWindowObject(*pWnd
);
564 IntUnLockThreadWindows(Win32Thread
);
570 * Returns client window rectangle relative to the upper-left corner of client area.
572 * \note Does not check the validity of the parameters
575 IntGetClientRect(PWINDOW_OBJECT WindowObject
, PRECT Rect
)
577 ASSERT( WindowObject
);
580 Rect
->left
= Rect
->top
= 0;
581 Rect
->right
= WindowObject
->ClientRect
.right
- WindowObject
->ClientRect
.left
;
582 Rect
->bottom
= WindowObject
->ClientRect
.bottom
- WindowObject
->ClientRect
.top
;
588 IntGetFocusWindow(VOID
)
590 PUSER_MESSAGE_QUEUE Queue
;
591 PDESKTOP_OBJECT pdo
= IntGetActiveDesktop();
596 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
601 return(Queue
->FocusWindow
);
605 PMENU_OBJECT FASTCALL
606 IntGetSystemMenu(PWINDOW_OBJECT WindowObject
, BOOL bRevert
, BOOL RetMenu
)
608 PMENU_OBJECT MenuObject
, NewMenuObject
, SysMenuObject
, ret
= NULL
;
609 PW32THREAD W32Thread
;
610 HMENU NewMenu
, SysMenu
;
611 ROSMENUITEMINFO ItemInfo
;
615 W32Thread
= PsGetWin32Thread();
617 if(!W32Thread
->Desktop
)
620 if(WindowObject
->SystemMenu
)
622 MenuObject
= IntGetMenuObject(WindowObject
->SystemMenu
);
625 IntDestroyMenuObject(MenuObject
, FALSE
, TRUE
);
626 WindowObject
->SystemMenu
= (HMENU
)0;
627 IntReleaseMenuObject(MenuObject
);
631 if(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
)
633 /* clone system menu */
634 MenuObject
= IntGetMenuObject(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
);
638 NewMenuObject
= IntCloneMenu(MenuObject
);
641 WindowObject
->SystemMenu
= NewMenuObject
->MenuInfo
.Self
;
642 NewMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
643 NewMenuObject
->MenuInfo
.Wnd
= WindowObject
->Self
;
645 //IntReleaseMenuObject(NewMenuObject);
647 IntReleaseMenuObject(MenuObject
);
651 SysMenu
= NtUserCreateMenu(FALSE
);
656 SysMenuObject
= IntGetMenuObject(SysMenu
);
657 if (NULL
== SysMenuObject
)
659 NtUserDestroyMenu(SysMenu
);
662 SysMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
663 SysMenuObject
->MenuInfo
.Wnd
= WindowObject
->Self
;
664 NewMenu
= IntLoadSysMenuTemplate();
667 IntReleaseMenuObject(SysMenuObject
);
668 NtUserDestroyMenu(SysMenu
);
671 MenuObject
= IntGetMenuObject(NewMenu
);
674 IntReleaseMenuObject(SysMenuObject
);
675 NtUserDestroyMenu(SysMenu
);
679 NewMenuObject
= IntCloneMenu(MenuObject
);
682 NewMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
683 IntReleaseMenuObject(NewMenuObject
);
684 NtUserSetMenuDefaultItem(NewMenuObject
->MenuInfo
.Self
, SC_CLOSE
, FALSE
);
686 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
687 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
688 ItemInfo
.fType
= MF_POPUP
;
689 ItemInfo
.fState
= MFS_ENABLED
;
690 ItemInfo
.dwTypeData
= NULL
;
692 ItemInfo
.hSubMenu
= NewMenuObject
->MenuInfo
.Self
;
693 IntInsertMenuItem(SysMenuObject
, (UINT
) -1, TRUE
, &ItemInfo
);
695 WindowObject
->SystemMenu
= SysMenuObject
->MenuInfo
.Self
;
699 IntDestroyMenuObject(MenuObject
, FALSE
, TRUE
);
700 IntReleaseMenuObject(MenuObject
);
709 if(WindowObject
->SystemMenu
)
710 return IntGetMenuObject((HMENU
)WindowObject
->SystemMenu
);
718 IntIsChildWindow(HWND Parent
, HWND Child
)
720 PWINDOW_OBJECT BaseWindow
, Window
, Old
;
722 if(!(BaseWindow
= IntGetWindowObject(Child
)))
730 if (Window
->Self
== Parent
)
732 if(Window
!= BaseWindow
)
733 IntReleaseWindowObject(Window
);
734 IntReleaseWindowObject(BaseWindow
);
737 if(!(Window
->Style
& WS_CHILD
))
739 if(Window
!= BaseWindow
)
740 IntReleaseWindowObject(Window
);
744 Window
= IntGetParentObject(Window
);
745 if(Old
!= BaseWindow
)
746 IntReleaseWindowObject(Old
);
749 IntReleaseWindowObject(BaseWindow
);
754 IntIsWindowVisible(HWND hWnd
)
756 PWINDOW_OBJECT BaseWindow
, Window
, Old
;
758 if(!(BaseWindow
= IntGetWindowObject(hWnd
)))
766 if(!(Window
->Style
& WS_CHILD
))
770 if(!(Window
->Style
& WS_VISIBLE
))
772 if(Window
!= BaseWindow
)
773 IntReleaseWindowObject(Window
);
774 IntReleaseWindowObject(BaseWindow
);
778 Window
= IntGetParentObject(Window
);
779 if(Old
!= BaseWindow
)
780 IntReleaseWindowObject(Old
);
785 if(Window
->Style
& WS_VISIBLE
)
787 if(Window
!= BaseWindow
)
788 IntReleaseWindowObject(Window
);
789 IntReleaseWindowObject(BaseWindow
);
792 if(Window
!= BaseWindow
)
793 IntReleaseWindowObject(Window
);
795 IntReleaseWindowObject(BaseWindow
);
800 /* link the window into siblings and parent. children are kept in place. */
804 PWINDOW_OBJECT WndParent
,
805 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
808 PWINDOW_OBJECT Parent
;
810 IntLockRelatives(Wnd
);
811 Wnd
->Parent
= WndParent
->Self
;
812 if ((Wnd
->PrevSibling
= WndPrevSibling
))
814 /* link after WndPrevSibling */
815 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
816 Wnd
->NextSibling
->PrevSibling
= Wnd
;
817 else if ((Parent
= IntGetWindowObject(Wnd
->Parent
)))
819 IntLockRelatives(Parent
);
820 if(Parent
->LastChild
== WndPrevSibling
)
821 Parent
->LastChild
= Wnd
;
822 IntUnLockRelatives(Parent
);
823 IntReleaseWindowObject(Parent
);
825 Wnd
->PrevSibling
->NextSibling
= Wnd
;
830 Parent
= IntGetWindowObject(Wnd
->Parent
);
831 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
832 Wnd
->NextSibling
->PrevSibling
= Wnd
;
835 IntLockRelatives(Parent
);
836 Parent
->LastChild
= Wnd
;
837 Parent
->FirstChild
= Wnd
;
838 IntUnLockRelatives(Parent
);
839 IntReleaseWindowObject(Parent
);
840 IntUnLockRelatives(Wnd
);
845 IntLockRelatives(Parent
);
846 Parent
->FirstChild
= Wnd
;
847 IntUnLockRelatives(Parent
);
848 IntReleaseWindowObject(Parent
);
851 IntUnLockRelatives(Wnd
);
855 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
857 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
860 Wnd
= IntGetWindowObject(hWnd
);
864 IntLockRelatives(Wnd
);
865 WndOldOwner
= IntGetWindowObject(Wnd
->Owner
);
868 ret
= WndOldOwner
->Self
;
869 IntReleaseWindowObject(WndOldOwner
);
876 if((WndNewOwner
= IntGetWindowObject(hWndNewOwner
)))
878 Wnd
->Owner
= hWndNewOwner
;
879 IntReleaseWindowObject(WndNewOwner
);
884 IntUnLockRelatives(Wnd
);
885 IntReleaseWindowObject(Wnd
);
889 PWINDOW_OBJECT FASTCALL
890 IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
892 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
893 HWND hWnd
, hWndNewParent
, hWndOldParent
;
898 ASSERT(WndNewParent
);
901 hWndNewParent
= WndNewParent
->Self
;
904 * Windows hides the window first, then shows it again
905 * including the WM_SHOWWINDOW messages and all
907 WasVisible
= WinPosShowWindow(hWnd
, SW_HIDE
);
909 /* Validate that window and parent still exist */
910 if (!IntIsWindow(hWnd
) || !IntIsWindow(hWndNewParent
))
913 /* Window must belong to current process */
914 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
917 WndOldParent
= IntGetParentObject(Wnd
);
918 hWndOldParent
= (WndOldParent
? WndOldParent
->Self
: NULL
);
920 if (WndNewParent
!= WndOldParent
)
922 IntUnlinkWindow(Wnd
);
924 if (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
))
926 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
927 IntLockRelatives(WndNewParent
);
928 Sibling
= WndNewParent
->FirstChild
;
929 while (NULL
!= Sibling
&& 0 != (Sibling
->ExStyle
& WS_EX_TOPMOST
))
931 InsertAfter
= Sibling
;
932 Sibling
= Sibling
->NextSibling
;
934 IntUnLockRelatives(WndNewParent
);
936 if (NULL
== InsertAfter
)
938 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
942 IntReferenceWindowObject(InsertAfter
);
943 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
944 IntReleaseWindowObject(InsertAfter
);
947 if (WndNewParent
->Self
!= IntGetDesktopWindow()) /* a child window */
949 if (!(Wnd
->Style
& WS_CHILD
))
951 //if ( Wnd->Menu ) DestroyMenu ( Wnd->menu );
952 IntSetMenu(Wnd
, NULL
, &MenuChanged
);
958 * SetParent additionally needs to make hwnd the top window
959 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
960 * WM_WINDOWPOSCHANGED notification messages.
962 WinPosSetWindowPos(hWnd
, (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
963 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
964 | (WasVisible
? SWP_SHOWWINDOW
: 0));
967 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
968 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
972 * Validate that the old parent still exist, since it migth have been
973 * destroyed during the last callbacks to user-mode
977 if(!IntIsWindow(WndOldParent
->Self
))
979 IntReleaseWindowObject(WndOldParent
);
983 /* don't dereference the window object here, it must be done by the caller
991 IntSetSystemMenu(PWINDOW_OBJECT WindowObject
, PMENU_OBJECT MenuObject
)
993 PMENU_OBJECT OldMenuObject
;
994 if(WindowObject
->SystemMenu
)
996 OldMenuObject
= IntGetMenuObject(WindowObject
->SystemMenu
);
999 OldMenuObject
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1000 IntReleaseMenuObject(OldMenuObject
);
1006 /* FIXME check window style, propably return FALSE ? */
1007 WindowObject
->SystemMenu
= MenuObject
->MenuInfo
.Self
;
1008 MenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
1011 WindowObject
->SystemMenu
= (HMENU
)0;
1017 /* unlink the window from siblings and parent. children are kept in place. */
1019 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1021 PWINDOW_OBJECT WndParent
;
1023 IntLockRelatives(Wnd
);
1024 if((WndParent
= IntGetWindowObject(Wnd
->Parent
)))
1026 IntLockRelatives(WndParent
);
1029 if (Wnd
->NextSibling
) Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1030 else if (WndParent
&& WndParent
->LastChild
== Wnd
) WndParent
->LastChild
= Wnd
->PrevSibling
;
1032 if (Wnd
->PrevSibling
) Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1033 else if (WndParent
&& WndParent
->FirstChild
== Wnd
) WndParent
->FirstChild
= Wnd
->NextSibling
;
1037 IntUnLockRelatives(WndParent
);
1038 IntReleaseWindowObject(WndParent
);
1040 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1041 IntUnLockRelatives(Wnd
);
1047 PWINDOW_OBJECT Window
, Child
;
1049 if(!(Window
= IntGetWindowObject(IntGetDesktopWindow())))
1051 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1055 IntLockRelatives(Window
);
1056 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1058 if(Child
->Owner
&& Child
->Style
& WS_VISIBLE
)
1061 * The desktop has a popup window if one of them has
1062 * an owner window and is visible
1064 IntUnLockRelatives(Window
);
1065 IntReleaseWindowObject(Window
);
1069 IntUnLockRelatives(Window
);
1070 IntReleaseWindowObject(Window
);
1075 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1077 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1080 /* FUNCTIONS *****************************************************************/
1086 NtUserAlterWindowStyle(DWORD Unknown0
,
1097 * As best as I can figure, this function is used by EnumWindows,
1098 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1100 * It's supposed to build a list of HWNDs to return to the caller.
1101 * We can figure out what kind of list by what parameters are
1109 NtUserBuildHwndList(
1121 /* FIXME handle bChildren */
1125 PWINDOW_OBJECT Window
, Child
;
1126 if(!(Window
= IntGetWindowObject(hwndParent
)))
1128 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1132 IntLockRelatives(Window
);
1133 for(Child
= Window
->FirstChild
; Child
!= NULL
; Child
= Child
->NextSibling
)
1135 if(dwCount
++ < nBufSize
&& pWnd
)
1137 Status
= MmCopyToCaller(pWnd
++, &Child
->Self
, sizeof(HWND
));
1138 if(!NT_SUCCESS(Status
))
1140 SetLastNtError(Status
);
1145 IntUnLockRelatives(Window
);
1147 IntReleaseWindowObject(Window
);
1152 PW32THREAD W32Thread
;
1153 PLIST_ENTRY Current
;
1154 PWINDOW_OBJECT Window
;
1156 Status
= PsLookupThreadByThreadId((PVOID
)dwThreadId
, &Thread
);
1157 if(!NT_SUCCESS(Status
))
1159 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1162 if(!(W32Thread
= Thread
->Tcb
.Win32Thread
))
1164 ObDereferenceObject(Thread
);
1165 DPRINT1("Thread is not a GUI Thread!\n");
1166 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1170 IntLockThreadWindows(W32Thread
);
1171 Current
= W32Thread
->WindowListHead
.Flink
;
1172 while(Current
!= &(W32Thread
->WindowListHead
))
1174 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1177 if(dwCount
< nBufSize
&& pWnd
)
1179 Status
= MmCopyToCaller(pWnd
++, &Window
->Self
, sizeof(HWND
));
1180 if(!NT_SUCCESS(Status
))
1182 SetLastNtError(Status
);
1187 Current
= Current
->Flink
;
1189 IntUnLockThreadWindows(W32Thread
);
1191 ObDereferenceObject(Thread
);
1195 PDESKTOP_OBJECT Desktop
;
1196 PWINDOW_OBJECT Window
, Child
;
1198 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1200 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1206 Status
= IntValidateDesktopHandle(hDesktop
,
1210 if(!NT_SUCCESS(Status
))
1212 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1216 if(!(Window
= IntGetWindowObject(Desktop
->DesktopWindow
)))
1219 ObDereferenceObject(Desktop
);
1220 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1224 IntLockRelatives(Window
);
1225 for(Child
= Window
->FirstChild
; Child
!= NULL
; Child
= Child
->NextSibling
)
1227 if(dwCount
++ < nBufSize
&& pWnd
)
1229 Status
= MmCopyToCaller(pWnd
++, &Child
->Self
, sizeof(HWND
));
1230 if(!NT_SUCCESS(Status
))
1232 SetLastNtError(Status
);
1237 IntUnLockRelatives(Window
);
1239 IntReleaseWindowObject(Window
);
1241 ObDereferenceObject(Desktop
);
1252 NtUserChildWindowFromPointEx(HWND hwndParent
,
1257 PWINDOW_OBJECT Parent
;
1262 if(!(Parent
= IntGetWindowObject(hwndParent
)))
1264 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1271 if(Parent
->Self
!= IntGetDesktopWindow())
1273 Pt
.x
+= Parent
->ClientRect
.left
;
1274 Pt
.y
+= Parent
->ClientRect
.top
;
1277 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1279 IntReleaseWindowObject(Parent
);
1284 if((List
= IntWinListChildren(Parent
)))
1286 for(phWnd
= List
; *phWnd
; phWnd
++)
1288 PWINDOW_OBJECT Child
;
1289 if((Child
= IntGetWindowObject(*phWnd
)))
1291 if(!(Child
->Style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1293 IntReleaseWindowObject(Child
);
1296 if((Child
->Style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1298 IntReleaseWindowObject(Child
);
1301 if((Child
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1303 IntReleaseWindowObject(Child
);
1306 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1309 IntReleaseWindowObject(Child
);
1312 IntReleaseWindowObject(Child
);
1318 IntReleaseWindowObject(Parent
);
1324 * calculates the default position of a window
1327 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT WindowObject
, RECT
*rc
, BOOL IncPos
)
1334 IntGdiIntersectRect(rc
, rc
, &Parent
->ClientRect
);
1338 Pos
.x
= Parent
->TiledCounter
* (NtUserGetSystemMetrics(SM_CXSIZE
) + NtUserGetSystemMetrics(SM_CXFRAME
));
1339 Pos
.y
= Parent
->TiledCounter
* (NtUserGetSystemMetrics(SM_CYSIZE
) + NtUserGetSystemMetrics(SM_CYFRAME
));
1340 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1341 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1343 /* reset counter and position */
1346 Parent
->TiledCounter
= 0;
1348 Parent
->TiledCounter
++;
1359 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1360 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1364 rc
->right
= rc
->left
+ Sz
.cx
;
1365 rc
->bottom
= rc
->top
+ Sz
.cy
;
1374 IntCreateWindowEx(DWORD dwExStyle
,
1375 PUNICODE_STRING ClassName
,
1376 PUNICODE_STRING WindowName
,
1384 HINSTANCE hInstance
,
1387 BOOL bUnicodeWindow
)
1389 PWINSTATION_OBJECT WinStaObject
;
1390 PWNDCLASS_OBJECT ClassObject
;
1391 PWINDOW_OBJECT WindowObject
;
1392 PWINDOW_OBJECT ParentWindow
, OwnerWindow
;
1393 HWND ParentWindowHandle
;
1394 HWND OwnerWindowHandle
;
1395 PMENU_OBJECT SystemMenu
;
1400 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1405 CBT_CREATEWNDW CbtCreate
;
1410 ParentWindowHandle
= PsGetWin32Thread()->Desktop
->DesktopWindow
;
1411 OwnerWindowHandle
= NULL
;
1413 if (hWndParent
== HWND_MESSAGE
)
1416 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1417 * message window (style: WS_POPUP|WS_DISABLED)
1419 DPRINT1("FIXME - Parent is HWND_MESSAGE\n");
1421 else if (hWndParent
)
1423 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1424 ParentWindowHandle
= hWndParent
;
1426 OwnerWindowHandle
= NtUserGetAncestor(hWndParent
, GA_ROOT
);
1428 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1430 return (HWND
)0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1433 if (NULL
!= ParentWindowHandle
)
1435 ParentWindow
= IntGetWindowObject(ParentWindowHandle
);
1439 ParentWindow
= NULL
;
1442 /* FIXME: parent must belong to the current process */
1444 /* Check the class. */
1445 ClassFound
= ClassReferenceClassByNameOrAtom(&ClassObject
, ClassName
->Buffer
, hInstance
);
1448 if (IS_ATOM(ClassName
->Buffer
))
1450 DPRINT1("Class 0x%x not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1454 DPRINT1("Class %wZ not found\n", ClassName
);
1456 if (NULL
!= ParentWindow
)
1458 IntReleaseWindowObject(ParentWindow
);
1460 SetLastWin32Error(ERROR_CANNOT_FIND_WND_CLASS
);
1464 /* Check the window station. */
1465 if (PsGetWin32Thread()->Desktop
== NULL
)
1467 ClassDereferenceObject(ClassObject
);
1468 if (NULL
!= ParentWindow
)
1470 IntReleaseWindowObject(ParentWindow
);
1472 DPRINT("Thread is not attached to a desktop! Cannot create window!\n");
1475 WinStaObject
= PsGetWin32Thread()->Desktop
->WindowStation
;
1476 ObReferenceObjectByPointer(WinStaObject
, KernelMode
, ExWindowStationObjectType
, 0);
1478 /* Create the window object. */
1479 WindowObject
= (PWINDOW_OBJECT
)
1480 ObmCreateObject(PsGetWin32Thread()->Desktop
->WindowStation
->HandleTable
, &Handle
,
1481 otWindow
, sizeof(WINDOW_OBJECT
) + ClassObject
->cbWndExtra
1484 DPRINT("Created object with handle %X\n", Handle
);
1487 ObDereferenceObject(WinStaObject
);
1488 ClassDereferenceObject(ClassObject
);
1489 if (NULL
!= ParentWindow
)
1491 IntReleaseWindowObject(ParentWindow
);
1493 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1496 ObDereferenceObject(WinStaObject
);
1498 if (NULL
== PsGetWin32Thread()->Desktop
->DesktopWindow
)
1500 /* If there is no desktop window yet, we must be creating it */
1501 PsGetWin32Thread()->Desktop
->DesktopWindow
= Handle
;
1505 * Fill out the structure describing it.
1507 WindowObject
->Class
= ClassObject
;
1508 IntLockClassWindows(ClassObject
);
1509 InsertTailList(&ClassObject
->ClassWindowsListHead
, &WindowObject
->ClassListEntry
);
1510 IntUnLockClassWindows(ClassObject
);
1512 WindowObject
->ExStyle
= dwExStyle
;
1513 WindowObject
->Style
= dwStyle
& ~WS_VISIBLE
;
1514 DPRINT("1: Style is now %lx\n", WindowObject
->Style
);
1516 WindowObject
->SystemMenu
= (HMENU
)0;
1517 WindowObject
->ContextHelpId
= 0;
1518 WindowObject
->IDMenu
= 0;
1519 WindowObject
->Instance
= hInstance
;
1520 WindowObject
->Self
= Handle
;
1521 if (0 != (dwStyle
& WS_CHILD
))
1523 WindowObject
->IDMenu
= (UINT
) hMenu
;
1527 IntSetMenu(WindowObject
, hMenu
, &MenuChanged
);
1529 WindowObject
->MessageQueue
= PsGetWin32Thread()->MessageQueue
;
1530 WindowObject
->Parent
= (ParentWindow
? ParentWindow
->Self
: NULL
);
1531 if((OwnerWindow
= IntGetWindowObject(OwnerWindowHandle
)))
1533 WindowObject
->Owner
= OwnerWindowHandle
;
1534 IntReleaseWindowObject(OwnerWindow
);
1537 WindowObject
->Owner
= NULL
;
1538 WindowObject
->UserData
= 0;
1539 if ((((DWORD
)ClassObject
->lpfnWndProcA
& 0xFFFF0000) != 0xFFFF0000)
1540 && (((DWORD
)ClassObject
->lpfnWndProcW
& 0xFFFF0000) != 0xFFFF0000))
1542 WindowObject
->Unicode
= bUnicodeWindow
;
1546 WindowObject
->Unicode
= ClassObject
->Unicode
;
1548 WindowObject
->WndProcA
= ClassObject
->lpfnWndProcA
;
1549 WindowObject
->WndProcW
= ClassObject
->lpfnWndProcW
;
1550 WindowObject
->OwnerThread
= PsGetCurrentThread();
1551 WindowObject
->FirstChild
= NULL
;
1552 WindowObject
->LastChild
= NULL
;
1553 WindowObject
->PrevSibling
= NULL
;
1554 WindowObject
->NextSibling
= NULL
;
1556 /* extra window data */
1557 if (ClassObject
->cbWndExtra
!= 0)
1559 WindowObject
->ExtraData
= (PCHAR
)(WindowObject
+ 1);
1560 WindowObject
->ExtraDataSize
= ClassObject
->cbWndExtra
;
1561 RtlZeroMemory(WindowObject
->ExtraData
, WindowObject
->ExtraDataSize
);
1565 WindowObject
->ExtraData
= NULL
;
1566 WindowObject
->ExtraDataSize
= 0;
1569 InitializeListHead(&WindowObject
->PropListHead
);
1570 ExInitializeFastMutex(&WindowObject
->PropListLock
);
1571 ExInitializeFastMutex(&WindowObject
->RelativesLock
);
1572 ExInitializeFastMutex(&WindowObject
->UpdateLock
);
1574 if (NULL
!= WindowName
->Buffer
)
1576 WindowObject
->WindowName
.MaximumLength
= WindowName
->MaximumLength
;
1577 WindowObject
->WindowName
.Length
= WindowName
->Length
;
1578 WindowObject
->WindowName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, WindowName
->MaximumLength
,
1580 if (NULL
== WindowObject
->WindowName
.Buffer
)
1582 ClassDereferenceObject(ClassObject
);
1583 DPRINT1("Failed to allocate mem for window name\n");
1584 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1587 RtlCopyMemory(WindowObject
->WindowName
.Buffer
, WindowName
->Buffer
, WindowName
->MaximumLength
);
1591 RtlInitUnicodeString(&WindowObject
->WindowName
, NULL
);
1596 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1597 * tested for WS_POPUP
1599 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1600 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1601 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1602 dwExStyle
|= WS_EX_WINDOWEDGE
;
1604 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1606 /* Correct the window style. */
1607 if (!(dwStyle
& WS_CHILD
))
1609 WindowObject
->Style
|= WS_CLIPSIBLINGS
;
1610 DPRINT("3: Style is now %lx\n", WindowObject
->Style
);
1611 if (!(dwStyle
& WS_POPUP
))
1613 WindowObject
->Style
|= WS_CAPTION
;
1614 WindowObject
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1615 DPRINT("4: Style is now %lx\n", WindowObject
->Style
);
1619 /* create system menu */
1620 if((WindowObject
->Style
& WS_SYSMENU
) &&
1621 (WindowObject
->Style
& WS_CAPTION
) == WS_CAPTION
)
1623 SystemMenu
= IntGetSystemMenu(WindowObject
, TRUE
, TRUE
);
1626 WindowObject
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1627 IntReleaseMenuObject(SystemMenu
);
1631 /* Insert the window into the thread's window list. */
1632 IntLockThreadWindows(PsGetWin32Thread());
1633 InsertTailList (&PsGetWin32Thread()->WindowListHead
,
1634 &WindowObject
->ThreadListEntry
);
1635 IntUnLockThreadWindows(PsGetWin32Thread());
1637 /* Allocate a DCE for this window. */
1638 if (dwStyle
& CS_OWNDC
)
1640 WindowObject
->Dce
= DceAllocDCE(WindowObject
->Self
, DCE_WINDOW_DC
);
1642 /* FIXME: Handle "CS_CLASSDC" */
1650 Cs
.lpCreateParams
= lpParam
;
1651 Cs
.hInstance
= hInstance
;
1653 Cs
.hwndParent
= ParentWindowHandle
;
1659 Cs
.lpszName
= (LPCWSTR
) WindowName
;
1660 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
1661 Cs
.dwExStyle
= dwExStyle
;
1662 CbtCreate
.lpcs
= &Cs
;
1663 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1664 if (HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) Handle
, (LPARAM
) &CbtCreate
))
1666 if (NULL
!= ParentWindow
)
1668 IntReleaseWindowObject(ParentWindow
);
1671 /* FIXME - Delete window object and remove it from the thread windows list */
1672 /* FIXME - delete allocated DCE */
1674 ClassDereferenceObject(ClassObject
);
1675 DPRINT1("CBT-hook returned !0\n");
1684 /* default positioning for overlapped windows */
1685 if(!(WindowObject
->Style
& (WS_POPUP
| WS_CHILD
)))
1688 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1689 BOOL CalculatedDefPosSize
= FALSE
;
1691 IntGetDesktopWorkArea(WindowObject
->OwnerThread
->Tcb
.Win32Thread
->Desktop
, &WorkArea
);
1694 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1696 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1698 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, WindowObject
, &rc
, TRUE
);
1700 if(ProcessParams
->dwFlags
& STARTF_USEPOSITION
)
1702 ProcessParams
->dwFlags
&= ~STARTF_USEPOSITION
;
1703 Pos
.x
= WorkArea
.left
+ ProcessParams
->dwX
;
1704 Pos
.y
= WorkArea
.top
+ ProcessParams
->dwY
;
1712 /* According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
1713 y is something else */
1714 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
1719 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1721 if(!CalculatedDefPosSize
)
1723 IntCalcDefPosSize(ParentWindow
, WindowObject
, &rc
, FALSE
);
1725 if(ProcessParams
->dwFlags
& STARTF_USESIZE
)
1727 ProcessParams
->dwFlags
&= ~STARTF_USESIZE
;
1728 Size
.cx
= ProcessParams
->dwXSize
;
1729 Size
.cy
= ProcessParams
->dwYSize
;
1733 Size
.cx
= rc
.right
- rc
.left
;
1734 Size
.cy
= rc
.bottom
- rc
.top
;
1737 /* move the window if necessary */
1739 Pos
.x
= max(rc
.left
, 0);
1741 Pos
.y
= max(rc
.top
, 0);
1746 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
1747 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1752 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1759 /* Initialize the window dimensions. */
1760 WindowObject
->WindowRect
.left
= Pos
.x
;
1761 WindowObject
->WindowRect
.top
= Pos
.y
;
1762 WindowObject
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1763 WindowObject
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1764 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1766 IntGdiOffsetRect(&(WindowObject
->WindowRect
), ParentWindow
->ClientRect
.left
,
1767 ParentWindow
->ClientRect
.top
);
1769 WindowObject
->ClientRect
= WindowObject
->WindowRect
;
1772 * Get the size and position of the window.
1774 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
1776 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1778 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
1779 WinPosGetMinMaxInfo(WindowObject
, &MaxSize
, &MaxPos
, &MinTrack
,
1781 if (MaxSize
.x
< nWidth
) nWidth
= MaxSize
.x
;
1782 if (MaxSize
.y
< nHeight
) nHeight
= MaxSize
.y
;
1783 if (nWidth
< MinTrack
.x
) nWidth
= MinTrack
.x
;
1784 if (nHeight
< MinTrack
.y
) nHeight
= MinTrack
.y
;
1785 if (nWidth
< 0) nWidth
= 0;
1786 if (nHeight
< 0) nHeight
= 0;
1789 WindowObject
->WindowRect
.left
= Pos
.x
;
1790 WindowObject
->WindowRect
.top
= Pos
.y
;
1791 WindowObject
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1792 WindowObject
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1793 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1795 IntGdiOffsetRect(&(WindowObject
->WindowRect
), ParentWindow
->ClientRect
.left
,
1796 ParentWindow
->ClientRect
.top
);
1798 WindowObject
->ClientRect
= WindowObject
->WindowRect
;
1800 /* FIXME: Initialize the window menu. */
1802 /* Send a NCCREATE message. */
1808 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
1809 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1810 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
1811 Result
= IntSendMessage(WindowObject
->Self
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
1814 /* FIXME: Cleanup. */
1815 if (NULL
!= ParentWindow
)
1817 IntReleaseWindowObject(ParentWindow
);
1819 DPRINT("IntCreateWindowEx(): NCCREATE message failed.\n");
1823 /* Calculate the non-client size. */
1824 MaxPos
.x
= WindowObject
->WindowRect
.left
;
1825 MaxPos
.y
= WindowObject
->WindowRect
.top
;
1826 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
1827 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
1828 Result
= WinPosGetNonClientSize(WindowObject
->Self
,
1829 &WindowObject
->WindowRect
,
1830 &WindowObject
->ClientRect
);
1831 IntGdiOffsetRect(&WindowObject
->WindowRect
,
1832 MaxPos
.x
- WindowObject
->WindowRect
.left
,
1833 MaxPos
.y
- WindowObject
->WindowRect
.top
);
1835 if (NULL
!= ParentWindow
)
1837 /* link the window into the parent's child list */
1838 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
1840 PWINDOW_OBJECT PrevSibling
;
1841 IntLockRelatives(ParentWindow
);
1842 if((PrevSibling
= ParentWindow
->LastChild
))
1843 IntReferenceWindowObject(PrevSibling
);
1844 IntUnLockRelatives(ParentWindow
);
1845 /* link window as bottom sibling */
1846 IntLinkWindow(WindowObject
, ParentWindow
, PrevSibling
/*prev sibling*/);
1848 IntReleaseWindowObject(PrevSibling
);
1852 /* link window as top sibling (but after topmost siblings) */
1853 PWINDOW_OBJECT InsertAfter
, Sibling
;
1854 if (0 == (dwExStyle
& WS_EX_TOPMOST
))
1856 IntLockRelatives(ParentWindow
);
1858 Sibling
= ParentWindow
->FirstChild
;
1859 while (NULL
!= Sibling
&& 0 != (Sibling
->ExStyle
& WS_EX_TOPMOST
))
1861 InsertAfter
= Sibling
;
1862 Sibling
= Sibling
->NextSibling
;
1864 IntUnLockRelatives(ParentWindow
);
1870 if (NULL
!= InsertAfter
)
1872 IntReferenceWindowObject(InsertAfter
);
1874 IntLinkWindow(WindowObject
, ParentWindow
, InsertAfter
/* prev sibling */);
1875 if (NULL
!= InsertAfter
)
1877 IntReleaseWindowObject(InsertAfter
);
1882 /* Send the WM_CREATE message. */
1883 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
1884 Result
= IntSendMessage(WindowObject
->Self
, WM_CREATE
, 0, (LPARAM
) &Cs
);
1885 if (Result
== (LRESULT
)-1)
1887 /* FIXME: Cleanup. */
1888 if (NULL
!= ParentWindow
)
1890 IntReleaseWindowObject(ParentWindow
);
1892 ClassDereferenceObject(ClassObject
);
1893 DPRINT("IntCreateWindowEx(): send CREATE message failed.\n");
1897 /* Send move and size messages. */
1898 if (!(WindowObject
->Flags
& WINDOWOBJECT_NEED_SIZE
))
1902 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
1904 if ((WindowObject
->ClientRect
.right
- WindowObject
->ClientRect
.left
) < 0 ||
1905 (WindowObject
->ClientRect
.bottom
- WindowObject
->ClientRect
.top
) < 0)
1907 DPRINT("Sending bogus WM_SIZE\n");
1910 lParam
= MAKE_LONG(WindowObject
->ClientRect
.right
-
1911 WindowObject
->ClientRect
.left
,
1912 WindowObject
->ClientRect
.bottom
-
1913 WindowObject
->ClientRect
.top
);
1914 IntSendMessage(WindowObject
->Self
, WM_SIZE
, SIZE_RESTORED
,
1917 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
1919 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1921 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
- ParentWindow
->ClientRect
.left
,
1922 WindowObject
->ClientRect
.top
- ParentWindow
->ClientRect
.top
);
1926 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
,
1927 WindowObject
->ClientRect
.top
);
1929 IntSendMessage(WindowObject
->Self
, WM_MOVE
, 0, lParam
);
1932 /* Show or maybe minimize or maximize the window. */
1933 if (WindowObject
->Style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1938 SwFlag
= (WindowObject
->Style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
1940 WinPosMinMaximize(WindowObject
, SwFlag
, &NewPos
);
1942 ((WindowObject
->Style
& WS_CHILD
) || NtUserGetActiveWindow()) ?
1943 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
1944 SWP_NOZORDER
| SWP_FRAMECHANGED
;
1945 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
1946 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
1947 WinPosSetWindowPos(WindowObject
->Self
, 0, NewPos
.left
, NewPos
.top
,
1948 NewPos
.right
, NewPos
.bottom
, SwFlag
);
1951 /* Notify the parent window of a new child. */
1952 if ((WindowObject
->Style
& WS_CHILD
) &&
1953 (!(WindowObject
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
1955 DPRINT("IntCreateWindow(): About to notify parent\n");
1956 IntSendMessage(ParentWindow
->Self
,
1958 MAKEWPARAM(WM_CREATE
, WindowObject
->IDMenu
),
1959 (LPARAM
)WindowObject
->Self
);
1962 if (NULL
!= ParentWindow
)
1964 IntReleaseWindowObject(ParentWindow
);
1967 /* Initialize and show the window's scrollbars */
1968 if (WindowObject
->Style
& WS_VSCROLL
)
1970 NtUserShowScrollBar(WindowObject
->Self
, SB_VERT
, TRUE
);
1972 if (WindowObject
->Style
& WS_HSCROLL
)
1974 NtUserShowScrollBar(WindowObject
->Self
, SB_HORZ
, TRUE
);
1977 if (dwStyle
& WS_VISIBLE
)
1979 DPRINT("IntCreateWindow(): About to show window\n");
1980 WinPosShowWindow(WindowObject
->Self
, dwShowMode
);
1983 DPRINT("IntCreateWindow(): = %X\n", Handle
);
1984 DPRINT("WindowObject->SystemMenu = 0x%x\n", WindowObject
->SystemMenu
);
1985 return((HWND
)Handle
);
1989 NtUserCreateWindowEx(DWORD dwExStyle
,
1990 PUNICODE_STRING UnsafeClassName
,
1991 PUNICODE_STRING UnsafeWindowName
,
1999 HINSTANCE hInstance
,
2002 BOOL bUnicodeWindow
)
2005 UNICODE_STRING WindowName
;
2006 UNICODE_STRING ClassName
;
2009 DPRINT("NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2011 /* Get the class name (string or atom) */
2012 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
2013 if (! NT_SUCCESS(Status
))
2015 SetLastNtError(Status
);
2018 if (! IS_ATOM(ClassName
.Buffer
))
2020 Status
= IntSafeCopyUnicodeStringTerminateNULL(&ClassName
, UnsafeClassName
);
2021 if (! NT_SUCCESS(Status
))
2023 SetLastNtError(Status
);
2028 /* safely copy the window name */
2029 if (NULL
!= UnsafeWindowName
)
2031 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
2032 if (! NT_SUCCESS(Status
))
2034 if (! IS_ATOM(ClassName
.Buffer
))
2036 RtlFreeUnicodeString(&ClassName
);
2038 SetLastNtError(Status
);
2044 RtlInitUnicodeString(&WindowName
, NULL
);
2047 NewWindow
= IntCreateWindowEx(dwExStyle
, &ClassName
, &WindowName
, dwStyle
, x
, y
, nWidth
, nHeight
,
2048 hWndParent
, hMenu
, hInstance
, lpParam
, dwShowMode
, bUnicodeWindow
);
2050 RtlFreeUnicodeString(&WindowName
);
2051 if (! IS_ATOM(ClassName
.Buffer
))
2053 RtlFreeUnicodeString(&ClassName
);
2063 NtUserDeferWindowPos(HDWP WinPosInfo
,
2065 HWND WndInsertAfter
,
2082 NtUserDestroyWindow(HWND Wnd
)
2084 PWINDOW_OBJECT Window
;
2087 Window
= IntGetWindowObject(Wnd
);
2093 /* Check for owner thread and desktop window */
2094 if ((Window
->OwnerThread
!= PsGetCurrentThread()) || IntIsDesktopWindow(Window
))
2096 IntReleaseWindowObject(Window
);
2097 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2101 /* Look whether the focus is within the tree of windows we will
2104 if (!WinPosShowWindow(Wnd
, SW_HIDE
))
2106 if (NtUserGetActiveWindow() == Wnd
)
2108 WinPosActivateOtherWindow(Window
);
2111 IntLockMessageQueue(Window
->MessageQueue
);
2112 if (Window
->MessageQueue
->ActiveWindow
== Window
->Self
)
2113 Window
->MessageQueue
->ActiveWindow
= NULL
;
2114 if (Window
->MessageQueue
->FocusWindow
== Window
->Self
)
2115 Window
->MessageQueue
->FocusWindow
= NULL
;
2116 if (Window
->MessageQueue
->CaptureWindow
== Window
->Self
)
2117 Window
->MessageQueue
->CaptureWindow
= NULL
;
2118 IntUnLockMessageQueue(Window
->MessageQueue
);
2122 if (HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hwnd
, 0, TRUE
))
2128 isChild
= (0 != (Window
->Style
& WS_CHILD
));
2133 if (! USER_IsExitingThread(GetCurrentThreadId()))
2135 send_parent_notify(hwnd
, WM_DESTROY
);
2138 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2140 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2141 /* FIXME: clean up palette - see "Internals" p.352 */
2145 if (!IntIsWindow(Wnd
))
2150 /* Recursively destroy owned windows */
2155 BOOL GotOne
= FALSE
;
2158 PWINDOW_OBJECT Child
, Desktop
;
2160 Desktop
= IntGetWindowObject(IntGetDesktopWindow());
2161 Children
= IntWinListChildren(Desktop
);
2162 IntReleaseWindowObject(Desktop
);
2165 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2167 Child
= IntGetWindowObject(*ChildHandle
);
2170 IntLockRelatives(Child
);
2171 if (Child
->Owner
!= Window
->Self
)
2173 IntUnLockRelatives(Child
);
2174 IntReleaseWindowObject(Child
);
2177 IntUnLockRelatives(Child
);
2178 if (IntWndBelongsToThread(Child
, PsGetWin32Thread()))
2180 IntReleaseWindowObject(Child
);
2181 NtUserDestroyWindow(*ChildHandle
);
2185 IntLockRelatives(Child
);
2186 if (Child
->Owner
!= NULL
)
2188 Child
->Owner
= NULL
;
2190 IntUnLockRelatives(Child
);
2191 IntReleaseWindowObject(Child
);
2193 ExFreePool(Children
);
2202 if (!IntIsWindow(Wnd
))
2204 IntReleaseWindowObject(Window
);
2208 /* Destroy the window storage */
2209 IntDestroyWindow(Window
, PsGetWin32Process(), PsGetWin32Thread(), TRUE
);
2211 IntReleaseWindowObject(Window
);
2221 NtUserDrawMenuBarTemp(
2228 /* we'll use this function just for caching the menu bar */
2238 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2251 NtUserFillWindow(DWORD Unknown0
,
2263 IntFindWindow(PWINDOW_OBJECT Parent
,
2264 PWINDOW_OBJECT ChildAfter
,
2265 PWNDCLASS_OBJECT ClassObject
,
2266 PUNICODE_STRING WindowName
)
2268 BOOL CheckWindowName
;
2274 CheckWindowName
= (WindowName
&& (WindowName
->Length
> 0));
2276 if((List
= IntWinListChildren(Parent
)))
2281 /* skip handles before and including ChildAfter */
2282 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->Self
));
2285 /* search children */
2288 PWINDOW_OBJECT Child
;
2289 if(!(Child
= IntGetWindowObject(*(phWnd
++))))
2294 /* Do not send WM_GETTEXT messages in the kernel mode version!
2295 The user mode version however calls GetWindowText() which will
2296 send WM_GETTEXT messages to windows belonging to its processes */
2297 if(((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(WindowName
, &(Child
->WindowName
), FALSE
))) &&
2298 (!ClassObject
|| (ClassObject
&& (Child
->Class
== ClassObject
))))
2300 ((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(WindowName
, &(Child
->WindowName
), FALSE
))) &&
2301 (!ClassObject
|| (ClassObject
&& (Child
->Class
== ClassObject
)))))
2304 IntReleaseWindowObject(Child
);
2308 IntReleaseWindowObject(Child
);
2318 * Searches a window's children for a window with the specified
2321 * hwndParent = The window whose childs are to be searched.
2323 * HWND_MESSAGE = message-only windows
2325 * hwndChildAfter = Search starts after this child window.
2326 * NULL = start from beginning
2328 * ucClassName = Class name to search for
2329 * Reguired parameter.
2331 * ucWindowName = Window name
2332 * ->Buffer == NULL = don't care
2335 * The HWND of the window if it was found, otherwise NULL
2341 NtUserFindWindowEx(HWND hwndParent
,
2342 HWND hwndChildAfter
,
2343 PUNICODE_STRING ucClassName
,
2344 PUNICODE_STRING ucWindowName
)
2346 PWINDOW_OBJECT Parent
, ChildAfter
;
2347 UNICODE_STRING ClassName
, WindowName
;
2349 HWND Desktop
, Ret
= NULL
;
2350 PWNDCLASS_OBJECT ClassObject
= NULL
;
2353 Desktop
= IntGetCurrentThreadDesktopWindow();
2355 if(hwndParent
== NULL
)
2356 hwndParent
= Desktop
;
2358 else if(hwndParent == HWND_MESSAGE)
2360 hwndParent = IntGetMessageWindow();
2364 if(!(Parent
= IntGetWindowObject(hwndParent
)))
2366 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2371 if(hwndChildAfter
&& !(ChildAfter
= IntGetWindowObject(hwndChildAfter
)))
2373 IntReleaseWindowObject(Parent
);
2374 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2378 /* copy the window name */
2379 Status
= IntSafeCopyUnicodeString(&WindowName
, ucWindowName
);
2380 if(!NT_SUCCESS(Status
))
2382 SetLastNtError(Status
);
2386 /* safely copy the class name */
2387 Status
= MmCopyFromCaller(&ClassName
, ucClassName
, sizeof(UNICODE_STRING
));
2388 if(!NT_SUCCESS(Status
))
2390 SetLastNtError(Status
);
2393 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2396 /* safely copy the class name string (NULL terminated because class-lookup
2398 buf
= ExAllocatePoolWithTag(PagedPool
, ClassName
.Length
+ sizeof(WCHAR
), TAG_STRING
);
2401 SetLastWin32Error(STATUS_INSUFFICIENT_RESOURCES
);
2404 Status
= MmCopyFromCaller(buf
, ClassName
.Buffer
, ClassName
.Length
);
2405 if(!NT_SUCCESS(Status
))
2408 SetLastNtError(Status
);
2411 ClassName
.Buffer
= buf
;
2412 /* make sure the string is null-terminated */
2413 buf
+= ClassName
.Length
/ sizeof(WCHAR
);
2417 /* find the class object */
2418 if(ClassName
.Buffer
)
2420 /* this expects the string in ClassName to be NULL-terminated! */
2421 ClassFound
= ClassReferenceClassByNameOrAtom(&ClassObject
, ClassName
.Buffer
, NULL
);
2424 if (IS_ATOM(ClassName
.Buffer
))
2425 DPRINT1("Window class not found (%lx)\n", (ULONG_PTR
)ClassName
.Buffer
);
2427 DPRINT1("Window class not found (%S)\n", ClassName
.Buffer
);
2428 SetLastWin32Error(ERROR_FILE_NOT_FOUND
);
2433 if(Parent
->Self
== Desktop
)
2436 PWINDOW_OBJECT TopLevelWindow
;
2437 BOOL CheckWindowName
;
2439 /* windows searches through all top-level windows if the parent is the desktop
2442 if((List
= IntWinListChildren(Parent
)))
2448 /* skip handles before and including ChildAfter */
2449 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->Self
));
2452 CheckWindowName
= WindowName
.Length
> 0;
2454 /* search children */
2457 if(!(TopLevelWindow
= IntGetWindowObject(*(phWnd
++))))
2462 /* Do not send WM_GETTEXT messages in the kernel mode version!
2463 The user mode version however calls GetWindowText() which will
2464 send WM_GETTEXT messages to windows belonging to its processes */
2465 if(((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(&WindowName
, &(TopLevelWindow
->WindowName
), FALSE
))) &&
2466 (!ClassObject
|| (ClassObject
&& (TopLevelWindow
->Class
== ClassObject
))))
2468 ((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(&WindowName
, &(TopLevelWindow
->WindowName
), FALSE
))) &&
2469 (!ClassObject
|| (ClassObject
&& (TopLevelWindow
->Class
== ClassObject
)))))
2471 Ret
= TopLevelWindow
->Self
;
2472 IntReleaseWindowObject(TopLevelWindow
);
2476 if(IntFindWindow(TopLevelWindow
, NULL
, ClassObject
, &WindowName
))
2478 /* window returns the handle of the top-level window, in case it found
2480 Ret
= TopLevelWindow
->Self
;
2481 IntReleaseWindowObject(TopLevelWindow
);
2485 IntReleaseWindowObject(TopLevelWindow
);
2491 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassObject
, &WindowName
);
2494 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2496 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2497 search the message-only windows. Should this also be done if
2498 Parent is the desktop window??? */
2499 PWINDOW_OBJECT MsgWindows
;
2501 if((MsgWindows
= IntGetWindowObject(IntGetMessageWindow())))
2503 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassObject
, &WindowName
);
2504 IntReleaseWindowObject(MsgWindows
);
2509 if (ClassObject
!= NULL
)
2511 ClassDereferenceObject(ClassObject
);
2515 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2516 ExFreePool(ClassName
.Buffer
);
2519 RtlFreeUnicodeString(&WindowName
);
2523 IntReleaseWindowObject(ChildAfter
);
2524 IntReleaseWindowObject(Parent
);
2534 NtUserFlashWindowEx(DWORD Unknown0
)
2546 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2548 PWINDOW_OBJECT Wnd
, WndAncestor
, Parent
;
2551 if (hWnd
== IntGetDesktopWindow())
2556 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2558 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2566 WndAncestor
= IntGetParentObject(Wnd
);
2579 if(!(Parent
= IntGetParentObject(WndAncestor
)))
2583 if(IntIsDesktopWindow(Parent
))
2585 IntReleaseWindowObject(Parent
);
2589 IntReleaseWindowObject(tmp
);
2590 WndAncestor
= Parent
;
2598 IntReferenceWindowObject(WndAncestor
);
2603 Parent
= IntGetParent(WndAncestor
);
2604 IntReleaseWindowObject(Old
);
2609 WndAncestor
= Parent
;
2616 IntReleaseWindowObject(Wnd
);
2621 hWndAncestor
= (WndAncestor
? WndAncestor
->Self
: NULL
);
2622 IntReleaseWindowObject(Wnd
);
2624 if(WndAncestor
&& (WndAncestor
!= Wnd
))
2625 IntReleaseWindowObject(WndAncestor
);
2627 return hWndAncestor
;
2632 * Returns client window rectangle relative to the upper-left corner of client area.
2634 * \param hWnd window handle.
2635 * \param Rect pointer to the buffer where the coordinates are returned.
2642 NtUserGetClientRect(HWND hWnd
, LPRECT Rect
)
2644 PWINDOW_OBJECT WindowObject
;
2647 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
2649 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2653 IntGetClientRect(WindowObject
, &SafeRect
);
2654 IntReleaseWindowObject(WindowObject
);
2656 if(!NT_SUCCESS(MmCopyToCaller(Rect
, &SafeRect
, sizeof(RECT
))))
2668 NtUserGetDesktopWindow()
2670 return IntGetDesktopWindow();
2678 NtUserGetInternalWindowPos(DWORD Unknown0
,
2692 NtUserGetLastActivePopup(HWND hWnd
)
2695 * This code can't work, because hWndLastPopup member of WINDOW_OBJECT is
2696 * not changed anywhere.
2697 * -- Filip, 01/nov/2003
2703 IntAcquireWinLockShared();
2705 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2707 IntReleaseWinLock();
2708 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2712 hWndLastPopup
= Wnd
->hWndLastPopup
;
2714 IntReleaseWinLock();
2716 return hWndLastPopup
;
2725 * The NtUserGetParent function retrieves a handle to the specified window's
2729 * Note that, despite its name, this function can return an owner window
2730 * instead of a parent window.
2737 NtUserGetParent(HWND hWnd
)
2739 PWINDOW_OBJECT Wnd
, WndParent
;
2740 HWND hWndParent
= NULL
;
2742 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2744 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2748 WndParent
= IntGetParent(Wnd
);
2751 hWndParent
= WndParent
->Self
;
2752 IntReleaseWindowObject(WndParent
);
2755 IntReleaseWindowObject(Wnd
);
2763 * The NtUserSetParent function changes the parent window of the specified
2767 * The new parent window and the child window must belong to the same
2768 * application. If the window identified by the hWndChild parameter is
2769 * visible, the system performs the appropriate redrawing and repainting.
2770 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
2771 * or WS_POPUP window styles of the window whose parent is being changed.
2778 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2780 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
2781 HWND hWndOldParent
= NULL
;
2783 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
2785 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2789 if (hWndChild
== IntGetDesktopWindow())
2791 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2797 if (!(WndParent
= IntGetWindowObject(hWndNewParent
)))
2799 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2805 if (!(WndParent
= IntGetWindowObject(IntGetDesktopWindow())))
2807 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2812 if (!(Wnd
= IntGetWindowObject(hWndChild
)))
2814 IntReleaseWindowObject(WndParent
);
2815 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2819 WndOldParent
= IntSetParent(Wnd
, WndParent
);
2823 hWndOldParent
= WndOldParent
->Self
;
2824 IntReleaseWindowObject(WndOldParent
);
2827 IntReleaseWindowObject(Wnd
);
2828 IntReleaseWindowObject(WndParent
);
2830 return hWndOldParent
;
2834 * NtUserGetShellWindow
2836 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
2843 NtUserGetShellWindow()
2845 PWINSTATION_OBJECT WinStaObject
;
2848 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
2853 if (!NT_SUCCESS(Status
))
2855 SetLastNtError(Status
);
2859 Ret
= (HWND
)WinStaObject
->ShellWindow
;
2861 ObDereferenceObject(WinStaObject
);
2866 * NtUserSetShellWindowEx
2868 * This is undocumented function to set global shell window. The global
2869 * shell window has special handling of window position.
2876 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
2878 PWINSTATION_OBJECT WinStaObject
;
2880 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
2885 if (!NT_SUCCESS(Status
))
2887 SetLastNtError(Status
);
2892 * Test if we are permitted to change the shell window.
2894 if (WinStaObject
->ShellWindow
)
2896 ObDereferenceObject(WinStaObject
);
2901 * Move shell window into background.
2903 if (hwndListView
&& hwndListView
!= hwndShell
)
2906 * Disabled for now to get Explorer working.
2907 * -- Filip, 01/nov/2003
2910 WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2913 if (NtUserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2915 ObDereferenceObject(WinStaObject
);
2920 if (NtUserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2922 ObDereferenceObject(WinStaObject
);
2926 WinPosSetWindowPos(hwndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2928 WinStaObject
->ShellWindow
= hwndShell
;
2929 WinStaObject
->ShellListView
= hwndListView
;
2931 ObDereferenceObject(WinStaObject
);
2936 * NtUserGetSystemMenu
2938 * The NtUserGetSystemMenu function allows the application to access the
2939 * window menu (also known as the system menu or the control menu) for
2940 * copying and modifying.
2944 * Handle to the window that will own a copy of the window menu.
2946 * Specifies the action to be taken. If this parameter is FALSE,
2947 * NtUserGetSystemMenu returns a handle to the copy of the window menu
2948 * currently in use. The copy is initially identical to the window menu
2949 * but it can be modified.
2950 * If this parameter is TRUE, GetSystemMenu resets the window menu back
2951 * to the default state. The previous window menu, if any, is destroyed.
2954 * If the bRevert parameter is FALSE, the return value is a handle to a
2955 * copy of the window menu. If the bRevert parameter is TRUE, the return
2963 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
2966 PWINDOW_OBJECT WindowObject
;
2967 PMENU_OBJECT MenuObject
;
2969 WindowObject
= IntGetWindowObject((HWND
)hWnd
);
2970 if (WindowObject
== NULL
)
2972 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2976 MenuObject
= IntGetSystemMenu(WindowObject
, bRevert
, FALSE
);
2979 Result
= MenuObject
->MenuInfo
.Self
;
2980 IntReleaseMenuObject(MenuObject
);
2983 IntReleaseWindowObject(WindowObject
);
2988 * NtUserSetSystemMenu
2995 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
2997 BOOL Result
= FALSE
;
2998 PWINDOW_OBJECT WindowObject
;
2999 PMENU_OBJECT MenuObject
;
3001 WindowObject
= IntGetWindowObject(hWnd
);
3004 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3011 * Assign new menu handle.
3013 MenuObject
= IntGetMenuObject(hMenu
);
3016 IntReleaseWindowObject(WindowObject
);
3017 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
3021 Result
= IntSetSystemMenu(WindowObject
, MenuObject
);
3023 IntReleaseMenuObject(MenuObject
);
3026 IntReleaseWindowObject(WindowObject
);
3034 * The NtUserGetWindow function retrieves a handle to a window that has the
3035 * specified relationship (Z order or owner) to the specified window.
3042 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3044 PWINDOW_OBJECT WindowObject
, Parent
;
3045 HWND hWndResult
= NULL
;
3047 if (!(WindowObject
= IntGetWindowObject(hWnd
)))
3049 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3053 switch (Relationship
)
3056 if((Parent
= IntGetParentObject(WindowObject
)))
3058 IntLockRelatives(Parent
);
3059 if (Parent
->FirstChild
)
3060 hWndResult
= Parent
->FirstChild
->Self
;
3061 IntUnLockRelatives(Parent
);
3062 IntReleaseWindowObject(Parent
);
3067 if((Parent
= IntGetParentObject(WindowObject
)))
3069 IntLockRelatives(Parent
);
3070 if (Parent
->LastChild
)
3071 hWndResult
= Parent
->LastChild
->Self
;
3072 IntUnLockRelatives(Parent
);
3073 IntReleaseWindowObject(Parent
);
3078 IntLockRelatives(WindowObject
);
3079 if (WindowObject
->NextSibling
)
3080 hWndResult
= WindowObject
->NextSibling
->Self
;
3081 IntUnLockRelatives(WindowObject
);
3085 IntLockRelatives(WindowObject
);
3086 if (WindowObject
->PrevSibling
)
3087 hWndResult
= WindowObject
->PrevSibling
->Self
;
3088 IntUnLockRelatives(WindowObject
);
3092 IntLockRelatives(WindowObject
);
3093 if((Parent
= IntGetWindowObject(WindowObject
->Owner
)))
3095 hWndResult
= Parent
->Self
;
3096 IntReleaseWindowObject(Parent
);
3098 IntUnLockRelatives(WindowObject
);
3101 IntLockRelatives(WindowObject
);
3102 if (WindowObject
->FirstChild
)
3103 hWndResult
= WindowObject
->FirstChild
->Self
;
3104 IntUnLockRelatives(WindowObject
);
3108 IntReleaseWindowObject(WindowObject
);
3114 * NtUserGetWindowLong
3116 * The NtUserGetWindowLong function retrieves information about the specified
3117 * window. The function also retrieves the 32-bit (long) value at the
3118 * specified offset into the extra window memory.
3125 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3127 PWINDOW_OBJECT WindowObject
, Parent
;
3130 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3132 WindowObject
= IntGetWindowObject(hWnd
);
3133 if (WindowObject
== NULL
)
3135 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3140 * Only allow CSRSS to mess with the desktop window
3142 if (hWnd
== IntGetDesktopWindow()
3143 && WindowObject
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3145 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3149 if ((INT
)Index
>= 0)
3151 if ((Index
+ sizeof(LONG
)) > WindowObject
->ExtraDataSize
)
3153 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3156 Result
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
3163 Result
= WindowObject
->ExStyle
;
3167 Result
= WindowObject
->Style
;
3172 Result
= (LONG
) WindowObject
->WndProcA
;
3174 Result
= (LONG
) WindowObject
->WndProcW
;
3178 Result
= (LONG
) WindowObject
->Instance
;
3181 case GWL_HWNDPARENT
:
3182 IntLockRelatives(WindowObject
);
3183 Parent
= IntGetWindowObject(WindowObject
->Parent
);
3184 IntUnLockRelatives(WindowObject
);
3187 if (Parent
&& Parent
->Self
== IntGetDesktopWindow())
3188 Result
= (LONG
) NtUserGetWindow(WindowObject
->Self
, GW_OWNER
);
3190 Result
= (LONG
) Parent
->Self
;
3191 IntReleaseWindowObject(Parent
);
3196 Result
= (LONG
) WindowObject
->IDMenu
;
3200 Result
= WindowObject
->UserData
;
3204 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3205 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3211 IntReleaseWindowObject(WindowObject
);
3217 * NtUserSetWindowLong
3219 * The NtUserSetWindowLong function changes an attribute of the specified
3220 * window. The function also sets the 32-bit (long) value at the specified
3221 * offset into the extra window memory.
3228 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3230 PWINDOW_OBJECT WindowObject
, Parent
;
3231 PWINSTATION_OBJECT WindowStation
;
3235 if (hWnd
== IntGetDesktopWindow())
3237 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3241 WindowObject
= IntGetWindowObject(hWnd
);
3242 if (WindowObject
== NULL
)
3244 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3248 if ((INT
)Index
>= 0)
3250 if ((Index
+ sizeof(LONG
)) > WindowObject
->ExtraDataSize
)
3252 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3253 IntReleaseWindowObject(WindowObject
);
3256 OldValue
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
3257 *((LONG
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
3264 OldValue
= (LONG
) WindowObject
->ExStyle
;
3265 Style
.styleOld
= OldValue
;
3266 Style
.styleNew
= NewValue
;
3269 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3271 WindowStation
= WindowObject
->OwnerThread
->Tcb
.Win32Thread
->Desktop
->WindowStation
;
3274 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3275 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3278 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3279 WindowObject
->ExStyle
= (DWORD
)Style
.styleNew
;
3280 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3284 OldValue
= (LONG
) WindowObject
->Style
;
3285 Style
.styleOld
= OldValue
;
3286 Style
.styleNew
= NewValue
;
3287 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3288 WindowObject
->Style
= (DWORD
)Style
.styleNew
;
3289 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3293 /* FIXME: should check if window belongs to current process */
3296 OldValue
= (LONG
) WindowObject
->WndProcA
;
3297 WindowObject
->WndProcA
= (WNDPROC
) NewValue
;
3298 WindowObject
->WndProcW
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,FALSE
);
3299 WindowObject
->Unicode
= FALSE
;
3303 OldValue
= (LONG
) WindowObject
->WndProcW
;
3304 WindowObject
->WndProcW
= (WNDPROC
) NewValue
;
3305 WindowObject
->WndProcA
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,TRUE
);
3306 WindowObject
->Unicode
= TRUE
;
3311 OldValue
= (LONG
) WindowObject
->Instance
;
3312 WindowObject
->Instance
= (HINSTANCE
) NewValue
;
3315 case GWL_HWNDPARENT
:
3316 Parent
= IntGetParentObject(WindowObject
);
3317 if (Parent
&& (Parent
->Self
== IntGetDesktopWindow()))
3318 OldValue
= (LONG
) IntSetOwner(WindowObject
->Self
, (HWND
) NewValue
);
3320 OldValue
= (LONG
) NtUserSetParent(WindowObject
->Self
, (HWND
) NewValue
);
3322 IntReleaseWindowObject(Parent
);
3326 OldValue
= (LONG
) WindowObject
->IDMenu
;
3327 WindowObject
->IDMenu
= (UINT
) NewValue
;
3331 OldValue
= WindowObject
->UserData
;
3332 WindowObject
->UserData
= NewValue
;
3336 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3337 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3343 IntReleaseWindowObject(WindowObject
);
3349 * NtUserSetWindowWord
3351 * Legacy function similar to NtUserSetWindowLong.
3358 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3360 PWINDOW_OBJECT WindowObject
;
3367 case GWL_HWNDPARENT
:
3368 return NtUserSetWindowLong(hWnd
, Index
, (UINT
)NewValue
, TRUE
);
3372 SetLastWin32Error(ERROR_INVALID_INDEX
);
3377 WindowObject
= IntGetWindowObject(hWnd
);
3378 if (WindowObject
== NULL
)
3380 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3384 if (Index
> WindowObject
->ExtraDataSize
- sizeof(WORD
))
3386 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3387 IntReleaseWindowObject(WindowObject
);
3391 OldValue
= *((WORD
*)(WindowObject
->ExtraData
+ Index
));
3392 *((WORD
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
3394 IntReleaseWindowObject(WindowObject
);
3403 NtUserGetWindowPlacement(HWND hWnd
,
3404 WINDOWPLACEMENT
*lpwndpl
)
3406 PWINDOW_OBJECT WindowObject
;
3407 PINTERNALPOS InternalPos
;
3409 WINDOWPLACEMENT Safepl
;
3412 WindowObject
= IntGetWindowObject(hWnd
);
3413 if (WindowObject
== NULL
)
3415 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3419 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3420 if(!NT_SUCCESS(Status
))
3422 SetLastNtError(Status
);
3423 IntReleaseWindowObject(WindowObject
);
3426 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3428 IntReleaseWindowObject(WindowObject
);
3433 Safepl
.showCmd
= ((WindowObject
->Flags
& WINDOWOBJECT_RESTOREMAX
) ? SW_MAXIMIZE
: SW_SHOWNORMAL
);
3435 Size
.x
= WindowObject
->WindowRect
.left
;
3436 Size
.y
= WindowObject
->WindowRect
.top
;
3437 InternalPos
= WinPosInitInternalPos(WindowObject
, &Size
,
3438 &WindowObject
->WindowRect
);
3441 Safepl
.rcNormalPosition
= InternalPos
->NormalRect
;
3442 Safepl
.ptMinPosition
= InternalPos
->IconPos
;
3443 Safepl
.ptMaxPosition
= InternalPos
->MaxPos
;
3447 IntReleaseWindowObject(WindowObject
);
3451 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3452 if(!NT_SUCCESS(Status
))
3454 SetLastNtError(Status
);
3455 IntReleaseWindowObject(WindowObject
);
3459 IntReleaseWindowObject(WindowObject
);
3465 * Return the dimension of the window in the screen coordinates.
3466 * \param hWnd window handle.
3467 * \param Rect pointer to the buffer where the coordinates are returned.
3473 NtUserGetWindowRect(HWND hWnd
, LPRECT Rect
)
3478 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3480 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3483 Status
= MmCopyToCaller(Rect
, &Wnd
->WindowRect
, sizeof(RECT
));
3484 if (!NT_SUCCESS(Status
))
3486 IntReleaseWindowObject(Wnd
);
3487 SetLastNtError(Status
);
3491 IntReleaseWindowObject(Wnd
);
3500 NtUserGetWindowThreadProcessId(HWND hWnd
, LPDWORD UnsafePid
)
3505 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3507 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3511 tid
= (DWORD
)IntGetWndThreadId(Wnd
);
3512 pid
= (DWORD
)IntGetWndProcessId(Wnd
);
3514 if (UnsafePid
) MmCopyToCaller(UnsafePid
, &pid
, sizeof(DWORD
));
3524 NtUserLockWindowUpdate(DWORD Unknown0
)
3544 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3545 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3546 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3550 QueryWindow based on KJK::Hyperion and James Tabor.
3552 0 = QWUniqueProcessId
3553 1 = QWUniqueThreadId
3554 4 = QWIsHung Implements IsHungAppWindow found
3557 9 = QWKillWindow When I called this with hWnd ==
3558 DesktopWindow, it shutdown the system
3565 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3567 PWINDOW_OBJECT Window
= IntGetWindowObject(hWnd
);
3572 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3578 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3579 Result
= (DWORD
)IntGetWndProcessId(Window
);
3582 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3583 Result
= (DWORD
)IntGetWndThreadId(Window
);
3586 case QUERY_WINDOW_ISHUNG
:
3587 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
3591 Result
= (DWORD
)NULL
;
3595 IntReleaseWindowObject(Window
);
3605 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3619 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3621 UNICODE_STRING SafeMessageName
;
3625 if(MessageNameUnsafe
== NULL
)
3627 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3631 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3632 if(!NT_SUCCESS(Status
))
3634 SetLastNtError(Status
);
3638 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3640 RtlFreeUnicodeString(&SafeMessageName
);
3649 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3662 NtUserSetInternalWindowPos(DWORD Unknown0
,
3678 NtUserSetLayeredWindowAttributes(DWORD Unknown0
,
3693 NtUserSetLogonNotifyWindow(DWORD Unknown0
)
3710 PWINDOW_OBJECT WindowObject
;
3713 WindowObject
= IntGetWindowObject((HWND
) Wnd
);
3714 if (NULL
== WindowObject
)
3716 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3720 if (! IntSetMenu(WindowObject
, Menu
, &Changed
))
3722 IntReleaseWindowObject(WindowObject
);
3726 IntReleaseWindowObject(WindowObject
);
3728 if (Changed
&& Repaint
)
3730 WinPosSetWindowPos(Wnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3731 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3742 NtUserSetWindowFNID(DWORD Unknown0
,
3756 NtUserSetWindowPlacement(HWND hWnd
,
3757 WINDOWPLACEMENT
*lpwndpl
)
3759 PWINDOW_OBJECT WindowObject
;
3760 WINDOWPLACEMENT Safepl
;
3763 WindowObject
= IntGetWindowObject(hWnd
);
3764 if (WindowObject
== NULL
)
3766 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3769 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3770 if(!NT_SUCCESS(Status
))
3772 SetLastNtError(Status
);
3773 IntReleaseWindowObject(WindowObject
);
3776 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3778 IntReleaseWindowObject(WindowObject
);
3782 if ((WindowObject
->Style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
3784 WinPosSetWindowPos(WindowObject
->Self
, NULL
,
3785 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
3786 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
3787 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
3788 SWP_NOZORDER
| SWP_NOACTIVATE
);
3791 /* FIXME - change window status */
3792 WinPosShowWindow(WindowObject
->Self
, Safepl
.showCmd
);
3794 if (WindowObject
->InternalPos
== NULL
)
3795 WindowObject
->InternalPos
= ExAllocatePoolWithTag(PagedPool
, sizeof(INTERNALPOS
), TAG_WININTLIST
);
3796 WindowObject
->InternalPos
->NormalRect
= Safepl
.rcNormalPosition
;
3797 WindowObject
->InternalPos
->IconPos
= Safepl
.ptMinPosition
;
3798 WindowObject
->InternalPos
->MaxPos
= Safepl
.ptMaxPosition
;
3800 IntReleaseWindowObject(WindowObject
);
3811 HWND hWndInsertAfter
,
3818 return WinPosSetWindowPos(hWnd
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
3823 IntGetWindowRgn(HWND hWnd
, HRGN hRgn
)
3826 PWINDOW_OBJECT WindowObject
;
3830 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
3832 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3837 IntReleaseWindowObject(WindowObject
);
3841 /* Create a new window region using the window rectangle */
3842 VisRgn
= UnsafeIntCreateRectRgnIndirect(&WindowObject
->WindowRect
);
3843 NtGdiOffsetRgn(VisRgn
, -WindowObject
->WindowRect
.left
, -WindowObject
->WindowRect
.top
);
3844 /* if there's a region assigned to the window, combine them both */
3845 if(WindowObject
->WindowRegion
&& !(WindowObject
->Style
& WS_MINIMIZE
))
3846 NtGdiCombineRgn(VisRgn
, VisRgn
, WindowObject
->WindowRegion
, RGN_AND
);
3847 /* Copy the region into hRgn */
3848 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
3850 if((pRgn
= RGNDATA_LockRgn(hRgn
)))
3852 Ret
= pRgn
->rdh
.iType
;
3853 RGNDATA_UnlockRgn(hRgn
);
3858 NtGdiDeleteObject(VisRgn
);
3860 IntReleaseWindowObject(WindowObject
);
3865 IntGetWindowRgnBox(HWND hWnd
, RECT
*Rect
)
3868 PWINDOW_OBJECT WindowObject
;
3872 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
3874 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3879 IntReleaseWindowObject(WindowObject
);
3883 /* Create a new window region using the window rectangle */
3884 VisRgn
= UnsafeIntCreateRectRgnIndirect(&WindowObject
->WindowRect
);
3885 NtGdiOffsetRgn(VisRgn
, -WindowObject
->WindowRect
.left
, -WindowObject
->WindowRect
.top
);
3886 /* if there's a region assigned to the window, combine them both */
3887 if(WindowObject
->WindowRegion
&& !(WindowObject
->Style
& WS_MINIMIZE
))
3888 NtGdiCombineRgn(VisRgn
, VisRgn
, WindowObject
->WindowRegion
, RGN_AND
);
3890 if((pRgn
= RGNDATA_LockRgn(VisRgn
)))
3892 Ret
= pRgn
->rdh
.iType
;
3893 *Rect
= pRgn
->rdh
.rcBound
;
3894 RGNDATA_UnlockRgn(VisRgn
);
3899 NtGdiDeleteObject(VisRgn
);
3901 IntReleaseWindowObject(WindowObject
);
3915 PWINDOW_OBJECT WindowObject
;
3917 WindowObject
= IntGetWindowObject(hWnd
);
3918 if (WindowObject
== NULL
)
3920 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3924 /* FIXME - Verify if hRgn is a valid handle!!!!
3925 Propably make this operation thread-safe, but maybe it's not necessary */
3927 if(WindowObject
->WindowRegion
)
3929 /* Delete no longer needed region handle */
3930 NtGdiDeleteObject(WindowObject
->WindowRegion
);
3932 WindowObject
->WindowRegion
= hRgn
;
3934 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
3938 IntRedrawWindow(WindowObject
, NULL
, NULL
, RDW_INVALIDATE
);
3941 IntReleaseWindowObject(WindowObject
);
3950 NtUserShowWindow(HWND hWnd
,
3953 return WinPosShowWindow(hWnd
, nCmdShow
);
3961 NtUserShowWindowAsync(DWORD Unknown0
,
3974 NtUserUpdateLayeredWindow(DWORD Unknown0
,
3994 NtUserValidateRect(HWND hWnd
, const RECT
* Rect
)
3996 return (VOID
)NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
4004 NtUserWindowFromPoint(LONG X
, LONG Y
)
4008 PWINDOW_OBJECT DesktopWindow
, Window
= NULL
;
4010 if ((DesktopWindow
= IntGetWindowObject(IntGetDesktopWindow())))
4017 Hit
= WinPosWindowFromPoint(DesktopWindow
, PsGetWin32Thread()->MessageQueue
, &pt
, &Window
);
4022 IntReleaseWindowObject(Window
);
4023 IntReleaseWindowObject(DesktopWindow
);
4027 IntReleaseWindowObject(DesktopWindow
);
4037 * Undocumented function that is called from DefWindowProc to set
4045 NtUserDefSetText(HWND WindowHandle
, PUNICODE_STRING WindowText
)
4047 PWINDOW_OBJECT WindowObject
;
4048 UNICODE_STRING SafeText
;
4051 WindowObject
= IntGetWindowObject(WindowHandle
);
4054 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4060 Status
= IntSafeCopyUnicodeString(&SafeText
, WindowText
);
4061 if(!NT_SUCCESS(Status
))
4063 SetLastNtError(Status
);
4064 IntReleaseWindowObject(WindowObject
);
4070 RtlInitUnicodeString(&SafeText
, NULL
);
4073 /* FIXME - do this thread-safe! otherwise one could crash here! */
4074 RtlFreeUnicodeString(&WindowObject
->WindowName
);
4076 WindowObject
->WindowName
= SafeText
;
4078 IntReleaseWindowObject(WindowObject
);
4083 * NtUserInternalGetWindowText
4090 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4092 PWINDOW_OBJECT WindowObject
;
4096 if(lpString
&& (nMaxCount
<= 1))
4098 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4102 WindowObject
= IntGetWindowObject(hWnd
);
4105 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4109 /* FIXME - do this thread-safe! otherwise one could crash here! */
4110 Result
= WindowObject
->WindowName
.Length
/ sizeof(WCHAR
);
4113 const WCHAR Terminator
= L
'\0';
4115 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4117 Copy
= min(nMaxCount
- 1, Result
);
4120 Status
= MmCopyToCaller(Buffer
, WindowObject
->WindowName
.Buffer
, Copy
* sizeof(WCHAR
));
4121 if(!NT_SUCCESS(Status
))
4123 SetLastNtError(Status
);
4124 IntReleaseWindowObject(WindowObject
);
4130 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4131 if(!NT_SUCCESS(Status
))
4133 SetLastNtError(Status
);
4134 IntReleaseWindowObject(WindowObject
);
4141 IntReleaseWindowObject(WindowObject
);
4146 NtUserDereferenceWndProcHandle(WNDPROC wpHandle
, WndProcHandle
*Data
)
4148 WndProcHandle Entry
;
4149 if (((DWORD
)wpHandle
& 0xFFFF0000) == 0xFFFF0000)
4151 Entry
= WndProcHandlesArray
[(DWORD
)wpHandle
& 0x0000FFFF];
4152 Data
->WindowProc
= Entry
.WindowProc
;
4153 Data
->IsUnicode
= Entry
.IsUnicode
;
4154 Data
->ProcessID
= Entry
.ProcessID
;
4163 IntAddWndProcHandle(WNDPROC WindowProc
, BOOL IsUnicode
)
4168 WndProcHandle
*OldArray
;
4171 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4173 if (WndProcHandlesArray
[i
].WindowProc
== NULL
)
4181 OldArray
= WndProcHandlesArray
;
4182 OldArraySize
= WndProcHandlesArraySize
;
4183 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,(OldArraySize
+ WPH_SIZE
) * sizeof(WndProcHandle
), TAG_WINPROCLST
);
4184 WndProcHandlesArraySize
= OldArraySize
+ WPH_SIZE
;
4185 RtlCopyMemory(WndProcHandlesArray
,OldArray
,OldArraySize
* sizeof(WndProcHandle
));
4186 ExFreePool(OldArray
);
4187 FreeSpot
= OldArraySize
+ 1;
4189 WndProcHandlesArray
[FreeSpot
].WindowProc
= WindowProc
;
4190 WndProcHandlesArray
[FreeSpot
].IsUnicode
= IsUnicode
;
4191 WndProcHandlesArray
[FreeSpot
].ProcessID
= PsGetCurrentProcessId();
4192 return FreeSpot
+ 0xFFFF0000;
4196 IntRemoveWndProcHandle(WNDPROC Handle
)
4199 position
= (DWORD
)Handle
& 0x0000FFFF;
4200 if (position
> WndProcHandlesArraySize
)
4204 WndProcHandlesArray
[position
].WindowProc
= NULL
;
4205 WndProcHandlesArray
[position
].IsUnicode
= FALSE
;
4206 WndProcHandlesArray
[position
].ProcessID
= NULL
;
4211 IntRemoveProcessWndProcHandles(HANDLE ProcessID
)
4214 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4216 if (WndProcHandlesArray
[i
].ProcessID
== ProcessID
)
4218 WndProcHandlesArray
[i
].WindowProc
= NULL
;
4219 WndProcHandlesArray
[i
].IsUnicode
= FALSE
;
4220 WndProcHandlesArray
[i
].ProcessID
= NULL
;