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.206 2004/03/31 19:20:18 gvg 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>
56 #include <include/timer.h>
59 #include <win32k/debug1.h>
62 static WndProcHandle
*WndProcHandlesArray
= 0;
63 static WORD WndProcHandlesArraySize
= 0;
64 #define WPH_SIZE 0x40 /* the size to add to the WndProcHandle array each time */
66 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
68 /* PRIVATE FUNCTIONS **********************************************************/
73 * Initialize windowing implementation.
79 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,WPH_SIZE
* sizeof(WndProcHandle
), TAG_WINPROCLST
);
80 WndProcHandlesArraySize
= WPH_SIZE
;
81 return STATUS_SUCCESS
;
87 * Cleanup windowing implementation.
91 CleanupWindowImpl(VOID
)
93 ExFreePool(WndProcHandlesArray
);
94 WndProcHandlesArray
= 0;
95 WndProcHandlesArraySize
= 0;
96 return STATUS_SUCCESS
;
99 /* HELPER FUNCTIONS ***********************************************************/
104 * The function determines whether the specified window handle identifies
105 * an existing window.
109 * Handle to the window to test.
112 * If the window handle identifies an existing window, the return value
113 * is TRUE. If the window handle does not identify an existing window,
114 * the return value is FALSE.
118 IntIsWindow(HWND hWnd
)
120 PWINDOW_OBJECT Window
;
122 if (!(Window
= IntGetWindowObject(hWnd
)))
125 IntReleaseWindowObject(Window
);
130 * IntGetProcessWindowObject
132 * Get window object from handle of specified process.
135 PWINDOW_OBJECT FASTCALL
136 IntGetProcessWindowObject(PW32PROCESS ProcessData
, HWND hWnd
)
138 PWINDOW_OBJECT WindowObject
;
141 Status
= ObmReferenceObjectByHandle(ProcessData
->WindowStation
->HandleTable
,
142 hWnd
, otWindow
, (PVOID
*)&WindowObject
);
143 if (!NT_SUCCESS(Status
))
151 PWINDOW_OBJECT FASTCALL
152 IntGetParent(PWINDOW_OBJECT Wnd
)
156 if (Wnd
->Style
& WS_POPUP
)
158 IntLockRelatives(Wnd
);
160 IntUnLockRelatives(Wnd
);
161 return IntGetWindowObject(hWnd
);
163 else if (Wnd
->Style
& WS_CHILD
)
165 IntLockRelatives(Wnd
);
167 IntUnLockRelatives(Wnd
);
168 return IntGetWindowObject(hWnd
);
175 PWINDOW_OBJECT FASTCALL
176 IntGetParentObject(PWINDOW_OBJECT Wnd
)
180 IntLockRelatives(Wnd
);
181 hParent
= Wnd
->Parent
;
182 IntUnLockRelatives(Wnd
);
183 return IntGetWindowObject(hParent
);
189 * Compile a list of all child window handles from given window.
192 * This function is similar to Wine WIN_ListChildren. The caller
193 * must free the returned list with ExFreePool.
197 IntWinListChildren(PWINDOW_OBJECT Window
)
199 PWINDOW_OBJECT Child
;
201 UINT Index
, NumChildren
= 0;
203 IntLockRelatives(Window
);
205 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
208 if (NumChildren
!= 0)
210 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
213 DPRINT1("Failed to allocate memory for children array\n");
214 IntUnLockRelatives(Window
);
217 for (Child
= Window
->FirstChild
, Index
= 0;
219 Child
= Child
->NextSibling
, ++Index
)
220 List
[Index
] = Child
->Self
;
224 IntUnLockRelatives(Window
);
226 return (NumChildren
> 0) ? List
: NULL
;
229 /***********************************************************************
232 static void IntSendDestroyMsg(HWND Wnd
)
237 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
239 if (Wnd
== info
.hwndCaret
)
247 * Send the WM_DESTROY to the window.
249 IntSendMessage(Wnd
, WM_DESTROY
, 0, 0);
252 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
253 * make sure that the window still exists when we come back.
261 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
263 /* start from the end (FIXME: is this needed?) */
264 for (i
= 0; pWndArray
[i
]; i
++) ;
268 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
270 HeapFree(GetProcessHeap(), 0, pWndArray
);
274 DPRINT("destroyed itself while in WM_DESTROY!\n");
279 /***********************************************************************
282 * Destroy storage associated to a window. "Internals" p.358
284 static LRESULT
IntDestroyWindow(PWINDOW_OBJECT Window
,
285 PW32PROCESS ProcessData
,
286 PW32THREAD ThreadData
,
287 BOOLEAN SendMessages
)
291 PWINDOW_OBJECT Child
;
293 BOOL BelongsToThreadData
;
297 RemoveTimersWindow(Window
->Self
);
299 IntLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
300 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
302 IntUnLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
303 DPRINT("Tried to call IntDestroyWindow() twice\n");
306 Window
->Status
|= WINDOWSTATUS_DESTROYING
;
307 /* remove the window already at this point from the thread window list so we
308 don't get into trouble when destroying the thread windows while we're still
309 in IntDestroyWindow() */
310 RemoveEntryList(&Window
->ThreadListEntry
);
311 IntUnLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
313 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
317 /* Send destroy messages */
318 IntSendDestroyMsg(Window
->Self
);
321 /* free child windows */
322 Children
= IntWinListChildren(Window
);
325 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
327 if ((Child
= IntGetWindowObject(*ChildHandle
)))
329 if(!IntWndBelongsToThread(Child
, ThreadData
))
331 /* send WM_DESTROY messages to windows not belonging to the same thread */
332 IntSendDestroyMsg(Child
->Self
);
335 IntDestroyWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
336 IntReleaseWindowObject(Child
);
339 ExFreePool(Children
);
345 * Clear the update region to make sure no WM_PAINT messages will be
346 * generated for this window while processing the WM_NCDESTROY.
348 IntRedrawWindow(Window
, NULL
, 0,
349 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
350 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
353 * Send the WM_NCDESTROY to the window being destroyed.
355 if(BelongsToThreadData
)
356 IntSendMessage(Window
->Self
, WM_NCDESTROY
, 0, 0);
359 /* reset shell window handles */
360 if(ProcessData
->WindowStation
)
362 if (Window
->Self
== ProcessData
->WindowStation
->ShellWindow
)
363 ProcessData
->WindowStation
->ShellWindow
= NULL
;
365 if (Window
->Self
== ProcessData
->WindowStation
->ShellListView
)
366 ProcessData
->WindowStation
->ShellListView
= NULL
;
369 /* Unregister hot keys */
370 UnregisterWindowHotKeys (Window
);
372 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
375 WinPosCheckInternalPos(Window
->Self
);
376 if (Window
->Self
== GetCapture())
381 /* free resources associated with the window */
382 TIMER_RemoveWindowTimers(Window
->Self
);
385 if (!(Window
->Style
& WS_CHILD
) && Window
->IDMenu
386 && (Menu
= IntGetMenuObject((HMENU
)Window
->IDMenu
)))
388 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
390 IntReleaseMenuObject(Menu
);
393 if(Window
->SystemMenu
394 && (Menu
= IntGetMenuObject(Window
->SystemMenu
)))
396 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
397 Window
->SystemMenu
= (HMENU
)0;
398 IntReleaseMenuObject(Menu
);
401 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
403 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
404 CLASS_RemoveWindow(Window
->Class
);
407 IntUnlinkWindow(Window
);
409 IntReferenceWindowObject(Window
);
410 ObmCloseHandle(ProcessData
->WindowStation
->HandleTable
, Window
->Self
);
412 IntDestroyScrollBar(Window
, SB_VERT
);
413 IntDestroyScrollBar(Window
, SB_HORZ
);
415 IntLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
416 Window
->Status
|= WINDOWSTATUS_DESTROYED
;
417 /* don't remove the WINDOWSTATUS_DESTROYING bit */
418 IntUnLockThreadWindows(Window
->OwnerThread
->Win32Thread
);
420 ObmDereferenceObject(Window
->Class
);
421 Window
->Class
= NULL
;
423 if(Window
->WindowRegion
)
425 NtGdiDeleteObject(Window
->WindowRegion
);
428 IntReleaseWindowObject(Window
);
435 PWINDOW_OBJECT WindowObject
,
439 PMENU_OBJECT OldMenuObject
, NewMenuObject
;
441 *Changed
= (WindowObject
->IDMenu
!= (UINT
) Menu
);
447 if (0 != WindowObject
->IDMenu
)
449 OldMenuObject
= IntGetMenuObject((HMENU
) WindowObject
->IDMenu
);
450 ASSERT(NULL
== OldMenuObject
|| OldMenuObject
->MenuInfo
.Wnd
== WindowObject
->Self
);
454 OldMenuObject
= NULL
;
459 NewMenuObject
= IntGetMenuObject(Menu
);
460 if (NULL
== NewMenuObject
)
462 if (NULL
!= OldMenuObject
)
464 IntReleaseMenuObject(OldMenuObject
);
466 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
469 if (NULL
!= NewMenuObject
->MenuInfo
.Wnd
)
471 /* Can't use the same menu for two windows */
472 if (NULL
!= OldMenuObject
)
474 IntReleaseMenuObject(OldMenuObject
);
476 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
482 WindowObject
->IDMenu
= (UINT
) Menu
;
483 if (NULL
!= NewMenuObject
)
485 NewMenuObject
->MenuInfo
.Wnd
= WindowObject
->Self
;
486 IntReleaseMenuObject(NewMenuObject
);
488 if (NULL
!= OldMenuObject
)
490 OldMenuObject
->MenuInfo
.Wnd
= NULL
;
491 IntReleaseMenuObject(OldMenuObject
);
498 /* INTERNAL ******************************************************************/
502 DestroyThreadWindows(struct _ETHREAD
*Thread
)
505 PW32PROCESS Win32Process
;
506 PW32THREAD Win32Thread
;
507 PWINDOW_OBJECT
*List
, *pWnd
;
510 Win32Thread
= Thread
->Win32Thread
;
511 Win32Process
= Thread
->ThreadsProcess
->Win32Process
;
513 IntLockThreadWindows(Win32Thread
);
514 Current
= Win32Thread
->WindowListHead
.Flink
;
515 while (Current
!= &(Win32Thread
->WindowListHead
))
518 Current
= Current
->Flink
;
523 List
= ExAllocatePool(PagedPool
, (Cnt
+ 1) * sizeof(PWINDOW_OBJECT
));
526 DPRINT("Not enough memory to allocate window handle list\n");
527 IntUnLockThreadWindows(Win32Thread
);
531 Current
= Win32Thread
->WindowListHead
.Flink
;
532 while (Current
!= &(Win32Thread
->WindowListHead
))
534 *pWnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
535 IntReferenceWindowObject(*pWnd
);
537 Current
= Current
->Flink
;
539 IntUnLockThreadWindows(Win32Thread
);
542 for(pWnd
= List
; *pWnd
; pWnd
++)
544 NtUserDestroyWindow((*pWnd
)->Self
);
545 IntReleaseWindowObject(*pWnd
);
551 IntUnLockThreadWindows(Win32Thread
);
557 * Returns client window rectangle relative to the upper-left corner of client area.
559 * \note Does not check the validity of the parameters
562 IntGetClientRect(PWINDOW_OBJECT WindowObject
, PRECT Rect
)
564 ASSERT( WindowObject
);
567 Rect
->left
= Rect
->top
= 0;
568 Rect
->right
= WindowObject
->ClientRect
.right
- WindowObject
->ClientRect
.left
;
569 Rect
->bottom
= WindowObject
->ClientRect
.bottom
- WindowObject
->ClientRect
.top
;
575 IntGetFocusWindow(VOID
)
577 PUSER_MESSAGE_QUEUE Queue
;
578 PDESKTOP_OBJECT pdo
= IntGetActiveDesktop();
583 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
588 return(Queue
->FocusWindow
);
592 PMENU_OBJECT FASTCALL
593 IntGetSystemMenu(PWINDOW_OBJECT WindowObject
, BOOL bRevert
, BOOL RetMenu
)
595 PMENU_OBJECT MenuObject
, NewMenuObject
, SysMenuObject
, ret
= NULL
;
596 PW32PROCESS W32Process
;
597 HMENU NewMenu
, SysMenu
;
598 ROSMENUITEMINFO ItemInfo
;
602 W32Process
= PsGetWin32Process();
604 if(!W32Process
->WindowStation
)
607 if(WindowObject
->SystemMenu
)
609 MenuObject
= IntGetMenuObject(WindowObject
->SystemMenu
);
612 IntDestroyMenuObject(MenuObject
, FALSE
, TRUE
);
613 WindowObject
->SystemMenu
= (HMENU
)0;
614 IntReleaseMenuObject(MenuObject
);
618 if(W32Process
->WindowStation
->SystemMenuTemplate
)
620 /* clone system menu */
621 MenuObject
= IntGetMenuObject(W32Process
->WindowStation
->SystemMenuTemplate
);
625 NewMenuObject
= IntCloneMenu(MenuObject
);
628 WindowObject
->SystemMenu
= NewMenuObject
->MenuInfo
.Self
;
629 NewMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
630 NewMenuObject
->MenuInfo
.Wnd
= WindowObject
->Self
;
632 //IntReleaseMenuObject(NewMenuObject);
634 IntReleaseMenuObject(MenuObject
);
638 SysMenu
= NtUserCreateMenu(FALSE
);
643 SysMenuObject
= IntGetMenuObject(SysMenu
);
644 if (NULL
== SysMenuObject
)
646 NtUserDestroyMenu(SysMenu
);
649 SysMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
650 SysMenuObject
->MenuInfo
.Wnd
= WindowObject
->Self
;
651 NewMenu
= IntLoadSysMenuTemplate();
654 IntReleaseMenuObject(SysMenuObject
);
655 NtUserDestroyMenu(SysMenu
);
658 MenuObject
= IntGetMenuObject(NewMenu
);
661 IntReleaseMenuObject(SysMenuObject
);
662 NtUserDestroyMenu(SysMenu
);
666 NewMenuObject
= IntCloneMenu(MenuObject
);
669 NewMenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
670 IntReleaseMenuObject(NewMenuObject
);
671 NtUserSetMenuDefaultItem(NewMenuObject
->MenuInfo
.Self
, SC_CLOSE
, FALSE
);
673 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
674 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
675 ItemInfo
.fType
= MF_POPUP
;
676 ItemInfo
.fState
= MFS_ENABLED
;
677 ItemInfo
.dwTypeData
= NULL
;
679 ItemInfo
.hSubMenu
= NewMenuObject
->MenuInfo
.Self
;
680 IntInsertMenuItem(SysMenuObject
, (UINT
) -1, TRUE
, &ItemInfo
);
682 WindowObject
->SystemMenu
= SysMenuObject
->MenuInfo
.Self
;
686 IntDestroyMenuObject(MenuObject
, FALSE
, TRUE
);
687 IntReleaseMenuObject(MenuObject
);
696 if(WindowObject
->SystemMenu
)
697 return IntGetMenuObject((HMENU
)WindowObject
->SystemMenu
);
705 IntIsChildWindow(HWND Parent
, HWND Child
)
707 PWINDOW_OBJECT BaseWindow
, Window
, Old
;
709 if(!(BaseWindow
= IntGetWindowObject(Child
)))
717 if (Window
->Self
== Parent
)
719 if(Window
!= BaseWindow
)
720 IntReleaseWindowObject(Window
);
721 IntReleaseWindowObject(BaseWindow
);
724 if(!(Window
->Style
& WS_CHILD
))
726 if(Window
!= BaseWindow
)
727 IntReleaseWindowObject(Window
);
731 Window
= IntGetParentObject(Window
);
732 if(Old
!= BaseWindow
)
733 IntReleaseWindowObject(Old
);
736 IntReleaseWindowObject(BaseWindow
);
741 IntIsWindowVisible(HWND hWnd
)
743 PWINDOW_OBJECT BaseWindow
, Window
, Old
;
745 if(!(BaseWindow
= IntGetWindowObject(hWnd
)))
753 if(!(Window
->Style
& WS_CHILD
))
757 if(!(Window
->Style
& WS_VISIBLE
))
759 if(Window
!= BaseWindow
)
760 IntReleaseWindowObject(Window
);
761 IntReleaseWindowObject(BaseWindow
);
765 Window
= IntGetParentObject(Window
);
766 if(Old
!= BaseWindow
)
767 IntReleaseWindowObject(Old
);
772 if(Window
->Style
& WS_VISIBLE
)
774 if(Window
!= BaseWindow
)
775 IntReleaseWindowObject(Window
);
776 IntReleaseWindowObject(BaseWindow
);
779 if(Window
!= BaseWindow
)
780 IntReleaseWindowObject(Window
);
782 IntReleaseWindowObject(BaseWindow
);
787 /* link the window into siblings and parent. children are kept in place. */
791 PWINDOW_OBJECT WndParent
,
792 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
795 PWINDOW_OBJECT Parent
;
797 IntLockRelatives(Wnd
);
798 Wnd
->Parent
= WndParent
->Self
;
799 if ((Wnd
->PrevSibling
= WndPrevSibling
))
801 /* link after WndPrevSibling */
802 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
803 Wnd
->NextSibling
->PrevSibling
= Wnd
;
804 else if ((Parent
= IntGetWindowObject(Wnd
->Parent
)))
806 IntLockRelatives(Parent
);
807 if(Parent
->LastChild
== WndPrevSibling
)
808 Parent
->LastChild
= Wnd
;
809 IntUnLockRelatives(Parent
);
810 IntReleaseWindowObject(Parent
);
812 Wnd
->PrevSibling
->NextSibling
= Wnd
;
817 Parent
= IntGetWindowObject(Wnd
->Parent
);
818 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
819 Wnd
->NextSibling
->PrevSibling
= Wnd
;
822 IntLockRelatives(Parent
);
823 Parent
->LastChild
= Wnd
;
824 Parent
->FirstChild
= Wnd
;
825 IntUnLockRelatives(Parent
);
826 IntReleaseWindowObject(Parent
);
827 IntUnLockRelatives(Wnd
);
832 IntLockRelatives(Parent
);
833 Parent
->FirstChild
= Wnd
;
834 IntUnLockRelatives(Parent
);
835 IntReleaseWindowObject(Parent
);
838 IntUnLockRelatives(Wnd
);
842 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
844 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
847 Wnd
= IntGetWindowObject(hWnd
);
851 IntLockRelatives(Wnd
);
852 WndOldOwner
= IntGetWindowObject(Wnd
->Owner
);
855 ret
= WndOldOwner
->Self
;
856 IntReleaseWindowObject(WndOldOwner
);
863 if((WndNewOwner
= IntGetWindowObject(hWndNewOwner
)))
865 Wnd
->Owner
= hWndNewOwner
;
866 IntReleaseWindowObject(WndNewOwner
);
871 IntUnLockRelatives(Wnd
);
872 IntReleaseWindowObject(Wnd
);
876 PWINDOW_OBJECT FASTCALL
877 IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
879 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
880 HWND hWnd
, hWndNewParent
, hWndOldParent
;
885 ASSERT(WndNewParent
);
888 hWndNewParent
= WndNewParent
->Self
;
891 * Windows hides the window first, then shows it again
892 * including the WM_SHOWWINDOW messages and all
894 WasVisible
= WinPosShowWindow(hWnd
, SW_HIDE
);
896 /* Validate that window and parent still exist */
897 if (!IntIsWindow(hWnd
) || !IntIsWindow(hWndNewParent
))
900 /* Window must belong to current process */
901 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
904 WndOldParent
= IntGetParentObject(Wnd
);
905 hWndOldParent
= (WndOldParent
? WndOldParent
->Self
: NULL
);
907 if (WndNewParent
!= WndOldParent
)
909 IntUnlinkWindow(Wnd
);
911 if (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
))
913 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
914 IntLockRelatives(WndNewParent
);
915 Sibling
= WndNewParent
->FirstChild
;
916 while (NULL
!= Sibling
&& 0 != (Sibling
->ExStyle
& WS_EX_TOPMOST
))
918 InsertAfter
= Sibling
;
919 Sibling
= Sibling
->NextSibling
;
921 IntUnLockRelatives(WndNewParent
);
923 if (NULL
== InsertAfter
)
925 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
929 IntReferenceWindowObject(InsertAfter
);
930 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
931 IntReleaseWindowObject(InsertAfter
);
934 if (WndNewParent
->Self
!= IntGetDesktopWindow()) /* a child window */
936 if (!(Wnd
->Style
& WS_CHILD
))
938 //if ( Wnd->Menu ) DestroyMenu ( Wnd->menu );
939 IntSetMenu(Wnd
, NULL
, &MenuChanged
);
945 * SetParent additionally needs to make hwnd the top window
946 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
947 * WM_WINDOWPOSCHANGED notification messages.
949 WinPosSetWindowPos(hWnd
, (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
950 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
951 | (WasVisible
? SWP_SHOWWINDOW
: 0));
954 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
955 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
959 * Validate that the old parent still exist, since it migth have been
960 * destroyed during the last callbacks to user-mode
964 if(!IntIsWindow(WndOldParent
->Self
))
966 IntReleaseWindowObject(WndOldParent
);
970 /* don't dereference the window object here, it must be done by the caller
978 IntSetSystemMenu(PWINDOW_OBJECT WindowObject
, PMENU_OBJECT MenuObject
)
980 PMENU_OBJECT OldMenuObject
;
981 if(WindowObject
->SystemMenu
)
983 OldMenuObject
= IntGetMenuObject(WindowObject
->SystemMenu
);
986 OldMenuObject
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
987 IntReleaseMenuObject(OldMenuObject
);
993 /* FIXME check window style, propably return FALSE ? */
994 WindowObject
->SystemMenu
= MenuObject
->MenuInfo
.Self
;
995 MenuObject
->MenuInfo
.Flags
|= MF_SYSMENU
;
998 WindowObject
->SystemMenu
= (HMENU
)0;
1004 /* unlink the window from siblings and parent. children are kept in place. */
1006 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1008 PWINDOW_OBJECT WndParent
;
1010 IntLockRelatives(Wnd
);
1011 if((WndParent
= IntGetWindowObject(Wnd
->Parent
)))
1013 IntLockRelatives(WndParent
);
1016 if (Wnd
->NextSibling
) Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1017 else if (WndParent
&& WndParent
->LastChild
== Wnd
) WndParent
->LastChild
= Wnd
->PrevSibling
;
1019 if (Wnd
->PrevSibling
) Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1020 else if (WndParent
&& WndParent
->FirstChild
== Wnd
) WndParent
->FirstChild
= Wnd
->NextSibling
;
1024 IntUnLockRelatives(WndParent
);
1025 IntReleaseWindowObject(WndParent
);
1027 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1028 IntUnLockRelatives(Wnd
);
1031 /* FUNCTIONS *****************************************************************/
1037 NtUserAlterWindowStyle(DWORD Unknown0
,
1048 * As best as I can figure, this function is used by EnumWindows,
1049 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1051 * It's supposed to build a list of HWNDs to return to the caller.
1052 * We can figure out what kind of list by what parameters are
1060 NtUserBuildHwndList(
1071 /* FIXME handle bChildren */
1074 PWINDOW_OBJECT WindowObject
= NULL
;
1075 PWINDOW_OBJECT Child
;
1077 WindowObject
= IntGetWindowObject ( hwndParent
);
1078 if ( !WindowObject
)
1080 DPRINT("Bad window handle 0x%x\n", hwndParent
);
1081 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
1085 IntLockRelatives(WindowObject
);
1086 Child
= WindowObject
->FirstChild
;
1089 if ( pWnd
&& dwCount
< nBufSize
)
1090 pWnd
[dwCount
] = Child
->Self
;
1092 Child
= Child
->NextSibling
;
1094 IntUnLockRelatives(WindowObject
);
1095 IntReleaseWindowObject ( WindowObject
);
1097 else if ( dwThreadId
)
1100 struct _ETHREAD
* Thread
;
1101 struct _EPROCESS
* ThreadsProcess
;
1102 struct _W32PROCESS
* Win32Process
;
1103 struct _WINSTATION_OBJECT
* WindowStation
;
1104 PUSER_HANDLE_TABLE HandleTable
;
1105 PLIST_ENTRY Current
;
1106 PUSER_HANDLE_BLOCK Block
= NULL
;
1109 Status
= PsLookupThreadByThreadId ( (PVOID
)dwThreadId
, &Thread
);
1110 if ( !NT_SUCCESS(Status
) || !Thread
)
1112 DPRINT("Bad ThreadId 0x%x\n", dwThreadId
);
1113 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1116 ThreadsProcess
= Thread
->ThreadsProcess
;
1117 ASSERT(ThreadsProcess
);
1118 Win32Process
= ThreadsProcess
->Win32Process
;
1119 ASSERT(Win32Process
);
1120 WindowStation
= Win32Process
->WindowStation
;
1121 ASSERT(WindowStation
);
1122 HandleTable
= (PUSER_HANDLE_TABLE
)(WindowStation
->HandleTable
);
1123 ASSERT(HandleTable
);
1125 ObDereferenceObject(Thread
);
1127 ObmpLockHandleTable(HandleTable
);
1129 Current
= HandleTable
->ListHead
.Flink
;
1130 while ( Current
!= &HandleTable
->ListHead
)
1132 Block
= CONTAINING_RECORD(Current
, USER_HANDLE_BLOCK
, ListEntry
);
1133 for ( i
= 0; i
< HANDLE_BLOCK_ENTRIES
; i
++ )
1135 PVOID ObjectBody
= Block
->Handles
[i
].ObjectBody
;
1138 if ( pWnd
&& dwCount
< nBufSize
)
1141 (HWND
)IntReferenceWindowObject(ObjectBody
);
1146 Current
= Current
->Flink
;
1149 ObmpUnlockHandleTable(HandleTable
);
1153 PDESKTOP_OBJECT DesktopObject
= NULL
;
1155 PWINDOW_OBJECT Child
, WndDesktop
;
1159 DesktopObject
= IntGetDesktopObject ( hDesktop
);
1162 DesktopObject
= IntGetActiveDesktop();
1165 DPRINT("Bad desktop handle 0x%x\n", hDesktop
);
1166 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1170 KeAcquireSpinLock ( &DesktopObject
->Lock
, &OldIrql
);
1172 WndDesktop
= IntGetWindowObject(DesktopObject
->DesktopWindow
);
1173 Child
= (WndDesktop
? WndDesktop
->FirstChild
: NULL
);
1176 if ( pWnd
&& dwCount
< nBufSize
)
1177 pWnd
[dwCount
] = Child
->Self
;
1179 Child
= Child
->NextSibling
;
1181 KeReleaseSpinLock ( &DesktopObject
->Lock
, OldIrql
);
1192 /* FIXME - NEEDS TO BE FIXED - UNSAFE !!! */
1194 NtUserChildWindowFromPointEx(HWND hwndParent
,
1199 PWINDOW_OBJECT pParent
, pCurrent
, pLast
, pPar
;
1202 BOOL bFirstRun
= TRUE
;
1206 pParent
= IntGetWindowObject(hwndParent
);
1209 IntLockRelatives(pParent
);
1211 pLast
= IntGetWindowObject(pParent
->LastChild
->Self
);
1212 pCurrent
= IntGetWindowObject(pParent
->FirstChild
->Self
);
1218 pCurrent
= IntGetWindowObject(pCurrent
->NextSibling
->Self
);
1225 IntUnLockRelatives(pParent
);
1228 if(!(pPar
= IntGetWindowObject(pCurrent
->Parent
)))
1230 IntUnLockRelatives(pParent
);
1233 rc
.left
= pCurrent
->WindowRect
.left
- pPar
->ClientRect
.left
;
1234 rc
.top
= pCurrent
->WindowRect
.top
- pPar
->ClientRect
.top
;
1235 rc
.right
= rc
.left
+ (pCurrent
->WindowRect
.right
- pCurrent
->WindowRect
.left
);
1236 rc
.bottom
= rc
.top
+ (pCurrent
->WindowRect
.bottom
- pCurrent
->WindowRect
.top
);
1237 DbgPrint("Rect: %i,%i,%i,%i\n",rc
.left
, rc
.top
, rc
.right
, rc
.bottom
);
1238 IntReleaseWindowObject(pPar
);
1239 if (POINT_IN_RECT(p
,rc
)) /* Found a match */
1241 if ( (uiFlags
& CWP_SKIPDISABLED
) && (pCurrent
->Style
& WS_DISABLED
) )
1243 if( (uiFlags
& CWP_SKIPTRANSPARENT
) && (pCurrent
->ExStyle
& WS_EX_TRANSPARENT
) )
1245 if( (uiFlags
& CWP_SKIPINVISIBLE
) && !(pCurrent
->Style
& WS_VISIBLE
) )
1248 IntUnLockRelatives(pParent
);
1249 return pCurrent
->Self
;
1252 while(pCurrent
!= pLast
);
1254 IntUnLockRelatives(pParent
);
1257 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1268 NtUserCreateWindowEx(DWORD dwExStyle
,
1269 PUNICODE_STRING lpClassName
,
1270 PUNICODE_STRING lpWindowName
,
1278 HINSTANCE hInstance
,
1281 BOOL bUnicodeWindow
)
1283 PWINSTATION_OBJECT WinStaObject
;
1284 PWNDCLASS_OBJECT ClassObject
;
1285 PWINDOW_OBJECT WindowObject
;
1286 PWINDOW_OBJECT ParentWindow
, OwnerWindow
;
1287 HWND ParentWindowHandle
;
1288 HWND OwnerWindowHandle
;
1289 PMENU_OBJECT SystemMenu
;
1290 UNICODE_STRING WindowName
;
1294 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1299 CBT_CREATEWNDW CbtCreate
;
1303 DPRINT("NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1305 if (! RtlCreateUnicodeString(&WindowName
,
1306 NULL
== lpWindowName
->Buffer
?
1307 L
"" : lpWindowName
->Buffer
))
1309 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1313 ParentWindowHandle
= PsGetWin32Thread()->Desktop
->DesktopWindow
;
1314 OwnerWindowHandle
= NULL
;
1316 if (hWndParent
== HWND_MESSAGE
)
1319 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1320 * message window (style: WS_POPUP|WS_DISABLED)
1324 else if (hWndParent
)
1326 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1327 ParentWindowHandle
= hWndParent
;
1329 OwnerWindowHandle
= NtUserGetAncestor(hWndParent
, GA_ROOT
);
1331 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1333 RtlFreeUnicodeString(&WindowName
);
1334 return (HWND
)0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1337 if (NULL
!= ParentWindowHandle
)
1339 ParentWindow
= IntGetWindowObject(ParentWindowHandle
);
1343 ParentWindow
= NULL
;
1346 /* FIXME: parent must belong to the current process */
1348 /* Check the class. */
1349 Status
= ClassReferenceClassByNameOrAtom(&ClassObject
, lpClassName
->Buffer
);
1350 if (!NT_SUCCESS(Status
))
1352 RtlFreeUnicodeString(&WindowName
);
1353 if (NULL
!= ParentWindow
)
1355 IntReleaseWindowObject(ParentWindow
);
1360 /* Check the window station. */
1361 DPRINT("IoGetCurrentProcess() %X\n", IoGetCurrentProcess());
1362 DPRINT("PROCESS_WINDOW_STATION %X\n", PROCESS_WINDOW_STATION());
1363 Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
1367 if (!NT_SUCCESS(Status
))
1369 ObmDereferenceObject(ClassObject
);
1370 RtlFreeUnicodeString(&WindowName
);
1371 if (NULL
!= ParentWindow
)
1373 IntReleaseWindowObject(ParentWindow
);
1375 DPRINT("Validation of window station handle (0x%X) failed\n",
1376 PROCESS_WINDOW_STATION());
1380 /* Create the window object. */
1381 WindowObject
= (PWINDOW_OBJECT
)
1382 ObmCreateObject(PsGetWin32Process()->WindowStation
->HandleTable
, &Handle
,
1383 otWindow
, sizeof(WINDOW_OBJECT
) + ClassObject
->cbWndExtra
1386 DPRINT("Created object with handle %X\n", Handle
);
1389 ObDereferenceObject(WinStaObject
);
1390 ObmDereferenceObject(ClassObject
);
1391 RtlFreeUnicodeString(&WindowName
);
1392 if (NULL
!= ParentWindow
)
1394 IntReleaseWindowObject(ParentWindow
);
1396 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1399 ObDereferenceObject(WinStaObject
);
1401 if (NULL
== PsGetWin32Thread()->Desktop
->DesktopWindow
)
1403 /* If there is no desktop window yet, we must be creating it */
1404 PsGetWin32Thread()->Desktop
->DesktopWindow
= Handle
;
1408 * Fill out the structure describing it.
1410 WindowObject
->Class
= ClassObject
;
1411 WindowObject
->ExStyle
= dwExStyle
;
1412 WindowObject
->Style
= dwStyle
& ~WS_VISIBLE
;
1413 DPRINT("1: Style is now %d\n", WindowObject
->Style
);
1415 WindowObject
->SystemMenu
= (HMENU
)0;
1416 WindowObject
->ContextHelpId
= 0;
1417 WindowObject
->IDMenu
= 0;
1418 WindowObject
->Instance
= hInstance
;
1419 WindowObject
->Self
= Handle
;
1420 if (0 != (dwStyle
& WS_CHILD
))
1422 WindowObject
->IDMenu
= (UINT
) hMenu
;
1426 IntSetMenu(WindowObject
, hMenu
, &MenuChanged
);
1428 WindowObject
->MessageQueue
= PsGetWin32Thread()->MessageQueue
;
1429 WindowObject
->Parent
= (ParentWindow
? ParentWindow
->Self
: NULL
);
1430 if((OwnerWindow
= IntGetWindowObject(OwnerWindowHandle
)))
1432 WindowObject
->Owner
= OwnerWindowHandle
;
1433 IntReleaseWindowObject(OwnerWindow
);
1436 WindowObject
->Owner
= NULL
;
1437 WindowObject
->UserData
= 0;
1438 if ((((DWORD
)ClassObject
->lpfnWndProcA
& 0xFFFF0000) != 0xFFFF0000)
1439 && (((DWORD
)ClassObject
->lpfnWndProcW
& 0xFFFF0000) != 0xFFFF0000))
1441 WindowObject
->Unicode
= bUnicodeWindow
;
1445 WindowObject
->Unicode
= ClassObject
->Unicode
;
1447 WindowObject
->WndProcA
= ClassObject
->lpfnWndProcA
;
1448 WindowObject
->WndProcW
= ClassObject
->lpfnWndProcW
;
1449 WindowObject
->OwnerThread
= PsGetCurrentThread();
1450 WindowObject
->FirstChild
= NULL
;
1451 WindowObject
->LastChild
= NULL
;
1452 WindowObject
->PrevSibling
= NULL
;
1453 WindowObject
->NextSibling
= NULL
;
1455 /* extra window data */
1456 if (ClassObject
->cbWndExtra
!= 0)
1458 WindowObject
->ExtraData
= (PCHAR
)(WindowObject
+ 1);
1459 WindowObject
->ExtraDataSize
= ClassObject
->cbWndExtra
;
1460 RtlZeroMemory(WindowObject
->ExtraData
, WindowObject
->ExtraDataSize
);
1464 WindowObject
->ExtraData
= NULL
;
1465 WindowObject
->ExtraDataSize
= 0;
1468 InitializeListHead(&WindowObject
->PropListHead
);
1469 ExInitializeFastMutex(&WindowObject
->PropListLock
);
1470 ExInitializeFastMutex(&WindowObject
->RelativesLock
);
1471 ExInitializeFastMutex(&WindowObject
->UpdateLock
);
1473 RtlInitUnicodeString(&WindowObject
->WindowName
, WindowName
.Buffer
);
1475 /* Correct the window style. */
1476 if (!(dwStyle
& WS_CHILD
))
1478 WindowObject
->Style
|= WS_CLIPSIBLINGS
;
1479 DPRINT("3: Style is now %d\n", WindowObject
->Style
);
1480 if (!(dwStyle
& WS_POPUP
))
1482 WindowObject
->Style
|= WS_CAPTION
;
1483 WindowObject
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1484 DPRINT("4: Style is now %d\n", WindowObject
->Style
);
1485 /* FIXME: Note the window needs a size. */
1489 /* create system menu */
1490 if((WindowObject
->Style
& WS_SYSMENU
) && (WindowObject
->Style
& WS_CAPTION
))
1492 SystemMenu
= IntGetSystemMenu(WindowObject
, TRUE
, TRUE
);
1495 WindowObject
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1496 IntReleaseMenuObject(SystemMenu
);
1500 /* Insert the window into the thread's window list. */
1501 IntLockThreadWindows(PsGetWin32Thread());
1502 InsertTailList (&PsGetWin32Thread()->WindowListHead
,
1503 &WindowObject
->ThreadListEntry
);
1504 IntUnLockThreadWindows(PsGetWin32Thread());
1506 /* Allocate a DCE for this window. */
1507 if (dwStyle
& CS_OWNDC
)
1509 WindowObject
->Dce
= DceAllocDCE(WindowObject
->Self
, DCE_WINDOW_DC
);
1511 /* FIXME: Handle "CS_CLASSDC" */
1513 /* Initialize the window dimensions. */
1514 WindowObject
->WindowRect
.left
= x
;
1515 WindowObject
->WindowRect
.top
= y
;
1516 WindowObject
->WindowRect
.right
= x
+ nWidth
;
1517 WindowObject
->WindowRect
.bottom
= y
+ nHeight
;
1518 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1520 NtGdiOffsetRect(&(WindowObject
->WindowRect
), ParentWindow
->ClientRect
.left
,
1521 ParentWindow
->ClientRect
.top
);
1523 WindowObject
->ClientRect
= WindowObject
->WindowRect
;
1525 Cs
.lpCreateParams
= lpParam
;
1526 Cs
.hInstance
= hInstance
;
1528 Cs
.hwndParent
= ParentWindowHandle
;
1534 Cs
.lpszName
= lpWindowName
->Buffer
;
1535 Cs
.lpszClass
= lpClassName
->Buffer
;
1536 Cs
.dwExStyle
= dwExStyle
;
1537 CbtCreate
.lpcs
= &Cs
;
1538 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1539 if (HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) Handle
, (LPARAM
) &CbtCreate
))
1541 if (NULL
!= ParentWindow
)
1543 IntReleaseWindowObject(ParentWindow
);
1545 DPRINT1("CBT-hook returned !0\n");
1550 * Get the size and position of the window.
1552 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
1554 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1556 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
1557 WinPosGetMinMaxInfo(WindowObject
, &MaxSize
, &MaxPos
, &MinTrack
,
1559 if (MaxSize
.x
< nWidth
) nWidth
= MaxSize
.x
;
1560 if (MaxSize
.y
< nHeight
) nHeight
= MaxSize
.y
;
1561 if (nWidth
< MinTrack
.x
) nWidth
= MinTrack
.x
;
1562 if (nHeight
< MinTrack
.y
) nHeight
= MinTrack
.y
;
1563 if (nWidth
< 0) nWidth
= 0;
1564 if (nHeight
< 0) nHeight
= 0;
1567 WindowObject
->WindowRect
.left
= x
;
1568 WindowObject
->WindowRect
.top
= y
;
1569 WindowObject
->WindowRect
.right
= x
+ nWidth
;
1570 WindowObject
->WindowRect
.bottom
= y
+ nHeight
;
1571 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1573 NtGdiOffsetRect(&(WindowObject
->WindowRect
), ParentWindow
->ClientRect
.left
,
1574 ParentWindow
->ClientRect
.top
);
1576 WindowObject
->ClientRect
= WindowObject
->WindowRect
;
1578 /* FIXME: Initialize the window menu. */
1580 /* Initialize the window's scrollbars */
1581 if (dwStyle
& WS_VSCROLL
)
1583 WindowObject
->Style
&= ~WS_VSCROLL
;
1584 NtUserShowScrollBar(WindowObject
->Self
, SB_VERT
, TRUE
);
1586 if (dwStyle
& WS_HSCROLL
)
1588 WindowObject
->Style
&= ~WS_HSCROLL
;
1589 NtUserShowScrollBar(WindowObject
->Self
, SB_HORZ
, TRUE
);
1592 /* Send a NCCREATE message. */
1598 DPRINT("[win32k.window] NtUserCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
1599 DPRINT("NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1600 DPRINT("NtUserCreateWindowEx(): About to send NCCREATE message.\n");
1601 Result
= IntSendMessage(WindowObject
->Self
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
1604 /* FIXME: Cleanup. */
1605 if (NULL
!= ParentWindow
)
1607 IntReleaseWindowObject(ParentWindow
);
1609 DPRINT("NtUserCreateWindowEx(): NCCREATE message failed.\n");
1613 /* Calculate the non-client size. */
1614 MaxPos
.x
= WindowObject
->WindowRect
.left
;
1615 MaxPos
.y
= WindowObject
->WindowRect
.top
;
1616 DPRINT("NtUserCreateWindowEx(): About to get non-client size.\n");
1617 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
1618 Result
= WinPosGetNonClientSize(WindowObject
->Self
,
1619 &WindowObject
->WindowRect
,
1620 &WindowObject
->ClientRect
);
1621 NtGdiOffsetRect(&WindowObject
->WindowRect
,
1622 MaxPos
.x
- WindowObject
->WindowRect
.left
,
1623 MaxPos
.y
- WindowObject
->WindowRect
.top
);
1625 if (NULL
!= ParentWindow
)
1627 /* link the window into the parent's child list */
1628 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
1630 PWINDOW_OBJECT PrevSibling
;
1631 IntLockRelatives(ParentWindow
);
1632 if((PrevSibling
= ParentWindow
->LastChild
))
1633 IntReferenceWindowObject(PrevSibling
);
1634 IntUnLockRelatives(ParentWindow
);
1635 /* link window as bottom sibling */
1636 IntLinkWindow(WindowObject
, ParentWindow
, PrevSibling
/*prev sibling*/);
1638 IntReleaseWindowObject(PrevSibling
);
1642 /* link window as top sibling (but after topmost siblings) */
1643 PWINDOW_OBJECT InsertAfter
, Sibling
;
1644 if (0 == (dwExStyle
& WS_EX_TOPMOST
))
1646 IntLockRelatives(ParentWindow
);
1648 Sibling
= ParentWindow
->FirstChild
;
1649 while (NULL
!= Sibling
&& 0 != (Sibling
->ExStyle
& WS_EX_TOPMOST
))
1651 InsertAfter
= Sibling
;
1652 Sibling
= Sibling
->NextSibling
;
1654 IntUnLockRelatives(ParentWindow
);
1660 if (NULL
!= InsertAfter
)
1662 IntReferenceWindowObject(InsertAfter
);
1664 IntLinkWindow(WindowObject
, ParentWindow
, InsertAfter
/* prev sibling */);
1665 if (NULL
!= InsertAfter
)
1667 IntReleaseWindowObject(InsertAfter
);
1672 /* Send the WM_CREATE message. */
1673 DPRINT("NtUserCreateWindowEx(): about to send CREATE message.\n");
1674 Result
= IntSendMessage(WindowObject
->Self
, WM_CREATE
, 0, (LPARAM
) &Cs
);
1675 if (Result
== (LRESULT
)-1)
1677 /* FIXME: Cleanup. */
1678 if (NULL
!= ParentWindow
)
1680 IntReleaseWindowObject(ParentWindow
);
1682 DPRINT("NtUserCreateWindowEx(): send CREATE message failed.\n");
1686 /* Send move and size messages. */
1687 if (!(WindowObject
->Flags
& WINDOWOBJECT_NEED_SIZE
))
1691 DPRINT("NtUserCreateWindow(): About to send WM_SIZE\n");
1693 if ((WindowObject
->ClientRect
.right
- WindowObject
->ClientRect
.left
) < 0 ||
1694 (WindowObject
->ClientRect
.bottom
- WindowObject
->ClientRect
.top
) < 0)
1695 DPRINT("Sending bogus WM_SIZE\n");
1697 lParam
= MAKE_LONG(WindowObject
->ClientRect
.right
-
1698 WindowObject
->ClientRect
.left
,
1699 WindowObject
->ClientRect
.bottom
-
1700 WindowObject
->ClientRect
.top
);
1701 IntSendMessage(WindowObject
->Self
, WM_SIZE
, SIZE_RESTORED
,
1704 DPRINT("NtUserCreateWindow(): About to send WM_MOVE\n");
1706 if (0 != (WindowObject
->Style
& WS_CHILD
) && ParentWindow
)
1708 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
- ParentWindow
->ClientRect
.left
,
1709 WindowObject
->ClientRect
.top
- ParentWindow
->ClientRect
.top
);
1713 lParam
= MAKE_LONG(WindowObject
->ClientRect
.left
,
1714 WindowObject
->ClientRect
.top
);
1716 IntSendMessage(WindowObject
->Self
, WM_MOVE
, 0, lParam
);
1719 /* Show or maybe minimize or maximize the window. */
1720 if (WindowObject
->Style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1725 SwFlag
= (WindowObject
->Style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
1727 WinPosMinMaximize(WindowObject
, SwFlag
, &NewPos
);
1729 ((WindowObject
->Style
& WS_CHILD
) || NtUserGetActiveWindow()) ?
1730 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
1731 SWP_NOZORDER
| SWP_FRAMECHANGED
;
1732 DPRINT("NtUserCreateWindow(): About to minimize/maximize\n");
1733 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
1734 WinPosSetWindowPos(WindowObject
->Self
, 0, NewPos
.left
, NewPos
.top
,
1735 NewPos
.right
, NewPos
.bottom
, SwFlag
);
1738 /* Notify the parent window of a new child. */
1739 if ((WindowObject
->Style
& WS_CHILD
) &&
1740 (!(WindowObject
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
1742 DPRINT("NtUserCreateWindow(): About to notify parent\n");
1743 IntSendMessage(ParentWindow
->Self
,
1745 MAKEWPARAM(WM_CREATE
, WindowObject
->IDMenu
),
1746 (LPARAM
)WindowObject
->Self
);
1749 if (NULL
!= ParentWindow
)
1751 IntReleaseWindowObject(ParentWindow
);
1754 if (dwStyle
& WS_VISIBLE
)
1756 DPRINT("NtUserCreateWindow(): About to show window\n");
1757 WinPosShowWindow(WindowObject
->Self
, dwShowMode
);
1760 DPRINT("NtUserCreateWindow(): = %X\n", Handle
);
1761 DPRINT("WindowObject->SystemMenu = 0x%x\n", WindowObject
->SystemMenu
);
1762 return((HWND
)Handle
);
1770 NtUserDeferWindowPos(HDWP WinPosInfo
,
1772 HWND WndInsertAfter
,
1789 NtUserDestroyWindow(HWND Wnd
)
1791 PWINDOW_OBJECT Window
;
1794 Window
= IntGetWindowObject(Wnd
);
1800 /* Check for owner thread and desktop window */
1801 if ((Window
->OwnerThread
!= PsGetCurrentThread()) || IntIsDesktopWindow(Window
))
1803 IntReleaseWindowObject(Window
);
1804 SetLastWin32Error(ERROR_ACCESS_DENIED
);
1808 /* Look whether the focus is within the tree of windows we will
1811 if (!WinPosShowWindow(Wnd
, SW_HIDE
))
1813 if (NtUserGetActiveWindow() == Wnd
)
1815 WinPosActivateOtherWindow(Window
);
1818 IntLockMessageQueue(Window
->MessageQueue
);
1819 if (Window
->MessageQueue
->ActiveWindow
== Window
->Self
)
1820 Window
->MessageQueue
->ActiveWindow
= NULL
;
1821 if (Window
->MessageQueue
->FocusWindow
== Window
->Self
)
1822 Window
->MessageQueue
->FocusWindow
= NULL
;
1823 if (Window
->MessageQueue
->CaptureWindow
== Window
->Self
)
1824 Window
->MessageQueue
->CaptureWindow
= NULL
;
1825 IntUnLockMessageQueue(Window
->MessageQueue
);
1829 if (HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hwnd
, 0, TRUE
))
1835 isChild
= (0 != (Window
->Style
& WS_CHILD
));
1840 if (! USER_IsExitingThread(GetCurrentThreadId()))
1842 send_parent_notify(hwnd
, WM_DESTROY
);
1845 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
1847 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
1848 /* FIXME: clean up palette - see "Internals" p.352 */
1851 if (! IsWindow(Wnd
))
1857 if (!IntIsWindow(Wnd
))
1862 /* Recursively destroy owned windows */
1867 BOOL GotOne
= FALSE
;
1870 PWINDOW_OBJECT Child
, Desktop
;
1872 Desktop
= IntGetWindowObject(IntGetDesktopWindow());
1873 Children
= IntWinListChildren(Desktop
);
1874 IntReleaseWindowObject(Desktop
);
1877 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
1879 Child
= IntGetWindowObject(*ChildHandle
);
1884 if(Child
->Self
== Wnd
)
1886 IntReleaseWindowObject(Child
);
1889 IntLockRelatives(Child
);
1890 if (Child
->Parent
!= Window
->Self
)
1892 IntUnLockRelatives(Child
);
1893 IntReleaseWindowObject(Child
);
1896 IntUnLockRelatives(Child
);
1897 if (IntWndBelongsToThread(Child
, PsGetWin32Thread()))
1899 IntReleaseWindowObject(Child
);
1900 NtUserDestroyWindow(*ChildHandle
);
1904 IntLockRelatives(Child
);
1905 if (Child
->Owner
!= NULL
)
1907 Child
->Owner
= NULL
;
1909 IntUnLockRelatives(Child
);
1910 IntReleaseWindowObject(Child
);
1912 ExFreePool(Children
);
1921 if (!IntIsWindow(Wnd
))
1923 IntReleaseWindowObject(Window
);
1927 /* Destroy the window storage */
1928 IntDestroyWindow(Window
, PsGetWin32Process(), PsGetWin32Thread(), TRUE
);
1930 IntReleaseWindowObject(Window
);
1940 NtUserDrawMenuBarTemp(
1947 /* we'll use this function just for caching the menu bar */
1957 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
1970 NtUserFillWindow(DWORD Unknown0
,
1983 * Searches a window's children for a window with the specified
1986 * hwndParent = The window whose childs are to be searched.
1989 * hwndChildAfter = Search starts after this child window.
1990 * NULL = start from beginning
1992 * ucClassName = Class name to search for
1993 * Reguired parameter.
1995 * ucWindowName = Window name
1996 * ->Buffer == NULL = don't care
1999 * The HWND of the window if it was found, otherwise NULL
2002 * Should use MmCopyFromCaller, we don't want an access violation in here
2009 NtUserFindWindowEx(HWND hwndParent
,
2010 HWND hwndChildAfter
,
2011 PUNICODE_STRING ucClassName
,
2012 PUNICODE_STRING ucWindowName
)
2016 PWINDOW_OBJECT ParentWindow
, WndChildAfter
, WndChild
;
2017 PWNDCLASS_OBJECT classObject
;
2019 // Get a pointer to the class
2020 status
= ClassReferenceClassByNameOrAtom(&classObject
, ucClassName
->Buffer
);
2021 if (!NT_SUCCESS(status
))
2026 // If hwndParent==NULL use the desktop window instead
2028 hwndParent
= PsGetWin32Thread()->Desktop
->DesktopWindow
;
2031 ParentWindow
= IntGetWindowObject(hwndParent
);
2035 ObmDereferenceObject(classObject
);
2039 IntLockRelatives(ParentWindow
);
2043 if (!(WndChildAfter
= IntGetWindowObject(hwndChildAfter
)))
2045 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2049 /* must be a direct child (not a decendant child)*/
2050 IntLockRelatives(WndChildAfter
);
2051 if (WndChildAfter
->Parent
!= ParentWindow
->Self
)
2053 IntUnLockRelatives(WndChildAfter
);
2054 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2057 IntUnLockRelatives(WndChildAfter
);
2059 WndChild
= WndChildAfter
->NextSibling
;
2063 WndChild
= ParentWindow
->FirstChild
;
2068 if (classObject
== WndChild
->Class
&& (ucWindowName
->Buffer
==NULL
||
2069 RtlCompareUnicodeString (ucWindowName
, &WndChild
->WindowName
, TRUE
) == 0))
2071 windowHandle
= WndChild
->Self
;
2073 IntUnLockRelatives(ParentWindow
);
2074 IntReleaseWindowObject(ParentWindow
);
2075 ObmDereferenceObject (classObject
);
2077 return windowHandle
;
2080 WndChild
= WndChild
->NextSibling
;
2083 IntUnLockRelatives(ParentWindow
);
2085 IntReleaseWindowObject(ParentWindow
);
2086 ObmDereferenceObject (classObject
);
2096 NtUserFlashWindowEx(DWORD Unknown0
)
2108 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2110 PWINDOW_OBJECT Wnd
, WndAncestor
, Parent
;
2113 if (hWnd
== IntGetDesktopWindow())
2118 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2120 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2127 WndAncestor
= IntGetParentObject(Wnd
);
2134 while (0 != (WndAncestor
->Style
& WS_CHILD
))
2136 Parent
= IntGetParentObject(WndAncestor
);
2137 if (WndAncestor
!= Wnd
)
2139 IntReleaseWindowObject(WndAncestor
);
2141 WndAncestor
= Parent
;
2148 IntReleaseWindowObject(Parent
);
2150 if(!(Parent
= IntGetParentObject(WndAncestor
)) ||
2151 !IntIsDesktopWindow(WndAncestor
))
2155 WndAncestor
= Parent
;
2162 IntReferenceWindowObject(WndAncestor
);
2167 Parent
= IntGetParent(WndAncestor
);
2168 IntReleaseWindowObject(Old
);
2173 WndAncestor
= Parent
;
2178 IntReleaseWindowObject(Wnd
);
2182 IntReleaseWindowObject(Wnd
);
2189 hWndAncestor
= WndAncestor
->Self
;
2190 if(WndAncestor
!= Wnd
)
2191 IntReleaseWindowObject(WndAncestor
);
2193 return hWndAncestor
;
2198 * Returns client window rectangle relative to the upper-left corner of client area.
2200 * \param hWnd window handle.
2201 * \param Rect pointer to the buffer where the coordinates are returned.
2208 NtUserGetClientRect(HWND hWnd
, LPRECT Rect
)
2210 PWINDOW_OBJECT WindowObject
;
2213 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
2215 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2219 IntGetClientRect(WindowObject
, &SafeRect
);
2220 IntReleaseWindowObject(WindowObject
);
2222 if(!NT_SUCCESS(MmCopyToCaller(Rect
, &SafeRect
, sizeof(RECT
))))
2234 NtUserGetDesktopWindow()
2236 return IntGetDesktopWindow();
2244 NtUserGetInternalWindowPos(DWORD Unknown0
,
2258 NtUserGetLastActivePopup(HWND hWnd
)
2261 * This code can't work, because hWndLastPopup member of WINDOW_OBJECT is
2262 * not changed anywhere.
2263 * -- Filip, 01/nov/2003
2269 IntAcquireWinLockShared();
2271 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2273 IntReleaseWinLock();
2274 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2278 hWndLastPopup
= Wnd
->hWndLastPopup
;
2280 IntReleaseWinLock();
2282 return hWndLastPopup
;
2291 * The NtUserGetParent function retrieves a handle to the specified window's
2295 * Note that, despite its name, this function can return an owner window
2296 * instead of a parent window.
2303 NtUserGetParent(HWND hWnd
)
2305 PWINDOW_OBJECT Wnd
, WndParent
;
2306 HWND hWndParent
= NULL
;
2308 if (!(Wnd
= IntGetWindowObject(hWnd
)))
2310 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2314 WndParent
= IntGetParent(Wnd
);
2317 hWndParent
= WndParent
->Self
;
2318 IntReleaseWindowObject(WndParent
);
2321 IntReleaseWindowObject(Wnd
);
2329 * The NtUserSetParent function changes the parent window of the specified
2333 * The new parent window and the child window must belong to the same
2334 * application. If the window identified by the hWndChild parameter is
2335 * visible, the system performs the appropriate redrawing and repainting.
2336 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
2337 * or WS_POPUP window styles of the window whose parent is being changed.
2344 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2346 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
2347 HWND hWndOldParent
= NULL
;
2349 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
2351 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2355 if (hWndChild
== IntGetDesktopWindow())
2357 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2363 if (!(WndParent
= IntGetWindowObject(hWndNewParent
)))
2365 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2371 if (!(WndParent
= IntGetWindowObject(IntGetDesktopWindow())))
2373 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2378 if (!(Wnd
= IntGetWindowObject(hWndChild
)))
2380 IntReleaseWindowObject(WndParent
);
2381 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2385 WndOldParent
= IntSetParent(Wnd
, WndParent
);
2389 hWndOldParent
= WndOldParent
->Self
;
2390 IntReleaseWindowObject(WndOldParent
);
2393 IntReleaseWindowObject(Wnd
);
2394 IntReleaseWindowObject(WndParent
);
2396 return hWndOldParent
;
2400 * NtUserGetShellWindow
2402 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
2409 NtUserGetShellWindow()
2411 PWINSTATION_OBJECT WinStaObject
;
2414 NTSTATUS Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
2419 if (!NT_SUCCESS(Status
))
2421 SetLastNtError(Status
);
2425 Ret
= (HWND
)WinStaObject
->ShellWindow
;
2427 ObDereferenceObject(WinStaObject
);
2432 * NtUserSetShellWindowEx
2434 * This is undocumented function to set global shell window. The global
2435 * shell window has special handling of window position.
2442 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
2444 PWINSTATION_OBJECT WinStaObject
;
2446 NTSTATUS Status
= IntValidateWindowStationHandle(PROCESS_WINDOW_STATION(),
2451 if (!NT_SUCCESS(Status
))
2453 SetLastNtError(Status
);
2458 * Test if we are permitted to change the shell window.
2460 if (WinStaObject
->ShellWindow
)
2462 ObDereferenceObject(WinStaObject
);
2467 * Move shell window into background.
2469 if (hwndListView
&& hwndListView
!= hwndShell
)
2472 * Disabled for now to get Explorer working.
2473 * -- Filip, 01/nov/2003
2476 WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2479 if (NtUserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2481 ObDereferenceObject(WinStaObject
);
2486 if (NtUserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2488 ObDereferenceObject(WinStaObject
);
2492 WinPosSetWindowPos(hwndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2494 WinStaObject
->ShellWindow
= hwndShell
;
2495 WinStaObject
->ShellListView
= hwndListView
;
2497 ObDereferenceObject(WinStaObject
);
2502 * NtUserGetSystemMenu
2504 * The NtUserGetSystemMenu function allows the application to access the
2505 * window menu (also known as the system menu or the control menu) for
2506 * copying and modifying.
2510 * Handle to the window that will own a copy of the window menu.
2512 * Specifies the action to be taken. If this parameter is FALSE,
2513 * NtUserGetSystemMenu returns a handle to the copy of the window menu
2514 * currently in use. The copy is initially identical to the window menu
2515 * but it can be modified.
2516 * If this parameter is TRUE, GetSystemMenu resets the window menu back
2517 * to the default state. The previous window menu, if any, is destroyed.
2520 * If the bRevert parameter is FALSE, the return value is a handle to a
2521 * copy of the window menu. If the bRevert parameter is TRUE, the return
2529 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
2532 PWINDOW_OBJECT WindowObject
;
2533 PMENU_OBJECT MenuObject
;
2535 WindowObject
= IntGetWindowObject((HWND
)hWnd
);
2536 if (WindowObject
== NULL
)
2538 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2542 MenuObject
= IntGetSystemMenu(WindowObject
, bRevert
, FALSE
);
2545 Result
= MenuObject
->MenuInfo
.Self
;
2546 IntReleaseMenuObject(MenuObject
);
2549 IntReleaseWindowObject(WindowObject
);
2554 * NtUserSetSystemMenu
2561 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
2563 BOOL Result
= FALSE
;
2564 PWINDOW_OBJECT WindowObject
;
2565 PMENU_OBJECT MenuObject
;
2567 WindowObject
= IntGetWindowObject(hWnd
);
2570 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2577 * Assign new menu handle.
2579 MenuObject
= IntGetMenuObject(hMenu
);
2582 IntReleaseWindowObject(WindowObject
);
2583 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
2587 Result
= IntSetSystemMenu(WindowObject
, MenuObject
);
2589 IntReleaseMenuObject(MenuObject
);
2592 IntReleaseWindowObject(WindowObject
);
2600 * The NtUserGetWindow function retrieves a handle to a window that has the
2601 * specified relationship (Z order or owner) to the specified window.
2608 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
2610 PWINDOW_OBJECT WindowObject
, Parent
;
2611 HWND hWndResult
= NULL
;
2613 if (!(WindowObject
= IntGetWindowObject(hWnd
)))
2615 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2619 switch (Relationship
)
2622 if((Parent
= IntGetParentObject(WindowObject
)))
2624 IntLockRelatives(Parent
);
2625 if (Parent
->FirstChild
)
2626 hWndResult
= Parent
->FirstChild
->Self
;
2627 IntUnLockRelatives(Parent
);
2628 IntReleaseWindowObject(Parent
);
2633 if((Parent
= IntGetParentObject(WindowObject
)))
2635 IntLockRelatives(Parent
);
2636 if (Parent
->LastChild
)
2637 hWndResult
= Parent
->LastChild
->Self
;
2638 IntUnLockRelatives(Parent
);
2639 IntReleaseWindowObject(Parent
);
2644 IntLockRelatives(WindowObject
);
2645 if (WindowObject
->NextSibling
)
2646 hWndResult
= WindowObject
->NextSibling
->Self
;
2647 IntUnLockRelatives(WindowObject
);
2651 IntLockRelatives(WindowObject
);
2652 if (WindowObject
->PrevSibling
)
2653 hWndResult
= WindowObject
->PrevSibling
->Self
;
2654 IntUnLockRelatives(WindowObject
);
2658 IntLockRelatives(WindowObject
);
2659 if((Parent
= IntGetWindowObject(WindowObject
->Owner
)))
2661 hWndResult
= Parent
->Self
;
2662 IntReleaseWindowObject(Parent
);
2664 IntUnLockRelatives(WindowObject
);
2667 IntLockRelatives(WindowObject
);
2668 if (WindowObject
->FirstChild
)
2669 hWndResult
= WindowObject
->FirstChild
->Self
;
2670 IntUnLockRelatives(WindowObject
);
2674 IntReleaseWindowObject(WindowObject
);
2682 * The NtUserGetWindowDC function retrieves the device context (DC) for the
2683 * entire window, including title bar, menus, and scroll bars. A window device
2684 * context permits painting anywhere in a window, because the origin of the
2685 * device context is the upper-left corner of the window instead of the client
2693 NtUserGetWindowDC(HWND hWnd
)
2695 return (DWORD
)NtUserGetDCEx(hWnd
, 0, DCX_USESTYLE
| DCX_WINDOW
);
2699 * NtUserGetWindowLong
2701 * The NtUserGetWindowLong function retrieves information about the specified
2702 * window. The function also retrieves the 32-bit (long) value at the
2703 * specified offset into the extra window memory.
2710 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
2712 PWINDOW_OBJECT WindowObject
, Parent
;
2715 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
2717 WindowObject
= IntGetWindowObject(hWnd
);
2718 if (WindowObject
== NULL
)
2720 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2725 * Only allow CSRSS to mess with the desktop window
2727 if (hWnd
== IntGetDesktopWindow()
2728 && WindowObject
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
2730 SetLastWin32Error(STATUS_ACCESS_DENIED
);
2734 if ((INT
)Index
>= 0)
2736 if ((Index
+ sizeof(LONG
)) > WindowObject
->ExtraDataSize
)
2738 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2741 Result
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
2748 Result
= WindowObject
->ExStyle
;
2752 Result
= WindowObject
->Style
;
2757 Result
= (LONG
) WindowObject
->WndProcA
;
2759 Result
= (LONG
) WindowObject
->WndProcW
;
2763 Result
= (LONG
) WindowObject
->Instance
;
2766 case GWL_HWNDPARENT
:
2767 IntLockRelatives(WindowObject
);
2768 Parent
= IntGetWindowObject(WindowObject
->Parent
);
2769 IntUnLockRelatives(WindowObject
);
2772 if (Parent
&& Parent
->Self
== IntGetDesktopWindow())
2773 Result
= (LONG
) NtUserGetWindow(WindowObject
->Self
, GW_OWNER
);
2775 Result
= (LONG
) Parent
->Self
;
2776 IntReleaseWindowObject(Parent
);
2781 Result
= (LONG
) WindowObject
->IDMenu
;
2785 Result
= WindowObject
->UserData
;
2789 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
2790 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2796 IntReleaseWindowObject(WindowObject
);
2802 * NtUserSetWindowLong
2804 * The NtUserSetWindowLong function changes an attribute of the specified
2805 * window. The function also sets the 32-bit (long) value at the specified
2806 * offset into the extra window memory.
2813 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
2815 PWINDOW_OBJECT WindowObject
, Parent
;
2816 PW32PROCESS Process
;
2817 PWINSTATION_OBJECT WindowStation
;
2821 if (hWnd
== IntGetDesktopWindow())
2823 SetLastWin32Error(STATUS_ACCESS_DENIED
);
2827 WindowObject
= IntGetWindowObject(hWnd
);
2828 if (WindowObject
== NULL
)
2830 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2834 if ((INT
)Index
>= 0)
2836 if ((Index
+ sizeof(LONG
)) > WindowObject
->ExtraDataSize
)
2838 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2839 IntReleaseWindowObject(WindowObject
);
2842 OldValue
= *((LONG
*)(WindowObject
->ExtraData
+ Index
));
2843 *((LONG
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
2850 OldValue
= (LONG
) WindowObject
->ExStyle
;
2851 Style
.styleOld
= OldValue
;
2852 Style
.styleNew
= NewValue
;
2855 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
2857 Process
= WindowObject
->OwnerThread
->ThreadsProcess
->Win32Process
;
2858 WindowStation
= Process
->WindowStation
;
2861 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
2862 Style
.styleNew
&= ~WS_EX_TOPMOST
;
2865 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
2866 WindowObject
->ExStyle
= (DWORD
)Style
.styleNew
;
2867 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
2871 OldValue
= (LONG
) WindowObject
->Style
;
2872 Style
.styleOld
= OldValue
;
2873 Style
.styleNew
= NewValue
;
2874 IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
2875 WindowObject
->Style
= (DWORD
)Style
.styleNew
;
2876 IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
2880 /* FIXME: should check if window belongs to current process */
2883 OldValue
= (LONG
) WindowObject
->WndProcA
;
2884 WindowObject
->WndProcA
= (WNDPROC
) NewValue
;
2885 WindowObject
->WndProcW
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,FALSE
);
2886 WindowObject
->Unicode
= FALSE
;
2890 OldValue
= (LONG
) WindowObject
->WndProcW
;
2891 WindowObject
->WndProcW
= (WNDPROC
) NewValue
;
2892 WindowObject
->WndProcA
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,TRUE
);
2893 WindowObject
->Unicode
= TRUE
;
2898 OldValue
= (LONG
) WindowObject
->Instance
;
2899 WindowObject
->Instance
= (HINSTANCE
) NewValue
;
2902 case GWL_HWNDPARENT
:
2903 Parent
= IntGetParentObject(WindowObject
);
2904 if (Parent
&& (Parent
->Self
== IntGetDesktopWindow()))
2905 OldValue
= (LONG
) IntSetOwner(WindowObject
->Self
, (HWND
) NewValue
);
2907 OldValue
= (LONG
) NtUserSetParent(WindowObject
->Self
, (HWND
) NewValue
);
2909 IntReleaseWindowObject(Parent
);
2913 OldValue
= (LONG
) WindowObject
->IDMenu
;
2914 WindowObject
->IDMenu
= (UINT
) NewValue
;
2918 OldValue
= WindowObject
->UserData
;
2919 WindowObject
->UserData
= NewValue
;
2923 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
2924 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2930 IntReleaseWindowObject(WindowObject
);
2936 * NtUserSetWindowWord
2938 * Legacy function similar to NtUserSetWindowLong.
2945 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
2947 PWINDOW_OBJECT WindowObject
;
2954 case GWL_HWNDPARENT
:
2955 return NtUserSetWindowLong(hWnd
, Index
, (UINT
)NewValue
, TRUE
);
2959 SetLastWin32Error(ERROR_INVALID_INDEX
);
2964 WindowObject
= IntGetWindowObject(hWnd
);
2965 if (WindowObject
== NULL
)
2967 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
2971 if (Index
> WindowObject
->ExtraDataSize
- sizeof(WORD
))
2973 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2974 IntReleaseWindowObject(WindowObject
);
2978 OldValue
= *((WORD
*)(WindowObject
->ExtraData
+ Index
));
2979 *((WORD
*)(WindowObject
->ExtraData
+ Index
)) = NewValue
;
2981 IntReleaseWindowObject(WindowObject
);
2990 NtUserGetWindowPlacement(HWND hWnd
,
2991 WINDOWPLACEMENT
*lpwndpl
)
2993 PWINDOW_OBJECT WindowObject
;
2994 PINTERNALPOS InternalPos
;
2996 WINDOWPLACEMENT Safepl
;
2999 WindowObject
= IntGetWindowObject(hWnd
);
3000 if (WindowObject
== NULL
)
3002 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3006 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3007 if(!NT_SUCCESS(Status
))
3009 SetLastNtError(Status
);
3010 IntReleaseWindowObject(WindowObject
);
3013 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3015 IntReleaseWindowObject(WindowObject
);
3020 Safepl
.showCmd
= ((WindowObject
->Flags
& WINDOWOBJECT_RESTOREMAX
) ? SW_MAXIMIZE
: SW_SHOWNORMAL
);
3022 Size
.x
= WindowObject
->WindowRect
.left
;
3023 Size
.y
= WindowObject
->WindowRect
.top
;
3024 InternalPos
= WinPosInitInternalPos(WindowObject
, &Size
,
3025 &WindowObject
->WindowRect
);
3028 Safepl
.rcNormalPosition
= InternalPos
->NormalRect
;
3029 Safepl
.ptMinPosition
= InternalPos
->IconPos
;
3030 Safepl
.ptMaxPosition
= InternalPos
->MaxPos
;
3034 IntReleaseWindowObject(WindowObject
);
3038 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3039 if(!NT_SUCCESS(Status
))
3041 SetLastNtError(Status
);
3042 IntReleaseWindowObject(WindowObject
);
3046 IntReleaseWindowObject(WindowObject
);
3052 * Return the dimension of the window in the screen coordinates.
3053 * \param hWnd window handle.
3054 * \param Rect pointer to the buffer where the coordinates are returned.
3060 NtUserGetWindowRect(HWND hWnd
, LPRECT Rect
)
3065 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3067 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3070 Status
= MmCopyToCaller(Rect
, &Wnd
->WindowRect
, sizeof(RECT
));
3071 if (!NT_SUCCESS(Status
))
3073 IntReleaseWindowObject(Wnd
);
3074 SetLastNtError(Status
);
3078 IntReleaseWindowObject(Wnd
);
3087 NtUserGetWindowThreadProcessId(HWND hWnd
, LPDWORD UnsafePid
)
3092 if (!(Wnd
= IntGetWindowObject(hWnd
)))
3094 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3098 tid
= (DWORD
)IntGetWndThreadId(Wnd
);
3099 pid
= (DWORD
)IntGetWndProcessId(Wnd
);
3101 if (UnsafePid
) MmCopyToCaller(UnsafePid
, &pid
, sizeof(DWORD
));
3111 NtUserLockWindowUpdate(DWORD Unknown0
)
3131 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3132 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3133 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3137 QueryWindow based on KJK::Hyperion and James Tabor.
3139 0 = QWUniqueProcessId
3140 1 = QWUniqueThreadId
3141 4 = QWIsHung Implements IsHungAppWindow found
3144 9 = QWKillWindow When I called this with hWnd ==
3145 DesktopWindow, it shutdown the system
3152 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3154 PWINDOW_OBJECT Window
= IntGetWindowObject(hWnd
);
3159 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3166 Result
= (DWORD
)IntGetWndProcessId(Window
);
3170 Result
= (DWORD
)IntGetWndThreadId(Window
);
3174 Result
= (DWORD
)NULL
;
3178 IntReleaseWindowObject(Window
);
3188 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3202 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3205 PLIST_ENTRY Current
;
3206 PREGISTERED_MESSAGE NewMsg
, RegMsg
;
3207 UINT Msg
= REGISTERED_MESSAGE_MIN
;
3208 UNICODE_STRING MessageName
;
3211 Status
= MmCopyFromCaller(&MessageName
, MessageNameUnsafe
, sizeof(UNICODE_STRING
));
3212 if (! NT_SUCCESS(Status
))
3214 SetLastNtError(Status
);
3218 NewMsg
= ExAllocatePoolWithTag(PagedPool
,
3219 sizeof(REGISTERED_MESSAGE
) +
3224 SetLastNtError(STATUS_NO_MEMORY
);
3228 Status
= MmCopyFromCaller(NewMsg
->MessageName
, MessageName
.Buffer
, MessageName
.Length
);
3229 if (! NT_SUCCESS(Status
))
3232 SetLastNtError(Status
);
3235 NewMsg
->MessageName
[MessageName
.Length
/ sizeof(WCHAR
)] = L
'\0';
3236 if (wcslen(NewMsg
->MessageName
) != MessageName
.Length
/ sizeof(WCHAR
))
3239 SetLastNtError(STATUS_INVALID_PARAMETER
);
3243 Current
= RegisteredMessageListHead
.Flink
;
3244 while (Current
!= &RegisteredMessageListHead
)
3246 RegMsg
= CONTAINING_RECORD(Current
, REGISTERED_MESSAGE
, ListEntry
);
3247 if (0 == wcscmp(NewMsg
->MessageName
, RegMsg
->MessageName
))
3253 Current
= Current
->Flink
;
3256 if (REGISTERED_MESSAGE_MAX
< Msg
)
3259 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
3263 InsertTailList(&RegisteredMessageListHead
, &(NewMsg
->ListEntry
));
3269 * - There's no need to call MmSafe*, because it should be done in kernel.
3270 * - The passed UNICODE_STRING is expected to be NULL-terminated.
3272 return (UINT
)IntAddAtom(MessageNameUnsafe
->Buffer
);
3281 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3294 NtUserSetInternalWindowPos(DWORD Unknown0
,
3310 NtUserSetLayeredWindowAttributes(DWORD Unknown0
,
3325 NtUserSetLogonNotifyWindow(DWORD Unknown0
)
3342 PWINDOW_OBJECT WindowObject
;
3345 WindowObject
= IntGetWindowObject((HWND
) Wnd
);
3346 if (NULL
== WindowObject
)
3348 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3352 if (! IntSetMenu(WindowObject
, Menu
, &Changed
))
3354 IntReleaseWindowObject(WindowObject
);
3358 IntReleaseWindowObject(WindowObject
);
3360 if (Changed
&& Repaint
)
3362 WinPosSetWindowPos(Wnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3363 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3374 NtUserSetWindowFNID(DWORD Unknown0
,
3388 NtUserSetWindowPlacement(HWND hWnd
,
3389 WINDOWPLACEMENT
*lpwndpl
)
3391 PWINDOW_OBJECT WindowObject
;
3392 WINDOWPLACEMENT Safepl
;
3395 WindowObject
= IntGetWindowObject(hWnd
);
3396 if (WindowObject
== NULL
)
3398 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3401 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3402 if(!NT_SUCCESS(Status
))
3404 SetLastNtError(Status
);
3405 IntReleaseWindowObject(WindowObject
);
3408 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3410 IntReleaseWindowObject(WindowObject
);
3414 if ((WindowObject
->Style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
3416 WinPosSetWindowPos(WindowObject
->Self
, NULL
,
3417 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
3418 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
3419 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
3420 SWP_NOZORDER
| SWP_NOACTIVATE
);
3423 /* FIXME - change window status */
3424 WinPosShowWindow(WindowObject
->Self
, Safepl
.showCmd
);
3426 if (WindowObject
->InternalPos
== NULL
)
3427 WindowObject
->InternalPos
= ExAllocatePoolWithTag(PagedPool
, sizeof(INTERNALPOS
), TAG_WININTLIST
);
3428 WindowObject
->InternalPos
->NormalRect
= Safepl
.rcNormalPosition
;
3429 WindowObject
->InternalPos
->IconPos
= Safepl
.ptMinPosition
;
3430 WindowObject
->InternalPos
->MaxPos
= Safepl
.ptMaxPosition
;
3432 IntReleaseWindowObject(WindowObject
);
3443 HWND hWndInsertAfter
,
3450 return WinPosSetWindowPos(hWnd
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
3455 IntGetWindowRgn(HWND hWnd
, HRGN hRgn
)
3458 PWINDOW_OBJECT WindowObject
;
3462 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
3464 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3469 IntReleaseWindowObject(WindowObject
);
3473 /* Create a new window region using the window rectangle */
3474 VisRgn
= UnsafeIntCreateRectRgnIndirect(&WindowObject
->WindowRect
);
3475 NtGdiOffsetRgn(VisRgn
, -WindowObject
->WindowRect
.left
, -WindowObject
->WindowRect
.top
);
3476 /* if there's a region assigned to the window, combine them both */
3477 if(WindowObject
->WindowRegion
&& !(WindowObject
->Style
& WS_MINIMIZE
))
3478 NtGdiCombineRgn(VisRgn
, VisRgn
, WindowObject
->WindowRegion
, RGN_AND
);
3479 /* Copy the region into hRgn */
3480 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
3482 if((pRgn
= RGNDATA_LockRgn(hRgn
)))
3484 Ret
= pRgn
->rdh
.iType
;
3485 RGNDATA_UnlockRgn(hRgn
);
3490 NtGdiDeleteObject(VisRgn
);
3492 IntReleaseWindowObject(WindowObject
);
3497 IntGetWindowRgnBox(HWND hWnd
, RECT
*Rect
)
3500 PWINDOW_OBJECT WindowObject
;
3504 if(!(WindowObject
= IntGetWindowObject(hWnd
)))
3506 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3511 IntReleaseWindowObject(WindowObject
);
3515 /* Create a new window region using the window rectangle */
3516 VisRgn
= UnsafeIntCreateRectRgnIndirect(&WindowObject
->WindowRect
);
3517 NtGdiOffsetRgn(VisRgn
, -WindowObject
->WindowRect
.left
, -WindowObject
->WindowRect
.top
);
3518 /* if there's a region assigned to the window, combine them both */
3519 if(WindowObject
->WindowRegion
&& !(WindowObject
->Style
& WS_MINIMIZE
))
3520 NtGdiCombineRgn(VisRgn
, VisRgn
, WindowObject
->WindowRegion
, RGN_AND
);
3522 if((pRgn
= RGNDATA_LockRgn(VisRgn
)))
3524 Ret
= pRgn
->rdh
.iType
;
3525 *Rect
= pRgn
->rdh
.rcBound
;
3526 RGNDATA_UnlockRgn(VisRgn
);
3531 NtGdiDeleteObject(VisRgn
);
3533 IntReleaseWindowObject(WindowObject
);
3547 PWINDOW_OBJECT WindowObject
;
3549 WindowObject
= IntGetWindowObject(hWnd
);
3550 if (WindowObject
== NULL
)
3552 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3556 /* FIXME - Verify if hRgn is a valid handle!!!!
3557 Propably make this operation thread-safe, but maybe it's not necessary */
3559 if(WindowObject
->WindowRegion
)
3561 /* Delete no longer needed region handle */
3562 NtGdiDeleteObject(WindowObject
->WindowRegion
);
3564 WindowObject
->WindowRegion
= hRgn
;
3566 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
3570 IntRedrawWindow(WindowObject
, NULL
, NULL
, RDW_INVALIDATE
);
3573 IntReleaseWindowObject(WindowObject
);
3582 NtUserShowWindow(HWND hWnd
,
3585 return WinPosShowWindow(hWnd
, nCmdShow
);
3593 NtUserShowWindowAsync(DWORD Unknown0
,
3606 NtUserUpdateLayeredWindow(DWORD Unknown0
,
3626 NtUserValidateRect(HWND hWnd
, const RECT
* Rect
)
3628 return (VOID
)NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
3636 NtUserWindowFromPoint(LONG X
, LONG Y
)
3640 PWINDOW_OBJECT DesktopWindow
, Window
= NULL
;
3642 if ((DesktopWindow
= IntGetWindowObject(IntGetDesktopWindow())))
3649 Hit
= WinPosWindowFromPoint(DesktopWindow
, TRUE
, &pt
, &Window
);
3654 IntReleaseWindowObject(Window
);
3655 IntReleaseWindowObject(DesktopWindow
);
3659 IntReleaseWindowObject(DesktopWindow
);
3669 * Undocumented function that is called from DefWindowProc to set
3672 * FIXME: Call this from user32.dll!
3679 NtUserDefSetText(HWND WindowHandle
, PANSI_STRING Text
)
3681 PWINDOW_OBJECT WindowObject
;
3682 UNICODE_STRING NewWindowName
;
3683 BOOL Result
= FALSE
;
3685 WindowObject
= IntGetWindowObject(WindowHandle
);
3688 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3692 if (NT_SUCCESS(RtlAnsiStringToUnicodeString(&NewWindowName
, Text
, TRUE
)))
3694 RtlFreeUnicodeString(&WindowObject
->WindowName
);
3695 WindowObject
->WindowName
.Buffer
= NewWindowName
.Buffer
;
3696 WindowObject
->WindowName
.Length
= NewWindowName
.Length
;
3697 WindowObject
->WindowName
.MaximumLength
= NewWindowName
.MaximumLength
;
3701 IntReleaseWindowObject(WindowObject
);
3707 * NtUserInternalGetWindowText
3709 * FIXME: Call this from user32.dll!
3716 NtUserInternalGetWindowText(HWND WindowHandle
, LPWSTR Text
, INT MaxCount
)
3718 PWINDOW_OBJECT WindowObject
;
3721 WindowObject
= IntGetWindowObject(WindowHandle
);
3724 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
3728 Result
= WindowObject
->WindowName
.Length
/ sizeof(WCHAR
);
3731 /* FIXME: Shouldn't it be always NULL terminated? */
3732 wcsncpy(Text
, WindowObject
->WindowName
.Buffer
, MaxCount
);
3733 if (MaxCount
< Result
)
3739 IntReleaseWindowObject(WindowObject
);
3745 NtUserDereferenceWndProcHandle(WNDPROC wpHandle
, WndProcHandle
*Data
)
3747 WndProcHandle Entry
;
3748 if (((DWORD
)wpHandle
& 0xFFFF0000) == 0xFFFF0000)
3750 Entry
= WndProcHandlesArray
[(DWORD
)wpHandle
& 0x0000FFFF];
3751 Data
->WindowProc
= Entry
.WindowProc
;
3752 Data
->IsUnicode
= Entry
.IsUnicode
;
3753 Data
->ProcessID
= Entry
.ProcessID
;
3762 IntAddWndProcHandle(WNDPROC WindowProc
, BOOL IsUnicode
)
3767 WndProcHandle
*OldArray
;
3770 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
3772 if (WndProcHandlesArray
[i
].WindowProc
== NULL
)
3780 OldArray
= WndProcHandlesArray
;
3781 OldArraySize
= WndProcHandlesArraySize
;
3782 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,(OldArraySize
+ WPH_SIZE
) * sizeof(WndProcHandle
), TAG_WINPROCLST
);
3783 WndProcHandlesArraySize
= OldArraySize
+ WPH_SIZE
;
3784 RtlCopyMemory(WndProcHandlesArray
,OldArray
,OldArraySize
* sizeof(WndProcHandle
));
3785 ExFreePool(OldArray
);
3786 FreeSpot
= OldArraySize
+ 1;
3788 WndProcHandlesArray
[FreeSpot
].WindowProc
= WindowProc
;
3789 WndProcHandlesArray
[FreeSpot
].IsUnicode
= IsUnicode
;
3790 WndProcHandlesArray
[FreeSpot
].ProcessID
= PsGetCurrentProcessId();
3791 return FreeSpot
+ 0xFFFF0000;
3795 IntRemoveWndProcHandle(WNDPROC Handle
)
3798 position
= (DWORD
)Handle
& 0x0000FFFF;
3799 if (position
> WndProcHandlesArraySize
)
3803 WndProcHandlesArray
[position
].WindowProc
= NULL
;
3804 WndProcHandlesArray
[position
].IsUnicode
= FALSE
;
3805 WndProcHandlesArray
[position
].ProcessID
= NULL
;
3810 IntRemoveProcessWndProcHandles(HANDLE ProcessID
)
3813 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
3815 if (WndProcHandlesArray
[i
].ProcessID
== ProcessID
)
3817 WndProcHandlesArray
[i
].WindowProc
= NULL
;
3818 WndProcHandlesArray
[i
].IsUnicode
= FALSE
;
3819 WndProcHandlesArray
[i
].ProcessID
= NULL
;