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.189 2004/02/22 15:14:27 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 ******************************************************************/
31 #include <ddk/ntddk.h>
32 #include <internal/safe.h>
33 #include <win32k/win32k.h>
34 #include <include/object.h>
35 #include <include/guicheck.h>
36 #include <include/window.h>
37 #include <include/class.h>
38 #include <include/error.h>
39 #include <include/winsta.h>
40 #include <include/desktop.h>
41 #include <include/winpos.h>
42 #include <include/callback.h>
43 #include <include/msgqueue.h>
44 #include <include/rect.h>
45 #include <include/dce.h>
46 #include <include/paint.h>
47 #include <include/painting.h>
48 #include <include/scroll.h>
49 #include <include/vis.h>
50 #include <include/menu.h>
51 #include <include/hotkey.h>
52 #include <include/focus.h>
53 #include <include/hook.h>
54 #include <include/useratom.h>
55 #include <include/tags.h>
58 #include <win32k/debug1.h>
61 static WndProcHandle
*WndProcHandlesArray
= 0;
62 static WORD WndProcHandlesArraySize
= 0;
63 #define WPH_SIZE 0x40 /* the size to add to the WndProcHandle array each time */
65 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
67 /* PRIVATE FUNCTIONS **********************************************************/
72 * Initialize windowing implementation.
78 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,WPH_SIZE
* sizeof(WndProcHandle
), TAG_WINPROCLST
);
79 WndProcHandlesArraySize
= WPH_SIZE
;
80 return STATUS_SUCCESS
;
86 * Cleanup windowing implementation.
90 CleanupWindowImpl(VOID
)
92 ExFreePool(WndProcHandlesArray
);
93 WndProcHandlesArray
= 0;
94 WndProcHandlesArraySize
= 0;
95 return STATUS_SUCCESS
;
98 /* HELPER FUNCTIONS ***********************************************************/
103 * Check if window is a broadcast.
106 * TRUE if window is broadcast, FALSE otherwise.
110 IntIsBroadcastHwnd(HWND hWnd
)
112 return (hWnd
== HWND_BROADCAST
|| hWnd
== HWND_TOPMOST
);
118 * Check if window is a desktop. Desktop windows has no parent.
121 * TRUE if window is desktop, FALSE otherwise.
125 IntIsDesktopWindow(PWINDOW_OBJECT Wnd
)
127 return Wnd
->Parent
== NULL
;
133 * The function determines whether the specified window handle identifies
134 * an existing window.
138 * Handle to the window to test.
141 * If the window handle identifies an existing window, the return value
142 * is TRUE. If the window handle does not identify an existing window,
143 * the return value is FALSE.
147 IntIsWindow(HWND hWnd
)
149 PWINDOW_OBJECT Window
;
151 if (!(Window
= IntGetWindowObject(hWnd
)))
154 IntReleaseWindowObject(Window
);
160 * IntGetProcessWindowObject
162 * Get window object from handle of specified process.
165 PWINDOW_OBJECT FASTCALL
166 IntGetProcessWindowObject(PW32PROCESS ProcessData
, HWND hWnd
)
168 PWINDOW_OBJECT WindowObject
;
171 Status
= ObmReferenceObjectByHandle(ProcessData
->WindowStation
->HandleTable
,
172 hWnd
, otWindow
, (PVOID
*)&WindowObject
);
173 if (!NT_SUCCESS(Status
))
183 * Get window object from handle of current process.
186 PWINDOW_OBJECT FASTCALL
187 IntGetWindowObject(HWND hWnd
)
189 return IntGetProcessWindowObject(PsGetWin32Process(), hWnd
);
193 * IntReleaseWindowObject
195 * Release window object returned by IntGetWindowObject or
196 * IntGetProcessWindowObject.
200 IntReleaseWindowObject(PWINDOW_OBJECT Window
)
202 ObmDereferenceObject(Window
);
208 * Compile a list of all child window handles from given window.
211 * This function is similar to Wine WIN_ListChildren. The caller
212 * must free the returned list with ExFreePool.
216 IntWinListChildren(PWINDOW_OBJECT Window
)
218 PWINDOW_OBJECT Child
;
220 UINT Index
, NumChildren
= 0;
222 ExAcquireFastMutexUnsafe(&Window
->ChildrenListLock
);
224 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
227 if (NumChildren
!= 0)
229 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
232 for (Child
= Window
->FirstChild
, Index
= 0;
234 Child
= Child
->NextSibling
, ++Index
)
235 List
[Index
] = Child
->Self
;
240 DPRINT1("Failed to allocate memory for children array\n");
244 ExReleaseFastMutexUnsafe(&Window
->ChildrenListLock
);
246 return (NumChildren
> 0) ? List
: NULL
;
249 /***********************************************************************
252 static void IntSendDestroyMsg(HWND Wnd
)
257 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
259 if (Wnd
== info
.hwndCaret
)
267 * Send the WM_DESTROY to the window.
269 IntSendMessage(Wnd
, WM_DESTROY
, 0, 0);
272 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
273 * make sure that the window still exists when we come back.
281 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
283 /* start from the end (FIXME: is this needed?) */
284 for (i
= 0; pWndArray
[i
]; i
++) ;
288 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
290 HeapFree(GetProcessHeap(), 0, pWndArray
);
294 DPRINT("destroyed itself while in WM_DESTROY!\n");
299 /***********************************************************************
302 * Destroy storage associated to a window. "Internals" p.358
304 static LRESULT
IntDestroyWindow(PWINDOW_OBJECT Window
,
305 PW32PROCESS ProcessData
,
306 PW32THREAD ThreadData
,
307 BOOLEAN SendMessages
)
311 PWINDOW_OBJECT Child
;
314 if (! IntWndBelongsToThread(Window
, ThreadData
))
321 /* Send destroy messages */
322 IntSendDestroyMsg(Window
->Self
);
325 /* free child windows */
326 Children
= IntWinListChildren(Window
);
329 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
331 Child
= IntGetProcessWindowObject(ProcessData
, *ChildHandle
);
334 if(IntWndBelongsToThread(Child
, ThreadData
))
336 IntDestroyWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
340 IntSendDestroyMsg(Child
->Self
);
341 IntDestroyWindow(Child
, ProcessData
, Child
->OwnerThread
->Win32Thread
, FALSE
);
343 IntReleaseWindowObject(Child
);
346 ExFreePool(Children
);
352 * Clear the update region to make sure no WM_PAINT messages will be
353 * generated for this window while processing the WM_NCDESTROY.
355 IntRedrawWindow(Window
, NULL
, 0,
356 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
357 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
360 * Send the WM_NCDESTROY to the window being destroyed.
362 IntSendMessage(Window
->Self
, WM_NCDESTROY
, 0, 0);
365 /* reset shell window handles */
366 if(ProcessData
->WindowStation
)
368 if (Window
->Self
== ProcessData
->WindowStation
->ShellWindow
)
369 ProcessData
->WindowStation
->ShellWindow
= NULL
;
371 if (Window
->Self
== ProcessData
->WindowStation
->ShellListView
)
372 ProcessData
->WindowStation
->ShellListView
= NULL
;
375 /* Unregister hot keys */
376 UnregisterWindowHotKeys (Window
);
378 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
381 WinPosCheckInternalPos(Window
->Self
);
382 if (Window
->Self
== GetCapture())
387 /* free resources associated with the window */
388 TIMER_RemoveWindowTimers(Window
->Self
);
391 if (!(Window
->Style
& WS_CHILD
) && Window
->IDMenu
392 && (Menu
= IntGetMenuObject((HMENU
)Window
->IDMenu
)))
394 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
396 IntReleaseMenuObject(Menu
);
399 if(Window
->SystemMenu
400 && (Menu
= IntGetMenuObject(Window
->SystemMenu
)))
402 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
403 Window
->SystemMenu
= (HMENU
)0;
404 IntReleaseMenuObject(Menu
);
407 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
409 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
410 CLASS_RemoveWindow(Window
->Class
);
415 PWINDOW_OBJECT Parent
= Window
->Parent
;
416 ExAcquireFastMutexUnsafe(&Parent
->ChildrenListLock
);
417 IntUnlinkWindow(Window
);
418 ExReleaseFastMutexUnsafe(&Parent
->ChildrenListLock
);
421 ExAcquireFastMutexUnsafe (&ThreadData
->WindowListLock
);
422 RemoveEntryList(&Window
->ThreadListEntry
);
423 ExReleaseFastMutexUnsafe (&ThreadData
->WindowListLock
);
425 IntDestroyScrollBar(Window
, SB_VERT
);
426 IntDestroyScrollBar(Window
, SB_HORZ
);
428 ObmDereferenceObject(Window
->Class
);
429 Window
->Class
= NULL
;
430 ObmCloseHandle(ProcessData
->WindowStation
->HandleTable
, Window
->Self
);
437 PWINDOW_OBJECT WindowObject
,
441 PMENU_OBJECT OldMenuObject
, NewMenuObject
;
443 *Changed
= (WindowObject
->IDMenu
!= (UINT
) Menu
);
449 if (0 != WindowObject
->IDMenu
)
451 OldMenuObject
= IntGetMenuObject((HMENU
) WindowObject
->IDMenu
);
452 ASSERT(NULL
== OldMenuObject
|| OldMenuObject
->MenuInfo
.Wnd
== WindowObject
->Self
);
456 OldMenuObject
= NULL
;
461 NewMenuObject
= IntGetMenuObject(Menu
);
462 if (NULL
== NewMenuObject
)
464 if (NULL
!= OldMenuObject
)
466 IntReleaseMenuObject(OldMenuObject
);
468 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
471 if (NULL
!= NewMenuObject
->MenuInfo
.Wnd
)
473 /* Can't use the same menu for two windows */
474 if (NULL
!= OldMenuObject
)
476 IntReleaseMenuObject(OldMenuObject
);
478 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
484 WindowObject
->IDMenu
= (UINT
) Menu
;
485 if (NULL
!= NewMenuObject
)
487 NewMenuObject
->MenuInfo
.Wnd
= WindowObject
->Self
;
488 IntReleaseMenuObject(NewMenuObject
);
490 if (NULL
!= OldMenuObject
)
492 OldMenuObject
->MenuInfo
.Wnd
= NULL
;
493 IntReleaseMenuObject(OldMenuObject
);
500 /* INTERNAL ******************************************************************/
504 DestroyThreadWindows(struct _ETHREAD
*Thread
)
506 PLIST_ENTRY LastHead
;
507 PW32PROCESS Win32Process
;
508 PW32THREAD Win32Thread
;
509 PWINDOW_OBJECT Window
;
511 Win32Thread
= Thread
->Win32Thread
;
512 Win32Process
= Thread
->ThreadsProcess
->Win32Process
;
513 ExAcquireFastMutexUnsafe(&Win32Thread
->WindowListLock
);
515 while (Win32Thread
->WindowListHead
.Flink
!= &(Win32Thread
->WindowListHead
) &&
516 Win32Thread
->WindowListHead
.Flink
!= LastHead
)
518 LastHead
= Win32Thread
->WindowListHead
.Flink
;
519 Window
= CONTAINING_RECORD(Win32Thread
->WindowListHead
.Flink
, WINDOW_OBJECT
, ThreadListEntry
);
520 ExReleaseFastMutexUnsafe(&Win32Thread
->WindowListLock
);
521 WinPosShowWindow(Window
->Self
, SW_HIDE
);
522 IntDestroyWindow(Window
, Win32Process
, Win32Thread
, FALSE
);
523 ExAcquireFastMutexUnsafe(&Win32Thread
->WindowListLock
);
525 if (Win32Thread
->WindowListHead
.Flink
== LastHead
)
527 /* Window at head of list was not removed, should never happen, infinite loop */
530 ExReleaseFastMutexUnsafe(&Win32Thread
->WindowListLock
);
536 * Returns client window rectangle relative to the upper-left corner of client area.
538 * \note Does not check the validity of the parameters
541 IntGetClientRect(PWINDOW_OBJECT WindowObject
, PRECT Rect
)
543 ASSERT( WindowObject
);
546 Rect
->left
= Rect
->top
= 0;
547 Rect
->right
= WindowObject
->ClientRect
.right
- WindowObject
->ClientRect
.left
;
549 WindowObject
->ClientRect
.bottom
- WindowObject
->ClientRect
.top
;
555 IntGetFocusWindow(VOID
)
557 PUSER_MESSAGE_QUEUE Queue
;
558 PDESKTOP_OBJECT pdo
= IntGetActiveDesktop();
563 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
568 return(Queue
->FocusWindow
);
572 PWINDOW_OBJECT FASTCALL
573 IntGetParent(PWINDOW_OBJECT Wnd
)
575 if (Wnd
->Style
& WS_POPUP
)
579 else if (Wnd
->Style
& WS_CHILD
)
589 PMENU_OBJECT FASTCALL
590 IntGetSystemMenu(PWINDOW_OBJECT WindowObject
, BOOL bRevert
, BOOL RetMenu
)
592 PMENU_OBJECT MenuObject
, NewMenuObject
, ret
= NULL
;
593 PW32PROCESS W32Process
;
598 W32Process
= PsGetWin32Process();
600 if(!W32Process
->WindowStation
)
603 if(WindowObject
->SystemMenu
)
605 MenuObject
= IntGetMenuObject(WindowObject
->SystemMenu
);
608 IntDestroyMenuObject(MenuObject
, FALSE
, TRUE
);
609 WindowObject
->SystemMenu
= (HMENU
)0;
610 IntReleaseMenuObject(MenuObject
);
614 if(W32Process
->WindowStation
->SystemMenuTemplate
)
616 /* clone system menu */
617 MenuObject
= IntGetMenuObject(W32Process
->WindowStation
->SystemMenuTemplate
);
621 NewMenuObject
= IntCloneMenu(MenuObject
);
624 WindowObject
->SystemMenu
= NewMenuObject
->MenuInfo
.Self
;
625 NewMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
627 //IntReleaseMenuObject(NewMenuObject);
629 IntReleaseMenuObject(MenuObject
);
633 NewMenu
= IntLoadSysMenuTemplate();
636 MenuObject
= IntGetMenuObject(NewMenu
);
640 NewMenuObject
= IntCloneMenu(MenuObject
);
643 WindowObject
->SystemMenu
= NewMenuObject
->MenuInfo
.Self
;
644 NewMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
646 //IntReleaseMenuObject(NewMenuObject);
648 IntDestroyMenuObject(MenuObject
, FALSE
, TRUE
);
649 IntReleaseMenuObject(MenuObject
);
658 if(WindowObject
->SystemMenu
)
659 return IntGetMenuObject((HMENU
)WindowObject
->SystemMenu
);
668 IntGetWindowThreadProcessId(PWINDOW_OBJECT Wnd
, PDWORD pid
)
670 if (pid
) *pid
= (DWORD
) Wnd
->OwnerThread
->ThreadsProcess
->UniqueProcessId
;
671 return (DWORD
) Wnd
->OwnerThread
->Cid
.UniqueThread
;
675 IntIsChildWindow(HWND Parent
, HWND Child
)
677 PWINDOW_OBJECT BaseWindow
= IntGetWindowObject(Child
);
678 PWINDOW_OBJECT Window
= BaseWindow
;
679 while (Window
!= NULL
&& Window
->Style
& WS_CHILD
)
681 if (Window
->Self
== Parent
)
683 IntReleaseWindowObject(BaseWindow
);
686 Window
= Window
->Parent
;
688 IntReleaseWindowObject(BaseWindow
);
693 IntIsWindowVisible(HWND Wnd
)
695 PWINDOW_OBJECT BaseWindow
= IntGetWindowObject(Wnd
);
696 PWINDOW_OBJECT Window
= BaseWindow
;
697 BOOLEAN Result
= FALSE
;
698 while (Window
!= NULL
&& Window
->Style
& WS_CHILD
)
700 if (!(Window
->Style
& WS_VISIBLE
))
702 IntReleaseWindowObject(BaseWindow
);
705 Window
= Window
->Parent
;
707 if (Window
!= NULL
&& Window
->Style
& WS_VISIBLE
)
711 IntReleaseWindowObject(BaseWindow
);
716 /* link the window into siblings and parent. children are kept in place. */
720 PWINDOW_OBJECT WndParent
,
721 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
724 Wnd
->Parent
= WndParent
;
726 if ((Wnd
->PrevSibling
= WndPrevSibling
))
728 /* link after WndPrevSibling */
729 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
)) Wnd
->NextSibling
->PrevSibling
= Wnd
;
730 else if (Wnd
->Parent
->LastChild
== WndPrevSibling
) Wnd
->Parent
->LastChild
= Wnd
;
731 Wnd
->PrevSibling
->NextSibling
= Wnd
;
736 if ((Wnd
->NextSibling
= WndParent
->FirstChild
)) Wnd
->NextSibling
->PrevSibling
= Wnd
;
737 else Wnd
->Parent
->LastChild
= Wnd
;
738 WndParent
->FirstChild
= Wnd
;
744 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
746 PWINDOW_OBJECT Wnd
, WndOldOwner
;
749 Wnd
= IntGetWindowObject(hWnd
);
750 WndOldOwner
= Wnd
->Owner
;
753 ret
= WndOldOwner
->Self
;
754 IntReleaseWindowObject(WndOldOwner
);
760 Wnd
->Owner
= IntGetWindowObject(hWndNewOwner
);
761 IntReleaseWindowObject(Wnd
);
765 PWINDOW_OBJECT FASTCALL
766 IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
768 PWINDOW_OBJECT WndOldParent
;
769 HWND hWnd
, hWndNewParent
, hWndOldParent
;
774 hWndNewParent
= WndNewParent
->Self
;
777 * Windows hides the window first, then shows it again
778 * including the WM_SHOWWINDOW messages and all
780 WasVisible
= WinPosShowWindow(hWnd
, SW_HIDE
);
782 /* Validate that window and parent still exist */
783 if (!IntIsWindow(hWnd
) || !IntIsWindow(hWndNewParent
))
786 /* Window must belong to current process */
787 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
790 WndOldParent
= Wnd
->Parent
;
791 hWndOldParent
= WndOldParent
->Self
;
793 if (WndNewParent
!= WndOldParent
)
795 ExAcquireFastMutexUnsafe(&WndOldParent
->ChildrenListLock
);
796 IntUnlinkWindow(Wnd
);
797 ExReleaseFastMutexUnsafe(&WndOldParent
->ChildrenListLock
);
798 ExAcquireFastMutexUnsafe(&WndNewParent
->ChildrenListLock
);
799 IntLinkWindow(Wnd
, WndNewParent
, NULL
/*prev sibling*/);
800 ExReleaseFastMutexUnsafe(&WndNewParent
->ChildrenListLock
);
802 if (WndNewParent
->Self
!= IntGetDesktopWindow()) /* a child window */
804 if (!(Wnd
->Style
& WS_CHILD
))
806 //if ( Wnd->Menu ) DestroyMenu ( Wnd->menu );
807 IntSetMenu(Wnd
, NULL
, &MenuChanged
);
813 * SetParent additionally needs to make hwnd the topmost window
814 * in the x-order and send the expected WM_WINDOWPOSCHANGING and
815 * WM_WINDOWPOSCHANGED notification messages.
817 WinPosSetWindowPos(hWnd
, HWND_TOPMOST
, 0, 0, 0, 0,
818 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
| (WasVisible
? SWP_SHOWWINDOW
: 0));
821 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
822 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
826 * Validate that the old parent still exist, since it migth have been
827 * destroyed during the last callbacks to user-mode
829 return !IntIsWindow(hWndOldParent
) ? NULL
: WndOldParent
;
833 IntSetSystemMenu(PWINDOW_OBJECT WindowObject
, PMENU_OBJECT MenuObject
)
835 PMENU_OBJECT OldMenuObject
;
836 if(WindowObject
->SystemMenu
)
838 OldMenuObject
= IntGetMenuObject(WindowObject
->SystemMenu
);
841 OldMenuObject
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
842 IntReleaseMenuObject(OldMenuObject
);
848 /* FIXME check window style, propably return FALSE ? */
849 WindowObject
->SystemMenu
= MenuObject
->MenuInfo
.Self
;
850 MenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
853 WindowObject
->SystemMenu
= (HMENU
)0;
859 /* unlink the window from siblings and parent. children are kept in place. */
861 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
863 PWINDOW_OBJECT WndParent
= Wnd
->Parent
;
865 if (Wnd
->NextSibling
) Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
866 else if (WndParent
->LastChild
== Wnd
) WndParent
->LastChild
= Wnd
->PrevSibling
;
868 if (Wnd
->PrevSibling
) Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
869 else if (WndParent
->FirstChild
== Wnd
) WndParent
->FirstChild
= Wnd
->NextSibling
;
870 //else if (parent->first_unlinked == win) parent->first_unlinked = Wnd->NextSibling;
875 IntWndBelongsToThread(PWINDOW_OBJECT Window
, PW32THREAD ThreadData
)
877 if (Window
->OwnerThread
&& Window
->OwnerThread
->Win32Thread
)
879 return (Window
->OwnerThread
->Win32Thread
== ThreadData
);
886 /* FUNCTIONS *****************************************************************/
892 NtUserAlterWindowStyle(DWORD Unknown0
,
903 * As best as I can figure, this function is used by EnumWindows,
904 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
906 * It's supposed to build a list of HWNDs to return to the caller.
907 * We can figure out what kind of list by what parameters are
926 /* FIXME handle bChildren */
929 PWINDOW_OBJECT WindowObject
= NULL
;
930 PWINDOW_OBJECT Child
;
932 WindowObject
= IntGetWindowObject ( hwndParent
);
935 DPRINT("Bad window handle 0x%x\n", hwndParent
);
936 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
940 ExAcquireFastMutex ( &WindowObject
->ChildrenListLock
);
941 Child
= WindowObject
->FirstChild
;
944 if ( pWnd
&& dwCount
< nBufSize
)
945 pWnd
[dwCount
] = Child
->Self
;
947 Child
= Child
->NextSibling
;
949 ExReleaseFastMutex ( &WindowObject
->ChildrenListLock
);
950 IntReleaseWindowObject ( WindowObject
);
952 else if ( dwThreadId
)
955 struct _ETHREAD
* Thread
;
956 struct _EPROCESS
* ThreadsProcess
;
957 struct _W32PROCESS
* Win32Process
;
958 struct _WINSTATION_OBJECT
* WindowStation
;
959 PUSER_HANDLE_TABLE HandleTable
;
961 PUSER_HANDLE_BLOCK Block
= NULL
;
964 Status
= PsLookupThreadByThreadId ( (PVOID
)dwThreadId
, &Thread
);
965 if ( !NT_SUCCESS(Status
) || !Thread
)
967 DPRINT("Bad ThreadId 0x%x\n", dwThreadId
);
968 SetLastWin32Error(ERROR_INVALID_HANDLE
);
971 ThreadsProcess
= Thread
->ThreadsProcess
;
972 ASSERT(ThreadsProcess
);
973 Win32Process
= ThreadsProcess
->Win32Process
;
974 ASSERT(Win32Process
);
975 WindowStation
= Win32Process
->WindowStation
;
976 ASSERT(WindowStation
);
977 HandleTable
= (PUSER_HANDLE_TABLE
)(WindowStation
->HandleTable
);
980 ObDereferenceObject(Thread
);
982 ExAcquireFastMutex(&HandleTable
->ListLock
);
984 Current
= HandleTable
->ListHead
.Flink
;
985 while ( Current
!= &HandleTable
->ListHead
)
987 Block
= CONTAINING_RECORD(Current
, USER_HANDLE_BLOCK
, ListEntry
);
988 for ( i
= 0; i
< HANDLE_BLOCK_ENTRIES
; i
++ )
990 PVOID ObjectBody
= Block
->Handles
[i
].ObjectBody
;
993 if ( pWnd
&& dwCount
< nBufSize
)
996 (HWND
)ObmReferenceObjectByPointer ( ObjectBody
, otWindow
);
1001 Current
= Current
->Flink
;
1004 ExReleaseFastMutex(&HandleTable
->ListLock
);
1008 PDESKTOP_OBJECT DesktopObject
= NULL
;
1010 PWINDOW_OBJECT Child
, WndDesktop
;
1014 DesktopObject
= IntGetDesktopObject ( hDesktop
);
1017 DesktopObject
= IntGetActiveDesktop();
1020 DPRINT("Bad desktop handle 0x%x\n", hDesktop
);
1021 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1025 KeAcquireSpinLock ( &DesktopObject
->Lock
, &OldIrql
);
1027 WndDesktop
= IntGetWindowObject(DesktopObject
->DesktopWindow
);
1028 Child
= (WndDesktop
? WndDesktop
->FirstChild
: NULL
);
1031 if ( pWnd
&& dwCount
< nBufSize
)
1032 pWnd
[dwCount
] = Child
->Self
;
1034 Child
= Child
->NextSibling
;
1036 KeReleaseSpinLock ( &DesktopObject
->Lock
, OldIrql
);
1047 NtUserChildWindowFromPointEx(HWND hwndParent
,
1052 PWINDOW_OBJECT pParent
, pCurrent
, pLast
;
1055 BOOL bFirstRun
= TRUE
;
1059 pParent
= IntGetWindowObject(hwndParent
);
1062 ExAcquireFastMutexUnsafe (&pParent
->ChildrenListLock
);
1064 pLast
= IntGetWindowObject(pParent
->LastChild
->Self
);
1065 pCurrent
= IntGetWindowObject(pParent
->FirstChild
->Self
);
1071 pCurrent
= IntGetWindowObject(pCurrent
->NextSibling
->Self
);
1079 rc
.left
= pCurrent
->WindowRect
.left
- pCurrent
->Parent
->ClientRect
.left
;
1080 rc
.top
= pCurrent
->WindowRect
.top
- pCurrent
->Parent
->ClientRect
.top
;
1081 rc
.right
= rc
.left
+ (pCurrent
->WindowRect
.right
- pCurrent
->WindowRect
.left
);
1082 rc
.bottom
= rc
.top
+ (pCurrent
->WindowRect
.bottom
- pCurrent
->WindowRect
.top
);
1083 DbgPrint("Rect: %i,%i,%i,%i\n",rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1084 if (POINT_IN_RECT(p
,rc
)) /* Found a match */
1086 if ( (uiFlags
& CWP_SKIPDISABLED
) && (pCurrent
->Style
& WS_DISABLED
) )
1088 if( (uiFlags
& CWP_SKIPTRANSPARENT
) && (pCurrent
->ExStyle
& WS_EX_TRANSPARENT
) )
1090 if( (uiFlags
& CWP_SKIPINVISIBLE
) && !(pCurrent
->Style
& WS_VISIBLE
) )
1093 ExReleaseFastMutexUnsafe(&pParent
->ChildrenListLock
);
1094 return pCurrent
->Self
;
1097 while(pCurrent
!= pLast
);
1099 ExReleaseFastMutexUnsafe(&pParent
->ChildrenListLock
);
1102 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1113 NtUserCreateWindowEx(DWORD dwExStyle
,
1114 PUNICODE_STRING lpClassName
,
1115 PUNICODE_STRING lpWindowName
,
1123 HINSTANCE hInstance
,
1126 BOOL bUnicodeWindow
)
1128 PWINSTATION_OBJECT WinStaObject
;
1129 PWNDCLASS_OBJECT ClassObject
;
1130 PWINDOW_OBJECT WindowObject
;
1131 PWINDOW_OBJECT ParentWindow
;
1132 HWND ParentWindowHandle
;
1133 HWND OwnerWindowHandle
;
1134 PMENU_OBJECT SystemMenu
;
1135 UNICODE_STRING WindowName
;
1139 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1144 CBT_CREATEWNDW CbtCreate
;
1148 DPRINT("NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1150 if (! RtlCreateUnicodeString(&WindowName
,
1151 NULL
== lpWindowName
->Buffer
?
1152 L
"" : lpWindowName
->Buffer
))
1154 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1158 ParentWindowHandle
= PsGetWin32Thread()->Desktop
->DesktopWindow
;
1159 OwnerWindowHandle
= NULL
;
1161 if (hWndParent
== HWND_MESSAGE
)
1164 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1165 * message window (style: WS_POPUP|WS_DISABLED)
1169 else if (hWndParent
)
1171 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1172 ParentWindowHandle
= hWndParent
;
1174 OwnerWindowHandle
= NtUserGetAncestor(hWndParent
, GA_ROOT
);
1176 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1178 RtlFreeUnicodeString(&WindowName
);
1179 return (HWND
)0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1182 if (NULL
!= ParentWindowHandle
)
1184 ParentWindow
= IntGetWindowObject(ParentWindowHandle
);
1188 ParentWindow
= NULL
;
1191 /* FIXME: parent must belong to the current process */
1193 /* Check the class. */
1194 Status
= ClassReferenceClassByNameOrAtom(&ClassObject
, lpClassName
->Buffer
);
1195 if (!NT_SUCCESS(Status
))
1197 RtlFreeUnicodeString(&WindowName
);
1198 if (NULL
!= ParentWindow
)
1200 IntReleaseWindowObject(ParentWindow
);
1205 /* Check the window station. */
1206 DPRINT("IoGetCurrentProcess() %X\n", IoGetCurrentProcess());
1207 DPRINT("PROCESS_WINDOW_STATION %X\n", PROCESS_WINDOW_STATION());
1208 Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
1212 if (!NT_SUCCESS(Status
))
1214 ObmDereferenceObject(ClassObject
);
1215 RtlFreeUnicodeString(&WindowName
);
1216 if (NULL
!= ParentWindow
)
1218 IntReleaseWindowObject(ParentWindow
);
1220 DPRINT("Validation of window station handle (0x%X) failed\n",
1221 PROCESS_WINDOW_STATION());
1225 /* Create the window object. */
1226 WindowObject
= (PWINDOW_OBJECT
)
1227 ObmCreateObject(PsGetWin32Process()->WindowStation
->HandleTable
, &Handle
,
1228 otWindow
, sizeof(WINDOW_OBJECT
) + ClassObject
->cbWndExtra
1231 DPRINT("Created object with handle %X\n", Handle
);
1234 ObDereferenceObject(WinStaObject
);
1235 ObmDereferenceObject(ClassObject
);
1236 RtlFreeUnicodeString(&WindowName
);
1237 if (NULL
!= ParentWindow
)
1239 IntReleaseWindowObject(ParentWindow
);
1241 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1244 ObDereferenceObject(WinStaObject
);
1246 if (NULL
== PsGetWin32Thread()->Desktop
->DesktopWindow
)
1248 /* If there is no desktop window yet, we must be creating it */
1249 PsGetWin32Thread()->Desktop
->DesktopWindow
= Handle
;
1253 * Fill out the structure describing it.
1255 WindowObject
->Class
= ClassObject
;
1256 WindowObject
->ExStyle
= dwExStyle
;
1257 WindowObject
->Style
= dwStyle
& ~WS_VISIBLE
;
1258 DPRINT("1: Style is now %d\n", WindowObject
->Style
);
1260 WindowObject
->SystemMenu
= (HMENU
)0;
1261 WindowObject
->ContextHelpId
= 0;
1262 WindowObject
->IDMenu
= 0;
1263 WindowObject
->Instance
= hInstance
;
1264 WindowObject
->Self
= Handle
;
1265 if (0 != (dwStyle
& WS_CHILD
))
1267 WindowObject
->IDMenu
= (UINT
) hMenu
;
1271 IntSetMenu(WindowObject
, hMenu
, &MenuChanged
);
1273 WindowObject
->MessageQueue
= PsGetWin32Thread()->MessageQueue
;
1274 WindowObject
->Parent
= ParentWindow
;
1275 WindowObject
->Owner
= IntGetWindowObject(OwnerWindowHandle
);
1276 WindowObject
->UserData
= 0;
1277 if ((((DWORD
)ClassObject
->lpfnWndProcA
& 0xFFFF0000) != 0xFFFF0000)
1278 && (((DWORD
)ClassObject
->lpfnWndProcW
& 0xFFFF0000) != 0xFFFF0000))
1280 WindowObject
->Unicode
= bUnicodeWindow
;
1284 WindowObject
->Unicode
= ClassObject
->Unicode
;
1286 WindowObject
->WndProcA
= ClassObject
->lpfnWndProcA
;
1287 WindowObject
->WndProcW
= ClassObject
->lpfnWndProcW
;
1288 WindowObject
->OwnerThread
= PsGetCurrentThread();
1289 WindowObject
->FirstChild
= NULL
;
1290 WindowObject
->LastChild
= NULL
;
1291 WindowObject
->PrevSibling
= NULL
;
1292 WindowObject
->NextSibling
= NULL
;
1294 /* extra window data */
1295 if (ClassObject
->cbWndExtra
!= 0)
1297 WindowObject
->ExtraData
= (PCHAR
)(WindowObject
+ 1);
1298 WindowObject
->ExtraDataSize
= ClassObject
->cbWndExtra
;
1299 RtlZeroMemory(WindowObject
->ExtraData
, WindowObject
->ExtraDataSize
);
1303 WindowObject
->ExtraData
= NULL
;
1304 WindowObject
->ExtraDataSize
= 0;
1307 InitializeListHead(&WindowObject
->PropListHead
);
1308 ExInitializeFastMutex(&WindowObject
->PropListLock
);
1309 ExInitializeFastMutex(&WindowObject
->ChildrenListLock
);
1310 ExInitializeFastMutex(&WindowObject
->UpdateLock
);
1312 RtlInitUnicodeString(&WindowObject
->WindowName
, WindowName
.Buffer
);
1314 /* Correct the window style. */
1315 if (!(dwStyle
& WS_CHILD
))
1317 WindowObject
->Style
|= WS_CLIPSIBLINGS
;
1318 DPRINT("3: Style is now %d\n", WindowObject
->Style
);
1319 if (!(dwStyle
& WS_POPUP
))
1321 WindowObject
->Style
|= WS_CAPTION
;
1322 WindowObject
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1323 DPRINT("4: Style is now %d\n", WindowObject
->Style
);
1324 /* FIXME: Note the window needs a size. */
1328 /* create system menu */
1329 if((WindowObject
->Style
& WS_SYSMENU
) && (WindowObject
->Style
& WS_CAPTION
))
1331 SystemMenu
= IntGetSystemMenu(WindowObject
, TRUE
, TRUE
);
1334 WindowObject
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1335 IntReleaseMenuObject(SystemMenu
);
1339 /* Insert the window into the thread's window list. */
1340 ExAcquireFastMutexUnsafe (&PsGetWin32Thread()->WindowListLock
);
1341 InsertTailList (&PsGetWin32Thread()->WindowListHead
,
1342 &WindowObject
->ThreadListEntry
);
1343 ExReleaseFastMutexUnsafe (&PsGetWin32Thread()->WindowListLock
);
1345 /* Allocate a DCE for this window. */
1346 if (dwStyle
& CS_OWNDC
)
1348 WindowObject
->Dce
= DceAllocDCE(WindowObject
->Self
, DCE_WINDOW_DC
);
1350 /* FIXME: Handle "CS_CLASSDC" */
1352 /* Initialize the window dimensions. */
1353 WindowObject
->WindowRect
.left
= x
;
1354 WindowObject
->WindowRect
.top
= y
;
1355 WindowObject
->WindowRect
.right
= x
+ nWidth
;
1356 WindowObject
->WindowRect
.bottom
= y
+ nHeight
;
1357 if (0 != (WindowObject
->Style
& WS_CHILD
))
1359 NtGdiOffsetRect(&(WindowObject
->WindowRect
), WindowObject
->Parent
->ClientRect
.left
,
1360 WindowObject
->Parent
->ClientRect
.top
);
1362 WindowObject
->ClientRect
= WindowObject
->WindowRect
;
1364 Cs
.lpCreateParams
= lpParam
;
1365 Cs
.hInstance
= hInstance
;
1367 Cs
.hwndParent
= ParentWindowHandle
;
1373 Cs
.lpszName
= lpWindowName
->Buffer
;
1374 Cs
.lpszClass
= lpClassName
->Buffer
;
1375 Cs
.dwExStyle
= dwExStyle
;
1376 CbtCreate
.lpcs
= &Cs
;
1377 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1378 if (HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) Handle
, (LPARAM
) &CbtCreate
))
1380 if (NULL
!= ParentWindow
)
1382 IntReleaseWindowObject(ParentWindow
);
1384 DPRINT1("CBT-hook returned !0\n");
1389 * Get the size and position of the window.
1391 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
1393 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1395 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
1396 WinPosGetMinMaxInfo(WindowObject
, &MaxSize
, &MaxPos
, &MinTrack
,
1398 if (MaxSize
.x
< nWidth
) nWidth
= MaxSize
.x
;
1399 if (MaxSize
.y
< nHeight
) nHeight
= MaxSize
.y
;
1400 if (nWidth
< MinTrack
.x
) nWidth
= MinTrack
.x
;
1401 if (nHeight
< MinTrack
.y
) nHeight
= MinTrack
.y
;
1402 if (nWidth
< 0) nWidth
= 0;
1403 if (nHeight
< 0) nHeight
= 0;
1406 WindowObject
->WindowRect
.left
= x
;
1407 WindowObject
->WindowRect
.top
= y
;
1408 WindowObject
->WindowRect
.right
= x
+ nWidth
;
1409 WindowObject
->WindowRect
.bottom
= y
+ nHeight
;
1410 if (0 != (WindowObject
->Style
& WS_CHILD
))
1412 NtGdiOffsetRect(&(WindowObject
->WindowRect
), WindowObject
->Parent
->ClientRect
.left
,
1413 WindowObject
->Parent
->ClientRect
.top
);
1415 WindowObject
->ClientRect
= WindowObject
->WindowRect
;
1417 /* FIXME: Initialize the window menu. */
1419 /* Initialize the window's scrollbars */
1420 if (dwStyle
& WS_VSCROLL
)
1422 WindowObject
->Style
&= ~WS_VSCROLL
;
1423 NtUserShowScrollBar(WindowObject
->Self
, SB_VERT
, TRUE
);
1425 if (dwStyle
& WS_HSCROLL
)
1427 WindowObject
->Style
&= ~WS_HSCROLL
;
1428 NtUserShowScrollBar(WindowObject
->Self
, SB_HORZ
, TRUE
);
1431 /* Send a NCCREATE message. */
1437 DPRINT("[win32k.window] NtUserCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
1438 DPRINT("NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1439 DPRINT("NtUserCreateWindowEx(): About to send NCCREATE message.\n");
1440 Result
= IntSendMessage(WindowObject
->Self
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
1443 /* FIXME: Cleanup. */
1444 if (NULL
!= ParentWindow
)
1446 IntReleaseWindowObject(ParentWindow
);
1448 DPRINT("NtUserCreateWindowEx(): NCCREATE message failed.\n");
1452 /* Calculate the non-client size. */
1453 MaxPos
.x
= WindowObject
->WindowRect
.left
;
1454 MaxPos
.y
= WindowObject
->WindowRect
.top
;
1455 DPRINT("NtUserCreateWindowEx(): About to get non-client size.\n");
1456 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
1457 Result
= WinPosGetNonClientSize(WindowObject
->Self
,
1458 &WindowObject
->WindowRect
,
1459 &WindowObject
->ClientRect
);
1460 NtGdiOffsetRect(&WindowObject
->WindowRect
,
1461 MaxPos
.x
- WindowObject
->WindowRect
.left
,
1462 MaxPos
.y
- WindowObject
->WindowRect
.top
);
1464 if (NULL
!= ParentWindow
)
1466 /* link the window into the parent's child list */
1467 ExAcquireFastMutexUnsafe(&ParentWindow
->ChildrenListLock
);
1468 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
1470 /* link window as bottom sibling */
1471 IntLinkWindow(WindowObject
, ParentWindow
, ParentWindow
->LastChild
/*prev sibling*/);
1475 /* link window as top sibling */
1476 IntLinkWindow(WindowObject
, ParentWindow
, NULL
/*prev sibling*/);
1478 ExReleaseFastMutexUnsafe(&ParentWindow
->ChildrenListLock
);
1481 /* Send the WM_CREATE message. */
1482 DPRINT("NtUserCreateWindowEx(): about to send CREATE message.\n");
1483 Result
= IntSendMessage(WindowObject
->Self
, WM_CREATE
, 0, (LPARAM
) &Cs
);
1484 if (Result
== (LRESULT
)-1)
1486 /* FIXME: Cleanup. */
1487 if (NULL
!= ParentWindow
)
1489 IntReleaseWindowObject(ParentWindow
);
1491 DPRINT("NtUserCreateWindowEx(): send CREATE message failed.\n");
1495 /* Send move and size messages. */
1496 if (!(WindowObject
->Flags
& WINDOWOBJECT_NEED_SIZE
))
1500 DPRINT("NtUserCreateWindow(): About to send WM_SIZE\n");
1502 if ((WindowObject
->ClientRect
.right
- WindowObject
->ClientRect
.left
) < 0 ||
1503 (WindowObject
->ClientRect
.bottom
- WindowObject
->ClientRect
.top
) < 0)
1504 DPRINT("Sending bogus WM_SIZE\n");
1506 lParam
= MAKE_LONG(WindowObject
->ClientRect
.right
-
1507 WindowObject
->ClientRect
.left
,
1508 WindowObject
->ClientRect
.bottom
-
1509 WindowObject
->ClientRect
.top
);
1510 IntSendMessage(WindowObject
->Self
, WM_SIZE
, SIZE_RESTORED
,
1513 DPRINT("NtUserCreateWindow(): About to send WM_MOVE\n");
1515 if (0 != (WindowObject
->Style
& WS_CHILD
))
1517 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
- WindowObject
->Parent
->ClientRect
.left
,
1518 WindowObject
->ClientRect
.top
- WindowObject
->Parent
->ClientRect
.top
);
1522 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
,
1523 WindowObject
->ClientRect
.top
);
1525 IntSendMessage(WindowObject
->Self
, WM_MOVE
, 0, lParam
);
1528 /* Show or maybe minimize or maximize the window. */
1529 if (WindowObject
->Style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1534 SwFlag
= (WindowObject
->Style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
1536 WinPosMinMaximize(WindowObject
, SwFlag
, &NewPos
);
1538 ((WindowObject
->Style
& WS_CHILD
) || NtUserGetActiveWindow()) ?
1539 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
1540 SWP_NOZORDER
| SWP_FRAMECHANGED
;
1541 DPRINT("NtUserCreateWindow(): About to minimize/maximize\n");
1542 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
1543 WinPosSetWindowPos(WindowObject
->Self
, 0, NewPos
.left
, NewPos
.top
,
1544 NewPos
.right
, NewPos
.bottom
, SwFlag
);
1547 /* Notify the parent window of a new child. */
1548 if ((WindowObject
->Style
& WS_CHILD
) &&
1549 (!(WindowObject
->ExStyle
& WS_EX_NOPARENTNOTIFY
)))
1551 DPRINT("NtUserCreateWindow(): About to notify parent\n");
1552 IntSendMessage(WindowObject
->Parent
->Self
,
1554 MAKEWPARAM(WM_CREATE
, WindowObject
->IDMenu
),
1555 (LPARAM
)WindowObject
->Self
);
1558 if (dwStyle
& WS_VISIBLE
)
1560 DPRINT("NtUserCreateWindow(): About to show window\n");
1561 WinPosShowWindow(WindowObject
->Self
, dwShowMode
);
1564 DPRINT("NtUserCreateWindow(): = %X\n", Handle
);
1565 DPRINT("WindowObject->SystemMenu = 0x%x\n", WindowObject
->SystemMenu
);
1566 return((HWND
)Handle
);
1574 NtUserDeferWindowPos(HDWP WinPosInfo
,
1576 HWND WndInsertAfter
,
1593 NtUserDestroyWindow(HWND Wnd
)
1595 PWINDOW_OBJECT Window
, Parent
;
1598 Window
= IntGetWindowObject(Wnd
);
1604 /* Check for owner thread and desktop window */
1605 if ((Window
->OwnerThread
!= PsGetCurrentThread()) || IntIsDesktopWindow(Window
))
1607 IntReleaseWindowObject(Window
);
1608 SetLastWin32Error(ERROR_ACCESS_DENIED
);
1612 /* Look whether the focus is within the tree of windows we will
1615 if (!WinPosShowWindow(Wnd
, SW_HIDE
))
1617 if (NtUserGetActiveWindow() == Wnd
)
1619 WinPosActivateOtherWindow(Window
);
1622 ExAcquireFastMutex(&Window
->MessageQueue
->Lock
);
1623 if (Window
->MessageQueue
->ActiveWindow
== Window
->Self
)
1624 Window
->MessageQueue
->ActiveWindow
= NULL
;
1625 if (Window
->MessageQueue
->FocusWindow
== Window
->Self
)
1626 Window
->MessageQueue
->FocusWindow
= NULL
;
1627 if (Window
->MessageQueue
->CaptureWindow
== Window
->Self
)
1628 Window
->MessageQueue
->CaptureWindow
= NULL
;
1629 ExReleaseFastMutex(&Window
->MessageQueue
->Lock
);
1633 if (HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hwnd
, 0, TRUE
))
1639 isChild
= (0 != (Window
->Style
& WS_CHILD
));
1644 if (! USER_IsExitingThread(GetCurrentThreadId()))
1646 send_parent_notify(hwnd
, WM_DESTROY
);
1649 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
1651 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
1652 /* FIXME: clean up palette - see "Internals" p.352 */
1655 if (! IsWindow(Wnd
))
1661 if (!IntIsWindow(Wnd
))
1666 /* Recursively destroy owned windows */
1671 BOOL GotOne
= FALSE
;
1674 PWINDOW_OBJECT Child
, Desktop
;
1676 Desktop
= IntGetWindowObject(IntGetDesktopWindow());
1677 Children
= IntWinListChildren(Desktop
);
1678 IntReleaseWindowObject(Desktop
);
1681 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
1683 Child
= IntGetWindowObject(*ChildHandle
);
1688 if (Child
->Parent
!= Window
)
1690 IntReleaseWindowObject(Child
);
1693 if (IntWndBelongsToThread(Child
, PsGetWin32Thread()))
1695 IntReleaseWindowObject(Child
);
1696 NtUserDestroyWindow(*ChildHandle
);
1700 if (Child
->Owner
!= NULL
)
1702 IntReleaseWindowObject(Child
->Owner
);
1703 Child
->Owner
= NULL
;
1705 IntReleaseWindowObject(Child
);
1707 ExFreePool(Children
);
1716 if (!IntIsWindow(Wnd
))
1721 /* Unlink now so we won't bother with the children later on */
1722 Parent
= Window
->Parent
;
1723 ExAcquireFastMutexUnsafe(&Parent
->ChildrenListLock
);
1724 IntUnlinkWindow(Window
);
1725 Window
->Parent
= NULL
;
1726 ExReleaseFastMutexUnsafe(&Parent
->ChildrenListLock
);
1728 /* Destroy the window storage */
1729 IntDestroyWindow(Window
, PsGetWin32Process(), PsGetWin32Thread(), TRUE
);
1731 IntReleaseWindowObject(Window
);
1741 NtUserDrawMenuBarTemp(
1748 /* we'll use this function just for caching the menu bar */
1758 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
1771 NtUserFillWindow(DWORD Unknown0
,
1784 * Searches a window's children for a window with the specified
1787 * hwndParent = The window whose childs are to be searched.
1790 * hwndChildAfter = Search starts after this child window.
1791 * NULL = start from beginning
1793 * ucClassName = Class name to search for
1794 * Reguired parameter.
1796 * ucWindowName = Window name
1797 * ->Buffer == NULL = don't care
1800 * The HWND of the window if it was found, otherwise NULL
1803 * Should use MmCopyFromCaller, we don't want an access violation in here
1810 NtUserFindWindowEx(HWND hwndParent
,
1811 HWND hwndChildAfter
,
1812 PUNICODE_STRING ucClassName
,
1813 PUNICODE_STRING ucWindowName
)
1817 PWINDOW_OBJECT ParentWindow
, WndChildAfter
, WndChild
;
1818 PWNDCLASS_OBJECT classObject
;
1820 // Get a pointer to the class
1821 status
= ClassReferenceClassByNameOrAtom(&classObject
, ucClassName
->Buffer
);
1822 if (!NT_SUCCESS(status
))
1827 // If hwndParent==NULL use the desktop window instead
1829 hwndParent
= PsGetWin32Thread()->Desktop
->DesktopWindow
;
1832 ParentWindow
= IntGetWindowObject(hwndParent
);
1836 ObmDereferenceObject(classObject
);
1840 ExAcquireFastMutexUnsafe (&ParentWindow
->ChildrenListLock
);
1844 if (!(WndChildAfter
= IntGetWindowObject(hwndChildAfter
)))
1846 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1850 /* must be a direct child (not a decendant child)*/
1851 if (WndChildAfter
->Parent
!= ParentWindow
)
1853 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1857 WndChild
= WndChildAfter
->NextSibling
;
1861 WndChild
= ParentWindow
->FirstChild
;
1866 if (classObject
== WndChild
->Class
&& (ucWindowName
->Buffer
==NULL
||
1867 RtlCompareUnicodeString (ucWindowName
, &WndChild
->WindowName
, TRUE
) == 0))
1869 windowHandle
= WndChild
->Self
;
1871 ExReleaseFastMutexUnsafe (&ParentWindow
->ChildrenListLock
);
1872 IntReleaseWindowObject(ParentWindow
);
1873 ObmDereferenceObject (classObject
);
1875 return windowHandle
;
1878 WndChild
= WndChild
->NextSibling
;
1881 ExReleaseFastMutexUnsafe (&ParentWindow
->ChildrenListLock
);
1883 IntReleaseWindowObject(ParentWindow
);
1884 ObmDereferenceObject (classObject
);
1894 NtUserFlashWindowEx(DWORD Unknown0
)
1906 NtUserGetAncestor(HWND hWnd
, UINT Type
)
1908 PWINDOW_OBJECT Wnd
, WndAncestor
;
1909 HWND hWndAncestor
= NULL
;
1911 if (hWnd
== IntGetDesktopWindow())
1916 IntAcquireWinLockShared();
1918 if (!(Wnd
= IntGetWindowObject(hWnd
)))
1920 IntReleaseWinLock();
1921 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1928 WndAncestor
= Wnd
->Parent
;
1933 while (!IntIsDesktopWindow(WndAncestor
->Parent
))
1934 WndAncestor
= WndAncestor
->Parent
;
1941 PWINDOW_OBJECT Parent
= IntGetParent(WndAncestor
);
1943 WndAncestor
= Parent
;
1953 hWndAncestor
= WndAncestor
->Self
;
1956 IntReleaseWindowObject(Wnd
);
1957 IntReleaseWinLock();
1959 return hWndAncestor
;
1964 * Returns client window rectangle relative to the upper-left corner of client area.
1966 * \param hWnd window handle.
1967 * \param Rect pointer to the buffer where the coordinates are returned.
1974 NtUserGetClientRect(HWND hWnd
, LPRECT Rect
)
1976 PWINDOW_OBJECT WindowObject
;
1979 IntAcquireWinLockShared();
1980 if (!(WindowObject
= IntGetWindowObject(hWnd
)))
1982 IntReleaseWinLock();
1983 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1987 IntGetClientRect(WindowObject
, &SafeRect
);
1988 IntReleaseWinLock();
1990 if (! NT_SUCCESS(MmCopyToCaller(Rect
, &SafeRect
, sizeof(RECT
))))
2003 NtUserGetDesktopWindow()
2005 return IntGetDesktopWindow();
2013 NtUserGetInternalWindowPos(DWORD Unknown0
,
2027 NtUserGetLastActivePopup(HWND hWnd
)
2030 * This code can't work, because hWndLastPopup member of WINDOW_OBJECT is
2031 * not changed anywhere.
2032 * -- Filip, 01/nov/2003
2038 IntAcquireWinLockShared();
2040 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2042 IntReleaseWinLock();
2043 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2047 hWndLastPopup
= Wnd
->hWndLastPopup
;
2049 IntReleaseWinLock();
2051 return hWndLastPopup
;
2060 * The NtUserGetParent function retrieves a handle to the specified window's
2064 * Note that, despite its name, this function can return an owner window
2065 * instead of a parent window.
2072 NtUserGetParent(HWND hWnd
)
2074 PWINDOW_OBJECT Wnd
, WndParent
;
2075 HWND hWndParent
= NULL
;
2077 IntAcquireWinLockShared();
2079 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2081 IntReleaseWinLock();
2082 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2086 WndParent
= IntGetParent(Wnd
);
2089 hWndParent
= WndParent
->Self
;
2092 IntReleaseWindowObject(Wnd
);
2093 IntReleaseWinLock();
2101 * The NtUserSetParent function changes the parent window of the specified
2105 * The new parent window and the child window must belong to the same
2106 * application. If the window identified by the hWndChild parameter is
2107 * visible, the system performs the appropriate redrawing and repainting.
2108 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
2109 * or WS_POPUP window styles of the window whose parent is being changed.
2116 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2118 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
2119 HWND hWndOldParent
= NULL
;
2121 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
2123 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2127 if (hWndChild
== IntGetDesktopWindow())
2129 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2133 IntAcquireWinLockExclusive();
2136 if (!(WndParent
= IntGetWindowObject(hWndNewParent
)))
2138 IntReleaseWinLock();
2139 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2145 if (!(WndParent
= IntGetWindowObject(IntGetDesktopWindow())))
2147 IntReleaseWinLock();
2148 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2153 if (!(Wnd
= IntGetWindowObject(hWndChild
)))
2155 IntReleaseWinLock();
2156 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2160 WndOldParent
= IntSetParent(Wnd
, WndParent
);
2164 hWndOldParent
= WndOldParent
->Self
;
2167 IntReleaseWindowObject(Wnd
);
2168 IntReleaseWindowObject(WndParent
);
2169 IntReleaseWinLock();
2171 return hWndOldParent
;
2175 * NtUserGetShellWindow
2177 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
2184 NtUserGetShellWindow()
2186 PWINSTATION_OBJECT WinStaObject
;
2189 NTSTATUS Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
2194 if (!NT_SUCCESS(Status
))
2196 SetLastNtError(Status
);
2200 Ret
= (HWND
)WinStaObject
->ShellWindow
;
2202 ObDereferenceObject(WinStaObject
);
2207 * NtUserSetShellWindowEx
2209 * This is undocumented function to set global shell window. The global
2210 * shell window has special handling of window position.
2217 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
2219 PWINSTATION_OBJECT WinStaObject
;
2221 NTSTATUS Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
2226 if (!NT_SUCCESS(Status
))
2228 SetLastNtError(Status
);
2233 * Test if we are permitted to change the shell window.
2235 if (WinStaObject
->ShellWindow
)
2237 ObDereferenceObject(WinStaObject
);
2242 * Move shell window into background.
2244 if (hwndListView
&& hwndListView
!= hwndShell
)
2247 * Disabled for now to get Explorer working.
2248 * -- Filip, 01/nov/2003
2251 WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2254 if (NtUserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2256 ObDereferenceObject(WinStaObject
);
2261 if (NtUserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2263 ObDereferenceObject(WinStaObject
);
2267 WinPosSetWindowPos(hwndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2269 WinStaObject
->ShellWindow
= hwndShell
;
2270 WinStaObject
->ShellListView
= hwndListView
;
2272 ObDereferenceObject(WinStaObject
);
2277 * NtUserGetSystemMenu
2279 * The NtUserGetSystemMenu function allows the application to access the
2280 * window menu (also known as the system menu or the control menu) for
2281 * copying and modifying.
2285 * Handle to the window that will own a copy of the window menu.
2287 * Specifies the action to be taken. If this parameter is FALSE,
2288 * NtUserGetSystemMenu returns a handle to the copy of the window menu
2289 * currently in use. The copy is initially identical to the window menu
2290 * but it can be modified.
2291 * If this parameter is TRUE, GetSystemMenu resets the window menu back
2292 * to the default state. The previous window menu, if any, is destroyed.
2295 * If the bRevert parameter is FALSE, the return value is a handle to a
2296 * copy of the window menu. If the bRevert parameter is TRUE, the return
2304 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
2307 PWINDOW_OBJECT WindowObject
;
2308 PMENU_OBJECT MenuObject
;
2310 WindowObject
= IntGetWindowObject((HWND
)hWnd
);
2311 if (WindowObject
== NULL
)
2313 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2317 MenuObject
= IntGetSystemMenu(WindowObject
, bRevert
, FALSE
);
2321 * Return the handle of the first submenu.
2323 ExAcquireFastMutexUnsafe(&MenuObject
->MenuItemsLock
);
2324 if (MenuObject
->MenuItemList
)
2326 Result
= MenuObject
->MenuItemList
->hSubMenu
;
2327 if (!IntIsMenu(Result
))
2330 ExReleaseFastMutexUnsafe(&MenuObject
->MenuItemsLock
);
2331 IntReleaseMenuObject(MenuObject
);
2334 IntReleaseWindowObject(WindowObject
);
2339 * NtUserSetSystemMenu
2346 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
2348 BOOL Result
= FALSE
;
2349 PWINDOW_OBJECT WindowObject
;
2350 PMENU_OBJECT MenuObject
;
2352 WindowObject
= IntGetWindowObject(hWnd
);
2355 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2362 * Assign new menu handle.
2364 MenuObject
= IntGetMenuObject(hMenu
);
2367 IntReleaseWindowObject(WindowObject
);
2368 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
2372 Result
= IntSetSystemMenu(WindowObject
, MenuObject
);
2374 IntReleaseMenuObject(MenuObject
);
2377 IntReleaseWindowObject(WindowObject
);
2385 * The NtUserGetWindow function retrieves a handle to a window that has the
2386 * specified relationship (Z order or owner) to the specified window.
2393 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
2395 PWINDOW_OBJECT WindowObject
;
2396 HWND hWndResult
= NULL
;
2398 IntAcquireWinLockShared();
2400 if (!(WindowObject
= IntGetWindowObject(hWnd
)))
2402 IntReleaseWinLock();
2403 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2407 switch (Relationship
)
2410 if (WindowObject
->Parent
&& WindowObject
->Parent
->FirstChild
)
2411 hWndResult
= WindowObject
->Parent
->FirstChild
->Self
;
2415 if (WindowObject
->Parent
&& WindowObject
->Parent
->LastChild
)
2416 hWndResult
= WindowObject
->Parent
->LastChild
->Self
;
2420 if (WindowObject
->NextSibling
)
2421 hWndResult
= WindowObject
->NextSibling
->Self
;
2425 if (WindowObject
->PrevSibling
)
2426 hWndResult
= WindowObject
->PrevSibling
->Self
;
2430 if (WindowObject
->Owner
)
2431 hWndResult
= WindowObject
->Owner
->Self
;
2434 if (WindowObject
->FirstChild
)
2435 hWndResult
= WindowObject
->FirstChild
->Self
;
2439 IntReleaseWindowObject(WindowObject
);
2440 IntReleaseWinLock();
2448 * The NtUserGetWindowDC function retrieves the device context (DC) for the
2449 * entire window, including title bar, menus, and scroll bars. A window device
2450 * context permits painting anywhere in a window, because the origin of the
2451 * device context is the upper-left corner of the window instead of the client
2459 NtUserGetWindowDC(HWND hWnd
)
2461 return (DWORD
)NtUserGetDCEx(hWnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
2465 * NtUserGetWindowLong
2467 * The NtUserGetWindowLong function retrieves information about the specified
2468 * window. The function also retrieves the 32-bit (long) value at the
2469 * specified offset into the extra window memory.
2476 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
2478 PWINDOW_OBJECT WindowObject
;
2481 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
2483 WindowObject
= IntGetWindowObject(hWnd
);
2484 if (WindowObject
== NULL
)
2486 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2491 * Only allow CSRSS to mess with the desktop window
2493 if (hWnd
== IntGetDesktopWindow()
2494 && WindowObject
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
2496 SetLastWin32Error(STATUS_ACCESS_DENIED
);
2500 if ((INT
)Index
>= 0)
2502 if (Index
> WindowObject
->ExtraDataSize
- sizeof(LONG
))
2504 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2507 Result
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
2514 Result
= WindowObject
->ExStyle
;
2518 Result
= WindowObject
->Style
;
2523 Result
= (LONG
) WindowObject
->WndProcA
;
2525 Result
= (LONG
) WindowObject
->WndProcW
;
2529 Result
= (LONG
) WindowObject
->Instance
;
2532 case GWL_HWNDPARENT
:
2533 if (WindowObject
->Parent
->Self
== IntGetDesktopWindow())
2534 Result
= (LONG
) NtUserGetWindow(WindowObject
->Self
, GW_OWNER
);
2536 Result
= (LONG
) NtUserGetAncestor(WindowObject
->Self
, GA_PARENT
);
2540 Result
= (LONG
) WindowObject
->IDMenu
;
2544 Result
= WindowObject
->UserData
;
2548 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
2549 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2555 IntReleaseWindowObject(WindowObject
);
2561 * NtUserSetWindowLong
2563 * The NtUserSetWindowLong function changes an attribute of the specified
2564 * window. The function also sets the 32-bit (long) value at the specified
2565 * offset into the extra window memory.
2572 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
2574 PWINDOW_OBJECT WindowObject
;
2575 PW32PROCESS Process
;
2576 PWINSTATION_OBJECT WindowStation
;
2580 if (hWnd
== IntGetDesktopWindow())
2582 SetLastWin32Error(STATUS_ACCESS_DENIED
);
2586 WindowObject
= IntGetWindowObject(hWnd
);
2587 if (WindowObject
== NULL
)
2589 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2593 if ((INT
)Index
>= 0)
2595 if (Index
> WindowObject
->ExtraDataSize
- sizeof(LONG
))
2597 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2598 IntReleaseWindowObject(WindowObject
);
2601 OldValue
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
2602 *((LONG
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
2609 OldValue
= (LONG
) WindowObject
->ExStyle
;
2610 Style
.styleOld
= OldValue
;
2611 Style
.styleNew
= NewValue
;
2614 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
2616 Process
= WindowObject
->OwnerThread
->ThreadsProcess
->Win32Process
;
2617 WindowStation
= Process
->WindowStation
;
2620 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
2621 Style
.styleNew
&= ~WS_EX_TOPMOST
;
2624 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
2625 WindowObject
->ExStyle
= (DWORD
)Style
.styleNew
;
2626 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
2630 OldValue
= (LONG
) WindowObject
->Style
;
2631 Style
.styleOld
= OldValue
;
2632 Style
.styleNew
= NewValue
;
2633 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
2634 WindowObject
->Style
= (DWORD
)Style
.styleNew
;
2635 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
2639 /* FIXME: should check if window belongs to current process */
2642 OldValue
= (LONG
) WindowObject
->WndProcA
;
2643 WindowObject
->WndProcA
= (WNDPROC
) NewValue
;
2644 WindowObject
->WndProcW
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,FALSE
);
2645 WindowObject
->Unicode
= FALSE
;
2649 OldValue
= (LONG
) WindowObject
->WndProcW
;
2650 WindowObject
->WndProcW
= (WNDPROC
) NewValue
;
2651 WindowObject
->WndProcA
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,TRUE
);
2652 WindowObject
->Unicode
= TRUE
;
2657 OldValue
= (LONG
) WindowObject
->Instance
;
2658 WindowObject
->Instance
= (HINSTANCE
) NewValue
;
2661 case GWL_HWNDPARENT
:
2662 if (WindowObject
->Parent
->Self
== IntGetDesktopWindow())
2663 OldValue
= (LONG
) IntSetOwner(WindowObject
->Self
, (HWND
) NewValue
);
2665 OldValue
= (LONG
) NtUserSetParent(WindowObject
->Self
, (HWND
) NewValue
);
2669 OldValue
= (LONG
) WindowObject
->IDMenu
;
2670 WindowObject
->IDMenu
= (UINT
) NewValue
;
2674 OldValue
= WindowObject
->UserData
;
2675 WindowObject
->UserData
= NewValue
;
2679 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
2680 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2686 IntReleaseWindowObject(WindowObject
);
2692 * NtUserSetWindowWord
2694 * Legacy function similar to NtUserSetWindowLong.
2701 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
2703 PWINDOW_OBJECT WindowObject
;
2710 case GWL_HWNDPARENT
:
2711 return NtUserSetWindowLong(hWnd
, Index
, (UINT
)NewValue
, TRUE
);
2715 SetLastWin32Error(ERROR_INVALID_INDEX
);
2720 WindowObject
= IntGetWindowObject(hWnd
);
2721 if (WindowObject
== NULL
)
2723 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2727 if (Index
> WindowObject
->ExtraDataSize
- sizeof(WORD
))
2729 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2730 IntReleaseWindowObject(WindowObject
);
2734 OldValue
= *((WORD
*)(WindowObject
->ExtraData
+ Index
));
2735 *((WORD
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
2737 IntReleaseWindowObject(WindowObject
);
2746 NtUserGetWindowPlacement(HWND hWnd
,
2747 WINDOWPLACEMENT
*lpwndpl
)
2749 PWINDOW_OBJECT WindowObject
;
2750 PINTERNALPOS InternalPos
;
2752 WINDOWPLACEMENT Safepl
;
2755 WindowObject
= IntGetWindowObject(hWnd
);
2756 if (WindowObject
== NULL
)
2758 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2762 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
2763 if(!NT_SUCCESS(Status
))
2765 SetLastNtError(Status
);
2766 IntReleaseWindowObject(WindowObject
);
2769 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
2771 IntReleaseWindowObject(WindowObject
);
2776 Safepl
.showCmd
= ((WindowObject
->Flags
& WINDOWOBJECT_RESTOREMAX
) ? SW_MAXIMIZE
: SW_SHOWNORMAL
);
2778 Size
.x
= WindowObject
->WindowRect
.left
;
2779 Size
.y
= WindowObject
->WindowRect
.top
;
2780 InternalPos
= WinPosInitInternalPos(WindowObject
, Size
,
2781 &WindowObject
->WindowRect
);
2784 Safepl
.rcNormalPosition
= InternalPos
->NormalRect
;
2785 Safepl
.ptMinPosition
= InternalPos
->IconPos
;
2786 Safepl
.ptMaxPosition
= InternalPos
->MaxPos
;
2790 IntReleaseWindowObject(WindowObject
);
2794 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
2795 if(!NT_SUCCESS(Status
))
2797 SetLastNtError(Status
);
2798 IntReleaseWindowObject(WindowObject
);
2802 IntReleaseWindowObject(WindowObject
);
2808 * Return the dimension of the window in the screen coordinates.
2809 * \param hWnd window handle.
2810 * \param Rect pointer to the buffer where the coordinates are returned.
2816 NtUserGetWindowRect(HWND hWnd
, LPRECT Rect
)
2821 IntAcquireWinLockShared();
2822 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2824 IntReleaseWinLock();
2825 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2829 SafeRect
= Wnd
->WindowRect
;
2830 IntReleaseWinLock();
2832 if (! NT_SUCCESS(MmCopyToCaller(Rect
, &SafeRect
, sizeof(RECT
))))
2845 NtUserGetWindowThreadProcessId(HWND hWnd
, LPDWORD UnsafePid
)
2850 IntAcquireWinLockShared();
2852 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2854 IntReleaseWinLock();
2855 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2859 tid
= IntGetWindowThreadProcessId(Wnd
, &pid
);
2860 IntReleaseWinLock();
2862 if (UnsafePid
) MmCopyToCaller(UnsafePid
, &pid
, sizeof(DWORD
));
2872 NtUserLockWindowUpdate(DWORD Unknown0
)
2892 UINT flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
2895 flags
|= SWP_NOREDRAW
;
2896 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
, flags
);
2900 QueryWindow based on KJK::Hyperion and James Tabor.
2902 0 = QWUniqueProcessId
2903 1 = QWUniqueThreadId
2904 4 = QWIsHung Implements IsHungAppWindow found
2907 9 = QWKillWindow When I called this with hWnd ==
2908 DesktopWindow, it shutdown the system
2915 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
2917 PWINDOW_OBJECT Window
= IntGetWindowObject(hWnd
);
2922 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2929 Result
= (DWORD
)Window
->OwnerThread
->ThreadsProcess
->UniqueProcessId
;
2933 Result
= (DWORD
)Window
->OwnerThread
->Cid
.UniqueThread
;
2937 Result
= (DWORD
)NULL
;
2941 IntReleaseWindowObject(Window
);
2951 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
2965 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
2968 PLIST_ENTRY Current
;
2969 PREGISTERED_MESSAGE NewMsg
, RegMsg
;
2970 UINT Msg
= REGISTERED_MESSAGE_MIN
;
2971 UNICODE_STRING MessageName
;
2974 Status
= MmCopyFromCaller(&MessageName
, MessageNameUnsafe
, sizeof(UNICODE_STRING
));
2975 if (! NT_SUCCESS(Status
))
2977 SetLastNtError(Status
);
2981 NewMsg
= ExAllocatePoolWithTag(PagedPool
,
2982 sizeof(REGISTERED_MESSAGE
) +
2987 SetLastNtError(STATUS_NO_MEMORY
);
2991 Status
= MmCopyFromCaller(NewMsg
->MessageName
, MessageName
.Buffer
, MessageName
.Length
);
2992 if (! NT_SUCCESS(Status
))
2995 SetLastNtError(Status
);
2998 NewMsg
->MessageName
[MessageName
.Length
/ sizeof(WCHAR
)] = L
'\0';
2999 if (wcslen(NewMsg
->MessageName
) != MessageName
.Length
/ sizeof(WCHAR
))
3002 SetLastNtError(STATUS_INVALID_PARAMETER
);
3006 Current
= RegisteredMessageListHead
.Flink
;
3007 while (Current
!= &RegisteredMessageListHead
)
3009 RegMsg
= CONTAINING_RECORD(Current
, REGISTERED_MESSAGE
, ListEntry
);
3010 if (0 == wcscmp(NewMsg
->MessageName
, RegMsg
->MessageName
))
3016 Current
= Current
->Flink
;
3019 if (REGISTERED_MESSAGE_MAX
< Msg
)
3022 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
3026 InsertTailList(&RegisteredMessageListHead
, &(NewMsg
->ListEntry
));
3032 * - There's no need to call MmSafe*, because it should be done in kernel.
3033 * - The passed UNICODE_STRING is expected to be NULL-terminated.
3035 return (UINT
)IntAddAtom(MessageNameUnsafe
->Buffer
);
3044 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3057 NtUserSetInternalWindowPos(DWORD Unknown0
,
3073 NtUserSetLayeredWindowAttributes(DWORD Unknown0
,
3088 NtUserSetLogonNotifyWindow(DWORD Unknown0
)
3105 PWINDOW_OBJECT WindowObject
;
3108 WindowObject
= IntGetWindowObject((HWND
) Wnd
);
3109 if (NULL
== WindowObject
)
3111 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3115 if (! IntSetMenu(WindowObject
, Menu
, &Changed
))
3117 IntReleaseWindowObject(WindowObject
);
3121 IntReleaseWindowObject(WindowObject
);
3123 if (Changed
&& Repaint
)
3125 WinPosSetWindowPos(Wnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3126 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3137 NtUserSetWindowFNID(DWORD Unknown0
,
3151 NtUserSetWindowPlacement(HWND hWnd
,
3152 WINDOWPLACEMENT
*lpwndpl
)
3154 PWINDOW_OBJECT WindowObject
;
3155 WINDOWPLACEMENT Safepl
;
3158 WindowObject
= IntGetWindowObject(hWnd
);
3159 if (WindowObject
== NULL
)
3161 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3164 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3165 if(!NT_SUCCESS(Status
))
3167 SetLastNtError(Status
);
3168 IntReleaseWindowObject(WindowObject
);
3171 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3173 IntReleaseWindowObject(WindowObject
);
3177 if ((WindowObject
->Style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
3179 WinPosSetWindowPos(WindowObject
->Self
, NULL
,
3180 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
3181 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
3182 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
3183 SWP_NOZORDER
| SWP_NOACTIVATE
);
3186 /* FIXME - change window status */
3187 WinPosShowWindow(WindowObject
->Self
, Safepl
.showCmd
);
3189 if (WindowObject
->InternalPos
== NULL
)
3190 WindowObject
->InternalPos
= ExAllocatePoolWithTag(PagedPool
, sizeof(INTERNALPOS
), TAG_WININTLIST
);
3191 WindowObject
->InternalPos
->NormalRect
= Safepl
.rcNormalPosition
;
3192 WindowObject
->InternalPos
->IconPos
= Safepl
.ptMinPosition
;
3193 WindowObject
->InternalPos
->MaxPos
= Safepl
.ptMaxPosition
;
3195 IntReleaseWindowObject(WindowObject
);
3206 HWND hWndInsertAfter
,
3213 return WinPosSetWindowPos(hWnd
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
3221 NtUserSetWindowRgn(DWORD Unknown0
,
3235 NtUserShowWindow(HWND hWnd
,
3238 return WinPosShowWindow(hWnd
, nCmdShow
);
3246 NtUserShowWindowAsync(DWORD Unknown0
,
3259 NtUserUpdateLayeredWindow(DWORD Unknown0
,
3279 NtUserValidateRect(HWND hWnd
, const RECT
* Rect
)
3281 return (VOID
)NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
3284 static BOOL
IsStaticClass(PWINDOW_OBJECT Window
)
3288 ASSERT(0 != Window
->Class
);
3289 ASSERT(0 != Window
->Class
->Atom
);
3291 DbgPrint("FIXME: Update IsStatic to really check if a window is a static\n");
3293 if (0 == wcscmp((LPWSTR)Window->Class->lpszClassName, L"Static"))
3299 static BOOL
IsDisabled(PWINDOW_OBJECT Window
)
3302 ASSERT(0 != Window
);
3304 rc
= (Window
->Style
& WS_DISABLED
);
3309 static PWINDOW_OBJECT
RestrictiveSearchChildWindows(PWINDOW_OBJECT Window
, POINT p
)
3311 PWINDOW_OBJECT ChildWindow
= 0;
3312 PWINDOW_OBJECT rc
= Window
;
3313 ASSERT(0 != Window
);
3316 **Aquire a mutex to the Child list.
3318 ExAcquireFastMutexUnsafe(&Window
->ChildrenListLock
);
3321 **Now Find the first non-static window.
3323 ChildWindow
= Window
->FirstChild
;
3325 while (0 != ChildWindow
)
3328 **Test Restrictions on the window.
3330 if (!IsStaticClass(ChildWindow
) &&
3331 !IsDisabled(ChildWindow
) &&
3332 IntIsWindowVisible(ChildWindow
->Self
))
3335 **Now find the deepest child window
3337 if (POINT_IN_RECT(p
, ChildWindow
->WindowRect
))
3339 rc
= RestrictiveSearchChildWindows(ChildWindow
, p
);
3343 ChildWindow
= ChildWindow
->NextSibling
;
3349 ExReleaseFastMutexUnsafe(&Window
->ChildrenListLock
);
3355 * NtUserWindowFromPoint
3358 * The return value is a handle to the window that contains the point.
3359 * If no window exists at the given point, the return value is NULL.
3360 * If the point is over a static text control, the return value is a handle
3361 * to the window under the static text control.
3364 * The WindowFromPoint function does not retrieve a handle to a hidden or
3365 * disabled window, even if the point is within the window. An application
3366 * should use the ChildWindowFromPoint function for a nonrestrictive search.
3376 NtUserWindowFromPoint(LONG X
, LONG Y
)
3379 PWINDOW_OBJECT DesktopWindow
= 0;
3380 PWINDOW_OBJECT TopWindow
= 0;
3381 PWINDOW_OBJECT ChildWindow
= 0;
3384 DesktopWindow
= IntGetWindowObject(IntGetDesktopWindow());
3389 if (DesktopWindow
!= NULL
)
3392 * Aquire the mutex to the child window list. (All the topmost windows)
3394 ExAcquireFastMutexUnsafe(&DesktopWindow
->ChildrenListLock
);
3397 * Spin through the windows looking for the window that contains the
3398 * point. The child windows are in Z-order.
3400 TopWindow
= DesktopWindow
->FirstChild
;
3401 while (TopWindow
!= NULL
)
3403 if (POINT_IN_RECT(pt
, TopWindow
->WindowRect
))
3407 TopWindow
= TopWindow
->NextSibling
;
3411 * Search for the child window that contains the point.
3413 if (TopWindow
!= NULL
)
3415 ChildWindow
= RestrictiveSearchChildWindows(TopWindow
, pt
);
3416 if (ChildWindow
!= NULL
)
3418 hWnd
= ChildWindow
->Self
;
3425 ExReleaseFastMutexUnsafe(&DesktopWindow
->ChildrenListLock
);
3428 IntReleaseWindowObject(DesktopWindow
);
3437 * Undocumented function that is called from DefWindowProc to set
3440 * FIXME: Call this from user32.dll!
3447 NtUserDefSetText(HWND WindowHandle
, PANSI_STRING Text
)
3449 PWINDOW_OBJECT WindowObject
;
3450 UNICODE_STRING NewWindowName
;
3451 BOOL Result
= FALSE
;
3453 WindowObject
= IntGetWindowObject(WindowHandle
);
3456 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3460 if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&NewWindowName
, Text
, TRUE
)))
3462 RtlFreeUnicodeString(&WindowObject
->WindowName
);
3463 WindowObject
->WindowName
.Buffer
= NewWindowName
.Buffer
;
3464 WindowObject
->WindowName
.Length
= NewWindowName
.Length
;
3465 WindowObject
->WindowName
.MaximumLength
= NewWindowName
.MaximumLength
;
3469 IntReleaseWindowObject(WindowObject
);
3475 * NtUserInternalGetWindowText
3477 * FIXME: Call this from user32.dll!
3484 NtUserInternalGetWindowText(HWND WindowHandle
, LPWSTR Text
, INT MaxCount
)
3486 PWINDOW_OBJECT WindowObject
;
3489 WindowObject
= IntGetWindowObject(WindowHandle
);
3492 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3496 Result
= WindowObject
->WindowName
.Length
/ sizeof(WCHAR
);
3499 /* FIXME: Shouldn't it be always NULL terminated? */
3500 wcsncpy(Text
, WindowObject
->WindowName
.Buffer
, MaxCount
);
3501 if (MaxCount
< Result
)
3507 IntReleaseWindowObject(WindowObject
);
3513 NtUserDereferenceWndProcHandle(WNDPROC wpHandle
, WndProcHandle
*Data
)
3515 WndProcHandle Entry
;
3516 if (((DWORD
)wpHandle
& 0xFFFF0000) == 0xFFFF0000)
3518 Entry
= WndProcHandlesArray
[(DWORD
)wpHandle
& 0x0000FFFF];
3519 Data
->WindowProc
= Entry
.WindowProc
;
3520 Data
->IsUnicode
= Entry
.IsUnicode
;
3521 Data
->ProcessID
= Entry
.ProcessID
;
3530 IntAddWndProcHandle(WNDPROC WindowProc
, BOOL IsUnicode
)
3535 WndProcHandle
*OldArray
;
3538 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
3540 if (WndProcHandlesArray
[i
].WindowProc
== NULL
)
3548 OldArray
= WndProcHandlesArray
;
3549 OldArraySize
= WndProcHandlesArraySize
;
3550 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,(OldArraySize
+ WPH_SIZE
) * sizeof(WndProcHandle
), TAG_WINPROCLST
);
3551 WndProcHandlesArraySize
= OldArraySize
+ WPH_SIZE
;
3552 RtlCopyMemory(WndProcHandlesArray
,OldArray
,OldArraySize
* sizeof(WndProcHandle
));
3553 ExFreePool(OldArray
);
3554 FreeSpot
= OldArraySize
+ 1;
3556 WndProcHandlesArray
[FreeSpot
].WindowProc
= WindowProc
;
3557 WndProcHandlesArray
[FreeSpot
].IsUnicode
= IsUnicode
;
3558 WndProcHandlesArray
[FreeSpot
].ProcessID
= PsGetCurrentProcessId();
3559 return FreeSpot
+ 0xFFFF0000;
3563 IntRemoveWndProcHandle(WNDPROC Handle
)
3566 position
= (DWORD
)Handle
& 0x0000FFFF;
3567 if (position
> WndProcHandlesArraySize
)
3571 WndProcHandlesArray
[position
].WindowProc
= NULL
;
3572 WndProcHandlesArray
[position
].IsUnicode
= FALSE
;
3573 WndProcHandlesArray
[position
].ProcessID
= NULL
;
3578 IntRemoveProcessWndProcHandles(HANDLE ProcessID
)
3581 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
3583 if (WndProcHandlesArray
[i
].ProcessID
== ProcessID
)
3585 WndProcHandlesArray
[i
].WindowProc
= NULL
;
3586 WndProcHandlesArray
[i
].IsUnicode
= FALSE
;
3587 WndProcHandlesArray
[i
].ProcessID
= NULL
;