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 /* HELPER FUNCTIONS ***********************************************************/
14 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
16 WORD Action
= LOWORD(wParam
);
17 WORD Flags
= HIWORD(wParam
);
19 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
21 EngSetLastError(ERROR_INVALID_PARAMETER
);
28 EngSetLastError(ERROR_INVALID_PARAMETER
);
32 if (Flags
& UISF_HIDEFOCUS
)
33 Wnd
->HideFocus
= TRUE
;
34 if (Flags
& UISF_HIDEACCEL
)
35 Wnd
->HideAccel
= TRUE
;
39 if (Flags
& UISF_HIDEFOCUS
)
40 Wnd
->HideFocus
= FALSE
;
41 if (Flags
& UISF_HIDEACCEL
)
42 Wnd
->HideAccel
= FALSE
;
49 PWND FASTCALL
IntGetWindowObject(HWND hWnd
)
53 if (!hWnd
) return NULL
;
55 Window
= UserGetWindowObject(hWnd
);
57 Window
->head
.cLockObj
++;
62 PWND FASTCALL
VerifyWnd(PWND pWnd
)
67 if (!pWnd
) return NULL
;
71 hWnd
= UserHMGetHandle(pWnd
);
73 State2
= pWnd
->state2
;
75 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
77 _SEH2_YIELD(return NULL
);
81 if ( UserObjectInDestroy(hWnd
) ||
82 State
& WNDS_DESTROYED
||
83 State2
& WNDS2_INDESTROY
)
90 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
96 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
100 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
101 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
103 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
111 IntSetStyle( PWND pwnd
, ULONG set_bits
, ULONG clear_bits
)
113 ULONG styleOld
, styleNew
;
114 styleOld
= pwnd
->style
;
115 styleNew
= (pwnd
->style
| set_bits
) & ~clear_bits
;
116 if (styleNew
== styleOld
) return styleNew
;
117 pwnd
->style
= styleNew
;
118 if ((styleOld
^ styleNew
) & WS_VISIBLE
) DceResetActiveDCEs( pwnd
);
125 * The function determines whether the specified window handle identifies
126 * an existing window.
130 * Handle to the window to test.
133 * If the window handle identifies an existing window, the return value
134 * is TRUE. If the window handle does not identify an existing window,
135 * the return value is FALSE.
139 IntIsWindow(HWND hWnd
)
143 if (!(Window
= UserGetWindowObject(hWnd
)))
150 IntIsWindowVisible(PWND Wnd
)
155 if (!(Wnd
->style
& WS_VISIBLE
))
160 if (Wnd
->spwndParent
!= NULL
)
161 Wnd
= Wnd
->spwndParent
;
170 IntGetParent(PWND Wnd
)
172 if (Wnd
->style
& WS_POPUP
)
174 return Wnd
->spwndOwner
;
176 else if (Wnd
->style
& WS_CHILD
)
178 return Wnd
->spwndParent
;
186 IntEnableWindow( HWND hWnd
, BOOL bEnable
)
192 if(!(pWnd
= UserGetWindowObject(hWnd
)))
197 /* check if updating is needed */
198 bIsDisabled
= !!(pWnd
->style
& WS_DISABLED
);
199 Update
= bIsDisabled
;
203 IntSetStyle( pWnd
, 0, WS_DISABLED
);
207 Update
= !bIsDisabled
;
209 co_IntSendMessage( hWnd
, WM_CANCELMODE
, 0, 0);
211 /* Remove keyboard focus from that window if it had focus */
212 if (hWnd
== IntGetThreadFocusWindow())
214 co_UserSetFocus(NULL
);
216 IntSetStyle( pWnd
, WS_DISABLED
, 0 );
221 IntNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, pWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
222 co_IntSendMessage(hWnd
, WM_ENABLE
, (LPARAM
)bEnable
, 0);
224 // Return nonzero if it was disabled, or zero if it wasn't:
231 * Compile a list of all child window handles from given window.
234 * This function is similar to Wine WIN_ListChildren. The caller
235 * must free the returned list with ExFreePool.
239 IntWinListChildren(PWND Window
)
243 UINT Index
, NumChildren
= 0;
245 if (!Window
) return NULL
;
247 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
250 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
253 ERR("Failed to allocate memory for children array\n");
254 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
257 for (Child
= Window
->spwndChild
, Index
= 0;
259 Child
= Child
->spwndNext
, ++Index
)
260 List
[Index
] = Child
->head
.h
;
266 /***********************************************************************
269 static void IntSendDestroyMsg(HWND hWnd
)
277 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
279 if (hWnd
== info
.hwndCaret
)
286 Window
= UserGetWindowObject(hWnd
);
289 // USER_REFERENCE_ENTRY Ref;
290 // UserRefObjectCo(Window, &Ref);
292 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
294 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
297 // UserDerefObjectCo(Window);
300 /* The window could already be destroyed here */
303 * Send the WM_DESTROY to the window.
306 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
309 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
310 * make sure that the window still exists when we come back.
319 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
322 /* start from the end (FIXME: is this needed?) */
323 for (i
= 0; pWndArray
[i
]; i
++)
328 if (IsWindow( pWndArray
[i
] ))
329 WIN_SendDestroyMsg( pWndArray
[i
] );
331 HeapFree(GetProcessHeap(), 0, pWndArray
);
335 TRACE("destroyed itself while in WM_DESTROY!\n");
341 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
343 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
347 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
349 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
350 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
353 if (Wnd
->strName
.Buffer
!= NULL
)
355 Wnd
->strName
.Length
= 0;
356 Wnd
->strName
.MaximumLength
= 0;
357 DesktopHeapFree(Wnd
->head
.rpdesk
,
358 Wnd
->strName
.Buffer
);
359 Wnd
->strName
.Buffer
= NULL
;
362 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
363 // WindowObject->Wnd = NULL;
366 /***********************************************************************
369 * Destroy storage associated to a window. "Internals" p.358
371 * This is the "functional" DestroyWindows function ei. all stuff
372 * done in CreateWindow is undone here and not in DestroyWindow:-P
375 static LRESULT
co_UserFreeWindow(PWND Window
,
376 PPROCESSINFO ProcessData
,
377 PTHREADINFO ThreadData
,
378 BOOLEAN SendMessages
)
384 BOOLEAN BelongsToThreadData
;
388 if(Window
->state2
& WNDS2_INDESTROY
)
390 TRACE("Tried to call IntDestroyWindow() twice\n");
393 Window
->state2
|= WNDS2_INDESTROY
;
394 Window
->style
&= ~WS_VISIBLE
;
396 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
398 /* remove the window already at this point from the thread window list so we
399 don't get into trouble when destroying the thread windows while we're still
400 in IntDestroyWindow() */
401 RemoveEntryList(&Window
->ThreadListEntry
);
403 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
405 IntDeRegisterShellHookWindow(Window
->head
.h
);
409 /* Send destroy messages */
410 IntSendDestroyMsg(Window
->head
.h
);
413 /* free child windows */
414 Children
= IntWinListChildren(Window
);
417 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
419 if ((Child
= IntGetWindowObject(*ChildHandle
)))
421 if(!IntWndBelongsToThread(Child
, ThreadData
))
423 /* send WM_DESTROY messages to windows not belonging to the same thread */
424 IntSendDestroyMsg(Child
->head
.h
);
427 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
429 UserDereferenceObject(Child
);
432 ExFreePool(Children
);
438 * Clear the update region to make sure no WM_PAINT messages will be
439 * generated for this window while processing the WM_NCDESTROY.
441 co_UserRedrawWindow(Window
, NULL
, 0,
442 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
443 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
444 if(BelongsToThreadData
)
445 co_IntSendMessage(Window
->head
.h
, WM_NCDESTROY
, 0, 0);
448 DestroyTimersForWindow(ThreadData
, Window
);
450 /* Unregister hot keys */
451 UnregisterWindowHotKeys (Window
);
453 /* flush the message queue */
454 MsqRemoveWindowMessagesFromQueue(Window
);
456 IntDereferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
458 /* from now on no messages can be sent to this window anymore */
459 Window
->state
|= WNDS_DESTROYED
;
460 Window
->fnid
|= FNID_FREED
;
462 /* don't remove the WINDOWSTATUS_DESTROYING bit */
464 /* reset shell window handles */
465 if(ThreadData
->rpdesk
)
467 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
468 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
470 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
471 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
474 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
478 WinPosCheckInternalPos(Window
->head
.h
);
479 if (Window
->head
.h
== GetCapture())
484 /* free resources associated with the window */
485 TIMER_RemoveWindowTimers(Window
->head
.h
);
488 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
490 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
492 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
496 if(Window
->SystemMenu
497 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
499 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
500 Window
->SystemMenu
= (HMENU
)0;
503 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
506 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
507 CLASS_RemoveWindow(Window
->Class
);
510 IntUnlinkWindow(Window
);
512 UserReferenceObject(Window
);
513 UserDeleteObject(Window
->head
.h
, otWindow
);
515 IntDestroyScrollBars(Window
);
517 /* dereference the class */
518 IntDereferenceClass(Window
->pcls
,
519 Window
->head
.pti
->pDeskInfo
,
520 Window
->head
.pti
->ppi
);
525 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
526 GreDeleteObject(Window
->hrgnClip
);
527 Window
->hrgnClip
= NULL
;
530 // ASSERT(Window != NULL);
531 UserFreeWindowInfo(Window
->head
.pti
, Window
);
533 UserDereferenceObject(Window
);
535 UserClipboardFreeWindow(Window
);
541 // Same as User32:IntGetWndProc.
544 IntGetWindowProc(PWND pWnd
,
549 WNDPROC gcpd
, Ret
= 0;
551 ASSERT(UserIsEnteredExclusive() == TRUE
);
555 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
557 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
559 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
562 Ret
= GETPFNCLIENTA(i
);
564 Ret
= GETPFNCLIENTW(i
);
570 if (Class
->fnid
== FNID_EDIT
)
571 Ret
= pWnd
->lpfnWndProc
;
574 Ret
= pWnd
->lpfnWndProc
;
576 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
580 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
581 Ret
= GETPFNCLIENTA(Class
->fnid
);
585 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
586 Ret
= GETPFNCLIENTW(Class
->fnid
);
589 if ( Ret
!= pWnd
->lpfnWndProc
)
592 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
595 gcpd
= (WNDPROC
)UserGetCPD(
597 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
600 return (gcpd
? gcpd
: Ret
);
604 IntSetWindowProc(PWND pWnd
,
609 PCALLPROCDATA CallProc
;
611 WNDPROC Ret
, chWndProc
= NULL
;
613 // Retrieve previous window proc.
614 Ret
= IntGetWindowProc(pWnd
, Ansi
);
618 if (IsCallProcHandle(NewWndProc
))
620 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, otCallProc
);
622 { // Reset new WndProc.
623 NewWndProc
= CallProc
->pfnClientPrevious
;
624 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
625 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
628 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
629 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
631 if (GETPFNCLIENTW(i
) == NewWndProc
)
633 chWndProc
= GETPFNSERVER(i
);
636 if (GETPFNCLIENTA(i
) == NewWndProc
)
638 chWndProc
= GETPFNSERVER(i
);
642 // If match, set/reset to Server Side and clear ansi.
645 pWnd
->lpfnWndProc
= chWndProc
;
646 pWnd
->Unicode
= TRUE
;
647 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
648 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
652 pWnd
->Unicode
= !Ansi
;
653 // Handle the state change in here.
655 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
657 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
659 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
660 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
662 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
664 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
668 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
669 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
673 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
674 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
677 // Now set the new window proc.
678 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
689 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
691 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
693 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
697 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
705 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
706 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Wnd
->head
.h
);
715 NewMenu
= IntGetMenuObject(Menu
);
720 IntReleaseMenuObject(OldMenu
);
722 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
725 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
727 /* Can't use the same menu for two windows */
730 IntReleaseMenuObject(OldMenu
);
732 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
738 Wnd
->IDMenu
= (UINT
) Menu
;
741 NewMenu
->MenuInfo
.Wnd
= Wnd
->head
.h
;
742 IntReleaseMenuObject(NewMenu
);
746 OldMenu
->MenuInfo
.Wnd
= NULL
;
747 IntReleaseMenuObject(OldMenu
);
754 /* INTERNAL ******************************************************************/
758 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
763 USER_REFERENCE_ENTRY Ref
;
764 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
766 while (!IsListEmpty(&WThread
->WindowListHead
))
768 Current
= WThread
->WindowListHead
.Flink
;
769 Wnd
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
771 TRACE("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
773 /* Window removes itself from the list */
776 * FIXME: It is critical that the window removes itself! If now, we will loop
780 //ASSERT(co_UserDestroyWindow(Wnd));
782 UserRefObjectCo(Wnd
, &Ref
); // FIXME: Temp HACK??
783 if (!co_UserDestroyWindow(Wnd
))
785 ERR("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
787 UserDerefObjectCo(Wnd
); // FIXME: Temp HACK??
791 PMENU_OBJECT FASTCALL
792 IntGetSystemMenu(PWND Window
, BOOL bRevert
, BOOL RetMenu
)
794 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
795 PTHREADINFO W32Thread
;
796 HMENU hNewMenu
, hSysMenu
;
797 ROSMENUITEMINFO ItemInfo
;
801 W32Thread
= PsGetCurrentThreadWin32Thread();
803 if(!W32Thread
->rpdesk
)
806 if(Window
->SystemMenu
)
808 Menu
= UserGetMenuObject(Window
->SystemMenu
);
811 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
812 Window
->SystemMenu
= (HMENU
)0;
816 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
818 /* Clone system menu */
819 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
823 NewMenu
= IntCloneMenu(Menu
);
826 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
827 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
828 NewMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
830 //IntReleaseMenuObject(NewMenu);
835 hSysMenu
= UserCreateMenu(FALSE
);
836 if (NULL
== hSysMenu
)
840 SysMenu
= IntGetMenuObject(hSysMenu
);
843 UserDestroyMenu(hSysMenu
);
846 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
847 SysMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
848 hNewMenu
= co_IntLoadSysMenuTemplate();
851 IntReleaseMenuObject(SysMenu
);
852 UserDestroyMenu(hSysMenu
);
855 Menu
= IntGetMenuObject(hNewMenu
);
858 IntReleaseMenuObject(SysMenu
);
859 UserDestroyMenu(hSysMenu
);
863 NewMenu
= IntCloneMenu(Menu
);
866 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
867 IntReleaseMenuObject(NewMenu
);
868 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
870 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
871 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
872 ItemInfo
.fType
= MF_POPUP
;
873 ItemInfo
.fState
= MFS_ENABLED
;
874 ItemInfo
.dwTypeData
= NULL
;
876 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
877 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
879 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
883 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
892 if(Window
->SystemMenu
)
893 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
901 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
906 while (Window
&& ((Window
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
908 if (Window
== Parent
)
913 Window
= Window
->spwndParent
;
920 Link the window into siblings list
921 children and parent are kept in place.
926 PWND WndInsertAfter
/* set to NULL if top sibling */
929 if ((Wnd
->spwndPrev
= WndInsertAfter
))
931 /* link after WndInsertAfter */
932 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
933 Wnd
->spwndNext
->spwndPrev
= Wnd
;
935 Wnd
->spwndPrev
->spwndNext
= Wnd
;
940 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
941 Wnd
->spwndNext
->spwndPrev
= Wnd
;
943 Wnd
->spwndParent
->spwndChild
= Wnd
;
948 Note: Wnd->spwndParent can be null if it is the desktop.
950 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
952 if (hWndPrev
== HWND_NOTOPMOST
)
954 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
955 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
956 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
957 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
960 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
962 if (hWndPrev
== HWND_BOTTOM
)
964 /* Link in the bottom of the list */
967 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
968 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
969 WndInsertAfter
= WndInsertAfter
->spwndNext
;
971 IntLinkWindow(Wnd
, WndInsertAfter
);
972 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
974 else if (hWndPrev
== HWND_TOPMOST
)
976 /* Link in the top of the list */
977 IntLinkWindow(Wnd
, NULL
);
979 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
981 else if (hWndPrev
== HWND_TOP
)
983 /* Link it after the last topmost window */
984 PWND WndInsertBefore
;
986 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
988 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
990 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
992 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
993 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
995 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
998 WndInsertBefore
= WndInsertBefore
->spwndNext
;
1002 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
1006 /* Link it after hWndPrev */
1007 PWND WndInsertAfter
;
1009 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1010 /* Are we called with an erroneous handle */
1011 if(WndInsertAfter
== NULL
)
1013 /* Link in a default position */
1014 IntLinkHwnd(Wnd
, HWND_TOP
);
1018 IntLinkWindow(Wnd
, WndInsertAfter
);
1020 /* Fix the WS_EX_TOPMOST flag */
1021 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1023 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1027 if(WndInsertAfter
->spwndNext
&&
1028 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1030 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1037 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1039 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1042 Wnd
= IntGetWindowObject(hWnd
);
1046 WndOldOwner
= Wnd
->spwndOwner
;
1048 ret
= WndOldOwner
? WndOldOwner
->head
.h
: 0;
1050 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1052 Wnd
->spwndOwner
= WndNewOwner
;
1056 Wnd
->spwndOwner
= NULL
;
1059 UserDereferenceObject(Wnd
);
1064 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1066 PWND WndOldParent
, pWndExam
;
1069 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1072 ASSERT(WndNewParent
);
1073 ASSERT_REFS_CO(Wnd
);
1074 ASSERT_REFS_CO(WndNewParent
);
1076 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1078 EngSetLastError(ERROR_ACCESS_DENIED
);
1082 /* Some applications try to set a child as a parent */
1083 if (IntIsChildWindow(Wnd
, WndNewParent
))
1085 EngSetLastError( ERROR_INVALID_PARAMETER
);
1089 pWndExam
= WndNewParent
; // Load parent Window to examine.
1090 // Now test for set parent to parent hit.
1093 if (Wnd
== pWndExam
)
1095 EngSetLastError(ERROR_INVALID_PARAMETER
);
1098 pWndExam
= pWndExam
->spwndParent
;
1102 * Windows hides the window first, then shows it again
1103 * including the WM_SHOWWINDOW messages and all
1105 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1107 /* Window must belong to current process */
1108 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1111 WndOldParent
= Wnd
->spwndParent
;
1113 if ( WndOldParent
&&
1114 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1115 pt
.x
= Wnd
->rcWindow
.right
;
1117 pt
.x
= Wnd
->rcWindow
.left
;
1118 pt
.y
= Wnd
->rcWindow
.top
;
1120 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1122 if (WndNewParent
!= WndOldParent
)
1124 /* Unlink the window from the siblings list */
1125 IntUnlinkWindow(Wnd
);
1127 /* Set the new parent */
1128 Wnd
->spwndParent
= WndNewParent
;
1130 if ( Wnd
->style
& WS_CHILD
&&
1132 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1134 ERR("SetParent Top Most from Pop up!\n");
1135 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1138 /* Link the window with its new siblings */
1140 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1141 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1145 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1146 swFlags
|= SWP_NOACTIVATE
;
1148 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1150 * SetParent additionally needs to make hwnd the top window
1151 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1152 * WM_WINDOWPOSCHANGED notification messages.
1154 co_WinPosSetWindowPos( Wnd
,
1155 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1156 pt
.x
, pt
.y
, 0, 0, swFlags
);
1158 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1160 return WndOldParent
;
1164 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1166 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1167 HWND hWndOldParent
= NULL
;
1168 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1170 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1172 EngSetLastError(ERROR_INVALID_PARAMETER
);
1176 if (hWndChild
== IntGetDesktopWindow())
1178 EngSetLastError(ERROR_ACCESS_DENIED
);
1184 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1191 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1197 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1202 UserRefObjectCo(Wnd
, &Ref
);
1203 UserRefObjectCo(WndParent
, &ParentRef
);
1204 //ERR("Enter co_IntSetParent\n");
1205 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1206 //ERR("Leave co_IntSetParent\n");
1207 UserDerefObjectCo(WndParent
);
1208 UserDerefObjectCo(Wnd
);
1212 hWndOldParent
= WndOldParent
->head
.h
;
1213 UserDereferenceObject(WndOldParent
);
1216 return( hWndOldParent
);
1220 IntSetSystemMenu(PWND Window
, PMENU_OBJECT Menu
)
1222 PMENU_OBJECT OldMenu
;
1223 if(Window
->SystemMenu
)
1225 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1228 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1229 IntReleaseMenuObject(OldMenu
);
1235 /* FIXME: Check window style, propably return FALSE? */
1236 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1237 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1240 Window
->SystemMenu
= (HMENU
)0;
1245 /* Unlink the window from siblings. children and parent are kept in place. */
1247 IntUnlinkWindow(PWND Wnd
)
1250 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1253 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1255 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1256 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1258 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1261 /* FUNCTIONS *****************************************************************/
1264 * As best as I can figure, this function is used by EnumWindows,
1265 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1267 * It's supposed to build a list of HWNDs to return to the caller.
1268 * We can figure out what kind of list by what parameters are
1276 NtUserBuildHwndList(
1289 return ERROR_INVALID_PARAMETER
;
1291 if (hwndParent
|| !dwThreadId
)
1294 PWND Parent
, Window
;
1298 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1300 return ERROR_INVALID_HANDLE
;
1305 Status
= IntValidateDesktopHandle(hDesktop
,
1309 if(!NT_SUCCESS(Status
))
1311 return ERROR_INVALID_HANDLE
;
1314 hwndParent
= Desktop
->DesktopWindow
;
1321 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1322 (Window
= Parent
->spwndChild
))
1324 BOOL bGoDown
= TRUE
;
1326 Status
= STATUS_SUCCESS
;
1331 if(dwCount
++ < *pBufSize
&& pWnd
)
1335 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1336 *pWnd
= Window
->head
.h
;
1339 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1341 Status
= _SEH2_GetExceptionCode();
1344 if(!NT_SUCCESS(Status
))
1346 SetLastNtError(Status
);
1350 if (Window
->spwndChild
&& bChildren
)
1352 Window
= Window
->spwndChild
;
1357 if (Window
->spwndNext
)
1359 Window
= Window
->spwndNext
;
1363 Window
= Window
->spwndParent
;
1364 if (Window
== Parent
)
1373 ObDereferenceObject(Desktop
);
1376 else // Build EnumThreadWindows list!
1379 PTHREADINFO W32Thread
;
1380 PLIST_ENTRY Current
;
1383 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1384 if (!NT_SUCCESS(Status
))
1386 ERR("Thread Id is not valid!\n");
1387 return ERROR_INVALID_PARAMETER
;
1389 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1391 ObDereferenceObject(Thread
);
1392 ERR("Thread is not initialized!\n");
1393 return ERROR_INVALID_PARAMETER
;
1396 Current
= W32Thread
->WindowListHead
.Flink
;
1397 while (Current
!= &(W32Thread
->WindowListHead
))
1399 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1402 if (dwCount
< *pBufSize
&& pWnd
)
1406 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1407 *pWnd
= Window
->head
.h
;
1410 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1412 Status
= _SEH2_GetExceptionCode();
1415 if (!NT_SUCCESS(Status
))
1417 ERR("Failure to build window list!\n");
1418 SetLastNtError(Status
);
1423 Current
= Window
->ThreadListEntry
.Flink
;
1426 ObDereferenceObject(Thread
);
1429 *pBufSize
= dwCount
;
1430 return STATUS_SUCCESS
;
1433 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1435 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1436 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1438 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1440 USER_REFERENCE_ENTRY Ref
;
1441 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1442 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1444 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1445 (LPARAM
)pWindow
->head
.h
);
1446 UserDerefObjectCo(pWindow
->spwndParent
);
1452 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1454 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1456 /* default positioning for overlapped windows */
1457 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1460 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1462 pMonitor
= UserGetPrimaryMonitor();
1464 /* Check if we don't have a monitor attached yet */
1465 if(pMonitor
== NULL
)
1473 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1475 if (IS_DEFAULT(Cs
->x
))
1477 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1479 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1481 Cs
->x
= ProcessParams
->StartingX
;
1482 Cs
->y
= ProcessParams
->StartingY
;
1486 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1487 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1488 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1489 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1491 /* reset counter and position */
1494 pMonitor
->cWndStack
= 0;
1496 pMonitor
->cWndStack
++;
1500 if (IS_DEFAULT(Cs
->cx
))
1502 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1504 Cs
->cx
= ProcessParams
->CountX
;
1505 Cs
->cy
= ProcessParams
->CountY
;
1509 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1510 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1513 /* neither x nor cx are default. Check the y values .
1514 * In the trace we see Outlook and Outlook Express using
1515 * cy set to CW_USEDEFAULT when opening the address book.
1517 else if (IS_DEFAULT(Cs
->cy
))
1519 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1520 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1525 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1526 if(IS_DEFAULT(Cs
->x
))
1531 if(IS_DEFAULT(Cs
->cx
))
1541 /* Allocates and initializes a window */
1542 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1543 PLARGE_STRING WindowName
,
1551 PTHREADINFO pti
= NULL
;
1552 PMENU_OBJECT SystemMenu
;
1554 BOOL bUnicodeWindow
;
1556 pti
= PsGetCurrentThreadWin32Thread();
1558 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1562 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1563 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1564 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1565 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1569 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1571 * Dialog boxes and message boxes do not inherit layout, so you must
1572 * set the layout explicitly.
1574 if ( Class
->fnid
!= FNID_DIALOG
)
1576 PPROCESSINFO ppi
= PsGetCurrentProcessWin32Process();
1577 if (ppi
->dwLayout
& LAYOUT_RTL
)
1579 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1585 /* Automatically add WS_EX_WINDOWEDGE */
1586 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1587 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1588 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1589 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1591 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1593 /* Is it a unicode window? */
1594 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1595 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1597 /* Allocate the new window */
1598 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1602 sizeof(WND
) + Class
->cbwndExtra
);
1609 TRACE("Created object with handle %X\n", hWnd
);
1611 if (NULL
== pti
->rpdesk
->DesktopWindow
)
1612 { /* HACK: Helper for win32csr/desktopbg.c */
1613 /* If there is no desktop window yet, we must be creating it */
1614 pti
->rpdesk
->DesktopWindow
= hWnd
;
1615 pti
->rpdesk
->pDeskInfo
->spwnd
= pWnd
;
1619 * Fill out the structure describing it.
1621 /* Remember, pWnd->head is setup in object.c ... */
1622 pWnd
->spwndParent
= ParentWindow
;
1623 pWnd
->spwndOwner
= OwnerWindow
;
1625 pWnd
->spwndLastActive
= pWnd
;
1626 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1628 pWnd
->hModule
= Cs
->hInstance
;
1629 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1630 pWnd
->ExStyle
= Cs
->dwExStyle
;
1631 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1632 pWnd
->pActCtx
= acbiBuffer
;
1633 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1634 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1636 IntReferenceMessageQueue(pWnd
->head
.pti
->MessageQueue
);
1637 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1639 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1640 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1643 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1644 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1646 /* BugBoy Comments: Comment below say that System classes are always created
1647 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1648 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1650 No where can I see in code or through testing does the window change back
1651 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1652 see what problems this would cause. */
1654 // Set WndProc from Class.
1655 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1657 // GetWindowProc, test for non server side default classes and set WndProc.
1658 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1662 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1663 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1667 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1668 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1672 // If not an Unicode caller, set Ansi creator bit.
1673 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1675 // Clone Class Ansi/Unicode proc type.
1676 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1678 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1679 pWnd
->Unicode
= FALSE
;
1683 * It seems there can be both an Ansi creator and Unicode Class Window
1684 * WndProc, unless the following overriding conditions occur:
1686 if ( !bUnicodeWindow
&&
1687 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1688 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1689 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1690 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1691 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1692 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1693 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1694 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1695 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1696 { // Override Class and set the window Ansi WndProc.
1697 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1698 pWnd
->Unicode
= FALSE
;
1701 { // Set the window Unicode WndProc.
1702 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1703 pWnd
->Unicode
= TRUE
;
1707 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1708 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1709 Dont understand why it does this. */
1710 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1712 PCALLPROCDATA CallProc
;
1713 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1717 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1718 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
1722 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1726 InitializeListHead(&pWnd
->PropListHead
);
1728 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1730 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1731 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1732 if (pWnd
->strName
.Buffer
== NULL
)
1737 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1738 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1739 pWnd
->strName
.Length
= WindowName
->Length
;
1740 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1743 /* Correct the window style. */
1744 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1746 pWnd
->style
|= WS_CLIPSIBLINGS
;
1747 if (!(pWnd
->style
& WS_POPUP
))
1749 pWnd
->style
|= WS_CAPTION
;
1753 /* WS_EX_WINDOWEDGE depends on some other styles */
1754 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1755 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1756 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1758 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1759 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1760 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1763 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1765 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1766 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1768 /* Create system menu */
1769 if ((Cs
->style
& WS_SYSMENU
)) // && (dwStyle & WS_CAPTION) == WS_CAPTION)
1771 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1774 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1775 IntReleaseMenuObject(SystemMenu
);
1779 /* Set the window menu */
1780 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1783 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1784 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1786 UNICODE_STRING MenuName
;
1789 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1791 MenuName
.Length
= 0;
1792 MenuName
.MaximumLength
= 0;
1793 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1797 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1799 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1800 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1804 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1806 /* Insert the window into the thread's window list. */
1807 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1809 /* Handle "CS_CLASSDC", it is tested first. */
1810 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1811 { /* One DCE per class to have CLASS. */
1812 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1814 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1815 { /* Allocate a DCE for this window. */
1816 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1822 ERR("IntCreateWindow Allocation Error.\n");
1824 UserDereferenceObject(pWnd
);
1826 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1834 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1835 PUNICODE_STRING ClassName
,
1836 PLARGE_STRING WindowName
,
1840 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1841 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1842 PWINSTATION_OBJECT WinSta
;
1846 CBT_CREATEWNDW
* pCbtCreate
;
1848 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1850 DWORD dwShowMode
= SW_SHOW
;
1851 CREATESTRUCTW
*pCsw
= NULL
;
1852 PVOID pszClass
= NULL
, pszName
= NULL
;
1855 /* Get the current window station and reference it */
1856 pti
= GetW32ThreadInfo();
1857 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1859 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1860 return NULL
; // There is nothing to cleanup.
1862 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1863 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1868 /* Get the class and reference it */
1869 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
);
1872 ERR("Failed to find class %wZ\n", ClassName
);
1876 /* Now find the parent and the owner window */
1877 hWndParent
= IntGetDesktopWindow();
1880 if (Cs
->hwndParent
== HWND_MESSAGE
)
1882 Cs
->hwndParent
= hWndParent
= IntGetMessageWindow();
1884 else if (Cs
->hwndParent
)
1886 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1887 hWndOwner
= Cs
->hwndParent
;
1889 hWndParent
= Cs
->hwndParent
;
1891 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1893 ERR("Cannot create a child window without a parrent!\n");
1894 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1895 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1898 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1899 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1901 /* FIXME: Is this correct? */
1903 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
1905 /* Fix the position and the size of the window */
1908 UserRefObjectCo(ParentWindow
, &ParentRef
);
1909 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
1912 /* Allocate and initialize the new window */
1913 Window
= IntCreateWindow(Cs
,
1921 ERR("IntCreateWindow failed!\n");
1925 hWnd
= UserHMGetHandle(Window
);
1926 hwndInsertAfter
= HWND_TOP
;
1928 UserRefObjectCo(Window
, &Ref
);
1929 UserDereferenceObject(Window
);
1930 ObDereferenceObject(WinSta
);
1932 //// Check for a hook to eliminate overhead. ////
1933 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
1935 // Allocate the calling structures Justin Case this goes Global.
1936 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
1937 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
1938 if (!pCsw
|| !pCbtCreate
)
1940 ERR("UserHeapAlloc() failed!\n");
1944 /* Fill the new CREATESTRUCTW */
1945 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
1946 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
1948 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
1949 if (!IS_ATOM(ClassName
->Buffer
))
1951 if (Window
->state
& WNDS_ANSICREATOR
)
1953 ANSI_STRING AnsiString
;
1954 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
1955 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
1958 ERR("UserHeapAlloc() failed!\n");
1961 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
1962 AnsiString
.Buffer
= (PCHAR
)pszClass
;
1963 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
1967 UNICODE_STRING UnicodeString
;
1968 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
1969 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
1972 ERR("UserHeapAlloc() failed!\n");
1975 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
1976 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
1977 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
1979 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
1981 if (WindowName
->Length
)
1983 UNICODE_STRING Name
;
1984 Name
.Buffer
= WindowName
->Buffer
;
1985 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
1986 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
1988 if (Window
->state
& WNDS_ANSICREATOR
)
1990 ANSI_STRING AnsiString
;
1991 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
1992 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
1995 ERR("UserHeapAlloc() failed!\n");
1998 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
1999 AnsiString
.Buffer
= (PCHAR
)pszName
;
2000 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2004 UNICODE_STRING UnicodeString
;
2005 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2006 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2009 ERR("UserHeapAlloc() failed!\n");
2012 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2013 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2014 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2016 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2019 pCbtCreate
->lpcs
= pCsw
;
2020 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2022 //// Call the WH_CBT hook ////
2023 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2026 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2029 // Write back changes.
2034 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2037 /* NCCREATE and WM_NCCALCSIZE need the original values */
2038 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2039 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2041 /* Send the WM_GETMINMAXINFO message */
2045 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2047 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2049 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2050 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2051 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2052 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2053 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2056 Window
->rcWindow
.left
= Cs
->x
;
2057 Window
->rcWindow
.top
= Cs
->y
;
2058 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2059 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2060 if (0 != (Window
->style
& WS_CHILD
) && ParentWindow
)
2062 // ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2063 RECTL_vOffsetRect(&Window
->rcWindow
,
2064 ParentWindow
->rcClient
.left
,
2065 ParentWindow
->rcClient
.top
);
2067 Window
->rcClient
= Window
->rcWindow
;
2069 /* Link the window */
2070 if (NULL
!= ParentWindow
)
2072 /* Link the window into the siblings list */
2073 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2074 IntLinkHwnd(Window
, HWND_BOTTOM
);
2076 IntLinkHwnd(Window
, hwndInsertAfter
);
2079 /* Send the NCCREATE message */
2080 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2083 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2087 /* Send the WM_NCCALCSIZE message */
2088 MaxPos
.x
= Window
->rcWindow
.left
;
2089 MaxPos
.y
= Window
->rcWindow
.top
;
2091 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2093 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2094 MaxPos
.y
- Window
->rcWindow
.top
);
2097 /* Send the WM_CREATE message. */
2098 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2099 if (Result
== (LRESULT
)-1)
2101 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2105 /* Send the EVENT_OBJECT_CREATE event */
2106 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2108 /* By setting the flag below it can be examined to determine if the window
2109 was created successfully and a valid pwnd was passed back to caller since
2110 from here the function has to succeed. */
2111 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2113 /* Send the WM_SIZE and WM_MOVE messages. */
2114 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2116 co_WinPosSendSizeMove(Window
);
2119 /* Show or maybe minimize or maximize the window. */
2121 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2122 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2125 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2127 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2128 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2129 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2130 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2131 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2134 /* Send the WM_PARENTNOTIFY message */
2135 IntSendParentNotify(Window
, WM_CREATE
);
2137 /* Notify the shell that a new window was created */
2138 if ((!hWndParent
) && (!hWndOwner
))
2140 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2143 /* Initialize and show the window's scrollbars */
2144 if (Window
->style
& WS_VSCROLL
)
2146 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2148 if (Window
->style
& WS_HSCROLL
)
2150 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2153 /* Show the new window */
2154 if (Cs
->style
& WS_VISIBLE
)
2156 if (Window
->style
& WS_MAXIMIZE
)
2157 dwShowMode
= SW_SHOW
;
2158 else if (Window
->style
& WS_MINIMIZE
)
2159 dwShowMode
= SW_SHOWMINIMIZED
;
2161 co_WinPosShowWindow(Window
, dwShowMode
);
2163 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2165 ASSERT(ParentWindow
);
2168 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2169 /* ShowWindow won't activate child windows */
2170 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2174 TRACE("co_UserCreateWindowEx(): Created window %X\n", hWnd
);
2180 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2181 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2183 co_UserDestroyWindow(Window
);
2185 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2188 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2189 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2190 if (pszName
) UserHeapFree(pszName
);
2191 if (pszClass
) UserHeapFree(pszClass
);
2195 UserDerefObjectCo(Window
);
2197 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2204 ProbeAndCaptureLargeString(
2205 OUT PLARGE_STRING plstrSafe
,
2206 IN PLARGE_STRING plstrUnsafe
)
2208 LARGE_STRING lstrTemp
;
2209 PVOID pvBuffer
= NULL
;
2213 /* Probe and copy the string */
2214 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2215 lstrTemp
= *plstrUnsafe
;
2217 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2220 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2224 if (lstrTemp
.Length
!= 0)
2226 /* Allocate a buffer from paged pool */
2227 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2230 return STATUS_NO_MEMORY
;
2235 /* Probe and copy the buffer */
2236 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2237 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2239 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2241 /* Cleanup and fail */
2242 ExFreePool(pvBuffer
);
2243 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2248 /* Set the output string */
2249 plstrSafe
->Buffer
= pvBuffer
;
2250 plstrSafe
->Length
= lstrTemp
.Length
;
2251 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2253 return STATUS_SUCCESS
;
2257 * \todo Allow passing plstrClassName as ANSI.
2261 NtUserCreateWindowEx(
2263 PLARGE_STRING plstrClassName
,
2264 PLARGE_STRING plstrClsVersion
,
2265 PLARGE_STRING plstrWindowName
,
2273 HINSTANCE hInstance
,
2279 LARGE_STRING lstrWindowName
;
2280 LARGE_STRING lstrClassName
;
2281 UNICODE_STRING ustrClassName
;
2286 lstrWindowName
.Buffer
= NULL
;
2287 lstrClassName
.Buffer
= NULL
;
2289 ASSERT(plstrWindowName
);
2291 /* Copy the window name to kernel mode */
2292 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2293 if (!NT_SUCCESS(Status
))
2295 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2296 SetLastNtError(Status
);
2300 plstrWindowName
= &lstrWindowName
;
2302 /* Check if the class is an atom */
2303 if (IS_ATOM(plstrClassName
))
2305 /* It is, pass the atom in the UNICODE_STRING */
2306 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2307 ustrClassName
.Length
= 0;
2308 ustrClassName
.MaximumLength
= 0;
2312 /* It's not, capture the class name */
2313 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2314 if (!NT_SUCCESS(Status
))
2316 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2317 /* Set last error, cleanup and return */
2318 SetLastNtError(Status
);
2322 /* We pass it on as a UNICODE_STRING */
2323 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2324 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2325 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2328 /* Fill the CREATESTRUCTW */
2329 /* we will keep here the original parameters */
2331 Cs
.lpCreateParams
= lpParam
;
2332 Cs
.hInstance
= hInstance
;
2334 Cs
.hwndParent
= hWndParent
;
2339 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2340 if (IS_ATOM(plstrClassName
))
2341 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2343 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2344 Cs
.dwExStyle
= dwExStyle
;
2346 UserEnterExclusive();
2348 /* Call the internal function */
2349 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
);
2353 ERR("co_UserCreateWindowEx failed!\n");
2355 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2360 if (lstrWindowName
.Buffer
)
2362 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2364 if (lstrClassName
.Buffer
)
2366 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2373 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2379 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2381 hWnd
= Window
->head
.h
;
2382 ti
= PsGetCurrentThreadWin32Thread();
2384 TRACE("co_UserDestroyWindow \n");
2386 /* Check for owner thread */
2387 if ( (Window
->head
.pti
->pEThread
!= PsGetCurrentThread()) ||
2388 Window
->head
.pti
!= PsGetCurrentThreadWin32Thread() )
2390 EngSetLastError(ERROR_ACCESS_DENIED
);
2394 /* If window was created successfully and it is hooked */
2395 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2397 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2399 ERR("Destroy Window WH_CBT Call Hook return!\n");
2404 /* Inform the parent */
2405 if (Window
->style
& WS_CHILD
)
2407 IntSendParentNotify(Window
, WM_DESTROY
);
2410 /* Look whether the focus is within the tree of windows we will
2413 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2415 if (ti
->MessageQueue
->spwndActive
== Window
&& ti
->MessageQueue
== IntGetFocusMessageQueue())
2416 { ERR("DestroyWindow AOW\n");
2417 co_WinPosActivateOtherWindow(Window
);
2421 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2422 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2423 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2424 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2425 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2426 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2427 if (Window
->head
.pti
->MessageQueue
->CaptureWindow
== Window
->head
.h
)
2428 Window
->head
.pti
->MessageQueue
->CaptureWindow
= NULL
;
2431 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2434 if ((ti
!= NULL
) & (ti
->pDeskInfo
!= NULL
))
2436 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2438 ERR("Destroying the ShellWindow!\n");
2439 ti
->pDeskInfo
->hShellWindow
= NULL
;
2443 IntEngWindowChanged(Window
, WOC_DELETE
);
2445 if (!IntIsWindow(Window
->head
.h
))
2450 /* Recursively destroy owned windows */
2452 if (! (Window
->style
& WS_CHILD
))
2456 BOOL GotOne
= FALSE
;
2459 PWND Child
, Desktop
;
2461 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2462 UserGetWindowObject(IntGetDesktopWindow());
2463 Children
= IntWinListChildren(Desktop
);
2467 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2469 Child
= UserGetWindowObject(*ChildHandle
);
2472 if (Child
->spwndOwner
!= Window
)
2477 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2479 USER_REFERENCE_ENTRY ChildRef
;
2480 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2481 co_UserDestroyWindow(Child
);
2482 UserDerefObjectCo(Child
); // Temp HACK?
2488 if (Child
->spwndOwner
!= NULL
)
2490 Child
->spwndOwner
= NULL
;
2494 ExFreePool(Children
);
2503 /* Generate mouse move message for the next window */
2504 msg
.message
= WM_MOUSEMOVE
;
2505 msg
.wParam
= UserGetMouseButtonsState();
2506 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2507 msg
.pt
= gpsi
->ptCursor
;
2508 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2510 if (!IntIsWindow(Window
->head
.h
))
2515 /* Destroy the window storage */
2516 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2526 NtUserDestroyWindow(HWND Wnd
)
2529 DECLARE_RETURN(BOOLEAN
);
2531 USER_REFERENCE_ENTRY Ref
;
2533 TRACE("Enter NtUserDestroyWindow\n");
2534 UserEnterExclusive();
2536 if (!(Window
= UserGetWindowObject(Wnd
)))
2541 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2542 ret
= co_UserDestroyWindow(Window
);
2543 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2548 TRACE("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2554 static HWND FASTCALL
2555 IntFindWindow(PWND Parent
,
2558 PUNICODE_STRING WindowName
)
2560 BOOL CheckWindowName
;
2563 UNICODE_STRING CurrentWindowName
;
2567 CheckWindowName
= WindowName
->Buffer
!= 0;
2569 if((List
= IntWinListChildren(Parent
)))
2574 /* skip handles before and including ChildAfter */
2575 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2579 /* search children */
2583 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2588 /* Do not send WM_GETTEXT messages in the kernel mode version!
2589 The user mode version however calls GetWindowText() which will
2590 send WM_GETTEXT messages to windows belonging to its processes */
2591 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2593 // FIXME: LARGE_STRING truncated
2594 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2595 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2596 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2597 if(!CheckWindowName
||
2598 (Child
->strName
.Length
< 0xFFFF &&
2599 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2601 Ret
= Child
->head
.h
;
2614 * Searches a window's children for a window with the specified
2617 * hwndParent = The window whose childs are to be searched.
2619 * HWND_MESSAGE = message-only windows
2621 * hwndChildAfter = Search starts after this child window.
2622 * NULL = start from beginning
2624 * ucClassName = Class name to search for
2625 * Reguired parameter.
2627 * ucWindowName = Window name
2628 * ->Buffer == NULL = don't care
2631 * The HWND of the window if it was found, otherwise NULL
2637 NtUserFindWindowEx(HWND hwndParent
,
2638 HWND hwndChildAfter
,
2639 PUNICODE_STRING ucClassName
,
2640 PUNICODE_STRING ucWindowName
,
2643 PWND Parent
, ChildAfter
;
2644 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2645 HWND Desktop
, Ret
= NULL
;
2646 BOOL DoMessageWnd
= FALSE
;
2647 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2648 DECLARE_RETURN(HWND
);
2650 TRACE("Enter NtUserFindWindowEx\n");
2653 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2657 if (ucClassName
!= NULL
)
2659 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2660 if (ClassName
.Length
!= 0)
2662 ProbeForRead(ClassName
.Buffer
,
2666 else if (!IS_ATOM(ClassName
.Buffer
))
2668 EngSetLastError(ERROR_INVALID_PARAMETER
);
2672 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2679 if (ucWindowName
!= NULL
)
2681 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2682 if (WindowName
.Length
!= 0)
2684 ProbeForRead(WindowName
.Buffer
,
2690 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2692 SetLastNtError(_SEH2_GetExceptionCode());
2693 _SEH2_YIELD(RETURN(NULL
));
2697 if (ucClassName
!= NULL
)
2699 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2700 !IS_ATOM(ClassName
.Buffer
))
2702 EngSetLastError(ERROR_INVALID_PARAMETER
);
2705 else if (ClassAtom
== (RTL_ATOM
)0)
2707 /* LastError code was set by IntGetAtomFromStringOrAtom */
2713 Desktop
= IntGetCurrentThreadDesktopWindow();
2715 if(hwndParent
== NULL
)
2717 hwndParent
= Desktop
;
2718 DoMessageWnd
= TRUE
;
2720 else if(hwndParent
== HWND_MESSAGE
)
2722 hwndParent
= IntGetMessageWindow();
2725 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2731 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2738 if(Parent
->head
.h
== Desktop
)
2741 PWND TopLevelWindow
;
2742 BOOLEAN CheckWindowName
;
2743 BOOLEAN WindowMatches
;
2744 BOOLEAN ClassMatches
;
2746 /* windows searches through all top-level windows if the parent is the desktop
2749 if((List
= IntWinListChildren(Parent
)))
2755 /* skip handles before and including ChildAfter */
2756 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2760 CheckWindowName
= WindowName
.Buffer
!= 0;
2762 /* search children */
2765 UNICODE_STRING ustr
;
2767 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2772 /* Do not send WM_GETTEXT messages in the kernel mode version!
2773 The user mode version however calls GetWindowText() which will
2774 send WM_GETTEXT messages to windows belonging to its processes */
2775 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2776 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
2777 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
2778 WindowMatches
= !CheckWindowName
||
2779 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2780 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2781 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2782 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2784 if (WindowMatches
&& ClassMatches
)
2786 Ret
= TopLevelWindow
->head
.h
;
2790 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2792 /* window returns the handle of the top-level window, in case it found
2794 Ret
= TopLevelWindow
->head
.h
;
2804 ERR("FindWindowEx: Not Desktop Parent!\n");
2805 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2808 if (Ret
== NULL
&& DoMessageWnd
)
2812 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2814 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2818 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2820 SetLastNtError(_SEH2_GetExceptionCode());
2828 TRACE("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2837 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
2839 PWND WndAncestor
, Parent
;
2841 if (Wnd
->head
.h
== IntGetDesktopWindow())
2850 WndAncestor
= Wnd
->spwndParent
;
2861 if(!(Parent
= WndAncestor
->spwndParent
))
2865 if(IntIsDesktopWindow(Parent
))
2870 WndAncestor
= Parent
;
2883 Parent
= IntGetParent(WndAncestor
);
2890 WndAncestor
= Parent
;
2908 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2910 PWND Window
, Ancestor
;
2911 DECLARE_RETURN(HWND
);
2913 TRACE("Enter NtUserGetAncestor\n");
2914 UserEnterExclusive();
2916 if (!(Window
= UserGetWindowObject(hWnd
)))
2921 Ancestor
= UserGetAncestor(Window
, Type
);
2922 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
2924 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
2927 TRACE("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
2935 NtUserGetComboBoxInfo(
2940 DECLARE_RETURN(BOOL
);
2942 TRACE("Enter NtUserGetComboBoxInfo\n");
2945 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2954 sizeof(COMBOBOXINFO
),
2958 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2960 SetLastNtError(_SEH2_GetExceptionCode());
2961 _SEH2_YIELD(RETURN(FALSE
));
2965 // Pass the user pointer, it was already probed.
2966 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
2969 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
2977 NtUserGetListBoxInfo(
2981 DECLARE_RETURN(DWORD
);
2983 TRACE("Enter NtUserGetListBoxInfo\n");
2986 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2991 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
2994 TRACE("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3002 * The NtUserSetParent function changes the parent window of the specified
3006 * The new parent window and the child window must belong to the same
3007 * application. If the window identified by the hWndChild parameter is
3008 * visible, the system performs the appropriate redrawing and repainting.
3009 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3010 * or WS_POPUP window styles of the window whose parent is being changed.
3017 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3019 DECLARE_RETURN(HWND
);
3021 TRACE("Enter NtUserSetParent\n");
3022 UserEnterExclusive();
3025 Check Parent first from user space, set it here.
3029 hWndNewParent
= IntGetDesktopWindow();
3031 else if (hWndNewParent
== HWND_MESSAGE
)
3033 hWndNewParent
= IntGetMessageWindow();
3036 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3039 TRACE("Leave NtUserSetParent, ret=%i\n",_ret_
);
3045 * UserGetShellWindow
3047 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3052 HWND FASTCALL
UserGetShellWindow(VOID
)
3054 PWINSTATION_OBJECT WinStaObject
;
3057 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3062 if (!NT_SUCCESS(Status
))
3064 SetLastNtError(Status
);
3068 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3070 ObDereferenceObject(WinStaObject
);
3075 * NtUserSetShellWindowEx
3077 * This is undocumented function to set global shell window. The global
3078 * shell window has special handling of window position.
3084 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3086 PWINSTATION_OBJECT WinStaObject
;
3087 PWND WndShell
, WndListView
;
3088 DECLARE_RETURN(BOOL
);
3089 USER_REFERENCE_ENTRY Ref
;
3093 TRACE("Enter NtUserSetShellWindowEx\n");
3094 UserEnterExclusive();
3096 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3101 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3106 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3111 if (!NT_SUCCESS(Status
))
3113 SetLastNtError(Status
);
3118 * Test if we are permitted to change the shell window.
3120 if (WinStaObject
->ShellWindow
)
3122 ObDereferenceObject(WinStaObject
);
3127 * Move shell window into background.
3129 if (hwndListView
&& hwndListView
!= hwndShell
)
3132 * Disabled for now to get Explorer working.
3133 * -- Filip, 01/nov/2003
3136 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3139 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3141 ObDereferenceObject(WinStaObject
);
3146 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3148 ObDereferenceObject(WinStaObject
);
3152 UserRefObjectCo(WndShell
, &Ref
);
3153 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3155 WinStaObject
->ShellWindow
= hwndShell
;
3156 WinStaObject
->ShellListView
= hwndListView
;
3158 ti
= GetW32ThreadInfo();
3161 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3162 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3165 UserDerefObjectCo(WndShell
);
3167 ObDereferenceObject(WinStaObject
);
3171 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3177 * NtUserGetSystemMenu
3179 * The NtUserGetSystemMenu function allows the application to access the
3180 * window menu (also known as the system menu or the control menu) for
3181 * copying and modifying.
3185 * Handle to the window that will own a copy of the window menu.
3187 * Specifies the action to be taken. If this parameter is FALSE,
3188 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3189 * currently in use. The copy is initially identical to the window menu
3190 * but it can be modified.
3191 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3192 * to the default state. The previous window menu, if any, is destroyed.
3195 * If the bRevert parameter is FALSE, the return value is a handle to a
3196 * copy of the window menu. If the bRevert parameter is TRUE, the return
3204 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3208 DECLARE_RETURN(HMENU
);
3210 TRACE("Enter NtUserGetSystemMenu\n");
3213 if (!(Window
= UserGetWindowObject(hWnd
)))
3218 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3223 RETURN(Menu
->MenuInfo
.Self
);
3226 TRACE("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3232 * NtUserSetSystemMenu
3239 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3241 BOOL Result
= FALSE
;
3244 DECLARE_RETURN(BOOL
);
3246 TRACE("Enter NtUserSetSystemMenu\n");
3247 UserEnterExclusive();
3249 if (!(Window
= UserGetWindowObject(hWnd
)))
3257 * Assign new menu handle.
3259 if (!(Menu
= UserGetMenuObject(hMenu
)))
3264 Result
= IntSetSystemMenu(Window
, Menu
);
3270 TRACE("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3275 // Fixes wine Win test_window_styles and todo tests...
3276 static BOOL FASTCALL
3277 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3279 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3281 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3288 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3290 PWND Window
, Parent
;
3291 PWINSTATION_OBJECT WindowStation
;
3295 if (hWnd
== IntGetDesktopWindow())
3297 EngSetLastError(STATUS_ACCESS_DENIED
);
3301 if (!(Window
= UserGetWindowObject(hWnd
)))
3306 if ((INT
)Index
>= 0)
3308 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3310 EngSetLastError(ERROR_INVALID_INDEX
);
3314 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3316 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3318 OldValue = (LONG)IntSetWindowProc( Wnd,
3321 if (!OldValue) return 0;
3324 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;