2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
5 * FILE: subsystems/win32/win32k/ntuser/window.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
11 /* INCLUDES ******************************************************************/
19 /* dialog resources appear to pass this in 16 bits, handle them properly */
20 #define CW_USEDEFAULT16 (0x8000)
22 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
24 /* PRIVATE FUNCTIONS **********************************************************/
29 * Initialize windowing implementation.
35 return STATUS_SUCCESS
;
41 * Cleanup windowing implementation.
45 CleanupWindowImpl(VOID
)
47 return STATUS_SUCCESS
;
50 /* HELPER FUNCTIONS ***********************************************************/
52 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
54 WORD Action
= LOWORD(wParam
);
55 WORD Flags
= HIWORD(wParam
);
57 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
59 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
66 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
70 if (Flags
& UISF_HIDEFOCUS
)
71 Wnd
->HideFocus
= TRUE
;
72 if (Flags
& UISF_HIDEACCEL
)
73 Wnd
->HideAccel
= TRUE
;
77 if (Flags
& UISF_HIDEFOCUS
)
78 Wnd
->HideFocus
= FALSE
;
79 if (Flags
& UISF_HIDEACCEL
)
80 Wnd
->HideAccel
= FALSE
;
87 PWINDOW_OBJECT FASTCALL
IntGetWindowObject(HWND hWnd
)
89 PWINDOW_OBJECT Window
;
91 if (!hWnd
) return NULL
;
93 Window
= UserGetWindowObject(hWnd
);
96 ASSERT(Window
->head
.cLockObj
>= 0);
98 Window
->head
.cLockObj
++;
104 PWINDOW_OBJECT FASTCALL
UserGetWindowObject(HWND hWnd
)
107 PWINDOW_OBJECT Window
;
109 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
111 ti
= GetW32ThreadInfo();
114 SetLastWin32Error(ERROR_ACCESS_DENIED
);
121 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
125 Window
= (PWINDOW_OBJECT
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
126 if (!Window
|| 0 != (Window
->state
& WINDOWSTATUS_DESTROYED
))
128 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
132 ASSERT(Window
->head
.cLockObj
>= 0);
140 * The function determines whether the specified window handle identifies
141 * an existing window.
145 * Handle to the window to test.
148 * If the window handle identifies an existing window, the return value
149 * is TRUE. If the window handle does not identify an existing window,
150 * the return value is FALSE.
154 IntIsWindow(HWND hWnd
)
156 PWINDOW_OBJECT Window
;
158 if (!(Window
= UserGetWindowObject(hWnd
)))
167 Caller must NOT dereference retval!
168 But if caller want the returned value to persist spanning a co_ call,
169 it must reference the value (because the owner is not garanteed to
170 exist just because the owned window exist)!
172 PWINDOW_OBJECT FASTCALL
173 IntGetParent(PWINDOW_OBJECT Wnd
)
175 if (!Wnd
->Wnd
) return NULL
;
177 if (Wnd
->Wnd
->style
& WS_POPUP
)
179 return UserGetWindowObject(Wnd
->hOwner
);
181 else if (Wnd
->Wnd
->style
& WS_CHILD
)
183 return Wnd
->spwndParent
;
191 Caller must NOT dereference retval!
192 But if caller want the returned value to persist spanning a co_ call,
193 it must reference the value (because the owner is not garanteed to
194 exist just because the owned window exist)!
196 PWINDOW_OBJECT FASTCALL
197 IntGetOwner(PWINDOW_OBJECT Wnd
)
199 return UserGetWindowObject(Wnd
->hOwner
);
207 * Compile a list of all child window handles from given window.
210 * This function is similar to Wine WIN_ListChildren. The caller
211 * must free the returned list with ExFreePool.
215 IntWinListChildren(PWINDOW_OBJECT Window
)
217 PWINDOW_OBJECT Child
;
219 UINT Index
, NumChildren
= 0;
221 if (!Window
) return NULL
;
223 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
226 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
229 DPRINT1("Failed to allocate memory for children array\n");
230 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
233 for (Child
= Window
->spwndChild
, Index
= 0;
235 Child
= Child
->spwndNext
, ++Index
)
236 List
[Index
] = Child
->hSelf
;
242 /***********************************************************************
245 static void IntSendDestroyMsg(HWND hWnd
)
248 PWINDOW_OBJECT Window
;
253 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
255 if (hWnd
== info
.hwndCaret
)
262 Window
= UserGetWindowObject(hWnd
);
265 // USER_REFERENCE_ENTRY Ref;
266 // UserRefObjectCo(Window, &Ref);
268 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
270 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
273 // UserDerefObjectCo(Window);
276 /* The window could already be destroyed here */
279 * Send the WM_DESTROY to the window.
282 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
285 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
286 * make sure that the window still exists when we come back.
295 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
298 /* start from the end (FIXME: is this needed?) */
299 for (i
= 0; pWndArray
[i
]; i
++)
304 if (IsWindow( pWndArray
[i
] ))
305 WIN_SendDestroyMsg( pWndArray
[i
] );
307 HeapFree(GetProcessHeap(), 0, pWndArray
);
311 DPRINT("destroyed itself while in WM_DESTROY!\n");
317 UserFreeWindowInfo(PTHREADINFO ti
, PWINDOW_OBJECT WindowObject
)
319 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
320 PWND Wnd
= WindowObject
->Wnd
;
324 if (ClientInfo
->CallbackWnd
.pvWnd
== DesktopHeapAddressToUser(WindowObject
->Wnd
))
326 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
327 ClientInfo
->CallbackWnd
.pvWnd
= NULL
;
330 if (Wnd
->strName
.Buffer
!= NULL
)
332 Wnd
->strName
.Length
= 0;
333 Wnd
->strName
.MaximumLength
= 0;
334 DesktopHeapFree(Wnd
->head
.rpdesk
,
335 Wnd
->strName
.Buffer
);
336 Wnd
->strName
.Buffer
= NULL
;
339 DesktopHeapFree(Wnd
->head
.rpdesk
, Wnd
);
340 WindowObject
->Wnd
= NULL
;
343 /***********************************************************************
346 * Destroy storage associated to a window. "Internals" p.358
348 * This is the "functional" DestroyWindows function ei. all stuff
349 * done in CreateWindow is undone here and not in DestroyWindow:-P
352 static LRESULT
co_UserFreeWindow(PWINDOW_OBJECT Window
,
353 PPROCESSINFO ProcessData
,
354 PTHREADINFO ThreadData
,
355 BOOLEAN SendMessages
)
359 PWINDOW_OBJECT Child
;
361 BOOLEAN BelongsToThreadData
;
368 if(Window
->state
& WINDOWSTATUS_DESTROYING
)
370 DPRINT("Tried to call IntDestroyWindow() twice\n");
373 Window
->state
|= WINDOWSTATUS_DESTROYING
;
374 Wnd
->style
&= ~WS_VISIBLE
;
376 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Wnd
, OBJID_WINDOW
, 0);
378 /* remove the window already at this point from the thread window list so we
379 don't get into trouble when destroying the thread windows while we're still
380 in IntDestroyWindow() */
381 RemoveEntryList(&Window
->ThreadListEntry
);
383 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
385 IntDeRegisterShellHookWindow(Window
->hSelf
);
389 /* Send destroy messages */
390 IntSendDestroyMsg(Window
->hSelf
);
393 /* free child windows */
394 Children
= IntWinListChildren(Window
);
397 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
399 if ((Child
= IntGetWindowObject(*ChildHandle
)))
401 if(!IntWndBelongsToThread(Child
, ThreadData
))
403 /* send WM_DESTROY messages to windows not belonging to the same thread */
404 IntSendDestroyMsg(Child
->hSelf
);
407 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
409 UserDereferenceObject(Child
);
412 ExFreePool(Children
);
418 * Clear the update region to make sure no WM_PAINT messages will be
419 * generated for this window while processing the WM_NCDESTROY.
421 co_UserRedrawWindow(Window
, NULL
, 0,
422 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
423 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
424 if(BelongsToThreadData
)
425 co_IntSendMessage(Window
->hSelf
, WM_NCDESTROY
, 0, 0);
427 MsqRemoveTimersWindow(ThreadData
->MessageQueue
, Window
->hSelf
);
428 HOOK_DestroyThreadHooks(ThreadData
->pEThread
); // This is needed here too!
430 /* flush the message queue */
431 MsqRemoveWindowMessagesFromQueue(Window
);
433 /* from now on no messages can be sent to this window anymore */
434 Window
->state
|= WINDOWSTATUS_DESTROYED
;
435 Wnd
->state
|= WNDS_DESTROYED
;
436 Wnd
->fnid
|= FNID_FREED
;
438 /* don't remove the WINDOWSTATUS_DESTROYING bit */
440 /* reset shell window handles */
441 if(ThreadData
->rpdesk
)
443 if (Window
->hSelf
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
444 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
446 if (Window
->hSelf
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
447 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
450 /* Unregister hot keys */
451 UnregisterWindowHotKeys (Window
);
453 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
457 WinPosCheckInternalPos(Window
->hSelf
);
458 if (Window
->hSelf
== GetCapture())
463 /* free resources associated with the window */
464 TIMER_RemoveWindowTimers(Window
->hSelf
);
467 if (!(Wnd
->style
& WS_CHILD
) && Wnd
->IDMenu
468 && (Menu
= UserGetMenuObject((HMENU
)Wnd
->IDMenu
)))
470 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
474 if(Window
->SystemMenu
475 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
477 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
478 Window
->SystemMenu
= (HMENU
)0;
481 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
484 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
485 CLASS_RemoveWindow(Window
->Class
);
488 IntUnlinkWindow(Window
);
490 UserReferenceObject(Window
);
491 UserDeleteObject(Window
->hSelf
, otWindow
);
493 IntDestroyScrollBars(Window
);
495 /* dereference the class */
496 IntDereferenceClass(Wnd
->pcls
,
497 Window
->pti
->pDeskInfo
,
503 GreDeleteObject(Window
->hrgnClip
);
506 ASSERT(Window
->Wnd
!= NULL
);
507 UserFreeWindowInfo(Window
->pti
, Window
);
509 UserDereferenceObject(Window
);
511 IntClipboardFreeWindow(Window
);
517 IntGetWindowBorderMeasures(PWINDOW_OBJECT Window
, UINT
*cx
, UINT
*cy
)
519 PWND Wnd
= Window
->Wnd
;
520 if(HAS_DLGFRAME(Wnd
->style
, Wnd
->ExStyle
) && !(Wnd
->style
& WS_MINIMIZE
))
522 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
523 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
527 if(HAS_THICKFRAME(Wnd
->style
, Wnd
->ExStyle
)&& !(Wnd
->style
& WS_MINIMIZE
))
529 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
530 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
532 else if(HAS_THINFRAME(Wnd
->style
, Wnd
->ExStyle
))
534 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
535 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
545 // Same as User32:IntGetWndProc.
548 IntGetWindowProc(PWND pWnd
,
553 WNDPROC gcpd
, Ret
= 0;
555 ASSERT(UserIsEnteredExclusive() == TRUE
);
559 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
561 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
563 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
566 Ret
= GETPFNCLIENTA(i
);
568 Ret
= GETPFNCLIENTW(i
);
574 if (Class
->fnid
== FNID_EDIT
)
575 Ret
= pWnd
->lpfnWndProc
;
578 Ret
= pWnd
->lpfnWndProc
;
580 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
584 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
585 Ret
= GETPFNCLIENTA(Class
->fnid
);
589 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
590 Ret
= GETPFNCLIENTW(Class
->fnid
);
593 if ( Ret
!= pWnd
->lpfnWndProc
)
596 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
599 gcpd
= (WNDPROC
)UserGetCPD(
601 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
604 return (gcpd
? gcpd
: Ret
);
608 IntSetWindowProc(PWND pWnd
,
613 PCALLPROCDATA CallProc
;
615 WNDPROC Ret
, chWndProc
= NULL
;
617 // Retrieve previous window proc.
618 Ret
= IntGetWindowProc(pWnd
, Ansi
);
622 if (IsCallProcHandle(NewWndProc
))
624 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, otCallProc
);
626 { // Reset new WndProc.
627 NewWndProc
= CallProc
->pfnClientPrevious
;
628 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
629 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
632 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
633 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
635 if (GETPFNCLIENTW(i
) == NewWndProc
)
637 chWndProc
= GETPFNSERVER(i
);
640 if (GETPFNCLIENTA(i
) == NewWndProc
)
642 chWndProc
= GETPFNSERVER(i
);
646 // If match, set/reset to Server Side and clear ansi.
649 pWnd
->lpfnWndProc
= chWndProc
;
650 pWnd
->Unicode
= TRUE
;
651 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
652 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
656 pWnd
->Unicode
= !Ansi
;
657 // Handle the state change in here.
659 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
661 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
663 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
664 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
666 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
668 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
672 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
673 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
677 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
678 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
681 // Now set the new window proc.
682 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
687 // Move this to user space!
689 IntGetWindowInfo(PWINDOW_OBJECT Window
, PWINDOWINFO pwi
)
691 PWND Wnd
= Window
->Wnd
;
693 pwi
->cbSize
= sizeof(WINDOWINFO
);
694 pwi
->rcWindow
= Window
->Wnd
->rcWindow
;
695 pwi
->rcClient
= Window
->Wnd
->rcClient
;
696 pwi
->dwStyle
= Wnd
->style
;
697 pwi
->dwExStyle
= Wnd
->ExStyle
;
698 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Window
->hSelf
); /* WS_ACTIVECAPTION */
699 IntGetWindowBorderMeasures(Window
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
700 pwi
->atomWindowType
= (Wnd
->pcls
? Wnd
->pcls
->atomClassName
: 0);
701 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
707 PWINDOW_OBJECT Window
,
711 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
712 PWND Wnd
= Window
->Wnd
;
714 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
716 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
720 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
728 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
729 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Window
->hSelf
);
738 NewMenu
= IntGetMenuObject(Menu
);
743 IntReleaseMenuObject(OldMenu
);
745 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
748 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
750 /* Can't use the same menu for two windows */
753 IntReleaseMenuObject(OldMenu
);
755 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
761 Wnd
->IDMenu
= (UINT
) Menu
;
764 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
765 IntReleaseMenuObject(NewMenu
);
769 OldMenu
->MenuInfo
.Wnd
= NULL
;
770 IntReleaseMenuObject(OldMenu
);
777 /* INTERNAL ******************************************************************/
781 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
786 USER_REFERENCE_ENTRY Ref
;
787 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
789 while (!IsListEmpty(&WThread
->WindowListHead
))
791 Current
= WThread
->WindowListHead
.Flink
;
792 Wnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
794 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
796 /* window removes itself from the list */
799 fixme: it is critical that the window removes itself! if now, we will loop
803 //ASSERT(co_UserDestroyWindow(Wnd));
805 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
806 if (!co_UserDestroyWindow(Wnd
))
808 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
810 UserDerefObjectCo(Wnd
);//faxme: temp hack??
818 * Returns client window rectangle relative to the upper-left corner of client area.
820 * \note Does not check the validity of the parameters
823 IntGetClientRect(PWINDOW_OBJECT Window
, RECTL
*Rect
)
828 Rect
->left
= Rect
->top
= 0;
829 Rect
->right
= Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
;
830 Rect
->bottom
= Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
;
836 IntGetFocusWindow(VOID
)
838 PUSER_MESSAGE_QUEUE Queue
;
839 PDESKTOP pdo
= IntGetActiveDesktop();
844 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
849 return(Queue
->FocusWindow
);
853 PMENU_OBJECT FASTCALL
854 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
)
856 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
857 PTHREADINFO W32Thread
;
858 HMENU hNewMenu
, hSysMenu
;
859 ROSMENUITEMINFO ItemInfo
;
863 W32Thread
= PsGetCurrentThreadWin32Thread();
865 if(!W32Thread
->rpdesk
)
868 if(Window
->SystemMenu
)
870 Menu
= UserGetMenuObject(Window
->SystemMenu
);
873 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
874 Window
->SystemMenu
= (HMENU
)0;
878 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
880 /* clone system menu */
881 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
885 NewMenu
= IntCloneMenu(Menu
);
888 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
889 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
890 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
892 //IntReleaseMenuObject(NewMenu);
897 hSysMenu
= UserCreateMenu(FALSE
);
898 if (NULL
== hSysMenu
)
902 SysMenu
= IntGetMenuObject(hSysMenu
);
905 UserDestroyMenu(hSysMenu
);
908 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
909 SysMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
910 hNewMenu
= co_IntLoadSysMenuTemplate();
913 IntReleaseMenuObject(SysMenu
);
914 UserDestroyMenu(hSysMenu
);
917 Menu
= IntGetMenuObject(hNewMenu
);
920 IntReleaseMenuObject(SysMenu
);
921 UserDestroyMenu(hSysMenu
);
925 NewMenu
= IntCloneMenu(Menu
);
928 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
929 IntReleaseMenuObject(NewMenu
);
930 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
932 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
933 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
934 ItemInfo
.fType
= MF_POPUP
;
935 ItemInfo
.fState
= MFS_ENABLED
;
936 ItemInfo
.dwTypeData
= NULL
;
938 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
939 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
941 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
945 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
954 if(Window
->SystemMenu
)
955 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
963 IntIsChildWindow(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT BaseWindow
)
965 PWINDOW_OBJECT Window
;
972 if (Window
== Parent
)
976 if(!(Wnd
->style
& WS_CHILD
))
981 Window
= Window
->spwndParent
;
988 IntIsWindowVisible(PWINDOW_OBJECT BaseWindow
)
990 PWINDOW_OBJECT Window
;
997 if(!(Wnd
->style
& WS_CHILD
))
1001 if(!(Wnd
->style
& WS_VISIBLE
))
1006 Window
= Window
->spwndParent
;
1009 if(Window
&& Wnd
->style
& WS_VISIBLE
)
1021 PWND WndPrevSibling
) /* set to NULL if top sibling */
1023 Wnd
->spwndParent
= WndParent
;
1024 if ((Wnd
->spwndPrev
= WndPrevSibling
))
1026 /* link after WndPrevSibling */
1027 if ((Wnd
->spwndNext
= WndPrevSibling
->spwndNext
))
1028 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1030 Wnd
->spwndPrev
->spwndNext
= Wnd
;
1035 if ((Wnd
->spwndNext
= WndParent
->spwndChild
))
1036 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1038 WndParent
->spwndChild
= Wnd
;
1043 /* link the window into siblings and parent. children are kept in place. */
1047 PWINDOW_OBJECT WndParent
,
1048 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
1051 PWINDOW_OBJECT Parent
;
1053 IntLinkWnd(Wnd
->Wnd
,
1055 WndPrevSibling
? WndPrevSibling
->Wnd
: NULL
);
1057 Wnd
->spwndParent
= WndParent
;
1058 if ((Wnd
->spwndPrev
= WndPrevSibling
))
1060 /* link after WndPrevSibling */
1061 if ((Wnd
->spwndNext
= WndPrevSibling
->spwndNext
))
1062 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1063 Wnd
->spwndPrev
->spwndNext
= Wnd
;
1068 Parent
= Wnd
->spwndParent
;
1069 if ((Wnd
->spwndNext
= WndParent
->spwndChild
))
1070 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1073 Parent
->spwndChild
= Wnd
;
1078 Parent
->spwndChild
= Wnd
;
1085 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1087 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
1090 Wnd
= IntGetWindowObject(hWnd
);
1094 WndOldOwner
= IntGetWindowObject(Wnd
->hOwner
);
1097 ret
= WndOldOwner
->hSelf
;
1098 UserDereferenceObject(WndOldOwner
);
1105 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1107 Wnd
->hOwner
= hWndNewOwner
;
1108 Wnd
->Wnd
->spwndOwner
= WndNewOwner
->Wnd
;
1113 Wnd
->Wnd
->spwndOwner
= NULL
;
1116 UserDereferenceObject(Wnd
);
1120 PWINDOW_OBJECT FASTCALL
1121 co_IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
1123 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
1124 // HWND hWnd, hWndNewParent;
1128 ASSERT(WndNewParent
);
1129 ASSERT_REFS_CO(Wnd
);
1130 ASSERT_REFS_CO(WndNewParent
);
1132 // hWnd = Wnd->hSelf;
1133 // hWndNewParent = WndNewParent->hSelf;
1135 /* Some applications try to set a child as a parent */
1136 if (IntIsChildWindow(Wnd
, WndNewParent
))
1138 SetLastWin32Error( ERROR_INVALID_PARAMETER
);
1143 * Windows hides the window first, then shows it again
1144 * including the WM_SHOWWINDOW messages and all
1146 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1148 // /* Validate that window and parent still exist */
1149 // if (!IntIsWindow(hWnd) || !IntIsWindow(hWndNewParent))
1152 /* Window must belong to current process */
1153 if (Wnd
->pti
->pEThread
->ThreadsProcess
!= PsGetCurrentProcess())
1156 WndOldParent
= Wnd
->spwndParent
;
1158 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1160 if (WndNewParent
!= WndOldParent
)
1162 IntUnlinkWindow(Wnd
);
1164 if (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1166 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
1167 Sibling
= WndNewParent
->spwndChild
;
1168 while (NULL
!= Sibling
&& 0 != (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1170 InsertAfter
= Sibling
;
1171 Sibling
= Sibling
->spwndNext
;
1174 if (NULL
== InsertAfter
)
1176 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1180 // UserReferenceObject(InsertAfter);
1181 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1182 // UserDereferenceObject(InsertAfter);
1187 * SetParent additionally needs to make hwnd the top window
1188 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1189 * WM_WINDOWPOSCHANGED notification messages.
1191 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1192 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1193 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1196 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1197 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1201 * Validate that the old parent still exist, since it migth have been
1202 * destroyed during the last callbacks to user-mode
1206 // if(!IntIsWindow(WndOldParent->hSelf))
1208 // UserDereferenceObject(WndOldParent);
1212 /* don't dereference the window object here, it must be done by the caller
1213 of IntSetParent() */
1214 // return WndOldParent;
1217 return WndOldParent
;//NULL;
1221 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
1223 PMENU_OBJECT OldMenu
;
1224 if(Window
->SystemMenu
)
1226 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1229 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1230 IntReleaseMenuObject(OldMenu
);
1236 /* FIXME check window style, propably return FALSE ? */
1237 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1238 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1241 Window
->SystemMenu
= (HMENU
)0;
1246 /* unlink the window from siblings and parent. children are kept in place. */
1248 IntUnlinkWnd(PWND Wnd
)
1251 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1254 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1256 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1257 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1259 Wnd
->spwndPrev
= Wnd
->spwndNext
= Wnd
->spwndParent
= NULL
;
1263 /* unlink the window from siblings and parent. children are kept in place. */
1265 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1267 PWINDOW_OBJECT WndParent
= Wnd
->spwndParent
;
1269 IntUnlinkWnd(Wnd
->Wnd
);
1272 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1275 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1276 else if (WndParent
&& WndParent
->spwndChild
== Wnd
)
1277 WndParent
->spwndChild
= Wnd
->spwndNext
;
1279 Wnd
->spwndPrev
= Wnd
->spwndNext
= Wnd
->spwndParent
= NULL
;
1285 PWINDOW_OBJECT Window
, Child
;
1287 if(!(Window
= UserGetWindowObject(IntGetDesktopWindow())))
1292 for(Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
1294 if(Child
->hOwner
&& Child
->Wnd
->style
& WS_VISIBLE
)
1297 * The desktop has a popup window if one of them has
1298 * an owner window and is visible
1308 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1310 return ((Window
->state
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1316 IntGetWindowPlacement(PWINDOW_OBJECT Window
, WINDOWPLACEMENT
*lpwndpl
)
1322 if (!Wnd
) return FALSE
;
1324 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1330 if (0 == (Wnd
->style
& WS_VISIBLE
))
1332 lpwndpl
->showCmd
= SW_HIDE
;
1334 else if (0 != (Window
->state
& WINDOWOBJECT_RESTOREMAX
) ||
1335 0 != (Wnd
->style
& WS_MAXIMIZE
))
1337 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1339 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1341 lpwndpl
->showCmd
= SW_MINIMIZE
;
1343 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1345 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1348 Size
.x
= Wnd
->rcWindow
.left
;
1349 Size
.y
= Wnd
->rcWindow
.top
;
1350 WinPosInitInternalPos(Window
, &Size
,
1353 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1354 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1355 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1361 /* FUNCTIONS *****************************************************************/
1367 NtUserAlterWindowStyle(DWORD Unknown0
,
1377 * As best as I can figure, this function is used by EnumWindows,
1378 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1380 * It's supposed to build a list of HWNDs to return to the caller.
1381 * We can figure out what kind of list by what parameters are
1389 NtUserBuildHwndList(
1402 return ERROR_INVALID_PARAMETER
;
1404 if (hwndParent
|| !dwThreadId
)
1407 PWINDOW_OBJECT Parent
, Window
;
1411 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1413 return ERROR_INVALID_HANDLE
;
1418 Status
= IntValidateDesktopHandle(hDesktop
,
1422 if(!NT_SUCCESS(Status
))
1424 return ERROR_INVALID_HANDLE
;
1427 hwndParent
= Desktop
->DesktopWindow
;
1434 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1435 (Window
= Parent
->spwndChild
))
1437 BOOL bGoDown
= TRUE
;
1439 Status
= STATUS_SUCCESS
;
1444 if(dwCount
++ < *pBufSize
&& pWnd
)
1448 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1449 *pWnd
= Window
->hSelf
;
1452 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1454 Status
= _SEH2_GetExceptionCode();
1457 if(!NT_SUCCESS(Status
))
1459 SetLastNtError(Status
);
1463 if (Window
->spwndChild
&& bChildren
)
1465 Window
= Window
->spwndChild
;
1470 if (Window
->spwndNext
)
1472 Window
= Window
->spwndNext
;
1476 Window
= Window
->spwndParent
;
1477 if (Window
== Parent
)
1486 ObDereferenceObject(Desktop
);
1492 PTHREADINFO W32Thread
;
1493 PLIST_ENTRY Current
;
1494 PWINDOW_OBJECT Window
;
1496 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1497 if(!NT_SUCCESS(Status
))
1499 return ERROR_INVALID_PARAMETER
;
1501 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1503 ObDereferenceObject(Thread
);
1504 DPRINT("Thread is not a GUI Thread!\n");
1505 return ERROR_INVALID_PARAMETER
;
1508 Current
= W32Thread
->WindowListHead
.Flink
;
1509 while(Current
!= &(W32Thread
->WindowListHead
))
1511 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1514 if(bChildren
|| Window
->hOwner
!= NULL
)
1516 if(dwCount
< *pBufSize
&& pWnd
)
1518 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1519 if(!NT_SUCCESS(Status
))
1521 SetLastNtError(Status
);
1527 Current
= Current
->Flink
;
1530 ObDereferenceObject(Thread
);
1533 *pBufSize
= dwCount
;
1534 return STATUS_SUCCESS
;
1542 NtUserChildWindowFromPointEx(HWND hwndParent
,
1547 PWINDOW_OBJECT Parent
;
1552 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1560 if(Parent
->hSelf
!= IntGetDesktopWindow())
1562 Pt
.x
+= Parent
->Wnd
->rcClient
.left
;
1563 Pt
.y
+= Parent
->Wnd
->rcClient
.top
;
1566 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1571 Ret
= Parent
->hSelf
;
1572 if((List
= IntWinListChildren(Parent
)))
1574 for(phWnd
= List
; *phWnd
; phWnd
++)
1576 PWINDOW_OBJECT Child
;
1578 if((Child
= UserGetWindowObject(*phWnd
)))
1580 ChildWnd
= Child
->Wnd
;
1581 if(!(ChildWnd
->style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1585 if((ChildWnd
->style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1589 if((ChildWnd
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1593 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1608 * calculates the default position of a window
1611 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, RECTL
*rc
, BOOL IncPos
)
1617 pMonitor
= IntGetPrimaryMonitor();
1621 RECTL_bIntersectRect(rc
, rc
, &pMonitor
->rcMonitor
);
1625 Pos
.x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1626 Pos
.y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1627 if (Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1628 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1630 /* reset counter and position */
1633 pMonitor
->cWndStack
= 0;
1635 pMonitor
->cWndStack
++;
1646 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1647 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1651 rc
->right
= rc
->left
+ Sz
.cx
;
1652 rc
->bottom
= rc
->top
+ Sz
.cy
;
1661 co_IntCreateWindowEx(DWORD dwExStyle
,
1662 PUNICODE_STRING ClassName
,
1663 PLARGE_STRING WindowName
,
1671 HINSTANCE hInstance
,
1674 BOOL bUnicodeWindow
)
1676 PWINSTATION_OBJECT WinSta
;
1678 PCLS
*ClassLink
, Class
= NULL
;
1680 PWINDOW_OBJECT Window
= NULL
;
1681 PWINDOW_OBJECT ParentWindow
= NULL
, OwnerWindow
;
1682 HWND ParentWindowHandle
= NULL
;
1683 HWND OwnerWindowHandle
;
1684 PMENU_OBJECT SystemMenu
;
1688 PTHREADINFO ti
= NULL
;
1691 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1697 CBT_CREATEWNDW CbtCreate
;
1700 DECLARE_RETURN(PWND
);
1702 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1705 pti
= PsGetCurrentThreadWin32Thread();
1709 ParentWindowHandle
= pti
->rpdesk
->DesktopWindow
;
1713 if ( !(pti
->ppi
->W32PF_flags
& W32PF_CLASSESREGISTERED
))
1715 UserRegisterSystemClasses();
1718 OwnerWindowHandle
= NULL
;
1720 DPRINT("co_IntCreateWindowEx %wZ\n", ClassName
);
1722 if (hWndParent
== HWND_MESSAGE
)
1725 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1726 * message window (style: WS_POPUP|WS_DISABLED)
1728 ParentWindowHandle
= IntGetMessageWindow();
1729 DPRINT("Parent is HWND_MESSAGE 0x%x\n", ParentWindowHandle
);
1731 else if (hWndParent
)
1733 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1735 PWINDOW_OBJECT Par
= UserGetWindowObject(hWndParent
), Root
;
1736 if (Par
&& (Root
= UserGetAncestor(Par
, GA_ROOT
)))
1737 OwnerWindowHandle
= Root
->hSelf
;
1740 ParentWindowHandle
= hWndParent
;
1742 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1744 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1745 RETURN( (PWND
)0); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1748 if (ParentWindowHandle
)
1750 ParentWindow
= UserGetWindowObject(ParentWindowHandle
);
1752 if (ParentWindow
) UserRefObjectCo(ParentWindow
, &ParentRef
);
1756 ParentWindow
= NULL
;
1759 /* FIXME: parent must belong to the current process */
1761 /* Check the window station. */
1762 ti
= GetW32ThreadInfo();
1763 if (ti
== NULL
|| pti
->rpdesk
== NULL
)
1765 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1769 /* Check the class. */
1771 DPRINT("Class %wZ\n", ClassName
);
1773 ClassAtom
= IntGetClassAtom(ClassName
,
1779 if (ClassAtom
== (RTL_ATOM
)0)
1781 if (IS_ATOM(ClassName
->Buffer
))
1783 DPRINT1("Class 0x%p not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1787 DPRINT1("Class \"%wZ\" not found\n", ClassName
);
1790 SetLastWin32Error(ERROR_CANNOT_FIND_WND_CLASS
);
1793 DPRINT("ClassAtom %x\n", ClassAtom
);
1794 Class
= IntReferenceClass(Class
,
1799 DPRINT1("Failed to reference window class!\n");
1803 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1805 //FIXME: Reference thread/desktop instead
1806 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1808 /* Create the window object. */
1809 Window
= (PWINDOW_OBJECT
) UserCreateObject( gHandleTable
,
1813 sizeof(WINDOW_OBJECT
));
1816 Window
->Wnd
= DesktopHeapAlloc(pti
->rpdesk
,
1817 sizeof(WND
) + Class
->cbwndExtra
);
1820 RtlZeroMemory(Window
->Wnd
,
1821 sizeof(WND
) + Class
->cbwndExtra
);
1822 Window
->Wnd
->head
.h
= hWnd
;
1827 Wnd
->head
.rpdesk
= pti
->rpdesk
;
1828 Wnd
->hWndLastActive
= hWnd
;
1829 Wnd
->state2
|= WNDS2_WIN40COMPAT
;
1832 DPRINT("Created object with handle %X\n", hWnd
);
1836 ObDereferenceObject(WinSta
);
1837 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1841 UserRefObjectCo(Window
, &Ref
);
1843 ObDereferenceObject(WinSta
);
1845 if (NULL
== pti
->rpdesk
->DesktopWindow
)
1847 /* If there is no desktop window yet, we must be creating it */
1848 pti
->rpdesk
->DesktopWindow
= hWnd
;
1849 pti
->rpdesk
->pDeskInfo
->spwnd
= Wnd
;
1853 * Fill out the structure describing it.
1859 Window
->SystemMenu
= (HMENU
)0;
1861 Wnd
->hModule
= hInstance
;
1862 Window
->hSelf
= hWnd
;
1864 IntReferenceMessageQueue(Window
->pti
->MessageQueue
);
1865 Window
->spwndParent
= ParentWindow
;
1866 Wnd
->spwndParent
= ParentWindow
? ParentWindow
->Wnd
: NULL
;
1867 if (Wnd
->spwndParent
!= NULL
&& hWndParent
!= 0)
1869 Wnd
->HideFocus
= Wnd
->spwndParent
->HideFocus
;
1870 Wnd
->HideAccel
= Wnd
->spwndParent
->HideAccel
;
1873 if((OwnerWindow
= UserGetWindowObject(OwnerWindowHandle
)))
1875 Window
->hOwner
= OwnerWindowHandle
;
1876 Wnd
->spwndOwner
= OwnerWindow
->Wnd
;
1881 Window
->hOwner
= NULL
;
1882 Wnd
->spwndOwner
= NULL
;
1886 Wnd
->dwUserData
= 0;
1888 if (Wnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1889 Wnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1891 /* BugBoy Comments: Comment below say that System classes are always created
1892 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1893 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1895 No where can I see in code or through testing does the window change back
1896 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1897 see what problems this would cause.*/
1899 // Set WndProc from Class.
1900 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
1902 // GetWindowProc, test for non server side default classes and set WndProc.
1903 if ( Wnd
->pcls
->fnid
<= FNID_GHOST
&& Wnd
->pcls
->fnid
>= FNID_BUTTON
)
1907 if (GETPFNCLIENTA(Wnd
->pcls
->fnid
) == Wnd
->lpfnWndProc
)
1908 Wnd
->lpfnWndProc
= GETPFNCLIENTW(Wnd
->pcls
->fnid
);
1912 if (GETPFNCLIENTW(Wnd
->pcls
->fnid
) == Wnd
->lpfnWndProc
)
1913 Wnd
->lpfnWndProc
= GETPFNCLIENTA(Wnd
->pcls
->fnid
);
1917 // If not an Unicode caller, set Ansi creator bit.
1918 if (!bUnicodeWindow
) Wnd
->state
|= WNDS_ANSICREATOR
;
1920 // Clone Class Ansi/Unicode proc type.
1921 if (Wnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1923 Wnd
->state
|= WNDS_ANSIWINDOWPROC
;
1924 Wnd
->Unicode
= FALSE
;
1928 It seems there can be both an Ansi creator and Unicode Class Window
1929 WndProc, unless the following overriding conditions occur:
1931 if ( !bUnicodeWindow
&&
1932 ( ClassAtom
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1933 ClassAtom
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1934 ClassAtom
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1935 ClassAtom
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1936 ClassAtom
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1937 ClassAtom
== gpsi
->atomSysClass
[ICLS_IME
] ||
1938 ClassAtom
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1939 ClassAtom
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1940 ClassAtom
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1941 { // Override Class and set the window Ansi WndProc.
1942 Wnd
->state
|= WNDS_ANSIWINDOWPROC
;
1943 Wnd
->Unicode
= FALSE
;
1946 { // Set the window Unicode WndProc.
1947 Wnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1948 Wnd
->Unicode
= TRUE
;
1952 Window
->spwndChild
= NULL
;
1953 Window
->spwndPrev
= NULL
;
1954 Window
->spwndNext
= NULL
;
1956 Wnd
->spwndNext
= NULL
;
1957 Wnd
->spwndPrev
= NULL
;
1958 Wnd
->spwndChild
= NULL
;
1960 Wnd
->cbwndExtra
= Wnd
->pcls
->cbwndExtra
;
1962 InitializeListHead(&Wnd
->PropListHead
);
1964 if ( NULL
!= WindowName
->Buffer
&& WindowName
->Length
> 0 )
1966 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
1967 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1968 if (Wnd
->strName
.Buffer
== NULL
)
1970 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1974 Wnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1977 RtlCopyMemory(Wnd
->strName
.Buffer
,
1979 WindowName
->Length
);
1980 Wnd
->strName
.Length
= WindowName
->Length
;
1982 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1984 WindowName
->Length
= 0;
1985 Wnd
->strName
.Buffer
[0] = L
'\0';
1991 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1992 * tested for WS_POPUP
1994 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1995 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1996 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1997 dwExStyle
|= WS_EX_WINDOWEDGE
;
1999 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
2001 Wnd
->style
= dwStyle
& ~WS_VISIBLE
;
2003 /* Correct the window style. */
2004 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
2006 Wnd
->style
|= WS_CLIPSIBLINGS
;
2007 DPRINT("3: Style is now %lx\n", dwStyle
);
2008 if (!(Wnd
->style
& WS_POPUP
))
2010 Wnd
->style
|= WS_CAPTION
;
2011 Window
->state
|= WINDOWOBJECT_NEED_SIZE
;
2012 DPRINT("4: Style is now %lx\n", dwStyle
);
2016 /* create system menu */
2017 if((dwStyle
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
2019 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
2022 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
2023 IntReleaseMenuObject(SystemMenu
);
2027 /* Set the window menu */
2028 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
2031 IntSetMenu(Window
, hMenu
, &MenuChanged
);
2032 else if (Wnd
->pcls
->lpszMenuName
) // Take it from the parent.
2034 UNICODE_STRING MenuName
;
2035 if (IS_INTRESOURCE(Wnd
->pcls
->lpszMenuName
))
2037 MenuName
.Length
= 0;
2038 MenuName
.MaximumLength
= 0;
2039 MenuName
.Buffer
= Wnd
->pcls
->lpszMenuName
;
2043 RtlInitUnicodeString( &MenuName
, Wnd
->pcls
->lpszMenuName
);
2045 hMenu
= co_IntCallLoadMenu( Wnd
->pcls
->hModule
, &MenuName
);
2046 if (hMenu
) IntSetMenu(Window
, hMenu
, &MenuChanged
);
2050 Wnd
->IDMenu
= (UINT
) hMenu
;
2052 /* Insert the window into the thread's window list. */
2053 InsertTailList (&pti
->WindowListHead
, &Window
->ThreadListEntry
);
2055 /* Handle "CS_CLASSDC", it is tested first. */
2056 if ( (Wnd
->pcls
->style
& CS_CLASSDC
) && !(Wnd
->pcls
->pdce
) )
2057 { /* One DCE per class to have CLASS. */
2058 Wnd
->pcls
->pdce
= DceAllocDCE( Window
, DCE_CLASS_DC
);
2060 else if ( Wnd
->pcls
->style
& CS_OWNDC
)
2061 { /* Allocate a DCE for this window. */
2062 DceAllocDCE(Window
, DCE_WINDOW_DC
);
2070 Wnd
->ExStyle
= dwExStyle
;
2073 Cs
.lpCreateParams
= lpParam
;
2074 Cs
.hInstance
= hInstance
;
2076 Cs
.hwndParent
= hWndParent
; //Pass the original Parent handle!
2081 Cs
.style
= Wnd
->style
;
2082 // Cs.lpszName = (LPCWSTR) WindowName->Buffer;
2083 // Cs.lpszClass = (LPCWSTR) ClassName->Buffer;
2084 Cs
.lpszName
= (LPCWSTR
) WindowName
;
2085 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
2086 Cs
.dwExStyle
= dwExStyle
;
2087 CbtCreate
.lpcs
= &Cs
;
2088 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
2089 if (ISITHOOKED(WH_CBT
))
2091 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) &CbtCreate
))
2093 /* FIXME - Delete window object and remove it from the thread windows list */
2094 /* FIXME - delete allocated DCE */
2095 DPRINT1("CBT-hook returned !0\n");
2096 RETURN( (PWND
) NULL
);
2105 // FIXME: Need to set the Z order in the window link list if the hook callback changed it!
2106 // hwndInsertAfter = CbtCreate.hwndInsertAfter;
2108 /* default positioning for overlapped windows */
2109 if(!(Wnd
->style
& (WS_POPUP
| WS_CHILD
)))
2112 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
2113 BOOL CalculatedDefPosSize
= FALSE
;
2115 UserSystemParametersInfo(SPI_GETWORKAREA
, 0, &WorkArea
, 0);
2118 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
2120 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
2122 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, &rc
, TRUE
);
2124 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
2126 ProcessParams
->WindowFlags
&= ~STARTF_USEPOSITION
;
2127 Pos
.x
= WorkArea
.left
+ ProcessParams
->StartingX
;
2128 Pos
.y
= WorkArea
.top
+ ProcessParams
->StartingY
;
2137 According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
2138 y is something else. and Quote!
2141 /* Never believe Microsoft's documentation... CreateWindowEx doc says
2142 * that if an overlapped window is created with WS_VISIBLE style bit
2143 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
2144 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
2147 * 1) not only it checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
2148 * 2) it does not ignore the y parameter as the docs claim; instead, it
2149 * uses it as second parameter to ShowWindow() unless y is either
2150 * CW_USEDEFAULT or CW_USEDEFAULT16.
2152 * The fact that we didn't do 2) caused bogus windows pop up when wine
2153 * was running apps that were using this obscure feature. Example -
2154 * calc.exe that comes with Win98 (only Win98, it's different from
2155 * the one that comes with Win95 and NT)
2157 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
2162 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
2164 if(!CalculatedDefPosSize
)
2166 IntCalcDefPosSize(ParentWindow
, &rc
, FALSE
);
2168 if(ProcessParams
->WindowFlags
& STARTF_USESIZE
)
2170 ProcessParams
->WindowFlags
&= ~STARTF_USESIZE
;
2171 Size
.cx
= ProcessParams
->CountX
;
2172 Size
.cy
= ProcessParams
->CountY
;
2176 Size
.cx
= rc
.right
- rc
.left
;
2177 Size
.cy
= rc
.bottom
- rc
.top
;
2180 /* move the window if necessary */
2182 Pos
.x
= max(rc
.left
, 0);
2184 Pos
.y
= max(rc
.top
, 0);
2189 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
2190 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
2195 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
2202 /* Initialize the window dimensions. */
2203 Wnd
->rcWindow
.left
= Pos
.x
;
2204 Wnd
->rcWindow
.top
= Pos
.y
;
2205 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
2206 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
2207 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2209 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2210 ParentWindow
->Wnd
->rcClient
.top
);
2212 Wnd
->rcClient
= Wnd
->rcWindow
;
2215 * Get the size and position of the window.
2217 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
2219 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2221 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
2222 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2223 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2224 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2225 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2226 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2229 if (Size
.cx
< 0) Size
.cx
= 0;
2230 if (Size
.cy
< 0) Size
.cy
= 0;
2232 Wnd
->rcWindow
.left
= Pos
.x
;
2233 Wnd
->rcWindow
.top
= Pos
.y
;
2234 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
2235 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
2236 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2238 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2239 ParentWindow
->Wnd
->rcClient
.top
);
2241 Wnd
->rcClient
= Wnd
->rcWindow
;
2243 /* FIXME: Initialize the window menu. */
2245 /* Send a NCCREATE message. */
2246 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
2247 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, Size
.cx
, Size
.cy
);
2248 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
2249 Result
= co_IntSendMessage(Window
->hSelf
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
2252 /* FIXME: Cleanup. */
2253 DPRINT1("IntCreateWindowEx(): NCCREATE message failed. No cleanup performed!\n");
2257 /* Calculate the non-client size. */
2258 MaxPos
.x
= Window
->Wnd
->rcWindow
.left
;
2259 MaxPos
.y
= Window
->Wnd
->rcWindow
.top
;
2262 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
2263 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
2264 Result
= co_WinPosGetNonClientSize(Window
,
2265 &Window
->Wnd
->rcWindow
,
2266 &Window
->Wnd
->rcClient
);
2268 RECTL_vOffsetRect(&Window
->Wnd
->rcWindow
,
2269 MaxPos
.x
- Window
->Wnd
->rcWindow
.left
,
2270 MaxPos
.y
- Window
->Wnd
->rcWindow
.top
);
2273 if (NULL
!= ParentWindow
)
2275 /* link the window into the parent's child list */
2276 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2278 PWINDOW_OBJECT PrevSibling
;
2280 PrevSibling
= ParentWindow
->spwndChild
;
2284 while (PrevSibling
->spwndNext
)
2285 PrevSibling
= PrevSibling
->spwndNext
;
2288 /* link window as bottom sibling */
2289 IntLinkWindow(Window
, ParentWindow
, PrevSibling
/*prev sibling*/);
2293 /* link window as top sibling (but after topmost siblings) */
2294 PWINDOW_OBJECT InsertAfter
, Sibling
;
2295 if (!(dwExStyle
& WS_EX_TOPMOST
))
2298 Sibling
= ParentWindow
->spwndChild
;
2299 while (Sibling
&& (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
2301 InsertAfter
= Sibling
;
2302 Sibling
= Sibling
->spwndNext
;
2310 IntLinkWindow(Window
, ParentWindow
, InsertAfter
/* prev sibling */);
2314 /* Send the WM_CREATE message. */
2315 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
2316 Result
= co_IntSendMessage(Window
->hSelf
, WM_CREATE
, 0, (LPARAM
) &Cs
);
2318 if (Result
== (LRESULT
)-1)
2320 /* FIXME: Cleanup. */
2321 DPRINT1("IntCreateWindowEx(): send CREATE message failed. No cleanup performed!\n");
2322 IntUnlinkWindow(Window
);
2326 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
->Wnd
, OBJID_WINDOW
, 0);
2328 /* By setting the flag below it can be examined to determine if the window
2329 was created successfully and a valid pwnd was passed back to caller since
2330 from here the function has to succeed. */
2331 Window
->Wnd
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2333 /* Send move and size messages. */
2334 if (!(Window
->state
& WINDOWOBJECT_NEED_SIZE
))
2338 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
2340 if ((Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
) < 0 ||
2341 (Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
) < 0)
2343 DPRINT("Sending bogus WM_SIZE\n");
2346 lParam
= MAKE_LONG(Window
->Wnd
->rcClient
.right
-
2347 Window
->Wnd
->rcClient
.left
,
2348 Window
->Wnd
->rcClient
.bottom
-
2349 Window
->Wnd
->rcClient
.top
);
2350 co_IntSendMessage(Window
->hSelf
, WM_SIZE
, SIZE_RESTORED
,
2353 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
2355 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2357 lParam
= MAKE_LONG(Wnd
->rcClient
.left
- ParentWindow
->Wnd
->rcClient
.left
,
2358 Wnd
->rcClient
.top
- ParentWindow
->Wnd
->rcClient
.top
);
2362 lParam
= MAKE_LONG(Wnd
->rcClient
.left
,
2366 co_IntSendMessage(Window
->hSelf
, WM_MOVE
, 0, lParam
);
2368 /* Call WNDOBJ change procs */
2369 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
2372 /* Show or maybe minimize or maximize the window. */
2373 if (Wnd
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2378 SwFlag
= (Wnd
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
2381 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2383 SwFlag
= ((Wnd
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2384 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2385 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2387 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
2388 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
2389 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2390 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2393 /* Notify the parent window of a new child. */
2394 if ((Wnd
->style
& WS_CHILD
) &&
2395 (!(Wnd
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
2397 DPRINT("IntCreateWindow(): About to notify parent\n");
2398 co_IntSendMessage(ParentWindow
->hSelf
,
2400 MAKEWPARAM(WM_CREATE
, Wnd
->IDMenu
),
2401 (LPARAM
)Window
->hSelf
);
2404 if ((!hWndParent
) && (!HasOwner
))
2406 DPRINT("Sending CREATED notify\n");
2407 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2411 DPRINT("Not sending CREATED notify, %x %d\n", ParentWindow
, HasOwner
);
2414 /* Initialize and show the window's scrollbars */
2415 if (Wnd
->style
& WS_VSCROLL
)
2417 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2419 if (Wnd
->style
& WS_HSCROLL
)
2421 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2424 if (dwStyle
& WS_VISIBLE
)
2426 if (Wnd
->style
& WS_MAXIMIZE
)
2427 dwShowMode
= SW_SHOW
;
2428 else if (Wnd
->style
& WS_MINIMIZE
)
2429 dwShowMode
= SW_SHOWMINIMIZED
;
2431 DPRINT("IntCreateWindow(): About to show window\n");
2432 co_WinPosShowWindow(Window
, dwShowMode
);
2434 if (Wnd
->ExStyle
& WS_EX_MDICHILD
)
2436 co_IntSendMessage(ParentWindow
->hSelf
, WM_MDIREFRESHMENU
, 0, 0);
2437 /* ShowWindow won't activate child windows */
2438 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2442 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
2443 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
2444 Dont understand why it does this. */
2445 if (ClassAtom
== gpsi
->atomSysClass
[ICLS_EDIT
])
2447 PCALLPROCDATA CallProc
;
2448 //CallProc = CreateCallProc(NULL, Wnd->lpfnWndProc, bUnicodeWindow, Wnd->ti->ppi);
2449 CallProc
= CreateCallProc(NULL
, Wnd
->lpfnWndProc
, Wnd
->Unicode
, Wnd
->head
.pti
->ppi
);
2453 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2454 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
2458 UserAddCallProcToClass(Wnd
->pcls
, CallProc
);
2462 DPRINT("IntCreateWindow(): = %X\n", hWnd
);
2463 DPRINT("WindowObject->SystemMenu = 0x%x\n", Window
->SystemMenu
);
2467 if (!_ret_
&& Window
&& Window
->Wnd
&& ti
)
2468 co_UserDestroyWindow(Window
);
2469 // UserFreeWindowInfo(ti, Window);
2472 UserDerefObjectCo(Window
);
2473 UserDereferenceObject(Window
);
2475 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2476 if (!_ret_
&& ti
!= NULL
)
2480 IntDereferenceClass(Class
,
2490 ProbeAndCaptureLargeString(
2491 OUT PLARGE_STRING plstrSafe
,
2492 IN PLARGE_STRING plstrUnsafe
)
2494 LARGE_STRING lstrTemp
;
2495 PVOID pvBuffer
= NULL
;
2499 /* Probe and copy the string */
2500 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2501 lstrTemp
= *plstrUnsafe
;
2503 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2506 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2510 if (lstrTemp
.Length
!= 0)
2512 /* Allocate a buffer from paged pool */
2513 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2516 return STATUS_NO_MEMORY
;
2521 /* Probe and copy the buffer */
2522 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2523 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2525 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2527 /* Cleanup and fail */
2528 ExFreePool(pvBuffer
);
2529 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2534 /* Set the output string */
2535 plstrSafe
->Buffer
= pvBuffer
;
2536 plstrSafe
->Length
= lstrTemp
.Length
;
2537 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2539 return STATUS_SUCCESS
;
2543 * \todo Allow passing plstrClassName as ANSI.
2547 NtUserCreateWindowEx(
2549 PLARGE_STRING plstrClassName
,
2550 PLARGE_STRING plstrClsVersion
,
2551 PLARGE_STRING plstrWindowName
,
2559 HINSTANCE hInstance
,
2565 LARGE_STRING lstrWindowName
;
2566 LARGE_STRING lstrClassName
;
2567 UNICODE_STRING ustrClassName
;
2571 DPRINT("Enter NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2572 UserEnterExclusive();
2574 lstrWindowName
.Buffer
= NULL
;
2575 lstrClassName
.Buffer
= NULL
;
2577 /* Check if we got a Window name */
2578 if (plstrWindowName
)
2580 /* Copy the string to kernel mode */
2581 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2582 if (!NT_SUCCESS(Status
))
2584 SetLastNtError(Status
);
2587 plstrWindowName
= &lstrWindowName
;
2590 /* Check if the class is an atom */
2591 if (IS_ATOM(plstrClassName
))
2593 /* It is, pass the atom in the UNICODE_STRING */
2594 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2595 ustrClassName
.Length
= 0;
2596 ustrClassName
.MaximumLength
= 0;
2600 /* It's not, capture the class name */
2601 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2602 if (!NT_SUCCESS(Status
))
2604 /* Set last error, cleanup and return */
2605 SetLastNtError(Status
);
2609 /* We pass it on as a UNICODE_STRING */
2610 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2611 ustrClassName
.Length
= lstrClassName
.Length
;
2612 ustrClassName
.MaximumLength
= lstrClassName
.MaximumLength
;
2615 /* Call the internal function */
2616 pwnd
= co_IntCreateWindowEx(dwExStyle
,
2629 !(dwExStyle
& WS_EX_SETANSICREATOR
));
2631 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2634 if (lstrWindowName
.Buffer
)
2636 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2638 if (lstrClassName
.Buffer
)
2640 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2644 DPRINT("Leave NtUserCreateWindowEx, hwnd=%i\n", hwnd
);
2654 NtUserDeferWindowPos(HDWP WinPosInfo
,
2656 HWND WndInsertAfter
,
2669 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2676 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2678 hWnd
= Window
->hSelf
;
2682 if (!Wnd
) return TRUE
; // FIXME: Need to finish object rewrite or lock the thread when killing the window!
2684 DPRINT("co_UserDestroyWindow \n");
2686 /* Check for owner thread */
2687 if ( (Window
->pti
->pEThread
!= PsGetCurrentThread()) ||
2688 Wnd
->head
.pti
!= PsGetCurrentThreadWin32Thread() )
2690 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2694 /* If window was created successfully and it is hooked */
2695 if ((Wnd
->state2
& WNDS2_WMCREATEMSGPROCESSED
) && (ISITHOOKED(WH_CBT
)))
2697 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0)) return FALSE
;
2700 /* Look whether the focus is within the tree of windows we will
2703 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2705 if (UserGetActiveWindow() == Window
->hSelf
)
2707 co_WinPosActivateOtherWindow(Window
);
2711 if (Window
->pti
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2712 Window
->pti
->MessageQueue
->ActiveWindow
= NULL
;
2713 if (Window
->pti
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2714 Window
->pti
->MessageQueue
->FocusWindow
= NULL
;
2715 if (Window
->pti
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2716 Window
->pti
->MessageQueue
->CaptureWindow
= NULL
;
2719 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2722 ti
= PsGetCurrentThreadWin32Thread();
2724 if ((ti
!= NULL
) & (ti
->pDeskInfo
!= NULL
))
2726 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2728 DPRINT1("Destroying the ShellWindow!\n");
2729 ti
->pDeskInfo
->hShellWindow
= NULL
;
2733 IntDereferenceMessageQueue(Window
->pti
->MessageQueue
);
2735 IntEngWindowChanged(Window
, WOC_DELETE
);
2736 isChild
= (0 != (Wnd
->style
& WS_CHILD
));
2742 if (! USER_IsExitingThread(GetCurrentThreadId()))
2744 send_parent_notify(hwnd
, WM_DESTROY
);
2747 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2749 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2750 /* FIXME: clean up palette - see "Internals" p.352 */
2754 if (!IntIsWindow(Window
->hSelf
))
2759 /* Recursively destroy owned windows */
2764 BOOL GotOne
= FALSE
;
2767 PWINDOW_OBJECT Child
, Desktop
;
2769 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2770 UserGetWindowObject(IntGetDesktopWindow());
2771 Children
= IntWinListChildren(Desktop
);
2775 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2777 Child
= UserGetWindowObject(*ChildHandle
);
2780 if (Child
->hOwner
!= Window
->hSelf
)
2785 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2787 USER_REFERENCE_ENTRY ChildRef
;
2788 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2789 co_UserDestroyWindow(Child
);
2790 UserDerefObjectCo(Child
);//temp hack?
2796 if (Child
->hOwner
!= NULL
)
2798 Child
->hOwner
= NULL
;
2799 Child
->Wnd
->spwndOwner
= NULL
;
2803 ExFreePool(Children
);
2812 if (!IntIsWindow(Window
->hSelf
))
2817 /* Destroy the window storage */
2818 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2828 NtUserDestroyWindow(HWND Wnd
)
2830 PWINDOW_OBJECT Window
;
2831 DECLARE_RETURN(BOOLEAN
);
2833 USER_REFERENCE_ENTRY Ref
;
2835 DPRINT("Enter NtUserDestroyWindow\n");
2836 UserEnterExclusive();
2838 if (!(Window
= UserGetWindowObject(Wnd
)))
2843 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2844 ret
= co_UserDestroyWindow(Window
);
2845 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2850 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2862 NtUserDrawMenuBarTemp(
2869 /* we'll use this function just for caching the menu bar */
2879 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2889 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2895 NtUserFillWindow(HWND hWndPaint
,
2906 static HWND FASTCALL
2907 IntFindWindow(PWINDOW_OBJECT Parent
,
2908 PWINDOW_OBJECT ChildAfter
,
2910 PUNICODE_STRING WindowName
)
2912 BOOL CheckWindowName
;
2915 UNICODE_STRING CurrentWindowName
;
2919 CheckWindowName
= WindowName
->Length
!= 0;
2921 if((List
= IntWinListChildren(Parent
)))
2926 /* skip handles before and including ChildAfter */
2927 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2931 /* search children */
2934 PWINDOW_OBJECT Child
;
2935 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2940 /* Do not send WM_GETTEXT messages in the kernel mode version!
2941 The user mode version however calls GetWindowText() which will
2942 send WM_GETTEXT messages to windows belonging to its processes */
2943 if (!ClassAtom
|| Child
->Wnd
->pcls
->atomClassName
== ClassAtom
)
2945 // HACK: use UNICODE_STRING instead of LARGE_STRING
2946 CurrentWindowName
.Buffer
= Child
->Wnd
->strName
.Buffer
;
2947 CurrentWindowName
.Length
= Child
->Wnd
->strName
.Length
;
2948 CurrentWindowName
.MaximumLength
= Child
->Wnd
->strName
.MaximumLength
;
2949 if(!CheckWindowName
||
2950 (Child
->Wnd
->strName
.Length
< 0xFFFF &&
2951 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2966 * Searches a window's children for a window with the specified
2969 * hwndParent = The window whose childs are to be searched.
2971 * HWND_MESSAGE = message-only windows
2973 * hwndChildAfter = Search starts after this child window.
2974 * NULL = start from beginning
2976 * ucClassName = Class name to search for
2977 * Reguired parameter.
2979 * ucWindowName = Window name
2980 * ->Buffer == NULL = don't care
2983 * The HWND of the window if it was found, otherwise NULL
2989 NtUserFindWindowEx(HWND hwndParent
,
2990 HWND hwndChildAfter
,
2991 PUNICODE_STRING ucClassName
,
2992 PUNICODE_STRING ucWindowName
,
2995 PWINDOW_OBJECT Parent
, ChildAfter
;
2996 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2997 HWND Desktop
, Ret
= NULL
;
2998 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2999 DECLARE_RETURN(HWND
);
3001 DPRINT("Enter NtUserFindWindowEx\n");
3004 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
3008 if (ucClassName
!= NULL
)
3010 ClassName
= ProbeForReadUnicodeString(ucClassName
);
3011 if (ClassName
.Length
!= 0)
3013 ProbeForRead(ClassName
.Buffer
,
3017 else if (!IS_ATOM(ClassName
.Buffer
))
3019 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3023 if (!IntGetAtomFromStringOrAtom(&ClassName
,
3030 if (ucWindowName
!= NULL
)
3032 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
3033 if (WindowName
.Length
!= 0)
3035 ProbeForRead(WindowName
.Buffer
,
3041 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3043 SetLastNtError(_SEH2_GetExceptionCode());
3044 _SEH2_YIELD(RETURN(NULL
));
3048 if (ucClassName
!= NULL
)
3050 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
3051 !IS_ATOM(ClassName
.Buffer
))
3053 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3056 else if (ClassAtom
== (RTL_ATOM
)0)
3058 /* LastError code was set by IntGetAtomFromStringOrAtom */
3064 Desktop
= IntGetCurrentThreadDesktopWindow();
3066 if(hwndParent
== NULL
)
3067 hwndParent
= Desktop
;
3068 else if(hwndParent
== HWND_MESSAGE
)
3070 hwndParent
= IntGetMessageWindow();
3073 if(!(Parent
= UserGetWindowObject(hwndParent
)))
3079 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
3086 if(Parent
->hSelf
== Desktop
)
3089 PWINDOW_OBJECT TopLevelWindow
;
3090 BOOLEAN CheckWindowName
;
3091 BOOLEAN WindowMatches
;
3092 BOOLEAN ClassMatches
;
3094 /* windows searches through all top-level windows if the parent is the desktop
3097 if((List
= IntWinListChildren(Parent
)))
3103 /* skip handles before and including ChildAfter */
3104 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
3108 CheckWindowName
= WindowName
.Length
!= 0;
3110 /* search children */
3113 UNICODE_STRING ustr
;
3115 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
3120 /* Do not send WM_GETTEXT messages in the kernel mode version!
3121 The user mode version however calls GetWindowText() which will
3122 send WM_GETTEXT messages to windows belonging to its processes */
3123 ustr
.Buffer
= TopLevelWindow
->Wnd
->strName
.Buffer
;
3124 ustr
.Length
= TopLevelWindow
->Wnd
->strName
.Length
;
3125 ustr
.MaximumLength
= TopLevelWindow
->Wnd
->strName
.MaximumLength
;
3126 WindowMatches
= !CheckWindowName
||
3127 (TopLevelWindow
->Wnd
->strName
.Length
< 0xFFFF &&
3128 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
3129 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
3130 ClassAtom
== TopLevelWindow
->Wnd
->pcls
->atomClassName
;
3132 if (WindowMatches
&& ClassMatches
)
3134 Ret
= TopLevelWindow
->hSelf
;
3138 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3140 /* window returns the handle of the top-level window, in case it found
3142 Ret
= TopLevelWindow
->hSelf
;
3151 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3155 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
3157 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
3158 search the message-only windows. Should this also be done if
3159 Parent is the desktop window??? */
3160 PWINDOW_OBJECT MsgWindows
;
3162 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3164 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3169 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3171 SetLastNtError(_SEH2_GetExceptionCode());
3179 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
3189 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
3200 PWINDOW_OBJECT FASTCALL
UserGetAncestor(PWINDOW_OBJECT Wnd
, UINT Type
)
3202 PWINDOW_OBJECT WndAncestor
, Parent
;
3204 if (Wnd
->hSelf
== IntGetDesktopWindow())
3213 WndAncestor
= Wnd
->spwndParent
;
3224 if(!(Parent
= WndAncestor
->spwndParent
))
3228 if(IntIsDesktopWindow(Parent
))
3233 WndAncestor
= Parent
;
3244 PWINDOW_OBJECT Parent
, Old
;
3247 Parent
= IntGetParent(WndAncestor
);
3255 // UserDereferenceObject(Parent);
3257 WndAncestor
= Parent
;
3275 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3277 PWINDOW_OBJECT Window
, Ancestor
;
3278 DECLARE_RETURN(HWND
);
3280 DPRINT("Enter NtUserGetAncestor\n");
3281 UserEnterExclusive();
3283 if (!(Window
= UserGetWindowObject(hWnd
)))
3288 Ancestor
= UserGetAncestor(Window
, Type
);
3289 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3291 RETURN(Ancestor
? Ancestor
->hSelf
: NULL
);
3294 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3302 NtUserGetComboBoxInfo(
3307 DECLARE_RETURN(BOOL
);
3309 DPRINT("Enter NtUserGetComboBoxInfo\n");
3312 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3321 sizeof(COMBOBOXINFO
),
3325 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3327 SetLastNtError(_SEH2_GetExceptionCode());
3328 _SEH2_YIELD(RETURN(FALSE
));
3332 // Pass the user pointer, it was already probed.
3333 RETURN( (BOOL
) co_IntSendMessage( Wnd
->hSelf
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3336 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3346 NtUserGetInternalWindowPos( HWND hWnd
,
3350 PWINDOW_OBJECT Window
;
3354 WINDOWPLACEMENT wndpl
;
3358 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3369 ProbeForWrite(rectWnd
,
3375 ProbeForWrite(ptIcon
,
3381 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3383 SetLastNtError(_SEH2_GetExceptionCode());
3388 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3390 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3396 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3400 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3404 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3406 SetLastNtError(_SEH2_GetExceptionCode());
3411 if (!Hit
) Ret
= wndpl
.showCmd
;
3420 NtUserGetListBoxInfo(
3424 DECLARE_RETURN(DWORD
);
3426 DPRINT("Enter NtUserGetListBoxInfo\n");
3429 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3434 RETURN( (DWORD
) co_IntSendMessage( Wnd
->hSelf
, LB_GETLISTBOXINFO
, 0, 0 ));
3437 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3444 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3446 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3447 HWND hWndOldParent
= NULL
;
3448 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3450 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3452 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3456 if (hWndChild
== IntGetDesktopWindow())
3458 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3464 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3471 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3477 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3482 UserRefObjectCo(Wnd
, &Ref
);
3483 UserRefObjectCo(WndParent
, &ParentRef
);
3485 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3487 UserDerefObjectCo(WndParent
);
3488 UserDerefObjectCo(Wnd
);
3492 hWndOldParent
= WndOldParent
->hSelf
;
3493 UserDereferenceObject(WndOldParent
);
3496 return( hWndOldParent
);
3502 * The NtUserSetParent function changes the parent window of the specified
3506 * The new parent window and the child window must belong to the same
3507 * application. If the window identified by the hWndChild parameter is
3508 * visible, the system performs the appropriate redrawing and repainting.
3509 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3510 * or WS_POPUP window styles of the window whose parent is being changed.
3517 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3519 DECLARE_RETURN(HWND
);
3521 DPRINT("Enter NtUserSetParent\n");
3522 UserEnterExclusive();
3525 Check Parent first from user space, set it here.
3529 hWndNewParent
= IntGetDesktopWindow();
3531 else if (hWndNewParent
== HWND_MESSAGE
)
3533 hWndNewParent
= IntGetMessageWindow();
3536 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3539 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3545 * UserGetShellWindow
3547 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3552 HWND FASTCALL
UserGetShellWindow(VOID
)
3554 PWINSTATION_OBJECT WinStaObject
;
3557 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3562 if (!NT_SUCCESS(Status
))
3564 SetLastNtError(Status
);
3568 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3570 ObDereferenceObject(WinStaObject
);
3575 * NtUserSetShellWindowEx
3577 * This is undocumented function to set global shell window. The global
3578 * shell window has special handling of window position.
3584 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3586 PWINSTATION_OBJECT WinStaObject
;
3587 PWINDOW_OBJECT WndShell
;
3588 DECLARE_RETURN(BOOL
);
3589 USER_REFERENCE_ENTRY Ref
;
3593 DPRINT("Enter NtUserSetShellWindowEx\n");
3594 UserEnterExclusive();
3596 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3601 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3606 if (!NT_SUCCESS(Status
))
3608 SetLastNtError(Status
);
3613 * Test if we are permitted to change the shell window.
3615 if (WinStaObject
->ShellWindow
)
3617 ObDereferenceObject(WinStaObject
);
3622 * Move shell window into background.
3624 if (hwndListView
&& hwndListView
!= hwndShell
)
3627 * Disabled for now to get Explorer working.
3628 * -- Filip, 01/nov/2003
3631 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3634 if (UserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3636 ObDereferenceObject(WinStaObject
);
3641 if (UserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3643 ObDereferenceObject(WinStaObject
);
3647 UserRefObjectCo(WndShell
, &Ref
);
3648 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3650 WinStaObject
->ShellWindow
= hwndShell
;
3651 WinStaObject
->ShellListView
= hwndListView
;
3653 ti
= GetW32ThreadInfo();
3654 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3656 UserDerefObjectCo(WndShell
);
3658 ObDereferenceObject(WinStaObject
);
3662 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3668 * NtUserGetSystemMenu
3670 * The NtUserGetSystemMenu function allows the application to access the
3671 * window menu (also known as the system menu or the control menu) for
3672 * copying and modifying.
3676 * Handle to the window that will own a copy of the window menu.
3678 * Specifies the action to be taken. If this parameter is FALSE,
3679 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3680 * currently in use. The copy is initially identical to the window menu
3681 * but it can be modified.
3682 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3683 * to the default state. The previous window menu, if any, is destroyed.
3686 * If the bRevert parameter is FALSE, the return value is a handle to a
3687 * copy of the window menu. If the bRevert parameter is TRUE, the return
3695 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3697 PWINDOW_OBJECT Window
;
3699 DECLARE_RETURN(HMENU
);
3701 DPRINT("Enter NtUserGetSystemMenu\n");
3704 if (!(Window
= UserGetWindowObject(hWnd
)))
3709 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3714 RETURN(Menu
->MenuInfo
.Self
);
3717 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3723 * NtUserSetSystemMenu
3730 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3732 BOOL Result
= FALSE
;
3733 PWINDOW_OBJECT Window
;
3735 DECLARE_RETURN(BOOL
);
3737 DPRINT("Enter NtUserSetSystemMenu\n");
3738 UserEnterExclusive();
3740 if (!(Window
= UserGetWindowObject(hWnd
)))
3748 * Assign new menu handle.
3750 if (!(Menu
= UserGetMenuObject(hMenu
)))
3755 Result
= IntSetSystemMenu(Window
, Menu
);
3761 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3767 UserGetWindow(HWND hWnd
, UINT Relationship
)
3769 PWINDOW_OBJECT Parent
, Window
;
3770 HWND hWndResult
= NULL
;
3772 if (!(Window
= UserGetWindowObject(hWnd
)))
3775 switch (Relationship
)
3778 if((Parent
= Window
->spwndParent
))
3780 if (Parent
->spwndChild
)
3781 hWndResult
= Parent
->spwndChild
->hSelf
;
3786 if((Parent
= Window
->spwndParent
))
3788 if (Parent
->spwndChild
)
3790 Window
= Parent
->spwndChild
;
3793 while(Window
->spwndNext
)
3794 Window
= Window
->spwndNext
;
3796 hWndResult
= Window
->hSelf
;
3802 if (Window
->spwndNext
)
3803 hWndResult
= Window
->spwndNext
->hSelf
;
3807 if (Window
->spwndPrev
)
3808 hWndResult
= Window
->spwndPrev
->hSelf
;
3812 if((Parent
= UserGetWindowObject(Window
->hOwner
)))
3814 hWndResult
= Parent
->hSelf
;
3818 if (Window
->spwndChild
)
3819 hWndResult
= Window
->spwndChild
->hSelf
;
3827 * NtUserGetWindowLong
3829 * The NtUserGetWindowLong function retrieves information about the specified
3830 * window. The function also retrieves the 32-bit (long) value at the
3831 * specified offset into the extra window memory.
3838 UserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3840 PWINDOW_OBJECT Window
, Parent
;
3844 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3846 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3854 * WndProc is only available to the owner process
3856 if (GWL_WNDPROC
== Index
3857 && Window
->pti
->pEThread
->ThreadsProcess
!= PsGetCurrentProcess())
3859 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3863 if ((INT
)Index
>= 0)
3865 if ((Index
+ sizeof(LONG
)) > Window
->Wnd
->cbwndExtra
)
3867 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3870 Result
= *((LONG
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3877 Result
= Wnd
->ExStyle
;
3881 Result
= Wnd
->style
;
3885 Result
= (LONG
)IntGetWindowProc(Wnd
, Ansi
);
3889 Result
= (LONG
) Wnd
->hModule
;
3892 case GWL_HWNDPARENT
:
3893 Parent
= Window
->spwndParent
;
3896 if (Parent
&& Parent
->hSelf
== IntGetDesktopWindow())
3897 Result
= (LONG
) UserGetWindow(Window
->hSelf
, GW_OWNER
);
3899 Result
= (LONG
) Parent
->hSelf
;
3904 Result
= (LONG
) Wnd
->IDMenu
;
3908 Result
= Wnd
->dwUserData
;
3912 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3913 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3923 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3925 PWINDOW_OBJECT Window
, Parent
;
3927 PWINSTATION_OBJECT WindowStation
;
3931 if (hWnd
== IntGetDesktopWindow())
3933 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3937 if (!(Window
= UserGetWindowObject(hWnd
)))
3944 if (!Wnd
) return 0; // No go on zero.
3946 if ((INT
)Index
>= 0)
3948 if ((Index
+ sizeof(LONG
)) > Wnd
->cbwndExtra
)
3950 SetLastWin32Error(ERROR_INVALID_INDEX
);
3954 OldValue
= *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
));
3956 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3958 OldValue = (LONG)IntSetWindowProc( Wnd,
3961 if (!OldValue) return 0;
3964 *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
)) = NewValue
;
3971 OldValue
= (LONG
) Wnd
->ExStyle
;
3972 Style
.styleOld
= OldValue
;
3973 Style
.styleNew
= NewValue
;
3976 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3978 WindowStation
= Window
->pti
->rpdesk
->rpwinstaParent
;
3981 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3982 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3985 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3986 Wnd
->ExStyle
= (DWORD
)Style
.styleNew
;
3987 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3991 OldValue
= (LONG
) Wnd
->style
;
3992 Style
.styleOld
= OldValue
;
3993 Style
.styleNew
= NewValue
;
3994 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3995 Wnd
->style
= (DWORD
)Style
.styleNew
;
3996 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
4001 if ( Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
4002 Wnd
->fnid
& FNID_FREED
)
4004 SetLastWin32Error(ERROR_ACCESS_DENIED
);
4007 OldValue
= (LONG
)IntSetWindowProc(Wnd
,
4014 OldValue
= (LONG
) Wnd
->hModule
;
4015 Wnd
->hModule
= (HINSTANCE
) NewValue
;
4018 case GWL_HWNDPARENT
:
4019 Parent
= Window
->spwndParent
;
4020 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
4021 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
4023 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
4027 OldValue
= (LONG
) Wnd
->IDMenu
;
4028 Wnd
->IDMenu
= (UINT
) NewValue
;
4032 OldValue
= Wnd
->dwUserData
;
4033 Wnd
->dwUserData
= NewValue
;
4037 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
4038 SetLastWin32Error(ERROR_INVALID_INDEX
);
4048 * NtUserSetWindowLong
4050 * The NtUserSetWindowLong function changes an attribute of the specified
4051 * window. The function also sets the 32-bit (long) value at the specified
4052 * offset into the extra window memory.
4059 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
4061 DECLARE_RETURN(LONG
);
4063 DPRINT("Enter NtUserSetWindowLong\n");
4064 UserEnterExclusive();
4066 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
4069 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
4075 * NtUserSetWindowWord
4077 * Legacy function similar to NtUserSetWindowLong.
4084 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
4086 PWINDOW_OBJECT Window
;
4088 DECLARE_RETURN(WORD
);
4090 DPRINT("Enter NtUserSetWindowWord\n");
4091 UserEnterExclusive();
4093 if (!(Window
= UserGetWindowObject(hWnd
)))
4102 case GWL_HWNDPARENT
:
4103 RETURN( co_UserSetWindowLong(Window
->hSelf
, Index
, (UINT
)NewValue
, TRUE
));
4107 SetLastWin32Error(ERROR_INVALID_INDEX
);
4112 if (Index
> Window
->Wnd
->cbwndExtra
- sizeof(WORD
))
4114 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4118 OldValue
= *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
4119 *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
)) = NewValue
;
4124 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
4133 NtUserGetWindowPlacement(HWND hWnd
,
4134 WINDOWPLACEMENT
*lpwndpl
)
4136 PWINDOW_OBJECT Window
;
4139 WINDOWPLACEMENT Safepl
;
4141 DECLARE_RETURN(BOOL
);
4143 DPRINT("Enter NtUserGetWindowPlacement\n");
4146 if (!(Window
= UserGetWindowObject(hWnd
)))
4152 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4153 if(!NT_SUCCESS(Status
))
4155 SetLastNtError(Status
);
4158 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4164 if (0 == (Wnd
->style
& WS_VISIBLE
))
4166 Safepl
.showCmd
= SW_HIDE
;
4168 else if ((0 != (Window
->state
& WINDOWOBJECT_RESTOREMAX
) ||
4169 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
4170 0 == (Wnd
->style
& WS_MINIMIZE
))
4172 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
4174 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
4176 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
4178 else if (0 != (Wnd
->style
& WS_VISIBLE
))
4180 Safepl
.showCmd
= SW_SHOWNORMAL
;
4183 Size
.x
= Wnd
->rcWindow
.left
;
4184 Size
.y
= Wnd
->rcWindow
.top
;
4185 WinPosInitInternalPos(Window
, &Size
,
4188 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
4189 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
4190 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
4192 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
4193 if(!NT_SUCCESS(Status
))
4195 SetLastNtError(Status
);
4202 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
4212 NtUserLockWindowUpdate(HWND hWnd
)
4232 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
4233 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
4234 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
4238 QueryWindow based on KJK::Hyperion and James Tabor.
4240 0 = QWUniqueProcessId
4241 1 = QWUniqueThreadId
4244 4 = QWIsHung Implements IsHungAppWindow found
4247 9 = QWKillWindow When I called this with hWnd ==
4248 DesktopWindow, it shutdown the system
4255 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
4257 PWINDOW_OBJECT Window
;
4260 DECLARE_RETURN(UINT
);
4262 DPRINT("Enter NtUserQueryWindow\n");
4265 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4274 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
4275 Result
= (DWORD
)IntGetWndProcessId(Window
);
4278 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
4279 Result
= (DWORD
)IntGetWndThreadId(Window
);
4282 case QUERY_WINDOW_ACTIVE
:
4283 Result
= (DWORD
)UserGetActiveWindow();
4286 case QUERY_WINDOW_FOCUS
:
4287 Result
= (DWORD
)IntGetFocusWindow();
4290 case QUERY_WINDOW_ISHUNG
:
4291 Result
= (DWORD
)MsqIsHung(Window
->pti
->MessageQueue
);
4294 case QUERY_WINDOW_REAL_ID
:
4295 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
4298 Result
= (DWORD
)NULL
;
4305 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
4315 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
4329 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4331 UNICODE_STRING SafeMessageName
;
4334 DECLARE_RETURN(UINT
);
4336 DPRINT("Enter NtUserRegisterWindowMessage\n");
4337 UserEnterExclusive();
4339 if(MessageNameUnsafe
== NULL
)
4341 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4345 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4346 if(!NT_SUCCESS(Status
))
4348 SetLastNtError(Status
);
4352 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4353 if (SafeMessageName
.Buffer
)
4354 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4358 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
4368 NtUserSetImeOwnerWindow(DWORD Unknown0
,
4381 NtUserSetInternalWindowPos(
4398 NtUserSetLayeredWindowAttributes(HWND hwnd
,
4412 NtUserSetLogonNotifyWindow(HWND hWnd
)
4429 PWINDOW_OBJECT Window
;
4431 DECLARE_RETURN(BOOL
);
4433 DPRINT("Enter NtUserSetMenu\n");
4434 UserEnterExclusive();
4436 if (!(Window
= UserGetWindowObject(hWnd
)))
4441 if (! IntSetMenu(Window
, Menu
, &Changed
))
4446 if (Changed
&& Repaint
)
4448 USER_REFERENCE_ENTRY Ref
;
4450 UserRefObjectCo(Window
, &Ref
);
4451 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4452 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4454 UserDerefObjectCo(Window
);
4460 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4470 NtUserSetWindowFNID(HWND hWnd
,
4473 PWINDOW_OBJECT Window
;
4475 DECLARE_RETURN(BOOL
);
4477 DPRINT("Enter NtUserSetWindowFNID\n");
4478 UserEnterExclusive();
4480 if (!(Window
= UserGetWindowObject(hWnd
)))
4487 { // From user land we only set these.
4488 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
4493 Wnd
->pcls
->fnid
|= fnID
;
4498 DPRINT("Leave NtUserSetWindowFNID\n");
4508 NtUserSetWindowPlacement(HWND hWnd
,
4509 WINDOWPLACEMENT
*lpwndpl
)
4511 PWINDOW_OBJECT Window
;
4513 WINDOWPLACEMENT Safepl
;
4515 DECLARE_RETURN(BOOL
);
4516 USER_REFERENCE_ENTRY Ref
;
4518 DPRINT("Enter NtUserSetWindowPlacement\n");
4519 UserEnterExclusive();
4521 if (!(Window
= UserGetWindowObject(hWnd
)))
4527 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4528 if(!NT_SUCCESS(Status
))
4530 SetLastNtError(Status
);
4533 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4538 UserRefObjectCo(Window
, &Ref
);
4540 if ((Wnd
->style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4542 co_WinPosSetWindowPos(Window
, NULL
,
4543 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4544 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4545 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4546 SWP_NOZORDER
| SWP_NOACTIVATE
);
4549 /* FIXME - change window status */
4550 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
4552 Wnd
->InternalPosInitialized
= TRUE
;
4553 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4554 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4555 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4557 UserDerefObjectCo(Window
);
4561 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4573 HWND hWndInsertAfter
,
4580 DECLARE_RETURN(BOOL
);
4581 PWINDOW_OBJECT Window
;
4583 USER_REFERENCE_ENTRY Ref
;
4585 DPRINT("Enter NtUserSetWindowPos\n");
4586 UserEnterExclusive();
4588 if (!(Window
= UserGetWindowObject(hWnd
)))
4593 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
4594 if (!(uFlags
& SWP_NOMOVE
))
4596 if (X
< -32768) X
= -32768;
4597 else if (X
> 32767) X
= 32767;
4598 if (Y
< -32768) Y
= -32768;
4599 else if (Y
> 32767) Y
= 32767;
4601 if (!(uFlags
& SWP_NOSIZE
))
4604 else if (cx
> 32767) cx
= 32767;
4606 else if (cy
> 32767) cy
= 32767;
4609 UserRefObjectCo(Window
, &Ref
);
4610 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4611 UserDerefObjectCo(Window
);
4616 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4623 IntGetWindowRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
4641 /* Create a new window region using the window rectangle */
4642 VisRgn
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4643 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4644 /* if there's a region assigned to the window, combine them both */
4645 if(Window
->hrgnClip
&& !(Wnd
->style
& WS_MINIMIZE
))
4646 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->hrgnClip
, RGN_AND
);
4647 /* Copy the region into hRgn */
4648 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4650 if((pRgn
= RGNOBJAPI_Lock(hRgn
, NULL
)))
4652 Ret
= pRgn
->rdh
.iType
;
4653 RGNOBJAPI_Unlock(pRgn
);
4658 REGION_FreeRgnByHandle(VisRgn
);
4664 IntGetWindowRgnBox(PWINDOW_OBJECT Window
, RECTL
*Rect
)
4682 /* Create a new window region using the window rectangle */
4683 VisRgn
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4684 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4685 /* if there's a region assigned to the window, combine them both */
4686 if(Window
->hrgnClip
&& !(Wnd
->style
& WS_MINIMIZE
))
4687 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->hrgnClip
, RGN_AND
);
4689 if((pRgn
= RGNOBJAPI_Lock(VisRgn
, NULL
)))
4691 Ret
= pRgn
->rdh
.iType
;
4692 *Rect
= pRgn
->rdh
.rcBound
;
4693 RGNOBJAPI_Unlock(pRgn
);
4698 REGION_FreeRgnByHandle(VisRgn
);
4714 PWINDOW_OBJECT Window
;
4715 DECLARE_RETURN(INT
);
4717 DPRINT("Enter NtUserSetWindowRgn\n");
4718 UserEnterExclusive();
4720 if (!(Window
= UserGetWindowObject(hWnd
)))
4725 if (hRgn
) // The region will be deleted in user32.
4727 if (GDIOBJ_ValidateHandle(hRgn
, GDI_OBJECT_TYPE_REGION
))
4729 hrgnCopy
= IntSysCreateRectRgn(0, 0, 0, 0);
4730 NtGdiCombineRgn(hrgnCopy
, hRgn
, 0, RGN_COPY
);
4736 hrgnCopy
= (HRGN
) 1;
4738 if (Window
->hrgnClip
)
4740 /* Delete no longer needed region handle */
4741 GreDeleteObject(Window
->hrgnClip
);
4743 Window
->hrgnClip
= hrgnCopy
;
4745 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4749 USER_REFERENCE_ENTRY Ref
;
4750 UserRefObjectCo(Window
, &Ref
);
4751 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4752 UserDerefObjectCo(Window
);
4758 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4768 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4770 PWINDOW_OBJECT Window
;
4772 DECLARE_RETURN(BOOL
);
4773 USER_REFERENCE_ENTRY Ref
;
4775 DPRINT("Enter NtUserShowWindow\n");
4776 UserEnterExclusive();
4778 if (!(Window
= UserGetWindowObject(hWnd
)))
4783 UserRefObjectCo(Window
, &Ref
);
4784 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4785 UserDerefObjectCo(Window
);
4790 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4800 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4806 return NtUserShowWindow(hWnd
, nCmdShow
);
4816 NtUserUpdateLayeredWindow(
4824 BLENDFUNCTION
*pblend
,
4837 NtUserWindowFromPhysicalPoint(POINT Point
)
4848 NtUserWindowFromPoint(LONG X
, LONG Y
)
4852 PWINDOW_OBJECT DesktopWindow
= NULL
, Window
= NULL
;
4853 DECLARE_RETURN(HWND
);
4854 USER_REFERENCE_ENTRY Ref
;
4856 DPRINT("Enter NtUserWindowFromPoint\n");
4857 UserEnterExclusive();
4859 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4867 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4868 //its possible this referencing is useless, thou it shouldnt hurt...
4869 UserRefObjectCo(DesktopWindow
, &Ref
);
4871 pti
= PsGetCurrentThreadWin32Thread();
4872 Hit
= co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4876 Ret
= Window
->hSelf
;
4885 if (Window
) UserDereferenceObject(Window
);
4886 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4888 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4898 * Undocumented function that is called from DefWindowProc to set
4905 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4907 PWINDOW_OBJECT Window
;
4909 LARGE_STRING SafeText
;
4910 UNICODE_STRING UnicodeString
;
4913 DPRINT("Enter NtUserDefSetText\n");
4915 if (WindowText
!= NULL
)
4919 SafeText
= ProbeForReadLargeString(WindowText
);
4921 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4924 SetLastNtError(_SEH2_GetExceptionCode());
4934 UserEnterExclusive();
4936 if(!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4943 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4944 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4945 // Now we know what the bAnsi is for.
4946 RtlInitUnicodeString(&UnicodeString
, NULL
);
4947 if (SafeText
.Buffer
)
4952 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4954 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4955 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4957 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4960 SetLastNtError(_SEH2_GetExceptionCode());
4963 if (!Ret
) goto Exit
;
4966 if (UnicodeString
.Length
!= 0)
4968 if (Wnd
->strName
.MaximumLength
> 0 &&
4969 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4971 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4973 Wnd
->strName
.Length
= UnicodeString
.Length
;
4974 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4975 RtlCopyMemory(Wnd
->strName
.Buffer
,
4976 UnicodeString
.Buffer
,
4977 UnicodeString
.Length
);
4982 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4983 buf
= Wnd
->strName
.Buffer
;
4984 Wnd
->strName
.Buffer
= NULL
;
4987 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4990 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4991 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4992 if (Wnd
->strName
.Buffer
!= NULL
)
4994 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4995 RtlCopyMemory(Wnd
->strName
.Buffer
,
4996 UnicodeString
.Buffer
,
4997 UnicodeString
.Length
);
4998 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4999 Wnd
->strName
.Length
= UnicodeString
.Length
;
5003 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
5011 Wnd
->strName
.Length
= 0;
5012 if (Wnd
->strName
.Buffer
!= NULL
)
5013 Wnd
->strName
.Buffer
[0] = L
'\0';
5016 // HAX! FIXME! Windows does not do this in here!
5017 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
5018 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
5019 /* Send shell notifications */
5020 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
5022 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
5027 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
5028 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
5034 * NtUserInternalGetWindowText
5041 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
5043 PWINDOW_OBJECT Window
;
5047 DECLARE_RETURN(INT
);
5049 DPRINT("Enter NtUserInternalGetWindowText\n");
5052 if(lpString
&& (nMaxCount
<= 1))
5054 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
5058 if(!(Window
= UserGetWindowObject(hWnd
)))
5064 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
5067 const WCHAR Terminator
= L
'\0';
5069 WCHAR
*Buffer
= (WCHAR
*)lpString
;
5071 Copy
= min(nMaxCount
- 1, Result
);
5074 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
5075 if(!NT_SUCCESS(Status
))
5077 SetLastNtError(Status
);
5083 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
5084 if(!NT_SUCCESS(Status
))
5086 SetLastNtError(Status
);
5096 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
5104 IntShowOwnedPopups(PWINDOW_OBJECT OwnerWnd
, BOOL fShow
)
5107 PWINDOW_OBJECT pWnd
;
5110 // ASSERT(OwnerWnd);
5112 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
5117 while (win_array
[count
])
5119 while (--count
>= 0)
5121 if (UserGetWindow( win_array
[count
], GW_OWNER
) != OwnerWnd
->hSelf
)
5123 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
5125 // if (pWnd == WND_OTHER_PROCESS) continue;
5129 if (pWnd
->Wnd
->state
& WNDS_HIDDENPOPUP
)
5131 /* In Windows, ShowOwnedPopups(TRUE) generates
5132 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
5133 * regardless of the state of the owner
5135 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
5141 if (pWnd
->Wnd
->style
& WS_VISIBLE
)
5143 /* In Windows, ShowOwnedPopups(FALSE) generates
5144 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
5145 * regardless of the state of the owner
5147 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
5153 ExFreePool( win_array
);
5158 * NtUserValidateHandleSecure
5166 NtUserValidateHandleSecure(
5174 PUSER_HANDLE_ENTRY entry
;
5175 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
5177 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5180 uType
= entry
->type
;
5186 PWINDOW_OBJECT Window
;
5187 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
5193 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
5198 PACCELERATOR_TABLE Accel
;
5199 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
5204 PCURICON_OBJECT Cursor
;
5205 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
5211 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
5217 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
5223 return UserGetCallProcInfo( handle
, &Proc
);
5226 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5230 { /* Is handle entry restricted? */