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 static LRESULT
co_IntDestroyWindow(PWINDOW_OBJECT Window
,
298 PW32PROCESS ProcessData
,
299 PW32THREAD ThreadData
,
300 BOOLEAN SendMessages
)
304 PWINDOW_OBJECT Child
;
306 BOOLEAN BelongsToThreadData
;
310 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
312 DPRINT("Tried to call IntDestroyWindow() twice\n");
315 Window
->Status
|= WINDOWSTATUS_DESTROYING
;
316 Window
->Style
&= ~WS_VISIBLE
;
317 /* remove the window already at this point from the thread window list so we
318 don't get into trouble when destroying the thread windows while we're still
319 in IntDestroyWindow() */
320 RemoveEntryList(&Window
->ThreadListEntry
);
322 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
324 IntDeRegisterShellHookWindow(Window
->hSelf
);
328 /* Send destroy messages */
329 IntSendDestroyMsg(Window
->hSelf
);
332 /* free child windows */
333 Children
= IntWinListChildren(Window
);
336 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
338 if ((Child
= IntGetWindowObject(*ChildHandle
)))
340 if(!IntWndBelongsToThread(Child
, ThreadData
))
342 /* send WM_DESTROY messages to windows not belonging to the same thread */
343 IntSendDestroyMsg(Child
->hSelf
);
346 co_IntDestroyWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
348 UserDerefObject(Child
);
351 ExFreePool(Children
);
357 * Clear the update region to make sure no WM_PAINT messages will be
358 * generated for this window while processing the WM_NCDESTROY.
360 co_UserRedrawWindow(Window
, NULL
, 0,
361 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
362 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
363 if(BelongsToThreadData
)
364 co_IntSendMessage(Window
->hSelf
, WM_NCDESTROY
, 0, 0);
366 MsqRemoveTimersWindow(ThreadData
->MessageQueue
, Window
->hSelf
);
368 /* flush the message queue */
369 MsqRemoveWindowMessagesFromQueue(Window
);
371 /* from now on no messages can be sent to this window anymore */
372 Window
->Status
|= WINDOWSTATUS_DESTROYED
;
373 /* don't remove the WINDOWSTATUS_DESTROYING bit */
375 /* reset shell window handles */
376 if(ThreadData
->Desktop
)
378 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellWindow
)
379 ThreadData
->Desktop
->WindowStation
->ShellWindow
= NULL
;
381 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellListView
)
382 ThreadData
->Desktop
->WindowStation
->ShellListView
= NULL
;
385 /* Unregister hot keys */
386 UnregisterWindowHotKeys (Window
);
388 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
392 WinPosCheckInternalPos(Window
->hSelf
);
393 if (Window
->hSelf
== GetCapture())
398 /* free resources associated with the window */
399 TIMER_RemoveWindowTimers(Window
->hSelf
);
402 if (!(Window
->Style
& WS_CHILD
) && Window
->IDMenu
403 && (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
405 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
409 if(Window
->SystemMenu
410 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
412 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
413 Window
->SystemMenu
= (HMENU
)0;
416 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
419 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
420 CLASS_RemoveWindow(Window
->Class
);
423 IntUnlinkWindow(Window
);
425 UserRefObject(Window
);
426 ObmDeleteObject(Window
->hSelf
, otWindow
);
428 IntDestroyScrollBars(Window
);
430 /* remove the window from the class object */
431 RemoveEntryList(&Window
->ClassListEntry
);
433 /* dereference the class */
434 ClassDereferenceObject(Window
->Class
);
435 Window
->Class
= NULL
;
437 if(Window
->WindowRegion
)
439 NtGdiDeleteObject(Window
->WindowRegion
);
442 RtlFreeUnicodeString(&Window
->WindowName
);
444 UserDerefObject(Window
);
450 IntGetWindowBorderMeasures(PWINDOW_OBJECT Window
, UINT
*cx
, UINT
*cy
)
452 if(HAS_DLGFRAME(Window
->Style
, Window
->ExStyle
) && !(Window
->Style
& WS_MINIMIZE
))
454 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
455 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
459 if(HAS_THICKFRAME(Window
->Style
, Window
->ExStyle
)&& !(Window
->Style
& WS_MINIMIZE
))
461 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
462 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
464 else if(HAS_THINFRAME(Window
->Style
, Window
->ExStyle
))
466 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
467 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
477 IntGetWindowInfo(PWINDOW_OBJECT Window
, PWINDOWINFO pwi
)
479 pwi
->cbSize
= sizeof(WINDOWINFO
);
480 pwi
->rcWindow
= Window
->WindowRect
;
481 pwi
->rcClient
= Window
->ClientRect
;
482 pwi
->dwStyle
= Window
->Style
;
483 pwi
->dwExStyle
= Window
->ExStyle
;
484 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Window
->hSelf
); /* WS_ACTIVECAPTION */
485 IntGetWindowBorderMeasures(Window
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
486 pwi
->atomWindowType
= (Window
->Class
? Window
->Class
->Atom
: 0);
487 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
493 PWINDOW_OBJECT Window
,
497 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
499 if ((Window
->Style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
501 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
505 *Changed
= (Window
->IDMenu
!= (UINT
) Menu
);
513 OldMenu
= IntGetMenuObject((HMENU
) Window
->IDMenu
);
514 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Window
->hSelf
);
523 NewMenu
= IntGetMenuObject(Menu
);
528 IntReleaseMenuObject(OldMenu
);
530 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
533 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
535 /* Can't use the same menu for two windows */
538 IntReleaseMenuObject(OldMenu
);
540 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
546 Window
->IDMenu
= (UINT
) Menu
;
549 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
550 IntReleaseMenuObject(NewMenu
);
554 OldMenu
->MenuInfo
.Wnd
= NULL
;
555 IntReleaseMenuObject(OldMenu
);
562 /* INTERNAL ******************************************************************/
566 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
572 WThread
= Thread
->Tcb
.Win32Thread
;
574 while (!IsListEmpty(&WThread
->WindowListHead
))
576 Current
= WThread
->WindowListHead
.Flink
;
577 Wnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
579 DPRINT1("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
581 /* window removes itself from the list */
584 fixme: it is critical that the window removes itself! if now, we will loop
588 //ASSERT(co_UserDestroyWindow(Wnd));
590 UserRefObjectCo(Wnd
);//faxme: temp hack??
591 if (!co_UserDestroyWindow(Wnd
))
593 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
595 UserDerefObjectCo(Wnd
);//faxme: temp hack??
603 * Returns client window rectangle relative to the upper-left corner of client area.
605 * \note Does not check the validity of the parameters
608 IntGetClientRect(PWINDOW_OBJECT Window
, PRECT Rect
)
613 Rect
->left
= Rect
->top
= 0;
614 Rect
->right
= Window
->ClientRect
.right
- Window
->ClientRect
.left
;
615 Rect
->bottom
= Window
->ClientRect
.bottom
- Window
->ClientRect
.top
;
621 IntGetFocusWindow(VOID
)
623 PUSER_MESSAGE_QUEUE Queue
;
624 PDESKTOP_OBJECT pdo
= IntGetActiveDesktop();
629 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
634 return(Queue
->FocusWindow
);
638 PMENU_OBJECT FASTCALL
639 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
)
641 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
642 PW32THREAD W32Thread
;
643 HMENU hNewMenu
, hSysMenu
;
644 ROSMENUITEMINFO ItemInfo
;
648 W32Thread
= PsGetWin32Thread();
650 if(!W32Thread
->Desktop
)
653 if(Window
->SystemMenu
)
655 Menu
= UserGetMenuObject(Window
->SystemMenu
);
658 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
659 Window
->SystemMenu
= (HMENU
)0;
663 if(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
)
665 /* clone system menu */
666 Menu
= UserGetMenuObject(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
);
670 NewMenu
= IntCloneMenu(Menu
);
673 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
674 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
675 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
677 //IntReleaseMenuObject(NewMenu);
682 hSysMenu
= UserCreateMenu(FALSE
);
683 if (NULL
== hSysMenu
)
687 SysMenu
= IntGetMenuObject(hSysMenu
);
690 UserDestroyMenu(hSysMenu
);
693 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
694 SysMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
695 hNewMenu
= co_IntLoadSysMenuTemplate();
698 IntReleaseMenuObject(SysMenu
);
699 UserDestroyMenu(hSysMenu
);
702 Menu
= IntGetMenuObject(hNewMenu
);
705 IntReleaseMenuObject(SysMenu
);
706 UserDestroyMenu(hSysMenu
);
710 NewMenu
= IntCloneMenu(Menu
);
713 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
714 IntReleaseMenuObject(NewMenu
);
715 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
717 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
718 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
719 ItemInfo
.fType
= MF_POPUP
;
720 ItemInfo
.fState
= MFS_ENABLED
;
721 ItemInfo
.dwTypeData
= NULL
;
723 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
724 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
726 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
730 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
731 IntReleaseMenuObject(Menu
);
740 if(Window
->SystemMenu
)
741 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
749 IntIsChildWindow(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT BaseWindow
)
751 PWINDOW_OBJECT Window
;
756 if (Window
== Parent
)
760 if(!(Window
->Style
& WS_CHILD
))
765 Window
= Window
->Parent
;
772 IntIsWindowVisible(PWINDOW_OBJECT BaseWindow
)
774 PWINDOW_OBJECT Window
;
779 if(!(Window
->Style
& WS_CHILD
))
783 if(!(Window
->Style
& WS_VISIBLE
))
788 Window
= Window
->Parent
;
791 if(Window
&& Window
->Style
& WS_VISIBLE
)
800 /* link the window into siblings and parent. children are kept in place. */
804 PWINDOW_OBJECT WndParent
,
805 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
808 PWINDOW_OBJECT Parent
;
810 Wnd
->Parent
= WndParent
;
811 if ((Wnd
->PrevSibling
= WndPrevSibling
))
813 /* link after WndPrevSibling */
814 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
815 Wnd
->NextSibling
->PrevSibling
= Wnd
;
816 else if ((Parent
= Wnd
->Parent
))
818 if(Parent
->LastChild
== WndPrevSibling
)
819 Parent
->LastChild
= Wnd
;
821 Wnd
->PrevSibling
->NextSibling
= Wnd
;
826 Parent
= Wnd
->Parent
;
827 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
828 Wnd
->NextSibling
->PrevSibling
= Wnd
;
831 Parent
->LastChild
= Wnd
;
832 Parent
->FirstChild
= Wnd
;
837 Parent
->FirstChild
= Wnd
;
844 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
846 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
849 Wnd
= IntGetWindowObject(hWnd
);
853 WndOldOwner
= IntGetWindowObject(Wnd
->hOwner
);
856 ret
= WndOldOwner
->hSelf
;
857 UserDerefObject(WndOldOwner
);
864 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
866 Wnd
->hOwner
= hWndNewOwner
;
871 UserDerefObject(Wnd
);
875 PWINDOW_OBJECT FASTCALL
876 co_IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
878 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
879 // HWND hWnd, hWndNewParent;
883 ASSERT(WndNewParent
);
885 ASSERT_REFS_CO(WndNewParent
);
887 // hWnd = Wnd->hSelf;
888 // hWndNewParent = WndNewParent->hSelf;
891 * Windows hides the window first, then shows it again
892 * including the WM_SHOWWINDOW messages and all
894 WasVisible
= co_WinPosShowWindow(Wnd
, 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
= Wnd
->Parent
;
906 if (WndOldParent
) UserRefObject(WndOldParent
); /* caller must deref */
908 if (WndNewParent
!= WndOldParent
)
910 IntUnlinkWindow(Wnd
);
912 if (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
))
914 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
915 Sibling
= WndNewParent
->FirstChild
;
916 while (NULL
!= Sibling
&& 0 != (Sibling
->ExStyle
& WS_EX_TOPMOST
))
918 InsertAfter
= Sibling
;
919 Sibling
= Sibling
->NextSibling
;
922 if (NULL
== InsertAfter
)
924 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
928 // UserRefObject(InsertAfter);
929 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
930 // UserDerefObject(InsertAfter);
935 * SetParent additionally needs to make hwnd the top window
936 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
937 * WM_WINDOWPOSCHANGED notification messages.
939 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
940 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
941 | (WasVisible
? SWP_SHOWWINDOW
: 0));
944 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
945 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
949 * Validate that the old parent still exist, since it migth have been
950 * destroyed during the last callbacks to user-mode
954 // if(!IntIsWindow(WndOldParent->hSelf))
956 // UserDerefObject(WndOldParent);
960 /* don't dereference the window object here, it must be done by the caller
962 // return WndOldParent;
965 return WndOldParent
;//NULL;
969 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
971 PMENU_OBJECT OldMenu
;
972 if(Window
->SystemMenu
)
974 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
977 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
978 IntReleaseMenuObject(OldMenu
);
984 /* FIXME check window style, propably return FALSE ? */
985 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
986 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
989 Window
->SystemMenu
= (HMENU
)0;
995 /* unlink the window from siblings and parent. children are kept in place. */
997 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
999 PWINDOW_OBJECT WndParent
= Wnd
->Parent
;
1001 if (Wnd
->NextSibling
)
1002 Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1003 else if (WndParent
&& WndParent
->LastChild
== Wnd
)
1004 WndParent
->LastChild
= Wnd
->PrevSibling
;
1006 if (Wnd
->PrevSibling
)
1007 Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1008 else if (WndParent
&& WndParent
->FirstChild
== Wnd
)
1009 WndParent
->FirstChild
= Wnd
->NextSibling
;
1011 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1017 PWINDOW_OBJECT Window
, Child
;
1019 if(!(Window
= UserGetWindowObject(IntGetDesktopWindow())))
1024 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1026 if(Child
->hOwner
&& Child
->Style
& WS_VISIBLE
)
1029 * The desktop has a popup window if one of them has
1030 * an owner window and is visible
1040 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1042 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1045 /* FUNCTIONS *****************************************************************/
1051 NtUserAlterWindowStyle(DWORD Unknown0
,
1062 * As best as I can figure, this function is used by EnumWindows,
1063 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1065 * It's supposed to build a list of HWNDs to return to the caller.
1066 * We can figure out what kind of list by what parameters are
1074 NtUserBuildHwndList(
1086 /* FIXME handle bChildren */
1090 PWINDOW_OBJECT Window
, Child
;
1091 if(!(Window
= UserGetWindowObject(hwndParent
)))
1096 for(Child
= Window
->FirstChild
; Child
!= NULL
; Child
= Child
->NextSibling
)
1098 if(dwCount
++ < nBufSize
&& pWnd
)
1100 Status
= MmCopyToCaller(pWnd
++, &Child
->hSelf
, sizeof(HWND
));
1101 if(!NT_SUCCESS(Status
))
1103 SetLastNtError(Status
);
1112 PW32THREAD W32Thread
;
1113 PLIST_ENTRY Current
;
1114 PWINDOW_OBJECT Window
;
1116 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1117 if(!NT_SUCCESS(Status
))
1119 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1122 if(!(W32Thread
= Thread
->Tcb
.Win32Thread
))
1124 ObDereferenceObject(Thread
);
1125 DPRINT("Thread is not a GUI Thread!\n");
1126 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
1130 Current
= W32Thread
->WindowListHead
.Flink
;
1131 while(Current
!= &(W32Thread
->WindowListHead
))
1133 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1136 if(dwCount
< nBufSize
&& pWnd
)
1138 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1139 if(!NT_SUCCESS(Status
))
1141 SetLastNtError(Status
);
1146 Current
= Current
->Flink
;
1149 ObDereferenceObject(Thread
);
1153 PDESKTOP_OBJECT Desktop
;
1154 PWINDOW_OBJECT Window
, Child
;
1156 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1158 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1164 Status
= IntValidateDesktopHandle(hDesktop
,
1168 if(!NT_SUCCESS(Status
))
1170 SetLastWin32Error(ERROR_INVALID_HANDLE
);
1174 if(!(Window
= UserGetWindowObject(Desktop
->DesktopWindow
)))
1176 if(hDesktop
) ObDereferenceObject(Desktop
);
1180 for(Child
= Window
->FirstChild
; Child
!= NULL
; Child
= Child
->NextSibling
)
1182 if(dwCount
++ < nBufSize
&& pWnd
)
1184 Status
= MmCopyToCaller(pWnd
++, &Child
->hSelf
, sizeof(HWND
));
1185 if(!NT_SUCCESS(Status
))
1187 SetLastNtError(Status
);
1193 if(hDesktop
) ObDereferenceObject(Desktop
);
1204 NtUserChildWindowFromPointEx(HWND hwndParent
,
1209 PWINDOW_OBJECT Parent
;
1214 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1222 if(Parent
->hSelf
!= IntGetDesktopWindow())
1224 Pt
.x
+= Parent
->ClientRect
.left
;
1225 Pt
.y
+= Parent
->ClientRect
.top
;
1228 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1233 Ret
= Parent
->hSelf
;
1234 if((List
= IntWinListChildren(Parent
)))
1236 for(phWnd
= List
; *phWnd
; phWnd
++)
1238 PWINDOW_OBJECT Child
;
1239 if((Child
= UserGetWindowObject(*phWnd
)))
1241 if(!(Child
->Style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1245 if((Child
->Style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1249 if((Child
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1253 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1268 * calculates the default position of a window
1271 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT Window
, RECT
*rc
, BOOL IncPos
)
1278 IntGdiIntersectRect(rc
, rc
, &Parent
->ClientRect
);
1282 Pos
.x
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1283 Pos
.y
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1284 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1285 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1287 /* reset counter and position */
1290 Parent
->TiledCounter
= 0;
1292 Parent
->TiledCounter
++;
1303 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1304 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1308 rc
->right
= rc
->left
+ Sz
.cx
;
1309 rc
->bottom
= rc
->top
+ Sz
.cy
;
1318 co_IntCreateWindowEx(DWORD dwExStyle
,
1319 PUNICODE_STRING ClassName
,
1320 PUNICODE_STRING WindowName
,
1328 HINSTANCE hInstance
,
1331 BOOL bUnicodeWindow
)
1333 PWINSTATION_OBJECT WinSta
;
1334 PWNDCLASS_OBJECT Class
;
1335 PWINDOW_OBJECT Window
= NULL
;
1336 PWINDOW_OBJECT ParentWindow
= NULL
, OwnerWindow
;
1337 HWND ParentWindowHandle
;
1338 HWND OwnerWindowHandle
;
1339 PMENU_OBJECT SystemMenu
;
1345 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1352 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
);
1379 OwnerWindowHandle
= UserGetAncestor(Par
, GA_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 ClassFound
= ClassReferenceClassByNameOrAtom(&Class
, 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 /* Check the window station. */
1418 if (PsGetWin32Thread()->Desktop
== NULL
)
1420 ClassDereferenceObject(Class
);
1422 DPRINT("Thread is not attached to a desktop! Cannot create window!\n");
1425 WinSta
= PsGetWin32Thread()->Desktop
->WindowStation
;
1426 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1428 /* Create the window object. */
1429 Window
= (PWINDOW_OBJECT
)
1430 ObmCreateObject(&gHandleTable
, &Handle
,
1431 otWindow
, sizeof(WINDOW_OBJECT
) + Class
->cbWndExtra
1434 DPRINT("Created object with handle %X\n", Handle
);
1437 ObDereferenceObject(WinSta
);
1438 ClassDereferenceObject(Class
);
1439 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1443 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
= Handle
;
1455 * Fill out the structure describing it.
1457 Window
->Class
= Class
;
1459 InsertTailList(&Class
->ClassWindowsListHead
, &Window
->ClassListEntry
);
1461 Window
->SystemMenu
= (HMENU
)0;
1462 Window
->ContextHelpId
= 0;
1464 Window
->Instance
= hInstance
;
1465 Window
->hSelf
= Handle
;
1466 if (0 != (dwStyle
& WS_CHILD
))
1468 Window
->IDMenu
= (UINT
) hMenu
;
1472 IntSetMenu(Window
, hMenu
, &MenuChanged
);
1475 Window
->MessageQueue
= PsGetWin32Thread()->MessageQueue
;
1476 IntReferenceMessageQueue(Window
->MessageQueue
);
1477 Window
->Parent
= ParentWindow
;
1479 if((OwnerWindow
= UserGetWindowObject(OwnerWindowHandle
)))
1481 Window
->hOwner
= OwnerWindowHandle
;
1486 Window
->hOwner
= NULL
;
1490 Window
->UserData
= 0;
1492 if ((((DWORD
)Class
->lpfnWndProcA
& 0xFFFF0000) != 0xFFFF0000)
1493 && (((DWORD
)Class
->lpfnWndProcW
& 0xFFFF0000) != 0xFFFF0000))
1495 Window
->Unicode
= bUnicodeWindow
;
1499 Window
->Unicode
= Class
->Unicode
;
1501 Window
->WndProcA
= Class
->lpfnWndProcA
;
1502 Window
->WndProcW
= Class
->lpfnWndProcW
;
1503 Window
->OwnerThread
= PsGetCurrentThread();
1504 Window
->FirstChild
= NULL
;
1505 Window
->LastChild
= NULL
;
1506 Window
->PrevSibling
= NULL
;
1507 Window
->NextSibling
= NULL
;
1509 /* extra window data */
1510 if (Class
->cbWndExtra
!= 0)
1512 Window
->ExtraData
= (PCHAR
)(Window
+ 1);
1513 Window
->ExtraDataSize
= Class
->cbWndExtra
;
1514 RtlZeroMemory(Window
->ExtraData
, Window
->ExtraDataSize
);
1518 Window
->ExtraData
= NULL
;
1519 Window
->ExtraDataSize
= 0;
1522 InitializeListHead(&Window
->PropListHead
);
1523 InitializeListHead(&Window
->WndObjListHead
);
1525 if (NULL
!= WindowName
->Buffer
)
1527 Window
->WindowName
.MaximumLength
= WindowName
->MaximumLength
;
1528 Window
->WindowName
.Length
= WindowName
->Length
;
1529 Window
->WindowName
.Buffer
= ExAllocatePoolWithTag(PagedPool
, WindowName
->MaximumLength
,
1531 if (NULL
== Window
->WindowName
.Buffer
)
1533 ClassDereferenceObject(Class
);
1534 DPRINT1("Failed to allocate mem for window name\n");
1535 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1538 RtlCopyMemory(Window
->WindowName
.Buffer
, WindowName
->Buffer
, WindowName
->MaximumLength
);
1542 RtlInitUnicodeString(&Window
->WindowName
, NULL
);
1547 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1548 * tested for WS_POPUP
1550 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1551 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1552 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1553 dwExStyle
|= WS_EX_WINDOWEDGE
;
1555 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1557 /* Correct the window style. */
1558 if (!(dwStyle
& WS_CHILD
))
1560 dwStyle
|= WS_CLIPSIBLINGS
;
1561 DPRINT("3: Style is now %lx\n", dwStyle
);
1562 if (!(dwStyle
& WS_POPUP
))
1564 dwStyle
|= WS_CAPTION
;
1565 Window
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1566 DPRINT("4: Style is now %lx\n", dwStyle
);
1570 /* create system menu */
1571 if((dwStyle
& WS_SYSMENU
) &&
1572 (dwStyle
& WS_CAPTION
) == WS_CAPTION
)
1574 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
1577 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1578 IntReleaseMenuObject(SystemMenu
);
1582 /* Insert the window into the thread's window list. */
1583 InsertTailList (&PsGetWin32Thread()->WindowListHead
, &Window
->ThreadListEntry
);
1585 /* Allocate a DCE for this window. */
1586 if (dwStyle
& CS_OWNDC
)
1588 Window
->Dce
= DceAllocDCE(Window
, DCE_WINDOW_DC
);
1590 /* FIXME: Handle "CS_CLASSDC" */
1597 Window
->ExStyle
= dwExStyle
;
1598 Window
->Style
= dwStyle
& ~WS_VISIBLE
;
1601 Cs
.lpCreateParams
= lpParam
;
1602 Cs
.hInstance
= hInstance
;
1604 Cs
.hwndParent
= ParentWindowHandle
;
1609 Cs
.style
= Window
->Style
;
1610 Cs
.lpszName
= (LPCWSTR
) WindowName
;
1611 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
1612 Cs
.dwExStyle
= dwExStyle
;
1613 CbtCreate
.lpcs
= &Cs
;
1614 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1615 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) Handle
, (LPARAM
) &CbtCreate
))
1618 /* FIXME - Delete window object and remove it from the thread windows list */
1619 /* FIXME - delete allocated DCE */
1621 ClassDereferenceObject(Class
);
1622 DPRINT1("CBT-hook returned !0\n");
1623 RETURN( (HWND
) NULL
);
1631 /* default positioning for overlapped windows */
1632 if(!(Window
->Style
& (WS_POPUP
| WS_CHILD
)))
1635 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1636 BOOL CalculatedDefPosSize
= FALSE
;
1638 IntGetDesktopWorkArea(Window
->OwnerThread
->Tcb
.Win32Thread
->Desktop
, &WorkArea
);
1641 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1643 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1645 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, Window
, &rc
, TRUE
);
1647 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1649 ProcessParams
->WindowFlags
&= ~STARTF_USEPOSITION
;
1650 Pos
.x
= WorkArea
.left
+ ProcessParams
->StartingX
;
1651 Pos
.y
= WorkArea
.top
+ ProcessParams
->StartingY
;
1659 /* According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
1660 y is something else */
1661 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
1666 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1668 if(!CalculatedDefPosSize
)
1670 IntCalcDefPosSize(ParentWindow
, Window
, &rc
, FALSE
);
1672 if(ProcessParams
->WindowFlags
& STARTF_USESIZE
)
1674 ProcessParams
->WindowFlags
&= ~STARTF_USESIZE
;
1675 Size
.cx
= ProcessParams
->CountX
;
1676 Size
.cy
= ProcessParams
->CountY
;
1680 Size
.cx
= rc
.right
- rc
.left
;
1681 Size
.cy
= rc
.bottom
- rc
.top
;
1684 /* move the window if necessary */
1686 Pos
.x
= max(rc
.left
, 0);
1688 Pos
.y
= max(rc
.top
, 0);
1693 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
1694 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1699 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1706 /* Initialize the window dimensions. */
1707 Window
->WindowRect
.left
= Pos
.x
;
1708 Window
->WindowRect
.top
= Pos
.y
;
1709 Window
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1710 Window
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1711 if (0 != (Window
->Style
& WS_CHILD
) && ParentWindow
)
1713 IntGdiOffsetRect(&(Window
->WindowRect
), ParentWindow
->ClientRect
.left
,
1714 ParentWindow
->ClientRect
.top
);
1716 Window
->ClientRect
= Window
->WindowRect
;
1719 * Get the size and position of the window.
1721 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
1723 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1725 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
1726 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
,
1728 if (MaxSize
.x
< nWidth
)
1730 if (MaxSize
.y
< nHeight
)
1731 nHeight
= MaxSize
.y
;
1732 if (nWidth
< MinTrack
.x
)
1733 nWidth
= MinTrack
.x
;
1734 if (nHeight
< MinTrack
.y
)
1735 nHeight
= MinTrack
.y
;
1742 Window
->WindowRect
.left
= Pos
.x
;
1743 Window
->WindowRect
.top
= Pos
.y
;
1744 Window
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1745 Window
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1746 if (0 != (Window
->Style
& WS_CHILD
) && ParentWindow
)
1748 IntGdiOffsetRect(&(Window
->WindowRect
), ParentWindow
->ClientRect
.left
,
1749 ParentWindow
->ClientRect
.top
);
1751 Window
->ClientRect
= Window
->WindowRect
;
1753 /* FIXME: Initialize the window menu. */
1755 /* Send a NCCREATE message. */
1761 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
1762 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1763 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
1764 Result
= co_IntSendMessage(Window
->hSelf
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
1767 /* FIXME: Cleanup. */
1768 DPRINT("IntCreateWindowEx(): NCCREATE message failed.\n");
1772 /* Calculate the non-client size. */
1773 MaxPos
.x
= Window
->WindowRect
.left
;
1774 MaxPos
.y
= Window
->WindowRect
.top
;
1775 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
1776 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
1777 Result
= co_WinPosGetNonClientSize(Window
,
1778 &Window
->WindowRect
,
1779 &Window
->ClientRect
);
1782 IntGdiOffsetRect(&Window
->WindowRect
,
1783 MaxPos
.x
- Window
->WindowRect
.left
,
1784 MaxPos
.y
- Window
->WindowRect
.top
);
1786 if (NULL
!= ParentWindow
)
1788 /* link the window into the parent's child list */
1789 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
1791 PWINDOW_OBJECT PrevSibling
;
1793 PrevSibling
= ParentWindow
->LastChild
;
1795 /* link window as bottom sibling */
1796 IntLinkWindow(Window
, ParentWindow
, PrevSibling
/*prev sibling*/);
1800 /* link window as top sibling (but after topmost siblings) */
1801 PWINDOW_OBJECT InsertAfter
, Sibling
;
1802 if (!(dwExStyle
& WS_EX_TOPMOST
))
1805 Sibling
= ParentWindow
->FirstChild
;
1806 while (Sibling
&& (Sibling
->ExStyle
& WS_EX_TOPMOST
))
1808 InsertAfter
= Sibling
;
1809 Sibling
= Sibling
->NextSibling
;
1817 IntLinkWindow(Window
, ParentWindow
, InsertAfter
/* prev sibling */);
1822 /* Send the WM_CREATE message. */
1823 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
1824 Result
= co_IntSendMessage(Window
->hSelf
, WM_CREATE
, 0, (LPARAM
) &Cs
);
1827 if (Result
== (LRESULT
)-1)
1829 /* FIXME: Cleanup. */
1830 ClassDereferenceObject(Class
);
1831 DPRINT("IntCreateWindowEx(): send CREATE message failed.\n");
1836 /* Send move and size messages. */
1837 if (!(Window
->Flags
& WINDOWOBJECT_NEED_SIZE
))
1841 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
1843 if ((Window
->ClientRect
.right
- Window
->ClientRect
.left
) < 0 ||
1844 (Window
->ClientRect
.bottom
- Window
->ClientRect
.top
) < 0)
1846 DPRINT("Sending bogus WM_SIZE\n");
1850 lParam
= MAKE_LONG(Window
->ClientRect
.right
-
1851 Window
->ClientRect
.left
,
1852 Window
->ClientRect
.bottom
-
1853 Window
->ClientRect
.top
);
1854 co_IntSendMessage(Window
->hSelf
, WM_SIZE
, SIZE_RESTORED
,
1858 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
1860 if (0 != (Window
->Style
& WS_CHILD
) && ParentWindow
)
1862 lParam
= MAKE_LONG(Window
->ClientRect
.left
- ParentWindow
->ClientRect
.left
,
1863 Window
->ClientRect
.top
- ParentWindow
->ClientRect
.top
);
1867 lParam
= MAKE_LONG(Window
->ClientRect
.left
,
1868 Window
->ClientRect
.top
);
1872 co_IntSendMessage(Window
->hSelf
, WM_MOVE
, 0, lParam
);
1875 /* Call WNDOBJ change procs */
1876 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
1881 /* Show or maybe minimize or maximize the window. */
1882 if (Window
->Style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1887 SwFlag
= (Window
->Style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
1889 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
1891 ((Window
->Style
& WS_CHILD
) || UserGetActiveWindow()) ?
1892 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
1893 SWP_NOZORDER
| SWP_FRAMECHANGED
;
1894 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
1895 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
1896 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
1897 NewPos
.right
, NewPos
.bottom
, SwFlag
);
1900 /* Notify the parent window of a new child. */
1901 if ((Window
->Style
& WS_CHILD
) &&
1902 (!(Window
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
1904 DPRINT("IntCreateWindow(): About to notify parent\n");
1905 co_IntSendMessage(ParentWindow
->hSelf
,
1907 MAKEWPARAM(WM_CREATE
, Window
->IDMenu
),
1908 (LPARAM
)Window
->hSelf
);
1911 if ((!hWndParent
) && (!HasOwner
))
1913 DPRINT("Sending CREATED notify\n");
1914 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)Handle
);
1918 DPRINT("Not sending CREATED notify, %x %d\n", ParentWindow
, HasOwner
);
1921 /* Initialize and show the window's scrollbars */
1922 if (Window
->Style
& WS_VSCROLL
)
1924 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
1926 if (Window
->Style
& WS_HSCROLL
)
1928 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
1931 if (dwStyle
& WS_VISIBLE
)
1933 DPRINT("IntCreateWindow(): About to show window\n");
1934 co_WinPosShowWindow(Window
, dwShowMode
);
1937 DPRINT("IntCreateWindow(): = %X\n", Handle
);
1938 DPRINT("WindowObject->SystemMenu = 0x%x\n", Window
->SystemMenu
);
1939 RETURN((HWND
)Handle
);
1942 if (Window
) UserDerefObjectCo(Window
);
1943 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
1949 NtUserCreateWindowEx(DWORD dwExStyle
,
1950 PUNICODE_STRING UnsafeClassName
,
1951 PUNICODE_STRING UnsafeWindowName
,
1959 HINSTANCE hInstance
,
1962 BOOL bUnicodeWindow
)
1965 UNICODE_STRING WindowName
;
1966 UNICODE_STRING ClassName
;
1968 DECLARE_RETURN(HWND
);
1970 DPRINT("Enter NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
1971 UserEnterExclusive();
1973 /* Get the class name (string or atom) */
1974 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
1975 if (! NT_SUCCESS(Status
))
1977 SetLastNtError(Status
);
1980 if (! IS_ATOM(ClassName
.Buffer
))
1982 Status
= IntSafeCopyUnicodeStringTerminateNULL(&ClassName
, UnsafeClassName
);
1983 if (! NT_SUCCESS(Status
))
1985 SetLastNtError(Status
);
1990 /* safely copy the window name */
1991 if (NULL
!= UnsafeWindowName
)
1993 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
1994 if (! NT_SUCCESS(Status
))
1996 if (! IS_ATOM(ClassName
.Buffer
))
1998 RtlFreeUnicodeString(&ClassName
);
2000 SetLastNtError(Status
);
2006 RtlInitUnicodeString(&WindowName
, NULL
);
2009 NewWindow
= co_IntCreateWindowEx(dwExStyle
, &ClassName
, &WindowName
, dwStyle
, x
, y
, nWidth
, nHeight
,
2010 hWndParent
, hMenu
, hInstance
, lpParam
, dwShowMode
, bUnicodeWindow
);
2012 RtlFreeUnicodeString(&WindowName
);
2013 if (! IS_ATOM(ClassName
.Buffer
))
2015 RtlFreeUnicodeString(&ClassName
);
2021 DPRINT("Leave NtUserCreateWindowEx, ret=%i\n",_ret_
);
2030 NtUserDeferWindowPos(HDWP WinPosInfo
,
2032 HWND WndInsertAfter
,
2045 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2049 ASSERT_REFS_CO(Window
); //fixme: temp hack?
2051 /* Check for owner thread and desktop window */
2052 if ((Window
->OwnerThread
!= PsGetCurrentThread()) || IntIsDesktopWindow(Window
))
2054 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2058 /* Look whether the focus is within the tree of windows we will
2061 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2063 if (UserGetActiveWindow() == Window
->hSelf
)
2065 co_WinPosActivateOtherWindow(Window
);
2069 if (Window
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2070 Window
->MessageQueue
->ActiveWindow
= NULL
;
2071 if (Window
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2072 Window
->MessageQueue
->FocusWindow
= NULL
;
2073 if (Window
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2074 Window
->MessageQueue
->CaptureWindow
= NULL
;
2076 IntDereferenceMessageQueue(Window
->MessageQueue
);
2080 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hwnd
, 0, TRUE
))
2086 IntEngWindowChanged(Window
, WOC_DELETE
);
2087 isChild
= (0 != (Window
->Style
& WS_CHILD
));
2093 if (! USER_IsExitingThread(GetCurrentThreadId()))
2095 send_parent_notify(hwnd
, WM_DESTROY
);
2098 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2100 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2101 /* FIXME: clean up palette - see "Internals" p.352 */
2105 if (!IntIsWindow(Window
->hSelf
))
2110 /* Recursively destroy owned windows */
2115 BOOL GotOne
= FALSE
;
2118 PWINDOW_OBJECT Child
, Desktop
;
2120 Desktop
= UserGetWindowObject(IntGetDesktopWindow());
2121 Children
= IntWinListChildren(Desktop
);
2125 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2127 Child
= UserGetWindowObject(*ChildHandle
);
2130 if (Child
->hOwner
!= Window
->hSelf
)
2135 if (IntWndBelongsToThread(Child
, PsGetWin32Thread()))
2138 UserRefObjectCo(Child
);//temp hack?
2139 co_UserDestroyWindow(Child
);
2140 UserDerefObjectCo(Child
);//temp hack?
2146 if (Child
->hOwner
!= NULL
)
2148 Child
->hOwner
= NULL
;
2152 ExFreePool(Children
);
2161 if (!IntIsWindow(Window
->hSelf
))
2166 /* Destroy the window storage */
2167 co_IntDestroyWindow(Window
, PsGetWin32Process(), PsGetWin32Thread(), TRUE
);
2179 NtUserDestroyWindow(HWND Wnd
)
2181 PWINDOW_OBJECT Window
;
2182 DECLARE_RETURN(BOOLEAN
);
2185 DPRINT("Enter NtUserDestroyWindow\n");
2186 UserEnterExclusive();
2188 if (!(Window
= UserGetWindowObject(Wnd
)))
2193 UserRefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2194 ret
= co_UserDestroyWindow(Window
);
2195 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2200 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2212 NtUserDrawMenuBarTemp(
2219 /* we'll use this function just for caching the menu bar */
2229 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2242 NtUserFillWindow(DWORD Unknown0
,
2254 IntFindWindow(PWINDOW_OBJECT Parent
,
2255 PWINDOW_OBJECT ChildAfter
,
2257 PUNICODE_STRING WindowName
)
2259 BOOL CheckWindowName
;
2265 CheckWindowName
= (WindowName
&& (WindowName
->Length
> 0));
2267 if((List
= IntWinListChildren(Parent
)))
2272 /* skip handles before and including ChildAfter */
2273 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2277 /* search children */
2280 PWINDOW_OBJECT Child
;
2281 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2286 /* Do not send WM_GETTEXT messages in the kernel mode version!
2287 The user mode version however calls GetWindowText() which will
2288 send WM_GETTEXT messages to windows belonging to its processes */
2289 if((!CheckWindowName
|| !RtlCompareUnicodeString(WindowName
, &(Child
->WindowName
), FALSE
)) &&
2290 (!ClassAtom
|| Child
->Class
->Atom
== ClassAtom
))
2305 * Searches a window's children for a window with the specified
2308 * hwndParent = The window whose childs are to be searched.
2310 * HWND_MESSAGE = message-only windows
2312 * hwndChildAfter = Search starts after this child window.
2313 * NULL = start from beginning
2315 * ucClassName = Class name to search for
2316 * Reguired parameter.
2318 * ucWindowName = Window name
2319 * ->Buffer == NULL = don't care
2322 * The HWND of the window if it was found, otherwise NULL
2328 NtUserFindWindowEx(HWND hwndParent
,
2329 HWND hwndChildAfter
,
2330 PUNICODE_STRING ucClassName
,
2331 PUNICODE_STRING ucWindowName
)
2333 PWINDOW_OBJECT Parent
, ChildAfter
;
2334 UNICODE_STRING ClassName
, WindowName
;
2336 HWND Desktop
, Ret
= NULL
;
2338 DECLARE_RETURN(HWND
);
2340 DPRINT("Enter NtUserFindWindowEx\n");
2343 Desktop
= IntGetCurrentThreadDesktopWindow();
2345 if(hwndParent
== NULL
)
2346 hwndParent
= Desktop
;
2348 else if(hwndParent == HWND_MESSAGE)
2350 hwndParent = IntGetMessageWindow();
2354 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2360 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2365 /* copy the window name */
2366 Status
= IntSafeCopyUnicodeString(&WindowName
, ucWindowName
);
2367 if(!NT_SUCCESS(Status
))
2369 SetLastNtError(Status
);
2373 /* safely copy the class name */
2374 Status
= MmCopyFromCaller(&ClassName
, ucClassName
, sizeof(UNICODE_STRING
));
2375 if(!NT_SUCCESS(Status
))
2377 SetLastNtError(Status
);
2380 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2383 /* safely copy the class name string (NULL terminated because class-lookup
2385 buf
= ExAllocatePoolWithTag(PagedPool
, ClassName
.Length
+ sizeof(WCHAR
), TAG_STRING
);
2388 SetLastWin32Error(STATUS_INSUFFICIENT_RESOURCES
);
2391 Status
= MmCopyFromCaller(buf
, ClassName
.Buffer
, ClassName
.Length
);
2392 if(!NT_SUCCESS(Status
))
2395 SetLastNtError(Status
);
2398 ClassName
.Buffer
= buf
;
2399 /* make sure the string is null-terminated */
2400 buf
+= ClassName
.Length
/ sizeof(WCHAR
);
2404 /* find the class object */
2405 if(ClassName
.Buffer
)
2407 PWINSTATION_OBJECT WinStaObject
;
2409 if (PsGetWin32Thread()->Desktop
== NULL
)
2411 SetLastWin32Error(ERROR_INVALID_HANDLE
);
2415 WinStaObject
= PsGetWin32Thread()->Desktop
->WindowStation
;
2417 Status
= RtlLookupAtomInAtomTable(
2418 WinStaObject
->AtomTable
,
2422 if (!NT_SUCCESS(Status
))
2424 DPRINT1("Failed to lookup class atom!\n");
2425 SetLastWin32Error(ERROR_CLASS_DOES_NOT_EXIST
);
2430 if(Parent
->hSelf
== Desktop
)
2433 PWINDOW_OBJECT TopLevelWindow
;
2434 BOOLEAN CheckWindowName
;
2435 BOOLEAN CheckClassName
;
2436 BOOLEAN WindowMatches
;
2437 BOOLEAN ClassMatches
;
2439 /* windows searches through all top-level windows if the parent is the desktop
2442 if((List
= IntWinListChildren(Parent
)))
2448 /* skip handles before and including ChildAfter */
2449 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2453 CheckWindowName
= WindowName
.Length
> 0;
2454 CheckClassName
= ClassName
.Buffer
!= NULL
;
2456 /* search children */
2459 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2464 /* Do not send WM_GETTEXT messages in the kernel mode version!
2465 The user mode version however calls GetWindowText() which will
2466 send WM_GETTEXT messages to windows belonging to its processes */
2467 WindowMatches
= !CheckWindowName
|| !RtlCompareUnicodeString(
2468 &WindowName
, &TopLevelWindow
->WindowName
, FALSE
);
2469 ClassMatches
= !CheckClassName
||
2470 ClassAtom
== TopLevelWindow
->Class
->Atom
;
2472 if (WindowMatches
&& ClassMatches
)
2474 Ret
= TopLevelWindow
->hSelf
;
2478 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2480 /* window returns the handle of the top-level window, in case it found
2482 Ret
= TopLevelWindow
->hSelf
;
2491 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2495 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2497 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2498 search the message-only windows. Should this also be done if
2499 Parent is the desktop window??? */
2500 PWINDOW_OBJECT MsgWindows
;
2502 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2504 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2510 if(ClassName
.Length
> 0 && ClassName
.Buffer
)
2511 ExFreePool(ClassName
.Buffer
);
2514 RtlFreeUnicodeString(&WindowName
);
2521 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2531 NtUserFlashWindowEx(DWORD Unknown0
)
2542 PWINDOW_OBJECT FASTCALL
UserGetAncestor(PWINDOW_OBJECT Wnd
, UINT Type
)
2544 PWINDOW_OBJECT WndAncestor
, Parent
;
2550 WndAncestor
= Wnd
->Parent
;
2561 if(!(Parent
= WndAncestor
->Parent
))
2565 if(IntIsDesktopWindow(Parent
))
2570 WndAncestor
= Parent
;
2581 PWINDOW_OBJECT Parent
, Old
;
2584 Parent
= IntGetParent(WndAncestor
);
2592 // UserDerefObject(Parent);
2594 WndAncestor
= Parent
;
2614 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2616 PWINDOW_OBJECT Window
, Ancestor
;
2617 DECLARE_RETURN(HWND
);
2619 DPRINT("Enter NtUserGetAncestor\n");
2620 UserEnterExclusive();
2622 if (!(Window
= UserGetWindowObject(hWnd
)))
2627 Ancestor
= UserGetAncestor(Window
, Type
);
2628 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
2630 RETURN(Ancestor
? Ancestor
->hSelf
: NULL
);
2633 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
2639 * Returns client window rectangle relative to the upper-left corner of client area.
2641 * \param hWnd window handle.
2642 * \param Rect pointer to the buffer where the coordinates are returned.
2649 NtUserGetClientRect(HWND hWnd
, LPRECT Rect
)
2651 PWINDOW_OBJECT Window
;
2653 DECLARE_RETURN(BOOL
);
2655 DPRINT("Enter NtUserGetClientRect\n");
2658 if(!(Window
= UserGetWindowObject(hWnd
)))
2663 IntGetClientRect(Window
, &SafeRect
);
2665 if(!NT_SUCCESS(MmCopyToCaller(Rect
, &SafeRect
, sizeof(RECT
))))
2672 DPRINT("Leave NtUserGetClientRect, ret=%i\n",_ret_
);
2682 NtUserGetDesktopWindow()
2684 DECLARE_RETURN(HWND
);
2686 DPRINT("Enter NtUserGetDesktopWindow\n");
2689 RETURN( IntGetDesktopWindow());
2692 DPRINT("Leave NtUserGetDesktopWindow, ret=%i\n",_ret_
);
2702 NtUserGetInternalWindowPos(DWORD Unknown0
,
2716 NtUserGetLastActivePopup(HWND hWnd
)
2719 * This code can't work, because hWndLastPopup member of WINDOW_OBJECT is
2720 * not changed anywhere.
2721 * -- Filip, 01/nov/2003
2727 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2732 hWndLastPopup
= Wnd
->hWndLastPopup
;
2734 return hWndLastPopup
;
2744 * The NtUserGetParent function retrieves a handle to the specified window's
2748 * Note that, despite its name, this function can return an owner window
2749 * instead of a parent window.
2756 NtUserGetParent(HWND hWnd
)
2758 PWINDOW_OBJECT Wnd
, WndParent
;
2759 HWND hWndParent
= NULL
;
2760 DECLARE_RETURN(HWND
);
2762 DPRINT("Enter NtUserGetParent\n");
2763 UserEnterExclusive();
2765 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2770 WndParent
= IntGetParent(Wnd
);
2773 hWndParent
= WndParent
->hSelf
;
2776 RETURN( hWndParent
);
2779 DPRINT("Leave NtUserGetParent, ret=%i\n",_ret_
);
2788 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2790 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
2791 HWND hWndOldParent
= NULL
;
2793 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
2795 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2799 if (hWndChild
== IntGetDesktopWindow())
2801 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2807 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
2814 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
2820 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
2825 UserRefObjectCo(Wnd
);
2826 UserRefObjectCo(WndParent
);
2828 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
2830 UserDerefObjectCo(WndParent
);
2831 UserDerefObjectCo(Wnd
);
2835 hWndOldParent
= WndOldParent
->hSelf
;
2836 UserDerefObject(WndOldParent
);
2839 return( hWndOldParent
);
2847 * The NtUserSetParent function changes the parent window of the specified
2851 * The new parent window and the child window must belong to the same
2852 * application. If the window identified by the hWndChild parameter is
2853 * visible, the system performs the appropriate redrawing and repainting.
2854 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
2855 * or WS_POPUP window styles of the window whose parent is being changed.
2862 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2864 DECLARE_RETURN(HWND
);
2866 DPRINT("Enter NtUserSetParent\n");
2867 UserEnterExclusive();
2869 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
2872 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
2880 HWND FASTCALL
UserGetShellWindow()
2882 PWINSTATION_OBJECT WinStaObject
;
2885 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
2890 if (!NT_SUCCESS(Status
))
2892 SetLastNtError(Status
);
2896 Ret
= (HWND
)WinStaObject
->ShellWindow
;
2898 ObDereferenceObject(WinStaObject
);
2904 * NtUserGetShellWindow
2906 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
2913 NtUserGetShellWindow()
2915 DECLARE_RETURN(HWND
);
2917 DPRINT("Enter NtUserGetShellWindow\n");
2920 RETURN( UserGetShellWindow() );
2923 DPRINT("Leave NtUserGetShellWindow, ret=%i\n",_ret_
);
2929 * NtUserSetShellWindowEx
2931 * This is undocumented function to set global shell window. The global
2932 * shell window has special handling of window position.
2939 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
2941 PWINSTATION_OBJECT WinStaObject
;
2942 PWINDOW_OBJECT WndShell
;
2943 DECLARE_RETURN(BOOL
);
2945 DPRINT("Enter NtUserSetShellWindowEx\n");
2946 UserEnterExclusive();
2948 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
2953 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
2958 if (!NT_SUCCESS(Status
))
2960 SetLastNtError(Status
);
2965 * Test if we are permitted to change the shell window.
2967 if (WinStaObject
->ShellWindow
)
2969 ObDereferenceObject(WinStaObject
);
2974 * Move shell window into background.
2976 if (hwndListView
&& hwndListView
!= hwndShell
)
2979 * Disabled for now to get Explorer working.
2980 * -- Filip, 01/nov/2003
2983 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
2986 if (UserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2988 ObDereferenceObject(WinStaObject
);
2993 if (UserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
2995 ObDereferenceObject(WinStaObject
);
2999 UserRefObjectCo(WndShell
);
3000 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3002 WinStaObject
->ShellWindow
= hwndShell
;
3003 WinStaObject
->ShellListView
= hwndListView
;
3005 UserDerefObjectCo(WndShell
);
3007 ObDereferenceObject(WinStaObject
);
3011 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3017 * NtUserGetSystemMenu
3019 * The NtUserGetSystemMenu function allows the application to access the
3020 * window menu (also known as the system menu or the control menu) for
3021 * copying and modifying.
3025 * Handle to the window that will own a copy of the window menu.
3027 * Specifies the action to be taken. If this parameter is FALSE,
3028 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3029 * currently in use. The copy is initially identical to the window menu
3030 * but it can be modified.
3031 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3032 * to the default state. The previous window menu, if any, is destroyed.
3035 * If the bRevert parameter is FALSE, the return value is a handle to a
3036 * copy of the window menu. If the bRevert parameter is TRUE, the return
3044 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3046 PWINDOW_OBJECT Window
;
3048 DECLARE_RETURN(HMENU
);
3050 DPRINT("Enter NtUserGetSystemMenu\n");
3053 if (!(Window
= UserGetWindowObject(hWnd
)))
3058 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3063 RETURN(Menu
->MenuInfo
.Self
);
3066 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3072 * NtUserSetSystemMenu
3079 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3081 BOOL Result
= FALSE
;
3082 PWINDOW_OBJECT Window
;
3084 DECLARE_RETURN(BOOL
);
3086 DPRINT("Enter NtUserSetSystemMenu\n");
3087 UserEnterExclusive();
3089 if (!(Window
= UserGetWindowObject(hWnd
)))
3097 * Assign new menu handle.
3099 if (!(Menu
= UserGetMenuObject(hMenu
)))
3104 Result
= IntSetSystemMenu(Window
, Menu
);
3110 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3119 UserGetWindow(HWND hWnd
, UINT Relationship
)
3121 PWINDOW_OBJECT Parent
, Window
;
3122 HWND hWndResult
= NULL
;
3124 if (!(Window
= UserGetWindowObject(hWnd
)))
3127 switch (Relationship
)
3130 if((Parent
= Window
->Parent
))
3132 if (Parent
->FirstChild
)
3133 hWndResult
= Parent
->FirstChild
->hSelf
;
3138 if((Parent
= Window
->Parent
))
3140 if (Parent
->LastChild
)
3141 hWndResult
= Parent
->LastChild
->hSelf
;
3146 if (Window
->NextSibling
)
3147 hWndResult
= Window
->NextSibling
->hSelf
;
3151 if (Window
->PrevSibling
)
3152 hWndResult
= Window
->PrevSibling
->hSelf
;
3156 if((Parent
= UserGetWindowObject(Window
->hOwner
)))
3158 hWndResult
= Parent
->hSelf
;
3162 if (Window
->FirstChild
)
3163 hWndResult
= Window
->FirstChild
->hSelf
;
3175 * The NtUserGetWindow function retrieves a handle to a window that has the
3176 * specified relationship (Z order or owner) to the specified window.
3183 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3185 DECLARE_RETURN(HWND
);
3187 DPRINT("Enter NtUserGetWindow\n");
3190 RETURN(UserGetWindow(hWnd
, Relationship
));
3193 DPRINT("Leave NtUserGetWindow, ret=%i\n",_ret_
);
3202 * NtUserGetWindowLong
3204 * The NtUserGetWindowLong function retrieves information about the specified
3205 * window. The function also retrieves the 32-bit (long) value at the
3206 * specified offset into the extra window memory.
3213 UserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3215 PWINDOW_OBJECT Window
, Parent
;
3218 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3220 if (!(Window
= UserGetWindowObject(hWnd
)))
3226 * WndProc is only available to the owner process
3228 if (GWL_WNDPROC
== Index
3229 && Window
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3231 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3235 if ((INT
)Index
>= 0)
3237 if ((Index
+ sizeof(LONG
)) > Window
->ExtraDataSize
)
3239 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3242 Result
= *((LONG
*)(Window
->ExtraData
+ Index
));
3249 Result
= Window
->ExStyle
;
3253 Result
= Window
->Style
;
3258 Result
= (LONG
) Window
->WndProcA
;
3260 Result
= (LONG
) Window
->WndProcW
;
3264 Result
= (LONG
) Window
->Instance
;
3267 case GWL_HWNDPARENT
:
3268 Parent
= Window
->Parent
;
3271 if (Parent
&& Parent
->hSelf
== IntGetDesktopWindow())
3272 Result
= (LONG
) UserGetWindow(Window
->hSelf
, GW_OWNER
);
3274 Result
= (LONG
) Parent
->hSelf
;
3279 Result
= (LONG
) Window
->IDMenu
;
3283 Result
= Window
->UserData
;
3287 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3288 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3301 * NtUserGetWindowLong
3303 * The NtUserGetWindowLong function retrieves information about the specified
3304 * window. The function also retrieves the 32-bit (long) value at the
3305 * specified offset into the extra window memory.
3312 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3314 DECLARE_RETURN(LONG
);
3316 DPRINT("Enter NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3317 UserEnterExclusive();
3319 RETURN(UserGetWindowLong(hWnd
, Index
, Ansi
));
3322 DPRINT("Leave NtUserGetWindowLong, ret=%i\n",_ret_
);
3331 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3333 PWINDOW_OBJECT Window
, Parent
;
3334 PWINSTATION_OBJECT WindowStation
;
3338 if (hWnd
== IntGetDesktopWindow())
3340 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3344 if (!(Window
= UserGetWindowObject(hWnd
)))
3349 if ((INT
)Index
>= 0)
3351 if ((Index
+ sizeof(LONG
)) > Window
->ExtraDataSize
)
3353 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3356 OldValue
= *((LONG
*)(Window
->ExtraData
+ Index
));
3357 *((LONG
*)(Window
->ExtraData
+ Index
)) = NewValue
;
3364 OldValue
= (LONG
) Window
->ExStyle
;
3365 Style
.styleOld
= OldValue
;
3366 Style
.styleNew
= NewValue
;
3369 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3371 WindowStation
= Window
->OwnerThread
->Tcb
.Win32Thread
->Desktop
->WindowStation
;
3374 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3375 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3378 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3379 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3380 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3384 OldValue
= (LONG
) Window
->Style
;
3385 Style
.styleOld
= OldValue
;
3386 Style
.styleNew
= NewValue
;
3387 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3388 Window
->Style
= (DWORD
)Style
.styleNew
;
3389 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3393 /* FIXME: should check if window belongs to current process */
3396 OldValue
= (LONG
) Window
->WndProcA
;
3397 Window
->WndProcA
= (WNDPROC
) NewValue
;
3398 Window
->WndProcW
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,FALSE
);
3399 Window
->Unicode
= FALSE
;
3403 OldValue
= (LONG
) Window
->WndProcW
;
3404 Window
->WndProcW
= (WNDPROC
) NewValue
;
3405 Window
->WndProcA
= (WNDPROC
) IntAddWndProcHandle((WNDPROC
)NewValue
,TRUE
);
3406 Window
->Unicode
= TRUE
;
3411 OldValue
= (LONG
) Window
->Instance
;
3412 Window
->Instance
= (HINSTANCE
) NewValue
;
3415 case GWL_HWNDPARENT
:
3416 Parent
= Window
->Parent
;
3417 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
3418 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
3420 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
3424 OldValue
= (LONG
) Window
->IDMenu
;
3425 Window
->IDMenu
= (UINT
) NewValue
;
3429 OldValue
= Window
->UserData
;
3430 Window
->UserData
= NewValue
;
3434 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3435 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3447 * NtUserSetWindowLong
3449 * The NtUserSetWindowLong function changes an attribute of the specified
3450 * window. The function also sets the 32-bit (long) value at the specified
3451 * offset into the extra window memory.
3458 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3460 DECLARE_RETURN(LONG
);
3462 DPRINT("Enter NtUserSetWindowLong\n");
3463 UserEnterExclusive();
3465 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3468 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3474 * NtUserSetWindowWord
3476 * Legacy function similar to NtUserSetWindowLong.
3483 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3485 PWINDOW_OBJECT Window
;
3487 DECLARE_RETURN(WORD
);
3489 DPRINT("Enter NtUserSetWindowWord\n");
3490 UserEnterExclusive();
3492 if (!(Window
= UserGetWindowObject(hWnd
)))
3501 case GWL_HWNDPARENT
:
3502 RETURN( co_UserSetWindowLong(Window
->hSelf
, Index
, (UINT
)NewValue
, TRUE
));
3506 SetLastWin32Error(ERROR_INVALID_INDEX
);
3511 if (Index
> Window
->ExtraDataSize
- sizeof(WORD
))
3513 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3517 OldValue
= *((WORD
*)(Window
->ExtraData
+ Index
));
3518 *((WORD
*)(Window
->ExtraData
+ Index
)) = NewValue
;
3523 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3532 NtUserGetWindowPlacement(HWND hWnd
,
3533 WINDOWPLACEMENT
*lpwndpl
)
3535 PWINDOW_OBJECT Window
;
3536 PINTERNALPOS InternalPos
;
3538 WINDOWPLACEMENT Safepl
;
3540 DECLARE_RETURN(BOOL
);
3542 DPRINT("Enter NtUserGetWindowPlacement\n");
3545 if (!(Window
= UserGetWindowObject(hWnd
)))
3550 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3551 if(!NT_SUCCESS(Status
))
3553 SetLastNtError(Status
);
3556 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3562 Safepl
.showCmd
= ((Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ? SW_MAXIMIZE
: SW_SHOWNORMAL
);
3564 Size
.x
= Window
->WindowRect
.left
;
3565 Size
.y
= Window
->WindowRect
.top
;
3566 InternalPos
= WinPosInitInternalPos(Window
, &Size
,
3567 &Window
->WindowRect
);
3570 Safepl
.rcNormalPosition
= InternalPos
->NormalRect
;
3571 Safepl
.ptMinPosition
= InternalPos
->IconPos
;
3572 Safepl
.ptMaxPosition
= InternalPos
->MaxPos
;
3579 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3580 if(!NT_SUCCESS(Status
))
3582 SetLastNtError(Status
);
3589 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
3596 * Return the dimension of the window in the screen coordinates.
3597 * \param hWnd window handle.
3598 * \param Rect pointer to the buffer where the coordinates are returned.
3604 NtUserGetWindowRect(HWND hWnd
, LPRECT Rect
)
3608 DECLARE_RETURN(BOOL
);
3610 DPRINT("Enter NtUserGetWindowRect\n");
3613 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3617 Status
= MmCopyToCaller(Rect
, &Wnd
->WindowRect
, sizeof(RECT
));
3618 if (!NT_SUCCESS(Status
))
3620 SetLastNtError(Status
);
3627 DPRINT("Leave NtUserGetWindowRect, ret=%i\n",_ret_
);
3637 NtUserGetWindowThreadProcessId(HWND hWnd
, LPDWORD UnsafePid
)
3641 DECLARE_RETURN(DWORD
);
3643 DPRINT("Enter NtUserGetWindowThreadProcessId\n");
3646 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3651 tid
= (DWORD
)IntGetWndThreadId(Wnd
);
3652 pid
= (DWORD
)IntGetWndProcessId(Wnd
);
3655 MmCopyToCaller(UnsafePid
, &pid
, sizeof(DWORD
));
3660 DPRINT("Leave NtUserGetWindowThreadProcessId, ret=%i\n",_ret_
);
3670 NtUserLockWindowUpdate(DWORD Unknown0
)
3690 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3691 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3692 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3696 QueryWindow based on KJK::Hyperion and James Tabor.
3698 0 = QWUniqueProcessId
3699 1 = QWUniqueThreadId
3700 4 = QWIsHung Implements IsHungAppWindow found
3703 9 = QWKillWindow When I called this with hWnd ==
3704 DesktopWindow, it shutdown the system
3711 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3713 PWINDOW_OBJECT Window
;
3715 DECLARE_RETURN(UINT
);
3717 DPRINT("Enter NtUserQueryWindow\n");
3720 if (!(Window
= UserGetWindowObject(hWnd
)))
3727 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3728 Result
= (DWORD
)IntGetWndProcessId(Window
);
3731 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3732 Result
= (DWORD
)IntGetWndThreadId(Window
);
3735 case QUERY_WINDOW_ISHUNG
:
3736 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
3740 Result
= (DWORD
)NULL
;
3747 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3757 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3771 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3773 UNICODE_STRING SafeMessageName
;
3776 DECLARE_RETURN(UINT
);
3778 DPRINT("Enter NtUserRegisterWindowMessage\n");
3779 UserEnterExclusive();
3781 if(MessageNameUnsafe
== NULL
)
3783 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3787 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3788 if(!NT_SUCCESS(Status
))
3790 SetLastNtError(Status
);
3794 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3796 RtlFreeUnicodeString(&SafeMessageName
);
3800 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3810 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3823 NtUserSetInternalWindowPos(DWORD Unknown0
,
3839 NtUserSetLayeredWindowAttributes(DWORD Unknown0
,
3854 NtUserSetLogonNotifyWindow(DWORD Unknown0
)
3871 PWINDOW_OBJECT Window
;
3873 DECLARE_RETURN(BOOL
);
3875 DPRINT("Enter NtUserSetMenu\n");
3876 UserEnterExclusive();
3878 if (!(Window
= UserGetWindowObject(hWnd
)))
3883 if (! IntSetMenu(Window
, Menu
, &Changed
))
3888 if (Changed
&& Repaint
)
3890 UserRefObjectCo(Window
);
3891 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3892 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3894 UserDerefObjectCo(Window
);
3900 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3910 NtUserSetWindowFNID(DWORD Unknown0
,
3924 NtUserSetWindowPlacement(HWND hWnd
,
3925 WINDOWPLACEMENT
*lpwndpl
)
3927 PWINDOW_OBJECT Window
;
3928 WINDOWPLACEMENT Safepl
;
3930 DECLARE_RETURN(BOOL
);
3932 DPRINT("Enter NtUserSetWindowPlacement\n");
3933 UserEnterExclusive();
3935 if (!(Window
= UserGetWindowObject(hWnd
)))
3939 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3940 if(!NT_SUCCESS(Status
))
3942 SetLastNtError(Status
);
3945 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3950 UserRefObjectCo(Window
);
3952 if ((Window
->Style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
3954 co_WinPosSetWindowPos(Window
, NULL
,
3955 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
3956 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
3957 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
3958 SWP_NOZORDER
| SWP_NOACTIVATE
);
3961 /* FIXME - change window status */
3962 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
3964 if (Window
->InternalPos
== NULL
)
3965 Window
->InternalPos
= ExAllocatePoolWithTag(PagedPool
, sizeof(INTERNALPOS
), TAG_WININTLIST
);
3966 Window
->InternalPos
->NormalRect
= Safepl
.rcNormalPosition
;
3967 Window
->InternalPos
->IconPos
= Safepl
.ptMinPosition
;
3968 Window
->InternalPos
->MaxPos
= Safepl
.ptMaxPosition
;
3970 UserDerefObjectCo(Window
);
3974 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
3986 HWND hWndInsertAfter
,
3993 DECLARE_RETURN(BOOL
);
3994 PWINDOW_OBJECT Window
;
3997 DPRINT("Enter NtUserSetWindowPos\n");
3998 UserEnterExclusive();
4000 if (!(Window
= UserGetWindowObject(hWnd
)))
4005 UserRefObjectCo(Window
);
4006 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4007 UserDerefObjectCo(Window
);
4012 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4019 IntGetWindowRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
4034 /* Create a new window region using the window rectangle */
4035 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
4036 NtGdiOffsetRgn(VisRgn
, -Window
->WindowRect
.left
, -Window
->WindowRect
.top
);
4037 /* if there's a region assigned to the window, combine them both */
4038 if(Window
->WindowRegion
&& !(Window
->Style
& WS_MINIMIZE
))
4039 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4040 /* Copy the region into hRgn */
4041 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4043 if((pRgn
= RGNDATA_LockRgn(hRgn
)))
4045 Ret
= pRgn
->rdh
.iType
;
4046 RGNDATA_UnlockRgn(pRgn
);
4051 NtGdiDeleteObject(VisRgn
);
4057 IntGetWindowRgnBox(PWINDOW_OBJECT Window
, RECT
*Rect
)
4072 /* Create a new window region using the window rectangle */
4073 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->WindowRect
);
4074 NtGdiOffsetRgn(VisRgn
, -Window
->WindowRect
.left
, -Window
->WindowRect
.top
);
4075 /* if there's a region assigned to the window, combine them both */
4076 if(Window
->WindowRegion
&& !(Window
->Style
& WS_MINIMIZE
))
4077 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4079 if((pRgn
= RGNDATA_LockRgn(VisRgn
)))
4081 Ret
= pRgn
->rdh
.iType
;
4082 *Rect
= pRgn
->rdh
.rcBound
;
4083 RGNDATA_UnlockRgn(pRgn
);
4088 NtGdiDeleteObject(VisRgn
);
4103 PWINDOW_OBJECT Window
;
4104 DECLARE_RETURN(INT
);
4106 DPRINT("Enter NtUserSetWindowRgn\n");
4107 UserEnterExclusive();
4109 if (!(Window
= UserGetWindowObject(hWnd
)))
4114 /* FIXME - Verify if hRgn is a valid handle!!!!
4115 Propably make this operation thread-safe, but maybe it's not necessary */
4117 if(Window
->WindowRegion
)
4119 /* Delete no longer needed region handle */
4120 NtGdiDeleteObject(Window
->WindowRegion
);
4122 Window
->WindowRegion
= hRgn
;
4124 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4128 UserRefObjectCo(Window
);
4129 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4130 UserDerefObjectCo(Window
);
4136 DPRINT("Leave NtUserSystemParametersInfo, ret=%i\n",_ret_
);
4146 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4148 PWINDOW_OBJECT Window
;
4150 DECLARE_RETURN(BOOL
);
4152 DPRINT("Enter NtUserShowWindow\n");
4153 UserEnterExclusive();
4155 if (!(Window
= UserGetWindowObject(hWnd
)))
4160 UserRefObjectCo(Window
);
4161 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4162 UserDerefObjectCo(Window
);
4167 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4177 NtUserShowWindowAsync(DWORD Unknown0
,
4190 NtUserUpdateLayeredWindow(DWORD Unknown0
,
4210 NtUserValidateRect(HWND hWnd
, const RECT
* Rect
)
4212 return (VOID
)NtUserRedrawWindow(hWnd
, Rect
, 0, RDW_VALIDATE
| RDW_NOCHILDREN
);
4220 NtUserWindowFromPoint(LONG X
, LONG Y
)
4224 PWINDOW_OBJECT DesktopWindow
= NULL
, Window
= NULL
;
4225 DECLARE_RETURN(HWND
);
4227 DPRINT("Enter NtUserWindowFromPoint\n");
4228 UserEnterExclusive();
4230 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4237 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4238 //its possible this referencing is useless, thou it shouldnt hurt...
4239 UserRefObjectCo(DesktopWindow
);
4241 Hit
= co_WinPosWindowFromPoint(DesktopWindow
, PsGetWin32Thread()->MessageQueue
, &pt
, &Window
);
4245 Ret
= Window
->hSelf
;
4254 if (Window
) UserDerefObject(Window
);
4255 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4257 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4267 * Undocumented function that is called from DefWindowProc to set
4275 NtUserDefSetText(HWND hWnd
, PUNICODE_STRING WindowText
)
4277 PWINDOW_OBJECT Window
;
4278 UNICODE_STRING SafeText
;
4280 DECLARE_RETURN(INT
);
4282 DPRINT("Enter NtUserDefSetText\n");
4283 UserEnterExclusive();
4285 if(!(Window
= UserGetWindowObject(hWnd
)))
4292 Status
= IntSafeCopyUnicodeString(&SafeText
, WindowText
);
4293 if(!NT_SUCCESS(Status
))
4295 SetLastNtError(Status
);
4301 RtlInitUnicodeString(&SafeText
, NULL
);
4304 /* FIXME - do this thread-safe! otherwise one could crash here! */
4305 RtlFreeUnicodeString(&Window
->WindowName
);
4307 Window
->WindowName
= SafeText
;
4309 /* Send shell notifications */
4310 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
4312 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4318 DPRINT("Leave NtUserDefSetText, ret=%i\n",_ret_
);
4324 * NtUserInternalGetWindowText
4331 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4333 PWINDOW_OBJECT Window
;
4336 DECLARE_RETURN(INT
);
4338 DPRINT("Enter NtUserInternalGetWindowText\n");
4341 if(lpString
&& (nMaxCount
<= 1))
4343 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4347 if(!(Window
= UserGetWindowObject(hWnd
)))
4352 /* FIXME - do this thread-safe! otherwise one could crash here! */
4353 Result
= Window
->WindowName
.Length
/ sizeof(WCHAR
);
4356 const WCHAR Terminator
= L
'\0';
4358 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4360 Copy
= min(nMaxCount
- 1, Result
);
4363 Status
= MmCopyToCaller(Buffer
, Window
->WindowName
.Buffer
, Copy
* sizeof(WCHAR
));
4364 if(!NT_SUCCESS(Status
))
4366 SetLastNtError(Status
);
4372 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4373 if(!NT_SUCCESS(Status
))
4375 SetLastNtError(Status
);
4385 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4391 NtUserDereferenceWndProcHandle(WNDPROC wpHandle
, WndProcHandle
*Data
)
4393 DECLARE_RETURN(DWORD
);
4395 DPRINT("Enter NtUserDereferenceWndProcHandle\n");
4398 WndProcHandle Entry
;
4399 if (((DWORD
)wpHandle
& 0xFFFF0000) == 0xFFFF0000)
4401 Entry
= WndProcHandlesArray
[(DWORD
)wpHandle
& 0x0000FFFF];
4402 Data
->WindowProc
= Entry
.WindowProc
;
4403 Data
->IsUnicode
= Entry
.IsUnicode
;
4404 Data
->ProcessID
= Entry
.ProcessID
;
4414 DPRINT("Leave NtUserDereferenceWndProcHandle, ret=%i\n",_ret_
);
4420 IntAddWndProcHandle(WNDPROC WindowProc
, BOOL IsUnicode
)
4425 WndProcHandle
*OldArray
;
4428 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4430 if (WndProcHandlesArray
[i
].WindowProc
== NULL
)
4438 OldArray
= WndProcHandlesArray
;
4439 OldArraySize
= WndProcHandlesArraySize
;
4440 WndProcHandlesArray
= ExAllocatePoolWithTag(PagedPool
,(OldArraySize
+ WPH_SIZE
) * sizeof(WndProcHandle
), TAG_WINPROCLST
);
4441 WndProcHandlesArraySize
= OldArraySize
+ WPH_SIZE
;
4442 RtlCopyMemory(WndProcHandlesArray
,OldArray
,OldArraySize
* sizeof(WndProcHandle
));
4443 ExFreePool(OldArray
);
4444 FreeSpot
= OldArraySize
+ 1;
4446 WndProcHandlesArray
[FreeSpot
].WindowProc
= WindowProc
;
4447 WndProcHandlesArray
[FreeSpot
].IsUnicode
= IsUnicode
;
4448 WndProcHandlesArray
[FreeSpot
].ProcessID
= PsGetCurrentProcessId();
4449 return FreeSpot
+ 0xFFFF0000;
4453 IntRemoveWndProcHandle(WNDPROC Handle
)
4456 position
= (DWORD
)Handle
& 0x0000FFFF;
4457 if (position
> WndProcHandlesArraySize
)
4461 WndProcHandlesArray
[position
].WindowProc
= NULL
;
4462 WndProcHandlesArray
[position
].IsUnicode
= FALSE
;
4463 WndProcHandlesArray
[position
].ProcessID
= NULL
;
4468 IntRemoveProcessWndProcHandles(HANDLE ProcessID
)
4471 for (i
= 0;i
< WndProcHandlesArraySize
;i
++)
4473 if (WndProcHandlesArray
[i
].ProcessID
== ProcessID
)
4475 WndProcHandlesArray
[i
].WindowProc
= NULL
;
4476 WndProcHandlesArray
[i
].IsUnicode
= FALSE
;
4477 WndProcHandlesArray
[i
].ProcessID
= NULL
;
4483 #define WIN_NEEDS_SHOW_OWNEDPOPUP (0x00000040)
4487 IntShowOwnedPopups(PWINDOW_OBJECT OwnerWnd
, BOOL fShow
)
4490 PWINDOW_OBJECT pWnd
;
4495 win_array
= IntWinListChildren(OwnerWnd
);//faxme: use desktop?
4500 while (win_array
[count
])
4502 while (--count
>= 0)
4504 if (UserGetWindow( win_array
[count
], GW_OWNER
) != OwnerWnd
->hSelf
)
4506 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4508 // if (pWnd == WND_OTHER_PROCESS) continue;
4512 if (pWnd
->Flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
)
4514 /* In Windows, ShowOwnedPopups(TRUE) generates
4515 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4516 * regardless of the state of the owner
4518 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4524 if (pWnd
->Style
& WS_VISIBLE
)
4526 /* In Windows, ShowOwnedPopups(FALSE) generates
4527 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4528 * regardless of the state of the owner
4530 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4536 ExFreePool( win_array
);