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
);
594 if(Window
->SystemMenu
595 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
597 IntDestroyMenuObject(Menu
, 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 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
870 while (Window
&& ((Window
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
872 if (Window
== Parent
)
877 Window
= Window
->spwndParent
;
884 Link the window into siblings list
885 children and parent are kept in place.
890 PWND WndInsertAfter
/* set to NULL if top sibling */
893 if ((Wnd
->spwndPrev
= WndInsertAfter
))
895 /* link after WndInsertAfter */
896 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
897 Wnd
->spwndNext
->spwndPrev
= Wnd
;
899 Wnd
->spwndPrev
->spwndNext
= Wnd
;
904 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
905 Wnd
->spwndNext
->spwndPrev
= Wnd
;
907 Wnd
->spwndParent
->spwndChild
= Wnd
;
912 Note: Wnd->spwndParent can be null if it is the desktop.
914 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
916 if (hWndPrev
== HWND_NOTOPMOST
)
918 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
919 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
920 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
921 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
924 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
926 if (hWndPrev
== HWND_BOTTOM
)
928 /* Link in the bottom of the list */
931 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
932 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
933 WndInsertAfter
= WndInsertAfter
->spwndNext
;
935 IntLinkWindow(Wnd
, WndInsertAfter
);
936 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
938 else if (hWndPrev
== HWND_TOPMOST
)
940 /* Link in the top of the list */
941 IntLinkWindow(Wnd
, NULL
);
943 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
945 else if (hWndPrev
== HWND_TOP
)
947 /* Link it after the last topmost window */
948 PWND WndInsertBefore
;
950 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
952 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
954 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
956 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
957 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
959 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
962 WndInsertBefore
= WndInsertBefore
->spwndNext
;
966 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
970 /* Link it after hWndPrev */
973 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
974 /* Are we called with an erroneous handle */
975 if(WndInsertAfter
== NULL
)
977 /* Link in a default position */
978 IntLinkHwnd(Wnd
, HWND_TOP
);
982 IntLinkWindow(Wnd
, WndInsertAfter
);
984 /* Fix the WS_EX_TOPMOST flag */
985 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
987 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
991 if(WndInsertAfter
->spwndNext
&&
992 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
994 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
998 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
1002 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
1006 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
1009 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
1010 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1012 //ERR("ProcessOwnerSwap Old out.\n");
1013 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
1019 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
1022 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1024 //ERR("ProcessOwnerSwap New in.\n");
1025 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1029 // FIXME: System Tray checks.
1033 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1035 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1038 Wnd
= IntGetWindowObject(hWnd
);
1042 WndOldOwner
= Wnd
->spwndOwner
;
1044 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1045 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1047 if (!WndNewOwner
&& hWndNewOwner
)
1049 EngSetLastError(ERROR_INVALID_PARAMETER
);
1054 /* if parent belongs to a different thread and the window isn't */
1055 /* top-level, attach the two threads */
1056 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1058 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1062 Wnd
->spwndOwner
= WndNewOwner
;
1066 Wnd
->spwndOwner
= NULL
;
1071 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1072 EngSetLastError(ERROR_INVALID_PARAMETER
);
1076 UserDereferenceObject(Wnd
);
1081 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1083 PWND WndOldParent
, pWndExam
;
1086 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1089 ASSERT(WndNewParent
);
1090 ASSERT_REFS_CO(Wnd
);
1091 ASSERT_REFS_CO(WndNewParent
);
1093 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1095 EngSetLastError(ERROR_ACCESS_DENIED
);
1099 /* Some applications try to set a child as a parent */
1100 if (IntIsChildWindow(Wnd
, WndNewParent
))
1102 TRACE("IntSetParent try to set a child as a parent.\n");
1103 EngSetLastError( ERROR_INVALID_PARAMETER
);
1107 pWndExam
= WndNewParent
; // Load parent Window to examine.
1108 // Now test for set parent to parent hit.
1111 if (Wnd
== pWndExam
)
1113 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1114 EngSetLastError(ERROR_INVALID_PARAMETER
);
1117 pWndExam
= pWndExam
->spwndParent
;
1121 * Windows hides the window first, then shows it again
1122 * including the WM_SHOWWINDOW messages and all
1124 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1126 /* Window must belong to current process */
1127 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1129 ERR("IntSetParent Window must belong to current process!\n");
1133 WndOldParent
= Wnd
->spwndParent
;
1135 if ( WndOldParent
&&
1136 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1137 pt
.x
= Wnd
->rcWindow
.right
;
1139 pt
.x
= Wnd
->rcWindow
.left
;
1140 pt
.y
= Wnd
->rcWindow
.top
;
1142 IntScreenToClient(WndOldParent
, &pt
);
1144 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1146 if (WndNewParent
!= WndOldParent
)
1148 /* Unlink the window from the siblings list */
1149 IntUnlinkWindow(Wnd
);
1150 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1152 /* Set the new parent */
1153 Wnd
->spwndParent
= WndNewParent
;
1155 if ( Wnd
->style
& WS_CHILD
&&
1157 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1159 ERR("SetParent Top Most from Pop up!\n");
1160 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1163 /* Link the window with its new siblings */
1165 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1166 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1170 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1171 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1173 Wnd
->style
|= WS_CLIPSIBLINGS
;
1174 DceResetActiveDCEs(Wnd
);
1177 /* if parent belongs to a different thread and the window isn't */
1178 /* top-level, attach the two threads */
1179 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1181 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1183 if (Wnd
->head
.pti
!= WndOldParent
->head
.pti
)
1185 //ERR("SetParent Old out.\n");
1186 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1189 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1191 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1193 //ERR("SetParent New in.\n");
1194 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1199 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1200 swFlags
|= SWP_NOACTIVATE
;
1202 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1204 * SetParent additionally needs to make hwnd the top window
1205 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1206 * WM_WINDOWPOSCHANGED notification messages.
1208 //ERR("IntSetParent SetWindowPos 1\n");
1209 co_WinPosSetWindowPos( Wnd
,
1210 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1211 pt
.x
, pt
.y
, 0, 0, swFlags
);
1212 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1213 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1215 return WndOldParent
;
1219 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1221 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1222 HWND hWndOldParent
= NULL
;
1223 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1225 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1227 EngSetLastError(ERROR_INVALID_PARAMETER
);
1231 if (hWndChild
== IntGetDesktopWindow())
1233 ERR("UserSetParent Access Denied!\n");
1234 EngSetLastError(ERROR_ACCESS_DENIED
);
1240 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1242 ERR("UserSetParent Bad New Parent!\n");
1248 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1254 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1256 ERR("UserSetParent Bad Child!\n");
1260 UserRefObjectCo(Wnd
, &Ref
);
1261 UserRefObjectCo(WndParent
, &ParentRef
);
1262 //ERR("Enter co_IntSetParent\n");
1263 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1264 //ERR("Leave co_IntSetParent\n");
1265 UserDerefObjectCo(WndParent
);
1266 UserDerefObjectCo(Wnd
);
1270 hWndOldParent
= WndOldParent
->head
.h
;
1271 UserDereferenceObject(WndOldParent
);
1274 return( hWndOldParent
);
1277 /* Unlink the window from siblings. children and parent are kept in place. */
1279 IntUnlinkWindow(PWND Wnd
)
1282 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1285 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1287 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1288 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1290 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1293 /* FUNCTIONS *****************************************************************/
1296 * As best as I can figure, this function is used by EnumWindows,
1297 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1299 * It's supposed to build a list of HWNDs to return to the caller.
1300 * We can figure out what kind of list by what parameters are
1308 NtUserBuildHwndList(
1321 return ERROR_INVALID_PARAMETER
;
1323 if (hwndParent
|| !dwThreadId
)
1326 PWND Parent
, Window
;
1330 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1332 return ERROR_INVALID_HANDLE
;
1337 Status
= IntValidateDesktopHandle(hDesktop
,
1341 if(!NT_SUCCESS(Status
))
1343 return ERROR_INVALID_HANDLE
;
1346 hwndParent
= Desktop
->DesktopWindow
;
1353 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1354 (Window
= Parent
->spwndChild
))
1356 BOOL bGoDown
= TRUE
;
1358 Status
= STATUS_SUCCESS
;
1363 if(dwCount
++ < *pBufSize
&& pWnd
)
1367 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1368 *pWnd
= Window
->head
.h
;
1371 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1373 Status
= _SEH2_GetExceptionCode();
1376 if(!NT_SUCCESS(Status
))
1378 SetLastNtError(Status
);
1382 if (Window
->spwndChild
&& bChildren
)
1384 Window
= Window
->spwndChild
;
1389 if (Window
->spwndNext
)
1391 Window
= Window
->spwndNext
;
1395 Window
= Window
->spwndParent
;
1396 if (Window
== Parent
)
1405 ObDereferenceObject(Desktop
);
1408 else // Build EnumThreadWindows list!
1411 PTHREADINFO W32Thread
;
1412 PLIST_ENTRY Current
;
1415 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1416 if (!NT_SUCCESS(Status
))
1418 ERR("Thread Id is not valid!\n");
1419 return ERROR_INVALID_PARAMETER
;
1421 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1423 ObDereferenceObject(Thread
);
1424 ERR("Thread is not initialized!\n");
1425 return ERROR_INVALID_PARAMETER
;
1428 Current
= W32Thread
->WindowListHead
.Flink
;
1429 while (Current
!= &(W32Thread
->WindowListHead
))
1431 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1434 if (dwCount
< *pBufSize
&& pWnd
)
1438 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1439 *pWnd
= Window
->head
.h
;
1442 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1444 Status
= _SEH2_GetExceptionCode();
1447 if (!NT_SUCCESS(Status
))
1449 ERR("Failure to build window list!\n");
1450 SetLastNtError(Status
);
1455 Current
= Window
->ThreadListEntry
.Flink
;
1458 ObDereferenceObject(Thread
);
1461 *pBufSize
= dwCount
;
1462 return STATUS_SUCCESS
;
1465 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1467 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1468 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1470 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1472 USER_REFERENCE_ENTRY Ref
;
1473 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1474 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1476 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1477 (LPARAM
)pWindow
->head
.h
);
1478 UserDerefObjectCo(pWindow
->spwndParent
);
1484 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1486 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1488 /* default positioning for overlapped windows */
1489 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1492 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1494 pMonitor
= UserGetPrimaryMonitor();
1496 /* Check if we don't have a monitor attached yet */
1497 if(pMonitor
== NULL
)
1505 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1507 if (IS_DEFAULT(Cs
->x
))
1509 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1511 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1513 Cs
->x
= ProcessParams
->StartingX
;
1514 Cs
->y
= ProcessParams
->StartingY
;
1518 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1519 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1520 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1521 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1523 /* reset counter and position */
1526 pMonitor
->cWndStack
= 0;
1528 pMonitor
->cWndStack
++;
1532 if (IS_DEFAULT(Cs
->cx
))
1534 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1536 Cs
->cx
= ProcessParams
->CountX
;
1537 Cs
->cy
= ProcessParams
->CountY
;
1541 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1542 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1545 /* neither x nor cx are default. Check the y values .
1546 * In the trace we see Outlook and Outlook Express using
1547 * cy set to CW_USEDEFAULT when opening the address book.
1549 else if (IS_DEFAULT(Cs
->cy
))
1551 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1552 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1557 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1558 if(IS_DEFAULT(Cs
->x
))
1563 if(IS_DEFAULT(Cs
->cx
))
1573 /* Allocates and initializes a window */
1574 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1575 PLARGE_STRING WindowName
,
1580 PDESKTOP pdeskCreated
)
1584 PTHREADINFO pti
= NULL
;
1586 BOOL bUnicodeWindow
;
1588 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1590 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1591 { // Need both here for wine win.c test_CreateWindow.
1592 //if (Cs->hwndParent && ParentWindow)
1593 if (ParentWindow
) // It breaks more tests..... WIP.
1595 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1596 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1597 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1598 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1602 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1604 * Dialog boxes and message boxes do not inherit layout, so you must
1605 * set the layout explicitly.
1607 if ( Class
->fnid
!= FNID_DIALOG
)
1609 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1611 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1617 /* Automatically add WS_EX_WINDOWEDGE */
1618 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1619 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1620 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1621 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1623 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1625 /* Is it a unicode window? */
1626 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1627 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1629 /* Allocate the new window */
1630 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1631 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1635 sizeof(WND
) + Class
->cbwndExtra
);
1642 TRACE("Created window object with handle %p\n", hWnd
);
1644 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1645 { /* HACK: Helper for win32csr/desktopbg.c */
1646 /* If there is no desktop window yet, we must be creating it */
1647 TRACE("CreateWindow setting desktop.\n");
1648 pdeskCreated
->DesktopWindow
= hWnd
;
1649 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1653 * Fill out the structure describing it.
1655 /* Remember, pWnd->head is setup in object.c ... */
1656 pWnd
->spwndParent
= ParentWindow
;
1657 pWnd
->spwndOwner
= OwnerWindow
;
1659 pWnd
->spwndLastActive
= pWnd
;
1660 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1662 pWnd
->hModule
= Cs
->hInstance
;
1663 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1664 pWnd
->ExStyle
= Cs
->dwExStyle
;
1665 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1666 pWnd
->pActCtx
= acbiBuffer
;
1667 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1668 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1670 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1672 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1673 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1676 pWnd
->head
.pti
->cWindows
++;
1677 #ifdef NEW_CURSORICON
1678 if (Class
->spicn
&& !Class
->spicnSm
)
1680 HICON IconSmHandle
= NULL
;
1681 if((Class
->spicn
->CURSORF_flags
& (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1682 == (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1684 IconSmHandle
= co_IntCopyImage(
1685 UserHMGetHandle(Class
->spicn
),
1687 UserGetSystemMetrics( SM_CXSMICON
),
1688 UserGetSystemMetrics( SM_CYSMICON
),
1689 LR_COPYFROMRESOURCE
| LR_SHARED
);
1693 /* Retry without copying from resource */
1694 IconSmHandle
= co_IntCopyImage(
1695 UserHMGetHandle(Class
->spicn
),
1697 UserGetSystemMetrics( SM_CXSMICON
),
1698 UserGetSystemMetrics( SM_CYSMICON
),
1704 Class
->spicnSm
= UserGetCurIconObject(IconSmHandle
);
1705 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1709 if (Class
->hIcon
&& !Class
->hIconSm
)
1711 Class
->hIconSmIntern
= co_IntCopyImage( Class
->hIcon
, IMAGE_ICON
,
1712 UserGetSystemMetrics( SM_CXSMICON
),
1713 UserGetSystemMetrics( SM_CYSMICON
), 0 );
1714 TRACE("IntCreateWindow hIconSmIntern %p\n",Class
->hIconSmIntern
);
1715 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1719 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1720 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1722 /* BugBoy Comments: Comment below say that System classes are always created
1723 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1724 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1726 No where can I see in code or through testing does the window change back
1727 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1728 see what problems this would cause. */
1730 // Set WndProc from Class.
1731 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1733 // GetWindowProc, test for non server side default classes and set WndProc.
1734 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1738 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1739 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1743 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1744 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1748 // If not an Unicode caller, set Ansi creator bit.
1749 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1751 // Clone Class Ansi/Unicode proc type.
1752 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1754 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1755 pWnd
->Unicode
= FALSE
;
1759 * It seems there can be both an Ansi creator and Unicode Class Window
1760 * WndProc, unless the following overriding conditions occur:
1762 if ( !bUnicodeWindow
&&
1763 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1764 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1765 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1766 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1767 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1768 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1769 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1770 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1771 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1772 { // Override Class and set the window Ansi WndProc.
1773 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1774 pWnd
->Unicode
= FALSE
;
1777 { // Set the window Unicode WndProc.
1778 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1779 pWnd
->Unicode
= TRUE
;
1783 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1784 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1785 Dont understand why it does this. */
1786 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1788 PCALLPROCDATA CallProc
;
1789 CallProc
= CreateCallProc(pWnd
->head
.rpdesk
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1793 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1794 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1798 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1802 InitializeListHead(&pWnd
->PropListHead
);
1803 pWnd
->PropListItems
= 0;
1805 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1807 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1808 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1809 if (pWnd
->strName
.Buffer
== NULL
)
1814 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1815 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1816 pWnd
->strName
.Length
= WindowName
->Length
;
1817 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1820 /* Correct the window style. */
1821 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1823 pWnd
->style
|= WS_CLIPSIBLINGS
;
1824 if (!(pWnd
->style
& WS_POPUP
))
1826 pWnd
->style
|= WS_CAPTION
;
1830 /* WS_EX_WINDOWEDGE depends on some other styles */
1831 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1832 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1833 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1835 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1836 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1837 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1840 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1842 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1843 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1845 /* Set the window menu */
1846 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1850 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1852 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1854 UNICODE_STRING MenuName
;
1857 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1859 MenuName
.Length
= 0;
1860 MenuName
.MaximumLength
= 0;
1861 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1865 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1867 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1868 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1872 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1875 if ( ParentWindow
&&
1876 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1877 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1879 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1881 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1883 EngSetLastError(ERROR_INVALID_PARAMETER
);
1886 if ( pWnd
->spwndOwner
&&
1887 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1889 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1891 if ( pWnd
->spwndOwner
&&
1892 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1893 pti
!= pWnd
->spwndOwner
->head
.pti
)
1895 //ERR("CreateWindow Owner in.\n");
1896 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1900 /* Insert the window into the thread's window list. */
1901 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1903 /* Handle "CS_CLASSDC", it is tested first. */
1904 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1905 { /* One DCE per class to have CLASS. */
1906 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1908 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1909 { /* Allocate a DCE for this window. */
1910 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1916 ERR("IntCreateWindow Allocation Error.\n");
1917 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1920 UserDereferenceObject(pWnd
);
1928 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1929 PUNICODE_STRING ClassName
,
1930 PLARGE_STRING WindowName
,
1934 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1935 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1936 PWINSTATION_OBJECT WinSta
;
1939 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1940 CBT_CREATEWNDW
* pCbtCreate
;
1942 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1944 DWORD dwShowMode
= SW_SHOW
;
1945 CREATESTRUCTW
*pCsw
= NULL
;
1946 PVOID pszClass
= NULL
, pszName
= NULL
;
1949 /* Get the current window station and reference it */
1950 pti
= GetW32ThreadInfo();
1951 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1953 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1954 return NULL
; // There is nothing to cleanup.
1956 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1957 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1962 /* Get the class and reference it */
1963 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
1966 ERR("Failed to find class %wZ\n", ClassName
);
1970 /* Now find the parent and the owner window */
1971 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
1974 if (Cs
->hwndParent
== HWND_MESSAGE
)
1976 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
1978 else if (Cs
->hwndParent
)
1980 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1981 hWndOwner
= Cs
->hwndParent
;
1983 hWndParent
= Cs
->hwndParent
;
1985 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1987 ERR("Cannot create a child window without a parrent!\n");
1988 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1989 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1992 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1993 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1995 /* FIXME: Is this correct? */
1997 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
1999 /* Fix the position and the size of the window */
2002 UserRefObjectCo(ParentWindow
, &ParentRef
);
2003 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2006 /* Allocate and initialize the new window */
2007 Window
= IntCreateWindow(Cs
,
2016 ERR("IntCreateWindow failed!\n");
2020 hWnd
= UserHMGetHandle(Window
);
2021 hwndInsertAfter
= HWND_TOP
;
2023 UserRefObjectCo(Window
, &Ref
);
2024 UserDereferenceObject(Window
);
2025 ObDereferenceObject(WinSta
);
2027 //// Check for a hook to eliminate overhead. ////
2028 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2030 // Allocate the calling structures Justin Case this goes Global.
2031 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2032 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2033 if (!pCsw
|| !pCbtCreate
)
2035 ERR("UserHeapAlloc() failed!\n");
2039 /* Fill the new CREATESTRUCTW */
2040 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2041 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2043 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2044 if (!IS_ATOM(ClassName
->Buffer
))
2046 if (Window
->state
& WNDS_ANSICREATOR
)
2048 ANSI_STRING AnsiString
;
2049 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2050 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2053 ERR("UserHeapAlloc() failed!\n");
2056 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2057 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2058 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2062 UNICODE_STRING UnicodeString
;
2063 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2064 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2067 ERR("UserHeapAlloc() failed!\n");
2070 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2071 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2072 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2074 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2076 if (WindowName
->Length
)
2078 UNICODE_STRING Name
;
2079 Name
.Buffer
= WindowName
->Buffer
;
2080 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2081 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2083 if (Window
->state
& WNDS_ANSICREATOR
)
2085 ANSI_STRING AnsiString
;
2086 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2087 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2090 ERR("UserHeapAlloc() failed!\n");
2093 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2094 AnsiString
.Buffer
= (PCHAR
)pszName
;
2095 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2099 UNICODE_STRING UnicodeString
;
2100 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2101 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2104 ERR("UserHeapAlloc() failed!\n");
2107 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2108 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2109 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2111 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2114 pCbtCreate
->lpcs
= pCsw
;
2115 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2117 //// Call the WH_CBT hook ////
2118 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2121 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2124 // Write back changes.
2129 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2132 /* NCCREATE and WM_NCCALCSIZE need the original values */
2133 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2134 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2136 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2138 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2140 Cs
->x
+= ParentWindow
->rcClient
.left
;
2141 Cs
->y
+= ParentWindow
->rcClient
.top
;
2145 /* Send the WM_GETMINMAXINFO message */
2149 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2151 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2152 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2153 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2154 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2155 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2158 Window
->rcWindow
.left
= Cs
->x
;
2159 Window
->rcWindow
.top
= Cs
->y
;
2160 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2161 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2163 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2165 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2166 RECTL_vOffsetRect(&Window->rcWindow,
2167 ParentWindow->rcClient.left,
2168 ParentWindow->rcClient.top);
2171 /* correct child window coordinates if mirroring on parent is enabled */
2172 if (ParentWindow
!= NULL
)
2174 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2175 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2177 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2178 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2182 Window
->rcClient
= Window
->rcWindow
;
2184 /* Link the window */
2185 if (NULL
!= ParentWindow
)
2187 /* Link the window into the siblings list */
2188 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2189 IntLinkHwnd(Window
, HWND_BOTTOM
);
2191 IntLinkHwnd(Window
, hwndInsertAfter
);
2194 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2196 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2197 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2200 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2202 if ( !IntIsTopLevelWindow(Window
) )
2204 if (pti
!= Window
->spwndParent
->head
.pti
)
2206 //ERR("CreateWindow Parent in.\n");
2207 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2212 /* Send the NCCREATE message */
2213 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2216 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2220 /* Send the WM_NCCALCSIZE message */
2223 MaxPos
.x
= Window
->rcWindow
.left
;
2224 MaxPos
.y
= Window
->rcWindow
.top
;
2226 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2227 //rc = Window->rcWindow;
2228 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2229 //Window->rcClient = rc;
2231 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2232 MaxPos
.y
- Window
->rcWindow
.top
);
2235 /* Send the WM_CREATE message. */
2236 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2237 if (Result
== (LRESULT
)-1)
2239 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2243 /* Send the EVENT_OBJECT_CREATE event */
2244 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2246 /* By setting the flag below it can be examined to determine if the window
2247 was created successfully and a valid pwnd was passed back to caller since
2248 from here the function has to succeed. */
2249 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2251 /* Send the WM_SIZE and WM_MOVE messages. */
2252 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2254 co_WinPosSendSizeMove(Window
);
2257 /* Show or maybe minimize or maximize the window. */
2259 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2260 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2263 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2265 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2266 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2267 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2268 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2269 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2272 /* Send the WM_PARENTNOTIFY message */
2273 IntSendParentNotify(Window
, WM_CREATE
);
2275 /* Notify the shell that a new window was created */
2276 if ((!hWndParent
) && (!hWndOwner
))
2278 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2281 /* Initialize and show the window's scrollbars */
2282 if (Window
->style
& WS_VSCROLL
)
2284 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2286 if (Window
->style
& WS_HSCROLL
)
2288 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2291 /* Show the new window */
2292 if (Cs
->style
& WS_VISIBLE
)
2294 if (Window
->style
& WS_MAXIMIZE
)
2295 dwShowMode
= SW_SHOW
;
2296 else if (Window
->style
& WS_MINIMIZE
)
2297 dwShowMode
= SW_SHOWMINIMIZED
;
2299 co_WinPosShowWindow(Window
, dwShowMode
);
2301 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2303 ASSERT(ParentWindow
);
2306 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2307 /* ShowWindow won't activate child windows */
2308 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2312 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2318 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2319 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2321 co_UserDestroyWindow(Window
);
2323 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2326 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2327 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2328 if (pszName
) UserHeapFree(pszName
);
2329 if (pszClass
) UserHeapFree(pszClass
);
2333 UserDerefObjectCo(Window
);
2335 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2342 ProbeAndCaptureLargeString(
2343 OUT PLARGE_STRING plstrSafe
,
2344 IN PLARGE_STRING plstrUnsafe
)
2346 LARGE_STRING lstrTemp
;
2347 PVOID pvBuffer
= NULL
;
2351 /* Probe and copy the string */
2352 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2353 lstrTemp
= *plstrUnsafe
;
2355 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2358 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2362 if (lstrTemp
.Length
!= 0)
2364 /* Allocate a buffer from paged pool */
2365 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2368 return STATUS_NO_MEMORY
;
2373 /* Probe and copy the buffer */
2374 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2375 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2377 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2379 /* Cleanup and fail */
2380 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2381 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2386 /* Set the output string */
2387 plstrSafe
->Buffer
= pvBuffer
;
2388 plstrSafe
->Length
= lstrTemp
.Length
;
2389 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2391 return STATUS_SUCCESS
;
2395 * \todo Allow passing plstrClassName as ANSI.
2399 NtUserCreateWindowEx(
2401 PLARGE_STRING plstrClassName
,
2402 PLARGE_STRING plstrClsVersion
,
2403 PLARGE_STRING plstrWindowName
,
2411 HINSTANCE hInstance
,
2417 LARGE_STRING lstrWindowName
;
2418 LARGE_STRING lstrClassName
;
2419 UNICODE_STRING ustrClassName
;
2424 lstrWindowName
.Buffer
= NULL
;
2425 lstrClassName
.Buffer
= NULL
;
2427 ASSERT(plstrWindowName
);
2429 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2431 /* check hMenu is valid handle */
2432 if (hMenu
&& !UserGetMenuObject(hMenu
))
2434 ERR("NtUserCreateWindowEx: Got an invalid menu handle!\n");
2435 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
2440 /* Copy the window name to kernel mode */
2441 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2442 if (!NT_SUCCESS(Status
))
2444 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2445 SetLastNtError(Status
);
2449 plstrWindowName
= &lstrWindowName
;
2451 /* Check if the class is an atom */
2452 if (IS_ATOM(plstrClassName
))
2454 /* It is, pass the atom in the UNICODE_STRING */
2455 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2456 ustrClassName
.Length
= 0;
2457 ustrClassName
.MaximumLength
= 0;
2461 /* It's not, capture the class name */
2462 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2463 if (!NT_SUCCESS(Status
))
2465 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2466 /* Set last error, cleanup and return */
2467 SetLastNtError(Status
);
2471 /* We pass it on as a UNICODE_STRING */
2472 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2473 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2474 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2477 /* Fill the CREATESTRUCTW */
2478 /* we will keep here the original parameters */
2480 Cs
.lpCreateParams
= lpParam
;
2481 Cs
.hInstance
= hInstance
;
2483 Cs
.hwndParent
= hWndParent
;
2488 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2489 if (IS_ATOM(plstrClassName
))
2490 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2492 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2493 Cs
.dwExStyle
= dwExStyle
;
2495 UserEnterExclusive();
2497 /* Call the internal function */
2498 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
);
2502 ERR("co_UserCreateWindowEx failed!\n");
2504 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2509 if (lstrWindowName
.Buffer
)
2511 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2513 if (lstrClassName
.Buffer
)
2515 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2522 BOOLEAN
co_UserDestroyWindow(PVOID Object
)
2528 PWND Window
= Object
;
2530 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2532 hWnd
= Window
->head
.h
;
2533 ti
= PsGetCurrentThreadWin32Thread();
2535 TRACE("co_UserDestroyWindow \n");
2537 /* Check for owner thread */
2538 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2540 /* Check if we are destroying the desktop window */
2541 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2543 EngSetLastError(ERROR_ACCESS_DENIED
);
2548 /* If window was created successfully and it is hooked */
2549 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2551 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2553 ERR("Destroy Window WH_CBT Call Hook return!\n");
2558 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2560 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2562 if (Window
->spwndOwner
)
2564 //ERR("DestroyWindow Owner out.\n");
2565 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2570 /* Inform the parent */
2571 if (Window
->style
& WS_CHILD
)
2573 IntSendParentNotify(Window
, WM_DESTROY
);
2576 /* Look whether the focus is within the tree of windows we will
2579 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2581 if (ti
->MessageQueue
->spwndActive
== Window
&& ti
->MessageQueue
== IntGetFocusMessageQueue())
2583 co_WinPosActivateOtherWindow(Window
);
2587 // Adjust last active.
2588 if ((pwndTemp
= Window
->spwndOwner
))
2590 while (pwndTemp
->spwndOwner
)
2591 pwndTemp
= pwndTemp
->spwndOwner
;
2593 if (pwndTemp
->spwndLastActive
== Window
)
2594 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2597 if (Window
->spwndParent
&& IntIsWindow(Window
->head
.h
))
2599 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2601 if (!IntIsTopLevelWindow(Window
))
2603 //ERR("DestroyWindow Parent out.\n");
2604 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2609 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2610 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2611 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2612 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2613 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2614 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2615 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2616 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2619 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2622 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2624 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2626 ERR("Destroying the ShellWindow!\n");
2627 ti
->pDeskInfo
->hShellWindow
= NULL
;
2631 IntEngWindowChanged(Window
, WOC_DELETE
);
2633 if (!IntIsWindow(Window
->head
.h
))
2638 /* Recursively destroy owned windows */
2640 if (! (Window
->style
& WS_CHILD
))
2644 BOOL GotOne
= FALSE
;
2647 PWND Child
, Desktop
;
2649 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2650 UserGetWindowObject(IntGetDesktopWindow());
2651 Children
= IntWinListChildren(Desktop
);
2655 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2657 Child
= UserGetWindowObject(*ChildHandle
);
2660 if (Child
->spwndOwner
!= Window
)
2665 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2667 USER_REFERENCE_ENTRY ChildRef
;
2668 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2669 co_UserDestroyWindow(Child
);
2670 UserDerefObjectCo(Child
); // Temp HACK?
2676 if (Child
->spwndOwner
!= NULL
)
2678 Child
->spwndOwner
= NULL
;
2682 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2691 /* Generate mouse move message for the next window */
2692 msg
.message
= WM_MOUSEMOVE
;
2693 msg
.wParam
= UserGetMouseButtonsState();
2694 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2695 msg
.pt
= gpsi
->ptCursor
;
2696 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2698 if (!IntIsWindow(Window
->head
.h
))
2703 /* Destroy the window storage */
2704 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2714 NtUserDestroyWindow(HWND Wnd
)
2717 DECLARE_RETURN(BOOLEAN
);
2719 USER_REFERENCE_ENTRY Ref
;
2721 TRACE("Enter NtUserDestroyWindow\n");
2722 UserEnterExclusive();
2724 if (!(Window
= UserGetWindowObject(Wnd
)))
2729 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2730 ret
= co_UserDestroyWindow(Window
);
2731 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2736 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2742 static HWND FASTCALL
2743 IntFindWindow(PWND Parent
,
2746 PUNICODE_STRING WindowName
)
2748 BOOL CheckWindowName
;
2751 UNICODE_STRING CurrentWindowName
;
2755 CheckWindowName
= WindowName
->Buffer
!= 0;
2757 if((List
= IntWinListChildren(Parent
)))
2762 /* skip handles before and including ChildAfter */
2763 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2767 /* search children */
2771 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2776 /* Do not send WM_GETTEXT messages in the kernel mode version!
2777 The user mode version however calls GetWindowText() which will
2778 send WM_GETTEXT messages to windows belonging to its processes */
2779 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2781 // FIXME: LARGE_STRING truncated
2782 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2783 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2784 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2785 if(!CheckWindowName
||
2786 (Child
->strName
.Length
< 0xFFFF &&
2787 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2789 Ret
= Child
->head
.h
;
2794 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2802 * Searches a window's children for a window with the specified
2805 * hwndParent = The window whose childs are to be searched.
2807 * HWND_MESSAGE = message-only windows
2809 * hwndChildAfter = Search starts after this child window.
2810 * NULL = start from beginning
2812 * ucClassName = Class name to search for
2813 * Reguired parameter.
2815 * ucWindowName = Window name
2816 * ->Buffer == NULL = don't care
2819 * The HWND of the window if it was found, otherwise NULL
2825 NtUserFindWindowEx(HWND hwndParent
,
2826 HWND hwndChildAfter
,
2827 PUNICODE_STRING ucClassName
,
2828 PUNICODE_STRING ucWindowName
,
2831 PWND Parent
, ChildAfter
;
2832 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2833 HWND Desktop
, Ret
= NULL
;
2834 BOOL DoMessageWnd
= FALSE
;
2835 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2836 DECLARE_RETURN(HWND
);
2838 TRACE("Enter NtUserFindWindowEx\n");
2841 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2845 if (ucClassName
!= NULL
)
2847 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2848 if (ClassName
.Length
!= 0)
2850 ProbeForRead(ClassName
.Buffer
,
2854 else if (!IS_ATOM(ClassName
.Buffer
))
2856 EngSetLastError(ERROR_INVALID_PARAMETER
);
2860 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2867 if (ucWindowName
!= NULL
)
2869 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2870 if (WindowName
.Length
!= 0)
2872 ProbeForRead(WindowName
.Buffer
,
2878 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2880 SetLastNtError(_SEH2_GetExceptionCode());
2881 _SEH2_YIELD(RETURN(NULL
));
2885 if (ucClassName
!= NULL
)
2887 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2888 !IS_ATOM(ClassName
.Buffer
))
2890 EngSetLastError(ERROR_INVALID_PARAMETER
);
2893 else if (ClassAtom
== (RTL_ATOM
)0)
2895 /* LastError code was set by IntGetAtomFromStringOrAtom */
2901 Desktop
= IntGetCurrentThreadDesktopWindow();
2903 if(hwndParent
== NULL
)
2905 hwndParent
= Desktop
;
2906 DoMessageWnd
= TRUE
;
2908 else if(hwndParent
== HWND_MESSAGE
)
2910 hwndParent
= IntGetMessageWindow();
2913 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2919 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2926 if(Parent
->head
.h
== Desktop
)
2929 PWND TopLevelWindow
;
2930 BOOLEAN CheckWindowName
;
2931 BOOLEAN WindowMatches
;
2932 BOOLEAN ClassMatches
;
2934 /* windows searches through all top-level windows if the parent is the desktop
2937 if((List
= IntWinListChildren(Parent
)))
2943 /* skip handles before and including ChildAfter */
2944 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2948 CheckWindowName
= WindowName
.Buffer
!= 0;
2950 /* search children */
2953 UNICODE_STRING ustr
;
2955 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2960 /* Do not send WM_GETTEXT messages in the kernel mode version!
2961 The user mode version however calls GetWindowText() which will
2962 send WM_GETTEXT messages to windows belonging to its processes */
2963 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2964 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
2965 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
2966 WindowMatches
= !CheckWindowName
||
2967 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2968 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2969 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2970 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2972 if (WindowMatches
&& ClassMatches
)
2974 Ret
= TopLevelWindow
->head
.h
;
2978 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2980 /* window returns the handle of the top-level window, in case it found
2982 Ret
= TopLevelWindow
->head
.h
;
2987 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2992 ERR("FindWindowEx: Not Desktop Parent!\n");
2993 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2996 if (Ret
== NULL
&& DoMessageWnd
)
3000 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3002 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3006 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3008 SetLastNtError(_SEH2_GetExceptionCode());
3016 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3025 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3027 PWND WndAncestor
, Parent
;
3029 if (Wnd
->head
.h
== IntGetDesktopWindow())
3038 WndAncestor
= Wnd
->spwndParent
;
3049 if(!(Parent
= WndAncestor
->spwndParent
))
3053 if(IntIsDesktopWindow(Parent
))
3058 WndAncestor
= Parent
;
3069 Parent
= IntGetParent(WndAncestor
);
3076 WndAncestor
= Parent
;
3094 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3096 PWND Window
, Ancestor
;
3097 DECLARE_RETURN(HWND
);
3099 TRACE("Enter NtUserGetAncestor\n");
3100 UserEnterExclusive();
3102 if (!(Window
= UserGetWindowObject(hWnd
)))
3107 Ancestor
= UserGetAncestor(Window
, Type
);
3108 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3110 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3113 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3119 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3121 /* combo state struct */
3135 INT fixedOwnerDrawHeight
;
3136 INT droppedWidth
; /* last two are not used unless set */
3137 INT editHeight
; /* explicitly */
3139 } HEADCOMBO
,*LPHEADCOMBO
;
3141 // Window Extra data container.
3142 typedef struct _WND2CBOX
3146 } WND2CBOX
, *PWND2CBOX
;
3148 #define CBF_BUTTONDOWN 0x0002
3154 NtUserGetComboBoxInfo(
3160 BOOL NotSameppi
= FALSE
;
3162 DECLARE_RETURN(BOOL
);
3164 TRACE("Enter NtUserGetComboBoxInfo\n");
3167 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3176 sizeof(COMBOBOXINFO
),
3180 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3182 SetLastNtError(_SEH2_GetExceptionCode());
3183 _SEH2_YIELD(RETURN(FALSE
));
3187 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3189 EngSetLastError(ERROR_INVALID_PARAMETER
);
3193 // Pass the user pointer, it was already probed.
3194 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3196 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3199 ppi
= PsGetCurrentProcessWin32Process();
3200 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3203 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3208 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3209 pcbi
->rcItem
= lphc
->textRect
;
3210 pcbi
->rcButton
= lphc
->buttonRect
;
3211 pcbi
->stateButton
= 0;
3212 if (lphc
->wState
& CBF_BUTTONDOWN
)
3213 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3214 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3215 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3216 pcbi
->hwndCombo
= lphc
->self
;
3217 pcbi
->hwndItem
= lphc
->hWndEdit
;
3218 pcbi
->hwndList
= lphc
->hWndLBox
;
3220 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3223 SetLastNtError(_SEH2_GetExceptionCode());
3230 if (NotSameppi
) KeDetachProcess();
3231 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3237 //// ReactOS work around! Keep it the sames as in Listbox.c
3239 /* Listbox structure */
3242 HWND self
; /* Our own window handle */
3243 HWND owner
; /* Owner window to send notifications to */
3244 UINT style
; /* Window style */
3245 INT width
; /* Window width */
3246 INT height
; /* Window height */
3247 VOID
*items
; /* Array of items */
3248 INT nb_items
; /* Number of items */
3249 INT top_item
; /* Top visible item */
3250 INT selected_item
; /* Selected item */
3251 INT focus_item
; /* Item that has the focus */
3252 INT anchor_item
; /* Anchor item for extended selection */
3253 INT item_height
; /* Default item height */
3254 INT page_size
; /* Items per listbox page */
3255 INT column_width
; /* Column width for multi-column listboxes */
3258 // Window Extra data container.
3259 typedef struct _WND2LB
3269 NtUserGetListBoxInfo(
3274 BOOL NotSameppi
= FALSE
;
3276 DECLARE_RETURN(DWORD
);
3278 TRACE("Enter NtUserGetListBoxInfo\n");
3281 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3286 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3288 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3291 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3292 ppi
= PsGetCurrentProcessWin32Process();
3293 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3296 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3301 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3302 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3303 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3304 Ret
= descr
->page_size
* descr
->column_width
;
3306 Ret
= descr
->page_size
;
3308 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3311 SetLastNtError(_SEH2_GetExceptionCode());
3318 if (NotSameppi
) KeDetachProcess();
3319 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3327 * The NtUserSetParent function changes the parent window of the specified
3331 * The new parent window and the child window must belong to the same
3332 * application. If the window identified by the hWndChild parameter is
3333 * visible, the system performs the appropriate redrawing and repainting.
3334 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3335 * or WS_POPUP window styles of the window whose parent is being changed.
3342 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3344 DECLARE_RETURN(HWND
);
3346 TRACE("Enter NtUserSetParent\n");
3347 UserEnterExclusive();
3350 Check Parent first from user space, set it here.
3354 hWndNewParent
= IntGetDesktopWindow();
3356 else if (hWndNewParent
== HWND_MESSAGE
)
3358 hWndNewParent
= IntGetMessageWindow();
3361 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3364 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3370 * UserGetShellWindow
3372 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3377 HWND FASTCALL
UserGetShellWindow(VOID
)
3379 PWINSTATION_OBJECT WinStaObject
;
3382 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3387 if (!NT_SUCCESS(Status
))
3389 SetLastNtError(Status
);
3393 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3395 ObDereferenceObject(WinStaObject
);
3400 * NtUserSetShellWindowEx
3402 * This is undocumented function to set global shell window. The global
3403 * shell window has special handling of window position.
3409 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3411 PWINSTATION_OBJECT WinStaObject
;
3412 PWND WndShell
, WndListView
;
3413 DECLARE_RETURN(BOOL
);
3414 USER_REFERENCE_ENTRY Ref
;
3418 TRACE("Enter NtUserSetShellWindowEx\n");
3419 UserEnterExclusive();
3421 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3426 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3431 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3436 if (!NT_SUCCESS(Status
))
3438 SetLastNtError(Status
);
3443 * Test if we are permitted to change the shell window.
3445 if (WinStaObject
->ShellWindow
)
3447 ObDereferenceObject(WinStaObject
);
3452 * Move shell window into background.
3454 if (hwndListView
&& hwndListView
!= hwndShell
)
3457 * Disabled for now to get Explorer working.
3458 * -- Filip, 01/nov/2003
3461 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3464 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3466 ObDereferenceObject(WinStaObject
);
3471 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3473 ObDereferenceObject(WinStaObject
);
3477 UserRefObjectCo(WndShell
, &Ref
);
3478 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3479 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3481 WinStaObject
->ShellWindow
= hwndShell
;
3482 WinStaObject
->ShellListView
= hwndListView
;
3484 ti
= GetW32ThreadInfo();
3487 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3488 ti
->pDeskInfo
->spwndShell
= WndShell
;
3489 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3492 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3494 UserDerefObjectCo(WndShell
);
3496 ObDereferenceObject(WinStaObject
);
3500 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3505 // Fixes wine Win test_window_styles and todo tests...
3506 static BOOL FASTCALL
3507 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3509 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3511 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3518 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3520 PWND Window
, Parent
;
3521 PWINSTATION_OBJECT WindowStation
;
3525 if (!(Window
= UserGetWindowObject(hWnd
)))
3530 if ((INT
)Index
>= 0)
3532 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3534 EngSetLastError(ERROR_INVALID_INDEX
);
3538 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3540 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3542 OldValue = (LONG)IntSetWindowProc( Wnd,
3545 if (!OldValue) return 0;
3548 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3555 OldValue
= (LONG
) Window
->ExStyle
;
3556 Style
.styleOld
= OldValue
;
3557 Style
.styleNew
= NewValue
;
3559 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3562 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3564 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3567 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3568 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3570 /* WS_EX_WINDOWEDGE depends on some other styles */
3571 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3572 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3574 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3576 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3577 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3581 OldValue
= (LONG
) Window
->style
;
3582 Style
.styleOld
= OldValue
;
3583 Style
.styleNew
= NewValue
;
3584 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3586 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3587 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3588 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3589 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3590 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3592 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3594 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3596 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3597 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3598 DceResetActiveDCEs( Window
);
3600 Window
->style
= (DWORD
)Style
.styleNew
;
3601 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3606 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3607 Window
->fnid
& FNID_FREED
)
3609 EngSetLastError(ERROR_ACCESS_DENIED
);
3612 OldValue
= (LONG
)IntSetWindowProc(Window
,
3619 OldValue
= (LONG
) Window
->hModule
;
3620 Window
->hModule
= (HINSTANCE
) NewValue
;
3623 case GWL_HWNDPARENT
:
3624 Parent
= Window
->spwndParent
;
3625 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3626 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3628 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3632 OldValue
= (LONG
) Window
->IDMenu
;
3633 Window
->IDMenu
= (UINT
) NewValue
;
3637 OldValue
= Window
->dwUserData
;
3638 Window
->dwUserData
= NewValue
;
3642 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3643 EngSetLastError(ERROR_INVALID_INDEX
);
3653 * NtUserSetWindowLong
3655 * The NtUserSetWindowLong function changes an attribute of the specified
3656 * window. The function also sets the 32-bit (long) value at the specified
3657 * offset into the extra window memory.
3664 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3666 DECLARE_RETURN(LONG
);
3668 TRACE("Enter NtUserSetWindowLong\n");
3669 UserEnterExclusive();
3671 if (hWnd
== IntGetDesktopWindow())
3673 EngSetLastError(STATUS_ACCESS_DENIED
);
3677 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3680 TRACE("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3686 * NtUserSetWindowWord
3688 * Legacy function similar to NtUserSetWindowLong.
3695 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3699 DECLARE_RETURN(WORD
);
3701 TRACE("Enter NtUserSetWindowWord\n");
3702 UserEnterExclusive();
3704 if (hWnd
== IntGetDesktopWindow())
3706 EngSetLastError(STATUS_ACCESS_DENIED
);
3710 if (!(Window
= UserGetWindowObject(hWnd
)))
3719 case GWL_HWNDPARENT
:
3720 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3724 EngSetLastError(ERROR_INVALID_INDEX
);
3729 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3731 EngSetLastError(ERROR_INVALID_PARAMETER
);
3735 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3736 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3741 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3747 QueryWindow based on KJK::Hyperion and James Tabor.
3749 0 = QWUniqueProcessId
3750 1 = QWUniqueThreadId
3753 4 = QWIsHung Implements IsHungAppWindow found
3756 9 = QWKillWindow When I called this with hWnd ==
3757 DesktopWindow, it shutdown the system
3764 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3766 /* Console Leader Process CID Window offsets */
3767 #define GWLP_CONSOLE_LEADER_PID 0
3768 #define GWLP_CONSOLE_LEADER_TID 4
3772 DECLARE_RETURN(UINT
);
3774 TRACE("Enter NtUserQueryWindow\n");
3777 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3784 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3786 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3787 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3789 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
3790 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
3794 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3799 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3801 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3802 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3804 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
3805 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
3809 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3814 case QUERY_WINDOW_ACTIVE
:
3815 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3818 case QUERY_WINDOW_FOCUS
:
3819 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3822 case QUERY_WINDOW_ISHUNG
:
3823 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
);
3826 case QUERY_WINDOW_REAL_ID
:
3827 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3830 case QUERY_WINDOW_FOREGROUND
:
3831 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3835 Result
= (DWORD
)NULL
;
3842 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
3852 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3854 UNICODE_STRING SafeMessageName
;
3857 DECLARE_RETURN(UINT
);
3859 TRACE("Enter NtUserRegisterWindowMessage\n");
3860 UserEnterExclusive();
3862 if(MessageNameUnsafe
== NULL
)
3864 EngSetLastError(ERROR_INVALID_PARAMETER
);
3868 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3869 if(!NT_SUCCESS(Status
))
3871 SetLastNtError(Status
);
3875 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3876 if (SafeMessageName
.Buffer
)
3877 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3881 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
3898 DECLARE_RETURN(BOOL
);
3900 TRACE("Enter NtUserSetMenu\n");
3901 UserEnterExclusive();
3903 if (!(Window
= UserGetWindowObject(hWnd
)))
3908 if (! IntSetMenu(Window
, Menu
, &Changed
))
3913 if (Changed
&& Repaint
)
3915 USER_REFERENCE_ENTRY Ref
;
3917 UserRefObjectCo(Window
, &Ref
);
3918 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3919 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3921 UserDerefObjectCo(Window
);
3927 TRACE("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3936 NtUserSetWindowFNID(HWND hWnd
,
3940 DECLARE_RETURN(BOOL
);
3942 TRACE("Enter NtUserSetWindowFNID\n");
3943 UserEnterExclusive();
3945 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3950 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3952 EngSetLastError(ERROR_ACCESS_DENIED
);
3956 // From user land we only set these.
3957 if (fnID
!= FNID_DESTROY
)
3958 { // Hacked so we can mark desktop~!
3959 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
3962 EngSetLastError(ERROR_INVALID_PARAMETER
);
3971 TRACE("Leave NtUserSetWindowFNID\n");
3979 * Undocumented function that is called from DefWindowProc to set
3986 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
3989 LARGE_STRING SafeText
;
3990 UNICODE_STRING UnicodeString
;
3993 TRACE("Enter NtUserDefSetText\n");
3995 if (WindowText
!= NULL
)
3999 SafeText
= ProbeForReadLargeString(WindowText
);
4001 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4004 SetLastNtError(_SEH2_GetExceptionCode());
4014 UserEnterExclusive();
4016 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4022 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4023 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4024 // Now we know what the bAnsi is for.
4025 RtlInitUnicodeString(&UnicodeString
, NULL
);
4026 if (SafeText
.Buffer
)
4031 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4033 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4034 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4036 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4039 SetLastNtError(_SEH2_GetExceptionCode());
4042 if (!Ret
) goto Exit
;
4045 if (UnicodeString
.Length
!= 0)
4047 if (Wnd
->strName
.MaximumLength
> 0 &&
4048 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4050 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4052 Wnd
->strName
.Length
= UnicodeString
.Length
;
4053 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4054 RtlCopyMemory(Wnd
->strName
.Buffer
,
4055 UnicodeString
.Buffer
,
4056 UnicodeString
.Length
);
4061 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4062 buf
= Wnd
->strName
.Buffer
;
4063 Wnd
->strName
.Buffer
= NULL
;
4066 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4069 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4070 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4071 if (Wnd
->strName
.Buffer
!= NULL
)
4073 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4074 RtlCopyMemory(Wnd
->strName
.Buffer
,
4075 UnicodeString
.Buffer
,
4076 UnicodeString
.Length
);
4077 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4078 Wnd
->strName
.Length
= UnicodeString
.Length
;
4082 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4090 Wnd
->strName
.Length
= 0;
4091 if (Wnd
->strName
.Buffer
!= NULL
)
4092 Wnd
->strName
.Buffer
[0] = L
'\0';
4095 // FIXME: HAX! Windows does not do this in here!
4096 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4097 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4098 /* Send shell notifications */
4099 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4101 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4106 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4107 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4113 * NtUserInternalGetWindowText
4120 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4125 DECLARE_RETURN(INT
);
4127 TRACE("Enter NtUserInternalGetWindowText\n");
4130 if(lpString
&& (nMaxCount
<= 1))
4132 EngSetLastError(ERROR_INVALID_PARAMETER
);
4136 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4141 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4144 const WCHAR Terminator
= L
'\0';
4146 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4148 Copy
= min(nMaxCount
- 1, Result
);
4151 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4152 if(!NT_SUCCESS(Status
))
4154 SetLastNtError(Status
);
4160 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4161 if(!NT_SUCCESS(Status
))
4163 SetLastNtError(Status
);
4173 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4183 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4189 // ASSERT(OwnerWnd);
4191 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4192 win_array
= IntWinListChildren(OwnerWnd
);
4197 while (win_array
[count
])
4199 while (--count
>= 0)
4201 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4203 if (pWnd
->spwndOwner
!= OwnerWnd
)
4208 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4210 /* In Windows, ShowOwnedPopups(TRUE) generates
4211 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4212 * regardless of the state of the owner
4214 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4220 if (pWnd
->style
& WS_VISIBLE
)
4222 /* In Windows, ShowOwnedPopups(FALSE) generates
4223 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4224 * regardless of the state of the owner
4226 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4232 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4233 TRACE("Leave ShowOwnedPopups\n");