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 Wnd
->spwndPrev
= WndInsertAfter
;
867 /* Link after WndInsertAfter */
868 Wnd
->spwndNext
= WndInsertAfter
->spwndNext
;
870 Wnd
->spwndNext
->spwndPrev
= Wnd
;
872 Wnd
->spwndPrev
->spwndNext
= Wnd
;
876 /* Link at the top */
877 Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
;
879 Wnd
->spwndNext
->spwndPrev
= Wnd
;
881 Wnd
->spwndParent
->spwndChild
= Wnd
;
886 Note: Wnd->spwndParent can be null if it is the desktop.
888 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
890 if (hWndPrev
== HWND_NOTOPMOST
)
892 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) && (Wnd
->ExStyle2
& WS_EX2_LINKED
))
893 return; /* nothing to do */
894 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
895 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
898 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
900 if (hWndPrev
== HWND_BOTTOM
)
902 /* Link in the bottom of the list */
905 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
906 while (WndInsertAfter
&& WndInsertAfter
->spwndNext
)
908 WndInsertAfter
= WndInsertAfter
->spwndNext
;
911 IntLinkWindow(Wnd
, WndInsertAfter
);
912 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
914 else if (hWndPrev
== HWND_TOPMOST
)
916 /* Link in the top of the list */
917 IntLinkWindow(Wnd
, NULL
);
918 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
920 else if (hWndPrev
== HWND_TOP
)
922 /* Link it after the last topmost window */
923 PWND WndInsertBefore
;
925 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
927 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
929 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
931 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
))
934 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
936 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
939 WndInsertBefore
= WndInsertBefore
->spwndNext
;
943 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
947 /* Link it after hWndPrev */
950 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
951 /* Are we called with an erroneous handle */
952 if (WndInsertAfter
== NULL
)
954 /* Link in a default position */
955 IntLinkHwnd(Wnd
, HWND_TOP
);
959 IntLinkWindow(Wnd
, WndInsertAfter
);
961 /* Fix the WS_EX_TOPMOST flag */
962 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
964 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
968 if (WndInsertAfter
->spwndNext
&&
969 (WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
))
971 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
975 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
979 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
983 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
986 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
987 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
989 //ERR("ProcessOwnerSwap Old out.\n");
990 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
996 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
999 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1001 //ERR("ProcessOwnerSwap New in.\n");
1002 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1006 // FIXME: System Tray checks.
1010 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1012 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1015 Wnd
= IntGetWindowObject(hWnd
);
1019 WndOldOwner
= Wnd
->spwndOwner
;
1021 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1022 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1024 if (!WndNewOwner
&& hWndNewOwner
)
1026 EngSetLastError(ERROR_INVALID_PARAMETER
);
1031 /* if parent belongs to a different thread and the window isn't */
1032 /* top-level, attach the two threads */
1033 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1035 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1039 Wnd
->spwndOwner
= WndNewOwner
;
1043 Wnd
->spwndOwner
= NULL
;
1048 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1049 EngSetLastError(ERROR_INVALID_PARAMETER
);
1053 UserDereferenceObject(Wnd
);
1058 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1060 PWND WndOldParent
, pWndExam
;
1063 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1066 ASSERT(WndNewParent
);
1067 ASSERT_REFS_CO(Wnd
);
1068 ASSERT_REFS_CO(WndNewParent
);
1070 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1072 EngSetLastError(ERROR_ACCESS_DENIED
);
1076 /* Some applications try to set a child as a parent */
1077 if (IntIsChildWindow(Wnd
, WndNewParent
))
1079 TRACE("IntSetParent try to set a child as a parent.\n");
1080 EngSetLastError( ERROR_INVALID_PARAMETER
);
1084 pWndExam
= WndNewParent
; // Load parent Window to examine.
1085 // Now test for set parent to parent hit.
1088 if (Wnd
== pWndExam
)
1090 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1091 EngSetLastError(ERROR_INVALID_PARAMETER
);
1094 pWndExam
= pWndExam
->spwndParent
;
1098 * Windows hides the window first, then shows it again
1099 * including the WM_SHOWWINDOW messages and all
1101 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1103 /* Window must belong to current process */
1104 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1106 ERR("IntSetParent Window must belong to current process!\n");
1110 WndOldParent
= Wnd
->spwndParent
;
1112 if ( WndOldParent
&&
1113 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1114 pt
.x
= Wnd
->rcWindow
.right
;
1116 pt
.x
= Wnd
->rcWindow
.left
;
1117 pt
.y
= Wnd
->rcWindow
.top
;
1119 IntScreenToClient(WndOldParent
, &pt
);
1121 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1123 if (WndNewParent
!= WndOldParent
)
1125 /* Unlink the window from the siblings list */
1126 IntUnlinkWindow(Wnd
);
1127 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1129 /* Set the new parent */
1130 Wnd
->spwndParent
= WndNewParent
;
1132 if ( Wnd
->style
& WS_CHILD
&&
1134 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1136 ERR("SetParent Top Most from Pop up!\n");
1137 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1140 /* Link the window with its new siblings */
1142 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1143 UserIsDesktopWindow(WndNewParent
) ) ? HWND_TOP
: HWND_TOPMOST
) );
1146 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1147 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1149 Wnd
->style
|= WS_CLIPSIBLINGS
;
1150 DceResetActiveDCEs(Wnd
);
1153 /* if parent belongs to a different thread and the window isn't */
1154 /* top-level, attach the two threads */
1155 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1157 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1159 if (WndOldParent
&& (Wnd
->head
.pti
!= WndOldParent
->head
.pti
))
1161 //ERR("SetParent Old out.\n");
1162 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1165 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1167 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1169 //ERR("SetParent New in.\n");
1170 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1175 if (UserIsMessageWindow(WndOldParent
) || UserIsMessageWindow(WndNewParent
))
1176 swFlags
|= SWP_NOACTIVATE
;
1178 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1180 * SetParent additionally needs to make hwnd the top window
1181 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1182 * WM_WINDOWPOSCHANGED notification messages.
1184 //ERR("IntSetParent SetWindowPos 1\n");
1185 co_WinPosSetWindowPos( Wnd
,
1186 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1187 pt
.x
, pt
.y
, 0, 0, swFlags
);
1188 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1189 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1191 return WndOldParent
;
1195 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1197 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1198 HWND hWndOldParent
= NULL
;
1199 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1201 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1203 EngSetLastError(ERROR_INVALID_PARAMETER
);
1207 if (hWndChild
== IntGetDesktopWindow())
1209 ERR("UserSetParent Access Denied!\n");
1210 EngSetLastError(ERROR_ACCESS_DENIED
);
1216 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1218 ERR("UserSetParent Bad New Parent!\n");
1224 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1230 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1232 ERR("UserSetParent Bad Child!\n");
1236 UserRefObjectCo(Wnd
, &Ref
);
1237 UserRefObjectCo(WndParent
, &ParentRef
);
1238 //ERR("Enter co_IntSetParent\n");
1239 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1240 //ERR("Leave co_IntSetParent\n");
1241 UserDerefObjectCo(WndParent
);
1242 UserDerefObjectCo(Wnd
);
1246 hWndOldParent
= WndOldParent
->head
.h
;
1247 UserDereferenceObject(WndOldParent
);
1250 return( hWndOldParent
);
1253 /* Unlink the window from siblings. Children and parent are kept in place. */
1255 IntUnlinkWindow(PWND Wnd
)
1258 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1261 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1263 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1264 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1266 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1269 /* FUNCTIONS *****************************************************************/
1272 * As best as I can figure, this function is used by EnumWindows,
1273 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1275 * It's supposed to build a list of HWNDs to return to the caller.
1276 * We can figure out what kind of list by what parameters are
1284 NtUserBuildHwndList(
1297 return ERROR_INVALID_PARAMETER
;
1299 if (hwndParent
|| !dwThreadId
)
1302 PWND Parent
, Window
;
1306 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1308 return ERROR_INVALID_HANDLE
;
1313 Status
= IntValidateDesktopHandle(hDesktop
,
1317 if(!NT_SUCCESS(Status
))
1319 return ERROR_INVALID_HANDLE
;
1322 hwndParent
= Desktop
->DesktopWindow
;
1329 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1330 (Window
= Parent
->spwndChild
))
1332 BOOL bGoDown
= TRUE
;
1334 Status
= STATUS_SUCCESS
;
1339 if(dwCount
++ < *pBufSize
&& pWnd
)
1343 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1344 *pWnd
= Window
->head
.h
;
1347 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1349 Status
= _SEH2_GetExceptionCode();
1352 if(!NT_SUCCESS(Status
))
1354 SetLastNtError(Status
);
1358 if (Window
->spwndChild
&& bChildren
)
1360 Window
= Window
->spwndChild
;
1365 if (Window
->spwndNext
)
1367 Window
= Window
->spwndNext
;
1371 Window
= Window
->spwndParent
;
1372 if (Window
== Parent
)
1381 ObDereferenceObject(Desktop
);
1384 else // Build EnumThreadWindows list!
1387 PTHREADINFO W32Thread
;
1391 Status
= PsLookupThreadByThreadId(UlongToHandle(dwThreadId
), &Thread
);
1392 if (!NT_SUCCESS(Status
))
1394 ERR("Thread Id is not valid!\n");
1395 return ERROR_INVALID_PARAMETER
;
1397 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1399 ObDereferenceObject(Thread
);
1400 TRACE("Tried to enumerate windows of a non gui thread\n");
1401 return ERROR_INVALID_PARAMETER
;
1404 // Do not use Thread link list due to co_UserFreeWindow!!!
1405 // Current = W32Thread->WindowListHead.Flink;
1406 // Fixes Api:CreateWindowEx tests!!!
1407 List
= IntWinListChildren(UserGetDesktopWindow());
1411 for (i
= 0; List
[i
]; i
++)
1413 Window
= ValidateHwndNoErr(List
[i
]);
1414 if (Window
&& Window
->head
.pti
== W32Thread
)
1416 if (dwCount
< *pBufSize
&& pWnd
)
1420 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1421 *pWnd
= Window
->head
.h
;
1424 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1426 Status
= _SEH2_GetExceptionCode();
1429 if (!NT_SUCCESS(Status
))
1431 ERR("Failure to build window list!\n");
1432 SetLastNtError(Status
);
1439 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
1442 ObDereferenceObject(Thread
);
1445 *pBufSize
= dwCount
;
1446 return STATUS_SUCCESS
;
1449 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1451 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1452 !(pWindow
->ExStyle
& WS_EX_NOPARENTNOTIFY
))
1454 if (VerifyWnd(pWindow
->spwndParent
) && !UserIsDesktopWindow(pWindow
->spwndParent
))
1456 USER_REFERENCE_ENTRY Ref
;
1457 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1458 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1460 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1461 (LPARAM
)pWindow
->head
.h
);
1462 UserDerefObjectCo(pWindow
->spwndParent
);
1468 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1470 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1472 /* default positioning for overlapped windows */
1473 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1476 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1478 pMonitor
= UserGetPrimaryMonitor();
1480 /* Check if we don't have a monitor attached yet */
1481 if(pMonitor
== NULL
)
1489 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1491 if (IS_DEFAULT(Cs
->x
))
1493 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1495 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1497 Cs
->x
= ProcessParams
->StartingX
;
1498 Cs
->y
= ProcessParams
->StartingY
;
1502 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1503 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1504 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1505 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1507 /* reset counter and position */
1510 pMonitor
->cWndStack
= 0;
1512 pMonitor
->cWndStack
++;
1516 if (IS_DEFAULT(Cs
->cx
))
1518 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1520 Cs
->cx
= ProcessParams
->CountX
;
1521 Cs
->cy
= ProcessParams
->CountY
;
1525 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1526 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1529 /* neither x nor cx are default. Check the y values .
1530 * In the trace we see Outlook and Outlook Express using
1531 * cy set to CW_USEDEFAULT when opening the address book.
1533 else if (IS_DEFAULT(Cs
->cy
))
1535 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1536 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1541 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1542 if(IS_DEFAULT(Cs
->x
))
1547 if(IS_DEFAULT(Cs
->cx
))
1557 /* Allocates and initializes a window */
1558 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1559 PLARGE_STRING WindowName
,
1564 PDESKTOP pdeskCreated
)
1568 PTHREADINFO pti
= NULL
;
1570 BOOL bUnicodeWindow
;
1572 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1574 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1575 { // Need both here for wine win.c test_CreateWindow.
1576 //if (Cs->hwndParent && ParentWindow)
1577 if (ParentWindow
) // It breaks more tests..... WIP.
1579 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1580 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1581 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1582 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1586 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1588 * Dialog boxes and message boxes do not inherit layout, so you must
1589 * set the layout explicitly.
1591 if ( Class
->fnid
!= FNID_DIALOG
)
1593 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1595 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1601 /* Automatically add WS_EX_WINDOWEDGE */
1602 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1603 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1604 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1605 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1607 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1609 /* Is it a unicode window? */
1610 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1611 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1613 /* Allocate the new window */
1614 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1615 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1619 sizeof(WND
) + Class
->cbwndExtra
);
1626 TRACE("Created window object with handle %p\n", hWnd
);
1628 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1629 { /* HACK: Helper for win32csr/desktopbg.c */
1630 /* If there is no desktop window yet, we must be creating it */
1631 TRACE("CreateWindow setting desktop.\n");
1632 pdeskCreated
->DesktopWindow
= hWnd
;
1633 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1637 * Fill out the structure describing it.
1639 /* Remember, pWnd->head is setup in object.c ... */
1640 pWnd
->spwndParent
= ParentWindow
;
1641 pWnd
->spwndOwner
= OwnerWindow
;
1643 pWnd
->spwndLastActive
= pWnd
;
1644 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1646 pWnd
->hModule
= Cs
->hInstance
;
1647 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1648 pWnd
->ExStyle
= Cs
->dwExStyle
;
1649 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1650 pWnd
->pActCtx
= acbiBuffer
;
1651 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1652 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1654 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1656 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1657 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1660 pWnd
->head
.pti
->cWindows
++;
1662 if (Class
->spicn
&& !Class
->spicnSm
)
1664 HICON IconSmHandle
= NULL
;
1665 if((Class
->spicn
->CURSORF_flags
& (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1666 == (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1668 IconSmHandle
= co_IntCopyImage(
1669 UserHMGetHandle(Class
->spicn
),
1671 UserGetSystemMetrics( SM_CXSMICON
),
1672 UserGetSystemMetrics( SM_CYSMICON
),
1673 LR_COPYFROMRESOURCE
);
1677 /* Retry without copying from resource */
1678 IconSmHandle
= co_IntCopyImage(
1679 UserHMGetHandle(Class
->spicn
),
1681 UserGetSystemMetrics( SM_CXSMICON
),
1682 UserGetSystemMetrics( SM_CYSMICON
),
1688 Class
->spicnSm
= UserGetCurIconObject(IconSmHandle
);
1689 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1693 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1694 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1696 /* BugBoy Comments: Comment below say that System classes are always created
1697 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1698 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1700 No where can I see in code or through testing does the window change back
1701 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1702 see what problems this would cause. */
1704 // Set WndProc from Class.
1705 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1707 // GetWindowProc, test for non server side default classes and set WndProc.
1708 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1712 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1713 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1717 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1718 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1722 // If not an Unicode caller, set Ansi creator bit.
1723 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1725 // Clone Class Ansi/Unicode proc type.
1726 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1728 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1729 pWnd
->Unicode
= FALSE
;
1733 * It seems there can be both an Ansi creator and Unicode Class Window
1734 * WndProc, unless the following overriding conditions occur:
1736 if ( !bUnicodeWindow
&&
1737 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1738 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1739 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1740 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1741 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1742 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1743 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1744 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1745 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1746 { // Override Class and set the window Ansi WndProc.
1747 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1748 pWnd
->Unicode
= FALSE
;
1751 { // Set the window Unicode WndProc.
1752 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1753 pWnd
->Unicode
= TRUE
;
1757 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1758 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1759 Dont understand why it does this. */
1760 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1762 PCALLPROCDATA CallProc
;
1763 CallProc
= CreateCallProc(pWnd
->head
.rpdesk
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1767 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1768 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1772 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1776 InitializeListHead(&pWnd
->PropListHead
);
1777 pWnd
->PropListItems
= 0;
1779 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1781 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1782 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1783 if (pWnd
->strName
.Buffer
== NULL
)
1788 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1789 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1790 pWnd
->strName
.Length
= WindowName
->Length
;
1791 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1794 /* Correct the window style. */
1795 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1797 pWnd
->style
|= WS_CLIPSIBLINGS
;
1798 if (!(pWnd
->style
& WS_POPUP
))
1800 pWnd
->style
|= WS_CAPTION
;
1804 /* WS_EX_WINDOWEDGE depends on some other styles */
1805 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1806 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1807 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1809 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1810 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1811 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1814 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1816 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1817 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1819 /* Set the window menu */
1820 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1824 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1826 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1828 UNICODE_STRING MenuName
;
1831 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1833 MenuName
.Length
= 0;
1834 MenuName
.MaximumLength
= 0;
1835 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1839 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1841 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1842 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1846 pWnd
->IDMenu
= (UINT_PTR
)Cs
->hMenu
;
1849 if ( ParentWindow
&&
1850 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1851 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1853 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1855 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1857 EngSetLastError(ERROR_INVALID_PARAMETER
);
1860 if ( pWnd
->spwndOwner
&&
1861 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1863 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1865 if ( pWnd
->spwndOwner
&&
1866 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1867 pti
!= pWnd
->spwndOwner
->head
.pti
)
1869 //ERR("CreateWindow Owner in.\n");
1870 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1874 /* Insert the window into the thread's window list. */
1875 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1877 /* Handle "CS_CLASSDC", it is tested first. */
1878 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1879 { /* One DCE per class to have CLASS. */
1880 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1882 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1883 { /* Allocate a DCE for this window. */
1884 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1890 ERR("IntCreateWindow Allocation Error.\n");
1891 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1894 UserDereferenceObject(pWnd
);
1902 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1903 PUNICODE_STRING ClassName
,
1904 PLARGE_STRING WindowName
,
1908 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1909 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1910 PWINSTATION_OBJECT WinSta
;
1913 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1914 CBT_CREATEWNDW
* pCbtCreate
;
1916 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1918 DWORD dwShowMode
= SW_SHOW
;
1919 CREATESTRUCTW
*pCsw
= NULL
;
1920 PVOID pszClass
= NULL
, pszName
= NULL
;
1923 /* Get the current window station and reference it */
1924 pti
= GetW32ThreadInfo();
1925 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1927 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1928 return NULL
; // There is nothing to cleanup.
1930 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1931 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1936 /* Get the class and reference it */
1937 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
1940 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
1941 ERR("Failed to find class %wZ\n", ClassName
);
1945 /* Now find the parent and the owner window */
1946 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
1949 if (Cs
->hwndParent
== HWND_MESSAGE
)
1951 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
1953 else if (Cs
->hwndParent
)
1955 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1956 hWndOwner
= Cs
->hwndParent
;
1958 hWndParent
= Cs
->hwndParent
;
1960 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1962 ERR("Cannot create a child window without a parent!\n");
1963 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1964 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1967 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1968 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1970 if (hWndParent
&& !ParentWindow
)
1972 ERR("Got invalid parent window handle\n");
1975 else if (hWndOwner
&& !OwnerWindow
)
1977 ERR("Got invalid owner window handle\n");
1978 ParentWindow
= NULL
;
1984 if (IntIsDesktopWindow(OwnerWindow
)) OwnerWindow
= NULL
;
1985 else if (ParentWindow
&& !IntIsDesktopWindow(ParentWindow
))
1987 ERR("an owned window must be created as top-level\n");
1988 EngSetLastError( STATUS_ACCESS_DENIED
);
1991 else /* owner must be a top-level window */
1993 while ((OwnerWindow
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
&& !IntIsDesktopWindow(OwnerWindow
->spwndParent
))
1994 OwnerWindow
= OwnerWindow
->spwndParent
;
1998 /* Fix the position and the size of the window */
2001 UserRefObjectCo(ParentWindow
, &ParentRef
);
2002 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2005 /* Allocate and initialize the new window */
2006 Window
= IntCreateWindow(Cs
,
2015 ERR("IntCreateWindow failed!\n");
2019 hWnd
= UserHMGetHandle(Window
);
2020 hwndInsertAfter
= HWND_TOP
;
2022 UserRefObjectCo(Window
, &Ref
);
2023 UserDereferenceObject(Window
);
2024 ObDereferenceObject(WinSta
);
2026 //// Check for a hook to eliminate overhead. ////
2027 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2029 // Allocate the calling structures Justin Case this goes Global.
2030 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2031 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2032 if (!pCsw
|| !pCbtCreate
)
2034 ERR("UserHeapAlloc() failed!\n");
2038 /* Fill the new CREATESTRUCTW */
2039 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2040 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2042 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2043 if (!IS_ATOM(ClassName
->Buffer
))
2045 if (Window
->state
& WNDS_ANSICREATOR
)
2047 ANSI_STRING AnsiString
;
2048 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2049 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2052 ERR("UserHeapAlloc() failed!\n");
2055 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2056 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2057 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2061 UNICODE_STRING UnicodeString
;
2062 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2063 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2066 ERR("UserHeapAlloc() failed!\n");
2069 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2070 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2071 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2073 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2075 if (WindowName
->Length
)
2077 UNICODE_STRING Name
;
2078 Name
.Buffer
= WindowName
->Buffer
;
2079 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2080 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2082 if (Window
->state
& WNDS_ANSICREATOR
)
2084 ANSI_STRING AnsiString
;
2085 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2086 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2089 ERR("UserHeapAlloc() failed!\n");
2092 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2093 AnsiString
.Buffer
= (PCHAR
)pszName
;
2094 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2098 UNICODE_STRING UnicodeString
;
2099 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2100 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2103 ERR("UserHeapAlloc() failed!\n");
2106 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2107 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2108 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2110 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2113 pCbtCreate
->lpcs
= pCsw
;
2114 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2116 //// Call the WH_CBT hook ////
2117 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2120 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2123 // Write back changes.
2128 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2131 /* NCCREATE and WM_NCCALCSIZE need the original values */
2132 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2133 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2135 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2137 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2139 Cs
->x
+= ParentWindow
->rcClient
.left
;
2140 Cs
->y
+= ParentWindow
->rcClient
.top
;
2144 /* Send the WM_GETMINMAXINFO message */
2148 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2150 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2151 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2152 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2153 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2154 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2157 Window
->rcWindow
.left
= Cs
->x
;
2158 Window
->rcWindow
.top
= Cs
->y
;
2159 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2160 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2162 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2164 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2165 RECTL_vOffsetRect(&Window->rcWindow,
2166 ParentWindow->rcClient.left,
2167 ParentWindow->rcClient.top);
2170 /* correct child window coordinates if mirroring on parent is enabled */
2171 if (ParentWindow
!= NULL
)
2173 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2174 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2176 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2177 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2181 Window
->rcClient
= Window
->rcWindow
;
2183 /* Link the window */
2184 if (NULL
!= ParentWindow
)
2186 /* Link the window into the siblings list */
2187 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2188 IntLinkHwnd(Window
, HWND_BOTTOM
);
2190 IntLinkHwnd(Window
, hwndInsertAfter
);
2193 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2195 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2196 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2199 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2201 if ( !IntIsTopLevelWindow(Window
) )
2203 if (pti
!= Window
->spwndParent
->head
.pti
)
2205 //ERR("CreateWindow Parent in.\n");
2206 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2211 /* Send the NCCREATE message */
2212 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2215 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2219 /* Send the WM_NCCALCSIZE message */
2222 MaxPos
.x
= Window
->rcWindow
.left
;
2223 MaxPos
.y
= Window
->rcWindow
.top
;
2225 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2226 //rc = Window->rcWindow;
2227 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2228 //Window->rcClient = rc;
2230 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2231 MaxPos
.y
- Window
->rcWindow
.top
);
2234 /* Send the WM_CREATE message. */
2235 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2236 if (Result
== (LRESULT
)-1)
2238 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2242 /* Send the EVENT_OBJECT_CREATE event */
2243 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2245 /* By setting the flag below it can be examined to determine if the window
2246 was created successfully and a valid pwnd was passed back to caller since
2247 from here the function has to succeed. */
2248 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2250 /* Send the WM_SIZE and WM_MOVE messages. */
2251 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2253 co_WinPosSendSizeMove(Window
);
2256 /* Show or maybe minimize or maximize the window. */
2258 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2259 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2262 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2264 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2265 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2266 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2267 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2268 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2271 /* Send the WM_PARENTNOTIFY message */
2272 IntSendParentNotify(Window
, WM_CREATE
);
2274 /* Notify the shell that a new window was created */
2275 if (UserIsDesktopWindow(Window
->spwndParent
) &&
2276 Window
->spwndOwner
== NULL
&&
2277 (Window
->style
& WS_VISIBLE
) &&
2278 (!(Window
->ExStyle
& WS_EX_TOOLWINDOW
) ||
2279 (Window
->ExStyle
& WS_EX_APPWINDOW
)))
2281 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2284 /* Initialize and show the window's scrollbars */
2285 if (Window
->style
& WS_VSCROLL
)
2287 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2289 if (Window
->style
& WS_HSCROLL
)
2291 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2294 /* Show the new window */
2295 if (Cs
->style
& WS_VISIBLE
)
2297 if (Window
->style
& WS_MAXIMIZE
)
2298 dwShowMode
= SW_SHOW
;
2299 else if (Window
->style
& WS_MINIMIZE
)
2300 dwShowMode
= SW_SHOWMINIMIZED
;
2302 co_WinPosShowWindow(Window
, dwShowMode
);
2304 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2306 ASSERT(ParentWindow
);
2309 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2310 /* ShowWindow won't activate child windows */
2311 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2315 if (Class
->atomClassName
== gaGuiConsoleWndClass
)
2317 /* Count only console windows manually */
2318 co_IntUserManualGuiCheck(TRUE
);
2321 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2327 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2328 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2330 co_UserDestroyWindow(Window
);
2332 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2335 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2336 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2337 if (pszName
) UserHeapFree(pszName
);
2338 if (pszClass
) UserHeapFree(pszClass
);
2342 UserDerefObjectCo(Window
);
2344 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2346 // See CORE-13717, not setting error on success.
2348 EngSetLastError(ERROR_SUCCESS
);
2355 ProbeAndCaptureLargeString(
2356 OUT PLARGE_STRING plstrSafe
,
2357 IN PLARGE_STRING plstrUnsafe
)
2359 LARGE_STRING lstrTemp
;
2360 PVOID pvBuffer
= NULL
;
2364 /* Probe and copy the string */
2365 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2366 lstrTemp
= *plstrUnsafe
;
2368 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2371 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2375 if (lstrTemp
.Length
!= 0)
2377 /* Allocate a buffer from paged pool */
2378 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2381 return STATUS_NO_MEMORY
;
2386 /* Probe and copy the buffer */
2387 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2388 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2390 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2392 /* Cleanup and fail */
2393 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2394 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2399 /* Set the output string */
2400 plstrSafe
->Buffer
= pvBuffer
;
2401 plstrSafe
->Length
= lstrTemp
.Length
;
2402 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2404 return STATUS_SUCCESS
;
2408 * \todo Allow passing plstrClassName as ANSI.
2412 NtUserCreateWindowEx(
2414 PLARGE_STRING plstrClassName
,
2415 PLARGE_STRING plstrClsVersion
,
2416 PLARGE_STRING plstrWindowName
,
2424 HINSTANCE hInstance
,
2430 LARGE_STRING lstrWindowName
;
2431 LARGE_STRING lstrClassName
;
2432 LARGE_STRING lstrClsVersion
;
2433 UNICODE_STRING ustrClassName
;
2434 UNICODE_STRING ustrClsVersion
;
2439 lstrWindowName
.Buffer
= NULL
;
2440 lstrClassName
.Buffer
= NULL
;
2441 lstrClsVersion
.Buffer
= NULL
;
2443 ASSERT(plstrWindowName
);
2445 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2447 /* check hMenu is valid handle */
2448 if (hMenu
&& !UserGetMenuObject(hMenu
))
2450 ERR("NtUserCreateWindowEx: Got an invalid menu handle!\n");
2451 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
2456 /* Copy the window name to kernel mode */
2457 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2458 if (!NT_SUCCESS(Status
))
2460 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2461 SetLastNtError(Status
);
2465 plstrWindowName
= &lstrWindowName
;
2467 /* Check if the class is an atom */
2468 if (IS_ATOM(plstrClassName
))
2470 /* It is, pass the atom in the UNICODE_STRING */
2471 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2472 ustrClassName
.Length
= 0;
2473 ustrClassName
.MaximumLength
= 0;
2477 /* It's not, capture the class name */
2478 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2479 if (!NT_SUCCESS(Status
))
2481 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2482 /* Set last error, cleanup and return */
2483 SetLastNtError(Status
);
2487 /* We pass it on as a UNICODE_STRING */
2488 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2489 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2490 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2493 /* Check if the class version is an atom */
2494 if (IS_ATOM(plstrClsVersion
))
2496 /* It is, pass the atom in the UNICODE_STRING */
2497 ustrClsVersion
.Buffer
= (PVOID
)plstrClsVersion
;
2498 ustrClsVersion
.Length
= 0;
2499 ustrClsVersion
.MaximumLength
= 0;
2503 /* It's not, capture the class name */
2504 Status
= ProbeAndCaptureLargeString(&lstrClsVersion
, plstrClsVersion
);
2505 if (!NT_SUCCESS(Status
))
2507 ERR("NtUserCreateWindowEx: failed to capture plstrClsVersion\n");
2508 /* Set last error, cleanup and return */
2509 SetLastNtError(Status
);
2513 /* We pass it on as a UNICODE_STRING */
2514 ustrClsVersion
.Buffer
= lstrClsVersion
.Buffer
;
2515 ustrClsVersion
.Length
= (USHORT
)min(lstrClsVersion
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2516 ustrClsVersion
.MaximumLength
= (USHORT
)min(lstrClsVersion
.MaximumLength
, MAXUSHORT
);
2519 /* Fill the CREATESTRUCTW */
2520 /* we will keep here the original parameters */
2522 Cs
.lpCreateParams
= lpParam
;
2523 Cs
.hInstance
= hInstance
;
2525 Cs
.hwndParent
= hWndParent
;
2530 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2531 Cs
.lpszClass
= ustrClassName
.Buffer
;
2532 Cs
.dwExStyle
= dwExStyle
;
2534 UserEnterExclusive();
2536 /* Call the internal function */
2537 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClsVersion
, plstrWindowName
, acbiBuffer
);
2541 ERR("co_UserCreateWindowEx failed!\n");
2543 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2548 if (lstrWindowName
.Buffer
)
2550 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2552 if (lstrClassName
.Buffer
)
2554 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2556 if (lstrClsVersion
.Buffer
)
2558 ExFreePoolWithTag(lstrClsVersion
.Buffer
, TAG_STRING
);
2565 BOOLEAN
co_UserDestroyWindow(PVOID Object
)
2571 PWND Window
= Object
;
2573 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2575 hWnd
= Window
->head
.h
;
2576 ti
= PsGetCurrentThreadWin32Thread();
2578 TRACE("co_UserDestroyWindow \n");
2580 /* Check for owner thread */
2581 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2583 /* Check if we are destroying the desktop window */
2584 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2586 EngSetLastError(ERROR_ACCESS_DENIED
);
2591 /* If window was created successfully and it is hooked */
2592 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2594 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2596 ERR("Destroy Window WH_CBT Call Hook return!\n");
2601 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2603 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2605 if (Window
->spwndOwner
)
2607 //ERR("DestroyWindow Owner out.\n");
2608 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2613 /* Inform the parent */
2614 if (Window
->style
& WS_CHILD
)
2616 IntSendParentNotify(Window
, WM_DESTROY
);
2619 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
2621 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
2624 /* Hide the window */
2625 if (Window
->style
& WS_VISIBLE
)
2627 if (Window
->style
& WS_CHILD
)
2629 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
2630 co_WinPosShowWindow(Window
, SW_HIDE
);
2634 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2638 // Adjust last active.
2639 if ((pwndTemp
= Window
->spwndOwner
))
2641 while (pwndTemp
->spwndOwner
)
2642 pwndTemp
= pwndTemp
->spwndOwner
;
2644 if (pwndTemp
->spwndLastActive
== Window
)
2645 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2648 if (Window
->spwndParent
&& IntIsWindow(UserHMGetHandle(Window
)))
2650 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2652 if (!IntIsTopLevelWindow(Window
))
2654 //ERR("DestroyWindow Parent out.\n");
2655 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2660 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2661 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2662 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2663 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2664 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2665 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2666 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2667 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2670 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2673 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2675 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2677 ERR("Destroying the ShellWindow!\n");
2678 ti
->pDeskInfo
->hShellWindow
= NULL
;
2682 IntEngWindowChanged(Window
, WOC_DELETE
);
2684 if (!IntIsWindow(UserHMGetHandle(Window
)))
2689 /* Recursively destroy owned windows */
2691 if (! (Window
->style
& WS_CHILD
))
2695 BOOL GotOne
= FALSE
;
2698 PWND Child
, Desktop
;
2700 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2701 UserGetWindowObject(IntGetDesktopWindow());
2702 Children
= IntWinListChildren(Desktop
);
2706 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2708 Child
= UserGetWindowObject(*ChildHandle
);
2711 if (Child
->spwndOwner
!= Window
)
2716 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2718 USER_REFERENCE_ENTRY ChildRef
;
2719 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2720 co_UserDestroyWindow(Child
);
2721 UserDerefObjectCo(Child
); // Temp HACK?
2727 if (Child
->spwndOwner
!= NULL
)
2729 Child
->spwndOwner
= NULL
;
2733 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2742 /* Generate mouse move message for the next window */
2743 msg
.message
= WM_MOUSEMOVE
;
2744 msg
.wParam
= UserGetMouseButtonsState();
2745 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2746 msg
.pt
= gpsi
->ptCursor
;
2747 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2749 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2751 /* Send destroy messages */
2752 IntSendDestroyMsg(UserHMGetHandle(Window
));
2754 if (!IntIsWindow(UserHMGetHandle(Window
)))
2759 /* Destroy the window storage */
2760 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2770 NtUserDestroyWindow(HWND Wnd
)
2773 DECLARE_RETURN(BOOLEAN
);
2775 USER_REFERENCE_ENTRY Ref
;
2777 TRACE("Enter NtUserDestroyWindow\n");
2778 UserEnterExclusive();
2780 if (!(Window
= UserGetWindowObject(Wnd
)))
2785 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2786 ret
= co_UserDestroyWindow(Window
);
2787 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2792 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2798 static HWND FASTCALL
2799 IntFindWindow(PWND Parent
,
2802 PUNICODE_STRING WindowName
)
2804 BOOL CheckWindowName
;
2807 UNICODE_STRING CurrentWindowName
;
2811 CheckWindowName
= WindowName
->Buffer
!= 0;
2813 if((List
= IntWinListChildren(Parent
)))
2818 /* skip handles before and including ChildAfter */
2819 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2823 /* search children */
2827 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2832 /* Do not send WM_GETTEXT messages in the kernel mode version!
2833 The user mode version however calls GetWindowText() which will
2834 send WM_GETTEXT messages to windows belonging to its processes */
2835 if (!ClassAtom
|| Child
->pcls
->atomNVClassName
== ClassAtom
)
2837 // FIXME: LARGE_STRING truncated
2838 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2839 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2840 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2841 if(!CheckWindowName
||
2842 (Child
->strName
.Length
< 0xFFFF &&
2843 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2845 Ret
= Child
->head
.h
;
2850 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2858 * Searches a window's children for a window with the specified
2861 * hwndParent = The window whose childs are to be searched.
2863 * HWND_MESSAGE = message-only windows
2865 * hwndChildAfter = Search starts after this child window.
2866 * NULL = start from beginning
2868 * ucClassName = Class name to search for
2869 * Reguired parameter.
2871 * ucWindowName = Window name
2872 * ->Buffer == NULL = don't care
2875 * The HWND of the window if it was found, otherwise NULL
2881 NtUserFindWindowEx(HWND hwndParent
,
2882 HWND hwndChildAfter
,
2883 PUNICODE_STRING ucClassName
,
2884 PUNICODE_STRING ucWindowName
,
2887 PWND Parent
, ChildAfter
;
2888 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2889 HWND Desktop
, Ret
= NULL
;
2890 BOOL DoMessageWnd
= FALSE
;
2891 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2892 DECLARE_RETURN(HWND
);
2894 TRACE("Enter NtUserFindWindowEx\n");
2897 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2901 if (ucClassName
!= NULL
)
2903 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2904 if (ClassName
.Length
!= 0)
2906 ProbeForRead(ClassName
.Buffer
,
2910 else if (!IS_ATOM(ClassName
.Buffer
))
2912 EngSetLastError(ERROR_INVALID_PARAMETER
);
2916 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2919 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
2924 if (ucWindowName
!= NULL
)
2926 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2927 if (WindowName
.Length
!= 0)
2929 ProbeForRead(WindowName
.Buffer
,
2935 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2937 SetLastNtError(_SEH2_GetExceptionCode());
2938 _SEH2_YIELD(RETURN(NULL
));
2942 if (ucClassName
!= NULL
)
2944 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2945 !IS_ATOM(ClassName
.Buffer
))
2947 EngSetLastError(ERROR_INVALID_PARAMETER
);
2950 else if (ClassAtom
== (RTL_ATOM
)0)
2952 /* LastError code was set by IntGetAtomFromStringOrAtom */
2958 Desktop
= IntGetCurrentThreadDesktopWindow();
2960 if(hwndParent
== NULL
)
2962 hwndParent
= Desktop
;
2963 DoMessageWnd
= TRUE
;
2965 else if(hwndParent
== HWND_MESSAGE
)
2967 hwndParent
= IntGetMessageWindow();
2970 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2976 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2983 if(Parent
->head
.h
== Desktop
)
2986 PWND TopLevelWindow
;
2987 BOOLEAN CheckWindowName
;
2988 BOOLEAN WindowMatches
;
2989 BOOLEAN ClassMatches
;
2991 /* windows searches through all top-level windows if the parent is the desktop
2994 if((List
= IntWinListChildren(Parent
)))
3000 /* skip handles before and including ChildAfter */
3001 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
3005 CheckWindowName
= WindowName
.Buffer
!= 0;
3007 /* search children */
3010 UNICODE_STRING ustr
;
3012 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
3017 /* Do not send WM_GETTEXT messages in the kernel mode version!
3018 The user mode version however calls GetWindowText() which will
3019 send WM_GETTEXT messages to windows belonging to its processes */
3020 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
3021 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
3022 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
3023 WindowMatches
= !CheckWindowName
||
3024 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
3025 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
3026 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
3027 ClassAtom
== TopLevelWindow
->pcls
->atomNVClassName
;
3029 if (WindowMatches
&& ClassMatches
)
3031 Ret
= TopLevelWindow
->head
.h
;
3035 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3037 /* window returns the handle of the top-level window, in case it found
3039 Ret
= TopLevelWindow
->head
.h
;
3044 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3049 TRACE("FindWindowEx: Not Desktop Parent!\n");
3050 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3053 if (Ret
== NULL
&& DoMessageWnd
)
3057 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3059 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3063 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3065 SetLastNtError(_SEH2_GetExceptionCode());
3073 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3082 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3084 PWND WndAncestor
, Parent
;
3086 if (Wnd
->head
.h
== IntGetDesktopWindow())
3095 WndAncestor
= Wnd
->spwndParent
;
3106 if(!(Parent
= WndAncestor
->spwndParent
))
3110 if(IntIsDesktopWindow(Parent
))
3115 WndAncestor
= Parent
;
3126 Parent
= IntGetParent(WndAncestor
);
3133 WndAncestor
= Parent
;
3151 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3153 PWND Window
, Ancestor
;
3154 DECLARE_RETURN(HWND
);
3156 TRACE("Enter NtUserGetAncestor\n");
3157 UserEnterExclusive();
3159 if (!(Window
= UserGetWindowObject(hWnd
)))
3164 Ancestor
= UserGetAncestor(Window
, Type
);
3165 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3167 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3170 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3176 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3178 /* combo state struct */
3192 INT fixedOwnerDrawHeight
;
3193 INT droppedWidth
; /* last two are not used unless set */
3194 INT editHeight
; /* explicitly */
3196 } HEADCOMBO
,*LPHEADCOMBO
;
3198 // Window Extra data container.
3199 typedef struct _WND2CBOX
3203 } WND2CBOX
, *PWND2CBOX
;
3205 #define CBF_BUTTONDOWN 0x0002
3211 NtUserGetComboBoxInfo(
3217 BOOL NotSameppi
= FALSE
;
3219 DECLARE_RETURN(BOOL
);
3221 TRACE("Enter NtUserGetComboBoxInfo\n");
3224 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3230 ProbeForWrite(pcbi
, sizeof(COMBOBOXINFO
), 1);
3232 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3234 SetLastNtError(_SEH2_GetExceptionCode());
3235 _SEH2_YIELD(RETURN(FALSE
));
3239 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3241 EngSetLastError(ERROR_INVALID_PARAMETER
);
3245 // Pass the user pointer, it was already probed.
3246 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3248 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3251 ppi
= PsGetCurrentProcessWin32Process();
3252 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3255 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3260 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3261 pcbi
->rcItem
= lphc
->textRect
;
3262 pcbi
->rcButton
= lphc
->buttonRect
;
3263 pcbi
->stateButton
= 0;
3264 if (lphc
->wState
& CBF_BUTTONDOWN
)
3265 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3266 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3267 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3268 pcbi
->hwndCombo
= lphc
->self
;
3269 pcbi
->hwndItem
= lphc
->hWndEdit
;
3270 pcbi
->hwndList
= lphc
->hWndLBox
;
3272 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3275 SetLastNtError(_SEH2_GetExceptionCode());
3282 if (NotSameppi
) KeDetachProcess();
3283 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3289 //// ReactOS work around! Keep it the sames as in Listbox.c
3291 /* Listbox structure */
3294 HWND self
; /* Our own window handle */
3295 HWND owner
; /* Owner window to send notifications to */
3296 UINT style
; /* Window style */
3297 INT width
; /* Window width */
3298 INT height
; /* Window height */
3299 VOID
*items
; /* Array of items */
3300 INT nb_items
; /* Number of items */
3301 INT top_item
; /* Top visible item */
3302 INT selected_item
; /* Selected item */
3303 INT focus_item
; /* Item that has the focus */
3304 INT anchor_item
; /* Anchor item for extended selection */
3305 INT item_height
; /* Default item height */
3306 INT page_size
; /* Items per listbox page */
3307 INT column_width
; /* Column width for multi-column listboxes */
3310 // Window Extra data container.
3311 typedef struct _WND2LB
3321 NtUserGetListBoxInfo(
3326 BOOL NotSameppi
= FALSE
;
3328 DECLARE_RETURN(DWORD
);
3330 TRACE("Enter NtUserGetListBoxInfo\n");
3333 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3338 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3340 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3343 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3344 ppi
= PsGetCurrentProcessWin32Process();
3345 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3348 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3353 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3354 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3355 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3356 Ret
= descr
->page_size
* descr
->column_width
;
3358 Ret
= descr
->page_size
;
3360 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3363 SetLastNtError(_SEH2_GetExceptionCode());
3370 if (NotSameppi
) KeDetachProcess();
3371 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3379 * The NtUserSetParent function changes the parent window of the specified
3383 * The new parent window and the child window must belong to the same
3384 * application. If the window identified by the hWndChild parameter is
3385 * visible, the system performs the appropriate redrawing and repainting.
3386 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3387 * or WS_POPUP window styles of the window whose parent is being changed.
3394 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3396 DECLARE_RETURN(HWND
);
3398 TRACE("Enter NtUserSetParent\n");
3399 UserEnterExclusive();
3402 Check Parent first from user space, set it here.
3406 hWndNewParent
= IntGetDesktopWindow();
3408 else if (hWndNewParent
== HWND_MESSAGE
)
3410 hWndNewParent
= IntGetMessageWindow();
3413 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3416 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3422 * UserGetShellWindow
3424 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3429 HWND FASTCALL
UserGetShellWindow(VOID
)
3431 PWINSTATION_OBJECT WinStaObject
;
3434 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3440 if (!NT_SUCCESS(Status
))
3442 SetLastNtError(Status
);
3446 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3448 ObDereferenceObject(WinStaObject
);
3453 * NtUserSetShellWindowEx
3455 * This is undocumented function to set global shell window. The global
3456 * shell window has special handling of window position.
3462 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3464 PWINSTATION_OBJECT WinStaObject
;
3465 PWND WndShell
, WndListView
;
3466 DECLARE_RETURN(BOOL
);
3467 USER_REFERENCE_ENTRY Ref
;
3471 TRACE("Enter NtUserSetShellWindowEx\n");
3472 UserEnterExclusive();
3474 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3479 if (!(WndListView
= UserGetWindowObject(hwndListView
)))
3484 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3490 if (!NT_SUCCESS(Status
))
3492 SetLastNtError(Status
);
3497 * Test if we are permitted to change the shell window.
3499 if (WinStaObject
->ShellWindow
)
3501 ObDereferenceObject(WinStaObject
);
3506 * Move shell window into background.
3508 if (hwndListView
&& hwndListView
!= hwndShell
)
3511 * Disabled for now to get Explorer working.
3512 * -- Filip, 01/nov/2003
3515 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3518 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3520 ObDereferenceObject(WinStaObject
);
3525 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3527 ObDereferenceObject(WinStaObject
);
3531 UserRefObjectCo(WndShell
, &Ref
);
3532 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3533 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3535 WinStaObject
->ShellWindow
= hwndShell
;
3536 WinStaObject
->ShellListView
= hwndListView
;
3538 ti
= GetW32ThreadInfo();
3541 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3542 ti
->pDeskInfo
->spwndShell
= WndShell
;
3543 ti
->pDeskInfo
->spwndBkGnd
= WndListView
;
3544 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3547 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3549 UserDerefObjectCo(WndShell
);
3551 ObDereferenceObject(WinStaObject
);
3555 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3560 // Fixes wine Win test_window_styles and todo tests...
3561 static BOOL FASTCALL
3562 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3564 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3566 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3573 co_IntSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
, ULONG Size
, BOOL bAlter
)
3575 PWND Window
, Parent
;
3576 PWINSTATION_OBJECT WindowStation
;
3580 if (!(Window
= UserGetWindowObject(hWnd
)))
3585 if ((INT
)Index
>= 0)
3587 if ((Index
+ Size
) > Window
->cbwndExtra
)
3589 EngSetLastError(ERROR_INVALID_INDEX
);
3594 if (Size
== sizeof(LONG
))
3596 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3597 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = (LONG
)NewValue
;
3602 OldValue
= *((LONG_PTR
*)((PCHAR
)(Window
+ 1) + Index
));
3604 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3606 OldValue = (LONG_PTR)IntSetWindowProc( Wnd, (WNDPROC)NewValue, Ansi);
3607 if (!OldValue) return 0;
3610 *((LONG_PTR
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3617 if (Size
== sizeof(LONG
))
3619 if ((Index
!= GWL_STYLE
) &&
3620 (Index
!= GWL_EXSTYLE
) &&
3621 (Index
!= GWL_ID
) &&
3622 (Index
!= GWL_USERDATA
))
3624 ERR("NtUserSetWindowLong(): Index requires pointer size: %lu\n", Index
);
3625 EngSetLastError(ERROR_INVALID_INDEX
);
3633 case GWL_EXSTYLE
: // LONG
3634 OldValue
= (LONG
) Window
->ExStyle
;
3635 Style
.styleOld
= OldValue
;
3636 Style
.styleNew
= NewValue
;
3638 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3641 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3643 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3646 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3647 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3649 /* WS_EX_WINDOWEDGE depends on some other styles */
3650 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3651 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3653 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3655 if (!(Window
->ExStyle
& WS_EX_LAYERED
))
3657 SetLayeredStatus(Window
, 0);
3660 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3662 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3665 case GWL_STYLE
: // LONG
3666 OldValue
= (LONG
) Window
->style
;
3667 Style
.styleOld
= OldValue
;
3668 Style
.styleNew
= NewValue
;
3671 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3673 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3674 if (UserIsDesktopWindow(Window
->spwndParent
)) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3675 /* WS_MINIMIZE can't be reset */
3676 if (OldValue
& WS_MINIMIZE
) Style
.styleNew
|= WS_MINIMIZE
;
3677 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3678 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3679 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3681 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3683 if ((OldValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3685 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
3687 //// From child to non-child it should be null already.
3688 ERR("IDMenu going null! %d\n",Window
->IDMenu
);
3689 Window
->IDMenu
= 0; // Window->spmenu = 0;
3694 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3696 PMENU pMenu
= UserGetMenuObject(UlongToHandle(Window
->IDMenu
));
3697 Window
->state
&= ~WNDS_HASMENU
;
3700 ERR("IDMenu released 0x%p\n",pMenu
);
3701 // ROS may not hold a lock after setting menu to window. But it should!
3702 //IntReleaseMenuObject(pMenu);
3707 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3709 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3710 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3711 DceResetActiveDCEs( Window
);
3713 Window
->style
= (DWORD
)Style
.styleNew
;
3716 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3719 case GWLP_WNDPROC
: // LONG_PTR
3721 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3722 Window
->fnid
& FNID_FREED
)
3724 EngSetLastError(ERROR_ACCESS_DENIED
);
3727 OldValue
= (LONG_PTR
)IntSetWindowProc(Window
,
3733 case GWLP_HINSTANCE
: // LONG_PTR
3734 OldValue
= (LONG_PTR
) Window
->hModule
;
3735 Window
->hModule
= (HINSTANCE
) NewValue
;
3738 case GWLP_HWNDPARENT
: // LONG_PTR
3739 Parent
= Window
->spwndParent
;
3740 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3741 OldValue
= (LONG_PTR
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3743 OldValue
= (LONG_PTR
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3746 case GWLP_ID
: // LONG
3747 OldValue
= (LONG
) Window
->IDMenu
;
3748 Window
->IDMenu
= (UINT
) NewValue
;
3751 case GWLP_USERDATA
: // LONG or LONG_PTR
3752 OldValue
= Window
->dwUserData
;
3753 Window
->dwUserData
= NewValue
;
3757 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3758 EngSetLastError(ERROR_INVALID_INDEX
);
3768 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3770 return (LONG
)co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG
), FALSE
);
3774 co_UserSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
)
3776 return co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG_PTR
), FALSE
);
3780 * NtUserSetWindowLong
3782 * The NtUserSetWindowLong function changes an attribute of the specified
3783 * window. The function also sets the 32-bit (long) value at the specified
3784 * offset into the extra window memory.
3791 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3795 UserEnterExclusive();
3797 if (hWnd
== IntGetDesktopWindow())
3799 EngSetLastError(STATUS_ACCESS_DENIED
);
3804 ret
= (LONG
)co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG
), FALSE
);
3813 NtUserSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
)
3817 UserEnterExclusive();
3819 if (hWnd
== IntGetDesktopWindow())
3821 EngSetLastError(STATUS_ACCESS_DENIED
);
3826 ret
= co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG_PTR
), FALSE
);
3835 NtUserAlterWindowStyle(HWND hWnd
, DWORD Index
, LONG NewValue
)
3839 UserEnterExclusive();
3841 if (hWnd
== IntGetDesktopWindow())
3843 EngSetLastError(STATUS_ACCESS_DENIED
);
3848 ret
= co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, FALSE
, sizeof(LONG
), TRUE
);
3857 * NtUserSetWindowWord
3859 * Legacy function similar to NtUserSetWindowLong.
3866 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3870 DECLARE_RETURN(WORD
);
3872 TRACE("Enter NtUserSetWindowWord\n");
3873 UserEnterExclusive();
3875 if (hWnd
== IntGetDesktopWindow())
3877 EngSetLastError(STATUS_ACCESS_DENIED
);
3881 if (!(Window
= UserGetWindowObject(hWnd
)))
3890 case GWL_HWNDPARENT
:
3891 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3895 EngSetLastError(ERROR_INVALID_INDEX
);
3900 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3902 EngSetLastError(ERROR_INVALID_PARAMETER
);
3906 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3907 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3912 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3918 QueryWindow based on KJK::Hyperion and James Tabor.
3920 0 = QWUniqueProcessId
3921 1 = QWUniqueThreadId
3924 4 = QWIsHung Implements IsHungAppWindow found
3927 9 = QWKillWindow When I called this with hWnd ==
3928 DesktopWindow, it shutdown the system
3935 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3937 /* Console Leader Process CID Window offsets */
3938 #define GWLP_CONSOLE_LEADER_PID 0
3939 #define GWLP_CONSOLE_LEADER_TID 4
3943 DECLARE_RETURN(UINT
);
3945 TRACE("Enter NtUserQueryWindow\n");
3948 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3955 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3957 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3958 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3960 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
3961 Result
= (DWORD_PTR
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
3965 Result
= (DWORD_PTR
)IntGetWndProcessId(pWnd
);
3970 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3972 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3973 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3975 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
3976 Result
= (DWORD_PTR
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
3980 Result
= (DWORD_PTR
)IntGetWndThreadId(pWnd
);
3985 case QUERY_WINDOW_ACTIVE
:
3986 Result
= (DWORD_PTR
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3989 case QUERY_WINDOW_FOCUS
:
3990 Result
= (DWORD_PTR
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3993 case QUERY_WINDOW_ISHUNG
:
3994 Result
= (DWORD_PTR
)MsqIsHung(pWnd
->head
.pti
);
3997 case QUERY_WINDOW_REAL_ID
:
3998 Result
= (DWORD_PTR
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
4001 case QUERY_WINDOW_FOREGROUND
:
4002 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
4013 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
4022 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4024 UNICODE_STRING SafeMessageName
;
4027 DECLARE_RETURN(UINT
);
4029 TRACE("Enter NtUserRegisterWindowMessage\n");
4030 UserEnterExclusive();
4032 if(MessageNameUnsafe
== NULL
)
4034 EngSetLastError(ERROR_INVALID_PARAMETER
);
4038 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4039 if(!NT_SUCCESS(Status
))
4041 SetLastNtError(Status
);
4045 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4046 if (SafeMessageName
.Buffer
)
4047 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4051 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
4060 NtUserSetWindowFNID(HWND hWnd
,
4064 DECLARE_RETURN(BOOL
);
4066 TRACE("Enter NtUserSetWindowFNID\n");
4067 UserEnterExclusive();
4069 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4074 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
4076 EngSetLastError(ERROR_ACCESS_DENIED
);
4080 // From user land we only set these.
4081 if (fnID
!= FNID_DESTROY
)
4083 /* HACK: The minimum should be FNID_BUTTON, but menu code relies on this */
4084 if (fnID
< FNID_FIRST
|| fnID
> FNID_GHOST
||
4087 EngSetLastError(ERROR_INVALID_PARAMETER
);
4096 TRACE("Leave NtUserSetWindowFNID\n");
4102 DefSetText(PWND Wnd
, PCWSTR WindowText
)
4104 UNICODE_STRING UnicodeString
;
4107 RtlInitUnicodeString(&UnicodeString
, WindowText
);
4109 if (UnicodeString
.Length
!= 0)
4111 if (Wnd
->strName
.MaximumLength
> 0 &&
4112 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4114 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4116 Wnd
->strName
.Length
= UnicodeString
.Length
;
4117 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4118 RtlCopyMemory(Wnd
->strName
.Buffer
,
4119 UnicodeString
.Buffer
,
4120 UnicodeString
.Length
);
4125 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4126 buf
= Wnd
->strName
.Buffer
;
4127 Wnd
->strName
.Buffer
= NULL
;
4130 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4133 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4134 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4135 if (Wnd
->strName
.Buffer
!= NULL
)
4137 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4138 RtlCopyMemory(Wnd
->strName
.Buffer
,
4139 UnicodeString
.Buffer
,
4140 UnicodeString
.Length
);
4141 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4142 Wnd
->strName
.Length
= UnicodeString
.Length
;
4146 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4153 Wnd
->strName
.Length
= 0;
4154 if (Wnd
->strName
.Buffer
!= NULL
)
4155 Wnd
->strName
.Buffer
[0] = L
'\0';
4158 // FIXME: HAX! Windows does not do this in here!
4159 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4160 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4161 /* Send shell notifications */
4162 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4164 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) UserHMGetHandle(Wnd
), FALSE
); // FIXME Flashing?
4169 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4176 * Undocumented function that is called from DefWindowProc to set
4183 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4186 LARGE_STRING SafeText
;
4187 UNICODE_STRING UnicodeString
;
4190 TRACE("Enter NtUserDefSetText\n");
4192 if (WindowText
!= NULL
)
4196 SafeText
= ProbeForReadLargeString(WindowText
);
4198 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4201 SetLastNtError(_SEH2_GetExceptionCode());
4211 UserEnterExclusive();
4213 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4219 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4220 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4221 // Now we know what the bAnsi is for.
4222 RtlInitUnicodeString(&UnicodeString
, NULL
);
4223 if (SafeText
.Buffer
)
4228 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4230 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4231 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4233 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4236 SetLastNtError(_SEH2_GetExceptionCode());
4239 if (!Ret
) goto Exit
;
4242 if (UnicodeString
.Length
!= 0)
4244 if (Wnd
->strName
.MaximumLength
> 0 &&
4245 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4247 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4249 Wnd
->strName
.Length
= UnicodeString
.Length
;
4250 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4251 RtlCopyMemory(Wnd
->strName
.Buffer
,
4252 UnicodeString
.Buffer
,
4253 UnicodeString
.Length
);
4258 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4259 buf
= Wnd
->strName
.Buffer
;
4260 Wnd
->strName
.Buffer
= NULL
;
4263 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4266 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4267 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4268 if (Wnd
->strName
.Buffer
!= NULL
)
4270 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4271 RtlCopyMemory(Wnd
->strName
.Buffer
,
4272 UnicodeString
.Buffer
,
4273 UnicodeString
.Length
);
4274 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4275 Wnd
->strName
.Length
= UnicodeString
.Length
;
4279 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4287 Wnd
->strName
.Length
= 0;
4288 if (Wnd
->strName
.Buffer
!= NULL
)
4289 Wnd
->strName
.Buffer
[0] = L
'\0';
4292 // FIXME: HAX! Windows does not do this in here!
4293 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4294 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4295 /* Send shell notifications */
4296 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4298 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4303 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4304 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4310 * NtUserInternalGetWindowText
4317 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4322 DECLARE_RETURN(INT
);
4324 TRACE("Enter NtUserInternalGetWindowText\n");
4327 if(lpString
&& (nMaxCount
<= 1))
4329 EngSetLastError(ERROR_INVALID_PARAMETER
);
4333 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4338 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4341 const WCHAR Terminator
= L
'\0';
4343 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4345 Copy
= min(nMaxCount
- 1, Result
);
4348 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4349 if(!NT_SUCCESS(Status
))
4351 SetLastNtError(Status
);
4357 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4358 if(!NT_SUCCESS(Status
))
4360 SetLastNtError(Status
);
4370 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4380 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4386 // ASSERT(OwnerWnd);
4388 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4389 win_array
= IntWinListChildren(OwnerWnd
);
4394 while (win_array
[count
])
4396 while (--count
>= 0)
4398 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4400 if (pWnd
->spwndOwner
!= OwnerWnd
)
4405 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4407 /* In Windows, ShowOwnedPopups(TRUE) generates
4408 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4409 * regardless of the state of the owner
4411 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4417 if (pWnd
->style
& WS_VISIBLE
)
4419 /* In Windows, ShowOwnedPopups(FALSE) generates
4420 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4421 * regardless of the state of the owner
4423 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4429 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4430 TRACE("Leave ShowOwnedPopups\n");