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 ******************************************************************/
18 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
20 /* PRIVATE FUNCTIONS **********************************************************/
25 * Initialize windowing implementation.
33 return STATUS_SUCCESS
;
39 * Cleanup windowing implementation.
43 CleanupWindowImpl(VOID
)
45 return STATUS_SUCCESS
;
48 /* HELPER FUNCTIONS ***********************************************************/
50 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
52 WORD Action
= LOWORD(wParam
);
53 WORD Flags
= HIWORD(wParam
);
55 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
57 EngSetLastError(ERROR_INVALID_PARAMETER
);
64 EngSetLastError(ERROR_INVALID_PARAMETER
);
68 if (Flags
& UISF_HIDEFOCUS
)
69 Wnd
->HideFocus
= TRUE
;
70 if (Flags
& UISF_HIDEACCEL
)
71 Wnd
->HideAccel
= TRUE
;
75 if (Flags
& UISF_HIDEFOCUS
)
76 Wnd
->HideFocus
= FALSE
;
77 if (Flags
& UISF_HIDEACCEL
)
78 Wnd
->HideAccel
= FALSE
;
85 PWND FASTCALL
IntGetWindowObject(HWND hWnd
)
89 if (!hWnd
) return NULL
;
91 Window
= UserGetWindowObject(hWnd
);
94 ASSERT(Window
->head
.cLockObj
>= 0);
96 Window
->head
.cLockObj
++;
102 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
107 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
109 ti
= GetW32ThreadInfo();
112 EngSetLastError(ERROR_ACCESS_DENIED
);
119 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
123 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
124 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
126 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
130 ASSERT(Window
->head
.cLockObj
>= 0);
139 * The function determines whether the specified window handle identifies
140 * an existing window.
144 * Handle to the window to test.
147 * If the window handle identifies an existing window, the return value
148 * is TRUE. If the window handle does not identify an existing window,
149 * the return value is FALSE.
153 IntIsWindow(HWND hWnd
)
157 if (!(Window
= UserGetWindowObject(hWnd
)))
165 IntGetParent(PWND Wnd
)
167 if (Wnd
->style
& WS_POPUP
)
169 return Wnd
->spwndOwner
;
171 else if (Wnd
->style
& WS_CHILD
)
173 return Wnd
->spwndParent
;
182 * Compile a list of all child window handles from given window.
185 * This function is similar to Wine WIN_ListChildren. The caller
186 * must free the returned list with ExFreePool.
190 IntWinListChildren(PWND Window
)
194 UINT Index
, NumChildren
= 0;
196 if (!Window
) return NULL
;
198 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
201 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
204 DPRINT1("Failed to allocate memory for children array\n");
205 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
208 for (Child
= Window
->spwndChild
, Index
= 0;
210 Child
= Child
->spwndNext
, ++Index
)
211 List
[Index
] = Child
->head
.h
;
217 /***********************************************************************
220 static void IntSendDestroyMsg(HWND hWnd
)
228 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
230 if (hWnd
== info
.hwndCaret
)
237 Window
= UserGetWindowObject(hWnd
);
240 // USER_REFERENCE_ENTRY Ref;
241 // UserRefObjectCo(Window, &Ref);
243 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
245 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
248 // UserDerefObjectCo(Window);
251 /* The window could already be destroyed here */
254 * Send the WM_DESTROY to the window.
257 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
260 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
261 * make sure that the window still exists when we come back.
270 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
273 /* start from the end (FIXME: is this needed?) */
274 for (i
= 0; pWndArray
[i
]; i
++)
279 if (IsWindow( pWndArray
[i
] ))
280 WIN_SendDestroyMsg( pWndArray
[i
] );
282 HeapFree(GetProcessHeap(), 0, pWndArray
);
286 DPRINT("destroyed itself while in WM_DESTROY!\n");
292 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
294 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
298 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
300 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
301 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
304 if (Wnd
->strName
.Buffer
!= NULL
)
306 Wnd
->strName
.Length
= 0;
307 Wnd
->strName
.MaximumLength
= 0;
308 DesktopHeapFree(Wnd
->head
.rpdesk
,
309 Wnd
->strName
.Buffer
);
310 Wnd
->strName
.Buffer
= NULL
;
313 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
314 // WindowObject->Wnd = NULL;
317 /***********************************************************************
320 * Destroy storage associated to a window. "Internals" p.358
322 * This is the "functional" DestroyWindows function ei. all stuff
323 * done in CreateWindow is undone here and not in DestroyWindow:-P
326 static LRESULT
co_UserFreeWindow(PWND Window
,
327 PPROCESSINFO ProcessData
,
328 PTHREADINFO ThreadData
,
329 BOOLEAN SendMessages
)
335 BOOLEAN BelongsToThreadData
;
339 if(Window
->state2
& WNDS2_INDESTROY
)
341 DPRINT("Tried to call IntDestroyWindow() twice\n");
344 Window
->state2
|= WNDS2_INDESTROY
;
345 Window
->style
&= ~WS_VISIBLE
;
347 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
349 /* remove the window already at this point from the thread window list so we
350 don't get into trouble when destroying the thread windows while we're still
351 in IntDestroyWindow() */
352 RemoveEntryList(&Window
->ThreadListEntry
);
354 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
356 IntDeRegisterShellHookWindow(Window
->head
.h
);
360 /* Send destroy messages */
361 IntSendDestroyMsg(Window
->head
.h
);
364 /* free child windows */
365 Children
= IntWinListChildren(Window
);
368 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
370 if ((Child
= IntGetWindowObject(*ChildHandle
)))
372 if(!IntWndBelongsToThread(Child
, ThreadData
))
374 /* send WM_DESTROY messages to windows not belonging to the same thread */
375 IntSendDestroyMsg(Child
->head
.h
);
378 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
380 UserDereferenceObject(Child
);
383 ExFreePool(Children
);
389 * Clear the update region to make sure no WM_PAINT messages will be
390 * generated for this window while processing the WM_NCDESTROY.
392 co_UserRedrawWindow(Window
, NULL
, 0,
393 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
394 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
395 if(BelongsToThreadData
)
396 co_IntSendMessage(Window
->head
.h
, WM_NCDESTROY
, 0, 0);
399 DestroyTimersForWindow(ThreadData
, Window
);
401 /* Unregister hot keys */
402 UnregisterWindowHotKeys (Window
);
404 /* flush the message queue */
405 MsqRemoveWindowMessagesFromQueue(Window
);
407 /* from now on no messages can be sent to this window anymore */
408 Window
->state
|= WNDS_DESTROYED
;
409 Window
->fnid
|= FNID_FREED
;
411 /* don't remove the WINDOWSTATUS_DESTROYING bit */
413 /* reset shell window handles */
414 if(ThreadData
->rpdesk
)
416 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
417 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
419 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
420 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
423 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
427 WinPosCheckInternalPos(Window
->head
.h
);
428 if (Window
->head
.h
== GetCapture())
433 /* free resources associated with the window */
434 TIMER_RemoveWindowTimers(Window
->head
.h
);
437 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
439 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
441 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
445 if(Window
->SystemMenu
446 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
448 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
449 Window
->SystemMenu
= (HMENU
)0;
452 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
455 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
456 CLASS_RemoveWindow(Window
->Class
);
459 IntUnlinkWindow(Window
);
461 UserReferenceObject(Window
);
462 UserDeleteObject(Window
->head
.h
, otWindow
);
464 IntDestroyScrollBars(Window
);
466 /* dereference the class */
467 IntDereferenceClass(Window
->pcls
,
468 Window
->head
.pti
->pDeskInfo
,
469 Window
->head
.pti
->ppi
);
474 GreDeleteObject(Window
->hrgnClip
);
475 Window
->hrgnClip
= NULL
;
478 // ASSERT(Window != NULL);
479 UserFreeWindowInfo(Window
->head
.pti
, Window
);
481 UserDereferenceObject(Window
);
483 IntClipboardFreeWindow(Window
);
489 IntGetWindowBorderMeasures(PWND Wnd
, UINT
*cx
, UINT
*cy
)
491 if(HAS_DLGFRAME(Wnd
->style
, Wnd
->ExStyle
) && !(Wnd
->style
& WS_MINIMIZE
))
493 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
494 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
498 if(HAS_THICKFRAME(Wnd
->style
, Wnd
->ExStyle
)&& !(Wnd
->style
& WS_MINIMIZE
))
500 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
501 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
503 else if(HAS_THINFRAME(Wnd
->style
, Wnd
->ExStyle
))
505 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
506 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
516 // Same as User32:IntGetWndProc.
519 IntGetWindowProc(PWND pWnd
,
524 WNDPROC gcpd
, Ret
= 0;
526 ASSERT(UserIsEnteredExclusive() == TRUE
);
530 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
532 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
534 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
537 Ret
= GETPFNCLIENTA(i
);
539 Ret
= GETPFNCLIENTW(i
);
545 if (Class
->fnid
== FNID_EDIT
)
546 Ret
= pWnd
->lpfnWndProc
;
549 Ret
= pWnd
->lpfnWndProc
;
551 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
555 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
556 Ret
= GETPFNCLIENTA(Class
->fnid
);
560 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
561 Ret
= GETPFNCLIENTW(Class
->fnid
);
564 if ( Ret
!= pWnd
->lpfnWndProc
)
567 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
570 gcpd
= (WNDPROC
)UserGetCPD(
572 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
575 return (gcpd
? gcpd
: Ret
);
579 IntSetWindowProc(PWND pWnd
,
584 PCALLPROCDATA CallProc
;
586 WNDPROC Ret
, chWndProc
= NULL
;
588 // Retrieve previous window proc.
589 Ret
= IntGetWindowProc(pWnd
, Ansi
);
593 if (IsCallProcHandle(NewWndProc
))
595 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, otCallProc
);
597 { // Reset new WndProc.
598 NewWndProc
= CallProc
->pfnClientPrevious
;
599 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
600 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
603 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
604 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
606 if (GETPFNCLIENTW(i
) == NewWndProc
)
608 chWndProc
= GETPFNSERVER(i
);
611 if (GETPFNCLIENTA(i
) == NewWndProc
)
613 chWndProc
= GETPFNSERVER(i
);
617 // If match, set/reset to Server Side and clear ansi.
620 pWnd
->lpfnWndProc
= chWndProc
;
621 pWnd
->Unicode
= TRUE
;
622 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
623 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
627 pWnd
->Unicode
= !Ansi
;
628 // Handle the state change in here.
630 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
632 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
634 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
635 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
637 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
639 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
643 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
644 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
648 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
649 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
652 // Now set the new window proc.
653 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
664 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
666 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
668 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
672 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
680 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
681 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Wnd
->head
.h
);
690 NewMenu
= IntGetMenuObject(Menu
);
695 IntReleaseMenuObject(OldMenu
);
697 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
700 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
702 /* Can't use the same menu for two windows */
705 IntReleaseMenuObject(OldMenu
);
707 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
713 Wnd
->IDMenu
= (UINT
) Menu
;
716 NewMenu
->MenuInfo
.Wnd
= Wnd
->head
.h
;
717 IntReleaseMenuObject(NewMenu
);
721 OldMenu
->MenuInfo
.Wnd
= NULL
;
722 IntReleaseMenuObject(OldMenu
);
729 /* INTERNAL ******************************************************************/
733 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
738 USER_REFERENCE_ENTRY Ref
;
739 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
741 while (!IsListEmpty(&WThread
->WindowListHead
))
743 Current
= WThread
->WindowListHead
.Flink
;
744 Wnd
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
746 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
748 /* window removes itself from the list */
751 fixme: it is critical that the window removes itself! if now, we will loop
755 //ASSERT(co_UserDestroyWindow(Wnd));
757 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
758 if (!co_UserDestroyWindow(Wnd
))
760 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
762 UserDerefObjectCo(Wnd
);//faxme: temp hack??
770 * Returns client window rectangle relative to the upper-left corner of client area.
772 * \note Does not check the validity of the parameters
775 IntGetClientRect(PWND Window
, RECTL
*Rect
)
780 Rect
->left
= Rect
->top
= 0;
781 Rect
->right
= Window
->rcClient
.right
- Window
->rcClient
.left
;
782 Rect
->bottom
= Window
->rcClient
.bottom
- Window
->rcClient
.top
;
786 PMENU_OBJECT FASTCALL
787 IntGetSystemMenu(PWND Window
, BOOL bRevert
, BOOL RetMenu
)
789 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
790 PTHREADINFO W32Thread
;
791 HMENU hNewMenu
, hSysMenu
;
792 ROSMENUITEMINFO ItemInfo
;
796 W32Thread
= PsGetCurrentThreadWin32Thread();
798 if(!W32Thread
->rpdesk
)
801 if(Window
->SystemMenu
)
803 Menu
= UserGetMenuObject(Window
->SystemMenu
);
806 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
807 Window
->SystemMenu
= (HMENU
)0;
811 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
813 /* clone system menu */
814 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
818 NewMenu
= IntCloneMenu(Menu
);
821 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
822 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
823 NewMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
825 //IntReleaseMenuObject(NewMenu);
830 hSysMenu
= UserCreateMenu(FALSE
);
831 if (NULL
== hSysMenu
)
835 SysMenu
= IntGetMenuObject(hSysMenu
);
838 UserDestroyMenu(hSysMenu
);
841 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
842 SysMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
843 hNewMenu
= co_IntLoadSysMenuTemplate();
846 IntReleaseMenuObject(SysMenu
);
847 UserDestroyMenu(hSysMenu
);
850 Menu
= IntGetMenuObject(hNewMenu
);
853 IntReleaseMenuObject(SysMenu
);
854 UserDestroyMenu(hSysMenu
);
858 NewMenu
= IntCloneMenu(Menu
);
861 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
862 IntReleaseMenuObject(NewMenu
);
863 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
865 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
866 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
867 ItemInfo
.fType
= MF_POPUP
;
868 ItemInfo
.fState
= MFS_ENABLED
;
869 ItemInfo
.dwTypeData
= NULL
;
871 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
872 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
874 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
878 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
887 if(Window
->SystemMenu
)
888 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
896 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
901 while (Window
&& ((Window
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
903 if (Window
== Parent
)
908 Window
= Window
->spwndParent
;
915 IntIsWindowVisible(PWND BaseWindow
)
922 if(!(Window
->style
& WS_CHILD
))
926 if(!(Window
->style
& WS_VISIBLE
))
931 Window
= Window
->spwndParent
;
934 if(Window
&& Window
->style
& WS_VISIBLE
)
944 link the window into siblings list
945 children and parent are kept in place.
950 PWND WndInsertAfter
/* set to NULL if top sibling */
953 if ((Wnd
->spwndPrev
= WndInsertAfter
))
955 /* link after WndInsertAfter */
956 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
957 Wnd
->spwndNext
->spwndPrev
= Wnd
;
959 Wnd
->spwndPrev
->spwndNext
= Wnd
;
964 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
965 Wnd
->spwndNext
->spwndPrev
= Wnd
;
967 Wnd
->spwndParent
->spwndChild
= Wnd
;
972 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
974 if (hWndPrev
== HWND_NOTOPMOST
)
976 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
977 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
978 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
979 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
982 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
984 if (hWndPrev
== HWND_BOTTOM
)
986 /* Link in the bottom of the list */
989 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
990 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
991 WndInsertAfter
= WndInsertAfter
->spwndNext
;
993 IntLinkWindow(Wnd
, WndInsertAfter
);
994 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
996 else if (hWndPrev
== HWND_TOPMOST
)
998 /* Link in the top of the list */
999 IntLinkWindow(Wnd
, NULL
);
1001 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1003 else if (hWndPrev
== HWND_TOP
)
1005 /* Link it after the last topmost window */
1006 PWND WndInsertBefore
;
1008 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
1010 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
1012 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
1014 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
1015 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
1017 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1020 WndInsertBefore
= WndInsertBefore
->spwndNext
;
1024 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
1028 /* Link it after hWndPrev */
1029 PWND WndInsertAfter
;
1031 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1032 /* Are we called with an erroneous handle */
1033 if(WndInsertAfter
== NULL
)
1035 /* Link in a default position */
1036 IntLinkHwnd(Wnd
, HWND_TOP
);
1040 IntLinkWindow(Wnd
, WndInsertAfter
);
1042 /* Fix the WS_EX_TOPMOST flag */
1043 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1045 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1049 if(WndInsertAfter
->spwndNext
&&
1050 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1052 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1059 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1061 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1064 Wnd
= IntGetWindowObject(hWnd
);
1068 WndOldOwner
= Wnd
->spwndOwner
;
1070 ret
= WndOldOwner
? WndOldOwner
->head
.h
: 0;
1072 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1074 Wnd
->spwndOwner
= WndNewOwner
;
1078 Wnd
->spwndOwner
= NULL
;
1081 UserDereferenceObject(Wnd
);
1086 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1088 PWND WndOldParent
, pWndExam
;
1092 ASSERT(WndNewParent
);
1093 ASSERT_REFS_CO(Wnd
);
1094 ASSERT_REFS_CO(WndNewParent
);
1096 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1098 EngSetLastError(ERROR_ACCESS_DENIED
);
1102 /* Some applications try to set a child as a parent */
1103 if (IntIsChildWindow(Wnd
, WndNewParent
))
1105 EngSetLastError( ERROR_INVALID_PARAMETER
);
1109 pWndExam
= WndNewParent
; // Load parent Window to examine.
1110 // Now test for set parent to parent hit.
1113 if (Wnd
== pWndExam
)
1115 EngSetLastError(ERROR_INVALID_PARAMETER
);
1118 pWndExam
= pWndExam
->spwndParent
;
1122 * Windows hides the window first, then shows it again
1123 * including the WM_SHOWWINDOW messages and all
1125 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1127 /* Window must belong to current process */
1128 if (Wnd
->head
.pti
->pEThread
->ThreadsProcess
!= PsGetCurrentProcess())
1131 WndOldParent
= Wnd
->spwndParent
;
1133 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1135 if (WndNewParent
!= WndOldParent
)
1137 /* Unlink the window from the siblings list */
1138 IntUnlinkWindow(Wnd
);
1140 /* Set the new parent */
1141 Wnd
->spwndParent
= WndNewParent
;
1143 /* Link the window with its new siblings*/
1144 IntLinkHwnd(Wnd
, HWND_TOP
);
1148 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1150 * SetParent additionally needs to make hwnd the top window
1151 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1152 * WM_WINDOWPOSCHANGED notification messages.
1154 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1155 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1156 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1159 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1160 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1163 return WndOldParent
;
1167 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1169 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1170 HWND hWndOldParent
= NULL
;
1171 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1173 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1175 EngSetLastError(ERROR_INVALID_PARAMETER
);
1179 if (hWndChild
== IntGetDesktopWindow())
1181 EngSetLastError(ERROR_ACCESS_DENIED
);
1187 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1194 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1200 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1205 UserRefObjectCo(Wnd
, &Ref
);
1206 UserRefObjectCo(WndParent
, &ParentRef
);
1208 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1210 UserDerefObjectCo(WndParent
);
1211 UserDerefObjectCo(Wnd
);
1215 hWndOldParent
= WndOldParent
->head
.h
;
1216 UserDereferenceObject(WndOldParent
);
1219 return( hWndOldParent
);
1223 IntSetSystemMenu(PWND Window
, PMENU_OBJECT Menu
)
1225 PMENU_OBJECT OldMenu
;
1226 if(Window
->SystemMenu
)
1228 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1231 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1232 IntReleaseMenuObject(OldMenu
);
1238 /* FIXME check window style, propably return FALSE ? */
1239 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1240 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1243 Window
->SystemMenu
= (HMENU
)0;
1248 /* unlink the window from siblings. children and parent are kept in place. */
1250 IntUnlinkWindow(PWND Wnd
)
1253 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1256 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1258 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1259 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1261 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1266 IntGetWindowPlacement(PWND Wnd
, WINDOWPLACEMENT
*lpwndpl
)
1270 if (!Wnd
) return FALSE
;
1272 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1278 if (0 == (Wnd
->style
& WS_VISIBLE
))
1280 lpwndpl
->showCmd
= SW_HIDE
;
1282 else if (0 != (Wnd
->state2
& WNDS2_MAXIMIZEBUTTONDOWN
) ||
1283 0 != (Wnd
->style
& WS_MAXIMIZE
))
1285 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1287 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1289 lpwndpl
->showCmd
= SW_MINIMIZE
;
1291 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1293 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1296 Size
.x
= Wnd
->rcWindow
.left
;
1297 Size
.y
= Wnd
->rcWindow
.top
;
1298 WinPosInitInternalPos(Wnd
, &Size
,
1301 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1302 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1303 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1309 /* FUNCTIONS *****************************************************************/
1312 * As best as I can figure, this function is used by EnumWindows,
1313 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1315 * It's supposed to build a list of HWNDs to return to the caller.
1316 * We can figure out what kind of list by what parameters are
1324 NtUserBuildHwndList(
1337 return ERROR_INVALID_PARAMETER
;
1339 if (hwndParent
|| !dwThreadId
)
1342 PWND Parent
, Window
;
1346 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1348 return ERROR_INVALID_HANDLE
;
1353 Status
= IntValidateDesktopHandle(hDesktop
,
1357 if(!NT_SUCCESS(Status
))
1359 return ERROR_INVALID_HANDLE
;
1362 hwndParent
= Desktop
->DesktopWindow
;
1369 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1370 (Window
= Parent
->spwndChild
))
1372 BOOL bGoDown
= TRUE
;
1374 Status
= STATUS_SUCCESS
;
1379 if(dwCount
++ < *pBufSize
&& pWnd
)
1383 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1384 *pWnd
= Window
->head
.h
;
1387 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1389 Status
= _SEH2_GetExceptionCode();
1392 if(!NT_SUCCESS(Status
))
1394 SetLastNtError(Status
);
1398 if (Window
->spwndChild
&& bChildren
)
1400 Window
= Window
->spwndChild
;
1405 if (Window
->spwndNext
)
1407 Window
= Window
->spwndNext
;
1411 Window
= Window
->spwndParent
;
1412 if (Window
== Parent
)
1421 ObDereferenceObject(Desktop
);
1424 else // Build EnumThreadWindows list!
1427 PTHREADINFO W32Thread
;
1428 PLIST_ENTRY Current
;
1431 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1432 if (!NT_SUCCESS(Status
))
1434 DPRINT1("Thread Id is not valid!\n");
1435 return ERROR_INVALID_PARAMETER
;
1437 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1439 ObDereferenceObject(Thread
);
1440 DPRINT1("Thread is not initialized!\n");
1441 return ERROR_INVALID_PARAMETER
;
1444 Current
= W32Thread
->WindowListHead
.Flink
;
1445 while (Current
!= &(W32Thread
->WindowListHead
))
1447 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1450 if (dwCount
< *pBufSize
&& pWnd
)
1454 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1455 *pWnd
= Window
->head
.h
;
1458 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1460 Status
= _SEH2_GetExceptionCode();
1463 if (!NT_SUCCESS(Status
))
1465 DPRINT1("Failure to build window list!\n");
1466 SetLastNtError(Status
);
1471 Current
= Window
->ThreadListEntry
.Flink
;
1474 ObDereferenceObject(Thread
);
1477 *pBufSize
= dwCount
;
1478 return STATUS_SUCCESS
;
1486 NtUserChildWindowFromPointEx(HWND hwndParent
,
1496 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1504 if(Parent
->head
.h
!= IntGetDesktopWindow())
1506 Pt
.x
+= Parent
->rcClient
.left
;
1507 Pt
.y
+= Parent
->rcClient
.top
;
1510 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1515 Ret
= Parent
->head
.h
;
1516 if((List
= IntWinListChildren(Parent
)))
1518 for(phWnd
= List
; *phWnd
; phWnd
++)
1521 if((Child
= UserGetWindowObject(*phWnd
)))
1523 if(!(Child
->style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1527 if((Child
->style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1531 if((Child
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1535 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1537 Ret
= Child
->head
.h
;
1548 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1550 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1551 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1553 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1555 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1557 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1558 (LPARAM
)pWindow
->head
.h
);
1564 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1566 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1568 /* default positioning for overlapped windows */
1569 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1572 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1574 pMonitor
= IntGetPrimaryMonitor();
1577 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1579 if (IS_DEFAULT(Cs
->x
))
1581 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1583 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1585 Cs
->x
= ProcessParams
->StartingX
;
1586 Cs
->y
= ProcessParams
->StartingY
;
1590 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1591 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1592 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1593 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1595 /* reset counter and position */
1598 pMonitor
->cWndStack
= 0;
1600 pMonitor
->cWndStack
++;
1604 if (IS_DEFAULT(Cs
->cx
))
1606 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1608 Cs
->cx
= ProcessParams
->CountX
;
1609 Cs
->cy
= ProcessParams
->CountY
;
1613 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1614 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1617 /* neither x nor cx are default. Check the y values .
1618 * In the trace we see Outlook and Outlook Express using
1619 * cy set to CW_USEDEFAULT when opening the address book.
1621 else if (IS_DEFAULT(Cs
->cy
))
1623 DPRINT("Strange use of CW_USEDEFAULT in nHeight\n");
1624 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1629 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1630 if(IS_DEFAULT(Cs
->x
))
1635 if(IS_DEFAULT(Cs
->cx
))
1645 /* Allocates and initializes a window*/
1646 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1647 PLARGE_STRING WindowName
,
1654 PTHREADINFO pti
= NULL
;
1655 PMENU_OBJECT SystemMenu
;
1657 BOOL bUnicodeWindow
;
1659 pti
= PsGetCurrentThreadWin32Thread();
1661 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1665 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1666 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1667 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1668 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1672 Note from MSDN http://msdn.microsoft.com/en-us/library/aa913269.aspx :
1674 Dialog boxes and message boxes do not inherit layout, so you must
1675 set the layout explicitly.
1677 if ( Class
&& Class
->fnid
!= FNID_DIALOG
)
1679 PPROCESSINFO ppi
= PsGetCurrentProcessWin32Process();
1680 if (ppi
->dwLayout
& LAYOUT_RTL
)
1682 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1688 /* Automatically add WS_EX_WINDOWEDGE */
1689 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1690 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1691 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1692 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1694 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1696 /* Is it a unicode window? */
1697 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1698 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1700 /* Allocate the new window */
1701 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1705 sizeof(WND
) + Class
->cbwndExtra
);
1712 DPRINT("Created object with handle %X\n", hWnd
);
1714 if (NULL
== pti
->rpdesk
->DesktopWindow
)
1716 /* If there is no desktop window yet, we must be creating it */
1717 pti
->rpdesk
->DesktopWindow
= hWnd
;
1718 pti
->rpdesk
->pDeskInfo
->spwnd
= pWnd
;
1722 * Fill out the structure describing it.
1724 /* Remember, pWnd->head is setup in object.c ...*/
1725 pWnd
->spwndParent
= ParentWindow
;
1726 pWnd
->spwndOwner
= OwnerWindow
;
1728 pWnd
->hWndLastActive
= hWnd
;
1729 pWnd
->state2
|= WNDS2_WIN40COMPAT
;
1731 pWnd
->hModule
= Cs
->hInstance
;
1732 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1733 pWnd
->ExStyle
= Cs
->dwExStyle
;
1734 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1736 IntReferenceMessageQueue(pWnd
->head
.pti
->MessageQueue
);
1737 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1739 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1740 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1743 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1744 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1746 /* BugBoy Comments: Comment below say that System classes are always created
1747 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1748 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1750 No where can I see in code or through testing does the window change back
1751 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1752 see what problems this would cause.*/
1754 // Set WndProc from Class.
1755 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1757 // GetWindowProc, test for non server side default classes and set WndProc.
1758 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1762 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1763 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1767 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1768 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1772 // If not an Unicode caller, set Ansi creator bit.
1773 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1775 // Clone Class Ansi/Unicode proc type.
1776 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1778 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1779 pWnd
->Unicode
= FALSE
;
1783 It seems there can be both an Ansi creator and Unicode Class Window
1784 WndProc, unless the following overriding conditions occur:
1786 if ( !bUnicodeWindow
&&
1787 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1788 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1789 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1790 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1791 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1792 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1793 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1794 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1795 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1796 { // Override Class and set the window Ansi WndProc.
1797 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1798 pWnd
->Unicode
= FALSE
;
1801 { // Set the window Unicode WndProc.
1802 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1803 pWnd
->Unicode
= TRUE
;
1807 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1808 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1809 Dont understand why it does this. */
1810 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1812 PCALLPROCDATA CallProc
;
1813 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1817 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1818 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
1822 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1826 InitializeListHead(&pWnd
->PropListHead
);
1828 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1830 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1831 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1832 if (pWnd
->strName
.Buffer
== NULL
)
1837 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1838 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1839 pWnd
->strName
.Length
= WindowName
->Length
;
1840 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1843 /* Correct the window style. */
1844 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1846 pWnd
->style
|= WS_CLIPSIBLINGS
;
1847 if (!(pWnd
->style
& WS_POPUP
))
1849 pWnd
->style
|= WS_CAPTION
;
1850 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1854 if ((pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
) ||
1855 (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
1856 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1858 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1860 /* create system menu */
1861 if((Cs
->style
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1863 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1866 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1867 IntReleaseMenuObject(SystemMenu
);
1871 /* Set the window menu */
1872 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1875 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1876 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1878 UNICODE_STRING MenuName
;
1881 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1883 MenuName
.Length
= 0;
1884 MenuName
.MaximumLength
= 0;
1885 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1889 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1891 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1892 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1896 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1898 /* Insert the window into the thread's window list. */
1899 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1901 /* Handle "CS_CLASSDC", it is tested first. */
1902 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1903 { /* One DCE per class to have CLASS. */
1904 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1906 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1907 { /* Allocate a DCE for this window. */
1908 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1916 UserDereferenceObject(pWnd
);
1918 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1926 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1927 PUNICODE_STRING ClassName
,
1928 PLARGE_STRING WindowName
)
1930 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1931 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1932 PWINSTATION_OBJECT WinSta
;
1936 CBT_CREATEWNDW
* pCbtCreate
;
1938 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1940 DWORD dwShowMode
= SW_SHOW
;
1941 CREATESTRUCTW
*pCsw
= NULL
;
1942 PVOID pszClass
= NULL
, pszName
= NULL
;
1943 DECLARE_RETURN(PWND
);
1945 /* Get the current window station and reference it */
1946 pti
= GetW32ThreadInfo();
1947 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1949 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1950 return NULL
; //There is nothing to cleanup
1952 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1953 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1958 /* Get the class and reference it*/
1959 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
);
1962 DPRINT1("Failed to find class %wZ\n", ClassName
);
1966 /* Now find the parent and the owner window */
1967 hWndParent
= IntGetDesktopWindow();
1970 if (Cs
->hwndParent
== HWND_MESSAGE
)
1972 Cs
->hwndParent
= hWndParent
= IntGetMessageWindow();
1974 else if (Cs
->hwndParent
)
1976 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1977 hWndOwner
= Cs
->hwndParent
;
1979 hWndParent
= Cs
->hwndParent
;
1981 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1983 DPRINT1("Cannot create a child window without a parrent!\n");
1984 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1985 RETURN(NULL
); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1988 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1989 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1991 /* FIXME: is this correct?*/
1993 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
1995 /* Fix the position and the size of the window */
1998 UserRefObjectCo(ParentWindow
, &ParentRef
);
1999 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2002 /* Allocate and initialize the new window */
2003 Window
= IntCreateWindow(Cs
,
2010 DPRINT1("IntCreateWindow failed!\n");
2014 hWnd
= UserHMGetHandle(Window
);
2015 hwndInsertAfter
= HWND_TOP
;
2017 UserRefObjectCo(Window
, &Ref
);
2018 ObDereferenceObject(WinSta
);
2020 //// Check for a hook to eliminate overhead. ////
2021 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2023 // Allocate the calling structures Justin Case this goes Global.
2024 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2025 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2027 /* Fill the new CREATESTRUCTW */
2028 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2029 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2031 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2032 if (!IS_ATOM(ClassName
->Buffer
))
2034 if (Window
->state
& WNDS_ANSICREATOR
)
2036 ANSI_STRING AnsiString
;
2037 AnsiString
.MaximumLength
= RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2038 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2039 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2040 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2041 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2045 UNICODE_STRING UnicodeString
;
2046 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2047 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2048 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2049 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2050 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2052 if (pszClass
) pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2054 if (WindowName
->Length
)
2056 UNICODE_STRING Name
;
2057 Name
.Buffer
= WindowName
->Buffer
;
2058 Name
.Length
= WindowName
->Length
;
2059 Name
.MaximumLength
= WindowName
->MaximumLength
;
2061 if (Window
->state
& WNDS_ANSICREATOR
)
2063 ANSI_STRING AnsiString
;
2064 AnsiString
.MaximumLength
= RtlUnicodeStringToAnsiSize(&Name
)+sizeof(CHAR
);
2065 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2066 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2067 AnsiString
.Buffer
= (PCHAR
)pszName
;
2068 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2072 UNICODE_STRING UnicodeString
;
2073 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2074 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2075 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2076 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2077 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2079 if (pszName
) pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2082 pCbtCreate
->lpcs
= pCsw
;
2083 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2085 //// Call the WH_CBT hook ////
2086 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2089 DPRINT1("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2090 RETURN( (PWND
) NULL
);
2092 // Write back changes.
2097 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2100 /* NCCREATE and WM_NCCALCSIZE need the original values */
2101 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2102 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2104 /* Send the WM_GETMINMAXINFO message*/
2108 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2110 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2112 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2113 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2114 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2115 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2116 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2119 Window
->rcWindow
.left
= Cs
->x
;
2120 Window
->rcWindow
.top
= Cs
->y
;
2121 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2122 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2123 if (0 != (Window
->style
& WS_CHILD
) && ParentWindow
)
2125 RECTL_vOffsetRect(&Window
->rcWindow
,
2126 ParentWindow
->rcClient
.left
,
2127 ParentWindow
->rcClient
.top
);
2129 Window
->rcClient
= Window
->rcWindow
;
2131 /* Link the window*/
2132 if (NULL
!= ParentWindow
)
2134 /* link the window into the siblings list */
2135 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2136 IntLinkHwnd(Window
, HWND_BOTTOM
);
2138 IntLinkHwnd(Window
, hwndInsertAfter
);
2141 /* Send the NCCREATE message */
2142 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2145 DPRINT1("co_UserCreateWindowEx(): NCCREATE message failed\n");
2149 /* Send the WM_NCCALCSIZE message */
2150 MaxPos
.x
= Window
->rcWindow
.left
;
2151 MaxPos
.y
= Window
->rcWindow
.top
;
2153 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2155 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2156 MaxPos
.y
- Window
->rcWindow
.top
);
2159 /* Send the WM_CREATE message. */
2160 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2161 if (Result
== (LRESULT
)-1)
2163 DPRINT1("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2167 /* Send the EVENT_OBJECT_CREATE event*/
2168 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2170 /* By setting the flag below it can be examined to determine if the window
2171 was created successfully and a valid pwnd was passed back to caller since
2172 from here the function has to succeed. */
2173 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2175 /* Send the WM_SIZE and WM_MOVE messages. */
2176 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2178 co_WinPosSendSizeMove(Window
);
2181 /* Show or maybe minimize or maximize the window. */
2182 if (Window
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2187 SwFlag
= (Window
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2189 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2191 SwFlag
= ((Window
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2192 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2193 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2195 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2196 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2199 /* Send the WM_PARENTNOTIFY message */
2200 IntSendParentNotify(Window
, WM_CREATE
);
2202 /* Notify the shell that a new window was created */
2203 if ((!hWndParent
) && (!hWndOwner
))
2205 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2208 /* Initialize and show the window's scrollbars */
2209 if (Window
->style
& WS_VSCROLL
)
2211 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2213 if (Window
->style
& WS_HSCROLL
)
2215 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2218 /* Show the new window */
2219 if (Cs
->style
& WS_VISIBLE
)
2221 if (Window
->style
& WS_MAXIMIZE
)
2222 dwShowMode
= SW_SHOW
;
2223 else if (Window
->style
& WS_MINIMIZE
)
2224 dwShowMode
= SW_SHOWMINIMIZED
;
2226 co_WinPosShowWindow(Window
, dwShowMode
);
2228 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2230 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2231 /* ShowWindow won't activate child windows */
2232 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2236 DPRINT("co_UserCreateWindowEx(): Created window %X\n", hWnd
);
2242 DPRINT("co_UserCreateWindowEx(): Error Created window!\n");
2243 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2245 co_UserDestroyWindow(Window
);
2247 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2250 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2251 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2252 if (pszName
) UserHeapFree(pszName
);
2253 if (pszClass
) UserHeapFree(pszClass
);
2257 UserDerefObjectCo(Window
);
2258 UserDereferenceObject(Window
);
2260 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2267 ProbeAndCaptureLargeString(
2268 OUT PLARGE_STRING plstrSafe
,
2269 IN PLARGE_STRING plstrUnsafe
)
2271 LARGE_STRING lstrTemp
;
2272 PVOID pvBuffer
= NULL
;
2276 /* Probe and copy the string */
2277 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2278 lstrTemp
= *plstrUnsafe
;
2280 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2283 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2287 if (lstrTemp
.Length
!= 0)
2289 /* Allocate a buffer from paged pool */
2290 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2293 return STATUS_NO_MEMORY
;
2298 /* Probe and copy the buffer */
2299 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2300 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2302 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2304 /* Cleanup and fail */
2305 ExFreePool(pvBuffer
);
2306 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2311 /* Set the output string */
2312 plstrSafe
->Buffer
= pvBuffer
;
2313 plstrSafe
->Length
= lstrTemp
.Length
;
2314 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2316 return STATUS_SUCCESS
;
2320 * \todo Allow passing plstrClassName as ANSI.
2324 NtUserCreateWindowEx(
2326 PLARGE_STRING plstrClassName
,
2327 PLARGE_STRING plstrClsVersion
,
2328 PLARGE_STRING plstrWindowName
,
2336 HINSTANCE hInstance
,
2342 LARGE_STRING lstrWindowName
;
2343 LARGE_STRING lstrClassName
;
2344 UNICODE_STRING ustrClassName
;
2349 lstrWindowName
.Buffer
= NULL
;
2350 lstrClassName
.Buffer
= NULL
;
2352 /* Check if we got a Window name */
2353 if (plstrWindowName
)
2355 /* Copy the string to kernel mode */
2356 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2357 if (!NT_SUCCESS(Status
))
2359 DPRINT1("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2360 SetLastNtError(Status
);
2363 plstrWindowName
= &lstrWindowName
;
2366 /* Check if the class is an atom */
2367 if (IS_ATOM(plstrClassName
))
2369 /* It is, pass the atom in the UNICODE_STRING */
2370 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2371 ustrClassName
.Length
= 0;
2372 ustrClassName
.MaximumLength
= 0;
2376 /* It's not, capture the class name */
2377 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2378 if (!NT_SUCCESS(Status
))
2380 DPRINT1("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2381 /* Set last error, cleanup and return */
2382 SetLastNtError(Status
);
2386 /* We pass it on as a UNICODE_STRING */
2387 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2388 ustrClassName
.Length
= lstrClassName
.Length
;
2389 ustrClassName
.MaximumLength
= lstrClassName
.MaximumLength
;
2392 /* Fill the CREATESTRUCTW */
2393 /* we will keep here the original parameters */
2395 Cs
.lpCreateParams
= lpParam
;
2396 Cs
.hInstance
= hInstance
;
2398 Cs
.hwndParent
= hWndParent
;
2403 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2404 if (IS_ATOM(plstrClassName
))
2405 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2407 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2408 Cs
.dwExStyle
= dwExStyle
;
2410 UserEnterExclusive();
2412 /* Call the internal function */
2413 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
);
2417 DPRINT1("co_UserCreateWindowEx failed!\n");
2419 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2424 if (lstrWindowName
.Buffer
)
2426 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2428 if (lstrClassName
.Buffer
)
2430 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2437 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2443 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2445 hWnd
= Window
->head
.h
;
2447 DPRINT("co_UserDestroyWindow \n");
2449 /* Check for owner thread */
2450 if ( (Window
->head
.pti
->pEThread
!= PsGetCurrentThread()) ||
2451 Window
->head
.pti
!= PsGetCurrentThreadWin32Thread() )
2453 EngSetLastError(ERROR_ACCESS_DENIED
);
2457 /* If window was created successfully and it is hooked */
2458 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2460 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2462 DPRINT1("Destroy Window WH_CBT Call Hook return!\n");
2467 /* Inform the parent */
2468 if (Window
->style
& WS_CHILD
)
2470 IntSendParentNotify(Window
, WM_DESTROY
);
2473 /* Look whether the focus is within the tree of windows we will
2476 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2478 if (UserGetActiveWindow() == Window
->head
.h
)
2480 co_WinPosActivateOtherWindow(Window
);
2484 if (Window
->head
.pti
->MessageQueue
->ActiveWindow
== Window
->head
.h
)
2485 Window
->head
.pti
->MessageQueue
->ActiveWindow
= NULL
;
2486 if (Window
->head
.pti
->MessageQueue
->FocusWindow
== Window
->head
.h
)
2487 Window
->head
.pti
->MessageQueue
->FocusWindow
= NULL
;
2488 if (Window
->head
.pti
->MessageQueue
->CaptureWindow
== Window
->head
.h
)
2489 Window
->head
.pti
->MessageQueue
->CaptureWindow
= NULL
;
2492 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2495 ti
= PsGetCurrentThreadWin32Thread();
2497 if ((ti
!= NULL
) & (ti
->pDeskInfo
!= NULL
))
2499 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2501 DPRINT1("Destroying the ShellWindow!\n");
2502 ti
->pDeskInfo
->hShellWindow
= NULL
;
2506 IntDereferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
2508 IntEngWindowChanged(Window
, WOC_DELETE
);
2510 if (!IntIsWindow(Window
->head
.h
))
2515 /* Recursively destroy owned windows */
2517 if (! (Window
->style
& WS_CHILD
))
2521 BOOL GotOne
= FALSE
;
2524 PWND Child
, Desktop
;
2526 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2527 UserGetWindowObject(IntGetDesktopWindow());
2528 Children
= IntWinListChildren(Desktop
);
2532 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2534 Child
= UserGetWindowObject(*ChildHandle
);
2537 if (Child
->spwndOwner
!= Window
)
2542 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2544 USER_REFERENCE_ENTRY ChildRef
;
2545 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2546 co_UserDestroyWindow(Child
);
2547 UserDerefObjectCo(Child
);//temp hack?
2553 if (Child
->spwndOwner
!= NULL
)
2555 Child
->spwndOwner
= NULL
;
2559 ExFreePool(Children
);
2568 /* Generate mouse move message for the next window */
2569 msg
.message
= WM_MOUSEMOVE
;
2570 msg
.wParam
= IntGetSysCursorInfo()->ButtonsDown
;
2571 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2572 msg
.pt
= gpsi
->ptCursor
;
2573 co_MsqInsertMouseMessage(&msg
);
2575 if (!IntIsWindow(Window
->head
.h
))
2580 /* Destroy the window storage */
2581 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2591 NtUserDestroyWindow(HWND Wnd
)
2594 DECLARE_RETURN(BOOLEAN
);
2596 USER_REFERENCE_ENTRY Ref
;
2598 DPRINT("Enter NtUserDestroyWindow\n");
2599 UserEnterExclusive();
2601 if (!(Window
= UserGetWindowObject(Wnd
)))
2606 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2607 ret
= co_UserDestroyWindow(Window
);
2608 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2613 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2619 static HWND FASTCALL
2620 IntFindWindow(PWND Parent
,
2623 PUNICODE_STRING WindowName
)
2625 BOOL CheckWindowName
;
2628 UNICODE_STRING CurrentWindowName
;
2632 CheckWindowName
= WindowName
->Length
!= 0;
2634 if((List
= IntWinListChildren(Parent
)))
2639 /* skip handles before and including ChildAfter */
2640 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2644 /* search children */
2648 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2653 /* Do not send WM_GETTEXT messages in the kernel mode version!
2654 The user mode version however calls GetWindowText() which will
2655 send WM_GETTEXT messages to windows belonging to its processes */
2656 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2658 // HACK: use UNICODE_STRING instead of LARGE_STRING
2659 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2660 CurrentWindowName
.Length
= Child
->strName
.Length
;
2661 CurrentWindowName
.MaximumLength
= Child
->strName
.MaximumLength
;
2662 if(!CheckWindowName
||
2663 (Child
->strName
.Length
< 0xFFFF &&
2664 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2666 Ret
= Child
->head
.h
;
2679 * Searches a window's children for a window with the specified
2682 * hwndParent = The window whose childs are to be searched.
2684 * HWND_MESSAGE = message-only windows
2686 * hwndChildAfter = Search starts after this child window.
2687 * NULL = start from beginning
2689 * ucClassName = Class name to search for
2690 * Reguired parameter.
2692 * ucWindowName = Window name
2693 * ->Buffer == NULL = don't care
2696 * The HWND of the window if it was found, otherwise NULL
2702 NtUserFindWindowEx(HWND hwndParent
,
2703 HWND hwndChildAfter
,
2704 PUNICODE_STRING ucClassName
,
2705 PUNICODE_STRING ucWindowName
,
2708 PWND Parent
, ChildAfter
;
2709 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2710 HWND Desktop
, Ret
= NULL
;
2711 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2712 DECLARE_RETURN(HWND
);
2714 DPRINT("Enter NtUserFindWindowEx\n");
2717 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2721 if (ucClassName
!= NULL
)
2723 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2724 if (ClassName
.Length
!= 0)
2726 ProbeForRead(ClassName
.Buffer
,
2730 else if (!IS_ATOM(ClassName
.Buffer
))
2732 EngSetLastError(ERROR_INVALID_PARAMETER
);
2736 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2743 if (ucWindowName
!= NULL
)
2745 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2746 if (WindowName
.Length
!= 0)
2748 ProbeForRead(WindowName
.Buffer
,
2754 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2756 SetLastNtError(_SEH2_GetExceptionCode());
2757 _SEH2_YIELD(RETURN(NULL
));
2761 if (ucClassName
!= NULL
)
2763 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2764 !IS_ATOM(ClassName
.Buffer
))
2766 EngSetLastError(ERROR_INVALID_PARAMETER
);
2769 else if (ClassAtom
== (RTL_ATOM
)0)
2771 /* LastError code was set by IntGetAtomFromStringOrAtom */
2777 Desktop
= IntGetCurrentThreadDesktopWindow();
2779 if(hwndParent
== NULL
)
2780 hwndParent
= Desktop
;
2781 else if(hwndParent
== HWND_MESSAGE
)
2783 hwndParent
= IntGetMessageWindow();
2786 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2792 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2799 if(Parent
->head
.h
== Desktop
)
2802 PWND TopLevelWindow
;
2803 BOOLEAN CheckWindowName
;
2804 BOOLEAN WindowMatches
;
2805 BOOLEAN ClassMatches
;
2807 /* windows searches through all top-level windows if the parent is the desktop
2810 if((List
= IntWinListChildren(Parent
)))
2816 /* skip handles before and including ChildAfter */
2817 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2821 CheckWindowName
= WindowName
.Length
!= 0;
2823 /* search children */
2826 UNICODE_STRING ustr
;
2828 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2833 /* Do not send WM_GETTEXT messages in the kernel mode version!
2834 The user mode version however calls GetWindowText() which will
2835 send WM_GETTEXT messages to windows belonging to its processes */
2836 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2837 ustr
.Length
= TopLevelWindow
->strName
.Length
;
2838 ustr
.MaximumLength
= TopLevelWindow
->strName
.MaximumLength
;
2839 WindowMatches
= !CheckWindowName
||
2840 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2841 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2842 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2843 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2845 if (WindowMatches
&& ClassMatches
)
2847 Ret
= TopLevelWindow
->head
.h
;
2851 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2853 /* window returns the handle of the top-level window, in case it found
2855 Ret
= TopLevelWindow
->head
.h
;
2864 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2868 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2870 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2871 search the message-only windows. Should this also be done if
2872 Parent is the desktop window??? */
2875 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2877 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2882 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2884 SetLastNtError(_SEH2_GetExceptionCode());
2892 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2901 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
2903 PWND WndAncestor
, Parent
;
2905 if (Wnd
->head
.h
== IntGetDesktopWindow())
2914 WndAncestor
= Wnd
->spwndParent
;
2925 if(!(Parent
= WndAncestor
->spwndParent
))
2929 if(IntIsDesktopWindow(Parent
))
2934 WndAncestor
= Parent
;
2947 Parent
= IntGetParent(WndAncestor
);
2954 WndAncestor
= Parent
;
2972 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2974 PWND Window
, Ancestor
;
2975 DECLARE_RETURN(HWND
);
2977 DPRINT("Enter NtUserGetAncestor\n");
2978 UserEnterExclusive();
2980 if (!(Window
= UserGetWindowObject(hWnd
)))
2985 Ancestor
= UserGetAncestor(Window
, Type
);
2986 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
2988 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
2991 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
2999 NtUserGetComboBoxInfo(
3004 DECLARE_RETURN(BOOL
);
3006 DPRINT("Enter NtUserGetComboBoxInfo\n");
3009 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3018 sizeof(COMBOBOXINFO
),
3022 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3024 SetLastNtError(_SEH2_GetExceptionCode());
3025 _SEH2_YIELD(RETURN(FALSE
));
3029 // Pass the user pointer, it was already probed.
3030 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3033 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3043 NtUserGetInternalWindowPos( HWND hWnd
,
3050 WINDOWPLACEMENT wndpl
;
3054 if (!(Window
= UserGetWindowObject(hWnd
)))
3064 ProbeForWrite(rectWnd
,
3070 ProbeForWrite(ptIcon
,
3076 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3078 SetLastNtError(_SEH2_GetExceptionCode());
3083 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3085 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3091 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3095 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3099 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3101 SetLastNtError(_SEH2_GetExceptionCode());
3106 if (!Hit
) Ret
= wndpl
.showCmd
;
3115 NtUserGetListBoxInfo(
3119 DECLARE_RETURN(DWORD
);
3121 DPRINT("Enter NtUserGetListBoxInfo\n");
3124 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3129 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3132 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3140 * The NtUserSetParent function changes the parent window of the specified
3144 * The new parent window and the child window must belong to the same
3145 * application. If the window identified by the hWndChild parameter is
3146 * visible, the system performs the appropriate redrawing and repainting.
3147 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3148 * or WS_POPUP window styles of the window whose parent is being changed.
3155 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3157 DECLARE_RETURN(HWND
);
3159 DPRINT("Enter NtUserSetParent\n");
3160 UserEnterExclusive();
3163 Check Parent first from user space, set it here.
3167 hWndNewParent
= IntGetDesktopWindow();
3169 else if (hWndNewParent
== HWND_MESSAGE
)
3171 hWndNewParent
= IntGetMessageWindow();
3174 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3177 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3183 * UserGetShellWindow
3185 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3190 HWND FASTCALL
UserGetShellWindow(VOID
)
3192 PWINSTATION_OBJECT WinStaObject
;
3195 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3200 if (!NT_SUCCESS(Status
))
3202 SetLastNtError(Status
);
3206 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3208 ObDereferenceObject(WinStaObject
);
3213 * NtUserSetShellWindowEx
3215 * This is undocumented function to set global shell window. The global
3216 * shell window has special handling of window position.
3222 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3224 PWINSTATION_OBJECT WinStaObject
;
3225 PWND WndShell
, WndListView
;
3226 DECLARE_RETURN(BOOL
);
3227 USER_REFERENCE_ENTRY Ref
;
3231 DPRINT("Enter NtUserSetShellWindowEx\n");
3232 UserEnterExclusive();
3234 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3239 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3244 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3249 if (!NT_SUCCESS(Status
))
3251 SetLastNtError(Status
);
3256 * Test if we are permitted to change the shell window.
3258 if (WinStaObject
->ShellWindow
)
3260 ObDereferenceObject(WinStaObject
);
3265 * Move shell window into background.
3267 if (hwndListView
&& hwndListView
!= hwndShell
)
3270 * Disabled for now to get Explorer working.
3271 * -- Filip, 01/nov/2003
3274 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3277 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3279 ObDereferenceObject(WinStaObject
);
3284 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3286 ObDereferenceObject(WinStaObject
);
3290 UserRefObjectCo(WndShell
, &Ref
);
3291 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3293 WinStaObject
->ShellWindow
= hwndShell
;
3294 WinStaObject
->ShellListView
= hwndListView
;
3296 ti
= GetW32ThreadInfo();
3297 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3299 UserDerefObjectCo(WndShell
);
3301 ObDereferenceObject(WinStaObject
);
3305 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3311 * NtUserGetSystemMenu
3313 * The NtUserGetSystemMenu function allows the application to access the
3314 * window menu (also known as the system menu or the control menu) for
3315 * copying and modifying.
3319 * Handle to the window that will own a copy of the window menu.
3321 * Specifies the action to be taken. If this parameter is FALSE,
3322 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3323 * currently in use. The copy is initially identical to the window menu
3324 * but it can be modified.
3325 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3326 * to the default state. The previous window menu, if any, is destroyed.
3329 * If the bRevert parameter is FALSE, the return value is a handle to a
3330 * copy of the window menu. If the bRevert parameter is TRUE, the return
3338 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3342 DECLARE_RETURN(HMENU
);
3344 DPRINT("Enter NtUserGetSystemMenu\n");
3347 if (!(Window
= UserGetWindowObject(hWnd
)))
3352 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3357 RETURN(Menu
->MenuInfo
.Self
);
3360 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3366 * NtUserSetSystemMenu
3373 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3375 BOOL Result
= FALSE
;
3378 DECLARE_RETURN(BOOL
);
3380 DPRINT("Enter NtUserSetSystemMenu\n");
3381 UserEnterExclusive();
3383 if (!(Window
= UserGetWindowObject(hWnd
)))
3391 * Assign new menu handle.
3393 if (!(Menu
= UserGetMenuObject(hMenu
)))
3398 Result
= IntSetSystemMenu(Window
, Menu
);
3404 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3410 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3412 PWND Window
, Parent
;
3413 PWINSTATION_OBJECT WindowStation
;
3417 if (hWnd
== IntGetDesktopWindow())
3419 EngSetLastError(STATUS_ACCESS_DENIED
);
3423 if (!(Window
= UserGetWindowObject(hWnd
)))
3428 if ((INT
)Index
>= 0)
3430 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3432 EngSetLastError(ERROR_INVALID_INDEX
);
3436 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3438 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3440 OldValue = (LONG)IntSetWindowProc( Wnd,
3443 if (!OldValue) return 0;
3446 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3453 OldValue
= (LONG
) Window
->ExStyle
;
3454 Style
.styleOld
= OldValue
;
3455 Style
.styleNew
= NewValue
;
3458 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3460 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3463 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3464 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3467 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3468 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3469 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3473 OldValue
= (LONG
) Window
->style
;
3474 Style
.styleOld
= OldValue
;
3475 Style
.styleNew
= NewValue
;
3476 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3477 Window
->style
= (DWORD
)Style
.styleNew
;
3478 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3483 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3484 Window
->fnid
& FNID_FREED
)
3486 EngSetLastError(ERROR_ACCESS_DENIED
);
3489 OldValue
= (LONG
)IntSetWindowProc(Window
,
3496 OldValue
= (LONG
) Window
->hModule
;
3497 Window
->hModule
= (HINSTANCE
) NewValue
;
3500 case GWL_HWNDPARENT
:
3501 Parent
= Window
->spwndParent
;
3502 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3503 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3505 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3509 OldValue
= (LONG
) Window
->IDMenu
;
3510 Window
->IDMenu
= (UINT
) NewValue
;
3514 OldValue
= Window
->dwUserData
;
3515 Window
->dwUserData
= NewValue
;
3519 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3520 EngSetLastError(ERROR_INVALID_INDEX
);
3530 * NtUserSetWindowLong
3532 * The NtUserSetWindowLong function changes an attribute of the specified
3533 * window. The function also sets the 32-bit (long) value at the specified
3534 * offset into the extra window memory.
3541 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3543 DECLARE_RETURN(LONG
);
3545 DPRINT("Enter NtUserSetWindowLong\n");
3546 UserEnterExclusive();
3548 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3551 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3557 * NtUserSetWindowWord
3559 * Legacy function similar to NtUserSetWindowLong.
3566 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3570 DECLARE_RETURN(WORD
);
3572 DPRINT("Enter NtUserSetWindowWord\n");
3573 UserEnterExclusive();
3575 if (!(Window
= UserGetWindowObject(hWnd
)))
3584 case GWL_HWNDPARENT
:
3585 RETURN( co_UserSetWindowLong(Window
->head
.h
, Index
, (UINT
)NewValue
, TRUE
));
3589 EngSetLastError(ERROR_INVALID_INDEX
);
3594 if (Index
> Window
->cbwndExtra
- sizeof(WORD
))
3596 EngSetLastError(ERROR_INVALID_PARAMETER
);
3600 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3601 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3606 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3615 NtUserGetWindowPlacement(HWND hWnd
,
3616 WINDOWPLACEMENT
*lpwndpl
)
3620 WINDOWPLACEMENT Safepl
;
3622 DECLARE_RETURN(BOOL
);
3624 DPRINT("Enter NtUserGetWindowPlacement\n");
3627 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3632 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3633 if(!NT_SUCCESS(Status
))
3635 SetLastNtError(Status
);
3638 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3644 if (0 == (Wnd
->style
& WS_VISIBLE
))
3646 Safepl
.showCmd
= SW_HIDE
;
3648 else if ((0 != (Wnd
->state2
& WNDS2_MAXIMIZEBUTTONDOWN
) ||
3649 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
3650 0 == (Wnd
->style
& WS_MINIMIZE
))
3652 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
3654 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
3656 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
3658 else if (0 != (Wnd
->style
& WS_VISIBLE
))
3660 Safepl
.showCmd
= SW_SHOWNORMAL
;
3663 Size
.x
= Wnd
->rcWindow
.left
;
3664 Size
.y
= Wnd
->rcWindow
.top
;
3665 WinPosInitInternalPos(Wnd
, &Size
,
3668 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
3669 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
3670 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
3672 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3673 if(!NT_SUCCESS(Status
))
3675 SetLastNtError(Status
);
3682 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
3688 QueryWindow based on KJK::Hyperion and James Tabor.
3690 0 = QWUniqueProcessId
3691 1 = QWUniqueThreadId
3694 4 = QWIsHung Implements IsHungAppWindow found
3697 9 = QWKillWindow When I called this with hWnd ==
3698 DesktopWindow, it shutdown the system
3705 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3709 DECLARE_RETURN(UINT
);
3711 DPRINT("Enter NtUserQueryWindow\n");
3714 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3721 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3722 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3725 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3726 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3729 case QUERY_WINDOW_ACTIVE
:
3730 Result
= (DWORD
)UserGetActiveWindow();
3733 case QUERY_WINDOW_FOCUS
:
3734 Result
= (DWORD
)IntGetFocusWindow();
3737 case QUERY_WINDOW_ISHUNG
:
3738 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
->MessageQueue
);
3741 case QUERY_WINDOW_REAL_ID
:
3742 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3745 Result
= (DWORD
)NULL
;
3752 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3762 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3764 UNICODE_STRING SafeMessageName
;
3767 DECLARE_RETURN(UINT
);
3769 DPRINT("Enter NtUserRegisterWindowMessage\n");
3770 UserEnterExclusive();
3772 if(MessageNameUnsafe
== NULL
)
3774 EngSetLastError(ERROR_INVALID_PARAMETER
);
3778 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3779 if(!NT_SUCCESS(Status
))
3781 SetLastNtError(Status
);
3785 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3786 if (SafeMessageName
.Buffer
)
3787 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3791 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3808 DECLARE_RETURN(BOOL
);
3810 DPRINT("Enter NtUserSetMenu\n");
3811 UserEnterExclusive();
3813 if (!(Window
= UserGetWindowObject(hWnd
)))
3818 if (! IntSetMenu(Window
, Menu
, &Changed
))
3823 if (Changed
&& Repaint
)
3825 USER_REFERENCE_ENTRY Ref
;
3827 UserRefObjectCo(Window
, &Ref
);
3828 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3829 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3831 UserDerefObjectCo(Window
);
3837 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3847 NtUserSetWindowFNID(HWND hWnd
,
3851 DECLARE_RETURN(BOOL
);
3853 DPRINT("Enter NtUserSetWindowFNID\n");
3854 UserEnterExclusive();
3856 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3861 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3863 EngSetLastError(ERROR_ACCESS_DENIED
);
3867 // From user land we only set these.
3868 if (fnID
!= FNID_DESTROY
)
3869 { // Hacked so we can mark desktop~!
3870 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
3873 EngSetLastError(ERROR_INVALID_PARAMETER
);
3882 DPRINT("Leave NtUserSetWindowFNID\n");
3891 NtUserWindowFromPoint(LONG X
, LONG Y
)
3895 PWND DesktopWindow
= NULL
, Window
= NULL
;
3897 DECLARE_RETURN(HWND
);
3898 USER_REFERENCE_ENTRY Ref
;
3900 DPRINT("Enter NtUserWindowFromPoint\n");
3901 UserEnterExclusive();
3903 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
3910 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
3911 //its possible this referencing is useless, thou it shouldnt hurt...
3912 UserRefObjectCo(DesktopWindow
, &Ref
);
3914 pti
= PsGetCurrentThreadWin32Thread();
3915 Window
= co_WinPosWindowFromPoint(DesktopWindow
, &pt
, &hittest
);
3919 Ret
= Window
->head
.h
;
3928 if (Window
) UserDereferenceObject(Window
);
3929 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
3931 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
3941 * Undocumented function that is called from DefWindowProc to set
3948 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
3951 LARGE_STRING SafeText
;
3952 UNICODE_STRING UnicodeString
;
3955 DPRINT("Enter NtUserDefSetText\n");
3957 if (WindowText
!= NULL
)
3961 SafeText
= ProbeForReadLargeString(WindowText
);
3963 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3966 SetLastNtError(_SEH2_GetExceptionCode());
3976 UserEnterExclusive();
3978 if(!(Wnd
= UserGetWindowObject(hWnd
)))
3984 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
3985 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
3986 // Now we know what the bAnsi is for.
3987 RtlInitUnicodeString(&UnicodeString
, NULL
);
3988 if (SafeText
.Buffer
)
3993 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
3995 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
3996 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
3998 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4001 SetLastNtError(_SEH2_GetExceptionCode());
4004 if (!Ret
) goto Exit
;
4007 if (UnicodeString
.Length
!= 0)
4009 if (Wnd
->strName
.MaximumLength
> 0 &&
4010 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4012 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4014 Wnd
->strName
.Length
= UnicodeString
.Length
;
4015 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4016 RtlCopyMemory(Wnd
->strName
.Buffer
,
4017 UnicodeString
.Buffer
,
4018 UnicodeString
.Length
);
4023 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4024 buf
= Wnd
->strName
.Buffer
;
4025 Wnd
->strName
.Buffer
= NULL
;
4028 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4031 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4032 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4033 if (Wnd
->strName
.Buffer
!= NULL
)
4035 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4036 RtlCopyMemory(Wnd
->strName
.Buffer
,
4037 UnicodeString
.Buffer
,
4038 UnicodeString
.Length
);
4039 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4040 Wnd
->strName
.Length
= UnicodeString
.Length
;
4044 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4052 Wnd
->strName
.Length
= 0;
4053 if (Wnd
->strName
.Buffer
!= NULL
)
4054 Wnd
->strName
.Buffer
[0] = L
'\0';
4057 // HAX! FIXME! Windows does not do this in here!
4058 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4059 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4060 /* Send shell notifications */
4061 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4063 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4068 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4069 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4075 * NtUserInternalGetWindowText
4082 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4087 DECLARE_RETURN(INT
);
4089 DPRINT("Enter NtUserInternalGetWindowText\n");
4092 if(lpString
&& (nMaxCount
<= 1))
4094 EngSetLastError(ERROR_INVALID_PARAMETER
);
4098 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4103 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4106 const WCHAR Terminator
= L
'\0';
4108 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4110 Copy
= min(nMaxCount
- 1, Result
);
4113 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4114 if(!NT_SUCCESS(Status
))
4116 SetLastNtError(Status
);
4122 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4123 if(!NT_SUCCESS(Status
))
4125 SetLastNtError(Status
);
4135 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4143 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4149 // ASSERT(OwnerWnd);
4151 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
4156 while (win_array
[count
])
4158 while (--count
>= 0)
4160 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4162 if (pWnd
->spwndOwner
!= OwnerWnd
)
4167 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4169 /* In Windows, ShowOwnedPopups(TRUE) generates
4170 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4171 * regardless of the state of the owner
4173 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4179 if (pWnd
->style
& WS_VISIBLE
)
4181 /* In Windows, ShowOwnedPopups(FALSE) generates
4182 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4183 * regardless of the state of the owner
4185 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4191 ExFreePool( win_array
);
4196 * NtUserValidateHandleSecure
4204 NtUserValidateHandleSecure(
4212 PUSER_HANDLE_ENTRY entry
;
4213 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
4215 EngSetLastError(ERROR_INVALID_HANDLE
);
4218 uType
= entry
->type
;
4225 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
4231 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
4236 PACCELERATOR_TABLE Accel
;
4237 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
4242 PCURICON_OBJECT Cursor
;
4243 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
4249 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
4255 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
4261 return UserGetCallProcInfo( handle
, &Proc
);
4264 EngSetLastError(ERROR_INVALID_HANDLE
);
4268 { /* Is handle entry restricted? */