2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
5 * FILE: win32ss/user/ntuser/window.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
10 DBG_DEFAULT_CHANNEL(UserWnd
);
12 INT gNestedWindowLimit
= 50;
14 /* HELPER FUNCTIONS ***********************************************************/
16 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
18 WORD Action
= LOWORD(wParam
);
19 WORD Flags
= HIWORD(wParam
);
21 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
23 EngSetLastError(ERROR_INVALID_PARAMETER
);
30 EngSetLastError(ERROR_INVALID_PARAMETER
);
34 if (Flags
& UISF_HIDEFOCUS
)
35 Wnd
->HideFocus
= TRUE
;
36 if (Flags
& UISF_HIDEACCEL
)
37 Wnd
->HideAccel
= TRUE
;
41 if (Flags
& UISF_HIDEFOCUS
)
42 Wnd
->HideFocus
= FALSE
;
43 if (Flags
& UISF_HIDEACCEL
)
44 Wnd
->HideAccel
= FALSE
;
51 PWND FASTCALL
IntGetWindowObject(HWND hWnd
)
55 if (!hWnd
) return NULL
;
57 Window
= UserGetWindowObject(hWnd
);
59 Window
->head
.cLockObj
++;
64 PWND FASTCALL
VerifyWnd(PWND pWnd
)
70 if (!pWnd
) return NULL
;
72 Error
= EngGetLastError();
76 hWnd
= UserHMGetHandle(pWnd
);
78 State2
= pWnd
->state2
;
80 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
82 EngSetLastError(Error
);
83 _SEH2_YIELD(return NULL
);
87 if ( UserObjectInDestroy(hWnd
) ||
88 State
& WNDS_DESTROYED
||
89 State2
& WNDS2_INDESTROY
)
92 EngSetLastError(Error
);
96 PWND FASTCALL
ValidateHwndNoErr(HWND hWnd
)
98 if (hWnd
) return (PWND
)UserGetObjectNoErr(gHandleTable
, hWnd
, TYPE_WINDOW
);
103 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
109 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
113 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, TYPE_WINDOW
);
114 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
116 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
124 IntSetStyle( PWND pwnd
, ULONG set_bits
, ULONG clear_bits
)
126 ULONG styleOld
, styleNew
;
127 styleOld
= pwnd
->style
;
128 styleNew
= (pwnd
->style
| set_bits
) & ~clear_bits
;
129 if (styleNew
== styleOld
) return styleNew
;
130 pwnd
->style
= styleNew
;
131 if ((styleOld
^ styleNew
) & WS_VISIBLE
) // State Change.
133 if (styleOld
& WS_VISIBLE
) pwnd
->head
.pti
->cVisWindows
--;
134 if (styleNew
& WS_VISIBLE
) pwnd
->head
.pti
->cVisWindows
++;
135 DceResetActiveDCEs( pwnd
);
143 * The function determines whether the specified window handle identifies
144 * an existing window.
148 * Handle to the window to test.
151 * If the window handle identifies an existing window, the return value
152 * is TRUE. If the window handle does not identify an existing window,
153 * the return value is FALSE.
157 IntIsWindow(HWND hWnd
)
161 if (!(Window
= UserGetWindowObject(hWnd
)))
170 IntIsWindowVisible(PWND Wnd
)
175 if (!Temp
) return TRUE
;
176 if (!(Temp
->style
& WS_VISIBLE
)) break;
177 if (Temp
->style
& WS_MINIMIZE
&& Temp
!= Wnd
) break;
178 if (Temp
->fnid
== FNID_DESKTOP
) return TRUE
;
179 Temp
= Temp
->spwndParent
;
185 IntGetParent(PWND Wnd
)
187 if (Wnd
->style
& WS_POPUP
)
189 return Wnd
->spwndOwner
;
191 else if (Wnd
->style
& WS_CHILD
)
193 return Wnd
->spwndParent
;
201 IntEnableWindow( HWND hWnd
, BOOL bEnable
)
207 if(!(pWnd
= UserGetWindowObject(hWnd
)))
212 /* check if updating is needed */
213 bIsDisabled
= !!(pWnd
->style
& WS_DISABLED
);
214 Update
= bIsDisabled
;
218 IntSetStyle( pWnd
, 0, WS_DISABLED
);
222 Update
= !bIsDisabled
;
224 co_IntSendMessage( hWnd
, WM_CANCELMODE
, 0, 0);
226 /* Remove keyboard focus from that window if it had focus */
227 if (hWnd
== IntGetThreadFocusWindow())
229 TRACE("IntEnableWindow SF NULL\n");
230 co_UserSetFocus(NULL
);
232 IntSetStyle( pWnd
, WS_DISABLED
, 0 );
237 IntNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, pWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
238 co_IntSendMessage(hWnd
, WM_ENABLE
, (LPARAM
)bEnable
, 0);
240 // Return nonzero if it was disabled, or zero if it wasn't:
247 * Compile a list of all child window handles from given window.
250 * This function is similar to Wine WIN_ListChildren. The caller
251 * must free the returned list with ExFreePool.
255 IntWinListChildren(PWND Window
)
259 UINT Index
, NumChildren
= 0;
261 if (!Window
) return NULL
;
263 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
266 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
269 ERR("Failed to allocate memory for children array\n");
270 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
273 for (Child
= Window
->spwndChild
, Index
= 0;
275 Child
= Child
->spwndNext
, ++Index
)
276 List
[Index
] = Child
->head
.h
;
283 IntWinListOwnedPopups(PWND Window
)
287 UINT Index
, NumChildren
= 0;
289 Desktop
= co_GetDesktopWindow(Window
);
293 for (Child
= Desktop
->spwndChild
; Child
; Child
= Child
->spwndNext
)
296 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
299 ERR("Failed to allocate memory for children array\n");
300 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
305 for (Child
= Desktop
->spwndChild
; Child
; Child
= Child
->spwndNext
)
307 if (Child
->spwndOwner
== Window
)
308 List
[Index
++] = Child
->head
.h
;
316 IntGetNonChildAncestor(PWND pWnd
)
318 while(pWnd
&& (pWnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
319 pWnd
= pWnd
->spwndParent
;
324 IntIsTopLevelWindow(PWND pWnd
)
326 if ( pWnd
->spwndParent
&&
327 pWnd
->spwndParent
== co_GetDesktopWindow(pWnd
) ) return TRUE
;
332 IntValidateOwnerDepth(PWND Wnd
, PWND Owner
)
337 if ( !Owner
) return gNestedWindowLimit
>= Depth
;
338 if (Owner
== Wnd
) break;
339 Owner
= Owner
->spwndOwner
;
346 IntGetWindow(HWND hWnd
,
352 Wnd
= ValidateHwndNoErr(hWnd
);
360 if (Wnd
->spwndOwner
!= NULL
)
361 FoundWnd
= Wnd
->spwndOwner
;
365 if(Wnd
->spwndParent
!= NULL
)
367 FoundWnd
= Wnd
->spwndParent
;
368 if (FoundWnd
->spwndChild
!= NULL
)
369 FoundWnd
= FoundWnd
->spwndChild
;
373 if (Wnd
->spwndNext
!= NULL
)
374 FoundWnd
= Wnd
->spwndNext
;
378 if (Wnd
->spwndPrev
!= NULL
)
379 FoundWnd
= Wnd
->spwndPrev
;
383 if (Wnd
->spwndChild
!= NULL
)
384 FoundWnd
= Wnd
->spwndChild
;
389 while ( FoundWnd
->spwndNext
!= NULL
)
390 FoundWnd
= FoundWnd
->spwndNext
;
398 if (FoundWnd
!= NULL
)
399 Ret
= UserHMGetHandle(FoundWnd
);
403 DWORD FASTCALL
IntGetWindowContextHelpId( PWND pWnd
)
409 HelpId
= (DWORD
)(DWORD_PTR
)UserGetProp(pWnd
, gpsi
->atomContextHelpIdProp
, TRUE
);
411 pWnd
= IntGetParent(pWnd
);
413 while (pWnd
&& pWnd
->fnid
!= FNID_DESKTOP
);
420 IntRemoveTrackMouseEvent(
423 /***********************************************************************
426 static void IntSendDestroyMsg(HWND hWnd
)
431 ti
= PsGetCurrentThreadWin32Thread();
432 Window
= UserGetWindowObject(hWnd
);
437 * Look whether the focus is within the tree of windows
438 * we will be destroying.
441 if ( ti
->MessageQueue
->spwndActive
== Window
|| // Fixes CORE-106 RegSvr32 exit and return focus to CMD.
442 (ti
->MessageQueue
->spwndActive
== NULL
&& ti
->MessageQueue
== IntGetFocusMessageQueue()) )
444 co_WinPosActivateOtherWindow(Window
);
447 /* Fixes CMD properties closing and returning focus to CMD */
448 if (ti
->MessageQueue
->spwndFocus
== Window
)
450 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
452 co_UserSetFocus(Window
->spwndParent
);
456 co_UserSetFocus(NULL
);
460 if (ti
->MessageQueue
->CaretInfo
.hWnd
== UserHMGetHandle(Window
))
462 co_IntDestroyCaret(ti
);
465 /* If the window being destroyed is currently tracked... */
466 if (ti
->rpdesk
->spwndTrack
== Window
)
468 IntRemoveTrackMouseEvent(ti
->rpdesk
);
472 /* If the window being destroyed is the current clipboard owner... */
473 if (ti
->ppi
->prpwinsta
!= NULL
&& Window
== ti
->ppi
->prpwinsta
->spwndClipOwner
)
475 /* ... make it release the clipboard */
476 UserClipboardRelease(Window
);
479 /* Send the WM_DESTROY to the window */
480 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
483 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
484 * make sure that the window still exists when we come back.
486 if (IntIsWindow(hWnd
))
491 if (!(pWndArray
= IntWinListChildren( Window
))) return;
493 for (i
= 0; pWndArray
[i
]; i
++)
495 if (IntIsWindow( pWndArray
[i
] )) IntSendDestroyMsg( pWndArray
[i
] );
497 ExFreePoolWithTag(pWndArray
, USERTAG_WINDOWLIST
);
501 TRACE("destroyed itself while in WM_DESTROY!\n");
506 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
508 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
512 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
514 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
515 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
518 if (Wnd
->strName
.Buffer
!= NULL
)
520 Wnd
->strName
.Length
= 0;
521 Wnd
->strName
.MaximumLength
= 0;
522 DesktopHeapFree(Wnd
->head
.rpdesk
,
523 Wnd
->strName
.Buffer
);
524 Wnd
->strName
.Buffer
= NULL
;
527 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
528 // WindowObject->hWnd = NULL;
531 /***********************************************************************
534 * Destroy storage associated to a window. "Internals" p.358
536 * This is the "functional" DestroyWindows function i.e. all stuff
537 * done in CreateWindow is undone here and not in DestroyWindow :-P
539 LRESULT
co_UserFreeWindow(PWND Window
,
540 PPROCESSINFO ProcessData
,
541 PTHREADINFO ThreadData
,
542 BOOLEAN SendMessages
)
548 BOOLEAN BelongsToThreadData
;
552 if(Window
->state2
& WNDS2_INDESTROY
)
554 TRACE("Tried to call co_UserFreeWindow() twice\n");
557 Window
->state2
|= WNDS2_INDESTROY
;
558 Window
->style
&= ~WS_VISIBLE
;
559 Window
->head
.pti
->cVisWindows
--;
562 /* remove the window already at this point from the thread window list so we
563 don't get into trouble when destroying the thread windows while we're still
564 in co_UserFreeWindow() */
565 RemoveEntryList(&Window
->ThreadListEntry
);
567 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
569 IntDeRegisterShellHookWindow(UserHMGetHandle(Window
));
571 /* free child windows */
572 Children
= IntWinListChildren(Window
);
575 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
577 if ((Child
= IntGetWindowObject(*ChildHandle
)))
579 if (!IntWndBelongsToThread(Child
, ThreadData
))
581 /* send WM_DESTROY messages to windows not belonging to the same thread */
582 co_IntSendMessage( UserHMGetHandle(Child
), WM_ASYNC_DESTROYWINDOW
, 0, 0 );
585 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
587 UserDereferenceObject(Child
);
590 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
596 * Clear the update region to make sure no WM_PAINT messages will be
597 * generated for this window while processing the WM_NCDESTROY.
599 co_UserRedrawWindow(Window
, NULL
, 0,
600 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
601 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
602 if (BelongsToThreadData
)
603 co_IntSendMessage(UserHMGetHandle(Window
), WM_NCDESTROY
, 0, 0);
606 UserClipboardFreeWindow(Window
);
608 DestroyTimersForWindow(ThreadData
, Window
);
610 /* Unregister hot keys */
611 UnregisterWindowHotKeys(Window
);
613 /* flush the message queue */
614 MsqRemoveWindowMessagesFromQueue(Window
);
616 /* from now on no messages can be sent to this window anymore */
617 Window
->state
|= WNDS_DESTROYED
;
618 Window
->fnid
|= FNID_FREED
;
620 /* don't remove the WINDOWSTATUS_DESTROYING bit */
622 /* reset shell window handles */
623 if (ThreadData
->rpdesk
)
625 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
626 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
628 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
629 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
632 /* Fixes dialog test_focus breakage due to r66237. */
633 if (ThreadData
->MessageQueue
->spwndFocus
== Window
)
634 ThreadData
->MessageQueue
->spwndFocus
= NULL
;
636 if (ThreadData
->MessageQueue
->spwndActive
== Window
)
637 ThreadData
->MessageQueue
->spwndActive
= NULL
;
639 if (ThreadData
->MessageQueue
->spwndCapture
== Window
)
644 //// Now kill those remaining "PAINTING BUG: Thread marked as containing dirty windows" spam!!!
645 if ( Window
->hrgnUpdate
!= NULL
|| Window
->state
& WNDS_INTERNALPAINT
)
647 MsqDecPaintCountQueue(Window
->head
.pti
);
648 if (Window
->hrgnUpdate
> HRGN_WINDOW
&& GreIsHandleValid(Window
->hrgnUpdate
))
650 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
651 GreDeleteObject(Window
->hrgnUpdate
);
653 Window
->hrgnUpdate
= NULL
;
654 Window
->state
&= ~WNDS_INTERNALPAINT
;
657 if (Window
->state
& (WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
))
659 Window
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
);
662 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
664 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
666 TRACE("UFW: IDMenu %p\n",Window
->IDMenu
);
667 IntDestroyMenuObject(Menu
, TRUE
);
671 if (Window
->SystemMenu
672 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
674 IntDestroyMenuObject(Menu
, TRUE
);
675 Window
->SystemMenu
= (HMENU
)0;
678 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
680 IntUnlinkWindow(Window
);
682 if (Window
->PropListItems
)
684 UserRemoveWindowProps(Window
);
685 TRACE("Window->PropListItems %lu\n",Window
->PropListItems
);
686 ASSERT(Window
->PropListItems
==0);
689 UserReferenceObject(Window
);
690 UserMarkObjectDestroy(Window
);
692 IntDestroyScrollBars(Window
);
694 if (Window
->pcls
->atomClassName
== gaGuiConsoleWndClass
)
696 /* Count only console windows manually */
697 co_IntUserManualGuiCheck(FALSE
);
700 /* dereference the class */
701 NT_ASSERT(Window
->head
.pti
!= NULL
);
702 IntDereferenceClass(Window
->pcls
,
703 Window
->head
.pti
->pDeskInfo
,
704 Window
->head
.pti
->ppi
);
707 if (Window
->hrgnClip
)
709 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
710 GreDeleteObject(Window
->hrgnClip
);
711 Window
->hrgnClip
= NULL
;
713 Window
->head
.pti
->cWindows
--;
715 // ASSERT(Window != NULL);
716 UserFreeWindowInfo(Window
->head
.pti
, Window
);
718 UserDereferenceObject(Window
);
719 UserDeleteObject(UserHMGetHandle(Window
), TYPE_WINDOW
);
725 // Same as User32:IntGetWndProc.
728 IntGetWindowProc(PWND pWnd
,
733 WNDPROC gcpd
, Ret
= 0;
735 ASSERT(UserIsEnteredExclusive() == TRUE
);
739 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
741 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
743 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
746 Ret
= GETPFNCLIENTA(i
);
748 Ret
= GETPFNCLIENTW(i
);
754 if (Class
->fnid
== FNID_EDIT
)
755 Ret
= pWnd
->lpfnWndProc
;
758 Ret
= pWnd
->lpfnWndProc
;
760 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
764 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
765 Ret
= GETPFNCLIENTA(Class
->fnid
);
769 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
770 Ret
= GETPFNCLIENTW(Class
->fnid
);
773 if ( Ret
!= pWnd
->lpfnWndProc
)
776 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
779 gcpd
= (WNDPROC
)UserGetCPD(
781 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
784 return (gcpd
? gcpd
: Ret
);
788 IntSetWindowProc(PWND pWnd
,
793 PCALLPROCDATA CallProc
;
795 WNDPROC Ret
, chWndProc
= NULL
;
797 // Retrieve previous window proc.
798 Ret
= IntGetWindowProc(pWnd
, Ansi
);
802 if (IsCallProcHandle(NewWndProc
))
804 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
806 { // Reset new WndProc.
807 NewWndProc
= CallProc
->pfnClientPrevious
;
808 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
809 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
812 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
813 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
815 if (GETPFNCLIENTW(i
) == NewWndProc
)
817 chWndProc
= GETPFNSERVER(i
);
820 if (GETPFNCLIENTA(i
) == NewWndProc
)
822 chWndProc
= GETPFNSERVER(i
);
826 // If match, set/reset to Server Side and clear ansi.
829 pWnd
->lpfnWndProc
= chWndProc
;
830 pWnd
->Unicode
= TRUE
;
831 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
832 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
836 pWnd
->Unicode
= !Ansi
;
837 // Handle the state change in here.
839 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
841 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
843 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
844 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
846 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
848 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
852 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
853 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
857 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
858 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
861 // Now set the new window proc.
862 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
868 /* INTERNAL ******************************************************************/
871 // This fixes a check for children messages that need paint while searching the parents messages!
872 // Fixes wine msg:test_paint_messages:WmParentErasePaint ..
875 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
877 PWND Window
= BaseWindow
;
880 if ( Window
== NULL
|| (Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
883 Window
= Window
->spwndParent
;
885 while(Parent
!= Window
);
890 /* Link the window into siblings list. Children and parent are kept in place. */
894 PWND WndInsertAfter
/* Set to NULL if top sibling */
897 if (Wnd
== WndInsertAfter
)
899 ERR("IntLinkWindow -- Trying to link window 0x%p to itself!!\n", Wnd
);
903 Wnd
->spwndPrev
= WndInsertAfter
;
906 /* Link after WndInsertAfter */
907 ASSERT(Wnd
!= WndInsertAfter
->spwndNext
);
908 Wnd
->spwndNext
= WndInsertAfter
->spwndNext
;
910 Wnd
->spwndNext
->spwndPrev
= Wnd
;
912 ASSERT(Wnd
!= Wnd
->spwndPrev
);
913 Wnd
->spwndPrev
->spwndNext
= Wnd
;
917 /* Link at the top */
918 ASSERT(Wnd
!= Wnd
->spwndParent
->spwndChild
);
919 Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
;
921 Wnd
->spwndNext
->spwndPrev
= Wnd
;
923 Wnd
->spwndParent
->spwndChild
= Wnd
;
928 Note: Wnd->spwndParent can be null if it is the desktop.
930 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
932 if (hWndPrev
== HWND_NOTOPMOST
)
934 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) && (Wnd
->ExStyle2
& WS_EX2_LINKED
))
935 return; /* nothing to do */
936 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
937 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
940 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
942 if (hWndPrev
== HWND_BOTTOM
)
944 /* Link in the bottom of the list */
947 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
948 while (WndInsertAfter
&& WndInsertAfter
->spwndNext
)
950 WndInsertAfter
= WndInsertAfter
->spwndNext
;
953 IntLinkWindow(Wnd
, WndInsertAfter
);
954 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
956 else if (hWndPrev
== HWND_TOPMOST
)
958 /* Link in the top of the list */
959 IntLinkWindow(Wnd
, NULL
);
960 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
962 else if (hWndPrev
== HWND_TOP
)
964 /* Link it after the last topmost window */
965 PWND WndInsertBefore
;
967 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
969 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
971 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
973 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
))
976 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
978 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
981 WndInsertBefore
= WndInsertBefore
->spwndNext
;
985 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
989 /* Link it after hWndPrev */
992 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
993 /* Are we called with an erroneous handle */
994 if (WndInsertAfter
== NULL
)
996 /* Link in a default position */
997 IntLinkHwnd(Wnd
, HWND_TOP
);
1001 if (Wnd
== WndInsertAfter
)
1002 ERR("IntLinkHwnd -- Trying to link window 0x%p to itself!!\n", Wnd
);
1003 IntLinkWindow(Wnd
, WndInsertAfter
);
1005 /* Fix the WS_EX_TOPMOST flag */
1006 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1008 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1012 if (WndInsertAfter
->spwndNext
&&
1013 (WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
))
1015 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1019 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
1023 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
1027 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
1030 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
1031 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1033 //ERR("ProcessOwnerSwap Old out.\n");
1034 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
1040 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
1043 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1045 //ERR("ProcessOwnerSwap New in.\n");
1046 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1050 // FIXME: System Tray checks.
1054 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1056 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1059 Wnd
= IntGetWindowObject(hWnd
);
1063 WndOldOwner
= Wnd
->spwndOwner
;
1065 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1066 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1068 if (!WndNewOwner
&& hWndNewOwner
)
1070 EngSetLastError(ERROR_INVALID_PARAMETER
);
1075 /* if parent belongs to a different thread and the window isn't */
1076 /* top-level, attach the two threads */
1077 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1079 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1083 Wnd
->spwndOwner
= WndNewOwner
;
1087 Wnd
->spwndOwner
= NULL
;
1092 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1093 EngSetLastError(ERROR_INVALID_PARAMETER
);
1097 UserDereferenceObject(Wnd
);
1102 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1104 PWND WndOldParent
, pWndExam
;
1107 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1110 ASSERT(WndNewParent
);
1111 ASSERT_REFS_CO(Wnd
);
1112 ASSERT_REFS_CO(WndNewParent
);
1114 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1116 EngSetLastError(ERROR_ACCESS_DENIED
);
1120 /* Some applications try to set a child as a parent */
1121 if (IntIsChildWindow(Wnd
, WndNewParent
))
1123 TRACE("IntSetParent try to set a child as a parent.\n");
1124 EngSetLastError( ERROR_INVALID_PARAMETER
);
1128 pWndExam
= WndNewParent
; // Load parent Window to examine.
1129 // Now test for set parent to parent hit.
1132 if (Wnd
== pWndExam
)
1134 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1135 EngSetLastError(ERROR_INVALID_PARAMETER
);
1138 pWndExam
= pWndExam
->spwndParent
;
1142 * Windows hides the window first, then shows it again
1143 * including the WM_SHOWWINDOW messages and all
1145 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1147 /* Window must belong to current process */
1148 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1150 ERR("IntSetParent Window must belong to current process!\n");
1154 WndOldParent
= Wnd
->spwndParent
;
1156 if ( WndOldParent
&&
1157 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1158 pt
.x
= Wnd
->rcWindow
.right
;
1160 pt
.x
= Wnd
->rcWindow
.left
;
1161 pt
.y
= Wnd
->rcWindow
.top
;
1163 IntScreenToClient(WndOldParent
, &pt
);
1165 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1167 if (WndNewParent
!= WndOldParent
)
1169 /* Unlink the window from the siblings list */
1170 IntUnlinkWindow(Wnd
);
1171 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1173 /* Set the new parent */
1174 Wnd
->spwndParent
= WndNewParent
;
1176 if ( Wnd
->style
& WS_CHILD
&&
1178 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1180 ERR("SetParent Top Most from Pop up!\n");
1181 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1184 /* Link the window with its new siblings */
1186 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1187 UserIsDesktopWindow(WndNewParent
) ) ? HWND_TOP
: HWND_TOPMOST
) );
1190 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1191 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1193 Wnd
->style
|= WS_CLIPSIBLINGS
;
1194 DceResetActiveDCEs(Wnd
);
1197 /* if parent belongs to a different thread and the window isn't */
1198 /* top-level, attach the two threads */
1199 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1201 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1203 if (WndOldParent
&& (Wnd
->head
.pti
!= WndOldParent
->head
.pti
))
1205 //ERR("SetParent Old out.\n");
1206 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1209 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1211 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1213 //ERR("SetParent New in.\n");
1214 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1219 if (UserIsMessageWindow(WndOldParent
) || UserIsMessageWindow(WndNewParent
))
1220 swFlags
|= SWP_NOACTIVATE
;
1222 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1224 * SetParent additionally needs to make hwnd the top window
1225 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1226 * WM_WINDOWPOSCHANGED notification messages.
1228 //ERR("IntSetParent SetWindowPos 1\n");
1229 co_WinPosSetWindowPos( Wnd
,
1230 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1231 pt
.x
, pt
.y
, 0, 0, swFlags
);
1232 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1233 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1235 return WndOldParent
;
1239 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1241 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1242 HWND hWndOldParent
= NULL
;
1243 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1245 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1247 EngSetLastError(ERROR_INVALID_PARAMETER
);
1251 if (hWndChild
== IntGetDesktopWindow())
1253 ERR("UserSetParent Access Denied!\n");
1254 EngSetLastError(ERROR_ACCESS_DENIED
);
1260 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1262 ERR("UserSetParent Bad New Parent!\n");
1268 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1274 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1276 ERR("UserSetParent Bad Child!\n");
1280 UserRefObjectCo(Wnd
, &Ref
);
1281 UserRefObjectCo(WndParent
, &ParentRef
);
1282 //ERR("Enter co_IntSetParent\n");
1283 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1284 //ERR("Leave co_IntSetParent\n");
1285 UserDerefObjectCo(WndParent
);
1286 UserDerefObjectCo(Wnd
);
1290 hWndOldParent
= WndOldParent
->head
.h
;
1291 UserDereferenceObject(WndOldParent
);
1294 return( hWndOldParent
);
1297 /* Unlink the window from siblings. Children and parent are kept in place. */
1299 IntUnlinkWindow(PWND Wnd
)
1301 ASSERT(Wnd
!= Wnd
->spwndNext
);
1302 ASSERT(Wnd
!= Wnd
->spwndPrev
);
1305 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1308 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1310 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1311 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1313 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1316 /* FUNCTIONS *****************************************************************/
1319 * As best as I can figure, this function is used by EnumWindows,
1320 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1322 * It's supposed to build a list of HWNDs to return to the caller.
1323 * We can figure out what kind of list by what parameters are
1331 NtUserBuildHwndList(
1344 return ERROR_INVALID_PARAMETER
;
1346 if (hwndParent
|| !dwThreadId
)
1349 PWND Parent
, Window
;
1353 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1355 return ERROR_INVALID_HANDLE
;
1360 Status
= IntValidateDesktopHandle(hDesktop
,
1364 if(!NT_SUCCESS(Status
))
1366 return ERROR_INVALID_HANDLE
;
1369 hwndParent
= Desktop
->DesktopWindow
;
1376 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1377 (Window
= Parent
->spwndChild
))
1379 BOOL bGoDown
= TRUE
;
1381 Status
= STATUS_SUCCESS
;
1386 if(dwCount
++ < *pBufSize
&& pWnd
)
1390 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1391 *pWnd
= Window
->head
.h
;
1394 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1396 Status
= _SEH2_GetExceptionCode();
1399 if(!NT_SUCCESS(Status
))
1401 SetLastNtError(Status
);
1405 if (Window
->spwndChild
&& bChildren
)
1407 Window
= Window
->spwndChild
;
1412 if (Window
->spwndNext
)
1414 Window
= Window
->spwndNext
;
1418 Window
= Window
->spwndParent
;
1419 if (Window
== Parent
)
1428 ObDereferenceObject(Desktop
);
1431 else // Build EnumThreadWindows list!
1434 PTHREADINFO W32Thread
;
1438 Status
= PsLookupThreadByThreadId(UlongToHandle(dwThreadId
), &Thread
);
1439 if (!NT_SUCCESS(Status
))
1441 ERR("Thread Id is not valid!\n");
1442 return ERROR_INVALID_PARAMETER
;
1444 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1446 ObDereferenceObject(Thread
);
1447 TRACE("Tried to enumerate windows of a non gui thread\n");
1448 return ERROR_INVALID_PARAMETER
;
1451 // Do not use Thread link list due to co_UserFreeWindow!!!
1452 // Current = W32Thread->WindowListHead.Flink;
1453 // Fixes Api:CreateWindowEx tests!!!
1454 List
= IntWinListChildren(UserGetDesktopWindow());
1458 for (i
= 0; List
[i
]; i
++)
1460 Window
= ValidateHwndNoErr(List
[i
]);
1461 if (Window
&& Window
->head
.pti
== W32Thread
)
1463 if (dwCount
< *pBufSize
&& pWnd
)
1467 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1468 *pWnd
= Window
->head
.h
;
1471 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1473 Status
= _SEH2_GetExceptionCode();
1476 if (!NT_SUCCESS(Status
))
1478 ERR("Failure to build window list!\n");
1479 SetLastNtError(Status
);
1486 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
1489 ObDereferenceObject(Thread
);
1492 *pBufSize
= dwCount
;
1493 return STATUS_SUCCESS
;
1496 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1498 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1499 !(pWindow
->ExStyle
& WS_EX_NOPARENTNOTIFY
))
1501 if (VerifyWnd(pWindow
->spwndParent
) && !UserIsDesktopWindow(pWindow
->spwndParent
))
1503 USER_REFERENCE_ENTRY Ref
;
1504 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1505 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1507 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1508 (LPARAM
)pWindow
->head
.h
);
1509 UserDerefObjectCo(pWindow
->spwndParent
);
1515 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1517 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1519 /* default positioning for overlapped windows */
1520 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1523 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1525 pMonitor
= UserGetPrimaryMonitor();
1527 /* Check if we don't have a monitor attached yet */
1528 if(pMonitor
== NULL
)
1536 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1538 if (IS_DEFAULT(Cs
->x
))
1540 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1542 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1544 Cs
->x
= ProcessParams
->StartingX
;
1545 Cs
->y
= ProcessParams
->StartingY
;
1549 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1550 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1551 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1552 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1554 /* reset counter and position */
1557 pMonitor
->cWndStack
= 0;
1559 pMonitor
->cWndStack
++;
1563 if (IS_DEFAULT(Cs
->cx
))
1565 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1567 Cs
->cx
= ProcessParams
->CountX
;
1568 Cs
->cy
= ProcessParams
->CountY
;
1572 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1573 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1576 /* neither x nor cx are default. Check the y values .
1577 * In the trace we see Outlook and Outlook Express using
1578 * cy set to CW_USEDEFAULT when opening the address book.
1580 else if (IS_DEFAULT(Cs
->cy
))
1582 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1583 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1588 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1589 if(IS_DEFAULT(Cs
->x
))
1594 if(IS_DEFAULT(Cs
->cx
))
1604 /* Allocates and initializes a window */
1605 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1606 PLARGE_STRING WindowName
,
1611 PDESKTOP pdeskCreated
)
1615 PTHREADINFO pti
= NULL
;
1617 BOOL bUnicodeWindow
;
1619 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1621 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1622 { // Need both here for wine win.c test_CreateWindow.
1623 //if (Cs->hwndParent && ParentWindow)
1624 if (ParentWindow
) // It breaks more tests..... WIP.
1626 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1627 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1628 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1629 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1633 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1635 * Dialog boxes and message boxes do not inherit layout, so you must
1636 * set the layout explicitly.
1638 if ( Class
->fnid
!= FNID_DIALOG
)
1640 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1642 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1648 /* Automatically add WS_EX_WINDOWEDGE */
1649 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1650 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1651 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1652 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1654 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1656 /* Is it a unicode window? */
1657 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1658 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1660 /* Allocate the new window */
1661 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1662 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1666 sizeof(WND
) + Class
->cbwndExtra
);
1673 TRACE("Created window object with handle %p\n", hWnd
);
1675 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1676 { /* HACK: Helper for win32csr/desktopbg.c */
1677 /* If there is no desktop window yet, we must be creating it */
1678 TRACE("CreateWindow setting desktop.\n");
1679 pdeskCreated
->DesktopWindow
= hWnd
;
1680 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1684 * Fill out the structure describing it.
1686 /* Remember, pWnd->head is setup in object.c ... */
1687 pWnd
->spwndParent
= ParentWindow
;
1688 pWnd
->spwndOwner
= OwnerWindow
;
1690 pWnd
->spwndLastActive
= pWnd
;
1691 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1693 pWnd
->hModule
= Cs
->hInstance
;
1694 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1695 pWnd
->ExStyle
= Cs
->dwExStyle
;
1696 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1697 pWnd
->pActCtx
= acbiBuffer
;
1698 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1699 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1701 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1703 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1704 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1707 pWnd
->head
.pti
->cWindows
++;
1709 if (Class
->spicn
&& !Class
->spicnSm
)
1711 HICON IconSmHandle
= NULL
;
1712 if((Class
->spicn
->CURSORF_flags
& (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1713 == (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1715 IconSmHandle
= co_IntCopyImage(
1716 UserHMGetHandle(Class
->spicn
),
1718 UserGetSystemMetrics( SM_CXSMICON
),
1719 UserGetSystemMetrics( SM_CYSMICON
),
1720 LR_COPYFROMRESOURCE
);
1724 /* Retry without copying from resource */
1725 IconSmHandle
= co_IntCopyImage(
1726 UserHMGetHandle(Class
->spicn
),
1728 UserGetSystemMetrics( SM_CXSMICON
),
1729 UserGetSystemMetrics( SM_CYSMICON
),
1735 Class
->spicnSm
= UserGetCurIconObject(IconSmHandle
);
1736 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1740 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1741 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1743 /* BugBoy Comments: Comment below say that System classes are always created
1744 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1745 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1747 No where can I see in code or through testing does the window change back
1748 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1749 see what problems this would cause. */
1751 // Set WndProc from Class.
1752 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1754 // GetWindowProc, test for non server side default classes and set WndProc.
1755 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1759 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1760 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1764 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1765 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1769 // If not an Unicode caller, set Ansi creator bit.
1770 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1772 // Clone Class Ansi/Unicode proc type.
1773 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1775 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1776 pWnd
->Unicode
= FALSE
;
1780 * It seems there can be both an Ansi creator and Unicode Class Window
1781 * WndProc, unless the following overriding conditions occur:
1783 if ( !bUnicodeWindow
&&
1784 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1785 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1786 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1787 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1788 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1789 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1790 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1791 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1792 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1793 { // Override Class and set the window Ansi WndProc.
1794 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1795 pWnd
->Unicode
= FALSE
;
1798 { // Set the window Unicode WndProc.
1799 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1800 pWnd
->Unicode
= TRUE
;
1804 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1805 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1806 Dont understand why it does this. */
1807 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1809 PCALLPROCDATA CallProc
;
1810 CallProc
= CreateCallProc(pWnd
->head
.rpdesk
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1814 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1815 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1819 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1823 InitializeListHead(&pWnd
->PropListHead
);
1824 pWnd
->PropListItems
= 0;
1826 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1828 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1829 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1830 if (pWnd
->strName
.Buffer
== NULL
)
1835 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1836 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1837 pWnd
->strName
.Length
= WindowName
->Length
;
1838 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1841 /* Correct the window style. */
1842 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1844 pWnd
->style
|= WS_CLIPSIBLINGS
;
1845 if (!(pWnd
->style
& WS_POPUP
))
1847 pWnd
->style
|= WS_CAPTION
;
1851 /* WS_EX_WINDOWEDGE depends on some other styles */
1852 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1853 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1854 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1856 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1857 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1858 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1861 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1863 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1864 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1866 /* Set the window menu */
1867 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1871 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1873 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1875 UNICODE_STRING MenuName
;
1878 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1880 MenuName
.Length
= 0;
1881 MenuName
.MaximumLength
= 0;
1882 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1886 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1888 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1889 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1893 pWnd
->IDMenu
= (UINT_PTR
)Cs
->hMenu
;
1896 if ( ParentWindow
&&
1897 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1898 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1900 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1902 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1904 EngSetLastError(ERROR_INVALID_PARAMETER
);
1907 if ( pWnd
->spwndOwner
&&
1908 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1910 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1912 if ( pWnd
->spwndOwner
&&
1913 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1914 pti
!= pWnd
->spwndOwner
->head
.pti
)
1916 //ERR("CreateWindow Owner in.\n");
1917 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1921 /* Insert the window into the thread's window list. */
1922 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1924 /* Handle "CS_CLASSDC", it is tested first. */
1925 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1926 { /* One DCE per class to have CLASS. */
1927 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1929 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1930 { /* Allocate a DCE for this window. */
1931 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1937 ERR("IntCreateWindow Allocation Error.\n");
1938 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1941 UserDereferenceObject(pWnd
);
1949 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1950 PUNICODE_STRING ClassName
,
1951 PLARGE_STRING WindowName
,
1955 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1956 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1957 PWINSTATION_OBJECT WinSta
;
1960 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1961 CBT_CREATEWNDW
* pCbtCreate
;
1963 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1965 DWORD dwShowMode
= SW_SHOW
;
1966 CREATESTRUCTW
*pCsw
= NULL
;
1967 PVOID pszClass
= NULL
, pszName
= NULL
;
1970 /* Get the current window station and reference it */
1971 pti
= GetW32ThreadInfo();
1972 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1974 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1975 return NULL
; // There is nothing to cleanup.
1977 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1978 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1983 /* Get the class and reference it */
1984 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
1987 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
1988 ERR("Failed to find class %wZ\n", ClassName
);
1992 /* Now find the parent and the owner window */
1993 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
1996 if (Cs
->hwndParent
== HWND_MESSAGE
)
1998 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
2000 else if (Cs
->hwndParent
)
2002 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
2003 hWndOwner
= Cs
->hwndParent
;
2005 hWndParent
= Cs
->hwndParent
;
2007 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2009 ERR("Cannot create a child window without a parent!\n");
2010 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
2011 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
2014 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
2015 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
2017 if (hWndParent
&& !ParentWindow
)
2019 ERR("Got invalid parent window handle\n");
2022 else if (hWndOwner
&& !OwnerWindow
)
2024 ERR("Got invalid owner window handle\n");
2025 ParentWindow
= NULL
;
2031 if (IntIsDesktopWindow(OwnerWindow
)) OwnerWindow
= NULL
;
2032 else if (ParentWindow
&& !IntIsDesktopWindow(ParentWindow
))
2034 ERR("an owned window must be created as top-level\n");
2035 EngSetLastError( STATUS_ACCESS_DENIED
);
2038 else /* owner must be a top-level window */
2040 while ((OwnerWindow
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
&& !IntIsDesktopWindow(OwnerWindow
->spwndParent
))
2041 OwnerWindow
= OwnerWindow
->spwndParent
;
2045 /* Fix the position and the size of the window */
2048 UserRefObjectCo(ParentWindow
, &ParentRef
);
2049 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2052 /* Allocate and initialize the new window */
2053 Window
= IntCreateWindow(Cs
,
2062 ERR("IntCreateWindow failed!\n");
2066 hWnd
= UserHMGetHandle(Window
);
2067 hwndInsertAfter
= HWND_TOP
;
2069 UserRefObjectCo(Window
, &Ref
);
2070 UserDereferenceObject(Window
);
2071 ObDereferenceObject(WinSta
);
2073 //// Check for a hook to eliminate overhead. ////
2074 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2076 // Allocate the calling structures Justin Case this goes Global.
2077 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2078 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2079 if (!pCsw
|| !pCbtCreate
)
2081 ERR("UserHeapAlloc() failed!\n");
2085 /* Fill the new CREATESTRUCTW */
2086 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2087 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2089 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2090 if (!IS_ATOM(ClassName
->Buffer
))
2092 if (Window
->state
& WNDS_ANSICREATOR
)
2094 ANSI_STRING AnsiString
;
2095 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2096 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2099 ERR("UserHeapAlloc() failed!\n");
2102 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2103 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2104 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2108 UNICODE_STRING UnicodeString
;
2109 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2110 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2113 ERR("UserHeapAlloc() failed!\n");
2116 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2117 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2118 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2120 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2122 if (WindowName
->Length
)
2124 UNICODE_STRING Name
;
2125 Name
.Buffer
= WindowName
->Buffer
;
2126 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2127 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2129 if (Window
->state
& WNDS_ANSICREATOR
)
2131 ANSI_STRING AnsiString
;
2132 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2133 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2136 ERR("UserHeapAlloc() failed!\n");
2139 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2140 AnsiString
.Buffer
= (PCHAR
)pszName
;
2141 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2145 UNICODE_STRING UnicodeString
;
2146 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2147 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2150 ERR("UserHeapAlloc() failed!\n");
2153 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2154 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2155 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2157 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2160 pCbtCreate
->lpcs
= pCsw
;
2161 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2163 //// Call the WH_CBT hook ////
2164 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2167 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2170 // Write back changes.
2175 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2178 /* NCCREATE and WM_NCCALCSIZE need the original values */
2179 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2180 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2182 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2184 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2186 Cs
->x
+= ParentWindow
->rcClient
.left
;
2187 Cs
->y
+= ParentWindow
->rcClient
.top
;
2191 /* Send the WM_GETMINMAXINFO message */
2195 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2197 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2198 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2199 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2200 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2201 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2204 Window
->rcWindow
.left
= Cs
->x
;
2205 Window
->rcWindow
.top
= Cs
->y
;
2206 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2207 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2209 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2211 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2212 RECTL_vOffsetRect(&Window->rcWindow,
2213 ParentWindow->rcClient.left,
2214 ParentWindow->rcClient.top);
2217 /* correct child window coordinates if mirroring on parent is enabled */
2218 if (ParentWindow
!= NULL
)
2220 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2221 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2223 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2224 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2228 Window
->rcClient
= Window
->rcWindow
;
2230 /* Link the window */
2231 if (NULL
!= ParentWindow
)
2233 /* Link the window into the siblings list */
2234 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2235 IntLinkHwnd(Window
, HWND_BOTTOM
);
2237 IntLinkHwnd(Window
, hwndInsertAfter
);
2240 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2242 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2243 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2246 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2248 if ( !IntIsTopLevelWindow(Window
) )
2250 if (pti
!= Window
->spwndParent
->head
.pti
)
2252 //ERR("CreateWindow Parent in.\n");
2253 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2258 /* Send the NCCREATE message */
2259 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2262 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2266 /* Send the WM_NCCALCSIZE message */
2269 MaxPos
.x
= Window
->rcWindow
.left
;
2270 MaxPos
.y
= Window
->rcWindow
.top
;
2272 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2273 //rc = Window->rcWindow;
2274 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2275 //Window->rcClient = rc;
2277 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2278 MaxPos
.y
- Window
->rcWindow
.top
);
2281 /* Send the WM_CREATE message. */
2282 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2283 if (Result
== (LRESULT
)-1)
2285 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2289 /* Send the EVENT_OBJECT_CREATE event */
2290 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2292 /* By setting the flag below it can be examined to determine if the window
2293 was created successfully and a valid pwnd was passed back to caller since
2294 from here the function has to succeed. */
2295 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2297 /* Send the WM_SIZE and WM_MOVE messages. */
2298 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2300 co_WinPosSendSizeMove(Window
);
2303 /* Show or maybe minimize or maximize the window. */
2305 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2306 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2309 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2311 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2312 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2313 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2314 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2315 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2318 /* Send the WM_PARENTNOTIFY message */
2319 IntSendParentNotify(Window
, WM_CREATE
);
2321 /* Notify the shell that a new window was created */
2322 if (UserIsDesktopWindow(Window
->spwndParent
) &&
2323 Window
->spwndOwner
== NULL
&&
2324 (Window
->style
& WS_VISIBLE
) &&
2325 (!(Window
->ExStyle
& WS_EX_TOOLWINDOW
) ||
2326 (Window
->ExStyle
& WS_EX_APPWINDOW
)))
2328 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2331 /* Initialize and show the window's scrollbars */
2332 if (Window
->style
& WS_VSCROLL
)
2334 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2336 if (Window
->style
& WS_HSCROLL
)
2338 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2341 /* Show the new window */
2342 if (Cs
->style
& WS_VISIBLE
)
2344 if (Window
->style
& WS_MAXIMIZE
)
2345 dwShowMode
= SW_SHOW
;
2346 else if (Window
->style
& WS_MINIMIZE
)
2347 dwShowMode
= SW_SHOWMINIMIZED
;
2349 co_WinPosShowWindow(Window
, dwShowMode
);
2351 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2353 ASSERT(ParentWindow
);
2356 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2357 /* ShowWindow won't activate child windows */
2358 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2362 if (Class
->atomClassName
== gaGuiConsoleWndClass
)
2364 /* Count only console windows manually */
2365 co_IntUserManualGuiCheck(TRUE
);
2368 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2374 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2375 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2377 co_UserDestroyWindow(Window
);
2379 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2382 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2383 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2384 if (pszName
) UserHeapFree(pszName
);
2385 if (pszClass
) UserHeapFree(pszClass
);
2389 UserDerefObjectCo(Window
);
2391 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2393 // See CORE-13717, not setting error on success.
2395 EngSetLastError(ERROR_SUCCESS
);
2402 ProbeAndCaptureLargeString(
2403 OUT PLARGE_STRING plstrSafe
,
2404 IN PLARGE_STRING plstrUnsafe
)
2406 LARGE_STRING lstrTemp
;
2407 PVOID pvBuffer
= NULL
;
2411 /* Probe and copy the string */
2412 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2413 lstrTemp
= *plstrUnsafe
;
2415 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2418 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2422 if (lstrTemp
.Length
!= 0)
2424 /* Allocate a buffer from paged pool */
2425 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2428 return STATUS_NO_MEMORY
;
2433 /* Probe and copy the buffer */
2434 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2435 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2437 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2439 /* Cleanup and fail */
2440 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2441 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2446 /* Set the output string */
2447 plstrSafe
->Buffer
= pvBuffer
;
2448 plstrSafe
->Length
= lstrTemp
.Length
;
2449 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2451 return STATUS_SUCCESS
;
2455 * \todo Allow passing plstrClassName as ANSI.
2459 NtUserCreateWindowEx(
2461 PLARGE_STRING plstrClassName
,
2462 PLARGE_STRING plstrClsVersion
,
2463 PLARGE_STRING plstrWindowName
,
2471 HINSTANCE hInstance
,
2477 LARGE_STRING lstrWindowName
;
2478 LARGE_STRING lstrClassName
;
2479 LARGE_STRING lstrClsVersion
;
2480 UNICODE_STRING ustrClassName
;
2481 UNICODE_STRING ustrClsVersion
;
2486 lstrWindowName
.Buffer
= NULL
;
2487 lstrClassName
.Buffer
= NULL
;
2488 lstrClsVersion
.Buffer
= NULL
;
2490 ASSERT(plstrWindowName
);
2492 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2494 /* check hMenu is valid handle */
2495 if (hMenu
&& !UserGetMenuObject(hMenu
))
2497 ERR("NtUserCreateWindowEx: Got an invalid menu handle!\n");
2498 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
2503 /* Copy the window name to kernel mode */
2504 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2505 if (!NT_SUCCESS(Status
))
2507 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2508 SetLastNtError(Status
);
2512 plstrWindowName
= &lstrWindowName
;
2514 /* Check if the class is an atom */
2515 if (IS_ATOM(plstrClassName
))
2517 /* It is, pass the atom in the UNICODE_STRING */
2518 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2519 ustrClassName
.Length
= 0;
2520 ustrClassName
.MaximumLength
= 0;
2524 /* It's not, capture the class name */
2525 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2526 if (!NT_SUCCESS(Status
))
2528 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2529 /* Set last error, cleanup and return */
2530 SetLastNtError(Status
);
2534 /* We pass it on as a UNICODE_STRING */
2535 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2536 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2537 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2540 /* Check if the class version is an atom */
2541 if (IS_ATOM(plstrClsVersion
))
2543 /* It is, pass the atom in the UNICODE_STRING */
2544 ustrClsVersion
.Buffer
= (PVOID
)plstrClsVersion
;
2545 ustrClsVersion
.Length
= 0;
2546 ustrClsVersion
.MaximumLength
= 0;
2550 /* It's not, capture the class name */
2551 Status
= ProbeAndCaptureLargeString(&lstrClsVersion
, plstrClsVersion
);
2552 if (!NT_SUCCESS(Status
))
2554 ERR("NtUserCreateWindowEx: failed to capture plstrClsVersion\n");
2555 /* Set last error, cleanup and return */
2556 SetLastNtError(Status
);
2560 /* We pass it on as a UNICODE_STRING */
2561 ustrClsVersion
.Buffer
= lstrClsVersion
.Buffer
;
2562 ustrClsVersion
.Length
= (USHORT
)min(lstrClsVersion
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2563 ustrClsVersion
.MaximumLength
= (USHORT
)min(lstrClsVersion
.MaximumLength
, MAXUSHORT
);
2566 /* Fill the CREATESTRUCTW */
2567 /* we will keep here the original parameters */
2569 Cs
.lpCreateParams
= lpParam
;
2570 Cs
.hInstance
= hInstance
;
2572 Cs
.hwndParent
= hWndParent
;
2577 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2578 Cs
.lpszClass
= ustrClassName
.Buffer
;
2579 Cs
.dwExStyle
= dwExStyle
;
2581 UserEnterExclusive();
2583 /* Call the internal function */
2584 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClsVersion
, plstrWindowName
, acbiBuffer
);
2588 ERR("co_UserCreateWindowEx failed!\n");
2590 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2595 if (lstrWindowName
.Buffer
)
2597 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2599 if (lstrClassName
.Buffer
)
2601 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2603 if (lstrClsVersion
.Buffer
)
2605 ExFreePoolWithTag(lstrClsVersion
.Buffer
, TAG_STRING
);
2612 BOOLEAN
co_UserDestroyWindow(PVOID Object
)
2618 PWND Window
= Object
;
2620 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2622 hWnd
= Window
->head
.h
;
2623 ti
= PsGetCurrentThreadWin32Thread();
2625 TRACE("co_UserDestroyWindow \n");
2627 /* Check for owner thread */
2628 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2630 /* Check if we are destroying the desktop window */
2631 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2633 EngSetLastError(ERROR_ACCESS_DENIED
);
2638 /* If window was created successfully and it is hooked */
2639 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2641 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2643 ERR("Destroy Window WH_CBT Call Hook return!\n");
2648 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2650 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2652 if (Window
->spwndOwner
)
2654 //ERR("DestroyWindow Owner out.\n");
2655 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2660 /* Inform the parent */
2661 if (Window
->style
& WS_CHILD
)
2663 IntSendParentNotify(Window
, WM_DESTROY
);
2666 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
2668 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
2671 /* Hide the window */
2672 if (Window
->style
& WS_VISIBLE
)
2674 if (Window
->style
& WS_CHILD
)
2676 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
2677 co_WinPosShowWindow(Window
, SW_HIDE
);
2681 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2685 // Adjust last active.
2686 if ((pwndTemp
= Window
->spwndOwner
))
2688 while (pwndTemp
->spwndOwner
)
2689 pwndTemp
= pwndTemp
->spwndOwner
;
2691 if (pwndTemp
->spwndLastActive
== Window
)
2692 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2695 if (Window
->spwndParent
&& IntIsWindow(UserHMGetHandle(Window
)))
2697 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2699 if (!IntIsTopLevelWindow(Window
))
2701 //ERR("DestroyWindow Parent out.\n");
2702 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2707 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2708 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2709 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2710 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2711 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2712 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2713 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2714 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2717 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2720 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2722 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2724 ERR("Destroying the ShellWindow!\n");
2725 ti
->pDeskInfo
->hShellWindow
= NULL
;
2729 IntEngWindowChanged(Window
, WOC_DELETE
);
2731 if (!IntIsWindow(UserHMGetHandle(Window
)))
2736 /* Recursively destroy owned windows */
2738 if (! (Window
->style
& WS_CHILD
))
2742 BOOL GotOne
= FALSE
;
2745 PWND Child
, Desktop
;
2747 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2748 UserGetWindowObject(IntGetDesktopWindow());
2749 Children
= IntWinListChildren(Desktop
);
2753 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2755 Child
= UserGetWindowObject(*ChildHandle
);
2758 if (Child
->spwndOwner
!= Window
)
2763 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2765 USER_REFERENCE_ENTRY ChildRef
;
2766 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2767 co_UserDestroyWindow(Child
);
2768 UserDerefObjectCo(Child
); // Temp HACK?
2774 if (Child
->spwndOwner
!= NULL
)
2776 Child
->spwndOwner
= NULL
;
2780 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2789 /* Generate mouse move message for the next window */
2790 msg
.message
= WM_MOUSEMOVE
;
2791 msg
.wParam
= UserGetMouseButtonsState();
2792 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2793 msg
.pt
= gpsi
->ptCursor
;
2794 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2796 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2798 /* Send destroy messages */
2799 IntSendDestroyMsg(UserHMGetHandle(Window
));
2801 if (!IntIsWindow(UserHMGetHandle(Window
)))
2806 /* Destroy the window storage */
2807 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2817 NtUserDestroyWindow(HWND Wnd
)
2820 DECLARE_RETURN(BOOLEAN
);
2822 USER_REFERENCE_ENTRY Ref
;
2824 TRACE("Enter NtUserDestroyWindow\n");
2825 UserEnterExclusive();
2827 if (!(Window
= UserGetWindowObject(Wnd
)))
2832 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2833 ret
= co_UserDestroyWindow(Window
);
2834 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2839 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2845 static HWND FASTCALL
2846 IntFindWindow(PWND Parent
,
2849 PUNICODE_STRING WindowName
)
2851 BOOL CheckWindowName
;
2854 UNICODE_STRING CurrentWindowName
;
2858 CheckWindowName
= WindowName
->Buffer
!= 0;
2860 if((List
= IntWinListChildren(Parent
)))
2865 /* skip handles before and including ChildAfter */
2866 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2870 /* search children */
2874 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2879 /* Do not send WM_GETTEXT messages in the kernel mode version!
2880 The user mode version however calls GetWindowText() which will
2881 send WM_GETTEXT messages to windows belonging to its processes */
2882 if (!ClassAtom
|| Child
->pcls
->atomNVClassName
== ClassAtom
)
2884 // FIXME: LARGE_STRING truncated
2885 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2886 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2887 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2888 if(!CheckWindowName
||
2889 (Child
->strName
.Length
< 0xFFFF &&
2890 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2892 Ret
= Child
->head
.h
;
2897 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2905 * Searches a window's children for a window with the specified
2908 * hwndParent = The window whose childs are to be searched.
2910 * HWND_MESSAGE = message-only windows
2912 * hwndChildAfter = Search starts after this child window.
2913 * NULL = start from beginning
2915 * ucClassName = Class name to search for
2916 * Reguired parameter.
2918 * ucWindowName = Window name
2919 * ->Buffer == NULL = don't care
2922 * The HWND of the window if it was found, otherwise NULL
2928 NtUserFindWindowEx(HWND hwndParent
,
2929 HWND hwndChildAfter
,
2930 PUNICODE_STRING ucClassName
,
2931 PUNICODE_STRING ucWindowName
,
2934 PWND Parent
, ChildAfter
;
2935 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2936 HWND Desktop
, Ret
= NULL
;
2937 BOOL DoMessageWnd
= FALSE
;
2938 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2939 DECLARE_RETURN(HWND
);
2941 TRACE("Enter NtUserFindWindowEx\n");
2944 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2948 if (ucClassName
!= NULL
)
2950 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2951 if (ClassName
.Length
!= 0)
2953 ProbeForRead(ClassName
.Buffer
,
2957 else if (!IS_ATOM(ClassName
.Buffer
))
2959 EngSetLastError(ERROR_INVALID_PARAMETER
);
2963 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2966 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
2971 if (ucWindowName
!= NULL
)
2973 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2974 if (WindowName
.Length
!= 0)
2976 ProbeForRead(WindowName
.Buffer
,
2982 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2984 SetLastNtError(_SEH2_GetExceptionCode());
2985 _SEH2_YIELD(RETURN(NULL
));
2989 if (ucClassName
!= NULL
)
2991 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2992 !IS_ATOM(ClassName
.Buffer
))
2994 EngSetLastError(ERROR_INVALID_PARAMETER
);
2997 else if (ClassAtom
== (RTL_ATOM
)0)
2999 /* LastError code was set by IntGetAtomFromStringOrAtom */
3005 Desktop
= IntGetCurrentThreadDesktopWindow();
3007 if(hwndParent
== NULL
)
3009 hwndParent
= Desktop
;
3010 DoMessageWnd
= TRUE
;
3012 else if(hwndParent
== HWND_MESSAGE
)
3014 hwndParent
= IntGetMessageWindow();
3017 if(!(Parent
= UserGetWindowObject(hwndParent
)))
3023 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
3030 if(Parent
->head
.h
== Desktop
)
3033 PWND TopLevelWindow
;
3034 BOOLEAN CheckWindowName
;
3035 BOOLEAN WindowMatches
;
3036 BOOLEAN ClassMatches
;
3038 /* windows searches through all top-level windows if the parent is the desktop
3041 if((List
= IntWinListChildren(Parent
)))
3047 /* skip handles before and including ChildAfter */
3048 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
3052 CheckWindowName
= WindowName
.Buffer
!= 0;
3054 /* search children */
3057 UNICODE_STRING ustr
;
3059 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
3064 /* Do not send WM_GETTEXT messages in the kernel mode version!
3065 The user mode version however calls GetWindowText() which will
3066 send WM_GETTEXT messages to windows belonging to its processes */
3067 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
3068 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
3069 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
3070 WindowMatches
= !CheckWindowName
||
3071 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
3072 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
3073 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
3074 ClassAtom
== TopLevelWindow
->pcls
->atomNVClassName
;
3076 if (WindowMatches
&& ClassMatches
)
3078 Ret
= TopLevelWindow
->head
.h
;
3082 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3084 /* window returns the handle of the top-level window, in case it found
3086 Ret
= TopLevelWindow
->head
.h
;
3091 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3096 TRACE("FindWindowEx: Not Desktop Parent!\n");
3097 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3100 if (Ret
== NULL
&& DoMessageWnd
)
3104 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3106 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3110 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3112 SetLastNtError(_SEH2_GetExceptionCode());
3120 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3129 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3131 PWND WndAncestor
, Parent
;
3133 if (Wnd
->head
.h
== IntGetDesktopWindow())
3142 WndAncestor
= Wnd
->spwndParent
;
3153 if(!(Parent
= WndAncestor
->spwndParent
))
3157 if(IntIsDesktopWindow(Parent
))
3162 WndAncestor
= Parent
;
3173 Parent
= IntGetParent(WndAncestor
);
3180 WndAncestor
= Parent
;
3198 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3200 PWND Window
, Ancestor
;
3201 DECLARE_RETURN(HWND
);
3203 TRACE("Enter NtUserGetAncestor\n");
3204 UserEnterExclusive();
3206 if (!(Window
= UserGetWindowObject(hWnd
)))
3211 Ancestor
= UserGetAncestor(Window
, Type
);
3212 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3214 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3217 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3223 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3225 /* combo state struct */
3239 INT fixedOwnerDrawHeight
;
3240 INT droppedWidth
; /* last two are not used unless set */
3241 INT editHeight
; /* explicitly */
3243 } HEADCOMBO
,*LPHEADCOMBO
;
3245 // Window Extra data container.
3246 typedef struct _WND2CBOX
3250 } WND2CBOX
, *PWND2CBOX
;
3252 #define CBF_BUTTONDOWN 0x0002
3258 NtUserGetComboBoxInfo(
3264 BOOL NotSameppi
= FALSE
;
3266 DECLARE_RETURN(BOOL
);
3268 TRACE("Enter NtUserGetComboBoxInfo\n");
3271 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3277 ProbeForWrite(pcbi
, sizeof(COMBOBOXINFO
), 1);
3279 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3281 SetLastNtError(_SEH2_GetExceptionCode());
3282 _SEH2_YIELD(RETURN(FALSE
));
3286 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3288 EngSetLastError(ERROR_INVALID_PARAMETER
);
3292 // Pass the user pointer, it was already probed.
3293 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3295 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3298 ppi
= PsGetCurrentProcessWin32Process();
3299 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3302 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3307 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3308 pcbi
->rcItem
= lphc
->textRect
;
3309 pcbi
->rcButton
= lphc
->buttonRect
;
3310 pcbi
->stateButton
= 0;
3311 if (lphc
->wState
& CBF_BUTTONDOWN
)
3312 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3313 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3314 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3315 pcbi
->hwndCombo
= lphc
->self
;
3316 pcbi
->hwndItem
= lphc
->hWndEdit
;
3317 pcbi
->hwndList
= lphc
->hWndLBox
;
3319 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3322 SetLastNtError(_SEH2_GetExceptionCode());
3329 if (NotSameppi
) KeDetachProcess();
3330 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3336 //// ReactOS work around! Keep it the sames as in Listbox.c
3338 /* Listbox structure */
3341 HWND self
; /* Our own window handle */
3342 HWND owner
; /* Owner window to send notifications to */
3343 UINT style
; /* Window style */
3344 INT width
; /* Window width */
3345 INT height
; /* Window height */
3346 VOID
*items
; /* Array of items */
3347 INT nb_items
; /* Number of items */
3348 INT top_item
; /* Top visible item */
3349 INT selected_item
; /* Selected item */
3350 INT focus_item
; /* Item that has the focus */
3351 INT anchor_item
; /* Anchor item for extended selection */
3352 INT item_height
; /* Default item height */
3353 INT page_size
; /* Items per listbox page */
3354 INT column_width
; /* Column width for multi-column listboxes */
3357 // Window Extra data container.
3358 typedef struct _WND2LB
3368 NtUserGetListBoxInfo(
3373 BOOL NotSameppi
= FALSE
;
3375 DECLARE_RETURN(DWORD
);
3377 TRACE("Enter NtUserGetListBoxInfo\n");
3380 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3385 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3387 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3390 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3391 ppi
= PsGetCurrentProcessWin32Process();
3392 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3395 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3400 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3401 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3402 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3403 Ret
= descr
->page_size
* descr
->column_width
;
3405 Ret
= descr
->page_size
;
3407 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3410 SetLastNtError(_SEH2_GetExceptionCode());
3417 if (NotSameppi
) KeDetachProcess();
3418 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3426 * The NtUserSetParent function changes the parent window of the specified
3430 * The new parent window and the child window must belong to the same
3431 * application. If the window identified by the hWndChild parameter is
3432 * visible, the system performs the appropriate redrawing and repainting.
3433 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3434 * or WS_POPUP window styles of the window whose parent is being changed.
3441 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3443 DECLARE_RETURN(HWND
);
3445 TRACE("Enter NtUserSetParent\n");
3446 UserEnterExclusive();
3449 Check Parent first from user space, set it here.
3453 hWndNewParent
= IntGetDesktopWindow();
3455 else if (hWndNewParent
== HWND_MESSAGE
)
3457 hWndNewParent
= IntGetMessageWindow();
3460 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3463 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3469 * UserGetShellWindow
3471 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3476 HWND FASTCALL
UserGetShellWindow(VOID
)
3478 PWINSTATION_OBJECT WinStaObject
;
3481 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3487 if (!NT_SUCCESS(Status
))
3489 SetLastNtError(Status
);
3493 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3495 ObDereferenceObject(WinStaObject
);
3500 * NtUserSetShellWindowEx
3502 * This is undocumented function to set global shell window. The global
3503 * shell window has special handling of window position.
3509 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3511 PWINSTATION_OBJECT WinStaObject
;
3512 PWND WndShell
, WndListView
;
3513 DECLARE_RETURN(BOOL
);
3514 USER_REFERENCE_ENTRY Ref
;
3518 TRACE("Enter NtUserSetShellWindowEx\n");
3519 UserEnterExclusive();
3521 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3526 if (!(WndListView
= UserGetWindowObject(hwndListView
)))
3531 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3537 if (!NT_SUCCESS(Status
))
3539 SetLastNtError(Status
);
3544 * Test if we are permitted to change the shell window.
3546 if (WinStaObject
->ShellWindow
)
3548 ObDereferenceObject(WinStaObject
);
3553 * Move shell window into background.
3555 if (hwndListView
&& hwndListView
!= hwndShell
)
3558 * Disabled for now to get Explorer working.
3559 * -- Filip, 01/nov/2003
3562 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3565 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3567 ObDereferenceObject(WinStaObject
);
3572 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3574 ObDereferenceObject(WinStaObject
);
3578 UserRefObjectCo(WndShell
, &Ref
);
3579 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3580 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3582 WinStaObject
->ShellWindow
= hwndShell
;
3583 WinStaObject
->ShellListView
= hwndListView
;
3585 ti
= GetW32ThreadInfo();
3588 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3589 ti
->pDeskInfo
->spwndShell
= WndShell
;
3590 ti
->pDeskInfo
->spwndBkGnd
= WndListView
;
3591 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3594 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3596 UserDerefObjectCo(WndShell
);
3598 ObDereferenceObject(WinStaObject
);
3602 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3607 // Fixes wine Win test_window_styles and todo tests...
3608 static BOOL FASTCALL
3609 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3611 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3613 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3620 co_IntSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
, ULONG Size
, BOOL bAlter
)
3622 PWND Window
, Parent
;
3623 PWINSTATION_OBJECT WindowStation
;
3627 if (!(Window
= UserGetWindowObject(hWnd
)))
3632 if ((INT
)Index
>= 0)
3634 if ((Index
+ Size
) > Window
->cbwndExtra
)
3636 EngSetLastError(ERROR_INVALID_INDEX
);
3641 if (Size
== sizeof(LONG
))
3643 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3644 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = (LONG
)NewValue
;
3649 OldValue
= *((LONG_PTR
*)((PCHAR
)(Window
+ 1) + Index
));
3651 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3653 OldValue = (LONG_PTR)IntSetWindowProc( Wnd, (WNDPROC)NewValue, Ansi);
3654 if (!OldValue) return 0;
3657 *((LONG_PTR
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3664 if (Size
== sizeof(LONG
))
3666 if ((Index
!= GWL_STYLE
) &&
3667 (Index
!= GWL_EXSTYLE
) &&
3668 (Index
!= GWL_ID
) &&
3669 (Index
!= GWL_USERDATA
))
3671 ERR("NtUserSetWindowLong(): Index requires pointer size: %lu\n", Index
);
3672 EngSetLastError(ERROR_INVALID_INDEX
);
3680 case GWL_EXSTYLE
: // LONG
3681 OldValue
= (LONG
) Window
->ExStyle
;
3682 Style
.styleOld
= OldValue
;
3683 Style
.styleNew
= NewValue
;
3685 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3688 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3690 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3693 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3694 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3696 /* WS_EX_WINDOWEDGE depends on some other styles */
3697 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3698 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3700 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3702 if (!(Window
->ExStyle
& WS_EX_LAYERED
))
3704 SetLayeredStatus(Window
, 0);
3707 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3709 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3712 case GWL_STYLE
: // LONG
3713 OldValue
= (LONG
) Window
->style
;
3714 Style
.styleOld
= OldValue
;
3715 Style
.styleNew
= NewValue
;
3718 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3720 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3721 if (UserIsDesktopWindow(Window
->spwndParent
)) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3722 /* WS_MINIMIZE can't be reset */
3723 if (OldValue
& WS_MINIMIZE
) Style
.styleNew
|= WS_MINIMIZE
;
3724 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3725 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3726 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3728 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3730 if ((OldValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3732 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
3734 //// From child to non-child it should be null already.
3735 ERR("IDMenu going null! %d\n",Window
->IDMenu
);
3736 Window
->IDMenu
= 0; // Window->spmenu = 0;
3741 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3743 PMENU pMenu
= UserGetMenuObject(UlongToHandle(Window
->IDMenu
));
3744 Window
->state
&= ~WNDS_HASMENU
;
3747 ERR("IDMenu released 0x%p\n",pMenu
);
3748 // ROS may not hold a lock after setting menu to window. But it should!
3749 //IntReleaseMenuObject(pMenu);
3754 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3756 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3757 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3758 DceResetActiveDCEs( Window
);
3760 Window
->style
= (DWORD
)Style
.styleNew
;
3763 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3766 case GWLP_WNDPROC
: // LONG_PTR
3768 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3769 Window
->fnid
& FNID_FREED
)
3771 EngSetLastError(ERROR_ACCESS_DENIED
);
3774 OldValue
= (LONG_PTR
)IntSetWindowProc(Window
,
3780 case GWLP_HINSTANCE
: // LONG_PTR
3781 OldValue
= (LONG_PTR
) Window
->hModule
;
3782 Window
->hModule
= (HINSTANCE
) NewValue
;
3785 case GWLP_HWNDPARENT
: // LONG_PTR
3786 Parent
= Window
->spwndParent
;
3787 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3788 OldValue
= (LONG_PTR
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3790 OldValue
= (LONG_PTR
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3793 case GWLP_ID
: // LONG
3794 OldValue
= (LONG
) Window
->IDMenu
;
3795 Window
->IDMenu
= (UINT
) NewValue
;
3798 case GWLP_USERDATA
: // LONG or LONG_PTR
3799 OldValue
= Window
->dwUserData
;
3800 Window
->dwUserData
= NewValue
;
3804 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3805 EngSetLastError(ERROR_INVALID_INDEX
);
3815 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3817 return (LONG
)co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG
), FALSE
);
3821 co_UserSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
)
3823 return co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG_PTR
), FALSE
);
3827 * NtUserSetWindowLong
3829 * The NtUserSetWindowLong function changes an attribute of the specified
3830 * window. The function also sets the 32-bit (long) value at the specified
3831 * offset into the extra window memory.
3838 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3842 UserEnterExclusive();
3844 if (hWnd
== IntGetDesktopWindow())
3846 EngSetLastError(STATUS_ACCESS_DENIED
);
3851 ret
= (LONG
)co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG
), FALSE
);
3860 NtUserSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
)
3864 UserEnterExclusive();
3866 if (hWnd
== IntGetDesktopWindow())
3868 EngSetLastError(STATUS_ACCESS_DENIED
);
3873 ret
= co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG_PTR
), FALSE
);
3882 NtUserAlterWindowStyle(HWND hWnd
, DWORD Index
, LONG NewValue
)
3886 UserEnterExclusive();
3888 if (hWnd
== IntGetDesktopWindow())
3890 EngSetLastError(STATUS_ACCESS_DENIED
);
3895 ret
= co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, FALSE
, sizeof(LONG
), TRUE
);
3904 * NtUserSetWindowWord
3906 * Legacy function similar to NtUserSetWindowLong.
3913 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3917 DECLARE_RETURN(WORD
);
3919 TRACE("Enter NtUserSetWindowWord\n");
3920 UserEnterExclusive();
3922 if (hWnd
== IntGetDesktopWindow())
3924 EngSetLastError(STATUS_ACCESS_DENIED
);
3928 if (!(Window
= UserGetWindowObject(hWnd
)))
3937 case GWL_HWNDPARENT
:
3938 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3942 EngSetLastError(ERROR_INVALID_INDEX
);
3947 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3949 EngSetLastError(ERROR_INVALID_PARAMETER
);
3953 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3954 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3959 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3965 QueryWindow based on KJK::Hyperion and James Tabor.
3967 0 = QWUniqueProcessId
3968 1 = QWUniqueThreadId
3971 4 = QWIsHung Implements IsHungAppWindow found
3974 9 = QWKillWindow When I called this with hWnd ==
3975 DesktopWindow, it shutdown the system
3982 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3984 /* Console Leader Process CID Window offsets */
3985 #define GWLP_CONSOLE_LEADER_PID 0
3986 #define GWLP_CONSOLE_LEADER_TID 4
3990 DECLARE_RETURN(UINT
);
3992 TRACE("Enter NtUserQueryWindow\n");
3995 if (!(pWnd
= UserGetWindowObject(hWnd
)))
4002 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
4004 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
4005 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
4007 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
4008 Result
= (DWORD_PTR
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
4012 Result
= (DWORD_PTR
)IntGetWndProcessId(pWnd
);
4017 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
4019 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
4020 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
4022 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
4023 Result
= (DWORD_PTR
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
4027 Result
= (DWORD_PTR
)IntGetWndThreadId(pWnd
);
4032 case QUERY_WINDOW_ACTIVE
:
4033 Result
= (DWORD_PTR
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
4036 case QUERY_WINDOW_FOCUS
:
4037 Result
= (DWORD_PTR
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
4040 case QUERY_WINDOW_ISHUNG
:
4041 Result
= (DWORD_PTR
)MsqIsHung(pWnd
->head
.pti
);
4044 case QUERY_WINDOW_REAL_ID
:
4045 Result
= (DWORD_PTR
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
4048 case QUERY_WINDOW_FOREGROUND
:
4049 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
4060 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
4069 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4071 UNICODE_STRING SafeMessageName
;
4074 DECLARE_RETURN(UINT
);
4076 TRACE("Enter NtUserRegisterWindowMessage\n");
4077 UserEnterExclusive();
4079 if(MessageNameUnsafe
== NULL
)
4081 EngSetLastError(ERROR_INVALID_PARAMETER
);
4085 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4086 if(!NT_SUCCESS(Status
))
4088 SetLastNtError(Status
);
4092 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4093 if (SafeMessageName
.Buffer
)
4094 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4098 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
4107 NtUserSetWindowFNID(HWND hWnd
,
4111 DECLARE_RETURN(BOOL
);
4113 TRACE("Enter NtUserSetWindowFNID\n");
4114 UserEnterExclusive();
4116 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4121 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
4123 EngSetLastError(ERROR_ACCESS_DENIED
);
4127 // From user land we only set these.
4128 if (fnID
!= FNID_DESTROY
)
4130 /* HACK: The minimum should be FNID_BUTTON, but menu code relies on this */
4131 if (fnID
< FNID_FIRST
|| fnID
> FNID_GHOST
||
4134 EngSetLastError(ERROR_INVALID_PARAMETER
);
4143 TRACE("Leave NtUserSetWindowFNID\n");
4149 DefSetText(PWND Wnd
, PCWSTR WindowText
)
4151 UNICODE_STRING UnicodeString
;
4154 RtlInitUnicodeString(&UnicodeString
, WindowText
);
4156 if (UnicodeString
.Length
!= 0)
4158 if (Wnd
->strName
.MaximumLength
> 0 &&
4159 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4161 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4163 Wnd
->strName
.Length
= UnicodeString
.Length
;
4164 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4165 RtlCopyMemory(Wnd
->strName
.Buffer
,
4166 UnicodeString
.Buffer
,
4167 UnicodeString
.Length
);
4172 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4173 buf
= Wnd
->strName
.Buffer
;
4174 Wnd
->strName
.Buffer
= NULL
;
4177 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4180 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4181 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4182 if (Wnd
->strName
.Buffer
!= NULL
)
4184 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4185 RtlCopyMemory(Wnd
->strName
.Buffer
,
4186 UnicodeString
.Buffer
,
4187 UnicodeString
.Length
);
4188 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4189 Wnd
->strName
.Length
= UnicodeString
.Length
;
4193 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4200 Wnd
->strName
.Length
= 0;
4201 if (Wnd
->strName
.Buffer
!= NULL
)
4202 Wnd
->strName
.Buffer
[0] = L
'\0';
4205 // FIXME: HAX! Windows does not do this in here!
4206 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4207 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4208 /* Send shell notifications */
4209 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4211 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) UserHMGetHandle(Wnd
), FALSE
); // FIXME Flashing?
4216 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4223 * Undocumented function that is called from DefWindowProc to set
4230 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4233 LARGE_STRING SafeText
;
4234 UNICODE_STRING UnicodeString
;
4237 TRACE("Enter NtUserDefSetText\n");
4239 if (WindowText
!= NULL
)
4243 SafeText
= ProbeForReadLargeString(WindowText
);
4245 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4248 SetLastNtError(_SEH2_GetExceptionCode());
4258 UserEnterExclusive();
4260 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4266 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4267 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4268 // Now we know what the bAnsi is for.
4269 RtlInitUnicodeString(&UnicodeString
, NULL
);
4270 if (SafeText
.Buffer
)
4275 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4277 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4278 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4280 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4283 SetLastNtError(_SEH2_GetExceptionCode());
4286 if (!Ret
) goto Exit
;
4289 if (UnicodeString
.Length
!= 0)
4291 if (Wnd
->strName
.MaximumLength
> 0 &&
4292 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4294 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4296 Wnd
->strName
.Length
= UnicodeString
.Length
;
4297 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4298 RtlCopyMemory(Wnd
->strName
.Buffer
,
4299 UnicodeString
.Buffer
,
4300 UnicodeString
.Length
);
4305 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4306 buf
= Wnd
->strName
.Buffer
;
4307 Wnd
->strName
.Buffer
= NULL
;
4310 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4313 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4314 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4315 if (Wnd
->strName
.Buffer
!= NULL
)
4317 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4318 RtlCopyMemory(Wnd
->strName
.Buffer
,
4319 UnicodeString
.Buffer
,
4320 UnicodeString
.Length
);
4321 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4322 Wnd
->strName
.Length
= UnicodeString
.Length
;
4326 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4334 Wnd
->strName
.Length
= 0;
4335 if (Wnd
->strName
.Buffer
!= NULL
)
4336 Wnd
->strName
.Buffer
[0] = L
'\0';
4339 // FIXME: HAX! Windows does not do this in here!
4340 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4341 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4342 /* Send shell notifications */
4343 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4345 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4350 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4351 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4357 * NtUserInternalGetWindowText
4364 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4369 DECLARE_RETURN(INT
);
4371 TRACE("Enter NtUserInternalGetWindowText\n");
4374 if(lpString
&& (nMaxCount
<= 1))
4376 EngSetLastError(ERROR_INVALID_PARAMETER
);
4380 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4385 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4388 const WCHAR Terminator
= L
'\0';
4390 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4392 Copy
= min(nMaxCount
- 1, Result
);
4395 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4396 if(!NT_SUCCESS(Status
))
4398 SetLastNtError(Status
);
4404 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4405 if(!NT_SUCCESS(Status
))
4407 SetLastNtError(Status
);
4417 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4427 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4433 // ASSERT(OwnerWnd);
4435 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4437 /* NOTE: Popups are not children */
4438 win_array
= IntWinListOwnedPopups(OwnerWnd
);
4443 while (win_array
[count
])
4445 while (--count
>= 0)
4447 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4449 if (pWnd
->spwndOwner
!= OwnerWnd
)
4454 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4456 /* In Windows, ShowOwnedPopups(TRUE) generates
4457 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4458 * regardless of the state of the owner
4460 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4461 pWnd
->state
&= ~WNDS_HIDDENPOPUP
;
4467 if (pWnd
->style
& WS_VISIBLE
)
4469 /* In Windows, ShowOwnedPopups(FALSE) generates
4470 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4471 * regardless of the state of the owner
4473 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4474 pWnd
->state
|= WNDS_HIDDENPOPUP
;
4479 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4480 TRACE("Leave ShowOwnedPopups\n");