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 IntGetNonChildAncestor(PWND pWnd
)
285 while(pWnd
&& (pWnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
286 pWnd
= pWnd
->spwndParent
;
291 IntIsTopLevelWindow(PWND pWnd
)
293 if ( pWnd
->spwndParent
&&
294 pWnd
->spwndParent
== co_GetDesktopWindow(pWnd
) ) return TRUE
;
299 IntValidateOwnerDepth(PWND Wnd
, PWND Owner
)
304 if ( !Owner
) return gNestedWindowLimit
>= Depth
;
305 if (Owner
== Wnd
) break;
306 Owner
= Owner
->spwndOwner
;
313 IntGetWindow(HWND hWnd
,
319 Wnd
= ValidateHwndNoErr(hWnd
);
327 if (Wnd
->spwndOwner
!= NULL
)
328 FoundWnd
= Wnd
->spwndOwner
;
332 if(Wnd
->spwndParent
!= NULL
)
334 FoundWnd
= Wnd
->spwndParent
;
335 if (FoundWnd
->spwndChild
!= NULL
)
336 FoundWnd
= FoundWnd
->spwndChild
;
340 if (Wnd
->spwndNext
!= NULL
)
341 FoundWnd
= Wnd
->spwndNext
;
345 if (Wnd
->spwndPrev
!= NULL
)
346 FoundWnd
= Wnd
->spwndPrev
;
350 if (Wnd
->spwndChild
!= NULL
)
351 FoundWnd
= Wnd
->spwndChild
;
356 while ( FoundWnd
->spwndNext
!= NULL
)
357 FoundWnd
= FoundWnd
->spwndNext
;
365 if (FoundWnd
!= NULL
)
366 Ret
= UserHMGetHandle(FoundWnd
);
370 DWORD FASTCALL
IntGetWindowContextHelpId( PWND pWnd
)
376 HelpId
= (DWORD
)(DWORD_PTR
)UserGetProp(pWnd
, gpsi
->atomContextHelpIdProp
, TRUE
);
378 pWnd
= IntGetParent(pWnd
);
380 while (pWnd
&& pWnd
->fnid
!= FNID_DESKTOP
);
387 IntRemoveTrackMouseEvent(
390 /***********************************************************************
393 static void IntSendDestroyMsg(HWND hWnd
)
398 ti
= PsGetCurrentThreadWin32Thread();
399 Window
= UserGetWindowObject(hWnd
);
404 * Look whether the focus is within the tree of windows
405 * we will be destroying.
408 if ( ti
->MessageQueue
->spwndActive
== Window
|| // Fixes CORE-106 RegSvr32 exit and return focus to CMD.
409 (ti
->MessageQueue
->spwndActive
== NULL
&& ti
->MessageQueue
== IntGetFocusMessageQueue()) )
411 co_WinPosActivateOtherWindow(Window
);
414 /* Fixes CMD properties closing and returning focus to CMD */
415 if (ti
->MessageQueue
->spwndFocus
== Window
)
417 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
419 co_UserSetFocus(Window
->spwndParent
);
423 co_UserSetFocus(NULL
);
427 if (ti
->MessageQueue
->CaretInfo
.hWnd
== UserHMGetHandle(Window
))
429 co_IntDestroyCaret(ti
);
432 /* If the window being destroyed is currently tracked... */
433 if (ti
->rpdesk
->spwndTrack
== Window
)
435 IntRemoveTrackMouseEvent(ti
->rpdesk
);
439 /* If the window being destroyed is the current clipboard owner... */
440 if (ti
->ppi
->prpwinsta
!= NULL
&& Window
== ti
->ppi
->prpwinsta
->spwndClipOwner
)
442 /* ... make it release the clipboard */
443 UserClipboardRelease(Window
);
446 /* Send the WM_DESTROY to the window */
447 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
450 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
451 * make sure that the window still exists when we come back.
453 if (IntIsWindow(hWnd
))
458 if (!(pWndArray
= IntWinListChildren( Window
))) return;
460 for (i
= 0; pWndArray
[i
]; i
++)
462 if (IntIsWindow( pWndArray
[i
] )) IntSendDestroyMsg( pWndArray
[i
] );
464 ExFreePoolWithTag(pWndArray
, USERTAG_WINDOWLIST
);
468 TRACE("destroyed itself while in WM_DESTROY!\n");
473 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
475 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
479 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
481 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
482 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
485 if (Wnd
->strName
.Buffer
!= NULL
)
487 Wnd
->strName
.Length
= 0;
488 Wnd
->strName
.MaximumLength
= 0;
489 DesktopHeapFree(Wnd
->head
.rpdesk
,
490 Wnd
->strName
.Buffer
);
491 Wnd
->strName
.Buffer
= NULL
;
494 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
495 // WindowObject->hWnd = NULL;
498 /***********************************************************************
501 * Destroy storage associated to a window. "Internals" p.358
503 * This is the "functional" DestroyWindows function i.e. all stuff
504 * done in CreateWindow is undone here and not in DestroyWindow :-P
506 LRESULT
co_UserFreeWindow(PWND Window
,
507 PPROCESSINFO ProcessData
,
508 PTHREADINFO ThreadData
,
509 BOOLEAN SendMessages
)
515 BOOLEAN BelongsToThreadData
;
519 if(Window
->state2
& WNDS2_INDESTROY
)
521 TRACE("Tried to call co_UserFreeWindow() twice\n");
524 Window
->state2
|= WNDS2_INDESTROY
;
525 Window
->style
&= ~WS_VISIBLE
;
526 Window
->head
.pti
->cVisWindows
--;
529 /* remove the window already at this point from the thread window list so we
530 don't get into trouble when destroying the thread windows while we're still
531 in co_UserFreeWindow() */
532 RemoveEntryList(&Window
->ThreadListEntry
);
534 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
536 IntDeRegisterShellHookWindow(UserHMGetHandle(Window
));
538 /* free child windows */
539 Children
= IntWinListChildren(Window
);
542 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
544 if ((Child
= IntGetWindowObject(*ChildHandle
)))
546 if (!IntWndBelongsToThread(Child
, ThreadData
))
548 /* send WM_DESTROY messages to windows not belonging to the same thread */
549 co_IntSendMessage( UserHMGetHandle(Child
), WM_ASYNC_DESTROYWINDOW
, 0, 0 );
552 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
554 UserDereferenceObject(Child
);
557 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
563 * Clear the update region to make sure no WM_PAINT messages will be
564 * generated for this window while processing the WM_NCDESTROY.
566 co_UserRedrawWindow(Window
, NULL
, 0,
567 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
568 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
569 if (BelongsToThreadData
)
570 co_IntSendMessage(UserHMGetHandle(Window
), WM_NCDESTROY
, 0, 0);
573 UserClipboardFreeWindow(Window
);
575 DestroyTimersForWindow(ThreadData
, Window
);
577 /* Unregister hot keys */
578 UnregisterWindowHotKeys(Window
);
580 /* flush the message queue */
581 MsqRemoveWindowMessagesFromQueue(Window
);
583 /* from now on no messages can be sent to this window anymore */
584 Window
->state
|= WNDS_DESTROYED
;
585 Window
->fnid
|= FNID_FREED
;
587 /* don't remove the WINDOWSTATUS_DESTROYING bit */
589 /* reset shell window handles */
590 if (ThreadData
->rpdesk
)
592 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
593 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
595 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
596 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
599 /* Fixes dialog test_focus breakage due to r66237. */
600 if (ThreadData
->MessageQueue
->spwndFocus
== Window
)
601 ThreadData
->MessageQueue
->spwndFocus
= NULL
;
603 if (ThreadData
->MessageQueue
->spwndActive
== Window
)
604 ThreadData
->MessageQueue
->spwndActive
= NULL
;
606 if (ThreadData
->MessageQueue
->spwndCapture
== Window
)
611 //// Now kill those remaining "PAINTING BUG: Thread marked as containing dirty windows" spam!!!
612 if ( Window
->hrgnUpdate
!= NULL
|| Window
->state
& WNDS_INTERNALPAINT
)
614 MsqDecPaintCountQueue(Window
->head
.pti
);
615 if (Window
->hrgnUpdate
> HRGN_WINDOW
&& GreIsHandleValid(Window
->hrgnUpdate
))
617 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
618 GreDeleteObject(Window
->hrgnUpdate
);
620 Window
->hrgnUpdate
= NULL
;
621 Window
->state
&= ~WNDS_INTERNALPAINT
;
624 if (Window
->state
& (WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
))
626 Window
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
);
629 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
631 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
633 TRACE("UFW: IDMenu %p\n",Window
->IDMenu
);
634 IntDestroyMenuObject(Menu
, TRUE
);
638 if (Window
->SystemMenu
639 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
641 IntDestroyMenuObject(Menu
, TRUE
);
642 Window
->SystemMenu
= (HMENU
)0;
645 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
647 IntUnlinkWindow(Window
);
649 if (Window
->PropListItems
)
651 UserRemoveWindowProps(Window
);
652 TRACE("Window->PropListItems %lu\n",Window
->PropListItems
);
653 ASSERT(Window
->PropListItems
==0);
656 UserReferenceObject(Window
);
657 UserMarkObjectDestroy(Window
);
659 IntDestroyScrollBars(Window
);
661 if (Window
->pcls
->atomClassName
== gaGuiConsoleWndClass
)
663 /* Count only console windows manually */
664 co_IntUserManualGuiCheck(FALSE
);
667 /* dereference the class */
668 NT_ASSERT(Window
->head
.pti
!= NULL
);
669 IntDereferenceClass(Window
->pcls
,
670 Window
->head
.pti
->pDeskInfo
,
671 Window
->head
.pti
->ppi
);
674 if (Window
->hrgnClip
)
676 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
677 GreDeleteObject(Window
->hrgnClip
);
678 Window
->hrgnClip
= NULL
;
680 Window
->head
.pti
->cWindows
--;
682 // ASSERT(Window != NULL);
683 UserFreeWindowInfo(Window
->head
.pti
, Window
);
685 UserDereferenceObject(Window
);
686 UserDeleteObject(UserHMGetHandle(Window
), TYPE_WINDOW
);
692 // Same as User32:IntGetWndProc.
695 IntGetWindowProc(PWND pWnd
,
700 WNDPROC gcpd
, Ret
= 0;
702 ASSERT(UserIsEnteredExclusive() == TRUE
);
706 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
708 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
710 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
713 Ret
= GETPFNCLIENTA(i
);
715 Ret
= GETPFNCLIENTW(i
);
721 if (Class
->fnid
== FNID_EDIT
)
722 Ret
= pWnd
->lpfnWndProc
;
725 Ret
= pWnd
->lpfnWndProc
;
727 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
731 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
732 Ret
= GETPFNCLIENTA(Class
->fnid
);
736 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
737 Ret
= GETPFNCLIENTW(Class
->fnid
);
740 if ( Ret
!= pWnd
->lpfnWndProc
)
743 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
746 gcpd
= (WNDPROC
)UserGetCPD(
748 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
751 return (gcpd
? gcpd
: Ret
);
755 IntSetWindowProc(PWND pWnd
,
760 PCALLPROCDATA CallProc
;
762 WNDPROC Ret
, chWndProc
= NULL
;
764 // Retrieve previous window proc.
765 Ret
= IntGetWindowProc(pWnd
, Ansi
);
769 if (IsCallProcHandle(NewWndProc
))
771 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
773 { // Reset new WndProc.
774 NewWndProc
= CallProc
->pfnClientPrevious
;
775 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
776 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
779 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
780 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
782 if (GETPFNCLIENTW(i
) == NewWndProc
)
784 chWndProc
= GETPFNSERVER(i
);
787 if (GETPFNCLIENTA(i
) == NewWndProc
)
789 chWndProc
= GETPFNSERVER(i
);
793 // If match, set/reset to Server Side and clear ansi.
796 pWnd
->lpfnWndProc
= chWndProc
;
797 pWnd
->Unicode
= TRUE
;
798 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
799 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
803 pWnd
->Unicode
= !Ansi
;
804 // Handle the state change in here.
806 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
808 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
810 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
811 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
813 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
815 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
819 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
820 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
824 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
825 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
828 // Now set the new window proc.
829 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
835 /* INTERNAL ******************************************************************/
838 // This fixes a check for children messages that need paint while searching the parents messages!
839 // Fixes wine msg:test_paint_messages:WmParentErasePaint ..
842 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
844 PWND Window
= BaseWindow
;
847 if ( Window
== NULL
|| (Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
850 Window
= Window
->spwndParent
;
852 while(Parent
!= Window
);
857 /* Link the window into siblings list. Children and parent are kept in place. */
861 PWND WndInsertAfter
/* Set to NULL if top sibling */
864 if (Wnd
== WndInsertAfter
)
866 ERR("IntLinkWindow -- Trying to link window 0x%p to itself!!\n", Wnd
);
870 Wnd
->spwndPrev
= WndInsertAfter
;
873 /* Link after WndInsertAfter */
874 ASSERT(Wnd
!= WndInsertAfter
->spwndNext
);
875 Wnd
->spwndNext
= WndInsertAfter
->spwndNext
;
877 Wnd
->spwndNext
->spwndPrev
= Wnd
;
879 ASSERT(Wnd
!= Wnd
->spwndPrev
);
880 Wnd
->spwndPrev
->spwndNext
= Wnd
;
884 /* Link at the top */
885 ASSERT(Wnd
!= Wnd
->spwndParent
->spwndChild
);
886 Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
;
888 Wnd
->spwndNext
->spwndPrev
= Wnd
;
890 Wnd
->spwndParent
->spwndChild
= Wnd
;
895 Note: Wnd->spwndParent can be null if it is the desktop.
897 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
899 if (hWndPrev
== HWND_NOTOPMOST
)
901 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) && (Wnd
->ExStyle2
& WS_EX2_LINKED
))
902 return; /* nothing to do */
903 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
904 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
907 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
909 if (hWndPrev
== HWND_BOTTOM
)
911 /* Link in the bottom of the list */
914 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
915 while (WndInsertAfter
&& WndInsertAfter
->spwndNext
)
917 WndInsertAfter
= WndInsertAfter
->spwndNext
;
920 IntLinkWindow(Wnd
, WndInsertAfter
);
921 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
923 else if (hWndPrev
== HWND_TOPMOST
)
925 /* Link in the top of the list */
926 IntLinkWindow(Wnd
, NULL
);
927 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
929 else if (hWndPrev
== HWND_TOP
)
931 /* Link it after the last topmost window */
932 PWND WndInsertBefore
;
934 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
936 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
938 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
940 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
))
943 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
945 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
948 WndInsertBefore
= WndInsertBefore
->spwndNext
;
952 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
956 /* Link it after hWndPrev */
959 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
960 /* Are we called with an erroneous handle */
961 if (WndInsertAfter
== NULL
)
963 /* Link in a default position */
964 IntLinkHwnd(Wnd
, HWND_TOP
);
968 if (Wnd
== WndInsertAfter
)
969 ERR("IntLinkHwnd -- Trying to link window 0x%p to itself!!\n", Wnd
);
970 IntLinkWindow(Wnd
, WndInsertAfter
);
972 /* Fix the WS_EX_TOPMOST flag */
973 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
975 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
979 if (WndInsertAfter
->spwndNext
&&
980 (WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
))
982 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
986 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
990 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
994 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
997 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
998 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1000 //ERR("ProcessOwnerSwap Old out.\n");
1001 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
1007 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
1010 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1012 //ERR("ProcessOwnerSwap New in.\n");
1013 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1017 // FIXME: System Tray checks.
1021 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1023 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1026 Wnd
= IntGetWindowObject(hWnd
);
1030 WndOldOwner
= Wnd
->spwndOwner
;
1032 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1033 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1035 if (!WndNewOwner
&& hWndNewOwner
)
1037 EngSetLastError(ERROR_INVALID_PARAMETER
);
1042 /* if parent belongs to a different thread and the window isn't */
1043 /* top-level, attach the two threads */
1044 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1046 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1050 Wnd
->spwndOwner
= WndNewOwner
;
1054 Wnd
->spwndOwner
= NULL
;
1059 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1060 EngSetLastError(ERROR_INVALID_PARAMETER
);
1064 UserDereferenceObject(Wnd
);
1069 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1071 PWND WndOldParent
, pWndExam
;
1074 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1077 ASSERT(WndNewParent
);
1078 ASSERT_REFS_CO(Wnd
);
1079 ASSERT_REFS_CO(WndNewParent
);
1081 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1083 EngSetLastError(ERROR_ACCESS_DENIED
);
1087 /* Some applications try to set a child as a parent */
1088 if (IntIsChildWindow(Wnd
, WndNewParent
))
1090 TRACE("IntSetParent try to set a child as a parent.\n");
1091 EngSetLastError( ERROR_INVALID_PARAMETER
);
1095 pWndExam
= WndNewParent
; // Load parent Window to examine.
1096 // Now test for set parent to parent hit.
1099 if (Wnd
== pWndExam
)
1101 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1102 EngSetLastError(ERROR_INVALID_PARAMETER
);
1105 pWndExam
= pWndExam
->spwndParent
;
1109 * Windows hides the window first, then shows it again
1110 * including the WM_SHOWWINDOW messages and all
1112 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1114 /* Window must belong to current process */
1115 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1117 ERR("IntSetParent Window must belong to current process!\n");
1121 WndOldParent
= Wnd
->spwndParent
;
1123 if ( WndOldParent
&&
1124 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1125 pt
.x
= Wnd
->rcWindow
.right
;
1127 pt
.x
= Wnd
->rcWindow
.left
;
1128 pt
.y
= Wnd
->rcWindow
.top
;
1130 IntScreenToClient(WndOldParent
, &pt
);
1132 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1134 if (WndNewParent
!= WndOldParent
)
1136 /* Unlink the window from the siblings list */
1137 IntUnlinkWindow(Wnd
);
1138 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1140 /* Set the new parent */
1141 Wnd
->spwndParent
= WndNewParent
;
1143 if ( Wnd
->style
& WS_CHILD
&&
1145 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1147 ERR("SetParent Top Most from Pop up!\n");
1148 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1151 /* Link the window with its new siblings */
1153 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1154 UserIsDesktopWindow(WndNewParent
) ) ? HWND_TOP
: HWND_TOPMOST
) );
1157 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1158 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1160 Wnd
->style
|= WS_CLIPSIBLINGS
;
1161 DceResetActiveDCEs(Wnd
);
1164 /* if parent belongs to a different thread and the window isn't */
1165 /* top-level, attach the two threads */
1166 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1168 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1170 if (WndOldParent
&& (Wnd
->head
.pti
!= WndOldParent
->head
.pti
))
1172 //ERR("SetParent Old out.\n");
1173 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1176 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1178 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1180 //ERR("SetParent New in.\n");
1181 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1186 if (UserIsMessageWindow(WndOldParent
) || UserIsMessageWindow(WndNewParent
))
1187 swFlags
|= SWP_NOACTIVATE
;
1189 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1191 * SetParent additionally needs to make hwnd the top window
1192 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1193 * WM_WINDOWPOSCHANGED notification messages.
1195 //ERR("IntSetParent SetWindowPos 1\n");
1196 co_WinPosSetWindowPos( Wnd
,
1197 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1198 pt
.x
, pt
.y
, 0, 0, swFlags
);
1199 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1200 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1202 return WndOldParent
;
1206 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1208 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1209 HWND hWndOldParent
= NULL
;
1210 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1212 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1214 EngSetLastError(ERROR_INVALID_PARAMETER
);
1218 if (hWndChild
== IntGetDesktopWindow())
1220 ERR("UserSetParent Access Denied!\n");
1221 EngSetLastError(ERROR_ACCESS_DENIED
);
1227 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1229 ERR("UserSetParent Bad New Parent!\n");
1235 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1241 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1243 ERR("UserSetParent Bad Child!\n");
1247 UserRefObjectCo(Wnd
, &Ref
);
1248 UserRefObjectCo(WndParent
, &ParentRef
);
1249 //ERR("Enter co_IntSetParent\n");
1250 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1251 //ERR("Leave co_IntSetParent\n");
1252 UserDerefObjectCo(WndParent
);
1253 UserDerefObjectCo(Wnd
);
1257 hWndOldParent
= WndOldParent
->head
.h
;
1258 UserDereferenceObject(WndOldParent
);
1261 return( hWndOldParent
);
1264 /* Unlink the window from siblings. Children and parent are kept in place. */
1266 IntUnlinkWindow(PWND Wnd
)
1268 ASSERT(Wnd
!= Wnd
->spwndNext
);
1269 ASSERT(Wnd
!= Wnd
->spwndPrev
);
1272 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1275 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1277 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1278 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1280 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1283 /* FUNCTIONS *****************************************************************/
1286 * As best as I can figure, this function is used by EnumWindows,
1287 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1289 * It's supposed to build a list of HWNDs to return to the caller.
1290 * We can figure out what kind of list by what parameters are
1298 NtUserBuildHwndList(
1311 return ERROR_INVALID_PARAMETER
;
1313 if (hwndParent
|| !dwThreadId
)
1316 PWND Parent
, Window
;
1320 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1322 return ERROR_INVALID_HANDLE
;
1327 Status
= IntValidateDesktopHandle(hDesktop
,
1331 if(!NT_SUCCESS(Status
))
1333 return ERROR_INVALID_HANDLE
;
1336 hwndParent
= Desktop
->DesktopWindow
;
1343 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1344 (Window
= Parent
->spwndChild
))
1346 BOOL bGoDown
= TRUE
;
1348 Status
= STATUS_SUCCESS
;
1353 if(dwCount
++ < *pBufSize
&& pWnd
)
1357 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1358 *pWnd
= Window
->head
.h
;
1361 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1363 Status
= _SEH2_GetExceptionCode();
1366 if(!NT_SUCCESS(Status
))
1368 SetLastNtError(Status
);
1372 if (Window
->spwndChild
&& bChildren
)
1374 Window
= Window
->spwndChild
;
1379 if (Window
->spwndNext
)
1381 Window
= Window
->spwndNext
;
1385 Window
= Window
->spwndParent
;
1386 if (Window
== Parent
)
1395 ObDereferenceObject(Desktop
);
1398 else // Build EnumThreadWindows list!
1401 PTHREADINFO W32Thread
;
1405 Status
= PsLookupThreadByThreadId(UlongToHandle(dwThreadId
), &Thread
);
1406 if (!NT_SUCCESS(Status
))
1408 ERR("Thread Id is not valid!\n");
1409 return ERROR_INVALID_PARAMETER
;
1411 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1413 ObDereferenceObject(Thread
);
1414 TRACE("Tried to enumerate windows of a non gui thread\n");
1415 return ERROR_INVALID_PARAMETER
;
1418 // Do not use Thread link list due to co_UserFreeWindow!!!
1419 // Current = W32Thread->WindowListHead.Flink;
1420 // Fixes Api:CreateWindowEx tests!!!
1421 List
= IntWinListChildren(UserGetDesktopWindow());
1425 for (i
= 0; List
[i
]; i
++)
1427 Window
= ValidateHwndNoErr(List
[i
]);
1428 if (Window
&& Window
->head
.pti
== W32Thread
)
1430 if (dwCount
< *pBufSize
&& pWnd
)
1434 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1435 *pWnd
= Window
->head
.h
;
1438 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1440 Status
= _SEH2_GetExceptionCode();
1443 if (!NT_SUCCESS(Status
))
1445 ERR("Failure to build window list!\n");
1446 SetLastNtError(Status
);
1453 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
1456 ObDereferenceObject(Thread
);
1459 *pBufSize
= dwCount
;
1460 return STATUS_SUCCESS
;
1463 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1465 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1466 !(pWindow
->ExStyle
& WS_EX_NOPARENTNOTIFY
))
1468 if (VerifyWnd(pWindow
->spwndParent
) && !UserIsDesktopWindow(pWindow
->spwndParent
))
1470 USER_REFERENCE_ENTRY Ref
;
1471 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1472 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1474 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1475 (LPARAM
)pWindow
->head
.h
);
1476 UserDerefObjectCo(pWindow
->spwndParent
);
1482 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1484 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1486 /* default positioning for overlapped windows */
1487 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1490 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1492 pMonitor
= UserGetPrimaryMonitor();
1494 /* Check if we don't have a monitor attached yet */
1495 if(pMonitor
== NULL
)
1503 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1505 if (IS_DEFAULT(Cs
->x
))
1507 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1509 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1511 Cs
->x
= ProcessParams
->StartingX
;
1512 Cs
->y
= ProcessParams
->StartingY
;
1516 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1517 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1518 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1519 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1521 /* reset counter and position */
1524 pMonitor
->cWndStack
= 0;
1526 pMonitor
->cWndStack
++;
1530 if (IS_DEFAULT(Cs
->cx
))
1532 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1534 Cs
->cx
= ProcessParams
->CountX
;
1535 Cs
->cy
= ProcessParams
->CountY
;
1539 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1540 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1543 /* neither x nor cx are default. Check the y values .
1544 * In the trace we see Outlook and Outlook Express using
1545 * cy set to CW_USEDEFAULT when opening the address book.
1547 else if (IS_DEFAULT(Cs
->cy
))
1549 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1550 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1555 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1556 if(IS_DEFAULT(Cs
->x
))
1561 if(IS_DEFAULT(Cs
->cx
))
1571 /* Allocates and initializes a window */
1572 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1573 PLARGE_STRING WindowName
,
1578 PDESKTOP pdeskCreated
)
1582 PTHREADINFO pti
= NULL
;
1584 BOOL bUnicodeWindow
;
1586 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1588 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1589 { // Need both here for wine win.c test_CreateWindow.
1590 //if (Cs->hwndParent && ParentWindow)
1591 if (ParentWindow
) // It breaks more tests..... WIP.
1593 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1594 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1595 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1596 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1600 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1602 * Dialog boxes and message boxes do not inherit layout, so you must
1603 * set the layout explicitly.
1605 if ( Class
->fnid
!= FNID_DIALOG
)
1607 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1609 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1615 /* Automatically add WS_EX_WINDOWEDGE */
1616 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1617 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1618 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1619 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1621 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1623 /* Is it a unicode window? */
1624 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1625 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1627 /* Allocate the new window */
1628 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1629 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1633 sizeof(WND
) + Class
->cbwndExtra
);
1640 TRACE("Created window object with handle %p\n", hWnd
);
1642 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1643 { /* HACK: Helper for win32csr/desktopbg.c */
1644 /* If there is no desktop window yet, we must be creating it */
1645 TRACE("CreateWindow setting desktop.\n");
1646 pdeskCreated
->DesktopWindow
= hWnd
;
1647 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1651 * Fill out the structure describing it.
1653 /* Remember, pWnd->head is setup in object.c ... */
1654 pWnd
->spwndParent
= ParentWindow
;
1655 pWnd
->spwndOwner
= OwnerWindow
;
1657 pWnd
->spwndLastActive
= pWnd
;
1658 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1660 pWnd
->hModule
= Cs
->hInstance
;
1661 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1662 pWnd
->ExStyle
= Cs
->dwExStyle
;
1663 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1664 pWnd
->pActCtx
= acbiBuffer
;
1665 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1666 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1668 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1670 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1671 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1674 pWnd
->head
.pti
->cWindows
++;
1676 if (Class
->spicn
&& !Class
->spicnSm
)
1678 HICON IconSmHandle
= NULL
;
1679 if((Class
->spicn
->CURSORF_flags
& (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1680 == (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1682 IconSmHandle
= co_IntCopyImage(
1683 UserHMGetHandle(Class
->spicn
),
1685 UserGetSystemMetrics( SM_CXSMICON
),
1686 UserGetSystemMetrics( SM_CYSMICON
),
1687 LR_COPYFROMRESOURCE
);
1691 /* Retry without copying from resource */
1692 IconSmHandle
= co_IntCopyImage(
1693 UserHMGetHandle(Class
->spicn
),
1695 UserGetSystemMetrics( SM_CXSMICON
),
1696 UserGetSystemMetrics( SM_CYSMICON
),
1702 Class
->spicnSm
= UserGetCurIconObject(IconSmHandle
);
1703 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1707 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1708 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1710 /* BugBoy Comments: Comment below say that System classes are always created
1711 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1712 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1714 No where can I see in code or through testing does the window change back
1715 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1716 see what problems this would cause. */
1718 // Set WndProc from Class.
1719 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1721 // GetWindowProc, test for non server side default classes and set WndProc.
1722 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1726 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1727 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1731 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1732 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1736 // If not an Unicode caller, set Ansi creator bit.
1737 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1739 // Clone Class Ansi/Unicode proc type.
1740 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1742 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1743 pWnd
->Unicode
= FALSE
;
1747 * It seems there can be both an Ansi creator and Unicode Class Window
1748 * WndProc, unless the following overriding conditions occur:
1750 if ( !bUnicodeWindow
&&
1751 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1752 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1753 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1754 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1755 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1756 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1757 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1758 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1759 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1760 { // Override Class and set the window Ansi WndProc.
1761 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1762 pWnd
->Unicode
= FALSE
;
1765 { // Set the window Unicode WndProc.
1766 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1767 pWnd
->Unicode
= TRUE
;
1771 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1772 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1773 Dont understand why it does this. */
1774 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1776 PCALLPROCDATA CallProc
;
1777 CallProc
= CreateCallProc(pWnd
->head
.rpdesk
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1781 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1782 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1786 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1790 InitializeListHead(&pWnd
->PropListHead
);
1791 pWnd
->PropListItems
= 0;
1793 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1795 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1796 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1797 if (pWnd
->strName
.Buffer
== NULL
)
1802 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1803 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1804 pWnd
->strName
.Length
= WindowName
->Length
;
1805 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1808 /* Correct the window style. */
1809 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1811 pWnd
->style
|= WS_CLIPSIBLINGS
;
1812 if (!(pWnd
->style
& WS_POPUP
))
1814 pWnd
->style
|= WS_CAPTION
;
1818 /* WS_EX_WINDOWEDGE depends on some other styles */
1819 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1820 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1821 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1823 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1824 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1825 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1828 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1830 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1831 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1833 /* Set the window menu */
1834 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1838 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1840 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1842 UNICODE_STRING MenuName
;
1845 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1847 MenuName
.Length
= 0;
1848 MenuName
.MaximumLength
= 0;
1849 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1853 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1855 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1856 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1860 pWnd
->IDMenu
= (UINT_PTR
)Cs
->hMenu
;
1863 if ( ParentWindow
&&
1864 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1865 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1867 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1869 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1871 EngSetLastError(ERROR_INVALID_PARAMETER
);
1874 if ( pWnd
->spwndOwner
&&
1875 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1877 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1879 if ( pWnd
->spwndOwner
&&
1880 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1881 pti
!= pWnd
->spwndOwner
->head
.pti
)
1883 //ERR("CreateWindow Owner in.\n");
1884 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1888 /* Insert the window into the thread's window list. */
1889 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1891 /* Handle "CS_CLASSDC", it is tested first. */
1892 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1893 { /* One DCE per class to have CLASS. */
1894 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1896 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1897 { /* Allocate a DCE for this window. */
1898 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1904 ERR("IntCreateWindow Allocation Error.\n");
1905 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1908 UserDereferenceObject(pWnd
);
1916 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1917 PUNICODE_STRING ClassName
,
1918 PLARGE_STRING WindowName
,
1922 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1923 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1924 PWINSTATION_OBJECT WinSta
;
1927 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1928 CBT_CREATEWNDW
* pCbtCreate
;
1930 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1932 DWORD dwShowMode
= SW_SHOW
;
1933 CREATESTRUCTW
*pCsw
= NULL
;
1934 PVOID pszClass
= NULL
, pszName
= NULL
;
1937 /* Get the current window station and reference it */
1938 pti
= GetW32ThreadInfo();
1939 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1941 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1942 return NULL
; // There is nothing to cleanup.
1944 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1945 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1950 /* Get the class and reference it */
1951 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
1954 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
1955 ERR("Failed to find class %wZ\n", ClassName
);
1959 /* Now find the parent and the owner window */
1960 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
1963 if (Cs
->hwndParent
== HWND_MESSAGE
)
1965 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
1967 else if (Cs
->hwndParent
)
1969 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1970 hWndOwner
= Cs
->hwndParent
;
1972 hWndParent
= Cs
->hwndParent
;
1974 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1976 ERR("Cannot create a child window without a parent!\n");
1977 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1978 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1981 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1982 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1984 if (hWndParent
&& !ParentWindow
)
1986 ERR("Got invalid parent window handle\n");
1989 else if (hWndOwner
&& !OwnerWindow
)
1991 ERR("Got invalid owner window handle\n");
1992 ParentWindow
= NULL
;
1998 if (IntIsDesktopWindow(OwnerWindow
)) OwnerWindow
= NULL
;
1999 else if (ParentWindow
&& !IntIsDesktopWindow(ParentWindow
))
2001 ERR("an owned window must be created as top-level\n");
2002 EngSetLastError( STATUS_ACCESS_DENIED
);
2005 else /* owner must be a top-level window */
2007 while ((OwnerWindow
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
&& !IntIsDesktopWindow(OwnerWindow
->spwndParent
))
2008 OwnerWindow
= OwnerWindow
->spwndParent
;
2012 /* Fix the position and the size of the window */
2015 UserRefObjectCo(ParentWindow
, &ParentRef
);
2016 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2019 /* Allocate and initialize the new window */
2020 Window
= IntCreateWindow(Cs
,
2029 ERR("IntCreateWindow failed!\n");
2033 hWnd
= UserHMGetHandle(Window
);
2034 hwndInsertAfter
= HWND_TOP
;
2036 UserRefObjectCo(Window
, &Ref
);
2037 UserDereferenceObject(Window
);
2038 ObDereferenceObject(WinSta
);
2040 //// Check for a hook to eliminate overhead. ////
2041 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2043 // Allocate the calling structures Justin Case this goes Global.
2044 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2045 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2046 if (!pCsw
|| !pCbtCreate
)
2048 ERR("UserHeapAlloc() failed!\n");
2052 /* Fill the new CREATESTRUCTW */
2053 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2054 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2056 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2057 if (!IS_ATOM(ClassName
->Buffer
))
2059 if (Window
->state
& WNDS_ANSICREATOR
)
2061 ANSI_STRING AnsiString
;
2062 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2063 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2066 ERR("UserHeapAlloc() failed!\n");
2069 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2070 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2071 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2075 UNICODE_STRING UnicodeString
;
2076 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2077 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2080 ERR("UserHeapAlloc() failed!\n");
2083 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2084 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2085 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2087 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2089 if (WindowName
->Length
)
2091 UNICODE_STRING Name
;
2092 Name
.Buffer
= WindowName
->Buffer
;
2093 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2094 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2096 if (Window
->state
& WNDS_ANSICREATOR
)
2098 ANSI_STRING AnsiString
;
2099 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2100 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2103 ERR("UserHeapAlloc() failed!\n");
2106 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2107 AnsiString
.Buffer
= (PCHAR
)pszName
;
2108 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2112 UNICODE_STRING UnicodeString
;
2113 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2114 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2117 ERR("UserHeapAlloc() failed!\n");
2120 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2121 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2122 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2124 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2127 pCbtCreate
->lpcs
= pCsw
;
2128 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2130 //// Call the WH_CBT hook ////
2131 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2134 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2137 // Write back changes.
2142 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2145 /* NCCREATE and WM_NCCALCSIZE need the original values */
2146 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2147 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2149 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2151 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2153 Cs
->x
+= ParentWindow
->rcClient
.left
;
2154 Cs
->y
+= ParentWindow
->rcClient
.top
;
2158 /* Send the WM_GETMINMAXINFO message */
2162 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2164 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2165 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2166 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2167 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2168 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2171 Window
->rcWindow
.left
= Cs
->x
;
2172 Window
->rcWindow
.top
= Cs
->y
;
2173 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2174 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2176 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2178 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2179 RECTL_vOffsetRect(&Window->rcWindow,
2180 ParentWindow->rcClient.left,
2181 ParentWindow->rcClient.top);
2184 /* correct child window coordinates if mirroring on parent is enabled */
2185 if (ParentWindow
!= NULL
)
2187 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2188 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2190 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2191 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2195 Window
->rcClient
= Window
->rcWindow
;
2197 /* Link the window */
2198 if (NULL
!= ParentWindow
)
2200 /* Link the window into the siblings list */
2201 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2202 IntLinkHwnd(Window
, HWND_BOTTOM
);
2204 IntLinkHwnd(Window
, hwndInsertAfter
);
2207 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2209 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2210 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2213 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2215 if ( !IntIsTopLevelWindow(Window
) )
2217 if (pti
!= Window
->spwndParent
->head
.pti
)
2219 //ERR("CreateWindow Parent in.\n");
2220 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2225 /* Send the NCCREATE message */
2226 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2229 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2233 /* Send the WM_NCCALCSIZE message */
2236 MaxPos
.x
= Window
->rcWindow
.left
;
2237 MaxPos
.y
= Window
->rcWindow
.top
;
2239 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2240 //rc = Window->rcWindow;
2241 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2242 //Window->rcClient = rc;
2244 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2245 MaxPos
.y
- Window
->rcWindow
.top
);
2248 /* Send the WM_CREATE message. */
2249 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2250 if (Result
== (LRESULT
)-1)
2252 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2256 /* Send the EVENT_OBJECT_CREATE event */
2257 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2259 /* By setting the flag below it can be examined to determine if the window
2260 was created successfully and a valid pwnd was passed back to caller since
2261 from here the function has to succeed. */
2262 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2264 /* Send the WM_SIZE and WM_MOVE messages. */
2265 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2267 co_WinPosSendSizeMove(Window
);
2270 /* Show or maybe minimize or maximize the window. */
2272 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2273 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2276 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2278 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2279 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2280 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2281 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2282 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2285 /* Send the WM_PARENTNOTIFY message */
2286 IntSendParentNotify(Window
, WM_CREATE
);
2288 /* Notify the shell that a new window was created */
2289 if (UserIsDesktopWindow(Window
->spwndParent
) &&
2290 Window
->spwndOwner
== NULL
&&
2291 (Window
->style
& WS_VISIBLE
) &&
2292 (!(Window
->ExStyle
& WS_EX_TOOLWINDOW
) ||
2293 (Window
->ExStyle
& WS_EX_APPWINDOW
)))
2295 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2298 /* Initialize and show the window's scrollbars */
2299 if (Window
->style
& WS_VSCROLL
)
2301 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2303 if (Window
->style
& WS_HSCROLL
)
2305 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2308 /* Show the new window */
2309 if (Cs
->style
& WS_VISIBLE
)
2311 if (Window
->style
& WS_MAXIMIZE
)
2312 dwShowMode
= SW_SHOW
;
2313 else if (Window
->style
& WS_MINIMIZE
)
2314 dwShowMode
= SW_SHOWMINIMIZED
;
2316 co_WinPosShowWindow(Window
, dwShowMode
);
2318 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2320 ASSERT(ParentWindow
);
2323 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2324 /* ShowWindow won't activate child windows */
2325 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2329 if (Class
->atomClassName
== gaGuiConsoleWndClass
)
2331 /* Count only console windows manually */
2332 co_IntUserManualGuiCheck(TRUE
);
2335 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2341 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2342 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2344 co_UserDestroyWindow(Window
);
2346 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2349 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2350 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2351 if (pszName
) UserHeapFree(pszName
);
2352 if (pszClass
) UserHeapFree(pszClass
);
2356 UserDerefObjectCo(Window
);
2358 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2360 // See CORE-13717, not setting error on success.
2362 EngSetLastError(ERROR_SUCCESS
);
2369 ProbeAndCaptureLargeString(
2370 OUT PLARGE_STRING plstrSafe
,
2371 IN PLARGE_STRING plstrUnsafe
)
2373 LARGE_STRING lstrTemp
;
2374 PVOID pvBuffer
= NULL
;
2378 /* Probe and copy the string */
2379 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2380 lstrTemp
= *plstrUnsafe
;
2382 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2385 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2389 if (lstrTemp
.Length
!= 0)
2391 /* Allocate a buffer from paged pool */
2392 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2395 return STATUS_NO_MEMORY
;
2400 /* Probe and copy the buffer */
2401 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2402 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2404 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2406 /* Cleanup and fail */
2407 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2408 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2413 /* Set the output string */
2414 plstrSafe
->Buffer
= pvBuffer
;
2415 plstrSafe
->Length
= lstrTemp
.Length
;
2416 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2418 return STATUS_SUCCESS
;
2422 * \todo Allow passing plstrClassName as ANSI.
2426 NtUserCreateWindowEx(
2428 PLARGE_STRING plstrClassName
,
2429 PLARGE_STRING plstrClsVersion
,
2430 PLARGE_STRING plstrWindowName
,
2438 HINSTANCE hInstance
,
2444 LARGE_STRING lstrWindowName
;
2445 LARGE_STRING lstrClassName
;
2446 LARGE_STRING lstrClsVersion
;
2447 UNICODE_STRING ustrClassName
;
2448 UNICODE_STRING ustrClsVersion
;
2453 lstrWindowName
.Buffer
= NULL
;
2454 lstrClassName
.Buffer
= NULL
;
2455 lstrClsVersion
.Buffer
= NULL
;
2457 ASSERT(plstrWindowName
);
2459 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2461 /* check hMenu is valid handle */
2462 if (hMenu
&& !UserGetMenuObject(hMenu
))
2464 ERR("NtUserCreateWindowEx: Got an invalid menu handle!\n");
2465 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
2470 /* Copy the window name to kernel mode */
2471 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2472 if (!NT_SUCCESS(Status
))
2474 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2475 SetLastNtError(Status
);
2479 plstrWindowName
= &lstrWindowName
;
2481 /* Check if the class is an atom */
2482 if (IS_ATOM(plstrClassName
))
2484 /* It is, pass the atom in the UNICODE_STRING */
2485 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2486 ustrClassName
.Length
= 0;
2487 ustrClassName
.MaximumLength
= 0;
2491 /* It's not, capture the class name */
2492 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2493 if (!NT_SUCCESS(Status
))
2495 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2496 /* Set last error, cleanup and return */
2497 SetLastNtError(Status
);
2501 /* We pass it on as a UNICODE_STRING */
2502 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2503 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2504 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2507 /* Check if the class version is an atom */
2508 if (IS_ATOM(plstrClsVersion
))
2510 /* It is, pass the atom in the UNICODE_STRING */
2511 ustrClsVersion
.Buffer
= (PVOID
)plstrClsVersion
;
2512 ustrClsVersion
.Length
= 0;
2513 ustrClsVersion
.MaximumLength
= 0;
2517 /* It's not, capture the class name */
2518 Status
= ProbeAndCaptureLargeString(&lstrClsVersion
, plstrClsVersion
);
2519 if (!NT_SUCCESS(Status
))
2521 ERR("NtUserCreateWindowEx: failed to capture plstrClsVersion\n");
2522 /* Set last error, cleanup and return */
2523 SetLastNtError(Status
);
2527 /* We pass it on as a UNICODE_STRING */
2528 ustrClsVersion
.Buffer
= lstrClsVersion
.Buffer
;
2529 ustrClsVersion
.Length
= (USHORT
)min(lstrClsVersion
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2530 ustrClsVersion
.MaximumLength
= (USHORT
)min(lstrClsVersion
.MaximumLength
, MAXUSHORT
);
2533 /* Fill the CREATESTRUCTW */
2534 /* we will keep here the original parameters */
2536 Cs
.lpCreateParams
= lpParam
;
2537 Cs
.hInstance
= hInstance
;
2539 Cs
.hwndParent
= hWndParent
;
2544 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2545 Cs
.lpszClass
= ustrClassName
.Buffer
;
2546 Cs
.dwExStyle
= dwExStyle
;
2548 UserEnterExclusive();
2550 /* Call the internal function */
2551 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClsVersion
, plstrWindowName
, acbiBuffer
);
2555 ERR("co_UserCreateWindowEx failed!\n");
2557 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2562 if (lstrWindowName
.Buffer
)
2564 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2566 if (lstrClassName
.Buffer
)
2568 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2570 if (lstrClsVersion
.Buffer
)
2572 ExFreePoolWithTag(lstrClsVersion
.Buffer
, TAG_STRING
);
2579 BOOLEAN
co_UserDestroyWindow(PVOID Object
)
2585 PWND Window
= Object
;
2587 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2589 hWnd
= Window
->head
.h
;
2590 ti
= PsGetCurrentThreadWin32Thread();
2592 TRACE("co_UserDestroyWindow \n");
2594 /* Check for owner thread */
2595 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2597 /* Check if we are destroying the desktop window */
2598 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2600 EngSetLastError(ERROR_ACCESS_DENIED
);
2605 /* If window was created successfully and it is hooked */
2606 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2608 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2610 ERR("Destroy Window WH_CBT Call Hook return!\n");
2615 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2617 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2619 if (Window
->spwndOwner
)
2621 //ERR("DestroyWindow Owner out.\n");
2622 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2627 /* Inform the parent */
2628 if (Window
->style
& WS_CHILD
)
2630 IntSendParentNotify(Window
, WM_DESTROY
);
2633 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
2635 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
2638 /* Hide the window */
2639 if (Window
->style
& WS_VISIBLE
)
2641 if (Window
->style
& WS_CHILD
)
2643 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
2644 co_WinPosShowWindow(Window
, SW_HIDE
);
2648 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2652 // Adjust last active.
2653 if ((pwndTemp
= Window
->spwndOwner
))
2655 while (pwndTemp
->spwndOwner
)
2656 pwndTemp
= pwndTemp
->spwndOwner
;
2658 if (pwndTemp
->spwndLastActive
== Window
)
2659 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2662 if (Window
->spwndParent
&& IntIsWindow(UserHMGetHandle(Window
)))
2664 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2666 if (!IntIsTopLevelWindow(Window
))
2668 //ERR("DestroyWindow Parent out.\n");
2669 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2674 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2675 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2676 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2677 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2678 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2679 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2680 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2681 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2684 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2687 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2689 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2691 ERR("Destroying the ShellWindow!\n");
2692 ti
->pDeskInfo
->hShellWindow
= NULL
;
2696 IntEngWindowChanged(Window
, WOC_DELETE
);
2698 if (!IntIsWindow(UserHMGetHandle(Window
)))
2703 /* Recursively destroy owned windows */
2705 if (! (Window
->style
& WS_CHILD
))
2709 BOOL GotOne
= FALSE
;
2712 PWND Child
, Desktop
;
2714 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2715 UserGetWindowObject(IntGetDesktopWindow());
2716 Children
= IntWinListChildren(Desktop
);
2720 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2722 Child
= UserGetWindowObject(*ChildHandle
);
2725 if (Child
->spwndOwner
!= Window
)
2730 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2732 USER_REFERENCE_ENTRY ChildRef
;
2733 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2734 co_UserDestroyWindow(Child
);
2735 UserDerefObjectCo(Child
); // Temp HACK?
2741 if (Child
->spwndOwner
!= NULL
)
2743 Child
->spwndOwner
= NULL
;
2747 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2756 /* Generate mouse move message for the next window */
2757 msg
.message
= WM_MOUSEMOVE
;
2758 msg
.wParam
= UserGetMouseButtonsState();
2759 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2760 msg
.pt
= gpsi
->ptCursor
;
2761 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2763 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2765 /* Send destroy messages */
2766 IntSendDestroyMsg(UserHMGetHandle(Window
));
2768 if (!IntIsWindow(UserHMGetHandle(Window
)))
2773 /* Destroy the window storage */
2774 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2784 NtUserDestroyWindow(HWND Wnd
)
2787 DECLARE_RETURN(BOOLEAN
);
2789 USER_REFERENCE_ENTRY Ref
;
2791 TRACE("Enter NtUserDestroyWindow\n");
2792 UserEnterExclusive();
2794 if (!(Window
= UserGetWindowObject(Wnd
)))
2799 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2800 ret
= co_UserDestroyWindow(Window
);
2801 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2806 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2812 static HWND FASTCALL
2813 IntFindWindow(PWND Parent
,
2816 PUNICODE_STRING WindowName
)
2818 BOOL CheckWindowName
;
2821 UNICODE_STRING CurrentWindowName
;
2825 CheckWindowName
= WindowName
->Buffer
!= 0;
2827 if((List
= IntWinListChildren(Parent
)))
2832 /* skip handles before and including ChildAfter */
2833 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2837 /* search children */
2841 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2846 /* Do not send WM_GETTEXT messages in the kernel mode version!
2847 The user mode version however calls GetWindowText() which will
2848 send WM_GETTEXT messages to windows belonging to its processes */
2849 if (!ClassAtom
|| Child
->pcls
->atomNVClassName
== ClassAtom
)
2851 // FIXME: LARGE_STRING truncated
2852 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2853 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2854 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2855 if(!CheckWindowName
||
2856 (Child
->strName
.Length
< 0xFFFF &&
2857 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2859 Ret
= Child
->head
.h
;
2864 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2872 * Searches a window's children for a window with the specified
2875 * hwndParent = The window whose childs are to be searched.
2877 * HWND_MESSAGE = message-only windows
2879 * hwndChildAfter = Search starts after this child window.
2880 * NULL = start from beginning
2882 * ucClassName = Class name to search for
2883 * Reguired parameter.
2885 * ucWindowName = Window name
2886 * ->Buffer == NULL = don't care
2889 * The HWND of the window if it was found, otherwise NULL
2895 NtUserFindWindowEx(HWND hwndParent
,
2896 HWND hwndChildAfter
,
2897 PUNICODE_STRING ucClassName
,
2898 PUNICODE_STRING ucWindowName
,
2901 PWND Parent
, ChildAfter
;
2902 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2903 HWND Desktop
, Ret
= NULL
;
2904 BOOL DoMessageWnd
= FALSE
;
2905 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2906 DECLARE_RETURN(HWND
);
2908 TRACE("Enter NtUserFindWindowEx\n");
2911 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2915 if (ucClassName
!= NULL
)
2917 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2918 if (ClassName
.Length
!= 0)
2920 ProbeForRead(ClassName
.Buffer
,
2924 else if (!IS_ATOM(ClassName
.Buffer
))
2926 EngSetLastError(ERROR_INVALID_PARAMETER
);
2930 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2933 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
2938 if (ucWindowName
!= NULL
)
2940 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2941 if (WindowName
.Length
!= 0)
2943 ProbeForRead(WindowName
.Buffer
,
2949 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2951 SetLastNtError(_SEH2_GetExceptionCode());
2952 _SEH2_YIELD(RETURN(NULL
));
2956 if (ucClassName
!= NULL
)
2958 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2959 !IS_ATOM(ClassName
.Buffer
))
2961 EngSetLastError(ERROR_INVALID_PARAMETER
);
2964 else if (ClassAtom
== (RTL_ATOM
)0)
2966 /* LastError code was set by IntGetAtomFromStringOrAtom */
2972 Desktop
= IntGetCurrentThreadDesktopWindow();
2974 if(hwndParent
== NULL
)
2976 hwndParent
= Desktop
;
2977 DoMessageWnd
= TRUE
;
2979 else if(hwndParent
== HWND_MESSAGE
)
2981 hwndParent
= IntGetMessageWindow();
2984 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2990 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2997 if(Parent
->head
.h
== Desktop
)
3000 PWND TopLevelWindow
;
3001 BOOLEAN CheckWindowName
;
3002 BOOLEAN WindowMatches
;
3003 BOOLEAN ClassMatches
;
3005 /* windows searches through all top-level windows if the parent is the desktop
3008 if((List
= IntWinListChildren(Parent
)))
3014 /* skip handles before and including ChildAfter */
3015 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
3019 CheckWindowName
= WindowName
.Buffer
!= 0;
3021 /* search children */
3024 UNICODE_STRING ustr
;
3026 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
3031 /* Do not send WM_GETTEXT messages in the kernel mode version!
3032 The user mode version however calls GetWindowText() which will
3033 send WM_GETTEXT messages to windows belonging to its processes */
3034 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
3035 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
3036 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
3037 WindowMatches
= !CheckWindowName
||
3038 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
3039 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
3040 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
3041 ClassAtom
== TopLevelWindow
->pcls
->atomNVClassName
;
3043 if (WindowMatches
&& ClassMatches
)
3045 Ret
= TopLevelWindow
->head
.h
;
3049 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3051 /* window returns the handle of the top-level window, in case it found
3053 Ret
= TopLevelWindow
->head
.h
;
3058 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3063 TRACE("FindWindowEx: Not Desktop Parent!\n");
3064 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3067 if (Ret
== NULL
&& DoMessageWnd
)
3071 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3073 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3077 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3079 SetLastNtError(_SEH2_GetExceptionCode());
3087 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3096 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3098 PWND WndAncestor
, Parent
;
3100 if (Wnd
->head
.h
== IntGetDesktopWindow())
3109 WndAncestor
= Wnd
->spwndParent
;
3120 if(!(Parent
= WndAncestor
->spwndParent
))
3124 if(IntIsDesktopWindow(Parent
))
3129 WndAncestor
= Parent
;
3140 Parent
= IntGetParent(WndAncestor
);
3147 WndAncestor
= Parent
;
3165 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3167 PWND Window
, Ancestor
;
3168 DECLARE_RETURN(HWND
);
3170 TRACE("Enter NtUserGetAncestor\n");
3171 UserEnterExclusive();
3173 if (!(Window
= UserGetWindowObject(hWnd
)))
3178 Ancestor
= UserGetAncestor(Window
, Type
);
3179 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3181 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3184 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3190 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3192 /* combo state struct */
3206 INT fixedOwnerDrawHeight
;
3207 INT droppedWidth
; /* last two are not used unless set */
3208 INT editHeight
; /* explicitly */
3210 } HEADCOMBO
,*LPHEADCOMBO
;
3212 // Window Extra data container.
3213 typedef struct _WND2CBOX
3217 } WND2CBOX
, *PWND2CBOX
;
3219 #define CBF_BUTTONDOWN 0x0002
3225 NtUserGetComboBoxInfo(
3231 BOOL NotSameppi
= FALSE
;
3233 DECLARE_RETURN(BOOL
);
3235 TRACE("Enter NtUserGetComboBoxInfo\n");
3238 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3244 ProbeForWrite(pcbi
, sizeof(COMBOBOXINFO
), 1);
3246 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3248 SetLastNtError(_SEH2_GetExceptionCode());
3249 _SEH2_YIELD(RETURN(FALSE
));
3253 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3255 EngSetLastError(ERROR_INVALID_PARAMETER
);
3259 // Pass the user pointer, it was already probed.
3260 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3262 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3265 ppi
= PsGetCurrentProcessWin32Process();
3266 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3269 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3274 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3275 pcbi
->rcItem
= lphc
->textRect
;
3276 pcbi
->rcButton
= lphc
->buttonRect
;
3277 pcbi
->stateButton
= 0;
3278 if (lphc
->wState
& CBF_BUTTONDOWN
)
3279 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3280 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3281 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3282 pcbi
->hwndCombo
= lphc
->self
;
3283 pcbi
->hwndItem
= lphc
->hWndEdit
;
3284 pcbi
->hwndList
= lphc
->hWndLBox
;
3286 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3289 SetLastNtError(_SEH2_GetExceptionCode());
3296 if (NotSameppi
) KeDetachProcess();
3297 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3303 //// ReactOS work around! Keep it the sames as in Listbox.c
3305 /* Listbox structure */
3308 HWND self
; /* Our own window handle */
3309 HWND owner
; /* Owner window to send notifications to */
3310 UINT style
; /* Window style */
3311 INT width
; /* Window width */
3312 INT height
; /* Window height */
3313 VOID
*items
; /* Array of items */
3314 INT nb_items
; /* Number of items */
3315 INT top_item
; /* Top visible item */
3316 INT selected_item
; /* Selected item */
3317 INT focus_item
; /* Item that has the focus */
3318 INT anchor_item
; /* Anchor item for extended selection */
3319 INT item_height
; /* Default item height */
3320 INT page_size
; /* Items per listbox page */
3321 INT column_width
; /* Column width for multi-column listboxes */
3324 // Window Extra data container.
3325 typedef struct _WND2LB
3335 NtUserGetListBoxInfo(
3340 BOOL NotSameppi
= FALSE
;
3342 DECLARE_RETURN(DWORD
);
3344 TRACE("Enter NtUserGetListBoxInfo\n");
3347 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3352 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3354 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3357 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3358 ppi
= PsGetCurrentProcessWin32Process();
3359 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3362 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3367 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3368 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3369 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3370 Ret
= descr
->page_size
* descr
->column_width
;
3372 Ret
= descr
->page_size
;
3374 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3377 SetLastNtError(_SEH2_GetExceptionCode());
3384 if (NotSameppi
) KeDetachProcess();
3385 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3393 * The NtUserSetParent function changes the parent window of the specified
3397 * The new parent window and the child window must belong to the same
3398 * application. If the window identified by the hWndChild parameter is
3399 * visible, the system performs the appropriate redrawing and repainting.
3400 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3401 * or WS_POPUP window styles of the window whose parent is being changed.
3408 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3410 DECLARE_RETURN(HWND
);
3412 TRACE("Enter NtUserSetParent\n");
3413 UserEnterExclusive();
3416 Check Parent first from user space, set it here.
3420 hWndNewParent
= IntGetDesktopWindow();
3422 else if (hWndNewParent
== HWND_MESSAGE
)
3424 hWndNewParent
= IntGetMessageWindow();
3427 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3430 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3436 * UserGetShellWindow
3438 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3443 HWND FASTCALL
UserGetShellWindow(VOID
)
3445 PWINSTATION_OBJECT WinStaObject
;
3448 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3454 if (!NT_SUCCESS(Status
))
3456 SetLastNtError(Status
);
3460 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3462 ObDereferenceObject(WinStaObject
);
3467 * NtUserSetShellWindowEx
3469 * This is undocumented function to set global shell window. The global
3470 * shell window has special handling of window position.
3476 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3478 PWINSTATION_OBJECT WinStaObject
;
3479 PWND WndShell
, WndListView
;
3480 DECLARE_RETURN(BOOL
);
3481 USER_REFERENCE_ENTRY Ref
;
3485 TRACE("Enter NtUserSetShellWindowEx\n");
3486 UserEnterExclusive();
3488 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3493 if (!(WndListView
= UserGetWindowObject(hwndListView
)))
3498 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3504 if (!NT_SUCCESS(Status
))
3506 SetLastNtError(Status
);
3511 * Test if we are permitted to change the shell window.
3513 if (WinStaObject
->ShellWindow
)
3515 ObDereferenceObject(WinStaObject
);
3520 * Move shell window into background.
3522 if (hwndListView
&& hwndListView
!= hwndShell
)
3525 * Disabled for now to get Explorer working.
3526 * -- Filip, 01/nov/2003
3529 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3532 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3534 ObDereferenceObject(WinStaObject
);
3539 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3541 ObDereferenceObject(WinStaObject
);
3545 UserRefObjectCo(WndShell
, &Ref
);
3546 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3547 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3549 WinStaObject
->ShellWindow
= hwndShell
;
3550 WinStaObject
->ShellListView
= hwndListView
;
3552 ti
= GetW32ThreadInfo();
3555 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3556 ti
->pDeskInfo
->spwndShell
= WndShell
;
3557 ti
->pDeskInfo
->spwndBkGnd
= WndListView
;
3558 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3561 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3563 UserDerefObjectCo(WndShell
);
3565 ObDereferenceObject(WinStaObject
);
3569 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3574 // Fixes wine Win test_window_styles and todo tests...
3575 static BOOL FASTCALL
3576 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3578 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3580 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3587 co_IntSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
, ULONG Size
, BOOL bAlter
)
3589 PWND Window
, Parent
;
3590 PWINSTATION_OBJECT WindowStation
;
3594 if (!(Window
= UserGetWindowObject(hWnd
)))
3599 if ((INT
)Index
>= 0)
3601 if ((Index
+ Size
) > Window
->cbwndExtra
)
3603 EngSetLastError(ERROR_INVALID_INDEX
);
3608 if (Size
== sizeof(LONG
))
3610 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3611 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = (LONG
)NewValue
;
3616 OldValue
= *((LONG_PTR
*)((PCHAR
)(Window
+ 1) + Index
));
3618 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3620 OldValue = (LONG_PTR)IntSetWindowProc( Wnd, (WNDPROC)NewValue, Ansi);
3621 if (!OldValue) return 0;
3624 *((LONG_PTR
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3631 if (Size
== sizeof(LONG
))
3633 if ((Index
!= GWL_STYLE
) &&
3634 (Index
!= GWL_EXSTYLE
) &&
3635 (Index
!= GWL_ID
) &&
3636 (Index
!= GWL_USERDATA
))
3638 ERR("NtUserSetWindowLong(): Index requires pointer size: %lu\n", Index
);
3639 EngSetLastError(ERROR_INVALID_INDEX
);
3647 case GWL_EXSTYLE
: // LONG
3648 OldValue
= (LONG
) Window
->ExStyle
;
3649 Style
.styleOld
= OldValue
;
3650 Style
.styleNew
= NewValue
;
3652 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3655 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3657 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3660 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3661 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3663 /* WS_EX_WINDOWEDGE depends on some other styles */
3664 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3665 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3667 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3669 if (!(Window
->ExStyle
& WS_EX_LAYERED
))
3671 SetLayeredStatus(Window
, 0);
3674 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3676 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3679 case GWL_STYLE
: // LONG
3680 OldValue
= (LONG
) Window
->style
;
3681 Style
.styleOld
= OldValue
;
3682 Style
.styleNew
= NewValue
;
3685 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3687 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3688 if (UserIsDesktopWindow(Window
->spwndParent
)) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3689 /* WS_MINIMIZE can't be reset */
3690 if (OldValue
& WS_MINIMIZE
) Style
.styleNew
|= WS_MINIMIZE
;
3691 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3692 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3693 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3695 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3697 if ((OldValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3699 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
3701 //// From child to non-child it should be null already.
3702 ERR("IDMenu going null! %d\n",Window
->IDMenu
);
3703 Window
->IDMenu
= 0; // Window->spmenu = 0;
3708 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3710 PMENU pMenu
= UserGetMenuObject(UlongToHandle(Window
->IDMenu
));
3711 Window
->state
&= ~WNDS_HASMENU
;
3714 ERR("IDMenu released 0x%p\n",pMenu
);
3715 // ROS may not hold a lock after setting menu to window. But it should!
3716 //IntReleaseMenuObject(pMenu);
3721 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3723 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3724 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3725 DceResetActiveDCEs( Window
);
3727 Window
->style
= (DWORD
)Style
.styleNew
;
3730 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3733 case GWLP_WNDPROC
: // LONG_PTR
3735 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3736 Window
->fnid
& FNID_FREED
)
3738 EngSetLastError(ERROR_ACCESS_DENIED
);
3741 OldValue
= (LONG_PTR
)IntSetWindowProc(Window
,
3747 case GWLP_HINSTANCE
: // LONG_PTR
3748 OldValue
= (LONG_PTR
) Window
->hModule
;
3749 Window
->hModule
= (HINSTANCE
) NewValue
;
3752 case GWLP_HWNDPARENT
: // LONG_PTR
3753 Parent
= Window
->spwndParent
;
3754 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3755 OldValue
= (LONG_PTR
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3757 OldValue
= (LONG_PTR
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3760 case GWLP_ID
: // LONG
3761 OldValue
= (LONG
) Window
->IDMenu
;
3762 Window
->IDMenu
= (UINT
) NewValue
;
3765 case GWLP_USERDATA
: // LONG or LONG_PTR
3766 OldValue
= Window
->dwUserData
;
3767 Window
->dwUserData
= NewValue
;
3771 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3772 EngSetLastError(ERROR_INVALID_INDEX
);
3782 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3784 return (LONG
)co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG
), FALSE
);
3788 co_UserSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
)
3790 return co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG_PTR
), FALSE
);
3794 * NtUserSetWindowLong
3796 * The NtUserSetWindowLong function changes an attribute of the specified
3797 * window. The function also sets the 32-bit (long) value at the specified
3798 * offset into the extra window memory.
3805 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3809 UserEnterExclusive();
3811 if (hWnd
== IntGetDesktopWindow())
3813 EngSetLastError(STATUS_ACCESS_DENIED
);
3818 ret
= (LONG
)co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG
), FALSE
);
3827 NtUserSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
)
3831 UserEnterExclusive();
3833 if (hWnd
== IntGetDesktopWindow())
3835 EngSetLastError(STATUS_ACCESS_DENIED
);
3840 ret
= co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG_PTR
), FALSE
);
3849 NtUserAlterWindowStyle(HWND hWnd
, DWORD Index
, LONG NewValue
)
3853 UserEnterExclusive();
3855 if (hWnd
== IntGetDesktopWindow())
3857 EngSetLastError(STATUS_ACCESS_DENIED
);
3862 ret
= co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, FALSE
, sizeof(LONG
), TRUE
);
3871 * NtUserSetWindowWord
3873 * Legacy function similar to NtUserSetWindowLong.
3880 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3884 DECLARE_RETURN(WORD
);
3886 TRACE("Enter NtUserSetWindowWord\n");
3887 UserEnterExclusive();
3889 if (hWnd
== IntGetDesktopWindow())
3891 EngSetLastError(STATUS_ACCESS_DENIED
);
3895 if (!(Window
= UserGetWindowObject(hWnd
)))
3904 case GWL_HWNDPARENT
:
3905 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3909 EngSetLastError(ERROR_INVALID_INDEX
);
3914 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3916 EngSetLastError(ERROR_INVALID_PARAMETER
);
3920 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3921 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3926 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3932 QueryWindow based on KJK::Hyperion and James Tabor.
3934 0 = QWUniqueProcessId
3935 1 = QWUniqueThreadId
3938 4 = QWIsHung Implements IsHungAppWindow found
3941 9 = QWKillWindow When I called this with hWnd ==
3942 DesktopWindow, it shutdown the system
3949 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3951 /* Console Leader Process CID Window offsets */
3952 #define GWLP_CONSOLE_LEADER_PID 0
3953 #define GWLP_CONSOLE_LEADER_TID 4
3957 DECLARE_RETURN(UINT
);
3959 TRACE("Enter NtUserQueryWindow\n");
3962 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3969 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3971 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3972 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3974 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
3975 Result
= (DWORD_PTR
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
3979 Result
= (DWORD_PTR
)IntGetWndProcessId(pWnd
);
3984 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3986 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3987 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3989 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
3990 Result
= (DWORD_PTR
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
3994 Result
= (DWORD_PTR
)IntGetWndThreadId(pWnd
);
3999 case QUERY_WINDOW_ACTIVE
:
4000 Result
= (DWORD_PTR
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
4003 case QUERY_WINDOW_FOCUS
:
4004 Result
= (DWORD_PTR
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
4007 case QUERY_WINDOW_ISHUNG
:
4008 Result
= (DWORD_PTR
)MsqIsHung(pWnd
->head
.pti
);
4011 case QUERY_WINDOW_REAL_ID
:
4012 Result
= (DWORD_PTR
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
4015 case QUERY_WINDOW_FOREGROUND
:
4016 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
4027 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
4036 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4038 UNICODE_STRING SafeMessageName
;
4041 DECLARE_RETURN(UINT
);
4043 TRACE("Enter NtUserRegisterWindowMessage\n");
4044 UserEnterExclusive();
4046 if(MessageNameUnsafe
== NULL
)
4048 EngSetLastError(ERROR_INVALID_PARAMETER
);
4052 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4053 if(!NT_SUCCESS(Status
))
4055 SetLastNtError(Status
);
4059 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4060 if (SafeMessageName
.Buffer
)
4061 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4065 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
4074 NtUserSetWindowFNID(HWND hWnd
,
4078 DECLARE_RETURN(BOOL
);
4080 TRACE("Enter NtUserSetWindowFNID\n");
4081 UserEnterExclusive();
4083 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4088 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
4090 EngSetLastError(ERROR_ACCESS_DENIED
);
4094 // From user land we only set these.
4095 if (fnID
!= FNID_DESTROY
)
4097 /* HACK: The minimum should be FNID_BUTTON, but menu code relies on this */
4098 if (fnID
< FNID_FIRST
|| fnID
> FNID_GHOST
||
4101 EngSetLastError(ERROR_INVALID_PARAMETER
);
4110 TRACE("Leave NtUserSetWindowFNID\n");
4116 DefSetText(PWND Wnd
, PCWSTR WindowText
)
4118 UNICODE_STRING UnicodeString
;
4121 RtlInitUnicodeString(&UnicodeString
, WindowText
);
4123 if (UnicodeString
.Length
!= 0)
4125 if (Wnd
->strName
.MaximumLength
> 0 &&
4126 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4128 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4130 Wnd
->strName
.Length
= UnicodeString
.Length
;
4131 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4132 RtlCopyMemory(Wnd
->strName
.Buffer
,
4133 UnicodeString
.Buffer
,
4134 UnicodeString
.Length
);
4139 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4140 buf
= Wnd
->strName
.Buffer
;
4141 Wnd
->strName
.Buffer
= NULL
;
4144 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4147 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4148 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4149 if (Wnd
->strName
.Buffer
!= NULL
)
4151 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4152 RtlCopyMemory(Wnd
->strName
.Buffer
,
4153 UnicodeString
.Buffer
,
4154 UnicodeString
.Length
);
4155 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4156 Wnd
->strName
.Length
= UnicodeString
.Length
;
4160 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4167 Wnd
->strName
.Length
= 0;
4168 if (Wnd
->strName
.Buffer
!= NULL
)
4169 Wnd
->strName
.Buffer
[0] = L
'\0';
4172 // FIXME: HAX! Windows does not do this in here!
4173 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4174 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4175 /* Send shell notifications */
4176 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4178 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) UserHMGetHandle(Wnd
), FALSE
); // FIXME Flashing?
4183 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4190 * Undocumented function that is called from DefWindowProc to set
4197 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4200 LARGE_STRING SafeText
;
4201 UNICODE_STRING UnicodeString
;
4204 TRACE("Enter NtUserDefSetText\n");
4206 if (WindowText
!= NULL
)
4210 SafeText
= ProbeForReadLargeString(WindowText
);
4212 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4215 SetLastNtError(_SEH2_GetExceptionCode());
4225 UserEnterExclusive();
4227 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4233 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4234 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4235 // Now we know what the bAnsi is for.
4236 RtlInitUnicodeString(&UnicodeString
, NULL
);
4237 if (SafeText
.Buffer
)
4242 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4244 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4245 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4247 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4250 SetLastNtError(_SEH2_GetExceptionCode());
4253 if (!Ret
) goto Exit
;
4256 if (UnicodeString
.Length
!= 0)
4258 if (Wnd
->strName
.MaximumLength
> 0 &&
4259 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4261 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4263 Wnd
->strName
.Length
= UnicodeString
.Length
;
4264 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4265 RtlCopyMemory(Wnd
->strName
.Buffer
,
4266 UnicodeString
.Buffer
,
4267 UnicodeString
.Length
);
4272 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4273 buf
= Wnd
->strName
.Buffer
;
4274 Wnd
->strName
.Buffer
= NULL
;
4277 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4280 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4281 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4282 if (Wnd
->strName
.Buffer
!= NULL
)
4284 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4285 RtlCopyMemory(Wnd
->strName
.Buffer
,
4286 UnicodeString
.Buffer
,
4287 UnicodeString
.Length
);
4288 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4289 Wnd
->strName
.Length
= UnicodeString
.Length
;
4293 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4301 Wnd
->strName
.Length
= 0;
4302 if (Wnd
->strName
.Buffer
!= NULL
)
4303 Wnd
->strName
.Buffer
[0] = L
'\0';
4306 // FIXME: HAX! Windows does not do this in here!
4307 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4308 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4309 /* Send shell notifications */
4310 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4312 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4317 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4318 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4324 * NtUserInternalGetWindowText
4331 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4336 DECLARE_RETURN(INT
);
4338 TRACE("Enter NtUserInternalGetWindowText\n");
4341 if(lpString
&& (nMaxCount
<= 1))
4343 EngSetLastError(ERROR_INVALID_PARAMETER
);
4347 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4352 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4355 const WCHAR Terminator
= L
'\0';
4357 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4359 Copy
= min(nMaxCount
- 1, Result
);
4362 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4363 if(!NT_SUCCESS(Status
))
4365 SetLastNtError(Status
);
4371 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4372 if(!NT_SUCCESS(Status
))
4374 SetLastNtError(Status
);
4384 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4394 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4400 // ASSERT(OwnerWnd);
4402 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4403 win_array
= IntWinListChildren(OwnerWnd
);
4408 while (win_array
[count
])
4410 while (--count
>= 0)
4412 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4414 if (pWnd
->spwndOwner
!= OwnerWnd
)
4419 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4421 /* In Windows, ShowOwnedPopups(TRUE) generates
4422 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4423 * regardless of the state of the owner
4425 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4431 if (pWnd
->style
& WS_VISIBLE
)
4433 /* In Windows, ShowOwnedPopups(FALSE) generates
4434 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4435 * regardless of the state of the owner
4437 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4443 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4444 TRACE("Leave ShowOwnedPopups\n");