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
, otWindow
);
98 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
104 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
108 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
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
) DceResetActiveDCEs( pwnd
);
133 * The function determines whether the specified window handle identifies
134 * an existing window.
138 * Handle to the window to test.
141 * If the window handle identifies an existing window, the return value
142 * is TRUE. If the window handle does not identify an existing window,
143 * the return value is FALSE.
147 IntIsWindow(HWND hWnd
)
151 if (!(Window
= UserGetWindowObject(hWnd
)))
160 IntIsWindowVisible(PWND Wnd
)
165 if (!(Wnd
->style
& WS_VISIBLE
))
170 if (Wnd
->spwndParent
!= NULL
)
171 Wnd
= Wnd
->spwndParent
;
180 IntGetParent(PWND Wnd
)
182 if (Wnd
->style
& WS_POPUP
)
184 return Wnd
->spwndOwner
;
186 else if (Wnd
->style
& WS_CHILD
)
188 return Wnd
->spwndParent
;
196 IntEnableWindow( HWND hWnd
, BOOL bEnable
)
202 if(!(pWnd
= UserGetWindowObject(hWnd
)))
207 /* check if updating is needed */
208 bIsDisabled
= !!(pWnd
->style
& WS_DISABLED
);
209 Update
= bIsDisabled
;
213 IntSetStyle( pWnd
, 0, WS_DISABLED
);
217 Update
= !bIsDisabled
;
219 co_IntSendMessage( hWnd
, WM_CANCELMODE
, 0, 0);
221 /* Remove keyboard focus from that window if it had focus */
222 if (hWnd
== IntGetThreadFocusWindow())
224 TRACE("IntEnableWindow SF NULL\n");
225 co_UserSetFocus(NULL
);
227 IntSetStyle( pWnd
, WS_DISABLED
, 0 );
232 IntNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, pWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
233 co_IntSendMessage(hWnd
, WM_ENABLE
, (LPARAM
)bEnable
, 0);
235 // Return nonzero if it was disabled, or zero if it wasn't:
242 * Compile a list of all child window handles from given window.
245 * This function is similar to Wine WIN_ListChildren. The caller
246 * must free the returned list with ExFreePool.
250 IntWinListChildren(PWND Window
)
254 UINT Index
, NumChildren
= 0;
256 if (!Window
) return NULL
;
258 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
261 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
264 ERR("Failed to allocate memory for children array\n");
265 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
268 for (Child
= Window
->spwndChild
, Index
= 0;
270 Child
= Child
->spwndNext
, ++Index
)
271 List
[Index
] = Child
->head
.h
;
278 IntGetNonChildAncestor(PWND pWnd
)
282 while(pWnd
&& ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
))
283 pWnd
= pWnd
->spwndParent
;
289 IntIsTopLevelWindow(PWND pWnd
)
291 if ( pWnd
->spwndParent
&&
292 pWnd
->spwndParent
== co_GetDesktopWindow(pWnd
) ) return TRUE
;
297 IntValidateOwnerDepth(PWND Wnd
, PWND Owner
)
302 if ( !Owner
) return gNestedWindowLimit
>= Depth
;
303 if (Owner
== Wnd
) break;
304 Owner
= Owner
->spwndOwner
;
310 /***********************************************************************
313 static void IntSendDestroyMsg(HWND hWnd
)
321 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
323 if (hWnd
== info
.hwndCaret
)
330 Window
= UserGetWindowObject(hWnd
);
333 // USER_REFERENCE_ENTRY Ref;
334 // UserRefObjectCo(Window, &Ref);
336 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
338 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
341 // UserDerefObjectCo(Window);
344 /* The window could already be destroyed here */
347 * Send the WM_DESTROY to the window.
350 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
353 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
354 * make sure that the window still exists when we come back.
363 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
366 /* start from the end (FIXME: is this needed?) */
367 for (i
= 0; pWndArray
[i
]; i
++)
372 if (IsWindow( pWndArray
[i
] ))
373 WIN_SendDestroyMsg( pWndArray
[i
] );
375 HeapFree(GetProcessHeap(), 0, pWndArray
);
379 TRACE("destroyed itself while in WM_DESTROY!\n");
385 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
387 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
391 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
393 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
394 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
397 if (Wnd
->strName
.Buffer
!= NULL
)
399 Wnd
->strName
.Length
= 0;
400 Wnd
->strName
.MaximumLength
= 0;
401 DesktopHeapFree(Wnd
->head
.rpdesk
,
402 Wnd
->strName
.Buffer
);
403 Wnd
->strName
.Buffer
= NULL
;
406 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
407 // WindowObject->Wnd = NULL;
410 /***********************************************************************
413 * Destroy storage associated to a window. "Internals" p.358
415 * This is the "functional" DestroyWindows function ei. all stuff
416 * done in CreateWindow is undone here and not in DestroyWindow:-P
419 static LRESULT
co_UserFreeWindow(PWND Window
,
420 PPROCESSINFO ProcessData
,
421 PTHREADINFO ThreadData
,
422 BOOLEAN SendMessages
)
428 BOOLEAN BelongsToThreadData
;
432 if(Window
->state2
& WNDS2_INDESTROY
)
434 TRACE("Tried to call IntDestroyWindow() twice\n");
437 Window
->state2
|= WNDS2_INDESTROY
;
438 Window
->style
&= ~WS_VISIBLE
;
440 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
442 /* remove the window already at this point from the thread window list so we
443 don't get into trouble when destroying the thread windows while we're still
444 in IntDestroyWindow() */
445 RemoveEntryList(&Window
->ThreadListEntry
);
447 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
449 IntDeRegisterShellHookWindow(Window
->head
.h
);
453 /* Send destroy messages */
454 IntSendDestroyMsg(Window
->head
.h
);
457 /* free child windows */
458 Children
= IntWinListChildren(Window
);
461 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
463 if ((Child
= IntGetWindowObject(*ChildHandle
)))
465 if(!IntWndBelongsToThread(Child
, ThreadData
))
467 /* send WM_DESTROY messages to windows not belonging to the same thread */
468 IntSendDestroyMsg(Child
->head
.h
);
471 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
473 UserDereferenceObject(Child
);
476 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
482 * Clear the update region to make sure no WM_PAINT messages will be
483 * generated for this window while processing the WM_NCDESTROY.
485 co_UserRedrawWindow(Window
, NULL
, 0,
486 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
487 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
488 if(BelongsToThreadData
)
489 co_IntSendMessage(Window
->head
.h
, WM_NCDESTROY
, 0, 0);
492 DestroyTimersForWindow(ThreadData
, Window
);
494 /* Unregister hot keys */
495 UnregisterWindowHotKeys (Window
);
497 /* flush the message queue */
498 MsqRemoveWindowMessagesFromQueue(Window
);
500 IntDereferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
502 /* from now on no messages can be sent to this window anymore */
503 Window
->state
|= WNDS_DESTROYED
;
504 Window
->fnid
|= FNID_FREED
;
506 /* don't remove the WINDOWSTATUS_DESTROYING bit */
508 /* reset shell window handles */
509 if(ThreadData
->rpdesk
)
511 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
512 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
514 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
515 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
518 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
522 WinPosCheckInternalPos(Window
->head
.h
);
523 if (Window
->head
.h
== GetCapture())
528 /* free resources associated with the window */
529 TIMER_RemoveWindowTimers(Window
->head
.h
);
532 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
534 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
536 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
540 if(Window
->SystemMenu
541 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
543 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
544 Window
->SystemMenu
= (HMENU
)0;
547 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
550 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
551 CLASS_RemoveWindow(Window
->Class
);
554 IntUnlinkWindow(Window
);
556 UserReferenceObject(Window
);
557 UserDeleteObject(Window
->head
.h
, otWindow
);
559 IntDestroyScrollBars(Window
);
561 /* dereference the class */
562 IntDereferenceClass(Window
->pcls
,
563 Window
->head
.pti
->pDeskInfo
,
564 Window
->head
.pti
->ppi
);
569 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
570 GreDeleteObject(Window
->hrgnClip
);
571 Window
->hrgnClip
= NULL
;
574 // ASSERT(Window != NULL);
575 UserFreeWindowInfo(Window
->head
.pti
, Window
);
577 UserDereferenceObject(Window
);
579 UserClipboardFreeWindow(Window
);
585 // Same as User32:IntGetWndProc.
588 IntGetWindowProc(PWND pWnd
,
593 WNDPROC gcpd
, Ret
= 0;
595 ASSERT(UserIsEnteredExclusive() == TRUE
);
599 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
601 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
603 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
606 Ret
= GETPFNCLIENTA(i
);
608 Ret
= GETPFNCLIENTW(i
);
614 if (Class
->fnid
== FNID_EDIT
)
615 Ret
= pWnd
->lpfnWndProc
;
618 Ret
= pWnd
->lpfnWndProc
;
620 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
624 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
625 Ret
= GETPFNCLIENTA(Class
->fnid
);
629 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
630 Ret
= GETPFNCLIENTW(Class
->fnid
);
633 if ( Ret
!= pWnd
->lpfnWndProc
)
636 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
639 gcpd
= (WNDPROC
)UserGetCPD(
641 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
644 return (gcpd
? gcpd
: Ret
);
648 IntSetWindowProc(PWND pWnd
,
653 PCALLPROCDATA CallProc
;
655 WNDPROC Ret
, chWndProc
= NULL
;
657 // Retrieve previous window proc.
658 Ret
= IntGetWindowProc(pWnd
, Ansi
);
662 if (IsCallProcHandle(NewWndProc
))
664 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, otCallProc
);
666 { // Reset new WndProc.
667 NewWndProc
= CallProc
->pfnClientPrevious
;
668 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
669 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
672 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
673 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
675 if (GETPFNCLIENTW(i
) == NewWndProc
)
677 chWndProc
= GETPFNSERVER(i
);
680 if (GETPFNCLIENTA(i
) == NewWndProc
)
682 chWndProc
= GETPFNSERVER(i
);
686 // If match, set/reset to Server Side and clear ansi.
689 pWnd
->lpfnWndProc
= chWndProc
;
690 pWnd
->Unicode
= TRUE
;
691 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
692 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
696 pWnd
->Unicode
= !Ansi
;
697 // Handle the state change in here.
699 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
701 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
703 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
704 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
706 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
708 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
712 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
713 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
717 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
718 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
721 // Now set the new window proc.
722 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
733 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
735 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
737 ERR("SetMenu: Invalid handle 0x%p!\n",UserHMGetHandle(Wnd
));
738 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
742 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
750 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
751 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Wnd
->head
.h
);
760 NewMenu
= IntGetMenuObject(Menu
);
765 IntReleaseMenuObject(OldMenu
);
767 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
770 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
772 /* Can't use the same menu for two windows */
775 IntReleaseMenuObject(OldMenu
);
777 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
783 Wnd
->IDMenu
= (UINT
) Menu
;
786 NewMenu
->MenuInfo
.Wnd
= Wnd
->head
.h
;
787 IntReleaseMenuObject(NewMenu
);
791 OldMenu
->MenuInfo
.Wnd
= NULL
;
792 IntReleaseMenuObject(OldMenu
);
799 /* INTERNAL ******************************************************************/
803 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
808 USER_REFERENCE_ENTRY Ref
;
809 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
811 while (!IsListEmpty(&WThread
->WindowListHead
))
813 Current
= WThread
->WindowListHead
.Flink
;
814 Wnd
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
816 TRACE("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
818 /* Window removes itself from the list */
821 * FIXME: It is critical that the window removes itself! If now, we will loop
825 //ASSERT(co_UserDestroyWindow(Wnd));
827 UserRefObjectCo(Wnd
, &Ref
); // FIXME: Temp HACK??
828 if (!co_UserDestroyWindow(Wnd
))
830 ERR("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
832 UserDerefObjectCo(Wnd
); // FIXME: Temp HACK??
836 PMENU_OBJECT FASTCALL
837 IntGetSystemMenu(PWND Window
, BOOL bRevert
, BOOL RetMenu
)
839 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
840 PTHREADINFO W32Thread
;
841 HMENU hNewMenu
, hSysMenu
;
842 ROSMENUITEMINFO ItemInfo
;
846 W32Thread
= PsGetCurrentThreadWin32Thread();
848 if(!W32Thread
->rpdesk
)
851 if(Window
->SystemMenu
)
853 Menu
= UserGetMenuObject(Window
->SystemMenu
);
856 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
857 Window
->SystemMenu
= (HMENU
)0;
861 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
863 /* Clone system menu */
864 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
868 NewMenu
= IntCloneMenu(Menu
);
871 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
872 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
873 NewMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
875 //IntReleaseMenuObject(NewMenu);
880 hSysMenu
= UserCreateMenu(FALSE
);
881 if (NULL
== hSysMenu
)
885 SysMenu
= IntGetMenuObject(hSysMenu
);
888 UserDestroyMenu(hSysMenu
);
891 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
892 SysMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
893 hNewMenu
= co_IntLoadSysMenuTemplate();
896 IntReleaseMenuObject(SysMenu
);
897 UserDestroyMenu(hSysMenu
);
900 Menu
= IntGetMenuObject(hNewMenu
);
903 IntReleaseMenuObject(SysMenu
);
904 UserDestroyMenu(hSysMenu
);
908 NewMenu
= IntCloneMenu(Menu
);
911 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
912 IntReleaseMenuObject(NewMenu
);
913 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
915 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
916 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
917 ItemInfo
.fType
= MF_POPUP
;
918 ItemInfo
.fState
= MFS_ENABLED
;
919 ItemInfo
.dwTypeData
= NULL
;
921 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
922 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
924 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
928 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
937 if(Window
->SystemMenu
)
938 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
946 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
951 while (Window
&& ((Window
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
953 if (Window
== Parent
)
958 Window
= Window
->spwndParent
;
965 Link the window into siblings list
966 children and parent are kept in place.
971 PWND WndInsertAfter
/* set to NULL if top sibling */
974 if ((Wnd
->spwndPrev
= WndInsertAfter
))
976 /* link after WndInsertAfter */
977 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
978 Wnd
->spwndNext
->spwndPrev
= Wnd
;
980 Wnd
->spwndPrev
->spwndNext
= Wnd
;
985 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
986 Wnd
->spwndNext
->spwndPrev
= Wnd
;
988 Wnd
->spwndParent
->spwndChild
= Wnd
;
993 Note: Wnd->spwndParent can be null if it is the desktop.
995 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
997 if (hWndPrev
== HWND_NOTOPMOST
)
999 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1000 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
1001 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1002 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
1005 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
1007 if (hWndPrev
== HWND_BOTTOM
)
1009 /* Link in the bottom of the list */
1010 PWND WndInsertAfter
;
1012 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
1013 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
1014 WndInsertAfter
= WndInsertAfter
->spwndNext
;
1016 IntLinkWindow(Wnd
, WndInsertAfter
);
1017 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1019 else if (hWndPrev
== HWND_TOPMOST
)
1021 /* Link in the top of the list */
1022 IntLinkWindow(Wnd
, NULL
);
1024 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1026 else if (hWndPrev
== HWND_TOP
)
1028 /* Link it after the last topmost window */
1029 PWND WndInsertBefore
;
1031 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
1033 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
1035 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
1037 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
1038 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
1040 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1043 WndInsertBefore
= WndInsertBefore
->spwndNext
;
1047 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
1051 /* Link it after hWndPrev */
1052 PWND WndInsertAfter
;
1054 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1055 /* Are we called with an erroneous handle */
1056 if(WndInsertAfter
== NULL
)
1058 /* Link in a default position */
1059 IntLinkHwnd(Wnd
, HWND_TOP
);
1063 IntLinkWindow(Wnd
, WndInsertAfter
);
1065 /* Fix the WS_EX_TOPMOST flag */
1066 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1068 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1072 if(WndInsertAfter
->spwndNext
&&
1073 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1075 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1079 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
1083 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
1087 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
1090 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
1091 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1093 ERR("ProcessOwnerSwap Old out.\n");
1094 //UserAttachThreadInput(Wnd->head.pti, WndOldOwner->head.pti, FALSE);
1100 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
1103 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1105 ERR("ProcessOwnerSwap New in.\n");
1106 //UserAttachThreadInput(Wnd->head.pti, WndNewOwner->head.pti, TRUE);
1110 // FIXME: System Tray checks.
1114 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1116 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1119 Wnd
= IntGetWindowObject(hWnd
);
1123 WndOldOwner
= Wnd
->spwndOwner
;
1125 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1126 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1128 if (!WndNewOwner
&& hWndNewOwner
)
1130 EngSetLastError(ERROR_INVALID_PARAMETER
);
1135 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1137 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1141 Wnd
->spwndOwner
= WndNewOwner
;
1145 Wnd
->spwndOwner
= NULL
;
1150 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1151 EngSetLastError(ERROR_INVALID_PARAMETER
);
1155 UserDereferenceObject(Wnd
);
1160 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1162 PWND WndOldParent
, pWndExam
;
1165 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1168 ASSERT(WndNewParent
);
1169 ASSERT_REFS_CO(Wnd
);
1170 ASSERT_REFS_CO(WndNewParent
);
1172 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1174 EngSetLastError(ERROR_ACCESS_DENIED
);
1178 /* Some applications try to set a child as a parent */
1179 if (IntIsChildWindow(Wnd
, WndNewParent
))
1181 EngSetLastError( ERROR_INVALID_PARAMETER
);
1185 pWndExam
= WndNewParent
; // Load parent Window to examine.
1186 // Now test for set parent to parent hit.
1189 if (Wnd
== pWndExam
)
1191 EngSetLastError(ERROR_INVALID_PARAMETER
);
1194 pWndExam
= pWndExam
->spwndParent
;
1198 * Windows hides the window first, then shows it again
1199 * including the WM_SHOWWINDOW messages and all
1201 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1203 /* Window must belong to current process */
1204 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1207 WndOldParent
= Wnd
->spwndParent
;
1209 if ( WndOldParent
&&
1210 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1211 pt
.x
= Wnd
->rcWindow
.right
;
1213 pt
.x
= Wnd
->rcWindow
.left
;
1214 pt
.y
= Wnd
->rcWindow
.top
;
1216 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1218 if (WndNewParent
!= WndOldParent
)
1220 /* Unlink the window from the siblings list */
1221 IntUnlinkWindow(Wnd
);
1222 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1224 /* Set the new parent */
1225 Wnd
->spwndParent
= WndNewParent
;
1227 if ( Wnd
->style
& WS_CHILD
&&
1229 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1231 ERR("SetParent Top Most from Pop up!\n");
1232 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1235 /* Link the window with its new siblings */
1237 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1238 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1242 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1244 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1246 if (Wnd
->head
.pti
!= WndOldParent
->head
.pti
)
1248 ERR("SetParent Old out.\n");
1249 //UserAttachThreadInput(Wnd->head.pti, WndOldParent->head.pti, FALSE);
1252 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1254 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1256 ERR("SetParent New in.\n");
1257 //UserAttachThreadInput(Wnd->head.pti, WndNewParent->head.pti, TRUE);
1262 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1263 swFlags
|= SWP_NOACTIVATE
;
1265 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1267 * SetParent additionally needs to make hwnd the top window
1268 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1269 * WM_WINDOWPOSCHANGED notification messages.
1271 co_WinPosSetWindowPos( Wnd
,
1272 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1273 pt
.x
, pt
.y
, 0, 0, swFlags
);
1275 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1277 return WndOldParent
;
1281 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1283 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1284 HWND hWndOldParent
= NULL
;
1285 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1287 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1289 EngSetLastError(ERROR_INVALID_PARAMETER
);
1293 if (hWndChild
== IntGetDesktopWindow())
1295 EngSetLastError(ERROR_ACCESS_DENIED
);
1301 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1308 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1314 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1319 UserRefObjectCo(Wnd
, &Ref
);
1320 UserRefObjectCo(WndParent
, &ParentRef
);
1321 //ERR("Enter co_IntSetParent\n");
1322 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1323 //ERR("Leave co_IntSetParent\n");
1324 UserDerefObjectCo(WndParent
);
1325 UserDerefObjectCo(Wnd
);
1329 hWndOldParent
= WndOldParent
->head
.h
;
1330 UserDereferenceObject(WndOldParent
);
1333 return( hWndOldParent
);
1337 IntSetSystemMenu(PWND Window
, PMENU_OBJECT Menu
)
1339 PMENU_OBJECT OldMenu
;
1340 if(Window
->SystemMenu
)
1342 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1345 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1346 IntReleaseMenuObject(OldMenu
);
1352 /* FIXME: Check window style, propably return FALSE? */
1353 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1354 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1357 Window
->SystemMenu
= (HMENU
)0;
1362 /* Unlink the window from siblings. children and parent are kept in place. */
1364 IntUnlinkWindow(PWND Wnd
)
1367 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1370 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1372 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1373 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1375 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1378 /* FUNCTIONS *****************************************************************/
1381 * As best as I can figure, this function is used by EnumWindows,
1382 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1384 * It's supposed to build a list of HWNDs to return to the caller.
1385 * We can figure out what kind of list by what parameters are
1393 NtUserBuildHwndList(
1406 return ERROR_INVALID_PARAMETER
;
1408 if (hwndParent
|| !dwThreadId
)
1411 PWND Parent
, Window
;
1415 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1417 return ERROR_INVALID_HANDLE
;
1422 Status
= IntValidateDesktopHandle(hDesktop
,
1426 if(!NT_SUCCESS(Status
))
1428 return ERROR_INVALID_HANDLE
;
1431 hwndParent
= Desktop
->DesktopWindow
;
1438 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1439 (Window
= Parent
->spwndChild
))
1441 BOOL bGoDown
= TRUE
;
1443 Status
= STATUS_SUCCESS
;
1448 if(dwCount
++ < *pBufSize
&& pWnd
)
1452 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1453 *pWnd
= Window
->head
.h
;
1456 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1458 Status
= _SEH2_GetExceptionCode();
1461 if(!NT_SUCCESS(Status
))
1463 SetLastNtError(Status
);
1467 if (Window
->spwndChild
&& bChildren
)
1469 Window
= Window
->spwndChild
;
1474 if (Window
->spwndNext
)
1476 Window
= Window
->spwndNext
;
1480 Window
= Window
->spwndParent
;
1481 if (Window
== Parent
)
1490 ObDereferenceObject(Desktop
);
1493 else // Build EnumThreadWindows list!
1496 PTHREADINFO W32Thread
;
1497 PLIST_ENTRY Current
;
1500 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1501 if (!NT_SUCCESS(Status
))
1503 ERR("Thread Id is not valid!\n");
1504 return ERROR_INVALID_PARAMETER
;
1506 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1508 ObDereferenceObject(Thread
);
1509 ERR("Thread is not initialized!\n");
1510 return ERROR_INVALID_PARAMETER
;
1513 Current
= W32Thread
->WindowListHead
.Flink
;
1514 while (Current
!= &(W32Thread
->WindowListHead
))
1516 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1519 if (dwCount
< *pBufSize
&& pWnd
)
1523 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1524 *pWnd
= Window
->head
.h
;
1527 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1529 Status
= _SEH2_GetExceptionCode();
1532 if (!NT_SUCCESS(Status
))
1534 ERR("Failure to build window list!\n");
1535 SetLastNtError(Status
);
1540 Current
= Window
->ThreadListEntry
.Flink
;
1543 ObDereferenceObject(Thread
);
1546 *pBufSize
= dwCount
;
1547 return STATUS_SUCCESS
;
1550 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1552 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1553 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1555 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1557 USER_REFERENCE_ENTRY Ref
;
1558 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1559 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1561 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1562 (LPARAM
)pWindow
->head
.h
);
1563 UserDerefObjectCo(pWindow
->spwndParent
);
1569 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1571 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1573 /* default positioning for overlapped windows */
1574 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1577 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1579 pMonitor
= UserGetPrimaryMonitor();
1581 /* Check if we don't have a monitor attached yet */
1582 if(pMonitor
== NULL
)
1590 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1592 if (IS_DEFAULT(Cs
->x
))
1594 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1596 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1598 Cs
->x
= ProcessParams
->StartingX
;
1599 Cs
->y
= ProcessParams
->StartingY
;
1603 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1604 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1605 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1606 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1608 /* reset counter and position */
1611 pMonitor
->cWndStack
= 0;
1613 pMonitor
->cWndStack
++;
1617 if (IS_DEFAULT(Cs
->cx
))
1619 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1621 Cs
->cx
= ProcessParams
->CountX
;
1622 Cs
->cy
= ProcessParams
->CountY
;
1626 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1627 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1630 /* neither x nor cx are default. Check the y values .
1631 * In the trace we see Outlook and Outlook Express using
1632 * cy set to CW_USEDEFAULT when opening the address book.
1634 else if (IS_DEFAULT(Cs
->cy
))
1636 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1637 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1642 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1643 if(IS_DEFAULT(Cs
->x
))
1648 if(IS_DEFAULT(Cs
->cx
))
1658 /* Allocates and initializes a window */
1659 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1660 PLARGE_STRING WindowName
,
1665 PDESKTOP pdeskCreated
)
1669 PTHREADINFO pti
= NULL
;
1670 PMENU_OBJECT SystemMenu
;
1672 BOOL bUnicodeWindow
;
1674 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1676 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1680 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1681 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1682 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1683 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1687 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1689 * Dialog boxes and message boxes do not inherit layout, so you must
1690 * set the layout explicitly.
1692 if ( Class
->fnid
!= FNID_DIALOG
)
1694 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1696 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1702 /* Automatically add WS_EX_WINDOWEDGE */
1703 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1704 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1705 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1706 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1708 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1710 /* Is it a unicode window? */
1711 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1712 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1714 /* Allocate the new window */
1715 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1716 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1720 sizeof(WND
) + Class
->cbwndExtra
);
1727 TRACE("Created window object with handle %X\n", hWnd
);
1729 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1730 { /* HACK: Helper for win32csr/desktopbg.c */
1731 /* If there is no desktop window yet, we must be creating it */
1732 TRACE("CreateWindow setting desktop.\n");
1733 pdeskCreated
->DesktopWindow
= hWnd
;
1734 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1738 * Fill out the structure describing it.
1740 /* Remember, pWnd->head is setup in object.c ... */
1741 pWnd
->spwndParent
= ParentWindow
;
1742 pWnd
->spwndOwner
= OwnerWindow
;
1744 pWnd
->spwndLastActive
= pWnd
;
1745 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1747 pWnd
->hModule
= Cs
->hInstance
;
1748 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1749 pWnd
->ExStyle
= Cs
->dwExStyle
;
1750 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1751 pWnd
->pActCtx
= acbiBuffer
;
1752 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1753 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1755 IntReferenceMessageQueue(pWnd
->head
.pti
->MessageQueue
);
1756 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1758 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1759 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1762 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1763 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1765 /* BugBoy Comments: Comment below say that System classes are always created
1766 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1767 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1769 No where can I see in code or through testing does the window change back
1770 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1771 see what problems this would cause. */
1773 // Set WndProc from Class.
1774 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1776 // GetWindowProc, test for non server side default classes and set WndProc.
1777 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1781 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1782 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1786 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1787 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1791 // If not an Unicode caller, set Ansi creator bit.
1792 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1794 // Clone Class Ansi/Unicode proc type.
1795 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1797 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1798 pWnd
->Unicode
= FALSE
;
1802 * It seems there can be both an Ansi creator and Unicode Class Window
1803 * WndProc, unless the following overriding conditions occur:
1805 if ( !bUnicodeWindow
&&
1806 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1807 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1808 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1809 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1810 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1811 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1812 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1813 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1814 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1815 { // Override Class and set the window Ansi WndProc.
1816 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1817 pWnd
->Unicode
= FALSE
;
1820 { // Set the window Unicode WndProc.
1821 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1822 pWnd
->Unicode
= TRUE
;
1826 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1827 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1828 Dont understand why it does this. */
1829 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1831 PCALLPROCDATA CallProc
;
1832 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1836 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1837 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
1841 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1845 InitializeListHead(&pWnd
->PropListHead
);
1847 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1849 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1850 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1851 if (pWnd
->strName
.Buffer
== NULL
)
1856 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1857 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1858 pWnd
->strName
.Length
= WindowName
->Length
;
1859 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1862 /* Correct the window style. */
1863 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1865 pWnd
->style
|= WS_CLIPSIBLINGS
;
1866 if (!(pWnd
->style
& WS_POPUP
))
1868 pWnd
->style
|= WS_CAPTION
;
1872 /* WS_EX_WINDOWEDGE depends on some other styles */
1873 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1874 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1875 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1877 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1878 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1879 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1882 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1884 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1885 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1887 /* Create system menu */
1888 if ((Cs
->style
& WS_SYSMENU
)) // && (dwStyle & WS_CAPTION) == WS_CAPTION)
1890 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1893 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1894 IntReleaseMenuObject(SystemMenu
);
1898 /* Set the window menu */
1899 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1902 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1903 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1905 UNICODE_STRING MenuName
;
1908 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1910 MenuName
.Length
= 0;
1911 MenuName
.MaximumLength
= 0;
1912 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1916 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1918 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1919 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1923 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1926 if ( ParentWindow
&&
1927 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1928 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1930 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1932 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1934 EngSetLastError(ERROR_INVALID_PARAMETER
);
1937 if ( pWnd
->spwndOwner
&&
1938 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1940 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1942 if ( pWnd
->spwndOwner
&&
1943 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1944 pti
!= pWnd
->spwndOwner
->head
.pti
)
1946 ERR("CreateWindow Owner in.\n");
1947 //UserAttachThreadInput(pti, pWnd->spwndOwner->head.pti, TRUE);
1951 /* Insert the window into the thread's window list. */
1952 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1954 /* Handle "CS_CLASSDC", it is tested first. */
1955 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1956 { /* One DCE per class to have CLASS. */
1957 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1959 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1960 { /* Allocate a DCE for this window. */
1961 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1967 ERR("IntCreateWindow Allocation Error.\n");
1968 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1971 UserDereferenceObject(pWnd
);
1979 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1980 PUNICODE_STRING ClassName
,
1981 PLARGE_STRING WindowName
,
1985 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1986 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1987 PWINSTATION_OBJECT WinSta
;
1991 CBT_CREATEWNDW
* pCbtCreate
;
1993 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1995 DWORD dwShowMode
= SW_SHOW
;
1996 CREATESTRUCTW
*pCsw
= NULL
;
1997 PVOID pszClass
= NULL
, pszName
= NULL
;
2000 /* Get the current window station and reference it */
2001 pti
= GetW32ThreadInfo();
2002 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
2004 ERR("Thread is not attached to a desktop! Cannot create window!\n");
2005 return NULL
; // There is nothing to cleanup.
2007 WinSta
= pti
->rpdesk
->rpwinstaParent
;
2008 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
2013 /* Get the class and reference it */
2014 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
2017 ERR("Failed to find class %wZ\n", ClassName
);
2021 /* Now find the parent and the owner window */
2022 hWndParent
= IntGetDesktopWindow();
2025 if (Cs
->hwndParent
== HWND_MESSAGE
)
2027 Cs
->hwndParent
= hWndParent
= IntGetMessageWindow();
2029 else if (Cs
->hwndParent
)
2031 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
2032 hWndOwner
= Cs
->hwndParent
;
2034 hWndParent
= Cs
->hwndParent
;
2036 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2038 ERR("Cannot create a child window without a parrent!\n");
2039 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
2040 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
2043 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
2044 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
2046 /* FIXME: Is this correct? */
2048 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
2050 /* Fix the position and the size of the window */
2053 UserRefObjectCo(ParentWindow
, &ParentRef
);
2054 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2057 /* Allocate and initialize the new window */
2058 Window
= IntCreateWindow(Cs
,
2067 ERR("IntCreateWindow failed!\n");
2071 hWnd
= UserHMGetHandle(Window
);
2072 hwndInsertAfter
= HWND_TOP
;
2074 UserRefObjectCo(Window
, &Ref
);
2075 UserDereferenceObject(Window
);
2076 ObDereferenceObject(WinSta
);
2078 //// Check for a hook to eliminate overhead. ////
2079 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2081 // Allocate the calling structures Justin Case this goes Global.
2082 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2083 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2084 if (!pCsw
|| !pCbtCreate
)
2086 ERR("UserHeapAlloc() failed!\n");
2090 /* Fill the new CREATESTRUCTW */
2091 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2092 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2094 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2095 if (!IS_ATOM(ClassName
->Buffer
))
2097 if (Window
->state
& WNDS_ANSICREATOR
)
2099 ANSI_STRING AnsiString
;
2100 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2101 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2104 ERR("UserHeapAlloc() failed!\n");
2107 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2108 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2109 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2113 UNICODE_STRING UnicodeString
;
2114 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2115 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2118 ERR("UserHeapAlloc() failed!\n");
2121 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2122 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2123 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2125 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2127 if (WindowName
->Length
)
2129 UNICODE_STRING Name
;
2130 Name
.Buffer
= WindowName
->Buffer
;
2131 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2132 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2134 if (Window
->state
& WNDS_ANSICREATOR
)
2136 ANSI_STRING AnsiString
;
2137 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2138 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2141 ERR("UserHeapAlloc() failed!\n");
2144 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2145 AnsiString
.Buffer
= (PCHAR
)pszName
;
2146 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2150 UNICODE_STRING UnicodeString
;
2151 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2152 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2155 ERR("UserHeapAlloc() failed!\n");
2158 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2159 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2160 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2162 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2165 pCbtCreate
->lpcs
= pCsw
;
2166 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2168 //// Call the WH_CBT hook ////
2169 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2172 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2175 // Write back changes.
2180 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2183 /* NCCREATE and WM_NCCALCSIZE need the original values */
2184 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2185 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2187 /* Send the WM_GETMINMAXINFO message */
2191 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2193 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2195 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2196 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2197 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2198 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2199 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2202 Window
->rcWindow
.left
= Cs
->x
;
2203 Window
->rcWindow
.top
= Cs
->y
;
2204 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2205 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2206 if (0 != (Window
->style
& WS_CHILD
) && ParentWindow
)
2208 // ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2209 RECTL_vOffsetRect(&Window
->rcWindow
,
2210 ParentWindow
->rcClient
.left
,
2211 ParentWindow
->rcClient
.top
);
2213 Window
->rcClient
= Window
->rcWindow
;
2215 /* Link the window */
2216 if (NULL
!= ParentWindow
)
2218 /* Link the window into the siblings list */
2219 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2220 IntLinkHwnd(Window
, HWND_BOTTOM
);
2222 IntLinkHwnd(Window
, hwndInsertAfter
);
2225 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2227 if ( !IntIsTopLevelWindow(Window
) )
2229 if (pti
!= Window
->spwndParent
->head
.pti
)
2231 ERR("CreateWindow Parent in.\n");
2232 //UserAttachThreadInput(pti, Window->spwndParent->head.pti, TRUE);
2237 /* Send the NCCREATE message */
2238 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2241 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2245 /* Send the WM_NCCALCSIZE message */
2246 MaxPos
.x
= Window
->rcWindow
.left
;
2247 MaxPos
.y
= Window
->rcWindow
.top
;
2249 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2251 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2252 MaxPos
.y
- Window
->rcWindow
.top
);
2255 /* Send the WM_CREATE message. */
2256 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2257 if (Result
== (LRESULT
)-1)
2259 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2263 /* Send the EVENT_OBJECT_CREATE event */
2264 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2266 /* By setting the flag below it can be examined to determine if the window
2267 was created successfully and a valid pwnd was passed back to caller since
2268 from here the function has to succeed. */
2269 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2271 /* Send the WM_SIZE and WM_MOVE messages. */
2272 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2274 co_WinPosSendSizeMove(Window
);
2277 /* Show or maybe minimize or maximize the window. */
2279 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2280 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2283 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2285 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2286 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2287 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2288 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2289 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2292 /* Send the WM_PARENTNOTIFY message */
2293 IntSendParentNotify(Window
, WM_CREATE
);
2295 /* Notify the shell that a new window was created */
2296 if ((!hWndParent
) && (!hWndOwner
))
2298 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2301 /* Initialize and show the window's scrollbars */
2302 if (Window
->style
& WS_VSCROLL
)
2304 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2306 if (Window
->style
& WS_HSCROLL
)
2308 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2311 /* Show the new window */
2312 if (Cs
->style
& WS_VISIBLE
)
2314 if (Window
->style
& WS_MAXIMIZE
)
2315 dwShowMode
= SW_SHOW
;
2316 else if (Window
->style
& WS_MINIMIZE
)
2317 dwShowMode
= SW_SHOWMINIMIZED
;
2319 co_WinPosShowWindow(Window
, dwShowMode
);
2321 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2323 ASSERT(ParentWindow
);
2326 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2327 /* ShowWindow won't activate child windows */
2328 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2332 TRACE("co_UserCreateWindowEx(): Created window %X\n", hWnd
);
2338 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2339 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2341 co_UserDestroyWindow(Window
);
2343 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2346 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2347 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2348 if (pszName
) UserHeapFree(pszName
);
2349 if (pszClass
) UserHeapFree(pszClass
);
2353 UserDerefObjectCo(Window
);
2355 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2362 ProbeAndCaptureLargeString(
2363 OUT PLARGE_STRING plstrSafe
,
2364 IN PLARGE_STRING plstrUnsafe
)
2366 LARGE_STRING lstrTemp
;
2367 PVOID pvBuffer
= NULL
;
2371 /* Probe and copy the string */
2372 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2373 lstrTemp
= *plstrUnsafe
;
2375 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2378 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2382 if (lstrTemp
.Length
!= 0)
2384 /* Allocate a buffer from paged pool */
2385 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2388 return STATUS_NO_MEMORY
;
2393 /* Probe and copy the buffer */
2394 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2395 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2397 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2399 /* Cleanup and fail */
2400 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2401 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2406 /* Set the output string */
2407 plstrSafe
->Buffer
= pvBuffer
;
2408 plstrSafe
->Length
= lstrTemp
.Length
;
2409 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2411 return STATUS_SUCCESS
;
2415 * \todo Allow passing plstrClassName as ANSI.
2419 NtUserCreateWindowEx(
2421 PLARGE_STRING plstrClassName
,
2422 PLARGE_STRING plstrClsVersion
,
2423 PLARGE_STRING plstrWindowName
,
2431 HINSTANCE hInstance
,
2437 LARGE_STRING lstrWindowName
;
2438 LARGE_STRING lstrClassName
;
2439 UNICODE_STRING ustrClassName
;
2444 lstrWindowName
.Buffer
= NULL
;
2445 lstrClassName
.Buffer
= NULL
;
2447 ASSERT(plstrWindowName
);
2449 /* Copy the window name to kernel mode */
2450 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2451 if (!NT_SUCCESS(Status
))
2453 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2454 SetLastNtError(Status
);
2458 plstrWindowName
= &lstrWindowName
;
2460 /* Check if the class is an atom */
2461 if (IS_ATOM(plstrClassName
))
2463 /* It is, pass the atom in the UNICODE_STRING */
2464 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2465 ustrClassName
.Length
= 0;
2466 ustrClassName
.MaximumLength
= 0;
2470 /* It's not, capture the class name */
2471 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2472 if (!NT_SUCCESS(Status
))
2474 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2475 /* Set last error, cleanup and return */
2476 SetLastNtError(Status
);
2480 /* We pass it on as a UNICODE_STRING */
2481 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2482 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2483 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2486 /* Fill the CREATESTRUCTW */
2487 /* we will keep here the original parameters */
2489 Cs
.lpCreateParams
= lpParam
;
2490 Cs
.hInstance
= hInstance
;
2492 Cs
.hwndParent
= hWndParent
;
2497 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2498 if (IS_ATOM(plstrClassName
))
2499 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2501 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2502 Cs
.dwExStyle
= dwExStyle
;
2504 UserEnterExclusive();
2506 /* Call the internal function */
2507 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
, NULL
);
2511 ERR("co_UserCreateWindowEx failed!\n");
2513 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2518 if (lstrWindowName
.Buffer
)
2520 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2522 if (lstrClassName
.Buffer
)
2524 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2531 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2538 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2540 hWnd
= Window
->head
.h
;
2541 ti
= PsGetCurrentThreadWin32Thread();
2543 TRACE("co_UserDestroyWindow \n");
2545 /* Check for owner thread */
2546 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2548 /* Check if we are destroying the desktop window */
2549 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2551 EngSetLastError(ERROR_ACCESS_DENIED
);
2556 /* If window was created successfully and it is hooked */
2557 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2559 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2561 ERR("Destroy Window WH_CBT Call Hook return!\n");
2566 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2568 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2570 if (Window
->spwndOwner
)
2572 ERR("DestroyWindow Owner out.\n");
2573 //UserAttachThreadInput(Window->head.pti, Window->spwndOwner->head.pti, FALSE);
2578 /* Inform the parent */
2579 if (Window
->style
& WS_CHILD
)
2581 IntSendParentNotify(Window
, WM_DESTROY
);
2584 /* Look whether the focus is within the tree of windows we will
2587 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2589 if (ti
->MessageQueue
->spwndActive
== Window
&& ti
->MessageQueue
== IntGetFocusMessageQueue())
2591 co_WinPosActivateOtherWindow(Window
);
2595 // Adjust last active.
2596 if ((pwndTemp
= Window
->spwndOwner
))
2598 while (pwndTemp
->spwndOwner
)
2599 pwndTemp
= pwndTemp
->spwndOwner
;
2601 if (pwndTemp
->spwndLastActive
== Window
)
2602 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2605 if (Window
->spwndParent
&& IntIsWindow(Window
->head
.h
))
2607 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2609 if (!IntIsTopLevelWindow(Window
))
2611 ERR("DestroyWindow Parent out.\n");
2612 //UserAttachThreadInput(Window->head.pti, Window->spwndParent->head.pti, FALSE);
2617 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2618 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2619 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2620 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2621 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2622 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2623 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2624 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2627 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2630 if ((ti
!= NULL
) & (ti
->pDeskInfo
!= NULL
))
2632 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2634 ERR("Destroying the ShellWindow!\n");
2635 ti
->pDeskInfo
->hShellWindow
= NULL
;
2639 IntEngWindowChanged(Window
, WOC_DELETE
);
2641 if (!IntIsWindow(Window
->head
.h
))
2646 /* Recursively destroy owned windows */
2648 if (! (Window
->style
& WS_CHILD
))
2652 BOOL GotOne
= FALSE
;
2655 PWND Child
, Desktop
;
2657 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2658 UserGetWindowObject(IntGetDesktopWindow());
2659 Children
= IntWinListChildren(Desktop
);
2663 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2665 Child
= UserGetWindowObject(*ChildHandle
);
2668 if (Child
->spwndOwner
!= Window
)
2673 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2675 USER_REFERENCE_ENTRY ChildRef
;
2676 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2677 co_UserDestroyWindow(Child
);
2678 UserDerefObjectCo(Child
); // Temp HACK?
2684 if (Child
->spwndOwner
!= NULL
)
2686 Child
->spwndOwner
= NULL
;
2690 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2699 /* Generate mouse move message for the next window */
2700 msg
.message
= WM_MOUSEMOVE
;
2701 msg
.wParam
= UserGetMouseButtonsState();
2702 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2703 msg
.pt
= gpsi
->ptCursor
;
2704 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2706 if (!IntIsWindow(Window
->head
.h
))
2711 /* Destroy the window storage */
2712 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2722 NtUserDestroyWindow(HWND Wnd
)
2725 DECLARE_RETURN(BOOLEAN
);
2727 USER_REFERENCE_ENTRY Ref
;
2729 TRACE("Enter NtUserDestroyWindow\n");
2730 UserEnterExclusive();
2732 if (!(Window
= UserGetWindowObject(Wnd
)))
2737 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2738 ret
= co_UserDestroyWindow(Window
);
2739 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2744 TRACE("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2750 static HWND FASTCALL
2751 IntFindWindow(PWND Parent
,
2754 PUNICODE_STRING WindowName
)
2756 BOOL CheckWindowName
;
2759 UNICODE_STRING CurrentWindowName
;
2763 CheckWindowName
= WindowName
->Buffer
!= 0;
2765 if((List
= IntWinListChildren(Parent
)))
2770 /* skip handles before and including ChildAfter */
2771 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2775 /* search children */
2779 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2784 /* Do not send WM_GETTEXT messages in the kernel mode version!
2785 The user mode version however calls GetWindowText() which will
2786 send WM_GETTEXT messages to windows belonging to its processes */
2787 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2789 // FIXME: LARGE_STRING truncated
2790 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2791 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2792 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2793 if(!CheckWindowName
||
2794 (Child
->strName
.Length
< 0xFFFF &&
2795 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2797 Ret
= Child
->head
.h
;
2802 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2810 * Searches a window's children for a window with the specified
2813 * hwndParent = The window whose childs are to be searched.
2815 * HWND_MESSAGE = message-only windows
2817 * hwndChildAfter = Search starts after this child window.
2818 * NULL = start from beginning
2820 * ucClassName = Class name to search for
2821 * Reguired parameter.
2823 * ucWindowName = Window name
2824 * ->Buffer == NULL = don't care
2827 * The HWND of the window if it was found, otherwise NULL
2833 NtUserFindWindowEx(HWND hwndParent
,
2834 HWND hwndChildAfter
,
2835 PUNICODE_STRING ucClassName
,
2836 PUNICODE_STRING ucWindowName
,
2839 PWND Parent
, ChildAfter
;
2840 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2841 HWND Desktop
, Ret
= NULL
;
2842 BOOL DoMessageWnd
= FALSE
;
2843 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2844 DECLARE_RETURN(HWND
);
2846 TRACE("Enter NtUserFindWindowEx\n");
2849 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2853 if (ucClassName
!= NULL
)
2855 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2856 if (ClassName
.Length
!= 0)
2858 ProbeForRead(ClassName
.Buffer
,
2862 else if (!IS_ATOM(ClassName
.Buffer
))
2864 EngSetLastError(ERROR_INVALID_PARAMETER
);
2868 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2875 if (ucWindowName
!= NULL
)
2877 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2878 if (WindowName
.Length
!= 0)
2880 ProbeForRead(WindowName
.Buffer
,
2886 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2888 SetLastNtError(_SEH2_GetExceptionCode());
2889 _SEH2_YIELD(RETURN(NULL
));
2893 if (ucClassName
!= NULL
)
2895 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2896 !IS_ATOM(ClassName
.Buffer
))
2898 EngSetLastError(ERROR_INVALID_PARAMETER
);
2901 else if (ClassAtom
== (RTL_ATOM
)0)
2903 /* LastError code was set by IntGetAtomFromStringOrAtom */
2909 Desktop
= IntGetCurrentThreadDesktopWindow();
2911 if(hwndParent
== NULL
)
2913 hwndParent
= Desktop
;
2914 DoMessageWnd
= TRUE
;
2916 else if(hwndParent
== HWND_MESSAGE
)
2918 hwndParent
= IntGetMessageWindow();
2921 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2927 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2934 if(Parent
->head
.h
== Desktop
)
2937 PWND TopLevelWindow
;
2938 BOOLEAN CheckWindowName
;
2939 BOOLEAN WindowMatches
;
2940 BOOLEAN ClassMatches
;
2942 /* windows searches through all top-level windows if the parent is the desktop
2945 if((List
= IntWinListChildren(Parent
)))
2951 /* skip handles before and including ChildAfter */
2952 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2956 CheckWindowName
= WindowName
.Buffer
!= 0;
2958 /* search children */
2961 UNICODE_STRING ustr
;
2963 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2968 /* Do not send WM_GETTEXT messages in the kernel mode version!
2969 The user mode version however calls GetWindowText() which will
2970 send WM_GETTEXT messages to windows belonging to its processes */
2971 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2972 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
2973 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
2974 WindowMatches
= !CheckWindowName
||
2975 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2976 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2977 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2978 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2980 if (WindowMatches
&& ClassMatches
)
2982 Ret
= TopLevelWindow
->head
.h
;
2986 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2988 /* window returns the handle of the top-level window, in case it found
2990 Ret
= TopLevelWindow
->head
.h
;
2995 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3000 ERR("FindWindowEx: Not Desktop Parent!\n");
3001 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3004 if (Ret
== NULL
&& DoMessageWnd
)
3008 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3010 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3014 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3016 SetLastNtError(_SEH2_GetExceptionCode());
3024 TRACE("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
3033 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3035 PWND WndAncestor
, Parent
;
3037 if (Wnd
->head
.h
== IntGetDesktopWindow())
3046 WndAncestor
= Wnd
->spwndParent
;
3057 if(!(Parent
= WndAncestor
->spwndParent
))
3061 if(IntIsDesktopWindow(Parent
))
3066 WndAncestor
= Parent
;
3079 Parent
= IntGetParent(WndAncestor
);
3086 WndAncestor
= Parent
;
3104 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3106 PWND Window
, Ancestor
;
3107 DECLARE_RETURN(HWND
);
3109 TRACE("Enter NtUserGetAncestor\n");
3110 UserEnterExclusive();
3112 if (!(Window
= UserGetWindowObject(hWnd
)))
3117 Ancestor
= UserGetAncestor(Window
, Type
);
3118 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3120 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3123 TRACE("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3131 NtUserGetComboBoxInfo(
3136 DECLARE_RETURN(BOOL
);
3138 TRACE("Enter NtUserGetComboBoxInfo\n");
3141 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3150 sizeof(COMBOBOXINFO
),
3154 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3156 SetLastNtError(_SEH2_GetExceptionCode());
3157 _SEH2_YIELD(RETURN(FALSE
));
3161 // Pass the user pointer, it was already probed.
3162 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3165 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3173 NtUserGetListBoxInfo(
3177 DECLARE_RETURN(DWORD
);
3179 TRACE("Enter NtUserGetListBoxInfo\n");
3182 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3187 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3190 TRACE("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3198 * The NtUserSetParent function changes the parent window of the specified
3202 * The new parent window and the child window must belong to the same
3203 * application. If the window identified by the hWndChild parameter is
3204 * visible, the system performs the appropriate redrawing and repainting.
3205 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3206 * or WS_POPUP window styles of the window whose parent is being changed.
3213 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3215 DECLARE_RETURN(HWND
);
3217 TRACE("Enter NtUserSetParent\n");
3218 UserEnterExclusive();
3221 Check Parent first from user space, set it here.
3225 hWndNewParent
= IntGetDesktopWindow();
3227 else if (hWndNewParent
== HWND_MESSAGE
)
3229 hWndNewParent
= IntGetMessageWindow();
3232 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3235 TRACE("Leave NtUserSetParent, ret=%i\n",_ret_
);
3241 * UserGetShellWindow
3243 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3248 HWND FASTCALL
UserGetShellWindow(VOID
)
3250 PWINSTATION_OBJECT WinStaObject
;
3253 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3258 if (!NT_SUCCESS(Status
))
3260 SetLastNtError(Status
);
3264 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3266 ObDereferenceObject(WinStaObject
);
3271 * NtUserSetShellWindowEx
3273 * This is undocumented function to set global shell window. The global
3274 * shell window has special handling of window position.
3280 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3282 PWINSTATION_OBJECT WinStaObject
;
3283 PWND WndShell
, WndListView
;
3284 DECLARE_RETURN(BOOL
);
3285 USER_REFERENCE_ENTRY Ref
;
3289 TRACE("Enter NtUserSetShellWindowEx\n");
3290 UserEnterExclusive();
3292 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3297 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3302 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3307 if (!NT_SUCCESS(Status
))
3309 SetLastNtError(Status
);
3314 * Test if we are permitted to change the shell window.
3316 if (WinStaObject
->ShellWindow
)
3318 ObDereferenceObject(WinStaObject
);
3323 * Move shell window into background.
3325 if (hwndListView
&& hwndListView
!= hwndShell
)
3328 * Disabled for now to get Explorer working.
3329 * -- Filip, 01/nov/2003
3332 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3335 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3337 ObDereferenceObject(WinStaObject
);
3342 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3344 ObDereferenceObject(WinStaObject
);
3348 UserRefObjectCo(WndShell
, &Ref
);
3349 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3351 WinStaObject
->ShellWindow
= hwndShell
;
3352 WinStaObject
->ShellListView
= hwndListView
;
3354 ti
= GetW32ThreadInfo();
3357 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3358 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3361 UserDerefObjectCo(WndShell
);
3363 ObDereferenceObject(WinStaObject
);
3367 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3373 * NtUserGetSystemMenu
3375 * The NtUserGetSystemMenu function allows the application to access the
3376 * window menu (also known as the system menu or the control menu) for
3377 * copying and modifying.
3381 * Handle to the window that will own a copy of the window menu.
3383 * Specifies the action to be taken. If this parameter is FALSE,
3384 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3385 * currently in use. The copy is initially identical to the window menu
3386 * but it can be modified.
3387 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3388 * to the default state. The previous window menu, if any, is destroyed.
3391 * If the bRevert parameter is FALSE, the return value is a handle to a
3392 * copy of the window menu. If the bRevert parameter is TRUE, the return
3400 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3404 DECLARE_RETURN(HMENU
);
3406 TRACE("Enter NtUserGetSystemMenu\n");
3409 if (!(Window
= UserGetWindowObject(hWnd
)))
3414 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3419 RETURN(Menu
->MenuInfo
.Self
);
3422 TRACE("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3428 * NtUserSetSystemMenu
3435 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3437 BOOL Result
= FALSE
;
3440 DECLARE_RETURN(BOOL
);
3442 TRACE("Enter NtUserSetSystemMenu\n");
3443 UserEnterExclusive();
3445 if (!(Window
= UserGetWindowObject(hWnd
)))
3453 * Assign new menu handle.
3455 if (!(Menu
= UserGetMenuObject(hMenu
)))
3460 Result
= IntSetSystemMenu(Window
, Menu
);
3466 TRACE("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3471 // Fixes wine Win test_window_styles and todo tests...
3472 static BOOL FASTCALL
3473 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3475 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3477 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3484 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3486 PWND Window
, Parent
;
3487 PWINSTATION_OBJECT WindowStation
;
3491 if (!(Window
= UserGetWindowObject(hWnd
)))
3496 if ((INT
)Index
>= 0)
3498 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3500 EngSetLastError(ERROR_INVALID_INDEX
);
3504 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3506 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3508 OldValue = (LONG)IntSetWindowProc( Wnd,
3511 if (!OldValue) return 0;
3514 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3521 OldValue
= (LONG
) Window
->ExStyle
;
3522 Style
.styleOld
= OldValue
;
3523 Style
.styleNew
= NewValue
;
3525 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3528 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3530 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3533 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3534 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3536 /* WS_EX_WINDOWEDGE depends on some other styles */
3537 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3538 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3540 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3542 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3543 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3547 OldValue
= (LONG
) Window
->style
;
3548 Style
.styleOld
= OldValue
;
3549 Style
.styleNew
= NewValue
;
3550 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3552 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3553 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3554 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3555 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3556 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3558 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3560 Window
->style
= (DWORD
)Style
.styleNew
;
3561 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3566 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3567 Window
->fnid
& FNID_FREED
)
3569 EngSetLastError(ERROR_ACCESS_DENIED
);
3572 OldValue
= (LONG
)IntSetWindowProc(Window
,
3579 OldValue
= (LONG
) Window
->hModule
;
3580 Window
->hModule
= (HINSTANCE
) NewValue
;
3583 case GWL_HWNDPARENT
:
3584 Parent
= Window
->spwndParent
;
3585 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3586 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3588 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3592 OldValue
= (LONG
) Window
->IDMenu
;
3593 Window
->IDMenu
= (UINT
) NewValue
;
3597 OldValue
= Window
->dwUserData
;
3598 Window
->dwUserData
= NewValue
;
3602 ERR("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3603 EngSetLastError(ERROR_INVALID_INDEX
);
3613 * NtUserSetWindowLong
3615 * The NtUserSetWindowLong function changes an attribute of the specified
3616 * window. The function also sets the 32-bit (long) value at the specified
3617 * offset into the extra window memory.
3624 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3626 DECLARE_RETURN(LONG
);
3628 TRACE("Enter NtUserSetWindowLong\n");
3629 UserEnterExclusive();
3631 if (hWnd
== IntGetDesktopWindow())
3633 EngSetLastError(STATUS_ACCESS_DENIED
);
3637 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3640 TRACE("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3646 * NtUserSetWindowWord
3648 * Legacy function similar to NtUserSetWindowLong.
3655 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3659 DECLARE_RETURN(WORD
);
3661 TRACE("Enter NtUserSetWindowWord\n");
3662 UserEnterExclusive();
3664 if (hWnd
== IntGetDesktopWindow())
3666 EngSetLastError(STATUS_ACCESS_DENIED
);
3670 if (!(Window
= UserGetWindowObject(hWnd
)))
3679 case GWL_HWNDPARENT
:
3680 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3684 EngSetLastError(ERROR_INVALID_INDEX
);
3689 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3691 EngSetLastError(ERROR_INVALID_PARAMETER
);
3695 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3696 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3701 TRACE("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3707 QueryWindow based on KJK::Hyperion and James Tabor.
3709 0 = QWUniqueProcessId
3710 1 = QWUniqueThreadId
3713 4 = QWIsHung Implements IsHungAppWindow found
3716 9 = QWKillWindow When I called this with hWnd ==
3717 DesktopWindow, it shutdown the system
3724 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3728 DECLARE_RETURN(UINT
);
3730 TRACE("Enter NtUserQueryWindow\n");
3733 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3740 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3741 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3744 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3745 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3748 case QUERY_WINDOW_ACTIVE
:
3749 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3752 case QUERY_WINDOW_FOCUS
:
3753 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3756 case QUERY_WINDOW_ISHUNG
:
3757 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
->MessageQueue
);
3760 case QUERY_WINDOW_REAL_ID
:
3761 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3764 case QUERY_WINDOW_FOREGROUND
:
3765 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3769 Result
= (DWORD
)NULL
;
3776 TRACE("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3786 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3788 UNICODE_STRING SafeMessageName
;
3791 DECLARE_RETURN(UINT
);
3793 TRACE("Enter NtUserRegisterWindowMessage\n");
3794 UserEnterExclusive();
3796 if(MessageNameUnsafe
== NULL
)
3798 EngSetLastError(ERROR_INVALID_PARAMETER
);
3802 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3803 if(!NT_SUCCESS(Status
))
3805 SetLastNtError(Status
);
3809 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3810 if (SafeMessageName
.Buffer
)
3811 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3815 TRACE("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3832 DECLARE_RETURN(BOOL
);
3834 TRACE("Enter NtUserSetMenu\n");
3835 UserEnterExclusive();
3837 if (!(Window
= UserGetWindowObject(hWnd
)))
3842 if (! IntSetMenu(Window
, Menu
, &Changed
))
3847 if (Changed
&& Repaint
)
3849 USER_REFERENCE_ENTRY Ref
;
3851 UserRefObjectCo(Window
, &Ref
);
3852 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3853 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3855 UserDerefObjectCo(Window
);
3861 TRACE("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3870 NtUserSetWindowFNID(HWND hWnd
,
3874 DECLARE_RETURN(BOOL
);
3876 TRACE("Enter NtUserSetWindowFNID\n");
3877 UserEnterExclusive();
3879 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3884 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3886 EngSetLastError(ERROR_ACCESS_DENIED
);
3890 // From user land we only set these.
3891 if (fnID
!= FNID_DESTROY
)
3892 { // Hacked so we can mark desktop~!
3893 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
3896 EngSetLastError(ERROR_INVALID_PARAMETER
);
3905 TRACE("Leave NtUserSetWindowFNID\n");
3913 * Undocumented function that is called from DefWindowProc to set
3920 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
3923 LARGE_STRING SafeText
;
3924 UNICODE_STRING UnicodeString
;
3927 TRACE("Enter NtUserDefSetText\n");
3929 if (WindowText
!= NULL
)
3933 SafeText
= ProbeForReadLargeString(WindowText
);
3935 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3938 SetLastNtError(_SEH2_GetExceptionCode());
3948 UserEnterExclusive();
3950 if(!(Wnd
= UserGetWindowObject(hWnd
)))
3956 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
3957 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
3958 // Now we know what the bAnsi is for.
3959 RtlInitUnicodeString(&UnicodeString
, NULL
);
3960 if (SafeText
.Buffer
)
3965 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
3967 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
3968 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
3970 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3973 SetLastNtError(_SEH2_GetExceptionCode());
3976 if (!Ret
) goto Exit
;
3979 if (UnicodeString
.Length
!= 0)
3981 if (Wnd
->strName
.MaximumLength
> 0 &&
3982 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
3984 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
3986 Wnd
->strName
.Length
= UnicodeString
.Length
;
3987 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
3988 RtlCopyMemory(Wnd
->strName
.Buffer
,
3989 UnicodeString
.Buffer
,
3990 UnicodeString
.Length
);
3995 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
3996 buf
= Wnd
->strName
.Buffer
;
3997 Wnd
->strName
.Buffer
= NULL
;
4000 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4003 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4004 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4005 if (Wnd
->strName
.Buffer
!= NULL
)
4007 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4008 RtlCopyMemory(Wnd
->strName
.Buffer
,
4009 UnicodeString
.Buffer
,
4010 UnicodeString
.Length
);
4011 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4012 Wnd
->strName
.Length
= UnicodeString
.Length
;
4016 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4024 Wnd
->strName
.Length
= 0;
4025 if (Wnd
->strName
.Buffer
!= NULL
)
4026 Wnd
->strName
.Buffer
[0] = L
'\0';
4029 // FIXME: HAX! Windows does not do this in here!
4030 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4031 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4032 /* Send shell notifications */
4033 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4035 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4040 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4041 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4047 * NtUserInternalGetWindowText
4054 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4059 DECLARE_RETURN(INT
);
4061 TRACE("Enter NtUserInternalGetWindowText\n");
4064 if(lpString
&& (nMaxCount
<= 1))
4066 EngSetLastError(ERROR_INVALID_PARAMETER
);
4070 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4075 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4078 const WCHAR Terminator
= L
'\0';
4080 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4082 Copy
= min(nMaxCount
- 1, Result
);
4085 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4086 if(!NT_SUCCESS(Status
))
4088 SetLastNtError(Status
);
4094 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4095 if(!NT_SUCCESS(Status
))
4097 SetLastNtError(Status
);
4107 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4117 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4123 // ASSERT(OwnerWnd);
4125 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4126 win_array
= IntWinListChildren(OwnerWnd
);
4131 while (win_array
[count
])
4133 while (--count
>= 0)
4135 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4137 if (pWnd
->spwndOwner
!= OwnerWnd
)
4142 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4144 /* In Windows, ShowOwnedPopups(TRUE) generates
4145 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4146 * regardless of the state of the owner
4148 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4154 if (pWnd
->style
& WS_VISIBLE
)
4156 /* In Windows, ShowOwnedPopups(FALSE) generates
4157 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4158 * regardless of the state of the owner
4160 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4166 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4167 TRACE("Leave ShowOwnedPopups\n");