2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
5 * FILE: subsystems/win32/win32k/ntuser/window.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
10 DBG_DEFAULT_CHANNEL(UserWnd
);
12 INT gNestedWindowLimit
= 50;
14 /* HELPER FUNCTIONS ***********************************************************/
16 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
18 WORD Action
= LOWORD(wParam
);
19 WORD Flags
= HIWORD(wParam
);
21 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
23 EngSetLastError(ERROR_INVALID_PARAMETER
);
30 EngSetLastError(ERROR_INVALID_PARAMETER
);
34 if (Flags
& UISF_HIDEFOCUS
)
35 Wnd
->HideFocus
= TRUE
;
36 if (Flags
& UISF_HIDEACCEL
)
37 Wnd
->HideAccel
= TRUE
;
41 if (Flags
& UISF_HIDEFOCUS
)
42 Wnd
->HideFocus
= FALSE
;
43 if (Flags
& UISF_HIDEACCEL
)
44 Wnd
->HideAccel
= FALSE
;
51 PWND FASTCALL
IntGetWindowObject(HWND hWnd
)
55 if (!hWnd
) return NULL
;
57 Window
= UserGetWindowObject(hWnd
);
59 Window
->head
.cLockObj
++;
64 PWND FASTCALL
VerifyWnd(PWND pWnd
)
69 if (!pWnd
) return NULL
;
73 hWnd
= UserHMGetHandle(pWnd
);
75 State2
= pWnd
->state2
;
77 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
79 _SEH2_YIELD(return NULL
);
83 if ( UserObjectInDestroy(hWnd
) ||
84 State
& WNDS_DESTROYED
||
85 State2
& WNDS2_INDESTROY
)
91 PWND FASTCALL
ValidateHwndNoErr(HWND hWnd
)
93 if (hWnd
) return (PWND
)UserGetObjectNoErr(gHandleTable
, hWnd
, TYPE_WINDOW
);
98 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
104 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
108 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, TYPE_WINDOW
);
109 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
111 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
119 IntSetStyle( PWND pwnd
, ULONG set_bits
, ULONG clear_bits
)
121 ULONG styleOld
, styleNew
;
122 styleOld
= pwnd
->style
;
123 styleNew
= (pwnd
->style
| set_bits
) & ~clear_bits
;
124 if (styleNew
== styleOld
) return styleNew
;
125 pwnd
->style
= styleNew
;
126 if ((styleOld
^ styleNew
) & WS_VISIBLE
) // State Change.
128 if (styleOld
& WS_VISIBLE
) pwnd
->head
.pti
->cVisWindows
--;
129 if (styleNew
& WS_VISIBLE
) pwnd
->head
.pti
->cVisWindows
++;
130 DceResetActiveDCEs( pwnd
);
138 * The function determines whether the specified window handle identifies
139 * an existing window.
143 * Handle to the window to test.
146 * If the window handle identifies an existing window, the return value
147 * is TRUE. If the window handle does not identify an existing window,
148 * the return value is FALSE.
152 IntIsWindow(HWND hWnd
)
156 if (!(Window
= UserGetWindowObject(hWnd
)))
165 IntIsWindowVisible(PWND Wnd
)
170 if (!Temp
) return TRUE
;
171 if (!(Temp
->style
& WS_VISIBLE
)) break;
172 if (Temp
->style
& WS_MINIMIZE
&& Temp
!= Wnd
) break;
173 if (Temp
->fnid
== FNID_DESKTOP
) return TRUE
;
174 Temp
= Temp
->spwndParent
;
180 IntGetParent(PWND Wnd
)
182 if (Wnd
->style
& WS_POPUP
)
184 return Wnd
->spwndOwner
;
186 else if (Wnd
->style
& WS_CHILD
)
188 return Wnd
->spwndParent
;
196 IntEnableWindow( HWND hWnd
, BOOL bEnable
)
202 if(!(pWnd
= UserGetWindowObject(hWnd
)))
207 /* check if updating is needed */
208 bIsDisabled
= !!(pWnd
->style
& WS_DISABLED
);
209 Update
= bIsDisabled
;
213 IntSetStyle( pWnd
, 0, WS_DISABLED
);
217 Update
= !bIsDisabled
;
219 co_IntSendMessage( hWnd
, WM_CANCELMODE
, 0, 0);
221 /* Remove keyboard focus from that window if it had focus */
222 if (hWnd
== IntGetThreadFocusWindow())
224 TRACE("IntEnableWindow SF NULL\n");
225 co_UserSetFocus(NULL
);
227 IntSetStyle( pWnd
, WS_DISABLED
, 0 );
232 IntNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, pWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
233 co_IntSendMessage(hWnd
, WM_ENABLE
, (LPARAM
)bEnable
, 0);
235 // Return nonzero if it was disabled, or zero if it wasn't:
242 * Compile a list of all child window handles from given window.
245 * This function is similar to Wine WIN_ListChildren. The caller
246 * must free the returned list with ExFreePool.
250 IntWinListChildren(PWND Window
)
254 UINT Index
, NumChildren
= 0;
256 if (!Window
) return NULL
;
258 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
261 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
264 ERR("Failed to allocate memory for children array\n");
265 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
268 for (Child
= Window
->spwndChild
, Index
= 0;
270 Child
= Child
->spwndNext
, ++Index
)
271 List
[Index
] = Child
->head
.h
;
278 IntGetNonChildAncestor(PWND pWnd
)
280 while(pWnd
&& (pWnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
281 pWnd
= pWnd
->spwndParent
;
286 IntIsTopLevelWindow(PWND pWnd
)
288 if ( pWnd
->spwndParent
&&
289 pWnd
->spwndParent
== co_GetDesktopWindow(pWnd
) ) return TRUE
;
294 IntValidateOwnerDepth(PWND Wnd
, PWND Owner
)
299 if ( !Owner
) return gNestedWindowLimit
>= Depth
;
300 if (Owner
== Wnd
) break;
301 Owner
= Owner
->spwndOwner
;
308 IntGetWindow(HWND hWnd
,
314 Wnd
= ValidateHwndNoErr(hWnd
);
322 if (Wnd
->spwndOwner
!= NULL
)
323 FoundWnd
= Wnd
->spwndOwner
;
327 if(Wnd
->spwndParent
!= NULL
)
329 FoundWnd
= Wnd
->spwndParent
;
330 if (FoundWnd
->spwndChild
!= NULL
)
331 FoundWnd
= FoundWnd
->spwndChild
;
335 if (Wnd
->spwndNext
!= NULL
)
336 FoundWnd
= Wnd
->spwndNext
;
340 if (Wnd
->spwndPrev
!= NULL
)
341 FoundWnd
= Wnd
->spwndPrev
;
345 if (Wnd
->spwndChild
!= NULL
)
346 FoundWnd
= Wnd
->spwndChild
;
351 while ( FoundWnd
->spwndNext
!= NULL
)
352 FoundWnd
= FoundWnd
->spwndNext
;
360 if (FoundWnd
!= NULL
)
361 Ret
= UserHMGetHandle(FoundWnd
);
365 /***********************************************************************
368 static void IntSendDestroyMsg(HWND hWnd
)
376 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
378 if (hWnd
== info
.hwndCaret
)
385 Window
= UserGetWindowObject(hWnd
);
388 // USER_REFERENCE_ENTRY Ref;
389 // UserRefObjectCo(Window, &Ref);
391 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
393 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
396 // UserDerefObjectCo(Window);
399 /* The window could already be destroyed here */
402 * Send the WM_DESTROY to the window.
405 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
408 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
409 * make sure that the window still exists when we come back.
418 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
421 /* start from the end (FIXME: is this needed?) */
422 for (i
= 0; pWndArray
[i
]; i
++)
427 if (IsWindow( pWndArray
[i
] ))
428 WIN_SendDestroyMsg( pWndArray
[i
] );
430 HeapFree(GetProcessHeap(), 0, pWndArray
);
434 TRACE("destroyed itself while in WM_DESTROY!\n");
440 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
442 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
446 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
448 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
449 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
452 if (Wnd
->strName
.Buffer
!= NULL
)
454 Wnd
->strName
.Length
= 0;
455 Wnd
->strName
.MaximumLength
= 0;
456 DesktopHeapFree(Wnd
->head
.rpdesk
,
457 Wnd
->strName
.Buffer
);
458 Wnd
->strName
.Buffer
= NULL
;
461 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
462 // WindowObject->Wnd = NULL;
465 /***********************************************************************
468 * Destroy storage associated to a window. "Internals" p.358
470 * This is the "functional" DestroyWindows function ei. all stuff
471 * done in CreateWindow is undone here and not in DestroyWindow:-P
474 static LRESULT
co_UserFreeWindow(PWND Window
,
475 PPROCESSINFO ProcessData
,
476 PTHREADINFO ThreadData
,
477 BOOLEAN SendMessages
)
483 BOOLEAN BelongsToThreadData
;
487 if(Window
->state2
& WNDS2_INDESTROY
)
489 TRACE("Tried to call IntDestroyWindow() twice\n");
492 Window
->state2
|= WNDS2_INDESTROY
;
493 Window
->style
&= ~WS_VISIBLE
;
494 Window
->head
.pti
->cVisWindows
--;
496 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
498 /* remove the window already at this point from the thread window list so we
499 don't get into trouble when destroying the thread windows while we're still
500 in IntDestroyWindow() */
501 RemoveEntryList(&Window
->ThreadListEntry
);
503 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
505 IntDeRegisterShellHookWindow(Window
->head
.h
);
509 /* Send destroy messages */
510 IntSendDestroyMsg(Window
->head
.h
);
513 /* free child windows */
514 Children
= IntWinListChildren(Window
);
517 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
519 if ((Child
= IntGetWindowObject(*ChildHandle
)))
521 if(!IntWndBelongsToThread(Child
, ThreadData
))
523 /* send WM_DESTROY messages to windows not belonging to the same thread */
524 IntSendDestroyMsg(Child
->head
.h
);
527 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
529 UserDereferenceObject(Child
);
532 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
538 * Clear the update region to make sure no WM_PAINT messages will be
539 * generated for this window while processing the WM_NCDESTROY.
541 co_UserRedrawWindow(Window
, NULL
, 0,
542 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
543 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
544 if(BelongsToThreadData
)
545 co_IntSendMessage(Window
->head
.h
, WM_NCDESTROY
, 0, 0);
548 DestroyTimersForWindow(ThreadData
, Window
);
550 /* Unregister hot keys */
551 UnregisterWindowHotKeys (Window
);
553 /* flush the message queue */
554 MsqRemoveWindowMessagesFromQueue(Window
);
556 /* from now on no messages can be sent to this window anymore */
557 Window
->state
|= WNDS_DESTROYED
;
558 Window
->fnid
|= FNID_FREED
;
560 /* don't remove the WINDOWSTATUS_DESTROYING bit */
562 /* reset shell window handles */
563 if(ThreadData
->rpdesk
)
565 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
566 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
568 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
569 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
572 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
576 WinPosCheckInternalPos(Window
->head
.h
);
577 if (Window
->head
.h
== GetCapture())
582 /* free resources associated with the window */
583 TIMER_RemoveWindowTimers(Window
->head
.h
);
586 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
588 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
590 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
594 if(Window
->SystemMenu
595 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
597 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
598 Window
->SystemMenu
= (HMENU
)0;
601 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
604 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
605 CLASS_RemoveWindow(Window
->Class
);
608 IntUnlinkWindow(Window
);
610 if (Window
->PropListItems
)
612 IntRemoveWindowProp(Window
);
613 TRACE("Window->PropListItems %d\n",Window
->PropListItems
);
614 ASSERT(Window
->PropListItems
==0);
617 UserReferenceObject(Window
);
618 UserDeleteObject(Window
->head
.h
, TYPE_WINDOW
);
620 IntDestroyScrollBars(Window
);
622 /* dereference the class */
623 IntDereferenceClass(Window
->pcls
,
624 Window
->head
.pti
->pDeskInfo
,
625 Window
->head
.pti
->ppi
);
630 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
631 GreDeleteObject(Window
->hrgnClip
);
632 Window
->hrgnClip
= NULL
;
634 Window
->head
.pti
->cWindows
--;
636 // ASSERT(Window != NULL);
637 UserFreeWindowInfo(Window
->head
.pti
, Window
);
639 UserDereferenceObject(Window
);
641 UserClipboardFreeWindow(Window
);
647 // Same as User32:IntGetWndProc.
650 IntGetWindowProc(PWND pWnd
,
655 WNDPROC gcpd
, Ret
= 0;
657 ASSERT(UserIsEnteredExclusive() == TRUE
);
661 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
663 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
665 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
668 Ret
= GETPFNCLIENTA(i
);
670 Ret
= GETPFNCLIENTW(i
);
676 if (Class
->fnid
== FNID_EDIT
)
677 Ret
= pWnd
->lpfnWndProc
;
680 Ret
= pWnd
->lpfnWndProc
;
682 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
686 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
687 Ret
= GETPFNCLIENTA(Class
->fnid
);
691 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
692 Ret
= GETPFNCLIENTW(Class
->fnid
);
695 if ( Ret
!= pWnd
->lpfnWndProc
)
698 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
701 gcpd
= (WNDPROC
)UserGetCPD(
703 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
706 return (gcpd
? gcpd
: Ret
);
710 IntSetWindowProc(PWND pWnd
,
715 PCALLPROCDATA CallProc
;
717 WNDPROC Ret
, chWndProc
= NULL
;
719 // Retrieve previous window proc.
720 Ret
= IntGetWindowProc(pWnd
, Ansi
);
724 if (IsCallProcHandle(NewWndProc
))
726 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
728 { // Reset new WndProc.
729 NewWndProc
= CallProc
->pfnClientPrevious
;
730 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
731 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
734 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
735 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
737 if (GETPFNCLIENTW(i
) == NewWndProc
)
739 chWndProc
= GETPFNSERVER(i
);
742 if (GETPFNCLIENTA(i
) == NewWndProc
)
744 chWndProc
= GETPFNSERVER(i
);
748 // If match, set/reset to Server Side and clear ansi.
751 pWnd
->lpfnWndProc
= chWndProc
;
752 pWnd
->Unicode
= TRUE
;
753 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
754 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
758 pWnd
->Unicode
= !Ansi
;
759 // Handle the state change in here.
761 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
763 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
765 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
766 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
768 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
770 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
774 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
775 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
779 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
780 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
783 // Now set the new window proc.
784 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
795 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
797 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
799 ERR("SetMenu: Invalid handle 0x%p!\n",UserHMGetHandle(Wnd
));
800 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
804 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
812 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
813 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Wnd
->head
.h
);
822 NewMenu
= IntGetMenuObject(Menu
);
827 IntReleaseMenuObject(OldMenu
);
829 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
832 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
834 /* Can't use the same menu for two windows */
837 IntReleaseMenuObject(OldMenu
);
839 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
845 Wnd
->IDMenu
= (UINT
) Menu
;
848 NewMenu
->MenuInfo
.Wnd
= Wnd
->head
.h
;
849 IntReleaseMenuObject(NewMenu
);
853 OldMenu
->MenuInfo
.Wnd
= NULL
;
854 IntReleaseMenuObject(OldMenu
);
861 /* INTERNAL ******************************************************************/
865 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
870 USER_REFERENCE_ENTRY Ref
;
871 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
873 while (!IsListEmpty(&WThread
->WindowListHead
))
875 Current
= WThread
->WindowListHead
.Flink
;
876 Wnd
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
878 TRACE("thread cleanup: while destroy wnds, wnd=%p\n", Wnd
);
880 /* Window removes itself from the list */
883 * FIXME: It is critical that the window removes itself! If now, we will loop
887 //ASSERT(co_UserDestroyWindow(Wnd));
889 UserRefObjectCo(Wnd
, &Ref
); // FIXME: Temp HACK??
890 if (!co_UserDestroyWindow(Wnd
))
892 ERR("Unable to destroy window %p at thread cleanup... This is _VERY_ bad!\n", Wnd
);
894 UserDerefObjectCo(Wnd
); // FIXME: Temp HACK??
898 PMENU_OBJECT FASTCALL
899 IntGetSystemMenu(PWND Window
, BOOL bRevert
, BOOL RetMenu
)
901 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
902 PTHREADINFO W32Thread
;
903 HMENU hNewMenu
, hSysMenu
;
904 ROSMENUITEMINFO ItemInfo
;
908 W32Thread
= PsGetCurrentThreadWin32Thread();
910 if(!W32Thread
->rpdesk
)
913 if(Window
->SystemMenu
)
915 Menu
= UserGetMenuObject(Window
->SystemMenu
);
918 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
919 Window
->SystemMenu
= (HMENU
)0;
923 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
925 /* Clone system menu */
926 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
930 NewMenu
= IntCloneMenu(Menu
);
933 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
934 NewMenu
->MenuInfo
.Flags
|= MNF_SYSDESKMN
;
935 NewMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
937 //IntReleaseMenuObject(NewMenu);
942 hSysMenu
= UserCreateMenu(FALSE
);
943 if (NULL
== hSysMenu
)
947 SysMenu
= IntGetMenuObject(hSysMenu
);
950 UserDestroyMenu(hSysMenu
);
953 SysMenu
->MenuInfo
.Flags
|= MNF_SYSDESKMN
;
954 SysMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
955 hNewMenu
= co_IntLoadSysMenuTemplate();
958 IntReleaseMenuObject(SysMenu
);
959 UserDestroyMenu(hSysMenu
);
962 Menu
= IntGetMenuObject(hNewMenu
);
965 IntReleaseMenuObject(SysMenu
);
966 UserDestroyMenu(hSysMenu
);
970 NewMenu
= IntCloneMenu(Menu
);
973 NewMenu
->MenuInfo
.Flags
|= MNF_SYSDESKMN
| MNF_POPUP
;
974 NewMenu
->MenuInfo
.dwStyle
= MNS_CHECKORBMP
;
975 IntReleaseMenuObject(NewMenu
);
976 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
978 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
979 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
981 ItemInfo
.fState
= MFS_ENABLED
;
982 ItemInfo
.dwTypeData
= NULL
;
984 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
985 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
987 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
991 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
1000 if(Window
->SystemMenu
)
1001 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
1009 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
1013 Window
= BaseWindow
;
1014 while (Window
&& ((Window
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
1016 if (Window
== Parent
)
1021 Window
= Window
->spwndParent
;
1028 Link the window into siblings list
1029 children and parent are kept in place.
1034 PWND WndInsertAfter
/* set to NULL if top sibling */
1037 if ((Wnd
->spwndPrev
= WndInsertAfter
))
1039 /* link after WndInsertAfter */
1040 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
1041 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1043 Wnd
->spwndPrev
->spwndNext
= Wnd
;
1048 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
1049 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1051 Wnd
->spwndParent
->spwndChild
= Wnd
;
1056 Note: Wnd->spwndParent can be null if it is the desktop.
1058 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
1060 if (hWndPrev
== HWND_NOTOPMOST
)
1062 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1063 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
1064 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1065 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
1068 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
1070 if (hWndPrev
== HWND_BOTTOM
)
1072 /* Link in the bottom of the list */
1073 PWND WndInsertAfter
;
1075 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
1076 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
1077 WndInsertAfter
= WndInsertAfter
->spwndNext
;
1079 IntLinkWindow(Wnd
, WndInsertAfter
);
1080 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1082 else if (hWndPrev
== HWND_TOPMOST
)
1084 /* Link in the top of the list */
1085 IntLinkWindow(Wnd
, NULL
);
1087 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1089 else if (hWndPrev
== HWND_TOP
)
1091 /* Link it after the last topmost window */
1092 PWND WndInsertBefore
;
1094 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
1096 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
1098 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
1100 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
1101 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
1103 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1106 WndInsertBefore
= WndInsertBefore
->spwndNext
;
1110 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
1114 /* Link it after hWndPrev */
1115 PWND WndInsertAfter
;
1117 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1118 /* Are we called with an erroneous handle */
1119 if(WndInsertAfter
== NULL
)
1121 /* Link in a default position */
1122 IntLinkHwnd(Wnd
, HWND_TOP
);
1126 IntLinkWindow(Wnd
, WndInsertAfter
);
1128 /* Fix the WS_EX_TOPMOST flag */
1129 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1131 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1135 if(WndInsertAfter
->spwndNext
&&
1136 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1138 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1142 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
1146 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
1150 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
1153 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
1154 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1156 //ERR("ProcessOwnerSwap Old out.\n");
1157 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
1163 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
1166 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1168 //ERR("ProcessOwnerSwap New in.\n");
1169 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1173 // FIXME: System Tray checks.
1177 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1179 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1182 Wnd
= IntGetWindowObject(hWnd
);
1186 WndOldOwner
= Wnd
->spwndOwner
;
1188 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1189 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1191 if (!WndNewOwner
&& hWndNewOwner
)
1193 EngSetLastError(ERROR_INVALID_PARAMETER
);
1198 /* if parent belongs to a different thread and the window isn't */
1199 /* top-level, attach the two threads */
1200 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1202 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1206 Wnd
->spwndOwner
= WndNewOwner
;
1210 Wnd
->spwndOwner
= NULL
;
1215 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1216 EngSetLastError(ERROR_INVALID_PARAMETER
);
1220 UserDereferenceObject(Wnd
);
1225 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1227 PWND WndOldParent
, pWndExam
;
1230 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1233 ASSERT(WndNewParent
);
1234 ASSERT_REFS_CO(Wnd
);
1235 ASSERT_REFS_CO(WndNewParent
);
1237 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1239 EngSetLastError(ERROR_ACCESS_DENIED
);
1243 /* Some applications try to set a child as a parent */
1244 if (IntIsChildWindow(Wnd
, WndNewParent
))
1246 TRACE("IntSetParent try to set a child as a parent.\n");
1247 EngSetLastError( ERROR_INVALID_PARAMETER
);
1251 pWndExam
= WndNewParent
; // Load parent Window to examine.
1252 // Now test for set parent to parent hit.
1255 if (Wnd
== pWndExam
)
1257 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1258 EngSetLastError(ERROR_INVALID_PARAMETER
);
1261 pWndExam
= pWndExam
->spwndParent
;
1265 * Windows hides the window first, then shows it again
1266 * including the WM_SHOWWINDOW messages and all
1268 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1270 /* Window must belong to current process */
1271 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1273 ERR("IntSetParent Window must belong to current process!\n");
1277 WndOldParent
= Wnd
->spwndParent
;
1279 if ( WndOldParent
&&
1280 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1281 pt
.x
= Wnd
->rcWindow
.right
;
1283 pt
.x
= Wnd
->rcWindow
.left
;
1284 pt
.y
= Wnd
->rcWindow
.top
;
1286 IntScreenToClient(WndOldParent
, &pt
);
1288 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1290 if (WndNewParent
!= WndOldParent
)
1292 /* Unlink the window from the siblings list */
1293 IntUnlinkWindow(Wnd
);
1294 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1296 /* Set the new parent */
1297 Wnd
->spwndParent
= WndNewParent
;
1299 if ( Wnd
->style
& WS_CHILD
&&
1301 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1303 ERR("SetParent Top Most from Pop up!\n");
1304 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1307 /* Link the window with its new siblings */
1309 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1310 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1314 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1315 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1317 Wnd
->style
|= WS_CLIPSIBLINGS
;
1318 DceResetActiveDCEs(Wnd
);
1321 /* if parent belongs to a different thread and the window isn't */
1322 /* top-level, attach the two threads */
1323 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1325 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1327 if (Wnd
->head
.pti
!= WndOldParent
->head
.pti
)
1329 //ERR("SetParent Old out.\n");
1330 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1333 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1335 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1337 //ERR("SetParent New in.\n");
1338 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1343 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1344 swFlags
|= SWP_NOACTIVATE
;
1346 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1348 * SetParent additionally needs to make hwnd the top window
1349 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1350 * WM_WINDOWPOSCHANGED notification messages.
1352 //ERR("IntSetParent SetWindowPos 1\n");
1353 co_WinPosSetWindowPos( Wnd
,
1354 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1355 pt
.x
, pt
.y
, 0, 0, swFlags
);
1356 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1357 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1359 return WndOldParent
;
1363 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1365 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1366 HWND hWndOldParent
= NULL
;
1367 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1369 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1371 EngSetLastError(ERROR_INVALID_PARAMETER
);
1375 if (hWndChild
== IntGetDesktopWindow())
1377 ERR("UserSetParent Access Denied!\n");
1378 EngSetLastError(ERROR_ACCESS_DENIED
);
1384 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1386 ERR("UserSetParent Bad New Parent!\n");
1392 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1398 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1400 ERR("UserSetParent Bad Child!\n");
1404 UserRefObjectCo(Wnd
, &Ref
);
1405 UserRefObjectCo(WndParent
, &ParentRef
);
1406 //ERR("Enter co_IntSetParent\n");
1407 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1408 //ERR("Leave co_IntSetParent\n");
1409 UserDerefObjectCo(WndParent
);
1410 UserDerefObjectCo(Wnd
);
1414 hWndOldParent
= WndOldParent
->head
.h
;
1415 UserDereferenceObject(WndOldParent
);
1418 return( hWndOldParent
);
1422 IntSetSystemMenu(PWND Window
, PMENU_OBJECT Menu
)
1424 PMENU_OBJECT OldMenu
;
1425 if(Window
->SystemMenu
)
1427 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1430 OldMenu
->MenuInfo
.Flags
&= ~ MNF_SYSDESKMN
;
1431 IntReleaseMenuObject(OldMenu
);
1437 /* FIXME: Check window style, propably return FALSE? */
1438 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1439 Menu
->MenuInfo
.Flags
|= MNF_SYSDESKMN
;
1442 Window
->SystemMenu
= (HMENU
)0;
1447 /* Unlink the window from siblings. children and parent are kept in place. */
1449 IntUnlinkWindow(PWND Wnd
)
1452 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1455 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1457 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1458 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1460 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1463 /* FUNCTIONS *****************************************************************/
1466 * As best as I can figure, this function is used by EnumWindows,
1467 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1469 * It's supposed to build a list of HWNDs to return to the caller.
1470 * We can figure out what kind of list by what parameters are
1478 NtUserBuildHwndList(
1491 return ERROR_INVALID_PARAMETER
;
1493 if (hwndParent
|| !dwThreadId
)
1496 PWND Parent
, Window
;
1500 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1502 return ERROR_INVALID_HANDLE
;
1507 Status
= IntValidateDesktopHandle(hDesktop
,
1511 if(!NT_SUCCESS(Status
))
1513 return ERROR_INVALID_HANDLE
;
1516 hwndParent
= Desktop
->DesktopWindow
;
1523 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1524 (Window
= Parent
->spwndChild
))
1526 BOOL bGoDown
= TRUE
;
1528 Status
= STATUS_SUCCESS
;
1533 if(dwCount
++ < *pBufSize
&& pWnd
)
1537 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1538 *pWnd
= Window
->head
.h
;
1541 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1543 Status
= _SEH2_GetExceptionCode();
1546 if(!NT_SUCCESS(Status
))
1548 SetLastNtError(Status
);
1552 if (Window
->spwndChild
&& bChildren
)
1554 Window
= Window
->spwndChild
;
1559 if (Window
->spwndNext
)
1561 Window
= Window
->spwndNext
;
1565 Window
= Window
->spwndParent
;
1566 if (Window
== Parent
)
1575 ObDereferenceObject(Desktop
);
1578 else // Build EnumThreadWindows list!
1581 PTHREADINFO W32Thread
;
1582 PLIST_ENTRY Current
;
1585 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1586 if (!NT_SUCCESS(Status
))
1588 ERR("Thread Id is not valid!\n");
1589 return ERROR_INVALID_PARAMETER
;
1591 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1593 ObDereferenceObject(Thread
);
1594 ERR("Thread is not initialized!\n");
1595 return ERROR_INVALID_PARAMETER
;
1598 Current
= W32Thread
->WindowListHead
.Flink
;
1599 while (Current
!= &(W32Thread
->WindowListHead
))
1601 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1604 if (dwCount
< *pBufSize
&& pWnd
)
1608 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1609 *pWnd
= Window
->head
.h
;
1612 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1614 Status
= _SEH2_GetExceptionCode();
1617 if (!NT_SUCCESS(Status
))
1619 ERR("Failure to build window list!\n");
1620 SetLastNtError(Status
);
1625 Current
= Window
->ThreadListEntry
.Flink
;
1628 ObDereferenceObject(Thread
);
1631 *pBufSize
= dwCount
;
1632 return STATUS_SUCCESS
;
1635 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1637 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1638 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1640 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1642 USER_REFERENCE_ENTRY Ref
;
1643 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1644 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1646 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1647 (LPARAM
)pWindow
->head
.h
);
1648 UserDerefObjectCo(pWindow
->spwndParent
);
1654 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1656 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1658 /* default positioning for overlapped windows */
1659 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1662 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1664 pMonitor
= UserGetPrimaryMonitor();
1666 /* Check if we don't have a monitor attached yet */
1667 if(pMonitor
== NULL
)
1675 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1677 if (IS_DEFAULT(Cs
->x
))
1679 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1681 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1683 Cs
->x
= ProcessParams
->StartingX
;
1684 Cs
->y
= ProcessParams
->StartingY
;
1688 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1689 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1690 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1691 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1693 /* reset counter and position */
1696 pMonitor
->cWndStack
= 0;
1698 pMonitor
->cWndStack
++;
1702 if (IS_DEFAULT(Cs
->cx
))
1704 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1706 Cs
->cx
= ProcessParams
->CountX
;
1707 Cs
->cy
= ProcessParams
->CountY
;
1711 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1712 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1715 /* neither x nor cx are default. Check the y values .
1716 * In the trace we see Outlook and Outlook Express using
1717 * cy set to CW_USEDEFAULT when opening the address book.
1719 else if (IS_DEFAULT(Cs
->cy
))
1721 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1722 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1727 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1728 if(IS_DEFAULT(Cs
->x
))
1733 if(IS_DEFAULT(Cs
->cx
))
1743 /* Allocates and initializes a window */
1744 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1745 PLARGE_STRING WindowName
,
1750 PDESKTOP pdeskCreated
)
1754 PTHREADINFO pti
= NULL
;
1755 PMENU_OBJECT SystemMenu
;
1757 BOOL bUnicodeWindow
;
1759 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1761 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1762 { // Need both here for wine win.c test_CreateWindow.
1763 //if (Cs->hwndParent && ParentWindow)
1764 if (ParentWindow
) // It breaks more tests..... WIP.
1766 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1767 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1768 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1769 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1773 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1775 * Dialog boxes and message boxes do not inherit layout, so you must
1776 * set the layout explicitly.
1778 if ( Class
->fnid
!= FNID_DIALOG
)
1780 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1782 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1788 /* Automatically add WS_EX_WINDOWEDGE */
1789 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1790 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1791 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1792 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1794 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1796 /* Is it a unicode window? */
1797 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1798 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1800 /* Allocate the new window */
1801 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1802 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1806 sizeof(WND
) + Class
->cbwndExtra
);
1813 TRACE("Created window object with handle %p\n", hWnd
);
1815 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1816 { /* HACK: Helper for win32csr/desktopbg.c */
1817 /* If there is no desktop window yet, we must be creating it */
1818 TRACE("CreateWindow setting desktop.\n");
1819 pdeskCreated
->DesktopWindow
= hWnd
;
1820 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1824 * Fill out the structure describing it.
1826 /* Remember, pWnd->head is setup in object.c ... */
1827 pWnd
->spwndParent
= ParentWindow
;
1828 pWnd
->spwndOwner
= OwnerWindow
;
1830 pWnd
->spwndLastActive
= pWnd
;
1831 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1833 pWnd
->hModule
= Cs
->hInstance
;
1834 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1835 pWnd
->ExStyle
= Cs
->dwExStyle
;
1836 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1837 pWnd
->pActCtx
= acbiBuffer
;
1838 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1839 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1841 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1843 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1844 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1847 pWnd
->head
.pti
->cWindows
++;
1849 if (Class
->hIcon
&& !Class
->hIconSm
)
1851 Class
->hIconSmIntern
= co_IntCopyImage( Class
->hIcon
, IMAGE_ICON
,
1852 UserGetSystemMetrics( SM_CXSMICON
),
1853 UserGetSystemMetrics( SM_CYSMICON
), 0 );
1854 TRACE("IntCreateWindow hIconSmIntern %p\n",Class
->hIconSmIntern
);
1855 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1858 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1859 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1861 /* BugBoy Comments: Comment below say that System classes are always created
1862 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1863 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1865 No where can I see in code or through testing does the window change back
1866 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1867 see what problems this would cause. */
1869 // Set WndProc from Class.
1870 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1872 // GetWindowProc, test for non server side default classes and set WndProc.
1873 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1877 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1878 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1882 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1883 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1887 // If not an Unicode caller, set Ansi creator bit.
1888 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1890 // Clone Class Ansi/Unicode proc type.
1891 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1893 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1894 pWnd
->Unicode
= FALSE
;
1898 * It seems there can be both an Ansi creator and Unicode Class Window
1899 * WndProc, unless the following overriding conditions occur:
1901 if ( !bUnicodeWindow
&&
1902 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1903 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1904 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1905 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1906 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1907 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1908 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1909 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1910 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1911 { // Override Class and set the window Ansi WndProc.
1912 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1913 pWnd
->Unicode
= FALSE
;
1916 { // Set the window Unicode WndProc.
1917 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1918 pWnd
->Unicode
= TRUE
;
1922 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1923 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1924 Dont understand why it does this. */
1925 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1927 PCALLPROCDATA CallProc
;
1928 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1932 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1933 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1937 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1941 InitializeListHead(&pWnd
->PropListHead
);
1943 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1945 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1946 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1947 if (pWnd
->strName
.Buffer
== NULL
)
1952 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1953 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1954 pWnd
->strName
.Length
= WindowName
->Length
;
1955 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1958 /* Correct the window style. */
1959 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1961 pWnd
->style
|= WS_CLIPSIBLINGS
;
1962 if (!(pWnd
->style
& WS_POPUP
))
1964 pWnd
->style
|= WS_CAPTION
;
1968 /* WS_EX_WINDOWEDGE depends on some other styles */
1969 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1970 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1971 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1973 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1974 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1975 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1978 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1980 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1981 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1983 /* Create system menu */
1984 if ((Cs
->style
& WS_SYSMENU
)) // && (dwStyle & WS_CAPTION) == WS_CAPTION)
1986 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1989 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1990 IntReleaseMenuObject(SystemMenu
);
1994 /* Set the window menu */
1995 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1998 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1999 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
2001 UNICODE_STRING MenuName
;
2004 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
2006 MenuName
.Length
= 0;
2007 MenuName
.MaximumLength
= 0;
2008 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
2012 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
2014 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
2015 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
2019 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
2022 if ( ParentWindow
&&
2023 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
2024 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
2026 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
2028 if (!IntValidateOwnerDepth(pWnd
, Owner
))
2030 EngSetLastError(ERROR_INVALID_PARAMETER
);
2033 if ( pWnd
->spwndOwner
&&
2034 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
2036 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
2038 if ( pWnd
->spwndOwner
&&
2039 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
2040 pti
!= pWnd
->spwndOwner
->head
.pti
)
2042 //ERR("CreateWindow Owner in.\n");
2043 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
2047 /* Insert the window into the thread's window list. */
2048 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
2050 /* Handle "CS_CLASSDC", it is tested first. */
2051 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
2052 { /* One DCE per class to have CLASS. */
2053 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
2055 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
2056 { /* Allocate a DCE for this window. */
2057 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
2063 ERR("IntCreateWindow Allocation Error.\n");
2064 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
2067 UserDereferenceObject(pWnd
);
2075 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
2076 PUNICODE_STRING ClassName
,
2077 PLARGE_STRING WindowName
,
2081 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
2082 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
2083 PWINSTATION_OBJECT WinSta
;
2086 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2087 CBT_CREATEWNDW
* pCbtCreate
;
2089 USER_REFERENCE_ENTRY ParentRef
, Ref
;
2091 DWORD dwShowMode
= SW_SHOW
;
2092 CREATESTRUCTW
*pCsw
= NULL
;
2093 PVOID pszClass
= NULL
, pszName
= NULL
;
2096 /* Get the current window station and reference it */
2097 pti
= GetW32ThreadInfo();
2098 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
2100 ERR("Thread is not attached to a desktop! Cannot create window!\n");
2101 return NULL
; // There is nothing to cleanup.
2103 WinSta
= pti
->rpdesk
->rpwinstaParent
;
2104 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
2109 /* Get the class and reference it */
2110 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
2113 ERR("Failed to find class %wZ\n", ClassName
);
2117 /* Now find the parent and the owner window */
2118 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
2121 if (Cs
->hwndParent
== HWND_MESSAGE
)
2123 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
2125 else if (Cs
->hwndParent
)
2127 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
2128 hWndOwner
= Cs
->hwndParent
;
2130 hWndParent
= Cs
->hwndParent
;
2132 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2134 ERR("Cannot create a child window without a parrent!\n");
2135 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
2136 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
2139 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
2140 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
2142 /* FIXME: Is this correct? */
2144 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
2146 /* Fix the position and the size of the window */
2149 UserRefObjectCo(ParentWindow
, &ParentRef
);
2150 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2153 /* Allocate and initialize the new window */
2154 Window
= IntCreateWindow(Cs
,
2163 ERR("IntCreateWindow failed!\n");
2167 hWnd
= UserHMGetHandle(Window
);
2168 hwndInsertAfter
= HWND_TOP
;
2170 UserRefObjectCo(Window
, &Ref
);
2171 UserDereferenceObject(Window
);
2172 ObDereferenceObject(WinSta
);
2174 //// Check for a hook to eliminate overhead. ////
2175 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2177 // Allocate the calling structures Justin Case this goes Global.
2178 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2179 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2180 if (!pCsw
|| !pCbtCreate
)
2182 ERR("UserHeapAlloc() failed!\n");
2186 /* Fill the new CREATESTRUCTW */
2187 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2188 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2190 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2191 if (!IS_ATOM(ClassName
->Buffer
))
2193 if (Window
->state
& WNDS_ANSICREATOR
)
2195 ANSI_STRING AnsiString
;
2196 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2197 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2200 ERR("UserHeapAlloc() failed!\n");
2203 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2204 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2205 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2209 UNICODE_STRING UnicodeString
;
2210 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2211 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2214 ERR("UserHeapAlloc() failed!\n");
2217 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2218 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2219 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2221 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2223 if (WindowName
->Length
)
2225 UNICODE_STRING Name
;
2226 Name
.Buffer
= WindowName
->Buffer
;
2227 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2228 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2230 if (Window
->state
& WNDS_ANSICREATOR
)
2232 ANSI_STRING AnsiString
;
2233 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2234 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2237 ERR("UserHeapAlloc() failed!\n");
2240 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2241 AnsiString
.Buffer
= (PCHAR
)pszName
;
2242 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2246 UNICODE_STRING UnicodeString
;
2247 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2248 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2251 ERR("UserHeapAlloc() failed!\n");
2254 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2255 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2256 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2258 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2261 pCbtCreate
->lpcs
= pCsw
;
2262 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2264 //// Call the WH_CBT hook ////
2265 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2268 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2271 // Write back changes.
2276 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2279 /* NCCREATE and WM_NCCALCSIZE need the original values */
2280 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2281 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2283 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2285 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2287 Cs
->x
+= ParentWindow
->rcClient
.left
;
2288 Cs
->y
+= ParentWindow
->rcClient
.top
;
2292 /* Send the WM_GETMINMAXINFO message */
2296 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2298 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2299 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2300 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2301 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2302 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2305 Window
->rcWindow
.left
= Cs
->x
;
2306 Window
->rcWindow
.top
= Cs
->y
;
2307 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2308 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2310 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2312 // ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2313 RECTL_vOffsetRect(&Window->rcWindow,
2314 ParentWindow->rcClient.left,
2315 ParentWindow->rcClient.top);
2318 /* correct child window coordinates if mirroring on parent is enabled */
2319 if (ParentWindow
!= NULL
)
2321 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2322 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2324 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2325 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2329 Window
->rcClient
= Window
->rcWindow
;
2331 /* Link the window */
2332 if (NULL
!= ParentWindow
)
2334 /* Link the window into the siblings list */
2335 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2336 IntLinkHwnd(Window
, HWND_BOTTOM
);
2338 IntLinkHwnd(Window
, hwndInsertAfter
);
2341 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2343 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2344 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2347 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2349 if ( !IntIsTopLevelWindow(Window
) )
2351 if (pti
!= Window
->spwndParent
->head
.pti
)
2353 //ERR("CreateWindow Parent in.\n");
2354 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2359 /* Send the NCCREATE message */
2360 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2363 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2367 /* Send the WM_NCCALCSIZE message */
2370 MaxPos
.x
= Window
->rcWindow
.left
;
2371 MaxPos
.y
= Window
->rcWindow
.top
;
2373 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2374 //rc = Window->rcWindow;
2375 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2376 //Window->rcClient = rc;
2378 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2379 MaxPos
.y
- Window
->rcWindow
.top
);
2382 /* Send the WM_CREATE message. */
2383 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2384 if (Result
== (LRESULT
)-1)
2386 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2390 /* Send the EVENT_OBJECT_CREATE event */
2391 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2393 /* By setting the flag below it can be examined to determine if the window
2394 was created successfully and a valid pwnd was passed back to caller since
2395 from here the function has to succeed. */
2396 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2398 /* Send the WM_SIZE and WM_MOVE messages. */
2399 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2401 co_WinPosSendSizeMove(Window
);
2404 /* Show or maybe minimize or maximize the window. */
2406 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2407 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2410 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2412 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2413 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2414 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2415 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2416 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2419 /* Send the WM_PARENTNOTIFY message */
2420 IntSendParentNotify(Window
, WM_CREATE
);
2422 /* Notify the shell that a new window was created */
2423 if ((!hWndParent
) && (!hWndOwner
))
2425 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2428 /* Initialize and show the window's scrollbars */
2429 if (Window
->style
& WS_VSCROLL
)
2431 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2433 if (Window
->style
& WS_HSCROLL
)
2435 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2438 /* Show the new window */
2439 if (Cs
->style
& WS_VISIBLE
)
2441 if (Window
->style
& WS_MAXIMIZE
)
2442 dwShowMode
= SW_SHOW
;
2443 else if (Window
->style
& WS_MINIMIZE
)
2444 dwShowMode
= SW_SHOWMINIMIZED
;
2446 co_WinPosShowWindow(Window
, dwShowMode
);
2448 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2450 ASSERT(ParentWindow
);
2453 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2454 /* ShowWindow won't activate child windows */
2455 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2459 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2465 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2466 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2468 co_UserDestroyWindow(Window
);
2470 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2473 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2474 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2475 if (pszName
) UserHeapFree(pszName
);
2476 if (pszClass
) UserHeapFree(pszClass
);
2480 UserDerefObjectCo(Window
);
2482 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2489 ProbeAndCaptureLargeString(
2490 OUT PLARGE_STRING plstrSafe
,
2491 IN PLARGE_STRING plstrUnsafe
)
2493 LARGE_STRING lstrTemp
;
2494 PVOID pvBuffer
= NULL
;
2498 /* Probe and copy the string */
2499 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2500 lstrTemp
= *plstrUnsafe
;
2502 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2505 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2509 if (lstrTemp
.Length
!= 0)
2511 /* Allocate a buffer from paged pool */
2512 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2515 return STATUS_NO_MEMORY
;
2520 /* Probe and copy the buffer */
2521 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2522 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2524 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2526 /* Cleanup and fail */
2527 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2528 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2533 /* Set the output string */
2534 plstrSafe
->Buffer
= pvBuffer
;
2535 plstrSafe
->Length
= lstrTemp
.Length
;
2536 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2538 return STATUS_SUCCESS
;
2542 * \todo Allow passing plstrClassName as ANSI.
2546 NtUserCreateWindowEx(
2548 PLARGE_STRING plstrClassName
,
2549 PLARGE_STRING plstrClsVersion
,
2550 PLARGE_STRING plstrWindowName
,
2558 HINSTANCE hInstance
,
2564 LARGE_STRING lstrWindowName
;
2565 LARGE_STRING lstrClassName
;
2566 UNICODE_STRING ustrClassName
;
2571 lstrWindowName
.Buffer
= NULL
;
2572 lstrClassName
.Buffer
= NULL
;
2574 ASSERT(plstrWindowName
);
2576 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2578 /* check hMenu is valid handle */
2579 if (hMenu
&& !ValidateHandle(hMenu
, TYPE_MENU
))
2581 /* error is set in ValidateHandle */
2586 /* Copy the window name to kernel mode */
2587 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2588 if (!NT_SUCCESS(Status
))
2590 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2591 SetLastNtError(Status
);
2595 plstrWindowName
= &lstrWindowName
;
2597 /* Check if the class is an atom */
2598 if (IS_ATOM(plstrClassName
))
2600 /* It is, pass the atom in the UNICODE_STRING */
2601 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2602 ustrClassName
.Length
= 0;
2603 ustrClassName
.MaximumLength
= 0;
2607 /* It's not, capture the class name */
2608 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2609 if (!NT_SUCCESS(Status
))
2611 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2612 /* Set last error, cleanup and return */
2613 SetLastNtError(Status
);
2617 /* We pass it on as a UNICODE_STRING */
2618 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2619 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2620 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2623 /* Fill the CREATESTRUCTW */
2624 /* we will keep here the original parameters */
2626 Cs
.lpCreateParams
= lpParam
;
2627 Cs
.hInstance
= hInstance
;
2629 Cs
.hwndParent
= hWndParent
;
2634 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2635 if (IS_ATOM(plstrClassName
))
2636 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2638 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2639 Cs
.dwExStyle
= dwExStyle
;
2641 UserEnterExclusive();
2643 /* Call the internal function */
2644 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
);
2648 ERR("co_UserCreateWindowEx failed!\n");
2650 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2655 if (lstrWindowName
.Buffer
)
2657 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2659 if (lstrClassName
.Buffer
)
2661 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2668 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2675 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2677 hWnd
= Window
->head
.h
;
2678 ti
= PsGetCurrentThreadWin32Thread();
2680 TRACE("co_UserDestroyWindow \n");
2682 /* Check for owner thread */
2683 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2685 /* Check if we are destroying the desktop window */
2686 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2688 EngSetLastError(ERROR_ACCESS_DENIED
);
2693 /* If window was created successfully and it is hooked */
2694 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2696 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2698 ERR("Destroy Window WH_CBT Call Hook return!\n");
2703 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2705 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2707 if (Window
->spwndOwner
)
2709 //ERR("DestroyWindow Owner out.\n");
2710 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2715 /* Inform the parent */
2716 if (Window
->style
& WS_CHILD
)
2718 IntSendParentNotify(Window
, WM_DESTROY
);
2721 /* Look whether the focus is within the tree of windows we will
2724 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2726 if (ti
->MessageQueue
->spwndActive
== Window
&& ti
->MessageQueue
== IntGetFocusMessageQueue())
2728 co_WinPosActivateOtherWindow(Window
);
2732 // Adjust last active.
2733 if ((pwndTemp
= Window
->spwndOwner
))
2735 while (pwndTemp
->spwndOwner
)
2736 pwndTemp
= pwndTemp
->spwndOwner
;
2738 if (pwndTemp
->spwndLastActive
== Window
)
2739 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2742 if (Window
->spwndParent
&& IntIsWindow(Window
->head
.h
))
2744 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2746 if (!IntIsTopLevelWindow(Window
))
2748 //ERR("DestroyWindow Parent out.\n");
2749 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2754 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2755 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2756 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2757 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2758 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2759 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2760 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2761 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2764 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2767 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2769 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2771 ERR("Destroying the ShellWindow!\n");
2772 ti
->pDeskInfo
->hShellWindow
= NULL
;
2776 IntEngWindowChanged(Window
, WOC_DELETE
);
2778 if (!IntIsWindow(Window
->head
.h
))
2783 /* Recursively destroy owned windows */
2785 if (! (Window
->style
& WS_CHILD
))
2789 BOOL GotOne
= FALSE
;
2792 PWND Child
, Desktop
;
2794 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2795 UserGetWindowObject(IntGetDesktopWindow());
2796 Children
= IntWinListChildren(Desktop
);
2800 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2802 Child
= UserGetWindowObject(*ChildHandle
);
2805 if (Child
->spwndOwner
!= Window
)
2810 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2812 USER_REFERENCE_ENTRY ChildRef
;
2813 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2814 co_UserDestroyWindow(Child
);
2815 UserDerefObjectCo(Child
); // Temp HACK?
2821 if (Child
->spwndOwner
!= NULL
)
2823 Child
->spwndOwner
= NULL
;
2827 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2836 /* Generate mouse move message for the next window */
2837 msg
.message
= WM_MOUSEMOVE
;
2838 msg
.wParam
= UserGetMouseButtonsState();
2839 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2840 msg
.pt
= gpsi
->ptCursor
;
2841 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2843 if (!IntIsWindow(Window
->head
.h
))
2848 /* Destroy the window storage */
2849 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2859 NtUserDestroyWindow(HWND Wnd
)
2862 DECLARE_RETURN(BOOLEAN
);
2864 USER_REFERENCE_ENTRY Ref
;
2866 TRACE("Enter NtUserDestroyWindow\n");
2867 UserEnterExclusive();
2869 if (!(Window
= UserGetWindowObject(Wnd
)))
2874 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2875 ret
= co_UserDestroyWindow(Window
);
2876 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2881 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2887 static HWND FASTCALL
2888 IntFindWindow(PWND Parent
,
2891 PUNICODE_STRING WindowName
)
2893 BOOL CheckWindowName
;
2896 UNICODE_STRING CurrentWindowName
;
2900 CheckWindowName
= WindowName
->Buffer
!= 0;
2902 if((List
= IntWinListChildren(Parent
)))
2907 /* skip handles before and including ChildAfter */
2908 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2912 /* search children */
2916 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2921 /* Do not send WM_GETTEXT messages in the kernel mode version!
2922 The user mode version however calls GetWindowText() which will
2923 send WM_GETTEXT messages to windows belonging to its processes */
2924 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2926 // FIXME: LARGE_STRING truncated
2927 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2928 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2929 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2930 if(!CheckWindowName
||
2931 (Child
->strName
.Length
< 0xFFFF &&
2932 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2934 Ret
= Child
->head
.h
;
2939 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2947 * Searches a window's children for a window with the specified
2950 * hwndParent = The window whose childs are to be searched.
2952 * HWND_MESSAGE = message-only windows
2954 * hwndChildAfter = Search starts after this child window.
2955 * NULL = start from beginning
2957 * ucClassName = Class name to search for
2958 * Reguired parameter.
2960 * ucWindowName = Window name
2961 * ->Buffer == NULL = don't care
2964 * The HWND of the window if it was found, otherwise NULL
2970 NtUserFindWindowEx(HWND hwndParent
,
2971 HWND hwndChildAfter
,
2972 PUNICODE_STRING ucClassName
,
2973 PUNICODE_STRING ucWindowName
,
2976 PWND Parent
, ChildAfter
;
2977 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2978 HWND Desktop
, Ret
= NULL
;
2979 BOOL DoMessageWnd
= FALSE
;
2980 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2981 DECLARE_RETURN(HWND
);
2983 TRACE("Enter NtUserFindWindowEx\n");
2986 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2990 if (ucClassName
!= NULL
)
2992 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2993 if (ClassName
.Length
!= 0)
2995 ProbeForRead(ClassName
.Buffer
,
2999 else if (!IS_ATOM(ClassName
.Buffer
))
3001 EngSetLastError(ERROR_INVALID_PARAMETER
);
3005 if (!IntGetAtomFromStringOrAtom(&ClassName
,
3012 if (ucWindowName
!= NULL
)
3014 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
3015 if (WindowName
.Length
!= 0)
3017 ProbeForRead(WindowName
.Buffer
,
3023 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3025 SetLastNtError(_SEH2_GetExceptionCode());
3026 _SEH2_YIELD(RETURN(NULL
));
3030 if (ucClassName
!= NULL
)
3032 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
3033 !IS_ATOM(ClassName
.Buffer
))
3035 EngSetLastError(ERROR_INVALID_PARAMETER
);
3038 else if (ClassAtom
== (RTL_ATOM
)0)
3040 /* LastError code was set by IntGetAtomFromStringOrAtom */
3046 Desktop
= IntGetCurrentThreadDesktopWindow();
3048 if(hwndParent
== NULL
)
3050 hwndParent
= Desktop
;
3051 DoMessageWnd
= TRUE
;
3053 else if(hwndParent
== HWND_MESSAGE
)
3055 hwndParent
= IntGetMessageWindow();
3058 if(!(Parent
= UserGetWindowObject(hwndParent
)))
3064 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
3071 if(Parent
->head
.h
== Desktop
)
3074 PWND TopLevelWindow
;
3075 BOOLEAN CheckWindowName
;
3076 BOOLEAN WindowMatches
;
3077 BOOLEAN ClassMatches
;
3079 /* windows searches through all top-level windows if the parent is the desktop
3082 if((List
= IntWinListChildren(Parent
)))
3088 /* skip handles before and including ChildAfter */
3089 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
3093 CheckWindowName
= WindowName
.Buffer
!= 0;
3095 /* search children */
3098 UNICODE_STRING ustr
;
3100 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
3105 /* Do not send WM_GETTEXT messages in the kernel mode version!
3106 The user mode version however calls GetWindowText() which will
3107 send WM_GETTEXT messages to windows belonging to its processes */
3108 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
3109 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
3110 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
3111 WindowMatches
= !CheckWindowName
||
3112 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
3113 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
3114 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
3115 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
3117 if (WindowMatches
&& ClassMatches
)
3119 Ret
= TopLevelWindow
->head
.h
;
3123 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3125 /* window returns the handle of the top-level window, in case it found
3127 Ret
= TopLevelWindow
->head
.h
;
3132 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3137 ERR("FindWindowEx: Not Desktop Parent!\n");
3138 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3141 if (Ret
== NULL
&& DoMessageWnd
)
3145 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3147 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3151 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3153 SetLastNtError(_SEH2_GetExceptionCode());
3161 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3170 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3172 PWND WndAncestor
, Parent
;
3174 if (Wnd
->head
.h
== IntGetDesktopWindow())
3183 WndAncestor
= Wnd
->spwndParent
;
3194 if(!(Parent
= WndAncestor
->spwndParent
))
3198 if(IntIsDesktopWindow(Parent
))
3203 WndAncestor
= Parent
;
3214 Parent
= IntGetParent(WndAncestor
);
3221 WndAncestor
= Parent
;
3239 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3241 PWND Window
, Ancestor
;
3242 DECLARE_RETURN(HWND
);
3244 TRACE("Enter NtUserGetAncestor\n");
3245 UserEnterExclusive();
3247 if (!(Window
= UserGetWindowObject(hWnd
)))
3252 Ancestor
= UserGetAncestor(Window
, Type
);
3253 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3255 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3258 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3264 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3266 /* combo state struct */
3280 INT fixedOwnerDrawHeight
;
3281 INT droppedWidth
; /* last two are not used unless set */
3282 INT editHeight
; /* explicitly */
3284 } HEADCOMBO
,*LPHEADCOMBO
;
3286 // Window Extra data container.
3287 typedef struct _WND2CBOX
3291 } WND2CBOX
, *PWND2CBOX
;
3293 #define CBF_BUTTONDOWN 0x0002
3299 NtUserGetComboBoxInfo(
3305 BOOL NotSameppi
= FALSE
;
3307 DECLARE_RETURN(BOOL
);
3309 TRACE("Enter NtUserGetComboBoxInfo\n");
3312 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3321 sizeof(COMBOBOXINFO
),
3325 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3327 SetLastNtError(_SEH2_GetExceptionCode());
3328 _SEH2_YIELD(RETURN(FALSE
));
3332 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3334 EngSetLastError(ERROR_INVALID_PARAMETER
);
3338 // Pass the user pointer, it was already probed.
3339 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3341 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3344 ppi
= PsGetCurrentProcessWin32Process();
3345 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3348 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3353 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3354 pcbi
->rcItem
= lphc
->textRect
;
3355 pcbi
->rcButton
= lphc
->buttonRect
;
3356 pcbi
->stateButton
= 0;
3357 if (lphc
->wState
& CBF_BUTTONDOWN
)
3358 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3359 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3360 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3361 pcbi
->hwndCombo
= lphc
->self
;
3362 pcbi
->hwndItem
= lphc
->hWndEdit
;
3363 pcbi
->hwndList
= lphc
->hWndLBox
;
3365 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3368 SetLastNtError(_SEH2_GetExceptionCode());
3375 if (NotSameppi
) KeDetachProcess();
3376 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3382 //// ReactOS work around! Keep it the sames as in Listbox.c
3384 /* Listbox structure */
3387 HWND self
; /* Our own window handle */
3388 HWND owner
; /* Owner window to send notifications to */
3389 UINT style
; /* Window style */
3390 INT width
; /* Window width */
3391 INT height
; /* Window height */
3392 VOID
*items
; /* Array of items */
3393 INT nb_items
; /* Number of items */
3394 INT top_item
; /* Top visible item */
3395 INT selected_item
; /* Selected item */
3396 INT focus_item
; /* Item that has the focus */
3397 INT anchor_item
; /* Anchor item for extended selection */
3398 INT item_height
; /* Default item height */
3399 INT page_size
; /* Items per listbox page */
3400 INT column_width
; /* Column width for multi-column listboxes */
3403 // Window Extra data container.
3404 typedef struct _WND2LB
3414 NtUserGetListBoxInfo(
3419 BOOL NotSameppi
= FALSE
;
3421 DECLARE_RETURN(DWORD
);
3423 TRACE("Enter NtUserGetListBoxInfo\n");
3426 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3431 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3433 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3436 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3437 ppi
= PsGetCurrentProcessWin32Process();
3438 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3441 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3446 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3447 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3448 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3449 Ret
= descr
->page_size
* descr
->column_width
;
3451 Ret
= descr
->page_size
;
3453 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3456 SetLastNtError(_SEH2_GetExceptionCode());
3463 if (NotSameppi
) KeDetachProcess();
3464 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3472 * The NtUserSetParent function changes the parent window of the specified
3476 * The new parent window and the child window must belong to the same
3477 * application. If the window identified by the hWndChild parameter is
3478 * visible, the system performs the appropriate redrawing and repainting.
3479 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3480 * or WS_POPUP window styles of the window whose parent is being changed.
3487 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3489 DECLARE_RETURN(HWND
);
3491 TRACE("Enter NtUserSetParent\n");
3492 UserEnterExclusive();
3495 Check Parent first from user space, set it here.
3499 hWndNewParent
= IntGetDesktopWindow();
3501 else if (hWndNewParent
== HWND_MESSAGE
)
3503 hWndNewParent
= IntGetMessageWindow();
3506 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3509 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3515 * UserGetShellWindow
3517 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3522 HWND FASTCALL
UserGetShellWindow(VOID
)
3524 PWINSTATION_OBJECT WinStaObject
;
3527 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3532 if (!NT_SUCCESS(Status
))
3534 SetLastNtError(Status
);
3538 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3540 ObDereferenceObject(WinStaObject
);
3545 * NtUserSetShellWindowEx
3547 * This is undocumented function to set global shell window. The global
3548 * shell window has special handling of window position.
3554 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3556 PWINSTATION_OBJECT WinStaObject
;
3557 PWND WndShell
, WndListView
;
3558 DECLARE_RETURN(BOOL
);
3559 USER_REFERENCE_ENTRY Ref
;
3563 TRACE("Enter NtUserSetShellWindowEx\n");
3564 UserEnterExclusive();
3566 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3571 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3576 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3581 if (!NT_SUCCESS(Status
))
3583 SetLastNtError(Status
);
3588 * Test if we are permitted to change the shell window.
3590 if (WinStaObject
->ShellWindow
)
3592 ObDereferenceObject(WinStaObject
);
3597 * Move shell window into background.
3599 if (hwndListView
&& hwndListView
!= hwndShell
)
3602 * Disabled for now to get Explorer working.
3603 * -- Filip, 01/nov/2003
3606 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3609 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3611 ObDereferenceObject(WinStaObject
);
3616 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3618 ObDereferenceObject(WinStaObject
);
3622 UserRefObjectCo(WndShell
, &Ref
);
3623 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3624 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3626 WinStaObject
->ShellWindow
= hwndShell
;
3627 WinStaObject
->ShellListView
= hwndListView
;
3629 ti
= GetW32ThreadInfo();
3632 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3633 ti
->pDeskInfo
->spwndShell
= WndShell
;
3634 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3637 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3639 UserDerefObjectCo(WndShell
);
3641 ObDereferenceObject(WinStaObject
);
3645 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3651 * NtUserGetSystemMenu
3653 * The NtUserGetSystemMenu function allows the application to access the
3654 * window menu (also known as the system menu or the control menu) for
3655 * copying and modifying.
3659 * Handle to the window that will own a copy of the window menu.
3661 * Specifies the action to be taken. If this parameter is FALSE,
3662 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3663 * currently in use. The copy is initially identical to the window menu
3664 * but it can be modified.
3665 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3666 * to the default state. The previous window menu, if any, is destroyed.
3669 * If the bRevert parameter is FALSE, the return value is a handle to a
3670 * copy of the window menu. If the bRevert parameter is TRUE, the return
3678 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3682 DECLARE_RETURN(HMENU
);
3684 TRACE("Enter NtUserGetSystemMenu\n");
3687 if (!(Window
= UserGetWindowObject(hWnd
)))
3692 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3697 RETURN(Menu
->MenuInfo
.Self
);
3700 TRACE("Leave NtUserGetSystemMenu, ret=%p\n", _ret_
);
3706 * NtUserSetSystemMenu
3713 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3715 BOOL Result
= FALSE
;
3718 DECLARE_RETURN(BOOL
);
3720 TRACE("Enter NtUserSetSystemMenu\n");
3721 UserEnterExclusive();
3723 if (!(Window
= UserGetWindowObject(hWnd
)))
3731 * Assign new menu handle.
3733 if (!(Menu
= UserGetMenuObject(hMenu
)))
3738 Result
= IntSetSystemMenu(Window
, Menu
);
3744 TRACE("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3749 // Fixes wine Win test_window_styles and todo tests...
3750 static BOOL FASTCALL
3751 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3753 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3755 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3762 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3764 PWND Window
, Parent
;
3765 PWINSTATION_OBJECT WindowStation
;
3769 if (!(Window
= UserGetWindowObject(hWnd
)))
3774 if ((INT
)Index
>= 0)
3776 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3778 EngSetLastError(ERROR_INVALID_INDEX
);
3782 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3784 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3786 OldValue = (LONG)IntSetWindowProc( Wnd,
3789 if (!OldValue) return 0;
3792 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3799 OldValue
= (LONG
) Window
->ExStyle
;
3800 Style
.styleOld
= OldValue
;
3801 Style
.styleNew
= NewValue
;
3803 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3806 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3808 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3811 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3812 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3814 /* WS_EX_WINDOWEDGE depends on some other styles */
3815 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3816 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3818 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3820 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3821 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3825 OldValue
= (LONG
) Window
->style
;
3826 Style
.styleOld
= OldValue
;
3827 Style
.styleNew
= NewValue
;
3828 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3830 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3831 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3832 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3833 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3834 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3836 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3838 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3840 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3841 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3842 DceResetActiveDCEs( Window
);
3844 Window
->style
= (DWORD
)Style
.styleNew
;
3845 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3850 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3851 Window
->fnid
& FNID_FREED
)
3853 EngSetLastError(ERROR_ACCESS_DENIED
);
3856 OldValue
= (LONG
)IntSetWindowProc(Window
,
3863 OldValue
= (LONG
) Window
->hModule
;
3864 Window
->hModule
= (HINSTANCE
) NewValue
;
3867 case GWL_HWNDPARENT
:
3868 Parent
= Window
->spwndParent
;
3869 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3870 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3872 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3876 OldValue
= (LONG
) Window
->IDMenu
;
3877 Window
->IDMenu
= (UINT
) NewValue
;
3881 OldValue
= Window
->dwUserData
;
3882 Window
->dwUserData
= NewValue
;
3886 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3887 EngSetLastError(ERROR_INVALID_INDEX
);
3897 * NtUserSetWindowLong
3899 * The NtUserSetWindowLong function changes an attribute of the specified
3900 * window. The function also sets the 32-bit (long) value at the specified
3901 * offset into the extra window memory.
3908 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3910 DECLARE_RETURN(LONG
);
3912 TRACE("Enter NtUserSetWindowLong\n");
3913 UserEnterExclusive();
3915 if (hWnd
== IntGetDesktopWindow())
3917 EngSetLastError(STATUS_ACCESS_DENIED
);
3921 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3924 TRACE("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3930 * NtUserSetWindowWord
3932 * Legacy function similar to NtUserSetWindowLong.
3939 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3943 DECLARE_RETURN(WORD
);
3945 TRACE("Enter NtUserSetWindowWord\n");
3946 UserEnterExclusive();
3948 if (hWnd
== IntGetDesktopWindow())
3950 EngSetLastError(STATUS_ACCESS_DENIED
);
3954 if (!(Window
= UserGetWindowObject(hWnd
)))
3963 case GWL_HWNDPARENT
:
3964 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3968 EngSetLastError(ERROR_INVALID_INDEX
);
3973 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3975 EngSetLastError(ERROR_INVALID_PARAMETER
);
3979 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3980 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3985 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3991 QueryWindow based on KJK::Hyperion and James Tabor.
3993 0 = QWUniqueProcessId
3994 1 = QWUniqueThreadId
3997 4 = QWIsHung Implements IsHungAppWindow found
4000 9 = QWKillWindow When I called this with hWnd ==
4001 DesktopWindow, it shutdown the system
4008 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
4010 /* Console Leader Process CID Window offsets */
4011 #define GWLP_CONSOLE_LEADER_PID 0
4012 #define GWLP_CONSOLE_LEADER_TID 4
4016 DECLARE_RETURN(UINT
);
4018 TRACE("Enter NtUserQueryWindow\n");
4021 if (!(pWnd
= UserGetWindowObject(hWnd
)))
4028 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
4030 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
4031 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
4033 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
4034 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
4038 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
4043 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
4045 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
4046 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
4048 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
4049 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
4053 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
4058 case QUERY_WINDOW_ACTIVE
:
4059 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
4062 case QUERY_WINDOW_FOCUS
:
4063 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
4066 case QUERY_WINDOW_ISHUNG
:
4067 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
);
4070 case QUERY_WINDOW_REAL_ID
:
4071 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
4074 case QUERY_WINDOW_FOREGROUND
:
4075 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
4079 Result
= (DWORD
)NULL
;
4086 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
4096 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4098 UNICODE_STRING SafeMessageName
;
4101 DECLARE_RETURN(UINT
);
4103 TRACE("Enter NtUserRegisterWindowMessage\n");
4104 UserEnterExclusive();
4106 if(MessageNameUnsafe
== NULL
)
4108 EngSetLastError(ERROR_INVALID_PARAMETER
);
4112 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4113 if(!NT_SUCCESS(Status
))
4115 SetLastNtError(Status
);
4119 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4120 if (SafeMessageName
.Buffer
)
4121 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4125 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
4142 DECLARE_RETURN(BOOL
);
4144 TRACE("Enter NtUserSetMenu\n");
4145 UserEnterExclusive();
4147 if (!(Window
= UserGetWindowObject(hWnd
)))
4152 if (! IntSetMenu(Window
, Menu
, &Changed
))
4157 if (Changed
&& Repaint
)
4159 USER_REFERENCE_ENTRY Ref
;
4161 UserRefObjectCo(Window
, &Ref
);
4162 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4163 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4165 UserDerefObjectCo(Window
);
4171 TRACE("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4180 NtUserSetWindowFNID(HWND hWnd
,
4184 DECLARE_RETURN(BOOL
);
4186 TRACE("Enter NtUserSetWindowFNID\n");
4187 UserEnterExclusive();
4189 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4194 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
4196 EngSetLastError(ERROR_ACCESS_DENIED
);
4200 // From user land we only set these.
4201 if (fnID
!= FNID_DESTROY
)
4202 { // Hacked so we can mark desktop~!
4203 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
4206 EngSetLastError(ERROR_INVALID_PARAMETER
);
4215 TRACE("Leave NtUserSetWindowFNID\n");
4223 * Undocumented function that is called from DefWindowProc to set
4230 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4233 LARGE_STRING SafeText
;
4234 UNICODE_STRING UnicodeString
;
4237 TRACE("Enter NtUserDefSetText\n");
4239 if (WindowText
!= NULL
)
4243 SafeText
= ProbeForReadLargeString(WindowText
);
4245 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4248 SetLastNtError(_SEH2_GetExceptionCode());
4258 UserEnterExclusive();
4260 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4266 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4267 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4268 // Now we know what the bAnsi is for.
4269 RtlInitUnicodeString(&UnicodeString
, NULL
);
4270 if (SafeText
.Buffer
)
4275 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4277 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4278 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4280 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4283 SetLastNtError(_SEH2_GetExceptionCode());
4286 if (!Ret
) goto Exit
;
4289 if (UnicodeString
.Length
!= 0)
4291 if (Wnd
->strName
.MaximumLength
> 0 &&
4292 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4294 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4296 Wnd
->strName
.Length
= UnicodeString
.Length
;
4297 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4298 RtlCopyMemory(Wnd
->strName
.Buffer
,
4299 UnicodeString
.Buffer
,
4300 UnicodeString
.Length
);
4305 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4306 buf
= Wnd
->strName
.Buffer
;
4307 Wnd
->strName
.Buffer
= NULL
;
4310 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4313 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4314 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4315 if (Wnd
->strName
.Buffer
!= NULL
)
4317 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4318 RtlCopyMemory(Wnd
->strName
.Buffer
,
4319 UnicodeString
.Buffer
,
4320 UnicodeString
.Length
);
4321 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4322 Wnd
->strName
.Length
= UnicodeString
.Length
;
4326 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4334 Wnd
->strName
.Length
= 0;
4335 if (Wnd
->strName
.Buffer
!= NULL
)
4336 Wnd
->strName
.Buffer
[0] = L
'\0';
4339 // FIXME: HAX! Windows does not do this in here!
4340 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4341 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4342 /* Send shell notifications */
4343 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4345 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4350 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4351 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4357 * NtUserInternalGetWindowText
4364 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4369 DECLARE_RETURN(INT
);
4371 TRACE("Enter NtUserInternalGetWindowText\n");
4374 if(lpString
&& (nMaxCount
<= 1))
4376 EngSetLastError(ERROR_INVALID_PARAMETER
);
4380 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4385 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4388 const WCHAR Terminator
= L
'\0';
4390 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4392 Copy
= min(nMaxCount
- 1, Result
);
4395 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4396 if(!NT_SUCCESS(Status
))
4398 SetLastNtError(Status
);
4404 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4405 if(!NT_SUCCESS(Status
))
4407 SetLastNtError(Status
);
4417 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4427 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4433 // ASSERT(OwnerWnd);
4435 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4436 win_array
= IntWinListChildren(OwnerWnd
);
4441 while (win_array
[count
])
4443 while (--count
>= 0)
4445 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4447 if (pWnd
->spwndOwner
!= OwnerWnd
)
4452 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4454 /* In Windows, ShowOwnedPopups(TRUE) generates
4455 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4456 * regardless of the state of the owner
4458 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4464 if (pWnd
->style
& WS_VISIBLE
)
4466 /* In Windows, ShowOwnedPopups(FALSE) generates
4467 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4468 * regardless of the state of the owner
4470 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4476 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4477 TRACE("Leave ShowOwnedPopups\n");