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.232 2004/05/14 16:50:16 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(PW32PROCESS ProcessData
, HWND hWnd
)
111 PWINDOW_OBJECT WindowObject
;
114 Status
= ObmReferenceObjectByHandle(ProcessData
->WindowStation
->HandleTable
,
115 hWnd
, otWindow
, (PVOID
*)&WindowObject
);
116 if (!NT_SUCCESS(Status
))
124 PWINDOW_OBJECT FASTCALL
125 IntGetParent(PWINDOW_OBJECT Wnd
)
129 if (Wnd
->Style
& WS_POPUP
)
131 IntLockRelatives(Wnd
);
133 IntUnLockRelatives(Wnd
);
134 return IntGetWindowObject(hWnd
);
136 else if (Wnd
->Style
& WS_CHILD
)
138 IntLockRelatives(Wnd
);
140 IntUnLockRelatives(Wnd
);
141 return IntGetWindowObject(hWnd
);
148 PWINDOW_OBJECT FASTCALL
149 IntGetParentObject(PWINDOW_OBJECT Wnd
)
153 IntLockRelatives(Wnd
);
154 hParent
= Wnd
->Parent
;
155 IntUnLockRelatives(Wnd
);
156 return IntGetWindowObject(hParent
);
162 * Compile a list of all child window handles from given window.
165 * This function is similar to Wine WIN_ListChildren. The caller
166 * must free the returned list with ExFreePool.
170 IntWinListChildren(PWINDOW_OBJECT Window
)
172 PWINDOW_OBJECT Child
;
174 UINT Index
, NumChildren
= 0;
176 IntLockRelatives(Window
);
178 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
181 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
184 DPRINT1("Failed to allocate memory for children array\n");
185 IntUnLockRelatives(Window
);
186 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
189 for (Child
= Window
->FirstChild
, Index
= 0;
191 Child
= Child
->NextSibling
, ++Index
)
192 List
[Index
] = Child
->Self
;
195 IntUnLockRelatives(Window
);
200 /***********************************************************************
203 static void IntSendDestroyMsg(HWND Wnd
)
208 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
210 if (Wnd
== info
.hwndCaret
)
218 * Send the WM_DESTROY to the window.
220 IntSendMessage(Wnd
, WM_DESTROY
, 0, 0);
223 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
224 * make sure that the window still exists when we come back.
232 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
234 /* start from the end (FIXME: is this needed?) */
235 for (i
= 0; pWndArray
[i
]; i
++) ;
239 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
241 HeapFree(GetProcessHeap(), 0, pWndArray
);
245 DPRINT("destroyed itself while in WM_DESTROY!\n");
250 /***********************************************************************
253 * Destroy storage associated to a window. "Internals" p.358
255 static LRESULT
IntDestroyWindow(PWINDOW_OBJECT Window
,
256 PW32PROCESS ProcessData
,
257 PW32THREAD ThreadData
,
258 BOOLEAN SendMessages
)
262 PWINDOW_OBJECT Child
;
264 BOOL BelongsToThreadData
;
268 RemoveTimersWindow(Window
->Self
);
270 IntLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
271 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
273 IntUnLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
274 DPRINT("Tried to call IntDestroyWindow() twice\n");
277 Window
->Status
|= WINDOWSTATUS_DESTROYING
;
278 /* remove the window already at this point from the thread window list so we
279 don't get into trouble when destroying the thread windows while we're still
280 in IntDestroyWindow() */
281 RemoveEntryList(&Window
->ThreadListEntry
);
282 IntUnLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
284 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
288 /* Send destroy messages */
289 IntSendDestroyMsg(Window
->Self
);
292 /* free child windows */
293 Children
= IntWinListChildren(Window
);
296 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
298 if ((Child
= IntGetWindowObject(*ChildHandle
)))
300 if(!IntWndBelongsToThread(Child
, ThreadData
))
302 /* send WM_DESTROY messages to windows not belonging to the same thread */
303 IntSendDestroyMsg(Child
->Self
);
306 IntDestroyWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
307 IntReleaseWindowObject(Child
);
310 ExFreePool(Children
);
316 * Clear the update region to make sure no WM_PAINT messages will be
317 * generated for this window while processing the WM_NCDESTROY.
319 IntRedrawWindow(Window
, NULL
, 0,
320 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
321 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
324 * Send the WM_NCDESTROY to the window being destroyed.
326 if(BelongsToThreadData
)
327 IntSendMessage(Window
->Self
, WM_NCDESTROY
, 0, 0);
330 /* reset shell window handles */
331 if(ProcessData
->WindowStation
)
333 if (Window
->Self
== ProcessData
->WindowStation
->ShellWindow
)
334 ProcessData
->WindowStation
->ShellWindow
= NULL
;
336 if (Window
->Self
== ProcessData
->WindowStation
->ShellListView
)
337 ProcessData
->WindowStation
->ShellListView
= NULL
;
340 /* Unregister hot keys */
341 UnregisterWindowHotKeys (Window
);
343 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
346 WinPosCheckInternalPos(Window
->Self
);
347 if (Window
->Self
== GetCapture())
352 /* free resources associated with the window */
353 TIMER_RemoveWindowTimers(Window
->Self
);
356 if (!(Window
->Style
& WS_CHILD
) && Window
->IDMenu
357 && (Menu
= IntGetMenuObject((HMENU
)Window
->IDMenu
)))
359 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
361 IntReleaseMenuObject(Menu
);
364 if(Window
->SystemMenu
365 && (Menu
= IntGetMenuObject(Window
->SystemMenu
)))
367 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
368 Window
->SystemMenu
= (HMENU
)0;
369 IntReleaseMenuObject(Menu
);
372 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
374 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
375 CLASS_RemoveWindow(Window
->Class
);
378 IntUnlinkWindow(Window
);
380 IntReferenceWindowObject(Window
);
381 ObmCloseHandle(ProcessData
->WindowStation
->HandleTable
, Window
->Self
);
383 IntDestroyScrollBars(Window
);
385 IntLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
386 Window
->Status
|= WINDOWSTATUS_DESTROYED
;
387 /* don't remove the WINDOWSTATUS_DESTROYING bit */
388 IntUnLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
390 ObmDereferenceObject(Window
->Class
);
391 Window
->Class
= NULL
;
393 if(Window
->WindowRegion
)
395 NtGdiDeleteObject(Window
->WindowRegion
);
398 RtlFreeUnicodeString(&Window
->WindowName
);
400 IntReleaseWindowObject(Window
);
406 IntGetWindowBorderMeasures(PWINDOW_OBJECT WindowObject
, INT
*cx
, INT
*cy
)
408 if(HAS_DLGFRAME(WindowObject
->Style
, WindowObject
->ExStyle
) && !(WindowObject
->Style
& WS_MINIMIZE
))
410 *cx
= NtUserGetSystemMetrics(SM_CXDLGFRAME
);
411 *cy
= NtUserGetSystemMetrics(SM_CYDLGFRAME
);
415 if(HAS_THICKFRAME(WindowObject
->Style
, WindowObject
->ExStyle
)&& !(WindowObject
->Style
& WS_MINIMIZE
))
417 *cx
= NtUserGetSystemMetrics(SM_CXFRAME
);
418 *cy
= NtUserGetSystemMetrics(SM_CYFRAME
);
420 else if(HAS_THINFRAME(WindowObject
->Style
, WindowObject
->ExStyle
))
422 *cx
= NtUserGetSystemMetrics(SM_CXBORDER
);
423 *cy
= NtUserGetSystemMetrics(SM_CYBORDER
);
433 IntGetWindowInfo(PWINDOW_OBJECT WindowObject
, PWINDOWINFO pwi
)
435 pwi
->cbSize
= sizeof(WINDOWINFO
);
436 pwi
->rcWindow
= WindowObject
->WindowRect
;
437 pwi
->rcClient
= WindowObject
->ClientRect
;
438 pwi
->dwStyle
= WindowObject
->Style
;
439 pwi
->dwExStyle
= WindowObject
->ExStyle
;
440 pwi
->dwWindowStatus
= (NtUserGetForegroundWindow() == WindowObject
->Self
); /* WS_ACTIVECAPTION */
441 IntGetWindowBorderMeasures(WindowObject
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
442 pwi
->atomWindowType
= (WindowObject
->Class
? WindowObject
->Class
->Atom
: 0);
443 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
449 PWINDOW_OBJECT WindowObject
,
453 PMENU_OBJECT OldMenuObject
, NewMenuObject
;
455 *Changed
= (WindowObject
->IDMenu
!= (UINT
) Menu
);
461 if (0 != WindowObject
->IDMenu
)
463 OldMenuObject
= IntGetMenuObject((HMENU
) WindowObject
->IDMenu
);
464 ASSERT(NULL
== OldMenuObject
|| OldMenuObject
->MenuInfo
.Wnd
== WindowObject
->Self
);
468 OldMenuObject
= NULL
;
473 NewMenuObject
= IntGetMenuObject(Menu
);
474 if (NULL
== NewMenuObject
)
476 if (NULL
!= OldMenuObject
)
478 IntReleaseMenuObject(OldMenuObject
);
480 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
483 if (NULL
!= NewMenuObject
->MenuInfo
.Wnd
)
485 /* Can't use the same menu for two windows */
486 if (NULL
!= OldMenuObject
)
488 IntReleaseMenuObject(OldMenuObject
);
490 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
496 WindowObject
->IDMenu
= (UINT
) Menu
;
497 if (NULL
!= NewMenuObject
)
499 NewMenuObject
->MenuInfo
.Wnd
= WindowObject
->Self
;
500 IntReleaseMenuObject(NewMenuObject
);
502 if (NULL
!= OldMenuObject
)
504 OldMenuObject
->MenuInfo
.Wnd
= NULL
;
505 IntReleaseMenuObject(OldMenuObject
);
512 /* INTERNAL ******************************************************************/
516 DestroyThreadWindows(struct _ETHREAD
*Thread
)
519 PW32PROCESS Win32Process
;
520 PW32THREAD Win32Thread
;
521 PWINDOW_OBJECT
*List
, *pWnd
;
524 Win32Thread
= Thread
->Win32Thread
;
525 Win32Process
= Thread
->ThreadsProcess
->Win32Process
;
527 IntLockThreadWindows(Win32Thread
);
528 Current
= Win32Thread
->WindowListHead
.Flink
;
529 while (Current
!= &(Win32Thread
->WindowListHead
))
532 Current
= Current
->Flink
;
537 List
= ExAllocatePool(PagedPool
, (Cnt
+ 1) * sizeof(PWINDOW_OBJECT
));
540 DPRINT("Not enough memory to allocate window handle list\n");
541 IntUnLockThreadWindows(Win32Thread
);
545 Current
= Win32Thread
->WindowListHead
.Flink
;
546 while (Current
!= &(Win32Thread
->WindowListHead
))
548 *pWnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
549 IntReferenceWindowObject(*pWnd
);
551 Current
= Current
->Flink
;
553 IntUnLockThreadWindows(Win32Thread
);
556 for(pWnd
= List
; *pWnd
; pWnd
++)
558 NtUserDestroyWindow((*pWnd
)->Self
);
559 IntReleaseWindowObject(*pWnd
);
565 IntUnLockThreadWindows(Win32Thread
);
571 * Returns client window rectangle relative to the upper-left corner of client area.
573 * \note Does not check the validity of the parameters
576 IntGetClientRect(PWINDOW_OBJECT WindowObject
, PRECT Rect
)
578 ASSERT( WindowObject
);
581 Rect
->left
= Rect
->top
= 0;
582 Rect
->right
= WindowObject
->ClientRect
.right
- WindowObject
->ClientRect
.left
;
583 Rect
->bottom
= WindowObject
->ClientRect
.bottom
- WindowObject
->ClientRect
.top
;
589 IntGetFocusWindow(VOID
)
591 PUSER_MESSAGE_QUEUE Queue
;
592 PDESKTOP_OBJECT pdo
= IntGetActiveDesktop();
597 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
602 return(Queue
->FocusWindow
);
606 PMENU_OBJECT FASTCALL
607 IntGetSystemMenu(PWINDOW_OBJECT WindowObject
, BOOL bRevert
, BOOL RetMenu
)
609 PMENU_OBJECT MenuObject
, NewMenuObject
, SysMenuObject
, ret
= NULL
;
610 PW32PROCESS W32Process
;
611 HMENU NewMenu
, SysMenu
;
612 ROSMENUITEMINFO ItemInfo
;
616 W32Process
= PsGetWin32Process();
618 if(!W32Process
->WindowStation
)
621 if(WindowObject
->SystemMenu
)
623 MenuObject
= IntGetMenuObject(WindowObject
->SystemMenu
);
626 IntDestroyMenuObject(MenuObject
, FALSE
, TRUE
);
627 WindowObject
->SystemMenu
= (HMENU
)0;
628 IntReleaseMenuObject(MenuObject
);
632 if(W32Process
->WindowStation
->SystemMenuTemplate
)
634 /* clone system menu */
635 MenuObject
= IntGetMenuObject(W32Process
->WindowStation
->SystemMenuTemplate
);
639 NewMenuObject
= IntCloneMenu(MenuObject
);
642 WindowObject
->SystemMenu
= NewMenuObject
->MenuInfo
.Self
;
643 NewMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
644 NewMenuObject
->MenuInfo
.Wnd
= WindowObject
->Self
;
646 //IntReleaseMenuObject(NewMenuObject);
648 IntReleaseMenuObject(MenuObject
);
652 SysMenu
= NtUserCreateMenu(FALSE
);
657 SysMenuObject
= IntGetMenuObject(SysMenu
);
658 if (NULL
== SysMenuObject
)
660 NtUserDestroyMenu(SysMenu
);
663 SysMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
664 SysMenuObject
->MenuInfo
.Wnd
= WindowObject
->Self
;
665 NewMenu
= IntLoadSysMenuTemplate();
668 IntReleaseMenuObject(SysMenuObject
);
669 NtUserDestroyMenu(SysMenu
);
672 MenuObject
= IntGetMenuObject(NewMenu
);
675 IntReleaseMenuObject(SysMenuObject
);
676 NtUserDestroyMenu(SysMenu
);
680 NewMenuObject
= IntCloneMenu(MenuObject
);
683 NewMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
684 IntReleaseMenuObject(NewMenuObject
);
685 NtUserSetMenuDefaultItem(NewMenuObject
->MenuInfo
.Self
, SC_CLOSE
, FALSE
);
687 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
688 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
689 ItemInfo
.fType
= MF_POPUP
;
690 ItemInfo
.fState
= MFS_ENABLED
;
691 ItemInfo
.dwTypeData
= NULL
;
693 ItemInfo
.hSubMenu
= NewMenuObject
->MenuInfo
.Self
;
694 IntInsertMenuItem(SysMenuObject
, (UINT
) -1, TRUE
, &ItemInfo
);
696 WindowObject
->SystemMenu
= SysMenuObject
->MenuInfo
.Self
;
700 IntDestroyMenuObject(MenuObject
, FALSE
, TRUE
);
701 IntReleaseMenuObject(MenuObject
);
710 if(WindowObject
->SystemMenu
)
711 return IntGetMenuObject((HMENU
)WindowObject
->SystemMenu
);
719 IntIsChildWindow(HWND Parent
, HWND Child
)
721 PWINDOW_OBJECT BaseWindow
, Window
, Old
;
723 if(!(BaseWindow
= IntGetWindowObject(Child
)))
731 if (Window
->Self
== Parent
)
733 if(Window
!= BaseWindow
)
734 IntReleaseWindowObject(Window
);
735 IntReleaseWindowObject(BaseWindow
);
738 if(!(Window
->Style
& WS_CHILD
))
740 if(Window
!= BaseWindow
)
741 IntReleaseWindowObject(Window
);
745 Window
= IntGetParentObject(Window
);
746 if(Old
!= BaseWindow
)
747 IntReleaseWindowObject(Old
);
750 IntReleaseWindowObject(BaseWindow
);
755 IntIsWindowVisible(HWND hWnd
)
757 PWINDOW_OBJECT BaseWindow
, Window
, Old
;
759 if(!(BaseWindow
= IntGetWindowObject(hWnd
)))
767 if(!(Window
->Style
& WS_CHILD
))
771 if(!(Window
->Style
& WS_VISIBLE
))
773 if(Window
!= BaseWindow
)
774 IntReleaseWindowObject(Window
);
775 IntReleaseWindowObject(BaseWindow
);
779 Window
= IntGetParentObject(Window
);
780 if(Old
!= BaseWindow
)
781 IntReleaseWindowObject(Old
);
786 if(Window
->Style
& WS_VISIBLE
)
788 if(Window
!= BaseWindow
)
789 IntReleaseWindowObject(Window
);
790 IntReleaseWindowObject(BaseWindow
);
793 if(Window
!= BaseWindow
)
794 IntReleaseWindowObject(Window
);
796 IntReleaseWindowObject(BaseWindow
);
801 /* link the window into siblings and parent. children are kept in place. */
805 PWINDOW_OBJECT WndParent
,
806 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
809 PWINDOW_OBJECT Parent
;
811 IntLockRelatives(Wnd
);
812 Wnd
->Parent
= WndParent
->Self
;
813 if ((Wnd
->PrevSibling
= WndPrevSibling
))
815 /* link after WndPrevSibling */
816 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
817 Wnd
->NextSibling
->PrevSibling
= Wnd
;
818 else if ((Parent
= IntGetWindowObject(Wnd
->Parent
)))
820 IntLockRelatives(Parent
);
821 if(Parent
->LastChild
== WndPrevSibling
)
822 Parent
->LastChild
= Wnd
;
823 IntUnLockRelatives(Parent
);
824 IntReleaseWindowObject(Parent
);
826 Wnd
->PrevSibling
->NextSibling
= Wnd
;
831 Parent
= IntGetWindowObject(Wnd
->Parent
);
832 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
833 Wnd
->NextSibling
->PrevSibling
= Wnd
;
836 IntLockRelatives(Parent
);
837 Parent
->LastChild
= Wnd
;
838 Parent
->FirstChild
= Wnd
;
839 IntUnLockRelatives(Parent
);
840 IntReleaseWindowObject(Parent
);
841 IntUnLockRelatives(Wnd
);
846 IntLockRelatives(Parent
);
847 Parent
->FirstChild
= Wnd
;
848 IntUnLockRelatives(Parent
);
849 IntReleaseWindowObject(Parent
);
852 IntUnLockRelatives(Wnd
);
856 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
858 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
861 Wnd
= IntGetWindowObject(hWnd
);
865 IntLockRelatives(Wnd
);
866 WndOldOwner
= IntGetWindowObject(Wnd
->Owner
);
869 ret
= WndOldOwner
->Self
;
870 IntReleaseWindowObject(WndOldOwner
);
877 if((WndNewOwner
= IntGetWindowObject(hWndNewOwner
)))
879 Wnd
->Owner
= hWndNewOwner
;
880 IntReleaseWindowObject(WndNewOwner
);
885 IntUnLockRelatives(Wnd
);
886 IntReleaseWindowObject(Wnd
);
890 PWINDOW_OBJECT FASTCALL
891 IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
893 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
894 HWND hWnd
, hWndNewParent
, hWndOldParent
;
899 ASSERT(WndNewParent
);
902 hWndNewParent
= WndNewParent
->Self
;
905 * Windows hides the window first, then shows it again
906 * including the WM_SHOWWINDOW messages and all
908 WasVisible
= WinPosShowWindow(hWnd
, SW_HIDE
);
910 /* Validate that window and parent still exist */
911 if (!IntIsWindow(hWnd
) || !IntIsWindow(hWndNewParent
))
914 /* Window must belong to current process */
915 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
918 WndOldParent
= IntGetParentObject(Wnd
);
919 hWndOldParent
= (WndOldParent
? WndOldParent
->Self
: NULL
);
921 if (WndNewParent
!= WndOldParent
)
923 IntUnlinkWindow(Wnd
);
925 if (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
))
927 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
928 IntLockRelatives(WndNewParent
);
929 Sibling
= WndNewParent
->FirstChild
;
930 while (NULL
!= Sibling
&& 0 != (Sibling
->ExStyle
& WS_EX_TOPMOST
))
932 InsertAfter
= Sibling
;
933 Sibling
= Sibling
->NextSibling
;
935 IntUnLockRelatives(WndNewParent
);
937 if (NULL
== InsertAfter
)
939 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
943 IntReferenceWindowObject(InsertAfter
);
944 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
945 IntReleaseWindowObject(InsertAfter
);
948 if (WndNewParent
->Self
!= IntGetDesktopWindow()) /* a child window */
950 if (!(Wnd
->Style
& WS_CHILD
))
952 //if ( Wnd->Menu ) DestroyMenu ( Wnd->menu );
953 IntSetMenu(Wnd
, NULL
, &MenuChanged
);
959 * SetParent additionally needs to make hwnd the top window
960 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
961 * WM_WINDOWPOSCHANGED notification messages.
963 WinPosSetWindowPos(hWnd
, (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
964 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
965 | (WasVisible
? SWP_SHOWWINDOW
: 0));
968 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
969 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
973 * Validate that the old parent still exist, since it migth have been
974 * destroyed during the last callbacks to user-mode
978 if(!IntIsWindow(WndOldParent
->Self
))
980 IntReleaseWindowObject(WndOldParent
);
984 /* don't dereference the window object here, it must be done by the caller
992 IntSetSystemMenu(PWINDOW_OBJECT WindowObject
, PMENU_OBJECT MenuObject
)
994 PMENU_OBJECT OldMenuObject
;
995 if(WindowObject
->SystemMenu
)
997 OldMenuObject
= IntGetMenuObject(WindowObject
->SystemMenu
);
1000 OldMenuObject
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1001 IntReleaseMenuObject(OldMenuObject
);
1007 /* FIXME check window style, propably return FALSE ? */
1008 WindowObject
->SystemMenu
= MenuObject
->MenuInfo
.Self
;
1009 MenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
1012 WindowObject
->SystemMenu
= (HMENU
)0;
1018 /* unlink the window from siblings and parent. children are kept in place. */
1020 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1022 PWINDOW_OBJECT WndParent
;
1024 IntLockRelatives(Wnd
);
1025 if((WndParent
= IntGetWindowObject(Wnd
->Parent
)))
1027 IntLockRelatives(WndParent
);
1030 if (Wnd
->NextSibling
) Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1031 else if (WndParent
&& WndParent
->LastChild
== Wnd
) WndParent
->LastChild
= Wnd
->PrevSibling
;
1033 if (Wnd
->PrevSibling
) Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1034 else if (WndParent
&& WndParent
->FirstChild
== Wnd
) WndParent
->FirstChild
= Wnd
->NextSibling
;
1038 IntUnLockRelatives(WndParent
);
1039 IntReleaseWindowObject(WndParent
);
1041 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1042 IntUnLockRelatives(Wnd
);
1048 PWINDOW_OBJECT Window
, Child
;
1050 if(!(Window
= IntGetWindowObject(IntGetDesktopWindow())))
1052 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1056 IntLockRelatives(Window
);
1057 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1059 if(Child
->Owner
&& Child
->Style
& WS_VISIBLE
)
1062 * The desktop has a popup window if one of them has
1063 * an owner window and is visible
1065 IntUnLockRelatives(Window
);
1066 IntReleaseWindowObject(Window
);
1070 IntUnLockRelatives(Window
);
1071 IntReleaseWindowObject(Window
);
1076 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1078 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1081 /* FUNCTIONS *****************************************************************/
1087 NtUserAlterWindowStyle(DWORD Unknown0
,
1098 * As best as I can figure, this function is used by EnumWindows,
1099 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1101 * It's supposed to build a list of HWNDs to return to the caller.
1102 * We can figure out what kind of list by what parameters are
1110 NtUserBuildHwndList(
1122 /* FIXME handle bChildren */
1126 PWINDOW_OBJECT Window
, Child
;
1127 if(!(Window
= IntGetWindowObject(hwndParent
)))
1129 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1133 IntLockRelatives(Window
);
1134 for(Child
= Window
->FirstChild
; Child
!= NULL
; Child
= Child
->NextSibling
)
1136 if(dwCount
++ < nBufSize
&& pWnd
)
1138 Status
= MmCopyToCaller(pWnd
++, &Child
->Self
, sizeof(HWND
));
1139 if(!NT_SUCCESS(Status
))
1141 SetLastNtError(Status
);
1146 IntUnLockRelatives(Window
);
1148 IntReleaseWindowObject(Window
);
1153 PW32THREAD W32Thread
;
1154 PLIST_ENTRY Current
;
1155 PWINDOW_OBJECT
*Window
;
1157 Status
= PsLookupThreadByThreadId((PVOID
)dwThreadId
, &Thread
);
1158 if(!NT_SUCCESS(Status
))
1160 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1163 if(!(W32Thread
= Thread
->Win32Thread
))
1165 ObDereferenceObject(Thread
);
1166 DPRINT1("Thread is not a GUI Thread!\n");
1167 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1171 IntLockThreadWindows(W32Thread
);
1172 Current
= W32Thread
->WindowListHead
.Flink
;
1173 while(Current
!= &(W32Thread
->WindowListHead
))
1175 *Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1178 if(dwCount
< nBufSize
&& pWnd
&& ((*Window
)->Style
& WS_CHILD
))
1180 Status
= MmCopyToCaller(pWnd
++, &(*Window
)->Self
, sizeof(HWND
));
1181 if(!NT_SUCCESS(Status
))
1183 SetLastNtError(Status
);
1188 if(!((*Window
)->Style
& WS_CHILD
))
1193 Current
= Current
->Flink
;
1195 IntUnLockThreadWindows(W32Thread
);
1197 ObDereferenceObject(Thread
);
1201 PDESKTOP_OBJECT Desktop
;
1202 PWINDOW_OBJECT Window
, Child
;
1204 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1206 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1212 Status
= IntValidateDesktopHandle(hDesktop
,
1216 if(!NT_SUCCESS(Status
))
1218 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1222 if(!(Window
= IntGetWindowObject(Desktop
->DesktopWindow
)))
1225 ObDereferenceObject(Desktop
);
1226 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1230 IntLockRelatives(Window
);
1231 for(Child
= Window
->FirstChild
; Child
!= NULL
; Child
= Child
->NextSibling
)
1233 if(dwCount
++ < nBufSize
&& pWnd
)
1235 Status
= MmCopyToCaller(pWnd
++, &Child
->Self
, sizeof(HWND
));
1236 if(!NT_SUCCESS(Status
))
1238 SetLastNtError(Status
);
1243 IntUnLockRelatives(Window
);
1245 IntReleaseWindowObject(Window
);
1247 ObDereferenceObject(Desktop
);
1258 NtUserChildWindowFromPointEx(HWND hwndParent
,
1263 PWINDOW_OBJECT Parent
;
1268 if(!(Parent
= IntGetWindowObject(hwndParent
)))
1270 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1277 if(Parent
->Self
!= IntGetDesktopWindow())
1279 Pt
.x
+= Parent
->ClientRect
.left
;
1280 Pt
.y
+= Parent
->ClientRect
.top
;
1283 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1285 IntReleaseWindowObject(Parent
);
1290 if((List
= IntWinListChildren(Parent
)))
1292 for(phWnd
= List
; *phWnd
; phWnd
++)
1294 PWINDOW_OBJECT Child
;
1295 if((Child
= IntGetWindowObject(*phWnd
)))
1297 if(!(Child
->Style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1299 IntReleaseWindowObject(Child
);
1302 if((Child
->Style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1304 IntReleaseWindowObject(Child
);
1307 if((Child
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1309 IntReleaseWindowObject(Child
);
1312 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1315 IntReleaseWindowObject(Child
);
1318 IntReleaseWindowObject(Child
);
1324 IntReleaseWindowObject(Parent
);
1330 * calculates the default position of a window
1333 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT WindowObject
, RECT
*rc
, BOOL IncPos
)
1340 NtGdiIntersectRect(rc
, rc
, &Parent
->ClientRect
);
1344 Pos
.x
= Parent
->TiledCounter
* (NtUserGetSystemMetrics(SM_CXSIZE
) + NtUserGetSystemMetrics(SM_CXFRAME
));
1345 Pos
.y
= Parent
->TiledCounter
* (NtUserGetSystemMetrics(SM_CYSIZE
) + NtUserGetSystemMetrics(SM_CYFRAME
));
1346 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1347 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1349 /* reset counter and position */
1352 Parent
->TiledCounter
= 0;
1354 Parent
->TiledCounter
++;
1365 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1366 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1370 rc
->right
= rc
->left
+ Sz
.cx
;
1371 rc
->bottom
= rc
->top
+ Sz
.cy
;
1380 NtUserCreateWindowEx(DWORD dwExStyle
,
1381 PUNICODE_STRING lpClassName
,
1382 PUNICODE_STRING lpWindowName
,
1390 HINSTANCE hInstance
,
1393 BOOL bUnicodeWindow
)
1395 PWINSTATION_OBJECT WinStaObject
;
1396 PWNDCLASS_OBJECT ClassObject
;
1397 PWINDOW_OBJECT WindowObject
;
1398 PWINDOW_OBJECT ParentWindow
, OwnerWindow
;
1399 HWND ParentWindowHandle
;
1400 HWND OwnerWindowHandle
;
1401 PMENU_OBJECT SystemMenu
;
1402 UNICODE_STRING WindowName
;
1408 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1413 CBT_CREATEWNDW CbtCreate
;
1416 LPWSTR OrigWindowName
= NULL
;
1418 DPRINT("NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1420 /* safely copy the window name */
1423 Status
= MmCopyFromCaller(&WindowName
, lpWindowName
, sizeof(UNICODE_STRING
));
1424 if (!NT_SUCCESS(Status
))
1426 SetLastNtError(Status
);
1429 if(WindowName
.Buffer
)
1431 /* safe the original pointer to the window name */
1432 OrigWindowName
= WindowName
.Buffer
;
1434 if(!(WindowName
.Buffer
= ExAllocatePoolWithTag(NonPagedPool
, WindowName
.MaximumLength
, TAG_STRING
)))
1436 SetLastNtError(STATUS_NO_MEMORY
);
1440 Status
= MmCopyFromCaller(WindowName
.Buffer
, OrigWindowName
, WindowName
.MaximumLength
);
1441 if(!NT_SUCCESS(Status
))
1443 ExFreePool(WindowName
.Buffer
);
1444 SetLastNtError(Status
);
1449 if(!WindowName
.Buffer
)
1450 RtlInitUnicodeString(&WindowName
, NULL
);
1453 RtlInitUnicodeString(&WindowName
, NULL
);
1455 ParentWindowHandle
= PsGetWin32Thread()->Desktop
->DesktopWindow
;
1456 OwnerWindowHandle
= NULL
;
1458 if (hWndParent
== HWND_MESSAGE
)
1461 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1462 * message window (style: WS_POPUP|WS_DISABLED)
1466 else if (hWndParent
)
1468 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1469 ParentWindowHandle
= hWndParent
;
1471 OwnerWindowHandle
= NtUserGetAncestor(hWndParent
, GA_ROOT
);
1473 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1475 RtlFreeUnicodeString(&WindowName
);
1476 return (HWND
)0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1479 if (NULL
!= ParentWindowHandle
)
1481 ParentWindow
= IntGetWindowObject(ParentWindowHandle
);
1485 ParentWindow
= NULL
;
1488 /* FIXME: parent must belong to the current process */
1490 /* Check the class. */
1491 Status
= ClassReferenceClassByNameOrAtom(&ClassObject
, lpClassName
->Buffer
);
1492 if (!NT_SUCCESS(Status
))
1494 RtlFreeUnicodeString(&WindowName
);
1495 if (NULL
!= ParentWindow
)
1497 IntReleaseWindowObject(ParentWindow
);
1502 /* Check the window station. */
1503 DPRINT("IoGetCurrentProcess() %X\n", IoGetCurrentProcess());
1504 DPRINT("PROCESS_WINDOW_STATION %X\n", PROCESS_WINDOW_STATION());
1505 Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
1509 if (!NT_SUCCESS(Status
))
1511 ObmDereferenceObject(ClassObject
);
1512 RtlFreeUnicodeString(&WindowName
);
1513 if (NULL
!= ParentWindow
)
1515 IntReleaseWindowObject(ParentWindow
);
1517 DPRINT("Validation of window station handle (0x%X) failed\n",
1518 PROCESS_WINDOW_STATION());
1522 /* Create the window object. */
1523 WindowObject
= (PWINDOW_OBJECT
)
1524 ObmCreateObject(PsGetWin32Process()->WindowStation
->HandleTable
, &Handle
,
1525 otWindow
, sizeof(WINDOW_OBJECT
) + ClassObject
->cbWndExtra
1528 DPRINT("Created object with handle %X\n", Handle
);
1531 ObDereferenceObject(WinStaObject
);
1532 ObmDereferenceObject(ClassObject
);
1533 RtlFreeUnicodeString(&WindowName
);
1534 if (NULL
!= ParentWindow
)
1536 IntReleaseWindowObject(ParentWindow
);
1538 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1541 ObDereferenceObject(WinStaObject
);
1543 if (NULL
== PsGetWin32Thread()->Desktop
->DesktopWindow
)
1545 /* If there is no desktop window yet, we must be creating it */
1546 PsGetWin32Thread()->Desktop
->DesktopWindow
= Handle
;
1550 * Fill out the structure describing it.
1552 WindowObject
->Class
= ClassObject
;
1553 WindowObject
->ExStyle
= dwExStyle
;
1554 WindowObject
->Style
= dwStyle
& ~WS_VISIBLE
;
1555 DPRINT("1: Style is now %lx\n", WindowObject
->Style
);
1557 WindowObject
->SystemMenu
= (HMENU
)0;
1558 WindowObject
->ContextHelpId
= 0;
1559 WindowObject
->IDMenu
= 0;
1560 WindowObject
->Instance
= hInstance
;
1561 WindowObject
->Self
= Handle
;
1562 if (0 != (dwStyle
& WS_CHILD
))
1564 WindowObject
->IDMenu
= (UINT
) hMenu
;
1568 IntSetMenu(WindowObject
, hMenu
, &MenuChanged
);
1570 WindowObject
->MessageQueue
= PsGetWin32Thread()->MessageQueue
;
1571 WindowObject
->Parent
= (ParentWindow
? ParentWindow
->Self
: NULL
);
1572 if((OwnerWindow
= IntGetWindowObject(OwnerWindowHandle
)))
1574 WindowObject
->Owner
= OwnerWindowHandle
;
1575 IntReleaseWindowObject(OwnerWindow
);
1578 WindowObject
->Owner
= NULL
;
1579 WindowObject
->UserData
= 0;
1580 if ((((DWORD
)ClassObject
->lpfnWndProcA
& 0xFFFF0000) != 0xFFFF0000)
1581 && (((DWORD
)ClassObject
->lpfnWndProcW
& 0xFFFF0000) != 0xFFFF0000))
1583 WindowObject
->Unicode
= bUnicodeWindow
;
1587 WindowObject
->Unicode
= ClassObject
->Unicode
;
1589 WindowObject
->WndProcA
= ClassObject
->lpfnWndProcA
;
1590 WindowObject
->WndProcW
= ClassObject
->lpfnWndProcW
;
1591 WindowObject
->OwnerThread
= PsGetCurrentThread();
1592 WindowObject
->FirstChild
= NULL
;
1593 WindowObject
->LastChild
= NULL
;
1594 WindowObject
->PrevSibling
= NULL
;
1595 WindowObject
->NextSibling
= NULL
;
1597 /* extra window data */
1598 if (ClassObject
->cbWndExtra
!= 0)
1600 WindowObject
->ExtraData
= (PCHAR
)(WindowObject
+ 1);
1601 WindowObject
->ExtraDataSize
= ClassObject
->cbWndExtra
;
1602 RtlZeroMemory(WindowObject
->ExtraData
, WindowObject
->ExtraDataSize
);
1606 WindowObject
->ExtraData
= NULL
;
1607 WindowObject
->ExtraDataSize
= 0;
1610 InitializeListHead(&WindowObject
->PropListHead
);
1611 ExInitializeFastMutex(&WindowObject
->PropListLock
);
1612 ExInitializeFastMutex(&WindowObject
->RelativesLock
);
1613 ExInitializeFastMutex(&WindowObject
->UpdateLock
);
1615 WindowObject
->WindowName
= WindowName
;
1617 /* Correct the window style. */
1618 if (!(dwStyle
& WS_CHILD
))
1620 WindowObject
->Style
|= WS_CLIPSIBLINGS
;
1621 DPRINT("3: Style is now %lx\n", WindowObject
->Style
);
1622 if (!(dwStyle
& WS_POPUP
))
1624 WindowObject
->Style
|= WS_CAPTION
;
1625 WindowObject
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1626 DPRINT("4: Style is now %lx\n", WindowObject
->Style
);
1627 /* FIXME: Note the window needs a size. */
1631 if(!(WindowObject
->Style
& (WS_POPUP
| WS_CHILD
)))
1633 /* Automatically assign the caption and border style. Also always
1634 clip siblings for overlapped windows. */
1635 WindowObject
->Style
|= (WS_CAPTION
| WS_BORDER
| WS_CLIPSIBLINGS
);
1638 /* create system menu */
1639 if((WindowObject
->Style
& WS_SYSMENU
) && (WindowObject
->Style
& WS_CAPTION
))
1641 SystemMenu
= IntGetSystemMenu(WindowObject
, TRUE
, TRUE
);
1644 WindowObject
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1645 IntReleaseMenuObject(SystemMenu
);
1649 /* Insert the window into the thread's window list. */
1650 IntLockThreadWindows(PsGetWin32Thread());
1651 InsertTailList (&PsGetWin32Thread()->WindowListHead
,
1652 &WindowObject
->ThreadListEntry
);
1653 IntUnLockThreadWindows(PsGetWin32Thread());
1655 /* Allocate a DCE for this window. */
1656 if (dwStyle
& CS_OWNDC
)
1658 WindowObject
->Dce
= DceAllocDCE(WindowObject
->Self
, DCE_WINDOW_DC
);
1660 /* FIXME: Handle "CS_CLASSDC" */
1668 Cs
.lpCreateParams
= lpParam
;
1669 Cs
.hInstance
= hInstance
;
1671 Cs
.hwndParent
= ParentWindowHandle
;
1677 Cs
.lpszName
= OrigWindowName
; /* pass the original pointer to usermode! */
1678 Cs
.lpszClass
= lpClassName
->Buffer
;
1679 Cs
.dwExStyle
= dwExStyle
;
1680 CbtCreate
.lpcs
= &Cs
;
1681 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1682 if (HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) Handle
, (LPARAM
) &CbtCreate
))
1684 if (NULL
!= ParentWindow
)
1686 IntReleaseWindowObject(ParentWindow
);
1689 /* FIXME - Delete window object and remove it from the thread windows list */
1690 /* FIXME - delete allocated DCE */
1692 DPRINT1("CBT-hook returned !0\n");
1701 /* default positioning for overlapped windows */
1702 if(!(WindowObject
->Style
& (WS_POPUP
| WS_CHILD
)))
1705 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1706 BOOL CalculatedDefPosSize
= FALSE
;
1708 IntGetDesktopWorkArea(WindowObject
->OwnerThread
->Win32Thread
->Desktop
, &WorkArea
);
1711 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1713 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1715 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, WindowObject
, &rc
, TRUE
);
1717 if(ProcessParams
->dwFlags
& STARTF_USEPOSITION
)
1719 ProcessParams
->dwFlags
&= ~STARTF_USEPOSITION
;
1720 Pos
.x
= WorkArea
.left
+ ProcessParams
->dwX
;
1721 Pos
.y
= WorkArea
.top
+ ProcessParams
->dwY
;
1729 /* According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
1730 y is something else */
1731 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
1736 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1738 if(!CalculatedDefPosSize
)
1740 IntCalcDefPosSize(ParentWindow
, WindowObject
, &rc
, FALSE
);
1742 if(ProcessParams
->dwFlags
& STARTF_USESIZE
)
1744 ProcessParams
->dwFlags
&= ~STARTF_USESIZE
;
1745 Size
.cx
= ProcessParams
->dwXSize
;
1746 Size
.cy
= ProcessParams
->dwYSize
;
1750 Size
.cx
= rc
.right
- rc
.left
;
1751 Size
.cy
= rc
.bottom
- rc
.top
;
1754 /* move the window if necessary */
1756 Pos
.x
= max(rc
.left
, 0);
1758 Pos
.y
= max(rc
.top
, 0);
1763 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
1764 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1769 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1776 /* Initialize the window dimensions. */
1777 WindowObject
->WindowRect
.left
= Pos
.x
;
1778 WindowObject
->WindowRect
.top
= Pos
.y
;
1779 WindowObject
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1780 WindowObject
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1781 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1783 NtGdiOffsetRect(&(WindowObject
->WindowRect
), ParentWindow
->ClientRect
.left
,
1784 ParentWindow
->ClientRect
.top
);
1786 WindowObject
->ClientRect
= WindowObject
->WindowRect
;
1789 * Get the size and position of the window.
1791 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
1793 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1795 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
1796 WinPosGetMinMaxInfo(WindowObject
, &MaxSize
, &MaxPos
, &MinTrack
,
1798 if (MaxSize
.x
< nWidth
) nWidth
= MaxSize
.x
;
1799 if (MaxSize
.y
< nHeight
) nHeight
= MaxSize
.y
;
1800 if (nWidth
< MinTrack
.x
) nWidth
= MinTrack
.x
;
1801 if (nHeight
< MinTrack
.y
) nHeight
= MinTrack
.y
;
1802 if (nWidth
< 0) nWidth
= 0;
1803 if (nHeight
< 0) nHeight
= 0;
1806 WindowObject
->WindowRect
.left
= Pos
.x
;
1807 WindowObject
->WindowRect
.top
= Pos
.y
;
1808 WindowObject
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1809 WindowObject
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1810 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1812 NtGdiOffsetRect(&(WindowObject
->WindowRect
), ParentWindow
->ClientRect
.left
,
1813 ParentWindow
->ClientRect
.top
);
1815 WindowObject
->ClientRect
= WindowObject
->WindowRect
;
1817 /* FIXME: Initialize the window menu. */
1819 /* Send a NCCREATE message. */
1825 DPRINT("[win32k.window] NtUserCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
1826 DPRINT("NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1827 DPRINT("NtUserCreateWindowEx(): About to send NCCREATE message.\n");
1828 Result
= IntSendMessage(WindowObject
->Self
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
1831 /* FIXME: Cleanup. */
1832 if (NULL
!= ParentWindow
)
1834 IntReleaseWindowObject(ParentWindow
);
1836 DPRINT("NtUserCreateWindowEx(): NCCREATE message failed.\n");
1840 /* Calculate the non-client size. */
1841 MaxPos
.x
= WindowObject
->WindowRect
.left
;
1842 MaxPos
.y
= WindowObject
->WindowRect
.top
;
1843 DPRINT("NtUserCreateWindowEx(): About to get non-client size.\n");
1844 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
1845 Result
= WinPosGetNonClientSize(WindowObject
->Self
,
1846 &WindowObject
->WindowRect
,
1847 &WindowObject
->ClientRect
);
1848 NtGdiOffsetRect(&WindowObject
->WindowRect
,
1849 MaxPos
.x
- WindowObject
->WindowRect
.left
,
1850 MaxPos
.y
- WindowObject
->WindowRect
.top
);
1852 if (NULL
!= ParentWindow
)
1854 /* link the window into the parent's child list */
1855 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
1857 PWINDOW_OBJECT PrevSibling
;
1858 IntLockRelatives(ParentWindow
);
1859 if((PrevSibling
= ParentWindow
->LastChild
))
1860 IntReferenceWindowObject(PrevSibling
);
1861 IntUnLockRelatives(ParentWindow
);
1862 /* link window as bottom sibling */
1863 IntLinkWindow(WindowObject
, ParentWindow
, PrevSibling
/*prev sibling*/);
1865 IntReleaseWindowObject(PrevSibling
);
1869 /* link window as top sibling (but after topmost siblings) */
1870 PWINDOW_OBJECT InsertAfter
, Sibling
;
1871 if (0 == (dwExStyle
& WS_EX_TOPMOST
))
1873 IntLockRelatives(ParentWindow
);
1875 Sibling
= ParentWindow
->FirstChild
;
1876 while (NULL
!= Sibling
&& 0 != (Sibling
->ExStyle
& WS_EX_TOPMOST
))
1878 InsertAfter
= Sibling
;
1879 Sibling
= Sibling
->NextSibling
;
1881 IntUnLockRelatives(ParentWindow
);
1887 if (NULL
!= InsertAfter
)
1889 IntReferenceWindowObject(InsertAfter
);
1891 IntLinkWindow(WindowObject
, ParentWindow
, InsertAfter
/* prev sibling */);
1892 if (NULL
!= InsertAfter
)
1894 IntReleaseWindowObject(InsertAfter
);
1899 /* Send the WM_CREATE message. */
1900 DPRINT("NtUserCreateWindowEx(): about to send CREATE message.\n");
1901 Result
= IntSendMessage(WindowObject
->Self
, WM_CREATE
, 0, (LPARAM
) &Cs
);
1902 if (Result
== (LRESULT
)-1)
1904 /* FIXME: Cleanup. */
1905 if (NULL
!= ParentWindow
)
1907 IntReleaseWindowObject(ParentWindow
);
1909 DPRINT("NtUserCreateWindowEx(): send CREATE message failed.\n");
1913 /* Send move and size messages. */
1914 if (!(WindowObject
->Flags
& WINDOWOBJECT_NEED_SIZE
))
1918 DPRINT("NtUserCreateWindow(): About to send WM_SIZE\n");
1920 if ((WindowObject
->ClientRect
.right
- WindowObject
->ClientRect
.left
) < 0 ||
1921 (WindowObject
->ClientRect
.bottom
- WindowObject
->ClientRect
.top
) < 0)
1922 DPRINT("Sending bogus WM_SIZE\n");
1924 lParam
= MAKE_LONG(WindowObject
->ClientRect
.right
-
1925 WindowObject
->ClientRect
.left
,
1926 WindowObject
->ClientRect
.bottom
-
1927 WindowObject
->ClientRect
.top
);
1928 IntSendMessage(WindowObject
->Self
, WM_SIZE
, SIZE_RESTORED
,
1931 DPRINT("NtUserCreateWindow(): About to send WM_MOVE\n");
1933 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1935 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
- ParentWindow
->ClientRect
.left
,
1936 WindowObject
->ClientRect
.top
- ParentWindow
->ClientRect
.top
);
1940 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
,
1941 WindowObject
->ClientRect
.top
);
1943 IntSendMessage(WindowObject
->Self
, WM_MOVE
, 0, lParam
);
1946 /* Show or maybe minimize or maximize the window. */
1947 if (WindowObject
->Style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1952 SwFlag
= (WindowObject
->Style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
1954 WinPosMinMaximize(WindowObject
, SwFlag
, &NewPos
);
1956 ((WindowObject
->Style
& WS_CHILD
) || NtUserGetActiveWindow()) ?
1957 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
1958 SWP_NOZORDER
| SWP_FRAMECHANGED
;
1959 DPRINT("NtUserCreateWindow(): About to minimize/maximize\n");
1960 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
1961 WinPosSetWindowPos(WindowObject
->Self
, 0, NewPos
.left
, NewPos
.top
,
1962 NewPos
.right
, NewPos
.bottom
, SwFlag
);
1965 /* Notify the parent window of a new child. */
1966 if ((WindowObject
->Style
& WS_CHILD
) &&
1967 (!(WindowObject
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
1969 DPRINT("NtUserCreateWindow(): About to notify parent\n");
1970 IntSendMessage(ParentWindow
->Self
,
1972 MAKEWPARAM(WM_CREATE
, WindowObject
->IDMenu
),
1973 (LPARAM
)WindowObject
->Self
);
1976 if (NULL
!= ParentWindow
)
1978 IntReleaseWindowObject(ParentWindow
);
1981 /* Initialize and show the window's scrollbars */
1982 if (WindowObject
->Style
& WS_VSCROLL
)
1984 NtUserShowScrollBar(WindowObject
->Self
, SB_VERT
, TRUE
);
1986 if (WindowObject
->Style
& WS_HSCROLL
)
1988 NtUserShowScrollBar(WindowObject
->Self
, SB_HORZ
, TRUE
);
1991 if (dwStyle
& WS_VISIBLE
)
1993 DPRINT("NtUserCreateWindow(): About to show window\n");
1994 WinPosShowWindow(WindowObject
->Self
, dwShowMode
);
1997 DPRINT("NtUserCreateWindow(): = %X\n", Handle
);
1998 DPRINT("WindowObject->SystemMenu = 0x%x\n", WindowObject
->SystemMenu
);
1999 return((HWND
)Handle
);
2007 NtUserDeferWindowPos(HDWP WinPosInfo
,
2009 HWND WndInsertAfter
,
2026 NtUserDestroyWindow(HWND Wnd
)
2028 PWINDOW_OBJECT Window
;
2031 Window
= IntGetWindowObject(Wnd
);
2037 /* Check for owner thread and desktop window */
2038 if ((Window
->OwnerThread
!= PsGetCurrentThread()) || IntIsDesktopWindow(Window
))
2040 IntReleaseWindowObject(Window
);
2041 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2045 /* Look whether the focus is within the tree of windows we will
2048 if (!WinPosShowWindow(Wnd
, SW_HIDE
))
2050 if (NtUserGetActiveWindow() == Wnd
)
2052 WinPosActivateOtherWindow(Window
);
2055 IntLockMessageQueue(Window
->MessageQueue
);
2056 if (Window
->MessageQueue
->ActiveWindow
== Window
->Self
)
2057 Window
->MessageQueue
->ActiveWindow
= NULL
;
2058 if (Window
->MessageQueue
->FocusWindow
== Window
->Self
)
2059 Window
->MessageQueue
->FocusWindow
= NULL
;
2060 if (Window
->MessageQueue
->CaptureWindow
== Window
->Self
)
2061 Window
->MessageQueue
->CaptureWindow
= NULL
;
2062 IntUnLockMessageQueue(Window
->MessageQueue
);
2066 if (HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hwnd
, 0, TRUE
))
2072 isChild
= (0 != (Window
->Style
& WS_CHILD
));
2077 if (! USER_IsExitingThread(GetCurrentThreadId()))
2079 send_parent_notify(hwnd
, WM_DESTROY
);
2082 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2084 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2085 /* FIXME: clean up palette - see "Internals" p.352 */
2088 if (! IsWindow(Wnd
))
2094 if (!IntIsWindow(Wnd
))
2099 /* Recursively destroy owned windows */
2104 BOOL GotOne
= FALSE
;
2107 PWINDOW_OBJECT Child
, Desktop
;
2109 Desktop
= IntGetWindowObject(IntGetDesktopWindow());
2110 Children
= IntWinListChildren(Desktop
);
2111 IntReleaseWindowObject(Desktop
);
2114 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2116 Child
= IntGetWindowObject(*ChildHandle
);
2121 if(Child
->Self
== Wnd
)
2123 IntReleaseWindowObject(Child
);
2126 IntLockRelatives(Child
);
2127 if (Child
->Parent
!= Window
->Self
)
2129 IntUnLockRelatives(Child
);
2130 IntReleaseWindowObject(Child
);
2133 IntUnLockRelatives(Child
);
2134 if (IntWndBelongsToThread(Child
, PsGetWin32Thread()))
2136 IntReleaseWindowObject(Child
);
2137 NtUserDestroyWindow(*ChildHandle
);
2141 IntLockRelatives(Child
);
2142 if (Child
->Owner
!= NULL
)
2144 Child
->Owner
= NULL
;
2146 IntUnLockRelatives(Child
);
2147 IntReleaseWindowObject(Child
);
2149 ExFreePool(Children
);
2158 if (!IntIsWindow(Wnd
))
2160 IntReleaseWindowObject(Window
);
2164 /* Destroy the window storage */
2165 IntDestroyWindow(Window
, PsGetWin32Process(), PsGetWin32Thread(), TRUE
);
2167 IntReleaseWindowObject(Window
);
2177 NtUserDrawMenuBarTemp(
2184 /* we'll use this function just for caching the menu bar */
2194 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2207 NtUserFillWindow(DWORD Unknown0
,
2219 IntFindWindow(PWINDOW_OBJECT Parent
,
2220 PWINDOW_OBJECT ChildAfter
,
2221 PWNDCLASS_OBJECT ClassObject
,
2222 PUNICODE_STRING WindowName
)
2224 BOOL CheckWindowName
;
2230 CheckWindowName
= (WindowName
&& (WindowName
->Length
> 0));
2232 if((List
= IntWinListChildren(Parent
)))
2237 /* skip handles before and including ChildAfter */
2238 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->Self
));
2241 /* search children */
2244 PWINDOW_OBJECT Child
;
2245 if(!(Child
= IntGetWindowObject(*(phWnd
++))))
2250 /* Do not send WM_GETTEXT messages in the kernel mode version!
2251 The user mode version however calls GetWindowText() which will
2252 send WM_GETTEXT messages to windows belonging to its processes */
2253 if(((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(WindowName
, &(Child
->WindowName
), FALSE
))) &&
2254 (!ClassObject
|| (ClassObject
&& (Child
->Class
== ClassObject
))))
2256 ((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(WindowName
, &(Child
->WindowName
), FALSE
))) &&
2257 (!ClassObject
|| (ClassObject
&& (Child
->Class
== ClassObject
)))))
2260 IntReleaseWindowObject(Child
);
2264 IntReleaseWindowObject(Child
);
2274 * Searches a window's children for a window with the specified
2277 * hwndParent = The window whose childs are to be searched.
2279 * HWND_MESSAGE = message-only windows
2281 * hwndChildAfter = Search starts after this child window.
2282 * NULL = start from beginning
2284 * ucClassName = Class name to search for
2285 * Reguired parameter.
2287 * ucWindowName = Window name
2288 * ->Buffer == NULL = don't care
2291 * The HWND of the window if it was found, otherwise NULL
2297 NtUserFindWindowEx(HWND hwndParent
,
2298 HWND hwndChildAfter
,
2299 PUNICODE_STRING ucClassName
,
2300 PUNICODE_STRING ucWindowName
)
2302 PWINDOW_OBJECT Parent
, ChildAfter
;
2303 UNICODE_STRING ClassName
, WindowName
;
2305 HWND Desktop
, Ret
= NULL
;
2306 PWNDCLASS_OBJECT ClassObject
= NULL
;
2308 Desktop
= IntGetDesktopWindow();
2310 if(hwndParent
== NULL
)
2311 hwndParent
= Desktop
;
2313 else if(hwndParent == HWND_MESSAGE)
2315 hwndParent = IntGetMessageWindow();
2319 if(!(Parent
= IntGetWindowObject(hwndParent
)))
2321 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2326 if(hwndChildAfter
&& !(ChildAfter
= IntGetWindowObject(hwndChildAfter
)))
2328 IntReleaseWindowObject(hwndParent
);
2329 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2333 /* copy the window name */
2334 Status
= IntSafeCopyUnicodeString(&WindowName
, ucWindowName
);
2335 if(!NT_SUCCESS(Status
))
2337 SetLastNtError(Status
);
2341 /* safely copy the class name */
2342 Status
= MmCopyFromCaller(&ClassName
, ucClassName
, sizeof(UNICODE_STRING
));
2343 if(!NT_SUCCESS(Status
))
2345 SetLastNtError(Status
);
2348 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2351 /* safely copy the class name string (NULL terminated because class-lookup
2353 buf
= ExAllocatePoolWithTag(NonPagedPool
, ClassName
.Length
+ sizeof(WCHAR
), TAG_STRING
);
2356 SetLastWin32Error(STATUS_INSUFFICIENT_RESOURCES
);
2359 Status
= MmCopyFromCaller(buf
, ClassName
.Buffer
, ClassName
.Length
);
2360 if(!NT_SUCCESS(Status
))
2363 SetLastNtError(Status
);
2366 ClassName
.Buffer
= buf
;
2367 /* make sure the string is null-terminated */
2368 buf
+= ClassName
.Length
/ sizeof(WCHAR
);
2372 /* find the class object */
2373 if(ClassName
.Buffer
)
2375 /* this expects the string in ClassName to be NULL-terminated! */
2376 Status
= ClassReferenceClassByNameOrAtom(&ClassObject
, ClassName
.Buffer
);
2377 if(!NT_SUCCESS(Status
))
2379 if (IS_ATOM(ClassName
.Buffer
))
2380 DPRINT1("Window class not found (%lx)\n", (ULONG_PTR
)ClassName
.Buffer
);
2382 DPRINT1("Window class not found (%S)\n", ClassName
.Buffer
);
2383 /* windows returns ERROR_FILE_NOT_FOUND !? */
2384 SetLastWin32Error(ERROR_FILE_NOT_FOUND
);
2389 if(Parent
->Self
== Desktop
)
2392 PWINDOW_OBJECT TopLevelWindow
;
2393 BOOL CheckWindowName
;
2395 /* windows searches through all top-level windows if the parent is the desktop
2398 if((List
= IntWinListChildren(Parent
)))
2404 /* skip handles before and including ChildAfter */
2405 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->Self
));
2408 CheckWindowName
= WindowName
.Length
> 0;
2410 /* search children */
2413 if(!(TopLevelWindow
= IntGetWindowObject(*(phWnd
++))))
2418 /* Do not send WM_GETTEXT messages in the kernel mode version!
2419 The user mode version however calls GetWindowText() which will
2420 send WM_GETTEXT messages to windows belonging to its processes */
2421 if(((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(&WindowName
, &(TopLevelWindow
->WindowName
), FALSE
))) &&
2422 (!ClassObject
|| (ClassObject
&& (TopLevelWindow
->Class
== ClassObject
))))
2424 ((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(&WindowName
, &(TopLevelWindow
->WindowName
), FALSE
))) &&
2425 (!ClassObject
|| (ClassObject
&& (TopLevelWindow
->Class
== ClassObject
)))))
2427 Ret
= TopLevelWindow
->Self
;
2428 IntReleaseWindowObject(TopLevelWindow
);
2432 if(IntFindWindow(TopLevelWindow
, NULL
, ClassObject
, &WindowName
))
2434 /* window returns the handle of the top-level window, in case it found
2436 Ret
= TopLevelWindow
->Self
;
2437 IntReleaseWindowObject(TopLevelWindow
);
2441 IntReleaseWindowObject(TopLevelWindow
);
2447 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassObject
, &WindowName
);
2450 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2452 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2453 search the message-only windows. Should this also be done if
2454 Parent is the desktop window??? */
2455 PWINDOW_OBJECT MsgWindows
;
2457 if((MsgWindows
= IntGetWindowObject(IntGetMessageWindow())))
2459 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassObject
, &WindowName
);
2460 IntReleaseWindowObject(MsgWindows
);
2466 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2467 ExFreePool(ClassName
.Buffer
);
2470 RtlFreeUnicodeString(&WindowName
);
2474 IntReleaseWindowObject(ChildAfter
);
2475 IntReleaseWindowObject(Parent
);
2485 NtUserFlashWindowEx(DWORD Unknown0
)
2497 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2499 PWINDOW_OBJECT Wnd
, WndAncestor
, Parent
;
2502 if (hWnd
== IntGetDesktopWindow())
2507 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2509 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2517 WndAncestor
= IntGetParentObject(Wnd
);
2530 if(!(Parent
= IntGetParentObject(WndAncestor
)))
2534 if(IntIsDesktopWindow(Parent
))
2536 IntReleaseWindowObject(Parent
);
2540 IntReleaseWindowObject(tmp
);
2541 WndAncestor
= Parent
;
2549 IntReferenceWindowObject(WndAncestor
);
2554 Parent
= IntGetParent(WndAncestor
);
2555 IntReleaseWindowObject(Old
);
2560 WndAncestor
= Parent
;
2567 IntReleaseWindowObject(Wnd
);
2572 hWndAncestor
= (WndAncestor
? WndAncestor
->Self
: NULL
);
2573 IntReleaseWindowObject(Wnd
);
2575 if(WndAncestor
&& (WndAncestor
!= Wnd
))
2576 IntReleaseWindowObject(WndAncestor
);
2578 return hWndAncestor
;
2583 * Returns client window rectangle relative to the upper-left corner of client area.
2585 * \param hWnd window handle.
2586 * \param Rect pointer to the buffer where the coordinates are returned.
2593 NtUserGetClientRect(HWND hWnd
, LPRECT Rect
)
2595 PWINDOW_OBJECT WindowObject
;
2598 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
2600 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2604 IntGetClientRect(WindowObject
, &SafeRect
);
2605 IntReleaseWindowObject(WindowObject
);
2607 if(!NT_SUCCESS(MmCopyToCaller(Rect
, &SafeRect
, sizeof(RECT
))))
2619 NtUserGetDesktopWindow()
2621 return IntGetDesktopWindow();
2629 NtUserGetInternalWindowPos(DWORD Unknown0
,
2643 NtUserGetLastActivePopup(HWND hWnd
)
2646 * This code can't work, because hWndLastPopup member of WINDOW_OBJECT is
2647 * not changed anywhere.
2648 * -- Filip, 01/nov/2003
2654 IntAcquireWinLockShared();
2656 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2658 IntReleaseWinLock();
2659 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2663 hWndLastPopup
= Wnd
->hWndLastPopup
;
2665 IntReleaseWinLock();
2667 return hWndLastPopup
;
2676 * The NtUserGetParent function retrieves a handle to the specified window's
2680 * Note that, despite its name, this function can return an owner window
2681 * instead of a parent window.
2688 NtUserGetParent(HWND hWnd
)
2690 PWINDOW_OBJECT Wnd
, WndParent
;
2691 HWND hWndParent
= NULL
;
2693 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2695 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2699 WndParent
= IntGetParent(Wnd
);
2702 hWndParent
= WndParent
->Self
;
2703 IntReleaseWindowObject(WndParent
);
2706 IntReleaseWindowObject(Wnd
);
2714 * The NtUserSetParent function changes the parent window of the specified
2718 * The new parent window and the child window must belong to the same
2719 * application. If the window identified by the hWndChild parameter is
2720 * visible, the system performs the appropriate redrawing and repainting.
2721 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
2722 * or WS_POPUP window styles of the window whose parent is being changed.
2729 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2731 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
2732 HWND hWndOldParent
= NULL
;
2734 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
2736 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2740 if (hWndChild
== IntGetDesktopWindow())
2742 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2748 if (!(WndParent
= IntGetWindowObject(hWndNewParent
)))
2750 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2756 if (!(WndParent
= IntGetWindowObject(IntGetDesktopWindow())))
2758 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2763 if (!(Wnd
= IntGetWindowObject(hWndChild
)))
2765 IntReleaseWindowObject(WndParent
);
2766 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2770 WndOldParent
= IntSetParent(Wnd
, WndParent
);
2774 hWndOldParent
= WndOldParent
->Self
;
2775 IntReleaseWindowObject(WndOldParent
);
2778 IntReleaseWindowObject(Wnd
);
2779 IntReleaseWindowObject(WndParent
);
2781 return hWndOldParent
;
2785 * NtUserGetShellWindow
2787 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
2794 NtUserGetShellWindow()
2796 PWINSTATION_OBJECT WinStaObject
;
2799 NTSTATUS Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
2804 if (!NT_SUCCESS(Status
))
2806 SetLastNtError(Status
);
2810 Ret
= (HWND
)WinStaObject
->ShellWindow
;
2812 ObDereferenceObject(WinStaObject
);
2817 * NtUserSetShellWindowEx
2819 * This is undocumented function to set global shell window. The global
2820 * shell window has special handling of window position.
2827 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
2829 PWINSTATION_OBJECT WinStaObject
;
2831 NTSTATUS Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
2836 if (!NT_SUCCESS(Status
))
2838 SetLastNtError(Status
);
2843 * Test if we are permitted to change the shell window.
2845 if (WinStaObject
->ShellWindow
)
2847 ObDereferenceObject(WinStaObject
);
2852 * Move shell window into background.
2854 if (hwndListView
&& hwndListView
!= hwndShell
)
2857 * Disabled for now to get Explorer working.
2858 * -- Filip, 01/nov/2003
2861 WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2864 if (NtUserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2866 ObDereferenceObject(WinStaObject
);
2871 if (NtUserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2873 ObDereferenceObject(WinStaObject
);
2877 WinPosSetWindowPos(hwndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2879 WinStaObject
->ShellWindow
= hwndShell
;
2880 WinStaObject
->ShellListView
= hwndListView
;
2882 ObDereferenceObject(WinStaObject
);
2887 * NtUserGetSystemMenu
2889 * The NtUserGetSystemMenu function allows the application to access the
2890 * window menu (also known as the system menu or the control menu) for
2891 * copying and modifying.
2895 * Handle to the window that will own a copy of the window menu.
2897 * Specifies the action to be taken. If this parameter is FALSE,
2898 * NtUserGetSystemMenu returns a handle to the copy of the window menu
2899 * currently in use. The copy is initially identical to the window menu
2900 * but it can be modified.
2901 * If this parameter is TRUE, GetSystemMenu resets the window menu back
2902 * to the default state. The previous window menu, if any, is destroyed.
2905 * If the bRevert parameter is FALSE, the return value is a handle to a
2906 * copy of the window menu. If the bRevert parameter is TRUE, the return
2914 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
2917 PWINDOW_OBJECT WindowObject
;
2918 PMENU_OBJECT MenuObject
;
2920 WindowObject
= IntGetWindowObject((HWND
)hWnd
);
2921 if (WindowObject
== NULL
)
2923 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2927 MenuObject
= IntGetSystemMenu(WindowObject
, bRevert
, FALSE
);
2930 Result
= MenuObject
->MenuInfo
.Self
;
2931 IntReleaseMenuObject(MenuObject
);
2934 IntReleaseWindowObject(WindowObject
);
2939 * NtUserSetSystemMenu
2946 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
2948 BOOL Result
= FALSE
;
2949 PWINDOW_OBJECT WindowObject
;
2950 PMENU_OBJECT MenuObject
;
2952 WindowObject
= IntGetWindowObject(hWnd
);
2955 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2962 * Assign new menu handle.
2964 MenuObject
= IntGetMenuObject(hMenu
);
2967 IntReleaseWindowObject(WindowObject
);
2968 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
2972 Result
= IntSetSystemMenu(WindowObject
, MenuObject
);
2974 IntReleaseMenuObject(MenuObject
);
2977 IntReleaseWindowObject(WindowObject
);
2985 * The NtUserGetWindow function retrieves a handle to a window that has the
2986 * specified relationship (Z order or owner) to the specified window.
2993 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
2995 PWINDOW_OBJECT WindowObject
, Parent
;
2996 HWND hWndResult
= NULL
;
2998 if (!(WindowObject
= IntGetWindowObject(hWnd
)))
3000 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3004 switch (Relationship
)
3007 if((Parent
= IntGetParentObject(WindowObject
)))
3009 IntLockRelatives(Parent
);
3010 if (Parent
->FirstChild
)
3011 hWndResult
= Parent
->FirstChild
->Self
;
3012 IntUnLockRelatives(Parent
);
3013 IntReleaseWindowObject(Parent
);
3018 if((Parent
= IntGetParentObject(WindowObject
)))
3020 IntLockRelatives(Parent
);
3021 if (Parent
->LastChild
)
3022 hWndResult
= Parent
->LastChild
->Self
;
3023 IntUnLockRelatives(Parent
);
3024 IntReleaseWindowObject(Parent
);
3029 IntLockRelatives(WindowObject
);
3030 if (WindowObject
->NextSibling
)
3031 hWndResult
= WindowObject
->NextSibling
->Self
;
3032 IntUnLockRelatives(WindowObject
);
3036 IntLockRelatives(WindowObject
);
3037 if (WindowObject
->PrevSibling
)
3038 hWndResult
= WindowObject
->PrevSibling
->Self
;
3039 IntUnLockRelatives(WindowObject
);
3043 IntLockRelatives(WindowObject
);
3044 if((Parent
= IntGetWindowObject(WindowObject
->Owner
)))
3046 hWndResult
= Parent
->Self
;
3047 IntReleaseWindowObject(Parent
);
3049 IntUnLockRelatives(WindowObject
);
3052 IntLockRelatives(WindowObject
);
3053 if (WindowObject
->FirstChild
)
3054 hWndResult
= WindowObject
->FirstChild
->Self
;
3055 IntUnLockRelatives(WindowObject
);
3059 IntReleaseWindowObject(WindowObject
);
3065 * NtUserGetWindowLong
3067 * The NtUserGetWindowLong function retrieves information about the specified
3068 * window. The function also retrieves the 32-bit (long) value at the
3069 * specified offset into the extra window memory.
3076 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3078 PWINDOW_OBJECT WindowObject
, Parent
;
3081 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3083 WindowObject
= IntGetWindowObject(hWnd
);
3084 if (WindowObject
== NULL
)
3086 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3091 * Only allow CSRSS to mess with the desktop window
3093 if (hWnd
== IntGetDesktopWindow()
3094 && WindowObject
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3096 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3100 if ((INT
)Index
>= 0)
3102 if ((Index
+ sizeof(LONG
)) > WindowObject
->ExtraDataSize
)
3104 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3107 Result
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
3114 Result
= WindowObject
->ExStyle
;
3118 Result
= WindowObject
->Style
;
3123 Result
= (LONG
) WindowObject
->WndProcA
;
3125 Result
= (LONG
) WindowObject
->WndProcW
;
3129 Result
= (LONG
) WindowObject
->Instance
;
3132 case GWL_HWNDPARENT
:
3133 IntLockRelatives(WindowObject
);
3134 Parent
= IntGetWindowObject(WindowObject
->Parent
);
3135 IntUnLockRelatives(WindowObject
);
3138 if (Parent
&& Parent
->Self
== IntGetDesktopWindow())
3139 Result
= (LONG
) NtUserGetWindow(WindowObject
->Self
, GW_OWNER
);
3141 Result
= (LONG
) Parent
->Self
;
3142 IntReleaseWindowObject(Parent
);
3147 Result
= (LONG
) WindowObject
->IDMenu
;
3151 Result
= WindowObject
->UserData
;
3155 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3156 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3162 IntReleaseWindowObject(WindowObject
);
3168 * NtUserSetWindowLong
3170 * The NtUserSetWindowLong function changes an attribute of the specified
3171 * window. The function also sets the 32-bit (long) value at the specified
3172 * offset into the extra window memory.
3179 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3181 PWINDOW_OBJECT WindowObject
, Parent
;
3182 PW32PROCESS Process
;
3183 PWINSTATION_OBJECT WindowStation
;
3187 if (hWnd
== IntGetDesktopWindow())
3189 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3193 WindowObject
= IntGetWindowObject(hWnd
);
3194 if (WindowObject
== NULL
)
3196 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3200 if ((INT
)Index
>= 0)
3202 if ((Index
+ sizeof(LONG
)) > WindowObject
->ExtraDataSize
)
3204 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3205 IntReleaseWindowObject(WindowObject
);
3208 OldValue
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
3209 *((LONG
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
3216 OldValue
= (LONG
) WindowObject
->ExStyle
;
3217 Style
.styleOld
= OldValue
;
3218 Style
.styleNew
= NewValue
;
3221 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3223 Process
= WindowObject
->OwnerThread
->ThreadsProcess
->Win32Process
;
3224 WindowStation
= Process
->WindowStation
;
3227 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3228 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3231 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3232 WindowObject
->ExStyle
= (DWORD
)Style
.styleNew
;
3233 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3237 OldValue
= (LONG
) WindowObject
->Style
;
3238 Style
.styleOld
= OldValue
;
3239 Style
.styleNew
= NewValue
;
3240 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3241 WindowObject
->Style
= (DWORD
)Style
.styleNew
;
3242 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3246 /* FIXME: should check if window belongs to current process */
3249 OldValue
= (LONG
) WindowObject
->WndProcA
;
3250 WindowObject
->WndProcA
= (WNDPROC
) NewValue
;
3251 WindowObject
->WndProcW
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,FALSE
);
3252 WindowObject
->Unicode
= FALSE
;
3256 OldValue
= (LONG
) WindowObject
->WndProcW
;
3257 WindowObject
->WndProcW
= (WNDPROC
) NewValue
;
3258 WindowObject
->WndProcA
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,TRUE
);
3259 WindowObject
->Unicode
= TRUE
;
3264 OldValue
= (LONG
) WindowObject
->Instance
;
3265 WindowObject
->Instance
= (HINSTANCE
) NewValue
;
3268 case GWL_HWNDPARENT
:
3269 Parent
= IntGetParentObject(WindowObject
);
3270 if (Parent
&& (Parent
->Self
== IntGetDesktopWindow()))
3271 OldValue
= (LONG
) IntSetOwner(WindowObject
->Self
, (HWND
) NewValue
);
3273 OldValue
= (LONG
) NtUserSetParent(WindowObject
->Self
, (HWND
) NewValue
);
3275 IntReleaseWindowObject(Parent
);
3279 OldValue
= (LONG
) WindowObject
->IDMenu
;
3280 WindowObject
->IDMenu
= (UINT
) NewValue
;
3284 OldValue
= WindowObject
->UserData
;
3285 WindowObject
->UserData
= NewValue
;
3289 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3290 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3296 IntReleaseWindowObject(WindowObject
);
3302 * NtUserSetWindowWord
3304 * Legacy function similar to NtUserSetWindowLong.
3311 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3313 PWINDOW_OBJECT WindowObject
;
3320 case GWL_HWNDPARENT
:
3321 return NtUserSetWindowLong(hWnd
, Index
, (UINT
)NewValue
, TRUE
);
3325 SetLastWin32Error(ERROR_INVALID_INDEX
);
3330 WindowObject
= IntGetWindowObject(hWnd
);
3331 if (WindowObject
== NULL
)
3333 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3337 if (Index
> WindowObject
->ExtraDataSize
- sizeof(WORD
))
3339 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3340 IntReleaseWindowObject(WindowObject
);
3344 OldValue
= *((WORD
*)(WindowObject
->ExtraData
+ Index
));
3345 *((WORD
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
3347 IntReleaseWindowObject(WindowObject
);
3356 NtUserGetWindowPlacement(HWND hWnd
,
3357 WINDOWPLACEMENT
*lpwndpl
)
3359 PWINDOW_OBJECT WindowObject
;
3360 PINTERNALPOS InternalPos
;
3362 WINDOWPLACEMENT Safepl
;
3365 WindowObject
= IntGetWindowObject(hWnd
);
3366 if (WindowObject
== NULL
)
3368 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3372 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3373 if(!NT_SUCCESS(Status
))
3375 SetLastNtError(Status
);
3376 IntReleaseWindowObject(WindowObject
);
3379 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3381 IntReleaseWindowObject(WindowObject
);
3386 Safepl
.showCmd
= ((WindowObject
->Flags
& WINDOWOBJECT_RESTOREMAX
) ? SW_MAXIMIZE
: SW_SHOWNORMAL
);
3388 Size
.x
= WindowObject
->WindowRect
.left
;
3389 Size
.y
= WindowObject
->WindowRect
.top
;
3390 InternalPos
= WinPosInitInternalPos(WindowObject
, &Size
,
3391 &WindowObject
->WindowRect
);
3394 Safepl
.rcNormalPosition
= InternalPos
->NormalRect
;
3395 Safepl
.ptMinPosition
= InternalPos
->IconPos
;
3396 Safepl
.ptMaxPosition
= InternalPos
->MaxPos
;
3400 IntReleaseWindowObject(WindowObject
);
3404 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3405 if(!NT_SUCCESS(Status
))
3407 SetLastNtError(Status
);
3408 IntReleaseWindowObject(WindowObject
);
3412 IntReleaseWindowObject(WindowObject
);
3418 * Return the dimension of the window in the screen coordinates.
3419 * \param hWnd window handle.
3420 * \param Rect pointer to the buffer where the coordinates are returned.
3426 NtUserGetWindowRect(HWND hWnd
, LPRECT Rect
)
3431 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3433 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3436 Status
= MmCopyToCaller(Rect
, &Wnd
->WindowRect
, sizeof(RECT
));
3437 if (!NT_SUCCESS(Status
))
3439 IntReleaseWindowObject(Wnd
);
3440 SetLastNtError(Status
);
3444 IntReleaseWindowObject(Wnd
);
3453 NtUserGetWindowThreadProcessId(HWND hWnd
, LPDWORD UnsafePid
)
3458 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3460 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3464 tid
= (DWORD
)IntGetWndThreadId(Wnd
);
3465 pid
= (DWORD
)IntGetWndProcessId(Wnd
);
3467 if (UnsafePid
) MmCopyToCaller(UnsafePid
, &pid
, sizeof(DWORD
));
3477 NtUserLockWindowUpdate(DWORD Unknown0
)
3497 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3498 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3499 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3503 QueryWindow based on KJK::Hyperion and James Tabor.
3505 0 = QWUniqueProcessId
3506 1 = QWUniqueThreadId
3507 4 = QWIsHung Implements IsHungAppWindow found
3510 9 = QWKillWindow When I called this with hWnd ==
3511 DesktopWindow, it shutdown the system
3518 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3520 PWINDOW_OBJECT Window
= IntGetWindowObject(hWnd
);
3525 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3531 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3532 Result
= (DWORD
)IntGetWndProcessId(Window
);
3535 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3536 Result
= (DWORD
)IntGetWndThreadId(Window
);
3539 case QUERY_WINDOW_ISHUNG
:
3540 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
3544 Result
= (DWORD
)NULL
;
3548 IntReleaseWindowObject(Window
);
3558 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3572 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3575 PLIST_ENTRY Current
;
3576 PREGISTERED_MESSAGE NewMsg
, RegMsg
;
3577 UINT Msg
= REGISTERED_MESSAGE_MIN
;
3578 UNICODE_STRING MessageName
;
3581 Status
= MmCopyFromCaller(&MessageName
, MessageNameUnsafe
, sizeof(UNICODE_STRING
));
3582 if (! NT_SUCCESS(Status
))
3584 SetLastNtError(Status
);
3588 NewMsg
= ExAllocatePoolWithTag(PagedPool
,
3589 sizeof(REGISTERED_MESSAGE
) +
3594 SetLastNtError(STATUS_NO_MEMORY
);
3598 Status
= MmCopyFromCaller(NewMsg
->MessageName
, MessageName
.Buffer
, MessageName
.Length
);
3599 if (! NT_SUCCESS(Status
))
3602 SetLastNtError(Status
);
3605 NewMsg
->MessageName
[MessageName
.Length
/ sizeof(WCHAR
)] = L
'\0';
3606 if (wcslen(NewMsg
->MessageName
) != MessageName
.Length
/ sizeof(WCHAR
))
3609 SetLastNtError(STATUS_INVALID_PARAMETER
);
3613 Current
= RegisteredMessageListHead
.Flink
;
3614 while (Current
!= &RegisteredMessageListHead
)
3616 RegMsg
= CONTAINING_RECORD(Current
, REGISTERED_MESSAGE
, ListEntry
);
3617 if (0 == wcscmp(NewMsg
->MessageName
, RegMsg
->MessageName
))
3623 Current
= Current
->Flink
;
3626 if (REGISTERED_MESSAGE_MAX
< Msg
)
3629 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
3633 InsertTailList(&RegisteredMessageListHead
, &(NewMsg
->ListEntry
));
3639 * - There's no need to call MmSafe*, because it should be done in kernel.
3640 * - The passed UNICODE_STRING is expected to be NULL-terminated.
3642 return (UINT
)IntAddAtom(MessageNameUnsafe
->Buffer
);
3651 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3664 NtUserSetInternalWindowPos(DWORD Unknown0
,
3680 NtUserSetLayeredWindowAttributes(DWORD Unknown0
,
3695 NtUserSetLogonNotifyWindow(DWORD Unknown0
)
3712 PWINDOW_OBJECT WindowObject
;
3715 WindowObject
= IntGetWindowObject((HWND
) Wnd
);
3716 if (NULL
== WindowObject
)
3718 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3722 if (! IntSetMenu(WindowObject
, Menu
, &Changed
))
3724 IntReleaseWindowObject(WindowObject
);
3728 IntReleaseWindowObject(WindowObject
);
3730 if (Changed
&& Repaint
)
3732 WinPosSetWindowPos(Wnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3733 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3744 NtUserSetWindowFNID(DWORD Unknown0
,
3758 NtUserSetWindowPlacement(HWND hWnd
,
3759 WINDOWPLACEMENT
*lpwndpl
)
3761 PWINDOW_OBJECT WindowObject
;
3762 WINDOWPLACEMENT Safepl
;
3765 WindowObject
= IntGetWindowObject(hWnd
);
3766 if (WindowObject
== NULL
)
3768 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3771 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3772 if(!NT_SUCCESS(Status
))
3774 SetLastNtError(Status
);
3775 IntReleaseWindowObject(WindowObject
);
3778 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3780 IntReleaseWindowObject(WindowObject
);
3784 if ((WindowObject
->Style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
3786 WinPosSetWindowPos(WindowObject
->Self
, NULL
,
3787 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
3788 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
3789 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
3790 SWP_NOZORDER
| SWP_NOACTIVATE
);
3793 /* FIXME - change window status */
3794 WinPosShowWindow(WindowObject
->Self
, Safepl
.showCmd
);
3796 if (WindowObject
->InternalPos
== NULL
)
3797 WindowObject
->InternalPos
= ExAllocatePoolWithTag(PagedPool
, sizeof(INTERNALPOS
), TAG_WININTLIST
);
3798 WindowObject
->InternalPos
->NormalRect
= Safepl
.rcNormalPosition
;
3799 WindowObject
->InternalPos
->IconPos
= Safepl
.ptMinPosition
;
3800 WindowObject
->InternalPos
->MaxPos
= Safepl
.ptMaxPosition
;
3802 IntReleaseWindowObject(WindowObject
);
3813 HWND hWndInsertAfter
,
3820 return WinPosSetWindowPos(hWnd
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
3825 IntGetWindowRgn(HWND hWnd
, HRGN hRgn
)
3828 PWINDOW_OBJECT WindowObject
;
3832 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
3834 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3839 IntReleaseWindowObject(WindowObject
);
3843 /* Create a new window region using the window rectangle */
3844 VisRgn
= UnsafeIntCreateRectRgnIndirect(&WindowObject
->WindowRect
);
3845 NtGdiOffsetRgn(VisRgn
, -WindowObject
->WindowRect
.left
, -WindowObject
->WindowRect
.top
);
3846 /* if there's a region assigned to the window, combine them both */
3847 if(WindowObject
->WindowRegion
&& !(WindowObject
->Style
& WS_MINIMIZE
))
3848 NtGdiCombineRgn(VisRgn
, VisRgn
, WindowObject
->WindowRegion
, RGN_AND
);
3849 /* Copy the region into hRgn */
3850 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
3852 if((pRgn
= RGNDATA_LockRgn(hRgn
)))
3854 Ret
= pRgn
->rdh
.iType
;
3855 RGNDATA_UnlockRgn(hRgn
);
3860 NtGdiDeleteObject(VisRgn
);
3862 IntReleaseWindowObject(WindowObject
);
3867 IntGetWindowRgnBox(HWND hWnd
, RECT
*Rect
)
3870 PWINDOW_OBJECT WindowObject
;
3874 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
3876 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3881 IntReleaseWindowObject(WindowObject
);
3885 /* Create a new window region using the window rectangle */
3886 VisRgn
= UnsafeIntCreateRectRgnIndirect(&WindowObject
->WindowRect
);
3887 NtGdiOffsetRgn(VisRgn
, -WindowObject
->WindowRect
.left
, -WindowObject
->WindowRect
.top
);
3888 /* if there's a region assigned to the window, combine them both */
3889 if(WindowObject
->WindowRegion
&& !(WindowObject
->Style
& WS_MINIMIZE
))
3890 NtGdiCombineRgn(VisRgn
, VisRgn
, WindowObject
->WindowRegion
, RGN_AND
);
3892 if((pRgn
= RGNDATA_LockRgn(VisRgn
)))
3894 Ret
= pRgn
->rdh
.iType
;
3895 *Rect
= pRgn
->rdh
.rcBound
;
3896 RGNDATA_UnlockRgn(VisRgn
);
3901 NtGdiDeleteObject(VisRgn
);
3903 IntReleaseWindowObject(WindowObject
);
3917 PWINDOW_OBJECT WindowObject
;
3919 WindowObject
= IntGetWindowObject(hWnd
);
3920 if (WindowObject
== NULL
)
3922 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3926 /* FIXME - Verify if hRgn is a valid handle!!!!
3927 Propably make this operation thread-safe, but maybe it's not necessary */
3929 if(WindowObject
->WindowRegion
)
3931 /* Delete no longer needed region handle */
3932 NtGdiDeleteObject(WindowObject
->WindowRegion
);
3934 WindowObject
->WindowRegion
= hRgn
;
3936 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
3940 IntRedrawWindow(WindowObject
, NULL
, NULL
, RDW_INVALIDATE
);
3943 IntReleaseWindowObject(WindowObject
);
3952 NtUserShowWindow(HWND hWnd
,
3955 return WinPosShowWindow(hWnd
, nCmdShow
);
3963 NtUserShowWindowAsync(DWORD Unknown0
,
3976 NtUserUpdateLayeredWindow(DWORD Unknown0
,
3996 NtUserValidateRect(HWND hWnd
, const RECT
* Rect
)
3998 return (VOID
)NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
4006 NtUserWindowFromPoint(LONG X
, LONG Y
)
4010 PWINDOW_OBJECT DesktopWindow
, Window
= NULL
;
4012 if ((DesktopWindow
= IntGetWindowObject(IntGetDesktopWindow())))
4019 Hit
= WinPosWindowFromPoint(DesktopWindow
, PsGetWin32Thread()->MessageQueue
, &pt
, &Window
);
4024 IntReleaseWindowObject(Window
);
4025 IntReleaseWindowObject(DesktopWindow
);
4029 IntReleaseWindowObject(DesktopWindow
);
4039 * Undocumented function that is called from DefWindowProc to set
4047 NtUserDefSetText(HWND WindowHandle
, PUNICODE_STRING WindowText
)
4049 PWINDOW_OBJECT WindowObject
;
4050 UNICODE_STRING SafeText
;
4053 WindowObject
= IntGetWindowObject(WindowHandle
);
4056 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4062 Status
= IntSafeCopyUnicodeString(&SafeText
, WindowText
);
4063 if(!NT_SUCCESS(Status
))
4065 SetLastNtError(Status
);
4066 IntReleaseWindowObject(WindowObject
);
4072 RtlInitUnicodeString(&SafeText
, NULL
);
4075 /* FIXME - do this thread-safe! otherwise one could crash here! */
4076 RtlFreeUnicodeString(&WindowObject
->WindowName
);
4078 WindowObject
->WindowName
= SafeText
;
4080 IntReleaseWindowObject(WindowObject
);
4085 * NtUserInternalGetWindowText
4092 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4094 PWINDOW_OBJECT WindowObject
;
4098 if(lpString
&& (nMaxCount
<= 1))
4100 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4104 WindowObject
= IntGetWindowObject(hWnd
);
4107 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4111 /* FIXME - do this thread-safe! otherwise one could crash here! */
4112 Result
= WindowObject
->WindowName
.Length
/ sizeof(WCHAR
);
4115 const WCHAR Terminator
= L
'\0';
4117 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4119 Copy
= min(nMaxCount
- 1, Result
);
4122 Status
= MmCopyToCaller(Buffer
, WindowObject
->WindowName
.Buffer
, Copy
* sizeof(WCHAR
));
4123 if(!NT_SUCCESS(Status
))
4125 SetLastNtError(Status
);
4126 IntReleaseWindowObject(WindowObject
);
4132 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4133 if(!NT_SUCCESS(Status
))
4135 SetLastNtError(Status
);
4136 IntReleaseWindowObject(WindowObject
);
4143 IntReleaseWindowObject(WindowObject
);
4148 NtUserDereferenceWndProcHandle(WNDPROC wpHandle
, WndProcHandle
*Data
)
4150 WndProcHandle Entry
;
4151 if (((DWORD
)wpHandle
& 0xFFFF0000) == 0xFFFF0000)
4153 Entry
= WndProcHandlesArray
[(DWORD
)wpHandle
& 0x0000FFFF];
4154 Data
->WindowProc
= Entry
.WindowProc
;
4155 Data
->IsUnicode
= Entry
.IsUnicode
;
4156 Data
->ProcessID
= Entry
.ProcessID
;
4165 IntAddWndProcHandle(WNDPROC WindowProc
, BOOL IsUnicode
)
4170 WndProcHandle
*OldArray
;
4173 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4175 if (WndProcHandlesArray
[i
].WindowProc
== NULL
)
4183 OldArray
= WndProcHandlesArray
;
4184 OldArraySize
= WndProcHandlesArraySize
;
4185 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,(OldArraySize
+ WPH_SIZE
) * sizeof(WndProcHandle
), TAG_WINPROCLST
);
4186 WndProcHandlesArraySize
= OldArraySize
+ WPH_SIZE
;
4187 RtlCopyMemory(WndProcHandlesArray
,OldArray
,OldArraySize
* sizeof(WndProcHandle
));
4188 ExFreePool(OldArray
);
4189 FreeSpot
= OldArraySize
+ 1;
4191 WndProcHandlesArray
[FreeSpot
].WindowProc
= WindowProc
;
4192 WndProcHandlesArray
[FreeSpot
].IsUnicode
= IsUnicode
;
4193 WndProcHandlesArray
[FreeSpot
].ProcessID
= PsGetCurrentProcessId();
4194 return FreeSpot
+ 0xFFFF0000;
4198 IntRemoveWndProcHandle(WNDPROC Handle
)
4201 position
= (DWORD
)Handle
& 0x0000FFFF;
4202 if (position
> WndProcHandlesArraySize
)
4206 WndProcHandlesArray
[position
].WindowProc
= NULL
;
4207 WndProcHandlesArray
[position
].IsUnicode
= FALSE
;
4208 WndProcHandlesArray
[position
].ProcessID
= NULL
;
4213 IntRemoveProcessWndProcHandles(HANDLE ProcessID
)
4216 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4218 if (WndProcHandlesArray
[i
].ProcessID
== ProcessID
)
4220 WndProcHandlesArray
[i
].WindowProc
= NULL
;
4221 WndProcHandlesArray
[i
].IsUnicode
= FALSE
;
4222 WndProcHandlesArray
[i
].ProcessID
= NULL
;