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
)
376 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
378 if (hWnd
== info
.hwndCaret
)
385 Window
= UserGetWindowObject(hWnd
);
388 // USER_REFERENCE_ENTRY Ref;
389 // UserRefObjectCo(Window, &Ref);
391 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
393 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
396 // UserDerefObjectCo(Window);
399 /* The window could already be destroyed here */
402 * Send the WM_DESTROY to the window.
405 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
408 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
409 * make sure that the window still exists when we come back.
418 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
421 /* start from the end (FIXME: is this needed?) */
422 for (i
= 0; pWndArray
[i
]; i
++)
427 if (IsWindow( pWndArray
[i
] ))
428 WIN_SendDestroyMsg( pWndArray
[i
] );
430 HeapFree(GetProcessHeap(), 0, pWndArray
);
434 TRACE("destroyed itself while in WM_DESTROY!\n");
440 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
442 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
446 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
448 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
449 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
452 if (Wnd
->strName
.Buffer
!= NULL
)
454 Wnd
->strName
.Length
= 0;
455 Wnd
->strName
.MaximumLength
= 0;
456 DesktopHeapFree(Wnd
->head
.rpdesk
,
457 Wnd
->strName
.Buffer
);
458 Wnd
->strName
.Buffer
= NULL
;
461 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
462 // WindowObject->hWnd = NULL;
465 /***********************************************************************
468 * Destroy storage associated to a window. "Internals" p.358
470 * This is the "functional" DestroyWindows function ei. all stuff
471 * done in CreateWindow is undone here and not in DestroyWindow:-P
474 static LRESULT
co_UserFreeWindow(PWND Window
,
475 PPROCESSINFO ProcessData
,
476 PTHREADINFO ThreadData
,
477 BOOLEAN SendMessages
)
483 BOOLEAN BelongsToThreadData
;
487 if(Window
->state2
& WNDS2_INDESTROY
)
489 TRACE("Tried to call IntDestroyWindow() twice\n");
492 Window
->state2
|= WNDS2_INDESTROY
;
493 Window
->style
&= ~WS_VISIBLE
;
494 Window
->head
.pti
->cVisWindows
--;
496 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
498 /* remove the window already at this point from the thread window list so we
499 don't get into trouble when destroying the thread windows while we're still
500 in IntDestroyWindow() */
501 RemoveEntryList(&Window
->ThreadListEntry
);
503 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
505 IntDeRegisterShellHookWindow(Window
->head
.h
);
509 /* Send destroy messages */
510 IntSendDestroyMsg(Window
->head
.h
);
513 /* free child windows */
514 Children
= IntWinListChildren(Window
);
517 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
519 if ((Child
= IntGetWindowObject(*ChildHandle
)))
521 if(!IntWndBelongsToThread(Child
, ThreadData
))
523 /* send WM_DESTROY messages to windows not belonging to the same thread */
524 IntSendDestroyMsg(Child
->head
.h
);
527 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
529 UserDereferenceObject(Child
);
532 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
538 * Clear the update region to make sure no WM_PAINT messages will be
539 * generated for this window while processing the WM_NCDESTROY.
541 co_UserRedrawWindow(Window
, NULL
, 0,
542 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
543 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
544 if(BelongsToThreadData
)
545 co_IntSendMessage(Window
->head
.h
, WM_NCDESTROY
, 0, 0);
548 DestroyTimersForWindow(ThreadData
, Window
);
550 /* Unregister hot keys */
551 UnregisterWindowHotKeys (Window
);
553 /* flush the message queue */
554 MsqRemoveWindowMessagesFromQueue(Window
);
556 /* from now on no messages can be sent to this window anymore */
557 Window
->state
|= WNDS_DESTROYED
;
558 Window
->fnid
|= FNID_FREED
;
560 /* don't remove the WINDOWSTATUS_DESTROYING bit */
562 /* reset shell window handles */
563 if(ThreadData
->rpdesk
)
565 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
566 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
568 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
569 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
572 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
576 WinPosCheckInternalPos(Window
->head
.h
);
577 if (Window
->head
.h
== GetCapture())
582 /* free resources associated with the window */
583 TIMER_RemoveWindowTimers(Window
->head
.h
);
586 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
588 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
590 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
594 if(Window
->SystemMenu
595 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
597 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
598 Window
->SystemMenu
= (HMENU
)0;
601 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
604 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
605 CLASS_RemoveWindow(Window
->Class
);
608 IntUnlinkWindow(Window
);
610 if (Window
->PropListItems
)
612 IntRemoveWindowProp(Window
);
613 TRACE("Window->PropListItems %d\n",Window
->PropListItems
);
614 ASSERT(Window
->PropListItems
==0);
617 UserReferenceObject(Window
);
618 UserDeleteObject(Window
->head
.h
, TYPE_WINDOW
);
620 IntDestroyScrollBars(Window
);
622 /* dereference the class */
623 IntDereferenceClass(Window
->pcls
,
624 Window
->head
.pti
->pDeskInfo
,
625 Window
->head
.pti
->ppi
);
630 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
631 GreDeleteObject(Window
->hrgnClip
);
632 Window
->hrgnClip
= NULL
;
634 Window
->head
.pti
->cWindows
--;
636 // ASSERT(Window != NULL);
637 UserFreeWindowInfo(Window
->head
.pti
, Window
);
639 UserDereferenceObject(Window
);
641 UserClipboardFreeWindow(Window
);
647 // Same as User32:IntGetWndProc.
650 IntGetWindowProc(PWND pWnd
,
655 WNDPROC gcpd
, Ret
= 0;
657 ASSERT(UserIsEnteredExclusive() == TRUE
);
661 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
663 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
665 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
668 Ret
= GETPFNCLIENTA(i
);
670 Ret
= GETPFNCLIENTW(i
);
676 if (Class
->fnid
== FNID_EDIT
)
677 Ret
= pWnd
->lpfnWndProc
;
680 Ret
= pWnd
->lpfnWndProc
;
682 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
686 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
687 Ret
= GETPFNCLIENTA(Class
->fnid
);
691 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
692 Ret
= GETPFNCLIENTW(Class
->fnid
);
695 if ( Ret
!= pWnd
->lpfnWndProc
)
698 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
701 gcpd
= (WNDPROC
)UserGetCPD(
703 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
706 return (gcpd
? gcpd
: Ret
);
710 IntSetWindowProc(PWND pWnd
,
715 PCALLPROCDATA CallProc
;
717 WNDPROC Ret
, chWndProc
= NULL
;
719 // Retrieve previous window proc.
720 Ret
= IntGetWindowProc(pWnd
, Ansi
);
724 if (IsCallProcHandle(NewWndProc
))
726 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
728 { // Reset new WndProc.
729 NewWndProc
= CallProc
->pfnClientPrevious
;
730 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
731 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
734 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
735 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
737 if (GETPFNCLIENTW(i
) == NewWndProc
)
739 chWndProc
= GETPFNSERVER(i
);
742 if (GETPFNCLIENTA(i
) == NewWndProc
)
744 chWndProc
= GETPFNSERVER(i
);
748 // If match, set/reset to Server Side and clear ansi.
751 pWnd
->lpfnWndProc
= chWndProc
;
752 pWnd
->Unicode
= TRUE
;
753 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
754 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
758 pWnd
->Unicode
= !Ansi
;
759 // Handle the state change in here.
761 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
763 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
765 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
766 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
768 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
770 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
774 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
775 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
779 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
780 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
783 // Now set the new window proc.
784 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
795 PMENU OldMenu
, NewMenu
= NULL
;
797 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
799 ERR("SetMenu: Invalid handle 0x%p!\n",UserHMGetHandle(Wnd
));
800 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
804 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
812 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
813 ASSERT(NULL
== OldMenu
|| OldMenu
->hWnd
== Wnd
->head
.h
);
822 NewMenu
= IntGetMenuObject(Menu
);
827 IntReleaseMenuObject(OldMenu
);
829 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
832 if (NULL
!= NewMenu
->hWnd
)
834 /* Can't use the same menu for two windows */
837 IntReleaseMenuObject(OldMenu
);
839 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
845 Wnd
->IDMenu
= (UINT
) Menu
;
848 NewMenu
->hWnd
= Wnd
->head
.h
;
849 IntReleaseMenuObject(NewMenu
);
853 OldMenu
->hWnd
= NULL
;
854 IntReleaseMenuObject(OldMenu
);
861 /* INTERNAL ******************************************************************/
865 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
870 USER_REFERENCE_ENTRY Ref
;
871 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
873 while (!IsListEmpty(&WThread
->WindowListHead
))
875 Current
= WThread
->WindowListHead
.Flink
;
876 Wnd
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
878 TRACE("thread cleanup: while destroy wnds, wnd=%p\n", Wnd
);
880 /* Window removes itself from the list */
883 * FIXME: It is critical that the window removes itself! If now, we will loop
887 //ASSERT(co_UserDestroyWindow(Wnd));
889 UserRefObjectCo(Wnd
, &Ref
); // FIXME: Temp HACK??
890 if (!co_UserDestroyWindow(Wnd
))
892 ERR("Unable to destroy window %p at thread cleanup... This is _VERY_ bad!\n", Wnd
);
894 UserDerefObjectCo(Wnd
); // FIXME: Temp HACK??
899 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
904 while (Window
&& ((Window
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
906 if (Window
== Parent
)
911 Window
= Window
->spwndParent
;
918 Link the window into siblings list
919 children and parent are kept in place.
924 PWND WndInsertAfter
/* set to NULL if top sibling */
927 if ((Wnd
->spwndPrev
= WndInsertAfter
))
929 /* link after WndInsertAfter */
930 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
931 Wnd
->spwndNext
->spwndPrev
= Wnd
;
933 Wnd
->spwndPrev
->spwndNext
= Wnd
;
938 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
939 Wnd
->spwndNext
->spwndPrev
= Wnd
;
941 Wnd
->spwndParent
->spwndChild
= Wnd
;
946 Note: Wnd->spwndParent can be null if it is the desktop.
948 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
950 if (hWndPrev
== HWND_NOTOPMOST
)
952 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
953 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
954 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
955 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
958 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
960 if (hWndPrev
== HWND_BOTTOM
)
962 /* Link in the bottom of the list */
965 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
966 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
967 WndInsertAfter
= WndInsertAfter
->spwndNext
;
969 IntLinkWindow(Wnd
, WndInsertAfter
);
970 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
972 else if (hWndPrev
== HWND_TOPMOST
)
974 /* Link in the top of the list */
975 IntLinkWindow(Wnd
, NULL
);
977 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
979 else if (hWndPrev
== HWND_TOP
)
981 /* Link it after the last topmost window */
982 PWND WndInsertBefore
;
984 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
986 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
988 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
990 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
991 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
993 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
996 WndInsertBefore
= WndInsertBefore
->spwndNext
;
1000 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
1004 /* Link it after hWndPrev */
1005 PWND WndInsertAfter
;
1007 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1008 /* Are we called with an erroneous handle */
1009 if(WndInsertAfter
== NULL
)
1011 /* Link in a default position */
1012 IntLinkHwnd(Wnd
, HWND_TOP
);
1016 IntLinkWindow(Wnd
, WndInsertAfter
);
1018 /* Fix the WS_EX_TOPMOST flag */
1019 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1021 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1025 if(WndInsertAfter
->spwndNext
&&
1026 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1028 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1032 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
1036 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
1040 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
1043 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
1044 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1046 //ERR("ProcessOwnerSwap Old out.\n");
1047 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
1053 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
1056 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1058 //ERR("ProcessOwnerSwap New in.\n");
1059 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1063 // FIXME: System Tray checks.
1067 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1069 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1072 Wnd
= IntGetWindowObject(hWnd
);
1076 WndOldOwner
= Wnd
->spwndOwner
;
1078 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1079 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1081 if (!WndNewOwner
&& hWndNewOwner
)
1083 EngSetLastError(ERROR_INVALID_PARAMETER
);
1088 /* if parent belongs to a different thread and the window isn't */
1089 /* top-level, attach the two threads */
1090 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1092 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1096 Wnd
->spwndOwner
= WndNewOwner
;
1100 Wnd
->spwndOwner
= NULL
;
1105 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1106 EngSetLastError(ERROR_INVALID_PARAMETER
);
1110 UserDereferenceObject(Wnd
);
1115 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1117 PWND WndOldParent
, pWndExam
;
1120 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1123 ASSERT(WndNewParent
);
1124 ASSERT_REFS_CO(Wnd
);
1125 ASSERT_REFS_CO(WndNewParent
);
1127 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1129 EngSetLastError(ERROR_ACCESS_DENIED
);
1133 /* Some applications try to set a child as a parent */
1134 if (IntIsChildWindow(Wnd
, WndNewParent
))
1136 TRACE("IntSetParent try to set a child as a parent.\n");
1137 EngSetLastError( ERROR_INVALID_PARAMETER
);
1141 pWndExam
= WndNewParent
; // Load parent Window to examine.
1142 // Now test for set parent to parent hit.
1145 if (Wnd
== pWndExam
)
1147 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1148 EngSetLastError(ERROR_INVALID_PARAMETER
);
1151 pWndExam
= pWndExam
->spwndParent
;
1155 * Windows hides the window first, then shows it again
1156 * including the WM_SHOWWINDOW messages and all
1158 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1160 /* Window must belong to current process */
1161 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1163 ERR("IntSetParent Window must belong to current process!\n");
1167 WndOldParent
= Wnd
->spwndParent
;
1169 if ( WndOldParent
&&
1170 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1171 pt
.x
= Wnd
->rcWindow
.right
;
1173 pt
.x
= Wnd
->rcWindow
.left
;
1174 pt
.y
= Wnd
->rcWindow
.top
;
1176 IntScreenToClient(WndOldParent
, &pt
);
1178 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1180 if (WndNewParent
!= WndOldParent
)
1182 /* Unlink the window from the siblings list */
1183 IntUnlinkWindow(Wnd
);
1184 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1186 /* Set the new parent */
1187 Wnd
->spwndParent
= WndNewParent
;
1189 if ( Wnd
->style
& WS_CHILD
&&
1191 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1193 ERR("SetParent Top Most from Pop up!\n");
1194 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1197 /* Link the window with its new siblings */
1199 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1200 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1204 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1205 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1207 Wnd
->style
|= WS_CLIPSIBLINGS
;
1208 DceResetActiveDCEs(Wnd
);
1211 /* if parent belongs to a different thread and the window isn't */
1212 /* top-level, attach the two threads */
1213 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1215 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1217 if (Wnd
->head
.pti
!= WndOldParent
->head
.pti
)
1219 //ERR("SetParent Old out.\n");
1220 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1223 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1225 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1227 //ERR("SetParent New in.\n");
1228 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1233 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1234 swFlags
|= SWP_NOACTIVATE
;
1236 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1238 * SetParent additionally needs to make hwnd the top window
1239 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1240 * WM_WINDOWPOSCHANGED notification messages.
1242 //ERR("IntSetParent SetWindowPos 1\n");
1243 co_WinPosSetWindowPos( Wnd
,
1244 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1245 pt
.x
, pt
.y
, 0, 0, swFlags
);
1246 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1247 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1249 return WndOldParent
;
1253 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1255 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1256 HWND hWndOldParent
= NULL
;
1257 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1259 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1261 EngSetLastError(ERROR_INVALID_PARAMETER
);
1265 if (hWndChild
== IntGetDesktopWindow())
1267 ERR("UserSetParent Access Denied!\n");
1268 EngSetLastError(ERROR_ACCESS_DENIED
);
1274 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1276 ERR("UserSetParent Bad New Parent!\n");
1282 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1288 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1290 ERR("UserSetParent Bad Child!\n");
1294 UserRefObjectCo(Wnd
, &Ref
);
1295 UserRefObjectCo(WndParent
, &ParentRef
);
1296 //ERR("Enter co_IntSetParent\n");
1297 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1298 //ERR("Leave co_IntSetParent\n");
1299 UserDerefObjectCo(WndParent
);
1300 UserDerefObjectCo(Wnd
);
1304 hWndOldParent
= WndOldParent
->head
.h
;
1305 UserDereferenceObject(WndOldParent
);
1308 return( hWndOldParent
);
1311 /* Unlink the window from siblings. children and parent are kept in place. */
1313 IntUnlinkWindow(PWND Wnd
)
1316 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1319 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1321 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1322 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1324 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1327 /* FUNCTIONS *****************************************************************/
1330 * As best as I can figure, this function is used by EnumWindows,
1331 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1333 * It's supposed to build a list of HWNDs to return to the caller.
1334 * We can figure out what kind of list by what parameters are
1342 NtUserBuildHwndList(
1355 return ERROR_INVALID_PARAMETER
;
1357 if (hwndParent
|| !dwThreadId
)
1360 PWND Parent
, Window
;
1364 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1366 return ERROR_INVALID_HANDLE
;
1371 Status
= IntValidateDesktopHandle(hDesktop
,
1375 if(!NT_SUCCESS(Status
))
1377 return ERROR_INVALID_HANDLE
;
1380 hwndParent
= Desktop
->DesktopWindow
;
1387 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1388 (Window
= Parent
->spwndChild
))
1390 BOOL bGoDown
= TRUE
;
1392 Status
= STATUS_SUCCESS
;
1397 if(dwCount
++ < *pBufSize
&& pWnd
)
1401 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1402 *pWnd
= Window
->head
.h
;
1405 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1407 Status
= _SEH2_GetExceptionCode();
1410 if(!NT_SUCCESS(Status
))
1412 SetLastNtError(Status
);
1416 if (Window
->spwndChild
&& bChildren
)
1418 Window
= Window
->spwndChild
;
1423 if (Window
->spwndNext
)
1425 Window
= Window
->spwndNext
;
1429 Window
= Window
->spwndParent
;
1430 if (Window
== Parent
)
1439 ObDereferenceObject(Desktop
);
1442 else // Build EnumThreadWindows list!
1445 PTHREADINFO W32Thread
;
1446 PLIST_ENTRY Current
;
1449 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1450 if (!NT_SUCCESS(Status
))
1452 ERR("Thread Id is not valid!\n");
1453 return ERROR_INVALID_PARAMETER
;
1455 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1457 ObDereferenceObject(Thread
);
1458 ERR("Thread is not initialized!\n");
1459 return ERROR_INVALID_PARAMETER
;
1462 Current
= W32Thread
->WindowListHead
.Flink
;
1463 while (Current
!= &(W32Thread
->WindowListHead
))
1465 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1468 if (dwCount
< *pBufSize
&& pWnd
)
1472 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1473 *pWnd
= Window
->head
.h
;
1476 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1478 Status
= _SEH2_GetExceptionCode();
1481 if (!NT_SUCCESS(Status
))
1483 ERR("Failure to build window list!\n");
1484 SetLastNtError(Status
);
1489 Current
= Window
->ThreadListEntry
.Flink
;
1492 ObDereferenceObject(Thread
);
1495 *pBufSize
= dwCount
;
1496 return STATUS_SUCCESS
;
1499 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1501 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1502 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1504 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1506 USER_REFERENCE_ENTRY Ref
;
1507 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1508 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1510 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1511 (LPARAM
)pWindow
->head
.h
);
1512 UserDerefObjectCo(pWindow
->spwndParent
);
1518 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1520 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1522 /* default positioning for overlapped windows */
1523 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1526 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1528 pMonitor
= UserGetPrimaryMonitor();
1530 /* Check if we don't have a monitor attached yet */
1531 if(pMonitor
== NULL
)
1539 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1541 if (IS_DEFAULT(Cs
->x
))
1543 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1545 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1547 Cs
->x
= ProcessParams
->StartingX
;
1548 Cs
->y
= ProcessParams
->StartingY
;
1552 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1553 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1554 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1555 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1557 /* reset counter and position */
1560 pMonitor
->cWndStack
= 0;
1562 pMonitor
->cWndStack
++;
1566 if (IS_DEFAULT(Cs
->cx
))
1568 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1570 Cs
->cx
= ProcessParams
->CountX
;
1571 Cs
->cy
= ProcessParams
->CountY
;
1575 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1576 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1579 /* neither x nor cx are default. Check the y values .
1580 * In the trace we see Outlook and Outlook Express using
1581 * cy set to CW_USEDEFAULT when opening the address book.
1583 else if (IS_DEFAULT(Cs
->cy
))
1585 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1586 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1591 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1592 if(IS_DEFAULT(Cs
->x
))
1597 if(IS_DEFAULT(Cs
->cx
))
1607 /* Allocates and initializes a window */
1608 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1609 PLARGE_STRING WindowName
,
1614 PDESKTOP pdeskCreated
)
1618 PTHREADINFO pti
= NULL
;
1620 BOOL bUnicodeWindow
;
1622 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1624 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1625 { // Need both here for wine win.c test_CreateWindow.
1626 //if (Cs->hwndParent && ParentWindow)
1627 if (ParentWindow
) // It breaks more tests..... WIP.
1629 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1630 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1631 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1632 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1636 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1638 * Dialog boxes and message boxes do not inherit layout, so you must
1639 * set the layout explicitly.
1641 if ( Class
->fnid
!= FNID_DIALOG
)
1643 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1645 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1651 /* Automatically add WS_EX_WINDOWEDGE */
1652 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1653 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1654 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1655 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1657 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1659 /* Is it a unicode window? */
1660 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1661 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1663 /* Allocate the new window */
1664 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1665 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1669 sizeof(WND
) + Class
->cbwndExtra
);
1676 TRACE("Created window object with handle %p\n", hWnd
);
1678 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1679 { /* HACK: Helper for win32csr/desktopbg.c */
1680 /* If there is no desktop window yet, we must be creating it */
1681 TRACE("CreateWindow setting desktop.\n");
1682 pdeskCreated
->DesktopWindow
= hWnd
;
1683 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1687 * Fill out the structure describing it.
1689 /* Remember, pWnd->head is setup in object.c ... */
1690 pWnd
->spwndParent
= ParentWindow
;
1691 pWnd
->spwndOwner
= OwnerWindow
;
1693 pWnd
->spwndLastActive
= pWnd
;
1694 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1696 pWnd
->hModule
= Cs
->hInstance
;
1697 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1698 pWnd
->ExStyle
= Cs
->dwExStyle
;
1699 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1700 pWnd
->pActCtx
= acbiBuffer
;
1701 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1702 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1704 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1706 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1707 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1710 pWnd
->head
.pti
->cWindows
++;
1712 if (Class
->hIcon
&& !Class
->hIconSm
)
1714 Class
->hIconSmIntern
= co_IntCopyImage( Class
->hIcon
, IMAGE_ICON
,
1715 UserGetSystemMetrics( SM_CXSMICON
),
1716 UserGetSystemMetrics( SM_CYSMICON
), 0 );
1717 TRACE("IntCreateWindow hIconSmIntern %p\n",Class
->hIconSmIntern
);
1718 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1721 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1722 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1724 /* BugBoy Comments: Comment below say that System classes are always created
1725 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1726 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1728 No where can I see in code or through testing does the window change back
1729 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1730 see what problems this would cause. */
1732 // Set WndProc from Class.
1733 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1735 // GetWindowProc, test for non server side default classes and set WndProc.
1736 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1740 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1741 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1745 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1746 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1750 // If not an Unicode caller, set Ansi creator bit.
1751 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1753 // Clone Class Ansi/Unicode proc type.
1754 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1756 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1757 pWnd
->Unicode
= FALSE
;
1761 * It seems there can be both an Ansi creator and Unicode Class Window
1762 * WndProc, unless the following overriding conditions occur:
1764 if ( !bUnicodeWindow
&&
1765 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1766 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1767 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1768 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1769 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1770 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1771 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1772 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1773 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1774 { // Override Class and set the window Ansi WndProc.
1775 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1776 pWnd
->Unicode
= FALSE
;
1779 { // Set the window Unicode WndProc.
1780 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1781 pWnd
->Unicode
= TRUE
;
1785 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1786 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1787 Dont understand why it does this. */
1788 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1790 PCALLPROCDATA CallProc
;
1791 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1795 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1796 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1800 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1804 InitializeListHead(&pWnd
->PropListHead
);
1805 pWnd
->PropListItems
= 0;
1807 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1809 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1810 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1811 if (pWnd
->strName
.Buffer
== NULL
)
1816 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1817 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1818 pWnd
->strName
.Length
= WindowName
->Length
;
1819 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1822 /* Correct the window style. */
1823 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1825 pWnd
->style
|= WS_CLIPSIBLINGS
;
1826 if (!(pWnd
->style
& WS_POPUP
))
1828 pWnd
->style
|= WS_CAPTION
;
1832 /* WS_EX_WINDOWEDGE depends on some other styles */
1833 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1834 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1835 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1837 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1838 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1839 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1842 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1844 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1845 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1847 /* Set the window menu */
1848 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1852 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1854 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1856 UNICODE_STRING MenuName
;
1859 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1861 MenuName
.Length
= 0;
1862 MenuName
.MaximumLength
= 0;
1863 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1867 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1869 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1870 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1874 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1877 if ( ParentWindow
&&
1878 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1879 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1881 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1883 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1885 EngSetLastError(ERROR_INVALID_PARAMETER
);
1888 if ( pWnd
->spwndOwner
&&
1889 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1891 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1893 if ( pWnd
->spwndOwner
&&
1894 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1895 pti
!= pWnd
->spwndOwner
->head
.pti
)
1897 //ERR("CreateWindow Owner in.\n");
1898 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1902 /* Insert the window into the thread's window list. */
1903 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1905 /* Handle "CS_CLASSDC", it is tested first. */
1906 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1907 { /* One DCE per class to have CLASS. */
1908 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1910 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1911 { /* Allocate a DCE for this window. */
1912 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1918 ERR("IntCreateWindow Allocation Error.\n");
1919 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1922 UserDereferenceObject(pWnd
);
1930 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1931 PUNICODE_STRING ClassName
,
1932 PLARGE_STRING WindowName
,
1936 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1937 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1938 PWINSTATION_OBJECT WinSta
;
1941 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1942 CBT_CREATEWNDW
* pCbtCreate
;
1944 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1946 DWORD dwShowMode
= SW_SHOW
;
1947 CREATESTRUCTW
*pCsw
= NULL
;
1948 PVOID pszClass
= NULL
, pszName
= NULL
;
1951 /* Get the current window station and reference it */
1952 pti
= GetW32ThreadInfo();
1953 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1955 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1956 return NULL
; // There is nothing to cleanup.
1958 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1959 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1964 /* Get the class and reference it */
1965 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
1968 ERR("Failed to find class %wZ\n", ClassName
);
1972 /* Now find the parent and the owner window */
1973 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
1976 if (Cs
->hwndParent
== HWND_MESSAGE
)
1978 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
1980 else if (Cs
->hwndParent
)
1982 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1983 hWndOwner
= Cs
->hwndParent
;
1985 hWndParent
= Cs
->hwndParent
;
1987 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1989 ERR("Cannot create a child window without a parrent!\n");
1990 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1991 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1994 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1995 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1997 /* FIXME: Is this correct? */
1999 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
2001 /* Fix the position and the size of the window */
2004 UserRefObjectCo(ParentWindow
, &ParentRef
);
2005 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2008 /* Allocate and initialize the new window */
2009 Window
= IntCreateWindow(Cs
,
2018 ERR("IntCreateWindow failed!\n");
2022 hWnd
= UserHMGetHandle(Window
);
2023 hwndInsertAfter
= HWND_TOP
;
2025 UserRefObjectCo(Window
, &Ref
);
2026 UserDereferenceObject(Window
);
2027 ObDereferenceObject(WinSta
);
2029 //// Check for a hook to eliminate overhead. ////
2030 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2032 // Allocate the calling structures Justin Case this goes Global.
2033 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2034 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2035 if (!pCsw
|| !pCbtCreate
)
2037 ERR("UserHeapAlloc() failed!\n");
2041 /* Fill the new CREATESTRUCTW */
2042 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2043 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2045 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2046 if (!IS_ATOM(ClassName
->Buffer
))
2048 if (Window
->state
& WNDS_ANSICREATOR
)
2050 ANSI_STRING AnsiString
;
2051 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2052 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2055 ERR("UserHeapAlloc() failed!\n");
2058 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2059 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2060 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2064 UNICODE_STRING UnicodeString
;
2065 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2066 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2069 ERR("UserHeapAlloc() failed!\n");
2072 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2073 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2074 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2076 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2078 if (WindowName
->Length
)
2080 UNICODE_STRING Name
;
2081 Name
.Buffer
= WindowName
->Buffer
;
2082 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2083 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2085 if (Window
->state
& WNDS_ANSICREATOR
)
2087 ANSI_STRING AnsiString
;
2088 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2089 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2092 ERR("UserHeapAlloc() failed!\n");
2095 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2096 AnsiString
.Buffer
= (PCHAR
)pszName
;
2097 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2101 UNICODE_STRING UnicodeString
;
2102 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2103 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2106 ERR("UserHeapAlloc() failed!\n");
2109 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2110 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2111 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2113 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2116 pCbtCreate
->lpcs
= pCsw
;
2117 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2119 //// Call the WH_CBT hook ////
2120 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2123 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2126 // Write back changes.
2131 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2134 /* NCCREATE and WM_NCCALCSIZE need the original values */
2135 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2136 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2138 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2140 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2142 Cs
->x
+= ParentWindow
->rcClient
.left
;
2143 Cs
->y
+= ParentWindow
->rcClient
.top
;
2147 /* Send the WM_GETMINMAXINFO message */
2151 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2153 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2154 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2155 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2156 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2157 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2160 Window
->rcWindow
.left
= Cs
->x
;
2161 Window
->rcWindow
.top
= Cs
->y
;
2162 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2163 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2165 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2167 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2168 RECTL_vOffsetRect(&Window->rcWindow,
2169 ParentWindow->rcClient.left,
2170 ParentWindow->rcClient.top);
2173 /* correct child window coordinates if mirroring on parent is enabled */
2174 if (ParentWindow
!= NULL
)
2176 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2177 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2179 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2180 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2184 Window
->rcClient
= Window
->rcWindow
;
2186 /* Link the window */
2187 if (NULL
!= ParentWindow
)
2189 /* Link the window into the siblings list */
2190 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2191 IntLinkHwnd(Window
, HWND_BOTTOM
);
2193 IntLinkHwnd(Window
, hwndInsertAfter
);
2196 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2198 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2199 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2202 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2204 if ( !IntIsTopLevelWindow(Window
) )
2206 if (pti
!= Window
->spwndParent
->head
.pti
)
2208 //ERR("CreateWindow Parent in.\n");
2209 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2214 /* Send the NCCREATE message */
2215 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2218 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2222 /* Send the WM_NCCALCSIZE message */
2225 MaxPos
.x
= Window
->rcWindow
.left
;
2226 MaxPos
.y
= Window
->rcWindow
.top
;
2228 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2229 //rc = Window->rcWindow;
2230 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2231 //Window->rcClient = rc;
2233 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2234 MaxPos
.y
- Window
->rcWindow
.top
);
2237 /* Send the WM_CREATE message. */
2238 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2239 if (Result
== (LRESULT
)-1)
2241 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2245 /* Send the EVENT_OBJECT_CREATE event */
2246 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2248 /* By setting the flag below it can be examined to determine if the window
2249 was created successfully and a valid pwnd was passed back to caller since
2250 from here the function has to succeed. */
2251 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2253 /* Send the WM_SIZE and WM_MOVE messages. */
2254 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2256 co_WinPosSendSizeMove(Window
);
2259 /* Show or maybe minimize or maximize the window. */
2261 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2262 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2265 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2267 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2268 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2269 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2270 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2271 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2274 /* Send the WM_PARENTNOTIFY message */
2275 IntSendParentNotify(Window
, WM_CREATE
);
2277 /* Notify the shell that a new window was created */
2278 if (Window
->spwndParent
== UserGetDesktopWindow() &&
2279 Window
->spwndOwner
== NULL
&&
2280 (Window
->style
& WS_VISIBLE
) &&
2281 (!(Window
->ExStyle
& WS_EX_TOOLWINDOW
) ||
2282 (Window
->ExStyle
& WS_EX_APPWINDOW
)))
2284 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2287 /* Initialize and show the window's scrollbars */
2288 if (Window
->style
& WS_VSCROLL
)
2290 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2292 if (Window
->style
& WS_HSCROLL
)
2294 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2297 /* Show the new window */
2298 if (Cs
->style
& WS_VISIBLE
)
2300 if (Window
->style
& WS_MAXIMIZE
)
2301 dwShowMode
= SW_SHOW
;
2302 else if (Window
->style
& WS_MINIMIZE
)
2303 dwShowMode
= SW_SHOWMINIMIZED
;
2305 co_WinPosShowWindow(Window
, dwShowMode
);
2307 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2309 ASSERT(ParentWindow
);
2312 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2313 /* ShowWindow won't activate child windows */
2314 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
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
);
2348 ProbeAndCaptureLargeString(
2349 OUT PLARGE_STRING plstrSafe
,
2350 IN PLARGE_STRING plstrUnsafe
)
2352 LARGE_STRING lstrTemp
;
2353 PVOID pvBuffer
= NULL
;
2357 /* Probe and copy the string */
2358 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2359 lstrTemp
= *plstrUnsafe
;
2361 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2364 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2368 if (lstrTemp
.Length
!= 0)
2370 /* Allocate a buffer from paged pool */
2371 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2374 return STATUS_NO_MEMORY
;
2379 /* Probe and copy the buffer */
2380 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2381 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2383 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2385 /* Cleanup and fail */
2386 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2387 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2392 /* Set the output string */
2393 plstrSafe
->Buffer
= pvBuffer
;
2394 plstrSafe
->Length
= lstrTemp
.Length
;
2395 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2397 return STATUS_SUCCESS
;
2401 * \todo Allow passing plstrClassName as ANSI.
2405 NtUserCreateWindowEx(
2407 PLARGE_STRING plstrClassName
,
2408 PLARGE_STRING plstrClsVersion
,
2409 PLARGE_STRING plstrWindowName
,
2417 HINSTANCE hInstance
,
2423 LARGE_STRING lstrWindowName
;
2424 LARGE_STRING lstrClassName
;
2425 UNICODE_STRING ustrClassName
;
2430 lstrWindowName
.Buffer
= NULL
;
2431 lstrClassName
.Buffer
= NULL
;
2433 ASSERT(plstrWindowName
);
2435 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2437 /* check hMenu is valid handle */
2438 if (hMenu
&& !ValidateHandle(hMenu
, TYPE_MENU
))
2440 /* error is set in ValidateHandle */
2445 /* Copy the window name to kernel mode */
2446 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2447 if (!NT_SUCCESS(Status
))
2449 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2450 SetLastNtError(Status
);
2454 plstrWindowName
= &lstrWindowName
;
2456 /* Check if the class is an atom */
2457 if (IS_ATOM(plstrClassName
))
2459 /* It is, pass the atom in the UNICODE_STRING */
2460 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2461 ustrClassName
.Length
= 0;
2462 ustrClassName
.MaximumLength
= 0;
2466 /* It's not, capture the class name */
2467 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2468 if (!NT_SUCCESS(Status
))
2470 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2471 /* Set last error, cleanup and return */
2472 SetLastNtError(Status
);
2476 /* We pass it on as a UNICODE_STRING */
2477 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2478 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2479 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2482 /* Fill the CREATESTRUCTW */
2483 /* we will keep here the original parameters */
2485 Cs
.lpCreateParams
= lpParam
;
2486 Cs
.hInstance
= hInstance
;
2488 Cs
.hwndParent
= hWndParent
;
2493 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2494 if (IS_ATOM(plstrClassName
))
2495 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2497 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2498 Cs
.dwExStyle
= dwExStyle
;
2500 UserEnterExclusive();
2502 /* Call the internal function */
2503 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
);
2507 ERR("co_UserCreateWindowEx failed!\n");
2509 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2514 if (lstrWindowName
.Buffer
)
2516 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2518 if (lstrClassName
.Buffer
)
2520 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2527 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2534 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2536 hWnd
= Window
->head
.h
;
2537 ti
= PsGetCurrentThreadWin32Thread();
2539 TRACE("co_UserDestroyWindow \n");
2541 /* Check for owner thread */
2542 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2544 /* Check if we are destroying the desktop window */
2545 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2547 EngSetLastError(ERROR_ACCESS_DENIED
);
2552 /* If window was created successfully and it is hooked */
2553 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2555 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2557 ERR("Destroy Window WH_CBT Call Hook return!\n");
2562 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2564 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2566 if (Window
->spwndOwner
)
2568 //ERR("DestroyWindow Owner out.\n");
2569 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2574 /* Inform the parent */
2575 if (Window
->style
& WS_CHILD
)
2577 IntSendParentNotify(Window
, WM_DESTROY
);
2580 /* Look whether the focus is within the tree of windows we will
2583 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2585 if (ti
->MessageQueue
->spwndActive
== Window
&& ti
->MessageQueue
== IntGetFocusMessageQueue())
2587 co_WinPosActivateOtherWindow(Window
);
2591 // Adjust last active.
2592 if ((pwndTemp
= Window
->spwndOwner
))
2594 while (pwndTemp
->spwndOwner
)
2595 pwndTemp
= pwndTemp
->spwndOwner
;
2597 if (pwndTemp
->spwndLastActive
== Window
)
2598 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2601 if (Window
->spwndParent
&& IntIsWindow(Window
->head
.h
))
2603 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2605 if (!IntIsTopLevelWindow(Window
))
2607 //ERR("DestroyWindow Parent out.\n");
2608 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2613 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2614 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2615 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2616 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2617 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2618 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2619 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2620 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2623 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2626 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2628 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2630 ERR("Destroying the ShellWindow!\n");
2631 ti
->pDeskInfo
->hShellWindow
= NULL
;
2635 IntEngWindowChanged(Window
, WOC_DELETE
);
2637 if (!IntIsWindow(Window
->head
.h
))
2642 /* Recursively destroy owned windows */
2644 if (! (Window
->style
& WS_CHILD
))
2648 BOOL GotOne
= FALSE
;
2651 PWND Child
, Desktop
;
2653 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2654 UserGetWindowObject(IntGetDesktopWindow());
2655 Children
= IntWinListChildren(Desktop
);
2659 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2661 Child
= UserGetWindowObject(*ChildHandle
);
2664 if (Child
->spwndOwner
!= Window
)
2669 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2671 USER_REFERENCE_ENTRY ChildRef
;
2672 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2673 co_UserDestroyWindow(Child
);
2674 UserDerefObjectCo(Child
); // Temp HACK?
2680 if (Child
->spwndOwner
!= NULL
)
2682 Child
->spwndOwner
= NULL
;
2686 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2695 /* Generate mouse move message for the next window */
2696 msg
.message
= WM_MOUSEMOVE
;
2697 msg
.wParam
= UserGetMouseButtonsState();
2698 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2699 msg
.pt
= gpsi
->ptCursor
;
2700 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2702 if (!IntIsWindow(Window
->head
.h
))
2707 /* Destroy the window storage */
2708 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2718 NtUserDestroyWindow(HWND Wnd
)
2721 DECLARE_RETURN(BOOLEAN
);
2723 USER_REFERENCE_ENTRY Ref
;
2725 TRACE("Enter NtUserDestroyWindow\n");
2726 UserEnterExclusive();
2728 if (!(Window
= UserGetWindowObject(Wnd
)))
2733 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2734 ret
= co_UserDestroyWindow(Window
);
2735 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2740 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2746 static HWND FASTCALL
2747 IntFindWindow(PWND Parent
,
2750 PUNICODE_STRING WindowName
)
2752 BOOL CheckWindowName
;
2755 UNICODE_STRING CurrentWindowName
;
2759 CheckWindowName
= WindowName
->Buffer
!= 0;
2761 if((List
= IntWinListChildren(Parent
)))
2766 /* skip handles before and including ChildAfter */
2767 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2771 /* search children */
2775 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2780 /* Do not send WM_GETTEXT messages in the kernel mode version!
2781 The user mode version however calls GetWindowText() which will
2782 send WM_GETTEXT messages to windows belonging to its processes */
2783 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2785 // FIXME: LARGE_STRING truncated
2786 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2787 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2788 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2789 if(!CheckWindowName
||
2790 (Child
->strName
.Length
< 0xFFFF &&
2791 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2793 Ret
= Child
->head
.h
;
2798 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2806 * Searches a window's children for a window with the specified
2809 * hwndParent = The window whose childs are to be searched.
2811 * HWND_MESSAGE = message-only windows
2813 * hwndChildAfter = Search starts after this child window.
2814 * NULL = start from beginning
2816 * ucClassName = Class name to search for
2817 * Reguired parameter.
2819 * ucWindowName = Window name
2820 * ->Buffer == NULL = don't care
2823 * The HWND of the window if it was found, otherwise NULL
2829 NtUserFindWindowEx(HWND hwndParent
,
2830 HWND hwndChildAfter
,
2831 PUNICODE_STRING ucClassName
,
2832 PUNICODE_STRING ucWindowName
,
2835 PWND Parent
, ChildAfter
;
2836 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2837 HWND Desktop
, Ret
= NULL
;
2838 BOOL DoMessageWnd
= FALSE
;
2839 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2840 DECLARE_RETURN(HWND
);
2842 TRACE("Enter NtUserFindWindowEx\n");
2845 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2849 if (ucClassName
!= NULL
)
2851 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2852 if (ClassName
.Length
!= 0)
2854 ProbeForRead(ClassName
.Buffer
,
2858 else if (!IS_ATOM(ClassName
.Buffer
))
2860 EngSetLastError(ERROR_INVALID_PARAMETER
);
2864 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2871 if (ucWindowName
!= NULL
)
2873 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2874 if (WindowName
.Length
!= 0)
2876 ProbeForRead(WindowName
.Buffer
,
2882 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2884 SetLastNtError(_SEH2_GetExceptionCode());
2885 _SEH2_YIELD(RETURN(NULL
));
2889 if (ucClassName
!= NULL
)
2891 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2892 !IS_ATOM(ClassName
.Buffer
))
2894 EngSetLastError(ERROR_INVALID_PARAMETER
);
2897 else if (ClassAtom
== (RTL_ATOM
)0)
2899 /* LastError code was set by IntGetAtomFromStringOrAtom */
2905 Desktop
= IntGetCurrentThreadDesktopWindow();
2907 if(hwndParent
== NULL
)
2909 hwndParent
= Desktop
;
2910 DoMessageWnd
= TRUE
;
2912 else if(hwndParent
== HWND_MESSAGE
)
2914 hwndParent
= IntGetMessageWindow();
2917 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2923 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2930 if(Parent
->head
.h
== Desktop
)
2933 PWND TopLevelWindow
;
2934 BOOLEAN CheckWindowName
;
2935 BOOLEAN WindowMatches
;
2936 BOOLEAN ClassMatches
;
2938 /* windows searches through all top-level windows if the parent is the desktop
2941 if((List
= IntWinListChildren(Parent
)))
2947 /* skip handles before and including ChildAfter */
2948 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2952 CheckWindowName
= WindowName
.Buffer
!= 0;
2954 /* search children */
2957 UNICODE_STRING ustr
;
2959 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2964 /* Do not send WM_GETTEXT messages in the kernel mode version!
2965 The user mode version however calls GetWindowText() which will
2966 send WM_GETTEXT messages to windows belonging to its processes */
2967 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2968 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
2969 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
2970 WindowMatches
= !CheckWindowName
||
2971 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2972 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2973 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2974 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2976 if (WindowMatches
&& ClassMatches
)
2978 Ret
= TopLevelWindow
->head
.h
;
2982 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2984 /* window returns the handle of the top-level window, in case it found
2986 Ret
= TopLevelWindow
->head
.h
;
2991 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2996 ERR("FindWindowEx: Not Desktop Parent!\n");
2997 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3000 if (Ret
== NULL
&& DoMessageWnd
)
3004 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3006 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3010 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3012 SetLastNtError(_SEH2_GetExceptionCode());
3020 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3029 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3031 PWND WndAncestor
, Parent
;
3033 if (Wnd
->head
.h
== IntGetDesktopWindow())
3042 WndAncestor
= Wnd
->spwndParent
;
3053 if(!(Parent
= WndAncestor
->spwndParent
))
3057 if(IntIsDesktopWindow(Parent
))
3062 WndAncestor
= Parent
;
3073 Parent
= IntGetParent(WndAncestor
);
3080 WndAncestor
= Parent
;
3098 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3100 PWND Window
, Ancestor
;
3101 DECLARE_RETURN(HWND
);
3103 TRACE("Enter NtUserGetAncestor\n");
3104 UserEnterExclusive();
3106 if (!(Window
= UserGetWindowObject(hWnd
)))
3111 Ancestor
= UserGetAncestor(Window
, Type
);
3112 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3114 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3117 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3123 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3125 /* combo state struct */
3139 INT fixedOwnerDrawHeight
;
3140 INT droppedWidth
; /* last two are not used unless set */
3141 INT editHeight
; /* explicitly */
3143 } HEADCOMBO
,*LPHEADCOMBO
;
3145 // Window Extra data container.
3146 typedef struct _WND2CBOX
3150 } WND2CBOX
, *PWND2CBOX
;
3152 #define CBF_BUTTONDOWN 0x0002
3158 NtUserGetComboBoxInfo(
3164 BOOL NotSameppi
= FALSE
;
3166 DECLARE_RETURN(BOOL
);
3168 TRACE("Enter NtUserGetComboBoxInfo\n");
3171 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3180 sizeof(COMBOBOXINFO
),
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
,
3391 if (!NT_SUCCESS(Status
))
3393 SetLastNtError(Status
);
3397 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3399 ObDereferenceObject(WinStaObject
);
3404 * NtUserSetShellWindowEx
3406 * This is undocumented function to set global shell window. The global
3407 * shell window has special handling of window position.
3413 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3415 PWINSTATION_OBJECT WinStaObject
;
3416 PWND WndShell
, WndListView
;
3417 DECLARE_RETURN(BOOL
);
3418 USER_REFERENCE_ENTRY Ref
;
3422 TRACE("Enter NtUserSetShellWindowEx\n");
3423 UserEnterExclusive();
3425 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3430 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3435 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3440 if (!NT_SUCCESS(Status
))
3442 SetLastNtError(Status
);
3447 * Test if we are permitted to change the shell window.
3449 if (WinStaObject
->ShellWindow
)
3451 ObDereferenceObject(WinStaObject
);
3456 * Move shell window into background.
3458 if (hwndListView
&& hwndListView
!= hwndShell
)
3461 * Disabled for now to get Explorer working.
3462 * -- Filip, 01/nov/2003
3465 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3468 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3470 ObDereferenceObject(WinStaObject
);
3475 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3477 ObDereferenceObject(WinStaObject
);
3481 UserRefObjectCo(WndShell
, &Ref
);
3482 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3483 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3485 WinStaObject
->ShellWindow
= hwndShell
;
3486 WinStaObject
->ShellListView
= hwndListView
;
3488 ti
= GetW32ThreadInfo();
3491 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3492 ti
->pDeskInfo
->spwndShell
= WndShell
;
3493 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3496 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3498 UserDerefObjectCo(WndShell
);
3500 ObDereferenceObject(WinStaObject
);
3504 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3509 // Fixes wine Win test_window_styles and todo tests...
3510 static BOOL FASTCALL
3511 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3513 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3515 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3522 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3524 PWND Window
, Parent
;
3525 PWINSTATION_OBJECT WindowStation
;
3529 if (!(Window
= UserGetWindowObject(hWnd
)))
3534 if ((INT
)Index
>= 0)
3536 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3538 EngSetLastError(ERROR_INVALID_INDEX
);
3542 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3544 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3546 OldValue = (LONG)IntSetWindowProc( Wnd,
3549 if (!OldValue) return 0;
3552 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3559 OldValue
= (LONG
) Window
->ExStyle
;
3560 Style
.styleOld
= OldValue
;
3561 Style
.styleNew
= NewValue
;
3563 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3566 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3568 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3571 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3572 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3574 /* WS_EX_WINDOWEDGE depends on some other styles */
3575 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3576 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3578 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3580 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3581 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3585 OldValue
= (LONG
) Window
->style
;
3586 Style
.styleOld
= OldValue
;
3587 Style
.styleNew
= NewValue
;
3588 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3590 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3591 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3592 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3593 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3594 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3596 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3598 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3600 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3601 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3602 DceResetActiveDCEs( Window
);
3604 Window
->style
= (DWORD
)Style
.styleNew
;
3605 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3610 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3611 Window
->fnid
& FNID_FREED
)
3613 EngSetLastError(ERROR_ACCESS_DENIED
);
3616 OldValue
= (LONG
)IntSetWindowProc(Window
,
3623 OldValue
= (LONG
) Window
->hModule
;
3624 Window
->hModule
= (HINSTANCE
) NewValue
;
3627 case GWL_HWNDPARENT
:
3628 Parent
= Window
->spwndParent
;
3629 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3630 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3632 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3636 OldValue
= (LONG
) Window
->IDMenu
;
3637 Window
->IDMenu
= (UINT
) NewValue
;
3641 OldValue
= Window
->dwUserData
;
3642 Window
->dwUserData
= NewValue
;
3646 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3647 EngSetLastError(ERROR_INVALID_INDEX
);
3657 * NtUserSetWindowLong
3659 * The NtUserSetWindowLong function changes an attribute of the specified
3660 * window. The function also sets the 32-bit (long) value at the specified
3661 * offset into the extra window memory.
3668 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3670 DECLARE_RETURN(LONG
);
3672 TRACE("Enter NtUserSetWindowLong\n");
3673 UserEnterExclusive();
3675 if (hWnd
== IntGetDesktopWindow())
3677 EngSetLastError(STATUS_ACCESS_DENIED
);
3681 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3684 TRACE("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3690 * NtUserSetWindowWord
3692 * Legacy function similar to NtUserSetWindowLong.
3699 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3703 DECLARE_RETURN(WORD
);
3705 TRACE("Enter NtUserSetWindowWord\n");
3706 UserEnterExclusive();
3708 if (hWnd
== IntGetDesktopWindow())
3710 EngSetLastError(STATUS_ACCESS_DENIED
);
3714 if (!(Window
= UserGetWindowObject(hWnd
)))
3723 case GWL_HWNDPARENT
:
3724 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3728 EngSetLastError(ERROR_INVALID_INDEX
);
3733 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3735 EngSetLastError(ERROR_INVALID_PARAMETER
);
3739 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3740 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3745 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3751 QueryWindow based on KJK::Hyperion and James Tabor.
3753 0 = QWUniqueProcessId
3754 1 = QWUniqueThreadId
3757 4 = QWIsHung Implements IsHungAppWindow found
3760 9 = QWKillWindow When I called this with hWnd ==
3761 DesktopWindow, it shutdown the system
3768 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3770 /* Console Leader Process CID Window offsets */
3771 #define GWLP_CONSOLE_LEADER_PID 0
3772 #define GWLP_CONSOLE_LEADER_TID 4
3776 DECLARE_RETURN(UINT
);
3778 TRACE("Enter NtUserQueryWindow\n");
3781 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3788 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3790 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3791 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3793 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
3794 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
3798 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3803 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3805 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3806 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3808 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
3809 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
3813 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3818 case QUERY_WINDOW_ACTIVE
:
3819 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3822 case QUERY_WINDOW_FOCUS
:
3823 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3826 case QUERY_WINDOW_ISHUNG
:
3827 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
);
3830 case QUERY_WINDOW_REAL_ID
:
3831 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3834 case QUERY_WINDOW_FOREGROUND
:
3835 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3839 Result
= (DWORD
)NULL
;
3846 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
3856 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3858 UNICODE_STRING SafeMessageName
;
3861 DECLARE_RETURN(UINT
);
3863 TRACE("Enter NtUserRegisterWindowMessage\n");
3864 UserEnterExclusive();
3866 if(MessageNameUnsafe
== NULL
)
3868 EngSetLastError(ERROR_INVALID_PARAMETER
);
3872 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3873 if(!NT_SUCCESS(Status
))
3875 SetLastNtError(Status
);
3879 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3880 if (SafeMessageName
.Buffer
)
3881 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3885 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
3902 DECLARE_RETURN(BOOL
);
3904 TRACE("Enter NtUserSetMenu\n");
3905 UserEnterExclusive();
3907 if (!(Window
= UserGetWindowObject(hWnd
)))
3912 if (! IntSetMenu(Window
, Menu
, &Changed
))
3917 if (Changed
&& Repaint
)
3919 USER_REFERENCE_ENTRY Ref
;
3921 UserRefObjectCo(Window
, &Ref
);
3922 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3923 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3925 UserDerefObjectCo(Window
);
3931 TRACE("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3940 NtUserSetWindowFNID(HWND hWnd
,
3944 DECLARE_RETURN(BOOL
);
3946 TRACE("Enter NtUserSetWindowFNID\n");
3947 UserEnterExclusive();
3949 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3954 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3956 EngSetLastError(ERROR_ACCESS_DENIED
);
3960 // From user land we only set these.
3961 if (fnID
!= FNID_DESTROY
)
3962 { // Hacked so we can mark desktop~!
3963 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
3966 EngSetLastError(ERROR_INVALID_PARAMETER
);
3975 TRACE("Leave NtUserSetWindowFNID\n");
3983 * Undocumented function that is called from DefWindowProc to set
3990 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
3993 LARGE_STRING SafeText
;
3994 UNICODE_STRING UnicodeString
;
3997 TRACE("Enter NtUserDefSetText\n");
3999 if (WindowText
!= NULL
)
4003 SafeText
= ProbeForReadLargeString(WindowText
);
4005 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4008 SetLastNtError(_SEH2_GetExceptionCode());
4018 UserEnterExclusive();
4020 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4026 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4027 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4028 // Now we know what the bAnsi is for.
4029 RtlInitUnicodeString(&UnicodeString
, NULL
);
4030 if (SafeText
.Buffer
)
4035 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4037 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4038 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4040 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4043 SetLastNtError(_SEH2_GetExceptionCode());
4046 if (!Ret
) goto Exit
;
4049 if (UnicodeString
.Length
!= 0)
4051 if (Wnd
->strName
.MaximumLength
> 0 &&
4052 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4054 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4056 Wnd
->strName
.Length
= UnicodeString
.Length
;
4057 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4058 RtlCopyMemory(Wnd
->strName
.Buffer
,
4059 UnicodeString
.Buffer
,
4060 UnicodeString
.Length
);
4065 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4066 buf
= Wnd
->strName
.Buffer
;
4067 Wnd
->strName
.Buffer
= NULL
;
4070 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4073 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4074 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4075 if (Wnd
->strName
.Buffer
!= NULL
)
4077 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4078 RtlCopyMemory(Wnd
->strName
.Buffer
,
4079 UnicodeString
.Buffer
,
4080 UnicodeString
.Length
);
4081 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4082 Wnd
->strName
.Length
= UnicodeString
.Length
;
4086 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4094 Wnd
->strName
.Length
= 0;
4095 if (Wnd
->strName
.Buffer
!= NULL
)
4096 Wnd
->strName
.Buffer
[0] = L
'\0';
4099 // FIXME: HAX! Windows does not do this in here!
4100 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4101 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4102 /* Send shell notifications */
4103 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4105 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4110 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4111 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4117 * NtUserInternalGetWindowText
4124 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4129 DECLARE_RETURN(INT
);
4131 TRACE("Enter NtUserInternalGetWindowText\n");
4134 if(lpString
&& (nMaxCount
<= 1))
4136 EngSetLastError(ERROR_INVALID_PARAMETER
);
4140 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4145 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4148 const WCHAR Terminator
= L
'\0';
4150 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4152 Copy
= min(nMaxCount
- 1, Result
);
4155 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4156 if(!NT_SUCCESS(Status
))
4158 SetLastNtError(Status
);
4164 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4165 if(!NT_SUCCESS(Status
))
4167 SetLastNtError(Status
);
4177 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4187 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4193 // ASSERT(OwnerWnd);
4195 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4196 win_array
= IntWinListChildren(OwnerWnd
);
4201 while (win_array
[count
])
4203 while (--count
>= 0)
4205 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4207 if (pWnd
->spwndOwner
!= OwnerWnd
)
4212 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4214 /* In Windows, ShowOwnedPopups(TRUE) generates
4215 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4216 * regardless of the state of the owner
4218 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4224 if (pWnd
->style
& WS_VISIBLE
)
4226 /* In Windows, ShowOwnedPopups(FALSE) generates
4227 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4228 * regardless of the state of the owner
4230 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4236 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4237 TRACE("Leave ShowOwnedPopups\n");