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.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
23 * FILE: subsys/win32k/ntuser/window.c
24 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 06-06-2001 CSH Created
29 /* INCLUDES ******************************************************************/
36 static WndProcHandle
*WndProcHandlesArray
= 0;
37 static WORD WndProcHandlesArraySize
= 0;
38 #define WPH_SIZE 0x40 /* the size to add to the WndProcHandle array each time */
40 /* dialog resources appear to pass this in 16 bits, handle them properly */
41 #define CW_USEDEFAULT16 (0x8000)
43 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
45 /* PRIVATE FUNCTIONS **********************************************************/
50 * Initialize windowing implementation.
56 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,WPH_SIZE
* sizeof(WndProcHandle
), TAG_WINPROCLST
);
57 WndProcHandlesArraySize
= WPH_SIZE
;
58 return STATUS_SUCCESS
;
64 * Cleanup windowing implementation.
68 CleanupWindowImpl(VOID
)
70 ExFreePool(WndProcHandlesArray
);
71 WndProcHandlesArray
= 0;
72 WndProcHandlesArraySize
= 0;
73 return STATUS_SUCCESS
;
76 /* HELPER FUNCTIONS ***********************************************************/
79 PWINDOW_OBJECT FASTCALL
IntGetWindowObject(HWND hWnd
)
81 PWINDOW_OBJECT Window
;
83 if (!hWnd
) return NULL
;
85 Window
= UserGetWindowObject(hWnd
);
88 ASSERT(USER_BODY_TO_HEADER(Window
)->RefCount
>= 0);
90 USER_BODY_TO_HEADER(Window
)->RefCount
++;
96 PWINDOW_OBJECT FASTCALL
UserGetWindowObject(HWND hWnd
)
98 PWINDOW_OBJECT Window
;
102 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
106 Window
= (PWINDOW_OBJECT
)UserGetObject(&gHandleTable
, hWnd
, otWindow
);
107 if (!Window
|| 0 != (Window
->Status
& WINDOWSTATUS_DESTROYED
))
109 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
113 ASSERT(USER_BODY_TO_HEADER(Window
)->RefCount
>= 0);
121 * The function determines whether the specified window handle identifies
122 * an existing window.
126 * Handle to the window to test.
129 * If the window handle identifies an existing window, the return value
130 * is TRUE. If the window handle does not identify an existing window,
131 * the return value is FALSE.
135 IntIsWindow(HWND hWnd
)
137 PWINDOW_OBJECT Window
;
139 if (!(Window
= UserGetWindowObject(hWnd
)))
148 Caller must NOT dereference retval!
149 But if caller want the returned value to persist spanning a co_ call,
150 it must reference the value (because the owner is not garanteed to
151 exist just because the owned window exist)!
153 PWINDOW_OBJECT FASTCALL
154 IntGetParent(PWINDOW_OBJECT Wnd
)
156 if (Wnd
->Style
& WS_POPUP
)
158 return UserGetWindowObject(Wnd
->hOwner
);
160 else if (Wnd
->Style
& WS_CHILD
)
170 Caller must NOT dereference retval!
171 But if caller want the returned value to persist spanning a co_ call,
172 it must reference the value (because the owner is not garanteed to
173 exist just because the owned window exist)!
175 PWINDOW_OBJECT FASTCALL
176 IntGetOwner(PWINDOW_OBJECT Wnd
)
178 return UserGetWindowObject(Wnd
->hOwner
);
186 * Compile a list of all child window handles from given window.
189 * This function is similar to Wine WIN_ListChildren. The caller
190 * must free the returned list with ExFreePool.
194 IntWinListChildren(PWINDOW_OBJECT Window
)
196 PWINDOW_OBJECT Child
;
198 UINT Index
, NumChildren
= 0;
200 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
203 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
206 DPRINT1("Failed to allocate memory for children array\n");
207 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
210 for (Child
= Window
->FirstChild
, Index
= 0;
212 Child
= Child
->NextSibling
, ++Index
)
213 List
[Index
] = Child
->hSelf
;
219 /***********************************************************************
222 static void IntSendDestroyMsg(HWND hWnd
)
225 PWINDOW_OBJECT Window
;
230 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
232 if (hWnd
== info
.hwndCaret
)
239 Window
= UserGetWindowObject(hWnd
);
242 // UserRefObjectCo(Window);
244 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
246 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
249 // UserDerefObjectCo(Window);
252 /* The window could already be destroyed here */
255 * Send the WM_DESTROY to the window.
258 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
261 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
262 * make sure that the window still exists when we come back.
271 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
274 /* start from the end (FIXME: is this needed?) */
275 for (i
= 0; pWndArray
[i
]; i
++)
280 if (IsWindow( pWndArray
[i
] ))
281 WIN_SendDestroyMsg( pWndArray
[i
] );
283 HeapFree(GetProcessHeap(), 0, pWndArray
);
287 DPRINT("destroyed itself while in WM_DESTROY!\n");
292 /***********************************************************************
295 * Destroy storage associated to a window. "Internals" p.358
297 * This is the "functional" DestroyWindows function ei. all stuff
298 * done in CreateWindow is undone here and not in DestroyWindow:-P
301 static LRESULT
co_UserFreeWindow(PWINDOW_OBJECT Window
,
302 PW32PROCESS ProcessData
,
303 PW32THREAD ThreadData
,
304 BOOLEAN SendMessages
)
308 PWINDOW_OBJECT Child
;
310 BOOLEAN BelongsToThreadData
;
314 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
316 DPRINT("Tried to call IntDestroyWindow() twice\n");
319 Window
->Status
|= WINDOWSTATUS_DESTROYING
;
320 Window
->Style
&= ~WS_VISIBLE
;
321 /* remove the window already at this point from the thread window list so we
322 don't get into trouble when destroying the thread windows while we're still
323 in IntDestroyWindow() */
324 RemoveEntryList(&Window
->ThreadListEntry
);
326 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
328 IntDeRegisterShellHookWindow(Window
->hSelf
);
332 /* Send destroy messages */
333 IntSendDestroyMsg(Window
->hSelf
);
336 /* free child windows */
337 Children
= IntWinListChildren(Window
);
340 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
342 if ((Child
= IntGetWindowObject(*ChildHandle
)))
344 if(!IntWndBelongsToThread(Child
, ThreadData
))
346 /* send WM_DESTROY messages to windows not belonging to the same thread */
347 IntSendDestroyMsg(Child
->hSelf
);
350 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
352 UserDerefObject(Child
);
355 ExFreePool(Children
);
361 * Clear the update region to make sure no WM_PAINT messages will be
362 * generated for this window while processing the WM_NCDESTROY.
364 co_UserRedrawWindow(Window
, NULL
, 0,
365 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
366 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
367 if(BelongsToThreadData
)
368 co_IntSendMessage(Window
->hSelf
, WM_NCDESTROY
, 0, 0);
370 MsqRemoveTimersWindow(ThreadData
->MessageQueue
, Window
->hSelf
);
372 /* flush the message queue */
373 MsqRemoveWindowMessagesFromQueue(Window
);
375 /* from now on no messages can be sent to this window anymore */
376 Window
->Status
|= WINDOWSTATUS_DESTROYED
;
377 /* don't remove the WINDOWSTATUS_DESTROYING bit */
379 /* reset shell window handles */
380 if(ThreadData
->Desktop
)
382 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellWindow
)
383 ThreadData
->Desktop
->WindowStation
->ShellWindow
= NULL
;
385 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellListView
)
386 ThreadData
->Desktop
->WindowStation
->ShellListView
= NULL
;
389 /* Unregister hot keys */
390 UnregisterWindowHotKeys (Window
);
392 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
396 WinPosCheckInternalPos(Window
->hSelf
);
397 if (Window
->hSelf
== GetCapture())
402 /* free resources associated with the window */
403 TIMER_RemoveWindowTimers(Window
->hSelf
);
406 if (!(Window
->Style
& WS_CHILD
) && Window
->IDMenu
407 && (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
409 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
413 if(Window
->SystemMenu
414 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
416 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
417 Window
->SystemMenu
= (HMENU
)0;
420 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
423 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
424 CLASS_RemoveWindow(Window
->Class
);
427 IntUnlinkWindow(Window
);
429 UserRefObject(Window
);
430 ObmDeleteObject(Window
->hSelf
, otWindow
);
432 IntDestroyScrollBars(Window
);
434 /* dereference the class */
435 ClassDerefObject(Window
->Class
);
436 Window
->Class
= NULL
;
438 if(Window
->WindowRegion
)
440 NtGdiDeleteObject(Window
->WindowRegion
);
443 RtlFreeUnicodeString(&Window
->WindowName
);
445 UserDerefObject(Window
);
451 IntGetWindowBorderMeasures(PWINDOW_OBJECT Window
, UINT
*cx
, UINT
*cy
)
453 if(HAS_DLGFRAME(Window
->Style
, Window
->ExStyle
) && !(Window
->Style
& WS_MINIMIZE
))
455 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
456 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
460 if(HAS_THICKFRAME(Window
->Style
, Window
->ExStyle
)&& !(Window
->Style
& WS_MINIMIZE
))
462 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
463 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
465 else if(HAS_THINFRAME(Window
->Style
, Window
->ExStyle
))
467 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
468 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
478 IntGetWindowInfo(PWINDOW_OBJECT Window
, PWINDOWINFO pwi
)
480 pwi
->cbSize
= sizeof(WINDOWINFO
);
481 pwi
->rcWindow
= Window
->WindowRect
;
482 pwi
->rcClient
= Window
->ClientRect
;
483 pwi
->dwStyle
= Window
->Style
;
484 pwi
->dwExStyle
= Window
->ExStyle
;
485 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Window
->hSelf
); /* WS_ACTIVECAPTION */
486 IntGetWindowBorderMeasures(Window
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
487 pwi
->atomWindowType
= (Window
->Class
? Window
->Class
->Atom
: 0);
488 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
494 PWINDOW_OBJECT Window
,
498 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
500 if ((Window
->Style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
502 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
506 *Changed
= (Window
->IDMenu
!= (UINT
) Menu
);
514 OldMenu
= IntGetMenuObject((HMENU
) Window
->IDMenu
);
515 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Window
->hSelf
);
524 NewMenu
= IntGetMenuObject(Menu
);
529 IntReleaseMenuObject(OldMenu
);
531 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
534 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
536 /* Can't use the same menu for two windows */
539 IntReleaseMenuObject(OldMenu
);
541 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
547 Window
->IDMenu
= (UINT
) Menu
;
550 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
551 IntReleaseMenuObject(NewMenu
);
555 OldMenu
->MenuInfo
.Wnd
= NULL
;
556 IntReleaseMenuObject(OldMenu
);
563 /* INTERNAL ******************************************************************/
567 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
573 WThread
= Thread
->Tcb
.Win32Thread
;
575 while (!IsListEmpty(&WThread
->WindowListHead
))
577 Current
= WThread
->WindowListHead
.Flink
;
578 Wnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
580 DPRINT1("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
582 /* window removes itself from the list */
585 fixme: it is critical that the window removes itself! if now, we will loop
589 //ASSERT(co_UserDestroyWindow(Wnd));
591 UserRefObjectCo(Wnd
);//faxme: temp hack??
592 if (!co_UserDestroyWindow(Wnd
))
594 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
596 UserDerefObjectCo(Wnd
);//faxme: temp hack??
604 * Returns client window rectangle relative to the upper-left corner of client area.
606 * \note Does not check the validity of the parameters
609 IntGetClientRect(PWINDOW_OBJECT Window
, PRECT Rect
)
614 Rect
->left
= Rect
->top
= 0;
615 Rect
->right
= Window
->ClientRect
.right
- Window
->ClientRect
.left
;
616 Rect
->bottom
= Window
->ClientRect
.bottom
- Window
->ClientRect
.top
;
622 IntGetFocusWindow(VOID
)
624 PUSER_MESSAGE_QUEUE Queue
;
625 PDESKTOP_OBJECT pdo
= IntGetActiveDesktop();
630 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
635 return(Queue
->FocusWindow
);
639 PMENU_OBJECT FASTCALL
640 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
)
642 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
643 PW32THREAD W32Thread
;
644 HMENU hNewMenu
, hSysMenu
;
645 ROSMENUITEMINFO ItemInfo
;
649 W32Thread
= PsGetWin32Thread();
651 if(!W32Thread
->Desktop
)
654 if(Window
->SystemMenu
)
656 Menu
= UserGetMenuObject(Window
->SystemMenu
);
659 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
660 Window
->SystemMenu
= (HMENU
)0;
664 if(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
)
666 /* clone system menu */
667 Menu
= UserGetMenuObject(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
);
671 NewMenu
= IntCloneMenu(Menu
);
674 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
675 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
676 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
678 //IntReleaseMenuObject(NewMenu);
683 hSysMenu
= UserCreateMenu(FALSE
);
684 if (NULL
== hSysMenu
)
688 SysMenu
= IntGetMenuObject(hSysMenu
);
691 UserDestroyMenu(hSysMenu
);
694 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
695 SysMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
696 hNewMenu
= co_IntLoadSysMenuTemplate();
699 IntReleaseMenuObject(SysMenu
);
700 UserDestroyMenu(hSysMenu
);
703 Menu
= IntGetMenuObject(hNewMenu
);
706 IntReleaseMenuObject(SysMenu
);
707 UserDestroyMenu(hSysMenu
);
711 NewMenu
= IntCloneMenu(Menu
);
714 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
715 IntReleaseMenuObject(NewMenu
);
716 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
718 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
719 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
720 ItemInfo
.fType
= MF_POPUP
;
721 ItemInfo
.fState
= MFS_ENABLED
;
722 ItemInfo
.dwTypeData
= NULL
;
724 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
725 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
727 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
731 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
732 IntReleaseMenuObject(Menu
);
741 if(Window
->SystemMenu
)
742 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
750 IntIsChildWindow(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT BaseWindow
)
752 PWINDOW_OBJECT Window
;
757 if (Window
== Parent
)
761 if(!(Window
->Style
& WS_CHILD
))
766 Window
= Window
->Parent
;
773 IntIsWindowVisible(PWINDOW_OBJECT BaseWindow
)
775 PWINDOW_OBJECT Window
;
780 if(!(Window
->Style
& WS_CHILD
))
784 if(!(Window
->Style
& WS_VISIBLE
))
789 Window
= Window
->Parent
;
792 if(Window
&& Window
->Style
& WS_VISIBLE
)
801 /* link the window into siblings and parent. children are kept in place. */
805 PWINDOW_OBJECT WndParent
,
806 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
809 PWINDOW_OBJECT Parent
;
811 Wnd
->Parent
= WndParent
;
812 if ((Wnd
->PrevSibling
= WndPrevSibling
))
814 /* link after WndPrevSibling */
815 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
816 Wnd
->NextSibling
->PrevSibling
= Wnd
;
817 else if ((Parent
= Wnd
->Parent
))
819 if(Parent
->LastChild
== WndPrevSibling
)
820 Parent
->LastChild
= Wnd
;
822 Wnd
->PrevSibling
->NextSibling
= Wnd
;
827 Parent
= Wnd
->Parent
;
828 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
829 Wnd
->NextSibling
->PrevSibling
= Wnd
;
832 Parent
->LastChild
= Wnd
;
833 Parent
->FirstChild
= Wnd
;
838 Parent
->FirstChild
= Wnd
;
845 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
847 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
850 Wnd
= IntGetWindowObject(hWnd
);
854 WndOldOwner
= IntGetWindowObject(Wnd
->hOwner
);
857 ret
= WndOldOwner
->hSelf
;
858 UserDerefObject(WndOldOwner
);
865 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
867 Wnd
->hOwner
= hWndNewOwner
;
872 UserDerefObject(Wnd
);
876 PWINDOW_OBJECT FASTCALL
877 co_IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
879 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
880 // HWND hWnd, hWndNewParent;
884 ASSERT(WndNewParent
);
886 ASSERT_REFS_CO(WndNewParent
);
888 // hWnd = Wnd->hSelf;
889 // hWndNewParent = WndNewParent->hSelf;
892 * Windows hides the window first, then shows it again
893 * including the WM_SHOWWINDOW messages and all
895 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
897 // /* Validate that window and parent still exist */
898 // if (!IntIsWindow(hWnd) || !IntIsWindow(hWndNewParent))
901 /* Window must belong to current process */
902 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
905 WndOldParent
= Wnd
->Parent
;
907 if (WndOldParent
) UserRefObject(WndOldParent
); /* caller must deref */
909 if (WndNewParent
!= WndOldParent
)
911 IntUnlinkWindow(Wnd
);
913 if (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
))
915 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
916 Sibling
= WndNewParent
->FirstChild
;
917 while (NULL
!= Sibling
&& 0 != (Sibling
->ExStyle
& WS_EX_TOPMOST
))
919 InsertAfter
= Sibling
;
920 Sibling
= Sibling
->NextSibling
;
923 if (NULL
== InsertAfter
)
925 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
929 // UserRefObject(InsertAfter);
930 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
931 // UserDerefObject(InsertAfter);
936 * SetParent additionally needs to make hwnd the top window
937 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
938 * WM_WINDOWPOSCHANGED notification messages.
940 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
941 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
942 | (WasVisible
? SWP_SHOWWINDOW
: 0));
945 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
946 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
950 * Validate that the old parent still exist, since it migth have been
951 * destroyed during the last callbacks to user-mode
955 // if(!IntIsWindow(WndOldParent->hSelf))
957 // UserDerefObject(WndOldParent);
961 /* don't dereference the window object here, it must be done by the caller
963 // return WndOldParent;
966 return WndOldParent
;//NULL;
970 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
972 PMENU_OBJECT OldMenu
;
973 if(Window
->SystemMenu
)
975 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
978 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
979 IntReleaseMenuObject(OldMenu
);
985 /* FIXME check window style, propably return FALSE ? */
986 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
987 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
990 Window
->SystemMenu
= (HMENU
)0;
996 /* unlink the window from siblings and parent. children are kept in place. */
998 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1000 PWINDOW_OBJECT WndParent
= Wnd
->Parent
;
1002 if (Wnd
->NextSibling
)
1003 Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1004 else if (WndParent
&& WndParent
->LastChild
== Wnd
)
1005 WndParent
->LastChild
= Wnd
->PrevSibling
;
1007 if (Wnd
->PrevSibling
)
1008 Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1009 else if (WndParent
&& WndParent
->FirstChild
== Wnd
)
1010 WndParent
->FirstChild
= Wnd
->NextSibling
;
1012 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1018 PWINDOW_OBJECT Window
, Child
;
1020 if(!(Window
= UserGetWindowObject(IntGetDesktopWindow())))
1025 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1027 if(Child
->hOwner
&& Child
->Style
& WS_VISIBLE
)
1030 * The desktop has a popup window if one of them has
1031 * an owner window and is visible
1041 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1043 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1046 /* FUNCTIONS *****************************************************************/
1052 NtUserAlterWindowStyle(DWORD Unknown0
,
1063 * As best as I can figure, this function is used by EnumWindows,
1064 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1066 * It's supposed to build a list of HWNDs to return to the caller.
1067 * We can figure out what kind of list by what parameters are
1075 NtUserBuildHwndList(
1087 /* FIXME handle bChildren */
1091 PWINDOW_OBJECT Window
, Child
;
1092 if(!(Window
= UserGetWindowObject(hwndParent
)))
1097 for(Child
= Window
->FirstChild
; Child
!= NULL
; Child
= Child
->NextSibling
)
1099 if(dwCount
++ < nBufSize
&& pWnd
)
1101 Status
= MmCopyToCaller(pWnd
++, &Child
->hSelf
, sizeof(HWND
));
1102 if(!NT_SUCCESS(Status
))
1104 SetLastNtError(Status
);
1113 PW32THREAD W32Thread
;
1114 PLIST_ENTRY Current
;
1115 PWINDOW_OBJECT Window
;
1117 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1118 if(!NT_SUCCESS(Status
))
1120 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1123 if(!(W32Thread
= Thread
->Tcb
.Win32Thread
))
1125 ObDereferenceObject(Thread
);
1126 DPRINT("Thread is not a GUI Thread!\n");
1127 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1131 Current
= W32Thread
->WindowListHead
.Flink
;
1132 while(Current
!= &(W32Thread
->WindowListHead
))
1134 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1137 if(dwCount
< nBufSize
&& pWnd
)
1139 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1140 if(!NT_SUCCESS(Status
))
1142 SetLastNtError(Status
);
1147 Current
= Current
->Flink
;
1150 ObDereferenceObject(Thread
);
1154 PDESKTOP_OBJECT Desktop
;
1155 PWINDOW_OBJECT Window
, Child
;
1157 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1159 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1165 Status
= IntValidateDesktopHandle(hDesktop
,
1169 if(!NT_SUCCESS(Status
))
1171 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1175 if(!(Window
= UserGetWindowObject(Desktop
->DesktopWindow
)))
1177 if(hDesktop
) ObDereferenceObject(Desktop
);
1181 for(Child
= Window
->FirstChild
; Child
!= NULL
; Child
= Child
->NextSibling
)
1183 if(dwCount
++ < nBufSize
&& pWnd
)
1185 Status
= MmCopyToCaller(pWnd
++, &Child
->hSelf
, sizeof(HWND
));
1186 if(!NT_SUCCESS(Status
))
1188 SetLastNtError(Status
);
1194 if(hDesktop
) ObDereferenceObject(Desktop
);
1205 NtUserChildWindowFromPointEx(HWND hwndParent
,
1210 PWINDOW_OBJECT Parent
;
1215 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1223 if(Parent
->hSelf
!= IntGetDesktopWindow())
1225 Pt
.x
+= Parent
->ClientRect
.left
;
1226 Pt
.y
+= Parent
->ClientRect
.top
;
1229 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1234 Ret
= Parent
->hSelf
;
1235 if((List
= IntWinListChildren(Parent
)))
1237 for(phWnd
= List
; *phWnd
; phWnd
++)
1239 PWINDOW_OBJECT Child
;
1240 if((Child
= UserGetWindowObject(*phWnd
)))
1242 if(!(Child
->Style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1246 if((Child
->Style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1250 if((Child
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1254 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1269 * calculates the default position of a window
1272 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT Window
, RECT
*rc
, BOOL IncPos
)
1279 IntGdiIntersectRect(rc
, rc
, &Parent
->ClientRect
);
1283 Pos
.x
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1284 Pos
.y
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1285 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1286 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1288 /* reset counter and position */
1291 Parent
->TiledCounter
= 0;
1293 Parent
->TiledCounter
++;
1304 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1305 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1309 rc
->right
= rc
->left
+ Sz
.cx
;
1310 rc
->bottom
= rc
->top
+ Sz
.cy
;
1319 co_IntCreateWindowEx(DWORD dwExStyle
,
1320 PUNICODE_STRING ClassName
,
1321 PUNICODE_STRING WindowName
,
1329 HINSTANCE hInstance
,
1332 BOOL bUnicodeWindow
)
1334 PWINSTATION_OBJECT WinSta
;
1335 PWNDCLASS_OBJECT Class
= NULL
;
1336 PWINDOW_OBJECT Window
= NULL
;
1337 PWINDOW_OBJECT ParentWindow
= NULL
, OwnerWindow
;
1338 HWND ParentWindowHandle
;
1339 HWND OwnerWindowHandle
;
1340 PMENU_OBJECT SystemMenu
;
1346 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1353 CBT_CREATEWNDW CbtCreate
;
1356 DECLARE_RETURN(HWND
);
1359 ParentWindowHandle
= PsGetWin32Thread()->Desktop
->DesktopWindow
;
1360 OwnerWindowHandle
= NULL
;
1362 if (hWndParent
== HWND_MESSAGE
)
1365 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1366 * message window (style: WS_POPUP|WS_DISABLED)
1368 DPRINT1("FIXME - Parent is HWND_MESSAGE\n");
1370 else if (hWndParent
)
1372 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1373 ParentWindowHandle
= hWndParent
;
1377 PWINDOW_OBJECT Par
= UserGetWindowObject(hWndParent
), Root
;
1378 if (Par
&& (Root
= UserGetAncestor(Par
, GA_ROOT
)))
1379 OwnerWindowHandle
= Root
->hSelf
;
1382 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1384 RETURN( (HWND
)0); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1387 // if (NULL != ParentWindowHandle)
1389 ParentWindow
= UserGetWindowObject(ParentWindowHandle
);
1391 if (ParentWindow
) UserRefObjectCo(ParentWindow
);
1395 // ParentWindow = NULL;
1398 /* FIXME: parent must belong to the current process */
1400 /* Check the class. */
1401 Class
= ClassGetClassByNameOrAtom(ClassName
->Buffer
, hInstance
);
1404 if (IS_ATOM(ClassName
->Buffer
))
1406 DPRINT1("Class 0x%x not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1410 DPRINT1("Class %wZ not found\n", ClassName
);
1413 SetLastWin32Error(ERROR_CANNOT_FIND_WND_CLASS
);
1417 ClassRefObject(Class
);
1419 /* Check the window station. */
1420 if (PsGetWin32Thread()->Desktop
== NULL
)
1422 DPRINT("Thread is not attached to a desktop! Cannot create window!\n");
1425 WinSta
= PsGetWin32Thread()->Desktop
->WindowStation
;
1427 //FIXME: Reference thread/desktop instead
1428 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1430 /* Create the window object. */
1431 Window
= (PWINDOW_OBJECT
)
1432 ObmCreateObject(&gHandleTable
, (PHANDLE
)&hWnd
,
1433 otWindow
, sizeof(WINDOW_OBJECT
) + Class
->cbWndExtra
1436 DPRINT("Created object with handle %X\n", hWnd
);
1439 ObDereferenceObject(WinSta
);
1440 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1444 UserRefObjectCo(Window
);
1446 ObDereferenceObject(WinSta
);
1448 if (NULL
== PsGetWin32Thread()->Desktop
->DesktopWindow
)
1450 /* If there is no desktop window yet, we must be creating it */
1451 PsGetWin32Thread()->Desktop
->DesktopWindow
= hWnd
;
1455 * Fill out the structure describing it.
1457 Window
->Class
= Class
;
1458 Window
->SystemMenu
= (HMENU
)0;
1459 Window
->ContextHelpId
= 0;
1461 Window
->Instance
= hInstance
;
1462 Window
->hSelf
= hWnd
;
1463 if (0 != (dwStyle
& WS_CHILD
))
1465 Window
->IDMenu
= (UINT
) hMenu
;
1469 IntSetMenu(Window
, hMenu
, &MenuChanged
);
1472 Window
->MessageQueue
= PsGetWin32Thread()->MessageQueue
;
1473 IntReferenceMessageQueue(Window
->MessageQueue
);
1474 Window
->Parent
= ParentWindow
;
1476 if((OwnerWindow
= UserGetWindowObject(OwnerWindowHandle
)))
1478 Window
->hOwner
= OwnerWindowHandle
;
1483 Window
->hOwner
= NULL
;
1487 Window
->UserData
= 0;
1489 if ((((DWORD
)Class
->lpfnWndProcA
& 0xFFFF0000) != 0xFFFF0000)
1490 && (((DWORD
)Class
->lpfnWndProcW
& 0xFFFF0000) != 0xFFFF0000))
1492 Window
->Unicode
= bUnicodeWindow
;
1496 Window
->Unicode
= Class
->Unicode
;
1498 Window
->WndProcA
= Class
->lpfnWndProcA
;
1499 Window
->WndProcW
= Class
->lpfnWndProcW
;
1500 Window
->OwnerThread
= PsGetCurrentThread();
1501 Window
->FirstChild
= NULL
;
1502 Window
->LastChild
= NULL
;
1503 Window
->PrevSibling
= NULL
;
1504 Window
->NextSibling
= NULL
;
1505 Window
->ExtraDataSize
= Class
->cbWndExtra
;
1507 /* extra window data */
1508 if (Class
->cbWndExtra
)
1509 Window
->ExtraData
= (PCHAR
)(Window
+ 1);
1511 InitializeListHead(&Window
->PropListHead
);
1512 InitializeListHead(&Window
->WndObjListHead
);
1514 if (NULL
!= WindowName
->Buffer
)
1516 Window
->WindowName
.MaximumLength
= WindowName
->MaximumLength
;
1517 Window
->WindowName
.Length
= WindowName
->Length
;
1518 Window
->WindowName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, WindowName
->MaximumLength
,
1520 if (NULL
== Window
->WindowName
.Buffer
)
1522 DPRINT1("Failed to allocate mem for window name\n");
1523 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1526 RtlCopyMemory(Window
->WindowName
.Buffer
, WindowName
->Buffer
, WindowName
->MaximumLength
);
1530 RtlInitUnicodeString(&Window
->WindowName
, NULL
);
1535 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1536 * tested for WS_POPUP
1538 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1539 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1540 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1541 dwExStyle
|= WS_EX_WINDOWEDGE
;
1543 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1545 /* Correct the window style. */
1546 if (!(dwStyle
& WS_CHILD
))
1548 dwStyle
|= WS_CLIPSIBLINGS
;
1549 DPRINT("3: Style is now %lx\n", dwStyle
);
1550 if (!(dwStyle
& WS_POPUP
))
1552 dwStyle
|= WS_CAPTION
;
1553 Window
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1554 DPRINT("4: Style is now %lx\n", dwStyle
);
1558 /* create system menu */
1559 if((dwStyle
& WS_SYSMENU
) &&
1560 (dwStyle
& WS_CAPTION
) == WS_CAPTION
)
1562 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
1565 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1566 IntReleaseMenuObject(SystemMenu
);
1570 /* Insert the window into the thread's window list. */
1571 InsertTailList (&PsGetWin32Thread()->WindowListHead
, &Window
->ThreadListEntry
);
1573 /* Allocate a DCE for this window. */
1574 if (dwStyle
& CS_OWNDC
)
1576 Window
->Dce
= DceAllocDCE(Window
, DCE_WINDOW_DC
);
1578 /* FIXME: Handle "CS_CLASSDC" */
1585 Window
->ExStyle
= dwExStyle
;
1586 Window
->Style
= dwStyle
& ~WS_VISIBLE
;
1589 Cs
.lpCreateParams
= lpParam
;
1590 Cs
.hInstance
= hInstance
;
1592 Cs
.hwndParent
= ParentWindowHandle
;
1597 Cs
.style
= Window
->Style
;
1598 Cs
.lpszName
= (LPCWSTR
) WindowName
;
1599 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
1600 Cs
.dwExStyle
= dwExStyle
;
1601 CbtCreate
.lpcs
= &Cs
;
1602 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1603 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) &CbtCreate
))
1605 /* FIXME - Delete window object and remove it from the thread windows list */
1606 /* FIXME - delete allocated DCE */
1607 DPRINT1("CBT-hook returned !0\n");
1608 RETURN( (HWND
) NULL
);
1616 /* default positioning for overlapped windows */
1617 if(!(Window
->Style
& (WS_POPUP
| WS_CHILD
)))
1620 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1621 BOOL CalculatedDefPosSize
= FALSE
;
1623 IntGetDesktopWorkArea(Window
->OwnerThread
->Tcb
.Win32Thread
->Desktop
, &WorkArea
);
1626 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1628 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1630 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, Window
, &rc
, TRUE
);
1632 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1634 ProcessParams
->WindowFlags
&= ~STARTF_USEPOSITION
;
1635 Pos
.x
= WorkArea
.left
+ ProcessParams
->StartingX
;
1636 Pos
.y
= WorkArea
.top
+ ProcessParams
->StartingY
;
1644 /* According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
1645 y is something else */
1646 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
1651 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1653 if(!CalculatedDefPosSize
)
1655 IntCalcDefPosSize(ParentWindow
, Window
, &rc
, FALSE
);
1657 if(ProcessParams
->WindowFlags
& STARTF_USESIZE
)
1659 ProcessParams
->WindowFlags
&= ~STARTF_USESIZE
;
1660 Size
.cx
= ProcessParams
->CountX
;
1661 Size
.cy
= ProcessParams
->CountY
;
1665 Size
.cx
= rc
.right
- rc
.left
;
1666 Size
.cy
= rc
.bottom
- rc
.top
;
1669 /* move the window if necessary */
1671 Pos
.x
= max(rc
.left
, 0);
1673 Pos
.y
= max(rc
.top
, 0);
1678 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
1679 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1684 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1691 /* Initialize the window dimensions. */
1692 Window
->WindowRect
.left
= Pos
.x
;
1693 Window
->WindowRect
.top
= Pos
.y
;
1694 Window
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1695 Window
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1696 if (0 != (Window
->Style
& WS_CHILD
) && ParentWindow
)
1698 IntGdiOffsetRect(&(Window
->WindowRect
), ParentWindow
->ClientRect
.left
,
1699 ParentWindow
->ClientRect
.top
);
1701 Window
->ClientRect
= Window
->WindowRect
;
1704 * Get the size and position of the window.
1706 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
1708 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1710 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
1711 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
,
1713 if (MaxSize
.x
< nWidth
)
1715 if (MaxSize
.y
< nHeight
)
1716 nHeight
= MaxSize
.y
;
1717 if (nWidth
< MinTrack
.x
)
1718 nWidth
= MinTrack
.x
;
1719 if (nHeight
< MinTrack
.y
)
1720 nHeight
= MinTrack
.y
;
1727 Window
->WindowRect
.left
= Pos
.x
;
1728 Window
->WindowRect
.top
= Pos
.y
;
1729 Window
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1730 Window
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1731 if (0 != (Window
->Style
& WS_CHILD
) && ParentWindow
)
1733 IntGdiOffsetRect(&(Window
->WindowRect
), ParentWindow
->ClientRect
.left
,
1734 ParentWindow
->ClientRect
.top
);
1736 Window
->ClientRect
= Window
->WindowRect
;
1738 /* FIXME: Initialize the window menu. */
1740 /* Send a NCCREATE message. */
1746 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
1747 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1748 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
1749 Result
= co_IntSendMessage(Window
->hSelf
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
1752 /* FIXME: Cleanup. */
1753 DPRINT("IntCreateWindowEx(): NCCREATE message failed.\n");
1757 /* Calculate the non-client size. */
1758 MaxPos
.x
= Window
->WindowRect
.left
;
1759 MaxPos
.y
= Window
->WindowRect
.top
;
1760 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
1761 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
1762 Result
= co_WinPosGetNonClientSize(Window
,
1763 &Window
->WindowRect
,
1764 &Window
->ClientRect
);
1767 IntGdiOffsetRect(&Window
->WindowRect
,
1768 MaxPos
.x
- Window
->WindowRect
.left
,
1769 MaxPos
.y
- Window
->WindowRect
.top
);
1771 if (NULL
!= ParentWindow
)
1773 /* link the window into the parent's child list */
1774 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
1776 PWINDOW_OBJECT PrevSibling
;
1778 PrevSibling
= ParentWindow
->LastChild
;
1780 /* link window as bottom sibling */
1781 IntLinkWindow(Window
, ParentWindow
, PrevSibling
/*prev sibling*/);
1785 /* link window as top sibling (but after topmost siblings) */
1786 PWINDOW_OBJECT InsertAfter
, Sibling
;
1787 if (!(dwExStyle
& WS_EX_TOPMOST
))
1790 Sibling
= ParentWindow
->FirstChild
;
1791 while (Sibling
&& (Sibling
->ExStyle
& WS_EX_TOPMOST
))
1793 InsertAfter
= Sibling
;
1794 Sibling
= Sibling
->NextSibling
;
1802 IntLinkWindow(Window
, ParentWindow
, InsertAfter
/* prev sibling */);
1807 /* Send the WM_CREATE message. */
1808 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
1809 Result
= co_IntSendMessage(Window
->hSelf
, WM_CREATE
, 0, (LPARAM
) &Cs
);
1812 if (Result
== (LRESULT
)-1)
1814 /* FIXME: Cleanup. */
1815 DPRINT("IntCreateWindowEx(): send CREATE message failed.\n");
1820 /* Send move and size messages. */
1821 if (!(Window
->Flags
& WINDOWOBJECT_NEED_SIZE
))
1825 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
1827 if ((Window
->ClientRect
.right
- Window
->ClientRect
.left
) < 0 ||
1828 (Window
->ClientRect
.bottom
- Window
->ClientRect
.top
) < 0)
1830 DPRINT("Sending bogus WM_SIZE\n");
1834 lParam
= MAKE_LONG(Window
->ClientRect
.right
-
1835 Window
->ClientRect
.left
,
1836 Window
->ClientRect
.bottom
-
1837 Window
->ClientRect
.top
);
1838 co_IntSendMessage(Window
->hSelf
, WM_SIZE
, SIZE_RESTORED
,
1842 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
1844 if (0 != (Window
->Style
& WS_CHILD
) && ParentWindow
)
1846 lParam
= MAKE_LONG(Window
->ClientRect
.left
- ParentWindow
->ClientRect
.left
,
1847 Window
->ClientRect
.top
- ParentWindow
->ClientRect
.top
);
1851 lParam
= MAKE_LONG(Window
->ClientRect
.left
,
1852 Window
->ClientRect
.top
);
1856 co_IntSendMessage(Window
->hSelf
, WM_MOVE
, 0, lParam
);
1859 /* Call WNDOBJ change procs */
1860 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
1865 /* Show or maybe minimize or maximize the window. */
1866 if (Window
->Style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1871 SwFlag
= (Window
->Style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
1873 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
1875 ((Window
->Style
& WS_CHILD
) || UserGetActiveWindow()) ?
1876 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
1877 SWP_NOZORDER
| SWP_FRAMECHANGED
;
1878 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
1879 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
1880 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
1881 NewPos
.right
, NewPos
.bottom
, SwFlag
);
1884 /* Notify the parent window of a new child. */
1885 if ((Window
->Style
& WS_CHILD
) &&
1886 (!(Window
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
1888 DPRINT("IntCreateWindow(): About to notify parent\n");
1889 co_IntSendMessage(ParentWindow
->hSelf
,
1891 MAKEWPARAM(WM_CREATE
, Window
->IDMenu
),
1892 (LPARAM
)Window
->hSelf
);
1895 if ((!hWndParent
) && (!HasOwner
))
1897 DPRINT("Sending CREATED notify\n");
1898 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
1902 DPRINT("Not sending CREATED notify, %x %d\n", ParentWindow
, HasOwner
);
1905 /* Initialize and show the window's scrollbars */
1906 if (Window
->Style
& WS_VSCROLL
)
1908 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
1910 if (Window
->Style
& WS_HSCROLL
)
1912 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
1915 if (dwStyle
& WS_VISIBLE
)
1917 DPRINT("IntCreateWindow(): About to show window\n");
1918 co_WinPosShowWindow(Window
, dwShowMode
);
1921 DPRINT("IntCreateWindow(): = %X\n", hWnd
);
1922 DPRINT("WindowObject->SystemMenu = 0x%x\n", Window
->SystemMenu
);
1926 if (Window
) UserDerefObjectCo(Window
);
1927 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
1928 if (!_ret_
&& Class
) ClassDerefObject(Class
); /* only deref if failure (return 0) */
1933 NtUserCreateWindowEx(DWORD dwExStyle
,
1934 PUNICODE_STRING UnsafeClassName
,
1935 PUNICODE_STRING UnsafeWindowName
,
1943 HINSTANCE hInstance
,
1946 BOOL bUnicodeWindow
)
1949 UNICODE_STRING WindowName
;
1950 UNICODE_STRING ClassName
;
1952 DECLARE_RETURN(HWND
);
1954 DPRINT("Enter NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1955 UserEnterExclusive();
1957 /* Get the class name (string or atom) */
1958 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
1959 if (! NT_SUCCESS(Status
))
1961 SetLastNtError(Status
);
1964 if (! IS_ATOM(ClassName
.Buffer
))
1966 Status
= IntSafeCopyUnicodeStringTerminateNULL(&ClassName
, UnsafeClassName
);
1967 if (! NT_SUCCESS(Status
))
1969 SetLastNtError(Status
);
1974 /* safely copy the window name */
1975 if (NULL
!= UnsafeWindowName
)
1977 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
1978 if (! NT_SUCCESS(Status
))
1980 if (! IS_ATOM(ClassName
.Buffer
))
1982 RtlFreeUnicodeString(&ClassName
);
1984 SetLastNtError(Status
);
1990 RtlInitUnicodeString(&WindowName
, NULL
);
1993 NewWindow
= co_IntCreateWindowEx(dwExStyle
, &ClassName
, &WindowName
, dwStyle
, x
, y
, nWidth
, nHeight
,
1994 hWndParent
, hMenu
, hInstance
, lpParam
, dwShowMode
, bUnicodeWindow
);
1996 RtlFreeUnicodeString(&WindowName
);
1997 if (! IS_ATOM(ClassName
.Buffer
))
1999 RtlFreeUnicodeString(&ClassName
);
2005 DPRINT("Leave NtUserCreateWindowEx, ret=%i\n",_ret_
);
2014 NtUserDeferWindowPos(HDWP WinPosInfo
,
2016 HWND WndInsertAfter
,
2029 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2033 ASSERT_REFS_CO(Window
); //fixme: temp hack?
2035 /* Check for owner thread and desktop window */
2036 if ((Window
->OwnerThread
!= PsGetCurrentThread()) || IntIsDesktopWindow(Window
))
2038 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2042 /* Look whether the focus is within the tree of windows we will
2045 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2047 if (UserGetActiveWindow() == Window
->hSelf
)
2049 co_WinPosActivateOtherWindow(Window
);
2053 if (Window
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2054 Window
->MessageQueue
->ActiveWindow
= NULL
;
2055 if (Window
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2056 Window
->MessageQueue
->FocusWindow
= NULL
;
2057 if (Window
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2058 Window
->MessageQueue
->CaptureWindow
= NULL
;
2060 IntDereferenceMessageQueue(Window
->MessageQueue
);
2064 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hwnd
, 0, TRUE
))
2070 IntEngWindowChanged(Window
, WOC_DELETE
);
2071 isChild
= (0 != (Window
->Style
& WS_CHILD
));
2077 if (! USER_IsExitingThread(GetCurrentThreadId()))
2079 send_parent_notify(hwnd
, WM_DESTROY
);
2082 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2084 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2085 /* FIXME: clean up palette - see "Internals" p.352 */
2089 if (!IntIsWindow(Window
->hSelf
))
2094 /* Recursively destroy owned windows */
2099 BOOL GotOne
= FALSE
;
2102 PWINDOW_OBJECT Child
, Desktop
;
2104 Desktop
= UserGetWindowObject(IntGetDesktopWindow());
2105 Children
= IntWinListChildren(Desktop
);
2109 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2111 Child
= UserGetWindowObject(*ChildHandle
);
2114 if (Child
->hOwner
!= Window
->hSelf
)
2119 if (IntWndBelongsToThread(Child
, PsGetWin32Thread()))
2122 UserRefObjectCo(Child
);//temp hack?
2123 co_UserDestroyWindow(Child
);
2124 UserDerefObjectCo(Child
);//temp hack?
2130 if (Child
->hOwner
!= NULL
)
2132 Child
->hOwner
= NULL
;
2136 ExFreePool(Children
);
2145 if (!IntIsWindow(Window
->hSelf
))
2150 /* Destroy the window storage */
2151 co_UserFreeWindow(Window
, PsGetWin32Process(), PsGetWin32Thread(), TRUE
);
2163 NtUserDestroyWindow(HWND Wnd
)
2165 PWINDOW_OBJECT Window
;
2166 DECLARE_RETURN(BOOLEAN
);
2169 DPRINT("Enter NtUserDestroyWindow\n");
2170 UserEnterExclusive();
2172 if (!(Window
= UserGetWindowObject(Wnd
)))
2177 UserRefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2178 ret
= co_UserDestroyWindow(Window
);
2179 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2184 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2196 NtUserDrawMenuBarTemp(
2203 /* we'll use this function just for caching the menu bar */
2213 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2226 NtUserFillWindow(DWORD Unknown0
,
2238 IntFindWindow(PWINDOW_OBJECT Parent
,
2239 PWINDOW_OBJECT ChildAfter
,
2241 PUNICODE_STRING WindowName
)
2243 BOOL CheckWindowName
;
2249 CheckWindowName
= (WindowName
&& (WindowName
->Length
> 0));
2251 if((List
= IntWinListChildren(Parent
)))
2256 /* skip handles before and including ChildAfter */
2257 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2261 /* search children */
2264 PWINDOW_OBJECT Child
;
2265 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2270 /* Do not send WM_GETTEXT messages in the kernel mode version!
2271 The user mode version however calls GetWindowText() which will
2272 send WM_GETTEXT messages to windows belonging to its processes */
2273 if((!CheckWindowName
|| !RtlCompareUnicodeString(WindowName
, &(Child
->WindowName
), FALSE
)) &&
2274 (!ClassAtom
|| Child
->Class
->Atom
== ClassAtom
))
2289 * Searches a window's children for a window with the specified
2292 * hwndParent = The window whose childs are to be searched.
2294 * HWND_MESSAGE = message-only windows
2296 * hwndChildAfter = Search starts after this child window.
2297 * NULL = start from beginning
2299 * ucClassName = Class name to search for
2300 * Reguired parameter.
2302 * ucWindowName = Window name
2303 * ->Buffer == NULL = don't care
2306 * The HWND of the window if it was found, otherwise NULL
2312 NtUserFindWindowEx(HWND hwndParent
,
2313 HWND hwndChildAfter
,
2314 PUNICODE_STRING ucClassName
,
2315 PUNICODE_STRING ucWindowName
)
2317 PWINDOW_OBJECT Parent
, ChildAfter
;
2318 UNICODE_STRING ClassName
, WindowName
;
2320 HWND Desktop
, Ret
= NULL
;
2322 DECLARE_RETURN(HWND
);
2324 DPRINT("Enter NtUserFindWindowEx\n");
2327 Desktop
= IntGetCurrentThreadDesktopWindow();
2329 if(hwndParent
== NULL
)
2330 hwndParent
= Desktop
;
2332 else if(hwndParent == HWND_MESSAGE)
2334 hwndParent = IntGetMessageWindow();
2338 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2344 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2349 /* copy the window name */
2350 Status
= IntSafeCopyUnicodeString(&WindowName
, ucWindowName
);
2351 if(!NT_SUCCESS(Status
))
2353 SetLastNtError(Status
);
2357 /* safely copy the class name */
2358 Status
= MmCopyFromCaller(&ClassName
, ucClassName
, sizeof(UNICODE_STRING
));
2359 if(!NT_SUCCESS(Status
))
2361 SetLastNtError(Status
);
2364 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2367 /* safely copy the class name string (NULL terminated because class-lookup
2369 buf
= ExAllocatePoolWithTag(PagedPool
, ClassName
.Length
+ sizeof(WCHAR
), TAG_STRING
);
2372 SetLastWin32Error(STATUS_INSUFFICIENT_RESOURCES
);
2375 Status
= MmCopyFromCaller(buf
, ClassName
.Buffer
, ClassName
.Length
);
2376 if(!NT_SUCCESS(Status
))
2379 SetLastNtError(Status
);
2382 ClassName
.Buffer
= buf
;
2383 /* make sure the string is null-terminated */
2384 buf
+= ClassName
.Length
/ sizeof(WCHAR
);
2388 /* find the class object */
2389 if(ClassName
.Buffer
)
2391 PWINSTATION_OBJECT WinStaObject
;
2393 if (PsGetWin32Thread()->Desktop
== NULL
)
2395 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2399 WinStaObject
= PsGetWin32Thread()->Desktop
->WindowStation
;
2401 Status
= RtlLookupAtomInAtomTable(
2402 WinStaObject
->AtomTable
,
2406 if (!NT_SUCCESS(Status
))
2408 DPRINT1("Failed to lookup class atom!\n");
2409 SetLastWin32Error(ERROR_CLASS_DOES_NOT_EXIST
);
2414 if(Parent
->hSelf
== Desktop
)
2417 PWINDOW_OBJECT TopLevelWindow
;
2418 BOOLEAN CheckWindowName
;
2419 BOOLEAN CheckClassName
;
2420 BOOLEAN WindowMatches
;
2421 BOOLEAN ClassMatches
;
2423 /* windows searches through all top-level windows if the parent is the desktop
2426 if((List
= IntWinListChildren(Parent
)))
2432 /* skip handles before and including ChildAfter */
2433 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2437 CheckWindowName
= WindowName
.Length
> 0;
2438 CheckClassName
= ClassName
.Buffer
!= NULL
;
2440 /* search children */
2443 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2448 /* Do not send WM_GETTEXT messages in the kernel mode version!
2449 The user mode version however calls GetWindowText() which will
2450 send WM_GETTEXT messages to windows belonging to its processes */
2451 WindowMatches
= !CheckWindowName
|| !RtlCompareUnicodeString(
2452 &WindowName
, &TopLevelWindow
->WindowName
, FALSE
);
2453 ClassMatches
= !CheckClassName
||
2454 ClassAtom
== TopLevelWindow
->Class
->Atom
;
2456 if (WindowMatches
&& ClassMatches
)
2458 Ret
= TopLevelWindow
->hSelf
;
2462 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2464 /* window returns the handle of the top-level window, in case it found
2466 Ret
= TopLevelWindow
->hSelf
;
2475 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2479 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2481 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2482 search the message-only windows. Should this also be done if
2483 Parent is the desktop window??? */
2484 PWINDOW_OBJECT MsgWindows
;
2486 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2488 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2494 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2495 ExFreePool(ClassName
.Buffer
);
2498 RtlFreeUnicodeString(&WindowName
);
2505 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2515 NtUserFlashWindowEx(DWORD Unknown0
)
2526 PWINDOW_OBJECT FASTCALL
UserGetAncestor(PWINDOW_OBJECT Wnd
, UINT Type
)
2528 PWINDOW_OBJECT WndAncestor
, Parent
;
2530 if (Wnd
->hSelf
== IntGetDesktopWindow())
2539 WndAncestor
= Wnd
->Parent
;
2550 if(!(Parent
= WndAncestor
->Parent
))
2554 if(IntIsDesktopWindow(Parent
))
2559 WndAncestor
= Parent
;
2570 PWINDOW_OBJECT Parent
, Old
;
2573 Parent
= IntGetParent(WndAncestor
);
2581 // UserDerefObject(Parent);
2583 WndAncestor
= Parent
;
2603 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2605 PWINDOW_OBJECT Window
, Ancestor
;
2606 DECLARE_RETURN(HWND
);
2608 DPRINT("Enter NtUserGetAncestor\n");
2609 UserEnterExclusive();
2611 if (!(Window
= UserGetWindowObject(hWnd
)))
2616 Ancestor
= UserGetAncestor(Window
, Type
);
2617 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
2619 RETURN(Ancestor
? Ancestor
->hSelf
: NULL
);
2622 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
2628 * Returns client window rectangle relative to the upper-left corner of client area.
2630 * \param hWnd window handle.
2631 * \param Rect pointer to the buffer where the coordinates are returned.
2638 NtUserGetClientRect(HWND hWnd
, LPRECT Rect
)
2640 PWINDOW_OBJECT Window
;
2642 DECLARE_RETURN(BOOL
);
2644 DPRINT("Enter NtUserGetClientRect\n");
2647 if(!(Window
= UserGetWindowObject(hWnd
)))
2652 IntGetClientRect(Window
, &SafeRect
);
2654 if(!NT_SUCCESS(MmCopyToCaller(Rect
, &SafeRect
, sizeof(RECT
))))
2661 DPRINT("Leave NtUserGetClientRect, ret=%i\n",_ret_
);
2671 NtUserGetDesktopWindow()
2673 DECLARE_RETURN(HWND
);
2675 DPRINT("Enter NtUserGetDesktopWindow\n");
2678 RETURN( IntGetDesktopWindow());
2681 DPRINT("Leave NtUserGetDesktopWindow, ret=%i\n",_ret_
);
2691 NtUserGetInternalWindowPos(DWORD Unknown0
,
2705 NtUserGetLastActivePopup(HWND hWnd
)
2708 * This code can't work, because hWndLastPopup member of WINDOW_OBJECT is
2709 * not changed anywhere.
2710 * -- Filip, 01/nov/2003
2716 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2721 hWndLastPopup
= Wnd
->hWndLastPopup
;
2723 return hWndLastPopup
;
2733 * The NtUserGetParent function retrieves a handle to the specified window's
2737 * Note that, despite its name, this function can return an owner window
2738 * instead of a parent window.
2745 NtUserGetParent(HWND hWnd
)
2747 PWINDOW_OBJECT Wnd
, WndParent
;
2748 HWND hWndParent
= NULL
;
2749 DECLARE_RETURN(HWND
);
2751 DPRINT("Enter NtUserGetParent\n");
2752 UserEnterExclusive();
2754 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2759 WndParent
= IntGetParent(Wnd
);
2762 hWndParent
= WndParent
->hSelf
;
2765 RETURN( hWndParent
);
2768 DPRINT("Leave NtUserGetParent, ret=%i\n",_ret_
);
2777 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2779 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
2780 HWND hWndOldParent
= NULL
;
2782 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
2784 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2788 if (hWndChild
== IntGetDesktopWindow())
2790 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2796 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
2803 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
2809 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
2814 UserRefObjectCo(Wnd
);
2815 UserRefObjectCo(WndParent
);
2817 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
2819 UserDerefObjectCo(WndParent
);
2820 UserDerefObjectCo(Wnd
);
2824 hWndOldParent
= WndOldParent
->hSelf
;
2825 UserDerefObject(WndOldParent
);
2828 return( hWndOldParent
);
2836 * The NtUserSetParent function changes the parent window of the specified
2840 * The new parent window and the child window must belong to the same
2841 * application. If the window identified by the hWndChild parameter is
2842 * visible, the system performs the appropriate redrawing and repainting.
2843 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
2844 * or WS_POPUP window styles of the window whose parent is being changed.
2851 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2853 DECLARE_RETURN(HWND
);
2855 DPRINT("Enter NtUserSetParent\n");
2856 UserEnterExclusive();
2858 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
2861 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
2869 HWND FASTCALL
UserGetShellWindow()
2871 PWINSTATION_OBJECT WinStaObject
;
2874 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
2879 if (!NT_SUCCESS(Status
))
2881 SetLastNtError(Status
);
2885 Ret
= (HWND
)WinStaObject
->ShellWindow
;
2887 ObDereferenceObject(WinStaObject
);
2893 * NtUserGetShellWindow
2895 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
2902 NtUserGetShellWindow()
2904 DECLARE_RETURN(HWND
);
2906 DPRINT("Enter NtUserGetShellWindow\n");
2909 RETURN( UserGetShellWindow() );
2912 DPRINT("Leave NtUserGetShellWindow, ret=%i\n",_ret_
);
2918 * NtUserSetShellWindowEx
2920 * This is undocumented function to set global shell window. The global
2921 * shell window has special handling of window position.
2928 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
2930 PWINSTATION_OBJECT WinStaObject
;
2931 PWINDOW_OBJECT WndShell
;
2932 DECLARE_RETURN(BOOL
);
2934 DPRINT("Enter NtUserSetShellWindowEx\n");
2935 UserEnterExclusive();
2937 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
2942 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
2947 if (!NT_SUCCESS(Status
))
2949 SetLastNtError(Status
);
2954 * Test if we are permitted to change the shell window.
2956 if (WinStaObject
->ShellWindow
)
2958 ObDereferenceObject(WinStaObject
);
2963 * Move shell window into background.
2965 if (hwndListView
&& hwndListView
!= hwndShell
)
2968 * Disabled for now to get Explorer working.
2969 * -- Filip, 01/nov/2003
2972 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2975 if (UserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2977 ObDereferenceObject(WinStaObject
);
2982 if (UserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2984 ObDereferenceObject(WinStaObject
);
2988 UserRefObjectCo(WndShell
);
2989 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2991 WinStaObject
->ShellWindow
= hwndShell
;
2992 WinStaObject
->ShellListView
= hwndListView
;
2994 UserDerefObjectCo(WndShell
);
2996 ObDereferenceObject(WinStaObject
);
3000 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3006 * NtUserGetSystemMenu
3008 * The NtUserGetSystemMenu function allows the application to access the
3009 * window menu (also known as the system menu or the control menu) for
3010 * copying and modifying.
3014 * Handle to the window that will own a copy of the window menu.
3016 * Specifies the action to be taken. If this parameter is FALSE,
3017 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3018 * currently in use. The copy is initially identical to the window menu
3019 * but it can be modified.
3020 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3021 * to the default state. The previous window menu, if any, is destroyed.
3024 * If the bRevert parameter is FALSE, the return value is a handle to a
3025 * copy of the window menu. If the bRevert parameter is TRUE, the return
3033 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3035 PWINDOW_OBJECT Window
;
3037 DECLARE_RETURN(HMENU
);
3039 DPRINT("Enter NtUserGetSystemMenu\n");
3042 if (!(Window
= UserGetWindowObject(hWnd
)))
3047 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3052 RETURN(Menu
->MenuInfo
.Self
);
3055 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3061 * NtUserSetSystemMenu
3068 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3070 BOOL Result
= FALSE
;
3071 PWINDOW_OBJECT Window
;
3073 DECLARE_RETURN(BOOL
);
3075 DPRINT("Enter NtUserSetSystemMenu\n");
3076 UserEnterExclusive();
3078 if (!(Window
= UserGetWindowObject(hWnd
)))
3086 * Assign new menu handle.
3088 if (!(Menu
= UserGetMenuObject(hMenu
)))
3093 Result
= IntSetSystemMenu(Window
, Menu
);
3099 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3108 UserGetWindow(HWND hWnd
, UINT Relationship
)
3110 PWINDOW_OBJECT Parent
, Window
;
3111 HWND hWndResult
= NULL
;
3113 if (!(Window
= UserGetWindowObject(hWnd
)))
3116 switch (Relationship
)
3119 if((Parent
= Window
->Parent
))
3121 if (Parent
->FirstChild
)
3122 hWndResult
= Parent
->FirstChild
->hSelf
;
3127 if((Parent
= Window
->Parent
))
3129 if (Parent
->LastChild
)
3130 hWndResult
= Parent
->LastChild
->hSelf
;
3135 if (Window
->NextSibling
)
3136 hWndResult
= Window
->NextSibling
->hSelf
;
3140 if (Window
->PrevSibling
)
3141 hWndResult
= Window
->PrevSibling
->hSelf
;
3145 if((Parent
= UserGetWindowObject(Window
->hOwner
)))
3147 hWndResult
= Parent
->hSelf
;
3151 if (Window
->FirstChild
)
3152 hWndResult
= Window
->FirstChild
->hSelf
;
3164 * The NtUserGetWindow function retrieves a handle to a window that has the
3165 * specified relationship (Z order or owner) to the specified window.
3172 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3174 DECLARE_RETURN(HWND
);
3176 DPRINT("Enter NtUserGetWindow\n");
3179 RETURN(UserGetWindow(hWnd
, Relationship
));
3182 DPRINT("Leave NtUserGetWindow, ret=%i\n",_ret_
);
3191 * NtUserGetWindowLong
3193 * The NtUserGetWindowLong function retrieves information about the specified
3194 * window. The function also retrieves the 32-bit (long) value at the
3195 * specified offset into the extra window memory.
3202 UserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3204 PWINDOW_OBJECT Window
, Parent
;
3207 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3209 if (!(Window
= UserGetWindowObject(hWnd
)))
3215 * WndProc is only available to the owner process
3217 if (GWL_WNDPROC
== Index
3218 && Window
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3220 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3224 if ((INT
)Index
>= 0)
3226 if ((Index
+ sizeof(LONG
)) > Window
->ExtraDataSize
)
3228 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3231 Result
= *((LONG
*)(Window
->ExtraData
+ Index
));
3238 Result
= Window
->ExStyle
;
3242 Result
= Window
->Style
;
3247 Result
= (LONG
) Window
->WndProcA
;
3249 Result
= (LONG
) Window
->WndProcW
;
3253 Result
= (LONG
) Window
->Instance
;
3256 case GWL_HWNDPARENT
:
3257 Parent
= Window
->Parent
;
3260 if (Parent
&& Parent
->hSelf
== IntGetDesktopWindow())
3261 Result
= (LONG
) UserGetWindow(Window
->hSelf
, GW_OWNER
);
3263 Result
= (LONG
) Parent
->hSelf
;
3268 Result
= (LONG
) Window
->IDMenu
;
3272 Result
= Window
->UserData
;
3276 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3277 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3290 * NtUserGetWindowLong
3292 * The NtUserGetWindowLong function retrieves information about the specified
3293 * window. The function also retrieves the 32-bit (long) value at the
3294 * specified offset into the extra window memory.
3301 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3303 DECLARE_RETURN(LONG
);
3305 DPRINT("Enter NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3306 UserEnterExclusive();
3308 RETURN(UserGetWindowLong(hWnd
, Index
, Ansi
));
3311 DPRINT("Leave NtUserGetWindowLong, ret=%i\n",_ret_
);
3320 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3322 PWINDOW_OBJECT Window
, Parent
;
3323 PWINSTATION_OBJECT WindowStation
;
3327 if (hWnd
== IntGetDesktopWindow())
3329 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3333 if (!(Window
= UserGetWindowObject(hWnd
)))
3338 if ((INT
)Index
>= 0)
3340 if ((Index
+ sizeof(LONG
)) > Window
->ExtraDataSize
)
3342 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3345 OldValue
= *((LONG
*)(Window
->ExtraData
+ Index
));
3346 *((LONG
*)(Window
->ExtraData
+ Index
)) = NewValue
;
3353 OldValue
= (LONG
) Window
->ExStyle
;
3354 Style
.styleOld
= OldValue
;
3355 Style
.styleNew
= NewValue
;
3358 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3360 WindowStation
= Window
->OwnerThread
->Tcb
.Win32Thread
->Desktop
->WindowStation
;
3363 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3364 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3367 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3368 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3369 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3373 OldValue
= (LONG
) Window
->Style
;
3374 Style
.styleOld
= OldValue
;
3375 Style
.styleNew
= NewValue
;
3376 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3377 Window
->Style
= (DWORD
)Style
.styleNew
;
3378 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3382 /* FIXME: should check if window belongs to current process */
3385 OldValue
= (LONG
) Window
->WndProcA
;
3386 Window
->WndProcA
= (WNDPROC
) NewValue
;
3387 Window
->WndProcW
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,FALSE
);
3388 Window
->Unicode
= FALSE
;
3392 OldValue
= (LONG
) Window
->WndProcW
;
3393 Window
->WndProcW
= (WNDPROC
) NewValue
;
3394 Window
->WndProcA
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,TRUE
);
3395 Window
->Unicode
= TRUE
;
3400 OldValue
= (LONG
) Window
->Instance
;
3401 Window
->Instance
= (HINSTANCE
) NewValue
;
3404 case GWL_HWNDPARENT
:
3405 Parent
= Window
->Parent
;
3406 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
3407 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
3409 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
3413 OldValue
= (LONG
) Window
->IDMenu
;
3414 Window
->IDMenu
= (UINT
) NewValue
;
3418 OldValue
= Window
->UserData
;
3419 Window
->UserData
= NewValue
;
3423 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3424 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3436 * NtUserSetWindowLong
3438 * The NtUserSetWindowLong function changes an attribute of the specified
3439 * window. The function also sets the 32-bit (long) value at the specified
3440 * offset into the extra window memory.
3447 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3449 DECLARE_RETURN(LONG
);
3451 DPRINT("Enter NtUserSetWindowLong\n");
3452 UserEnterExclusive();
3454 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3457 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3463 * NtUserSetWindowWord
3465 * Legacy function similar to NtUserSetWindowLong.
3472 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3474 PWINDOW_OBJECT Window
;
3476 DECLARE_RETURN(WORD
);
3478 DPRINT("Enter NtUserSetWindowWord\n");
3479 UserEnterExclusive();
3481 if (!(Window
= UserGetWindowObject(hWnd
)))
3490 case GWL_HWNDPARENT
:
3491 RETURN( co_UserSetWindowLong(Window
->hSelf
, Index
, (UINT
)NewValue
, TRUE
));
3495 SetLastWin32Error(ERROR_INVALID_INDEX
);
3500 if (Index
> Window
->ExtraDataSize
- sizeof(WORD
))
3502 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3506 OldValue
= *((WORD
*)(Window
->ExtraData
+ Index
));
3507 *((WORD
*)(Window
->ExtraData
+ Index
)) = NewValue
;
3512 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3521 NtUserGetWindowPlacement(HWND hWnd
,
3522 WINDOWPLACEMENT
*lpwndpl
)
3524 PWINDOW_OBJECT Window
;
3525 PINTERNALPOS InternalPos
;
3527 WINDOWPLACEMENT Safepl
;
3529 DECLARE_RETURN(BOOL
);
3531 DPRINT("Enter NtUserGetWindowPlacement\n");
3534 if (!(Window
= UserGetWindowObject(hWnd
)))
3539 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3540 if(!NT_SUCCESS(Status
))
3542 SetLastNtError(Status
);
3545 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3551 Safepl
.showCmd
= ((Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ? SW_MAXIMIZE
: SW_SHOWNORMAL
);
3553 Size
.x
= Window
->WindowRect
.left
;
3554 Size
.y
= Window
->WindowRect
.top
;
3555 InternalPos
= WinPosInitInternalPos(Window
, &Size
,
3556 &Window
->WindowRect
);
3559 Safepl
.rcNormalPosition
= InternalPos
->NormalRect
;
3560 Safepl
.ptMinPosition
= InternalPos
->IconPos
;
3561 Safepl
.ptMaxPosition
= InternalPos
->MaxPos
;
3568 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3569 if(!NT_SUCCESS(Status
))
3571 SetLastNtError(Status
);
3578 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
3585 * Return the dimension of the window in the screen coordinates.
3586 * \param hWnd window handle.
3587 * \param Rect pointer to the buffer where the coordinates are returned.
3593 NtUserGetWindowRect(HWND hWnd
, LPRECT Rect
)
3597 DECLARE_RETURN(BOOL
);
3599 DPRINT("Enter NtUserGetWindowRect\n");
3602 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3606 Status
= MmCopyToCaller(Rect
, &Wnd
->WindowRect
, sizeof(RECT
));
3607 if (!NT_SUCCESS(Status
))
3609 SetLastNtError(Status
);
3616 DPRINT("Leave NtUserGetWindowRect, ret=%i\n",_ret_
);
3626 NtUserGetWindowThreadProcessId(HWND hWnd
, LPDWORD UnsafePid
)
3630 DECLARE_RETURN(DWORD
);
3632 DPRINT("Enter NtUserGetWindowThreadProcessId\n");
3635 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3640 tid
= (DWORD
)IntGetWndThreadId(Wnd
);
3641 pid
= (DWORD
)IntGetWndProcessId(Wnd
);
3644 MmCopyToCaller(UnsafePid
, &pid
, sizeof(DWORD
));
3649 DPRINT("Leave NtUserGetWindowThreadProcessId, ret=%i\n",_ret_
);
3659 NtUserLockWindowUpdate(DWORD Unknown0
)
3679 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3680 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3681 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3685 QueryWindow based on KJK::Hyperion and James Tabor.
3687 0 = QWUniqueProcessId
3688 1 = QWUniqueThreadId
3689 4 = QWIsHung Implements IsHungAppWindow found
3692 9 = QWKillWindow When I called this with hWnd ==
3693 DesktopWindow, it shutdown the system
3700 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3702 PWINDOW_OBJECT Window
;
3704 DECLARE_RETURN(UINT
);
3706 DPRINT("Enter NtUserQueryWindow\n");
3709 if (!(Window
= UserGetWindowObject(hWnd
)))
3716 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3717 Result
= (DWORD
)IntGetWndProcessId(Window
);
3720 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3721 Result
= (DWORD
)IntGetWndThreadId(Window
);
3724 case QUERY_WINDOW_ISHUNG
:
3725 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
3729 Result
= (DWORD
)NULL
;
3736 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3746 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3760 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3762 UNICODE_STRING SafeMessageName
;
3765 DECLARE_RETURN(UINT
);
3767 DPRINT("Enter NtUserRegisterWindowMessage\n");
3768 UserEnterExclusive();
3770 if(MessageNameUnsafe
== NULL
)
3772 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3776 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3777 if(!NT_SUCCESS(Status
))
3779 SetLastNtError(Status
);
3783 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3785 RtlFreeUnicodeString(&SafeMessageName
);
3789 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3799 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3812 NtUserSetInternalWindowPos(DWORD Unknown0
,
3828 NtUserSetLayeredWindowAttributes(DWORD Unknown0
,
3843 NtUserSetLogonNotifyWindow(DWORD Unknown0
)
3860 PWINDOW_OBJECT Window
;
3862 DECLARE_RETURN(BOOL
);
3864 DPRINT("Enter NtUserSetMenu\n");
3865 UserEnterExclusive();
3867 if (!(Window
= UserGetWindowObject(hWnd
)))
3872 if (! IntSetMenu(Window
, Menu
, &Changed
))
3877 if (Changed
&& Repaint
)
3879 UserRefObjectCo(Window
);
3880 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3881 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3883 UserDerefObjectCo(Window
);
3889 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3899 NtUserSetWindowFNID(DWORD Unknown0
,
3913 NtUserSetWindowPlacement(HWND hWnd
,
3914 WINDOWPLACEMENT
*lpwndpl
)
3916 PWINDOW_OBJECT Window
;
3917 WINDOWPLACEMENT Safepl
;
3919 DECLARE_RETURN(BOOL
);
3921 DPRINT("Enter NtUserSetWindowPlacement\n");
3922 UserEnterExclusive();
3924 if (!(Window
= UserGetWindowObject(hWnd
)))
3928 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3929 if(!NT_SUCCESS(Status
))
3931 SetLastNtError(Status
);
3934 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3939 UserRefObjectCo(Window
);
3941 if ((Window
->Style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
3943 co_WinPosSetWindowPos(Window
, NULL
,
3944 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
3945 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
3946 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
3947 SWP_NOZORDER
| SWP_NOACTIVATE
);
3950 /* FIXME - change window status */
3951 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
3953 if (Window
->InternalPos
== NULL
)
3954 Window
->InternalPos
= ExAllocatePoolWithTag(PagedPool
, sizeof(INTERNALPOS
), TAG_WININTLIST
);
3955 Window
->InternalPos
->NormalRect
= Safepl
.rcNormalPosition
;
3956 Window
->InternalPos
->IconPos
= Safepl
.ptMinPosition
;
3957 Window
->InternalPos
->MaxPos
= Safepl
.ptMaxPosition
;
3959 UserDerefObjectCo(Window
);
3963 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
3975 HWND hWndInsertAfter
,
3982 DECLARE_RETURN(BOOL
);
3983 PWINDOW_OBJECT Window
;
3986 DPRINT("Enter NtUserSetWindowPos\n");
3987 UserEnterExclusive();
3989 if (!(Window
= UserGetWindowObject(hWnd
)))
3994 UserRefObjectCo(Window
);
3995 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
3996 UserDerefObjectCo(Window
);
4001 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4008 IntGetWindowRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
4023 /* Create a new window region using the window rectangle */
4024 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
4025 NtGdiOffsetRgn(VisRgn
, -Window
->WindowRect
.left
, -Window
->WindowRect
.top
);
4026 /* if there's a region assigned to the window, combine them both */
4027 if(Window
->WindowRegion
&& !(Window
->Style
& WS_MINIMIZE
))
4028 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4029 /* Copy the region into hRgn */
4030 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4032 if((pRgn
= RGNDATA_LockRgn(hRgn
)))
4034 Ret
= pRgn
->rdh
.iType
;
4035 RGNDATA_UnlockRgn(pRgn
);
4040 NtGdiDeleteObject(VisRgn
);
4046 IntGetWindowRgnBox(PWINDOW_OBJECT Window
, RECT
*Rect
)
4061 /* Create a new window region using the window rectangle */
4062 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
4063 NtGdiOffsetRgn(VisRgn
, -Window
->WindowRect
.left
, -Window
->WindowRect
.top
);
4064 /* if there's a region assigned to the window, combine them both */
4065 if(Window
->WindowRegion
&& !(Window
->Style
& WS_MINIMIZE
))
4066 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4068 if((pRgn
= RGNDATA_LockRgn(VisRgn
)))
4070 Ret
= pRgn
->rdh
.iType
;
4071 *Rect
= pRgn
->rdh
.rcBound
;
4072 RGNDATA_UnlockRgn(pRgn
);
4077 NtGdiDeleteObject(VisRgn
);
4092 PWINDOW_OBJECT Window
;
4093 DECLARE_RETURN(INT
);
4095 DPRINT("Enter NtUserSetWindowRgn\n");
4096 UserEnterExclusive();
4098 if (!(Window
= UserGetWindowObject(hWnd
)))
4103 /* FIXME - Verify if hRgn is a valid handle!!!!
4104 Propably make this operation thread-safe, but maybe it's not necessary */
4106 if(Window
->WindowRegion
)
4108 /* Delete no longer needed region handle */
4109 NtGdiDeleteObject(Window
->WindowRegion
);
4111 Window
->WindowRegion
= hRgn
;
4113 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4117 UserRefObjectCo(Window
);
4118 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4119 UserDerefObjectCo(Window
);
4125 DPRINT("Leave NtUserSystemParametersInfo, ret=%i\n",_ret_
);
4135 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4137 PWINDOW_OBJECT Window
;
4139 DECLARE_RETURN(BOOL
);
4141 DPRINT("Enter NtUserShowWindow\n");
4142 UserEnterExclusive();
4144 if (!(Window
= UserGetWindowObject(hWnd
)))
4149 UserRefObjectCo(Window
);
4150 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4151 UserDerefObjectCo(Window
);
4156 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4166 NtUserShowWindowAsync(DWORD Unknown0
,
4179 NtUserUpdateLayeredWindow(DWORD Unknown0
,
4201 NtUserWindowFromPoint(LONG X
, LONG Y
)
4205 PWINDOW_OBJECT DesktopWindow
= NULL
, Window
= NULL
;
4206 DECLARE_RETURN(HWND
);
4208 DPRINT("Enter NtUserWindowFromPoint\n");
4209 UserEnterExclusive();
4211 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4218 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4219 //its possible this referencing is useless, thou it shouldnt hurt...
4220 UserRefObjectCo(DesktopWindow
);
4222 Hit
= co_WinPosWindowFromPoint(DesktopWindow
, PsGetWin32Thread()->MessageQueue
, &pt
, &Window
);
4226 Ret
= Window
->hSelf
;
4235 if (Window
) UserDerefObject(Window
);
4236 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4238 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4248 * Undocumented function that is called from DefWindowProc to set
4256 NtUserDefSetText(HWND hWnd
, PUNICODE_STRING WindowText
)
4258 PWINDOW_OBJECT Window
;
4259 UNICODE_STRING SafeText
;
4261 DECLARE_RETURN(INT
);
4263 DPRINT("Enter NtUserDefSetText\n");
4264 UserEnterExclusive();
4266 if(!(Window
= UserGetWindowObject(hWnd
)))
4273 Status
= IntSafeCopyUnicodeString(&SafeText
, WindowText
);
4274 if(!NT_SUCCESS(Status
))
4276 SetLastNtError(Status
);
4282 RtlInitUnicodeString(&SafeText
, NULL
);
4285 /* FIXME - do this thread-safe! otherwise one could crash here! */
4286 RtlFreeUnicodeString(&Window
->WindowName
);
4288 Window
->WindowName
= SafeText
;
4290 /* Send shell notifications */
4291 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
4293 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4299 DPRINT("Leave NtUserDefSetText, ret=%i\n",_ret_
);
4305 * NtUserInternalGetWindowText
4312 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4314 PWINDOW_OBJECT Window
;
4317 DECLARE_RETURN(INT
);
4319 DPRINT("Enter NtUserInternalGetWindowText\n");
4322 if(lpString
&& (nMaxCount
<= 1))
4324 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4328 if(!(Window
= UserGetWindowObject(hWnd
)))
4333 /* FIXME - do this thread-safe! otherwise one could crash here! */
4334 Result
= Window
->WindowName
.Length
/ sizeof(WCHAR
);
4337 const WCHAR Terminator
= L
'\0';
4339 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4341 Copy
= min(nMaxCount
- 1, Result
);
4344 Status
= MmCopyToCaller(Buffer
, Window
->WindowName
.Buffer
, Copy
* sizeof(WCHAR
));
4345 if(!NT_SUCCESS(Status
))
4347 SetLastNtError(Status
);
4353 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4354 if(!NT_SUCCESS(Status
))
4356 SetLastNtError(Status
);
4366 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4372 NtUserDereferenceWndProcHandle(WNDPROC wpHandle
, WndProcHandle
*Data
)
4374 DECLARE_RETURN(DWORD
);
4376 DPRINT("Enter NtUserDereferenceWndProcHandle\n");
4379 WndProcHandle Entry
;
4380 if (((DWORD
)wpHandle
& 0xFFFF0000) == 0xFFFF0000)
4382 Entry
= WndProcHandlesArray
[(DWORD
)wpHandle
& 0x0000FFFF];
4383 Data
->WindowProc
= Entry
.WindowProc
;
4384 Data
->IsUnicode
= Entry
.IsUnicode
;
4385 Data
->ProcessID
= Entry
.ProcessID
;
4395 DPRINT("Leave NtUserDereferenceWndProcHandle, ret=%i\n",_ret_
);
4401 IntAddWndProcHandle(WNDPROC WindowProc
, BOOL IsUnicode
)
4406 WndProcHandle
*OldArray
;
4409 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4411 if (WndProcHandlesArray
[i
].WindowProc
== NULL
)
4419 OldArray
= WndProcHandlesArray
;
4420 OldArraySize
= WndProcHandlesArraySize
;
4421 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,(OldArraySize
+ WPH_SIZE
) * sizeof(WndProcHandle
), TAG_WINPROCLST
);
4422 WndProcHandlesArraySize
= OldArraySize
+ WPH_SIZE
;
4423 RtlCopyMemory(WndProcHandlesArray
,OldArray
,OldArraySize
* sizeof(WndProcHandle
));
4424 ExFreePool(OldArray
);
4425 FreeSpot
= OldArraySize
+ 1;
4427 WndProcHandlesArray
[FreeSpot
].WindowProc
= WindowProc
;
4428 WndProcHandlesArray
[FreeSpot
].IsUnicode
= IsUnicode
;
4429 WndProcHandlesArray
[FreeSpot
].ProcessID
= PsGetCurrentProcessId();
4430 return FreeSpot
+ 0xFFFF0000;
4434 IntRemoveWndProcHandle(WNDPROC Handle
)
4437 position
= (DWORD
)Handle
& 0x0000FFFF;
4438 if (position
> WndProcHandlesArraySize
)
4442 WndProcHandlesArray
[position
].WindowProc
= NULL
;
4443 WndProcHandlesArray
[position
].IsUnicode
= FALSE
;
4444 WndProcHandlesArray
[position
].ProcessID
= NULL
;
4449 IntRemoveProcessWndProcHandles(HANDLE ProcessID
)
4452 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4454 if (WndProcHandlesArray
[i
].ProcessID
== ProcessID
)
4456 WndProcHandlesArray
[i
].WindowProc
= NULL
;
4457 WndProcHandlesArray
[i
].IsUnicode
= FALSE
;
4458 WndProcHandlesArray
[i
].ProcessID
= NULL
;
4464 #define WIN_NEEDS_SHOW_OWNEDPOPUP (0x00000040)
4468 IntShowOwnedPopups(PWINDOW_OBJECT OwnerWnd
, BOOL fShow
)
4471 PWINDOW_OBJECT pWnd
;
4476 win_array
= IntWinListChildren(OwnerWnd
);//faxme: use desktop?
4481 while (win_array
[count
])
4483 while (--count
>= 0)
4485 if (UserGetWindow( win_array
[count
], GW_OWNER
) != OwnerWnd
->hSelf
)
4487 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4489 // if (pWnd == WND_OTHER_PROCESS) continue;
4493 if (pWnd
->Flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
)
4495 /* In Windows, ShowOwnedPopups(TRUE) generates
4496 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4497 * regardless of the state of the owner
4499 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4505 if (pWnd
->Style
& WS_VISIBLE
)
4507 /* In Windows, ShowOwnedPopups(FALSE) generates
4508 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4509 * regardless of the state of the owner
4511 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4517 ExFreePool( win_array
);