2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
5 * FILE: subsystems/win32/win32k/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
)
69 if (!pWnd
) return NULL
;
73 hWnd
= UserHMGetHandle(pWnd
);
75 State2
= pWnd
->state2
;
77 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
79 _SEH2_YIELD(return NULL
);
83 if ( UserObjectInDestroy(hWnd
) ||
84 State
& WNDS_DESTROYED
||
85 State2
& WNDS2_INDESTROY
)
91 PWND FASTCALL
ValidateHwndNoErr(HWND hWnd
)
93 if (hWnd
) return (PWND
)UserGetObjectNoErr(gHandleTable
, hWnd
, TYPE_WINDOW
);
98 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
104 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
108 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, TYPE_WINDOW
);
109 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
111 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
119 IntSetStyle( PWND pwnd
, ULONG set_bits
, ULONG clear_bits
)
121 ULONG styleOld
, styleNew
;
122 styleOld
= pwnd
->style
;
123 styleNew
= (pwnd
->style
| set_bits
) & ~clear_bits
;
124 if (styleNew
== styleOld
) return styleNew
;
125 pwnd
->style
= styleNew
;
126 if ((styleOld
^ styleNew
) & WS_VISIBLE
) // State Change.
128 if (styleOld
& WS_VISIBLE
) pwnd
->head
.pti
->cVisWindows
--;
129 if (styleNew
& WS_VISIBLE
) pwnd
->head
.pti
->cVisWindows
++;
130 DceResetActiveDCEs( pwnd
);
138 * The function determines whether the specified window handle identifies
139 * an existing window.
143 * Handle to the window to test.
146 * If the window handle identifies an existing window, the return value
147 * is TRUE. If the window handle does not identify an existing window,
148 * the return value is FALSE.
152 IntIsWindow(HWND hWnd
)
156 if (!(Window
= UserGetWindowObject(hWnd
)))
165 IntIsWindowVisible(PWND Wnd
)
170 if (!Temp
) return TRUE
;
171 if (!(Temp
->style
& WS_VISIBLE
)) break;
172 if (Temp
->style
& WS_MINIMIZE
&& Temp
!= Wnd
) break;
173 if (Temp
->fnid
== FNID_DESKTOP
) return TRUE
;
174 Temp
= Temp
->spwndParent
;
180 IntGetParent(PWND Wnd
)
182 if (Wnd
->style
& WS_POPUP
)
184 return Wnd
->spwndOwner
;
186 else if (Wnd
->style
& WS_CHILD
)
188 return Wnd
->spwndParent
;
196 IntEnableWindow( HWND hWnd
, BOOL bEnable
)
202 if(!(pWnd
= UserGetWindowObject(hWnd
)))
207 /* check if updating is needed */
208 bIsDisabled
= !!(pWnd
->style
& WS_DISABLED
);
209 Update
= bIsDisabled
;
213 IntSetStyle( pWnd
, 0, WS_DISABLED
);
217 Update
= !bIsDisabled
;
219 co_IntSendMessage( hWnd
, WM_CANCELMODE
, 0, 0);
221 /* Remove keyboard focus from that window if it had focus */
222 if (hWnd
== IntGetThreadFocusWindow())
224 TRACE("IntEnableWindow SF NULL\n");
225 co_UserSetFocus(NULL
);
227 IntSetStyle( pWnd
, WS_DISABLED
, 0 );
232 IntNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, pWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
233 co_IntSendMessage(hWnd
, WM_ENABLE
, (LPARAM
)bEnable
, 0);
235 // Return nonzero if it was disabled, or zero if it wasn't:
242 * Compile a list of all child window handles from given window.
245 * This function is similar to Wine WIN_ListChildren. The caller
246 * must free the returned list with ExFreePool.
250 IntWinListChildren(PWND Window
)
254 UINT Index
, NumChildren
= 0;
256 if (!Window
) return NULL
;
258 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
261 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
264 ERR("Failed to allocate memory for children array\n");
265 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
268 for (Child
= Window
->spwndChild
, Index
= 0;
270 Child
= Child
->spwndNext
, ++Index
)
271 List
[Index
] = Child
->head
.h
;
278 IntGetNonChildAncestor(PWND pWnd
)
280 while(pWnd
&& (pWnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
281 pWnd
= pWnd
->spwndParent
;
286 IntIsTopLevelWindow(PWND pWnd
)
288 if ( pWnd
->spwndParent
&&
289 pWnd
->spwndParent
== co_GetDesktopWindow(pWnd
) ) return TRUE
;
294 IntValidateOwnerDepth(PWND Wnd
, PWND Owner
)
299 if ( !Owner
) return gNestedWindowLimit
>= Depth
;
300 if (Owner
== Wnd
) break;
301 Owner
= Owner
->spwndOwner
;
308 IntGetWindow(HWND hWnd
,
314 Wnd
= ValidateHwndNoErr(hWnd
);
322 if (Wnd
->spwndOwner
!= NULL
)
323 FoundWnd
= Wnd
->spwndOwner
;
327 if(Wnd
->spwndParent
!= NULL
)
329 FoundWnd
= Wnd
->spwndParent
;
330 if (FoundWnd
->spwndChild
!= NULL
)
331 FoundWnd
= FoundWnd
->spwndChild
;
335 if (Wnd
->spwndNext
!= NULL
)
336 FoundWnd
= Wnd
->spwndNext
;
340 if (Wnd
->spwndPrev
!= NULL
)
341 FoundWnd
= Wnd
->spwndPrev
;
345 if (Wnd
->spwndChild
!= NULL
)
346 FoundWnd
= Wnd
->spwndChild
;
351 while ( FoundWnd
->spwndNext
!= NULL
)
352 FoundWnd
= FoundWnd
->spwndNext
;
360 if (FoundWnd
!= NULL
)
361 Ret
= UserHMGetHandle(FoundWnd
);
365 /***********************************************************************
368 static void IntSendDestroyMsg(HWND hWnd
)
373 ti
= PsGetCurrentThreadWin32Thread();
374 Window
= UserGetWindowObject(hWnd
);
378 /* Look whether the focus is within the tree of windows we will
382 if ( ti
->MessageQueue
->spwndActive
== Window
|| // Fixes CORE-106 RegSvr32 exit and return focus to CMD.
383 (ti
->MessageQueue
->spwndActive
== NULL
&& ti
->MessageQueue
== IntGetFocusMessageQueue()) )
385 co_WinPosActivateOtherWindow(Window
);
388 /* Fixes CMD properties closing and returning focus to CMD */
389 if (ti
->MessageQueue
->spwndFocus
== Window
)
391 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
393 co_UserSetFocus(Window
->spwndParent
);
397 co_UserSetFocus(NULL
);
401 if (ti
->MessageQueue
->CaretInfo
->hWnd
== UserHMGetHandle(Window
))
403 co_IntDestroyCaret(ti
);
408 * Send the WM_DESTROY to the window.
411 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
414 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
415 * make sure that the window still exists when we come back.
418 if (IntIsWindow(hWnd
))
423 if (!(pWndArray
= IntWinListChildren( Window
))) return;
425 for (i
= 0; pWndArray
[i
]; i
++)
427 if (IntIsWindow( pWndArray
[i
] )) IntSendDestroyMsg( pWndArray
[i
] );
429 ExFreePoolWithTag(pWndArray
, USERTAG_WINDOWLIST
);
433 TRACE("destroyed itself while in WM_DESTROY!\n");
438 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
440 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
444 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
446 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
447 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
450 if (Wnd
->strName
.Buffer
!= NULL
)
452 Wnd
->strName
.Length
= 0;
453 Wnd
->strName
.MaximumLength
= 0;
454 DesktopHeapFree(Wnd
->head
.rpdesk
,
455 Wnd
->strName
.Buffer
);
456 Wnd
->strName
.Buffer
= NULL
;
459 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
460 // WindowObject->hWnd = NULL;
463 /***********************************************************************
466 * Destroy storage associated to a window. "Internals" p.358
468 * This is the "functional" DestroyWindows function ei. all stuff
469 * done in CreateWindow is undone here and not in DestroyWindow:-P
472 LRESULT
co_UserFreeWindow(PWND Window
,
473 PPROCESSINFO ProcessData
,
474 PTHREADINFO ThreadData
,
475 BOOLEAN SendMessages
)
481 BOOLEAN BelongsToThreadData
;
485 if(Window
->state2
& WNDS2_INDESTROY
)
487 TRACE("Tried to call IntDestroyWindow() twice\n");
490 Window
->state2
|= WNDS2_INDESTROY
;
491 Window
->style
&= ~WS_VISIBLE
;
492 Window
->head
.pti
->cVisWindows
--;
495 /* remove the window already at this point from the thread window list so we
496 don't get into trouble when destroying the thread windows while we're still
497 in IntDestroyWindow() */
498 RemoveEntryList(&Window
->ThreadListEntry
);
500 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
502 IntDeRegisterShellHookWindow(UserHMGetHandle(Window
));
504 /* free child windows */
505 Children
= IntWinListChildren(Window
);
508 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
510 if ((Child
= IntGetWindowObject(*ChildHandle
)))
512 if(!IntWndBelongsToThread(Child
, ThreadData
))
514 /* send WM_DESTROY messages to windows not belonging to the same thread */
515 co_IntSendMessage( UserHMGetHandle(Child
), WM_ASYNC_DESTROYWINDOW
, 0, 0 );
518 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
520 UserDereferenceObject(Child
);
523 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
529 * Clear the update region to make sure no WM_PAINT messages will be
530 * generated for this window while processing the WM_NCDESTROY.
532 co_UserRedrawWindow(Window
, NULL
, 0,
533 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
534 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
535 if(BelongsToThreadData
)
536 co_IntSendMessage(UserHMGetHandle(Window
), WM_NCDESTROY
, 0, 0);
539 DestroyTimersForWindow(ThreadData
, Window
);
541 /* Unregister hot keys */
542 UnregisterWindowHotKeys(Window
);
544 /* flush the message queue */
545 MsqRemoveWindowMessagesFromQueue(Window
);
547 /* from now on no messages can be sent to this window anymore */
548 Window
->state
|= WNDS_DESTROYED
;
549 Window
->fnid
|= FNID_FREED
;
551 /* don't remove the WINDOWSTATUS_DESTROYING bit */
553 /* reset shell window handles */
554 if(ThreadData
->rpdesk
)
556 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
557 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
559 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
560 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
563 /* Fixes dialog test_focus breakage due to r66237. */
564 if (ThreadData
->MessageQueue
->spwndFocus
== Window
)
565 ThreadData
->MessageQueue
->spwndFocus
= NULL
;
567 if (ThreadData
->MessageQueue
->spwndActive
== Window
)
568 ThreadData
->MessageQueue
->spwndActive
= NULL
;
570 if (ThreadData
->MessageQueue
->spwndCapture
== Window
)
575 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
577 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
579 IntDestroyMenuObject(Menu
, TRUE
);
583 if(Window
->SystemMenu
584 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
586 IntDestroyMenuObject(Menu
, TRUE
);
587 Window
->SystemMenu
= (HMENU
)0;
590 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
592 IntUnlinkWindow(Window
);
594 if (Window
->PropListItems
)
596 IntRemoveWindowProp(Window
);
597 TRACE("Window->PropListItems %lu\n",Window
->PropListItems
);
598 ASSERT(Window
->PropListItems
==0);
601 UserReferenceObject(Window
);
602 UserDeleteObject(UserHMGetHandle(Window
), TYPE_WINDOW
);
604 IntDestroyScrollBars(Window
);
606 if (Window
->pcls
->atomClassName
== gaGuiConsoleWndClass
)
608 /* Count only console windows manually */
609 co_IntUserManualGuiCheck(FALSE
);
612 /* dereference the class */
613 NT_ASSERT(Window
->head
.pti
!= NULL
);
614 IntDereferenceClass(Window
->pcls
,
615 Window
->head
.pti
->pDeskInfo
,
616 Window
->head
.pti
->ppi
);
621 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
622 GreDeleteObject(Window
->hrgnClip
);
623 Window
->hrgnClip
= NULL
;
625 Window
->head
.pti
->cWindows
--;
627 // ASSERT(Window != NULL);
628 UserFreeWindowInfo(Window
->head
.pti
, Window
);
630 UserDereferenceObject(Window
);
632 UserClipboardFreeWindow(Window
);
638 // Same as User32:IntGetWndProc.
641 IntGetWindowProc(PWND pWnd
,
646 WNDPROC gcpd
, Ret
= 0;
648 ASSERT(UserIsEnteredExclusive() == TRUE
);
652 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
654 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
656 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
659 Ret
= GETPFNCLIENTA(i
);
661 Ret
= GETPFNCLIENTW(i
);
667 if (Class
->fnid
== FNID_EDIT
)
668 Ret
= pWnd
->lpfnWndProc
;
671 Ret
= pWnd
->lpfnWndProc
;
673 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
677 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
678 Ret
= GETPFNCLIENTA(Class
->fnid
);
682 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
683 Ret
= GETPFNCLIENTW(Class
->fnid
);
686 if ( Ret
!= pWnd
->lpfnWndProc
)
689 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
692 gcpd
= (WNDPROC
)UserGetCPD(
694 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
697 return (gcpd
? gcpd
: Ret
);
701 IntSetWindowProc(PWND pWnd
,
706 PCALLPROCDATA CallProc
;
708 WNDPROC Ret
, chWndProc
= NULL
;
710 // Retrieve previous window proc.
711 Ret
= IntGetWindowProc(pWnd
, Ansi
);
715 if (IsCallProcHandle(NewWndProc
))
717 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
719 { // Reset new WndProc.
720 NewWndProc
= CallProc
->pfnClientPrevious
;
721 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
722 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
725 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
726 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
728 if (GETPFNCLIENTW(i
) == NewWndProc
)
730 chWndProc
= GETPFNSERVER(i
);
733 if (GETPFNCLIENTA(i
) == NewWndProc
)
735 chWndProc
= GETPFNSERVER(i
);
739 // If match, set/reset to Server Side and clear ansi.
742 pWnd
->lpfnWndProc
= chWndProc
;
743 pWnd
->Unicode
= TRUE
;
744 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
745 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
749 pWnd
->Unicode
= !Ansi
;
750 // Handle the state change in here.
752 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
754 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
756 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
757 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
759 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
761 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
765 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
766 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
770 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
771 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
774 // Now set the new window proc.
775 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
786 PMENU OldMenu
, NewMenu
= NULL
;
788 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
790 ERR("SetMenu: Invalid handle 0x%p!\n",UserHMGetHandle(Wnd
));
791 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
795 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
803 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
804 ASSERT(NULL
== OldMenu
|| OldMenu
->hWnd
== Wnd
->head
.h
);
813 NewMenu
= IntGetMenuObject(Menu
);
818 IntReleaseMenuObject(OldMenu
);
820 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
823 if (NULL
!= NewMenu
->hWnd
)
825 /* Can't use the same menu for two windows */
828 IntReleaseMenuObject(OldMenu
);
830 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
836 Wnd
->IDMenu
= (UINT
) Menu
;
839 NewMenu
->hWnd
= Wnd
->head
.h
;
840 IntReleaseMenuObject(NewMenu
);
844 OldMenu
->hWnd
= NULL
;
845 IntReleaseMenuObject(OldMenu
);
852 /* INTERNAL ******************************************************************/
855 // This fixes a check for children messages that need paint while searching the parents messages!
856 // Fixes wine msg:test_paint_messages:WmParentErasePaint ..
859 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
861 PWND Window
= BaseWindow
;
864 if ( Window
== NULL
|| (Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
867 Window
= Window
->spwndParent
;
869 while(Parent
!= Window
);
875 Link the window into siblings list
876 children and parent are kept in place.
881 PWND WndInsertAfter
/* set to NULL if top sibling */
884 if ((Wnd
->spwndPrev
= WndInsertAfter
))
886 /* link after WndInsertAfter */
887 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
888 Wnd
->spwndNext
->spwndPrev
= Wnd
;
890 Wnd
->spwndPrev
->spwndNext
= Wnd
;
895 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
896 Wnd
->spwndNext
->spwndPrev
= Wnd
;
898 Wnd
->spwndParent
->spwndChild
= Wnd
;
903 Note: Wnd->spwndParent can be null if it is the desktop.
905 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
907 if (hWndPrev
== HWND_NOTOPMOST
)
909 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
910 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
911 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
912 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
915 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
917 if (hWndPrev
== HWND_BOTTOM
)
919 /* Link in the bottom of the list */
922 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
923 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
924 WndInsertAfter
= WndInsertAfter
->spwndNext
;
926 IntLinkWindow(Wnd
, WndInsertAfter
);
927 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
929 else if (hWndPrev
== HWND_TOPMOST
)
931 /* Link in the top of the list */
932 IntLinkWindow(Wnd
, NULL
);
934 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
936 else if (hWndPrev
== HWND_TOP
)
938 /* Link it after the last topmost window */
939 PWND WndInsertBefore
;
941 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
943 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
945 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
947 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
948 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
950 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
953 WndInsertBefore
= WndInsertBefore
->spwndNext
;
957 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
961 /* Link it after hWndPrev */
964 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
965 /* Are we called with an erroneous handle */
966 if(WndInsertAfter
== NULL
)
968 /* Link in a default position */
969 IntLinkHwnd(Wnd
, HWND_TOP
);
973 IntLinkWindow(Wnd
, WndInsertAfter
);
975 /* Fix the WS_EX_TOPMOST flag */
976 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
978 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
982 if(WndInsertAfter
->spwndNext
&&
983 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
985 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
989 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
993 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
997 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
1000 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
1001 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1003 //ERR("ProcessOwnerSwap Old out.\n");
1004 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
1010 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
1013 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1015 //ERR("ProcessOwnerSwap New in.\n");
1016 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1020 // FIXME: System Tray checks.
1024 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1026 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1029 Wnd
= IntGetWindowObject(hWnd
);
1033 WndOldOwner
= Wnd
->spwndOwner
;
1035 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1036 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1038 if (!WndNewOwner
&& hWndNewOwner
)
1040 EngSetLastError(ERROR_INVALID_PARAMETER
);
1045 /* if parent belongs to a different thread and the window isn't */
1046 /* top-level, attach the two threads */
1047 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1049 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1053 Wnd
->spwndOwner
= WndNewOwner
;
1057 Wnd
->spwndOwner
= NULL
;
1062 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1063 EngSetLastError(ERROR_INVALID_PARAMETER
);
1067 UserDereferenceObject(Wnd
);
1072 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1074 PWND WndOldParent
, pWndExam
;
1077 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1080 ASSERT(WndNewParent
);
1081 ASSERT_REFS_CO(Wnd
);
1082 ASSERT_REFS_CO(WndNewParent
);
1084 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1086 EngSetLastError(ERROR_ACCESS_DENIED
);
1090 /* Some applications try to set a child as a parent */
1091 if (IntIsChildWindow(Wnd
, WndNewParent
))
1093 TRACE("IntSetParent try to set a child as a parent.\n");
1094 EngSetLastError( ERROR_INVALID_PARAMETER
);
1098 pWndExam
= WndNewParent
; // Load parent Window to examine.
1099 // Now test for set parent to parent hit.
1102 if (Wnd
== pWndExam
)
1104 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1105 EngSetLastError(ERROR_INVALID_PARAMETER
);
1108 pWndExam
= pWndExam
->spwndParent
;
1112 * Windows hides the window first, then shows it again
1113 * including the WM_SHOWWINDOW messages and all
1115 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1117 /* Window must belong to current process */
1118 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1120 ERR("IntSetParent Window must belong to current process!\n");
1124 WndOldParent
= Wnd
->spwndParent
;
1126 if ( WndOldParent
&&
1127 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1128 pt
.x
= Wnd
->rcWindow
.right
;
1130 pt
.x
= Wnd
->rcWindow
.left
;
1131 pt
.y
= Wnd
->rcWindow
.top
;
1133 IntScreenToClient(WndOldParent
, &pt
);
1135 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1137 if (WndNewParent
!= WndOldParent
)
1139 /* Unlink the window from the siblings list */
1140 IntUnlinkWindow(Wnd
);
1141 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1143 /* Set the new parent */
1144 Wnd
->spwndParent
= WndNewParent
;
1146 if ( Wnd
->style
& WS_CHILD
&&
1148 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1150 ERR("SetParent Top Most from Pop up!\n");
1151 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1154 /* Link the window with its new siblings */
1156 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1157 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1161 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1162 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1164 Wnd
->style
|= WS_CLIPSIBLINGS
;
1165 DceResetActiveDCEs(Wnd
);
1168 /* if parent belongs to a different thread and the window isn't */
1169 /* top-level, attach the two threads */
1170 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1172 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1174 if (WndOldParent
&& (Wnd
->head
.pti
!= WndOldParent
->head
.pti
))
1176 //ERR("SetParent Old out.\n");
1177 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1180 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1182 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1184 //ERR("SetParent New in.\n");
1185 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1190 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1191 swFlags
|= SWP_NOACTIVATE
;
1193 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1195 * SetParent additionally needs to make hwnd the top window
1196 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1197 * WM_WINDOWPOSCHANGED notification messages.
1199 //ERR("IntSetParent SetWindowPos 1\n");
1200 co_WinPosSetWindowPos( Wnd
,
1201 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1202 pt
.x
, pt
.y
, 0, 0, swFlags
);
1203 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1204 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1206 return WndOldParent
;
1210 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1212 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1213 HWND hWndOldParent
= NULL
;
1214 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1216 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1218 EngSetLastError(ERROR_INVALID_PARAMETER
);
1222 if (hWndChild
== IntGetDesktopWindow())
1224 ERR("UserSetParent Access Denied!\n");
1225 EngSetLastError(ERROR_ACCESS_DENIED
);
1231 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1233 ERR("UserSetParent Bad New Parent!\n");
1239 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1245 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1247 ERR("UserSetParent Bad Child!\n");
1251 UserRefObjectCo(Wnd
, &Ref
);
1252 UserRefObjectCo(WndParent
, &ParentRef
);
1253 //ERR("Enter co_IntSetParent\n");
1254 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1255 //ERR("Leave co_IntSetParent\n");
1256 UserDerefObjectCo(WndParent
);
1257 UserDerefObjectCo(Wnd
);
1261 hWndOldParent
= WndOldParent
->head
.h
;
1262 UserDereferenceObject(WndOldParent
);
1265 return( hWndOldParent
);
1268 /* Unlink the window from siblings. children and parent are kept in place. */
1270 IntUnlinkWindow(PWND Wnd
)
1273 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1276 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1278 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1279 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1281 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1284 /* FUNCTIONS *****************************************************************/
1287 * As best as I can figure, this function is used by EnumWindows,
1288 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1290 * It's supposed to build a list of HWNDs to return to the caller.
1291 * We can figure out what kind of list by what parameters are
1299 NtUserBuildHwndList(
1312 return ERROR_INVALID_PARAMETER
;
1314 if (hwndParent
|| !dwThreadId
)
1317 PWND Parent
, Window
;
1321 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1323 return ERROR_INVALID_HANDLE
;
1328 Status
= IntValidateDesktopHandle(hDesktop
,
1332 if(!NT_SUCCESS(Status
))
1334 return ERROR_INVALID_HANDLE
;
1337 hwndParent
= Desktop
->DesktopWindow
;
1344 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1345 (Window
= Parent
->spwndChild
))
1347 BOOL bGoDown
= TRUE
;
1349 Status
= STATUS_SUCCESS
;
1354 if(dwCount
++ < *pBufSize
&& pWnd
)
1358 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1359 *pWnd
= Window
->head
.h
;
1362 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1364 Status
= _SEH2_GetExceptionCode();
1367 if(!NT_SUCCESS(Status
))
1369 SetLastNtError(Status
);
1373 if (Window
->spwndChild
&& bChildren
)
1375 Window
= Window
->spwndChild
;
1380 if (Window
->spwndNext
)
1382 Window
= Window
->spwndNext
;
1386 Window
= Window
->spwndParent
;
1387 if (Window
== Parent
)
1396 ObDereferenceObject(Desktop
);
1399 else // Build EnumThreadWindows list!
1402 PTHREADINFO W32Thread
;
1406 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1407 if (!NT_SUCCESS(Status
))
1409 ERR("Thread Id is not valid!\n");
1410 return ERROR_INVALID_PARAMETER
;
1412 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1414 ObDereferenceObject(Thread
);
1415 TRACE("Tried to enumerate windows of a non gui thread\n");
1416 return ERROR_INVALID_PARAMETER
;
1419 // Do not use Thread link list due to co_UserFreeWindow!!!
1420 // Current = W32Thread->WindowListHead.Flink;
1421 // Fixes Api:CreateWindowEx tests!!!
1422 List
= IntWinListChildren(UserGetDesktopWindow());
1426 for (i
= 0; List
[i
]; i
++)
1428 Window
= ValidateHwndNoErr(List
[i
]);
1429 if (Window
&& Window
->head
.pti
== W32Thread
)
1431 if (dwCount
< *pBufSize
&& pWnd
)
1435 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1436 *pWnd
= Window
->head
.h
;
1439 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1441 Status
= _SEH2_GetExceptionCode();
1444 if (!NT_SUCCESS(Status
))
1446 ERR("Failure to build window list!\n");
1447 SetLastNtError(Status
);
1456 ObDereferenceObject(Thread
);
1459 *pBufSize
= dwCount
;
1460 return STATUS_SUCCESS
;
1463 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1465 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1466 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1468 if (VerifyWnd(pWindow
->spwndParent
) && pWindow
->spwndParent
!= UserGetDesktopWindow())
1470 USER_REFERENCE_ENTRY Ref
;
1471 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1472 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1474 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1475 (LPARAM
)pWindow
->head
.h
);
1476 UserDerefObjectCo(pWindow
->spwndParent
);
1482 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1484 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1486 /* default positioning for overlapped windows */
1487 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1490 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1492 pMonitor
= UserGetPrimaryMonitor();
1494 /* Check if we don't have a monitor attached yet */
1495 if(pMonitor
== NULL
)
1503 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1505 if (IS_DEFAULT(Cs
->x
))
1507 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1509 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1511 Cs
->x
= ProcessParams
->StartingX
;
1512 Cs
->y
= ProcessParams
->StartingY
;
1516 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1517 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1518 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1519 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1521 /* reset counter and position */
1524 pMonitor
->cWndStack
= 0;
1526 pMonitor
->cWndStack
++;
1530 if (IS_DEFAULT(Cs
->cx
))
1532 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1534 Cs
->cx
= ProcessParams
->CountX
;
1535 Cs
->cy
= ProcessParams
->CountY
;
1539 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1540 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1543 /* neither x nor cx are default. Check the y values .
1544 * In the trace we see Outlook and Outlook Express using
1545 * cy set to CW_USEDEFAULT when opening the address book.
1547 else if (IS_DEFAULT(Cs
->cy
))
1549 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1550 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1555 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1556 if(IS_DEFAULT(Cs
->x
))
1561 if(IS_DEFAULT(Cs
->cx
))
1571 /* Allocates and initializes a window */
1572 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1573 PLARGE_STRING WindowName
,
1578 PDESKTOP pdeskCreated
)
1582 PTHREADINFO pti
= NULL
;
1584 BOOL bUnicodeWindow
;
1586 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1588 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1589 { // Need both here for wine win.c test_CreateWindow.
1590 //if (Cs->hwndParent && ParentWindow)
1591 if (ParentWindow
) // It breaks more tests..... WIP.
1593 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1594 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1595 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1596 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1600 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1602 * Dialog boxes and message boxes do not inherit layout, so you must
1603 * set the layout explicitly.
1605 if ( Class
->fnid
!= FNID_DIALOG
)
1607 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1609 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1615 /* Automatically add WS_EX_WINDOWEDGE */
1616 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1617 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1618 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1619 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1621 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1623 /* Is it a unicode window? */
1624 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1625 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1627 /* Allocate the new window */
1628 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1629 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1633 sizeof(WND
) + Class
->cbwndExtra
);
1640 TRACE("Created window object with handle %p\n", hWnd
);
1642 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1643 { /* HACK: Helper for win32csr/desktopbg.c */
1644 /* If there is no desktop window yet, we must be creating it */
1645 TRACE("CreateWindow setting desktop.\n");
1646 pdeskCreated
->DesktopWindow
= hWnd
;
1647 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1651 * Fill out the structure describing it.
1653 /* Remember, pWnd->head is setup in object.c ... */
1654 pWnd
->spwndParent
= ParentWindow
;
1655 pWnd
->spwndOwner
= OwnerWindow
;
1657 pWnd
->spwndLastActive
= pWnd
;
1658 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1660 pWnd
->hModule
= Cs
->hInstance
;
1661 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1662 pWnd
->ExStyle
= Cs
->dwExStyle
;
1663 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1664 pWnd
->pActCtx
= acbiBuffer
;
1665 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1666 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1668 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1670 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1671 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1674 pWnd
->head
.pti
->cWindows
++;
1676 if (Class
->spicn
&& !Class
->spicnSm
)
1678 HICON IconSmHandle
= NULL
;
1679 if((Class
->spicn
->CURSORF_flags
& (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1680 == (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1682 IconSmHandle
= co_IntCopyImage(
1683 UserHMGetHandle(Class
->spicn
),
1685 UserGetSystemMetrics( SM_CXSMICON
),
1686 UserGetSystemMetrics( SM_CYSMICON
),
1687 LR_COPYFROMRESOURCE
);
1691 /* Retry without copying from resource */
1692 IconSmHandle
= co_IntCopyImage(
1693 UserHMGetHandle(Class
->spicn
),
1695 UserGetSystemMetrics( SM_CXSMICON
),
1696 UserGetSystemMetrics( SM_CYSMICON
),
1702 Class
->spicnSm
= UserGetCurIconObject(IconSmHandle
);
1703 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1707 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1708 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1710 /* BugBoy Comments: Comment below say that System classes are always created
1711 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1712 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1714 No where can I see in code or through testing does the window change back
1715 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1716 see what problems this would cause. */
1718 // Set WndProc from Class.
1719 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1721 // GetWindowProc, test for non server side default classes and set WndProc.
1722 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1726 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1727 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1731 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1732 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1736 // If not an Unicode caller, set Ansi creator bit.
1737 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1739 // Clone Class Ansi/Unicode proc type.
1740 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1742 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1743 pWnd
->Unicode
= FALSE
;
1747 * It seems there can be both an Ansi creator and Unicode Class Window
1748 * WndProc, unless the following overriding conditions occur:
1750 if ( !bUnicodeWindow
&&
1751 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1752 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1753 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1754 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1755 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1756 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1757 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1758 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1759 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1760 { // Override Class and set the window Ansi WndProc.
1761 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1762 pWnd
->Unicode
= FALSE
;
1765 { // Set the window Unicode WndProc.
1766 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1767 pWnd
->Unicode
= TRUE
;
1771 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1772 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1773 Dont understand why it does this. */
1774 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1776 PCALLPROCDATA CallProc
;
1777 CallProc
= CreateCallProc(pWnd
->head
.rpdesk
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1781 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1782 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1786 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1790 InitializeListHead(&pWnd
->PropListHead
);
1791 pWnd
->PropListItems
= 0;
1793 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1795 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1796 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1797 if (pWnd
->strName
.Buffer
== NULL
)
1802 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1803 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1804 pWnd
->strName
.Length
= WindowName
->Length
;
1805 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1808 /* Correct the window style. */
1809 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1811 pWnd
->style
|= WS_CLIPSIBLINGS
;
1812 if (!(pWnd
->style
& WS_POPUP
))
1814 pWnd
->style
|= WS_CAPTION
;
1818 /* WS_EX_WINDOWEDGE depends on some other styles */
1819 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1820 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1821 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1823 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1824 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1825 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1828 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1830 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1831 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1833 /* Set the window menu */
1834 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1838 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1840 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1842 UNICODE_STRING MenuName
;
1845 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1847 MenuName
.Length
= 0;
1848 MenuName
.MaximumLength
= 0;
1849 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1853 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1855 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1856 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1860 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1863 if ( ParentWindow
&&
1864 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1865 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1867 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1869 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1871 EngSetLastError(ERROR_INVALID_PARAMETER
);
1874 if ( pWnd
->spwndOwner
&&
1875 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1877 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1879 if ( pWnd
->spwndOwner
&&
1880 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1881 pti
!= pWnd
->spwndOwner
->head
.pti
)
1883 //ERR("CreateWindow Owner in.\n");
1884 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1888 /* Insert the window into the thread's window list. */
1889 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1891 /* Handle "CS_CLASSDC", it is tested first. */
1892 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1893 { /* One DCE per class to have CLASS. */
1894 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1896 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1897 { /* Allocate a DCE for this window. */
1898 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1904 ERR("IntCreateWindow Allocation Error.\n");
1905 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1908 UserDereferenceObject(pWnd
);
1916 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1917 PUNICODE_STRING ClassName
,
1918 PLARGE_STRING WindowName
,
1922 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1923 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1924 PWINSTATION_OBJECT WinSta
;
1927 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1928 CBT_CREATEWNDW
* pCbtCreate
;
1930 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1932 DWORD dwShowMode
= SW_SHOW
;
1933 CREATESTRUCTW
*pCsw
= NULL
;
1934 PVOID pszClass
= NULL
, pszName
= NULL
;
1937 /* Get the current window station and reference it */
1938 pti
= GetW32ThreadInfo();
1939 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1941 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1942 return NULL
; // There is nothing to cleanup.
1944 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1945 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1950 /* Get the class and reference it */
1951 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
1954 ERR("Failed to find class %wZ\n", ClassName
);
1958 /* Now find the parent and the owner window */
1959 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
1962 if (Cs
->hwndParent
== HWND_MESSAGE
)
1964 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
1966 else if (Cs
->hwndParent
)
1968 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1969 hWndOwner
= Cs
->hwndParent
;
1971 hWndParent
= Cs
->hwndParent
;
1973 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1975 ERR("Cannot create a child window without a parrent!\n");
1976 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1977 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1980 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1981 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1983 /* FIXME: Is this correct? */
1985 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
1987 /* Fix the position and the size of the window */
1990 UserRefObjectCo(ParentWindow
, &ParentRef
);
1991 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
1994 /* Allocate and initialize the new window */
1995 Window
= IntCreateWindow(Cs
,
2004 ERR("IntCreateWindow failed!\n");
2008 hWnd
= UserHMGetHandle(Window
);
2009 hwndInsertAfter
= HWND_TOP
;
2011 UserRefObjectCo(Window
, &Ref
);
2012 UserDereferenceObject(Window
);
2013 ObDereferenceObject(WinSta
);
2015 //// Check for a hook to eliminate overhead. ////
2016 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2018 // Allocate the calling structures Justin Case this goes Global.
2019 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2020 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2021 if (!pCsw
|| !pCbtCreate
)
2023 ERR("UserHeapAlloc() failed!\n");
2027 /* Fill the new CREATESTRUCTW */
2028 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2029 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2031 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2032 if (!IS_ATOM(ClassName
->Buffer
))
2034 if (Window
->state
& WNDS_ANSICREATOR
)
2036 ANSI_STRING AnsiString
;
2037 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2038 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2041 ERR("UserHeapAlloc() failed!\n");
2044 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2045 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2046 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2050 UNICODE_STRING UnicodeString
;
2051 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2052 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2055 ERR("UserHeapAlloc() failed!\n");
2058 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2059 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2060 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2062 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2064 if (WindowName
->Length
)
2066 UNICODE_STRING Name
;
2067 Name
.Buffer
= WindowName
->Buffer
;
2068 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2069 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2071 if (Window
->state
& WNDS_ANSICREATOR
)
2073 ANSI_STRING AnsiString
;
2074 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2075 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2078 ERR("UserHeapAlloc() failed!\n");
2081 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2082 AnsiString
.Buffer
= (PCHAR
)pszName
;
2083 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2087 UNICODE_STRING UnicodeString
;
2088 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2089 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2092 ERR("UserHeapAlloc() failed!\n");
2095 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2096 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2097 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2099 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2102 pCbtCreate
->lpcs
= pCsw
;
2103 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2105 //// Call the WH_CBT hook ////
2106 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2109 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2112 // Write back changes.
2117 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2120 /* NCCREATE and WM_NCCALCSIZE need the original values */
2121 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2122 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2124 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2126 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2128 Cs
->x
+= ParentWindow
->rcClient
.left
;
2129 Cs
->y
+= ParentWindow
->rcClient
.top
;
2133 /* Send the WM_GETMINMAXINFO message */
2137 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2139 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2140 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2141 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2142 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2143 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2146 Window
->rcWindow
.left
= Cs
->x
;
2147 Window
->rcWindow
.top
= Cs
->y
;
2148 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2149 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2151 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2153 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2154 RECTL_vOffsetRect(&Window->rcWindow,
2155 ParentWindow->rcClient.left,
2156 ParentWindow->rcClient.top);
2159 /* correct child window coordinates if mirroring on parent is enabled */
2160 if (ParentWindow
!= NULL
)
2162 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2163 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2165 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2166 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2170 Window
->rcClient
= Window
->rcWindow
;
2172 /* Link the window */
2173 if (NULL
!= ParentWindow
)
2175 /* Link the window into the siblings list */
2176 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2177 IntLinkHwnd(Window
, HWND_BOTTOM
);
2179 IntLinkHwnd(Window
, hwndInsertAfter
);
2182 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2184 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2185 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2188 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2190 if ( !IntIsTopLevelWindow(Window
) )
2192 if (pti
!= Window
->spwndParent
->head
.pti
)
2194 //ERR("CreateWindow Parent in.\n");
2195 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2200 /* Send the NCCREATE message */
2201 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2204 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2208 /* Send the WM_NCCALCSIZE message */
2211 MaxPos
.x
= Window
->rcWindow
.left
;
2212 MaxPos
.y
= Window
->rcWindow
.top
;
2214 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2215 //rc = Window->rcWindow;
2216 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2217 //Window->rcClient = rc;
2219 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2220 MaxPos
.y
- Window
->rcWindow
.top
);
2223 /* Send the WM_CREATE message. */
2224 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2225 if (Result
== (LRESULT
)-1)
2227 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2231 /* Send the EVENT_OBJECT_CREATE event */
2232 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2234 /* By setting the flag below it can be examined to determine if the window
2235 was created successfully and a valid pwnd was passed back to caller since
2236 from here the function has to succeed. */
2237 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2239 /* Send the WM_SIZE and WM_MOVE messages. */
2240 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2242 co_WinPosSendSizeMove(Window
);
2245 /* Show or maybe minimize or maximize the window. */
2247 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2248 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2251 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2253 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2254 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2255 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2256 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2257 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2260 /* Send the WM_PARENTNOTIFY message */
2261 IntSendParentNotify(Window
, WM_CREATE
);
2263 /* Notify the shell that a new window was created */
2264 if (Window
->spwndParent
== UserGetDesktopWindow() &&
2265 Window
->spwndOwner
== NULL
&&
2266 (Window
->style
& WS_VISIBLE
) &&
2267 (!(Window
->ExStyle
& WS_EX_TOOLWINDOW
) ||
2268 (Window
->ExStyle
& WS_EX_APPWINDOW
)))
2270 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2273 /* Initialize and show the window's scrollbars */
2274 if (Window
->style
& WS_VSCROLL
)
2276 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2278 if (Window
->style
& WS_HSCROLL
)
2280 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2283 /* Show the new window */
2284 if (Cs
->style
& WS_VISIBLE
)
2286 if (Window
->style
& WS_MAXIMIZE
)
2287 dwShowMode
= SW_SHOW
;
2288 else if (Window
->style
& WS_MINIMIZE
)
2289 dwShowMode
= SW_SHOWMINIMIZED
;
2291 co_WinPosShowWindow(Window
, dwShowMode
);
2293 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2295 ASSERT(ParentWindow
);
2298 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2299 /* ShowWindow won't activate child windows */
2300 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2304 if (Class
->atomClassName
== gaGuiConsoleWndClass
)
2306 /* Count only console windows manually */
2307 co_IntUserManualGuiCheck(TRUE
);
2310 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2316 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2317 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2319 co_UserDestroyWindow(Window
);
2321 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2324 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2325 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2326 if (pszName
) UserHeapFree(pszName
);
2327 if (pszClass
) UserHeapFree(pszClass
);
2331 UserDerefObjectCo(Window
);
2333 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2340 ProbeAndCaptureLargeString(
2341 OUT PLARGE_STRING plstrSafe
,
2342 IN PLARGE_STRING plstrUnsafe
)
2344 LARGE_STRING lstrTemp
;
2345 PVOID pvBuffer
= NULL
;
2349 /* Probe and copy the string */
2350 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2351 lstrTemp
= *plstrUnsafe
;
2353 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2356 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2360 if (lstrTemp
.Length
!= 0)
2362 /* Allocate a buffer from paged pool */
2363 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2366 return STATUS_NO_MEMORY
;
2371 /* Probe and copy the buffer */
2372 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2373 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2375 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2377 /* Cleanup and fail */
2378 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2379 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2384 /* Set the output string */
2385 plstrSafe
->Buffer
= pvBuffer
;
2386 plstrSafe
->Length
= lstrTemp
.Length
;
2387 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2389 return STATUS_SUCCESS
;
2393 * \todo Allow passing plstrClassName as ANSI.
2397 NtUserCreateWindowEx(
2399 PLARGE_STRING plstrClassName
,
2400 PLARGE_STRING plstrClsVersion
,
2401 PLARGE_STRING plstrWindowName
,
2409 HINSTANCE hInstance
,
2415 LARGE_STRING lstrWindowName
;
2416 LARGE_STRING lstrClassName
;
2417 UNICODE_STRING ustrClassName
;
2422 lstrWindowName
.Buffer
= NULL
;
2423 lstrClassName
.Buffer
= NULL
;
2425 ASSERT(plstrWindowName
);
2427 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2429 /* check hMenu is valid handle */
2430 if (hMenu
&& !UserGetMenuObject(hMenu
))
2432 ERR("NtUserCreateWindowEx: Got an invalid menu handle!\n");
2433 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
2438 /* Copy the window name to kernel mode */
2439 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2440 if (!NT_SUCCESS(Status
))
2442 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2443 SetLastNtError(Status
);
2447 plstrWindowName
= &lstrWindowName
;
2449 /* Check if the class is an atom */
2450 if (IS_ATOM(plstrClassName
))
2452 /* It is, pass the atom in the UNICODE_STRING */
2453 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2454 ustrClassName
.Length
= 0;
2455 ustrClassName
.MaximumLength
= 0;
2459 /* It's not, capture the class name */
2460 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2461 if (!NT_SUCCESS(Status
))
2463 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2464 /* Set last error, cleanup and return */
2465 SetLastNtError(Status
);
2469 /* We pass it on as a UNICODE_STRING */
2470 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2471 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2472 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2475 /* Fill the CREATESTRUCTW */
2476 /* we will keep here the original parameters */
2478 Cs
.lpCreateParams
= lpParam
;
2479 Cs
.hInstance
= hInstance
;
2481 Cs
.hwndParent
= hWndParent
;
2486 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2487 Cs
.lpszClass
= ustrClassName
.Buffer
;
2488 Cs
.dwExStyle
= dwExStyle
;
2490 UserEnterExclusive();
2492 /* Call the internal function */
2493 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
);
2497 ERR("co_UserCreateWindowEx failed!\n");
2499 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2504 if (lstrWindowName
.Buffer
)
2506 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2508 if (lstrClassName
.Buffer
)
2510 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2517 BOOLEAN
co_UserDestroyWindow(PVOID Object
)
2523 PWND Window
= Object
;
2525 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2527 hWnd
= Window
->head
.h
;
2528 ti
= PsGetCurrentThreadWin32Thread();
2530 TRACE("co_UserDestroyWindow \n");
2532 /* Check for owner thread */
2533 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2535 /* Check if we are destroying the desktop window */
2536 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2538 EngSetLastError(ERROR_ACCESS_DENIED
);
2543 /* If window was created successfully and it is hooked */
2544 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2546 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2548 ERR("Destroy Window WH_CBT Call Hook return!\n");
2553 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2555 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2557 if (Window
->spwndOwner
)
2559 //ERR("DestroyWindow Owner out.\n");
2560 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2565 /* Inform the parent */
2566 if (Window
->style
& WS_CHILD
)
2568 IntSendParentNotify(Window
, WM_DESTROY
);
2571 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
2573 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
2576 /* Hide the window */
2577 if (Window
->style
& WS_VISIBLE
)
2579 if (Window
->style
& WS_CHILD
)
2581 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
2582 co_WinPosShowWindow(Window
, SW_HIDE
);
2586 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2590 // Adjust last active.
2591 if ((pwndTemp
= Window
->spwndOwner
))
2593 while (pwndTemp
->spwndOwner
)
2594 pwndTemp
= pwndTemp
->spwndOwner
;
2596 if (pwndTemp
->spwndLastActive
== Window
)
2597 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2600 if (Window
->spwndParent
&& IntIsWindow(UserHMGetHandle(Window
)))
2602 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2604 if (!IntIsTopLevelWindow(Window
))
2606 //ERR("DestroyWindow Parent out.\n");
2607 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2612 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2613 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2614 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2615 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2616 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2617 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2618 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2619 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2622 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2625 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2627 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2629 ERR("Destroying the ShellWindow!\n");
2630 ti
->pDeskInfo
->hShellWindow
= NULL
;
2634 IntEngWindowChanged(Window
, WOC_DELETE
);
2636 if (!IntIsWindow(UserHMGetHandle(Window
)))
2641 /* Recursively destroy owned windows */
2643 if (! (Window
->style
& WS_CHILD
))
2647 BOOL GotOne
= FALSE
;
2650 PWND Child
, Desktop
;
2652 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2653 UserGetWindowObject(IntGetDesktopWindow());
2654 Children
= IntWinListChildren(Desktop
);
2658 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2660 Child
= UserGetWindowObject(*ChildHandle
);
2663 if (Child
->spwndOwner
!= Window
)
2668 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2670 USER_REFERENCE_ENTRY ChildRef
;
2671 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2672 co_UserDestroyWindow(Child
);
2673 UserDerefObjectCo(Child
); // Temp HACK?
2679 if (Child
->spwndOwner
!= NULL
)
2681 Child
->spwndOwner
= NULL
;
2685 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2694 /* Generate mouse move message for the next window */
2695 msg
.message
= WM_MOUSEMOVE
;
2696 msg
.wParam
= UserGetMouseButtonsState();
2697 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2698 msg
.pt
= gpsi
->ptCursor
;
2699 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2701 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2703 /* Send destroy messages */
2705 IntSendDestroyMsg(UserHMGetHandle(Window
));
2707 if (!IntIsWindow(UserHMGetHandle(Window
)))
2712 /* Destroy the window storage */
2713 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2723 NtUserDestroyWindow(HWND Wnd
)
2726 DECLARE_RETURN(BOOLEAN
);
2728 USER_REFERENCE_ENTRY Ref
;
2730 TRACE("Enter NtUserDestroyWindow\n");
2731 UserEnterExclusive();
2733 if (!(Window
= UserGetWindowObject(Wnd
)))
2738 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2739 ret
= co_UserDestroyWindow(Window
);
2740 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2745 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2751 static HWND FASTCALL
2752 IntFindWindow(PWND Parent
,
2755 PUNICODE_STRING WindowName
)
2757 BOOL CheckWindowName
;
2760 UNICODE_STRING CurrentWindowName
;
2764 CheckWindowName
= WindowName
->Buffer
!= 0;
2766 if((List
= IntWinListChildren(Parent
)))
2771 /* skip handles before and including ChildAfter */
2772 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2776 /* search children */
2780 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2785 /* Do not send WM_GETTEXT messages in the kernel mode version!
2786 The user mode version however calls GetWindowText() which will
2787 send WM_GETTEXT messages to windows belonging to its processes */
2788 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2790 // FIXME: LARGE_STRING truncated
2791 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2792 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2793 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2794 if(!CheckWindowName
||
2795 (Child
->strName
.Length
< 0xFFFF &&
2796 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2798 Ret
= Child
->head
.h
;
2803 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2811 * Searches a window's children for a window with the specified
2814 * hwndParent = The window whose childs are to be searched.
2816 * HWND_MESSAGE = message-only windows
2818 * hwndChildAfter = Search starts after this child window.
2819 * NULL = start from beginning
2821 * ucClassName = Class name to search for
2822 * Reguired parameter.
2824 * ucWindowName = Window name
2825 * ->Buffer == NULL = don't care
2828 * The HWND of the window if it was found, otherwise NULL
2834 NtUserFindWindowEx(HWND hwndParent
,
2835 HWND hwndChildAfter
,
2836 PUNICODE_STRING ucClassName
,
2837 PUNICODE_STRING ucWindowName
,
2840 PWND Parent
, ChildAfter
;
2841 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2842 HWND Desktop
, Ret
= NULL
;
2843 BOOL DoMessageWnd
= FALSE
;
2844 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2845 DECLARE_RETURN(HWND
);
2847 TRACE("Enter NtUserFindWindowEx\n");
2850 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2854 if (ucClassName
!= NULL
)
2856 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2857 if (ClassName
.Length
!= 0)
2859 ProbeForRead(ClassName
.Buffer
,
2863 else if (!IS_ATOM(ClassName
.Buffer
))
2865 EngSetLastError(ERROR_INVALID_PARAMETER
);
2869 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2876 if (ucWindowName
!= NULL
)
2878 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2879 if (WindowName
.Length
!= 0)
2881 ProbeForRead(WindowName
.Buffer
,
2887 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2889 SetLastNtError(_SEH2_GetExceptionCode());
2890 _SEH2_YIELD(RETURN(NULL
));
2894 if (ucClassName
!= NULL
)
2896 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2897 !IS_ATOM(ClassName
.Buffer
))
2899 EngSetLastError(ERROR_INVALID_PARAMETER
);
2902 else if (ClassAtom
== (RTL_ATOM
)0)
2904 /* LastError code was set by IntGetAtomFromStringOrAtom */
2910 Desktop
= IntGetCurrentThreadDesktopWindow();
2912 if(hwndParent
== NULL
)
2914 hwndParent
= Desktop
;
2915 DoMessageWnd
= TRUE
;
2917 else if(hwndParent
== HWND_MESSAGE
)
2919 hwndParent
= IntGetMessageWindow();
2922 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2928 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2935 if(Parent
->head
.h
== Desktop
)
2938 PWND TopLevelWindow
;
2939 BOOLEAN CheckWindowName
;
2940 BOOLEAN WindowMatches
;
2941 BOOLEAN ClassMatches
;
2943 /* windows searches through all top-level windows if the parent is the desktop
2946 if((List
= IntWinListChildren(Parent
)))
2952 /* skip handles before and including ChildAfter */
2953 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2957 CheckWindowName
= WindowName
.Buffer
!= 0;
2959 /* search children */
2962 UNICODE_STRING ustr
;
2964 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2969 /* Do not send WM_GETTEXT messages in the kernel mode version!
2970 The user mode version however calls GetWindowText() which will
2971 send WM_GETTEXT messages to windows belonging to its processes */
2972 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2973 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
2974 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
2975 WindowMatches
= !CheckWindowName
||
2976 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2977 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2978 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2979 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2981 if (WindowMatches
&& ClassMatches
)
2983 Ret
= TopLevelWindow
->head
.h
;
2987 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2989 /* window returns the handle of the top-level window, in case it found
2991 Ret
= TopLevelWindow
->head
.h
;
2996 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3001 ERR("FindWindowEx: Not Desktop Parent!\n");
3002 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3005 if (Ret
== NULL
&& DoMessageWnd
)
3009 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3011 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3015 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3017 SetLastNtError(_SEH2_GetExceptionCode());
3025 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3034 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3036 PWND WndAncestor
, Parent
;
3038 if (Wnd
->head
.h
== IntGetDesktopWindow())
3047 WndAncestor
= Wnd
->spwndParent
;
3058 if(!(Parent
= WndAncestor
->spwndParent
))
3062 if(IntIsDesktopWindow(Parent
))
3067 WndAncestor
= Parent
;
3078 Parent
= IntGetParent(WndAncestor
);
3085 WndAncestor
= Parent
;
3103 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3105 PWND Window
, Ancestor
;
3106 DECLARE_RETURN(HWND
);
3108 TRACE("Enter NtUserGetAncestor\n");
3109 UserEnterExclusive();
3111 if (!(Window
= UserGetWindowObject(hWnd
)))
3116 Ancestor
= UserGetAncestor(Window
, Type
);
3117 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3119 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3122 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3128 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3130 /* combo state struct */
3144 INT fixedOwnerDrawHeight
;
3145 INT droppedWidth
; /* last two are not used unless set */
3146 INT editHeight
; /* explicitly */
3148 } HEADCOMBO
,*LPHEADCOMBO
;
3150 // Window Extra data container.
3151 typedef struct _WND2CBOX
3155 } WND2CBOX
, *PWND2CBOX
;
3157 #define CBF_BUTTONDOWN 0x0002
3163 NtUserGetComboBoxInfo(
3169 BOOL NotSameppi
= FALSE
;
3171 DECLARE_RETURN(BOOL
);
3173 TRACE("Enter NtUserGetComboBoxInfo\n");
3176 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3182 ProbeForWrite(pcbi
, sizeof(COMBOBOXINFO
), 1);
3184 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3186 SetLastNtError(_SEH2_GetExceptionCode());
3187 _SEH2_YIELD(RETURN(FALSE
));
3191 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3193 EngSetLastError(ERROR_INVALID_PARAMETER
);
3197 // Pass the user pointer, it was already probed.
3198 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3200 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3203 ppi
= PsGetCurrentProcessWin32Process();
3204 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3207 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3212 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3213 pcbi
->rcItem
= lphc
->textRect
;
3214 pcbi
->rcButton
= lphc
->buttonRect
;
3215 pcbi
->stateButton
= 0;
3216 if (lphc
->wState
& CBF_BUTTONDOWN
)
3217 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3218 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3219 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3220 pcbi
->hwndCombo
= lphc
->self
;
3221 pcbi
->hwndItem
= lphc
->hWndEdit
;
3222 pcbi
->hwndList
= lphc
->hWndLBox
;
3224 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3227 SetLastNtError(_SEH2_GetExceptionCode());
3234 if (NotSameppi
) KeDetachProcess();
3235 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3241 //// ReactOS work around! Keep it the sames as in Listbox.c
3243 /* Listbox structure */
3246 HWND self
; /* Our own window handle */
3247 HWND owner
; /* Owner window to send notifications to */
3248 UINT style
; /* Window style */
3249 INT width
; /* Window width */
3250 INT height
; /* Window height */
3251 VOID
*items
; /* Array of items */
3252 INT nb_items
; /* Number of items */
3253 INT top_item
; /* Top visible item */
3254 INT selected_item
; /* Selected item */
3255 INT focus_item
; /* Item that has the focus */
3256 INT anchor_item
; /* Anchor item for extended selection */
3257 INT item_height
; /* Default item height */
3258 INT page_size
; /* Items per listbox page */
3259 INT column_width
; /* Column width for multi-column listboxes */
3262 // Window Extra data container.
3263 typedef struct _WND2LB
3273 NtUserGetListBoxInfo(
3278 BOOL NotSameppi
= FALSE
;
3280 DECLARE_RETURN(DWORD
);
3282 TRACE("Enter NtUserGetListBoxInfo\n");
3285 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3290 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3292 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3295 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3296 ppi
= PsGetCurrentProcessWin32Process();
3297 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3300 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3305 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3306 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3307 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3308 Ret
= descr
->page_size
* descr
->column_width
;
3310 Ret
= descr
->page_size
;
3312 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3315 SetLastNtError(_SEH2_GetExceptionCode());
3322 if (NotSameppi
) KeDetachProcess();
3323 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3331 * The NtUserSetParent function changes the parent window of the specified
3335 * The new parent window and the child window must belong to the same
3336 * application. If the window identified by the hWndChild parameter is
3337 * visible, the system performs the appropriate redrawing and repainting.
3338 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3339 * or WS_POPUP window styles of the window whose parent is being changed.
3346 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3348 DECLARE_RETURN(HWND
);
3350 TRACE("Enter NtUserSetParent\n");
3351 UserEnterExclusive();
3354 Check Parent first from user space, set it here.
3358 hWndNewParent
= IntGetDesktopWindow();
3360 else if (hWndNewParent
== HWND_MESSAGE
)
3362 hWndNewParent
= IntGetMessageWindow();
3365 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3368 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3374 * UserGetShellWindow
3376 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3381 HWND FASTCALL
UserGetShellWindow(VOID
)
3383 PWINSTATION_OBJECT WinStaObject
;
3386 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3392 if (!NT_SUCCESS(Status
))
3394 SetLastNtError(Status
);
3398 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3400 ObDereferenceObject(WinStaObject
);
3405 * NtUserSetShellWindowEx
3407 * This is undocumented function to set global shell window. The global
3408 * shell window has special handling of window position.
3414 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3416 PWINSTATION_OBJECT WinStaObject
;
3417 PWND WndShell
, WndListView
;
3418 DECLARE_RETURN(BOOL
);
3419 USER_REFERENCE_ENTRY Ref
;
3423 TRACE("Enter NtUserSetShellWindowEx\n");
3424 UserEnterExclusive();
3426 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3431 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3436 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3442 if (!NT_SUCCESS(Status
))
3444 SetLastNtError(Status
);
3449 * Test if we are permitted to change the shell window.
3451 if (WinStaObject
->ShellWindow
)
3453 ObDereferenceObject(WinStaObject
);
3458 * Move shell window into background.
3460 if (hwndListView
&& hwndListView
!= hwndShell
)
3463 * Disabled for now to get Explorer working.
3464 * -- Filip, 01/nov/2003
3467 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3470 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3472 ObDereferenceObject(WinStaObject
);
3477 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3479 ObDereferenceObject(WinStaObject
);
3483 UserRefObjectCo(WndShell
, &Ref
);
3484 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3485 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3487 WinStaObject
->ShellWindow
= hwndShell
;
3488 WinStaObject
->ShellListView
= hwndListView
;
3490 ti
= GetW32ThreadInfo();
3493 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3494 ti
->pDeskInfo
->spwndShell
= WndShell
;
3495 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3498 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3500 UserDerefObjectCo(WndShell
);
3502 ObDereferenceObject(WinStaObject
);
3506 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3511 // Fixes wine Win test_window_styles and todo tests...
3512 static BOOL FASTCALL
3513 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3515 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3517 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3524 co_IntSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
, BOOL bAlter
)
3526 PWND Window
, Parent
;
3527 PWINSTATION_OBJECT WindowStation
;
3531 if (!(Window
= UserGetWindowObject(hWnd
)))
3536 if ((INT
)Index
>= 0)
3538 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3540 EngSetLastError(ERROR_INVALID_INDEX
);
3544 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3546 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3548 OldValue = (LONG)IntSetWindowProc( Wnd,
3551 if (!OldValue) return 0;
3554 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3561 OldValue
= (LONG
) Window
->ExStyle
;
3562 Style
.styleOld
= OldValue
;
3563 Style
.styleNew
= NewValue
;
3565 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3568 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3570 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3573 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3574 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3576 /* WS_EX_WINDOWEDGE depends on some other styles */
3577 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3578 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3580 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3582 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3584 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3588 OldValue
= (LONG
) Window
->style
;
3589 Style
.styleOld
= OldValue
;
3590 Style
.styleNew
= NewValue
;
3593 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3595 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3596 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3597 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3598 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3599 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3601 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3603 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3605 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3606 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3607 DceResetActiveDCEs( Window
);
3609 Window
->style
= (DWORD
)Style
.styleNew
;
3612 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3617 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3618 Window
->fnid
& FNID_FREED
)
3620 EngSetLastError(ERROR_ACCESS_DENIED
);
3623 OldValue
= (LONG
)IntSetWindowProc(Window
,
3630 OldValue
= (LONG
) Window
->hModule
;
3631 Window
->hModule
= (HINSTANCE
) NewValue
;
3634 case GWL_HWNDPARENT
:
3635 Parent
= Window
->spwndParent
;
3636 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3637 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3639 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3643 OldValue
= (LONG
) Window
->IDMenu
;
3644 Window
->IDMenu
= (UINT
) NewValue
;
3648 OldValue
= Window
->dwUserData
;
3649 Window
->dwUserData
= NewValue
;
3653 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3654 EngSetLastError(ERROR_INVALID_INDEX
);
3665 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3667 return co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3671 * NtUserSetWindowLong
3673 * The NtUserSetWindowLong function changes an attribute of the specified
3674 * window. The function also sets the 32-bit (long) value at the specified
3675 * offset into the extra window memory.
3682 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3686 UserEnterExclusive();
3688 if (hWnd
== IntGetDesktopWindow())
3690 EngSetLastError(STATUS_ACCESS_DENIED
);
3695 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3703 NtUserAlterWindowStyle(HWND hWnd
, DWORD Index
, LONG NewValue
)
3707 UserEnterExclusive();
3709 if (hWnd
== IntGetDesktopWindow())
3711 EngSetLastError(STATUS_ACCESS_DENIED
);
3716 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, FALSE
, TRUE
);
3725 * NtUserSetWindowWord
3727 * Legacy function similar to NtUserSetWindowLong.
3734 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3738 DECLARE_RETURN(WORD
);
3740 TRACE("Enter NtUserSetWindowWord\n");
3741 UserEnterExclusive();
3743 if (hWnd
== IntGetDesktopWindow())
3745 EngSetLastError(STATUS_ACCESS_DENIED
);
3749 if (!(Window
= UserGetWindowObject(hWnd
)))
3758 case GWL_HWNDPARENT
:
3759 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3763 EngSetLastError(ERROR_INVALID_INDEX
);
3768 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3770 EngSetLastError(ERROR_INVALID_PARAMETER
);
3774 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3775 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3780 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3786 QueryWindow based on KJK::Hyperion and James Tabor.
3788 0 = QWUniqueProcessId
3789 1 = QWUniqueThreadId
3792 4 = QWIsHung Implements IsHungAppWindow found
3795 9 = QWKillWindow When I called this with hWnd ==
3796 DesktopWindow, it shutdown the system
3803 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3805 /* Console Leader Process CID Window offsets */
3806 #define GWLP_CONSOLE_LEADER_PID 0
3807 #define GWLP_CONSOLE_LEADER_TID 4
3811 DECLARE_RETURN(UINT
);
3813 TRACE("Enter NtUserQueryWindow\n");
3816 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3823 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3825 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3826 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3828 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
3829 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
3833 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3838 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3840 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3841 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3843 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
3844 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
3848 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3853 case QUERY_WINDOW_ACTIVE
:
3854 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3857 case QUERY_WINDOW_FOCUS
:
3858 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3861 case QUERY_WINDOW_ISHUNG
:
3862 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
);
3865 case QUERY_WINDOW_REAL_ID
:
3866 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3869 case QUERY_WINDOW_FOREGROUND
:
3870 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3874 Result
= (DWORD
)NULL
;
3881 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
3890 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3892 UNICODE_STRING SafeMessageName
;
3895 DECLARE_RETURN(UINT
);
3897 TRACE("Enter NtUserRegisterWindowMessage\n");
3898 UserEnterExclusive();
3900 if(MessageNameUnsafe
== NULL
)
3902 EngSetLastError(ERROR_INVALID_PARAMETER
);
3906 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3907 if(!NT_SUCCESS(Status
))
3909 SetLastNtError(Status
);
3913 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3914 if (SafeMessageName
.Buffer
)
3915 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3919 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
3935 DECLARE_RETURN(BOOL
);
3937 TRACE("Enter NtUserSetMenu\n");
3938 UserEnterExclusive();
3940 if (!(Window
= UserGetWindowObject(hWnd
)))
3945 if (! IntSetMenu(Window
, Menu
, &Changed
))
3950 if (Changed
&& Repaint
)
3952 USER_REFERENCE_ENTRY Ref
;
3954 UserRefObjectCo(Window
, &Ref
);
3955 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3956 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3958 UserDerefObjectCo(Window
);
3964 TRACE("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3973 NtUserSetWindowFNID(HWND hWnd
,
3977 DECLARE_RETURN(BOOL
);
3979 TRACE("Enter NtUserSetWindowFNID\n");
3980 UserEnterExclusive();
3982 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3987 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3989 EngSetLastError(ERROR_ACCESS_DENIED
);
3993 // From user land we only set these.
3994 if (fnID
!= FNID_DESTROY
)
3995 { // Hacked so we can mark desktop~!
3996 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
3999 EngSetLastError(ERROR_INVALID_PARAMETER
);
4008 TRACE("Leave NtUserSetWindowFNID\n");
4016 * Undocumented function that is called from DefWindowProc to set
4023 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4026 LARGE_STRING SafeText
;
4027 UNICODE_STRING UnicodeString
;
4030 TRACE("Enter NtUserDefSetText\n");
4032 if (WindowText
!= NULL
)
4036 SafeText
= ProbeForReadLargeString(WindowText
);
4038 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4041 SetLastNtError(_SEH2_GetExceptionCode());
4051 UserEnterExclusive();
4053 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4059 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4060 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4061 // Now we know what the bAnsi is for.
4062 RtlInitUnicodeString(&UnicodeString
, NULL
);
4063 if (SafeText
.Buffer
)
4068 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4070 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4071 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4073 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4076 SetLastNtError(_SEH2_GetExceptionCode());
4079 if (!Ret
) goto Exit
;
4082 if (UnicodeString
.Length
!= 0)
4084 if (Wnd
->strName
.MaximumLength
> 0 &&
4085 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4087 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4089 Wnd
->strName
.Length
= UnicodeString
.Length
;
4090 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4091 RtlCopyMemory(Wnd
->strName
.Buffer
,
4092 UnicodeString
.Buffer
,
4093 UnicodeString
.Length
);
4098 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4099 buf
= Wnd
->strName
.Buffer
;
4100 Wnd
->strName
.Buffer
= NULL
;
4103 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4106 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4107 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4108 if (Wnd
->strName
.Buffer
!= NULL
)
4110 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4111 RtlCopyMemory(Wnd
->strName
.Buffer
,
4112 UnicodeString
.Buffer
,
4113 UnicodeString
.Length
);
4114 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4115 Wnd
->strName
.Length
= UnicodeString
.Length
;
4119 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4127 Wnd
->strName
.Length
= 0;
4128 if (Wnd
->strName
.Buffer
!= NULL
)
4129 Wnd
->strName
.Buffer
[0] = L
'\0';
4132 // FIXME: HAX! Windows does not do this in here!
4133 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4134 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4135 /* Send shell notifications */
4136 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4138 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4143 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4144 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4150 * NtUserInternalGetWindowText
4157 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4162 DECLARE_RETURN(INT
);
4164 TRACE("Enter NtUserInternalGetWindowText\n");
4167 if(lpString
&& (nMaxCount
<= 1))
4169 EngSetLastError(ERROR_INVALID_PARAMETER
);
4173 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4178 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4181 const WCHAR Terminator
= L
'\0';
4183 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4185 Copy
= min(nMaxCount
- 1, Result
);
4188 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4189 if(!NT_SUCCESS(Status
))
4191 SetLastNtError(Status
);
4197 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4198 if(!NT_SUCCESS(Status
))
4200 SetLastNtError(Status
);
4210 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4220 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4226 // ASSERT(OwnerWnd);
4228 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4229 win_array
= IntWinListChildren(OwnerWnd
);
4234 while (win_array
[count
])
4236 while (--count
>= 0)
4238 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4240 if (pWnd
->spwndOwner
!= OwnerWnd
)
4245 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4247 /* In Windows, ShowOwnedPopups(TRUE) generates
4248 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4249 * regardless of the state of the owner
4251 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4257 if (pWnd
->style
& WS_VISIBLE
)
4259 /* In Windows, ShowOwnedPopups(FALSE) generates
4260 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4261 * regardless of the state of the owner
4263 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4269 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4270 TRACE("Leave ShowOwnedPopups\n");