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
)
282 while(pWnd
&& ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
))
283 pWnd
= pWnd
->spwndParent
;
289 IntIsTopLevelWindow(PWND pWnd
)
291 if ( pWnd
->spwndParent
&&
292 pWnd
->spwndParent
== co_GetDesktopWindow(pWnd
) ) return TRUE
;
297 IntValidateOwnerDepth(PWND Wnd
, PWND Owner
)
302 if ( !Owner
) return gNestedWindowLimit
>= Depth
;
303 if (Owner
== Wnd
) break;
304 Owner
= Owner
->spwndOwner
;
310 /***********************************************************************
313 static void IntSendDestroyMsg(HWND hWnd
)
321 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
323 if (hWnd
== info
.hwndCaret
)
330 Window
= UserGetWindowObject(hWnd
);
333 // USER_REFERENCE_ENTRY Ref;
334 // UserRefObjectCo(Window, &Ref);
336 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
338 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
341 // UserDerefObjectCo(Window);
344 /* The window could already be destroyed here */
347 * Send the WM_DESTROY to the window.
350 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
353 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
354 * make sure that the window still exists when we come back.
363 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
366 /* start from the end (FIXME: is this needed?) */
367 for (i
= 0; pWndArray
[i
]; i
++)
372 if (IsWindow( pWndArray
[i
] ))
373 WIN_SendDestroyMsg( pWndArray
[i
] );
375 HeapFree(GetProcessHeap(), 0, pWndArray
);
379 TRACE("destroyed itself while in WM_DESTROY!\n");
385 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
387 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
391 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
393 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
394 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
397 if (Wnd
->strName
.Buffer
!= NULL
)
399 Wnd
->strName
.Length
= 0;
400 Wnd
->strName
.MaximumLength
= 0;
401 DesktopHeapFree(Wnd
->head
.rpdesk
,
402 Wnd
->strName
.Buffer
);
403 Wnd
->strName
.Buffer
= NULL
;
406 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
407 // WindowObject->Wnd = NULL;
410 /***********************************************************************
413 * Destroy storage associated to a window. "Internals" p.358
415 * This is the "functional" DestroyWindows function ei. all stuff
416 * done in CreateWindow is undone here and not in DestroyWindow:-P
419 static LRESULT
co_UserFreeWindow(PWND Window
,
420 PPROCESSINFO ProcessData
,
421 PTHREADINFO ThreadData
,
422 BOOLEAN SendMessages
)
428 BOOLEAN BelongsToThreadData
;
432 if(Window
->state2
& WNDS2_INDESTROY
)
434 TRACE("Tried to call IntDestroyWindow() twice\n");
437 Window
->state2
|= WNDS2_INDESTROY
;
438 Window
->style
&= ~WS_VISIBLE
;
439 Window
->head
.pti
->cVisWindows
--;
441 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
443 /* remove the window already at this point from the thread window list so we
444 don't get into trouble when destroying the thread windows while we're still
445 in IntDestroyWindow() */
446 RemoveEntryList(&Window
->ThreadListEntry
);
448 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
450 IntDeRegisterShellHookWindow(Window
->head
.h
);
454 /* Send destroy messages */
455 IntSendDestroyMsg(Window
->head
.h
);
458 /* free child windows */
459 Children
= IntWinListChildren(Window
);
462 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
464 if ((Child
= IntGetWindowObject(*ChildHandle
)))
466 if(!IntWndBelongsToThread(Child
, ThreadData
))
468 /* send WM_DESTROY messages to windows not belonging to the same thread */
469 IntSendDestroyMsg(Child
->head
.h
);
472 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
474 UserDereferenceObject(Child
);
477 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
483 * Clear the update region to make sure no WM_PAINT messages will be
484 * generated for this window while processing the WM_NCDESTROY.
486 co_UserRedrawWindow(Window
, NULL
, 0,
487 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
488 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
489 if(BelongsToThreadData
)
490 co_IntSendMessage(Window
->head
.h
, WM_NCDESTROY
, 0, 0);
493 DestroyTimersForWindow(ThreadData
, Window
);
495 /* Unregister hot keys */
496 UnregisterWindowHotKeys (Window
);
498 /* flush the message queue */
499 MsqRemoveWindowMessagesFromQueue(Window
);
501 /* from now on no messages can be sent to this window anymore */
502 Window
->state
|= WNDS_DESTROYED
;
503 Window
->fnid
|= FNID_FREED
;
505 /* don't remove the WINDOWSTATUS_DESTROYING bit */
507 /* reset shell window handles */
508 if(ThreadData
->rpdesk
)
510 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
511 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
513 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
514 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
517 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
521 WinPosCheckInternalPos(Window
->head
.h
);
522 if (Window
->head
.h
== GetCapture())
527 /* free resources associated with the window */
528 TIMER_RemoveWindowTimers(Window
->head
.h
);
531 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
533 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
535 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
539 if(Window
->SystemMenu
540 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
542 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
543 Window
->SystemMenu
= (HMENU
)0;
546 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
549 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
550 CLASS_RemoveWindow(Window
->Class
);
553 IntUnlinkWindow(Window
);
555 if (Window
->PropListItems
)
557 IntRemoveWindowProp(Window
);
558 TRACE("Window->PropListItems %d\n",Window
->PropListItems
);
559 ASSERT(Window
->PropListItems
==0);
562 UserReferenceObject(Window
);
563 UserDeleteObject(Window
->head
.h
, TYPE_WINDOW
);
565 IntDestroyScrollBars(Window
);
567 /* dereference the class */
568 IntDereferenceClass(Window
->pcls
,
569 Window
->head
.pti
->pDeskInfo
,
570 Window
->head
.pti
->ppi
);
575 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
576 GreDeleteObject(Window
->hrgnClip
);
577 Window
->hrgnClip
= NULL
;
579 Window
->head
.pti
->cWindows
--;
581 // ASSERT(Window != NULL);
582 UserFreeWindowInfo(Window
->head
.pti
, Window
);
584 UserDereferenceObject(Window
);
586 UserClipboardFreeWindow(Window
);
592 // Same as User32:IntGetWndProc.
595 IntGetWindowProc(PWND pWnd
,
600 WNDPROC gcpd
, Ret
= 0;
602 ASSERT(UserIsEnteredExclusive() == TRUE
);
606 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
608 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
610 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
613 Ret
= GETPFNCLIENTA(i
);
615 Ret
= GETPFNCLIENTW(i
);
621 if (Class
->fnid
== FNID_EDIT
)
622 Ret
= pWnd
->lpfnWndProc
;
625 Ret
= pWnd
->lpfnWndProc
;
627 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
631 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
632 Ret
= GETPFNCLIENTA(Class
->fnid
);
636 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
637 Ret
= GETPFNCLIENTW(Class
->fnid
);
640 if ( Ret
!= pWnd
->lpfnWndProc
)
643 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
646 gcpd
= (WNDPROC
)UserGetCPD(
648 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
651 return (gcpd
? gcpd
: Ret
);
655 IntSetWindowProc(PWND pWnd
,
660 PCALLPROCDATA CallProc
;
662 WNDPROC Ret
, chWndProc
= NULL
;
664 // Retrieve previous window proc.
665 Ret
= IntGetWindowProc(pWnd
, Ansi
);
669 if (IsCallProcHandle(NewWndProc
))
671 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
673 { // Reset new WndProc.
674 NewWndProc
= CallProc
->pfnClientPrevious
;
675 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
676 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
679 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
680 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
682 if (GETPFNCLIENTW(i
) == NewWndProc
)
684 chWndProc
= GETPFNSERVER(i
);
687 if (GETPFNCLIENTA(i
) == NewWndProc
)
689 chWndProc
= GETPFNSERVER(i
);
693 // If match, set/reset to Server Side and clear ansi.
696 pWnd
->lpfnWndProc
= chWndProc
;
697 pWnd
->Unicode
= TRUE
;
698 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
699 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
703 pWnd
->Unicode
= !Ansi
;
704 // Handle the state change in here.
706 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
708 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
710 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
711 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
713 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
715 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
719 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
720 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
724 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
725 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
728 // Now set the new window proc.
729 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
740 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
742 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
744 ERR("SetMenu: Invalid handle 0x%p!\n",UserHMGetHandle(Wnd
));
745 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
749 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
757 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
758 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Wnd
->head
.h
);
767 NewMenu
= IntGetMenuObject(Menu
);
772 IntReleaseMenuObject(OldMenu
);
774 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
777 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
779 /* Can't use the same menu for two windows */
782 IntReleaseMenuObject(OldMenu
);
784 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
790 Wnd
->IDMenu
= (UINT
) Menu
;
793 NewMenu
->MenuInfo
.Wnd
= Wnd
->head
.h
;
794 IntReleaseMenuObject(NewMenu
);
798 OldMenu
->MenuInfo
.Wnd
= NULL
;
799 IntReleaseMenuObject(OldMenu
);
806 /* INTERNAL ******************************************************************/
810 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
815 USER_REFERENCE_ENTRY Ref
;
816 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
818 while (!IsListEmpty(&WThread
->WindowListHead
))
820 Current
= WThread
->WindowListHead
.Flink
;
821 Wnd
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
823 TRACE("thread cleanup: while destroy wnds, wnd=%p\n", Wnd
);
825 /* Window removes itself from the list */
828 * FIXME: It is critical that the window removes itself! If now, we will loop
832 //ASSERT(co_UserDestroyWindow(Wnd));
834 UserRefObjectCo(Wnd
, &Ref
); // FIXME: Temp HACK??
835 if (!co_UserDestroyWindow(Wnd
))
837 ERR("Unable to destroy window %p at thread cleanup... This is _VERY_ bad!\n", Wnd
);
839 UserDerefObjectCo(Wnd
); // FIXME: Temp HACK??
843 PMENU_OBJECT FASTCALL
844 IntGetSystemMenu(PWND Window
, BOOL bRevert
, BOOL RetMenu
)
846 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
847 PTHREADINFO W32Thread
;
848 HMENU hNewMenu
, hSysMenu
;
849 ROSMENUITEMINFO ItemInfo
;
853 W32Thread
= PsGetCurrentThreadWin32Thread();
855 if(!W32Thread
->rpdesk
)
858 if(Window
->SystemMenu
)
860 Menu
= UserGetMenuObject(Window
->SystemMenu
);
863 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
864 Window
->SystemMenu
= (HMENU
)0;
868 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
870 /* Clone system menu */
871 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
875 NewMenu
= IntCloneMenu(Menu
);
878 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
879 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
880 NewMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
882 //IntReleaseMenuObject(NewMenu);
887 hSysMenu
= UserCreateMenu(FALSE
);
888 if (NULL
== hSysMenu
)
892 SysMenu
= IntGetMenuObject(hSysMenu
);
895 UserDestroyMenu(hSysMenu
);
898 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
899 SysMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
900 hNewMenu
= co_IntLoadSysMenuTemplate();
903 IntReleaseMenuObject(SysMenu
);
904 UserDestroyMenu(hSysMenu
);
907 Menu
= IntGetMenuObject(hNewMenu
);
910 IntReleaseMenuObject(SysMenu
);
911 UserDestroyMenu(hSysMenu
);
915 NewMenu
= IntCloneMenu(Menu
);
918 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
919 IntReleaseMenuObject(NewMenu
);
920 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
922 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
923 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
924 ItemInfo
.fType
= MF_POPUP
;
925 ItemInfo
.fState
= MFS_ENABLED
;
926 ItemInfo
.dwTypeData
= NULL
;
928 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
929 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
931 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
935 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
944 if(Window
->SystemMenu
)
945 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
953 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
958 while (Window
&& ((Window
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
960 if (Window
== Parent
)
965 Window
= Window
->spwndParent
;
972 Link the window into siblings list
973 children and parent are kept in place.
978 PWND WndInsertAfter
/* set to NULL if top sibling */
981 if ((Wnd
->spwndPrev
= WndInsertAfter
))
983 /* link after WndInsertAfter */
984 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
985 Wnd
->spwndNext
->spwndPrev
= Wnd
;
987 Wnd
->spwndPrev
->spwndNext
= Wnd
;
992 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
993 Wnd
->spwndNext
->spwndPrev
= Wnd
;
995 Wnd
->spwndParent
->spwndChild
= Wnd
;
1000 Note: Wnd->spwndParent can be null if it is the desktop.
1002 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
1004 if (hWndPrev
== HWND_NOTOPMOST
)
1006 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1007 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
1008 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1009 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
1012 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
1014 if (hWndPrev
== HWND_BOTTOM
)
1016 /* Link in the bottom of the list */
1017 PWND WndInsertAfter
;
1019 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
1020 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
1021 WndInsertAfter
= WndInsertAfter
->spwndNext
;
1023 IntLinkWindow(Wnd
, WndInsertAfter
);
1024 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1026 else if (hWndPrev
== HWND_TOPMOST
)
1028 /* Link in the top of the list */
1029 IntLinkWindow(Wnd
, NULL
);
1031 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1033 else if (hWndPrev
== HWND_TOP
)
1035 /* Link it after the last topmost window */
1036 PWND WndInsertBefore
;
1038 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
1040 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
1042 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
1044 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
1045 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
1047 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1050 WndInsertBefore
= WndInsertBefore
->spwndNext
;
1054 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
1058 /* Link it after hWndPrev */
1059 PWND WndInsertAfter
;
1061 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1062 /* Are we called with an erroneous handle */
1063 if(WndInsertAfter
== NULL
)
1065 /* Link in a default position */
1066 IntLinkHwnd(Wnd
, HWND_TOP
);
1070 IntLinkWindow(Wnd
, WndInsertAfter
);
1072 /* Fix the WS_EX_TOPMOST flag */
1073 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1075 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1079 if(WndInsertAfter
->spwndNext
&&
1080 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1082 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1086 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
1090 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
1094 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
1097 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
1098 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1100 //ERR("ProcessOwnerSwap Old out.\n");
1101 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
1107 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
1110 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1112 //ERR("ProcessOwnerSwap New in.\n");
1113 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1117 // FIXME: System Tray checks.
1121 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1123 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1126 Wnd
= IntGetWindowObject(hWnd
);
1130 WndOldOwner
= Wnd
->spwndOwner
;
1132 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1133 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1135 if (!WndNewOwner
&& hWndNewOwner
)
1137 EngSetLastError(ERROR_INVALID_PARAMETER
);
1142 /* if parent belongs to a different thread and the window isn't */
1143 /* top-level, attach the two threads */
1144 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1146 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1150 Wnd
->spwndOwner
= WndNewOwner
;
1154 Wnd
->spwndOwner
= NULL
;
1159 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1160 EngSetLastError(ERROR_INVALID_PARAMETER
);
1164 UserDereferenceObject(Wnd
);
1169 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1171 PWND WndOldParent
, pWndExam
;
1174 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1177 ASSERT(WndNewParent
);
1178 ASSERT_REFS_CO(Wnd
);
1179 ASSERT_REFS_CO(WndNewParent
);
1181 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1183 EngSetLastError(ERROR_ACCESS_DENIED
);
1187 /* Some applications try to set a child as a parent */
1188 if (IntIsChildWindow(Wnd
, WndNewParent
))
1190 TRACE("IntSetParent try to set a child as a parent.\n");
1191 EngSetLastError( ERROR_INVALID_PARAMETER
);
1195 pWndExam
= WndNewParent
; // Load parent Window to examine.
1196 // Now test for set parent to parent hit.
1199 if (Wnd
== pWndExam
)
1201 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1202 EngSetLastError(ERROR_INVALID_PARAMETER
);
1205 pWndExam
= pWndExam
->spwndParent
;
1209 * Windows hides the window first, then shows it again
1210 * including the WM_SHOWWINDOW messages and all
1212 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1214 /* Window must belong to current process */
1215 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1217 ERR("IntSetParent Window must belong to current process!\n");
1221 WndOldParent
= Wnd
->spwndParent
;
1223 if ( WndOldParent
&&
1224 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1225 pt
.x
= Wnd
->rcWindow
.right
;
1227 pt
.x
= Wnd
->rcWindow
.left
;
1228 pt
.y
= Wnd
->rcWindow
.top
;
1230 IntScreenToClient(WndOldParent
, &pt
);
1232 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1234 if (WndNewParent
!= WndOldParent
)
1236 /* Unlink the window from the siblings list */
1237 IntUnlinkWindow(Wnd
);
1238 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1240 /* Set the new parent */
1241 Wnd
->spwndParent
= WndNewParent
;
1243 if ( Wnd
->style
& WS_CHILD
&&
1245 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1247 ERR("SetParent Top Most from Pop up!\n");
1248 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1251 /* Link the window with its new siblings */
1253 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1254 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1258 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1259 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1261 Wnd
->style
|= WS_CLIPSIBLINGS
;
1262 DceResetActiveDCEs(Wnd
);
1265 /* if parent belongs to a different thread and the window isn't */
1266 /* top-level, attach the two threads */
1267 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1269 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1271 if (Wnd
->head
.pti
!= WndOldParent
->head
.pti
)
1273 //ERR("SetParent Old out.\n");
1274 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1277 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1279 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1281 //ERR("SetParent New in.\n");
1282 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1287 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1288 swFlags
|= SWP_NOACTIVATE
;
1290 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1292 * SetParent additionally needs to make hwnd the top window
1293 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1294 * WM_WINDOWPOSCHANGED notification messages.
1296 //ERR("IntSetParent SetWindowPos 1\n");
1297 co_WinPosSetWindowPos( Wnd
,
1298 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1299 pt
.x
, pt
.y
, 0, 0, swFlags
);
1300 //ERR("IntSetParent SetWindowPos 2\n");
1301 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1303 return WndOldParent
;
1307 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1309 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1310 HWND hWndOldParent
= NULL
;
1311 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1313 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1315 EngSetLastError(ERROR_INVALID_PARAMETER
);
1319 if (hWndChild
== IntGetDesktopWindow())
1321 ERR("UserSetParent Access Denied!\n");
1322 EngSetLastError(ERROR_ACCESS_DENIED
);
1328 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1330 ERR("UserSetParent Bad New Parent!\n");
1336 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1342 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1344 ERR("UserSetParent Bad Child!\n");
1348 UserRefObjectCo(Wnd
, &Ref
);
1349 UserRefObjectCo(WndParent
, &ParentRef
);
1350 //ERR("Enter co_IntSetParent\n");
1351 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1352 //ERR("Leave co_IntSetParent\n");
1353 UserDerefObjectCo(WndParent
);
1354 UserDerefObjectCo(Wnd
);
1358 hWndOldParent
= WndOldParent
->head
.h
;
1359 UserDereferenceObject(WndOldParent
);
1362 return( hWndOldParent
);
1366 IntSetSystemMenu(PWND Window
, PMENU_OBJECT Menu
)
1368 PMENU_OBJECT OldMenu
;
1369 if(Window
->SystemMenu
)
1371 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1374 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1375 IntReleaseMenuObject(OldMenu
);
1381 /* FIXME: Check window style, propably return FALSE? */
1382 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1383 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1386 Window
->SystemMenu
= (HMENU
)0;
1391 /* Unlink the window from siblings. children and parent are kept in place. */
1393 IntUnlinkWindow(PWND Wnd
)
1396 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1399 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1401 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1402 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1404 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1407 /* FUNCTIONS *****************************************************************/
1410 * As best as I can figure, this function is used by EnumWindows,
1411 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1413 * It's supposed to build a list of HWNDs to return to the caller.
1414 * We can figure out what kind of list by what parameters are
1422 NtUserBuildHwndList(
1435 return ERROR_INVALID_PARAMETER
;
1437 if (hwndParent
|| !dwThreadId
)
1440 PWND Parent
, Window
;
1444 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1446 return ERROR_INVALID_HANDLE
;
1451 Status
= IntValidateDesktopHandle(hDesktop
,
1455 if(!NT_SUCCESS(Status
))
1457 return ERROR_INVALID_HANDLE
;
1460 hwndParent
= Desktop
->DesktopWindow
;
1467 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1468 (Window
= Parent
->spwndChild
))
1470 BOOL bGoDown
= TRUE
;
1472 Status
= STATUS_SUCCESS
;
1477 if(dwCount
++ < *pBufSize
&& pWnd
)
1481 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1482 *pWnd
= Window
->head
.h
;
1485 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1487 Status
= _SEH2_GetExceptionCode();
1490 if(!NT_SUCCESS(Status
))
1492 SetLastNtError(Status
);
1496 if (Window
->spwndChild
&& bChildren
)
1498 Window
= Window
->spwndChild
;
1503 if (Window
->spwndNext
)
1505 Window
= Window
->spwndNext
;
1509 Window
= Window
->spwndParent
;
1510 if (Window
== Parent
)
1519 ObDereferenceObject(Desktop
);
1522 else // Build EnumThreadWindows list!
1525 PTHREADINFO W32Thread
;
1526 PLIST_ENTRY Current
;
1529 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1530 if (!NT_SUCCESS(Status
))
1532 ERR("Thread Id is not valid!\n");
1533 return ERROR_INVALID_PARAMETER
;
1535 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1537 ObDereferenceObject(Thread
);
1538 ERR("Thread is not initialized!\n");
1539 return ERROR_INVALID_PARAMETER
;
1542 Current
= W32Thread
->WindowListHead
.Flink
;
1543 while (Current
!= &(W32Thread
->WindowListHead
))
1545 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1548 if (dwCount
< *pBufSize
&& pWnd
)
1552 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1553 *pWnd
= Window
->head
.h
;
1556 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1558 Status
= _SEH2_GetExceptionCode();
1561 if (!NT_SUCCESS(Status
))
1563 ERR("Failure to build window list!\n");
1564 SetLastNtError(Status
);
1569 Current
= Window
->ThreadListEntry
.Flink
;
1572 ObDereferenceObject(Thread
);
1575 *pBufSize
= dwCount
;
1576 return STATUS_SUCCESS
;
1579 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1581 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1582 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1584 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1586 USER_REFERENCE_ENTRY Ref
;
1587 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1588 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1590 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1591 (LPARAM
)pWindow
->head
.h
);
1592 UserDerefObjectCo(pWindow
->spwndParent
);
1598 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1600 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1602 /* default positioning for overlapped windows */
1603 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1606 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1608 pMonitor
= UserGetPrimaryMonitor();
1610 /* Check if we don't have a monitor attached yet */
1611 if(pMonitor
== NULL
)
1619 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1621 if (IS_DEFAULT(Cs
->x
))
1623 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1625 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1627 Cs
->x
= ProcessParams
->StartingX
;
1628 Cs
->y
= ProcessParams
->StartingY
;
1632 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1633 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1634 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1635 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1637 /* reset counter and position */
1640 pMonitor
->cWndStack
= 0;
1642 pMonitor
->cWndStack
++;
1646 if (IS_DEFAULT(Cs
->cx
))
1648 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1650 Cs
->cx
= ProcessParams
->CountX
;
1651 Cs
->cy
= ProcessParams
->CountY
;
1655 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1656 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1659 /* neither x nor cx are default. Check the y values .
1660 * In the trace we see Outlook and Outlook Express using
1661 * cy set to CW_USEDEFAULT when opening the address book.
1663 else if (IS_DEFAULT(Cs
->cy
))
1665 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1666 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1671 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1672 if(IS_DEFAULT(Cs
->x
))
1677 if(IS_DEFAULT(Cs
->cx
))
1687 /* Allocates and initializes a window */
1688 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1689 PLARGE_STRING WindowName
,
1694 PDESKTOP pdeskCreated
)
1698 PTHREADINFO pti
= NULL
;
1699 PMENU_OBJECT SystemMenu
;
1701 BOOL bUnicodeWindow
;
1703 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1705 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1709 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1710 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1711 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1712 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1716 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1718 * Dialog boxes and message boxes do not inherit layout, so you must
1719 * set the layout explicitly.
1721 if ( Class
->fnid
!= FNID_DIALOG
)
1723 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1725 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1731 /* Automatically add WS_EX_WINDOWEDGE */
1732 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1733 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1734 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1735 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1737 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1739 /* Is it a unicode window? */
1740 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1741 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1743 /* Allocate the new window */
1744 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1745 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1749 sizeof(WND
) + Class
->cbwndExtra
);
1756 TRACE("Created window object with handle %p\n", hWnd
);
1758 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1759 { /* HACK: Helper for win32csr/desktopbg.c */
1760 /* If there is no desktop window yet, we must be creating it */
1761 TRACE("CreateWindow setting desktop.\n");
1762 pdeskCreated
->DesktopWindow
= hWnd
;
1763 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1767 * Fill out the structure describing it.
1769 /* Remember, pWnd->head is setup in object.c ... */
1770 pWnd
->spwndParent
= ParentWindow
;
1771 pWnd
->spwndOwner
= OwnerWindow
;
1773 pWnd
->spwndLastActive
= pWnd
;
1774 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1776 pWnd
->hModule
= Cs
->hInstance
;
1777 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1778 pWnd
->ExStyle
= Cs
->dwExStyle
;
1779 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1780 pWnd
->pActCtx
= acbiBuffer
;
1781 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1782 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1784 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1786 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1787 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1790 pWnd
->head
.pti
->cWindows
++;
1792 if (Class
->hIcon
&& !Class
->hIconSm
)
1794 Class
->hIconSmIntern
= co_IntCopyImage( Class
->hIcon
, IMAGE_ICON
,
1795 UserGetSystemMetrics( SM_CXSMICON
),
1796 UserGetSystemMetrics( SM_CYSMICON
), 0 );
1797 TRACE("IntCreateWindow hIconSmIntern %p\n",Class
->hIconSmIntern
);
1798 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1801 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1802 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1804 /* BugBoy Comments: Comment below say that System classes are always created
1805 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1806 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1808 No where can I see in code or through testing does the window change back
1809 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1810 see what problems this would cause. */
1812 // Set WndProc from Class.
1813 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1815 // GetWindowProc, test for non server side default classes and set WndProc.
1816 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1820 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1821 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1825 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1826 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1830 // If not an Unicode caller, set Ansi creator bit.
1831 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1833 // Clone Class Ansi/Unicode proc type.
1834 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1836 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1837 pWnd
->Unicode
= FALSE
;
1841 * It seems there can be both an Ansi creator and Unicode Class Window
1842 * WndProc, unless the following overriding conditions occur:
1844 if ( !bUnicodeWindow
&&
1845 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1846 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1847 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1848 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1849 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1850 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1851 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1852 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1853 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1854 { // Override Class and set the window Ansi WndProc.
1855 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1856 pWnd
->Unicode
= FALSE
;
1859 { // Set the window Unicode WndProc.
1860 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1861 pWnd
->Unicode
= TRUE
;
1865 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1866 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1867 Dont understand why it does this. */
1868 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1870 PCALLPROCDATA CallProc
;
1871 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1875 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1876 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1880 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1884 InitializeListHead(&pWnd
->PropListHead
);
1886 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1888 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1889 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1890 if (pWnd
->strName
.Buffer
== NULL
)
1895 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1896 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1897 pWnd
->strName
.Length
= WindowName
->Length
;
1898 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1901 /* Correct the window style. */
1902 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1904 pWnd
->style
|= WS_CLIPSIBLINGS
;
1905 if (!(pWnd
->style
& WS_POPUP
))
1907 pWnd
->style
|= WS_CAPTION
;
1911 /* WS_EX_WINDOWEDGE depends on some other styles */
1912 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1913 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1914 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1916 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1917 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1918 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1921 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1923 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1924 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1926 /* Create system menu */
1927 if ((Cs
->style
& WS_SYSMENU
)) // && (dwStyle & WS_CAPTION) == WS_CAPTION)
1929 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1932 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1933 IntReleaseMenuObject(SystemMenu
);
1937 /* Set the window menu */
1938 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1941 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1942 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1944 UNICODE_STRING MenuName
;
1947 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1949 MenuName
.Length
= 0;
1950 MenuName
.MaximumLength
= 0;
1951 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1955 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1957 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1958 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1962 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1965 if ( ParentWindow
&&
1966 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1967 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1969 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1971 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1973 EngSetLastError(ERROR_INVALID_PARAMETER
);
1976 if ( pWnd
->spwndOwner
&&
1977 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1979 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1981 if ( pWnd
->spwndOwner
&&
1982 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1983 pti
!= pWnd
->spwndOwner
->head
.pti
)
1985 //ERR("CreateWindow Owner in.\n");
1986 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1990 /* Insert the window into the thread's window list. */
1991 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1993 /* Handle "CS_CLASSDC", it is tested first. */
1994 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1995 { /* One DCE per class to have CLASS. */
1996 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1998 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1999 { /* Allocate a DCE for this window. */
2000 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
2006 ERR("IntCreateWindow Allocation Error.\n");
2007 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
2010 UserDereferenceObject(pWnd
);
2018 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
2019 PUNICODE_STRING ClassName
,
2020 PLARGE_STRING WindowName
,
2024 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
2025 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
2026 PWINSTATION_OBJECT WinSta
;
2029 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2030 CBT_CREATEWNDW
* pCbtCreate
;
2032 USER_REFERENCE_ENTRY ParentRef
, Ref
;
2034 DWORD dwShowMode
= SW_SHOW
;
2035 CREATESTRUCTW
*pCsw
= NULL
;
2036 PVOID pszClass
= NULL
, pszName
= NULL
;
2039 /* Get the current window station and reference it */
2040 pti
= GetW32ThreadInfo();
2041 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
2043 ERR("Thread is not attached to a desktop! Cannot create window!\n");
2044 return NULL
; // There is nothing to cleanup.
2046 WinSta
= pti
->rpdesk
->rpwinstaParent
;
2047 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
2052 /* Get the class and reference it */
2053 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
2056 ERR("Failed to find class %wZ\n", ClassName
);
2060 /* Now find the parent and the owner window */
2061 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
2064 if (Cs
->hwndParent
== HWND_MESSAGE
)
2066 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
2068 else if (Cs
->hwndParent
)
2070 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
2071 hWndOwner
= Cs
->hwndParent
;
2073 hWndParent
= Cs
->hwndParent
;
2075 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2077 ERR("Cannot create a child window without a parrent!\n");
2078 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
2079 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
2082 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
2083 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
2085 /* FIXME: Is this correct? */
2087 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
2089 /* Fix the position and the size of the window */
2092 UserRefObjectCo(ParentWindow
, &ParentRef
);
2093 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2096 /* Allocate and initialize the new window */
2097 Window
= IntCreateWindow(Cs
,
2106 ERR("IntCreateWindow failed!\n");
2110 hWnd
= UserHMGetHandle(Window
);
2111 hwndInsertAfter
= HWND_TOP
;
2113 UserRefObjectCo(Window
, &Ref
);
2114 UserDereferenceObject(Window
);
2115 ObDereferenceObject(WinSta
);
2117 //// Check for a hook to eliminate overhead. ////
2118 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2120 // Allocate the calling structures Justin Case this goes Global.
2121 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2122 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2123 if (!pCsw
|| !pCbtCreate
)
2125 ERR("UserHeapAlloc() failed!\n");
2129 /* Fill the new CREATESTRUCTW */
2130 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2131 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2133 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2134 if (!IS_ATOM(ClassName
->Buffer
))
2136 if (Window
->state
& WNDS_ANSICREATOR
)
2138 ANSI_STRING AnsiString
;
2139 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2140 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2143 ERR("UserHeapAlloc() failed!\n");
2146 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2147 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2148 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2152 UNICODE_STRING UnicodeString
;
2153 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2154 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2157 ERR("UserHeapAlloc() failed!\n");
2160 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2161 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2162 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2164 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2166 if (WindowName
->Length
)
2168 UNICODE_STRING Name
;
2169 Name
.Buffer
= WindowName
->Buffer
;
2170 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2171 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2173 if (Window
->state
& WNDS_ANSICREATOR
)
2175 ANSI_STRING AnsiString
;
2176 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2177 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2180 ERR("UserHeapAlloc() failed!\n");
2183 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2184 AnsiString
.Buffer
= (PCHAR
)pszName
;
2185 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2189 UNICODE_STRING UnicodeString
;
2190 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2191 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2194 ERR("UserHeapAlloc() failed!\n");
2197 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2198 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2199 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2201 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2204 pCbtCreate
->lpcs
= pCsw
;
2205 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2207 //// Call the WH_CBT hook ////
2208 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2211 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2214 // Write back changes.
2219 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2222 /* NCCREATE and WM_NCCALCSIZE need the original values */
2223 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2224 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2226 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2228 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2230 Cs
->x
+= ParentWindow
->rcClient
.left
;
2231 Cs
->y
+= ParentWindow
->rcClient
.top
;
2235 /* Send the WM_GETMINMAXINFO message */
2239 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2241 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2242 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2243 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2244 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2245 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2248 Window
->rcWindow
.left
= Cs
->x
;
2249 Window
->rcWindow
.top
= Cs
->y
;
2250 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2251 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2253 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2255 // ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2256 RECTL_vOffsetRect(&Window->rcWindow,
2257 ParentWindow->rcClient.left,
2258 ParentWindow->rcClient.top);
2261 Window
->rcClient
= Window
->rcWindow
;
2263 /* Link the window */
2264 if (NULL
!= ParentWindow
)
2266 /* Link the window into the siblings list */
2267 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2268 IntLinkHwnd(Window
, HWND_BOTTOM
);
2270 IntLinkHwnd(Window
, hwndInsertAfter
);
2273 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2275 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2276 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2279 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2281 if ( !IntIsTopLevelWindow(Window
) )
2283 if (pti
!= Window
->spwndParent
->head
.pti
)
2285 //ERR("CreateWindow Parent in.\n");
2286 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2291 /* Send the NCCREATE message */
2292 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2295 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2299 /* Send the WM_NCCALCSIZE message */
2302 MaxPos
.x
= Window
->rcWindow
.left
;
2303 MaxPos
.y
= Window
->rcWindow
.top
;
2305 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2306 //rc = Window->rcWindow;
2307 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2308 //Window->rcClient = rc;
2310 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2311 MaxPos
.y
- Window
->rcWindow
.top
);
2314 /* Send the WM_CREATE message. */
2315 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2316 if (Result
== (LRESULT
)-1)
2318 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2322 /* Send the EVENT_OBJECT_CREATE event */
2323 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2325 /* By setting the flag below it can be examined to determine if the window
2326 was created successfully and a valid pwnd was passed back to caller since
2327 from here the function has to succeed. */
2328 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2330 /* Send the WM_SIZE and WM_MOVE messages. */
2331 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2333 co_WinPosSendSizeMove(Window
);
2336 /* Show or maybe minimize or maximize the window. */
2338 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2339 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2342 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2344 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2345 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2346 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2347 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2348 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2351 /* Send the WM_PARENTNOTIFY message */
2352 IntSendParentNotify(Window
, WM_CREATE
);
2354 /* Notify the shell that a new window was created */
2355 if ((!hWndParent
) && (!hWndOwner
))
2357 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2360 /* Initialize and show the window's scrollbars */
2361 if (Window
->style
& WS_VSCROLL
)
2363 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2365 if (Window
->style
& WS_HSCROLL
)
2367 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2370 /* Show the new window */
2371 if (Cs
->style
& WS_VISIBLE
)
2373 if (Window
->style
& WS_MAXIMIZE
)
2374 dwShowMode
= SW_SHOW
;
2375 else if (Window
->style
& WS_MINIMIZE
)
2376 dwShowMode
= SW_SHOWMINIMIZED
;
2378 co_WinPosShowWindow(Window
, dwShowMode
);
2380 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2382 ASSERT(ParentWindow
);
2385 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2386 /* ShowWindow won't activate child windows */
2387 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2391 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2397 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2398 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2400 co_UserDestroyWindow(Window
);
2402 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2405 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2406 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2407 if (pszName
) UserHeapFree(pszName
);
2408 if (pszClass
) UserHeapFree(pszClass
);
2412 UserDerefObjectCo(Window
);
2414 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2421 ProbeAndCaptureLargeString(
2422 OUT PLARGE_STRING plstrSafe
,
2423 IN PLARGE_STRING plstrUnsafe
)
2425 LARGE_STRING lstrTemp
;
2426 PVOID pvBuffer
= NULL
;
2430 /* Probe and copy the string */
2431 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2432 lstrTemp
= *plstrUnsafe
;
2434 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2437 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2441 if (lstrTemp
.Length
!= 0)
2443 /* Allocate a buffer from paged pool */
2444 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2447 return STATUS_NO_MEMORY
;
2452 /* Probe and copy the buffer */
2453 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2454 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2456 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2458 /* Cleanup and fail */
2459 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2460 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2465 /* Set the output string */
2466 plstrSafe
->Buffer
= pvBuffer
;
2467 plstrSafe
->Length
= lstrTemp
.Length
;
2468 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2470 return STATUS_SUCCESS
;
2474 * \todo Allow passing plstrClassName as ANSI.
2478 NtUserCreateWindowEx(
2480 PLARGE_STRING plstrClassName
,
2481 PLARGE_STRING plstrClsVersion
,
2482 PLARGE_STRING plstrWindowName
,
2490 HINSTANCE hInstance
,
2496 LARGE_STRING lstrWindowName
;
2497 LARGE_STRING lstrClassName
;
2498 UNICODE_STRING ustrClassName
;
2503 lstrWindowName
.Buffer
= NULL
;
2504 lstrClassName
.Buffer
= NULL
;
2506 ASSERT(plstrWindowName
);
2508 /* Copy the window name to kernel mode */
2509 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2510 if (!NT_SUCCESS(Status
))
2512 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2513 SetLastNtError(Status
);
2517 plstrWindowName
= &lstrWindowName
;
2519 /* Check if the class is an atom */
2520 if (IS_ATOM(plstrClassName
))
2522 /* It is, pass the atom in the UNICODE_STRING */
2523 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2524 ustrClassName
.Length
= 0;
2525 ustrClassName
.MaximumLength
= 0;
2529 /* It's not, capture the class name */
2530 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2531 if (!NT_SUCCESS(Status
))
2533 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2534 /* Set last error, cleanup and return */
2535 SetLastNtError(Status
);
2539 /* We pass it on as a UNICODE_STRING */
2540 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2541 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2542 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2545 /* Fill the CREATESTRUCTW */
2546 /* we will keep here the original parameters */
2548 Cs
.lpCreateParams
= lpParam
;
2549 Cs
.hInstance
= hInstance
;
2551 Cs
.hwndParent
= hWndParent
;
2556 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2557 if (IS_ATOM(plstrClassName
))
2558 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2560 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2561 Cs
.dwExStyle
= dwExStyle
;
2563 UserEnterExclusive();
2565 /* Call the internal function */
2566 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
);
2570 ERR("co_UserCreateWindowEx failed!\n");
2572 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2577 if (lstrWindowName
.Buffer
)
2579 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2581 if (lstrClassName
.Buffer
)
2583 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2590 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2597 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2599 hWnd
= Window
->head
.h
;
2600 ti
= PsGetCurrentThreadWin32Thread();
2602 TRACE("co_UserDestroyWindow \n");
2604 /* Check for owner thread */
2605 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2607 /* Check if we are destroying the desktop window */
2608 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2610 EngSetLastError(ERROR_ACCESS_DENIED
);
2615 /* If window was created successfully and it is hooked */
2616 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2618 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2620 ERR("Destroy Window WH_CBT Call Hook return!\n");
2625 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2627 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2629 if (Window
->spwndOwner
)
2631 //ERR("DestroyWindow Owner out.\n");
2632 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2637 /* Inform the parent */
2638 if (Window
->style
& WS_CHILD
)
2640 IntSendParentNotify(Window
, WM_DESTROY
);
2643 /* Look whether the focus is within the tree of windows we will
2646 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2648 if (ti
->MessageQueue
->spwndActive
== Window
&& ti
->MessageQueue
== IntGetFocusMessageQueue())
2650 co_WinPosActivateOtherWindow(Window
);
2654 // Adjust last active.
2655 if ((pwndTemp
= Window
->spwndOwner
))
2657 while (pwndTemp
->spwndOwner
)
2658 pwndTemp
= pwndTemp
->spwndOwner
;
2660 if (pwndTemp
->spwndLastActive
== Window
)
2661 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2664 if (Window
->spwndParent
&& IntIsWindow(Window
->head
.h
))
2666 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2668 if (!IntIsTopLevelWindow(Window
))
2670 //ERR("DestroyWindow Parent out.\n");
2671 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2676 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2677 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2678 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2679 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2680 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2681 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2682 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2683 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2686 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2689 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2691 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2693 ERR("Destroying the ShellWindow!\n");
2694 ti
->pDeskInfo
->hShellWindow
= NULL
;
2698 IntEngWindowChanged(Window
, WOC_DELETE
);
2700 if (!IntIsWindow(Window
->head
.h
))
2705 /* Recursively destroy owned windows */
2707 if (! (Window
->style
& WS_CHILD
))
2711 BOOL GotOne
= FALSE
;
2714 PWND Child
, Desktop
;
2716 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2717 UserGetWindowObject(IntGetDesktopWindow());
2718 Children
= IntWinListChildren(Desktop
);
2722 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2724 Child
= UserGetWindowObject(*ChildHandle
);
2727 if (Child
->spwndOwner
!= Window
)
2732 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2734 USER_REFERENCE_ENTRY ChildRef
;
2735 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2736 co_UserDestroyWindow(Child
);
2737 UserDerefObjectCo(Child
); // Temp HACK?
2743 if (Child
->spwndOwner
!= NULL
)
2745 Child
->spwndOwner
= NULL
;
2749 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2758 /* Generate mouse move message for the next window */
2759 msg
.message
= WM_MOUSEMOVE
;
2760 msg
.wParam
= UserGetMouseButtonsState();
2761 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2762 msg
.pt
= gpsi
->ptCursor
;
2763 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2765 if (!IntIsWindow(Window
->head
.h
))
2770 /* Destroy the window storage */
2771 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2781 NtUserDestroyWindow(HWND Wnd
)
2784 DECLARE_RETURN(BOOLEAN
);
2786 USER_REFERENCE_ENTRY Ref
;
2788 TRACE("Enter NtUserDestroyWindow\n");
2789 UserEnterExclusive();
2791 if (!(Window
= UserGetWindowObject(Wnd
)))
2796 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2797 ret
= co_UserDestroyWindow(Window
);
2798 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2803 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2809 static HWND FASTCALL
2810 IntFindWindow(PWND Parent
,
2813 PUNICODE_STRING WindowName
)
2815 BOOL CheckWindowName
;
2818 UNICODE_STRING CurrentWindowName
;
2822 CheckWindowName
= WindowName
->Buffer
!= 0;
2824 if((List
= IntWinListChildren(Parent
)))
2829 /* skip handles before and including ChildAfter */
2830 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2834 /* search children */
2838 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2843 /* Do not send WM_GETTEXT messages in the kernel mode version!
2844 The user mode version however calls GetWindowText() which will
2845 send WM_GETTEXT messages to windows belonging to its processes */
2846 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2848 // FIXME: LARGE_STRING truncated
2849 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2850 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2851 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2852 if(!CheckWindowName
||
2853 (Child
->strName
.Length
< 0xFFFF &&
2854 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2856 Ret
= Child
->head
.h
;
2861 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2869 * Searches a window's children for a window with the specified
2872 * hwndParent = The window whose childs are to be searched.
2874 * HWND_MESSAGE = message-only windows
2876 * hwndChildAfter = Search starts after this child window.
2877 * NULL = start from beginning
2879 * ucClassName = Class name to search for
2880 * Reguired parameter.
2882 * ucWindowName = Window name
2883 * ->Buffer == NULL = don't care
2886 * The HWND of the window if it was found, otherwise NULL
2892 NtUserFindWindowEx(HWND hwndParent
,
2893 HWND hwndChildAfter
,
2894 PUNICODE_STRING ucClassName
,
2895 PUNICODE_STRING ucWindowName
,
2898 PWND Parent
, ChildAfter
;
2899 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2900 HWND Desktop
, Ret
= NULL
;
2901 BOOL DoMessageWnd
= FALSE
;
2902 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2903 DECLARE_RETURN(HWND
);
2905 TRACE("Enter NtUserFindWindowEx\n");
2908 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2912 if (ucClassName
!= NULL
)
2914 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2915 if (ClassName
.Length
!= 0)
2917 ProbeForRead(ClassName
.Buffer
,
2921 else if (!IS_ATOM(ClassName
.Buffer
))
2923 EngSetLastError(ERROR_INVALID_PARAMETER
);
2927 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2934 if (ucWindowName
!= NULL
)
2936 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2937 if (WindowName
.Length
!= 0)
2939 ProbeForRead(WindowName
.Buffer
,
2945 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2947 SetLastNtError(_SEH2_GetExceptionCode());
2948 _SEH2_YIELD(RETURN(NULL
));
2952 if (ucClassName
!= NULL
)
2954 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2955 !IS_ATOM(ClassName
.Buffer
))
2957 EngSetLastError(ERROR_INVALID_PARAMETER
);
2960 else if (ClassAtom
== (RTL_ATOM
)0)
2962 /* LastError code was set by IntGetAtomFromStringOrAtom */
2968 Desktop
= IntGetCurrentThreadDesktopWindow();
2970 if(hwndParent
== NULL
)
2972 hwndParent
= Desktop
;
2973 DoMessageWnd
= TRUE
;
2975 else if(hwndParent
== HWND_MESSAGE
)
2977 hwndParent
= IntGetMessageWindow();
2980 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2986 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2993 if(Parent
->head
.h
== Desktop
)
2996 PWND TopLevelWindow
;
2997 BOOLEAN CheckWindowName
;
2998 BOOLEAN WindowMatches
;
2999 BOOLEAN ClassMatches
;
3001 /* windows searches through all top-level windows if the parent is the desktop
3004 if((List
= IntWinListChildren(Parent
)))
3010 /* skip handles before and including ChildAfter */
3011 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
3015 CheckWindowName
= WindowName
.Buffer
!= 0;
3017 /* search children */
3020 UNICODE_STRING ustr
;
3022 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
3027 /* Do not send WM_GETTEXT messages in the kernel mode version!
3028 The user mode version however calls GetWindowText() which will
3029 send WM_GETTEXT messages to windows belonging to its processes */
3030 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
3031 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
3032 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
3033 WindowMatches
= !CheckWindowName
||
3034 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
3035 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
3036 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
3037 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
3039 if (WindowMatches
&& ClassMatches
)
3041 Ret
= TopLevelWindow
->head
.h
;
3045 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3047 /* window returns the handle of the top-level window, in case it found
3049 Ret
= TopLevelWindow
->head
.h
;
3054 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3059 ERR("FindWindowEx: Not Desktop Parent!\n");
3060 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3063 if (Ret
== NULL
&& DoMessageWnd
)
3067 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3069 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3073 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3075 SetLastNtError(_SEH2_GetExceptionCode());
3083 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3092 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3094 PWND WndAncestor
, Parent
;
3096 if (Wnd
->head
.h
== IntGetDesktopWindow())
3105 WndAncestor
= Wnd
->spwndParent
;
3116 if(!(Parent
= WndAncestor
->spwndParent
))
3120 if(IntIsDesktopWindow(Parent
))
3125 WndAncestor
= Parent
;
3136 Parent
= IntGetParent(WndAncestor
);
3143 WndAncestor
= Parent
;
3161 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3163 PWND Window
, Ancestor
;
3164 DECLARE_RETURN(HWND
);
3166 TRACE("Enter NtUserGetAncestor\n");
3167 UserEnterExclusive();
3169 if (!(Window
= UserGetWindowObject(hWnd
)))
3174 Ancestor
= UserGetAncestor(Window
, Type
);
3175 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3177 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3180 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3188 NtUserGetComboBoxInfo(
3193 DECLARE_RETURN(BOOL
);
3195 TRACE("Enter NtUserGetComboBoxInfo\n");
3198 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3207 sizeof(COMBOBOXINFO
),
3211 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3213 SetLastNtError(_SEH2_GetExceptionCode());
3214 _SEH2_YIELD(RETURN(FALSE
));
3218 // Pass the user pointer, it was already probed.
3219 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3222 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3230 NtUserGetListBoxInfo(
3234 DECLARE_RETURN(DWORD
);
3236 TRACE("Enter NtUserGetListBoxInfo\n");
3239 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3244 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3247 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3255 * The NtUserSetParent function changes the parent window of the specified
3259 * The new parent window and the child window must belong to the same
3260 * application. If the window identified by the hWndChild parameter is
3261 * visible, the system performs the appropriate redrawing and repainting.
3262 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3263 * or WS_POPUP window styles of the window whose parent is being changed.
3270 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3272 DECLARE_RETURN(HWND
);
3274 TRACE("Enter NtUserSetParent\n");
3275 UserEnterExclusive();
3278 Check Parent first from user space, set it here.
3282 hWndNewParent
= IntGetDesktopWindow();
3284 else if (hWndNewParent
== HWND_MESSAGE
)
3286 hWndNewParent
= IntGetMessageWindow();
3289 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3292 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3298 * UserGetShellWindow
3300 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3305 HWND FASTCALL
UserGetShellWindow(VOID
)
3307 PWINSTATION_OBJECT WinStaObject
;
3310 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3315 if (!NT_SUCCESS(Status
))
3317 SetLastNtError(Status
);
3321 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3323 ObDereferenceObject(WinStaObject
);
3328 * NtUserSetShellWindowEx
3330 * This is undocumented function to set global shell window. The global
3331 * shell window has special handling of window position.
3337 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3339 PWINSTATION_OBJECT WinStaObject
;
3340 PWND WndShell
, WndListView
;
3341 DECLARE_RETURN(BOOL
);
3342 USER_REFERENCE_ENTRY Ref
;
3346 TRACE("Enter NtUserSetShellWindowEx\n");
3347 UserEnterExclusive();
3349 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3354 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3359 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3364 if (!NT_SUCCESS(Status
))
3366 SetLastNtError(Status
);
3371 * Test if we are permitted to change the shell window.
3373 if (WinStaObject
->ShellWindow
)
3375 ObDereferenceObject(WinStaObject
);
3380 * Move shell window into background.
3382 if (hwndListView
&& hwndListView
!= hwndShell
)
3385 * Disabled for now to get Explorer working.
3386 * -- Filip, 01/nov/2003
3389 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3392 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3394 ObDereferenceObject(WinStaObject
);
3399 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3401 ObDereferenceObject(WinStaObject
);
3405 UserRefObjectCo(WndShell
, &Ref
);
3406 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3408 WinStaObject
->ShellWindow
= hwndShell
;
3409 WinStaObject
->ShellListView
= hwndListView
;
3411 ti
= GetW32ThreadInfo();
3414 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3415 ti
->pDeskInfo
->spwndShell
= WndShell
;
3416 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3419 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3421 UserDerefObjectCo(WndShell
);
3423 ObDereferenceObject(WinStaObject
);
3427 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3433 * NtUserGetSystemMenu
3435 * The NtUserGetSystemMenu function allows the application to access the
3436 * window menu (also known as the system menu or the control menu) for
3437 * copying and modifying.
3441 * Handle to the window that will own a copy of the window menu.
3443 * Specifies the action to be taken. If this parameter is FALSE,
3444 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3445 * currently in use. The copy is initially identical to the window menu
3446 * but it can be modified.
3447 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3448 * to the default state. The previous window menu, if any, is destroyed.
3451 * If the bRevert parameter is FALSE, the return value is a handle to a
3452 * copy of the window menu. If the bRevert parameter is TRUE, the return
3460 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3464 DECLARE_RETURN(HMENU
);
3466 TRACE("Enter NtUserGetSystemMenu\n");
3469 if (!(Window
= UserGetWindowObject(hWnd
)))
3474 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3479 RETURN(Menu
->MenuInfo
.Self
);
3482 TRACE("Leave NtUserGetSystemMenu, ret=%p\n", _ret_
);
3488 * NtUserSetSystemMenu
3495 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3497 BOOL Result
= FALSE
;
3500 DECLARE_RETURN(BOOL
);
3502 TRACE("Enter NtUserSetSystemMenu\n");
3503 UserEnterExclusive();
3505 if (!(Window
= UserGetWindowObject(hWnd
)))
3513 * Assign new menu handle.
3515 if (!(Menu
= UserGetMenuObject(hMenu
)))
3520 Result
= IntSetSystemMenu(Window
, Menu
);
3526 TRACE("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3531 // Fixes wine Win test_window_styles and todo tests...
3532 static BOOL FASTCALL
3533 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3535 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3537 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3544 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3546 PWND Window
, Parent
;
3547 PWINSTATION_OBJECT WindowStation
;
3551 if (!(Window
= UserGetWindowObject(hWnd
)))
3556 if ((INT
)Index
>= 0)
3558 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3560 EngSetLastError(ERROR_INVALID_INDEX
);
3564 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3566 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3568 OldValue = (LONG)IntSetWindowProc( Wnd,
3571 if (!OldValue) return 0;
3574 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3581 OldValue
= (LONG
) Window
->ExStyle
;
3582 Style
.styleOld
= OldValue
;
3583 Style
.styleNew
= NewValue
;
3585 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3588 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3590 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3593 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3594 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3596 /* WS_EX_WINDOWEDGE depends on some other styles */
3597 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3598 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3600 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3602 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3603 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3607 OldValue
= (LONG
) Window
->style
;
3608 Style
.styleOld
= OldValue
;
3609 Style
.styleNew
= NewValue
;
3610 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3612 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3613 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3614 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3615 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3616 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3618 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3620 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3622 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3623 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3624 DceResetActiveDCEs( Window
);
3626 Window
->style
= (DWORD
)Style
.styleNew
;
3627 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3632 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3633 Window
->fnid
& FNID_FREED
)
3635 EngSetLastError(ERROR_ACCESS_DENIED
);
3638 OldValue
= (LONG
)IntSetWindowProc(Window
,
3645 OldValue
= (LONG
) Window
->hModule
;
3646 Window
->hModule
= (HINSTANCE
) NewValue
;
3649 case GWL_HWNDPARENT
:
3650 Parent
= Window
->spwndParent
;
3651 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3652 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3654 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3658 OldValue
= (LONG
) Window
->IDMenu
;
3659 Window
->IDMenu
= (UINT
) NewValue
;
3663 OldValue
= Window
->dwUserData
;
3664 Window
->dwUserData
= NewValue
;
3668 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3669 EngSetLastError(ERROR_INVALID_INDEX
);
3679 * NtUserSetWindowLong
3681 * The NtUserSetWindowLong function changes an attribute of the specified
3682 * window. The function also sets the 32-bit (long) value at the specified
3683 * offset into the extra window memory.
3690 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3692 DECLARE_RETURN(LONG
);
3694 TRACE("Enter NtUserSetWindowLong\n");
3695 UserEnterExclusive();
3697 if (hWnd
== IntGetDesktopWindow())
3699 EngSetLastError(STATUS_ACCESS_DENIED
);
3703 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3706 TRACE("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3712 * NtUserSetWindowWord
3714 * Legacy function similar to NtUserSetWindowLong.
3721 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3725 DECLARE_RETURN(WORD
);
3727 TRACE("Enter NtUserSetWindowWord\n");
3728 UserEnterExclusive();
3730 if (hWnd
== IntGetDesktopWindow())
3732 EngSetLastError(STATUS_ACCESS_DENIED
);
3736 if (!(Window
= UserGetWindowObject(hWnd
)))
3745 case GWL_HWNDPARENT
:
3746 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3750 EngSetLastError(ERROR_INVALID_INDEX
);
3755 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3757 EngSetLastError(ERROR_INVALID_PARAMETER
);
3761 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3762 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3767 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3773 QueryWindow based on KJK::Hyperion and James Tabor.
3775 0 = QWUniqueProcessId
3776 1 = QWUniqueThreadId
3779 4 = QWIsHung Implements IsHungAppWindow found
3782 9 = QWKillWindow When I called this with hWnd ==
3783 DesktopWindow, it shutdown the system
3790 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3792 /* Console Leader Process CID Window offsets */
3793 #define GWLP_CONSOLE_LEADER_PID 0
3794 #define GWLP_CONSOLE_LEADER_TID 4
3798 DECLARE_RETURN(UINT
);
3800 TRACE("Enter NtUserQueryWindow\n");
3803 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3810 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3812 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3813 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3815 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
3816 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
3820 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3825 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3827 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3828 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3830 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
3831 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
3835 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3840 case QUERY_WINDOW_ACTIVE
:
3841 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3844 case QUERY_WINDOW_FOCUS
:
3845 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3848 case QUERY_WINDOW_ISHUNG
:
3849 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
);
3852 case QUERY_WINDOW_REAL_ID
:
3853 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3856 case QUERY_WINDOW_FOREGROUND
:
3857 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3861 Result
= (DWORD
)NULL
;
3868 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
3878 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3880 UNICODE_STRING SafeMessageName
;
3883 DECLARE_RETURN(UINT
);
3885 TRACE("Enter NtUserRegisterWindowMessage\n");
3886 UserEnterExclusive();
3888 if(MessageNameUnsafe
== NULL
)
3890 EngSetLastError(ERROR_INVALID_PARAMETER
);
3894 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3895 if(!NT_SUCCESS(Status
))
3897 SetLastNtError(Status
);
3901 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3902 if (SafeMessageName
.Buffer
)
3903 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3907 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
3924 DECLARE_RETURN(BOOL
);
3926 TRACE("Enter NtUserSetMenu\n");
3927 UserEnterExclusive();
3929 if (!(Window
= UserGetWindowObject(hWnd
)))
3934 if (! IntSetMenu(Window
, Menu
, &Changed
))
3939 if (Changed
&& Repaint
)
3941 USER_REFERENCE_ENTRY Ref
;
3943 UserRefObjectCo(Window
, &Ref
);
3944 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3945 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3947 UserDerefObjectCo(Window
);
3953 TRACE("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3962 NtUserSetWindowFNID(HWND hWnd
,
3966 DECLARE_RETURN(BOOL
);
3968 TRACE("Enter NtUserSetWindowFNID\n");
3969 UserEnterExclusive();
3971 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3976 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3978 EngSetLastError(ERROR_ACCESS_DENIED
);
3982 // From user land we only set these.
3983 if (fnID
!= FNID_DESTROY
)
3984 { // Hacked so we can mark desktop~!
3985 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
3988 EngSetLastError(ERROR_INVALID_PARAMETER
);
3997 TRACE("Leave NtUserSetWindowFNID\n");
4005 * Undocumented function that is called from DefWindowProc to set
4012 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4015 LARGE_STRING SafeText
;
4016 UNICODE_STRING UnicodeString
;
4019 TRACE("Enter NtUserDefSetText\n");
4021 if (WindowText
!= NULL
)
4025 SafeText
= ProbeForReadLargeString(WindowText
);
4027 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4030 SetLastNtError(_SEH2_GetExceptionCode());
4040 UserEnterExclusive();
4042 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4048 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4049 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4050 // Now we know what the bAnsi is for.
4051 RtlInitUnicodeString(&UnicodeString
, NULL
);
4052 if (SafeText
.Buffer
)
4057 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4059 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4060 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4062 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4065 SetLastNtError(_SEH2_GetExceptionCode());
4068 if (!Ret
) goto Exit
;
4071 if (UnicodeString
.Length
!= 0)
4073 if (Wnd
->strName
.MaximumLength
> 0 &&
4074 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4076 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4078 Wnd
->strName
.Length
= UnicodeString
.Length
;
4079 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4080 RtlCopyMemory(Wnd
->strName
.Buffer
,
4081 UnicodeString
.Buffer
,
4082 UnicodeString
.Length
);
4087 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4088 buf
= Wnd
->strName
.Buffer
;
4089 Wnd
->strName
.Buffer
= NULL
;
4092 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4095 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4096 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4097 if (Wnd
->strName
.Buffer
!= NULL
)
4099 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4100 RtlCopyMemory(Wnd
->strName
.Buffer
,
4101 UnicodeString
.Buffer
,
4102 UnicodeString
.Length
);
4103 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4104 Wnd
->strName
.Length
= UnicodeString
.Length
;
4108 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4116 Wnd
->strName
.Length
= 0;
4117 if (Wnd
->strName
.Buffer
!= NULL
)
4118 Wnd
->strName
.Buffer
[0] = L
'\0';
4121 // FIXME: HAX! Windows does not do this in here!
4122 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4123 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4124 /* Send shell notifications */
4125 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4127 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4132 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4133 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4139 * NtUserInternalGetWindowText
4146 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4151 DECLARE_RETURN(INT
);
4153 TRACE("Enter NtUserInternalGetWindowText\n");
4156 if(lpString
&& (nMaxCount
<= 1))
4158 EngSetLastError(ERROR_INVALID_PARAMETER
);
4162 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4167 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4170 const WCHAR Terminator
= L
'\0';
4172 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4174 Copy
= min(nMaxCount
- 1, Result
);
4177 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4178 if(!NT_SUCCESS(Status
))
4180 SetLastNtError(Status
);
4186 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4187 if(!NT_SUCCESS(Status
))
4189 SetLastNtError(Status
);
4199 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4209 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4215 // ASSERT(OwnerWnd);
4217 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4218 win_array
= IntWinListChildren(OwnerWnd
);
4223 while (win_array
[count
])
4225 while (--count
>= 0)
4227 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4229 if (pWnd
->spwndOwner
!= OwnerWnd
)
4234 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4236 /* In Windows, ShowOwnedPopups(TRUE) generates
4237 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4238 * regardless of the state of the owner
4240 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4246 if (pWnd
->style
& WS_VISIBLE
)
4248 /* In Windows, ShowOwnedPopups(FALSE) generates
4249 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4250 * regardless of the state of the owner
4252 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4258 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4259 TRACE("Leave ShowOwnedPopups\n");