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.235 2004/05/19 19:16:47 weiden 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
;
1417 LPWSTR OrigWindowName
= NULL
;
1419 DPRINT("NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1421 /* safely copy the window name */
1424 Status
= MmCopyFromCaller(&WindowName
, lpWindowName
, sizeof(UNICODE_STRING
));
1425 if (!NT_SUCCESS(Status
))
1427 SetLastNtError(Status
);
1430 if(WindowName
.Buffer
)
1432 /* safe the original pointer to the window name */
1433 OrigWindowName
= WindowName
.Buffer
;
1435 if(!(WindowName
.Buffer
= ExAllocatePoolWithTag(NonPagedPool
, WindowName
.MaximumLength
, TAG_STRING
)))
1437 SetLastNtError(STATUS_NO_MEMORY
);
1441 Status
= MmCopyFromCaller(WindowName
.Buffer
, OrigWindowName
, WindowName
.MaximumLength
);
1442 if(!NT_SUCCESS(Status
))
1444 ExFreePool(WindowName
.Buffer
);
1445 SetLastNtError(Status
);
1450 if(!WindowName
.Buffer
)
1451 RtlInitUnicodeString(&WindowName
, NULL
);
1454 RtlInitUnicodeString(&WindowName
, NULL
);
1456 ParentWindowHandle
= PsGetWin32Thread()->Desktop
->DesktopWindow
;
1457 OwnerWindowHandle
= NULL
;
1459 if (hWndParent
== HWND_MESSAGE
)
1462 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1463 * message window (style: WS_POPUP|WS_DISABLED)
1467 else if (hWndParent
)
1469 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1470 ParentWindowHandle
= hWndParent
;
1472 OwnerWindowHandle
= NtUserGetAncestor(hWndParent
, GA_ROOT
);
1474 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1476 RtlFreeUnicodeString(&WindowName
);
1477 return (HWND
)0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1480 if (NULL
!= ParentWindowHandle
)
1482 ParentWindow
= IntGetWindowObject(ParentWindowHandle
);
1486 ParentWindow
= NULL
;
1489 /* FIXME: parent must belong to the current process */
1491 /* Check the class. */
1492 ClassFound
= ClassReferenceClassByNameOrAtom(&ClassObject
, lpClassName
->Buffer
, hInstance
);
1495 RtlFreeUnicodeString(&WindowName
);
1496 if (NULL
!= ParentWindow
)
1498 IntReleaseWindowObject(ParentWindow
);
1503 /* Check the window station. */
1504 DPRINT("IoGetCurrentProcess() %X\n", IoGetCurrentProcess());
1505 DPRINT("PROCESS_WINDOW_STATION %X\n", PROCESS_WINDOW_STATION());
1506 Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
1510 if (!NT_SUCCESS(Status
))
1512 ObmDereferenceObject(ClassObject
);
1513 RtlFreeUnicodeString(&WindowName
);
1514 if (NULL
!= ParentWindow
)
1516 IntReleaseWindowObject(ParentWindow
);
1518 DPRINT("Validation of window station handle (0x%X) failed\n",
1519 PROCESS_WINDOW_STATION());
1523 /* Create the window object. */
1524 WindowObject
= (PWINDOW_OBJECT
)
1525 ObmCreateObject(PsGetWin32Process()->WindowStation
->HandleTable
, &Handle
,
1526 otWindow
, sizeof(WINDOW_OBJECT
) + ClassObject
->cbWndExtra
1529 DPRINT("Created object with handle %X\n", Handle
);
1532 ObDereferenceObject(WinStaObject
);
1533 ObmDereferenceObject(ClassObject
);
1534 RtlFreeUnicodeString(&WindowName
);
1535 if (NULL
!= ParentWindow
)
1537 IntReleaseWindowObject(ParentWindow
);
1539 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1542 ObDereferenceObject(WinStaObject
);
1544 if (NULL
== PsGetWin32Thread()->Desktop
->DesktopWindow
)
1546 /* If there is no desktop window yet, we must be creating it */
1547 PsGetWin32Thread()->Desktop
->DesktopWindow
= Handle
;
1551 * Fill out the structure describing it.
1553 WindowObject
->Class
= ClassObject
;
1554 WindowObject
->ExStyle
= dwExStyle
;
1555 WindowObject
->Style
= dwStyle
& ~WS_VISIBLE
;
1556 DPRINT("1: Style is now %lx\n", WindowObject
->Style
);
1558 WindowObject
->SystemMenu
= (HMENU
)0;
1559 WindowObject
->ContextHelpId
= 0;
1560 WindowObject
->IDMenu
= 0;
1561 WindowObject
->Instance
= hInstance
;
1562 WindowObject
->Self
= Handle
;
1563 if (0 != (dwStyle
& WS_CHILD
))
1565 WindowObject
->IDMenu
= (UINT
) hMenu
;
1569 IntSetMenu(WindowObject
, hMenu
, &MenuChanged
);
1571 WindowObject
->MessageQueue
= PsGetWin32Thread()->MessageQueue
;
1572 WindowObject
->Parent
= (ParentWindow
? ParentWindow
->Self
: NULL
);
1573 if((OwnerWindow
= IntGetWindowObject(OwnerWindowHandle
)))
1575 WindowObject
->Owner
= OwnerWindowHandle
;
1576 IntReleaseWindowObject(OwnerWindow
);
1579 WindowObject
->Owner
= NULL
;
1580 WindowObject
->UserData
= 0;
1581 if ((((DWORD
)ClassObject
->lpfnWndProcA
& 0xFFFF0000) != 0xFFFF0000)
1582 && (((DWORD
)ClassObject
->lpfnWndProcW
& 0xFFFF0000) != 0xFFFF0000))
1584 WindowObject
->Unicode
= bUnicodeWindow
;
1588 WindowObject
->Unicode
= ClassObject
->Unicode
;
1590 WindowObject
->WndProcA
= ClassObject
->lpfnWndProcA
;
1591 WindowObject
->WndProcW
= ClassObject
->lpfnWndProcW
;
1592 WindowObject
->OwnerThread
= PsGetCurrentThread();
1593 WindowObject
->FirstChild
= NULL
;
1594 WindowObject
->LastChild
= NULL
;
1595 WindowObject
->PrevSibling
= NULL
;
1596 WindowObject
->NextSibling
= NULL
;
1598 /* extra window data */
1599 if (ClassObject
->cbWndExtra
!= 0)
1601 WindowObject
->ExtraData
= (PCHAR
)(WindowObject
+ 1);
1602 WindowObject
->ExtraDataSize
= ClassObject
->cbWndExtra
;
1603 RtlZeroMemory(WindowObject
->ExtraData
, WindowObject
->ExtraDataSize
);
1607 WindowObject
->ExtraData
= NULL
;
1608 WindowObject
->ExtraDataSize
= 0;
1611 InitializeListHead(&WindowObject
->PropListHead
);
1612 ExInitializeFastMutex(&WindowObject
->PropListLock
);
1613 ExInitializeFastMutex(&WindowObject
->RelativesLock
);
1614 ExInitializeFastMutex(&WindowObject
->UpdateLock
);
1616 WindowObject
->WindowName
= WindowName
;
1618 /* Correct the window style. */
1619 if (!(dwStyle
& WS_CHILD
))
1621 WindowObject
->Style
|= WS_CLIPSIBLINGS
;
1622 DPRINT("3: Style is now %lx\n", WindowObject
->Style
);
1623 if (!(dwStyle
& WS_POPUP
))
1625 WindowObject
->Style
|= WS_CAPTION
;
1626 WindowObject
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1627 DPRINT("4: Style is now %lx\n", WindowObject
->Style
);
1628 /* FIXME: Note the window needs a size. */
1632 if(!(WindowObject
->Style
& (WS_POPUP
| WS_CHILD
)))
1634 /* Automatically assign the caption and border style. Also always
1635 clip siblings for overlapped windows. */
1636 WindowObject
->Style
|= (WS_CAPTION
| WS_BORDER
| WS_CLIPSIBLINGS
);
1639 /* create system menu */
1640 if((WindowObject
->Style
& WS_SYSMENU
) && (WindowObject
->Style
& WS_CAPTION
))
1642 SystemMenu
= IntGetSystemMenu(WindowObject
, TRUE
, TRUE
);
1645 WindowObject
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1646 IntReleaseMenuObject(SystemMenu
);
1650 /* Insert the window into the thread's window list. */
1651 IntLockThreadWindows(PsGetWin32Thread());
1652 InsertTailList (&PsGetWin32Thread()->WindowListHead
,
1653 &WindowObject
->ThreadListEntry
);
1654 IntUnLockThreadWindows(PsGetWin32Thread());
1656 /* Allocate a DCE for this window. */
1657 if (dwStyle
& CS_OWNDC
)
1659 WindowObject
->Dce
= DceAllocDCE(WindowObject
->Self
, DCE_WINDOW_DC
);
1661 /* FIXME: Handle "CS_CLASSDC" */
1669 Cs
.lpCreateParams
= lpParam
;
1670 Cs
.hInstance
= hInstance
;
1672 Cs
.hwndParent
= ParentWindowHandle
;
1678 Cs
.lpszName
= OrigWindowName
; /* pass the original pointer to usermode! */
1679 Cs
.lpszClass
= lpClassName
->Buffer
;
1680 Cs
.dwExStyle
= dwExStyle
;
1681 CbtCreate
.lpcs
= &Cs
;
1682 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1683 if (HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) Handle
, (LPARAM
) &CbtCreate
))
1685 if (NULL
!= ParentWindow
)
1687 IntReleaseWindowObject(ParentWindow
);
1690 /* FIXME - Delete window object and remove it from the thread windows list */
1691 /* FIXME - delete allocated DCE */
1693 DPRINT1("CBT-hook returned !0\n");
1702 /* default positioning for overlapped windows */
1703 if(!(WindowObject
->Style
& (WS_POPUP
| WS_CHILD
)))
1706 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1707 BOOL CalculatedDefPosSize
= FALSE
;
1709 IntGetDesktopWorkArea(WindowObject
->OwnerThread
->Win32Thread
->Desktop
, &WorkArea
);
1712 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1714 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1716 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, WindowObject
, &rc
, TRUE
);
1718 if(ProcessParams
->dwFlags
& STARTF_USEPOSITION
)
1720 ProcessParams
->dwFlags
&= ~STARTF_USEPOSITION
;
1721 Pos
.x
= WorkArea
.left
+ ProcessParams
->dwX
;
1722 Pos
.y
= WorkArea
.top
+ ProcessParams
->dwY
;
1730 /* According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
1731 y is something else */
1732 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
1737 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1739 if(!CalculatedDefPosSize
)
1741 IntCalcDefPosSize(ParentWindow
, WindowObject
, &rc
, FALSE
);
1743 if(ProcessParams
->dwFlags
& STARTF_USESIZE
)
1745 ProcessParams
->dwFlags
&= ~STARTF_USESIZE
;
1746 Size
.cx
= ProcessParams
->dwXSize
;
1747 Size
.cy
= ProcessParams
->dwYSize
;
1751 Size
.cx
= rc
.right
- rc
.left
;
1752 Size
.cy
= rc
.bottom
- rc
.top
;
1755 /* move the window if necessary */
1757 Pos
.x
= max(rc
.left
, 0);
1759 Pos
.y
= max(rc
.top
, 0);
1764 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
1765 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1770 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1777 /* Initialize the window dimensions. */
1778 WindowObject
->WindowRect
.left
= Pos
.x
;
1779 WindowObject
->WindowRect
.top
= Pos
.y
;
1780 WindowObject
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1781 WindowObject
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1782 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1784 NtGdiOffsetRect(&(WindowObject
->WindowRect
), ParentWindow
->ClientRect
.left
,
1785 ParentWindow
->ClientRect
.top
);
1787 WindowObject
->ClientRect
= WindowObject
->WindowRect
;
1790 * Get the size and position of the window.
1792 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
1794 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1796 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
1797 WinPosGetMinMaxInfo(WindowObject
, &MaxSize
, &MaxPos
, &MinTrack
,
1799 if (MaxSize
.x
< nWidth
) nWidth
= MaxSize
.x
;
1800 if (MaxSize
.y
< nHeight
) nHeight
= MaxSize
.y
;
1801 if (nWidth
< MinTrack
.x
) nWidth
= MinTrack
.x
;
1802 if (nHeight
< MinTrack
.y
) nHeight
= MinTrack
.y
;
1803 if (nWidth
< 0) nWidth
= 0;
1804 if (nHeight
< 0) nHeight
= 0;
1807 WindowObject
->WindowRect
.left
= Pos
.x
;
1808 WindowObject
->WindowRect
.top
= Pos
.y
;
1809 WindowObject
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1810 WindowObject
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1811 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1813 NtGdiOffsetRect(&(WindowObject
->WindowRect
), ParentWindow
->ClientRect
.left
,
1814 ParentWindow
->ClientRect
.top
);
1816 WindowObject
->ClientRect
= WindowObject
->WindowRect
;
1818 /* FIXME: Initialize the window menu. */
1820 /* Send a NCCREATE message. */
1826 DPRINT("[win32k.window] NtUserCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
1827 DPRINT("NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1828 DPRINT("NtUserCreateWindowEx(): About to send NCCREATE message.\n");
1829 Result
= IntSendMessage(WindowObject
->Self
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
1832 /* FIXME: Cleanup. */
1833 if (NULL
!= ParentWindow
)
1835 IntReleaseWindowObject(ParentWindow
);
1837 DPRINT("NtUserCreateWindowEx(): NCCREATE message failed.\n");
1841 /* Calculate the non-client size. */
1842 MaxPos
.x
= WindowObject
->WindowRect
.left
;
1843 MaxPos
.y
= WindowObject
->WindowRect
.top
;
1844 DPRINT("NtUserCreateWindowEx(): About to get non-client size.\n");
1845 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
1846 Result
= WinPosGetNonClientSize(WindowObject
->Self
,
1847 &WindowObject
->WindowRect
,
1848 &WindowObject
->ClientRect
);
1849 NtGdiOffsetRect(&WindowObject
->WindowRect
,
1850 MaxPos
.x
- WindowObject
->WindowRect
.left
,
1851 MaxPos
.y
- WindowObject
->WindowRect
.top
);
1853 if (NULL
!= ParentWindow
)
1855 /* link the window into the parent's child list */
1856 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
1858 PWINDOW_OBJECT PrevSibling
;
1859 IntLockRelatives(ParentWindow
);
1860 if((PrevSibling
= ParentWindow
->LastChild
))
1861 IntReferenceWindowObject(PrevSibling
);
1862 IntUnLockRelatives(ParentWindow
);
1863 /* link window as bottom sibling */
1864 IntLinkWindow(WindowObject
, ParentWindow
, PrevSibling
/*prev sibling*/);
1866 IntReleaseWindowObject(PrevSibling
);
1870 /* link window as top sibling (but after topmost siblings) */
1871 PWINDOW_OBJECT InsertAfter
, Sibling
;
1872 if (0 == (dwExStyle
& WS_EX_TOPMOST
))
1874 IntLockRelatives(ParentWindow
);
1876 Sibling
= ParentWindow
->FirstChild
;
1877 while (NULL
!= Sibling
&& 0 != (Sibling
->ExStyle
& WS_EX_TOPMOST
))
1879 InsertAfter
= Sibling
;
1880 Sibling
= Sibling
->NextSibling
;
1882 IntUnLockRelatives(ParentWindow
);
1888 if (NULL
!= InsertAfter
)
1890 IntReferenceWindowObject(InsertAfter
);
1892 IntLinkWindow(WindowObject
, ParentWindow
, InsertAfter
/* prev sibling */);
1893 if (NULL
!= InsertAfter
)
1895 IntReleaseWindowObject(InsertAfter
);
1900 /* Send the WM_CREATE message. */
1901 DPRINT("NtUserCreateWindowEx(): about to send CREATE message.\n");
1902 Result
= IntSendMessage(WindowObject
->Self
, WM_CREATE
, 0, (LPARAM
) &Cs
);
1903 if (Result
== (LRESULT
)-1)
1905 /* FIXME: Cleanup. */
1906 if (NULL
!= ParentWindow
)
1908 IntReleaseWindowObject(ParentWindow
);
1910 DPRINT("NtUserCreateWindowEx(): send CREATE message failed.\n");
1914 /* Send move and size messages. */
1915 if (!(WindowObject
->Flags
& WINDOWOBJECT_NEED_SIZE
))
1919 DPRINT("NtUserCreateWindow(): About to send WM_SIZE\n");
1921 if ((WindowObject
->ClientRect
.right
- WindowObject
->ClientRect
.left
) < 0 ||
1922 (WindowObject
->ClientRect
.bottom
- WindowObject
->ClientRect
.top
) < 0)
1923 DPRINT("Sending bogus WM_SIZE\n");
1925 lParam
= MAKE_LONG(WindowObject
->ClientRect
.right
-
1926 WindowObject
->ClientRect
.left
,
1927 WindowObject
->ClientRect
.bottom
-
1928 WindowObject
->ClientRect
.top
);
1929 IntSendMessage(WindowObject
->Self
, WM_SIZE
, SIZE_RESTORED
,
1932 DPRINT("NtUserCreateWindow(): About to send WM_MOVE\n");
1934 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1936 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
- ParentWindow
->ClientRect
.left
,
1937 WindowObject
->ClientRect
.top
- ParentWindow
->ClientRect
.top
);
1941 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
,
1942 WindowObject
->ClientRect
.top
);
1944 IntSendMessage(WindowObject
->Self
, WM_MOVE
, 0, lParam
);
1947 /* Show or maybe minimize or maximize the window. */
1948 if (WindowObject
->Style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1953 SwFlag
= (WindowObject
->Style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
1955 WinPosMinMaximize(WindowObject
, SwFlag
, &NewPos
);
1957 ((WindowObject
->Style
& WS_CHILD
) || NtUserGetActiveWindow()) ?
1958 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
1959 SWP_NOZORDER
| SWP_FRAMECHANGED
;
1960 DPRINT("NtUserCreateWindow(): About to minimize/maximize\n");
1961 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
1962 WinPosSetWindowPos(WindowObject
->Self
, 0, NewPos
.left
, NewPos
.top
,
1963 NewPos
.right
, NewPos
.bottom
, SwFlag
);
1966 /* Notify the parent window of a new child. */
1967 if ((WindowObject
->Style
& WS_CHILD
) &&
1968 (!(WindowObject
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
1970 DPRINT("NtUserCreateWindow(): About to notify parent\n");
1971 IntSendMessage(ParentWindow
->Self
,
1973 MAKEWPARAM(WM_CREATE
, WindowObject
->IDMenu
),
1974 (LPARAM
)WindowObject
->Self
);
1977 if (NULL
!= ParentWindow
)
1979 IntReleaseWindowObject(ParentWindow
);
1982 /* Initialize and show the window's scrollbars */
1983 if (WindowObject
->Style
& WS_VSCROLL
)
1985 NtUserShowScrollBar(WindowObject
->Self
, SB_VERT
, TRUE
);
1987 if (WindowObject
->Style
& WS_HSCROLL
)
1989 NtUserShowScrollBar(WindowObject
->Self
, SB_HORZ
, TRUE
);
1992 if (dwStyle
& WS_VISIBLE
)
1994 DPRINT("NtUserCreateWindow(): About to show window\n");
1995 WinPosShowWindow(WindowObject
->Self
, dwShowMode
);
1998 DPRINT("NtUserCreateWindow(): = %X\n", Handle
);
1999 DPRINT("WindowObject->SystemMenu = 0x%x\n", WindowObject
->SystemMenu
);
2000 return((HWND
)Handle
);
2008 NtUserDeferWindowPos(HDWP WinPosInfo
,
2010 HWND WndInsertAfter
,
2027 NtUserDestroyWindow(HWND Wnd
)
2029 PWINDOW_OBJECT Window
;
2032 Window
= IntGetWindowObject(Wnd
);
2038 /* Check for owner thread and desktop window */
2039 if ((Window
->OwnerThread
!= PsGetCurrentThread()) || IntIsDesktopWindow(Window
))
2041 IntReleaseWindowObject(Window
);
2042 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2046 /* Look whether the focus is within the tree of windows we will
2049 if (!WinPosShowWindow(Wnd
, SW_HIDE
))
2051 if (NtUserGetActiveWindow() == Wnd
)
2053 WinPosActivateOtherWindow(Window
);
2056 IntLockMessageQueue(Window
->MessageQueue
);
2057 if (Window
->MessageQueue
->ActiveWindow
== Window
->Self
)
2058 Window
->MessageQueue
->ActiveWindow
= NULL
;
2059 if (Window
->MessageQueue
->FocusWindow
== Window
->Self
)
2060 Window
->MessageQueue
->FocusWindow
= NULL
;
2061 if (Window
->MessageQueue
->CaptureWindow
== Window
->Self
)
2062 Window
->MessageQueue
->CaptureWindow
= NULL
;
2063 IntUnLockMessageQueue(Window
->MessageQueue
);
2067 if (HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hwnd
, 0, TRUE
))
2073 isChild
= (0 != (Window
->Style
& WS_CHILD
));
2078 if (! USER_IsExitingThread(GetCurrentThreadId()))
2080 send_parent_notify(hwnd
, WM_DESTROY
);
2083 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2085 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2086 /* FIXME: clean up palette - see "Internals" p.352 */
2089 if (! IsWindow(Wnd
))
2095 if (!IntIsWindow(Wnd
))
2100 /* Recursively destroy owned windows */
2105 BOOL GotOne
= FALSE
;
2108 PWINDOW_OBJECT Child
, Desktop
;
2110 Desktop
= IntGetWindowObject(IntGetDesktopWindow());
2111 Children
= IntWinListChildren(Desktop
);
2112 IntReleaseWindowObject(Desktop
);
2115 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2117 Child
= IntGetWindowObject(*ChildHandle
);
2122 if(Child
->Self
== Wnd
)
2124 IntReleaseWindowObject(Child
);
2127 IntLockRelatives(Child
);
2128 if (Child
->Parent
!= Window
->Self
)
2130 IntUnLockRelatives(Child
);
2131 IntReleaseWindowObject(Child
);
2134 IntUnLockRelatives(Child
);
2135 if (IntWndBelongsToThread(Child
, PsGetWin32Thread()))
2137 IntReleaseWindowObject(Child
);
2138 NtUserDestroyWindow(*ChildHandle
);
2142 IntLockRelatives(Child
);
2143 if (Child
->Owner
!= NULL
)
2145 Child
->Owner
= NULL
;
2147 IntUnLockRelatives(Child
);
2148 IntReleaseWindowObject(Child
);
2150 ExFreePool(Children
);
2159 if (!IntIsWindow(Wnd
))
2161 IntReleaseWindowObject(Window
);
2165 /* Destroy the window storage */
2166 IntDestroyWindow(Window
, PsGetWin32Process(), PsGetWin32Thread(), TRUE
);
2168 IntReleaseWindowObject(Window
);
2178 NtUserDrawMenuBarTemp(
2185 /* we'll use this function just for caching the menu bar */
2195 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2208 NtUserFillWindow(DWORD Unknown0
,
2220 IntFindWindow(PWINDOW_OBJECT Parent
,
2221 PWINDOW_OBJECT ChildAfter
,
2222 PWNDCLASS_OBJECT ClassObject
,
2223 PUNICODE_STRING WindowName
)
2225 BOOL CheckWindowName
;
2231 CheckWindowName
= (WindowName
&& (WindowName
->Length
> 0));
2233 if((List
= IntWinListChildren(Parent
)))
2238 /* skip handles before and including ChildAfter */
2239 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->Self
));
2242 /* search children */
2245 PWINDOW_OBJECT Child
;
2246 if(!(Child
= IntGetWindowObject(*(phWnd
++))))
2251 /* Do not send WM_GETTEXT messages in the kernel mode version!
2252 The user mode version however calls GetWindowText() which will
2253 send WM_GETTEXT messages to windows belonging to its processes */
2254 if(((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(WindowName
, &(Child
->WindowName
), FALSE
))) &&
2255 (!ClassObject
|| (ClassObject
&& (Child
->Class
== ClassObject
))))
2257 ((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(WindowName
, &(Child
->WindowName
), FALSE
))) &&
2258 (!ClassObject
|| (ClassObject
&& (Child
->Class
== ClassObject
)))))
2261 IntReleaseWindowObject(Child
);
2265 IntReleaseWindowObject(Child
);
2275 * Searches a window's children for a window with the specified
2278 * hwndParent = The window whose childs are to be searched.
2280 * HWND_MESSAGE = message-only windows
2282 * hwndChildAfter = Search starts after this child window.
2283 * NULL = start from beginning
2285 * ucClassName = Class name to search for
2286 * Reguired parameter.
2288 * ucWindowName = Window name
2289 * ->Buffer == NULL = don't care
2292 * The HWND of the window if it was found, otherwise NULL
2298 NtUserFindWindowEx(HWND hwndParent
,
2299 HWND hwndChildAfter
,
2300 PUNICODE_STRING ucClassName
,
2301 PUNICODE_STRING ucWindowName
)
2303 PWINDOW_OBJECT Parent
, ChildAfter
;
2304 UNICODE_STRING ClassName
, WindowName
;
2306 HWND Desktop
, Ret
= NULL
;
2307 PWNDCLASS_OBJECT ClassObject
= NULL
;
2310 Desktop
= IntGetDesktopWindow();
2312 if(hwndParent
== NULL
)
2313 hwndParent
= Desktop
;
2315 else if(hwndParent == HWND_MESSAGE)
2317 hwndParent = IntGetMessageWindow();
2321 if(!(Parent
= IntGetWindowObject(hwndParent
)))
2323 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2328 if(hwndChildAfter
&& !(ChildAfter
= IntGetWindowObject(hwndChildAfter
)))
2330 IntReleaseWindowObject(hwndParent
);
2331 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2335 /* copy the window name */
2336 Status
= IntSafeCopyUnicodeString(&WindowName
, ucWindowName
);
2337 if(!NT_SUCCESS(Status
))
2339 SetLastNtError(Status
);
2343 /* safely copy the class name */
2344 Status
= MmCopyFromCaller(&ClassName
, ucClassName
, sizeof(UNICODE_STRING
));
2345 if(!NT_SUCCESS(Status
))
2347 SetLastNtError(Status
);
2350 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2353 /* safely copy the class name string (NULL terminated because class-lookup
2355 buf
= ExAllocatePoolWithTag(NonPagedPool
, ClassName
.Length
+ sizeof(WCHAR
), TAG_STRING
);
2358 SetLastWin32Error(STATUS_INSUFFICIENT_RESOURCES
);
2361 Status
= MmCopyFromCaller(buf
, ClassName
.Buffer
, ClassName
.Length
);
2362 if(!NT_SUCCESS(Status
))
2365 SetLastNtError(Status
);
2368 ClassName
.Buffer
= buf
;
2369 /* make sure the string is null-terminated */
2370 buf
+= ClassName
.Length
/ sizeof(WCHAR
);
2374 /* find the class object */
2375 if(ClassName
.Buffer
)
2377 /* this expects the string in ClassName to be NULL-terminated! */
2378 ClassFound
= ClassReferenceClassByNameOrAtom(&ClassObject
, ClassName
.Buffer
, NULL
);
2381 if (IS_ATOM(ClassName
.Buffer
))
2382 DPRINT1("Window class not found (%lx)\n", (ULONG_PTR
)ClassName
.Buffer
);
2384 DPRINT1("Window class not found (%S)\n", ClassName
.Buffer
);
2385 SetLastWin32Error(ERROR_CLASS_DOES_NOT_EXIST
);
2390 if(Parent
->Self
== Desktop
)
2393 PWINDOW_OBJECT TopLevelWindow
;
2394 BOOL CheckWindowName
;
2396 /* windows searches through all top-level windows if the parent is the desktop
2399 if((List
= IntWinListChildren(Parent
)))
2405 /* skip handles before and including ChildAfter */
2406 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->Self
));
2409 CheckWindowName
= WindowName
.Length
> 0;
2411 /* search children */
2414 if(!(TopLevelWindow
= IntGetWindowObject(*(phWnd
++))))
2419 /* Do not send WM_GETTEXT messages in the kernel mode version!
2420 The user mode version however calls GetWindowText() which will
2421 send WM_GETTEXT messages to windows belonging to its processes */
2422 if(((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(&WindowName
, &(TopLevelWindow
->WindowName
), FALSE
))) &&
2423 (!ClassObject
|| (ClassObject
&& (TopLevelWindow
->Class
== ClassObject
))))
2425 ((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(&WindowName
, &(TopLevelWindow
->WindowName
), FALSE
))) &&
2426 (!ClassObject
|| (ClassObject
&& (TopLevelWindow
->Class
== ClassObject
)))))
2428 Ret
= TopLevelWindow
->Self
;
2429 IntReleaseWindowObject(TopLevelWindow
);
2433 if(IntFindWindow(TopLevelWindow
, NULL
, ClassObject
, &WindowName
))
2435 /* window returns the handle of the top-level window, in case it found
2437 Ret
= TopLevelWindow
->Self
;
2438 IntReleaseWindowObject(TopLevelWindow
);
2442 IntReleaseWindowObject(TopLevelWindow
);
2448 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassObject
, &WindowName
);
2451 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2453 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2454 search the message-only windows. Should this also be done if
2455 Parent is the desktop window??? */
2456 PWINDOW_OBJECT MsgWindows
;
2458 if((MsgWindows
= IntGetWindowObject(IntGetMessageWindow())))
2460 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassObject
, &WindowName
);
2461 IntReleaseWindowObject(MsgWindows
);
2467 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2468 ExFreePool(ClassName
.Buffer
);
2471 RtlFreeUnicodeString(&WindowName
);
2475 IntReleaseWindowObject(ChildAfter
);
2476 IntReleaseWindowObject(Parent
);
2486 NtUserFlashWindowEx(DWORD Unknown0
)
2498 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2500 PWINDOW_OBJECT Wnd
, WndAncestor
, Parent
;
2503 if (hWnd
== IntGetDesktopWindow())
2508 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2510 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2518 WndAncestor
= IntGetParentObject(Wnd
);
2531 if(!(Parent
= IntGetParentObject(WndAncestor
)))
2535 if(IntIsDesktopWindow(Parent
))
2537 IntReleaseWindowObject(Parent
);
2541 IntReleaseWindowObject(tmp
);
2542 WndAncestor
= Parent
;
2550 IntReferenceWindowObject(WndAncestor
);
2555 Parent
= IntGetParent(WndAncestor
);
2556 IntReleaseWindowObject(Old
);
2561 WndAncestor
= Parent
;
2568 IntReleaseWindowObject(Wnd
);
2573 hWndAncestor
= (WndAncestor
? WndAncestor
->Self
: NULL
);
2574 IntReleaseWindowObject(Wnd
);
2576 if(WndAncestor
&& (WndAncestor
!= Wnd
))
2577 IntReleaseWindowObject(WndAncestor
);
2579 return hWndAncestor
;
2584 * Returns client window rectangle relative to the upper-left corner of client area.
2586 * \param hWnd window handle.
2587 * \param Rect pointer to the buffer where the coordinates are returned.
2594 NtUserGetClientRect(HWND hWnd
, LPRECT Rect
)
2596 PWINDOW_OBJECT WindowObject
;
2599 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
2601 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2605 IntGetClientRect(WindowObject
, &SafeRect
);
2606 IntReleaseWindowObject(WindowObject
);
2608 if(!NT_SUCCESS(MmCopyToCaller(Rect
, &SafeRect
, sizeof(RECT
))))
2620 NtUserGetDesktopWindow()
2622 return IntGetDesktopWindow();
2630 NtUserGetInternalWindowPos(DWORD Unknown0
,
2644 NtUserGetLastActivePopup(HWND hWnd
)
2647 * This code can't work, because hWndLastPopup member of WINDOW_OBJECT is
2648 * not changed anywhere.
2649 * -- Filip, 01/nov/2003
2655 IntAcquireWinLockShared();
2657 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2659 IntReleaseWinLock();
2660 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2664 hWndLastPopup
= Wnd
->hWndLastPopup
;
2666 IntReleaseWinLock();
2668 return hWndLastPopup
;
2677 * The NtUserGetParent function retrieves a handle to the specified window's
2681 * Note that, despite its name, this function can return an owner window
2682 * instead of a parent window.
2689 NtUserGetParent(HWND hWnd
)
2691 PWINDOW_OBJECT Wnd
, WndParent
;
2692 HWND hWndParent
= NULL
;
2694 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2696 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2700 WndParent
= IntGetParent(Wnd
);
2703 hWndParent
= WndParent
->Self
;
2704 IntReleaseWindowObject(WndParent
);
2707 IntReleaseWindowObject(Wnd
);
2715 * The NtUserSetParent function changes the parent window of the specified
2719 * The new parent window and the child window must belong to the same
2720 * application. If the window identified by the hWndChild parameter is
2721 * visible, the system performs the appropriate redrawing and repainting.
2722 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
2723 * or WS_POPUP window styles of the window whose parent is being changed.
2730 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2732 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
2733 HWND hWndOldParent
= NULL
;
2735 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
2737 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2741 if (hWndChild
== IntGetDesktopWindow())
2743 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2749 if (!(WndParent
= IntGetWindowObject(hWndNewParent
)))
2751 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2757 if (!(WndParent
= IntGetWindowObject(IntGetDesktopWindow())))
2759 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2764 if (!(Wnd
= IntGetWindowObject(hWndChild
)))
2766 IntReleaseWindowObject(WndParent
);
2767 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2771 WndOldParent
= IntSetParent(Wnd
, WndParent
);
2775 hWndOldParent
= WndOldParent
->Self
;
2776 IntReleaseWindowObject(WndOldParent
);
2779 IntReleaseWindowObject(Wnd
);
2780 IntReleaseWindowObject(WndParent
);
2782 return hWndOldParent
;
2786 * NtUserGetShellWindow
2788 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
2795 NtUserGetShellWindow()
2797 PWINSTATION_OBJECT WinStaObject
;
2800 NTSTATUS Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
2805 if (!NT_SUCCESS(Status
))
2807 SetLastNtError(Status
);
2811 Ret
= (HWND
)WinStaObject
->ShellWindow
;
2813 ObDereferenceObject(WinStaObject
);
2818 * NtUserSetShellWindowEx
2820 * This is undocumented function to set global shell window. The global
2821 * shell window has special handling of window position.
2828 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
2830 PWINSTATION_OBJECT WinStaObject
;
2832 NTSTATUS Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
2837 if (!NT_SUCCESS(Status
))
2839 SetLastNtError(Status
);
2844 * Test if we are permitted to change the shell window.
2846 if (WinStaObject
->ShellWindow
)
2848 ObDereferenceObject(WinStaObject
);
2853 * Move shell window into background.
2855 if (hwndListView
&& hwndListView
!= hwndShell
)
2858 * Disabled for now to get Explorer working.
2859 * -- Filip, 01/nov/2003
2862 WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2865 if (NtUserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2867 ObDereferenceObject(WinStaObject
);
2872 if (NtUserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2874 ObDereferenceObject(WinStaObject
);
2878 WinPosSetWindowPos(hwndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2880 WinStaObject
->ShellWindow
= hwndShell
;
2881 WinStaObject
->ShellListView
= hwndListView
;
2883 ObDereferenceObject(WinStaObject
);
2888 * NtUserGetSystemMenu
2890 * The NtUserGetSystemMenu function allows the application to access the
2891 * window menu (also known as the system menu or the control menu) for
2892 * copying and modifying.
2896 * Handle to the window that will own a copy of the window menu.
2898 * Specifies the action to be taken. If this parameter is FALSE,
2899 * NtUserGetSystemMenu returns a handle to the copy of the window menu
2900 * currently in use. The copy is initially identical to the window menu
2901 * but it can be modified.
2902 * If this parameter is TRUE, GetSystemMenu resets the window menu back
2903 * to the default state. The previous window menu, if any, is destroyed.
2906 * If the bRevert parameter is FALSE, the return value is a handle to a
2907 * copy of the window menu. If the bRevert parameter is TRUE, the return
2915 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
2918 PWINDOW_OBJECT WindowObject
;
2919 PMENU_OBJECT MenuObject
;
2921 WindowObject
= IntGetWindowObject((HWND
)hWnd
);
2922 if (WindowObject
== NULL
)
2924 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2928 MenuObject
= IntGetSystemMenu(WindowObject
, bRevert
, FALSE
);
2931 Result
= MenuObject
->MenuInfo
.Self
;
2932 IntReleaseMenuObject(MenuObject
);
2935 IntReleaseWindowObject(WindowObject
);
2940 * NtUserSetSystemMenu
2947 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
2949 BOOL Result
= FALSE
;
2950 PWINDOW_OBJECT WindowObject
;
2951 PMENU_OBJECT MenuObject
;
2953 WindowObject
= IntGetWindowObject(hWnd
);
2956 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2963 * Assign new menu handle.
2965 MenuObject
= IntGetMenuObject(hMenu
);
2968 IntReleaseWindowObject(WindowObject
);
2969 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
2973 Result
= IntSetSystemMenu(WindowObject
, MenuObject
);
2975 IntReleaseMenuObject(MenuObject
);
2978 IntReleaseWindowObject(WindowObject
);
2986 * The NtUserGetWindow function retrieves a handle to a window that has the
2987 * specified relationship (Z order or owner) to the specified window.
2994 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
2996 PWINDOW_OBJECT WindowObject
, Parent
;
2997 HWND hWndResult
= NULL
;
2999 if (!(WindowObject
= IntGetWindowObject(hWnd
)))
3001 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3005 switch (Relationship
)
3008 if((Parent
= IntGetParentObject(WindowObject
)))
3010 IntLockRelatives(Parent
);
3011 if (Parent
->FirstChild
)
3012 hWndResult
= Parent
->FirstChild
->Self
;
3013 IntUnLockRelatives(Parent
);
3014 IntReleaseWindowObject(Parent
);
3019 if((Parent
= IntGetParentObject(WindowObject
)))
3021 IntLockRelatives(Parent
);
3022 if (Parent
->LastChild
)
3023 hWndResult
= Parent
->LastChild
->Self
;
3024 IntUnLockRelatives(Parent
);
3025 IntReleaseWindowObject(Parent
);
3030 IntLockRelatives(WindowObject
);
3031 if (WindowObject
->NextSibling
)
3032 hWndResult
= WindowObject
->NextSibling
->Self
;
3033 IntUnLockRelatives(WindowObject
);
3037 IntLockRelatives(WindowObject
);
3038 if (WindowObject
->PrevSibling
)
3039 hWndResult
= WindowObject
->PrevSibling
->Self
;
3040 IntUnLockRelatives(WindowObject
);
3044 IntLockRelatives(WindowObject
);
3045 if((Parent
= IntGetWindowObject(WindowObject
->Owner
)))
3047 hWndResult
= Parent
->Self
;
3048 IntReleaseWindowObject(Parent
);
3050 IntUnLockRelatives(WindowObject
);
3053 IntLockRelatives(WindowObject
);
3054 if (WindowObject
->FirstChild
)
3055 hWndResult
= WindowObject
->FirstChild
->Self
;
3056 IntUnLockRelatives(WindowObject
);
3060 IntReleaseWindowObject(WindowObject
);
3066 * NtUserGetWindowLong
3068 * The NtUserGetWindowLong function retrieves information about the specified
3069 * window. The function also retrieves the 32-bit (long) value at the
3070 * specified offset into the extra window memory.
3077 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3079 PWINDOW_OBJECT WindowObject
, Parent
;
3082 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3084 WindowObject
= IntGetWindowObject(hWnd
);
3085 if (WindowObject
== NULL
)
3087 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3092 * Only allow CSRSS to mess with the desktop window
3094 if (hWnd
== IntGetDesktopWindow()
3095 && WindowObject
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3097 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3101 if ((INT
)Index
>= 0)
3103 if ((Index
+ sizeof(LONG
)) > WindowObject
->ExtraDataSize
)
3105 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3108 Result
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
3115 Result
= WindowObject
->ExStyle
;
3119 Result
= WindowObject
->Style
;
3124 Result
= (LONG
) WindowObject
->WndProcA
;
3126 Result
= (LONG
) WindowObject
->WndProcW
;
3130 Result
= (LONG
) WindowObject
->Instance
;
3133 case GWL_HWNDPARENT
:
3134 IntLockRelatives(WindowObject
);
3135 Parent
= IntGetWindowObject(WindowObject
->Parent
);
3136 IntUnLockRelatives(WindowObject
);
3139 if (Parent
&& Parent
->Self
== IntGetDesktopWindow())
3140 Result
= (LONG
) NtUserGetWindow(WindowObject
->Self
, GW_OWNER
);
3142 Result
= (LONG
) Parent
->Self
;
3143 IntReleaseWindowObject(Parent
);
3148 Result
= (LONG
) WindowObject
->IDMenu
;
3152 Result
= WindowObject
->UserData
;
3156 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3157 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3163 IntReleaseWindowObject(WindowObject
);
3169 * NtUserSetWindowLong
3171 * The NtUserSetWindowLong function changes an attribute of the specified
3172 * window. The function also sets the 32-bit (long) value at the specified
3173 * offset into the extra window memory.
3180 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3182 PWINDOW_OBJECT WindowObject
, Parent
;
3183 PW32PROCESS Process
;
3184 PWINSTATION_OBJECT WindowStation
;
3188 if (hWnd
== IntGetDesktopWindow())
3190 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3194 WindowObject
= IntGetWindowObject(hWnd
);
3195 if (WindowObject
== NULL
)
3197 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3201 if ((INT
)Index
>= 0)
3203 if ((Index
+ sizeof(LONG
)) > WindowObject
->ExtraDataSize
)
3205 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3206 IntReleaseWindowObject(WindowObject
);
3209 OldValue
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
3210 *((LONG
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
3217 OldValue
= (LONG
) WindowObject
->ExStyle
;
3218 Style
.styleOld
= OldValue
;
3219 Style
.styleNew
= NewValue
;
3222 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3224 Process
= WindowObject
->OwnerThread
->ThreadsProcess
->Win32Process
;
3225 WindowStation
= Process
->WindowStation
;
3228 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3229 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3232 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3233 WindowObject
->ExStyle
= (DWORD
)Style
.styleNew
;
3234 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3238 OldValue
= (LONG
) WindowObject
->Style
;
3239 Style
.styleOld
= OldValue
;
3240 Style
.styleNew
= NewValue
;
3241 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3242 WindowObject
->Style
= (DWORD
)Style
.styleNew
;
3243 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3247 /* FIXME: should check if window belongs to current process */
3250 OldValue
= (LONG
) WindowObject
->WndProcA
;
3251 WindowObject
->WndProcA
= (WNDPROC
) NewValue
;
3252 WindowObject
->WndProcW
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,FALSE
);
3253 WindowObject
->Unicode
= FALSE
;
3257 OldValue
= (LONG
) WindowObject
->WndProcW
;
3258 WindowObject
->WndProcW
= (WNDPROC
) NewValue
;
3259 WindowObject
->WndProcA
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,TRUE
);
3260 WindowObject
->Unicode
= TRUE
;
3265 OldValue
= (LONG
) WindowObject
->Instance
;
3266 WindowObject
->Instance
= (HINSTANCE
) NewValue
;
3269 case GWL_HWNDPARENT
:
3270 Parent
= IntGetParentObject(WindowObject
);
3271 if (Parent
&& (Parent
->Self
== IntGetDesktopWindow()))
3272 OldValue
= (LONG
) IntSetOwner(WindowObject
->Self
, (HWND
) NewValue
);
3274 OldValue
= (LONG
) NtUserSetParent(WindowObject
->Self
, (HWND
) NewValue
);
3276 IntReleaseWindowObject(Parent
);
3280 OldValue
= (LONG
) WindowObject
->IDMenu
;
3281 WindowObject
->IDMenu
= (UINT
) NewValue
;
3285 OldValue
= WindowObject
->UserData
;
3286 WindowObject
->UserData
= NewValue
;
3290 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3291 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3297 IntReleaseWindowObject(WindowObject
);
3303 * NtUserSetWindowWord
3305 * Legacy function similar to NtUserSetWindowLong.
3312 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3314 PWINDOW_OBJECT WindowObject
;
3321 case GWL_HWNDPARENT
:
3322 return NtUserSetWindowLong(hWnd
, Index
, (UINT
)NewValue
, TRUE
);
3326 SetLastWin32Error(ERROR_INVALID_INDEX
);
3331 WindowObject
= IntGetWindowObject(hWnd
);
3332 if (WindowObject
== NULL
)
3334 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3338 if (Index
> WindowObject
->ExtraDataSize
- sizeof(WORD
))
3340 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3341 IntReleaseWindowObject(WindowObject
);
3345 OldValue
= *((WORD
*)(WindowObject
->ExtraData
+ Index
));
3346 *((WORD
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
3348 IntReleaseWindowObject(WindowObject
);
3357 NtUserGetWindowPlacement(HWND hWnd
,
3358 WINDOWPLACEMENT
*lpwndpl
)
3360 PWINDOW_OBJECT WindowObject
;
3361 PINTERNALPOS InternalPos
;
3363 WINDOWPLACEMENT Safepl
;
3366 WindowObject
= IntGetWindowObject(hWnd
);
3367 if (WindowObject
== NULL
)
3369 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3373 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3374 if(!NT_SUCCESS(Status
))
3376 SetLastNtError(Status
);
3377 IntReleaseWindowObject(WindowObject
);
3380 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3382 IntReleaseWindowObject(WindowObject
);
3387 Safepl
.showCmd
= ((WindowObject
->Flags
& WINDOWOBJECT_RESTOREMAX
) ? SW_MAXIMIZE
: SW_SHOWNORMAL
);
3389 Size
.x
= WindowObject
->WindowRect
.left
;
3390 Size
.y
= WindowObject
->WindowRect
.top
;
3391 InternalPos
= WinPosInitInternalPos(WindowObject
, &Size
,
3392 &WindowObject
->WindowRect
);
3395 Safepl
.rcNormalPosition
= InternalPos
->NormalRect
;
3396 Safepl
.ptMinPosition
= InternalPos
->IconPos
;
3397 Safepl
.ptMaxPosition
= InternalPos
->MaxPos
;
3401 IntReleaseWindowObject(WindowObject
);
3405 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3406 if(!NT_SUCCESS(Status
))
3408 SetLastNtError(Status
);
3409 IntReleaseWindowObject(WindowObject
);
3413 IntReleaseWindowObject(WindowObject
);
3419 * Return the dimension of the window in the screen coordinates.
3420 * \param hWnd window handle.
3421 * \param Rect pointer to the buffer where the coordinates are returned.
3427 NtUserGetWindowRect(HWND hWnd
, LPRECT Rect
)
3432 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3434 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3437 Status
= MmCopyToCaller(Rect
, &Wnd
->WindowRect
, sizeof(RECT
));
3438 if (!NT_SUCCESS(Status
))
3440 IntReleaseWindowObject(Wnd
);
3441 SetLastNtError(Status
);
3445 IntReleaseWindowObject(Wnd
);
3454 NtUserGetWindowThreadProcessId(HWND hWnd
, LPDWORD UnsafePid
)
3459 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3461 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3465 tid
= (DWORD
)IntGetWndThreadId(Wnd
);
3466 pid
= (DWORD
)IntGetWndProcessId(Wnd
);
3468 if (UnsafePid
) MmCopyToCaller(UnsafePid
, &pid
, sizeof(DWORD
));
3478 NtUserLockWindowUpdate(DWORD Unknown0
)
3498 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3499 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3500 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3504 QueryWindow based on KJK::Hyperion and James Tabor.
3506 0 = QWUniqueProcessId
3507 1 = QWUniqueThreadId
3508 4 = QWIsHung Implements IsHungAppWindow found
3511 9 = QWKillWindow When I called this with hWnd ==
3512 DesktopWindow, it shutdown the system
3519 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3521 PWINDOW_OBJECT Window
= IntGetWindowObject(hWnd
);
3526 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3532 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3533 Result
= (DWORD
)IntGetWndProcessId(Window
);
3536 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3537 Result
= (DWORD
)IntGetWndThreadId(Window
);
3540 case QUERY_WINDOW_ISHUNG
:
3541 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
3545 Result
= (DWORD
)NULL
;
3549 IntReleaseWindowObject(Window
);
3559 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3573 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3575 UNICODE_STRING SafeMessageName
;
3579 if(MessageNameUnsafe
== NULL
)
3581 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3585 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3586 if(!NT_SUCCESS(Status
))
3588 SetLastNtError(Status
);
3592 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3594 RtlFreeUnicodeString(&SafeMessageName
);
3603 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3616 NtUserSetInternalWindowPos(DWORD Unknown0
,
3632 NtUserSetLayeredWindowAttributes(DWORD Unknown0
,
3647 NtUserSetLogonNotifyWindow(DWORD Unknown0
)
3664 PWINDOW_OBJECT WindowObject
;
3667 WindowObject
= IntGetWindowObject((HWND
) Wnd
);
3668 if (NULL
== WindowObject
)
3670 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3674 if (! IntSetMenu(WindowObject
, Menu
, &Changed
))
3676 IntReleaseWindowObject(WindowObject
);
3680 IntReleaseWindowObject(WindowObject
);
3682 if (Changed
&& Repaint
)
3684 WinPosSetWindowPos(Wnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3685 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3696 NtUserSetWindowFNID(DWORD Unknown0
,
3710 NtUserSetWindowPlacement(HWND hWnd
,
3711 WINDOWPLACEMENT
*lpwndpl
)
3713 PWINDOW_OBJECT WindowObject
;
3714 WINDOWPLACEMENT Safepl
;
3717 WindowObject
= IntGetWindowObject(hWnd
);
3718 if (WindowObject
== NULL
)
3720 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3723 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3724 if(!NT_SUCCESS(Status
))
3726 SetLastNtError(Status
);
3727 IntReleaseWindowObject(WindowObject
);
3730 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3732 IntReleaseWindowObject(WindowObject
);
3736 if ((WindowObject
->Style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
3738 WinPosSetWindowPos(WindowObject
->Self
, NULL
,
3739 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
3740 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
3741 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
3742 SWP_NOZORDER
| SWP_NOACTIVATE
);
3745 /* FIXME - change window status */
3746 WinPosShowWindow(WindowObject
->Self
, Safepl
.showCmd
);
3748 if (WindowObject
->InternalPos
== NULL
)
3749 WindowObject
->InternalPos
= ExAllocatePoolWithTag(PagedPool
, sizeof(INTERNALPOS
), TAG_WININTLIST
);
3750 WindowObject
->InternalPos
->NormalRect
= Safepl
.rcNormalPosition
;
3751 WindowObject
->InternalPos
->IconPos
= Safepl
.ptMinPosition
;
3752 WindowObject
->InternalPos
->MaxPos
= Safepl
.ptMaxPosition
;
3754 IntReleaseWindowObject(WindowObject
);
3765 HWND hWndInsertAfter
,
3772 return WinPosSetWindowPos(hWnd
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
3777 IntGetWindowRgn(HWND hWnd
, HRGN hRgn
)
3780 PWINDOW_OBJECT WindowObject
;
3784 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
3786 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3791 IntReleaseWindowObject(WindowObject
);
3795 /* Create a new window region using the window rectangle */
3796 VisRgn
= UnsafeIntCreateRectRgnIndirect(&WindowObject
->WindowRect
);
3797 NtGdiOffsetRgn(VisRgn
, -WindowObject
->WindowRect
.left
, -WindowObject
->WindowRect
.top
);
3798 /* if there's a region assigned to the window, combine them both */
3799 if(WindowObject
->WindowRegion
&& !(WindowObject
->Style
& WS_MINIMIZE
))
3800 NtGdiCombineRgn(VisRgn
, VisRgn
, WindowObject
->WindowRegion
, RGN_AND
);
3801 /* Copy the region into hRgn */
3802 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
3804 if((pRgn
= RGNDATA_LockRgn(hRgn
)))
3806 Ret
= pRgn
->rdh
.iType
;
3807 RGNDATA_UnlockRgn(hRgn
);
3812 NtGdiDeleteObject(VisRgn
);
3814 IntReleaseWindowObject(WindowObject
);
3819 IntGetWindowRgnBox(HWND hWnd
, RECT
*Rect
)
3822 PWINDOW_OBJECT WindowObject
;
3826 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
3828 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3833 IntReleaseWindowObject(WindowObject
);
3837 /* Create a new window region using the window rectangle */
3838 VisRgn
= UnsafeIntCreateRectRgnIndirect(&WindowObject
->WindowRect
);
3839 NtGdiOffsetRgn(VisRgn
, -WindowObject
->WindowRect
.left
, -WindowObject
->WindowRect
.top
);
3840 /* if there's a region assigned to the window, combine them both */
3841 if(WindowObject
->WindowRegion
&& !(WindowObject
->Style
& WS_MINIMIZE
))
3842 NtGdiCombineRgn(VisRgn
, VisRgn
, WindowObject
->WindowRegion
, RGN_AND
);
3844 if((pRgn
= RGNDATA_LockRgn(VisRgn
)))
3846 Ret
= pRgn
->rdh
.iType
;
3847 *Rect
= pRgn
->rdh
.rcBound
;
3848 RGNDATA_UnlockRgn(VisRgn
);
3853 NtGdiDeleteObject(VisRgn
);
3855 IntReleaseWindowObject(WindowObject
);
3869 PWINDOW_OBJECT WindowObject
;
3871 WindowObject
= IntGetWindowObject(hWnd
);
3872 if (WindowObject
== NULL
)
3874 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3878 /* FIXME - Verify if hRgn is a valid handle!!!!
3879 Propably make this operation thread-safe, but maybe it's not necessary */
3881 if(WindowObject
->WindowRegion
)
3883 /* Delete no longer needed region handle */
3884 NtGdiDeleteObject(WindowObject
->WindowRegion
);
3886 WindowObject
->WindowRegion
= hRgn
;
3888 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
3892 IntRedrawWindow(WindowObject
, NULL
, NULL
, RDW_INVALIDATE
);
3895 IntReleaseWindowObject(WindowObject
);
3904 NtUserShowWindow(HWND hWnd
,
3907 return WinPosShowWindow(hWnd
, nCmdShow
);
3915 NtUserShowWindowAsync(DWORD Unknown0
,
3928 NtUserUpdateLayeredWindow(DWORD Unknown0
,
3948 NtUserValidateRect(HWND hWnd
, const RECT
* Rect
)
3950 return (VOID
)NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
3958 NtUserWindowFromPoint(LONG X
, LONG Y
)
3962 PWINDOW_OBJECT DesktopWindow
, Window
= NULL
;
3964 if ((DesktopWindow
= IntGetWindowObject(IntGetDesktopWindow())))
3971 Hit
= WinPosWindowFromPoint(DesktopWindow
, PsGetWin32Thread()->MessageQueue
, &pt
, &Window
);
3976 IntReleaseWindowObject(Window
);
3977 IntReleaseWindowObject(DesktopWindow
);
3981 IntReleaseWindowObject(DesktopWindow
);
3991 * Undocumented function that is called from DefWindowProc to set
3999 NtUserDefSetText(HWND WindowHandle
, PUNICODE_STRING WindowText
)
4001 PWINDOW_OBJECT WindowObject
;
4002 UNICODE_STRING SafeText
;
4005 WindowObject
= IntGetWindowObject(WindowHandle
);
4008 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4014 Status
= IntSafeCopyUnicodeString(&SafeText
, WindowText
);
4015 if(!NT_SUCCESS(Status
))
4017 SetLastNtError(Status
);
4018 IntReleaseWindowObject(WindowObject
);
4024 RtlInitUnicodeString(&SafeText
, NULL
);
4027 /* FIXME - do this thread-safe! otherwise one could crash here! */
4028 RtlFreeUnicodeString(&WindowObject
->WindowName
);
4030 WindowObject
->WindowName
= SafeText
;
4032 IntReleaseWindowObject(WindowObject
);
4037 * NtUserInternalGetWindowText
4044 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4046 PWINDOW_OBJECT WindowObject
;
4050 if(lpString
&& (nMaxCount
<= 1))
4052 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4056 WindowObject
= IntGetWindowObject(hWnd
);
4059 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4063 /* FIXME - do this thread-safe! otherwise one could crash here! */
4064 Result
= WindowObject
->WindowName
.Length
/ sizeof(WCHAR
);
4067 const WCHAR Terminator
= L
'\0';
4069 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4071 Copy
= min(nMaxCount
- 1, Result
);
4074 Status
= MmCopyToCaller(Buffer
, WindowObject
->WindowName
.Buffer
, Copy
* sizeof(WCHAR
));
4075 if(!NT_SUCCESS(Status
))
4077 SetLastNtError(Status
);
4078 IntReleaseWindowObject(WindowObject
);
4084 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4085 if(!NT_SUCCESS(Status
))
4087 SetLastNtError(Status
);
4088 IntReleaseWindowObject(WindowObject
);
4095 IntReleaseWindowObject(WindowObject
);
4100 NtUserDereferenceWndProcHandle(WNDPROC wpHandle
, WndProcHandle
*Data
)
4102 WndProcHandle Entry
;
4103 if (((DWORD
)wpHandle
& 0xFFFF0000) == 0xFFFF0000)
4105 Entry
= WndProcHandlesArray
[(DWORD
)wpHandle
& 0x0000FFFF];
4106 Data
->WindowProc
= Entry
.WindowProc
;
4107 Data
->IsUnicode
= Entry
.IsUnicode
;
4108 Data
->ProcessID
= Entry
.ProcessID
;
4117 IntAddWndProcHandle(WNDPROC WindowProc
, BOOL IsUnicode
)
4122 WndProcHandle
*OldArray
;
4125 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4127 if (WndProcHandlesArray
[i
].WindowProc
== NULL
)
4135 OldArray
= WndProcHandlesArray
;
4136 OldArraySize
= WndProcHandlesArraySize
;
4137 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,(OldArraySize
+ WPH_SIZE
) * sizeof(WndProcHandle
), TAG_WINPROCLST
);
4138 WndProcHandlesArraySize
= OldArraySize
+ WPH_SIZE
;
4139 RtlCopyMemory(WndProcHandlesArray
,OldArray
,OldArraySize
* sizeof(WndProcHandle
));
4140 ExFreePool(OldArray
);
4141 FreeSpot
= OldArraySize
+ 1;
4143 WndProcHandlesArray
[FreeSpot
].WindowProc
= WindowProc
;
4144 WndProcHandlesArray
[FreeSpot
].IsUnicode
= IsUnicode
;
4145 WndProcHandlesArray
[FreeSpot
].ProcessID
= PsGetCurrentProcessId();
4146 return FreeSpot
+ 0xFFFF0000;
4150 IntRemoveWndProcHandle(WNDPROC Handle
)
4153 position
= (DWORD
)Handle
& 0x0000FFFF;
4154 if (position
> WndProcHandlesArraySize
)
4158 WndProcHandlesArray
[position
].WindowProc
= NULL
;
4159 WndProcHandlesArray
[position
].IsUnicode
= FALSE
;
4160 WndProcHandlesArray
[position
].ProcessID
= NULL
;
4165 IntRemoveProcessWndProcHandles(HANDLE ProcessID
)
4168 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4170 if (WndProcHandlesArray
[i
].ProcessID
== ProcessID
)
4172 WndProcHandlesArray
[i
].WindowProc
= NULL
;
4173 WndProcHandlesArray
[i
].IsUnicode
= FALSE
;
4174 WndProcHandlesArray
[i
].ProcessID
= NULL
;