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 ******************************************************************/
15 DBG_DEFAULT_CHANNEL(UserWnd
);
17 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
19 /* HELPER FUNCTIONS ***********************************************************/
21 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
23 WORD Action
= LOWORD(wParam
);
24 WORD Flags
= HIWORD(wParam
);
26 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
28 EngSetLastError(ERROR_INVALID_PARAMETER
);
35 EngSetLastError(ERROR_INVALID_PARAMETER
);
39 if (Flags
& UISF_HIDEFOCUS
)
40 Wnd
->HideFocus
= TRUE
;
41 if (Flags
& UISF_HIDEACCEL
)
42 Wnd
->HideAccel
= TRUE
;
46 if (Flags
& UISF_HIDEFOCUS
)
47 Wnd
->HideFocus
= FALSE
;
48 if (Flags
& UISF_HIDEACCEL
)
49 Wnd
->HideAccel
= FALSE
;
56 PWND FASTCALL
IntGetWindowObject(HWND hWnd
)
60 if (!hWnd
) return NULL
;
62 Window
= UserGetWindowObject(hWnd
);
64 Window
->head
.cLockObj
++;
70 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
76 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
80 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
81 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
83 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
94 * The function determines whether the specified window handle identifies
99 * Handle to the window to test.
102 * If the window handle identifies an existing window, the return value
103 * is TRUE. If the window handle does not identify an existing window,
104 * the return value is FALSE.
108 IntIsWindow(HWND hWnd
)
112 if (!(Window
= UserGetWindowObject(hWnd
)))
120 IntGetParent(PWND Wnd
)
122 if (Wnd
->style
& WS_POPUP
)
124 return Wnd
->spwndOwner
;
126 else if (Wnd
->style
& WS_CHILD
)
128 return Wnd
->spwndParent
;
136 IntEnableWindow( HWND hWnd
, BOOL bEnable
)
142 if(!(pWnd
= UserGetWindowObject(hWnd
)))
147 /* check if updating is needed */
148 bIsDisabled
= (pWnd
->style
& WS_DISABLED
);
149 Update
= bIsDisabled
;
153 pWnd
->style
&= ~WS_DISABLED
;
157 Update
= !bIsDisabled
;
159 co_IntSendMessage( hWnd
, WM_CANCELMODE
, 0, 0);
161 /* Remove keyboard focus from that window if it had focus */
162 if (hWnd
== IntGetThreadFocusWindow())
164 co_UserSetFocus(NULL
);
166 pWnd
->style
|= WS_DISABLED
;
171 IntNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, pWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
172 co_IntSendMessage(hWnd
, WM_ENABLE
, (LPARAM
)bEnable
, 0);
174 // Return nonzero if it was disabled, or zero if it wasn't:
181 * Compile a list of all child window handles from given window.
184 * This function is similar to Wine WIN_ListChildren. The caller
185 * must free the returned list with ExFreePool.
189 IntWinListChildren(PWND Window
)
193 UINT Index
, NumChildren
= 0;
195 if (!Window
) return NULL
;
197 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
200 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
203 ERR("Failed to allocate memory for children array\n");
204 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
207 for (Child
= Window
->spwndChild
, Index
= 0;
209 Child
= Child
->spwndNext
, ++Index
)
210 List
[Index
] = Child
->head
.h
;
216 /***********************************************************************
219 static void IntSendDestroyMsg(HWND hWnd
)
227 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
229 if (hWnd
== info
.hwndCaret
)
236 Window
= UserGetWindowObject(hWnd
);
239 // USER_REFERENCE_ENTRY Ref;
240 // UserRefObjectCo(Window, &Ref);
242 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
244 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
247 // UserDerefObjectCo(Window);
250 /* The window could already be destroyed here */
253 * Send the WM_DESTROY to the window.
256 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
259 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
260 * make sure that the window still exists when we come back.
269 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
272 /* start from the end (FIXME: is this needed?) */
273 for (i
= 0; pWndArray
[i
]; i
++)
278 if (IsWindow( pWndArray
[i
] ))
279 WIN_SendDestroyMsg( pWndArray
[i
] );
281 HeapFree(GetProcessHeap(), 0, pWndArray
);
285 TRACE("destroyed itself while in WM_DESTROY!\n");
291 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
293 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
297 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
299 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
300 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
303 if (Wnd
->strName
.Buffer
!= NULL
)
305 Wnd
->strName
.Length
= 0;
306 Wnd
->strName
.MaximumLength
= 0;
307 DesktopHeapFree(Wnd
->head
.rpdesk
,
308 Wnd
->strName
.Buffer
);
309 Wnd
->strName
.Buffer
= NULL
;
312 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
313 // WindowObject->Wnd = NULL;
316 /***********************************************************************
319 * Destroy storage associated to a window. "Internals" p.358
321 * This is the "functional" DestroyWindows function ei. all stuff
322 * done in CreateWindow is undone here and not in DestroyWindow:-P
325 static LRESULT
co_UserFreeWindow(PWND Window
,
326 PPROCESSINFO ProcessData
,
327 PTHREADINFO ThreadData
,
328 BOOLEAN SendMessages
)
334 BOOLEAN BelongsToThreadData
;
338 if(Window
->state2
& WNDS2_INDESTROY
)
340 TRACE("Tried to call IntDestroyWindow() twice\n");
343 Window
->state2
|= WNDS2_INDESTROY
;
344 Window
->style
&= ~WS_VISIBLE
;
346 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
348 /* remove the window already at this point from the thread window list so we
349 don't get into trouble when destroying the thread windows while we're still
350 in IntDestroyWindow() */
351 RemoveEntryList(&Window
->ThreadListEntry
);
353 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
355 IntDeRegisterShellHookWindow(Window
->head
.h
);
359 /* Send destroy messages */
360 IntSendDestroyMsg(Window
->head
.h
);
363 /* free child windows */
364 Children
= IntWinListChildren(Window
);
367 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
369 if ((Child
= IntGetWindowObject(*ChildHandle
)))
371 if(!IntWndBelongsToThread(Child
, ThreadData
))
373 /* send WM_DESTROY messages to windows not belonging to the same thread */
374 IntSendDestroyMsg(Child
->head
.h
);
377 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
379 UserDereferenceObject(Child
);
382 ExFreePool(Children
);
388 * Clear the update region to make sure no WM_PAINT messages will be
389 * generated for this window while processing the WM_NCDESTROY.
391 co_UserRedrawWindow(Window
, NULL
, 0,
392 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
393 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
394 if(BelongsToThreadData
)
395 co_IntSendMessage(Window
->head
.h
, WM_NCDESTROY
, 0, 0);
398 DestroyTimersForWindow(ThreadData
, Window
);
400 /* Unregister hot keys */
401 UnregisterWindowHotKeys (Window
);
403 /* flush the message queue */
404 MsqRemoveWindowMessagesFromQueue(Window
);
406 IntDereferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
408 /* from now on no messages can be sent to this window anymore */
409 Window
->state
|= WNDS_DESTROYED
;
410 Window
->fnid
|= FNID_FREED
;
412 /* don't remove the WINDOWSTATUS_DESTROYING bit */
414 /* reset shell window handles */
415 if(ThreadData
->rpdesk
)
417 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
418 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
420 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
421 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
424 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
428 WinPosCheckInternalPos(Window
->head
.h
);
429 if (Window
->head
.h
== GetCapture())
434 /* free resources associated with the window */
435 TIMER_RemoveWindowTimers(Window
->head
.h
);
438 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
440 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
442 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
446 if(Window
->SystemMenu
447 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
449 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
450 Window
->SystemMenu
= (HMENU
)0;
453 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
456 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
457 CLASS_RemoveWindow(Window
->Class
);
460 IntUnlinkWindow(Window
);
462 UserReferenceObject(Window
);
463 UserDeleteObject(Window
->head
.h
, otWindow
);
465 IntDestroyScrollBars(Window
);
467 /* dereference the class */
468 IntDereferenceClass(Window
->pcls
,
469 Window
->head
.pti
->pDeskInfo
,
470 Window
->head
.pti
->ppi
);
475 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
476 GreDeleteObject(Window
->hrgnClip
);
477 Window
->hrgnClip
= NULL
;
480 // ASSERT(Window != NULL);
481 UserFreeWindowInfo(Window
->head
.pti
, Window
);
483 UserDereferenceObject(Window
);
485 IntClipboardFreeWindow(Window
);
491 IntGetWindowBorderMeasures(PWND Wnd
, UINT
*cx
, UINT
*cy
)
493 if(HAS_DLGFRAME(Wnd
->style
, Wnd
->ExStyle
) && !(Wnd
->style
& WS_MINIMIZE
))
495 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
496 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
500 if(HAS_THICKFRAME(Wnd
->style
, Wnd
->ExStyle
)&& !(Wnd
->style
& WS_MINIMIZE
))
502 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
503 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
505 else if(HAS_THINFRAME(Wnd
->style
, Wnd
->ExStyle
))
507 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
508 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
518 // Same as User32:IntGetWndProc.
521 IntGetWindowProc(PWND pWnd
,
526 WNDPROC gcpd
, Ret
= 0;
528 ASSERT(UserIsEnteredExclusive() == TRUE
);
532 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
534 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
536 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
539 Ret
= GETPFNCLIENTA(i
);
541 Ret
= GETPFNCLIENTW(i
);
547 if (Class
->fnid
== FNID_EDIT
)
548 Ret
= pWnd
->lpfnWndProc
;
551 Ret
= pWnd
->lpfnWndProc
;
553 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
557 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
558 Ret
= GETPFNCLIENTA(Class
->fnid
);
562 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
563 Ret
= GETPFNCLIENTW(Class
->fnid
);
566 if ( Ret
!= pWnd
->lpfnWndProc
)
569 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
572 gcpd
= (WNDPROC
)UserGetCPD(
574 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
577 return (gcpd
? gcpd
: Ret
);
581 IntSetWindowProc(PWND pWnd
,
586 PCALLPROCDATA CallProc
;
588 WNDPROC Ret
, chWndProc
= NULL
;
590 // Retrieve previous window proc.
591 Ret
= IntGetWindowProc(pWnd
, Ansi
);
595 if (IsCallProcHandle(NewWndProc
))
597 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, otCallProc
);
599 { // Reset new WndProc.
600 NewWndProc
= CallProc
->pfnClientPrevious
;
601 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
602 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
605 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
606 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
608 if (GETPFNCLIENTW(i
) == NewWndProc
)
610 chWndProc
= GETPFNSERVER(i
);
613 if (GETPFNCLIENTA(i
) == NewWndProc
)
615 chWndProc
= GETPFNSERVER(i
);
619 // If match, set/reset to Server Side and clear ansi.
622 pWnd
->lpfnWndProc
= chWndProc
;
623 pWnd
->Unicode
= TRUE
;
624 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
625 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
629 pWnd
->Unicode
= !Ansi
;
630 // Handle the state change in here.
632 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
634 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
636 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
637 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
639 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
641 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
645 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
646 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
650 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
651 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
654 // Now set the new window proc.
655 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
666 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
668 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
670 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
674 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
682 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
683 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Wnd
->head
.h
);
692 NewMenu
= IntGetMenuObject(Menu
);
697 IntReleaseMenuObject(OldMenu
);
699 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
702 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
704 /* Can't use the same menu for two windows */
707 IntReleaseMenuObject(OldMenu
);
709 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
715 Wnd
->IDMenu
= (UINT
) Menu
;
718 NewMenu
->MenuInfo
.Wnd
= Wnd
->head
.h
;
719 IntReleaseMenuObject(NewMenu
);
723 OldMenu
->MenuInfo
.Wnd
= NULL
;
724 IntReleaseMenuObject(OldMenu
);
731 /* INTERNAL ******************************************************************/
735 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
740 USER_REFERENCE_ENTRY Ref
;
741 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
743 while (!IsListEmpty(&WThread
->WindowListHead
))
745 Current
= WThread
->WindowListHead
.Flink
;
746 Wnd
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
748 TRACE("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
750 /* window removes itself from the list */
753 fixme: it is critical that the window removes itself! if now, we will loop
757 //ASSERT(co_UserDestroyWindow(Wnd));
759 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
760 if (!co_UserDestroyWindow(Wnd
))
762 ERR("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
764 UserDerefObjectCo(Wnd
);//faxme: temp hack??
772 * Returns client window rectangle relative to the upper-left corner of client area.
774 * \note Does not check the validity of the parameters
777 IntGetClientRect(PWND Window
, RECTL
*Rect
)
782 Rect
->left
= Rect
->top
= 0;
783 Rect
->right
= Window
->rcClient
.right
- Window
->rcClient
.left
;
784 Rect
->bottom
= Window
->rcClient
.bottom
- Window
->rcClient
.top
;
788 PMENU_OBJECT FASTCALL
789 IntGetSystemMenu(PWND Window
, BOOL bRevert
, BOOL RetMenu
)
791 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
792 PTHREADINFO W32Thread
;
793 HMENU hNewMenu
, hSysMenu
;
794 ROSMENUITEMINFO ItemInfo
;
798 W32Thread
= PsGetCurrentThreadWin32Thread();
800 if(!W32Thread
->rpdesk
)
803 if(Window
->SystemMenu
)
805 Menu
= UserGetMenuObject(Window
->SystemMenu
);
808 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
809 Window
->SystemMenu
= (HMENU
)0;
813 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
815 /* clone system menu */
816 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
820 NewMenu
= IntCloneMenu(Menu
);
823 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
824 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
825 NewMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
827 //IntReleaseMenuObject(NewMenu);
832 hSysMenu
= UserCreateMenu(FALSE
);
833 if (NULL
== hSysMenu
)
837 SysMenu
= IntGetMenuObject(hSysMenu
);
840 UserDestroyMenu(hSysMenu
);
843 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
844 SysMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
845 hNewMenu
= co_IntLoadSysMenuTemplate();
848 IntReleaseMenuObject(SysMenu
);
849 UserDestroyMenu(hSysMenu
);
852 Menu
= IntGetMenuObject(hNewMenu
);
855 IntReleaseMenuObject(SysMenu
);
856 UserDestroyMenu(hSysMenu
);
860 NewMenu
= IntCloneMenu(Menu
);
863 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
864 IntReleaseMenuObject(NewMenu
);
865 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
867 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
868 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
869 ItemInfo
.fType
= MF_POPUP
;
870 ItemInfo
.fState
= MFS_ENABLED
;
871 ItemInfo
.dwTypeData
= NULL
;
873 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
874 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
876 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
880 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
889 if(Window
->SystemMenu
)
890 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
898 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
903 while (Window
&& ((Window
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
905 if (Window
== Parent
)
910 Window
= Window
->spwndParent
;
917 link the window into siblings list
918 children and parent are kept in place.
923 PWND WndInsertAfter
/* set to NULL if top sibling */
926 if ((Wnd
->spwndPrev
= WndInsertAfter
))
928 /* link after WndInsertAfter */
929 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
930 Wnd
->spwndNext
->spwndPrev
= Wnd
;
932 Wnd
->spwndPrev
->spwndNext
= Wnd
;
937 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
938 Wnd
->spwndNext
->spwndPrev
= Wnd
;
940 Wnd
->spwndParent
->spwndChild
= Wnd
;
945 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
947 if (hWndPrev
== HWND_NOTOPMOST
)
949 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
950 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
951 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
952 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
955 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
957 if (hWndPrev
== HWND_BOTTOM
)
959 /* Link in the bottom of the list */
962 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
963 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
964 WndInsertAfter
= WndInsertAfter
->spwndNext
;
966 IntLinkWindow(Wnd
, WndInsertAfter
);
967 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
969 else if (hWndPrev
== HWND_TOPMOST
)
971 /* Link in the top of the list */
972 IntLinkWindow(Wnd
, NULL
);
974 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
976 else if (hWndPrev
== HWND_TOP
)
978 /* Link it after the last topmost window */
979 PWND WndInsertBefore
;
981 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
983 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
985 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
987 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
988 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
990 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
993 WndInsertBefore
= WndInsertBefore
->spwndNext
;
997 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
1001 /* Link it after hWndPrev */
1002 PWND WndInsertAfter
;
1004 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1005 /* Are we called with an erroneous handle */
1006 if(WndInsertAfter
== NULL
)
1008 /* Link in a default position */
1009 IntLinkHwnd(Wnd
, HWND_TOP
);
1013 IntLinkWindow(Wnd
, WndInsertAfter
);
1015 /* Fix the WS_EX_TOPMOST flag */
1016 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1018 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1022 if(WndInsertAfter
->spwndNext
&&
1023 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1025 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1032 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1034 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1037 Wnd
= IntGetWindowObject(hWnd
);
1041 WndOldOwner
= Wnd
->spwndOwner
;
1043 ret
= WndOldOwner
? WndOldOwner
->head
.h
: 0;
1045 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1047 Wnd
->spwndOwner
= WndNewOwner
;
1051 Wnd
->spwndOwner
= NULL
;
1054 UserDereferenceObject(Wnd
);
1059 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1061 PWND WndOldParent
, pWndExam
;
1065 ASSERT(WndNewParent
);
1066 ASSERT_REFS_CO(Wnd
);
1067 ASSERT_REFS_CO(WndNewParent
);
1069 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1071 EngSetLastError(ERROR_ACCESS_DENIED
);
1075 /* Some applications try to set a child as a parent */
1076 if (IntIsChildWindow(Wnd
, WndNewParent
))
1078 EngSetLastError( ERROR_INVALID_PARAMETER
);
1082 pWndExam
= WndNewParent
; // Load parent Window to examine.
1083 // Now test for set parent to parent hit.
1086 if (Wnd
== pWndExam
)
1088 EngSetLastError(ERROR_INVALID_PARAMETER
);
1091 pWndExam
= pWndExam
->spwndParent
;
1095 * Windows hides the window first, then shows it again
1096 * including the WM_SHOWWINDOW messages and all
1098 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1100 /* Window must belong to current process */
1101 if (Wnd
->head
.pti
->pEThread
->ThreadsProcess
!= PsGetCurrentProcess())
1104 WndOldParent
= Wnd
->spwndParent
;
1106 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1108 if (WndNewParent
!= WndOldParent
)
1110 /* Unlink the window from the siblings list */
1111 IntUnlinkWindow(Wnd
);
1113 /* Set the new parent */
1114 Wnd
->spwndParent
= WndNewParent
;
1116 /* Link the window with its new siblings*/
1117 IntLinkHwnd(Wnd
, HWND_TOP
);
1121 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1123 * SetParent additionally needs to make hwnd the top window
1124 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1125 * WM_WINDOWPOSCHANGED notification messages.
1127 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1128 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1129 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1132 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1133 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1136 return WndOldParent
;
1140 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1142 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1143 HWND hWndOldParent
= NULL
;
1144 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1146 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1148 EngSetLastError(ERROR_INVALID_PARAMETER
);
1152 if (hWndChild
== IntGetDesktopWindow())
1154 EngSetLastError(ERROR_ACCESS_DENIED
);
1160 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1167 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1173 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1178 UserRefObjectCo(Wnd
, &Ref
);
1179 UserRefObjectCo(WndParent
, &ParentRef
);
1181 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1183 UserDerefObjectCo(WndParent
);
1184 UserDerefObjectCo(Wnd
);
1188 hWndOldParent
= WndOldParent
->head
.h
;
1189 UserDereferenceObject(WndOldParent
);
1192 return( hWndOldParent
);
1196 IntSetSystemMenu(PWND Window
, PMENU_OBJECT Menu
)
1198 PMENU_OBJECT OldMenu
;
1199 if(Window
->SystemMenu
)
1201 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1204 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1205 IntReleaseMenuObject(OldMenu
);
1211 /* FIXME check window style, propably return FALSE ? */
1212 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1213 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1216 Window
->SystemMenu
= (HMENU
)0;
1221 /* unlink the window from siblings. children and parent are kept in place. */
1223 IntUnlinkWindow(PWND Wnd
)
1226 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1229 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1231 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1232 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1234 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1239 IntGetWindowPlacement(PWND Wnd
, WINDOWPLACEMENT
*lpwndpl
)
1243 if (!Wnd
) return FALSE
;
1245 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1251 if (0 == (Wnd
->style
& WS_VISIBLE
))
1253 lpwndpl
->showCmd
= SW_HIDE
;
1255 else if (0 != (Wnd
->state2
& WNDS2_MAXIMIZEBUTTONDOWN
) ||
1256 0 != (Wnd
->style
& WS_MAXIMIZE
))
1258 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1260 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1262 lpwndpl
->showCmd
= SW_MINIMIZE
;
1264 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1266 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1269 Size
.x
= Wnd
->rcWindow
.left
;
1270 Size
.y
= Wnd
->rcWindow
.top
;
1271 WinPosInitInternalPos(Wnd
, &Size
,
1274 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1275 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1276 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1282 /* FUNCTIONS *****************************************************************/
1285 * As best as I can figure, this function is used by EnumWindows,
1286 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1288 * It's supposed to build a list of HWNDs to return to the caller.
1289 * We can figure out what kind of list by what parameters are
1297 NtUserBuildHwndList(
1310 return ERROR_INVALID_PARAMETER
;
1312 if (hwndParent
|| !dwThreadId
)
1315 PWND Parent
, Window
;
1319 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1321 return ERROR_INVALID_HANDLE
;
1326 Status
= IntValidateDesktopHandle(hDesktop
,
1330 if(!NT_SUCCESS(Status
))
1332 return ERROR_INVALID_HANDLE
;
1335 hwndParent
= Desktop
->DesktopWindow
;
1342 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1343 (Window
= Parent
->spwndChild
))
1345 BOOL bGoDown
= TRUE
;
1347 Status
= STATUS_SUCCESS
;
1352 if(dwCount
++ < *pBufSize
&& pWnd
)
1356 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1357 *pWnd
= Window
->head
.h
;
1360 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1362 Status
= _SEH2_GetExceptionCode();
1365 if(!NT_SUCCESS(Status
))
1367 SetLastNtError(Status
);
1371 if (Window
->spwndChild
&& bChildren
)
1373 Window
= Window
->spwndChild
;
1378 if (Window
->spwndNext
)
1380 Window
= Window
->spwndNext
;
1384 Window
= Window
->spwndParent
;
1385 if (Window
== Parent
)
1394 ObDereferenceObject(Desktop
);
1397 else // Build EnumThreadWindows list!
1400 PTHREADINFO W32Thread
;
1401 PLIST_ENTRY Current
;
1404 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1405 if (!NT_SUCCESS(Status
))
1407 ERR("Thread Id is not valid!\n");
1408 return ERROR_INVALID_PARAMETER
;
1410 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1412 ObDereferenceObject(Thread
);
1413 ERR("Thread is not initialized!\n");
1414 return ERROR_INVALID_PARAMETER
;
1417 Current
= W32Thread
->WindowListHead
.Flink
;
1418 while (Current
!= &(W32Thread
->WindowListHead
))
1420 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1423 if (dwCount
< *pBufSize
&& pWnd
)
1427 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1428 *pWnd
= Window
->head
.h
;
1431 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1433 Status
= _SEH2_GetExceptionCode();
1436 if (!NT_SUCCESS(Status
))
1438 ERR("Failure to build window list!\n");
1439 SetLastNtError(Status
);
1444 Current
= Window
->ThreadListEntry
.Flink
;
1447 ObDereferenceObject(Thread
);
1450 *pBufSize
= dwCount
;
1451 return STATUS_SUCCESS
;
1454 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1456 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1457 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1459 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1461 USER_REFERENCE_ENTRY Ref
;
1462 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1463 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1465 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1466 (LPARAM
)pWindow
->head
.h
);
1467 UserDerefObjectCo(pWindow
->spwndParent
);
1473 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1475 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1477 /* default positioning for overlapped windows */
1478 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1481 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1483 pMonitor
= IntGetPrimaryMonitor();
1485 /* Check if we don't have a monitor attached yet */
1486 if(pMonitor
== NULL
)
1494 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1496 if (IS_DEFAULT(Cs
->x
))
1498 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1500 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1502 Cs
->x
= ProcessParams
->StartingX
;
1503 Cs
->y
= ProcessParams
->StartingY
;
1507 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1508 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1509 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1510 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1512 /* reset counter and position */
1515 pMonitor
->cWndStack
= 0;
1517 pMonitor
->cWndStack
++;
1521 if (IS_DEFAULT(Cs
->cx
))
1523 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1525 Cs
->cx
= ProcessParams
->CountX
;
1526 Cs
->cy
= ProcessParams
->CountY
;
1530 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1531 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1534 /* neither x nor cx are default. Check the y values .
1535 * In the trace we see Outlook and Outlook Express using
1536 * cy set to CW_USEDEFAULT when opening the address book.
1538 else if (IS_DEFAULT(Cs
->cy
))
1540 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1541 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1546 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1547 if(IS_DEFAULT(Cs
->x
))
1552 if(IS_DEFAULT(Cs
->cx
))
1562 /* Allocates and initializes a window*/
1563 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1564 PLARGE_STRING WindowName
,
1571 PTHREADINFO pti
= NULL
;
1572 PMENU_OBJECT SystemMenu
;
1574 BOOL bUnicodeWindow
;
1576 pti
= PsGetCurrentThreadWin32Thread();
1578 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1582 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1583 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1584 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1585 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1589 Note from MSDN http://msdn.microsoft.com/en-us/library/aa913269.aspx :
1591 Dialog boxes and message boxes do not inherit layout, so you must
1592 set the layout explicitly.
1594 if ( Class
&& Class
->fnid
!= FNID_DIALOG
)
1596 PPROCESSINFO ppi
= PsGetCurrentProcessWin32Process();
1597 if (ppi
->dwLayout
& LAYOUT_RTL
)
1599 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1605 /* Automatically add WS_EX_WINDOWEDGE */
1606 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1607 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1608 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1609 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1611 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1613 /* Is it a unicode window? */
1614 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1615 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1617 /* Allocate the new window */
1618 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1622 sizeof(WND
) + Class
->cbwndExtra
);
1629 TRACE("Created object with handle %X\n", hWnd
);
1631 if (NULL
== pti
->rpdesk
->DesktopWindow
)
1632 { /*HACK! Helper for win32csr/desktopbg.c */
1633 /* If there is no desktop window yet, we must be creating it */
1634 pti
->rpdesk
->DesktopWindow
= hWnd
;
1635 pti
->rpdesk
->pDeskInfo
->spwnd
= pWnd
;
1639 * Fill out the structure describing it.
1641 /* Remember, pWnd->head is setup in object.c ...*/
1642 pWnd
->spwndParent
= ParentWindow
;
1643 pWnd
->spwndOwner
= OwnerWindow
;
1645 pWnd
->hWndLastActive
= hWnd
;
1646 pWnd
->state2
|= WNDS2_WIN40COMPAT
;
1648 pWnd
->hModule
= Cs
->hInstance
;
1649 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1650 pWnd
->ExStyle
= Cs
->dwExStyle
;
1651 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1653 IntReferenceMessageQueue(pWnd
->head
.pti
->MessageQueue
);
1654 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1656 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1657 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1660 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1661 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1663 /* BugBoy Comments: Comment below say that System classes are always created
1664 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1665 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1667 No where can I see in code or through testing does the window change back
1668 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1669 see what problems this would cause.*/
1671 // Set WndProc from Class.
1672 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1674 // GetWindowProc, test for non server side default classes and set WndProc.
1675 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1679 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1680 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1684 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1685 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1689 // If not an Unicode caller, set Ansi creator bit.
1690 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1692 // Clone Class Ansi/Unicode proc type.
1693 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1695 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1696 pWnd
->Unicode
= FALSE
;
1700 It seems there can be both an Ansi creator and Unicode Class Window
1701 WndProc, unless the following overriding conditions occur:
1703 if ( !bUnicodeWindow
&&
1704 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1705 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1706 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1707 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1708 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1709 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1710 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1711 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1712 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1713 { // Override Class and set the window Ansi WndProc.
1714 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1715 pWnd
->Unicode
= FALSE
;
1718 { // Set the window Unicode WndProc.
1719 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1720 pWnd
->Unicode
= TRUE
;
1724 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1725 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1726 Dont understand why it does this. */
1727 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1729 PCALLPROCDATA CallProc
;
1730 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1734 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1735 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
1739 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1743 InitializeListHead(&pWnd
->PropListHead
);
1745 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1747 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1748 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1749 if (pWnd
->strName
.Buffer
== NULL
)
1754 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1755 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1756 pWnd
->strName
.Length
= WindowName
->Length
;
1757 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1760 /* Correct the window style. */
1761 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1763 pWnd
->style
|= WS_CLIPSIBLINGS
;
1764 if (!(pWnd
->style
& WS_POPUP
))
1766 pWnd
->style
|= WS_CAPTION
;
1767 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1771 if ((pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
) ||
1772 (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
1773 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1775 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1777 /* create system menu */
1778 if((Cs
->style
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1780 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1783 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1784 IntReleaseMenuObject(SystemMenu
);
1788 /* Set the window menu */
1789 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1792 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1793 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1795 UNICODE_STRING MenuName
;
1798 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1800 MenuName
.Length
= 0;
1801 MenuName
.MaximumLength
= 0;
1802 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1806 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1808 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1809 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1813 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1815 /* Insert the window into the thread's window list. */
1816 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1818 /* Handle "CS_CLASSDC", it is tested first. */
1819 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1820 { /* One DCE per class to have CLASS. */
1821 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1823 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1824 { /* Allocate a DCE for this window. */
1825 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1831 ERR("IntCreateWindow Allocation Error.\n");
1833 UserDereferenceObject(pWnd
);
1835 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1843 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1844 PUNICODE_STRING ClassName
,
1845 PLARGE_STRING WindowName
)
1847 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1848 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1849 PWINSTATION_OBJECT WinSta
;
1853 CBT_CREATEWNDW
* pCbtCreate
;
1855 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1857 DWORD dwShowMode
= SW_SHOW
;
1858 CREATESTRUCTW
*pCsw
= NULL
;
1859 PVOID pszClass
= NULL
, pszName
= NULL
;
1862 /* Get the current window station and reference it */
1863 pti
= GetW32ThreadInfo();
1864 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1866 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1867 return NULL
; //There is nothing to cleanup
1869 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1870 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1875 /* Get the class and reference it*/
1876 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
);
1879 ERR("Failed to find class %wZ\n", ClassName
);
1883 /* Now find the parent and the owner window */
1884 hWndParent
= IntGetDesktopWindow();
1887 if (Cs
->hwndParent
== HWND_MESSAGE
)
1889 Cs
->hwndParent
= hWndParent
= IntGetMessageWindow();
1891 else if (Cs
->hwndParent
)
1893 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1894 hWndOwner
= Cs
->hwndParent
;
1896 hWndParent
= Cs
->hwndParent
;
1898 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1900 ERR("Cannot create a child window without a parrent!\n");
1901 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1902 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1905 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1906 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1908 /* FIXME: is this correct?*/
1910 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
1912 /* Fix the position and the size of the window */
1915 UserRefObjectCo(ParentWindow
, &ParentRef
);
1916 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
1919 /* Allocate and initialize the new window */
1920 Window
= IntCreateWindow(Cs
,
1927 ERR("IntCreateWindow failed!\n");
1931 hWnd
= UserHMGetHandle(Window
);
1932 hwndInsertAfter
= HWND_TOP
;
1934 UserRefObjectCo(Window
, &Ref
);
1935 UserDereferenceObject(Window
);
1936 ObDereferenceObject(WinSta
);
1938 //// Check for a hook to eliminate overhead. ////
1939 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
1941 // Allocate the calling structures Justin Case this goes Global.
1942 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
1943 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
1944 if (!pCsw
|| !pCbtCreate
)
1946 ERR("UserHeapAlloc() failed!\n");
1950 /* Fill the new CREATESTRUCTW */
1951 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
1952 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
1954 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
1955 if (!IS_ATOM(ClassName
->Buffer
))
1957 if (Window
->state
& WNDS_ANSICREATOR
)
1959 ANSI_STRING AnsiString
;
1960 AnsiString
.MaximumLength
= RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
1961 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
1964 ERR("UserHeapAlloc() failed!\n");
1967 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
1968 AnsiString
.Buffer
= (PCHAR
)pszClass
;
1969 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
1973 UNICODE_STRING UnicodeString
;
1974 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
1975 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
1978 ERR("UserHeapAlloc() failed!\n");
1981 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
1982 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
1983 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
1985 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
1987 if (WindowName
->Length
)
1989 UNICODE_STRING Name
;
1990 Name
.Buffer
= WindowName
->Buffer
;
1991 Name
.Length
= WindowName
->Length
;
1992 Name
.MaximumLength
= WindowName
->MaximumLength
;
1994 if (Window
->state
& WNDS_ANSICREATOR
)
1996 ANSI_STRING AnsiString
;
1997 AnsiString
.MaximumLength
= RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
1998 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2001 ERR("UserHeapAlloc() failed!\n");
2004 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2005 AnsiString
.Buffer
= (PCHAR
)pszName
;
2006 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2010 UNICODE_STRING UnicodeString
;
2011 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2012 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2015 ERR("UserHeapAlloc() failed!\n");
2018 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2019 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2020 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2022 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2025 pCbtCreate
->lpcs
= pCsw
;
2026 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2028 //// Call the WH_CBT hook ////
2029 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2032 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2035 // Write back changes.
2040 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2043 /* NCCREATE and WM_NCCALCSIZE need the original values */
2044 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2045 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2047 /* Send the WM_GETMINMAXINFO message*/
2051 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2053 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2055 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2056 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2057 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2058 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2059 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2062 Window
->rcWindow
.left
= Cs
->x
;
2063 Window
->rcWindow
.top
= Cs
->y
;
2064 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2065 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2066 if (0 != (Window
->style
& WS_CHILD
) && ParentWindow
)
2068 RECTL_vOffsetRect(&Window
->rcWindow
,
2069 ParentWindow
->rcClient
.left
,
2070 ParentWindow
->rcClient
.top
);
2072 Window
->rcClient
= Window
->rcWindow
;
2074 /* Link the window*/
2075 if (NULL
!= ParentWindow
)
2077 /* link the window into the siblings list */
2078 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2079 IntLinkHwnd(Window
, HWND_BOTTOM
);
2081 IntLinkHwnd(Window
, hwndInsertAfter
);
2084 /* Send the NCCREATE message */
2085 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2088 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2092 /* Send the WM_NCCALCSIZE message */
2093 MaxPos
.x
= Window
->rcWindow
.left
;
2094 MaxPos
.y
= Window
->rcWindow
.top
;
2096 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2098 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2099 MaxPos
.y
- Window
->rcWindow
.top
);
2102 /* Send the WM_CREATE message. */
2103 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2104 if (Result
== (LRESULT
)-1)
2106 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2110 /* Send the EVENT_OBJECT_CREATE event*/
2111 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2113 /* By setting the flag below it can be examined to determine if the window
2114 was created successfully and a valid pwnd was passed back to caller since
2115 from here the function has to succeed. */
2116 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2118 /* Send the WM_SIZE and WM_MOVE messages. */
2119 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2121 co_WinPosSendSizeMove(Window
);
2124 /* Show or maybe minimize or maximize the window. */
2125 if (Window
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2130 SwFlag
= (Window
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2132 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2134 SwFlag
= ((Window
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2135 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2136 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2138 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2139 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2142 /* Send the WM_PARENTNOTIFY message */
2143 IntSendParentNotify(Window
, WM_CREATE
);
2145 /* Notify the shell that a new window was created */
2146 if ((!hWndParent
) && (!hWndOwner
))
2148 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2151 /* Initialize and show the window's scrollbars */
2152 if (Window
->style
& WS_VSCROLL
)
2154 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2156 if (Window
->style
& WS_HSCROLL
)
2158 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2161 /* Show the new window */
2162 if (Cs
->style
& WS_VISIBLE
)
2164 if (Window
->style
& WS_MAXIMIZE
)
2165 dwShowMode
= SW_SHOW
;
2166 else if (Window
->style
& WS_MINIMIZE
)
2167 dwShowMode
= SW_SHOWMINIMIZED
;
2169 co_WinPosShowWindow(Window
, dwShowMode
);
2171 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2173 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2174 /* ShowWindow won't activate child windows */
2175 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2179 TRACE("co_UserCreateWindowEx(): Created window %X\n", hWnd
);
2185 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2186 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2188 co_UserDestroyWindow(Window
);
2190 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2193 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2194 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2195 if (pszName
) UserHeapFree(pszName
);
2196 if (pszClass
) UserHeapFree(pszClass
);
2200 UserDerefObjectCo(Window
);
2202 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2209 ProbeAndCaptureLargeString(
2210 OUT PLARGE_STRING plstrSafe
,
2211 IN PLARGE_STRING plstrUnsafe
)
2213 LARGE_STRING lstrTemp
;
2214 PVOID pvBuffer
= NULL
;
2218 /* Probe and copy the string */
2219 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2220 lstrTemp
= *plstrUnsafe
;
2222 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2225 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2229 if (lstrTemp
.Length
!= 0)
2231 /* Allocate a buffer from paged pool */
2232 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2235 return STATUS_NO_MEMORY
;
2240 /* Probe and copy the buffer */
2241 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2242 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2244 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2246 /* Cleanup and fail */
2247 ExFreePool(pvBuffer
);
2248 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2253 /* Set the output string */
2254 plstrSafe
->Buffer
= pvBuffer
;
2255 plstrSafe
->Length
= lstrTemp
.Length
;
2256 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2258 return STATUS_SUCCESS
;
2262 * \todo Allow passing plstrClassName as ANSI.
2266 NtUserCreateWindowEx(
2268 PLARGE_STRING plstrClassName
,
2269 PLARGE_STRING plstrClsVersion
,
2270 PLARGE_STRING plstrWindowName
,
2278 HINSTANCE hInstance
,
2284 LARGE_STRING lstrWindowName
;
2285 LARGE_STRING lstrClassName
;
2286 UNICODE_STRING ustrClassName
;
2291 lstrWindowName
.Buffer
= NULL
;
2292 lstrClassName
.Buffer
= NULL
;
2294 /* Check if we got a Window name */
2295 if (plstrWindowName
)
2297 /* Copy the string to kernel mode */
2298 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2299 if (!NT_SUCCESS(Status
))
2301 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2302 SetLastNtError(Status
);
2305 plstrWindowName
= &lstrWindowName
;
2308 /* Check if the class is an atom */
2309 if (IS_ATOM(plstrClassName
))
2311 /* It is, pass the atom in the UNICODE_STRING */
2312 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2313 ustrClassName
.Length
= 0;
2314 ustrClassName
.MaximumLength
= 0;
2318 /* It's not, capture the class name */
2319 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2320 if (!NT_SUCCESS(Status
))
2322 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2323 /* Set last error, cleanup and return */
2324 SetLastNtError(Status
);
2328 /* We pass it on as a UNICODE_STRING */
2329 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2330 ustrClassName
.Length
= lstrClassName
.Length
;
2331 ustrClassName
.MaximumLength
= lstrClassName
.MaximumLength
;
2334 /* Fill the CREATESTRUCTW */
2335 /* we will keep here the original parameters */
2337 Cs
.lpCreateParams
= lpParam
;
2338 Cs
.hInstance
= hInstance
;
2340 Cs
.hwndParent
= hWndParent
;
2345 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2346 if (IS_ATOM(plstrClassName
))
2347 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2349 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2350 Cs
.dwExStyle
= dwExStyle
;
2352 UserEnterExclusive();
2354 /* Call the internal function */
2355 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
);
2359 ERR("co_UserCreateWindowEx failed!\n");
2361 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2366 if (lstrWindowName
.Buffer
)
2368 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2370 if (lstrClassName
.Buffer
)
2372 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2379 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2385 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2387 hWnd
= Window
->head
.h
;
2389 TRACE("co_UserDestroyWindow \n");
2391 /* Check for owner thread */
2392 if ( (Window
->head
.pti
->pEThread
!= PsGetCurrentThread()) ||
2393 Window
->head
.pti
!= PsGetCurrentThreadWin32Thread() )
2395 EngSetLastError(ERROR_ACCESS_DENIED
);
2399 /* If window was created successfully and it is hooked */
2400 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2402 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2404 ERR("Destroy Window WH_CBT Call Hook return!\n");
2409 /* Inform the parent */
2410 if (Window
->style
& WS_CHILD
)
2412 IntSendParentNotify(Window
, WM_DESTROY
);
2415 /* Look whether the focus is within the tree of windows we will
2418 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2420 if (UserGetActiveWindow() == Window
->head
.h
)
2422 co_WinPosActivateOtherWindow(Window
);
2426 if (Window
->head
.pti
->MessageQueue
->ActiveWindow
== Window
->head
.h
)
2427 Window
->head
.pti
->MessageQueue
->ActiveWindow
= NULL
;
2428 if (Window
->head
.pti
->MessageQueue
->FocusWindow
== Window
->head
.h
)
2429 Window
->head
.pti
->MessageQueue
->FocusWindow
= NULL
;
2430 if (Window
->head
.pti
->MessageQueue
->CaptureWindow
== Window
->head
.h
)
2431 Window
->head
.pti
->MessageQueue
->CaptureWindow
= NULL
;
2434 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2437 ti
= PsGetCurrentThreadWin32Thread();
2439 if ((ti
!= NULL
) & (ti
->pDeskInfo
!= NULL
))
2441 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2443 ERR("Destroying the ShellWindow!\n");
2444 ti
->pDeskInfo
->hShellWindow
= NULL
;
2448 IntEngWindowChanged(Window
, WOC_DELETE
);
2450 if (!IntIsWindow(Window
->head
.h
))
2455 /* Recursively destroy owned windows */
2457 if (! (Window
->style
& WS_CHILD
))
2461 BOOL GotOne
= FALSE
;
2464 PWND Child
, Desktop
;
2466 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2467 UserGetWindowObject(IntGetDesktopWindow());
2468 Children
= IntWinListChildren(Desktop
);
2472 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2474 Child
= UserGetWindowObject(*ChildHandle
);
2477 if (Child
->spwndOwner
!= Window
)
2482 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2484 USER_REFERENCE_ENTRY ChildRef
;
2485 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2486 co_UserDestroyWindow(Child
);
2487 UserDerefObjectCo(Child
);//temp hack?
2493 if (Child
->spwndOwner
!= NULL
)
2495 Child
->spwndOwner
= NULL
;
2499 ExFreePool(Children
);
2508 /* Generate mouse move message for the next window */
2509 msg
.message
= WM_MOUSEMOVE
;
2510 msg
.wParam
= IntGetSysCursorInfo()->ButtonsDown
;
2511 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2512 msg
.pt
= gpsi
->ptCursor
;
2513 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2515 if (!IntIsWindow(Window
->head
.h
))
2520 /* Destroy the window storage */
2521 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2531 NtUserDestroyWindow(HWND Wnd
)
2534 DECLARE_RETURN(BOOLEAN
);
2536 USER_REFERENCE_ENTRY Ref
;
2538 TRACE("Enter NtUserDestroyWindow\n");
2539 UserEnterExclusive();
2541 if (!(Window
= UserGetWindowObject(Wnd
)))
2546 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2547 ret
= co_UserDestroyWindow(Window
);
2548 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2553 TRACE("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2559 static HWND FASTCALL
2560 IntFindWindow(PWND Parent
,
2563 PUNICODE_STRING WindowName
)
2565 BOOL CheckWindowName
;
2568 UNICODE_STRING CurrentWindowName
;
2572 CheckWindowName
= WindowName
->Length
!= 0;
2574 if((List
= IntWinListChildren(Parent
)))
2579 /* skip handles before and including ChildAfter */
2580 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2584 /* search children */
2588 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2593 /* Do not send WM_GETTEXT messages in the kernel mode version!
2594 The user mode version however calls GetWindowText() which will
2595 send WM_GETTEXT messages to windows belonging to its processes */
2596 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2598 // HACK: use UNICODE_STRING instead of LARGE_STRING
2599 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2600 CurrentWindowName
.Length
= Child
->strName
.Length
;
2601 CurrentWindowName
.MaximumLength
= Child
->strName
.MaximumLength
;
2602 if(!CheckWindowName
||
2603 (Child
->strName
.Length
< 0xFFFF &&
2604 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2606 Ret
= Child
->head
.h
;
2619 * Searches a window's children for a window with the specified
2622 * hwndParent = The window whose childs are to be searched.
2624 * HWND_MESSAGE = message-only windows
2626 * hwndChildAfter = Search starts after this child window.
2627 * NULL = start from beginning
2629 * ucClassName = Class name to search for
2630 * Reguired parameter.
2632 * ucWindowName = Window name
2633 * ->Buffer == NULL = don't care
2636 * The HWND of the window if it was found, otherwise NULL
2642 NtUserFindWindowEx(HWND hwndParent
,
2643 HWND hwndChildAfter
,
2644 PUNICODE_STRING ucClassName
,
2645 PUNICODE_STRING ucWindowName
,
2648 PWND Parent
, ChildAfter
;
2649 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2650 HWND Desktop
, Ret
= NULL
;
2651 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2652 DECLARE_RETURN(HWND
);
2654 TRACE("Enter NtUserFindWindowEx\n");
2657 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2661 if (ucClassName
!= NULL
)
2663 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2664 if (ClassName
.Length
!= 0)
2666 ProbeForRead(ClassName
.Buffer
,
2670 else if (!IS_ATOM(ClassName
.Buffer
))
2672 EngSetLastError(ERROR_INVALID_PARAMETER
);
2676 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2683 if (ucWindowName
!= NULL
)
2685 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2686 if (WindowName
.Length
!= 0)
2688 ProbeForRead(WindowName
.Buffer
,
2694 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2696 SetLastNtError(_SEH2_GetExceptionCode());
2697 _SEH2_YIELD(RETURN(NULL
));
2701 if (ucClassName
!= NULL
)
2703 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2704 !IS_ATOM(ClassName
.Buffer
))
2706 EngSetLastError(ERROR_INVALID_PARAMETER
);
2709 else if (ClassAtom
== (RTL_ATOM
)0)
2711 /* LastError code was set by IntGetAtomFromStringOrAtom */
2717 Desktop
= IntGetCurrentThreadDesktopWindow();
2719 if(hwndParent
== NULL
)
2720 hwndParent
= Desktop
;
2721 else if(hwndParent
== HWND_MESSAGE
)
2723 hwndParent
= IntGetMessageWindow();
2726 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2732 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2739 if(Parent
->head
.h
== Desktop
)
2742 PWND TopLevelWindow
;
2743 BOOLEAN CheckWindowName
;
2744 BOOLEAN WindowMatches
;
2745 BOOLEAN ClassMatches
;
2747 /* windows searches through all top-level windows if the parent is the desktop
2750 if((List
= IntWinListChildren(Parent
)))
2756 /* skip handles before and including ChildAfter */
2757 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2761 CheckWindowName
= WindowName
.Length
!= 0;
2763 /* search children */
2766 UNICODE_STRING ustr
;
2768 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2773 /* Do not send WM_GETTEXT messages in the kernel mode version!
2774 The user mode version however calls GetWindowText() which will
2775 send WM_GETTEXT messages to windows belonging to its processes */
2776 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2777 ustr
.Length
= TopLevelWindow
->strName
.Length
;
2778 ustr
.MaximumLength
= TopLevelWindow
->strName
.MaximumLength
;
2779 WindowMatches
= !CheckWindowName
||
2780 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2781 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2782 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2783 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2785 if (WindowMatches
&& ClassMatches
)
2787 Ret
= TopLevelWindow
->head
.h
;
2791 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2793 /* window returns the handle of the top-level window, in case it found
2795 Ret
= TopLevelWindow
->head
.h
;
2804 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2808 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2810 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2811 search the message-only windows. Should this also be done if
2812 Parent is the desktop window??? */
2815 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2817 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2822 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2824 SetLastNtError(_SEH2_GetExceptionCode());
2832 TRACE("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2841 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
2843 PWND WndAncestor
, Parent
;
2845 if (Wnd
->head
.h
== IntGetDesktopWindow())
2854 WndAncestor
= Wnd
->spwndParent
;
2865 if(!(Parent
= WndAncestor
->spwndParent
))
2869 if(IntIsDesktopWindow(Parent
))
2874 WndAncestor
= Parent
;
2887 Parent
= IntGetParent(WndAncestor
);
2894 WndAncestor
= Parent
;
2912 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2914 PWND Window
, Ancestor
;
2915 DECLARE_RETURN(HWND
);
2917 TRACE("Enter NtUserGetAncestor\n");
2918 UserEnterExclusive();
2920 if (!(Window
= UserGetWindowObject(hWnd
)))
2925 Ancestor
= UserGetAncestor(Window
, Type
);
2926 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
2928 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
2931 TRACE("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
2939 NtUserGetComboBoxInfo(
2944 DECLARE_RETURN(BOOL
);
2946 TRACE("Enter NtUserGetComboBoxInfo\n");
2949 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2958 sizeof(COMBOBOXINFO
),
2962 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2964 SetLastNtError(_SEH2_GetExceptionCode());
2965 _SEH2_YIELD(RETURN(FALSE
));
2969 // Pass the user pointer, it was already probed.
2970 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
2973 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
2983 NtUserGetInternalWindowPos( HWND hWnd
,
2990 WINDOWPLACEMENT wndpl
;
2994 if (!(Window
= UserGetWindowObject(hWnd
)))
3004 ProbeForWrite(rectWnd
,
3010 ProbeForWrite(ptIcon
,
3016 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3018 SetLastNtError(_SEH2_GetExceptionCode());
3023 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3025 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3031 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3035 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3039 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3041 SetLastNtError(_SEH2_GetExceptionCode());
3046 if (!Hit
) Ret
= wndpl
.showCmd
;
3055 NtUserGetListBoxInfo(
3059 DECLARE_RETURN(DWORD
);
3061 TRACE("Enter NtUserGetListBoxInfo\n");
3064 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3069 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3072 TRACE("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3080 * The NtUserSetParent function changes the parent window of the specified
3084 * The new parent window and the child window must belong to the same
3085 * application. If the window identified by the hWndChild parameter is
3086 * visible, the system performs the appropriate redrawing and repainting.
3087 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3088 * or WS_POPUP window styles of the window whose parent is being changed.
3095 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3097 DECLARE_RETURN(HWND
);
3099 TRACE("Enter NtUserSetParent\n");
3100 UserEnterExclusive();
3103 Check Parent first from user space, set it here.
3107 hWndNewParent
= IntGetDesktopWindow();
3109 else if (hWndNewParent
== HWND_MESSAGE
)
3111 hWndNewParent
= IntGetMessageWindow();
3114 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3117 TRACE("Leave NtUserSetParent, ret=%i\n",_ret_
);
3123 * UserGetShellWindow
3125 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3130 HWND FASTCALL
UserGetShellWindow(VOID
)
3132 PWINSTATION_OBJECT WinStaObject
;
3135 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3140 if (!NT_SUCCESS(Status
))
3142 SetLastNtError(Status
);
3146 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3148 ObDereferenceObject(WinStaObject
);
3153 * NtUserSetShellWindowEx
3155 * This is undocumented function to set global shell window. The global
3156 * shell window has special handling of window position.
3162 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3164 PWINSTATION_OBJECT WinStaObject
;
3165 PWND WndShell
, WndListView
;
3166 DECLARE_RETURN(BOOL
);
3167 USER_REFERENCE_ENTRY Ref
;
3171 TRACE("Enter NtUserSetShellWindowEx\n");
3172 UserEnterExclusive();
3174 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3179 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3184 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3189 if (!NT_SUCCESS(Status
))
3191 SetLastNtError(Status
);
3196 * Test if we are permitted to change the shell window.
3198 if (WinStaObject
->ShellWindow
)
3200 ObDereferenceObject(WinStaObject
);
3205 * Move shell window into background.
3207 if (hwndListView
&& hwndListView
!= hwndShell
)
3210 * Disabled for now to get Explorer working.
3211 * -- Filip, 01/nov/2003
3214 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3217 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3219 ObDereferenceObject(WinStaObject
);
3224 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3226 ObDereferenceObject(WinStaObject
);
3230 UserRefObjectCo(WndShell
, &Ref
);
3231 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3233 WinStaObject
->ShellWindow
= hwndShell
;
3234 WinStaObject
->ShellListView
= hwndListView
;
3236 ti
= GetW32ThreadInfo();
3239 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3240 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3243 UserDerefObjectCo(WndShell
);
3245 ObDereferenceObject(WinStaObject
);
3249 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3255 * NtUserGetSystemMenu
3257 * The NtUserGetSystemMenu function allows the application to access the
3258 * window menu (also known as the system menu or the control menu) for
3259 * copying and modifying.
3263 * Handle to the window that will own a copy of the window menu.
3265 * Specifies the action to be taken. If this parameter is FALSE,
3266 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3267 * currently in use. The copy is initially identical to the window menu
3268 * but it can be modified.
3269 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3270 * to the default state. The previous window menu, if any, is destroyed.
3273 * If the bRevert parameter is FALSE, the return value is a handle to a
3274 * copy of the window menu. If the bRevert parameter is TRUE, the return
3282 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3286 DECLARE_RETURN(HMENU
);
3288 TRACE("Enter NtUserGetSystemMenu\n");
3291 if (!(Window
= UserGetWindowObject(hWnd
)))
3296 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3301 RETURN(Menu
->MenuInfo
.Self
);
3304 TRACE("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3310 * NtUserSetSystemMenu
3317 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3319 BOOL Result
= FALSE
;
3322 DECLARE_RETURN(BOOL
);
3324 TRACE("Enter NtUserSetSystemMenu\n");
3325 UserEnterExclusive();
3327 if (!(Window
= UserGetWindowObject(hWnd
)))
3335 * Assign new menu handle.
3337 if (!(Menu
= UserGetMenuObject(hMenu
)))
3342 Result
= IntSetSystemMenu(Window
, Menu
);
3348 TRACE("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3354 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3356 PWND Window
, Parent
;
3357 PWINSTATION_OBJECT WindowStation
;
3361 if (hWnd
== IntGetDesktopWindow())
3363 EngSetLastError(STATUS_ACCESS_DENIED
);
3367 if (!(Window
= UserGetWindowObject(hWnd
)))
3372 if ((INT
)Index
>= 0)
3374 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3376 EngSetLastError(ERROR_INVALID_INDEX
);
3380 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3382 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3384 OldValue = (LONG)IntSetWindowProc( Wnd,
3387 if (!OldValue) return 0;
3390 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3397 OldValue
= (LONG
) Window
->ExStyle
;
3398 Style
.styleOld
= OldValue
;
3399 Style
.styleNew
= NewValue
;
3402 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3404 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3407 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3408 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3411 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3412 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3413 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3417 OldValue
= (LONG
) Window
->style
;
3418 Style
.styleOld
= OldValue
;
3419 Style
.styleNew
= NewValue
;
3420 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3421 Window
->style
= (DWORD
)Style
.styleNew
;
3422 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3427 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3428 Window
->fnid
& FNID_FREED
)
3430 EngSetLastError(ERROR_ACCESS_DENIED
);
3433 OldValue
= (LONG
)IntSetWindowProc(Window
,
3440 OldValue
= (LONG
) Window
->hModule
;
3441 Window
->hModule
= (HINSTANCE
) NewValue
;
3444 case GWL_HWNDPARENT
:
3445 Parent
= Window
->spwndParent
;
3446 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3447 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3449 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3453 OldValue
= (LONG
) Window
->IDMenu
;
3454 Window
->IDMenu
= (UINT
) NewValue
;
3458 OldValue
= Window
->dwUserData
;
3459 Window
->dwUserData
= NewValue
;
3463 ERR("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3464 EngSetLastError(ERROR_INVALID_INDEX
);
3474 * NtUserSetWindowLong
3476 * The NtUserSetWindowLong function changes an attribute of the specified
3477 * window. The function also sets the 32-bit (long) value at the specified
3478 * offset into the extra window memory.
3485 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3487 DECLARE_RETURN(LONG
);
3489 TRACE("Enter NtUserSetWindowLong\n");
3490 UserEnterExclusive();
3492 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3495 TRACE("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3501 * NtUserSetWindowWord
3503 * Legacy function similar to NtUserSetWindowLong.
3510 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3514 DECLARE_RETURN(WORD
);
3516 TRACE("Enter NtUserSetWindowWord\n");
3517 UserEnterExclusive();
3519 if (!(Window
= UserGetWindowObject(hWnd
)))
3528 case GWL_HWNDPARENT
:
3529 RETURN( co_UserSetWindowLong(Window
->head
.h
, Index
, (UINT
)NewValue
, TRUE
));
3533 EngSetLastError(ERROR_INVALID_INDEX
);
3538 if (Index
> Window
->cbwndExtra
- sizeof(WORD
))
3540 EngSetLastError(ERROR_INVALID_PARAMETER
);
3544 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3545 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3550 TRACE("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3559 NtUserGetWindowPlacement(HWND hWnd
,
3560 WINDOWPLACEMENT
*lpwndpl
)
3564 WINDOWPLACEMENT Safepl
;
3566 DECLARE_RETURN(BOOL
);
3568 TRACE("Enter NtUserGetWindowPlacement\n");
3571 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3576 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3577 if(!NT_SUCCESS(Status
))
3579 SetLastNtError(Status
);
3582 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3588 if (0 == (Wnd
->style
& WS_VISIBLE
))
3590 Safepl
.showCmd
= SW_HIDE
;
3592 else if ((0 != (Wnd
->state2
& WNDS2_MAXIMIZEBUTTONDOWN
) ||
3593 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
3594 0 == (Wnd
->style
& WS_MINIMIZE
))
3596 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
3598 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
3600 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
3602 else if (0 != (Wnd
->style
& WS_VISIBLE
))
3604 Safepl
.showCmd
= SW_SHOWNORMAL
;
3607 Size
.x
= Wnd
->rcWindow
.left
;
3608 Size
.y
= Wnd
->rcWindow
.top
;
3609 WinPosInitInternalPos(Wnd
, &Size
,
3612 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
3613 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
3614 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
3616 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3617 if(!NT_SUCCESS(Status
))
3619 SetLastNtError(Status
);
3626 TRACE("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
3632 QueryWindow based on KJK::Hyperion and James Tabor.
3634 0 = QWUniqueProcessId
3635 1 = QWUniqueThreadId
3638 4 = QWIsHung Implements IsHungAppWindow found
3641 9 = QWKillWindow When I called this with hWnd ==
3642 DesktopWindow, it shutdown the system
3649 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3653 DECLARE_RETURN(UINT
);
3655 TRACE("Enter NtUserQueryWindow\n");
3658 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3665 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3666 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3669 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3670 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3673 case QUERY_WINDOW_ACTIVE
:
3674 Result
= (DWORD
)UserGetActiveWindow();
3677 case QUERY_WINDOW_FOCUS
:
3678 Result
= (DWORD
)IntGetFocusWindow();
3681 case QUERY_WINDOW_ISHUNG
:
3682 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
->MessageQueue
);
3685 case QUERY_WINDOW_REAL_ID
:
3686 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3689 Result
= (DWORD
)NULL
;
3696 TRACE("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3706 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3708 UNICODE_STRING SafeMessageName
;
3711 DECLARE_RETURN(UINT
);
3713 TRACE("Enter NtUserRegisterWindowMessage\n");
3714 UserEnterExclusive();
3716 if(MessageNameUnsafe
== NULL
)
3718 EngSetLastError(ERROR_INVALID_PARAMETER
);
3722 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3723 if(!NT_SUCCESS(Status
))
3725 SetLastNtError(Status
);
3729 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3730 if (SafeMessageName
.Buffer
)
3731 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3735 TRACE("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3752 DECLARE_RETURN(BOOL
);
3754 TRACE("Enter NtUserSetMenu\n");
3755 UserEnterExclusive();
3757 if (!(Window
= UserGetWindowObject(hWnd
)))
3762 if (! IntSetMenu(Window
, Menu
, &Changed
))
3767 if (Changed
&& Repaint
)
3769 USER_REFERENCE_ENTRY Ref
;
3771 UserRefObjectCo(Window
, &Ref
);
3772 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3773 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3775 UserDerefObjectCo(Window
);
3781 TRACE("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3791 NtUserSetWindowFNID(HWND hWnd
,
3795 DECLARE_RETURN(BOOL
);
3797 TRACE("Enter NtUserSetWindowFNID\n");
3798 UserEnterExclusive();
3800 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3805 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3807 EngSetLastError(ERROR_ACCESS_DENIED
);
3811 // From user land we only set these.
3812 if (fnID
!= FNID_DESTROY
)
3813 { // Hacked so we can mark desktop~!
3814 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
3817 EngSetLastError(ERROR_INVALID_PARAMETER
);
3826 TRACE("Leave NtUserSetWindowFNID\n");
3835 NtUserWindowFromPoint(LONG X
, LONG Y
)
3839 PWND DesktopWindow
= NULL
, Window
= NULL
;
3841 DECLARE_RETURN(HWND
);
3842 USER_REFERENCE_ENTRY Ref
;
3844 TRACE("Enter NtUserWindowFromPoint\n");
3845 UserEnterExclusive();
3847 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
3854 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
3855 //its possible this referencing is useless, thou it shouldnt hurt...
3856 UserRefObjectCo(DesktopWindow
, &Ref
);
3858 pti
= PsGetCurrentThreadWin32Thread();
3859 Window
= co_WinPosWindowFromPoint(DesktopWindow
, &pt
, &hittest
);
3863 Ret
= Window
->head
.h
;
3872 if (Window
) UserDereferenceObject(Window
);
3873 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
3875 TRACE("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
3885 * Undocumented function that is called from DefWindowProc to set
3892 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
3895 LARGE_STRING SafeText
;
3896 UNICODE_STRING UnicodeString
;
3899 TRACE("Enter NtUserDefSetText\n");
3901 if (WindowText
!= NULL
)
3905 SafeText
= ProbeForReadLargeString(WindowText
);
3907 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3910 SetLastNtError(_SEH2_GetExceptionCode());
3920 UserEnterExclusive();
3922 if(!(Wnd
= UserGetWindowObject(hWnd
)))
3928 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
3929 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
3930 // Now we know what the bAnsi is for.
3931 RtlInitUnicodeString(&UnicodeString
, NULL
);
3932 if (SafeText
.Buffer
)
3937 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
3939 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
3940 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
3942 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3945 SetLastNtError(_SEH2_GetExceptionCode());
3948 if (!Ret
) goto Exit
;
3951 if (UnicodeString
.Length
!= 0)
3953 if (Wnd
->strName
.MaximumLength
> 0 &&
3954 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
3956 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
3958 Wnd
->strName
.Length
= UnicodeString
.Length
;
3959 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
3960 RtlCopyMemory(Wnd
->strName
.Buffer
,
3961 UnicodeString
.Buffer
,
3962 UnicodeString
.Length
);
3967 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
3968 buf
= Wnd
->strName
.Buffer
;
3969 Wnd
->strName
.Buffer
= NULL
;
3972 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
3975 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
3976 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
3977 if (Wnd
->strName
.Buffer
!= NULL
)
3979 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
3980 RtlCopyMemory(Wnd
->strName
.Buffer
,
3981 UnicodeString
.Buffer
,
3982 UnicodeString
.Length
);
3983 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
3984 Wnd
->strName
.Length
= UnicodeString
.Length
;
3988 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3996 Wnd
->strName
.Length
= 0;
3997 if (Wnd
->strName
.Buffer
!= NULL
)
3998 Wnd
->strName
.Buffer
[0] = L
'\0';
4001 // HAX! FIXME! Windows does not do this in here!
4002 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4003 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4004 /* Send shell notifications */
4005 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4007 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4012 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4013 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4019 * NtUserInternalGetWindowText
4026 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4031 DECLARE_RETURN(INT
);
4033 TRACE("Enter NtUserInternalGetWindowText\n");
4036 if(lpString
&& (nMaxCount
<= 1))
4038 EngSetLastError(ERROR_INVALID_PARAMETER
);
4042 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4047 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4050 const WCHAR Terminator
= L
'\0';
4052 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4054 Copy
= min(nMaxCount
- 1, Result
);
4057 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4058 if(!NT_SUCCESS(Status
))
4060 SetLastNtError(Status
);
4066 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4067 if(!NT_SUCCESS(Status
))
4069 SetLastNtError(Status
);
4079 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4087 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4093 // ASSERT(OwnerWnd);
4095 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
4100 while (win_array
[count
])
4102 while (--count
>= 0)
4104 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4106 if (pWnd
->spwndOwner
!= OwnerWnd
)
4111 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4113 /* In Windows, ShowOwnedPopups(TRUE) generates
4114 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4115 * regardless of the state of the owner
4117 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4123 if (pWnd
->style
& WS_VISIBLE
)
4125 /* In Windows, ShowOwnedPopups(FALSE) generates
4126 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4127 * regardless of the state of the owner
4129 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4135 ExFreePool( win_array
);