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.240 2004/06/20 16:06:05 navaraf Exp $
21 * COPYRIGHT: See COPYING in the top level directory
22 * PROJECT: ReactOS kernel
24 * FILE: subsys/win32k/ntuser/window.c
25 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
27 * 06-06-2001 CSH Created
29 /* INCLUDES ******************************************************************/
32 static WndProcHandle
*WndProcHandlesArray
= 0;
33 static WORD WndProcHandlesArraySize
= 0;
34 #define WPH_SIZE 0x40 /* the size to add to the WndProcHandle array each time */
36 /* dialog resources appear to pass this in 16 bits, handle them properly */
37 #define CW_USEDEFAULT16 (0x8000)
39 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
41 /* PRIVATE FUNCTIONS **********************************************************/
46 * Initialize windowing implementation.
52 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,WPH_SIZE
* sizeof(WndProcHandle
), TAG_WINPROCLST
);
53 WndProcHandlesArraySize
= WPH_SIZE
;
54 return STATUS_SUCCESS
;
60 * Cleanup windowing implementation.
64 CleanupWindowImpl(VOID
)
66 ExFreePool(WndProcHandlesArray
);
67 WndProcHandlesArray
= 0;
68 WndProcHandlesArraySize
= 0;
69 return STATUS_SUCCESS
;
72 /* HELPER FUNCTIONS ***********************************************************/
77 * The function determines whether the specified window handle identifies
82 * Handle to the window to test.
85 * If the window handle identifies an existing window, the return value
86 * is TRUE. If the window handle does not identify an existing window,
87 * the return value is FALSE.
91 IntIsWindow(HWND hWnd
)
93 PWINDOW_OBJECT Window
;
95 if (!(Window
= IntGetWindowObject(hWnd
)))
98 IntReleaseWindowObject(Window
);
103 * IntGetProcessWindowObject
105 * Get window object from handle of specified process.
108 PWINDOW_OBJECT FASTCALL
109 IntGetProcessWindowObject(PW32PROCESS ProcessData
, HWND hWnd
)
111 PWINDOW_OBJECT WindowObject
;
114 Status
= ObmReferenceObjectByHandle(ProcessData
->WindowStation
->HandleTable
,
115 hWnd
, otWindow
, (PVOID
*)&WindowObject
);
116 if (!NT_SUCCESS(Status
))
124 PWINDOW_OBJECT FASTCALL
125 IntGetParent(PWINDOW_OBJECT Wnd
)
129 if (Wnd
->Style
& WS_POPUP
)
131 IntLockRelatives(Wnd
);
133 IntUnLockRelatives(Wnd
);
134 return IntGetWindowObject(hWnd
);
136 else if (Wnd
->Style
& WS_CHILD
)
138 IntLockRelatives(Wnd
);
140 IntUnLockRelatives(Wnd
);
141 return IntGetWindowObject(hWnd
);
148 PWINDOW_OBJECT FASTCALL
149 IntGetParentObject(PWINDOW_OBJECT Wnd
)
153 IntLockRelatives(Wnd
);
154 hParent
= Wnd
->Parent
;
155 IntUnLockRelatives(Wnd
);
156 return IntGetWindowObject(hParent
);
162 * Compile a list of all child window handles from given window.
165 * This function is similar to Wine WIN_ListChildren. The caller
166 * must free the returned list with ExFreePool.
170 IntWinListChildren(PWINDOW_OBJECT Window
)
172 PWINDOW_OBJECT Child
;
174 UINT Index
, NumChildren
= 0;
176 IntLockRelatives(Window
);
178 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
181 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
184 DPRINT1("Failed to allocate memory for children array\n");
185 IntUnLockRelatives(Window
);
186 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
189 for (Child
= Window
->FirstChild
, Index
= 0;
191 Child
= Child
->NextSibling
, ++Index
)
192 List
[Index
] = Child
->Self
;
195 IntUnLockRelatives(Window
);
200 /***********************************************************************
203 static void IntSendDestroyMsg(HWND Wnd
)
208 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
210 if (Wnd
== info
.hwndCaret
)
218 * Send the WM_DESTROY to the window.
220 IntSendMessage(Wnd
, WM_DESTROY
, 0, 0);
223 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
224 * make sure that the window still exists when we come back.
232 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
234 /* start from the end (FIXME: is this needed?) */
235 for (i
= 0; pWndArray
[i
]; i
++) ;
239 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
241 HeapFree(GetProcessHeap(), 0, pWndArray
);
245 DPRINT("destroyed itself while in WM_DESTROY!\n");
250 /***********************************************************************
253 * Destroy storage associated to a window. "Internals" p.358
255 static LRESULT
IntDestroyWindow(PWINDOW_OBJECT Window
,
256 PW32PROCESS ProcessData
,
257 PW32THREAD ThreadData
,
258 BOOLEAN SendMessages
)
262 PWINDOW_OBJECT Child
;
264 BOOL BelongsToThreadData
;
268 RemoveTimersWindow(Window
->Self
);
270 IntLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
271 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
273 IntUnLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
274 DPRINT("Tried to call IntDestroyWindow() twice\n");
277 Window
->Status
|= WINDOWSTATUS_DESTROYING
;
278 /* remove the window already at this point from the thread window list so we
279 don't get into trouble when destroying the thread windows while we're still
280 in IntDestroyWindow() */
281 RemoveEntryList(&Window
->ThreadListEntry
);
282 IntUnLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
284 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
288 /* Send destroy messages */
289 IntSendDestroyMsg(Window
->Self
);
292 /* free child windows */
293 Children
= IntWinListChildren(Window
);
296 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
298 if ((Child
= IntGetWindowObject(*ChildHandle
)))
300 if(!IntWndBelongsToThread(Child
, ThreadData
))
302 /* send WM_DESTROY messages to windows not belonging to the same thread */
303 IntSendDestroyMsg(Child
->Self
);
306 IntDestroyWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
307 IntReleaseWindowObject(Child
);
310 ExFreePool(Children
);
316 * Clear the update region to make sure no WM_PAINT messages will be
317 * generated for this window while processing the WM_NCDESTROY.
319 IntRedrawWindow(Window
, NULL
, 0,
320 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
321 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
324 * Send the WM_NCDESTROY to the window being destroyed.
326 if(BelongsToThreadData
)
327 IntSendMessage(Window
->Self
, WM_NCDESTROY
, 0, 0);
330 /* reset shell window handles */
331 if(ProcessData
->WindowStation
)
333 if (Window
->Self
== ProcessData
->WindowStation
->ShellWindow
)
334 ProcessData
->WindowStation
->ShellWindow
= NULL
;
336 if (Window
->Self
== ProcessData
->WindowStation
->ShellListView
)
337 ProcessData
->WindowStation
->ShellListView
= NULL
;
340 /* Unregister hot keys */
341 UnregisterWindowHotKeys (Window
);
343 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
346 WinPosCheckInternalPos(Window
->Self
);
347 if (Window
->Self
== GetCapture())
352 /* free resources associated with the window */
353 TIMER_RemoveWindowTimers(Window
->Self
);
356 if (!(Window
->Style
& WS_CHILD
) && Window
->IDMenu
357 && (Menu
= IntGetMenuObject((HMENU
)Window
->IDMenu
)))
359 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
361 IntReleaseMenuObject(Menu
);
364 if(Window
->SystemMenu
365 && (Menu
= IntGetMenuObject(Window
->SystemMenu
)))
367 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
368 Window
->SystemMenu
= (HMENU
)0;
369 IntReleaseMenuObject(Menu
);
372 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
374 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
375 CLASS_RemoveWindow(Window
->Class
);
378 IntUnlinkWindow(Window
);
380 IntReferenceWindowObject(Window
);
381 ObmCloseHandle(ProcessData
->WindowStation
->HandleTable
, Window
->Self
);
383 IntDestroyScrollBars(Window
);
385 IntLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
386 Window
->Status
|= WINDOWSTATUS_DESTROYED
;
387 /* don't remove the WINDOWSTATUS_DESTROYING bit */
388 IntUnLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
390 /* 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)
1937 DPRINT("Sending bogus WM_SIZE\n");
1939 lParam
= MAKE_LONG(WindowObject
->ClientRect
.right
-
1940 WindowObject
->ClientRect
.left
,
1941 WindowObject
->ClientRect
.bottom
-
1942 WindowObject
->ClientRect
.top
);
1943 IntSendMessage(WindowObject
->Self
, WM_SIZE
, SIZE_RESTORED
,
1946 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
1948 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1950 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
- ParentWindow
->ClientRect
.left
,
1951 WindowObject
->ClientRect
.top
- ParentWindow
->ClientRect
.top
);
1955 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
,
1956 WindowObject
->ClientRect
.top
);
1958 IntSendMessage(WindowObject
->Self
, WM_MOVE
, 0, lParam
);
1961 /* Show or maybe minimize or maximize the window. */
1962 if (WindowObject
->Style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1967 SwFlag
= (WindowObject
->Style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
1969 WinPosMinMaximize(WindowObject
, SwFlag
, &NewPos
);
1971 ((WindowObject
->Style
& WS_CHILD
) || NtUserGetActiveWindow()) ?
1972 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
1973 SWP_NOZORDER
| SWP_FRAMECHANGED
;
1974 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
1975 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
1976 WinPosSetWindowPos(WindowObject
->Self
, 0, NewPos
.left
, NewPos
.top
,
1977 NewPos
.right
, NewPos
.bottom
, SwFlag
);
1980 /* Notify the parent window of a new child. */
1981 if ((WindowObject
->Style
& WS_CHILD
) &&
1982 (!(WindowObject
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
1984 DPRINT("IntCreateWindow(): About to notify parent\n");
1985 IntSendMessage(ParentWindow
->Self
,
1987 MAKEWPARAM(WM_CREATE
, WindowObject
->IDMenu
),
1988 (LPARAM
)WindowObject
->Self
);
1991 if (NULL
!= ParentWindow
)
1993 IntReleaseWindowObject(ParentWindow
);
1996 /* Initialize and show the window's scrollbars */
1997 if (WindowObject
->Style
& WS_VSCROLL
)
1999 NtUserShowScrollBar(WindowObject
->Self
, SB_VERT
, TRUE
);
2001 if (WindowObject
->Style
& WS_HSCROLL
)
2003 NtUserShowScrollBar(WindowObject
->Self
, SB_HORZ
, TRUE
);
2006 if (dwStyle
& WS_VISIBLE
)
2008 DPRINT("IntCreateWindow(): About to show window\n");
2009 WinPosShowWindow(WindowObject
->Self
, dwShowMode
);
2012 DPRINT("IntCreateWindow(): = %X\n", Handle
);
2013 DPRINT("WindowObject->SystemMenu = 0x%x\n", WindowObject
->SystemMenu
);
2014 return((HWND
)Handle
);
2018 NtUserCreateWindowEx(DWORD dwExStyle
,
2019 PUNICODE_STRING UnsafeClassName
,
2020 PUNICODE_STRING UnsafeWindowName
,
2028 HINSTANCE hInstance
,
2031 BOOL bUnicodeWindow
)
2034 UNICODE_STRING WindowName
;
2035 UNICODE_STRING ClassName
;
2038 DPRINT("NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2040 /* Get the class name (string or atom) */
2041 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
2042 if (! NT_SUCCESS(Status
))
2044 SetLastNtError(Status
);
2047 if (! IS_ATOM(ClassName
.Buffer
))
2049 Status
= IntSafeCopyUnicodeString(&ClassName
, UnsafeClassName
);
2050 if (! NT_SUCCESS(Status
))
2052 SetLastNtError(Status
);
2057 /* safely copy the window name */
2058 if (NULL
!= UnsafeWindowName
)
2060 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
2061 if (! NT_SUCCESS(Status
))
2063 if (! IS_ATOM(ClassName
.Buffer
))
2065 RtlFreeUnicodeString(&ClassName
);
2067 SetLastNtError(Status
);
2073 RtlInitUnicodeString(&WindowName
, NULL
);
2076 NewWindow
= IntCreateWindowEx(dwExStyle
, &ClassName
, &WindowName
, dwStyle
, x
, y
, nWidth
, nHeight
,
2077 hWndParent
, hMenu
, hInstance
, lpParam
, dwShowMode
, bUnicodeWindow
);
2079 RtlFreeUnicodeString(&WindowName
);
2080 if (! IS_ATOM(ClassName
.Buffer
))
2082 RtlFreeUnicodeString(&ClassName
);
2092 NtUserDeferWindowPos(HDWP WinPosInfo
,
2094 HWND WndInsertAfter
,
2111 NtUserDestroyWindow(HWND Wnd
)
2113 PWINDOW_OBJECT Window
;
2116 Window
= IntGetWindowObject(Wnd
);
2122 /* Check for owner thread and desktop window */
2123 if ((Window
->OwnerThread
!= PsGetCurrentThread()) || IntIsDesktopWindow(Window
))
2125 IntReleaseWindowObject(Window
);
2126 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2130 /* Look whether the focus is within the tree of windows we will
2133 if (!WinPosShowWindow(Wnd
, SW_HIDE
))
2135 if (NtUserGetActiveWindow() == Wnd
)
2137 WinPosActivateOtherWindow(Window
);
2140 IntLockMessageQueue(Window
->MessageQueue
);
2141 if (Window
->MessageQueue
->ActiveWindow
== Window
->Self
)
2142 Window
->MessageQueue
->ActiveWindow
= NULL
;
2143 if (Window
->MessageQueue
->FocusWindow
== Window
->Self
)
2144 Window
->MessageQueue
->FocusWindow
= NULL
;
2145 if (Window
->MessageQueue
->CaptureWindow
== Window
->Self
)
2146 Window
->MessageQueue
->CaptureWindow
= NULL
;
2147 IntUnLockMessageQueue(Window
->MessageQueue
);
2151 if (HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hwnd
, 0, TRUE
))
2157 isChild
= (0 != (Window
->Style
& WS_CHILD
));
2162 if (! USER_IsExitingThread(GetCurrentThreadId()))
2164 send_parent_notify(hwnd
, WM_DESTROY
);
2167 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2169 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2170 /* FIXME: clean up palette - see "Internals" p.352 */
2174 if (!IntIsWindow(Wnd
))
2179 /* Recursively destroy owned windows */
2184 BOOL GotOne
= FALSE
;
2187 PWINDOW_OBJECT Child
, Desktop
;
2189 Desktop
= IntGetWindowObject(IntGetDesktopWindow());
2190 Children
= IntWinListChildren(Desktop
);
2191 IntReleaseWindowObject(Desktop
);
2194 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2196 Child
= IntGetWindowObject(*ChildHandle
);
2199 IntLockRelatives(Child
);
2200 if (Child
->Owner
!= Window
->Self
)
2202 IntUnLockRelatives(Child
);
2203 IntReleaseWindowObject(Child
);
2206 IntUnLockRelatives(Child
);
2207 if (IntWndBelongsToThread(Child
, PsGetWin32Thread()))
2209 IntReleaseWindowObject(Child
);
2210 NtUserDestroyWindow(*ChildHandle
);
2214 IntLockRelatives(Child
);
2215 if (Child
->Owner
!= NULL
)
2217 Child
->Owner
= NULL
;
2219 IntUnLockRelatives(Child
);
2220 IntReleaseWindowObject(Child
);
2222 ExFreePool(Children
);
2231 if (!IntIsWindow(Wnd
))
2233 IntReleaseWindowObject(Window
);
2237 /* Destroy the window storage */
2238 IntDestroyWindow(Window
, PsGetWin32Process(), PsGetWin32Thread(), TRUE
);
2240 IntReleaseWindowObject(Window
);
2250 NtUserDrawMenuBarTemp(
2257 /* we'll use this function just for caching the menu bar */
2267 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2280 NtUserFillWindow(DWORD Unknown0
,
2292 IntFindWindow(PWINDOW_OBJECT Parent
,
2293 PWINDOW_OBJECT ChildAfter
,
2294 PWNDCLASS_OBJECT ClassObject
,
2295 PUNICODE_STRING WindowName
)
2297 BOOL CheckWindowName
;
2303 CheckWindowName
= (WindowName
&& (WindowName
->Length
> 0));
2305 if((List
= IntWinListChildren(Parent
)))
2310 /* skip handles before and including ChildAfter */
2311 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->Self
));
2314 /* search children */
2317 PWINDOW_OBJECT Child
;
2318 if(!(Child
= IntGetWindowObject(*(phWnd
++))))
2323 /* Do not send WM_GETTEXT messages in the kernel mode version!
2324 The user mode version however calls GetWindowText() which will
2325 send WM_GETTEXT messages to windows belonging to its processes */
2326 if(((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(WindowName
, &(Child
->WindowName
), FALSE
))) &&
2327 (!ClassObject
|| (ClassObject
&& (Child
->Class
== ClassObject
))))
2329 ((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(WindowName
, &(Child
->WindowName
), FALSE
))) &&
2330 (!ClassObject
|| (ClassObject
&& (Child
->Class
== ClassObject
)))))
2333 IntReleaseWindowObject(Child
);
2337 IntReleaseWindowObject(Child
);
2347 * Searches a window's children for a window with the specified
2350 * hwndParent = The window whose childs are to be searched.
2352 * HWND_MESSAGE = message-only windows
2354 * hwndChildAfter = Search starts after this child window.
2355 * NULL = start from beginning
2357 * ucClassName = Class name to search for
2358 * Reguired parameter.
2360 * ucWindowName = Window name
2361 * ->Buffer == NULL = don't care
2364 * The HWND of the window if it was found, otherwise NULL
2370 NtUserFindWindowEx(HWND hwndParent
,
2371 HWND hwndChildAfter
,
2372 PUNICODE_STRING ucClassName
,
2373 PUNICODE_STRING ucWindowName
)
2375 PWINDOW_OBJECT Parent
, ChildAfter
;
2376 UNICODE_STRING ClassName
, WindowName
;
2378 HWND Desktop
, Ret
= NULL
;
2379 PWNDCLASS_OBJECT ClassObject
= NULL
;
2382 Desktop
= IntGetDesktopWindow();
2384 if(hwndParent
== NULL
)
2385 hwndParent
= Desktop
;
2387 else if(hwndParent == HWND_MESSAGE)
2389 hwndParent = IntGetMessageWindow();
2393 if(!(Parent
= IntGetWindowObject(hwndParent
)))
2395 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2400 if(hwndChildAfter
&& !(ChildAfter
= IntGetWindowObject(hwndChildAfter
)))
2402 IntReleaseWindowObject(hwndParent
);
2403 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2407 /* copy the window name */
2408 Status
= IntSafeCopyUnicodeString(&WindowName
, ucWindowName
);
2409 if(!NT_SUCCESS(Status
))
2411 SetLastNtError(Status
);
2415 /* safely copy the class name */
2416 Status
= MmCopyFromCaller(&ClassName
, ucClassName
, sizeof(UNICODE_STRING
));
2417 if(!NT_SUCCESS(Status
))
2419 SetLastNtError(Status
);
2422 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2425 /* safely copy the class name string (NULL terminated because class-lookup
2427 buf
= ExAllocatePoolWithTag(PagedPool
, ClassName
.Length
+ sizeof(WCHAR
), TAG_STRING
);
2430 SetLastWin32Error(STATUS_INSUFFICIENT_RESOURCES
);
2433 Status
= MmCopyFromCaller(buf
, ClassName
.Buffer
, ClassName
.Length
);
2434 if(!NT_SUCCESS(Status
))
2437 SetLastNtError(Status
);
2440 ClassName
.Buffer
= buf
;
2441 /* make sure the string is null-terminated */
2442 buf
+= ClassName
.Length
/ sizeof(WCHAR
);
2446 /* find the class object */
2447 if(ClassName
.Buffer
)
2449 /* this expects the string in ClassName to be NULL-terminated! */
2450 ClassFound
= ClassReferenceClassByNameOrAtom(&ClassObject
, ClassName
.Buffer
, NULL
);
2453 if (IS_ATOM(ClassName
.Buffer
))
2454 DPRINT1("Window class not found (%lx)\n", (ULONG_PTR
)ClassName
.Buffer
);
2456 DPRINT1("Window class not found (%S)\n", ClassName
.Buffer
);
2457 SetLastWin32Error(ERROR_CLASS_DOES_NOT_EXIST
);
2462 if(Parent
->Self
== Desktop
)
2465 PWINDOW_OBJECT TopLevelWindow
;
2466 BOOL CheckWindowName
;
2468 /* windows searches through all top-level windows if the parent is the desktop
2471 if((List
= IntWinListChildren(Parent
)))
2477 /* skip handles before and including ChildAfter */
2478 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->Self
));
2481 CheckWindowName
= WindowName
.Length
> 0;
2483 /* search children */
2486 if(!(TopLevelWindow
= IntGetWindowObject(*(phWnd
++))))
2491 /* Do not send WM_GETTEXT messages in the kernel mode version!
2492 The user mode version however calls GetWindowText() which will
2493 send WM_GETTEXT messages to windows belonging to its processes */
2494 if(((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(&WindowName
, &(TopLevelWindow
->WindowName
), FALSE
))) &&
2495 (!ClassObject
|| (ClassObject
&& (TopLevelWindow
->Class
== ClassObject
))))
2497 ((!CheckWindowName
|| (CheckWindowName
&& !RtlCompareUnicodeString(&WindowName
, &(TopLevelWindow
->WindowName
), FALSE
))) &&
2498 (!ClassObject
|| (ClassObject
&& (TopLevelWindow
->Class
== ClassObject
)))))
2500 Ret
= TopLevelWindow
->Self
;
2501 IntReleaseWindowObject(TopLevelWindow
);
2505 if(IntFindWindow(TopLevelWindow
, NULL
, ClassObject
, &WindowName
))
2507 /* window returns the handle of the top-level window, in case it found
2509 Ret
= TopLevelWindow
->Self
;
2510 IntReleaseWindowObject(TopLevelWindow
);
2514 IntReleaseWindowObject(TopLevelWindow
);
2520 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassObject
, &WindowName
);
2523 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2525 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2526 search the message-only windows. Should this also be done if
2527 Parent is the desktop window??? */
2528 PWINDOW_OBJECT MsgWindows
;
2530 if((MsgWindows
= IntGetWindowObject(IntGetMessageWindow())))
2532 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassObject
, &WindowName
);
2533 IntReleaseWindowObject(MsgWindows
);
2538 ClassDereferenceObject(ClassObject
);
2541 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2542 ExFreePool(ClassName
.Buffer
);
2545 RtlFreeUnicodeString(&WindowName
);
2549 IntReleaseWindowObject(ChildAfter
);
2550 IntReleaseWindowObject(Parent
);
2560 NtUserFlashWindowEx(DWORD Unknown0
)
2572 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2574 PWINDOW_OBJECT Wnd
, WndAncestor
, Parent
;
2577 if (hWnd
== IntGetDesktopWindow())
2582 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2584 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2592 WndAncestor
= IntGetParentObject(Wnd
);
2605 if(!(Parent
= IntGetParentObject(WndAncestor
)))
2609 if(IntIsDesktopWindow(Parent
))
2611 IntReleaseWindowObject(Parent
);
2615 IntReleaseWindowObject(tmp
);
2616 WndAncestor
= Parent
;
2624 IntReferenceWindowObject(WndAncestor
);
2629 Parent
= IntGetParent(WndAncestor
);
2630 IntReleaseWindowObject(Old
);
2635 WndAncestor
= Parent
;
2642 IntReleaseWindowObject(Wnd
);
2647 hWndAncestor
= (WndAncestor
? WndAncestor
->Self
: NULL
);
2648 IntReleaseWindowObject(Wnd
);
2650 if(WndAncestor
&& (WndAncestor
!= Wnd
))
2651 IntReleaseWindowObject(WndAncestor
);
2653 return hWndAncestor
;
2658 * Returns client window rectangle relative to the upper-left corner of client area.
2660 * \param hWnd window handle.
2661 * \param Rect pointer to the buffer where the coordinates are returned.
2668 NtUserGetClientRect(HWND hWnd
, LPRECT Rect
)
2670 PWINDOW_OBJECT WindowObject
;
2673 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
2675 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2679 IntGetClientRect(WindowObject
, &SafeRect
);
2680 IntReleaseWindowObject(WindowObject
);
2682 if(!NT_SUCCESS(MmCopyToCaller(Rect
, &SafeRect
, sizeof(RECT
))))
2694 NtUserGetDesktopWindow()
2696 return IntGetDesktopWindow();
2704 NtUserGetInternalWindowPos(DWORD Unknown0
,
2718 NtUserGetLastActivePopup(HWND hWnd
)
2721 * This code can't work, because hWndLastPopup member of WINDOW_OBJECT is
2722 * not changed anywhere.
2723 * -- Filip, 01/nov/2003
2729 IntAcquireWinLockShared();
2731 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2733 IntReleaseWinLock();
2734 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2738 hWndLastPopup
= Wnd
->hWndLastPopup
;
2740 IntReleaseWinLock();
2742 return hWndLastPopup
;
2751 * The NtUserGetParent function retrieves a handle to the specified window's
2755 * Note that, despite its name, this function can return an owner window
2756 * instead of a parent window.
2763 NtUserGetParent(HWND hWnd
)
2765 PWINDOW_OBJECT Wnd
, WndParent
;
2766 HWND hWndParent
= NULL
;
2768 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2770 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2774 WndParent
= IntGetParent(Wnd
);
2777 hWndParent
= WndParent
->Self
;
2778 IntReleaseWindowObject(WndParent
);
2781 IntReleaseWindowObject(Wnd
);
2789 * The NtUserSetParent function changes the parent window of the specified
2793 * The new parent window and the child window must belong to the same
2794 * application. If the window identified by the hWndChild parameter is
2795 * visible, the system performs the appropriate redrawing and repainting.
2796 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
2797 * or WS_POPUP window styles of the window whose parent is being changed.
2804 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2806 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
2807 HWND hWndOldParent
= NULL
;
2809 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
2811 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2815 if (hWndChild
== IntGetDesktopWindow())
2817 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2823 if (!(WndParent
= IntGetWindowObject(hWndNewParent
)))
2825 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2831 if (!(WndParent
= IntGetWindowObject(IntGetDesktopWindow())))
2833 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2838 if (!(Wnd
= IntGetWindowObject(hWndChild
)))
2840 IntReleaseWindowObject(WndParent
);
2841 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2845 WndOldParent
= IntSetParent(Wnd
, WndParent
);
2849 hWndOldParent
= WndOldParent
->Self
;
2850 IntReleaseWindowObject(WndOldParent
);
2853 IntReleaseWindowObject(Wnd
);
2854 IntReleaseWindowObject(WndParent
);
2856 return hWndOldParent
;
2860 * NtUserGetShellWindow
2862 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
2869 NtUserGetShellWindow()
2871 PWINSTATION_OBJECT WinStaObject
;
2874 NTSTATUS Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
2879 if (!NT_SUCCESS(Status
))
2881 SetLastNtError(Status
);
2885 Ret
= (HWND
)WinStaObject
->ShellWindow
;
2887 ObDereferenceObject(WinStaObject
);
2892 * NtUserSetShellWindowEx
2894 * This is undocumented function to set global shell window. The global
2895 * shell window has special handling of window position.
2902 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
2904 PWINSTATION_OBJECT WinStaObject
;
2906 NTSTATUS Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
2911 if (!NT_SUCCESS(Status
))
2913 SetLastNtError(Status
);
2918 * Test if we are permitted to change the shell window.
2920 if (WinStaObject
->ShellWindow
)
2922 ObDereferenceObject(WinStaObject
);
2927 * Move shell window into background.
2929 if (hwndListView
&& hwndListView
!= hwndShell
)
2932 * Disabled for now to get Explorer working.
2933 * -- Filip, 01/nov/2003
2936 WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2939 if (NtUserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2941 ObDereferenceObject(WinStaObject
);
2946 if (NtUserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2948 ObDereferenceObject(WinStaObject
);
2952 WinPosSetWindowPos(hwndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2954 WinStaObject
->ShellWindow
= hwndShell
;
2955 WinStaObject
->ShellListView
= hwndListView
;
2957 ObDereferenceObject(WinStaObject
);
2962 * NtUserGetSystemMenu
2964 * The NtUserGetSystemMenu function allows the application to access the
2965 * window menu (also known as the system menu or the control menu) for
2966 * copying and modifying.
2970 * Handle to the window that will own a copy of the window menu.
2972 * Specifies the action to be taken. If this parameter is FALSE,
2973 * NtUserGetSystemMenu returns a handle to the copy of the window menu
2974 * currently in use. The copy is initially identical to the window menu
2975 * but it can be modified.
2976 * If this parameter is TRUE, GetSystemMenu resets the window menu back
2977 * to the default state. The previous window menu, if any, is destroyed.
2980 * If the bRevert parameter is FALSE, the return value is a handle to a
2981 * copy of the window menu. If the bRevert parameter is TRUE, the return
2989 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
2992 PWINDOW_OBJECT WindowObject
;
2993 PMENU_OBJECT MenuObject
;
2995 WindowObject
= IntGetWindowObject((HWND
)hWnd
);
2996 if (WindowObject
== NULL
)
2998 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3002 MenuObject
= IntGetSystemMenu(WindowObject
, bRevert
, FALSE
);
3005 Result
= MenuObject
->MenuInfo
.Self
;
3006 IntReleaseMenuObject(MenuObject
);
3009 IntReleaseWindowObject(WindowObject
);
3014 * NtUserSetSystemMenu
3021 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3023 BOOL Result
= FALSE
;
3024 PWINDOW_OBJECT WindowObject
;
3025 PMENU_OBJECT MenuObject
;
3027 WindowObject
= IntGetWindowObject(hWnd
);
3030 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3037 * Assign new menu handle.
3039 MenuObject
= IntGetMenuObject(hMenu
);
3042 IntReleaseWindowObject(WindowObject
);
3043 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
3047 Result
= IntSetSystemMenu(WindowObject
, MenuObject
);
3049 IntReleaseMenuObject(MenuObject
);
3052 IntReleaseWindowObject(WindowObject
);
3060 * The NtUserGetWindow function retrieves a handle to a window that has the
3061 * specified relationship (Z order or owner) to the specified window.
3068 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3070 PWINDOW_OBJECT WindowObject
, Parent
;
3071 HWND hWndResult
= NULL
;
3073 if (!(WindowObject
= IntGetWindowObject(hWnd
)))
3075 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3079 switch (Relationship
)
3082 if((Parent
= IntGetParentObject(WindowObject
)))
3084 IntLockRelatives(Parent
);
3085 if (Parent
->FirstChild
)
3086 hWndResult
= Parent
->FirstChild
->Self
;
3087 IntUnLockRelatives(Parent
);
3088 IntReleaseWindowObject(Parent
);
3093 if((Parent
= IntGetParentObject(WindowObject
)))
3095 IntLockRelatives(Parent
);
3096 if (Parent
->LastChild
)
3097 hWndResult
= Parent
->LastChild
->Self
;
3098 IntUnLockRelatives(Parent
);
3099 IntReleaseWindowObject(Parent
);
3104 IntLockRelatives(WindowObject
);
3105 if (WindowObject
->NextSibling
)
3106 hWndResult
= WindowObject
->NextSibling
->Self
;
3107 IntUnLockRelatives(WindowObject
);
3111 IntLockRelatives(WindowObject
);
3112 if (WindowObject
->PrevSibling
)
3113 hWndResult
= WindowObject
->PrevSibling
->Self
;
3114 IntUnLockRelatives(WindowObject
);
3118 IntLockRelatives(WindowObject
);
3119 if((Parent
= IntGetWindowObject(WindowObject
->Owner
)))
3121 hWndResult
= Parent
->Self
;
3122 IntReleaseWindowObject(Parent
);
3124 IntUnLockRelatives(WindowObject
);
3127 IntLockRelatives(WindowObject
);
3128 if (WindowObject
->FirstChild
)
3129 hWndResult
= WindowObject
->FirstChild
->Self
;
3130 IntUnLockRelatives(WindowObject
);
3134 IntReleaseWindowObject(WindowObject
);
3140 * NtUserGetWindowLong
3142 * The NtUserGetWindowLong function retrieves information about the specified
3143 * window. The function also retrieves the 32-bit (long) value at the
3144 * specified offset into the extra window memory.
3151 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3153 PWINDOW_OBJECT WindowObject
, Parent
;
3156 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3158 WindowObject
= IntGetWindowObject(hWnd
);
3159 if (WindowObject
== NULL
)
3161 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3166 * Only allow CSRSS to mess with the desktop window
3168 if (hWnd
== IntGetDesktopWindow()
3169 && WindowObject
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3171 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3175 if ((INT
)Index
>= 0)
3177 if ((Index
+ sizeof(LONG
)) > WindowObject
->ExtraDataSize
)
3179 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3182 Result
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
3189 Result
= WindowObject
->ExStyle
;
3193 Result
= WindowObject
->Style
;
3198 Result
= (LONG
) WindowObject
->WndProcA
;
3200 Result
= (LONG
) WindowObject
->WndProcW
;
3204 Result
= (LONG
) WindowObject
->Instance
;
3207 case GWL_HWNDPARENT
:
3208 IntLockRelatives(WindowObject
);
3209 Parent
= IntGetWindowObject(WindowObject
->Parent
);
3210 IntUnLockRelatives(WindowObject
);
3213 if (Parent
&& Parent
->Self
== IntGetDesktopWindow())
3214 Result
= (LONG
) NtUserGetWindow(WindowObject
->Self
, GW_OWNER
);
3216 Result
= (LONG
) Parent
->Self
;
3217 IntReleaseWindowObject(Parent
);
3222 Result
= (LONG
) WindowObject
->IDMenu
;
3226 Result
= WindowObject
->UserData
;
3230 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3231 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3237 IntReleaseWindowObject(WindowObject
);
3243 * NtUserSetWindowLong
3245 * The NtUserSetWindowLong function changes an attribute of the specified
3246 * window. The function also sets the 32-bit (long) value at the specified
3247 * offset into the extra window memory.
3254 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3256 PWINDOW_OBJECT WindowObject
, Parent
;
3257 PW32PROCESS Process
;
3258 PWINSTATION_OBJECT WindowStation
;
3262 if (hWnd
== IntGetDesktopWindow())
3264 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3268 WindowObject
= IntGetWindowObject(hWnd
);
3269 if (WindowObject
== NULL
)
3271 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3275 if ((INT
)Index
>= 0)
3277 if ((Index
+ sizeof(LONG
)) > WindowObject
->ExtraDataSize
)
3279 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3280 IntReleaseWindowObject(WindowObject
);
3283 OldValue
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
3284 *((LONG
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
3291 OldValue
= (LONG
) WindowObject
->ExStyle
;
3292 Style
.styleOld
= OldValue
;
3293 Style
.styleNew
= NewValue
;
3296 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3298 Process
= WindowObject
->OwnerThread
->ThreadsProcess
->Win32Process
;
3299 WindowStation
= Process
->WindowStation
;
3302 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3303 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3306 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3307 WindowObject
->ExStyle
= (DWORD
)Style
.styleNew
;
3308 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3312 OldValue
= (LONG
) WindowObject
->Style
;
3313 Style
.styleOld
= OldValue
;
3314 Style
.styleNew
= NewValue
;
3315 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3316 WindowObject
->Style
= (DWORD
)Style
.styleNew
;
3317 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3321 /* FIXME: should check if window belongs to current process */
3324 OldValue
= (LONG
) WindowObject
->WndProcA
;
3325 WindowObject
->WndProcA
= (WNDPROC
) NewValue
;
3326 WindowObject
->WndProcW
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,FALSE
);
3327 WindowObject
->Unicode
= FALSE
;
3331 OldValue
= (LONG
) WindowObject
->WndProcW
;
3332 WindowObject
->WndProcW
= (WNDPROC
) NewValue
;
3333 WindowObject
->WndProcA
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,TRUE
);
3334 WindowObject
->Unicode
= TRUE
;
3339 OldValue
= (LONG
) WindowObject
->Instance
;
3340 WindowObject
->Instance
= (HINSTANCE
) NewValue
;
3343 case GWL_HWNDPARENT
:
3344 Parent
= IntGetParentObject(WindowObject
);
3345 if (Parent
&& (Parent
->Self
== IntGetDesktopWindow()))
3346 OldValue
= (LONG
) IntSetOwner(WindowObject
->Self
, (HWND
) NewValue
);
3348 OldValue
= (LONG
) NtUserSetParent(WindowObject
->Self
, (HWND
) NewValue
);
3350 IntReleaseWindowObject(Parent
);
3354 OldValue
= (LONG
) WindowObject
->IDMenu
;
3355 WindowObject
->IDMenu
= (UINT
) NewValue
;
3359 OldValue
= WindowObject
->UserData
;
3360 WindowObject
->UserData
= NewValue
;
3364 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3365 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3371 IntReleaseWindowObject(WindowObject
);
3377 * NtUserSetWindowWord
3379 * Legacy function similar to NtUserSetWindowLong.
3386 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3388 PWINDOW_OBJECT WindowObject
;
3395 case GWL_HWNDPARENT
:
3396 return NtUserSetWindowLong(hWnd
, Index
, (UINT
)NewValue
, TRUE
);
3400 SetLastWin32Error(ERROR_INVALID_INDEX
);
3405 WindowObject
= IntGetWindowObject(hWnd
);
3406 if (WindowObject
== NULL
)
3408 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3412 if (Index
> WindowObject
->ExtraDataSize
- sizeof(WORD
))
3414 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3415 IntReleaseWindowObject(WindowObject
);
3419 OldValue
= *((WORD
*)(WindowObject
->ExtraData
+ Index
));
3420 *((WORD
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
3422 IntReleaseWindowObject(WindowObject
);
3431 NtUserGetWindowPlacement(HWND hWnd
,
3432 WINDOWPLACEMENT
*lpwndpl
)
3434 PWINDOW_OBJECT WindowObject
;
3435 PINTERNALPOS InternalPos
;
3437 WINDOWPLACEMENT Safepl
;
3440 WindowObject
= IntGetWindowObject(hWnd
);
3441 if (WindowObject
== NULL
)
3443 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3447 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3448 if(!NT_SUCCESS(Status
))
3450 SetLastNtError(Status
);
3451 IntReleaseWindowObject(WindowObject
);
3454 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3456 IntReleaseWindowObject(WindowObject
);
3461 Safepl
.showCmd
= ((WindowObject
->Flags
& WINDOWOBJECT_RESTOREMAX
) ? SW_MAXIMIZE
: SW_SHOWNORMAL
);
3463 Size
.x
= WindowObject
->WindowRect
.left
;
3464 Size
.y
= WindowObject
->WindowRect
.top
;
3465 InternalPos
= WinPosInitInternalPos(WindowObject
, &Size
,
3466 &WindowObject
->WindowRect
);
3469 Safepl
.rcNormalPosition
= InternalPos
->NormalRect
;
3470 Safepl
.ptMinPosition
= InternalPos
->IconPos
;
3471 Safepl
.ptMaxPosition
= InternalPos
->MaxPos
;
3475 IntReleaseWindowObject(WindowObject
);
3479 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3480 if(!NT_SUCCESS(Status
))
3482 SetLastNtError(Status
);
3483 IntReleaseWindowObject(WindowObject
);
3487 IntReleaseWindowObject(WindowObject
);
3493 * Return the dimension of the window in the screen coordinates.
3494 * \param hWnd window handle.
3495 * \param Rect pointer to the buffer where the coordinates are returned.
3501 NtUserGetWindowRect(HWND hWnd
, LPRECT Rect
)
3506 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3508 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3511 Status
= MmCopyToCaller(Rect
, &Wnd
->WindowRect
, sizeof(RECT
));
3512 if (!NT_SUCCESS(Status
))
3514 IntReleaseWindowObject(Wnd
);
3515 SetLastNtError(Status
);
3519 IntReleaseWindowObject(Wnd
);
3528 NtUserGetWindowThreadProcessId(HWND hWnd
, LPDWORD UnsafePid
)
3533 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3535 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3539 tid
= (DWORD
)IntGetWndThreadId(Wnd
);
3540 pid
= (DWORD
)IntGetWndProcessId(Wnd
);
3542 if (UnsafePid
) MmCopyToCaller(UnsafePid
, &pid
, sizeof(DWORD
));
3552 NtUserLockWindowUpdate(DWORD Unknown0
)
3572 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3573 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3574 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3578 QueryWindow based on KJK::Hyperion and James Tabor.
3580 0 = QWUniqueProcessId
3581 1 = QWUniqueThreadId
3582 4 = QWIsHung Implements IsHungAppWindow found
3585 9 = QWKillWindow When I called this with hWnd ==
3586 DesktopWindow, it shutdown the system
3593 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3595 PWINDOW_OBJECT Window
= IntGetWindowObject(hWnd
);
3600 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3606 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3607 Result
= (DWORD
)IntGetWndProcessId(Window
);
3610 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3611 Result
= (DWORD
)IntGetWndThreadId(Window
);
3614 case QUERY_WINDOW_ISHUNG
:
3615 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
3619 Result
= (DWORD
)NULL
;
3623 IntReleaseWindowObject(Window
);
3633 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3647 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3649 UNICODE_STRING SafeMessageName
;
3653 if(MessageNameUnsafe
== NULL
)
3655 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3659 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3660 if(!NT_SUCCESS(Status
))
3662 SetLastNtError(Status
);
3666 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3668 RtlFreeUnicodeString(&SafeMessageName
);
3677 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3690 NtUserSetInternalWindowPos(DWORD Unknown0
,
3706 NtUserSetLayeredWindowAttributes(DWORD Unknown0
,
3721 NtUserSetLogonNotifyWindow(DWORD Unknown0
)
3738 PWINDOW_OBJECT WindowObject
;
3741 WindowObject
= IntGetWindowObject((HWND
) Wnd
);
3742 if (NULL
== WindowObject
)
3744 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3748 if (! IntSetMenu(WindowObject
, Menu
, &Changed
))
3750 IntReleaseWindowObject(WindowObject
);
3754 IntReleaseWindowObject(WindowObject
);
3756 if (Changed
&& Repaint
)
3758 WinPosSetWindowPos(Wnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3759 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3770 NtUserSetWindowFNID(DWORD Unknown0
,
3784 NtUserSetWindowPlacement(HWND hWnd
,
3785 WINDOWPLACEMENT
*lpwndpl
)
3787 PWINDOW_OBJECT WindowObject
;
3788 WINDOWPLACEMENT Safepl
;
3791 WindowObject
= IntGetWindowObject(hWnd
);
3792 if (WindowObject
== NULL
)
3794 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3797 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3798 if(!NT_SUCCESS(Status
))
3800 SetLastNtError(Status
);
3801 IntReleaseWindowObject(WindowObject
);
3804 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3806 IntReleaseWindowObject(WindowObject
);
3810 if ((WindowObject
->Style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
3812 WinPosSetWindowPos(WindowObject
->Self
, NULL
,
3813 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
3814 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
3815 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
3816 SWP_NOZORDER
| SWP_NOACTIVATE
);
3819 /* FIXME - change window status */
3820 WinPosShowWindow(WindowObject
->Self
, Safepl
.showCmd
);
3822 if (WindowObject
->InternalPos
== NULL
)
3823 WindowObject
->InternalPos
= ExAllocatePoolWithTag(PagedPool
, sizeof(INTERNALPOS
), TAG_WININTLIST
);
3824 WindowObject
->InternalPos
->NormalRect
= Safepl
.rcNormalPosition
;
3825 WindowObject
->InternalPos
->IconPos
= Safepl
.ptMinPosition
;
3826 WindowObject
->InternalPos
->MaxPos
= Safepl
.ptMaxPosition
;
3828 IntReleaseWindowObject(WindowObject
);
3839 HWND hWndInsertAfter
,
3846 return WinPosSetWindowPos(hWnd
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
3851 IntGetWindowRgn(HWND hWnd
, HRGN hRgn
)
3854 PWINDOW_OBJECT WindowObject
;
3858 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
3860 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3865 IntReleaseWindowObject(WindowObject
);
3869 /* Create a new window region using the window rectangle */
3870 VisRgn
= UnsafeIntCreateRectRgnIndirect(&WindowObject
->WindowRect
);
3871 NtGdiOffsetRgn(VisRgn
, -WindowObject
->WindowRect
.left
, -WindowObject
->WindowRect
.top
);
3872 /* if there's a region assigned to the window, combine them both */
3873 if(WindowObject
->WindowRegion
&& !(WindowObject
->Style
& WS_MINIMIZE
))
3874 NtGdiCombineRgn(VisRgn
, VisRgn
, WindowObject
->WindowRegion
, RGN_AND
);
3875 /* Copy the region into hRgn */
3876 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
3878 if((pRgn
= RGNDATA_LockRgn(hRgn
)))
3880 Ret
= pRgn
->rdh
.iType
;
3881 RGNDATA_UnlockRgn(hRgn
);
3886 NtGdiDeleteObject(VisRgn
);
3888 IntReleaseWindowObject(WindowObject
);
3893 IntGetWindowRgnBox(HWND hWnd
, RECT
*Rect
)
3896 PWINDOW_OBJECT WindowObject
;
3900 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
3902 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3907 IntReleaseWindowObject(WindowObject
);
3911 /* Create a new window region using the window rectangle */
3912 VisRgn
= UnsafeIntCreateRectRgnIndirect(&WindowObject
->WindowRect
);
3913 NtGdiOffsetRgn(VisRgn
, -WindowObject
->WindowRect
.left
, -WindowObject
->WindowRect
.top
);
3914 /* if there's a region assigned to the window, combine them both */
3915 if(WindowObject
->WindowRegion
&& !(WindowObject
->Style
& WS_MINIMIZE
))
3916 NtGdiCombineRgn(VisRgn
, VisRgn
, WindowObject
->WindowRegion
, RGN_AND
);
3918 if((pRgn
= RGNDATA_LockRgn(VisRgn
)))
3920 Ret
= pRgn
->rdh
.iType
;
3921 *Rect
= pRgn
->rdh
.rcBound
;
3922 RGNDATA_UnlockRgn(VisRgn
);
3927 NtGdiDeleteObject(VisRgn
);
3929 IntReleaseWindowObject(WindowObject
);
3943 PWINDOW_OBJECT WindowObject
;
3945 WindowObject
= IntGetWindowObject(hWnd
);
3946 if (WindowObject
== NULL
)
3948 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3952 /* FIXME - Verify if hRgn is a valid handle!!!!
3953 Propably make this operation thread-safe, but maybe it's not necessary */
3955 if(WindowObject
->WindowRegion
)
3957 /* Delete no longer needed region handle */
3958 NtGdiDeleteObject(WindowObject
->WindowRegion
);
3960 WindowObject
->WindowRegion
= hRgn
;
3962 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
3966 IntRedrawWindow(WindowObject
, NULL
, NULL
, RDW_INVALIDATE
);
3969 IntReleaseWindowObject(WindowObject
);
3978 NtUserShowWindow(HWND hWnd
,
3981 return WinPosShowWindow(hWnd
, nCmdShow
);
3989 NtUserShowWindowAsync(DWORD Unknown0
,
4002 NtUserUpdateLayeredWindow(DWORD Unknown0
,
4022 NtUserValidateRect(HWND hWnd
, const RECT
* Rect
)
4024 return (VOID
)NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
4032 NtUserWindowFromPoint(LONG X
, LONG Y
)
4036 PWINDOW_OBJECT DesktopWindow
, Window
= NULL
;
4038 if ((DesktopWindow
= IntGetWindowObject(IntGetDesktopWindow())))
4045 Hit
= WinPosWindowFromPoint(DesktopWindow
, PsGetWin32Thread()->MessageQueue
, &pt
, &Window
);
4050 IntReleaseWindowObject(Window
);
4051 IntReleaseWindowObject(DesktopWindow
);
4055 IntReleaseWindowObject(DesktopWindow
);
4065 * Undocumented function that is called from DefWindowProc to set
4073 NtUserDefSetText(HWND WindowHandle
, PUNICODE_STRING WindowText
)
4075 PWINDOW_OBJECT WindowObject
;
4076 UNICODE_STRING SafeText
;
4079 WindowObject
= IntGetWindowObject(WindowHandle
);
4082 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4088 Status
= IntSafeCopyUnicodeString(&SafeText
, WindowText
);
4089 if(!NT_SUCCESS(Status
))
4091 SetLastNtError(Status
);
4092 IntReleaseWindowObject(WindowObject
);
4098 RtlInitUnicodeString(&SafeText
, NULL
);
4101 /* FIXME - do this thread-safe! otherwise one could crash here! */
4102 RtlFreeUnicodeString(&WindowObject
->WindowName
);
4104 WindowObject
->WindowName
= SafeText
;
4106 IntReleaseWindowObject(WindowObject
);
4111 * NtUserInternalGetWindowText
4118 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4120 PWINDOW_OBJECT WindowObject
;
4124 if(lpString
&& (nMaxCount
<= 1))
4126 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4130 WindowObject
= IntGetWindowObject(hWnd
);
4133 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
4137 /* FIXME - do this thread-safe! otherwise one could crash here! */
4138 Result
= WindowObject
->WindowName
.Length
/ sizeof(WCHAR
);
4141 const WCHAR Terminator
= L
'\0';
4143 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4145 Copy
= min(nMaxCount
- 1, Result
);
4148 Status
= MmCopyToCaller(Buffer
, WindowObject
->WindowName
.Buffer
, Copy
* sizeof(WCHAR
));
4149 if(!NT_SUCCESS(Status
))
4151 SetLastNtError(Status
);
4152 IntReleaseWindowObject(WindowObject
);
4158 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4159 if(!NT_SUCCESS(Status
))
4161 SetLastNtError(Status
);
4162 IntReleaseWindowObject(WindowObject
);
4169 IntReleaseWindowObject(WindowObject
);
4174 NtUserDereferenceWndProcHandle(WNDPROC wpHandle
, WndProcHandle
*Data
)
4176 WndProcHandle Entry
;
4177 if (((DWORD
)wpHandle
& 0xFFFF0000) == 0xFFFF0000)
4179 Entry
= WndProcHandlesArray
[(DWORD
)wpHandle
& 0x0000FFFF];
4180 Data
->WindowProc
= Entry
.WindowProc
;
4181 Data
->IsUnicode
= Entry
.IsUnicode
;
4182 Data
->ProcessID
= Entry
.ProcessID
;
4191 IntAddWndProcHandle(WNDPROC WindowProc
, BOOL IsUnicode
)
4196 WndProcHandle
*OldArray
;
4199 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4201 if (WndProcHandlesArray
[i
].WindowProc
== NULL
)
4209 OldArray
= WndProcHandlesArray
;
4210 OldArraySize
= WndProcHandlesArraySize
;
4211 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,(OldArraySize
+ WPH_SIZE
) * sizeof(WndProcHandle
), TAG_WINPROCLST
);
4212 WndProcHandlesArraySize
= OldArraySize
+ WPH_SIZE
;
4213 RtlCopyMemory(WndProcHandlesArray
,OldArray
,OldArraySize
* sizeof(WndProcHandle
));
4214 ExFreePool(OldArray
);
4215 FreeSpot
= OldArraySize
+ 1;
4217 WndProcHandlesArray
[FreeSpot
].WindowProc
= WindowProc
;
4218 WndProcHandlesArray
[FreeSpot
].IsUnicode
= IsUnicode
;
4219 WndProcHandlesArray
[FreeSpot
].ProcessID
= PsGetCurrentProcessId();
4220 return FreeSpot
+ 0xFFFF0000;
4224 IntRemoveWndProcHandle(WNDPROC Handle
)
4227 position
= (DWORD
)Handle
& 0x0000FFFF;
4228 if (position
> WndProcHandlesArraySize
)
4232 WndProcHandlesArray
[position
].WindowProc
= NULL
;
4233 WndProcHandlesArray
[position
].IsUnicode
= FALSE
;
4234 WndProcHandlesArray
[position
].ProcessID
= NULL
;
4239 IntRemoveProcessWndProcHandles(HANDLE ProcessID
)
4242 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4244 if (WndProcHandlesArray
[i
].ProcessID
== ProcessID
)
4246 WndProcHandlesArray
[i
].WindowProc
= NULL
;
4247 WndProcHandlesArray
[i
].IsUnicode
= FALSE
;
4248 WndProcHandlesArray
[i
].ProcessID
= NULL
;