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 ******************************************************************/
37 /* dialog resources appear to pass this in 16 bits, handle them properly */
38 #define CW_USEDEFAULT16 (0x8000)
40 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
42 /* PRIVATE FUNCTIONS **********************************************************/
47 * Initialize windowing implementation.
53 return STATUS_SUCCESS
;
59 * Cleanup windowing implementation.
63 CleanupWindowImpl(VOID
)
65 return STATUS_SUCCESS
;
68 /* HELPER FUNCTIONS ***********************************************************/
70 BOOL FASTCALL
UserUpdateUiState(PWINDOW Wnd
, WPARAM wParam
)
72 WORD Action
= LOWORD(wParam
);
73 WORD Flags
= HIWORD(wParam
);
75 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
77 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
84 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
88 if (Flags
& UISF_HIDEFOCUS
)
89 Wnd
->HideFocus
= TRUE
;
90 if (Flags
& UISF_HIDEACCEL
)
91 Wnd
->HideAccel
= TRUE
;
95 if (Flags
& UISF_HIDEFOCUS
)
96 Wnd
->HideFocus
= FALSE
;
97 if (Flags
& UISF_HIDEACCEL
)
98 Wnd
->HideAccel
= FALSE
;
105 PWINDOW_OBJECT FASTCALL
IntGetWindowObject(HWND hWnd
)
107 PWINDOW_OBJECT Window
;
109 if (!hWnd
) return NULL
;
111 Window
= UserGetWindowObject(hWnd
);
114 ASSERT(USER_BODY_TO_HEADER(Window
)->RefCount
>= 0);
116 USER_BODY_TO_HEADER(Window
)->RefCount
++;
122 PWINDOW_OBJECT FASTCALL
UserGetWindowObject(HWND hWnd
)
125 PWINDOW_OBJECT Window
;
127 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
129 ti
= GetW32ThreadInfo();
132 SetLastWin32Error(ERROR_ACCESS_DENIED
);
139 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
143 Window
= (PWINDOW_OBJECT
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
144 if (!Window
|| 0 != (Window
->Status
& WINDOWSTATUS_DESTROYED
))
146 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
150 ASSERT(USER_BODY_TO_HEADER(Window
)->RefCount
>= 0);
158 * The function determines whether the specified window handle identifies
159 * an existing window.
163 * Handle to the window to test.
166 * If the window handle identifies an existing window, the return value
167 * is TRUE. If the window handle does not identify an existing window,
168 * the return value is FALSE.
172 IntIsWindow(HWND hWnd
)
174 PWINDOW_OBJECT Window
;
176 if (!(Window
= UserGetWindowObject(hWnd
)))
185 Caller must NOT dereference retval!
186 But if caller want the returned value to persist spanning a co_ call,
187 it must reference the value (because the owner is not garanteed to
188 exist just because the owned window exist)!
190 PWINDOW_OBJECT FASTCALL
191 IntGetParent(PWINDOW_OBJECT Wnd
)
193 if (!Wnd
->Wnd
) return NULL
;
195 if (Wnd
->Wnd
->Style
& WS_POPUP
)
197 return UserGetWindowObject(Wnd
->hOwner
);
199 else if (Wnd
->Wnd
->Style
& WS_CHILD
)
209 Caller must NOT dereference retval!
210 But if caller want the returned value to persist spanning a co_ call,
211 it must reference the value (because the owner is not garanteed to
212 exist just because the owned window exist)!
214 PWINDOW_OBJECT FASTCALL
215 IntGetOwner(PWINDOW_OBJECT Wnd
)
217 return UserGetWindowObject(Wnd
->hOwner
);
225 * Compile a list of all child window handles from given window.
228 * This function is similar to Wine WIN_ListChildren. The caller
229 * must free the returned list with ExFreePool.
233 IntWinListChildren(PWINDOW_OBJECT Window
)
235 PWINDOW_OBJECT Child
;
237 UINT Index
, NumChildren
= 0;
239 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
242 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
245 DPRINT1("Failed to allocate memory for children array\n");
246 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
249 for (Child
= Window
->FirstChild
, Index
= 0;
251 Child
= Child
->NextSibling
, ++Index
)
252 List
[Index
] = Child
->hSelf
;
258 /***********************************************************************
261 static void IntSendDestroyMsg(HWND hWnd
)
264 PWINDOW_OBJECT Window
;
269 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
271 if (hWnd
== info
.hwndCaret
)
278 Window
= UserGetWindowObject(hWnd
);
281 // USER_REFERENCE_ENTRY Ref;
282 // UserRefObjectCo(Window, &Ref);
284 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
286 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
289 // UserDerefObjectCo(Window);
292 /* The window could already be destroyed here */
295 * Send the WM_DESTROY to the window.
298 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
301 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
302 * make sure that the window still exists when we come back.
311 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
314 /* start from the end (FIXME: is this needed?) */
315 for (i
= 0; pWndArray
[i
]; i
++)
320 if (IsWindow( pWndArray
[i
] ))
321 WIN_SendDestroyMsg( pWndArray
[i
] );
323 HeapFree(GetProcessHeap(), 0, pWndArray
);
327 DPRINT("destroyed itself while in WM_DESTROY!\n");
333 UserFreeWindowInfo(PW32THREADINFO ti
, PWINDOW_OBJECT WindowObject
)
335 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
336 PWINDOW Wnd
= WindowObject
->Wnd
;
338 if (ClientInfo
->CallbackWnd
.pvWnd
== DesktopHeapAddressToUser(WindowObject
->Wnd
))
340 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
341 ClientInfo
->CallbackWnd
.pvWnd
= NULL
;
344 if (Wnd
->WindowName
.Buffer
!= NULL
)
346 Wnd
->WindowName
.Length
= 0;
347 Wnd
->WindowName
.MaximumLength
= 0;
348 DesktopHeapFree(Wnd
->pdesktop
,
349 Wnd
->WindowName
.Buffer
);
350 Wnd
->WindowName
.Buffer
= NULL
;
353 DesktopHeapFree(Wnd
->pdesktop
, Wnd
);
354 WindowObject
->Wnd
= NULL
;
357 /***********************************************************************
360 * Destroy storage associated to a window. "Internals" p.358
362 * This is the "functional" DestroyWindows function ei. all stuff
363 * done in CreateWindow is undone here and not in DestroyWindow:-P
366 static LRESULT
co_UserFreeWindow(PWINDOW_OBJECT Window
,
367 PW32PROCESS ProcessData
,
368 PTHREADINFO ThreadData
,
369 BOOLEAN SendMessages
)
373 PWINDOW_OBJECT Child
;
375 BOOLEAN BelongsToThreadData
;
382 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
384 DPRINT("Tried to call IntDestroyWindow() twice\n");
387 Window
->Status
|= WINDOWSTATUS_DESTROYING
;
388 Wnd
->Style
&= ~WS_VISIBLE
;
389 /* remove the window already at this point from the thread window list so we
390 don't get into trouble when destroying the thread windows while we're still
391 in IntDestroyWindow() */
392 RemoveEntryList(&Window
->ThreadListEntry
);
394 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
396 IntDeRegisterShellHookWindow(Window
->hSelf
);
398 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
->hSelf
, OBJID_WINDOW
, 0);
402 /* Send destroy messages */
403 IntSendDestroyMsg(Window
->hSelf
);
406 /* free child windows */
407 Children
= IntWinListChildren(Window
);
410 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
412 if ((Child
= IntGetWindowObject(*ChildHandle
)))
414 if(!IntWndBelongsToThread(Child
, ThreadData
))
416 /* send WM_DESTROY messages to windows not belonging to the same thread */
417 IntSendDestroyMsg(Child
->hSelf
);
420 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
422 UserDereferenceObject(Child
);
425 ExFreePool(Children
);
431 * Clear the update region to make sure no WM_PAINT messages will be
432 * generated for this window while processing the WM_NCDESTROY.
434 co_UserRedrawWindow(Window
, NULL
, 0,
435 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
436 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
437 if(BelongsToThreadData
)
438 co_IntSendMessage(Window
->hSelf
, WM_NCDESTROY
, 0, 0);
440 MsqRemoveTimersWindow(ThreadData
->MessageQueue
, Window
->hSelf
);
442 /* flush the message queue */
443 MsqRemoveWindowMessagesFromQueue(Window
);
445 /* from now on no messages can be sent to this window anymore */
446 Window
->Status
|= WINDOWSTATUS_DESTROYED
;
447 /* don't remove the WINDOWSTATUS_DESTROYING bit */
449 /* reset shell window handles */
450 if(ThreadData
->Desktop
)
452 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellWindow
)
453 ThreadData
->Desktop
->WindowStation
->ShellWindow
= NULL
;
455 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellListView
)
456 ThreadData
->Desktop
->WindowStation
->ShellListView
= NULL
;
459 /* Unregister hot keys */
460 UnregisterWindowHotKeys (Window
);
462 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
466 WinPosCheckInternalPos(Window
->hSelf
);
467 if (Window
->hSelf
== GetCapture())
472 /* free resources associated with the window */
473 TIMER_RemoveWindowTimers(Window
->hSelf
);
476 if (!(Wnd
->Style
& WS_CHILD
) && Wnd
->IDMenu
477 && (Menu
= UserGetMenuObject((HMENU
)Wnd
->IDMenu
)))
479 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
483 if(Window
->SystemMenu
484 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
486 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
487 Window
->SystemMenu
= (HMENU
)0;
490 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
493 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
494 CLASS_RemoveWindow(Window
->Class
);
497 IntUnlinkWindow(Window
);
499 UserReferenceObject(Window
);
500 UserDeleteObject(Window
->hSelf
, otWindow
);
502 IntDestroyScrollBars(Window
);
504 /* dereference the class */
505 IntDereferenceClass(Wnd
->Class
,
506 Window
->ti
->pDeskInfo
,
510 if(Window
->WindowRegion
)
512 GreDeleteObject(Window
->WindowRegion
);
515 ASSERT(Window
->Wnd
!= NULL
);
516 UserFreeWindowInfo(Window
->ti
, Window
);
518 UserDereferenceObject(Window
);
520 IntClipboardFreeWindow(Window
);
526 IntGetWindowBorderMeasures(PWINDOW_OBJECT Window
, UINT
*cx
, UINT
*cy
)
528 PWINDOW Wnd
= Window
->Wnd
;
529 if(HAS_DLGFRAME(Wnd
->Style
, Wnd
->ExStyle
) && !(Wnd
->Style
& WS_MINIMIZE
))
531 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
532 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
536 if(HAS_THICKFRAME(Wnd
->Style
, Wnd
->ExStyle
)&& !(Wnd
->Style
& WS_MINIMIZE
))
538 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
539 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
541 else if(HAS_THINFRAME(Wnd
->Style
, Wnd
->ExStyle
))
543 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
544 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
554 IntGetWindowProc(IN PWINDOW_OBJECT Window
,
557 PWINDOW Wnd
= Window
->Wnd
;
559 ASSERT(UserIsEnteredExclusive() == TRUE
);
563 return (Ansi
? Wnd
->WndProcExtra
: Wnd
->WndProc
);
567 if (!Ansi
== Wnd
->Unicode
)
573 if (Wnd
->CallProc
!= NULL
)
575 return GetCallProcHandle(Wnd
->CallProc
);
577 /* BUGBOY Comments: Maybe theres something Im not undestanding here, but why would a CallProc be created
578 on a function that I thought is only suppose to return the current Windows Proc? */
581 PCALLPROC NewCallProc
, CallProc
;
583 NewCallProc
= UserFindCallProc(Wnd
->Class
,
586 if (NewCallProc
== NULL
)
588 NewCallProc
= CreateCallProc(Wnd
->ti
->pDeskInfo
,
592 if (NewCallProc
== NULL
)
594 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
598 UserAddCallProcToClass(Wnd
->Class
,
602 CallProc
= Wnd
->CallProc
;
603 Wnd
->CallProc
= NewCallProc
;
605 return GetCallProcHandle((CallProc
== NULL
? NewCallProc
: CallProc
));
612 IntGetWindowInfo(PWINDOW_OBJECT Window
, PWINDOWINFO pwi
)
614 PWINDOW Wnd
= Window
->Wnd
;
616 pwi
->cbSize
= sizeof(WINDOWINFO
);
617 pwi
->rcWindow
= Window
->Wnd
->WindowRect
;
618 pwi
->rcClient
= Window
->Wnd
->ClientRect
;
619 pwi
->dwStyle
= Wnd
->Style
;
620 pwi
->dwExStyle
= Wnd
->ExStyle
;
621 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Window
->hSelf
); /* WS_ACTIVECAPTION */
622 IntGetWindowBorderMeasures(Window
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
623 pwi
->atomWindowType
= (Wnd
->Class
? Wnd
->Class
->Atom
: 0);
624 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
630 PWINDOW_OBJECT Window
,
634 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
635 PWINDOW Wnd
= Window
->Wnd
;
637 if ((Wnd
->Style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
639 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
643 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
651 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
652 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Window
->hSelf
);
661 NewMenu
= IntGetMenuObject(Menu
);
666 IntReleaseMenuObject(OldMenu
);
668 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
671 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
673 /* Can't use the same menu for two windows */
676 IntReleaseMenuObject(OldMenu
);
678 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
684 Wnd
->IDMenu
= (UINT
) Menu
;
687 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
688 IntReleaseMenuObject(NewMenu
);
692 OldMenu
->MenuInfo
.Wnd
= NULL
;
693 IntReleaseMenuObject(OldMenu
);
700 /* INTERNAL ******************************************************************/
704 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
709 USER_REFERENCE_ENTRY Ref
;
710 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
712 while (!IsListEmpty(&WThread
->WindowListHead
))
714 Current
= WThread
->WindowListHead
.Flink
;
715 Wnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
717 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
719 /* window removes itself from the list */
722 fixme: it is critical that the window removes itself! if now, we will loop
726 //ASSERT(co_UserDestroyWindow(Wnd));
728 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
729 if (!co_UserDestroyWindow(Wnd
))
731 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
733 UserDerefObjectCo(Wnd
);//faxme: temp hack??
741 * Returns client window rectangle relative to the upper-left corner of client area.
743 * \note Does not check the validity of the parameters
746 IntGetClientRect(PWINDOW_OBJECT Window
, RECTL
*Rect
)
751 Rect
->left
= Rect
->top
= 0;
752 Rect
->right
= Window
->Wnd
->ClientRect
.right
- Window
->Wnd
->ClientRect
.left
;
753 Rect
->bottom
= Window
->Wnd
->ClientRect
.bottom
- Window
->Wnd
->ClientRect
.top
;
759 IntGetFocusWindow(VOID
)
761 PUSER_MESSAGE_QUEUE Queue
;
762 PDESKTOP pdo
= IntGetActiveDesktop();
767 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
772 return(Queue
->FocusWindow
);
776 PMENU_OBJECT FASTCALL
777 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
)
779 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
780 PTHREADINFO W32Thread
;
781 HMENU hNewMenu
, hSysMenu
;
782 ROSMENUITEMINFO ItemInfo
;
786 W32Thread
= PsGetCurrentThreadWin32Thread();
788 if(!W32Thread
->Desktop
)
791 if(Window
->SystemMenu
)
793 Menu
= UserGetMenuObject(Window
->SystemMenu
);
796 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
797 Window
->SystemMenu
= (HMENU
)0;
801 if(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
)
803 /* clone system menu */
804 Menu
= UserGetMenuObject(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
);
808 NewMenu
= IntCloneMenu(Menu
);
811 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
812 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
813 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
815 //IntReleaseMenuObject(NewMenu);
820 hSysMenu
= UserCreateMenu(FALSE
);
821 if (NULL
== hSysMenu
)
825 SysMenu
= IntGetMenuObject(hSysMenu
);
828 UserDestroyMenu(hSysMenu
);
831 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
832 SysMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
833 hNewMenu
= co_IntLoadSysMenuTemplate();
836 IntReleaseMenuObject(SysMenu
);
837 UserDestroyMenu(hSysMenu
);
840 Menu
= IntGetMenuObject(hNewMenu
);
843 IntReleaseMenuObject(SysMenu
);
844 UserDestroyMenu(hSysMenu
);
848 NewMenu
= IntCloneMenu(Menu
);
851 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
852 IntReleaseMenuObject(NewMenu
);
853 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
855 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
856 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
857 ItemInfo
.fType
= MF_POPUP
;
858 ItemInfo
.fState
= MFS_ENABLED
;
859 ItemInfo
.dwTypeData
= NULL
;
861 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
862 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
864 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
868 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
877 if(Window
->SystemMenu
)
878 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
886 IntIsChildWindow(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT BaseWindow
)
888 PWINDOW_OBJECT Window
;
895 if (Window
== Parent
)
899 if(!(Wnd
->Style
& WS_CHILD
))
904 Window
= Window
->Parent
;
911 IntIsWindowVisible(PWINDOW_OBJECT BaseWindow
)
913 PWINDOW_OBJECT Window
;
920 if(!(Wnd
->Style
& WS_CHILD
))
924 if(!(Wnd
->Style
& WS_VISIBLE
))
929 Window
= Window
->Parent
;
932 if(Window
&& Wnd
->Style
& WS_VISIBLE
)
941 /* link the window into siblings and parent. children are kept in place. */
945 PWINDOW_OBJECT WndParent
,
946 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
949 PWINDOW_OBJECT Parent
;
951 Wnd
->Parent
= WndParent
;
952 Wnd
->Wnd
->Parent
= WndParent
? WndParent
->Wnd
: NULL
;
953 if ((Wnd
->PrevSibling
= WndPrevSibling
))
955 /* link after WndPrevSibling */
956 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
957 Wnd
->NextSibling
->PrevSibling
= Wnd
;
958 else if ((Parent
= Wnd
->Parent
))
960 if(Parent
->LastChild
== WndPrevSibling
)
961 Parent
->LastChild
= Wnd
;
963 Wnd
->PrevSibling
->NextSibling
= Wnd
;
968 Parent
= Wnd
->Parent
;
969 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
970 Wnd
->NextSibling
->PrevSibling
= Wnd
;
973 Parent
->LastChild
= Wnd
;
974 Parent
->FirstChild
= Wnd
;
979 Parent
->FirstChild
= Wnd
;
986 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
988 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
991 Wnd
= IntGetWindowObject(hWnd
);
995 WndOldOwner
= IntGetWindowObject(Wnd
->hOwner
);
998 ret
= WndOldOwner
->hSelf
;
999 UserDereferenceObject(WndOldOwner
);
1006 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1008 Wnd
->hOwner
= hWndNewOwner
;
1009 Wnd
->Wnd
->Owner
= WndNewOwner
->Wnd
;
1014 Wnd
->Wnd
->Owner
= NULL
;
1017 UserDereferenceObject(Wnd
);
1021 PWINDOW_OBJECT FASTCALL
1022 co_IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
1024 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
1025 // HWND hWnd, hWndNewParent;
1029 ASSERT(WndNewParent
);
1030 ASSERT_REFS_CO(Wnd
);
1031 ASSERT_REFS_CO(WndNewParent
);
1033 // hWnd = Wnd->hSelf;
1034 // hWndNewParent = WndNewParent->hSelf;
1037 * Windows hides the window first, then shows it again
1038 * including the WM_SHOWWINDOW messages and all
1040 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1042 // /* Validate that window and parent still exist */
1043 // if (!IntIsWindow(hWnd) || !IntIsWindow(hWndNewParent))
1046 /* Window must belong to current process */
1047 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
1050 WndOldParent
= Wnd
->Parent
;
1052 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1054 if (WndNewParent
!= WndOldParent
)
1056 IntUnlinkWindow(Wnd
);
1058 if (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1060 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
1061 Sibling
= WndNewParent
->FirstChild
;
1062 while (NULL
!= Sibling
&& 0 != (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1064 InsertAfter
= Sibling
;
1065 Sibling
= Sibling
->NextSibling
;
1068 if (NULL
== InsertAfter
)
1070 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1074 // UserReferenceObject(InsertAfter);
1075 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1076 // UserDereferenceObject(InsertAfter);
1081 * SetParent additionally needs to make hwnd the top window
1082 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1083 * WM_WINDOWPOSCHANGED notification messages.
1085 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1086 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1087 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1090 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1091 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1095 * Validate that the old parent still exist, since it migth have been
1096 * destroyed during the last callbacks to user-mode
1100 // if(!IntIsWindow(WndOldParent->hSelf))
1102 // UserDereferenceObject(WndOldParent);
1106 /* don't dereference the window object here, it must be done by the caller
1107 of IntSetParent() */
1108 // return WndOldParent;
1111 return WndOldParent
;//NULL;
1115 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
1117 PMENU_OBJECT OldMenu
;
1118 if(Window
->SystemMenu
)
1120 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1123 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1124 IntReleaseMenuObject(OldMenu
);
1130 /* FIXME check window style, propably return FALSE ? */
1131 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1132 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1135 Window
->SystemMenu
= (HMENU
)0;
1141 /* unlink the window from siblings and parent. children are kept in place. */
1143 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1145 PWINDOW_OBJECT WndParent
= Wnd
->Parent
;
1147 if (Wnd
->NextSibling
)
1148 Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1149 else if (WndParent
&& WndParent
->LastChild
== Wnd
)
1150 WndParent
->LastChild
= Wnd
->PrevSibling
;
1152 if (Wnd
->PrevSibling
)
1153 Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1154 else if (WndParent
&& WndParent
->FirstChild
== Wnd
)
1155 WndParent
->FirstChild
= Wnd
->NextSibling
;
1157 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1159 Wnd
->Wnd
->Parent
= NULL
;
1165 PWINDOW_OBJECT Window
, Child
;
1167 if(!(Window
= UserGetWindowObject(IntGetDesktopWindow())))
1172 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1174 if(Child
->hOwner
&& Child
->Wnd
->Style
& WS_VISIBLE
)
1177 * The desktop has a popup window if one of them has
1178 * an owner window and is visible
1188 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1190 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1196 IntGetWindowPlacement(PWINDOW_OBJECT Window
, WINDOWPLACEMENT
*lpwndpl
)
1202 if (!Wnd
) return FALSE
;
1204 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1210 if (0 == (Wnd
->Style
& WS_VISIBLE
))
1212 lpwndpl
->showCmd
= SW_HIDE
;
1214 else if (0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
1215 0 != (Wnd
->Style
& WS_MAXIMIZE
))
1217 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1219 else if (0 != (Wnd
->Style
& WS_MINIMIZE
))
1221 lpwndpl
->showCmd
= SW_MINIMIZE
;
1223 else if (0 != (Wnd
->Style
& WS_VISIBLE
))
1225 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1228 Size
.x
= Wnd
->WindowRect
.left
;
1229 Size
.y
= Wnd
->WindowRect
.top
;
1230 WinPosInitInternalPos(Window
, &Size
,
1233 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1234 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1235 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1241 /* FUNCTIONS *****************************************************************/
1247 NtUserAlterWindowStyle(DWORD Unknown0
,
1257 * As best as I can figure, this function is used by EnumWindows,
1258 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1260 * It's supposed to build a list of HWNDs to return to the caller.
1261 * We can figure out what kind of list by what parameters are
1269 NtUserBuildHwndList(
1282 return ERROR_INVALID_PARAMETER
;
1284 if (hwndParent
|| !dwThreadId
)
1287 PWINDOW_OBJECT Parent
, Window
;
1291 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1293 return ERROR_INVALID_HANDLE
;
1298 Status
= IntValidateDesktopHandle(hDesktop
,
1302 if(!NT_SUCCESS(Status
))
1304 return ERROR_INVALID_HANDLE
;
1307 hwndParent
= Desktop
->DesktopWindow
;
1314 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1315 (Window
= Parent
->FirstChild
))
1317 BOOL bGoDown
= TRUE
;
1319 Status
= STATUS_SUCCESS
;
1324 if(dwCount
++ < *pBufSize
&& pWnd
)
1328 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1329 *pWnd
= Window
->hSelf
;
1332 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1334 Status
= _SEH2_GetExceptionCode();
1337 if(!NT_SUCCESS(Status
))
1339 SetLastNtError(Status
);
1343 if (Window
->FirstChild
&& bChildren
)
1345 Window
= Window
->FirstChild
;
1350 if (Window
->NextSibling
)
1352 Window
= Window
->NextSibling
;
1356 Window
= Window
->Parent
;
1357 if (Window
== Parent
)
1366 ObDereferenceObject(Desktop
);
1372 PTHREADINFO W32Thread
;
1373 PLIST_ENTRY Current
;
1374 PWINDOW_OBJECT Window
;
1376 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1377 if(!NT_SUCCESS(Status
))
1379 return ERROR_INVALID_PARAMETER
;
1381 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1383 ObDereferenceObject(Thread
);
1384 DPRINT("Thread is not a GUI Thread!\n");
1385 return ERROR_INVALID_PARAMETER
;
1388 Current
= W32Thread
->WindowListHead
.Flink
;
1389 while(Current
!= &(W32Thread
->WindowListHead
))
1391 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1394 if(bChildren
|| Window
->hOwner
!= NULL
)
1396 if(dwCount
< *pBufSize
&& pWnd
)
1398 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1399 if(!NT_SUCCESS(Status
))
1401 SetLastNtError(Status
);
1407 Current
= Current
->Flink
;
1410 ObDereferenceObject(Thread
);
1413 *pBufSize
= dwCount
;
1414 return STATUS_SUCCESS
;
1422 NtUserChildWindowFromPointEx(HWND hwndParent
,
1427 PWINDOW_OBJECT Parent
;
1432 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1440 if(Parent
->hSelf
!= IntGetDesktopWindow())
1442 Pt
.x
+= Parent
->Wnd
->ClientRect
.left
;
1443 Pt
.y
+= Parent
->Wnd
->ClientRect
.top
;
1446 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1451 Ret
= Parent
->hSelf
;
1452 if((List
= IntWinListChildren(Parent
)))
1454 for(phWnd
= List
; *phWnd
; phWnd
++)
1456 PWINDOW_OBJECT Child
;
1458 if((Child
= UserGetWindowObject(*phWnd
)))
1460 ChildWnd
= Child
->Wnd
;
1461 if(!(ChildWnd
->Style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1465 if((ChildWnd
->Style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1469 if((ChildWnd
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1473 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1488 * calculates the default position of a window
1491 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT Window
, RECTL
*rc
, BOOL IncPos
)
1498 RECTL_bIntersectRect(rc
, rc
, &Parent
->Wnd
->ClientRect
);
1502 Pos
.x
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1503 Pos
.y
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1504 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1505 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1507 /* reset counter and position */
1510 Parent
->TiledCounter
= 0;
1512 Parent
->TiledCounter
++;
1523 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1524 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1528 rc
->right
= rc
->left
+ Sz
.cx
;
1529 rc
->bottom
= rc
->top
+ Sz
.cy
;
1538 co_IntCreateWindowEx(DWORD dwExStyle
,
1539 PUNICODE_STRING ClassName
,
1540 PUNICODE_STRING WindowName
,
1548 HINSTANCE hInstance
,
1551 BOOL bUnicodeWindow
)
1553 PWINSTATION_OBJECT WinSta
;
1555 PWINDOWCLASS
*ClassLink
, Class
= NULL
;
1557 PWINDOW_OBJECT Window
= NULL
;
1558 PWINDOW_OBJECT ParentWindow
= NULL
, OwnerWindow
;
1559 HWND ParentWindowHandle
= NULL
;
1560 HWND OwnerWindowHandle
;
1561 PMENU_OBJECT SystemMenu
;
1565 PW32THREADINFO ti
= NULL
;
1568 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1574 CBT_CREATEWNDW CbtCreate
;
1577 DECLARE_RETURN(HWND
);
1579 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1582 pti
= PsGetCurrentThreadWin32Thread();
1586 ParentWindowHandle
= pti
->Desktop
->DesktopWindow
;
1589 OwnerWindowHandle
= NULL
;
1591 if (hWndParent
== HWND_MESSAGE
)
1594 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1595 * message window (style: WS_POPUP|WS_DISABLED)
1597 DPRINT1("FIXME - Parent is HWND_MESSAGE\n");
1598 // ParentWindowHandle = IntGetMessageWindow();
1600 else if (hWndParent
)
1602 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1604 PWINDOW_OBJECT Par
= UserGetWindowObject(hWndParent
), Root
;
1605 if (Par
&& (Root
= UserGetAncestor(Par
, GA_ROOT
)))
1606 OwnerWindowHandle
= Root
->hSelf
;
1609 ParentWindowHandle
= hWndParent
;
1611 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1613 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1614 RETURN( (HWND
)0); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1617 if (ParentWindowHandle
)
1619 ParentWindow
= UserGetWindowObject(ParentWindowHandle
);
1621 if (ParentWindow
) UserRefObjectCo(ParentWindow
, &ParentRef
);
1625 ParentWindow
= NULL
;
1628 /* FIXME: parent must belong to the current process */
1630 /* Check the window station. */
1631 ti
= GetW32ThreadInfo();
1632 if (ti
== NULL
|| pti
->Desktop
== NULL
)
1634 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1638 /* Check the class. */
1640 ClassAtom
= IntGetClassAtom(ClassName
,
1646 if (ClassAtom
== (RTL_ATOM
)0)
1648 if (IS_ATOM(ClassName
->Buffer
))
1650 DPRINT1("Class 0x%p not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1654 DPRINT1("Class \"%wZ\" not found\n", ClassName
);
1657 SetLastWin32Error(ERROR_CANNOT_FIND_WND_CLASS
);
1661 Class
= IntReferenceClass(Class
,
1666 DPRINT1("Failed to reference window class!\n");
1670 WinSta
= pti
->Desktop
->WindowStation
;
1672 //FIXME: Reference thread/desktop instead
1673 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1675 /* Create the window object. */
1676 Window
= (PWINDOW_OBJECT
)
1677 UserCreateObject(gHandleTable
, (PHANDLE
)&hWnd
,
1678 otWindow
, sizeof(WINDOW_OBJECT
));
1681 Window
->Wnd
= DesktopHeapAlloc(pti
->Desktop
,
1682 sizeof(WINDOW
) + Class
->WndExtra
);
1685 RtlZeroMemory(Window
->Wnd
,
1686 sizeof(WINDOW
) + Class
->WndExtra
);
1687 Window
->Wnd
->hdr
.Handle
= hWnd
; /* FIXME: Remove hack */
1692 Wnd
->pdesktop
= pti
->Desktop
;
1693 Wnd
->hWndLastActive
= hWnd
;
1696 DPRINT("Created object with handle %X\n", hWnd
);
1700 ObDereferenceObject(WinSta
);
1701 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1705 UserRefObjectCo(Window
, &Ref
);
1707 ObDereferenceObject(WinSta
);
1709 if (NULL
== pti
->Desktop
->DesktopWindow
)
1711 /* If there is no desktop window yet, we must be creating it */
1712 pti
->Desktop
->DesktopWindow
= hWnd
;
1713 pti
->Desktop
->DesktopInfo
->Wnd
= Wnd
;
1717 * Fill out the structure describing it.
1723 Window
->SystemMenu
= (HMENU
)0;
1724 Wnd
->ContextHelpId
= 0;
1726 Wnd
->Instance
= hInstance
;
1727 Window
->hSelf
= hWnd
;
1729 Window
->MessageQueue
= pti
->MessageQueue
;
1730 IntReferenceMessageQueue(Window
->MessageQueue
);
1731 Window
->Parent
= ParentWindow
;
1732 Wnd
->Parent
= ParentWindow
? ParentWindow
->Wnd
: NULL
;
1733 if (Wnd
->Parent
!= NULL
&& hWndParent
!= 0)
1735 Wnd
->HideFocus
= Wnd
->Parent
->HideFocus
;
1736 Wnd
->HideAccel
= Wnd
->Parent
->HideAccel
;
1739 if((OwnerWindow
= UserGetWindowObject(OwnerWindowHandle
)))
1741 Window
->hOwner
= OwnerWindowHandle
;
1742 Wnd
->Owner
= OwnerWindow
->Wnd
;
1747 Window
->hOwner
= NULL
;
1754 Wnd
->IsSystem
= Wnd
->Class
->System
;
1756 /* BugBoy Comments: Comment below say that System classes are always created as UNICODE.
1757 In windows, creating a window with the ANSI version of CreateWindow sets the window
1758 to ansi as verified by testing with IsUnicodeWindow API.
1760 No where can I see in code or through testing does the window change back to ANSI
1761 after being created as UNICODE in ROS. I didnt do more testing to see what problems this would cause.*/
1762 // See NtUserDefSetText! We convert to Unicode all the time and never use Mix. (jt)
1763 if (Wnd
->Class
->System
)
1765 /* NOTE: Always create a unicode window for system classes! */
1766 Wnd
->Unicode
= TRUE
;
1767 Wnd
->WndProc
= Wnd
->Class
->WndProc
;
1768 Wnd
->WndProcExtra
= Wnd
->Class
->WndProcExtra
;
1772 Wnd
->Unicode
= Wnd
->Class
->Unicode
;
1773 Wnd
->WndProc
= Wnd
->Class
->WndProc
;
1774 Wnd
->CallProc
= NULL
;
1777 Window
->OwnerThread
= PsGetCurrentThread();
1778 Window
->FirstChild
= NULL
;
1779 Window
->LastChild
= NULL
;
1780 Window
->PrevSibling
= NULL
;
1781 Window
->NextSibling
= NULL
;
1782 Wnd
->ExtraDataSize
= Wnd
->Class
->WndExtra
;
1784 InitializeListHead(&Wnd
->PropListHead
);
1785 InitializeListHead(&Window
->WndObjListHead
);
1787 if (NULL
!= WindowName
->Buffer
&& WindowName
->Length
> 0)
1789 Wnd
->WindowName
.Buffer
= DesktopHeapAlloc(Wnd
->pdesktop
,
1790 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1791 if (Wnd
->WindowName
.Buffer
== NULL
)
1793 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1797 Wnd
->WindowName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1800 RtlCopyMemory(Wnd
->WindowName
.Buffer
,
1802 WindowName
->Length
);
1803 Wnd
->WindowName
.Length
= WindowName
->Length
;
1805 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1807 WindowName
->Length
= 0;
1808 Wnd
->WindowName
.Buffer
[0] = L
'\0';
1814 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1815 * tested for WS_POPUP
1817 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1818 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1819 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1820 dwExStyle
|= WS_EX_WINDOWEDGE
;
1822 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1824 /* Correct the window style. */
1825 if (!(dwStyle
& WS_CHILD
))
1827 dwStyle
|= WS_CLIPSIBLINGS
;
1828 DPRINT("3: Style is now %lx\n", dwStyle
);
1829 if (!(dwStyle
& WS_POPUP
))
1831 dwStyle
|= WS_CAPTION
;
1832 Window
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1833 DPRINT("4: Style is now %lx\n", dwStyle
);
1837 /* create system menu */
1838 if((dwStyle
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1840 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
1843 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1844 IntReleaseMenuObject(SystemMenu
);
1848 /* Set the window menu */
1849 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1852 IntSetMenu(Window
, hMenu
, &MenuChanged
);
1855 hMenu
= Wnd
->Class
->hMenu
;
1856 if (hMenu
) IntSetMenu(Window
, hMenu
, &MenuChanged
);
1860 Wnd
->IDMenu
= (UINT
) hMenu
;
1862 /* Insert the window into the thread's window list. */
1863 InsertTailList (&pti
->WindowListHead
, &Window
->ThreadListEntry
);
1865 /* Handle "CS_CLASSDC", it is tested first. */
1866 if ((Wnd
->Class
->Style
& CS_CLASSDC
) && !(Wnd
->Class
->Dce
)) // One DCE per class to have CLASS.
1867 Wnd
->Class
->Dce
= DceAllocDCE(Window
, DCE_CLASS_DC
);
1868 /* Allocate a DCE for this window. */
1869 else if ( Wnd
->Class
->Style
& CS_OWNDC
)
1870 Window
->Dce
= DceAllocDCE(Window
, DCE_WINDOW_DC
);
1877 Wnd
->ExStyle
= dwExStyle
;
1878 Wnd
->Style
= dwStyle
& ~WS_VISIBLE
;
1881 Cs
.lpCreateParams
= lpParam
;
1882 Cs
.hInstance
= hInstance
;
1884 Cs
.hwndParent
= hWndParent
; //Pass the original Parent handle!
1889 Cs
.style
= Wnd
->Style
;
1890 Cs
.lpszName
= (LPCWSTR
) WindowName
;
1891 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
1892 Cs
.dwExStyle
= dwExStyle
;
1893 CbtCreate
.lpcs
= &Cs
;
1894 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1895 if (ISITHOOKED(WH_CBT
))
1897 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) &CbtCreate
))
1899 /* FIXME - Delete window object and remove it from the thread windows list */
1900 /* FIXME - delete allocated DCE */
1901 DPRINT1("CBT-hook returned !0\n");
1902 RETURN( (HWND
) NULL
);
1909 // FIXME: Need to set the Z order in the window link list if the hook callback changed it!
1910 // hwndInsertAfter = CbtCreate.hwndInsertAfter;
1912 /* default positioning for overlapped windows */
1913 if(!(Wnd
->Style
& (WS_POPUP
| WS_CHILD
)))
1916 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1917 BOOL CalculatedDefPosSize
= FALSE
;
1919 IntGetDesktopWorkArea(((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
, &WorkArea
);
1922 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1924 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1926 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, Window
, &rc
, TRUE
);
1928 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1930 ProcessParams
->WindowFlags
&= ~STARTF_USEPOSITION
;
1931 Pos
.x
= WorkArea
.left
+ ProcessParams
->StartingX
;
1932 Pos
.y
= WorkArea
.top
+ ProcessParams
->StartingY
;
1941 According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
1942 y is something else. and Quote!
1945 /* Never believe Microsoft's documentation... CreateWindowEx doc says
1946 * that if an overlapped window is created with WS_VISIBLE style bit
1947 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
1948 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
1951 * 1) not only it checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
1952 * 2) it does not ignore the y parameter as the docs claim; instead, it
1953 * uses it as second parameter to ShowWindow() unless y is either
1954 * CW_USEDEFAULT or CW_USEDEFAULT16.
1956 * The fact that we didn't do 2) caused bogus windows pop up when wine
1957 * was running apps that were using this obscure feature. Example -
1958 * calc.exe that comes with Win98 (only Win98, it's different from
1959 * the one that comes with Win95 and NT)
1961 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
1966 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1968 if(!CalculatedDefPosSize
)
1970 IntCalcDefPosSize(ParentWindow
, Window
, &rc
, FALSE
);
1972 if(ProcessParams
->WindowFlags
& STARTF_USESIZE
)
1974 ProcessParams
->WindowFlags
&= ~STARTF_USESIZE
;
1975 Size
.cx
= ProcessParams
->CountX
;
1976 Size
.cy
= ProcessParams
->CountY
;
1980 Size
.cx
= rc
.right
- rc
.left
;
1981 Size
.cy
= rc
.bottom
- rc
.top
;
1984 /* move the window if necessary */
1986 Pos
.x
= max(rc
.left
, 0);
1988 Pos
.y
= max(rc
.top
, 0);
1993 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
1994 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1999 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
2006 /* Initialize the window dimensions. */
2007 Wnd
->WindowRect
.left
= Pos
.x
;
2008 Wnd
->WindowRect
.top
= Pos
.y
;
2009 Wnd
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
2010 Wnd
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
2011 if (0 != (Wnd
->Style
& WS_CHILD
) && ParentWindow
)
2013 RECTL_vOffsetRect(&(Wnd
->WindowRect
), ParentWindow
->Wnd
->ClientRect
.left
,
2014 ParentWindow
->Wnd
->ClientRect
.top
);
2016 Wnd
->ClientRect
= Wnd
->WindowRect
;
2019 * Get the size and position of the window.
2021 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
2023 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2025 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
2026 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
,
2028 if (MaxSize
.x
< Size
.cx
)
2029 Size
.cx
= MaxSize
.x
;
2030 if (MaxSize
.y
< Size
.cy
)
2031 Size
.cy
= MaxSize
.y
;
2032 if (Size
.cx
< MinTrack
.x
)
2033 Size
.cx
= MinTrack
.x
;
2034 if (Size
.cy
< MinTrack
.y
)
2035 Size
.cy
= MinTrack
.y
;
2042 Wnd
->WindowRect
.left
= Pos
.x
;
2043 Wnd
->WindowRect
.top
= Pos
.y
;
2044 Wnd
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
2045 Wnd
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
2046 if (0 != (Wnd
->Style
& WS_CHILD
) && ParentWindow
)
2048 RECTL_vOffsetRect(&(Wnd
->WindowRect
), ParentWindow
->Wnd
->ClientRect
.left
,
2049 ParentWindow
->Wnd
->ClientRect
.top
);
2051 Wnd
->ClientRect
= Wnd
->WindowRect
;
2053 /* FIXME: Initialize the window menu. */
2055 /* Send a NCCREATE message. */
2061 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
2062 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, Size
.cx
, Size
.cy
);
2063 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
2064 Result
= co_IntSendMessage(Window
->hSelf
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
2067 /* FIXME: Cleanup. */
2068 DPRINT1("IntCreateWindowEx(): NCCREATE message failed. No cleanup performed!\n");
2072 /* Calculate the non-client size. */
2073 MaxPos
.x
= Window
->Wnd
->WindowRect
.left
;
2074 MaxPos
.y
= Window
->Wnd
->WindowRect
.top
;
2077 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
2078 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
2079 Result
= co_WinPosGetNonClientSize(Window
,
2080 &Window
->Wnd
->WindowRect
,
2081 &Window
->Wnd
->ClientRect
);
2083 RECTL_vOffsetRect(&Window
->Wnd
->WindowRect
,
2084 MaxPos
.x
- Window
->Wnd
->WindowRect
.left
,
2085 MaxPos
.y
- Window
->Wnd
->WindowRect
.top
);
2088 if (NULL
!= ParentWindow
)
2090 /* link the window into the parent's child list */
2091 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2093 PWINDOW_OBJECT PrevSibling
;
2095 PrevSibling
= ParentWindow
->LastChild
;
2097 /* link window as bottom sibling */
2098 IntLinkWindow(Window
, ParentWindow
, PrevSibling
/*prev sibling*/);
2102 /* link window as top sibling (but after topmost siblings) */
2103 PWINDOW_OBJECT InsertAfter
, Sibling
;
2104 if (!(dwExStyle
& WS_EX_TOPMOST
))
2107 Sibling
= ParentWindow
->FirstChild
;
2108 while (Sibling
&& (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
2110 InsertAfter
= Sibling
;
2111 Sibling
= Sibling
->NextSibling
;
2119 IntLinkWindow(Window
, ParentWindow
, InsertAfter
/* prev sibling */);
2124 /* Send the WM_CREATE message. */
2125 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
2126 Result
= co_IntSendMessage(Window
->hSelf
, WM_CREATE
, 0, (LPARAM
) &Cs
);
2128 if (Result
== (LRESULT
)-1)
2130 /* FIXME: Cleanup. */
2131 DPRINT1("IntCreateWindowEx(): send CREATE message failed. No cleanup performed!\n");
2132 IntUnlinkWindow(Window
);
2136 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
->hSelf
, OBJID_WINDOW
, 0);
2138 /* Send move and size messages. */
2139 if (!(Window
->Flags
& WINDOWOBJECT_NEED_SIZE
))
2143 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
2145 if ((Window
->Wnd
->ClientRect
.right
- Window
->Wnd
->ClientRect
.left
) < 0 ||
2146 (Window
->Wnd
->ClientRect
.bottom
- Window
->Wnd
->ClientRect
.top
) < 0)
2148 DPRINT("Sending bogus WM_SIZE\n");
2151 lParam
= MAKE_LONG(Window
->Wnd
->ClientRect
.right
-
2152 Window
->Wnd
->ClientRect
.left
,
2153 Window
->Wnd
->ClientRect
.bottom
-
2154 Window
->Wnd
->ClientRect
.top
);
2155 co_IntSendMessage(Window
->hSelf
, WM_SIZE
, SIZE_RESTORED
,
2158 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
2160 if (0 != (Wnd
->Style
& WS_CHILD
) && ParentWindow
)
2162 lParam
= MAKE_LONG(Wnd
->ClientRect
.left
- ParentWindow
->Wnd
->ClientRect
.left
,
2163 Wnd
->ClientRect
.top
- ParentWindow
->Wnd
->ClientRect
.top
);
2167 lParam
= MAKE_LONG(Wnd
->ClientRect
.left
,
2168 Wnd
->ClientRect
.top
);
2171 co_IntSendMessage(Window
->hSelf
, WM_MOVE
, 0, lParam
);
2173 /* Call WNDOBJ change procs */
2174 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
2177 /* Show or maybe minimize or maximize the window. */
2178 if (Wnd
->Style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2183 SwFlag
= (Wnd
->Style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
2186 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2188 SwFlag
= ((Wnd
->Style
& WS_CHILD
) || UserGetActiveWindow()) ?
2189 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2190 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2192 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
2193 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
2194 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2195 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2198 /* Notify the parent window of a new child. */
2199 if ((Wnd
->Style
& WS_CHILD
) &&
2200 (!(Wnd
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
2202 DPRINT("IntCreateWindow(): About to notify parent\n");
2203 co_IntSendMessage(ParentWindow
->hSelf
,
2205 MAKEWPARAM(WM_CREATE
, Wnd
->IDMenu
),
2206 (LPARAM
)Window
->hSelf
);
2209 if ((!hWndParent
) && (!HasOwner
))
2211 DPRINT("Sending CREATED notify\n");
2212 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2216 DPRINT("Not sending CREATED notify, %x %d\n", ParentWindow
, HasOwner
);
2219 /* Initialize and show the window's scrollbars */
2220 if (Wnd
->Style
& WS_VSCROLL
)
2222 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2224 if (Wnd
->Style
& WS_HSCROLL
)
2226 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2229 if (dwStyle
& WS_VISIBLE
)
2231 if (Wnd
->Style
& WS_MAXIMIZE
)
2232 dwShowMode
= SW_SHOW
;
2233 else if (Wnd
->Style
& WS_MINIMIZE
)
2234 dwShowMode
= SW_SHOWMINIMIZED
;
2236 DPRINT("IntCreateWindow(): About to show window\n");
2237 co_WinPosShowWindow(Window
, dwShowMode
);
2239 if (Wnd
->ExStyle
& WS_EX_MDICHILD
)
2241 co_IntSendMessage(ParentWindow
->hSelf
, WM_MDIREFRESHMENU
, 0, 0);
2242 /* ShowWindow won't activate child windows */
2243 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2247 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xC007,
2248 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
2249 Dont understand why it does this. */
2250 if (ClassAtom
== 0XC007)
2253 //CallProc = CreateCallProc(NULL, Wnd->WndProc, bUnicodeWindow, Wnd->ti->ppi);
2254 CallProc
= CreateCallProc(NULL
, Wnd
->WndProc
, Wnd
->Unicode
, Wnd
->ti
->ppi
);
2258 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2259 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
2263 UserAddCallProcToClass(Wnd
->Class
, CallProc
);
2264 Wnd
->CallProc
= CallProc
;
2265 Wnd
->IsSystem
= FALSE
;
2269 DPRINT("IntCreateWindow(): = %X\n", hWnd
);
2270 DPRINT("WindowObject->SystemMenu = 0x%x\n", Window
->SystemMenu
);
2274 if (!_ret_
&& Window
&& Window
->Wnd
&& ti
)
2275 UserFreeWindowInfo(ti
, Window
);
2278 UserDerefObjectCo(Window
);
2279 UserDereferenceObject(Window
);
2281 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2282 if (!_ret_
&& ti
!= NULL
)
2286 IntDereferenceClass(Class
,
2295 NtUserCreateWindowEx(DWORD dwExStyle
,
2296 PUNICODE_STRING UnsafeClassName
,
2297 PUNICODE_STRING UnsafeWindowName
,
2305 HINSTANCE hInstance
,
2308 BOOL bUnicodeWindow
,
2312 UNICODE_STRING WindowName
;
2313 UNICODE_STRING ClassName
;
2315 DECLARE_RETURN(HWND
);
2317 DPRINT("Enter NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2318 UserEnterExclusive();
2320 /* Get the class name (string or atom) */
2321 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
2322 if (! NT_SUCCESS(Status
))
2324 SetLastNtError(Status
);
2327 if (ClassName
.Length
!= 0)
2329 Status
= IntSafeCopyUnicodeStringTerminateNULL(&ClassName
, UnsafeClassName
);
2330 if (! NT_SUCCESS(Status
))
2332 SetLastNtError(Status
);
2336 else if (! IS_ATOM(ClassName
.Buffer
))
2338 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2342 /* safely copy the window name */
2343 if (NULL
!= UnsafeWindowName
)
2345 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
2346 if (! NT_SUCCESS(Status
))
2348 if (! IS_ATOM(ClassName
.Buffer
))
2350 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2352 SetLastNtError(Status
);
2358 RtlInitUnicodeString(&WindowName
, NULL
);
2361 NewWindow
= co_IntCreateWindowEx(dwExStyle
, &ClassName
, &WindowName
, dwStyle
, x
, y
, nWidth
, nHeight
,
2362 hWndParent
, hMenu
, hInstance
, lpParam
, dwShowMode
, bUnicodeWindow
);
2364 if (WindowName
.Buffer
)
2366 ExFreePoolWithTag(WindowName
.Buffer
, TAG_STRING
);
2368 if (! IS_ATOM(ClassName
.Buffer
))
2370 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2376 DPRINT("Leave NtUserCreateWindowEx, ret=%i\n",_ret_
);
2385 NtUserDeferWindowPos(HDWP WinPosInfo
,
2387 HWND WndInsertAfter
,
2400 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2406 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2408 hWnd
= Window
->hSelf
;
2412 if (!Wnd
) return TRUE
; // FIXME: Need to finish object rewrite or lock the thread when killing the window!
2414 /* Check for owner thread */
2415 if ((Window
->OwnerThread
!= PsGetCurrentThread()))
2417 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2422 if (ISITHOOKED(WH_CBT
))
2424 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0)) return FALSE
;
2427 /* Look whether the focus is within the tree of windows we will
2430 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2432 if (UserGetActiveWindow() == Window
->hSelf
)
2434 co_WinPosActivateOtherWindow(Window
);
2438 if (Window
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2439 Window
->MessageQueue
->ActiveWindow
= NULL
;
2440 if (Window
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2441 Window
->MessageQueue
->FocusWindow
= NULL
;
2442 if (Window
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2443 Window
->MessageQueue
->CaptureWindow
= NULL
;
2445 IntDereferenceMessageQueue(Window
->MessageQueue
);
2447 IntEngWindowChanged(Window
, WOC_DELETE
);
2448 isChild
= (0 != (Wnd
->Style
& WS_CHILD
));
2454 if (! USER_IsExitingThread(GetCurrentThreadId()))
2456 send_parent_notify(hwnd
, WM_DESTROY
);
2459 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2461 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2462 /* FIXME: clean up palette - see "Internals" p.352 */
2466 if (!IntIsWindow(Window
->hSelf
))
2471 /* Recursively destroy owned windows */
2476 BOOL GotOne
= FALSE
;
2479 PWINDOW_OBJECT Child
, Desktop
;
2481 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2482 UserGetWindowObject(IntGetDesktopWindow());
2483 Children
= IntWinListChildren(Desktop
);
2487 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2489 Child
= UserGetWindowObject(*ChildHandle
);
2492 if (Child
->hOwner
!= Window
->hSelf
)
2497 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2499 USER_REFERENCE_ENTRY ChildRef
;
2500 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2501 co_UserDestroyWindow(Child
);
2502 UserDerefObjectCo(Child
);//temp hack?
2508 if (Child
->hOwner
!= NULL
)
2510 Child
->hOwner
= NULL
;
2511 Child
->Wnd
->Owner
= NULL
;
2515 ExFreePool(Children
);
2524 if (!IntIsWindow(Window
->hSelf
))
2529 /* Destroy the window storage */
2530 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2542 NtUserDestroyWindow(HWND Wnd
)
2544 PWINDOW_OBJECT Window
;
2545 DECLARE_RETURN(BOOLEAN
);
2547 USER_REFERENCE_ENTRY Ref
;
2549 DPRINT("Enter NtUserDestroyWindow\n");
2550 UserEnterExclusive();
2552 if (!(Window
= UserGetWindowObject(Wnd
)))
2557 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2558 ret
= co_UserDestroyWindow(Window
);
2559 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2564 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2576 NtUserDrawMenuBarTemp(
2583 /* we'll use this function just for caching the menu bar */
2593 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2603 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2609 NtUserFillWindow(HWND hWndPaint
,
2620 static HWND FASTCALL
2621 IntFindWindow(PWINDOW_OBJECT Parent
,
2622 PWINDOW_OBJECT ChildAfter
,
2624 PUNICODE_STRING WindowName
)
2626 BOOL CheckWindowName
;
2632 CheckWindowName
= WindowName
->Length
!= 0;
2634 if((List
= IntWinListChildren(Parent
)))
2639 /* skip handles before and including ChildAfter */
2640 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2644 /* search children */
2647 PWINDOW_OBJECT Child
;
2648 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2653 /* Do not send WM_GETTEXT messages in the kernel mode version!
2654 The user mode version however calls GetWindowText() which will
2655 send WM_GETTEXT messages to windows belonging to its processes */
2656 if((!CheckWindowName
|| !RtlCompareUnicodeString(WindowName
, &(Child
->Wnd
->WindowName
), TRUE
)) &&
2657 (!ClassAtom
|| Child
->Wnd
->Class
->Atom
== ClassAtom
))
2672 * Searches a window's children for a window with the specified
2675 * hwndParent = The window whose childs are to be searched.
2677 * HWND_MESSAGE = message-only windows
2679 * hwndChildAfter = Search starts after this child window.
2680 * NULL = start from beginning
2682 * ucClassName = Class name to search for
2683 * Reguired parameter.
2685 * ucWindowName = Window name
2686 * ->Buffer == NULL = don't care
2689 * The HWND of the window if it was found, otherwise NULL
2695 NtUserFindWindowEx(HWND hwndParent
,
2696 HWND hwndChildAfter
,
2697 PUNICODE_STRING ucClassName
,
2698 PUNICODE_STRING ucWindowName
,
2701 PWINDOW_OBJECT Parent
, ChildAfter
;
2702 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2703 HWND Desktop
, Ret
= NULL
;
2704 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2705 DECLARE_RETURN(HWND
);
2707 DPRINT("Enter NtUserFindWindowEx\n");
2710 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2714 if (ucClassName
!= NULL
)
2716 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2717 if (ClassName
.Length
!= 0)
2719 ProbeForRead(ClassName
.Buffer
,
2723 else if (!IS_ATOM(ClassName
.Buffer
))
2725 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2729 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2736 if (ucWindowName
!= NULL
)
2738 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2739 if (WindowName
.Length
!= 0)
2741 ProbeForRead(WindowName
.Buffer
,
2747 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2749 SetLastNtError(_SEH2_GetExceptionCode());
2750 _SEH2_YIELD(RETURN(NULL
));
2754 if (ucClassName
!= NULL
)
2756 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2757 !IS_ATOM(ClassName
.Buffer
))
2759 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2762 else if (ClassAtom
== (RTL_ATOM
)0)
2764 /* LastError code was set by IntGetAtomFromStringOrAtom */
2770 Desktop
= IntGetCurrentThreadDesktopWindow();
2772 if(hwndParent
== NULL
)
2773 hwndParent
= Desktop
;
2775 else if(hwndParent == HWND_MESSAGE)
2777 hwndParent = IntGetMessageWindow();
2781 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2787 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2794 if(Parent
->hSelf
== Desktop
)
2797 PWINDOW_OBJECT TopLevelWindow
;
2798 BOOLEAN CheckWindowName
;
2799 BOOLEAN WindowMatches
;
2800 BOOLEAN ClassMatches
;
2802 /* windows searches through all top-level windows if the parent is the desktop
2805 if((List
= IntWinListChildren(Parent
)))
2811 /* skip handles before and including ChildAfter */
2812 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2816 CheckWindowName
= WindowName
.Length
!= 0;
2818 /* search children */
2821 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2826 /* Do not send WM_GETTEXT messages in the kernel mode version!
2827 The user mode version however calls GetWindowText() which will
2828 send WM_GETTEXT messages to windows belonging to its processes */
2829 WindowMatches
= !CheckWindowName
|| !RtlCompareUnicodeString(
2830 &WindowName
, &TopLevelWindow
->Wnd
->WindowName
, TRUE
);
2831 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2832 ClassAtom
== TopLevelWindow
->Wnd
->Class
->Atom
;
2834 if (WindowMatches
&& ClassMatches
)
2836 Ret
= TopLevelWindow
->hSelf
;
2840 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2842 /* window returns the handle of the top-level window, in case it found
2844 Ret
= TopLevelWindow
->hSelf
;
2853 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2857 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2859 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2860 search the message-only windows. Should this also be done if
2861 Parent is the desktop window??? */
2862 PWINDOW_OBJECT MsgWindows
;
2864 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2866 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2871 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2873 SetLastNtError(_SEH2_GetExceptionCode());
2881 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2891 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
2902 PWINDOW_OBJECT FASTCALL
UserGetAncestor(PWINDOW_OBJECT Wnd
, UINT Type
)
2904 PWINDOW_OBJECT WndAncestor
, Parent
;
2906 if (Wnd
->hSelf
== IntGetDesktopWindow())
2915 WndAncestor
= Wnd
->Parent
;
2926 if(!(Parent
= WndAncestor
->Parent
))
2930 if(IntIsDesktopWindow(Parent
))
2935 WndAncestor
= Parent
;
2946 PWINDOW_OBJECT Parent
, Old
;
2949 Parent
= IntGetParent(WndAncestor
);
2957 // UserDereferenceObject(Parent);
2959 WndAncestor
= Parent
;
2979 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2981 PWINDOW_OBJECT Window
, Ancestor
;
2982 DECLARE_RETURN(HWND
);
2984 DPRINT("Enter NtUserGetAncestor\n");
2985 UserEnterExclusive();
2987 if (!(Window
= UserGetWindowObject(hWnd
)))
2992 Ancestor
= UserGetAncestor(Window
, Type
);
2993 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
2995 RETURN(Ancestor
? Ancestor
->hSelf
: NULL
);
2998 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3006 NtUserGetComboBoxInfo(
3011 DECLARE_RETURN(BOOL
);
3013 DPRINT("Enter NtUserGetComboBoxInfo\n");
3016 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3025 sizeof(COMBOBOXINFO
),
3029 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3031 SetLastNtError(_SEH2_GetExceptionCode());
3032 _SEH2_YIELD(RETURN(FALSE
));
3036 // Pass the user pointer, it was already probed.
3037 RETURN( (BOOL
) co_IntSendMessage( Wnd
->hSelf
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3040 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3050 NtUserGetInternalWindowPos( HWND hWnd
,
3054 PWINDOW_OBJECT Window
;
3058 WINDOWPLACEMENT wndpl
;
3062 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3073 ProbeForWrite(rectWnd
,
3079 ProbeForWrite(ptIcon
,
3085 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3087 SetLastNtError(_SEH2_GetExceptionCode());
3092 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3094 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3100 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3104 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3108 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3110 SetLastNtError(_SEH2_GetExceptionCode());
3115 if (!Hit
) Ret
= wndpl
.showCmd
;
3124 NtUserGetListBoxInfo(
3128 DECLARE_RETURN(DWORD
);
3130 DPRINT("Enter NtUserGetListBoxInfo\n");
3133 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3138 RETURN( (DWORD
) co_IntSendMessage( Wnd
->hSelf
, LB_GETLISTBOXINFO
, 0, 0 ));
3141 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3148 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3150 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3151 HWND hWndOldParent
= NULL
;
3152 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3154 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3156 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3160 if (hWndChild
== IntGetDesktopWindow())
3162 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3168 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3175 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3181 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3186 UserRefObjectCo(Wnd
, &Ref
);
3187 UserRefObjectCo(WndParent
, &ParentRef
);
3189 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3191 UserDerefObjectCo(WndParent
);
3192 UserDerefObjectCo(Wnd
);
3196 hWndOldParent
= WndOldParent
->hSelf
;
3197 UserDereferenceObject(WndOldParent
);
3200 return( hWndOldParent
);
3208 * The NtUserSetParent function changes the parent window of the specified
3212 * The new parent window and the child window must belong to the same
3213 * application. If the window identified by the hWndChild parameter is
3214 * visible, the system performs the appropriate redrawing and repainting.
3215 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3216 * or WS_POPUP window styles of the window whose parent is being changed.
3223 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3225 DECLARE_RETURN(HWND
);
3227 DPRINT("Enter NtUserSetParent\n");
3228 UserEnterExclusive();
3231 Check Parent first from user space, set it here.
3235 hWndNewParent
= IntGetDesktopWindow();
3237 else if (hWndNewParent
== HWND_MESSAGE
)
3239 // hWndNewParent = IntGetMessageWindow();
3242 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3245 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3253 * UserGetShellWindow
3255 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3260 HWND FASTCALL
UserGetShellWindow()
3262 PWINSTATION_OBJECT WinStaObject
;
3265 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3270 if (!NT_SUCCESS(Status
))
3272 SetLastNtError(Status
);
3276 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3278 ObDereferenceObject(WinStaObject
);
3283 * NtUserSetShellWindowEx
3285 * This is undocumented function to set global shell window. The global
3286 * shell window has special handling of window position.
3292 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3294 PWINSTATION_OBJECT WinStaObject
;
3295 PWINDOW_OBJECT WndShell
;
3296 DECLARE_RETURN(BOOL
);
3297 USER_REFERENCE_ENTRY Ref
;
3301 DPRINT("Enter NtUserSetShellWindowEx\n");
3302 UserEnterExclusive();
3304 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3309 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3314 if (!NT_SUCCESS(Status
))
3316 SetLastNtError(Status
);
3321 * Test if we are permitted to change the shell window.
3323 if (WinStaObject
->ShellWindow
)
3325 ObDereferenceObject(WinStaObject
);
3330 * Move shell window into background.
3332 if (hwndListView
&& hwndListView
!= hwndShell
)
3335 * Disabled for now to get Explorer working.
3336 * -- Filip, 01/nov/2003
3339 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3342 if (UserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3344 ObDereferenceObject(WinStaObject
);
3349 if (UserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3351 ObDereferenceObject(WinStaObject
);
3355 UserRefObjectCo(WndShell
, &Ref
);
3356 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3358 WinStaObject
->ShellWindow
= hwndShell
;
3359 WinStaObject
->ShellListView
= hwndListView
;
3361 ti
= GetW32ThreadInfo();
3362 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3364 UserDerefObjectCo(WndShell
);
3366 ObDereferenceObject(WinStaObject
);
3370 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3376 * NtUserGetSystemMenu
3378 * The NtUserGetSystemMenu function allows the application to access the
3379 * window menu (also known as the system menu or the control menu) for
3380 * copying and modifying.
3384 * Handle to the window that will own a copy of the window menu.
3386 * Specifies the action to be taken. If this parameter is FALSE,
3387 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3388 * currently in use. The copy is initially identical to the window menu
3389 * but it can be modified.
3390 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3391 * to the default state. The previous window menu, if any, is destroyed.
3394 * If the bRevert parameter is FALSE, the return value is a handle to a
3395 * copy of the window menu. If the bRevert parameter is TRUE, the return
3403 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3405 PWINDOW_OBJECT Window
;
3407 DECLARE_RETURN(HMENU
);
3409 DPRINT("Enter NtUserGetSystemMenu\n");
3412 if (!(Window
= UserGetWindowObject(hWnd
)))
3417 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3422 RETURN(Menu
->MenuInfo
.Self
);
3425 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3431 * NtUserSetSystemMenu
3438 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3440 BOOL Result
= FALSE
;
3441 PWINDOW_OBJECT Window
;
3443 DECLARE_RETURN(BOOL
);
3445 DPRINT("Enter NtUserSetSystemMenu\n");
3446 UserEnterExclusive();
3448 if (!(Window
= UserGetWindowObject(hWnd
)))
3456 * Assign new menu handle.
3458 if (!(Menu
= UserGetMenuObject(hMenu
)))
3463 Result
= IntSetSystemMenu(Window
, Menu
);
3469 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3478 UserGetWindow(HWND hWnd
, UINT Relationship
)
3480 PWINDOW_OBJECT Parent
, Window
;
3481 HWND hWndResult
= NULL
;
3483 if (!(Window
= UserGetWindowObject(hWnd
)))
3486 switch (Relationship
)
3489 if((Parent
= Window
->Parent
))
3491 if (Parent
->FirstChild
)
3492 hWndResult
= Parent
->FirstChild
->hSelf
;
3497 if((Parent
= Window
->Parent
))
3499 if (Parent
->LastChild
)
3500 hWndResult
= Parent
->LastChild
->hSelf
;
3505 if (Window
->NextSibling
)
3506 hWndResult
= Window
->NextSibling
->hSelf
;
3510 if (Window
->PrevSibling
)
3511 hWndResult
= Window
->PrevSibling
->hSelf
;
3515 if((Parent
= UserGetWindowObject(Window
->hOwner
)))
3517 hWndResult
= Parent
->hSelf
;
3521 if (Window
->FirstChild
)
3522 hWndResult
= Window
->FirstChild
->hSelf
;
3534 * The NtUserGetWindow function retrieves a handle to a window that has the
3535 * specified relationship (Z order or owner) to the specified window.
3542 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3544 DECLARE_RETURN(HWND
);
3546 DPRINT("Enter NtUserGetWindow\n");
3549 RETURN(UserGetWindow(hWnd
, Relationship
));
3552 DPRINT("Leave NtUserGetWindow, ret=%i\n",_ret_
);
3561 * NtUserGetWindowLong
3563 * The NtUserGetWindowLong function retrieves information about the specified
3564 * window. The function also retrieves the 32-bit (long) value at the
3565 * specified offset into the extra window memory.
3572 UserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3574 PWINDOW_OBJECT Window
, Parent
;
3578 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3580 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3588 * WndProc is only available to the owner process
3590 if (GWL_WNDPROC
== Index
3591 && Window
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3593 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3597 if ((INT
)Index
>= 0)
3599 if ((Index
+ sizeof(LONG
)) > Window
->Wnd
->ExtraDataSize
)
3601 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3604 Result
= *((LONG
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3611 Result
= Wnd
->ExStyle
;
3615 Result
= Wnd
->Style
;
3619 Result
= (LONG
)IntGetWindowProc(Window
,
3624 Result
= (LONG
) Wnd
->Instance
;
3627 case GWL_HWNDPARENT
:
3628 Parent
= Window
->Parent
;
3631 if (Parent
&& Parent
->hSelf
== IntGetDesktopWindow())
3632 Result
= (LONG
) UserGetWindow(Window
->hSelf
, GW_OWNER
);
3634 Result
= (LONG
) Parent
->hSelf
;
3639 Result
= (LONG
) Wnd
->IDMenu
;
3643 Result
= Wnd
->UserData
;
3647 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3648 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3661 * NtUserGetWindowLong
3663 * The NtUserGetWindowLong function retrieves information about the specified
3664 * window. The function also retrieves the 32-bit (long) value at the
3665 * specified offset into the extra window memory.
3672 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3674 DECLARE_RETURN(LONG
);
3676 DPRINT("Enter NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3677 UserEnterExclusive();
3679 RETURN(UserGetWindowLong(hWnd
, Index
, Ansi
));
3682 DPRINT("Leave NtUserGetWindowLong, ret=%i\n",_ret_
);
3688 IntSetWindowProc(PWINDOW_OBJECT Window
,
3694 PWINDOW Wnd
= Window
->Wnd
;
3696 /* resolve any callproc handle if possible */
3697 if (IsCallProcHandle(NewWndProc
))
3699 WNDPROC_INFO wpInfo
;
3701 if (UserGetCallProcInfo((HANDLE
)NewWndProc
,
3704 NewWndProc
= wpInfo
.WindowProc
;
3705 /* FIXME - what if wpInfo.IsUnicode doesn't match Ansi? */
3709 /* attempt to get the previous window proc */
3712 Ret
= (Ansi
? Wnd
->WndProcExtra
: Wnd
->WndProc
);
3716 if (!Ansi
== Wnd
->Unicode
)
3722 CallProc
= UserFindCallProc(Wnd
->Class
,
3725 if (CallProc
== NULL
)
3727 CallProc
= CreateCallProc(NULL
,
3731 if (CallProc
== NULL
)
3733 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3737 UserAddCallProcToClass(Wnd
->Class
,
3740 /* BugBoy Comments: Added this if else, see below comments */
3747 Ret
= GetCallProcHandle(Wnd
->CallProc
);
3750 Wnd
->CallProc
= CallProc
;
3752 /* BugBoy Comments: Above sets the current CallProc for the
3753 window and below we set the Ret value to it.
3754 SetWindowLong for WNDPROC should return the previous proc
3755 Ret = GetCallProcHandle(Wnd->CallProc); */
3759 if (Wnd
->Class
->System
)
3761 /* check if the new procedure matches with the one in the
3762 window class. If so, we need to restore both procedures! */
3763 Wnd
->IsSystem
= (NewWndProc
== Wnd
->Class
->WndProc
||
3764 NewWndProc
== Wnd
->Class
->WndProcExtra
);
3768 Wnd
->WndProc
= Wnd
->Class
->WndProc
;
3769 Wnd
->WndProcExtra
= Wnd
->Class
->WndProcExtra
;
3770 Wnd
->Unicode
= !Ansi
;
3775 ASSERT(!Wnd
->IsSystem
);
3777 /* update the window procedure */
3778 Wnd
->WndProc
= NewWndProc
;
3779 Wnd
->Unicode
= !Ansi
;
3786 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3788 PWINDOW_OBJECT Window
, Parent
;
3790 PWINSTATION_OBJECT WindowStation
;
3794 if (hWnd
== IntGetDesktopWindow())
3796 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3800 if (!(Window
= UserGetWindowObject(hWnd
)))
3807 if (!Wnd
) return 0; // No go on zero.
3809 if ((INT
)Index
>= 0)
3811 if ((Index
+ sizeof(LONG
)) > Wnd
->ExtraDataSize
)
3813 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3816 OldValue
= *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
));
3817 *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
)) = NewValue
;
3824 OldValue
= (LONG
) Wnd
->ExStyle
;
3825 Style
.styleOld
= OldValue
;
3826 Style
.styleNew
= NewValue
;
3829 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3831 WindowStation
= ((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
->WindowStation
;
3834 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3835 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3838 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3839 Wnd
->ExStyle
= (DWORD
)Style
.styleNew
;
3840 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3844 OldValue
= (LONG
) Wnd
->Style
;
3845 Style
.styleOld
= OldValue
;
3846 Style
.styleNew
= NewValue
;
3847 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3848 Wnd
->Style
= (DWORD
)Style
.styleNew
;
3849 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3854 /* FIXME: should check if window belongs to current process */
3855 OldValue
= (LONG
)IntSetWindowProc(Window
,
3862 OldValue
= (LONG
) Wnd
->Instance
;
3863 Wnd
->Instance
= (HINSTANCE
) NewValue
;
3866 case GWL_HWNDPARENT
:
3867 Parent
= Window
->Parent
;
3868 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
3869 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
3871 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
3875 OldValue
= (LONG
) Wnd
->IDMenu
;
3876 Wnd
->IDMenu
= (UINT
) NewValue
;
3880 OldValue
= Wnd
->UserData
;
3881 Wnd
->UserData
= NewValue
;
3885 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3886 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3898 * NtUserSetWindowLong
3900 * The NtUserSetWindowLong function changes an attribute of the specified
3901 * window. The function also sets the 32-bit (long) value at the specified
3902 * offset into the extra window memory.
3909 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3911 DECLARE_RETURN(LONG
);
3913 DPRINT("Enter NtUserSetWindowLong\n");
3914 UserEnterExclusive();
3916 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3919 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3925 * NtUserSetWindowWord
3927 * Legacy function similar to NtUserSetWindowLong.
3934 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3936 PWINDOW_OBJECT Window
;
3938 DECLARE_RETURN(WORD
);
3940 DPRINT("Enter NtUserSetWindowWord\n");
3941 UserEnterExclusive();
3943 if (!(Window
= UserGetWindowObject(hWnd
)))
3952 case GWL_HWNDPARENT
:
3953 RETURN( co_UserSetWindowLong(Window
->hSelf
, Index
, (UINT
)NewValue
, TRUE
));
3957 SetLastWin32Error(ERROR_INVALID_INDEX
);
3962 if (Index
> Window
->Wnd
->ExtraDataSize
- sizeof(WORD
))
3964 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3968 OldValue
= *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3969 *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
)) = NewValue
;
3974 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3983 NtUserGetWindowPlacement(HWND hWnd
,
3984 WINDOWPLACEMENT
*lpwndpl
)
3986 PWINDOW_OBJECT Window
;
3989 WINDOWPLACEMENT Safepl
;
3991 DECLARE_RETURN(BOOL
);
3993 DPRINT("Enter NtUserGetWindowPlacement\n");
3996 if (!(Window
= UserGetWindowObject(hWnd
)))
4002 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4003 if(!NT_SUCCESS(Status
))
4005 SetLastNtError(Status
);
4008 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4014 if (0 == (Wnd
->Style
& WS_VISIBLE
))
4016 Safepl
.showCmd
= SW_HIDE
;
4018 else if ((0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
4019 0 != (Wnd
->Style
& WS_MAXIMIZE
)) &&
4020 0 == (Wnd
->Style
& WS_MINIMIZE
))
4022 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
4024 else if (0 != (Wnd
->Style
& WS_MINIMIZE
))
4026 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
4028 else if (0 != (Wnd
->Style
& WS_VISIBLE
))
4030 Safepl
.showCmd
= SW_SHOWNORMAL
;
4033 Size
.x
= Wnd
->WindowRect
.left
;
4034 Size
.y
= Wnd
->WindowRect
.top
;
4035 WinPosInitInternalPos(Window
, &Size
,
4038 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
4039 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
4040 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
4042 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
4043 if(!NT_SUCCESS(Status
))
4045 SetLastNtError(Status
);
4052 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
4062 NtUserLockWindowUpdate(HWND hWnd
)
4082 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
4083 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
4084 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
4088 QueryWindow based on KJK::Hyperion and James Tabor.
4090 0 = QWUniqueProcessId
4091 1 = QWUniqueThreadId
4094 4 = QWIsHung Implements IsHungAppWindow found
4097 9 = QWKillWindow When I called this with hWnd ==
4098 DesktopWindow, it shutdown the system
4105 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
4107 PWINDOW_OBJECT Window
;
4109 DECLARE_RETURN(UINT
);
4111 DPRINT("Enter NtUserQueryWindow\n");
4114 if (!(Window
= UserGetWindowObject(hWnd
)))
4121 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
4122 Result
= (DWORD
)IntGetWndProcessId(Window
);
4125 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
4126 Result
= (DWORD
)IntGetWndThreadId(Window
);
4129 case QUERY_WINDOW_ACTIVE
:
4130 Result
= (DWORD
)UserGetActiveWindow();
4133 case QUERY_WINDOW_FOCUS
:
4134 Result
= (DWORD
)IntGetFocusWindow();
4137 case QUERY_WINDOW_ISHUNG
:
4138 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
4142 Result
= (DWORD
)NULL
;
4149 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
4159 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
4173 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4175 UNICODE_STRING SafeMessageName
;
4178 DECLARE_RETURN(UINT
);
4180 DPRINT("Enter NtUserRegisterWindowMessage\n");
4181 UserEnterExclusive();
4183 if(MessageNameUnsafe
== NULL
)
4185 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4189 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4190 if(!NT_SUCCESS(Status
))
4192 SetLastNtError(Status
);
4196 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4198 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4202 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
4212 NtUserSetImeOwnerWindow(DWORD Unknown0
,
4225 NtUserSetInternalWindowPos(
4242 NtUserSetLayeredWindowAttributes(HWND hwnd
,
4256 NtUserSetLogonNotifyWindow(HWND hWnd
)
4273 PWINDOW_OBJECT Window
;
4275 DECLARE_RETURN(BOOL
);
4277 DPRINT("Enter NtUserSetMenu\n");
4278 UserEnterExclusive();
4280 if (!(Window
= UserGetWindowObject(hWnd
)))
4285 if (! IntSetMenu(Window
, Menu
, &Changed
))
4290 if (Changed
&& Repaint
)
4292 USER_REFERENCE_ENTRY Ref
;
4294 UserRefObjectCo(Window
, &Ref
);
4295 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4296 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4298 UserDerefObjectCo(Window
);
4304 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4314 NtUserSetWindowFNID(HWND hWnd
,
4317 PWINDOW_OBJECT Window
;
4319 DECLARE_RETURN(BOOL
);
4321 DPRINT("Enter NtUserSetWindowFNID\n");
4322 UserEnterExclusive();
4324 if (!(Window
= UserGetWindowObject(hWnd
)))
4331 { // From user land we only set these.
4332 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
4337 Wnd
->Class
->fnID
|= fnID
;
4342 DPRINT("Leave NtUserSetWindowFNID\n");
4352 NtUserSetWindowPlacement(HWND hWnd
,
4353 WINDOWPLACEMENT
*lpwndpl
)
4355 PWINDOW_OBJECT Window
;
4357 WINDOWPLACEMENT Safepl
;
4359 DECLARE_RETURN(BOOL
);
4360 USER_REFERENCE_ENTRY Ref
;
4362 DPRINT("Enter NtUserSetWindowPlacement\n");
4363 UserEnterExclusive();
4365 if (!(Window
= UserGetWindowObject(hWnd
)))
4371 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4372 if(!NT_SUCCESS(Status
))
4374 SetLastNtError(Status
);
4377 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4382 UserRefObjectCo(Window
, &Ref
);
4384 if ((Wnd
->Style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4386 co_WinPosSetWindowPos(Window
, NULL
,
4387 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4388 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4389 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4390 SWP_NOZORDER
| SWP_NOACTIVATE
);
4393 /* FIXME - change window status */
4394 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
4396 Wnd
->InternalPosInitialized
= TRUE
;
4397 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4398 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4399 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4401 UserDerefObjectCo(Window
);
4405 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4417 HWND hWndInsertAfter
,
4424 DECLARE_RETURN(BOOL
);
4425 PWINDOW_OBJECT Window
;
4427 USER_REFERENCE_ENTRY Ref
;
4429 DPRINT("Enter NtUserSetWindowPos\n");
4430 UserEnterExclusive();
4432 if (!(Window
= UserGetWindowObject(hWnd
)))
4437 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
4438 if (!(uFlags
& SWP_NOMOVE
))
4440 if (X
< -32768) X
= -32768;
4441 else if (X
> 32767) X
= 32767;
4442 if (Y
< -32768) Y
= -32768;
4443 else if (Y
> 32767) Y
= 32767;
4445 if (!(uFlags
& SWP_NOSIZE
))
4448 else if (cx
> 32767) cx
= 32767;
4450 else if (cy
> 32767) cy
= 32767;
4453 UserRefObjectCo(Window
, &Ref
);
4454 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4455 UserDerefObjectCo(Window
);
4460 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4467 IntGetWindowRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
4485 /* Create a new window region using the window rectangle */
4486 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->WindowRect
);
4487 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->WindowRect
.left
, -Window
->Wnd
->WindowRect
.top
);
4488 /* if there's a region assigned to the window, combine them both */
4489 if(Window
->WindowRegion
&& !(Wnd
->Style
& WS_MINIMIZE
))
4490 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4491 /* Copy the region into hRgn */
4492 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4494 if((pRgn
= REGION_LockRgn(hRgn
)))
4496 Ret
= pRgn
->rdh
.iType
;
4497 REGION_UnlockRgn(pRgn
);
4502 GreDeleteObject(VisRgn
);
4508 IntGetWindowRgnBox(PWINDOW_OBJECT Window
, RECTL
*Rect
)
4526 /* Create a new window region using the window rectangle */
4527 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->WindowRect
);
4528 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->WindowRect
.left
, -Window
->Wnd
->WindowRect
.top
);
4529 /* if there's a region assigned to the window, combine them both */
4530 if(Window
->WindowRegion
&& !(Wnd
->Style
& WS_MINIMIZE
))
4531 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4533 if((pRgn
= REGION_LockRgn(VisRgn
)))
4535 Ret
= pRgn
->rdh
.iType
;
4536 *Rect
= pRgn
->rdh
.rcBound
;
4537 REGION_UnlockRgn(pRgn
);
4542 GreDeleteObject(VisRgn
);
4557 PWINDOW_OBJECT Window
;
4558 DECLARE_RETURN(INT
);
4560 DPRINT("Enter NtUserSetWindowRgn\n");
4561 UserEnterExclusive();
4563 if (!(Window
= UserGetWindowObject(hWnd
)))
4568 /* FIXME - Verify if hRgn is a valid handle!!!!
4569 Propably make this operation thread-safe, but maybe it's not necessary */
4571 if(Window
->WindowRegion
)
4573 /* Delete no longer needed region handle */
4574 GreDeleteObject(Window
->WindowRegion
);
4576 Window
->WindowRegion
= hRgn
;
4578 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4582 USER_REFERENCE_ENTRY Ref
;
4583 UserRefObjectCo(Window
, &Ref
);
4584 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4585 UserDerefObjectCo(Window
);
4591 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4601 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4603 PWINDOW_OBJECT Window
;
4605 DECLARE_RETURN(BOOL
);
4606 USER_REFERENCE_ENTRY Ref
;
4608 DPRINT("Enter NtUserShowWindow\n");
4609 UserEnterExclusive();
4611 if (!(Window
= UserGetWindowObject(hWnd
)))
4616 UserRefObjectCo(Window
, &Ref
);
4617 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4618 UserDerefObjectCo(Window
);
4623 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4633 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4639 return NtUserShowWindow(hWnd
, nCmdShow
);
4649 NtUserUpdateLayeredWindow(
4657 BLENDFUNCTION
*pblend
,
4671 NtUserWindowFromPoint(LONG X
, LONG Y
)
4675 PWINDOW_OBJECT DesktopWindow
= NULL
, Window
= NULL
;
4676 DECLARE_RETURN(HWND
);
4677 USER_REFERENCE_ENTRY Ref
;
4679 DPRINT("Enter NtUserWindowFromPoint\n");
4680 UserEnterExclusive();
4682 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4690 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4691 //its possible this referencing is useless, thou it shouldnt hurt...
4692 UserRefObjectCo(DesktopWindow
, &Ref
);
4694 pti
= PsGetCurrentThreadWin32Thread();
4695 Hit
= co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4699 Ret
= Window
->hSelf
;
4708 if (Window
) UserDereferenceObject(Window
);
4709 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4711 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4721 * Undocumented function that is called from DefWindowProc to set
4728 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4730 PWINDOW_OBJECT Window
;
4732 LARGE_STRING SafeText
;
4733 UNICODE_STRING UnicodeString
;
4736 DPRINT("Enter NtUserDefSetText\n");
4738 if (WindowText
!= NULL
)
4742 SafeText
= ProbeForReadLargeString(WindowText
);
4744 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4747 SetLastNtError(_SEH2_GetExceptionCode());
4757 UserEnterExclusive();
4759 if(!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4766 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4767 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4768 // Now we know what the bAnsi is for.
4769 RtlInitUnicodeString(&UnicodeString
, NULL
);
4770 if (SafeText
.Buffer
)
4775 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4777 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4778 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4780 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4783 SetLastNtError(_SEH2_GetExceptionCode());
4786 if (!Ret
) goto Exit
;
4789 if (UnicodeString
.Length
!= 0)
4791 if (Wnd
->WindowName
.MaximumLength
> 0 &&
4792 UnicodeString
.Length
<= Wnd
->WindowName
.MaximumLength
- sizeof(UNICODE_NULL
))
4794 ASSERT(Wnd
->WindowName
.Buffer
!= NULL
);
4796 Wnd
->WindowName
.Length
= UnicodeString
.Length
;
4797 Wnd
->WindowName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4798 RtlCopyMemory(Wnd
->WindowName
.Buffer
,
4799 UnicodeString
.Buffer
,
4800 UnicodeString
.Length
);
4805 Wnd
->WindowName
.MaximumLength
= Wnd
->WindowName
.Length
= 0;
4806 buf
= Wnd
->WindowName
.Buffer
;
4807 Wnd
->WindowName
.Buffer
= NULL
;
4810 DesktopHeapFree(Wnd
->pdesktop
, buf
);
4813 Wnd
->WindowName
.Buffer
= DesktopHeapAlloc(Wnd
->pdesktop
,
4814 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4815 if (Wnd
->WindowName
.Buffer
!= NULL
)
4817 Wnd
->WindowName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4818 RtlCopyMemory(Wnd
->WindowName
.Buffer
,
4819 UnicodeString
.Buffer
,
4820 UnicodeString
.Length
);
4821 Wnd
->WindowName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4822 Wnd
->WindowName
.Length
= UnicodeString
.Length
;
4826 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4834 Wnd
->WindowName
.Length
= 0;
4835 if (Wnd
->WindowName
.Buffer
!= NULL
)
4836 Wnd
->WindowName
.Buffer
[0] = L
'\0';
4839 // HAX! FIXME! Windows does not do this in here!
4840 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4841 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4842 /* Send shell notifications */
4843 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
4845 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4850 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4851 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4857 * NtUserInternalGetWindowText
4864 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4866 PWINDOW_OBJECT Window
;
4870 DECLARE_RETURN(INT
);
4872 DPRINT("Enter NtUserInternalGetWindowText\n");
4875 if(lpString
&& (nMaxCount
<= 1))
4877 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4881 if(!(Window
= UserGetWindowObject(hWnd
)))
4887 Result
= Wnd
->WindowName
.Length
/ sizeof(WCHAR
);
4890 const WCHAR Terminator
= L
'\0';
4892 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4894 Copy
= min(nMaxCount
- 1, Result
);
4897 Status
= MmCopyToCaller(Buffer
, Wnd
->WindowName
.Buffer
, Copy
* sizeof(WCHAR
));
4898 if(!NT_SUCCESS(Status
))
4900 SetLastNtError(Status
);
4906 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4907 if(!NT_SUCCESS(Status
))
4909 SetLastNtError(Status
);
4919 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4927 IntShowOwnedPopups(PWINDOW_OBJECT OwnerWnd
, BOOL fShow
)
4930 PWINDOW_OBJECT pWnd
;
4933 // ASSERT(OwnerWnd);
4935 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
4940 while (win_array
[count
])
4942 while (--count
>= 0)
4944 if (UserGetWindow( win_array
[count
], GW_OWNER
) != OwnerWnd
->hSelf
)
4946 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4948 // if (pWnd == WND_OTHER_PROCESS) continue;
4952 if (pWnd
->Flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
)
4954 /* In Windows, ShowOwnedPopups(TRUE) generates
4955 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4956 * regardless of the state of the owner
4958 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4964 if (pWnd
->Wnd
->Style
& WS_VISIBLE
)
4966 /* In Windows, ShowOwnedPopups(FALSE) generates
4967 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4968 * regardless of the state of the owner
4970 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4976 ExFreePool( win_array
);
4981 * NtUserValidateHandleSecure
4989 NtUserValidateHandleSecure(
4997 PUSER_HANDLE_ENTRY entry
;
4998 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
5000 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5003 uType
= entry
->type
;
5009 PWINDOW_OBJECT Window
;
5010 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
5016 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
5021 PACCELERATOR_TABLE Accel
;
5022 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
5027 PCURICON_OBJECT Cursor
;
5028 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
5034 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
5039 PMONITOR_OBJECT Monitor
;
5040 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
5046 return UserGetCallProcInfo( handle
, &Proc
);
5049 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5053 { /* Is handle entry restricted? */