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.241 2004/06/22 12:43:49 royce 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 /* remove the window from the class object */
391 IntLockClassWindows(Window
->Class
);
392 RemoveEntryList(&Window
->ClassListEntry
);
393 IntUnLockClassWindows(Window
->Class
);
395 /* dereference the class */
396 ClassDereferenceObject(Window
->Class
);
397 Window
->Class
= NULL
;
399 if(Window
->WindowRegion
)
401 NtGdiDeleteObject(Window
->WindowRegion
);
404 RtlFreeUnicodeString(&Window
->WindowName
);
406 IntReleaseWindowObject(Window
);
412 IntGetWindowBorderMeasures(PWINDOW_OBJECT WindowObject
, INT
*cx
, INT
*cy
)
414 if(HAS_DLGFRAME(WindowObject
->Style
, WindowObject
->ExStyle
) && !(WindowObject
->Style
& WS_MINIMIZE
))
416 *cx
= NtUserGetSystemMetrics(SM_CXDLGFRAME
);
417 *cy
= NtUserGetSystemMetrics(SM_CYDLGFRAME
);
421 if(HAS_THICKFRAME(WindowObject
->Style
, WindowObject
->ExStyle
)&& !(WindowObject
->Style
& WS_MINIMIZE
))
423 *cx
= NtUserGetSystemMetrics(SM_CXFRAME
);
424 *cy
= NtUserGetSystemMetrics(SM_CYFRAME
);
426 else if(HAS_THINFRAME(WindowObject
->Style
, WindowObject
->ExStyle
))
428 *cx
= NtUserGetSystemMetrics(SM_CXBORDER
);
429 *cy
= NtUserGetSystemMetrics(SM_CYBORDER
);
439 IntGetWindowInfo(PWINDOW_OBJECT WindowObject
, PWINDOWINFO pwi
)
441 pwi
->cbSize
= sizeof(WINDOWINFO
);
442 pwi
->rcWindow
= WindowObject
->WindowRect
;
443 pwi
->rcClient
= WindowObject
->ClientRect
;
444 pwi
->dwStyle
= WindowObject
->Style
;
445 pwi
->dwExStyle
= WindowObject
->ExStyle
;
446 pwi
->dwWindowStatus
= (NtUserGetForegroundWindow() == WindowObject
->Self
); /* WS_ACTIVECAPTION */
447 IntGetWindowBorderMeasures(WindowObject
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
448 pwi
->atomWindowType
= (WindowObject
->Class
? WindowObject
->Class
->Atom
: 0);
449 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
455 PWINDOW_OBJECT WindowObject
,
459 PMENU_OBJECT OldMenuObject
, NewMenuObject
;
461 *Changed
= (WindowObject
->IDMenu
!= (UINT
) Menu
);
467 if (0 != WindowObject
->IDMenu
)
469 OldMenuObject
= IntGetMenuObject((HMENU
) WindowObject
->IDMenu
);
470 ASSERT(NULL
== OldMenuObject
|| OldMenuObject
->MenuInfo
.Wnd
== WindowObject
->Self
);
474 OldMenuObject
= NULL
;
479 NewMenuObject
= IntGetMenuObject(Menu
);
480 if (NULL
== NewMenuObject
)
482 if (NULL
!= OldMenuObject
)
484 IntReleaseMenuObject(OldMenuObject
);
486 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
489 if (NULL
!= NewMenuObject
->MenuInfo
.Wnd
)
491 /* Can't use the same menu for two windows */
492 if (NULL
!= OldMenuObject
)
494 IntReleaseMenuObject(OldMenuObject
);
496 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
502 WindowObject
->IDMenu
= (UINT
) Menu
;
503 if (NULL
!= NewMenuObject
)
505 NewMenuObject
->MenuInfo
.Wnd
= WindowObject
->Self
;
506 IntReleaseMenuObject(NewMenuObject
);
508 if (NULL
!= OldMenuObject
)
510 OldMenuObject
->MenuInfo
.Wnd
= NULL
;
511 IntReleaseMenuObject(OldMenuObject
);
518 /* INTERNAL ******************************************************************/
522 DestroyThreadWindows(struct _ETHREAD
*Thread
)
525 PW32PROCESS Win32Process
;
526 PW32THREAD Win32Thread
;
527 PWINDOW_OBJECT
*List
, *pWnd
;
530 Win32Thread
= Thread
->Win32Thread
;
531 Win32Process
= Thread
->ThreadsProcess
->Win32Process
;
533 IntLockThreadWindows(Win32Thread
);
534 Current
= Win32Thread
->WindowListHead
.Flink
;
535 while (Current
!= &(Win32Thread
->WindowListHead
))
538 Current
= Current
->Flink
;
543 List
= ExAllocatePool(PagedPool
, (Cnt
+ 1) * sizeof(PWINDOW_OBJECT
));
546 DPRINT("Not enough memory to allocate window handle list\n");
547 IntUnLockThreadWindows(Win32Thread
);
551 Current
= Win32Thread
->WindowListHead
.Flink
;
552 while (Current
!= &(Win32Thread
->WindowListHead
))
554 *pWnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
555 IntReferenceWindowObject(*pWnd
);
557 Current
= Current
->Flink
;
559 IntUnLockThreadWindows(Win32Thread
);
562 for(pWnd
= List
; *pWnd
; pWnd
++)
564 NtUserDestroyWindow((*pWnd
)->Self
);
565 IntReleaseWindowObject(*pWnd
);
571 IntUnLockThreadWindows(Win32Thread
);
577 * Returns client window rectangle relative to the upper-left corner of client area.
579 * \note Does not check the validity of the parameters
582 IntGetClientRect(PWINDOW_OBJECT WindowObject
, PRECT Rect
)
584 ASSERT( WindowObject
);
587 Rect
->left
= Rect
->top
= 0;
588 Rect
->right
= WindowObject
->ClientRect
.right
- WindowObject
->ClientRect
.left
;
589 Rect
->bottom
= WindowObject
->ClientRect
.bottom
- WindowObject
->ClientRect
.top
;
595 IntGetFocusWindow(VOID
)
597 PUSER_MESSAGE_QUEUE Queue
;
598 PDESKTOP_OBJECT pdo
= IntGetActiveDesktop();
603 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
608 return(Queue
->FocusWindow
);
612 PMENU_OBJECT FASTCALL
613 IntGetSystemMenu(PWINDOW_OBJECT WindowObject
, BOOL bRevert
, BOOL RetMenu
)
615 PMENU_OBJECT MenuObject
, NewMenuObject
, SysMenuObject
, ret
= NULL
;
616 PW32PROCESS W32Process
;
617 HMENU NewMenu
, SysMenu
;
618 ROSMENUITEMINFO ItemInfo
;
622 W32Process
= PsGetWin32Process();
624 if(!W32Process
->WindowStation
)
627 if(WindowObject
->SystemMenu
)
629 MenuObject
= IntGetMenuObject(WindowObject
->SystemMenu
);
632 IntDestroyMenuObject(MenuObject
, FALSE
, TRUE
);
633 WindowObject
->SystemMenu
= (HMENU
)0;
634 IntReleaseMenuObject(MenuObject
);
638 if(W32Process
->WindowStation
->SystemMenuTemplate
)
640 /* clone system menu */
641 MenuObject
= IntGetMenuObject(W32Process
->WindowStation
->SystemMenuTemplate
);
645 NewMenuObject
= IntCloneMenu(MenuObject
);
648 WindowObject
->SystemMenu
= NewMenuObject
->MenuInfo
.Self
;
649 NewMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
650 NewMenuObject
->MenuInfo
.Wnd
= WindowObject
->Self
;
652 //IntReleaseMenuObject(NewMenuObject);
654 IntReleaseMenuObject(MenuObject
);
658 SysMenu
= NtUserCreateMenu(FALSE
);
663 SysMenuObject
= IntGetMenuObject(SysMenu
);
664 if (NULL
== SysMenuObject
)
666 NtUserDestroyMenu(SysMenu
);
669 SysMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
670 SysMenuObject
->MenuInfo
.Wnd
= WindowObject
->Self
;
671 NewMenu
= IntLoadSysMenuTemplate();
674 IntReleaseMenuObject(SysMenuObject
);
675 NtUserDestroyMenu(SysMenu
);
678 MenuObject
= IntGetMenuObject(NewMenu
);
681 IntReleaseMenuObject(SysMenuObject
);
682 NtUserDestroyMenu(SysMenu
);
686 NewMenuObject
= IntCloneMenu(MenuObject
);
689 NewMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
690 IntReleaseMenuObject(NewMenuObject
);
691 NtUserSetMenuDefaultItem(NewMenuObject
->MenuInfo
.Self
, SC_CLOSE
, FALSE
);
693 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
694 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
695 ItemInfo
.fType
= MF_POPUP
;
696 ItemInfo
.fState
= MFS_ENABLED
;
697 ItemInfo
.dwTypeData
= NULL
;
699 ItemInfo
.hSubMenu
= NewMenuObject
->MenuInfo
.Self
;
700 IntInsertMenuItem(SysMenuObject
, (UINT
) -1, TRUE
, &ItemInfo
);
702 WindowObject
->SystemMenu
= SysMenuObject
->MenuInfo
.Self
;
706 IntDestroyMenuObject(MenuObject
, FALSE
, TRUE
);
707 IntReleaseMenuObject(MenuObject
);
716 if(WindowObject
->SystemMenu
)
717 return IntGetMenuObject((HMENU
)WindowObject
->SystemMenu
);
725 IntIsChildWindow(HWND Parent
, HWND Child
)
727 PWINDOW_OBJECT BaseWindow
, Window
, Old
;
729 if(!(BaseWindow
= IntGetWindowObject(Child
)))
737 if (Window
->Self
== Parent
)
739 if(Window
!= BaseWindow
)
740 IntReleaseWindowObject(Window
);
741 IntReleaseWindowObject(BaseWindow
);
744 if(!(Window
->Style
& WS_CHILD
))
746 if(Window
!= BaseWindow
)
747 IntReleaseWindowObject(Window
);
751 Window
= IntGetParentObject(Window
);
752 if(Old
!= BaseWindow
)
753 IntReleaseWindowObject(Old
);
756 IntReleaseWindowObject(BaseWindow
);
761 IntIsWindowVisible(HWND hWnd
)
763 PWINDOW_OBJECT BaseWindow
, Window
, Old
;
765 if(!(BaseWindow
= IntGetWindowObject(hWnd
)))
773 if(!(Window
->Style
& WS_CHILD
))
777 if(!(Window
->Style
& WS_VISIBLE
))
779 if(Window
!= BaseWindow
)
780 IntReleaseWindowObject(Window
);
781 IntReleaseWindowObject(BaseWindow
);
785 Window
= IntGetParentObject(Window
);
786 if(Old
!= BaseWindow
)
787 IntReleaseWindowObject(Old
);
792 if(Window
->Style
& WS_VISIBLE
)
794 if(Window
!= BaseWindow
)
795 IntReleaseWindowObject(Window
);
796 IntReleaseWindowObject(BaseWindow
);
799 if(Window
!= BaseWindow
)
800 IntReleaseWindowObject(Window
);
802 IntReleaseWindowObject(BaseWindow
);
807 /* link the window into siblings and parent. children are kept in place. */
811 PWINDOW_OBJECT WndParent
,
812 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
815 PWINDOW_OBJECT Parent
;
817 IntLockRelatives(Wnd
);
818 Wnd
->Parent
= WndParent
->Self
;
819 if ((Wnd
->PrevSibling
= WndPrevSibling
))
821 /* link after WndPrevSibling */
822 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
823 Wnd
->NextSibling
->PrevSibling
= Wnd
;
824 else if ((Parent
= IntGetWindowObject(Wnd
->Parent
)))
826 IntLockRelatives(Parent
);
827 if(Parent
->LastChild
== WndPrevSibling
)
828 Parent
->LastChild
= Wnd
;
829 IntUnLockRelatives(Parent
);
830 IntReleaseWindowObject(Parent
);
832 Wnd
->PrevSibling
->NextSibling
= Wnd
;
837 Parent
= IntGetWindowObject(Wnd
->Parent
);
838 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
839 Wnd
->NextSibling
->PrevSibling
= Wnd
;
842 IntLockRelatives(Parent
);
843 Parent
->LastChild
= Wnd
;
844 Parent
->FirstChild
= Wnd
;
845 IntUnLockRelatives(Parent
);
846 IntReleaseWindowObject(Parent
);
847 IntUnLockRelatives(Wnd
);
852 IntLockRelatives(Parent
);
853 Parent
->FirstChild
= Wnd
;
854 IntUnLockRelatives(Parent
);
855 IntReleaseWindowObject(Parent
);
858 IntUnLockRelatives(Wnd
);
862 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
864 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
867 Wnd
= IntGetWindowObject(hWnd
);
871 IntLockRelatives(Wnd
);
872 WndOldOwner
= IntGetWindowObject(Wnd
->Owner
);
875 ret
= WndOldOwner
->Self
;
876 IntReleaseWindowObject(WndOldOwner
);
883 if((WndNewOwner
= IntGetWindowObject(hWndNewOwner
)))
885 Wnd
->Owner
= hWndNewOwner
;
886 IntReleaseWindowObject(WndNewOwner
);
891 IntUnLockRelatives(Wnd
);
892 IntReleaseWindowObject(Wnd
);
896 PWINDOW_OBJECT FASTCALL
897 IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
899 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
900 HWND hWnd
, hWndNewParent
, hWndOldParent
;
905 ASSERT(WndNewParent
);
908 hWndNewParent
= WndNewParent
->Self
;
911 * Windows hides the window first, then shows it again
912 * including the WM_SHOWWINDOW messages and all
914 WasVisible
= WinPosShowWindow(hWnd
, SW_HIDE
);
916 /* Validate that window and parent still exist */
917 if (!IntIsWindow(hWnd
) || !IntIsWindow(hWndNewParent
))
920 /* Window must belong to current process */
921 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
924 WndOldParent
= IntGetParentObject(Wnd
);
925 hWndOldParent
= (WndOldParent
? WndOldParent
->Self
: NULL
);
927 if (WndNewParent
!= WndOldParent
)
929 IntUnlinkWindow(Wnd
);
931 if (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
))
933 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
934 IntLockRelatives(WndNewParent
);
935 Sibling
= WndNewParent
->FirstChild
;
936 while (NULL
!= Sibling
&& 0 != (Sibling
->ExStyle
& WS_EX_TOPMOST
))
938 InsertAfter
= Sibling
;
939 Sibling
= Sibling
->NextSibling
;
941 IntUnLockRelatives(WndNewParent
);
943 if (NULL
== InsertAfter
)
945 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
949 IntReferenceWindowObject(InsertAfter
);
950 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
951 IntReleaseWindowObject(InsertAfter
);
954 if (WndNewParent
->Self
!= IntGetDesktopWindow()) /* a child window */
956 if (!(Wnd
->Style
& WS_CHILD
))
958 //if ( Wnd->Menu ) DestroyMenu ( Wnd->menu );
959 IntSetMenu(Wnd
, NULL
, &MenuChanged
);
965 * SetParent additionally needs to make hwnd the top window
966 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
967 * WM_WINDOWPOSCHANGED notification messages.
969 WinPosSetWindowPos(hWnd
, (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
970 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
971 | (WasVisible
? SWP_SHOWWINDOW
: 0));
974 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
975 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
979 * Validate that the old parent still exist, since it migth have been
980 * destroyed during the last callbacks to user-mode
984 if(!IntIsWindow(WndOldParent
->Self
))
986 IntReleaseWindowObject(WndOldParent
);
990 /* don't dereference the window object here, it must be done by the caller
998 IntSetSystemMenu(PWINDOW_OBJECT WindowObject
, PMENU_OBJECT MenuObject
)
1000 PMENU_OBJECT OldMenuObject
;
1001 if(WindowObject
->SystemMenu
)
1003 OldMenuObject
= IntGetMenuObject(WindowObject
->SystemMenu
);
1006 OldMenuObject
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1007 IntReleaseMenuObject(OldMenuObject
);
1013 /* FIXME check window style, propably return FALSE ? */
1014 WindowObject
->SystemMenu
= MenuObject
->MenuInfo
.Self
;
1015 MenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
1018 WindowObject
->SystemMenu
= (HMENU
)0;
1024 /* unlink the window from siblings and parent. children are kept in place. */
1026 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1028 PWINDOW_OBJECT WndParent
;
1030 IntLockRelatives(Wnd
);
1031 if((WndParent
= IntGetWindowObject(Wnd
->Parent
)))
1033 IntLockRelatives(WndParent
);
1036 if (Wnd
->NextSibling
) Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1037 else if (WndParent
&& WndParent
->LastChild
== Wnd
) WndParent
->LastChild
= Wnd
->PrevSibling
;
1039 if (Wnd
->PrevSibling
) Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1040 else if (WndParent
&& WndParent
->FirstChild
== Wnd
) WndParent
->FirstChild
= Wnd
->NextSibling
;
1044 IntUnLockRelatives(WndParent
);
1045 IntReleaseWindowObject(WndParent
);
1047 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1048 IntUnLockRelatives(Wnd
);
1054 PWINDOW_OBJECT Window
, Child
;
1056 if(!(Window
= IntGetWindowObject(IntGetDesktopWindow())))
1058 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1062 IntLockRelatives(Window
);
1063 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1065 if(Child
->Owner
&& Child
->Style
& WS_VISIBLE
)
1068 * The desktop has a popup window if one of them has
1069 * an owner window and is visible
1071 IntUnLockRelatives(Window
);
1072 IntReleaseWindowObject(Window
);
1076 IntUnLockRelatives(Window
);
1077 IntReleaseWindowObject(Window
);
1082 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1084 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1087 /* FUNCTIONS *****************************************************************/
1093 NtUserAlterWindowStyle(DWORD Unknown0
,
1104 * As best as I can figure, this function is used by EnumWindows,
1105 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1107 * It's supposed to build a list of HWNDs to return to the caller.
1108 * We can figure out what kind of list by what parameters are
1116 NtUserBuildHwndList(
1128 /* FIXME handle bChildren */
1132 PWINDOW_OBJECT Window
, Child
;
1133 if(!(Window
= IntGetWindowObject(hwndParent
)))
1135 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1139 IntLockRelatives(Window
);
1140 for(Child
= Window
->FirstChild
; Child
!= NULL
; Child
= Child
->NextSibling
)
1142 if(dwCount
++ < nBufSize
&& pWnd
)
1144 Status
= MmCopyToCaller(pWnd
++, &Child
->Self
, sizeof(HWND
));
1145 if(!NT_SUCCESS(Status
))
1147 SetLastNtError(Status
);
1152 IntUnLockRelatives(Window
);
1154 IntReleaseWindowObject(Window
);
1159 PW32THREAD W32Thread
;
1160 PLIST_ENTRY Current
;
1161 PWINDOW_OBJECT Window
;
1163 Status
= PsLookupThreadByThreadId((PVOID
)dwThreadId
, &Thread
);
1164 if(!NT_SUCCESS(Status
))
1166 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1169 if(!(W32Thread
= Thread
->Win32Thread
))
1171 ObDereferenceObject(Thread
);
1172 DPRINT1("Thread is not a GUI Thread!\n");
1173 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1177 IntLockThreadWindows(W32Thread
);
1178 Current
= W32Thread
->WindowListHead
.Flink
;
1179 while(Current
!= &(W32Thread
->WindowListHead
))
1181 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1184 if(dwCount
< nBufSize
&& pWnd
&& (Window
->Style
& WS_CHILD
))
1186 Status
= MmCopyToCaller(pWnd
++, &Window
->Self
, sizeof(HWND
));
1187 if(!NT_SUCCESS(Status
))
1189 SetLastNtError(Status
);
1194 if(!(Window
->Style
& WS_CHILD
))
1199 Current
= Current
->Flink
;
1201 IntUnLockThreadWindows(W32Thread
);
1203 ObDereferenceObject(Thread
);
1207 PDESKTOP_OBJECT Desktop
;
1208 PWINDOW_OBJECT Window
, Child
;
1210 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1212 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1218 Status
= IntValidateDesktopHandle(hDesktop
,
1222 if(!NT_SUCCESS(Status
))
1224 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1228 if(!(Window
= IntGetWindowObject(Desktop
->DesktopWindow
)))
1231 ObDereferenceObject(Desktop
);
1232 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1236 IntLockRelatives(Window
);
1237 for(Child
= Window
->FirstChild
; Child
!= NULL
; Child
= Child
->NextSibling
)
1239 if(dwCount
++ < nBufSize
&& pWnd
)
1241 Status
= MmCopyToCaller(pWnd
++, &Child
->Self
, sizeof(HWND
));
1242 if(!NT_SUCCESS(Status
))
1244 SetLastNtError(Status
);
1249 IntUnLockRelatives(Window
);
1251 IntReleaseWindowObject(Window
);
1253 ObDereferenceObject(Desktop
);
1264 NtUserChildWindowFromPointEx(HWND hwndParent
,
1269 PWINDOW_OBJECT Parent
;
1274 if(!(Parent
= IntGetWindowObject(hwndParent
)))
1276 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1283 if(Parent
->Self
!= IntGetDesktopWindow())
1285 Pt
.x
+= Parent
->ClientRect
.left
;
1286 Pt
.y
+= Parent
->ClientRect
.top
;
1289 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1291 IntReleaseWindowObject(Parent
);
1296 if((List
= IntWinListChildren(Parent
)))
1298 for(phWnd
= List
; *phWnd
; phWnd
++)
1300 PWINDOW_OBJECT Child
;
1301 if((Child
= IntGetWindowObject(*phWnd
)))
1303 if(!(Child
->Style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1305 IntReleaseWindowObject(Child
);
1308 if((Child
->Style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1310 IntReleaseWindowObject(Child
);
1313 if((Child
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1315 IntReleaseWindowObject(Child
);
1318 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1321 IntReleaseWindowObject(Child
);
1324 IntReleaseWindowObject(Child
);
1330 IntReleaseWindowObject(Parent
);
1336 * calculates the default position of a window
1339 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT WindowObject
, RECT
*rc
, BOOL IncPos
)
1346 NtGdiIntersectRect(rc
, rc
, &Parent
->ClientRect
);
1350 Pos
.x
= Parent
->TiledCounter
* (NtUserGetSystemMetrics(SM_CXSIZE
) + NtUserGetSystemMetrics(SM_CXFRAME
));
1351 Pos
.y
= Parent
->TiledCounter
* (NtUserGetSystemMetrics(SM_CYSIZE
) + NtUserGetSystemMetrics(SM_CYFRAME
));
1352 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1353 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1355 /* reset counter and position */
1358 Parent
->TiledCounter
= 0;
1360 Parent
->TiledCounter
++;
1371 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1372 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1376 rc
->right
= rc
->left
+ Sz
.cx
;
1377 rc
->bottom
= rc
->top
+ Sz
.cy
;
1386 IntCreateWindowEx(DWORD dwExStyle
,
1387 PUNICODE_STRING ClassName
,
1388 PUNICODE_STRING WindowName
,
1396 HINSTANCE hInstance
,
1399 BOOL bUnicodeWindow
)
1401 PWINSTATION_OBJECT WinStaObject
;
1402 PWNDCLASS_OBJECT ClassObject
;
1403 PWINDOW_OBJECT WindowObject
;
1404 PWINDOW_OBJECT ParentWindow
, OwnerWindow
;
1405 HWND ParentWindowHandle
;
1406 HWND OwnerWindowHandle
;
1407 PMENU_OBJECT SystemMenu
;
1413 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1418 CBT_CREATEWNDW CbtCreate
;
1422 PWSTR ClassNameString
;
1424 ParentWindowHandle
= PsGetWin32Thread()->Desktop
->DesktopWindow
;
1425 OwnerWindowHandle
= NULL
;
1427 if (hWndParent
== HWND_MESSAGE
)
1430 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1431 * message window (style: WS_POPUP|WS_DISABLED)
1435 else if (hWndParent
)
1437 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1438 ParentWindowHandle
= hWndParent
;
1440 OwnerWindowHandle
= NtUserGetAncestor(hWndParent
, GA_ROOT
);
1442 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1444 return (HWND
)0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1447 if (NULL
!= ParentWindowHandle
)
1449 ParentWindow
= IntGetWindowObject(ParentWindowHandle
);
1453 ParentWindow
= NULL
;
1456 /* FIXME: parent must belong to the current process */
1458 /* Check the class. */
1459 if (IS_ATOM(ClassName
->Buffer
))
1461 ClassFound
= ClassReferenceClassByNameOrAtom(&ClassObject
, ClassName
->Buffer
, hInstance
);
1465 Status
= IntUnicodeStringToNULLTerminated(&ClassNameString
, ClassName
);
1466 if (! NT_SUCCESS(Status
))
1468 if (NULL
!= ParentWindow
)
1470 IntReleaseWindowObject(ParentWindow
);
1474 ClassFound
= ClassReferenceClassByNameOrAtom(&ClassObject
, ClassNameString
, hInstance
);
1475 IntFreeNULLTerminatedFromUnicodeString(ClassNameString
, ClassName
);
1479 if (IS_ATOM(ClassName
->Buffer
))
1481 DPRINT1("Class 0x%x not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1485 DPRINT1("Class %wZ not found\n", ClassName
);
1487 if (NULL
!= ParentWindow
)
1489 IntReleaseWindowObject(ParentWindow
);
1494 /* Check the window station. */
1495 DPRINT("IoGetCurrentProcess() %X\n", IoGetCurrentProcess());
1496 DPRINT("PROCESS_WINDOW_STATION %X\n", PROCESS_WINDOW_STATION());
1497 Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
1501 if (!NT_SUCCESS(Status
))
1503 ClassDereferenceObject(ClassObject
);
1504 if (NULL
!= ParentWindow
)
1506 IntReleaseWindowObject(ParentWindow
);
1508 DPRINT("Validation of window station handle (0x%X) failed\n",
1509 PROCESS_WINDOW_STATION());
1513 /* Create the window object. */
1514 WindowObject
= (PWINDOW_OBJECT
)
1515 ObmCreateObject(PsGetWin32Process()->WindowStation
->HandleTable
, &Handle
,
1516 otWindow
, sizeof(WINDOW_OBJECT
) + ClassObject
->cbWndExtra
1519 DPRINT("Created object with handle %X\n", Handle
);
1522 ObDereferenceObject(WinStaObject
);
1523 ClassDereferenceObject(ClassObject
);
1524 if (NULL
!= ParentWindow
)
1526 IntReleaseWindowObject(ParentWindow
);
1528 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1531 ObDereferenceObject(WinStaObject
);
1533 if (NULL
== PsGetWin32Thread()->Desktop
->DesktopWindow
)
1535 /* If there is no desktop window yet, we must be creating it */
1536 PsGetWin32Thread()->Desktop
->DesktopWindow
= Handle
;
1540 * Fill out the structure describing it.
1542 WindowObject
->Class
= ClassObject
;
1543 IntLockClassWindows(ClassObject
);
1544 InsertTailList(&ClassObject
->ClassWindowsListHead
, &WindowObject
->ClassListEntry
);
1545 IntUnLockClassWindows(ClassObject
);
1547 WindowObject
->ExStyle
= dwExStyle
;
1548 WindowObject
->Style
= dwStyle
& ~WS_VISIBLE
;
1549 DPRINT("1: Style is now %lx\n", WindowObject
->Style
);
1551 WindowObject
->SystemMenu
= (HMENU
)0;
1552 WindowObject
->ContextHelpId
= 0;
1553 WindowObject
->IDMenu
= 0;
1554 WindowObject
->Instance
= hInstance
;
1555 WindowObject
->Self
= Handle
;
1556 if (0 != (dwStyle
& WS_CHILD
))
1558 WindowObject
->IDMenu
= (UINT
) hMenu
;
1562 IntSetMenu(WindowObject
, hMenu
, &MenuChanged
);
1564 WindowObject
->MessageQueue
= PsGetWin32Thread()->MessageQueue
;
1565 WindowObject
->Parent
= (ParentWindow
? ParentWindow
->Self
: NULL
);
1566 if((OwnerWindow
= IntGetWindowObject(OwnerWindowHandle
)))
1568 WindowObject
->Owner
= OwnerWindowHandle
;
1569 IntReleaseWindowObject(OwnerWindow
);
1572 WindowObject
->Owner
= NULL
;
1573 WindowObject
->UserData
= 0;
1574 if ((((DWORD
)ClassObject
->lpfnWndProcA
& 0xFFFF0000) != 0xFFFF0000)
1575 && (((DWORD
)ClassObject
->lpfnWndProcW
& 0xFFFF0000) != 0xFFFF0000))
1577 WindowObject
->Unicode
= bUnicodeWindow
;
1581 WindowObject
->Unicode
= ClassObject
->Unicode
;
1583 WindowObject
->WndProcA
= ClassObject
->lpfnWndProcA
;
1584 WindowObject
->WndProcW
= ClassObject
->lpfnWndProcW
;
1585 WindowObject
->OwnerThread
= PsGetCurrentThread();
1586 WindowObject
->FirstChild
= NULL
;
1587 WindowObject
->LastChild
= NULL
;
1588 WindowObject
->PrevSibling
= NULL
;
1589 WindowObject
->NextSibling
= NULL
;
1591 /* extra window data */
1592 if (ClassObject
->cbWndExtra
!= 0)
1594 WindowObject
->ExtraData
= (PCHAR
)(WindowObject
+ 1);
1595 WindowObject
->ExtraDataSize
= ClassObject
->cbWndExtra
;
1596 RtlZeroMemory(WindowObject
->ExtraData
, WindowObject
->ExtraDataSize
);
1600 WindowObject
->ExtraData
= NULL
;
1601 WindowObject
->ExtraDataSize
= 0;
1604 InitializeListHead(&WindowObject
->PropListHead
);
1605 ExInitializeFastMutex(&WindowObject
->PropListLock
);
1606 ExInitializeFastMutex(&WindowObject
->RelativesLock
);
1607 ExInitializeFastMutex(&WindowObject
->UpdateLock
);
1609 if (NULL
!= WindowName
->Buffer
)
1611 WindowObject
->WindowName
.MaximumLength
= WindowName
->MaximumLength
;
1612 WindowObject
->WindowName
.Length
= WindowName
->Length
;
1613 WindowObject
->WindowName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, WindowName
->MaximumLength
,
1615 if (NULL
== WindowObject
->WindowName
.Buffer
)
1617 ClassDereferenceObject(ClassObject
);
1618 DPRINT1("Failed to allocate mem for window name\n");
1619 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1622 RtlCopyMemory(WindowObject
->WindowName
.Buffer
, WindowName
->Buffer
, WindowName
->MaximumLength
);
1626 RtlInitUnicodeString(&WindowObject
->WindowName
, NULL
);
1630 /* Correct the window style. */
1631 if (!(dwStyle
& WS_CHILD
))
1633 WindowObject
->Style
|= WS_CLIPSIBLINGS
;
1634 DPRINT("3: Style is now %lx\n", WindowObject
->Style
);
1635 if (!(dwStyle
& WS_POPUP
))
1637 WindowObject
->Style
|= WS_CAPTION
;
1638 WindowObject
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1639 DPRINT("4: Style is now %lx\n", WindowObject
->Style
);
1640 /* FIXME: Note the window needs a size. */
1644 if(!(WindowObject
->Style
& (WS_POPUP
| WS_CHILD
)))
1646 /* Automatically assign the caption and border style. Also always
1647 clip siblings for overlapped windows. */
1648 WindowObject
->Style
|= (WS_CAPTION
| WS_BORDER
| WS_CLIPSIBLINGS
);
1651 /* create system menu */
1652 if((WindowObject
->Style
& WS_SYSMENU
) && (WindowObject
->Style
& WS_CAPTION
))
1654 SystemMenu
= IntGetSystemMenu(WindowObject
, TRUE
, TRUE
);
1657 WindowObject
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1658 IntReleaseMenuObject(SystemMenu
);
1662 /* Insert the window into the thread's window list. */
1663 IntLockThreadWindows(PsGetWin32Thread());
1664 InsertTailList (&PsGetWin32Thread()->WindowListHead
,
1665 &WindowObject
->ThreadListEntry
);
1666 IntUnLockThreadWindows(PsGetWin32Thread());
1668 /* Allocate a DCE for this window. */
1669 if (dwStyle
& CS_OWNDC
)
1671 WindowObject
->Dce
= DceAllocDCE(WindowObject
->Self
, DCE_WINDOW_DC
);
1673 /* FIXME: Handle "CS_CLASSDC" */
1681 Cs
.lpCreateParams
= lpParam
;
1682 Cs
.hInstance
= hInstance
;
1684 Cs
.hwndParent
= ParentWindowHandle
;
1690 Cs
.lpszName
= (LPCWSTR
) WindowName
;
1691 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
1692 Cs
.dwExStyle
= dwExStyle
;
1693 CbtCreate
.lpcs
= &Cs
;
1694 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1695 if (HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) Handle
, (LPARAM
) &CbtCreate
))
1697 if (NULL
!= ParentWindow
)
1699 IntReleaseWindowObject(ParentWindow
);
1702 /* FIXME - Delete window object and remove it from the thread windows list */
1703 /* FIXME - delete allocated DCE */
1705 ClassDereferenceObject(ClassObject
);
1706 DPRINT1("CBT-hook returned !0\n");
1715 /* default positioning for overlapped windows */
1716 if(!(WindowObject
->Style
& (WS_POPUP
| WS_CHILD
)))
1719 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1720 BOOL CalculatedDefPosSize
= FALSE
;
1722 IntGetDesktopWorkArea(WindowObject
->OwnerThread
->Win32Thread
->Desktop
, &WorkArea
);
1725 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1727 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1729 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, WindowObject
, &rc
, TRUE
);
1731 if(ProcessParams
->dwFlags
& STARTF_USEPOSITION
)
1733 ProcessParams
->dwFlags
&= ~STARTF_USEPOSITION
;
1734 Pos
.x
= WorkArea
.left
+ ProcessParams
->dwX
;
1735 Pos
.y
= WorkArea
.top
+ ProcessParams
->dwY
;
1743 /* According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
1744 y is something else */
1745 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
1750 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1752 if(!CalculatedDefPosSize
)
1754 IntCalcDefPosSize(ParentWindow
, WindowObject
, &rc
, FALSE
);
1756 if(ProcessParams
->dwFlags
& STARTF_USESIZE
)
1758 ProcessParams
->dwFlags
&= ~STARTF_USESIZE
;
1759 Size
.cx
= ProcessParams
->dwXSize
;
1760 Size
.cy
= ProcessParams
->dwYSize
;
1764 Size
.cx
= rc
.right
- rc
.left
;
1765 Size
.cy
= rc
.bottom
- rc
.top
;
1768 /* move the window if necessary */
1770 Pos
.x
= max(rc
.left
, 0);
1772 Pos
.y
= max(rc
.top
, 0);
1777 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
1778 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1783 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1790 /* Initialize the window dimensions. */
1791 WindowObject
->WindowRect
.left
= Pos
.x
;
1792 WindowObject
->WindowRect
.top
= Pos
.y
;
1793 WindowObject
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1794 WindowObject
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1795 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1797 NtGdiOffsetRect(&(WindowObject
->WindowRect
), ParentWindow
->ClientRect
.left
,
1798 ParentWindow
->ClientRect
.top
);
1800 WindowObject
->ClientRect
= WindowObject
->WindowRect
;
1803 * Get the size and position of the window.
1805 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
1807 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1809 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
1810 WinPosGetMinMaxInfo(WindowObject
, &MaxSize
, &MaxPos
, &MinTrack
,
1812 if (MaxSize
.x
< nWidth
) nWidth
= MaxSize
.x
;
1813 if (MaxSize
.y
< nHeight
) nHeight
= MaxSize
.y
;
1814 if (nWidth
< MinTrack
.x
) nWidth
= MinTrack
.x
;
1815 if (nHeight
< MinTrack
.y
) nHeight
= MinTrack
.y
;
1816 if (nWidth
< 0) nWidth
= 0;
1817 if (nHeight
< 0) nHeight
= 0;
1820 WindowObject
->WindowRect
.left
= Pos
.x
;
1821 WindowObject
->WindowRect
.top
= Pos
.y
;
1822 WindowObject
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1823 WindowObject
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1824 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1826 NtGdiOffsetRect(&(WindowObject
->WindowRect
), ParentWindow
->ClientRect
.left
,
1827 ParentWindow
->ClientRect
.top
);
1829 WindowObject
->ClientRect
= WindowObject
->WindowRect
;
1831 /* FIXME: Initialize the window menu. */
1833 /* Send a NCCREATE message. */
1839 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
1840 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1841 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
1842 Result
= IntSendMessage(WindowObject
->Self
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
1845 /* FIXME: Cleanup. */
1846 if (NULL
!= ParentWindow
)
1848 IntReleaseWindowObject(ParentWindow
);
1850 DPRINT("IntCreateWindowEx(): NCCREATE message failed.\n");
1854 /* Calculate the non-client size. */
1855 MaxPos
.x
= WindowObject
->WindowRect
.left
;
1856 MaxPos
.y
= WindowObject
->WindowRect
.top
;
1857 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
1858 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
1859 Result
= WinPosGetNonClientSize(WindowObject
->Self
,
1860 &WindowObject
->WindowRect
,
1861 &WindowObject
->ClientRect
);
1862 NtGdiOffsetRect(&WindowObject
->WindowRect
,
1863 MaxPos
.x
- WindowObject
->WindowRect
.left
,
1864 MaxPos
.y
- WindowObject
->WindowRect
.top
);
1866 if (NULL
!= ParentWindow
)
1868 /* link the window into the parent's child list */
1869 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
1871 PWINDOW_OBJECT PrevSibling
;
1872 IntLockRelatives(ParentWindow
);
1873 if((PrevSibling
= ParentWindow
->LastChild
))
1874 IntReferenceWindowObject(PrevSibling
);
1875 IntUnLockRelatives(ParentWindow
);
1876 /* link window as bottom sibling */
1877 IntLinkWindow(WindowObject
, ParentWindow
, PrevSibling
/*prev sibling*/);
1879 IntReleaseWindowObject(PrevSibling
);
1883 /* link window as top sibling (but after topmost siblings) */
1884 PWINDOW_OBJECT InsertAfter
, Sibling
;
1885 if (0 == (dwExStyle
& WS_EX_TOPMOST
))
1887 IntLockRelatives(ParentWindow
);
1889 Sibling
= ParentWindow
->FirstChild
;
1890 while (NULL
!= Sibling
&& 0 != (Sibling
->ExStyle
& WS_EX_TOPMOST
))
1892 InsertAfter
= Sibling
;
1893 Sibling
= Sibling
->NextSibling
;
1895 IntUnLockRelatives(ParentWindow
);
1901 if (NULL
!= InsertAfter
)
1903 IntReferenceWindowObject(InsertAfter
);
1905 IntLinkWindow(WindowObject
, ParentWindow
, InsertAfter
/* prev sibling */);
1906 if (NULL
!= InsertAfter
)
1908 IntReleaseWindowObject(InsertAfter
);
1913 /* Send the WM_CREATE message. */
1914 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
1915 Result
= IntSendMessage(WindowObject
->Self
, WM_CREATE
, 0, (LPARAM
) &Cs
);
1916 if (Result
== (LRESULT
)-1)
1918 /* FIXME: Cleanup. */
1919 if (NULL
!= ParentWindow
)
1921 IntReleaseWindowObject(ParentWindow
);
1923 ClassDereferenceObject(ClassObject
);
1924 DPRINT("IntCreateWindowEx(): send CREATE message failed.\n");
1928 /* Send move and size messages. */
1929 if (!(WindowObject
->Flags
& WINDOWOBJECT_NEED_SIZE
))
1933 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
1935 if ((WindowObject
->ClientRect
.right
- WindowObject
->ClientRect
.left
) < 0 ||
1936 (WindowObject
->ClientRect
.bottom
- WindowObject
->ClientRect
.top
) < 0)
1938 DPRINT("Sending bogus WM_SIZE\n");
1941 lParam
= MAKE_LONG(WindowObject
->ClientRect
.right
-
1942 WindowObject
->ClientRect
.left
,
1943 WindowObject
->ClientRect
.bottom
-
1944 WindowObject
->ClientRect
.top
);
1945 IntSendMessage(WindowObject
->Self
, WM_SIZE
, SIZE_RESTORED
,
1948 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
1950 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1952 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
- ParentWindow
->ClientRect
.left
,
1953 WindowObject
->ClientRect
.top
- ParentWindow
->ClientRect
.top
);
1957 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
,
1958 WindowObject
->ClientRect
.top
);
1960 IntSendMessage(WindowObject
->Self
, WM_MOVE
, 0, lParam
);
1963 /* Show or maybe minimize or maximize the window. */
1964 if (WindowObject
->Style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1969 SwFlag
= (WindowObject
->Style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
1971 WinPosMinMaximize(WindowObject
, SwFlag
, &NewPos
);
1973 ((WindowObject
->Style
& WS_CHILD
) || NtUserGetActiveWindow()) ?
1974 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
1975 SWP_NOZORDER
| SWP_FRAMECHANGED
;
1976 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
1977 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
1978 WinPosSetWindowPos(WindowObject
->Self
, 0, NewPos
.left
, NewPos
.top
,
1979 NewPos
.right
, NewPos
.bottom
, SwFlag
);
1982 /* Notify the parent window of a new child. */
1983 if ((WindowObject
->Style
& WS_CHILD
) &&
1984 (!(WindowObject
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
1986 DPRINT("IntCreateWindow(): About to notify parent\n");
1987 IntSendMessage(ParentWindow
->Self
,
1989 MAKEWPARAM(WM_CREATE
, WindowObject
->IDMenu
),
1990 (LPARAM
)WindowObject
->Self
);
1993 if (NULL
!= ParentWindow
)
1995 IntReleaseWindowObject(ParentWindow
);
1998 /* Initialize and show the window's scrollbars */
1999 if (WindowObject
->Style
& WS_VSCROLL
)
2001 NtUserShowScrollBar(WindowObject
->Self
, SB_VERT
, TRUE
);
2003 if (WindowObject
->Style
& WS_HSCROLL
)
2005 NtUserShowScrollBar(WindowObject
->Self
, SB_HORZ
, TRUE
);
2008 if (dwStyle
& WS_VISIBLE
)
2010 DPRINT("IntCreateWindow(): About to show window\n");
2011 WinPosShowWindow(WindowObject
->Self
, dwShowMode
);
2014 DPRINT("IntCreateWindow(): = %X\n", Handle
);
2015 DPRINT("WindowObject->SystemMenu = 0x%x\n", WindowObject
->SystemMenu
);
2016 return((HWND
)Handle
);
2020 NtUserCreateWindowEx(DWORD dwExStyle
,
2021 PUNICODE_STRING UnsafeClassName
,
2022 PUNICODE_STRING UnsafeWindowName
,
2030 HINSTANCE hInstance
,
2033 BOOL bUnicodeWindow
)
2036 UNICODE_STRING WindowName
;
2037 UNICODE_STRING ClassName
;
2040 DPRINT("NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2042 /* Get the class name (string or atom) */
2043 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
2044 if (! NT_SUCCESS(Status
))
2046 SetLastNtError(Status
);
2049 if (! IS_ATOM(ClassName
.Buffer
))
2051 Status
= IntSafeCopyUnicodeString(&ClassName
, UnsafeClassName
);
2052 if (! NT_SUCCESS(Status
))
2054 SetLastNtError(Status
);
2059 /* safely copy the window name */
2060 if (NULL
!= UnsafeWindowName
)
2062 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
2063 if (! NT_SUCCESS(Status
))
2065 if (! IS_ATOM(ClassName
.Buffer
))
2067 RtlFreeUnicodeString(&ClassName
);
2069 SetLastNtError(Status
);
2075 RtlInitUnicodeString(&WindowName
, NULL
);
2078 NewWindow
= IntCreateWindowEx(dwExStyle
, &ClassName
, &WindowName
, dwStyle
, x
, y
, nWidth
, nHeight
,
2079 hWndParent
, hMenu
, hInstance
, lpParam
, dwShowMode
, bUnicodeWindow
);
2081 RtlFreeUnicodeString(&WindowName
);
2082 if (! IS_ATOM(ClassName
.Buffer
))
2084 RtlFreeUnicodeString(&ClassName
);
2094 NtUserDeferWindowPos(HDWP WinPosInfo
,
2096 HWND WndInsertAfter
,
2113 NtUserDestroyWindow(HWND Wnd
)
2115 PWINDOW_OBJECT Window
;
2118 Window
= IntGetWindowObject(Wnd
);
2124 /* Check for owner thread and desktop window */
2125 if ((Window
->OwnerThread
!= PsGetCurrentThread()) || IntIsDesktopWindow(Window
))
2127 IntReleaseWindowObject(Window
);
2128 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2132 /* Look whether the focus is within the tree of windows we will
2135 if (!WinPosShowWindow(Wnd
, SW_HIDE
))
2137 if (NtUserGetActiveWindow() == Wnd
)
2139 WinPosActivateOtherWindow(Window
);
2142 IntLockMessageQueue(Window
->MessageQueue
);
2143 if (Window
->MessageQueue
->ActiveWindow
== Window
->Self
)
2144 Window
->MessageQueue
->ActiveWindow
= NULL
;
2145 if (Window
->MessageQueue
->FocusWindow
== Window
->Self
)
2146 Window
->MessageQueue
->FocusWindow
= NULL
;
2147 if (Window
->MessageQueue
->CaptureWindow
== Window
->Self
)
2148 Window
->MessageQueue
->CaptureWindow
= NULL
;
2149 IntUnLockMessageQueue(Window
->MessageQueue
);
2153 if (HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hwnd
, 0, TRUE
))
2159 isChild
= (0 != (Window
->Style
& WS_CHILD
));
2164 if (! USER_IsExitingThread(GetCurrentThreadId()))
2166 send_parent_notify(hwnd
, WM_DESTROY
);
2169 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2171 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2172 /* FIXME: clean up palette - see "Internals" p.352 */
2176 if (!IntIsWindow(Wnd
))
2181 /* Recursively destroy owned windows */
2186 BOOL GotOne
= FALSE
;
2189 PWINDOW_OBJECT Child
, Desktop
;
2191 Desktop
= IntGetWindowObject(IntGetDesktopWindow());
2192 Children
= IntWinListChildren(Desktop
);
2193 IntReleaseWindowObject(Desktop
);
2196 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2198 Child
= IntGetWindowObject(*ChildHandle
);
2201 IntLockRelatives(Child
);
2202 if (Child
->Owner
!= Window
->Self
)
2204 IntUnLockRelatives(Child
);
2205 IntReleaseWindowObject(Child
);
2208 IntUnLockRelatives(Child
);
2209 if (IntWndBelongsToThread(Child
, PsGetWin32Thread()))
2211 IntReleaseWindowObject(Child
);
2212 NtUserDestroyWindow(*ChildHandle
);
2216 IntLockRelatives(Child
);
2217 if (Child
->Owner
!= NULL
)
2219 Child
->Owner
= NULL
;
2221 IntUnLockRelatives(Child
);
2222 IntReleaseWindowObject(Child
);
2224 ExFreePool(Children
);
2233 if (!IntIsWindow(Wnd
))
2235 IntReleaseWindowObject(Window
);
2239 /* Destroy the window storage */
2240 IntDestroyWindow(Window
, PsGetWin32Process(), PsGetWin32Thread(), TRUE
);
2242 IntReleaseWindowObject(Window
);
2252 NtUserDrawMenuBarTemp(
2259 /* we'll use this function just for caching the menu bar */
2269 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2282 NtUserFillWindow(DWORD Unknown0
,
2294 IntFindWindow(PWINDOW_OBJECT Parent
,
2295 PWINDOW_OBJECT ChildAfter
,
2296 PWNDCLASS_OBJECT ClassObject
,
2297 PUNICODE_STRING WindowName
)
2299 BOOL CheckWindowName
;
2305 CheckWindowName
= (WindowName
&& (WindowName
->Length
> 0));
2307 if((List
= IntWinListChildren(Parent
)))
2312 /* skip handles before and including ChildAfter */
2313 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->Self
));
2316 /* search children */
2319 PWINDOW_OBJECT Child
;
2320 if(!(Child
= IntGetWindowObject(*(phWnd
++))))
2325 /* Do not send WM_GETTEXT messages in the kernel mode version!
2326 The user mode version however calls GetWindowText() which will
2327 send WM_GETTEXT messages to windows belonging to its processes */
2328 if(((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(WindowName
, &(Child
->WindowName
), FALSE
))) &&
2329 (!ClassObject
|| (ClassObject
&& (Child
->Class
== ClassObject
))))
2331 ((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(WindowName
, &(Child
->WindowName
), FALSE
))) &&
2332 (!ClassObject
|| (ClassObject
&& (Child
->Class
== ClassObject
)))))
2335 IntReleaseWindowObject(Child
);
2339 IntReleaseWindowObject(Child
);
2349 * Searches a window's children for a window with the specified
2352 * hwndParent = The window whose childs are to be searched.
2354 * HWND_MESSAGE = message-only windows
2356 * hwndChildAfter = Search starts after this child window.
2357 * NULL = start from beginning
2359 * ucClassName = Class name to search for
2360 * Reguired parameter.
2362 * ucWindowName = Window name
2363 * ->Buffer == NULL = don't care
2366 * The HWND of the window if it was found, otherwise NULL
2372 NtUserFindWindowEx(HWND hwndParent
,
2373 HWND hwndChildAfter
,
2374 PUNICODE_STRING ucClassName
,
2375 PUNICODE_STRING ucWindowName
)
2377 PWINDOW_OBJECT Parent
, ChildAfter
;
2378 UNICODE_STRING ClassName
, WindowName
;
2380 HWND Desktop
, Ret
= NULL
;
2381 PWNDCLASS_OBJECT ClassObject
= NULL
;
2384 Desktop
= IntGetDesktopWindow();
2386 if(hwndParent
== NULL
)
2387 hwndParent
= Desktop
;
2389 else if(hwndParent == HWND_MESSAGE)
2391 hwndParent = IntGetMessageWindow();
2395 if(!(Parent
= IntGetWindowObject(hwndParent
)))
2397 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2402 if(hwndChildAfter
&& !(ChildAfter
= IntGetWindowObject(hwndChildAfter
)))
2404 IntReleaseWindowObject(hwndParent
);
2405 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2409 /* copy the window name */
2410 Status
= IntSafeCopyUnicodeString(&WindowName
, ucWindowName
);
2411 if(!NT_SUCCESS(Status
))
2413 SetLastNtError(Status
);
2417 /* safely copy the class name */
2418 Status
= MmCopyFromCaller(&ClassName
, ucClassName
, sizeof(UNICODE_STRING
));
2419 if(!NT_SUCCESS(Status
))
2421 SetLastNtError(Status
);
2424 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2427 /* safely copy the class name string (NULL terminated because class-lookup
2429 buf
= ExAllocatePoolWithTag(PagedPool
, ClassName
.Length
+ sizeof(WCHAR
), TAG_STRING
);
2432 SetLastWin32Error(STATUS_INSUFFICIENT_RESOURCES
);
2435 Status
= MmCopyFromCaller(buf
, ClassName
.Buffer
, ClassName
.Length
);
2436 if(!NT_SUCCESS(Status
))
2439 SetLastNtError(Status
);
2442 ClassName
.Buffer
= buf
;
2443 /* make sure the string is null-terminated */
2444 buf
+= ClassName
.Length
/ sizeof(WCHAR
);
2448 /* find the class object */
2449 if(ClassName
.Buffer
)
2451 /* this expects the string in ClassName to be NULL-terminated! */
2452 ClassFound
= ClassReferenceClassByNameOrAtom(&ClassObject
, ClassName
.Buffer
, NULL
);
2455 if (IS_ATOM(ClassName
.Buffer
))
2456 DPRINT1("Window class not found (%lx)\n", (ULONG_PTR
)ClassName
.Buffer
);
2458 DPRINT1("Window class not found (%S)\n", ClassName
.Buffer
);
2459 SetLastWin32Error(ERROR_CLASS_DOES_NOT_EXIST
);
2464 if(Parent
->Self
== Desktop
)
2467 PWINDOW_OBJECT TopLevelWindow
;
2468 BOOL CheckWindowName
;
2470 /* windows searches through all top-level windows if the parent is the desktop
2473 if((List
= IntWinListChildren(Parent
)))
2479 /* skip handles before and including ChildAfter */
2480 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->Self
));
2483 CheckWindowName
= WindowName
.Length
> 0;
2485 /* search children */
2488 if(!(TopLevelWindow
= IntGetWindowObject(*(phWnd
++))))
2493 /* Do not send WM_GETTEXT messages in the kernel mode version!
2494 The user mode version however calls GetWindowText() which will
2495 send WM_GETTEXT messages to windows belonging to its processes */
2496 if(((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(&WindowName
, &(TopLevelWindow
->WindowName
), FALSE
))) &&
2497 (!ClassObject
|| (ClassObject
&& (TopLevelWindow
->Class
== ClassObject
))))
2499 ((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(&WindowName
, &(TopLevelWindow
->WindowName
), FALSE
))) &&
2500 (!ClassObject
|| (ClassObject
&& (TopLevelWindow
->Class
== ClassObject
)))))
2502 Ret
= TopLevelWindow
->Self
;
2503 IntReleaseWindowObject(TopLevelWindow
);
2507 if(IntFindWindow(TopLevelWindow
, NULL
, ClassObject
, &WindowName
))
2509 /* window returns the handle of the top-level window, in case it found
2511 Ret
= TopLevelWindow
->Self
;
2512 IntReleaseWindowObject(TopLevelWindow
);
2516 IntReleaseWindowObject(TopLevelWindow
);
2522 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassObject
, &WindowName
);
2525 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2527 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2528 search the message-only windows. Should this also be done if
2529 Parent is the desktop window??? */
2530 PWINDOW_OBJECT MsgWindows
;
2532 if((MsgWindows
= IntGetWindowObject(IntGetMessageWindow())))
2534 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassObject
, &WindowName
);
2535 IntReleaseWindowObject(MsgWindows
);
2540 ClassDereferenceObject(ClassObject
);
2543 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2544 ExFreePool(ClassName
.Buffer
);
2547 RtlFreeUnicodeString(&WindowName
);
2551 IntReleaseWindowObject(ChildAfter
);
2552 IntReleaseWindowObject(Parent
);
2562 NtUserFlashWindowEx(DWORD Unknown0
)
2574 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2576 PWINDOW_OBJECT Wnd
, WndAncestor
, Parent
;
2579 if (hWnd
== IntGetDesktopWindow())
2584 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2586 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2594 WndAncestor
= IntGetParentObject(Wnd
);
2607 if(!(Parent
= IntGetParentObject(WndAncestor
)))
2611 if(IntIsDesktopWindow(Parent
))
2613 IntReleaseWindowObject(Parent
);
2617 IntReleaseWindowObject(tmp
);
2618 WndAncestor
= Parent
;
2626 IntReferenceWindowObject(WndAncestor
);
2631 Parent
= IntGetParent(WndAncestor
);
2632 IntReleaseWindowObject(Old
);
2637 WndAncestor
= Parent
;
2644 IntReleaseWindowObject(Wnd
);
2649 hWndAncestor
= (WndAncestor
? WndAncestor
->Self
: NULL
);
2650 IntReleaseWindowObject(Wnd
);
2652 if(WndAncestor
&& (WndAncestor
!= Wnd
))
2653 IntReleaseWindowObject(WndAncestor
);
2655 return hWndAncestor
;
2660 * Returns client window rectangle relative to the upper-left corner of client area.
2662 * \param hWnd window handle.
2663 * \param Rect pointer to the buffer where the coordinates are returned.
2670 NtUserGetClientRect(HWND hWnd
, LPRECT Rect
)
2672 PWINDOW_OBJECT WindowObject
;
2675 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
2677 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2681 IntGetClientRect(WindowObject
, &SafeRect
);
2682 IntReleaseWindowObject(WindowObject
);
2684 if(!NT_SUCCESS(MmCopyToCaller(Rect
, &SafeRect
, sizeof(RECT
))))
2696 NtUserGetDesktopWindow()
2698 return IntGetDesktopWindow();
2706 NtUserGetInternalWindowPos(DWORD Unknown0
,
2720 NtUserGetLastActivePopup(HWND hWnd
)
2723 * This code can't work, because hWndLastPopup member of WINDOW_OBJECT is
2724 * not changed anywhere.
2725 * -- Filip, 01/nov/2003
2731 IntAcquireWinLockShared();
2733 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2735 IntReleaseWinLock();
2736 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2740 hWndLastPopup
= Wnd
->hWndLastPopup
;
2742 IntReleaseWinLock();
2744 return hWndLastPopup
;
2753 * The NtUserGetParent function retrieves a handle to the specified window's
2757 * Note that, despite its name, this function can return an owner window
2758 * instead of a parent window.
2765 NtUserGetParent(HWND hWnd
)
2767 PWINDOW_OBJECT Wnd
, WndParent
;
2768 HWND hWndParent
= NULL
;
2770 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2772 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2776 WndParent
= IntGetParent(Wnd
);
2779 hWndParent
= WndParent
->Self
;
2780 IntReleaseWindowObject(WndParent
);
2783 IntReleaseWindowObject(Wnd
);
2791 * The NtUserSetParent function changes the parent window of the specified
2795 * The new parent window and the child window must belong to the same
2796 * application. If the window identified by the hWndChild parameter is
2797 * visible, the system performs the appropriate redrawing and repainting.
2798 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
2799 * or WS_POPUP window styles of the window whose parent is being changed.
2806 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2808 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
2809 HWND hWndOldParent
= NULL
;
2811 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
2813 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2817 if (hWndChild
== IntGetDesktopWindow())
2819 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2825 if (!(WndParent
= IntGetWindowObject(hWndNewParent
)))
2827 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2833 if (!(WndParent
= IntGetWindowObject(IntGetDesktopWindow())))
2835 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2840 if (!(Wnd
= IntGetWindowObject(hWndChild
)))
2842 IntReleaseWindowObject(WndParent
);
2843 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2847 WndOldParent
= IntSetParent(Wnd
, WndParent
);
2851 hWndOldParent
= WndOldParent
->Self
;
2852 IntReleaseWindowObject(WndOldParent
);
2855 IntReleaseWindowObject(Wnd
);
2856 IntReleaseWindowObject(WndParent
);
2858 return hWndOldParent
;
2862 * NtUserGetShellWindow
2864 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
2871 NtUserGetShellWindow()
2873 PWINSTATION_OBJECT WinStaObject
;
2876 NTSTATUS Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
2881 if (!NT_SUCCESS(Status
))
2883 SetLastNtError(Status
);
2887 Ret
= (HWND
)WinStaObject
->ShellWindow
;
2889 ObDereferenceObject(WinStaObject
);
2894 * NtUserSetShellWindowEx
2896 * This is undocumented function to set global shell window. The global
2897 * shell window has special handling of window position.
2904 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
2906 PWINSTATION_OBJECT WinStaObject
;
2908 NTSTATUS Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
2913 if (!NT_SUCCESS(Status
))
2915 SetLastNtError(Status
);
2920 * Test if we are permitted to change the shell window.
2922 if (WinStaObject
->ShellWindow
)
2924 ObDereferenceObject(WinStaObject
);
2929 * Move shell window into background.
2931 if (hwndListView
&& hwndListView
!= hwndShell
)
2934 * Disabled for now to get Explorer working.
2935 * -- Filip, 01/nov/2003
2938 WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2941 if (NtUserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2943 ObDereferenceObject(WinStaObject
);
2948 if (NtUserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2950 ObDereferenceObject(WinStaObject
);
2954 WinPosSetWindowPos(hwndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2956 WinStaObject
->ShellWindow
= hwndShell
;
2957 WinStaObject
->ShellListView
= hwndListView
;
2959 ObDereferenceObject(WinStaObject
);
2964 * NtUserGetSystemMenu
2966 * The NtUserGetSystemMenu function allows the application to access the
2967 * window menu (also known as the system menu or the control menu) for
2968 * copying and modifying.
2972 * Handle to the window that will own a copy of the window menu.
2974 * Specifies the action to be taken. If this parameter is FALSE,
2975 * NtUserGetSystemMenu returns a handle to the copy of the window menu
2976 * currently in use. The copy is initially identical to the window menu
2977 * but it can be modified.
2978 * If this parameter is TRUE, GetSystemMenu resets the window menu back
2979 * to the default state. The previous window menu, if any, is destroyed.
2982 * If the bRevert parameter is FALSE, the return value is a handle to a
2983 * copy of the window menu. If the bRevert parameter is TRUE, the return
2991 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
2994 PWINDOW_OBJECT WindowObject
;
2995 PMENU_OBJECT MenuObject
;
2997 WindowObject
= IntGetWindowObject((HWND
)hWnd
);
2998 if (WindowObject
== NULL
)
3000 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3004 MenuObject
= IntGetSystemMenu(WindowObject
, bRevert
, FALSE
);
3007 Result
= MenuObject
->MenuInfo
.Self
;
3008 IntReleaseMenuObject(MenuObject
);
3011 IntReleaseWindowObject(WindowObject
);
3016 * NtUserSetSystemMenu
3023 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3025 BOOL Result
= FALSE
;
3026 PWINDOW_OBJECT WindowObject
;
3027 PMENU_OBJECT MenuObject
;
3029 WindowObject
= IntGetWindowObject(hWnd
);
3032 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3039 * Assign new menu handle.
3041 MenuObject
= IntGetMenuObject(hMenu
);
3044 IntReleaseWindowObject(WindowObject
);
3045 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
3049 Result
= IntSetSystemMenu(WindowObject
, MenuObject
);
3051 IntReleaseMenuObject(MenuObject
);
3054 IntReleaseWindowObject(WindowObject
);
3062 * The NtUserGetWindow function retrieves a handle to a window that has the
3063 * specified relationship (Z order or owner) to the specified window.
3070 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3072 PWINDOW_OBJECT WindowObject
, Parent
;
3073 HWND hWndResult
= NULL
;
3075 if (!(WindowObject
= IntGetWindowObject(hWnd
)))
3077 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3081 switch (Relationship
)
3084 if((Parent
= IntGetParentObject(WindowObject
)))
3086 IntLockRelatives(Parent
);
3087 if (Parent
->FirstChild
)
3088 hWndResult
= Parent
->FirstChild
->Self
;
3089 IntUnLockRelatives(Parent
);
3090 IntReleaseWindowObject(Parent
);
3095 if((Parent
= IntGetParentObject(WindowObject
)))
3097 IntLockRelatives(Parent
);
3098 if (Parent
->LastChild
)
3099 hWndResult
= Parent
->LastChild
->Self
;
3100 IntUnLockRelatives(Parent
);
3101 IntReleaseWindowObject(Parent
);
3106 IntLockRelatives(WindowObject
);
3107 if (WindowObject
->NextSibling
)
3108 hWndResult
= WindowObject
->NextSibling
->Self
;
3109 IntUnLockRelatives(WindowObject
);
3113 IntLockRelatives(WindowObject
);
3114 if (WindowObject
->PrevSibling
)
3115 hWndResult
= WindowObject
->PrevSibling
->Self
;
3116 IntUnLockRelatives(WindowObject
);
3120 IntLockRelatives(WindowObject
);
3121 if((Parent
= IntGetWindowObject(WindowObject
->Owner
)))
3123 hWndResult
= Parent
->Self
;
3124 IntReleaseWindowObject(Parent
);
3126 IntUnLockRelatives(WindowObject
);
3129 IntLockRelatives(WindowObject
);
3130 if (WindowObject
->FirstChild
)
3131 hWndResult
= WindowObject
->FirstChild
->Self
;
3132 IntUnLockRelatives(WindowObject
);
3136 IntReleaseWindowObject(WindowObject
);
3142 * NtUserGetWindowLong
3144 * The NtUserGetWindowLong function retrieves information about the specified
3145 * window. The function also retrieves the 32-bit (long) value at the
3146 * specified offset into the extra window memory.
3153 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3155 PWINDOW_OBJECT WindowObject
, Parent
;
3158 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3160 WindowObject
= IntGetWindowObject(hWnd
);
3161 if (WindowObject
== NULL
)
3163 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3168 * Only allow CSRSS to mess with the desktop window
3170 if (hWnd
== IntGetDesktopWindow()
3171 && WindowObject
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3173 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3177 if ((INT
)Index
>= 0)
3179 if ((Index
+ sizeof(LONG
)) > WindowObject
->ExtraDataSize
)
3181 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3184 Result
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
3191 Result
= WindowObject
->ExStyle
;
3195 Result
= WindowObject
->Style
;
3200 Result
= (LONG
) WindowObject
->WndProcA
;
3202 Result
= (LONG
) WindowObject
->WndProcW
;
3206 Result
= (LONG
) WindowObject
->Instance
;
3209 case GWL_HWNDPARENT
:
3210 IntLockRelatives(WindowObject
);
3211 Parent
= IntGetWindowObject(WindowObject
->Parent
);
3212 IntUnLockRelatives(WindowObject
);
3215 if (Parent
&& Parent
->Self
== IntGetDesktopWindow())
3216 Result
= (LONG
) NtUserGetWindow(WindowObject
->Self
, GW_OWNER
);
3218 Result
= (LONG
) Parent
->Self
;
3219 IntReleaseWindowObject(Parent
);
3224 Result
= (LONG
) WindowObject
->IDMenu
;
3228 Result
= WindowObject
->UserData
;
3232 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3233 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3239 IntReleaseWindowObject(WindowObject
);
3245 * NtUserSetWindowLong
3247 * The NtUserSetWindowLong function changes an attribute of the specified
3248 * window. The function also sets the 32-bit (long) value at the specified
3249 * offset into the extra window memory.
3256 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3258 PWINDOW_OBJECT WindowObject
, Parent
;
3259 PW32PROCESS Process
;
3260 PWINSTATION_OBJECT WindowStation
;
3264 if (hWnd
== IntGetDesktopWindow())
3266 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3270 WindowObject
= IntGetWindowObject(hWnd
);
3271 if (WindowObject
== NULL
)
3273 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3277 if ((INT
)Index
>= 0)
3279 if ((Index
+ sizeof(LONG
)) > WindowObject
->ExtraDataSize
)
3281 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3282 IntReleaseWindowObject(WindowObject
);
3285 OldValue
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
3286 *((LONG
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
3293 OldValue
= (LONG
) WindowObject
->ExStyle
;
3294 Style
.styleOld
= OldValue
;
3295 Style
.styleNew
= NewValue
;
3298 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3300 Process
= WindowObject
->OwnerThread
->ThreadsProcess
->Win32Process
;
3301 WindowStation
= Process
->WindowStation
;
3304 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3305 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3308 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3309 WindowObject
->ExStyle
= (DWORD
)Style
.styleNew
;
3310 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3314 OldValue
= (LONG
) WindowObject
->Style
;
3315 Style
.styleOld
= OldValue
;
3316 Style
.styleNew
= NewValue
;
3317 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3318 WindowObject
->Style
= (DWORD
)Style
.styleNew
;
3319 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3323 /* FIXME: should check if window belongs to current process */
3326 OldValue
= (LONG
) WindowObject
->WndProcA
;
3327 WindowObject
->WndProcA
= (WNDPROC
) NewValue
;
3328 WindowObject
->WndProcW
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,FALSE
);
3329 WindowObject
->Unicode
= FALSE
;
3333 OldValue
= (LONG
) WindowObject
->WndProcW
;
3334 WindowObject
->WndProcW
= (WNDPROC
) NewValue
;
3335 WindowObject
->WndProcA
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,TRUE
);
3336 WindowObject
->Unicode
= TRUE
;
3341 OldValue
= (LONG
) WindowObject
->Instance
;
3342 WindowObject
->Instance
= (HINSTANCE
) NewValue
;
3345 case GWL_HWNDPARENT
:
3346 Parent
= IntGetParentObject(WindowObject
);
3347 if (Parent
&& (Parent
->Self
== IntGetDesktopWindow()))
3348 OldValue
= (LONG
) IntSetOwner(WindowObject
->Self
, (HWND
) NewValue
);
3350 OldValue
= (LONG
) NtUserSetParent(WindowObject
->Self
, (HWND
) NewValue
);
3352 IntReleaseWindowObject(Parent
);
3356 OldValue
= (LONG
) WindowObject
->IDMenu
;
3357 WindowObject
->IDMenu
= (UINT
) NewValue
;
3361 OldValue
= WindowObject
->UserData
;
3362 WindowObject
->UserData
= NewValue
;
3366 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3367 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3373 IntReleaseWindowObject(WindowObject
);
3379 * NtUserSetWindowWord
3381 * Legacy function similar to NtUserSetWindowLong.
3388 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3390 PWINDOW_OBJECT WindowObject
;
3397 case GWL_HWNDPARENT
:
3398 return NtUserSetWindowLong(hWnd
, Index
, (UINT
)NewValue
, TRUE
);
3402 SetLastWin32Error(ERROR_INVALID_INDEX
);
3407 WindowObject
= IntGetWindowObject(hWnd
);
3408 if (WindowObject
== NULL
)
3410 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3414 if (Index
> WindowObject
->ExtraDataSize
- sizeof(WORD
))
3416 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3417 IntReleaseWindowObject(WindowObject
);
3421 OldValue
= *((WORD
*)(WindowObject
->ExtraData
+ Index
));
3422 *((WORD
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
3424 IntReleaseWindowObject(WindowObject
);
3433 NtUserGetWindowPlacement(HWND hWnd
,
3434 WINDOWPLACEMENT
*lpwndpl
)
3436 PWINDOW_OBJECT WindowObject
;
3437 PINTERNALPOS InternalPos
;
3439 WINDOWPLACEMENT Safepl
;
3442 WindowObject
= IntGetWindowObject(hWnd
);
3443 if (WindowObject
== NULL
)
3445 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3449 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3450 if(!NT_SUCCESS(Status
))
3452 SetLastNtError(Status
);
3453 IntReleaseWindowObject(WindowObject
);
3456 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3458 IntReleaseWindowObject(WindowObject
);
3463 Safepl
.showCmd
= ((WindowObject
->Flags
& WINDOWOBJECT_RESTOREMAX
) ? SW_MAXIMIZE
: SW_SHOWNORMAL
);
3465 Size
.x
= WindowObject
->WindowRect
.left
;
3466 Size
.y
= WindowObject
->WindowRect
.top
;
3467 InternalPos
= WinPosInitInternalPos(WindowObject
, &Size
,
3468 &WindowObject
->WindowRect
);
3471 Safepl
.rcNormalPosition
= InternalPos
->NormalRect
;
3472 Safepl
.ptMinPosition
= InternalPos
->IconPos
;
3473 Safepl
.ptMaxPosition
= InternalPos
->MaxPos
;
3477 IntReleaseWindowObject(WindowObject
);
3481 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3482 if(!NT_SUCCESS(Status
))
3484 SetLastNtError(Status
);
3485 IntReleaseWindowObject(WindowObject
);
3489 IntReleaseWindowObject(WindowObject
);
3495 * Return the dimension of the window in the screen coordinates.
3496 * \param hWnd window handle.
3497 * \param Rect pointer to the buffer where the coordinates are returned.
3503 NtUserGetWindowRect(HWND hWnd
, LPRECT Rect
)
3508 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3510 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3513 Status
= MmCopyToCaller(Rect
, &Wnd
->WindowRect
, sizeof(RECT
));
3514 if (!NT_SUCCESS(Status
))
3516 IntReleaseWindowObject(Wnd
);
3517 SetLastNtError(Status
);
3521 IntReleaseWindowObject(Wnd
);
3530 NtUserGetWindowThreadProcessId(HWND hWnd
, LPDWORD UnsafePid
)
3535 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3537 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3541 tid
= (DWORD
)IntGetWndThreadId(Wnd
);
3542 pid
= (DWORD
)IntGetWndProcessId(Wnd
);
3544 if (UnsafePid
) MmCopyToCaller(UnsafePid
, &pid
, sizeof(DWORD
));
3554 NtUserLockWindowUpdate(DWORD Unknown0
)
3574 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3575 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3576 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3580 QueryWindow based on KJK::Hyperion and James Tabor.
3582 0 = QWUniqueProcessId
3583 1 = QWUniqueThreadId
3584 4 = QWIsHung Implements IsHungAppWindow found
3587 9 = QWKillWindow When I called this with hWnd ==
3588 DesktopWindow, it shutdown the system
3595 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3597 PWINDOW_OBJECT Window
= IntGetWindowObject(hWnd
);
3602 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3608 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3609 Result
= (DWORD
)IntGetWndProcessId(Window
);
3612 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3613 Result
= (DWORD
)IntGetWndThreadId(Window
);
3616 case QUERY_WINDOW_ISHUNG
:
3617 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
3621 Result
= (DWORD
)NULL
;
3625 IntReleaseWindowObject(Window
);
3635 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3649 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3651 UNICODE_STRING SafeMessageName
;
3655 if(MessageNameUnsafe
== NULL
)
3657 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3661 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3662 if(!NT_SUCCESS(Status
))
3664 SetLastNtError(Status
);
3668 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3670 RtlFreeUnicodeString(&SafeMessageName
);
3679 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3692 NtUserSetInternalWindowPos(DWORD Unknown0
,
3708 NtUserSetLayeredWindowAttributes(DWORD Unknown0
,
3723 NtUserSetLogonNotifyWindow(DWORD Unknown0
)
3740 PWINDOW_OBJECT WindowObject
;
3743 WindowObject
= IntGetWindowObject((HWND
) Wnd
);
3744 if (NULL
== WindowObject
)
3746 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3750 if (! IntSetMenu(WindowObject
, Menu
, &Changed
))
3752 IntReleaseWindowObject(WindowObject
);
3756 IntReleaseWindowObject(WindowObject
);
3758 if (Changed
&& Repaint
)
3760 WinPosSetWindowPos(Wnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3761 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3772 NtUserSetWindowFNID(DWORD Unknown0
,
3786 NtUserSetWindowPlacement(HWND hWnd
,
3787 WINDOWPLACEMENT
*lpwndpl
)
3789 PWINDOW_OBJECT WindowObject
;
3790 WINDOWPLACEMENT Safepl
;
3793 WindowObject
= IntGetWindowObject(hWnd
);
3794 if (WindowObject
== NULL
)
3796 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3799 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3800 if(!NT_SUCCESS(Status
))
3802 SetLastNtError(Status
);
3803 IntReleaseWindowObject(WindowObject
);
3806 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3808 IntReleaseWindowObject(WindowObject
);
3812 if ((WindowObject
->Style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
3814 WinPosSetWindowPos(WindowObject
->Self
, NULL
,
3815 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
3816 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
3817 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
3818 SWP_NOZORDER
| SWP_NOACTIVATE
);
3821 /* FIXME - change window status */
3822 WinPosShowWindow(WindowObject
->Self
, Safepl
.showCmd
);
3824 if (WindowObject
->InternalPos
== NULL
)
3825 WindowObject
->InternalPos
= ExAllocatePoolWithTag(PagedPool
, sizeof(INTERNALPOS
), TAG_WININTLIST
);
3826 WindowObject
->InternalPos
->NormalRect
= Safepl
.rcNormalPosition
;
3827 WindowObject
->InternalPos
->IconPos
= Safepl
.ptMinPosition
;
3828 WindowObject
->InternalPos
->MaxPos
= Safepl
.ptMaxPosition
;
3830 IntReleaseWindowObject(WindowObject
);
3841 HWND hWndInsertAfter
,
3848 return WinPosSetWindowPos(hWnd
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
3853 IntGetWindowRgn(HWND hWnd
, HRGN hRgn
)
3856 PWINDOW_OBJECT WindowObject
;
3860 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
3862 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3867 IntReleaseWindowObject(WindowObject
);
3871 /* Create a new window region using the window rectangle */
3872 VisRgn
= UnsafeIntCreateRectRgnIndirect(&WindowObject
->WindowRect
);
3873 NtGdiOffsetRgn(VisRgn
, -WindowObject
->WindowRect
.left
, -WindowObject
->WindowRect
.top
);
3874 /* if there's a region assigned to the window, combine them both */
3875 if(WindowObject
->WindowRegion
&& !(WindowObject
->Style
& WS_MINIMIZE
))
3876 NtGdiCombineRgn(VisRgn
, VisRgn
, WindowObject
->WindowRegion
, RGN_AND
);
3877 /* Copy the region into hRgn */
3878 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
3880 if((pRgn
= RGNDATA_LockRgn(hRgn
)))
3882 Ret
= pRgn
->rdh
.iType
;
3883 RGNDATA_UnlockRgn(hRgn
);
3888 NtGdiDeleteObject(VisRgn
);
3890 IntReleaseWindowObject(WindowObject
);
3895 IntGetWindowRgnBox(HWND hWnd
, RECT
*Rect
)
3898 PWINDOW_OBJECT WindowObject
;
3902 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
3904 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3909 IntReleaseWindowObject(WindowObject
);
3913 /* Create a new window region using the window rectangle */
3914 VisRgn
= UnsafeIntCreateRectRgnIndirect(&WindowObject
->WindowRect
);
3915 NtGdiOffsetRgn(VisRgn
, -WindowObject
->WindowRect
.left
, -WindowObject
->WindowRect
.top
);
3916 /* if there's a region assigned to the window, combine them both */
3917 if(WindowObject
->WindowRegion
&& !(WindowObject
->Style
& WS_MINIMIZE
))
3918 NtGdiCombineRgn(VisRgn
, VisRgn
, WindowObject
->WindowRegion
, RGN_AND
);
3920 if((pRgn
= RGNDATA_LockRgn(VisRgn
)))
3922 Ret
= pRgn
->rdh
.iType
;
3923 *Rect
= pRgn
->rdh
.rcBound
;
3924 RGNDATA_UnlockRgn(VisRgn
);
3929 NtGdiDeleteObject(VisRgn
);
3931 IntReleaseWindowObject(WindowObject
);
3945 PWINDOW_OBJECT WindowObject
;
3947 WindowObject
= IntGetWindowObject(hWnd
);
3948 if (WindowObject
== NULL
)
3950 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3954 /* FIXME - Verify if hRgn is a valid handle!!!!
3955 Propably make this operation thread-safe, but maybe it's not necessary */
3957 if(WindowObject
->WindowRegion
)
3959 /* Delete no longer needed region handle */
3960 NtGdiDeleteObject(WindowObject
->WindowRegion
);
3962 WindowObject
->WindowRegion
= hRgn
;
3964 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
3968 IntRedrawWindow(WindowObject
, NULL
, NULL
, RDW_INVALIDATE
);
3971 IntReleaseWindowObject(WindowObject
);
3980 NtUserShowWindow(HWND hWnd
,
3983 return WinPosShowWindow(hWnd
, nCmdShow
);
3991 NtUserShowWindowAsync(DWORD Unknown0
,
4004 NtUserUpdateLayeredWindow(DWORD Unknown0
,
4024 NtUserValidateRect(HWND hWnd
, const RECT
* Rect
)
4026 return (VOID
)NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
4034 NtUserWindowFromPoint(LONG X
, LONG Y
)
4038 PWINDOW_OBJECT DesktopWindow
, Window
= NULL
;
4040 if ((DesktopWindow
= IntGetWindowObject(IntGetDesktopWindow())))
4047 Hit
= WinPosWindowFromPoint(DesktopWindow
, PsGetWin32Thread()->MessageQueue
, &pt
, &Window
);
4052 IntReleaseWindowObject(Window
);
4053 IntReleaseWindowObject(DesktopWindow
);
4057 IntReleaseWindowObject(DesktopWindow
);
4067 * Undocumented function that is called from DefWindowProc to set
4075 NtUserDefSetText(HWND WindowHandle
, PUNICODE_STRING WindowText
)
4077 PWINDOW_OBJECT WindowObject
;
4078 UNICODE_STRING SafeText
;
4081 WindowObject
= IntGetWindowObject(WindowHandle
);
4084 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4090 Status
= IntSafeCopyUnicodeString(&SafeText
, WindowText
);
4091 if(!NT_SUCCESS(Status
))
4093 SetLastNtError(Status
);
4094 IntReleaseWindowObject(WindowObject
);
4100 RtlInitUnicodeString(&SafeText
, NULL
);
4103 /* FIXME - do this thread-safe! otherwise one could crash here! */
4104 RtlFreeUnicodeString(&WindowObject
->WindowName
);
4106 WindowObject
->WindowName
= SafeText
;
4108 IntReleaseWindowObject(WindowObject
);
4113 * NtUserInternalGetWindowText
4120 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4122 PWINDOW_OBJECT WindowObject
;
4126 if(lpString
&& (nMaxCount
<= 1))
4128 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4132 WindowObject
= IntGetWindowObject(hWnd
);
4135 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4139 /* FIXME - do this thread-safe! otherwise one could crash here! */
4140 Result
= WindowObject
->WindowName
.Length
/ sizeof(WCHAR
);
4143 const WCHAR Terminator
= L
'\0';
4145 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4147 Copy
= min(nMaxCount
- 1, Result
);
4150 Status
= MmCopyToCaller(Buffer
, WindowObject
->WindowName
.Buffer
, Copy
* sizeof(WCHAR
));
4151 if(!NT_SUCCESS(Status
))
4153 SetLastNtError(Status
);
4154 IntReleaseWindowObject(WindowObject
);
4160 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4161 if(!NT_SUCCESS(Status
))
4163 SetLastNtError(Status
);
4164 IntReleaseWindowObject(WindowObject
);
4171 IntReleaseWindowObject(WindowObject
);
4176 NtUserDereferenceWndProcHandle(WNDPROC wpHandle
, WndProcHandle
*Data
)
4178 WndProcHandle Entry
;
4179 if (((DWORD
)wpHandle
& 0xFFFF0000) == 0xFFFF0000)
4181 Entry
= WndProcHandlesArray
[(DWORD
)wpHandle
& 0x0000FFFF];
4182 Data
->WindowProc
= Entry
.WindowProc
;
4183 Data
->IsUnicode
= Entry
.IsUnicode
;
4184 Data
->ProcessID
= Entry
.ProcessID
;
4193 IntAddWndProcHandle(WNDPROC WindowProc
, BOOL IsUnicode
)
4198 WndProcHandle
*OldArray
;
4201 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4203 if (WndProcHandlesArray
[i
].WindowProc
== NULL
)
4211 OldArray
= WndProcHandlesArray
;
4212 OldArraySize
= WndProcHandlesArraySize
;
4213 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,(OldArraySize
+ WPH_SIZE
) * sizeof(WndProcHandle
), TAG_WINPROCLST
);
4214 WndProcHandlesArraySize
= OldArraySize
+ WPH_SIZE
;
4215 RtlCopyMemory(WndProcHandlesArray
,OldArray
,OldArraySize
* sizeof(WndProcHandle
));
4216 ExFreePool(OldArray
);
4217 FreeSpot
= OldArraySize
+ 1;
4219 WndProcHandlesArray
[FreeSpot
].WindowProc
= WindowProc
;
4220 WndProcHandlesArray
[FreeSpot
].IsUnicode
= IsUnicode
;
4221 WndProcHandlesArray
[FreeSpot
].ProcessID
= PsGetCurrentProcessId();
4222 return FreeSpot
+ 0xFFFF0000;
4226 IntRemoveWndProcHandle(WNDPROC Handle
)
4229 position
= (DWORD
)Handle
& 0x0000FFFF;
4230 if (position
> WndProcHandlesArraySize
)
4234 WndProcHandlesArray
[position
].WindowProc
= NULL
;
4235 WndProcHandlesArray
[position
].IsUnicode
= FALSE
;
4236 WndProcHandlesArray
[position
].ProcessID
= NULL
;
4241 IntRemoveProcessWndProcHandles(HANDLE ProcessID
)
4244 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4246 if (WndProcHandlesArray
[i
].ProcessID
== ProcessID
)
4248 WndProcHandlesArray
[i
].WindowProc
= NULL
;
4249 WndProcHandlesArray
[i
].IsUnicode
= FALSE
;
4250 WndProcHandlesArray
[i
].ProcessID
= NULL
;