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
;
311 IntGetWindow(HWND hWnd
,
317 Wnd
= ValidateHwndNoErr(hWnd
);
325 if (Wnd
->spwndOwner
!= NULL
)
326 FoundWnd
= Wnd
->spwndOwner
;
330 if(Wnd
->spwndParent
!= NULL
)
332 FoundWnd
= Wnd
->spwndParent
;
333 if (FoundWnd
->spwndChild
!= NULL
)
334 FoundWnd
= FoundWnd
->spwndChild
;
338 if (Wnd
->spwndNext
!= NULL
)
339 FoundWnd
= Wnd
->spwndNext
;
343 if (Wnd
->spwndPrev
!= NULL
)
344 FoundWnd
= Wnd
->spwndPrev
;
348 if (Wnd
->spwndChild
!= NULL
)
349 FoundWnd
= Wnd
->spwndChild
;
354 while ( FoundWnd
->spwndNext
!= NULL
)
355 FoundWnd
= FoundWnd
->spwndNext
;
363 if (FoundWnd
!= NULL
)
364 Ret
= UserHMGetHandle(FoundWnd
);
368 /***********************************************************************
371 static void IntSendDestroyMsg(HWND hWnd
)
379 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
381 if (hWnd
== info
.hwndCaret
)
388 Window
= UserGetWindowObject(hWnd
);
391 // USER_REFERENCE_ENTRY Ref;
392 // UserRefObjectCo(Window, &Ref);
394 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
396 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
399 // UserDerefObjectCo(Window);
402 /* The window could already be destroyed here */
405 * Send the WM_DESTROY to the window.
408 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
411 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
412 * make sure that the window still exists when we come back.
421 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
424 /* start from the end (FIXME: is this needed?) */
425 for (i
= 0; pWndArray
[i
]; i
++)
430 if (IsWindow( pWndArray
[i
] ))
431 WIN_SendDestroyMsg( pWndArray
[i
] );
433 HeapFree(GetProcessHeap(), 0, pWndArray
);
437 TRACE("destroyed itself while in WM_DESTROY!\n");
443 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
445 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
449 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
451 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
452 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
455 if (Wnd
->strName
.Buffer
!= NULL
)
457 Wnd
->strName
.Length
= 0;
458 Wnd
->strName
.MaximumLength
= 0;
459 DesktopHeapFree(Wnd
->head
.rpdesk
,
460 Wnd
->strName
.Buffer
);
461 Wnd
->strName
.Buffer
= NULL
;
464 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
465 // WindowObject->Wnd = NULL;
468 /***********************************************************************
471 * Destroy storage associated to a window. "Internals" p.358
473 * This is the "functional" DestroyWindows function ei. all stuff
474 * done in CreateWindow is undone here and not in DestroyWindow:-P
477 static LRESULT
co_UserFreeWindow(PWND Window
,
478 PPROCESSINFO ProcessData
,
479 PTHREADINFO ThreadData
,
480 BOOLEAN SendMessages
)
486 BOOLEAN BelongsToThreadData
;
490 if(Window
->state2
& WNDS2_INDESTROY
)
492 TRACE("Tried to call IntDestroyWindow() twice\n");
495 Window
->state2
|= WNDS2_INDESTROY
;
496 Window
->style
&= ~WS_VISIBLE
;
497 Window
->head
.pti
->cVisWindows
--;
499 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
501 /* remove the window already at this point from the thread window list so we
502 don't get into trouble when destroying the thread windows while we're still
503 in IntDestroyWindow() */
504 RemoveEntryList(&Window
->ThreadListEntry
);
506 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
508 IntDeRegisterShellHookWindow(Window
->head
.h
);
512 /* Send destroy messages */
513 IntSendDestroyMsg(Window
->head
.h
);
516 /* free child windows */
517 Children
= IntWinListChildren(Window
);
520 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
522 if ((Child
= IntGetWindowObject(*ChildHandle
)))
524 if(!IntWndBelongsToThread(Child
, ThreadData
))
526 /* send WM_DESTROY messages to windows not belonging to the same thread */
527 IntSendDestroyMsg(Child
->head
.h
);
530 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
532 UserDereferenceObject(Child
);
535 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
541 * Clear the update region to make sure no WM_PAINT messages will be
542 * generated for this window while processing the WM_NCDESTROY.
544 co_UserRedrawWindow(Window
, NULL
, 0,
545 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
546 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
547 if(BelongsToThreadData
)
548 co_IntSendMessage(Window
->head
.h
, WM_NCDESTROY
, 0, 0);
551 DestroyTimersForWindow(ThreadData
, Window
);
553 /* Unregister hot keys */
554 UnregisterWindowHotKeys (Window
);
556 /* flush the message queue */
557 MsqRemoveWindowMessagesFromQueue(Window
);
559 /* from now on no messages can be sent to this window anymore */
560 Window
->state
|= WNDS_DESTROYED
;
561 Window
->fnid
|= FNID_FREED
;
563 /* don't remove the WINDOWSTATUS_DESTROYING bit */
565 /* reset shell window handles */
566 if(ThreadData
->rpdesk
)
568 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
569 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
571 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
572 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
575 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
579 WinPosCheckInternalPos(Window
->head
.h
);
580 if (Window
->head
.h
== GetCapture())
585 /* free resources associated with the window */
586 TIMER_RemoveWindowTimers(Window
->head
.h
);
589 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
591 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
593 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
597 if(Window
->SystemMenu
598 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
600 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
601 Window
->SystemMenu
= (HMENU
)0;
604 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
607 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
608 CLASS_RemoveWindow(Window
->Class
);
611 IntUnlinkWindow(Window
);
613 if (Window
->PropListItems
)
615 IntRemoveWindowProp(Window
);
616 TRACE("Window->PropListItems %d\n",Window
->PropListItems
);
617 ASSERT(Window
->PropListItems
==0);
620 UserReferenceObject(Window
);
621 UserDeleteObject(Window
->head
.h
, TYPE_WINDOW
);
623 IntDestroyScrollBars(Window
);
625 /* dereference the class */
626 IntDereferenceClass(Window
->pcls
,
627 Window
->head
.pti
->pDeskInfo
,
628 Window
->head
.pti
->ppi
);
633 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
634 GreDeleteObject(Window
->hrgnClip
);
635 Window
->hrgnClip
= NULL
;
637 Window
->head
.pti
->cWindows
--;
639 // ASSERT(Window != NULL);
640 UserFreeWindowInfo(Window
->head
.pti
, Window
);
642 UserDereferenceObject(Window
);
644 UserClipboardFreeWindow(Window
);
650 // Same as User32:IntGetWndProc.
653 IntGetWindowProc(PWND pWnd
,
658 WNDPROC gcpd
, Ret
= 0;
660 ASSERT(UserIsEnteredExclusive() == TRUE
);
664 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
666 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
668 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
671 Ret
= GETPFNCLIENTA(i
);
673 Ret
= GETPFNCLIENTW(i
);
679 if (Class
->fnid
== FNID_EDIT
)
680 Ret
= pWnd
->lpfnWndProc
;
683 Ret
= pWnd
->lpfnWndProc
;
685 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
689 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
690 Ret
= GETPFNCLIENTA(Class
->fnid
);
694 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
695 Ret
= GETPFNCLIENTW(Class
->fnid
);
698 if ( Ret
!= pWnd
->lpfnWndProc
)
701 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
704 gcpd
= (WNDPROC
)UserGetCPD(
706 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
709 return (gcpd
? gcpd
: Ret
);
713 IntSetWindowProc(PWND pWnd
,
718 PCALLPROCDATA CallProc
;
720 WNDPROC Ret
, chWndProc
= NULL
;
722 // Retrieve previous window proc.
723 Ret
= IntGetWindowProc(pWnd
, Ansi
);
727 if (IsCallProcHandle(NewWndProc
))
729 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
731 { // Reset new WndProc.
732 NewWndProc
= CallProc
->pfnClientPrevious
;
733 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
734 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
737 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
738 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
740 if (GETPFNCLIENTW(i
) == NewWndProc
)
742 chWndProc
= GETPFNSERVER(i
);
745 if (GETPFNCLIENTA(i
) == NewWndProc
)
747 chWndProc
= GETPFNSERVER(i
);
751 // If match, set/reset to Server Side and clear ansi.
754 pWnd
->lpfnWndProc
= chWndProc
;
755 pWnd
->Unicode
= TRUE
;
756 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
757 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
761 pWnd
->Unicode
= !Ansi
;
762 // Handle the state change in here.
764 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
766 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
768 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
769 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
771 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
773 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
777 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
778 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
782 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
783 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
786 // Now set the new window proc.
787 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
798 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
800 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
802 ERR("SetMenu: Invalid handle 0x%p!\n",UserHMGetHandle(Wnd
));
803 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
807 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
815 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
816 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Wnd
->head
.h
);
825 NewMenu
= IntGetMenuObject(Menu
);
830 IntReleaseMenuObject(OldMenu
);
832 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
835 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
837 /* Can't use the same menu for two windows */
840 IntReleaseMenuObject(OldMenu
);
842 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
848 Wnd
->IDMenu
= (UINT
) Menu
;
851 NewMenu
->MenuInfo
.Wnd
= Wnd
->head
.h
;
852 IntReleaseMenuObject(NewMenu
);
856 OldMenu
->MenuInfo
.Wnd
= NULL
;
857 IntReleaseMenuObject(OldMenu
);
864 /* INTERNAL ******************************************************************/
868 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
873 USER_REFERENCE_ENTRY Ref
;
874 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
876 while (!IsListEmpty(&WThread
->WindowListHead
))
878 Current
= WThread
->WindowListHead
.Flink
;
879 Wnd
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
881 TRACE("thread cleanup: while destroy wnds, wnd=%p\n", Wnd
);
883 /* Window removes itself from the list */
886 * FIXME: It is critical that the window removes itself! If now, we will loop
890 //ASSERT(co_UserDestroyWindow(Wnd));
892 UserRefObjectCo(Wnd
, &Ref
); // FIXME: Temp HACK??
893 if (!co_UserDestroyWindow(Wnd
))
895 ERR("Unable to destroy window %p at thread cleanup... This is _VERY_ bad!\n", Wnd
);
897 UserDerefObjectCo(Wnd
); // FIXME: Temp HACK??
901 PMENU_OBJECT FASTCALL
902 IntGetSystemMenu(PWND Window
, BOOL bRevert
, BOOL RetMenu
)
904 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
905 PTHREADINFO W32Thread
;
906 HMENU hNewMenu
, hSysMenu
;
907 ROSMENUITEMINFO ItemInfo
;
911 W32Thread
= PsGetCurrentThreadWin32Thread();
913 if(!W32Thread
->rpdesk
)
916 if(Window
->SystemMenu
)
918 Menu
= UserGetMenuObject(Window
->SystemMenu
);
921 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
922 Window
->SystemMenu
= (HMENU
)0;
926 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
928 /* Clone system menu */
929 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
933 NewMenu
= IntCloneMenu(Menu
);
936 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
937 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
938 NewMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
940 //IntReleaseMenuObject(NewMenu);
945 hSysMenu
= UserCreateMenu(FALSE
);
946 if (NULL
== hSysMenu
)
950 SysMenu
= IntGetMenuObject(hSysMenu
);
953 UserDestroyMenu(hSysMenu
);
956 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
957 SysMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
958 hNewMenu
= co_IntLoadSysMenuTemplate();
961 IntReleaseMenuObject(SysMenu
);
962 UserDestroyMenu(hSysMenu
);
965 Menu
= IntGetMenuObject(hNewMenu
);
968 IntReleaseMenuObject(SysMenu
);
969 UserDestroyMenu(hSysMenu
);
973 NewMenu
= IntCloneMenu(Menu
);
976 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
977 IntReleaseMenuObject(NewMenu
);
978 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
980 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
981 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
982 ItemInfo
.fType
= MF_POPUP
;
983 ItemInfo
.fState
= MFS_ENABLED
;
984 ItemInfo
.dwTypeData
= NULL
;
986 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
987 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
989 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
993 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
1002 if(Window
->SystemMenu
)
1003 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
1011 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
1015 Window
= BaseWindow
;
1016 while (Window
&& ((Window
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
1018 if (Window
== Parent
)
1023 Window
= Window
->spwndParent
;
1030 Link the window into siblings list
1031 children and parent are kept in place.
1036 PWND WndInsertAfter
/* set to NULL if top sibling */
1039 if ((Wnd
->spwndPrev
= WndInsertAfter
))
1041 /* link after WndInsertAfter */
1042 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
1043 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1045 Wnd
->spwndPrev
->spwndNext
= Wnd
;
1050 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
1051 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1053 Wnd
->spwndParent
->spwndChild
= Wnd
;
1058 Note: Wnd->spwndParent can be null if it is the desktop.
1060 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
1062 if (hWndPrev
== HWND_NOTOPMOST
)
1064 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1065 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
1066 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1067 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
1070 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
1072 if (hWndPrev
== HWND_BOTTOM
)
1074 /* Link in the bottom of the list */
1075 PWND WndInsertAfter
;
1077 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
1078 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
1079 WndInsertAfter
= WndInsertAfter
->spwndNext
;
1081 IntLinkWindow(Wnd
, WndInsertAfter
);
1082 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1084 else if (hWndPrev
== HWND_TOPMOST
)
1086 /* Link in the top of the list */
1087 IntLinkWindow(Wnd
, NULL
);
1089 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1091 else if (hWndPrev
== HWND_TOP
)
1093 /* Link it after the last topmost window */
1094 PWND WndInsertBefore
;
1096 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
1098 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
1100 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
1102 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
1103 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
1105 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1108 WndInsertBefore
= WndInsertBefore
->spwndNext
;
1112 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
1116 /* Link it after hWndPrev */
1117 PWND WndInsertAfter
;
1119 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1120 /* Are we called with an erroneous handle */
1121 if(WndInsertAfter
== NULL
)
1123 /* Link in a default position */
1124 IntLinkHwnd(Wnd
, HWND_TOP
);
1128 IntLinkWindow(Wnd
, WndInsertAfter
);
1130 /* Fix the WS_EX_TOPMOST flag */
1131 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1133 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1137 if(WndInsertAfter
->spwndNext
&&
1138 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1140 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1144 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
1148 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
1152 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
1155 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
1156 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1158 //ERR("ProcessOwnerSwap Old out.\n");
1159 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
1165 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
1168 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1170 //ERR("ProcessOwnerSwap New in.\n");
1171 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1175 // FIXME: System Tray checks.
1179 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1181 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1184 Wnd
= IntGetWindowObject(hWnd
);
1188 WndOldOwner
= Wnd
->spwndOwner
;
1190 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1191 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1193 if (!WndNewOwner
&& hWndNewOwner
)
1195 EngSetLastError(ERROR_INVALID_PARAMETER
);
1200 /* if parent belongs to a different thread and the window isn't */
1201 /* top-level, attach the two threads */
1202 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1204 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1208 Wnd
->spwndOwner
= WndNewOwner
;
1212 Wnd
->spwndOwner
= NULL
;
1217 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1218 EngSetLastError(ERROR_INVALID_PARAMETER
);
1222 UserDereferenceObject(Wnd
);
1227 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1229 PWND WndOldParent
, pWndExam
;
1232 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1235 ASSERT(WndNewParent
);
1236 ASSERT_REFS_CO(Wnd
);
1237 ASSERT_REFS_CO(WndNewParent
);
1239 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1241 EngSetLastError(ERROR_ACCESS_DENIED
);
1245 /* Some applications try to set a child as a parent */
1246 if (IntIsChildWindow(Wnd
, WndNewParent
))
1248 TRACE("IntSetParent try to set a child as a parent.\n");
1249 EngSetLastError( ERROR_INVALID_PARAMETER
);
1253 pWndExam
= WndNewParent
; // Load parent Window to examine.
1254 // Now test for set parent to parent hit.
1257 if (Wnd
== pWndExam
)
1259 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1260 EngSetLastError(ERROR_INVALID_PARAMETER
);
1263 pWndExam
= pWndExam
->spwndParent
;
1267 * Windows hides the window first, then shows it again
1268 * including the WM_SHOWWINDOW messages and all
1270 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1272 /* Window must belong to current process */
1273 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1275 ERR("IntSetParent Window must belong to current process!\n");
1279 WndOldParent
= Wnd
->spwndParent
;
1281 if ( WndOldParent
&&
1282 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1283 pt
.x
= Wnd
->rcWindow
.right
;
1285 pt
.x
= Wnd
->rcWindow
.left
;
1286 pt
.y
= Wnd
->rcWindow
.top
;
1288 IntScreenToClient(WndOldParent
, &pt
);
1290 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1292 if (WndNewParent
!= WndOldParent
)
1294 /* Unlink the window from the siblings list */
1295 IntUnlinkWindow(Wnd
);
1296 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1298 /* Set the new parent */
1299 Wnd
->spwndParent
= WndNewParent
;
1301 if ( Wnd
->style
& WS_CHILD
&&
1303 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1305 ERR("SetParent Top Most from Pop up!\n");
1306 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1309 /* Link the window with its new siblings */
1311 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1312 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1316 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1317 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1319 Wnd
->style
|= WS_CLIPSIBLINGS
;
1320 DceResetActiveDCEs(Wnd
);
1323 /* if parent belongs to a different thread and the window isn't */
1324 /* top-level, attach the two threads */
1325 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1327 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1329 if (Wnd
->head
.pti
!= WndOldParent
->head
.pti
)
1331 //ERR("SetParent Old out.\n");
1332 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1335 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1337 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1339 //ERR("SetParent New in.\n");
1340 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1345 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1346 swFlags
|= SWP_NOACTIVATE
;
1348 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1350 * SetParent additionally needs to make hwnd the top window
1351 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1352 * WM_WINDOWPOSCHANGED notification messages.
1354 //ERR("IntSetParent SetWindowPos 1\n");
1355 co_WinPosSetWindowPos( Wnd
,
1356 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1357 pt
.x
, pt
.y
, 0, 0, swFlags
);
1358 //ERR("IntSetParent SetWindowPos 2\n");
1359 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1361 return WndOldParent
;
1365 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1367 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1368 HWND hWndOldParent
= NULL
;
1369 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1371 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1373 EngSetLastError(ERROR_INVALID_PARAMETER
);
1377 if (hWndChild
== IntGetDesktopWindow())
1379 ERR("UserSetParent Access Denied!\n");
1380 EngSetLastError(ERROR_ACCESS_DENIED
);
1386 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1388 ERR("UserSetParent Bad New Parent!\n");
1394 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1400 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1402 ERR("UserSetParent Bad Child!\n");
1406 UserRefObjectCo(Wnd
, &Ref
);
1407 UserRefObjectCo(WndParent
, &ParentRef
);
1408 //ERR("Enter co_IntSetParent\n");
1409 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1410 //ERR("Leave co_IntSetParent\n");
1411 UserDerefObjectCo(WndParent
);
1412 UserDerefObjectCo(Wnd
);
1416 hWndOldParent
= WndOldParent
->head
.h
;
1417 UserDereferenceObject(WndOldParent
);
1420 return( hWndOldParent
);
1424 IntSetSystemMenu(PWND Window
, PMENU_OBJECT Menu
)
1426 PMENU_OBJECT OldMenu
;
1427 if(Window
->SystemMenu
)
1429 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1432 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1433 IntReleaseMenuObject(OldMenu
);
1439 /* FIXME: Check window style, propably return FALSE? */
1440 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1441 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1444 Window
->SystemMenu
= (HMENU
)0;
1449 /* Unlink the window from siblings. children and parent are kept in place. */
1451 IntUnlinkWindow(PWND Wnd
)
1454 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1457 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1459 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1460 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1462 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1465 /* FUNCTIONS *****************************************************************/
1468 * As best as I can figure, this function is used by EnumWindows,
1469 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1471 * It's supposed to build a list of HWNDs to return to the caller.
1472 * We can figure out what kind of list by what parameters are
1480 NtUserBuildHwndList(
1493 return ERROR_INVALID_PARAMETER
;
1495 if (hwndParent
|| !dwThreadId
)
1498 PWND Parent
, Window
;
1502 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1504 return ERROR_INVALID_HANDLE
;
1509 Status
= IntValidateDesktopHandle(hDesktop
,
1513 if(!NT_SUCCESS(Status
))
1515 return ERROR_INVALID_HANDLE
;
1518 hwndParent
= Desktop
->DesktopWindow
;
1525 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1526 (Window
= Parent
->spwndChild
))
1528 BOOL bGoDown
= TRUE
;
1530 Status
= STATUS_SUCCESS
;
1535 if(dwCount
++ < *pBufSize
&& pWnd
)
1539 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1540 *pWnd
= Window
->head
.h
;
1543 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1545 Status
= _SEH2_GetExceptionCode();
1548 if(!NT_SUCCESS(Status
))
1550 SetLastNtError(Status
);
1554 if (Window
->spwndChild
&& bChildren
)
1556 Window
= Window
->spwndChild
;
1561 if (Window
->spwndNext
)
1563 Window
= Window
->spwndNext
;
1567 Window
= Window
->spwndParent
;
1568 if (Window
== Parent
)
1577 ObDereferenceObject(Desktop
);
1580 else // Build EnumThreadWindows list!
1583 PTHREADINFO W32Thread
;
1584 PLIST_ENTRY Current
;
1587 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1588 if (!NT_SUCCESS(Status
))
1590 ERR("Thread Id is not valid!\n");
1591 return ERROR_INVALID_PARAMETER
;
1593 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1595 ObDereferenceObject(Thread
);
1596 ERR("Thread is not initialized!\n");
1597 return ERROR_INVALID_PARAMETER
;
1600 Current
= W32Thread
->WindowListHead
.Flink
;
1601 while (Current
!= &(W32Thread
->WindowListHead
))
1603 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1606 if (dwCount
< *pBufSize
&& pWnd
)
1610 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1611 *pWnd
= Window
->head
.h
;
1614 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1616 Status
= _SEH2_GetExceptionCode();
1619 if (!NT_SUCCESS(Status
))
1621 ERR("Failure to build window list!\n");
1622 SetLastNtError(Status
);
1627 Current
= Window
->ThreadListEntry
.Flink
;
1630 ObDereferenceObject(Thread
);
1633 *pBufSize
= dwCount
;
1634 return STATUS_SUCCESS
;
1637 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1639 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1640 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1642 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1644 USER_REFERENCE_ENTRY Ref
;
1645 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1646 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1648 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1649 (LPARAM
)pWindow
->head
.h
);
1650 UserDerefObjectCo(pWindow
->spwndParent
);
1656 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1658 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1660 /* default positioning for overlapped windows */
1661 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1664 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1666 pMonitor
= UserGetPrimaryMonitor();
1668 /* Check if we don't have a monitor attached yet */
1669 if(pMonitor
== NULL
)
1677 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1679 if (IS_DEFAULT(Cs
->x
))
1681 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1683 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1685 Cs
->x
= ProcessParams
->StartingX
;
1686 Cs
->y
= ProcessParams
->StartingY
;
1690 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1691 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1692 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1693 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1695 /* reset counter and position */
1698 pMonitor
->cWndStack
= 0;
1700 pMonitor
->cWndStack
++;
1704 if (IS_DEFAULT(Cs
->cx
))
1706 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1708 Cs
->cx
= ProcessParams
->CountX
;
1709 Cs
->cy
= ProcessParams
->CountY
;
1713 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1714 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1717 /* neither x nor cx are default. Check the y values .
1718 * In the trace we see Outlook and Outlook Express using
1719 * cy set to CW_USEDEFAULT when opening the address book.
1721 else if (IS_DEFAULT(Cs
->cy
))
1723 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1724 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1729 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1730 if(IS_DEFAULT(Cs
->x
))
1735 if(IS_DEFAULT(Cs
->cx
))
1745 /* Allocates and initializes a window */
1746 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1747 PLARGE_STRING WindowName
,
1752 PDESKTOP pdeskCreated
)
1756 PTHREADINFO pti
= NULL
;
1757 PMENU_OBJECT SystemMenu
;
1759 BOOL bUnicodeWindow
;
1761 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1763 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1767 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1768 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1769 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1770 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1774 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1776 * Dialog boxes and message boxes do not inherit layout, so you must
1777 * set the layout explicitly.
1779 if ( Class
->fnid
!= FNID_DIALOG
)
1781 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1783 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1789 /* Automatically add WS_EX_WINDOWEDGE */
1790 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1791 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1792 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1793 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1795 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1797 /* Is it a unicode window? */
1798 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1799 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1801 /* Allocate the new window */
1802 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1803 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1807 sizeof(WND
) + Class
->cbwndExtra
);
1814 TRACE("Created window object with handle %p\n", hWnd
);
1816 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1817 { /* HACK: Helper for win32csr/desktopbg.c */
1818 /* If there is no desktop window yet, we must be creating it */
1819 TRACE("CreateWindow setting desktop.\n");
1820 pdeskCreated
->DesktopWindow
= hWnd
;
1821 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1825 * Fill out the structure describing it.
1827 /* Remember, pWnd->head is setup in object.c ... */
1828 pWnd
->spwndParent
= ParentWindow
;
1829 pWnd
->spwndOwner
= OwnerWindow
;
1831 pWnd
->spwndLastActive
= pWnd
;
1832 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1834 pWnd
->hModule
= Cs
->hInstance
;
1835 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1836 pWnd
->ExStyle
= Cs
->dwExStyle
;
1837 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1838 pWnd
->pActCtx
= acbiBuffer
;
1839 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1840 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1842 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1844 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1845 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1848 pWnd
->head
.pti
->cWindows
++;
1850 if (Class
->hIcon
&& !Class
->hIconSm
)
1852 Class
->hIconSmIntern
= co_IntCopyImage( Class
->hIcon
, IMAGE_ICON
,
1853 UserGetSystemMetrics( SM_CXSMICON
),
1854 UserGetSystemMetrics( SM_CYSMICON
), 0 );
1855 TRACE("IntCreateWindow hIconSmIntern %p\n",Class
->hIconSmIntern
);
1856 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1859 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1860 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1862 /* BugBoy Comments: Comment below say that System classes are always created
1863 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1864 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1866 No where can I see in code or through testing does the window change back
1867 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1868 see what problems this would cause. */
1870 // Set WndProc from Class.
1871 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1873 // GetWindowProc, test for non server side default classes and set WndProc.
1874 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1878 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1879 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1883 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1884 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1888 // If not an Unicode caller, set Ansi creator bit.
1889 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1891 // Clone Class Ansi/Unicode proc type.
1892 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1894 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1895 pWnd
->Unicode
= FALSE
;
1899 * It seems there can be both an Ansi creator and Unicode Class Window
1900 * WndProc, unless the following overriding conditions occur:
1902 if ( !bUnicodeWindow
&&
1903 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1904 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1905 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1906 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1907 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1908 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1909 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1910 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1911 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1912 { // Override Class and set the window Ansi WndProc.
1913 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1914 pWnd
->Unicode
= FALSE
;
1917 { // Set the window Unicode WndProc.
1918 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1919 pWnd
->Unicode
= TRUE
;
1923 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1924 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1925 Dont understand why it does this. */
1926 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1928 PCALLPROCDATA CallProc
;
1929 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1933 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1934 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1938 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1942 InitializeListHead(&pWnd
->PropListHead
);
1944 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1946 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1947 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1948 if (pWnd
->strName
.Buffer
== NULL
)
1953 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1954 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1955 pWnd
->strName
.Length
= WindowName
->Length
;
1956 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1959 /* Correct the window style. */
1960 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1962 pWnd
->style
|= WS_CLIPSIBLINGS
;
1963 if (!(pWnd
->style
& WS_POPUP
))
1965 pWnd
->style
|= WS_CAPTION
;
1969 /* WS_EX_WINDOWEDGE depends on some other styles */
1970 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1971 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1972 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1974 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1975 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1976 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1979 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1981 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1982 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1984 /* Create system menu */
1985 if ((Cs
->style
& WS_SYSMENU
)) // && (dwStyle & WS_CAPTION) == WS_CAPTION)
1987 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1990 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1991 IntReleaseMenuObject(SystemMenu
);
1995 /* Set the window menu */
1996 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1999 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
2000 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
2002 UNICODE_STRING MenuName
;
2005 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
2007 MenuName
.Length
= 0;
2008 MenuName
.MaximumLength
= 0;
2009 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
2013 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
2015 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
2016 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
2020 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
2023 if ( ParentWindow
&&
2024 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
2025 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
2027 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
2029 if (!IntValidateOwnerDepth(pWnd
, Owner
))
2031 EngSetLastError(ERROR_INVALID_PARAMETER
);
2034 if ( pWnd
->spwndOwner
&&
2035 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
2037 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
2039 if ( pWnd
->spwndOwner
&&
2040 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
2041 pti
!= pWnd
->spwndOwner
->head
.pti
)
2043 //ERR("CreateWindow Owner in.\n");
2044 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
2048 /* Insert the window into the thread's window list. */
2049 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
2051 /* Handle "CS_CLASSDC", it is tested first. */
2052 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
2053 { /* One DCE per class to have CLASS. */
2054 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
2056 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
2057 { /* Allocate a DCE for this window. */
2058 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
2064 ERR("IntCreateWindow Allocation Error.\n");
2065 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
2068 UserDereferenceObject(pWnd
);
2076 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
2077 PUNICODE_STRING ClassName
,
2078 PLARGE_STRING WindowName
,
2082 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
2083 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
2084 PWINSTATION_OBJECT WinSta
;
2087 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2088 CBT_CREATEWNDW
* pCbtCreate
;
2090 USER_REFERENCE_ENTRY ParentRef
, Ref
;
2092 DWORD dwShowMode
= SW_SHOW
;
2093 CREATESTRUCTW
*pCsw
= NULL
;
2094 PVOID pszClass
= NULL
, pszName
= NULL
;
2097 /* Get the current window station and reference it */
2098 pti
= GetW32ThreadInfo();
2099 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
2101 ERR("Thread is not attached to a desktop! Cannot create window!\n");
2102 return NULL
; // There is nothing to cleanup.
2104 WinSta
= pti
->rpdesk
->rpwinstaParent
;
2105 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
2110 /* Get the class and reference it */
2111 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
2114 ERR("Failed to find class %wZ\n", ClassName
);
2118 /* Now find the parent and the owner window */
2119 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
2122 if (Cs
->hwndParent
== HWND_MESSAGE
)
2124 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
2126 else if (Cs
->hwndParent
)
2128 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
2129 hWndOwner
= Cs
->hwndParent
;
2131 hWndParent
= Cs
->hwndParent
;
2133 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2135 ERR("Cannot create a child window without a parrent!\n");
2136 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
2137 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
2140 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
2141 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
2143 /* FIXME: Is this correct? */
2145 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
2147 /* Fix the position and the size of the window */
2150 UserRefObjectCo(ParentWindow
, &ParentRef
);
2151 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2154 /* Allocate and initialize the new window */
2155 Window
= IntCreateWindow(Cs
,
2164 ERR("IntCreateWindow failed!\n");
2168 hWnd
= UserHMGetHandle(Window
);
2169 hwndInsertAfter
= HWND_TOP
;
2171 UserRefObjectCo(Window
, &Ref
);
2172 UserDereferenceObject(Window
);
2173 ObDereferenceObject(WinSta
);
2175 //// Check for a hook to eliminate overhead. ////
2176 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2178 // Allocate the calling structures Justin Case this goes Global.
2179 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2180 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2181 if (!pCsw
|| !pCbtCreate
)
2183 ERR("UserHeapAlloc() failed!\n");
2187 /* Fill the new CREATESTRUCTW */
2188 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2189 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2191 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2192 if (!IS_ATOM(ClassName
->Buffer
))
2194 if (Window
->state
& WNDS_ANSICREATOR
)
2196 ANSI_STRING AnsiString
;
2197 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2198 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2201 ERR("UserHeapAlloc() failed!\n");
2204 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2205 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2206 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2210 UNICODE_STRING UnicodeString
;
2211 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2212 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2215 ERR("UserHeapAlloc() failed!\n");
2218 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2219 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2220 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2222 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2224 if (WindowName
->Length
)
2226 UNICODE_STRING Name
;
2227 Name
.Buffer
= WindowName
->Buffer
;
2228 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2229 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2231 if (Window
->state
& WNDS_ANSICREATOR
)
2233 ANSI_STRING AnsiString
;
2234 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2235 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2238 ERR("UserHeapAlloc() failed!\n");
2241 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2242 AnsiString
.Buffer
= (PCHAR
)pszName
;
2243 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2247 UNICODE_STRING UnicodeString
;
2248 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2249 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2252 ERR("UserHeapAlloc() failed!\n");
2255 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2256 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2257 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2259 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2262 pCbtCreate
->lpcs
= pCsw
;
2263 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2265 //// Call the WH_CBT hook ////
2266 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2269 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2272 // Write back changes.
2277 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2280 /* NCCREATE and WM_NCCALCSIZE need the original values */
2281 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2282 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2284 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2286 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2288 Cs
->x
+= ParentWindow
->rcClient
.left
;
2289 Cs
->y
+= ParentWindow
->rcClient
.top
;
2293 /* Send the WM_GETMINMAXINFO message */
2297 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2299 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2300 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2301 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2302 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2303 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2306 Window
->rcWindow
.left
= Cs
->x
;
2307 Window
->rcWindow
.top
= Cs
->y
;
2308 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2309 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2311 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2313 // ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2314 RECTL_vOffsetRect(&Window->rcWindow,
2315 ParentWindow->rcClient.left,
2316 ParentWindow->rcClient.top);
2319 Window
->rcClient
= Window
->rcWindow
;
2321 /* Link the window */
2322 if (NULL
!= ParentWindow
)
2324 /* Link the window into the siblings list */
2325 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2326 IntLinkHwnd(Window
, HWND_BOTTOM
);
2328 IntLinkHwnd(Window
, hwndInsertAfter
);
2331 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2333 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2334 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2337 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2339 if ( !IntIsTopLevelWindow(Window
) )
2341 if (pti
!= Window
->spwndParent
->head
.pti
)
2343 //ERR("CreateWindow Parent in.\n");
2344 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2349 /* Send the NCCREATE message */
2350 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2353 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2357 /* Send the WM_NCCALCSIZE message */
2360 MaxPos
.x
= Window
->rcWindow
.left
;
2361 MaxPos
.y
= Window
->rcWindow
.top
;
2363 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2364 //rc = Window->rcWindow;
2365 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2366 //Window->rcClient = rc;
2368 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2369 MaxPos
.y
- Window
->rcWindow
.top
);
2372 /* Send the WM_CREATE message. */
2373 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2374 if (Result
== (LRESULT
)-1)
2376 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2380 /* Send the EVENT_OBJECT_CREATE event */
2381 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2383 /* By setting the flag below it can be examined to determine if the window
2384 was created successfully and a valid pwnd was passed back to caller since
2385 from here the function has to succeed. */
2386 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2388 /* Send the WM_SIZE and WM_MOVE messages. */
2389 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2391 co_WinPosSendSizeMove(Window
);
2394 /* Show or maybe minimize or maximize the window. */
2396 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2397 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2400 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2402 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2403 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2404 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2405 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2406 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2409 /* Send the WM_PARENTNOTIFY message */
2410 IntSendParentNotify(Window
, WM_CREATE
);
2412 /* Notify the shell that a new window was created */
2413 if ((!hWndParent
) && (!hWndOwner
))
2415 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2418 /* Initialize and show the window's scrollbars */
2419 if (Window
->style
& WS_VSCROLL
)
2421 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2423 if (Window
->style
& WS_HSCROLL
)
2425 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2428 /* Show the new window */
2429 if (Cs
->style
& WS_VISIBLE
)
2431 if (Window
->style
& WS_MAXIMIZE
)
2432 dwShowMode
= SW_SHOW
;
2433 else if (Window
->style
& WS_MINIMIZE
)
2434 dwShowMode
= SW_SHOWMINIMIZED
;
2436 co_WinPosShowWindow(Window
, dwShowMode
);
2438 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2440 ASSERT(ParentWindow
);
2443 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2444 /* ShowWindow won't activate child windows */
2445 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2449 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2455 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2456 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2458 co_UserDestroyWindow(Window
);
2460 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2463 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2464 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2465 if (pszName
) UserHeapFree(pszName
);
2466 if (pszClass
) UserHeapFree(pszClass
);
2470 UserDerefObjectCo(Window
);
2472 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2479 ProbeAndCaptureLargeString(
2480 OUT PLARGE_STRING plstrSafe
,
2481 IN PLARGE_STRING plstrUnsafe
)
2483 LARGE_STRING lstrTemp
;
2484 PVOID pvBuffer
= NULL
;
2488 /* Probe and copy the string */
2489 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2490 lstrTemp
= *plstrUnsafe
;
2492 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2495 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2499 if (lstrTemp
.Length
!= 0)
2501 /* Allocate a buffer from paged pool */
2502 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2505 return STATUS_NO_MEMORY
;
2510 /* Probe and copy the buffer */
2511 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2512 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2514 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2516 /* Cleanup and fail */
2517 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2518 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2523 /* Set the output string */
2524 plstrSafe
->Buffer
= pvBuffer
;
2525 plstrSafe
->Length
= lstrTemp
.Length
;
2526 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2528 return STATUS_SUCCESS
;
2532 * \todo Allow passing plstrClassName as ANSI.
2536 NtUserCreateWindowEx(
2538 PLARGE_STRING plstrClassName
,
2539 PLARGE_STRING plstrClsVersion
,
2540 PLARGE_STRING plstrWindowName
,
2548 HINSTANCE hInstance
,
2554 LARGE_STRING lstrWindowName
;
2555 LARGE_STRING lstrClassName
;
2556 UNICODE_STRING ustrClassName
;
2561 lstrWindowName
.Buffer
= NULL
;
2562 lstrClassName
.Buffer
= NULL
;
2564 ASSERT(plstrWindowName
);
2566 /* Copy the window name to kernel mode */
2567 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2568 if (!NT_SUCCESS(Status
))
2570 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2571 SetLastNtError(Status
);
2575 plstrWindowName
= &lstrWindowName
;
2577 /* Check if the class is an atom */
2578 if (IS_ATOM(plstrClassName
))
2580 /* It is, pass the atom in the UNICODE_STRING */
2581 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2582 ustrClassName
.Length
= 0;
2583 ustrClassName
.MaximumLength
= 0;
2587 /* It's not, capture the class name */
2588 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2589 if (!NT_SUCCESS(Status
))
2591 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2592 /* Set last error, cleanup and return */
2593 SetLastNtError(Status
);
2597 /* We pass it on as a UNICODE_STRING */
2598 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2599 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2600 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2603 /* Fill the CREATESTRUCTW */
2604 /* we will keep here the original parameters */
2606 Cs
.lpCreateParams
= lpParam
;
2607 Cs
.hInstance
= hInstance
;
2609 Cs
.hwndParent
= hWndParent
;
2614 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2615 if (IS_ATOM(plstrClassName
))
2616 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2618 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2619 Cs
.dwExStyle
= dwExStyle
;
2621 UserEnterExclusive();
2623 /* Call the internal function */
2624 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
);
2628 ERR("co_UserCreateWindowEx failed!\n");
2630 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2635 if (lstrWindowName
.Buffer
)
2637 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2639 if (lstrClassName
.Buffer
)
2641 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2648 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2655 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2657 hWnd
= Window
->head
.h
;
2658 ti
= PsGetCurrentThreadWin32Thread();
2660 TRACE("co_UserDestroyWindow \n");
2662 /* Check for owner thread */
2663 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2665 /* Check if we are destroying the desktop window */
2666 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2668 EngSetLastError(ERROR_ACCESS_DENIED
);
2673 /* If window was created successfully and it is hooked */
2674 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2676 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2678 ERR("Destroy Window WH_CBT Call Hook return!\n");
2683 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2685 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2687 if (Window
->spwndOwner
)
2689 //ERR("DestroyWindow Owner out.\n");
2690 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2695 /* Inform the parent */
2696 if (Window
->style
& WS_CHILD
)
2698 IntSendParentNotify(Window
, WM_DESTROY
);
2701 /* Look whether the focus is within the tree of windows we will
2704 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2706 if (ti
->MessageQueue
->spwndActive
== Window
&& ti
->MessageQueue
== IntGetFocusMessageQueue())
2708 co_WinPosActivateOtherWindow(Window
);
2712 // Adjust last active.
2713 if ((pwndTemp
= Window
->spwndOwner
))
2715 while (pwndTemp
->spwndOwner
)
2716 pwndTemp
= pwndTemp
->spwndOwner
;
2718 if (pwndTemp
->spwndLastActive
== Window
)
2719 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2722 if (Window
->spwndParent
&& IntIsWindow(Window
->head
.h
))
2724 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2726 if (!IntIsTopLevelWindow(Window
))
2728 //ERR("DestroyWindow Parent out.\n");
2729 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2734 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2735 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2736 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2737 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2738 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2739 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2740 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2741 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2744 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2747 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2749 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2751 ERR("Destroying the ShellWindow!\n");
2752 ti
->pDeskInfo
->hShellWindow
= NULL
;
2756 IntEngWindowChanged(Window
, WOC_DELETE
);
2758 if (!IntIsWindow(Window
->head
.h
))
2763 /* Recursively destroy owned windows */
2765 if (! (Window
->style
& WS_CHILD
))
2769 BOOL GotOne
= FALSE
;
2772 PWND Child
, Desktop
;
2774 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2775 UserGetWindowObject(IntGetDesktopWindow());
2776 Children
= IntWinListChildren(Desktop
);
2780 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2782 Child
= UserGetWindowObject(*ChildHandle
);
2785 if (Child
->spwndOwner
!= Window
)
2790 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2792 USER_REFERENCE_ENTRY ChildRef
;
2793 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2794 co_UserDestroyWindow(Child
);
2795 UserDerefObjectCo(Child
); // Temp HACK?
2801 if (Child
->spwndOwner
!= NULL
)
2803 Child
->spwndOwner
= NULL
;
2807 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2816 /* Generate mouse move message for the next window */
2817 msg
.message
= WM_MOUSEMOVE
;
2818 msg
.wParam
= UserGetMouseButtonsState();
2819 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2820 msg
.pt
= gpsi
->ptCursor
;
2821 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2823 if (!IntIsWindow(Window
->head
.h
))
2828 /* Destroy the window storage */
2829 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2839 NtUserDestroyWindow(HWND Wnd
)
2842 DECLARE_RETURN(BOOLEAN
);
2844 USER_REFERENCE_ENTRY Ref
;
2846 TRACE("Enter NtUserDestroyWindow\n");
2847 UserEnterExclusive();
2849 if (!(Window
= UserGetWindowObject(Wnd
)))
2854 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2855 ret
= co_UserDestroyWindow(Window
);
2856 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2861 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2867 static HWND FASTCALL
2868 IntFindWindow(PWND Parent
,
2871 PUNICODE_STRING WindowName
)
2873 BOOL CheckWindowName
;
2876 UNICODE_STRING CurrentWindowName
;
2880 CheckWindowName
= WindowName
->Buffer
!= 0;
2882 if((List
= IntWinListChildren(Parent
)))
2887 /* skip handles before and including ChildAfter */
2888 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2892 /* search children */
2896 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2901 /* Do not send WM_GETTEXT messages in the kernel mode version!
2902 The user mode version however calls GetWindowText() which will
2903 send WM_GETTEXT messages to windows belonging to its processes */
2904 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2906 // FIXME: LARGE_STRING truncated
2907 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2908 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2909 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2910 if(!CheckWindowName
||
2911 (Child
->strName
.Length
< 0xFFFF &&
2912 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2914 Ret
= Child
->head
.h
;
2919 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2927 * Searches a window's children for a window with the specified
2930 * hwndParent = The window whose childs are to be searched.
2932 * HWND_MESSAGE = message-only windows
2934 * hwndChildAfter = Search starts after this child window.
2935 * NULL = start from beginning
2937 * ucClassName = Class name to search for
2938 * Reguired parameter.
2940 * ucWindowName = Window name
2941 * ->Buffer == NULL = don't care
2944 * The HWND of the window if it was found, otherwise NULL
2950 NtUserFindWindowEx(HWND hwndParent
,
2951 HWND hwndChildAfter
,
2952 PUNICODE_STRING ucClassName
,
2953 PUNICODE_STRING ucWindowName
,
2956 PWND Parent
, ChildAfter
;
2957 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2958 HWND Desktop
, Ret
= NULL
;
2959 BOOL DoMessageWnd
= FALSE
;
2960 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2961 DECLARE_RETURN(HWND
);
2963 TRACE("Enter NtUserFindWindowEx\n");
2966 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2970 if (ucClassName
!= NULL
)
2972 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2973 if (ClassName
.Length
!= 0)
2975 ProbeForRead(ClassName
.Buffer
,
2979 else if (!IS_ATOM(ClassName
.Buffer
))
2981 EngSetLastError(ERROR_INVALID_PARAMETER
);
2985 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2992 if (ucWindowName
!= NULL
)
2994 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2995 if (WindowName
.Length
!= 0)
2997 ProbeForRead(WindowName
.Buffer
,
3003 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3005 SetLastNtError(_SEH2_GetExceptionCode());
3006 _SEH2_YIELD(RETURN(NULL
));
3010 if (ucClassName
!= NULL
)
3012 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
3013 !IS_ATOM(ClassName
.Buffer
))
3015 EngSetLastError(ERROR_INVALID_PARAMETER
);
3018 else if (ClassAtom
== (RTL_ATOM
)0)
3020 /* LastError code was set by IntGetAtomFromStringOrAtom */
3026 Desktop
= IntGetCurrentThreadDesktopWindow();
3028 if(hwndParent
== NULL
)
3030 hwndParent
= Desktop
;
3031 DoMessageWnd
= TRUE
;
3033 else if(hwndParent
== HWND_MESSAGE
)
3035 hwndParent
= IntGetMessageWindow();
3038 if(!(Parent
= UserGetWindowObject(hwndParent
)))
3044 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
3051 if(Parent
->head
.h
== Desktop
)
3054 PWND TopLevelWindow
;
3055 BOOLEAN CheckWindowName
;
3056 BOOLEAN WindowMatches
;
3057 BOOLEAN ClassMatches
;
3059 /* windows searches through all top-level windows if the parent is the desktop
3062 if((List
= IntWinListChildren(Parent
)))
3068 /* skip handles before and including ChildAfter */
3069 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
3073 CheckWindowName
= WindowName
.Buffer
!= 0;
3075 /* search children */
3078 UNICODE_STRING ustr
;
3080 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
3085 /* Do not send WM_GETTEXT messages in the kernel mode version!
3086 The user mode version however calls GetWindowText() which will
3087 send WM_GETTEXT messages to windows belonging to its processes */
3088 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
3089 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
3090 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
3091 WindowMatches
= !CheckWindowName
||
3092 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
3093 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
3094 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
3095 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
3097 if (WindowMatches
&& ClassMatches
)
3099 Ret
= TopLevelWindow
->head
.h
;
3103 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3105 /* window returns the handle of the top-level window, in case it found
3107 Ret
= TopLevelWindow
->head
.h
;
3112 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3117 ERR("FindWindowEx: Not Desktop Parent!\n");
3118 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3121 if (Ret
== NULL
&& DoMessageWnd
)
3125 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3127 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3131 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3133 SetLastNtError(_SEH2_GetExceptionCode());
3141 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3150 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3152 PWND WndAncestor
, Parent
;
3154 if (Wnd
->head
.h
== IntGetDesktopWindow())
3163 WndAncestor
= Wnd
->spwndParent
;
3174 if(!(Parent
= WndAncestor
->spwndParent
))
3178 if(IntIsDesktopWindow(Parent
))
3183 WndAncestor
= Parent
;
3194 Parent
= IntGetParent(WndAncestor
);
3201 WndAncestor
= Parent
;
3219 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3221 PWND Window
, Ancestor
;
3222 DECLARE_RETURN(HWND
);
3224 TRACE("Enter NtUserGetAncestor\n");
3225 UserEnterExclusive();
3227 if (!(Window
= UserGetWindowObject(hWnd
)))
3232 Ancestor
= UserGetAncestor(Window
, Type
);
3233 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3235 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3238 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3246 NtUserGetComboBoxInfo(
3251 DECLARE_RETURN(BOOL
);
3253 TRACE("Enter NtUserGetComboBoxInfo\n");
3256 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3265 sizeof(COMBOBOXINFO
),
3269 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3271 SetLastNtError(_SEH2_GetExceptionCode());
3272 _SEH2_YIELD(RETURN(FALSE
));
3276 // Pass the user pointer, it was already probed.
3277 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3280 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3288 NtUserGetListBoxInfo(
3292 DECLARE_RETURN(DWORD
);
3294 TRACE("Enter NtUserGetListBoxInfo\n");
3297 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3302 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3305 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3313 * The NtUserSetParent function changes the parent window of the specified
3317 * The new parent window and the child window must belong to the same
3318 * application. If the window identified by the hWndChild parameter is
3319 * visible, the system performs the appropriate redrawing and repainting.
3320 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3321 * or WS_POPUP window styles of the window whose parent is being changed.
3328 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3330 DECLARE_RETURN(HWND
);
3332 TRACE("Enter NtUserSetParent\n");
3333 UserEnterExclusive();
3336 Check Parent first from user space, set it here.
3340 hWndNewParent
= IntGetDesktopWindow();
3342 else if (hWndNewParent
== HWND_MESSAGE
)
3344 hWndNewParent
= IntGetMessageWindow();
3347 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3350 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3356 * UserGetShellWindow
3358 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3363 HWND FASTCALL
UserGetShellWindow(VOID
)
3365 PWINSTATION_OBJECT WinStaObject
;
3368 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3373 if (!NT_SUCCESS(Status
))
3375 SetLastNtError(Status
);
3379 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3381 ObDereferenceObject(WinStaObject
);
3386 * NtUserSetShellWindowEx
3388 * This is undocumented function to set global shell window. The global
3389 * shell window has special handling of window position.
3395 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3397 PWINSTATION_OBJECT WinStaObject
;
3398 PWND WndShell
, WndListView
;
3399 DECLARE_RETURN(BOOL
);
3400 USER_REFERENCE_ENTRY Ref
;
3404 TRACE("Enter NtUserSetShellWindowEx\n");
3405 UserEnterExclusive();
3407 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3412 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3417 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3422 if (!NT_SUCCESS(Status
))
3424 SetLastNtError(Status
);
3429 * Test if we are permitted to change the shell window.
3431 if (WinStaObject
->ShellWindow
)
3433 ObDereferenceObject(WinStaObject
);
3438 * Move shell window into background.
3440 if (hwndListView
&& hwndListView
!= hwndShell
)
3443 * Disabled for now to get Explorer working.
3444 * -- Filip, 01/nov/2003
3447 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3450 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3452 ObDereferenceObject(WinStaObject
);
3457 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3459 ObDereferenceObject(WinStaObject
);
3463 UserRefObjectCo(WndShell
, &Ref
);
3464 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3465 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3467 WinStaObject
->ShellWindow
= hwndShell
;
3468 WinStaObject
->ShellListView
= hwndListView
;
3470 ti
= GetW32ThreadInfo();
3473 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3474 ti
->pDeskInfo
->spwndShell
= WndShell
;
3475 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3478 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3480 UserDerefObjectCo(WndShell
);
3482 ObDereferenceObject(WinStaObject
);
3486 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3492 * NtUserGetSystemMenu
3494 * The NtUserGetSystemMenu function allows the application to access the
3495 * window menu (also known as the system menu or the control menu) for
3496 * copying and modifying.
3500 * Handle to the window that will own a copy of the window menu.
3502 * Specifies the action to be taken. If this parameter is FALSE,
3503 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3504 * currently in use. The copy is initially identical to the window menu
3505 * but it can be modified.
3506 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3507 * to the default state. The previous window menu, if any, is destroyed.
3510 * If the bRevert parameter is FALSE, the return value is a handle to a
3511 * copy of the window menu. If the bRevert parameter is TRUE, the return
3519 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3523 DECLARE_RETURN(HMENU
);
3525 TRACE("Enter NtUserGetSystemMenu\n");
3528 if (!(Window
= UserGetWindowObject(hWnd
)))
3533 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3538 RETURN(Menu
->MenuInfo
.Self
);
3541 TRACE("Leave NtUserGetSystemMenu, ret=%p\n", _ret_
);
3547 * NtUserSetSystemMenu
3554 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3556 BOOL Result
= FALSE
;
3559 DECLARE_RETURN(BOOL
);
3561 TRACE("Enter NtUserSetSystemMenu\n");
3562 UserEnterExclusive();
3564 if (!(Window
= UserGetWindowObject(hWnd
)))
3572 * Assign new menu handle.
3574 if (!(Menu
= UserGetMenuObject(hMenu
)))
3579 Result
= IntSetSystemMenu(Window
, Menu
);
3585 TRACE("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3590 // Fixes wine Win test_window_styles and todo tests...
3591 static BOOL FASTCALL
3592 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3594 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3596 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3603 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3605 PWND Window
, Parent
;
3606 PWINSTATION_OBJECT WindowStation
;
3610 if (!(Window
= UserGetWindowObject(hWnd
)))
3615 if ((INT
)Index
>= 0)
3617 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3619 EngSetLastError(ERROR_INVALID_INDEX
);
3623 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3625 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3627 OldValue = (LONG)IntSetWindowProc( Wnd,
3630 if (!OldValue) return 0;
3633 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3640 OldValue
= (LONG
) Window
->ExStyle
;
3641 Style
.styleOld
= OldValue
;
3642 Style
.styleNew
= NewValue
;
3644 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3647 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3649 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3652 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3653 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3655 /* WS_EX_WINDOWEDGE depends on some other styles */
3656 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3657 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3659 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3661 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3662 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3666 OldValue
= (LONG
) Window
->style
;
3667 Style
.styleOld
= OldValue
;
3668 Style
.styleNew
= NewValue
;
3669 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3671 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3672 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3673 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3674 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3675 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3677 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3679 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3681 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3682 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3683 DceResetActiveDCEs( Window
);
3685 Window
->style
= (DWORD
)Style
.styleNew
;
3686 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3691 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3692 Window
->fnid
& FNID_FREED
)
3694 EngSetLastError(ERROR_ACCESS_DENIED
);
3697 OldValue
= (LONG
)IntSetWindowProc(Window
,
3704 OldValue
= (LONG
) Window
->hModule
;
3705 Window
->hModule
= (HINSTANCE
) NewValue
;
3708 case GWL_HWNDPARENT
:
3709 Parent
= Window
->spwndParent
;
3710 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3711 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3713 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3717 OldValue
= (LONG
) Window
->IDMenu
;
3718 Window
->IDMenu
= (UINT
) NewValue
;
3722 OldValue
= Window
->dwUserData
;
3723 Window
->dwUserData
= NewValue
;
3727 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3728 EngSetLastError(ERROR_INVALID_INDEX
);
3738 * NtUserSetWindowLong
3740 * The NtUserSetWindowLong function changes an attribute of the specified
3741 * window. The function also sets the 32-bit (long) value at the specified
3742 * offset into the extra window memory.
3749 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3751 DECLARE_RETURN(LONG
);
3753 TRACE("Enter NtUserSetWindowLong\n");
3754 UserEnterExclusive();
3756 if (hWnd
== IntGetDesktopWindow())
3758 EngSetLastError(STATUS_ACCESS_DENIED
);
3762 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3765 TRACE("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3771 * NtUserSetWindowWord
3773 * Legacy function similar to NtUserSetWindowLong.
3780 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3784 DECLARE_RETURN(WORD
);
3786 TRACE("Enter NtUserSetWindowWord\n");
3787 UserEnterExclusive();
3789 if (hWnd
== IntGetDesktopWindow())
3791 EngSetLastError(STATUS_ACCESS_DENIED
);
3795 if (!(Window
= UserGetWindowObject(hWnd
)))
3804 case GWL_HWNDPARENT
:
3805 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3809 EngSetLastError(ERROR_INVALID_INDEX
);
3814 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3816 EngSetLastError(ERROR_INVALID_PARAMETER
);
3820 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3821 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3826 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3832 QueryWindow based on KJK::Hyperion and James Tabor.
3834 0 = QWUniqueProcessId
3835 1 = QWUniqueThreadId
3838 4 = QWIsHung Implements IsHungAppWindow found
3841 9 = QWKillWindow When I called this with hWnd ==
3842 DesktopWindow, it shutdown the system
3849 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3851 /* Console Leader Process CID Window offsets */
3852 #define GWLP_CONSOLE_LEADER_PID 0
3853 #define GWLP_CONSOLE_LEADER_TID 4
3857 DECLARE_RETURN(UINT
);
3859 TRACE("Enter NtUserQueryWindow\n");
3862 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3869 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3871 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3872 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3874 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
3875 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
3879 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3884 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3886 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3887 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3889 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
3890 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
3894 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3899 case QUERY_WINDOW_ACTIVE
:
3900 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3903 case QUERY_WINDOW_FOCUS
:
3904 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3907 case QUERY_WINDOW_ISHUNG
:
3908 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
);
3911 case QUERY_WINDOW_REAL_ID
:
3912 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3915 case QUERY_WINDOW_FOREGROUND
:
3916 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3920 Result
= (DWORD
)NULL
;
3927 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
3937 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3939 UNICODE_STRING SafeMessageName
;
3942 DECLARE_RETURN(UINT
);
3944 TRACE("Enter NtUserRegisterWindowMessage\n");
3945 UserEnterExclusive();
3947 if(MessageNameUnsafe
== NULL
)
3949 EngSetLastError(ERROR_INVALID_PARAMETER
);
3953 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3954 if(!NT_SUCCESS(Status
))
3956 SetLastNtError(Status
);
3960 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3961 if (SafeMessageName
.Buffer
)
3962 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3966 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
3983 DECLARE_RETURN(BOOL
);
3985 TRACE("Enter NtUserSetMenu\n");
3986 UserEnterExclusive();
3988 if (!(Window
= UserGetWindowObject(hWnd
)))
3993 if (! IntSetMenu(Window
, Menu
, &Changed
))
3998 if (Changed
&& Repaint
)
4000 USER_REFERENCE_ENTRY Ref
;
4002 UserRefObjectCo(Window
, &Ref
);
4003 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4004 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4006 UserDerefObjectCo(Window
);
4012 TRACE("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4021 NtUserSetWindowFNID(HWND hWnd
,
4025 DECLARE_RETURN(BOOL
);
4027 TRACE("Enter NtUserSetWindowFNID\n");
4028 UserEnterExclusive();
4030 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4035 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
4037 EngSetLastError(ERROR_ACCESS_DENIED
);
4041 // From user land we only set these.
4042 if (fnID
!= FNID_DESTROY
)
4043 { // Hacked so we can mark desktop~!
4044 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
4047 EngSetLastError(ERROR_INVALID_PARAMETER
);
4056 TRACE("Leave NtUserSetWindowFNID\n");
4064 * Undocumented function that is called from DefWindowProc to set
4071 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4074 LARGE_STRING SafeText
;
4075 UNICODE_STRING UnicodeString
;
4078 TRACE("Enter NtUserDefSetText\n");
4080 if (WindowText
!= NULL
)
4084 SafeText
= ProbeForReadLargeString(WindowText
);
4086 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4089 SetLastNtError(_SEH2_GetExceptionCode());
4099 UserEnterExclusive();
4101 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4107 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4108 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4109 // Now we know what the bAnsi is for.
4110 RtlInitUnicodeString(&UnicodeString
, NULL
);
4111 if (SafeText
.Buffer
)
4116 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4118 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4119 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4121 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4124 SetLastNtError(_SEH2_GetExceptionCode());
4127 if (!Ret
) goto Exit
;
4130 if (UnicodeString
.Length
!= 0)
4132 if (Wnd
->strName
.MaximumLength
> 0 &&
4133 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4135 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4137 Wnd
->strName
.Length
= UnicodeString
.Length
;
4138 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4139 RtlCopyMemory(Wnd
->strName
.Buffer
,
4140 UnicodeString
.Buffer
,
4141 UnicodeString
.Length
);
4146 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4147 buf
= Wnd
->strName
.Buffer
;
4148 Wnd
->strName
.Buffer
= NULL
;
4151 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4154 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4155 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4156 if (Wnd
->strName
.Buffer
!= NULL
)
4158 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4159 RtlCopyMemory(Wnd
->strName
.Buffer
,
4160 UnicodeString
.Buffer
,
4161 UnicodeString
.Length
);
4162 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4163 Wnd
->strName
.Length
= UnicodeString
.Length
;
4167 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4175 Wnd
->strName
.Length
= 0;
4176 if (Wnd
->strName
.Buffer
!= NULL
)
4177 Wnd
->strName
.Buffer
[0] = L
'\0';
4180 // FIXME: HAX! Windows does not do this in here!
4181 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4182 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4183 /* Send shell notifications */
4184 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4186 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4191 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4192 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4198 * NtUserInternalGetWindowText
4205 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4210 DECLARE_RETURN(INT
);
4212 TRACE("Enter NtUserInternalGetWindowText\n");
4215 if(lpString
&& (nMaxCount
<= 1))
4217 EngSetLastError(ERROR_INVALID_PARAMETER
);
4221 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4226 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4229 const WCHAR Terminator
= L
'\0';
4231 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4233 Copy
= min(nMaxCount
- 1, Result
);
4236 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4237 if(!NT_SUCCESS(Status
))
4239 SetLastNtError(Status
);
4245 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4246 if(!NT_SUCCESS(Status
))
4248 SetLastNtError(Status
);
4258 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4268 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4274 // ASSERT(OwnerWnd);
4276 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4277 win_array
= IntWinListChildren(OwnerWnd
);
4282 while (win_array
[count
])
4284 while (--count
>= 0)
4286 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4288 if (pWnd
->spwndOwner
!= OwnerWnd
)
4293 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4295 /* In Windows, ShowOwnedPopups(TRUE) generates
4296 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4297 * regardless of the state of the owner
4299 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4305 if (pWnd
->style
& WS_VISIBLE
)
4307 /* In Windows, ShowOwnedPopups(FALSE) generates
4308 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4309 * regardless of the state of the owner
4311 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4317 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4318 TRACE("Leave ShowOwnedPopups\n");