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
);
858 Link the window into siblings list
859 children and parent are kept in place.
864 PWND WndInsertAfter
/* set to NULL if top sibling */
867 if ((Wnd
->spwndPrev
= WndInsertAfter
))
869 /* link after WndInsertAfter */
870 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
871 Wnd
->spwndNext
->spwndPrev
= Wnd
;
873 Wnd
->spwndPrev
->spwndNext
= Wnd
;
878 if ((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
) &&
893 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) 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
)
907 WndInsertAfter
= WndInsertAfter
->spwndNext
;
909 IntLinkWindow(Wnd
, WndInsertAfter
);
910 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
912 else if (hWndPrev
== HWND_TOPMOST
)
914 /* Link in the top of the list */
915 IntLinkWindow(Wnd
, NULL
);
917 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
919 else if (hWndPrev
== HWND_TOP
)
921 /* Link it after the last topmost window */
922 PWND WndInsertBefore
;
924 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
926 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
928 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
930 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
931 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
933 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
936 WndInsertBefore
= WndInsertBefore
->spwndNext
;
940 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
944 /* Link it after hWndPrev */
947 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
948 /* Are we called with an erroneous handle */
949 if(WndInsertAfter
== NULL
)
951 /* Link in a default position */
952 IntLinkHwnd(Wnd
, HWND_TOP
);
956 IntLinkWindow(Wnd
, WndInsertAfter
);
958 /* Fix the WS_EX_TOPMOST flag */
959 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
961 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
965 if(WndInsertAfter
->spwndNext
&&
966 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
968 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
972 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
976 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
980 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
983 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
984 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
986 //ERR("ProcessOwnerSwap Old out.\n");
987 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
993 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
996 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
998 //ERR("ProcessOwnerSwap New in.\n");
999 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1003 // FIXME: System Tray checks.
1007 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1009 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1012 Wnd
= IntGetWindowObject(hWnd
);
1016 WndOldOwner
= Wnd
->spwndOwner
;
1018 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1019 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1021 if (!WndNewOwner
&& hWndNewOwner
)
1023 EngSetLastError(ERROR_INVALID_PARAMETER
);
1028 /* if parent belongs to a different thread and the window isn't */
1029 /* top-level, attach the two threads */
1030 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1032 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1036 Wnd
->spwndOwner
= WndNewOwner
;
1040 Wnd
->spwndOwner
= NULL
;
1045 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1046 EngSetLastError(ERROR_INVALID_PARAMETER
);
1050 UserDereferenceObject(Wnd
);
1055 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1057 PWND WndOldParent
, pWndExam
;
1060 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1063 ASSERT(WndNewParent
);
1064 ASSERT_REFS_CO(Wnd
);
1065 ASSERT_REFS_CO(WndNewParent
);
1067 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1069 EngSetLastError(ERROR_ACCESS_DENIED
);
1073 /* Some applications try to set a child as a parent */
1074 if (IntIsChildWindow(Wnd
, WndNewParent
))
1076 TRACE("IntSetParent try to set a child as a parent.\n");
1077 EngSetLastError( ERROR_INVALID_PARAMETER
);
1081 pWndExam
= WndNewParent
; // Load parent Window to examine.
1082 // Now test for set parent to parent hit.
1085 if (Wnd
== pWndExam
)
1087 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1088 EngSetLastError(ERROR_INVALID_PARAMETER
);
1091 pWndExam
= pWndExam
->spwndParent
;
1095 * Windows hides the window first, then shows it again
1096 * including the WM_SHOWWINDOW messages and all
1098 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1100 /* Window must belong to current process */
1101 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1103 ERR("IntSetParent Window must belong to current process!\n");
1107 WndOldParent
= Wnd
->spwndParent
;
1109 if ( WndOldParent
&&
1110 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1111 pt
.x
= Wnd
->rcWindow
.right
;
1113 pt
.x
= Wnd
->rcWindow
.left
;
1114 pt
.y
= Wnd
->rcWindow
.top
;
1116 IntScreenToClient(WndOldParent
, &pt
);
1118 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1120 if (WndNewParent
!= WndOldParent
)
1122 /* Unlink the window from the siblings list */
1123 IntUnlinkWindow(Wnd
);
1124 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1126 /* Set the new parent */
1127 Wnd
->spwndParent
= WndNewParent
;
1129 if ( Wnd
->style
& WS_CHILD
&&
1131 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1133 ERR("SetParent Top Most from Pop up!\n");
1134 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1137 /* Link the window with its new siblings */
1139 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1140 UserIsDesktopWindow(WndNewParent
) ) ? HWND_TOP
: HWND_TOPMOST
) );
1143 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1144 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1146 Wnd
->style
|= WS_CLIPSIBLINGS
;
1147 DceResetActiveDCEs(Wnd
);
1150 /* if parent belongs to a different thread and the window isn't */
1151 /* top-level, attach the two threads */
1152 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1154 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1156 if (WndOldParent
&& (Wnd
->head
.pti
!= WndOldParent
->head
.pti
))
1158 //ERR("SetParent Old out.\n");
1159 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1162 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1164 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1166 //ERR("SetParent New in.\n");
1167 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1172 if (UserIsMessageWindow(WndOldParent
) || UserIsMessageWindow(WndNewParent
))
1173 swFlags
|= SWP_NOACTIVATE
;
1175 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1177 * SetParent additionally needs to make hwnd the top window
1178 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1179 * WM_WINDOWPOSCHANGED notification messages.
1181 //ERR("IntSetParent SetWindowPos 1\n");
1182 co_WinPosSetWindowPos( Wnd
,
1183 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1184 pt
.x
, pt
.y
, 0, 0, swFlags
);
1185 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1186 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1188 return WndOldParent
;
1192 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1194 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1195 HWND hWndOldParent
= NULL
;
1196 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1198 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1200 EngSetLastError(ERROR_INVALID_PARAMETER
);
1204 if (hWndChild
== IntGetDesktopWindow())
1206 ERR("UserSetParent Access Denied!\n");
1207 EngSetLastError(ERROR_ACCESS_DENIED
);
1213 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1215 ERR("UserSetParent Bad New Parent!\n");
1221 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1227 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1229 ERR("UserSetParent Bad Child!\n");
1233 UserRefObjectCo(Wnd
, &Ref
);
1234 UserRefObjectCo(WndParent
, &ParentRef
);
1235 //ERR("Enter co_IntSetParent\n");
1236 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1237 //ERR("Leave co_IntSetParent\n");
1238 UserDerefObjectCo(WndParent
);
1239 UserDerefObjectCo(Wnd
);
1243 hWndOldParent
= WndOldParent
->head
.h
;
1244 UserDereferenceObject(WndOldParent
);
1247 return( hWndOldParent
);
1250 /* Unlink the window from siblings. children and parent are kept in place. */
1252 IntUnlinkWindow(PWND Wnd
)
1255 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1258 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1260 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1261 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1263 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1266 /* FUNCTIONS *****************************************************************/
1269 * As best as I can figure, this function is used by EnumWindows,
1270 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1272 * It's supposed to build a list of HWNDs to return to the caller.
1273 * We can figure out what kind of list by what parameters are
1281 NtUserBuildHwndList(
1294 return ERROR_INVALID_PARAMETER
;
1296 if (hwndParent
|| !dwThreadId
)
1299 PWND Parent
, Window
;
1303 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1305 return ERROR_INVALID_HANDLE
;
1310 Status
= IntValidateDesktopHandle(hDesktop
,
1314 if(!NT_SUCCESS(Status
))
1316 return ERROR_INVALID_HANDLE
;
1319 hwndParent
= Desktop
->DesktopWindow
;
1326 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1327 (Window
= Parent
->spwndChild
))
1329 BOOL bGoDown
= TRUE
;
1331 Status
= STATUS_SUCCESS
;
1336 if(dwCount
++ < *pBufSize
&& pWnd
)
1340 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1341 *pWnd
= Window
->head
.h
;
1344 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1346 Status
= _SEH2_GetExceptionCode();
1349 if(!NT_SUCCESS(Status
))
1351 SetLastNtError(Status
);
1355 if (Window
->spwndChild
&& bChildren
)
1357 Window
= Window
->spwndChild
;
1362 if (Window
->spwndNext
)
1364 Window
= Window
->spwndNext
;
1368 Window
= Window
->spwndParent
;
1369 if (Window
== Parent
)
1378 ObDereferenceObject(Desktop
);
1381 else // Build EnumThreadWindows list!
1384 PTHREADINFO W32Thread
;
1388 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1389 if (!NT_SUCCESS(Status
))
1391 ERR("Thread Id is not valid!\n");
1392 return ERROR_INVALID_PARAMETER
;
1394 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1396 ObDereferenceObject(Thread
);
1397 TRACE("Tried to enumerate windows of a non gui thread\n");
1398 return ERROR_INVALID_PARAMETER
;
1401 // Do not use Thread link list due to co_UserFreeWindow!!!
1402 // Current = W32Thread->WindowListHead.Flink;
1403 // Fixes Api:CreateWindowEx tests!!!
1404 List
= IntWinListChildren(UserGetDesktopWindow());
1408 for (i
= 0; List
[i
]; i
++)
1410 Window
= ValidateHwndNoErr(List
[i
]);
1411 if (Window
&& Window
->head
.pti
== W32Thread
)
1413 if (dwCount
< *pBufSize
&& pWnd
)
1417 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1418 *pWnd
= Window
->head
.h
;
1421 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1423 Status
= _SEH2_GetExceptionCode();
1426 if (!NT_SUCCESS(Status
))
1428 ERR("Failure to build window list!\n");
1429 SetLastNtError(Status
);
1436 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
1439 ObDereferenceObject(Thread
);
1442 *pBufSize
= dwCount
;
1443 return STATUS_SUCCESS
;
1446 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1448 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1449 !(pWindow
->ExStyle
& WS_EX_NOPARENTNOTIFY
))
1451 if (VerifyWnd(pWindow
->spwndParent
) && !UserIsDesktopWindow(pWindow
->spwndParent
))
1453 USER_REFERENCE_ENTRY Ref
;
1454 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1455 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1457 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1458 (LPARAM
)pWindow
->head
.h
);
1459 UserDerefObjectCo(pWindow
->spwndParent
);
1465 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1467 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1469 /* default positioning for overlapped windows */
1470 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1473 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1475 pMonitor
= UserGetPrimaryMonitor();
1477 /* Check if we don't have a monitor attached yet */
1478 if(pMonitor
== NULL
)
1486 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1488 if (IS_DEFAULT(Cs
->x
))
1490 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1492 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1494 Cs
->x
= ProcessParams
->StartingX
;
1495 Cs
->y
= ProcessParams
->StartingY
;
1499 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1500 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1501 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1502 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1504 /* reset counter and position */
1507 pMonitor
->cWndStack
= 0;
1509 pMonitor
->cWndStack
++;
1513 if (IS_DEFAULT(Cs
->cx
))
1515 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1517 Cs
->cx
= ProcessParams
->CountX
;
1518 Cs
->cy
= ProcessParams
->CountY
;
1522 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1523 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1526 /* neither x nor cx are default. Check the y values .
1527 * In the trace we see Outlook and Outlook Express using
1528 * cy set to CW_USEDEFAULT when opening the address book.
1530 else if (IS_DEFAULT(Cs
->cy
))
1532 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1533 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1538 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1539 if(IS_DEFAULT(Cs
->x
))
1544 if(IS_DEFAULT(Cs
->cx
))
1554 /* Allocates and initializes a window */
1555 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1556 PLARGE_STRING WindowName
,
1561 PDESKTOP pdeskCreated
)
1565 PTHREADINFO pti
= NULL
;
1567 BOOL bUnicodeWindow
;
1569 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1571 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1572 { // Need both here for wine win.c test_CreateWindow.
1573 //if (Cs->hwndParent && ParentWindow)
1574 if (ParentWindow
) // It breaks more tests..... WIP.
1576 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1577 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1578 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1579 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1583 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1585 * Dialog boxes and message boxes do not inherit layout, so you must
1586 * set the layout explicitly.
1588 if ( Class
->fnid
!= FNID_DIALOG
)
1590 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1592 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1598 /* Automatically add WS_EX_WINDOWEDGE */
1599 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1600 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1601 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1602 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1604 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1606 /* Is it a unicode window? */
1607 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1608 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1610 /* Allocate the new window */
1611 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1612 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1616 sizeof(WND
) + Class
->cbwndExtra
);
1623 TRACE("Created window object with handle %p\n", hWnd
);
1625 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1626 { /* HACK: Helper for win32csr/desktopbg.c */
1627 /* If there is no desktop window yet, we must be creating it */
1628 TRACE("CreateWindow setting desktop.\n");
1629 pdeskCreated
->DesktopWindow
= hWnd
;
1630 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1634 * Fill out the structure describing it.
1636 /* Remember, pWnd->head is setup in object.c ... */
1637 pWnd
->spwndParent
= ParentWindow
;
1638 pWnd
->spwndOwner
= OwnerWindow
;
1640 pWnd
->spwndLastActive
= pWnd
;
1641 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1643 pWnd
->hModule
= Cs
->hInstance
;
1644 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1645 pWnd
->ExStyle
= Cs
->dwExStyle
;
1646 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1647 pWnd
->pActCtx
= acbiBuffer
;
1648 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1649 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1651 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1653 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1654 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1657 pWnd
->head
.pti
->cWindows
++;
1659 if (Class
->spicn
&& !Class
->spicnSm
)
1661 HICON IconSmHandle
= NULL
;
1662 if((Class
->spicn
->CURSORF_flags
& (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1663 == (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1665 IconSmHandle
= co_IntCopyImage(
1666 UserHMGetHandle(Class
->spicn
),
1668 UserGetSystemMetrics( SM_CXSMICON
),
1669 UserGetSystemMetrics( SM_CYSMICON
),
1670 LR_COPYFROMRESOURCE
);
1674 /* Retry without copying from resource */
1675 IconSmHandle
= co_IntCopyImage(
1676 UserHMGetHandle(Class
->spicn
),
1678 UserGetSystemMetrics( SM_CXSMICON
),
1679 UserGetSystemMetrics( SM_CYSMICON
),
1685 Class
->spicnSm
= UserGetCurIconObject(IconSmHandle
);
1686 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1690 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1691 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1693 /* BugBoy Comments: Comment below say that System classes are always created
1694 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1695 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1697 No where can I see in code or through testing does the window change back
1698 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1699 see what problems this would cause. */
1701 // Set WndProc from Class.
1702 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1704 // GetWindowProc, test for non server side default classes and set WndProc.
1705 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1709 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1710 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1714 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1715 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1719 // If not an Unicode caller, set Ansi creator bit.
1720 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1722 // Clone Class Ansi/Unicode proc type.
1723 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1725 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1726 pWnd
->Unicode
= FALSE
;
1730 * It seems there can be both an Ansi creator and Unicode Class Window
1731 * WndProc, unless the following overriding conditions occur:
1733 if ( !bUnicodeWindow
&&
1734 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1735 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1736 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1737 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1738 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1739 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1740 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1741 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1742 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1743 { // Override Class and set the window Ansi WndProc.
1744 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1745 pWnd
->Unicode
= FALSE
;
1748 { // Set the window Unicode WndProc.
1749 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1750 pWnd
->Unicode
= TRUE
;
1754 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1755 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1756 Dont understand why it does this. */
1757 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1759 PCALLPROCDATA CallProc
;
1760 CallProc
= CreateCallProc(pWnd
->head
.rpdesk
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1764 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1765 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1769 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1773 InitializeListHead(&pWnd
->PropListHead
);
1774 pWnd
->PropListItems
= 0;
1776 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1778 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1779 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1780 if (pWnd
->strName
.Buffer
== NULL
)
1785 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1786 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1787 pWnd
->strName
.Length
= WindowName
->Length
;
1788 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1791 /* Correct the window style. */
1792 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1794 pWnd
->style
|= WS_CLIPSIBLINGS
;
1795 if (!(pWnd
->style
& WS_POPUP
))
1797 pWnd
->style
|= WS_CAPTION
;
1801 /* WS_EX_WINDOWEDGE depends on some other styles */
1802 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1803 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1804 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1806 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1807 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1808 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1811 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1813 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1814 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1816 /* Set the window menu */
1817 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1821 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1823 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1825 UNICODE_STRING MenuName
;
1828 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1830 MenuName
.Length
= 0;
1831 MenuName
.MaximumLength
= 0;
1832 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1836 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1838 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1839 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1843 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1846 if ( ParentWindow
&&
1847 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1848 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1850 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1852 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1854 EngSetLastError(ERROR_INVALID_PARAMETER
);
1857 if ( pWnd
->spwndOwner
&&
1858 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1860 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1862 if ( pWnd
->spwndOwner
&&
1863 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1864 pti
!= pWnd
->spwndOwner
->head
.pti
)
1866 //ERR("CreateWindow Owner in.\n");
1867 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1871 /* Insert the window into the thread's window list. */
1872 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1874 /* Handle "CS_CLASSDC", it is tested first. */
1875 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1876 { /* One DCE per class to have CLASS. */
1877 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1879 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1880 { /* Allocate a DCE for this window. */
1881 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1887 ERR("IntCreateWindow Allocation Error.\n");
1888 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1891 UserDereferenceObject(pWnd
);
1899 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1900 PUNICODE_STRING ClassName
,
1901 PLARGE_STRING WindowName
,
1905 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1906 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1907 PWINSTATION_OBJECT WinSta
;
1910 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1911 CBT_CREATEWNDW
* pCbtCreate
;
1913 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1915 DWORD dwShowMode
= SW_SHOW
;
1916 CREATESTRUCTW
*pCsw
= NULL
;
1917 PVOID pszClass
= NULL
, pszName
= NULL
;
1920 /* Get the current window station and reference it */
1921 pti
= GetW32ThreadInfo();
1922 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1924 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1925 return NULL
; // There is nothing to cleanup.
1927 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1928 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1933 /* Get the class and reference it */
1934 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
1937 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
1938 ERR("Failed to find class %wZ\n", ClassName
);
1942 /* Now find the parent and the owner window */
1943 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
1946 if (Cs
->hwndParent
== HWND_MESSAGE
)
1948 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
1950 else if (Cs
->hwndParent
)
1952 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1953 hWndOwner
= Cs
->hwndParent
;
1955 hWndParent
= Cs
->hwndParent
;
1957 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1959 ERR("Cannot create a child window without a parent!\n");
1960 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1961 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1964 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1965 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1967 if (hWndParent
&& !ParentWindow
)
1969 ERR("Got invalid parent window handle\n");
1972 else if (hWndOwner
&& !OwnerWindow
)
1974 ERR("Got invalid owner window handle\n");
1975 ParentWindow
= NULL
;
1981 if (IntIsDesktopWindow(OwnerWindow
)) OwnerWindow
= NULL
;
1982 else if (ParentWindow
&& !IntIsDesktopWindow(ParentWindow
))
1984 ERR("an owned window must be created as top-level\n");
1985 EngSetLastError( STATUS_ACCESS_DENIED
);
1988 else /* owner must be a top-level window */
1990 while ((OwnerWindow
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
&& !IntIsDesktopWindow(OwnerWindow
->spwndParent
))
1991 OwnerWindow
= OwnerWindow
->spwndParent
;
1995 /* Fix the position and the size of the window */
1998 UserRefObjectCo(ParentWindow
, &ParentRef
);
1999 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2002 /* Allocate and initialize the new window */
2003 Window
= IntCreateWindow(Cs
,
2012 ERR("IntCreateWindow failed!\n");
2016 hWnd
= UserHMGetHandle(Window
);
2017 hwndInsertAfter
= HWND_TOP
;
2019 UserRefObjectCo(Window
, &Ref
);
2020 UserDereferenceObject(Window
);
2021 ObDereferenceObject(WinSta
);
2023 //// Check for a hook to eliminate overhead. ////
2024 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2026 // Allocate the calling structures Justin Case this goes Global.
2027 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2028 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2029 if (!pCsw
|| !pCbtCreate
)
2031 ERR("UserHeapAlloc() failed!\n");
2035 /* Fill the new CREATESTRUCTW */
2036 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2037 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2039 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2040 if (!IS_ATOM(ClassName
->Buffer
))
2042 if (Window
->state
& WNDS_ANSICREATOR
)
2044 ANSI_STRING AnsiString
;
2045 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2046 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2049 ERR("UserHeapAlloc() failed!\n");
2052 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2053 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2054 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2058 UNICODE_STRING UnicodeString
;
2059 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2060 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2063 ERR("UserHeapAlloc() failed!\n");
2066 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2067 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2068 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2070 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2072 if (WindowName
->Length
)
2074 UNICODE_STRING Name
;
2075 Name
.Buffer
= WindowName
->Buffer
;
2076 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2077 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2079 if (Window
->state
& WNDS_ANSICREATOR
)
2081 ANSI_STRING AnsiString
;
2082 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2083 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2086 ERR("UserHeapAlloc() failed!\n");
2089 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2090 AnsiString
.Buffer
= (PCHAR
)pszName
;
2091 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2095 UNICODE_STRING UnicodeString
;
2096 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2097 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2100 ERR("UserHeapAlloc() failed!\n");
2103 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2104 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2105 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2107 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2110 pCbtCreate
->lpcs
= pCsw
;
2111 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2113 //// Call the WH_CBT hook ////
2114 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2117 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2120 // Write back changes.
2125 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2128 /* NCCREATE and WM_NCCALCSIZE need the original values */
2129 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2130 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2132 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2134 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2136 Cs
->x
+= ParentWindow
->rcClient
.left
;
2137 Cs
->y
+= ParentWindow
->rcClient
.top
;
2141 /* Send the WM_GETMINMAXINFO message */
2145 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2147 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2148 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2149 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2150 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2151 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2154 Window
->rcWindow
.left
= Cs
->x
;
2155 Window
->rcWindow
.top
= Cs
->y
;
2156 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2157 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2159 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2161 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2162 RECTL_vOffsetRect(&Window->rcWindow,
2163 ParentWindow->rcClient.left,
2164 ParentWindow->rcClient.top);
2167 /* correct child window coordinates if mirroring on parent is enabled */
2168 if (ParentWindow
!= NULL
)
2170 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2171 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2173 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2174 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2178 Window
->rcClient
= Window
->rcWindow
;
2180 /* Link the window */
2181 if (NULL
!= ParentWindow
)
2183 /* Link the window into the siblings list */
2184 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2185 IntLinkHwnd(Window
, HWND_BOTTOM
);
2187 IntLinkHwnd(Window
, hwndInsertAfter
);
2190 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2192 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2193 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2196 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2198 if ( !IntIsTopLevelWindow(Window
) )
2200 if (pti
!= Window
->spwndParent
->head
.pti
)
2202 //ERR("CreateWindow Parent in.\n");
2203 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2208 /* Send the NCCREATE message */
2209 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2212 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2216 /* Send the WM_NCCALCSIZE message */
2219 MaxPos
.x
= Window
->rcWindow
.left
;
2220 MaxPos
.y
= Window
->rcWindow
.top
;
2222 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2223 //rc = Window->rcWindow;
2224 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2225 //Window->rcClient = rc;
2227 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2228 MaxPos
.y
- Window
->rcWindow
.top
);
2231 /* Send the WM_CREATE message. */
2232 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2233 if (Result
== (LRESULT
)-1)
2235 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2239 /* Send the EVENT_OBJECT_CREATE event */
2240 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2242 /* By setting the flag below it can be examined to determine if the window
2243 was created successfully and a valid pwnd was passed back to caller since
2244 from here the function has to succeed. */
2245 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2247 /* Send the WM_SIZE and WM_MOVE messages. */
2248 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2250 co_WinPosSendSizeMove(Window
);
2253 /* Show or maybe minimize or maximize the window. */
2255 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2256 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2259 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2261 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2262 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2263 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2264 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2265 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2268 /* Send the WM_PARENTNOTIFY message */
2269 IntSendParentNotify(Window
, WM_CREATE
);
2271 /* Notify the shell that a new window was created */
2272 if (UserIsDesktopWindow(Window
->spwndParent
) &&
2273 Window
->spwndOwner
== NULL
&&
2274 (Window
->style
& WS_VISIBLE
) &&
2275 (!(Window
->ExStyle
& WS_EX_TOOLWINDOW
) ||
2276 (Window
->ExStyle
& WS_EX_APPWINDOW
)))
2278 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2281 /* Initialize and show the window's scrollbars */
2282 if (Window
->style
& WS_VSCROLL
)
2284 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2286 if (Window
->style
& WS_HSCROLL
)
2288 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2291 /* Show the new window */
2292 if (Cs
->style
& WS_VISIBLE
)
2294 if (Window
->style
& WS_MAXIMIZE
)
2295 dwShowMode
= SW_SHOW
;
2296 else if (Window
->style
& WS_MINIMIZE
)
2297 dwShowMode
= SW_SHOWMINIMIZED
;
2299 co_WinPosShowWindow(Window
, dwShowMode
);
2301 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2303 ASSERT(ParentWindow
);
2306 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2307 /* ShowWindow won't activate child windows */
2308 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2312 if (Class
->atomClassName
== gaGuiConsoleWndClass
)
2314 /* Count only console windows manually */
2315 co_IntUserManualGuiCheck(TRUE
);
2318 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2324 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2325 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2327 co_UserDestroyWindow(Window
);
2329 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2332 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2333 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2334 if (pszName
) UserHeapFree(pszName
);
2335 if (pszClass
) UserHeapFree(pszClass
);
2339 UserDerefObjectCo(Window
);
2341 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2343 // See CORE-13717, not setting error on success.
2345 EngSetLastError(ERROR_SUCCESS
);
2352 ProbeAndCaptureLargeString(
2353 OUT PLARGE_STRING plstrSafe
,
2354 IN PLARGE_STRING plstrUnsafe
)
2356 LARGE_STRING lstrTemp
;
2357 PVOID pvBuffer
= NULL
;
2361 /* Probe and copy the string */
2362 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2363 lstrTemp
= *plstrUnsafe
;
2365 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2368 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2372 if (lstrTemp
.Length
!= 0)
2374 /* Allocate a buffer from paged pool */
2375 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2378 return STATUS_NO_MEMORY
;
2383 /* Probe and copy the buffer */
2384 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2385 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2387 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2389 /* Cleanup and fail */
2390 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2391 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2396 /* Set the output string */
2397 plstrSafe
->Buffer
= pvBuffer
;
2398 plstrSafe
->Length
= lstrTemp
.Length
;
2399 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2401 return STATUS_SUCCESS
;
2405 * \todo Allow passing plstrClassName as ANSI.
2409 NtUserCreateWindowEx(
2411 PLARGE_STRING plstrClassName
,
2412 PLARGE_STRING plstrClsVersion
,
2413 PLARGE_STRING plstrWindowName
,
2421 HINSTANCE hInstance
,
2427 LARGE_STRING lstrWindowName
;
2428 LARGE_STRING lstrClassName
;
2429 LARGE_STRING lstrClsVersion
;
2430 UNICODE_STRING ustrClassName
;
2431 UNICODE_STRING ustrClsVersion
;
2436 lstrWindowName
.Buffer
= NULL
;
2437 lstrClassName
.Buffer
= NULL
;
2438 lstrClsVersion
.Buffer
= NULL
;
2440 ASSERT(plstrWindowName
);
2442 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2444 /* check hMenu is valid handle */
2445 if (hMenu
&& !UserGetMenuObject(hMenu
))
2447 ERR("NtUserCreateWindowEx: Got an invalid menu handle!\n");
2448 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
2453 /* Copy the window name to kernel mode */
2454 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2455 if (!NT_SUCCESS(Status
))
2457 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2458 SetLastNtError(Status
);
2462 plstrWindowName
= &lstrWindowName
;
2464 /* Check if the class is an atom */
2465 if (IS_ATOM(plstrClassName
))
2467 /* It is, pass the atom in the UNICODE_STRING */
2468 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2469 ustrClassName
.Length
= 0;
2470 ustrClassName
.MaximumLength
= 0;
2474 /* It's not, capture the class name */
2475 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2476 if (!NT_SUCCESS(Status
))
2478 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2479 /* Set last error, cleanup and return */
2480 SetLastNtError(Status
);
2484 /* We pass it on as a UNICODE_STRING */
2485 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2486 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2487 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2490 /* Check if the class version is an atom */
2491 if (IS_ATOM(plstrClsVersion
))
2493 /* It is, pass the atom in the UNICODE_STRING */
2494 ustrClsVersion
.Buffer
= (PVOID
)plstrClsVersion
;
2495 ustrClsVersion
.Length
= 0;
2496 ustrClsVersion
.MaximumLength
= 0;
2500 /* It's not, capture the class name */
2501 Status
= ProbeAndCaptureLargeString(&lstrClsVersion
, plstrClsVersion
);
2502 if (!NT_SUCCESS(Status
))
2504 ERR("NtUserCreateWindowEx: failed to capture plstrClsVersion\n");
2505 /* Set last error, cleanup and return */
2506 SetLastNtError(Status
);
2510 /* We pass it on as a UNICODE_STRING */
2511 ustrClsVersion
.Buffer
= lstrClsVersion
.Buffer
;
2512 ustrClsVersion
.Length
= (USHORT
)min(lstrClsVersion
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2513 ustrClsVersion
.MaximumLength
= (USHORT
)min(lstrClsVersion
.MaximumLength
, MAXUSHORT
);
2516 /* Fill the CREATESTRUCTW */
2517 /* we will keep here the original parameters */
2519 Cs
.lpCreateParams
= lpParam
;
2520 Cs
.hInstance
= hInstance
;
2522 Cs
.hwndParent
= hWndParent
;
2527 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2528 Cs
.lpszClass
= ustrClassName
.Buffer
;
2529 Cs
.dwExStyle
= dwExStyle
;
2531 UserEnterExclusive();
2533 /* Call the internal function */
2534 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClsVersion
, plstrWindowName
, acbiBuffer
);
2538 ERR("co_UserCreateWindowEx failed!\n");
2540 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2545 if (lstrWindowName
.Buffer
)
2547 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2549 if (lstrClassName
.Buffer
)
2551 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2553 if (lstrClsVersion
.Buffer
)
2555 ExFreePoolWithTag(lstrClsVersion
.Buffer
, TAG_STRING
);
2562 BOOLEAN
co_UserDestroyWindow(PVOID Object
)
2568 PWND Window
= Object
;
2570 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2572 hWnd
= Window
->head
.h
;
2573 ti
= PsGetCurrentThreadWin32Thread();
2575 TRACE("co_UserDestroyWindow \n");
2577 /* Check for owner thread */
2578 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2580 /* Check if we are destroying the desktop window */
2581 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2583 EngSetLastError(ERROR_ACCESS_DENIED
);
2588 /* If window was created successfully and it is hooked */
2589 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2591 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2593 ERR("Destroy Window WH_CBT Call Hook return!\n");
2598 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2600 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2602 if (Window
->spwndOwner
)
2604 //ERR("DestroyWindow Owner out.\n");
2605 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2610 /* Inform the parent */
2611 if (Window
->style
& WS_CHILD
)
2613 IntSendParentNotify(Window
, WM_DESTROY
);
2616 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
2618 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
2621 /* Hide the window */
2622 if (Window
->style
& WS_VISIBLE
)
2624 if (Window
->style
& WS_CHILD
)
2626 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
2627 co_WinPosShowWindow(Window
, SW_HIDE
);
2631 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2635 // Adjust last active.
2636 if ((pwndTemp
= Window
->spwndOwner
))
2638 while (pwndTemp
->spwndOwner
)
2639 pwndTemp
= pwndTemp
->spwndOwner
;
2641 if (pwndTemp
->spwndLastActive
== Window
)
2642 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2645 if (Window
->spwndParent
&& IntIsWindow(UserHMGetHandle(Window
)))
2647 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2649 if (!IntIsTopLevelWindow(Window
))
2651 //ERR("DestroyWindow Parent out.\n");
2652 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2657 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2658 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2659 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2660 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2661 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2662 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2663 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2664 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2667 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2670 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2672 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2674 ERR("Destroying the ShellWindow!\n");
2675 ti
->pDeskInfo
->hShellWindow
= NULL
;
2679 IntEngWindowChanged(Window
, WOC_DELETE
);
2681 if (!IntIsWindow(UserHMGetHandle(Window
)))
2686 /* Recursively destroy owned windows */
2688 if (! (Window
->style
& WS_CHILD
))
2692 BOOL GotOne
= FALSE
;
2695 PWND Child
, Desktop
;
2697 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2698 UserGetWindowObject(IntGetDesktopWindow());
2699 Children
= IntWinListChildren(Desktop
);
2703 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2705 Child
= UserGetWindowObject(*ChildHandle
);
2708 if (Child
->spwndOwner
!= Window
)
2713 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2715 USER_REFERENCE_ENTRY ChildRef
;
2716 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2717 co_UserDestroyWindow(Child
);
2718 UserDerefObjectCo(Child
); // Temp HACK?
2724 if (Child
->spwndOwner
!= NULL
)
2726 Child
->spwndOwner
= NULL
;
2730 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2739 /* Generate mouse move message for the next window */
2740 msg
.message
= WM_MOUSEMOVE
;
2741 msg
.wParam
= UserGetMouseButtonsState();
2742 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2743 msg
.pt
= gpsi
->ptCursor
;
2744 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2746 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2748 /* Send destroy messages */
2749 IntSendDestroyMsg(UserHMGetHandle(Window
));
2751 if (!IntIsWindow(UserHMGetHandle(Window
)))
2756 /* Destroy the window storage */
2757 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2767 NtUserDestroyWindow(HWND Wnd
)
2770 DECLARE_RETURN(BOOLEAN
);
2772 USER_REFERENCE_ENTRY Ref
;
2774 TRACE("Enter NtUserDestroyWindow\n");
2775 UserEnterExclusive();
2777 if (!(Window
= UserGetWindowObject(Wnd
)))
2782 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2783 ret
= co_UserDestroyWindow(Window
);
2784 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2789 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2795 static HWND FASTCALL
2796 IntFindWindow(PWND Parent
,
2799 PUNICODE_STRING WindowName
)
2801 BOOL CheckWindowName
;
2804 UNICODE_STRING CurrentWindowName
;
2808 CheckWindowName
= WindowName
->Buffer
!= 0;
2810 if((List
= IntWinListChildren(Parent
)))
2815 /* skip handles before and including ChildAfter */
2816 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2820 /* search children */
2824 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2829 /* Do not send WM_GETTEXT messages in the kernel mode version!
2830 The user mode version however calls GetWindowText() which will
2831 send WM_GETTEXT messages to windows belonging to its processes */
2832 if (!ClassAtom
|| Child
->pcls
->atomNVClassName
== ClassAtom
)
2834 // FIXME: LARGE_STRING truncated
2835 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2836 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2837 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2838 if(!CheckWindowName
||
2839 (Child
->strName
.Length
< 0xFFFF &&
2840 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2842 Ret
= Child
->head
.h
;
2847 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2855 * Searches a window's children for a window with the specified
2858 * hwndParent = The window whose childs are to be searched.
2860 * HWND_MESSAGE = message-only windows
2862 * hwndChildAfter = Search starts after this child window.
2863 * NULL = start from beginning
2865 * ucClassName = Class name to search for
2866 * Reguired parameter.
2868 * ucWindowName = Window name
2869 * ->Buffer == NULL = don't care
2872 * The HWND of the window if it was found, otherwise NULL
2878 NtUserFindWindowEx(HWND hwndParent
,
2879 HWND hwndChildAfter
,
2880 PUNICODE_STRING ucClassName
,
2881 PUNICODE_STRING ucWindowName
,
2884 PWND Parent
, ChildAfter
;
2885 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2886 HWND Desktop
, Ret
= NULL
;
2887 BOOL DoMessageWnd
= FALSE
;
2888 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2889 DECLARE_RETURN(HWND
);
2891 TRACE("Enter NtUserFindWindowEx\n");
2894 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2898 if (ucClassName
!= NULL
)
2900 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2901 if (ClassName
.Length
!= 0)
2903 ProbeForRead(ClassName
.Buffer
,
2907 else if (!IS_ATOM(ClassName
.Buffer
))
2909 EngSetLastError(ERROR_INVALID_PARAMETER
);
2913 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2916 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
2921 if (ucWindowName
!= NULL
)
2923 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2924 if (WindowName
.Length
!= 0)
2926 ProbeForRead(WindowName
.Buffer
,
2932 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2934 SetLastNtError(_SEH2_GetExceptionCode());
2935 _SEH2_YIELD(RETURN(NULL
));
2939 if (ucClassName
!= NULL
)
2941 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2942 !IS_ATOM(ClassName
.Buffer
))
2944 EngSetLastError(ERROR_INVALID_PARAMETER
);
2947 else if (ClassAtom
== (RTL_ATOM
)0)
2949 /* LastError code was set by IntGetAtomFromStringOrAtom */
2955 Desktop
= IntGetCurrentThreadDesktopWindow();
2957 if(hwndParent
== NULL
)
2959 hwndParent
= Desktop
;
2960 DoMessageWnd
= TRUE
;
2962 else if(hwndParent
== HWND_MESSAGE
)
2964 hwndParent
= IntGetMessageWindow();
2967 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2973 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2980 if(Parent
->head
.h
== Desktop
)
2983 PWND TopLevelWindow
;
2984 BOOLEAN CheckWindowName
;
2985 BOOLEAN WindowMatches
;
2986 BOOLEAN ClassMatches
;
2988 /* windows searches through all top-level windows if the parent is the desktop
2991 if((List
= IntWinListChildren(Parent
)))
2997 /* skip handles before and including ChildAfter */
2998 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
3002 CheckWindowName
= WindowName
.Buffer
!= 0;
3004 /* search children */
3007 UNICODE_STRING ustr
;
3009 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
3014 /* Do not send WM_GETTEXT messages in the kernel mode version!
3015 The user mode version however calls GetWindowText() which will
3016 send WM_GETTEXT messages to windows belonging to its processes */
3017 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
3018 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
3019 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
3020 WindowMatches
= !CheckWindowName
||
3021 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
3022 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
3023 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
3024 ClassAtom
== TopLevelWindow
->pcls
->atomNVClassName
;
3026 if (WindowMatches
&& ClassMatches
)
3028 Ret
= TopLevelWindow
->head
.h
;
3032 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3034 /* window returns the handle of the top-level window, in case it found
3036 Ret
= TopLevelWindow
->head
.h
;
3041 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3046 TRACE("FindWindowEx: Not Desktop Parent!\n");
3047 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3050 if (Ret
== NULL
&& DoMessageWnd
)
3054 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3056 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3060 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3062 SetLastNtError(_SEH2_GetExceptionCode());
3070 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3079 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3081 PWND WndAncestor
, Parent
;
3083 if (Wnd
->head
.h
== IntGetDesktopWindow())
3092 WndAncestor
= Wnd
->spwndParent
;
3103 if(!(Parent
= WndAncestor
->spwndParent
))
3107 if(IntIsDesktopWindow(Parent
))
3112 WndAncestor
= Parent
;
3123 Parent
= IntGetParent(WndAncestor
);
3130 WndAncestor
= Parent
;
3148 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3150 PWND Window
, Ancestor
;
3151 DECLARE_RETURN(HWND
);
3153 TRACE("Enter NtUserGetAncestor\n");
3154 UserEnterExclusive();
3156 if (!(Window
= UserGetWindowObject(hWnd
)))
3161 Ancestor
= UserGetAncestor(Window
, Type
);
3162 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3164 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3167 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3173 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3175 /* combo state struct */
3189 INT fixedOwnerDrawHeight
;
3190 INT droppedWidth
; /* last two are not used unless set */
3191 INT editHeight
; /* explicitly */
3193 } HEADCOMBO
,*LPHEADCOMBO
;
3195 // Window Extra data container.
3196 typedef struct _WND2CBOX
3200 } WND2CBOX
, *PWND2CBOX
;
3202 #define CBF_BUTTONDOWN 0x0002
3208 NtUserGetComboBoxInfo(
3214 BOOL NotSameppi
= FALSE
;
3216 DECLARE_RETURN(BOOL
);
3218 TRACE("Enter NtUserGetComboBoxInfo\n");
3221 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3227 ProbeForWrite(pcbi
, sizeof(COMBOBOXINFO
), 1);
3229 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3231 SetLastNtError(_SEH2_GetExceptionCode());
3232 _SEH2_YIELD(RETURN(FALSE
));
3236 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3238 EngSetLastError(ERROR_INVALID_PARAMETER
);
3242 // Pass the user pointer, it was already probed.
3243 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3245 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3248 ppi
= PsGetCurrentProcessWin32Process();
3249 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3252 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3257 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3258 pcbi
->rcItem
= lphc
->textRect
;
3259 pcbi
->rcButton
= lphc
->buttonRect
;
3260 pcbi
->stateButton
= 0;
3261 if (lphc
->wState
& CBF_BUTTONDOWN
)
3262 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3263 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3264 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3265 pcbi
->hwndCombo
= lphc
->self
;
3266 pcbi
->hwndItem
= lphc
->hWndEdit
;
3267 pcbi
->hwndList
= lphc
->hWndLBox
;
3269 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3272 SetLastNtError(_SEH2_GetExceptionCode());
3279 if (NotSameppi
) KeDetachProcess();
3280 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3286 //// ReactOS work around! Keep it the sames as in Listbox.c
3288 /* Listbox structure */
3291 HWND self
; /* Our own window handle */
3292 HWND owner
; /* Owner window to send notifications to */
3293 UINT style
; /* Window style */
3294 INT width
; /* Window width */
3295 INT height
; /* Window height */
3296 VOID
*items
; /* Array of items */
3297 INT nb_items
; /* Number of items */
3298 INT top_item
; /* Top visible item */
3299 INT selected_item
; /* Selected item */
3300 INT focus_item
; /* Item that has the focus */
3301 INT anchor_item
; /* Anchor item for extended selection */
3302 INT item_height
; /* Default item height */
3303 INT page_size
; /* Items per listbox page */
3304 INT column_width
; /* Column width for multi-column listboxes */
3307 // Window Extra data container.
3308 typedef struct _WND2LB
3318 NtUserGetListBoxInfo(
3323 BOOL NotSameppi
= FALSE
;
3325 DECLARE_RETURN(DWORD
);
3327 TRACE("Enter NtUserGetListBoxInfo\n");
3330 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3335 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3337 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3340 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3341 ppi
= PsGetCurrentProcessWin32Process();
3342 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3345 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3350 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3351 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3352 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3353 Ret
= descr
->page_size
* descr
->column_width
;
3355 Ret
= descr
->page_size
;
3357 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3360 SetLastNtError(_SEH2_GetExceptionCode());
3367 if (NotSameppi
) KeDetachProcess();
3368 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3376 * The NtUserSetParent function changes the parent window of the specified
3380 * The new parent window and the child window must belong to the same
3381 * application. If the window identified by the hWndChild parameter is
3382 * visible, the system performs the appropriate redrawing and repainting.
3383 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3384 * or WS_POPUP window styles of the window whose parent is being changed.
3391 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3393 DECLARE_RETURN(HWND
);
3395 TRACE("Enter NtUserSetParent\n");
3396 UserEnterExclusive();
3399 Check Parent first from user space, set it here.
3403 hWndNewParent
= IntGetDesktopWindow();
3405 else if (hWndNewParent
== HWND_MESSAGE
)
3407 hWndNewParent
= IntGetMessageWindow();
3410 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3413 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3419 * UserGetShellWindow
3421 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3426 HWND FASTCALL
UserGetShellWindow(VOID
)
3428 PWINSTATION_OBJECT WinStaObject
;
3431 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3437 if (!NT_SUCCESS(Status
))
3439 SetLastNtError(Status
);
3443 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3445 ObDereferenceObject(WinStaObject
);
3450 * NtUserSetShellWindowEx
3452 * This is undocumented function to set global shell window. The global
3453 * shell window has special handling of window position.
3459 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3461 PWINSTATION_OBJECT WinStaObject
;
3462 PWND WndShell
, WndListView
;
3463 DECLARE_RETURN(BOOL
);
3464 USER_REFERENCE_ENTRY Ref
;
3468 TRACE("Enter NtUserSetShellWindowEx\n");
3469 UserEnterExclusive();
3471 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3476 if (!(WndListView
= UserGetWindowObject(hwndListView
)))
3481 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3487 if (!NT_SUCCESS(Status
))
3489 SetLastNtError(Status
);
3494 * Test if we are permitted to change the shell window.
3496 if (WinStaObject
->ShellWindow
)
3498 ObDereferenceObject(WinStaObject
);
3503 * Move shell window into background.
3505 if (hwndListView
&& hwndListView
!= hwndShell
)
3508 * Disabled for now to get Explorer working.
3509 * -- Filip, 01/nov/2003
3512 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3515 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3517 ObDereferenceObject(WinStaObject
);
3522 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3524 ObDereferenceObject(WinStaObject
);
3528 UserRefObjectCo(WndShell
, &Ref
);
3529 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3530 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3532 WinStaObject
->ShellWindow
= hwndShell
;
3533 WinStaObject
->ShellListView
= hwndListView
;
3535 ti
= GetW32ThreadInfo();
3538 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3539 ti
->pDeskInfo
->spwndShell
= WndShell
;
3540 ti
->pDeskInfo
->spwndBkGnd
= WndListView
;
3541 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3544 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3546 UserDerefObjectCo(WndShell
);
3548 ObDereferenceObject(WinStaObject
);
3552 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3557 // Fixes wine Win test_window_styles and todo tests...
3558 static BOOL FASTCALL
3559 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3561 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3563 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3570 co_IntSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
, BOOL bAlter
)
3572 PWND Window
, Parent
;
3573 PWINSTATION_OBJECT WindowStation
;
3577 if (!(Window
= UserGetWindowObject(hWnd
)))
3582 if ((INT
)Index
>= 0)
3584 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3586 EngSetLastError(ERROR_INVALID_INDEX
);
3590 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3592 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3594 OldValue = (LONG)IntSetWindowProc( Wnd,
3597 if (!OldValue) return 0;
3600 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3607 OldValue
= (LONG
) Window
->ExStyle
;
3608 Style
.styleOld
= OldValue
;
3609 Style
.styleNew
= NewValue
;
3611 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3614 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3616 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3619 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3620 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3622 /* WS_EX_WINDOWEDGE depends on some other styles */
3623 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3624 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3626 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3628 if (!(Window
->ExStyle
& WS_EX_LAYERED
))
3630 SetLayeredStatus(Window
, 0);
3633 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3635 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3639 OldValue
= (LONG
) Window
->style
;
3640 Style
.styleOld
= OldValue
;
3641 Style
.styleNew
= NewValue
;
3644 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3646 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3647 if (UserIsDesktopWindow(Window
->spwndParent
)) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3648 /* WS_MINIMIZE can't be reset */
3649 if (OldValue
& WS_MINIMIZE
) Style
.styleNew
|= WS_MINIMIZE
;
3650 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3651 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3652 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3654 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3656 if ((OldValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3658 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
3660 //// From child to non-child it should be null already.
3661 ERR("IDMenu going null! %d\n",Window
->IDMenu
);
3662 Window
->IDMenu
= 0; // Window->spmenu = 0;
3667 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3669 PMENU pMenu
= UserGetMenuObject(UlongToHandle(Window
->IDMenu
));
3670 Window
->state
&= ~WNDS_HASMENU
;
3673 ERR("IDMenu released 0x%p\n",pMenu
);
3674 // ROS may not hold a lock after setting menu to window. But it should!
3675 //IntReleaseMenuObject(pMenu);
3680 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3682 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3683 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3684 DceResetActiveDCEs( Window
);
3686 Window
->style
= (DWORD
)Style
.styleNew
;
3689 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3694 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3695 Window
->fnid
& FNID_FREED
)
3697 EngSetLastError(ERROR_ACCESS_DENIED
);
3700 OldValue
= (LONG
)IntSetWindowProc(Window
,
3707 OldValue
= (LONG
) Window
->hModule
;
3708 Window
->hModule
= (HINSTANCE
) NewValue
;
3711 case GWL_HWNDPARENT
:
3712 Parent
= Window
->spwndParent
;
3713 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3714 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3716 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3720 OldValue
= (LONG
) Window
->IDMenu
;
3721 Window
->IDMenu
= (UINT
) NewValue
;
3725 OldValue
= Window
->dwUserData
;
3726 Window
->dwUserData
= NewValue
;
3730 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3731 EngSetLastError(ERROR_INVALID_INDEX
);
3742 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3744 return co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3748 * NtUserSetWindowLong
3750 * The NtUserSetWindowLong function changes an attribute of the specified
3751 * window. The function also sets the 32-bit (long) value at the specified
3752 * offset into the extra window memory.
3759 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3763 UserEnterExclusive();
3765 if (hWnd
== IntGetDesktopWindow())
3767 EngSetLastError(STATUS_ACCESS_DENIED
);
3772 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3780 NtUserAlterWindowStyle(HWND hWnd
, DWORD Index
, LONG NewValue
)
3784 UserEnterExclusive();
3786 if (hWnd
== IntGetDesktopWindow())
3788 EngSetLastError(STATUS_ACCESS_DENIED
);
3793 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, FALSE
, TRUE
);
3802 * NtUserSetWindowWord
3804 * Legacy function similar to NtUserSetWindowLong.
3811 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3815 DECLARE_RETURN(WORD
);
3817 TRACE("Enter NtUserSetWindowWord\n");
3818 UserEnterExclusive();
3820 if (hWnd
== IntGetDesktopWindow())
3822 EngSetLastError(STATUS_ACCESS_DENIED
);
3826 if (!(Window
= UserGetWindowObject(hWnd
)))
3835 case GWL_HWNDPARENT
:
3836 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3840 EngSetLastError(ERROR_INVALID_INDEX
);
3845 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3847 EngSetLastError(ERROR_INVALID_PARAMETER
);
3851 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3852 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3857 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3863 QueryWindow based on KJK::Hyperion and James Tabor.
3865 0 = QWUniqueProcessId
3866 1 = QWUniqueThreadId
3869 4 = QWIsHung Implements IsHungAppWindow found
3872 9 = QWKillWindow When I called this with hWnd ==
3873 DesktopWindow, it shutdown the system
3880 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3882 /* Console Leader Process CID Window offsets */
3883 #define GWLP_CONSOLE_LEADER_PID 0
3884 #define GWLP_CONSOLE_LEADER_TID 4
3888 DECLARE_RETURN(UINT
);
3890 TRACE("Enter NtUserQueryWindow\n");
3893 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3900 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3902 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3903 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3905 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
3906 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
3910 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3915 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3917 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3918 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3920 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
3921 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
3925 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3930 case QUERY_WINDOW_ACTIVE
:
3931 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3934 case QUERY_WINDOW_FOCUS
:
3935 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3938 case QUERY_WINDOW_ISHUNG
:
3939 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
);
3942 case QUERY_WINDOW_REAL_ID
:
3943 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3946 case QUERY_WINDOW_FOREGROUND
:
3947 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3951 Result
= (DWORD
)NULL
;
3958 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
3967 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3969 UNICODE_STRING SafeMessageName
;
3972 DECLARE_RETURN(UINT
);
3974 TRACE("Enter NtUserRegisterWindowMessage\n");
3975 UserEnterExclusive();
3977 if(MessageNameUnsafe
== NULL
)
3979 EngSetLastError(ERROR_INVALID_PARAMETER
);
3983 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3984 if(!NT_SUCCESS(Status
))
3986 SetLastNtError(Status
);
3990 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3991 if (SafeMessageName
.Buffer
)
3992 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3996 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
4005 NtUserSetWindowFNID(HWND hWnd
,
4009 DECLARE_RETURN(BOOL
);
4011 TRACE("Enter NtUserSetWindowFNID\n");
4012 UserEnterExclusive();
4014 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4019 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
4021 EngSetLastError(ERROR_ACCESS_DENIED
);
4025 // From user land we only set these.
4026 if (fnID
!= FNID_DESTROY
)
4028 /* HACK: The minimum should be FNID_BUTTON, but menu code relies on this */
4029 if (fnID
< FNID_FIRST
|| fnID
> FNID_GHOST
||
4032 EngSetLastError(ERROR_INVALID_PARAMETER
);
4041 TRACE("Leave NtUserSetWindowFNID\n");
4047 DefSetText(PWND Wnd
, PCWSTR WindowText
)
4049 UNICODE_STRING UnicodeString
;
4052 RtlInitUnicodeString(&UnicodeString
, WindowText
);
4054 if (UnicodeString
.Length
!= 0)
4056 if (Wnd
->strName
.MaximumLength
> 0 &&
4057 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4059 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4061 Wnd
->strName
.Length
= UnicodeString
.Length
;
4062 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4063 RtlCopyMemory(Wnd
->strName
.Buffer
,
4064 UnicodeString
.Buffer
,
4065 UnicodeString
.Length
);
4070 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4071 buf
= Wnd
->strName
.Buffer
;
4072 Wnd
->strName
.Buffer
= NULL
;
4075 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4078 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4079 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4080 if (Wnd
->strName
.Buffer
!= NULL
)
4082 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4083 RtlCopyMemory(Wnd
->strName
.Buffer
,
4084 UnicodeString
.Buffer
,
4085 UnicodeString
.Length
);
4086 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4087 Wnd
->strName
.Length
= UnicodeString
.Length
;
4091 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4098 Wnd
->strName
.Length
= 0;
4099 if (Wnd
->strName
.Buffer
!= NULL
)
4100 Wnd
->strName
.Buffer
[0] = L
'\0';
4103 // FIXME: HAX! Windows does not do this in here!
4104 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4105 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4106 /* Send shell notifications */
4107 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4109 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) UserHMGetHandle(Wnd
), FALSE
); // FIXME Flashing?
4114 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4121 * Undocumented function that is called from DefWindowProc to set
4128 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4131 LARGE_STRING SafeText
;
4132 UNICODE_STRING UnicodeString
;
4135 TRACE("Enter NtUserDefSetText\n");
4137 if (WindowText
!= NULL
)
4141 SafeText
= ProbeForReadLargeString(WindowText
);
4143 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4146 SetLastNtError(_SEH2_GetExceptionCode());
4156 UserEnterExclusive();
4158 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4164 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4165 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4166 // Now we know what the bAnsi is for.
4167 RtlInitUnicodeString(&UnicodeString
, NULL
);
4168 if (SafeText
.Buffer
)
4173 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4175 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4176 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4178 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4181 SetLastNtError(_SEH2_GetExceptionCode());
4184 if (!Ret
) goto Exit
;
4187 if (UnicodeString
.Length
!= 0)
4189 if (Wnd
->strName
.MaximumLength
> 0 &&
4190 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4192 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4194 Wnd
->strName
.Length
= UnicodeString
.Length
;
4195 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4196 RtlCopyMemory(Wnd
->strName
.Buffer
,
4197 UnicodeString
.Buffer
,
4198 UnicodeString
.Length
);
4203 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4204 buf
= Wnd
->strName
.Buffer
;
4205 Wnd
->strName
.Buffer
= NULL
;
4208 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4211 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4212 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4213 if (Wnd
->strName
.Buffer
!= NULL
)
4215 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4216 RtlCopyMemory(Wnd
->strName
.Buffer
,
4217 UnicodeString
.Buffer
,
4218 UnicodeString
.Length
);
4219 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4220 Wnd
->strName
.Length
= UnicodeString
.Length
;
4224 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4232 Wnd
->strName
.Length
= 0;
4233 if (Wnd
->strName
.Buffer
!= NULL
)
4234 Wnd
->strName
.Buffer
[0] = L
'\0';
4237 // FIXME: HAX! Windows does not do this in here!
4238 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4239 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4240 /* Send shell notifications */
4241 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4243 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4248 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4249 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4255 * NtUserInternalGetWindowText
4262 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4267 DECLARE_RETURN(INT
);
4269 TRACE("Enter NtUserInternalGetWindowText\n");
4272 if(lpString
&& (nMaxCount
<= 1))
4274 EngSetLastError(ERROR_INVALID_PARAMETER
);
4278 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4283 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4286 const WCHAR Terminator
= L
'\0';
4288 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4290 Copy
= min(nMaxCount
- 1, Result
);
4293 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4294 if(!NT_SUCCESS(Status
))
4296 SetLastNtError(Status
);
4302 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4303 if(!NT_SUCCESS(Status
))
4305 SetLastNtError(Status
);
4315 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4325 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4331 // ASSERT(OwnerWnd);
4333 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4334 win_array
= IntWinListChildren(OwnerWnd
);
4339 while (win_array
[count
])
4341 while (--count
>= 0)
4343 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4345 if (pWnd
->spwndOwner
!= OwnerWnd
)
4350 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4352 /* In Windows, ShowOwnedPopups(TRUE) generates
4353 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4354 * regardless of the state of the owner
4356 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4362 if (pWnd
->style
& WS_VISIBLE
)
4364 /* In Windows, ShowOwnedPopups(FALSE) generates
4365 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4366 * regardless of the state of the owner
4368 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4374 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4375 TRACE("Leave ShowOwnedPopups\n");