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 ExFreePool(Children
);
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
,
1668 PTHREADINFO pti
= NULL
;
1669 PMENU_OBJECT SystemMenu
;
1671 BOOL bUnicodeWindow
;
1673 pti
= PsGetCurrentThreadWin32Thread();
1675 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1679 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1680 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1681 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1682 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1686 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1688 * Dialog boxes and message boxes do not inherit layout, so you must
1689 * set the layout explicitly.
1691 if ( Class
->fnid
!= FNID_DIALOG
)
1693 PPROCESSINFO ppi
= PsGetCurrentProcessWin32Process();
1694 if (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
,
1719 sizeof(WND
) + Class
->cbwndExtra
);
1726 TRACE("Created object with handle %X\n", hWnd
);
1728 if (NULL
== pti
->rpdesk
->DesktopWindow
)
1729 { /* HACK: Helper for win32csr/desktopbg.c */
1730 /* If there is no desktop window yet, we must be creating it */
1731 TRACE("CreateWindow setting desktop.\n");
1732 pti
->rpdesk
->DesktopWindow
= hWnd
;
1733 pti
->rpdesk
->pDeskInfo
->spwnd
= pWnd
;
1737 * Fill out the structure describing it.
1739 /* Remember, pWnd->head is setup in object.c ... */
1740 pWnd
->spwndParent
= ParentWindow
;
1741 pWnd
->spwndOwner
= OwnerWindow
;
1743 pWnd
->spwndLastActive
= pWnd
;
1744 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1746 pWnd
->hModule
= Cs
->hInstance
;
1747 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1748 pWnd
->ExStyle
= Cs
->dwExStyle
;
1749 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1750 pWnd
->pActCtx
= acbiBuffer
;
1751 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1752 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1754 IntReferenceMessageQueue(pWnd
->head
.pti
->MessageQueue
);
1755 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1757 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1758 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1761 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1762 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1764 /* BugBoy Comments: Comment below say that System classes are always created
1765 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1766 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1768 No where can I see in code or through testing does the window change back
1769 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1770 see what problems this would cause. */
1772 // Set WndProc from Class.
1773 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1775 // GetWindowProc, test for non server side default classes and set WndProc.
1776 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1780 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1781 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1785 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1786 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1790 // If not an Unicode caller, set Ansi creator bit.
1791 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1793 // Clone Class Ansi/Unicode proc type.
1794 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1796 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1797 pWnd
->Unicode
= FALSE
;
1801 * It seems there can be both an Ansi creator and Unicode Class Window
1802 * WndProc, unless the following overriding conditions occur:
1804 if ( !bUnicodeWindow
&&
1805 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1806 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1807 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1808 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1809 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1810 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1811 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1812 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1813 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1814 { // Override Class and set the window Ansi WndProc.
1815 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1816 pWnd
->Unicode
= FALSE
;
1819 { // Set the window Unicode WndProc.
1820 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1821 pWnd
->Unicode
= TRUE
;
1825 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1826 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1827 Dont understand why it does this. */
1828 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1830 PCALLPROCDATA CallProc
;
1831 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1835 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1836 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
1840 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1844 InitializeListHead(&pWnd
->PropListHead
);
1846 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1848 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1849 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1850 if (pWnd
->strName
.Buffer
== NULL
)
1855 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1856 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1857 pWnd
->strName
.Length
= WindowName
->Length
;
1858 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1861 /* Correct the window style. */
1862 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1864 pWnd
->style
|= WS_CLIPSIBLINGS
;
1865 if (!(pWnd
->style
& WS_POPUP
))
1867 pWnd
->style
|= WS_CAPTION
;
1871 /* WS_EX_WINDOWEDGE depends on some other styles */
1872 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1873 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1874 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1876 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1877 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1878 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1881 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1883 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1884 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1886 /* Create system menu */
1887 if ((Cs
->style
& WS_SYSMENU
)) // && (dwStyle & WS_CAPTION) == WS_CAPTION)
1889 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1892 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1893 IntReleaseMenuObject(SystemMenu
);
1897 /* Set the window menu */
1898 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1901 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1902 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1904 UNICODE_STRING MenuName
;
1907 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1909 MenuName
.Length
= 0;
1910 MenuName
.MaximumLength
= 0;
1911 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1915 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1917 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1918 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1922 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1925 if ( ParentWindow
&&
1926 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1927 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1929 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1931 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1933 EngSetLastError(ERROR_INVALID_PARAMETER
);
1936 if ( pWnd
->spwndOwner
&&
1937 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1939 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1941 if ( pWnd
->spwndOwner
&&
1942 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1943 pti
!= pWnd
->spwndOwner
->head
.pti
)
1945 ERR("CreateWindow Owner in.\n");
1946 //UserAttachThreadInput(pti, pWnd->spwndOwner->head.pti, TRUE);
1950 /* Insert the window into the thread's window list. */
1951 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1953 /* Handle "CS_CLASSDC", it is tested first. */
1954 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1955 { /* One DCE per class to have CLASS. */
1956 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1958 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1959 { /* Allocate a DCE for this window. */
1960 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1966 ERR("IntCreateWindow Allocation Error.\n");
1967 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1970 UserDereferenceObject(pWnd
);
1978 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1979 PUNICODE_STRING ClassName
,
1980 PLARGE_STRING WindowName
,
1984 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1985 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1986 PWINSTATION_OBJECT WinSta
;
1990 CBT_CREATEWNDW
* pCbtCreate
;
1992 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1994 DWORD dwShowMode
= SW_SHOW
;
1995 CREATESTRUCTW
*pCsw
= NULL
;
1996 PVOID pszClass
= NULL
, pszName
= NULL
;
1999 /* Get the current window station and reference it */
2000 pti
= GetW32ThreadInfo();
2001 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
2003 ERR("Thread is not attached to a desktop! Cannot create window!\n");
2004 return NULL
; // There is nothing to cleanup.
2006 WinSta
= pti
->rpdesk
->rpwinstaParent
;
2007 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
2012 /* Get the class and reference it */
2013 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
);
2016 ERR("Failed to find class %wZ\n", ClassName
);
2020 /* Now find the parent and the owner window */
2021 hWndParent
= IntGetDesktopWindow();
2024 if (Cs
->hwndParent
== HWND_MESSAGE
)
2026 Cs
->hwndParent
= hWndParent
= IntGetMessageWindow();
2028 else if (Cs
->hwndParent
)
2030 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
2031 hWndOwner
= Cs
->hwndParent
;
2033 hWndParent
= Cs
->hwndParent
;
2035 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2037 ERR("Cannot create a child window without a parrent!\n");
2038 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
2039 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
2042 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
2043 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
2045 /* FIXME: Is this correct? */
2047 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
2049 /* Fix the position and the size of the window */
2052 UserRefObjectCo(ParentWindow
, &ParentRef
);
2053 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2056 /* Allocate and initialize the new window */
2057 Window
= IntCreateWindow(Cs
,
2065 ERR("IntCreateWindow failed!\n");
2069 hWnd
= UserHMGetHandle(Window
);
2070 hwndInsertAfter
= HWND_TOP
;
2072 UserRefObjectCo(Window
, &Ref
);
2073 UserDereferenceObject(Window
);
2074 ObDereferenceObject(WinSta
);
2076 //// Check for a hook to eliminate overhead. ////
2077 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2079 // Allocate the calling structures Justin Case this goes Global.
2080 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2081 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2082 if (!pCsw
|| !pCbtCreate
)
2084 ERR("UserHeapAlloc() failed!\n");
2088 /* Fill the new CREATESTRUCTW */
2089 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2090 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2092 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2093 if (!IS_ATOM(ClassName
->Buffer
))
2095 if (Window
->state
& WNDS_ANSICREATOR
)
2097 ANSI_STRING AnsiString
;
2098 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2099 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2102 ERR("UserHeapAlloc() failed!\n");
2105 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2106 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2107 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2111 UNICODE_STRING UnicodeString
;
2112 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2113 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2116 ERR("UserHeapAlloc() failed!\n");
2119 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2120 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2121 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2123 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2125 if (WindowName
->Length
)
2127 UNICODE_STRING Name
;
2128 Name
.Buffer
= WindowName
->Buffer
;
2129 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2130 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2132 if (Window
->state
& WNDS_ANSICREATOR
)
2134 ANSI_STRING AnsiString
;
2135 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2136 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2139 ERR("UserHeapAlloc() failed!\n");
2142 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2143 AnsiString
.Buffer
= (PCHAR
)pszName
;
2144 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2148 UNICODE_STRING UnicodeString
;
2149 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2150 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2153 ERR("UserHeapAlloc() failed!\n");
2156 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2157 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2158 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2160 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2163 pCbtCreate
->lpcs
= pCsw
;
2164 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2166 //// Call the WH_CBT hook ////
2167 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2170 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2173 // Write back changes.
2178 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2181 /* NCCREATE and WM_NCCALCSIZE need the original values */
2182 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2183 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2185 /* Send the WM_GETMINMAXINFO message */
2189 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2191 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2193 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2194 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2195 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2196 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2197 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2200 Window
->rcWindow
.left
= Cs
->x
;
2201 Window
->rcWindow
.top
= Cs
->y
;
2202 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2203 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2204 if (0 != (Window
->style
& WS_CHILD
) && ParentWindow
)
2206 // ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2207 RECTL_vOffsetRect(&Window
->rcWindow
,
2208 ParentWindow
->rcClient
.left
,
2209 ParentWindow
->rcClient
.top
);
2211 Window
->rcClient
= Window
->rcWindow
;
2213 /* Link the window */
2214 if (NULL
!= ParentWindow
)
2216 /* Link the window into the siblings list */
2217 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2218 IntLinkHwnd(Window
, HWND_BOTTOM
);
2220 IntLinkHwnd(Window
, hwndInsertAfter
);
2223 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2225 if ( !IntIsTopLevelWindow(Window
) )
2227 if (pti
!= Window
->spwndParent
->head
.pti
)
2229 ERR("CreateWindow Parent in.\n");
2230 //UserAttachThreadInput(pti, Window->spwndParent->head.pti, TRUE);
2235 /* Send the NCCREATE message */
2236 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2239 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2243 /* Send the WM_NCCALCSIZE message */
2244 MaxPos
.x
= Window
->rcWindow
.left
;
2245 MaxPos
.y
= Window
->rcWindow
.top
;
2247 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2249 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2250 MaxPos
.y
- Window
->rcWindow
.top
);
2253 /* Send the WM_CREATE message. */
2254 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2255 if (Result
== (LRESULT
)-1)
2257 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2261 /* Send the EVENT_OBJECT_CREATE event */
2262 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2264 /* By setting the flag below it can be examined to determine if the window
2265 was created successfully and a valid pwnd was passed back to caller since
2266 from here the function has to succeed. */
2267 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2269 /* Send the WM_SIZE and WM_MOVE messages. */
2270 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2272 co_WinPosSendSizeMove(Window
);
2275 /* Show or maybe minimize or maximize the window. */
2277 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2278 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2281 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2283 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2284 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2285 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2286 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2287 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2290 /* Send the WM_PARENTNOTIFY message */
2291 IntSendParentNotify(Window
, WM_CREATE
);
2293 /* Notify the shell that a new window was created */
2294 if ((!hWndParent
) && (!hWndOwner
))
2296 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2299 /* Initialize and show the window's scrollbars */
2300 if (Window
->style
& WS_VSCROLL
)
2302 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2304 if (Window
->style
& WS_HSCROLL
)
2306 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2309 /* Show the new window */
2310 if (Cs
->style
& WS_VISIBLE
)
2312 if (Window
->style
& WS_MAXIMIZE
)
2313 dwShowMode
= SW_SHOW
;
2314 else if (Window
->style
& WS_MINIMIZE
)
2315 dwShowMode
= SW_SHOWMINIMIZED
;
2317 co_WinPosShowWindow(Window
, dwShowMode
);
2319 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2321 ASSERT(ParentWindow
);
2324 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2325 /* ShowWindow won't activate child windows */
2326 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2330 TRACE("co_UserCreateWindowEx(): Created window %X\n", hWnd
);
2336 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2337 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2339 co_UserDestroyWindow(Window
);
2341 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2344 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2345 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2346 if (pszName
) UserHeapFree(pszName
);
2347 if (pszClass
) UserHeapFree(pszClass
);
2351 UserDerefObjectCo(Window
);
2353 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2360 ProbeAndCaptureLargeString(
2361 OUT PLARGE_STRING plstrSafe
,
2362 IN PLARGE_STRING plstrUnsafe
)
2364 LARGE_STRING lstrTemp
;
2365 PVOID pvBuffer
= NULL
;
2369 /* Probe and copy the string */
2370 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2371 lstrTemp
= *plstrUnsafe
;
2373 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2376 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2380 if (lstrTemp
.Length
!= 0)
2382 /* Allocate a buffer from paged pool */
2383 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2386 return STATUS_NO_MEMORY
;
2391 /* Probe and copy the buffer */
2392 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2393 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2395 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2397 /* Cleanup and fail */
2398 ExFreePool(pvBuffer
);
2399 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2404 /* Set the output string */
2405 plstrSafe
->Buffer
= pvBuffer
;
2406 plstrSafe
->Length
= lstrTemp
.Length
;
2407 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2409 return STATUS_SUCCESS
;
2413 * \todo Allow passing plstrClassName as ANSI.
2417 NtUserCreateWindowEx(
2419 PLARGE_STRING plstrClassName
,
2420 PLARGE_STRING plstrClsVersion
,
2421 PLARGE_STRING plstrWindowName
,
2429 HINSTANCE hInstance
,
2435 LARGE_STRING lstrWindowName
;
2436 LARGE_STRING lstrClassName
;
2437 UNICODE_STRING ustrClassName
;
2442 lstrWindowName
.Buffer
= NULL
;
2443 lstrClassName
.Buffer
= NULL
;
2445 ASSERT(plstrWindowName
);
2447 /* Copy the window name to kernel mode */
2448 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2449 if (!NT_SUCCESS(Status
))
2451 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2452 SetLastNtError(Status
);
2456 plstrWindowName
= &lstrWindowName
;
2458 /* Check if the class is an atom */
2459 if (IS_ATOM(plstrClassName
))
2461 /* It is, pass the atom in the UNICODE_STRING */
2462 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2463 ustrClassName
.Length
= 0;
2464 ustrClassName
.MaximumLength
= 0;
2468 /* It's not, capture the class name */
2469 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2470 if (!NT_SUCCESS(Status
))
2472 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2473 /* Set last error, cleanup and return */
2474 SetLastNtError(Status
);
2478 /* We pass it on as a UNICODE_STRING */
2479 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2480 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2481 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2484 /* Fill the CREATESTRUCTW */
2485 /* we will keep here the original parameters */
2487 Cs
.lpCreateParams
= lpParam
;
2488 Cs
.hInstance
= hInstance
;
2490 Cs
.hwndParent
= hWndParent
;
2495 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2496 if (IS_ATOM(plstrClassName
))
2497 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2499 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2500 Cs
.dwExStyle
= dwExStyle
;
2502 UserEnterExclusive();
2504 /* Call the internal function */
2505 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
);
2509 ERR("co_UserCreateWindowEx failed!\n");
2511 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2516 if (lstrWindowName
.Buffer
)
2518 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2520 if (lstrClassName
.Buffer
)
2522 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2529 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2536 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2538 hWnd
= Window
->head
.h
;
2539 ti
= PsGetCurrentThreadWin32Thread();
2541 TRACE("co_UserDestroyWindow \n");
2543 /* Check for owner thread */
2544 if ( (Window
->head
.pti
->pEThread
!= PsGetCurrentThread()) ||
2545 Window
->head
.pti
!= PsGetCurrentThreadWin32Thread() )
2547 EngSetLastError(ERROR_ACCESS_DENIED
);
2551 /* If window was created successfully and it is hooked */
2552 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2554 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2556 ERR("Destroy Window WH_CBT Call Hook return!\n");
2561 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2563 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2565 if (Window
->spwndOwner
)
2567 ERR("DestroyWindow Owner out.\n");
2568 //UserAttachThreadInput(Window->head.pti, Window->spwndOwner->head.pti, FALSE);
2573 /* Inform the parent */
2574 if (Window
->style
& WS_CHILD
)
2576 IntSendParentNotify(Window
, WM_DESTROY
);
2579 /* Look whether the focus is within the tree of windows we will
2582 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2584 if (ti
->MessageQueue
->spwndActive
== Window
&& ti
->MessageQueue
== IntGetFocusMessageQueue())
2586 co_WinPosActivateOtherWindow(Window
);
2590 // Adjust last active.
2591 if ((pwndTemp
= Window
->spwndOwner
))
2593 while (pwndTemp
->spwndOwner
)
2594 pwndTemp
= pwndTemp
->spwndOwner
;
2596 if (pwndTemp
->spwndLastActive
== Window
)
2597 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2600 if (Window
->spwndParent
&& IntIsWindow(Window
->head
.h
))
2602 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2604 if (!IntIsTopLevelWindow(Window
))
2606 ERR("DestroyWindow Parent out.\n");
2607 //UserAttachThreadInput(Window->head.pti, Window->spwndParent->head.pti, FALSE);
2612 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2613 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2614 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2615 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2616 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2617 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2618 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2619 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2622 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2625 if ((ti
!= NULL
) & (ti
->pDeskInfo
!= NULL
))
2627 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2629 ERR("Destroying the ShellWindow!\n");
2630 ti
->pDeskInfo
->hShellWindow
= NULL
;
2634 IntEngWindowChanged(Window
, WOC_DELETE
);
2636 if (!IntIsWindow(Window
->head
.h
))
2641 /* Recursively destroy owned windows */
2643 if (! (Window
->style
& WS_CHILD
))
2647 BOOL GotOne
= FALSE
;
2650 PWND Child
, Desktop
;
2652 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2653 UserGetWindowObject(IntGetDesktopWindow());
2654 Children
= IntWinListChildren(Desktop
);
2658 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2660 Child
= UserGetWindowObject(*ChildHandle
);
2663 if (Child
->spwndOwner
!= Window
)
2668 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2670 USER_REFERENCE_ENTRY ChildRef
;
2671 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2672 co_UserDestroyWindow(Child
);
2673 UserDerefObjectCo(Child
); // Temp HACK?
2679 if (Child
->spwndOwner
!= NULL
)
2681 Child
->spwndOwner
= NULL
;
2685 ExFreePool(Children
);
2694 /* Generate mouse move message for the next window */
2695 msg
.message
= WM_MOUSEMOVE
;
2696 msg
.wParam
= UserGetMouseButtonsState();
2697 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2698 msg
.pt
= gpsi
->ptCursor
;
2699 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2701 if (!IntIsWindow(Window
->head
.h
))
2706 /* Destroy the window storage */
2707 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2717 NtUserDestroyWindow(HWND Wnd
)
2720 DECLARE_RETURN(BOOLEAN
);
2722 USER_REFERENCE_ENTRY Ref
;
2724 TRACE("Enter NtUserDestroyWindow\n");
2725 UserEnterExclusive();
2727 if (!(Window
= UserGetWindowObject(Wnd
)))
2732 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2733 ret
= co_UserDestroyWindow(Window
);
2734 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2739 TRACE("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2745 static HWND FASTCALL
2746 IntFindWindow(PWND Parent
,
2749 PUNICODE_STRING WindowName
)
2751 BOOL CheckWindowName
;
2754 UNICODE_STRING CurrentWindowName
;
2758 CheckWindowName
= WindowName
->Buffer
!= 0;
2760 if((List
= IntWinListChildren(Parent
)))
2765 /* skip handles before and including ChildAfter */
2766 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2770 /* search children */
2774 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2779 /* Do not send WM_GETTEXT messages in the kernel mode version!
2780 The user mode version however calls GetWindowText() which will
2781 send WM_GETTEXT messages to windows belonging to its processes */
2782 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2784 // FIXME: LARGE_STRING truncated
2785 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2786 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2787 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2788 if(!CheckWindowName
||
2789 (Child
->strName
.Length
< 0xFFFF &&
2790 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2792 Ret
= Child
->head
.h
;
2805 * Searches a window's children for a window with the specified
2808 * hwndParent = The window whose childs are to be searched.
2810 * HWND_MESSAGE = message-only windows
2812 * hwndChildAfter = Search starts after this child window.
2813 * NULL = start from beginning
2815 * ucClassName = Class name to search for
2816 * Reguired parameter.
2818 * ucWindowName = Window name
2819 * ->Buffer == NULL = don't care
2822 * The HWND of the window if it was found, otherwise NULL
2828 NtUserFindWindowEx(HWND hwndParent
,
2829 HWND hwndChildAfter
,
2830 PUNICODE_STRING ucClassName
,
2831 PUNICODE_STRING ucWindowName
,
2834 PWND Parent
, ChildAfter
;
2835 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2836 HWND Desktop
, Ret
= NULL
;
2837 BOOL DoMessageWnd
= FALSE
;
2838 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2839 DECLARE_RETURN(HWND
);
2841 TRACE("Enter NtUserFindWindowEx\n");
2844 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2848 if (ucClassName
!= NULL
)
2850 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2851 if (ClassName
.Length
!= 0)
2853 ProbeForRead(ClassName
.Buffer
,
2857 else if (!IS_ATOM(ClassName
.Buffer
))
2859 EngSetLastError(ERROR_INVALID_PARAMETER
);
2863 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2870 if (ucWindowName
!= NULL
)
2872 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2873 if (WindowName
.Length
!= 0)
2875 ProbeForRead(WindowName
.Buffer
,
2881 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2883 SetLastNtError(_SEH2_GetExceptionCode());
2884 _SEH2_YIELD(RETURN(NULL
));
2888 if (ucClassName
!= NULL
)
2890 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2891 !IS_ATOM(ClassName
.Buffer
))
2893 EngSetLastError(ERROR_INVALID_PARAMETER
);
2896 else if (ClassAtom
== (RTL_ATOM
)0)
2898 /* LastError code was set by IntGetAtomFromStringOrAtom */
2904 Desktop
= IntGetCurrentThreadDesktopWindow();
2906 if(hwndParent
== NULL
)
2908 hwndParent
= Desktop
;
2909 DoMessageWnd
= TRUE
;
2911 else if(hwndParent
== HWND_MESSAGE
)
2913 hwndParent
= IntGetMessageWindow();
2916 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2922 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2929 if(Parent
->head
.h
== Desktop
)
2932 PWND TopLevelWindow
;
2933 BOOLEAN CheckWindowName
;
2934 BOOLEAN WindowMatches
;
2935 BOOLEAN ClassMatches
;
2937 /* windows searches through all top-level windows if the parent is the desktop
2940 if((List
= IntWinListChildren(Parent
)))
2946 /* skip handles before and including ChildAfter */
2947 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2951 CheckWindowName
= WindowName
.Buffer
!= 0;
2953 /* search children */
2956 UNICODE_STRING ustr
;
2958 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2963 /* Do not send WM_GETTEXT messages in the kernel mode version!
2964 The user mode version however calls GetWindowText() which will
2965 send WM_GETTEXT messages to windows belonging to its processes */
2966 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2967 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
2968 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
2969 WindowMatches
= !CheckWindowName
||
2970 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2971 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2972 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2973 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2975 if (WindowMatches
&& ClassMatches
)
2977 Ret
= TopLevelWindow
->head
.h
;
2981 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2983 /* window returns the handle of the top-level window, in case it found
2985 Ret
= TopLevelWindow
->head
.h
;
2995 ERR("FindWindowEx: Not Desktop Parent!\n");
2996 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2999 if (Ret
== NULL
&& DoMessageWnd
)
3003 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3005 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3009 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3011 SetLastNtError(_SEH2_GetExceptionCode());
3019 TRACE("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
3028 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3030 PWND WndAncestor
, Parent
;
3032 if (Wnd
->head
.h
== IntGetDesktopWindow())
3041 WndAncestor
= Wnd
->spwndParent
;
3052 if(!(Parent
= WndAncestor
->spwndParent
))
3056 if(IntIsDesktopWindow(Parent
))
3061 WndAncestor
= Parent
;
3074 Parent
= IntGetParent(WndAncestor
);
3081 WndAncestor
= Parent
;
3099 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3101 PWND Window
, Ancestor
;
3102 DECLARE_RETURN(HWND
);
3104 TRACE("Enter NtUserGetAncestor\n");
3105 UserEnterExclusive();
3107 if (!(Window
= UserGetWindowObject(hWnd
)))
3112 Ancestor
= UserGetAncestor(Window
, Type
);
3113 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3115 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3118 TRACE("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3126 NtUserGetComboBoxInfo(
3131 DECLARE_RETURN(BOOL
);
3133 TRACE("Enter NtUserGetComboBoxInfo\n");
3136 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3145 sizeof(COMBOBOXINFO
),
3149 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3151 SetLastNtError(_SEH2_GetExceptionCode());
3152 _SEH2_YIELD(RETURN(FALSE
));
3156 // Pass the user pointer, it was already probed.
3157 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3160 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3168 NtUserGetListBoxInfo(
3172 DECLARE_RETURN(DWORD
);
3174 TRACE("Enter NtUserGetListBoxInfo\n");
3177 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3182 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3185 TRACE("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3193 * The NtUserSetParent function changes the parent window of the specified
3197 * The new parent window and the child window must belong to the same
3198 * application. If the window identified by the hWndChild parameter is
3199 * visible, the system performs the appropriate redrawing and repainting.
3200 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3201 * or WS_POPUP window styles of the window whose parent is being changed.
3208 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3210 DECLARE_RETURN(HWND
);
3212 TRACE("Enter NtUserSetParent\n");
3213 UserEnterExclusive();
3216 Check Parent first from user space, set it here.
3220 hWndNewParent
= IntGetDesktopWindow();
3222 else if (hWndNewParent
== HWND_MESSAGE
)
3224 hWndNewParent
= IntGetMessageWindow();
3227 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3230 TRACE("Leave NtUserSetParent, ret=%i\n",_ret_
);
3236 * UserGetShellWindow
3238 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3243 HWND FASTCALL
UserGetShellWindow(VOID
)
3245 PWINSTATION_OBJECT WinStaObject
;
3248 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3253 if (!NT_SUCCESS(Status
))
3255 SetLastNtError(Status
);
3259 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3261 ObDereferenceObject(WinStaObject
);
3266 * NtUserSetShellWindowEx
3268 * This is undocumented function to set global shell window. The global
3269 * shell window has special handling of window position.
3275 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3277 PWINSTATION_OBJECT WinStaObject
;
3278 PWND WndShell
, WndListView
;
3279 DECLARE_RETURN(BOOL
);
3280 USER_REFERENCE_ENTRY Ref
;
3284 TRACE("Enter NtUserSetShellWindowEx\n");
3285 UserEnterExclusive();
3287 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3292 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3297 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3302 if (!NT_SUCCESS(Status
))
3304 SetLastNtError(Status
);
3309 * Test if we are permitted to change the shell window.
3311 if (WinStaObject
->ShellWindow
)
3313 ObDereferenceObject(WinStaObject
);
3318 * Move shell window into background.
3320 if (hwndListView
&& hwndListView
!= hwndShell
)
3323 * Disabled for now to get Explorer working.
3324 * -- Filip, 01/nov/2003
3327 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3330 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3332 ObDereferenceObject(WinStaObject
);
3337 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3339 ObDereferenceObject(WinStaObject
);
3343 UserRefObjectCo(WndShell
, &Ref
);
3344 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3346 WinStaObject
->ShellWindow
= hwndShell
;
3347 WinStaObject
->ShellListView
= hwndListView
;
3349 ti
= GetW32ThreadInfo();
3352 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3353 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3356 UserDerefObjectCo(WndShell
);
3358 ObDereferenceObject(WinStaObject
);
3362 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3368 * NtUserGetSystemMenu
3370 * The NtUserGetSystemMenu function allows the application to access the
3371 * window menu (also known as the system menu or the control menu) for
3372 * copying and modifying.
3376 * Handle to the window that will own a copy of the window menu.
3378 * Specifies the action to be taken. If this parameter is FALSE,
3379 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3380 * currently in use. The copy is initially identical to the window menu
3381 * but it can be modified.
3382 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3383 * to the default state. The previous window menu, if any, is destroyed.
3386 * If the bRevert parameter is FALSE, the return value is a handle to a
3387 * copy of the window menu. If the bRevert parameter is TRUE, the return
3395 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3399 DECLARE_RETURN(HMENU
);
3401 TRACE("Enter NtUserGetSystemMenu\n");
3404 if (!(Window
= UserGetWindowObject(hWnd
)))
3409 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3414 RETURN(Menu
->MenuInfo
.Self
);
3417 TRACE("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3423 * NtUserSetSystemMenu
3430 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3432 BOOL Result
= FALSE
;
3435 DECLARE_RETURN(BOOL
);
3437 TRACE("Enter NtUserSetSystemMenu\n");
3438 UserEnterExclusive();
3440 if (!(Window
= UserGetWindowObject(hWnd
)))
3448 * Assign new menu handle.
3450 if (!(Menu
= UserGetMenuObject(hMenu
)))
3455 Result
= IntSetSystemMenu(Window
, Menu
);
3461 TRACE("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3466 // Fixes wine Win test_window_styles and todo tests...
3467 static BOOL FASTCALL
3468 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3470 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3472 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3479 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3481 PWND Window
, Parent
;
3482 PWINSTATION_OBJECT WindowStation
;
3486 if (!(Window
= UserGetWindowObject(hWnd
)))
3491 if ((INT
)Index
>= 0)
3493 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3495 EngSetLastError(ERROR_INVALID_INDEX
);
3499 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3501 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3503 OldValue = (LONG)IntSetWindowProc( Wnd,
3506 if (!OldValue) return 0;
3509 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3516 OldValue
= (LONG
) Window
->ExStyle
;
3517 Style
.styleOld
= OldValue
;
3518 Style
.styleNew
= NewValue
;
3520 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3523 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3525 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3528 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3529 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3531 /* WS_EX_WINDOWEDGE depends on some other styles */
3532 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3533 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3535 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3537 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3538 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3542 OldValue
= (LONG
) Window
->style
;
3543 Style
.styleOld
= OldValue
;
3544 Style
.styleNew
= NewValue
;
3545 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3547 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3548 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3549 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3550 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3551 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3553 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3555 Window
->style
= (DWORD
)Style
.styleNew
;
3556 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3561 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3562 Window
->fnid
& FNID_FREED
)
3564 EngSetLastError(ERROR_ACCESS_DENIED
);
3567 OldValue
= (LONG
)IntSetWindowProc(Window
,
3574 OldValue
= (LONG
) Window
->hModule
;
3575 Window
->hModule
= (HINSTANCE
) NewValue
;
3578 case GWL_HWNDPARENT
:
3579 Parent
= Window
->spwndParent
;
3580 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3581 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3583 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3587 OldValue
= (LONG
) Window
->IDMenu
;
3588 Window
->IDMenu
= (UINT
) NewValue
;
3592 OldValue
= Window
->dwUserData
;
3593 Window
->dwUserData
= NewValue
;
3597 ERR("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3598 EngSetLastError(ERROR_INVALID_INDEX
);
3608 * NtUserSetWindowLong
3610 * The NtUserSetWindowLong function changes an attribute of the specified
3611 * window. The function also sets the 32-bit (long) value at the specified
3612 * offset into the extra window memory.
3619 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3621 DECLARE_RETURN(LONG
);
3623 TRACE("Enter NtUserSetWindowLong\n");
3624 UserEnterExclusive();
3626 if (hWnd
== IntGetDesktopWindow())
3628 EngSetLastError(STATUS_ACCESS_DENIED
);
3632 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3635 TRACE("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3641 * NtUserSetWindowWord
3643 * Legacy function similar to NtUserSetWindowLong.
3650 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3654 DECLARE_RETURN(WORD
);
3656 TRACE("Enter NtUserSetWindowWord\n");
3657 UserEnterExclusive();
3659 if (hWnd
== IntGetDesktopWindow())
3661 EngSetLastError(STATUS_ACCESS_DENIED
);
3665 if (!(Window
= UserGetWindowObject(hWnd
)))
3674 case GWL_HWNDPARENT
:
3675 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3679 EngSetLastError(ERROR_INVALID_INDEX
);
3684 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3686 EngSetLastError(ERROR_INVALID_PARAMETER
);
3690 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3691 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3696 TRACE("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3702 QueryWindow based on KJK::Hyperion and James Tabor.
3704 0 = QWUniqueProcessId
3705 1 = QWUniqueThreadId
3708 4 = QWIsHung Implements IsHungAppWindow found
3711 9 = QWKillWindow When I called this with hWnd ==
3712 DesktopWindow, it shutdown the system
3719 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3723 DECLARE_RETURN(UINT
);
3725 TRACE("Enter NtUserQueryWindow\n");
3728 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3735 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3736 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3739 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3740 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3743 case QUERY_WINDOW_ACTIVE
:
3744 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3747 case QUERY_WINDOW_FOCUS
:
3748 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3751 case QUERY_WINDOW_ISHUNG
:
3752 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
->MessageQueue
);
3755 case QUERY_WINDOW_REAL_ID
:
3756 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3759 case QUERY_WINDOW_FOREGROUND
:
3760 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3764 Result
= (DWORD
)NULL
;
3771 TRACE("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3781 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3783 UNICODE_STRING SafeMessageName
;
3786 DECLARE_RETURN(UINT
);
3788 TRACE("Enter NtUserRegisterWindowMessage\n");
3789 UserEnterExclusive();
3791 if(MessageNameUnsafe
== NULL
)
3793 EngSetLastError(ERROR_INVALID_PARAMETER
);
3797 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3798 if(!NT_SUCCESS(Status
))
3800 SetLastNtError(Status
);
3804 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3805 if (SafeMessageName
.Buffer
)
3806 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3810 TRACE("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3827 DECLARE_RETURN(BOOL
);
3829 TRACE("Enter NtUserSetMenu\n");
3830 UserEnterExclusive();
3832 if (!(Window
= UserGetWindowObject(hWnd
)))
3837 if (! IntSetMenu(Window
, Menu
, &Changed
))
3842 if (Changed
&& Repaint
)
3844 USER_REFERENCE_ENTRY Ref
;
3846 UserRefObjectCo(Window
, &Ref
);
3847 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3848 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3850 UserDerefObjectCo(Window
);
3856 TRACE("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3865 NtUserSetWindowFNID(HWND hWnd
,
3869 DECLARE_RETURN(BOOL
);
3871 TRACE("Enter NtUserSetWindowFNID\n");
3872 UserEnterExclusive();
3874 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3879 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3881 EngSetLastError(ERROR_ACCESS_DENIED
);
3885 // From user land we only set these.
3886 if (fnID
!= FNID_DESTROY
)
3887 { // Hacked so we can mark desktop~!
3888 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
3891 EngSetLastError(ERROR_INVALID_PARAMETER
);
3900 TRACE("Leave NtUserSetWindowFNID\n");
3908 * Undocumented function that is called from DefWindowProc to set
3915 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
3918 LARGE_STRING SafeText
;
3919 UNICODE_STRING UnicodeString
;
3922 TRACE("Enter NtUserDefSetText\n");
3924 if (WindowText
!= NULL
)
3928 SafeText
= ProbeForReadLargeString(WindowText
);
3930 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3933 SetLastNtError(_SEH2_GetExceptionCode());
3943 UserEnterExclusive();
3945 if(!(Wnd
= UserGetWindowObject(hWnd
)))
3951 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
3952 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
3953 // Now we know what the bAnsi is for.
3954 RtlInitUnicodeString(&UnicodeString
, NULL
);
3955 if (SafeText
.Buffer
)
3960 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
3962 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
3963 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
3965 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3968 SetLastNtError(_SEH2_GetExceptionCode());
3971 if (!Ret
) goto Exit
;
3974 if (UnicodeString
.Length
!= 0)
3976 if (Wnd
->strName
.MaximumLength
> 0 &&
3977 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
3979 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
3981 Wnd
->strName
.Length
= UnicodeString
.Length
;
3982 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
3983 RtlCopyMemory(Wnd
->strName
.Buffer
,
3984 UnicodeString
.Buffer
,
3985 UnicodeString
.Length
);
3990 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
3991 buf
= Wnd
->strName
.Buffer
;
3992 Wnd
->strName
.Buffer
= NULL
;
3995 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
3998 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
3999 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4000 if (Wnd
->strName
.Buffer
!= NULL
)
4002 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4003 RtlCopyMemory(Wnd
->strName
.Buffer
,
4004 UnicodeString
.Buffer
,
4005 UnicodeString
.Length
);
4006 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4007 Wnd
->strName
.Length
= UnicodeString
.Length
;
4011 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4019 Wnd
->strName
.Length
= 0;
4020 if (Wnd
->strName
.Buffer
!= NULL
)
4021 Wnd
->strName
.Buffer
[0] = L
'\0';
4024 // FIXME: HAX! Windows does not do this in here!
4025 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4026 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4027 /* Send shell notifications */
4028 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4030 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4035 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4036 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4042 * NtUserInternalGetWindowText
4049 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4054 DECLARE_RETURN(INT
);
4056 TRACE("Enter NtUserInternalGetWindowText\n");
4059 if(lpString
&& (nMaxCount
<= 1))
4061 EngSetLastError(ERROR_INVALID_PARAMETER
);
4065 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4070 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4073 const WCHAR Terminator
= L
'\0';
4075 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4077 Copy
= min(nMaxCount
- 1, Result
);
4080 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4081 if(!NT_SUCCESS(Status
))
4083 SetLastNtError(Status
);
4089 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4090 if(!NT_SUCCESS(Status
))
4092 SetLastNtError(Status
);
4102 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4112 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4118 // ASSERT(OwnerWnd);
4120 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4121 win_array
= IntWinListChildren(OwnerWnd
);
4126 while (win_array
[count
])
4128 while (--count
>= 0)
4130 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4132 if (pWnd
->spwndOwner
!= OwnerWnd
)
4137 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4139 /* In Windows, ShowOwnedPopups(TRUE) generates
4140 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4141 * regardless of the state of the owner
4143 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4149 if (pWnd
->style
& WS_VISIBLE
)
4151 /* In Windows, ShowOwnedPopups(FALSE) generates
4152 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4153 * regardless of the state of the owner
4155 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4161 ExFreePool( win_array
);
4162 TRACE("Leave ShowOwnedPopups\n");