2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
5 * FILE: subsystems/win32/win32k/ntuser/window.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
11 /* INCLUDES ******************************************************************/
18 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
20 /* PRIVATE FUNCTIONS **********************************************************/
25 * Initialize windowing implementation.
33 return STATUS_SUCCESS
;
39 * Cleanup windowing implementation.
43 CleanupWindowImpl(VOID
)
45 return STATUS_SUCCESS
;
48 /* HELPER FUNCTIONS ***********************************************************/
50 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
52 WORD Action
= LOWORD(wParam
);
53 WORD Flags
= HIWORD(wParam
);
55 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
57 EngSetLastError(ERROR_INVALID_PARAMETER
);
64 EngSetLastError(ERROR_INVALID_PARAMETER
);
68 if (Flags
& UISF_HIDEFOCUS
)
69 Wnd
->HideFocus
= TRUE
;
70 if (Flags
& UISF_HIDEACCEL
)
71 Wnd
->HideAccel
= TRUE
;
75 if (Flags
& UISF_HIDEFOCUS
)
76 Wnd
->HideFocus
= FALSE
;
77 if (Flags
& UISF_HIDEACCEL
)
78 Wnd
->HideAccel
= FALSE
;
85 PWND FASTCALL
IntGetWindowObject(HWND hWnd
)
89 if (!hWnd
) return NULL
;
91 Window
= UserGetWindowObject(hWnd
);
94 ASSERT(Window
->head
.cLockObj
>= 0);
96 Window
->head
.cLockObj
++;
102 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
108 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
112 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
113 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
115 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
119 ASSERT(Window
->head
.cLockObj
>= 0);
128 * The function determines whether the specified window handle identifies
129 * an existing window.
133 * Handle to the window to test.
136 * If the window handle identifies an existing window, the return value
137 * is TRUE. If the window handle does not identify an existing window,
138 * the return value is FALSE.
142 IntIsWindow(HWND hWnd
)
146 if (!(Window
= UserGetWindowObject(hWnd
)))
154 IntGetParent(PWND Wnd
)
156 if (Wnd
->style
& WS_POPUP
)
158 return Wnd
->spwndOwner
;
160 else if (Wnd
->style
& WS_CHILD
)
162 return Wnd
->spwndParent
;
170 IntEnableWindow( HWND hWnd
, BOOL bEnable
)
176 if(!(pWnd
= UserGetWindowObject(hWnd
)))
181 /* check if updating is needed */
182 bIsDisabled
= (pWnd
->style
& WS_DISABLED
);
183 Update
= bIsDisabled
;
187 pWnd
->style
&= ~WS_DISABLED
;
191 Update
= !bIsDisabled
;
193 co_IntSendMessage( hWnd
, WM_CANCELMODE
, 0, 0);
195 /* Remove keyboard focus from that window if it had focus */
196 if (hWnd
== IntGetThreadFocusWindow())
198 co_UserSetFocus(NULL
);
200 pWnd
->style
|= WS_DISABLED
;
205 IntNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, pWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
206 co_IntSendMessage(hWnd
, WM_ENABLE
, (LPARAM
)bEnable
, 0);
208 // Return nonzero if it was disabled, or zero if it wasn't:
215 * Compile a list of all child window handles from given window.
218 * This function is similar to Wine WIN_ListChildren. The caller
219 * must free the returned list with ExFreePool.
223 IntWinListChildren(PWND Window
)
227 UINT Index
, NumChildren
= 0;
229 if (!Window
) return NULL
;
231 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
234 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
237 DPRINT1("Failed to allocate memory for children array\n");
238 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
241 for (Child
= Window
->spwndChild
, Index
= 0;
243 Child
= Child
->spwndNext
, ++Index
)
244 List
[Index
] = Child
->head
.h
;
250 /***********************************************************************
253 static void IntSendDestroyMsg(HWND hWnd
)
261 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
263 if (hWnd
== info
.hwndCaret
)
270 Window
= UserGetWindowObject(hWnd
);
273 // USER_REFERENCE_ENTRY Ref;
274 // UserRefObjectCo(Window, &Ref);
276 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
278 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
281 // UserDerefObjectCo(Window);
284 /* The window could already be destroyed here */
287 * Send the WM_DESTROY to the window.
290 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
293 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
294 * make sure that the window still exists when we come back.
303 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
306 /* start from the end (FIXME: is this needed?) */
307 for (i
= 0; pWndArray
[i
]; i
++)
312 if (IsWindow( pWndArray
[i
] ))
313 WIN_SendDestroyMsg( pWndArray
[i
] );
315 HeapFree(GetProcessHeap(), 0, pWndArray
);
319 DPRINT("destroyed itself while in WM_DESTROY!\n");
325 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
327 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
331 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
333 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
334 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
337 if (Wnd
->strName
.Buffer
!= NULL
)
339 Wnd
->strName
.Length
= 0;
340 Wnd
->strName
.MaximumLength
= 0;
341 DesktopHeapFree(Wnd
->head
.rpdesk
,
342 Wnd
->strName
.Buffer
);
343 Wnd
->strName
.Buffer
= NULL
;
346 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
347 // WindowObject->Wnd = NULL;
350 /***********************************************************************
353 * Destroy storage associated to a window. "Internals" p.358
355 * This is the "functional" DestroyWindows function ei. all stuff
356 * done in CreateWindow is undone here and not in DestroyWindow:-P
359 static LRESULT
co_UserFreeWindow(PWND Window
,
360 PPROCESSINFO ProcessData
,
361 PTHREADINFO ThreadData
,
362 BOOLEAN SendMessages
)
368 BOOLEAN BelongsToThreadData
;
372 if(Window
->state2
& WNDS2_INDESTROY
)
374 DPRINT("Tried to call IntDestroyWindow() twice\n");
377 Window
->state2
|= WNDS2_INDESTROY
;
378 Window
->style
&= ~WS_VISIBLE
;
380 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
382 /* remove the window already at this point from the thread window list so we
383 don't get into trouble when destroying the thread windows while we're still
384 in IntDestroyWindow() */
385 RemoveEntryList(&Window
->ThreadListEntry
);
387 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
389 IntDeRegisterShellHookWindow(Window
->head
.h
);
393 /* Send destroy messages */
394 IntSendDestroyMsg(Window
->head
.h
);
397 /* free child windows */
398 Children
= IntWinListChildren(Window
);
401 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
403 if ((Child
= IntGetWindowObject(*ChildHandle
)))
405 if(!IntWndBelongsToThread(Child
, ThreadData
))
407 /* send WM_DESTROY messages to windows not belonging to the same thread */
408 IntSendDestroyMsg(Child
->head
.h
);
411 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
413 UserDereferenceObject(Child
);
416 ExFreePool(Children
);
422 * Clear the update region to make sure no WM_PAINT messages will be
423 * generated for this window while processing the WM_NCDESTROY.
425 co_UserRedrawWindow(Window
, NULL
, 0,
426 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
427 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
428 if(BelongsToThreadData
)
429 co_IntSendMessage(Window
->head
.h
, WM_NCDESTROY
, 0, 0);
432 DestroyTimersForWindow(ThreadData
, Window
);
434 /* Unregister hot keys */
435 UnregisterWindowHotKeys (Window
);
437 /* flush the message queue */
438 MsqRemoveWindowMessagesFromQueue(Window
);
440 IntDereferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
442 /* from now on no messages can be sent to this window anymore */
443 Window
->state
|= WNDS_DESTROYED
;
444 Window
->fnid
|= FNID_FREED
;
446 /* don't remove the WINDOWSTATUS_DESTROYING bit */
448 /* reset shell window handles */
449 if(ThreadData
->rpdesk
)
451 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
452 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
454 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
455 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
458 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
462 WinPosCheckInternalPos(Window
->head
.h
);
463 if (Window
->head
.h
== GetCapture())
468 /* free resources associated with the window */
469 TIMER_RemoveWindowTimers(Window
->head
.h
);
472 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
474 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
476 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
480 if(Window
->SystemMenu
481 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
483 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
484 Window
->SystemMenu
= (HMENU
)0;
487 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
490 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
491 CLASS_RemoveWindow(Window
->Class
);
494 IntUnlinkWindow(Window
);
496 UserReferenceObject(Window
);
497 UserDeleteObject(Window
->head
.h
, otWindow
);
499 IntDestroyScrollBars(Window
);
501 /* dereference the class */
502 IntDereferenceClass(Window
->pcls
,
503 Window
->head
.pti
->pDeskInfo
,
504 Window
->head
.pti
->ppi
);
509 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
510 GreDeleteObject(Window
->hrgnClip
);
511 Window
->hrgnClip
= NULL
;
514 // ASSERT(Window != NULL);
515 UserFreeWindowInfo(Window
->head
.pti
, Window
);
517 UserDereferenceObject(Window
);
519 IntClipboardFreeWindow(Window
);
525 IntGetWindowBorderMeasures(PWND Wnd
, UINT
*cx
, UINT
*cy
)
527 if(HAS_DLGFRAME(Wnd
->style
, Wnd
->ExStyle
) && !(Wnd
->style
& WS_MINIMIZE
))
529 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
530 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
534 if(HAS_THICKFRAME(Wnd
->style
, Wnd
->ExStyle
)&& !(Wnd
->style
& WS_MINIMIZE
))
536 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
537 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
539 else if(HAS_THINFRAME(Wnd
->style
, Wnd
->ExStyle
))
541 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
542 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
552 // Same as User32:IntGetWndProc.
555 IntGetWindowProc(PWND pWnd
,
560 WNDPROC gcpd
, Ret
= 0;
562 ASSERT(UserIsEnteredExclusive() == TRUE
);
566 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
568 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
570 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
573 Ret
= GETPFNCLIENTA(i
);
575 Ret
= GETPFNCLIENTW(i
);
581 if (Class
->fnid
== FNID_EDIT
)
582 Ret
= pWnd
->lpfnWndProc
;
585 Ret
= pWnd
->lpfnWndProc
;
587 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
591 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
592 Ret
= GETPFNCLIENTA(Class
->fnid
);
596 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
597 Ret
= GETPFNCLIENTW(Class
->fnid
);
600 if ( Ret
!= pWnd
->lpfnWndProc
)
603 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
606 gcpd
= (WNDPROC
)UserGetCPD(
608 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
611 return (gcpd
? gcpd
: Ret
);
615 IntSetWindowProc(PWND pWnd
,
620 PCALLPROCDATA CallProc
;
622 WNDPROC Ret
, chWndProc
= NULL
;
624 // Retrieve previous window proc.
625 Ret
= IntGetWindowProc(pWnd
, Ansi
);
629 if (IsCallProcHandle(NewWndProc
))
631 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, otCallProc
);
633 { // Reset new WndProc.
634 NewWndProc
= CallProc
->pfnClientPrevious
;
635 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
636 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
639 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
640 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
642 if (GETPFNCLIENTW(i
) == NewWndProc
)
644 chWndProc
= GETPFNSERVER(i
);
647 if (GETPFNCLIENTA(i
) == NewWndProc
)
649 chWndProc
= GETPFNSERVER(i
);
653 // If match, set/reset to Server Side and clear ansi.
656 pWnd
->lpfnWndProc
= chWndProc
;
657 pWnd
->Unicode
= TRUE
;
658 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
659 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
663 pWnd
->Unicode
= !Ansi
;
664 // Handle the state change in here.
666 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
668 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
670 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
671 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
673 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
675 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
679 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
680 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
684 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
685 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
688 // Now set the new window proc.
689 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
700 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
702 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
704 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
708 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
716 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
717 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Wnd
->head
.h
);
726 NewMenu
= IntGetMenuObject(Menu
);
731 IntReleaseMenuObject(OldMenu
);
733 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
736 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
738 /* Can't use the same menu for two windows */
741 IntReleaseMenuObject(OldMenu
);
743 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
749 Wnd
->IDMenu
= (UINT
) Menu
;
752 NewMenu
->MenuInfo
.Wnd
= Wnd
->head
.h
;
753 IntReleaseMenuObject(NewMenu
);
757 OldMenu
->MenuInfo
.Wnd
= NULL
;
758 IntReleaseMenuObject(OldMenu
);
765 /* INTERNAL ******************************************************************/
769 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
774 USER_REFERENCE_ENTRY Ref
;
775 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
777 while (!IsListEmpty(&WThread
->WindowListHead
))
779 Current
= WThread
->WindowListHead
.Flink
;
780 Wnd
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
782 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
784 /* window removes itself from the list */
787 fixme: it is critical that the window removes itself! if now, we will loop
791 //ASSERT(co_UserDestroyWindow(Wnd));
793 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
794 if (!co_UserDestroyWindow(Wnd
))
796 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
798 UserDerefObjectCo(Wnd
);//faxme: temp hack??
806 * Returns client window rectangle relative to the upper-left corner of client area.
808 * \note Does not check the validity of the parameters
811 IntGetClientRect(PWND Window
, RECTL
*Rect
)
816 Rect
->left
= Rect
->top
= 0;
817 Rect
->right
= Window
->rcClient
.right
- Window
->rcClient
.left
;
818 Rect
->bottom
= Window
->rcClient
.bottom
- Window
->rcClient
.top
;
822 PMENU_OBJECT FASTCALL
823 IntGetSystemMenu(PWND Window
, BOOL bRevert
, BOOL RetMenu
)
825 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
826 PTHREADINFO W32Thread
;
827 HMENU hNewMenu
, hSysMenu
;
828 ROSMENUITEMINFO ItemInfo
;
832 W32Thread
= PsGetCurrentThreadWin32Thread();
834 if(!W32Thread
->rpdesk
)
837 if(Window
->SystemMenu
)
839 Menu
= UserGetMenuObject(Window
->SystemMenu
);
842 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
843 Window
->SystemMenu
= (HMENU
)0;
847 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
849 /* clone system menu */
850 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
854 NewMenu
= IntCloneMenu(Menu
);
857 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
858 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
859 NewMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
861 //IntReleaseMenuObject(NewMenu);
866 hSysMenu
= UserCreateMenu(FALSE
);
867 if (NULL
== hSysMenu
)
871 SysMenu
= IntGetMenuObject(hSysMenu
);
874 UserDestroyMenu(hSysMenu
);
877 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
878 SysMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
879 hNewMenu
= co_IntLoadSysMenuTemplate();
882 IntReleaseMenuObject(SysMenu
);
883 UserDestroyMenu(hSysMenu
);
886 Menu
= IntGetMenuObject(hNewMenu
);
889 IntReleaseMenuObject(SysMenu
);
890 UserDestroyMenu(hSysMenu
);
894 NewMenu
= IntCloneMenu(Menu
);
897 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
898 IntReleaseMenuObject(NewMenu
);
899 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
901 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
902 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
903 ItemInfo
.fType
= MF_POPUP
;
904 ItemInfo
.fState
= MFS_ENABLED
;
905 ItemInfo
.dwTypeData
= NULL
;
907 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
908 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
910 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
914 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
923 if(Window
->SystemMenu
)
924 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
932 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
937 while (Window
&& ((Window
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
939 if (Window
== Parent
)
944 Window
= Window
->spwndParent
;
951 IntIsWindowVisible(PWND BaseWindow
)
958 if(!(Window
->style
& WS_CHILD
))
962 if(!(Window
->style
& WS_VISIBLE
))
967 Window
= Window
->spwndParent
;
970 if(Window
&& Window
->style
& WS_VISIBLE
)
980 link the window into siblings list
981 children and parent are kept in place.
986 PWND WndInsertAfter
/* set to NULL if top sibling */
989 if ((Wnd
->spwndPrev
= WndInsertAfter
))
991 /* link after WndInsertAfter */
992 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
993 Wnd
->spwndNext
->spwndPrev
= Wnd
;
995 Wnd
->spwndPrev
->spwndNext
= Wnd
;
1000 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
1001 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1003 Wnd
->spwndParent
->spwndChild
= Wnd
;
1008 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
1010 if (hWndPrev
== HWND_NOTOPMOST
)
1012 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1013 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
1014 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1015 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
1018 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
1020 if (hWndPrev
== HWND_BOTTOM
)
1022 /* Link in the bottom of the list */
1023 PWND WndInsertAfter
;
1025 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
1026 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
1027 WndInsertAfter
= WndInsertAfter
->spwndNext
;
1029 IntLinkWindow(Wnd
, WndInsertAfter
);
1030 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1032 else if (hWndPrev
== HWND_TOPMOST
)
1034 /* Link in the top of the list */
1035 IntLinkWindow(Wnd
, NULL
);
1037 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1039 else if (hWndPrev
== HWND_TOP
)
1041 /* Link it after the last topmost window */
1042 PWND WndInsertBefore
;
1044 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
1046 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
1048 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
1050 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
1051 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
1053 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1056 WndInsertBefore
= WndInsertBefore
->spwndNext
;
1060 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
1064 /* Link it after hWndPrev */
1065 PWND WndInsertAfter
;
1067 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1068 /* Are we called with an erroneous handle */
1069 if(WndInsertAfter
== NULL
)
1071 /* Link in a default position */
1072 IntLinkHwnd(Wnd
, HWND_TOP
);
1076 IntLinkWindow(Wnd
, WndInsertAfter
);
1078 /* Fix the WS_EX_TOPMOST flag */
1079 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1081 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1085 if(WndInsertAfter
->spwndNext
&&
1086 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1088 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1095 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1097 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1100 Wnd
= IntGetWindowObject(hWnd
);
1104 WndOldOwner
= Wnd
->spwndOwner
;
1106 ret
= WndOldOwner
? WndOldOwner
->head
.h
: 0;
1108 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1110 Wnd
->spwndOwner
= WndNewOwner
;
1114 Wnd
->spwndOwner
= NULL
;
1117 UserDereferenceObject(Wnd
);
1122 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1124 PWND WndOldParent
, pWndExam
;
1128 ASSERT(WndNewParent
);
1129 ASSERT_REFS_CO(Wnd
);
1130 ASSERT_REFS_CO(WndNewParent
);
1132 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1134 EngSetLastError(ERROR_ACCESS_DENIED
);
1138 /* Some applications try to set a child as a parent */
1139 if (IntIsChildWindow(Wnd
, WndNewParent
))
1141 EngSetLastError( ERROR_INVALID_PARAMETER
);
1145 pWndExam
= WndNewParent
; // Load parent Window to examine.
1146 // Now test for set parent to parent hit.
1149 if (Wnd
== pWndExam
)
1151 EngSetLastError(ERROR_INVALID_PARAMETER
);
1154 pWndExam
= pWndExam
->spwndParent
;
1158 * Windows hides the window first, then shows it again
1159 * including the WM_SHOWWINDOW messages and all
1161 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1163 /* Window must belong to current process */
1164 if (Wnd
->head
.pti
->pEThread
->ThreadsProcess
!= PsGetCurrentProcess())
1167 WndOldParent
= Wnd
->spwndParent
;
1169 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1171 if (WndNewParent
!= WndOldParent
)
1173 /* Unlink the window from the siblings list */
1174 IntUnlinkWindow(Wnd
);
1176 /* Set the new parent */
1177 Wnd
->spwndParent
= WndNewParent
;
1179 /* Link the window with its new siblings*/
1180 IntLinkHwnd(Wnd
, HWND_TOP
);
1184 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1186 * SetParent additionally needs to make hwnd the top window
1187 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1188 * WM_WINDOWPOSCHANGED notification messages.
1190 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1191 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1192 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1195 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1196 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1199 return WndOldParent
;
1203 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1205 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1206 HWND hWndOldParent
= NULL
;
1207 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1209 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1211 EngSetLastError(ERROR_INVALID_PARAMETER
);
1215 if (hWndChild
== IntGetDesktopWindow())
1217 EngSetLastError(ERROR_ACCESS_DENIED
);
1223 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1230 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1236 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1241 UserRefObjectCo(Wnd
, &Ref
);
1242 UserRefObjectCo(WndParent
, &ParentRef
);
1244 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1246 UserDerefObjectCo(WndParent
);
1247 UserDerefObjectCo(Wnd
);
1251 hWndOldParent
= WndOldParent
->head
.h
;
1252 UserDereferenceObject(WndOldParent
);
1255 return( hWndOldParent
);
1259 IntSetSystemMenu(PWND Window
, PMENU_OBJECT Menu
)
1261 PMENU_OBJECT OldMenu
;
1262 if(Window
->SystemMenu
)
1264 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1267 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1268 IntReleaseMenuObject(OldMenu
);
1274 /* FIXME check window style, propably return FALSE ? */
1275 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1276 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1279 Window
->SystemMenu
= (HMENU
)0;
1284 /* unlink the window from siblings. children and parent are kept in place. */
1286 IntUnlinkWindow(PWND Wnd
)
1289 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1292 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1294 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1295 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1297 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1302 IntGetWindowPlacement(PWND Wnd
, WINDOWPLACEMENT
*lpwndpl
)
1306 if (!Wnd
) return FALSE
;
1308 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1314 if (0 == (Wnd
->style
& WS_VISIBLE
))
1316 lpwndpl
->showCmd
= SW_HIDE
;
1318 else if (0 != (Wnd
->state2
& WNDS2_MAXIMIZEBUTTONDOWN
) ||
1319 0 != (Wnd
->style
& WS_MAXIMIZE
))
1321 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1323 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1325 lpwndpl
->showCmd
= SW_MINIMIZE
;
1327 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1329 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1332 Size
.x
= Wnd
->rcWindow
.left
;
1333 Size
.y
= Wnd
->rcWindow
.top
;
1334 WinPosInitInternalPos(Wnd
, &Size
,
1337 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1338 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1339 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1345 /* FUNCTIONS *****************************************************************/
1348 * As best as I can figure, this function is used by EnumWindows,
1349 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1351 * It's supposed to build a list of HWNDs to return to the caller.
1352 * We can figure out what kind of list by what parameters are
1360 NtUserBuildHwndList(
1373 return ERROR_INVALID_PARAMETER
;
1375 if (hwndParent
|| !dwThreadId
)
1378 PWND Parent
, Window
;
1382 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1384 return ERROR_INVALID_HANDLE
;
1389 Status
= IntValidateDesktopHandle(hDesktop
,
1393 if(!NT_SUCCESS(Status
))
1395 return ERROR_INVALID_HANDLE
;
1398 hwndParent
= Desktop
->DesktopWindow
;
1405 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1406 (Window
= Parent
->spwndChild
))
1408 BOOL bGoDown
= TRUE
;
1410 Status
= STATUS_SUCCESS
;
1415 if(dwCount
++ < *pBufSize
&& pWnd
)
1419 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1420 *pWnd
= Window
->head
.h
;
1423 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1425 Status
= _SEH2_GetExceptionCode();
1428 if(!NT_SUCCESS(Status
))
1430 SetLastNtError(Status
);
1434 if (Window
->spwndChild
&& bChildren
)
1436 Window
= Window
->spwndChild
;
1441 if (Window
->spwndNext
)
1443 Window
= Window
->spwndNext
;
1447 Window
= Window
->spwndParent
;
1448 if (Window
== Parent
)
1457 ObDereferenceObject(Desktop
);
1460 else // Build EnumThreadWindows list!
1463 PTHREADINFO W32Thread
;
1464 PLIST_ENTRY Current
;
1467 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1468 if (!NT_SUCCESS(Status
))
1470 DPRINT1("Thread Id is not valid!\n");
1471 return ERROR_INVALID_PARAMETER
;
1473 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1475 ObDereferenceObject(Thread
);
1476 DPRINT1("Thread is not initialized!\n");
1477 return ERROR_INVALID_PARAMETER
;
1480 Current
= W32Thread
->WindowListHead
.Flink
;
1481 while (Current
!= &(W32Thread
->WindowListHead
))
1483 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1486 if (dwCount
< *pBufSize
&& pWnd
)
1490 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1491 *pWnd
= Window
->head
.h
;
1494 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1496 Status
= _SEH2_GetExceptionCode();
1499 if (!NT_SUCCESS(Status
))
1501 DPRINT1("Failure to build window list!\n");
1502 SetLastNtError(Status
);
1507 Current
= Window
->ThreadListEntry
.Flink
;
1510 ObDereferenceObject(Thread
);
1513 *pBufSize
= dwCount
;
1514 return STATUS_SUCCESS
;
1517 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1519 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1520 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1522 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1524 USER_REFERENCE_ENTRY Ref
;
1525 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1526 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1528 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1529 (LPARAM
)pWindow
->head
.h
);
1530 UserDerefObjectCo(pWindow
->spwndParent
);
1536 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1538 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1540 /* default positioning for overlapped windows */
1541 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1544 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1546 pMonitor
= IntGetPrimaryMonitor();
1548 /* Check if we don't have a monitor attached yet */
1549 if(pMonitor
== NULL
)
1557 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1559 if (IS_DEFAULT(Cs
->x
))
1561 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1563 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1565 Cs
->x
= ProcessParams
->StartingX
;
1566 Cs
->y
= ProcessParams
->StartingY
;
1570 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1571 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1572 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1573 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1575 /* reset counter and position */
1578 pMonitor
->cWndStack
= 0;
1580 pMonitor
->cWndStack
++;
1584 if (IS_DEFAULT(Cs
->cx
))
1586 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1588 Cs
->cx
= ProcessParams
->CountX
;
1589 Cs
->cy
= ProcessParams
->CountY
;
1593 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1594 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1597 /* neither x nor cx are default. Check the y values .
1598 * In the trace we see Outlook and Outlook Express using
1599 * cy set to CW_USEDEFAULT when opening the address book.
1601 else if (IS_DEFAULT(Cs
->cy
))
1603 DPRINT("Strange use of CW_USEDEFAULT in nHeight\n");
1604 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1609 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1610 if(IS_DEFAULT(Cs
->x
))
1615 if(IS_DEFAULT(Cs
->cx
))
1625 /* Allocates and initializes a window*/
1626 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1627 PLARGE_STRING WindowName
,
1634 PTHREADINFO pti
= NULL
;
1635 PMENU_OBJECT SystemMenu
;
1637 BOOL bUnicodeWindow
;
1639 pti
= PsGetCurrentThreadWin32Thread();
1641 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1645 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1646 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1647 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1648 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1652 Note from MSDN http://msdn.microsoft.com/en-us/library/aa913269.aspx :
1654 Dialog boxes and message boxes do not inherit layout, so you must
1655 set the layout explicitly.
1657 if ( Class
&& Class
->fnid
!= FNID_DIALOG
)
1659 PPROCESSINFO ppi
= PsGetCurrentProcessWin32Process();
1660 if (ppi
->dwLayout
& LAYOUT_RTL
)
1662 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1668 /* Automatically add WS_EX_WINDOWEDGE */
1669 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1670 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1671 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1672 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1674 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1676 /* Is it a unicode window? */
1677 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1678 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1680 /* Allocate the new window */
1681 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1685 sizeof(WND
) + Class
->cbwndExtra
);
1692 DPRINT("Created object with handle %X\n", hWnd
);
1694 if (NULL
== pti
->rpdesk
->DesktopWindow
)
1695 { /*HACK! Helper for win32csr/desktopbg.c */
1696 /* If there is no desktop window yet, we must be creating it */
1697 pti
->rpdesk
->DesktopWindow
= hWnd
;
1698 pti
->rpdesk
->pDeskInfo
->spwnd
= pWnd
;
1702 * Fill out the structure describing it.
1704 /* Remember, pWnd->head is setup in object.c ...*/
1705 pWnd
->spwndParent
= ParentWindow
;
1706 pWnd
->spwndOwner
= OwnerWindow
;
1708 pWnd
->hWndLastActive
= hWnd
;
1709 pWnd
->state2
|= WNDS2_WIN40COMPAT
;
1711 pWnd
->hModule
= Cs
->hInstance
;
1712 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1713 pWnd
->ExStyle
= Cs
->dwExStyle
;
1714 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1716 IntReferenceMessageQueue(pWnd
->head
.pti
->MessageQueue
);
1717 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1719 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1720 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1723 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1724 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1726 /* BugBoy Comments: Comment below say that System classes are always created
1727 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1728 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1730 No where can I see in code or through testing does the window change back
1731 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1732 see what problems this would cause.*/
1734 // Set WndProc from Class.
1735 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1737 // GetWindowProc, test for non server side default classes and set WndProc.
1738 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1742 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1743 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1747 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1748 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1752 // If not an Unicode caller, set Ansi creator bit.
1753 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1755 // Clone Class Ansi/Unicode proc type.
1756 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1758 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1759 pWnd
->Unicode
= FALSE
;
1763 It seems there can be both an Ansi creator and Unicode Class Window
1764 WndProc, unless the following overriding conditions occur:
1766 if ( !bUnicodeWindow
&&
1767 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1768 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1769 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1770 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1771 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1772 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1773 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1774 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1775 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1776 { // Override Class and set the window Ansi WndProc.
1777 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1778 pWnd
->Unicode
= FALSE
;
1781 { // Set the window Unicode WndProc.
1782 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1783 pWnd
->Unicode
= TRUE
;
1787 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1788 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1789 Dont understand why it does this. */
1790 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1792 PCALLPROCDATA CallProc
;
1793 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1797 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1798 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
1802 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1806 InitializeListHead(&pWnd
->PropListHead
);
1808 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1810 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1811 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1812 if (pWnd
->strName
.Buffer
== NULL
)
1817 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1818 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1819 pWnd
->strName
.Length
= WindowName
->Length
;
1820 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1823 /* Correct the window style. */
1824 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1826 pWnd
->style
|= WS_CLIPSIBLINGS
;
1827 if (!(pWnd
->style
& WS_POPUP
))
1829 pWnd
->style
|= WS_CAPTION
;
1830 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1834 if ((pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
) ||
1835 (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
1836 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1838 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1840 /* create system menu */
1841 if((Cs
->style
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1843 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1846 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1847 IntReleaseMenuObject(SystemMenu
);
1851 /* Set the window menu */
1852 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1855 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1856 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1858 UNICODE_STRING MenuName
;
1861 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1863 MenuName
.Length
= 0;
1864 MenuName
.MaximumLength
= 0;
1865 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1869 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1871 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1872 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1876 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1878 /* Insert the window into the thread's window list. */
1879 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1881 /* Handle "CS_CLASSDC", it is tested first. */
1882 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1883 { /* One DCE per class to have CLASS. */
1884 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1886 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1887 { /* Allocate a DCE for this window. */
1888 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1894 DPRINT1("IntCreateWindow Allocation Error.\n");
1896 UserDereferenceObject(pWnd
);
1898 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1906 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1907 PUNICODE_STRING ClassName
,
1908 PLARGE_STRING WindowName
)
1910 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1911 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1912 PWINSTATION_OBJECT WinSta
;
1916 CBT_CREATEWNDW
* pCbtCreate
;
1918 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1920 DWORD dwShowMode
= SW_SHOW
;
1921 CREATESTRUCTW
*pCsw
= NULL
;
1922 PVOID pszClass
= NULL
, pszName
= NULL
;
1925 /* Get the current window station and reference it */
1926 pti
= GetW32ThreadInfo();
1927 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1929 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1930 return NULL
; //There is nothing to cleanup
1932 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1933 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1938 /* Get the class and reference it*/
1939 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
);
1942 DPRINT1("Failed to find class %wZ\n", ClassName
);
1946 /* Now find the parent and the owner window */
1947 hWndParent
= IntGetDesktopWindow();
1950 if (Cs
->hwndParent
== HWND_MESSAGE
)
1952 Cs
->hwndParent
= hWndParent
= IntGetMessageWindow();
1954 else if (Cs
->hwndParent
)
1956 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1957 hWndOwner
= Cs
->hwndParent
;
1959 hWndParent
= Cs
->hwndParent
;
1961 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1963 DPRINT1("Cannot create a child window without a parrent!\n");
1964 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1965 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1968 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1969 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1971 /* FIXME: is this correct?*/
1973 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
1975 /* Fix the position and the size of the window */
1978 UserRefObjectCo(ParentWindow
, &ParentRef
);
1979 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
1982 /* Allocate and initialize the new window */
1983 Window
= IntCreateWindow(Cs
,
1990 DPRINT1("IntCreateWindow failed!\n");
1994 hWnd
= UserHMGetHandle(Window
);
1995 hwndInsertAfter
= HWND_TOP
;
1997 UserRefObjectCo(Window
, &Ref
);
1998 UserDereferenceObject(Window
);
1999 ObDereferenceObject(WinSta
);
2001 //// Check for a hook to eliminate overhead. ////
2002 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2004 // Allocate the calling structures Justin Case this goes Global.
2005 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2006 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2007 if (!pCsw
|| !pCbtCreate
)
2009 DPRINT1("UserHeapAlloc() failed!\n");
2013 /* Fill the new CREATESTRUCTW */
2014 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2015 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2017 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2018 if (!IS_ATOM(ClassName
->Buffer
))
2020 if (Window
->state
& WNDS_ANSICREATOR
)
2022 ANSI_STRING AnsiString
;
2023 AnsiString
.MaximumLength
= RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2024 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2027 DPRINT1("UserHeapAlloc() failed!\n");
2030 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2031 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2032 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2036 UNICODE_STRING UnicodeString
;
2037 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2038 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2041 DPRINT1("UserHeapAlloc() failed!\n");
2044 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2045 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2046 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2048 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2050 if (WindowName
->Length
)
2052 UNICODE_STRING Name
;
2053 Name
.Buffer
= WindowName
->Buffer
;
2054 Name
.Length
= WindowName
->Length
;
2055 Name
.MaximumLength
= WindowName
->MaximumLength
;
2057 if (Window
->state
& WNDS_ANSICREATOR
)
2059 ANSI_STRING AnsiString
;
2060 AnsiString
.MaximumLength
= RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2061 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2064 DPRINT1("UserHeapAlloc() failed!\n");
2067 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2068 AnsiString
.Buffer
= (PCHAR
)pszName
;
2069 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2073 UNICODE_STRING UnicodeString
;
2074 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2075 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2078 DPRINT1("UserHeapAlloc() failed!\n");
2081 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2082 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2083 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2085 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2088 pCbtCreate
->lpcs
= pCsw
;
2089 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2091 //// Call the WH_CBT hook ////
2092 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2095 DPRINT1("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2098 // Write back changes.
2103 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2106 /* NCCREATE and WM_NCCALCSIZE need the original values */
2107 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2108 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2110 /* Send the WM_GETMINMAXINFO message*/
2114 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2116 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2118 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2119 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2120 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2121 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2122 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2125 Window
->rcWindow
.left
= Cs
->x
;
2126 Window
->rcWindow
.top
= Cs
->y
;
2127 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2128 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2129 if (0 != (Window
->style
& WS_CHILD
) && ParentWindow
)
2131 RECTL_vOffsetRect(&Window
->rcWindow
,
2132 ParentWindow
->rcClient
.left
,
2133 ParentWindow
->rcClient
.top
);
2135 Window
->rcClient
= Window
->rcWindow
;
2137 /* Link the window*/
2138 if (NULL
!= ParentWindow
)
2140 /* link the window into the siblings list */
2141 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2142 IntLinkHwnd(Window
, HWND_BOTTOM
);
2144 IntLinkHwnd(Window
, hwndInsertAfter
);
2147 /* Send the NCCREATE message */
2148 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2151 DPRINT1("co_UserCreateWindowEx(): NCCREATE message failed\n");
2155 /* Send the WM_NCCALCSIZE message */
2156 MaxPos
.x
= Window
->rcWindow
.left
;
2157 MaxPos
.y
= Window
->rcWindow
.top
;
2159 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2161 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2162 MaxPos
.y
- Window
->rcWindow
.top
);
2165 /* Send the WM_CREATE message. */
2166 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2167 if (Result
== (LRESULT
)-1)
2169 DPRINT1("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2173 /* Send the EVENT_OBJECT_CREATE event*/
2174 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2176 /* By setting the flag below it can be examined to determine if the window
2177 was created successfully and a valid pwnd was passed back to caller since
2178 from here the function has to succeed. */
2179 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2181 /* Send the WM_SIZE and WM_MOVE messages. */
2182 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2184 co_WinPosSendSizeMove(Window
);
2187 /* Show or maybe minimize or maximize the window. */
2188 if (Window
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2193 SwFlag
= (Window
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2195 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2197 SwFlag
= ((Window
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2198 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2199 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2201 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2202 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2205 /* Send the WM_PARENTNOTIFY message */
2206 IntSendParentNotify(Window
, WM_CREATE
);
2208 /* Notify the shell that a new window was created */
2209 if ((!hWndParent
) && (!hWndOwner
))
2211 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2214 /* Initialize and show the window's scrollbars */
2215 if (Window
->style
& WS_VSCROLL
)
2217 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2219 if (Window
->style
& WS_HSCROLL
)
2221 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2224 /* Show the new window */
2225 if (Cs
->style
& WS_VISIBLE
)
2227 if (Window
->style
& WS_MAXIMIZE
)
2228 dwShowMode
= SW_SHOW
;
2229 else if (Window
->style
& WS_MINIMIZE
)
2230 dwShowMode
= SW_SHOWMINIMIZED
;
2232 co_WinPosShowWindow(Window
, dwShowMode
);
2234 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2236 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2237 /* ShowWindow won't activate child windows */
2238 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2242 DPRINT("co_UserCreateWindowEx(): Created window %X\n", hWnd
);
2248 DPRINT("co_UserCreateWindowEx(): Error Created window!\n");
2249 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2251 co_UserDestroyWindow(Window
);
2253 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2256 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2257 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2258 if (pszName
) UserHeapFree(pszName
);
2259 if (pszClass
) UserHeapFree(pszClass
);
2263 UserDerefObjectCo(Window
);
2265 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2272 ProbeAndCaptureLargeString(
2273 OUT PLARGE_STRING plstrSafe
,
2274 IN PLARGE_STRING plstrUnsafe
)
2276 LARGE_STRING lstrTemp
;
2277 PVOID pvBuffer
= NULL
;
2281 /* Probe and copy the string */
2282 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2283 lstrTemp
= *plstrUnsafe
;
2285 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2288 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2292 if (lstrTemp
.Length
!= 0)
2294 /* Allocate a buffer from paged pool */
2295 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2298 return STATUS_NO_MEMORY
;
2303 /* Probe and copy the buffer */
2304 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2305 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2307 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2309 /* Cleanup and fail */
2310 ExFreePool(pvBuffer
);
2311 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2316 /* Set the output string */
2317 plstrSafe
->Buffer
= pvBuffer
;
2318 plstrSafe
->Length
= lstrTemp
.Length
;
2319 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2321 return STATUS_SUCCESS
;
2325 * \todo Allow passing plstrClassName as ANSI.
2329 NtUserCreateWindowEx(
2331 PLARGE_STRING plstrClassName
,
2332 PLARGE_STRING plstrClsVersion
,
2333 PLARGE_STRING plstrWindowName
,
2341 HINSTANCE hInstance
,
2347 LARGE_STRING lstrWindowName
;
2348 LARGE_STRING lstrClassName
;
2349 UNICODE_STRING ustrClassName
;
2354 lstrWindowName
.Buffer
= NULL
;
2355 lstrClassName
.Buffer
= NULL
;
2357 /* Check if we got a Window name */
2358 if (plstrWindowName
)
2360 /* Copy the string to kernel mode */
2361 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2362 if (!NT_SUCCESS(Status
))
2364 DPRINT1("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2365 SetLastNtError(Status
);
2368 plstrWindowName
= &lstrWindowName
;
2371 /* Check if the class is an atom */
2372 if (IS_ATOM(plstrClassName
))
2374 /* It is, pass the atom in the UNICODE_STRING */
2375 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2376 ustrClassName
.Length
= 0;
2377 ustrClassName
.MaximumLength
= 0;
2381 /* It's not, capture the class name */
2382 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2383 if (!NT_SUCCESS(Status
))
2385 DPRINT1("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2386 /* Set last error, cleanup and return */
2387 SetLastNtError(Status
);
2391 /* We pass it on as a UNICODE_STRING */
2392 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2393 ustrClassName
.Length
= lstrClassName
.Length
;
2394 ustrClassName
.MaximumLength
= lstrClassName
.MaximumLength
;
2397 /* Fill the CREATESTRUCTW */
2398 /* we will keep here the original parameters */
2400 Cs
.lpCreateParams
= lpParam
;
2401 Cs
.hInstance
= hInstance
;
2403 Cs
.hwndParent
= hWndParent
;
2408 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2409 if (IS_ATOM(plstrClassName
))
2410 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2412 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2413 Cs
.dwExStyle
= dwExStyle
;
2415 UserEnterExclusive();
2417 /* Call the internal function */
2418 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
);
2422 DPRINT1("co_UserCreateWindowEx failed!\n");
2424 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2429 if (lstrWindowName
.Buffer
)
2431 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2433 if (lstrClassName
.Buffer
)
2435 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2442 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2448 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2450 hWnd
= Window
->head
.h
;
2452 DPRINT("co_UserDestroyWindow \n");
2454 /* Check for owner thread */
2455 if ( (Window
->head
.pti
->pEThread
!= PsGetCurrentThread()) ||
2456 Window
->head
.pti
!= PsGetCurrentThreadWin32Thread() )
2458 EngSetLastError(ERROR_ACCESS_DENIED
);
2462 /* If window was created successfully and it is hooked */
2463 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2465 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2467 DPRINT1("Destroy Window WH_CBT Call Hook return!\n");
2472 /* Inform the parent */
2473 if (Window
->style
& WS_CHILD
)
2475 IntSendParentNotify(Window
, WM_DESTROY
);
2478 /* Look whether the focus is within the tree of windows we will
2481 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2483 if (UserGetActiveWindow() == Window
->head
.h
)
2485 co_WinPosActivateOtherWindow(Window
);
2489 if (Window
->head
.pti
->MessageQueue
->ActiveWindow
== Window
->head
.h
)
2490 Window
->head
.pti
->MessageQueue
->ActiveWindow
= NULL
;
2491 if (Window
->head
.pti
->MessageQueue
->FocusWindow
== Window
->head
.h
)
2492 Window
->head
.pti
->MessageQueue
->FocusWindow
= NULL
;
2493 if (Window
->head
.pti
->MessageQueue
->CaptureWindow
== Window
->head
.h
)
2494 Window
->head
.pti
->MessageQueue
->CaptureWindow
= NULL
;
2497 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2500 ti
= PsGetCurrentThreadWin32Thread();
2502 if ((ti
!= NULL
) & (ti
->pDeskInfo
!= NULL
))
2504 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2506 DPRINT1("Destroying the ShellWindow!\n");
2507 ti
->pDeskInfo
->hShellWindow
= NULL
;
2511 IntEngWindowChanged(Window
, WOC_DELETE
);
2513 if (!IntIsWindow(Window
->head
.h
))
2518 /* Recursively destroy owned windows */
2520 if (! (Window
->style
& WS_CHILD
))
2524 BOOL GotOne
= FALSE
;
2527 PWND Child
, Desktop
;
2529 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2530 UserGetWindowObject(IntGetDesktopWindow());
2531 Children
= IntWinListChildren(Desktop
);
2535 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2537 Child
= UserGetWindowObject(*ChildHandle
);
2540 if (Child
->spwndOwner
!= Window
)
2545 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2547 USER_REFERENCE_ENTRY ChildRef
;
2548 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2549 co_UserDestroyWindow(Child
);
2550 UserDerefObjectCo(Child
);//temp hack?
2556 if (Child
->spwndOwner
!= NULL
)
2558 Child
->spwndOwner
= NULL
;
2562 ExFreePool(Children
);
2571 /* Generate mouse move message for the next window */
2572 msg
.message
= WM_MOUSEMOVE
;
2573 msg
.wParam
= IntGetSysCursorInfo()->ButtonsDown
;
2574 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2575 msg
.pt
= gpsi
->ptCursor
;
2576 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2578 if (!IntIsWindow(Window
->head
.h
))
2583 /* Destroy the window storage */
2584 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2594 NtUserDestroyWindow(HWND Wnd
)
2597 DECLARE_RETURN(BOOLEAN
);
2599 USER_REFERENCE_ENTRY Ref
;
2601 DPRINT("Enter NtUserDestroyWindow\n");
2602 UserEnterExclusive();
2604 if (!(Window
= UserGetWindowObject(Wnd
)))
2609 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2610 ret
= co_UserDestroyWindow(Window
);
2611 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2616 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2622 static HWND FASTCALL
2623 IntFindWindow(PWND Parent
,
2626 PUNICODE_STRING WindowName
)
2628 BOOL CheckWindowName
;
2631 UNICODE_STRING CurrentWindowName
;
2635 CheckWindowName
= WindowName
->Length
!= 0;
2637 if((List
= IntWinListChildren(Parent
)))
2642 /* skip handles before and including ChildAfter */
2643 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2647 /* search children */
2651 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2656 /* Do not send WM_GETTEXT messages in the kernel mode version!
2657 The user mode version however calls GetWindowText() which will
2658 send WM_GETTEXT messages to windows belonging to its processes */
2659 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2661 // HACK: use UNICODE_STRING instead of LARGE_STRING
2662 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2663 CurrentWindowName
.Length
= Child
->strName
.Length
;
2664 CurrentWindowName
.MaximumLength
= Child
->strName
.MaximumLength
;
2665 if(!CheckWindowName
||
2666 (Child
->strName
.Length
< 0xFFFF &&
2667 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2669 Ret
= Child
->head
.h
;
2682 * Searches a window's children for a window with the specified
2685 * hwndParent = The window whose childs are to be searched.
2687 * HWND_MESSAGE = message-only windows
2689 * hwndChildAfter = Search starts after this child window.
2690 * NULL = start from beginning
2692 * ucClassName = Class name to search for
2693 * Reguired parameter.
2695 * ucWindowName = Window name
2696 * ->Buffer == NULL = don't care
2699 * The HWND of the window if it was found, otherwise NULL
2705 NtUserFindWindowEx(HWND hwndParent
,
2706 HWND hwndChildAfter
,
2707 PUNICODE_STRING ucClassName
,
2708 PUNICODE_STRING ucWindowName
,
2711 PWND Parent
, ChildAfter
;
2712 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2713 HWND Desktop
, Ret
= NULL
;
2714 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2715 DECLARE_RETURN(HWND
);
2717 DPRINT("Enter NtUserFindWindowEx\n");
2720 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2724 if (ucClassName
!= NULL
)
2726 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2727 if (ClassName
.Length
!= 0)
2729 ProbeForRead(ClassName
.Buffer
,
2733 else if (!IS_ATOM(ClassName
.Buffer
))
2735 EngSetLastError(ERROR_INVALID_PARAMETER
);
2739 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2746 if (ucWindowName
!= NULL
)
2748 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2749 if (WindowName
.Length
!= 0)
2751 ProbeForRead(WindowName
.Buffer
,
2757 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2759 SetLastNtError(_SEH2_GetExceptionCode());
2760 _SEH2_YIELD(RETURN(NULL
));
2764 if (ucClassName
!= NULL
)
2766 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2767 !IS_ATOM(ClassName
.Buffer
))
2769 EngSetLastError(ERROR_INVALID_PARAMETER
);
2772 else if (ClassAtom
== (RTL_ATOM
)0)
2774 /* LastError code was set by IntGetAtomFromStringOrAtom */
2780 Desktop
= IntGetCurrentThreadDesktopWindow();
2782 if(hwndParent
== NULL
)
2783 hwndParent
= Desktop
;
2784 else if(hwndParent
== HWND_MESSAGE
)
2786 hwndParent
= IntGetMessageWindow();
2789 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2795 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2802 if(Parent
->head
.h
== Desktop
)
2805 PWND TopLevelWindow
;
2806 BOOLEAN CheckWindowName
;
2807 BOOLEAN WindowMatches
;
2808 BOOLEAN ClassMatches
;
2810 /* windows searches through all top-level windows if the parent is the desktop
2813 if((List
= IntWinListChildren(Parent
)))
2819 /* skip handles before and including ChildAfter */
2820 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2824 CheckWindowName
= WindowName
.Length
!= 0;
2826 /* search children */
2829 UNICODE_STRING ustr
;
2831 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2836 /* Do not send WM_GETTEXT messages in the kernel mode version!
2837 The user mode version however calls GetWindowText() which will
2838 send WM_GETTEXT messages to windows belonging to its processes */
2839 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2840 ustr
.Length
= TopLevelWindow
->strName
.Length
;
2841 ustr
.MaximumLength
= TopLevelWindow
->strName
.MaximumLength
;
2842 WindowMatches
= !CheckWindowName
||
2843 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2844 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2845 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2846 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2848 if (WindowMatches
&& ClassMatches
)
2850 Ret
= TopLevelWindow
->head
.h
;
2854 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2856 /* window returns the handle of the top-level window, in case it found
2858 Ret
= TopLevelWindow
->head
.h
;
2867 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2871 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2873 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2874 search the message-only windows. Should this also be done if
2875 Parent is the desktop window??? */
2878 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2880 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2885 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2887 SetLastNtError(_SEH2_GetExceptionCode());
2895 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2904 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
2906 PWND WndAncestor
, Parent
;
2908 if (Wnd
->head
.h
== IntGetDesktopWindow())
2917 WndAncestor
= Wnd
->spwndParent
;
2928 if(!(Parent
= WndAncestor
->spwndParent
))
2932 if(IntIsDesktopWindow(Parent
))
2937 WndAncestor
= Parent
;
2950 Parent
= IntGetParent(WndAncestor
);
2957 WndAncestor
= Parent
;
2975 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2977 PWND Window
, Ancestor
;
2978 DECLARE_RETURN(HWND
);
2980 DPRINT("Enter NtUserGetAncestor\n");
2981 UserEnterExclusive();
2983 if (!(Window
= UserGetWindowObject(hWnd
)))
2988 Ancestor
= UserGetAncestor(Window
, Type
);
2989 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
2991 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
2994 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3002 NtUserGetComboBoxInfo(
3007 DECLARE_RETURN(BOOL
);
3009 DPRINT("Enter NtUserGetComboBoxInfo\n");
3012 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3021 sizeof(COMBOBOXINFO
),
3025 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3027 SetLastNtError(_SEH2_GetExceptionCode());
3028 _SEH2_YIELD(RETURN(FALSE
));
3032 // Pass the user pointer, it was already probed.
3033 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3036 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3046 NtUserGetInternalWindowPos( HWND hWnd
,
3053 WINDOWPLACEMENT wndpl
;
3057 if (!(Window
= UserGetWindowObject(hWnd
)))
3067 ProbeForWrite(rectWnd
,
3073 ProbeForWrite(ptIcon
,
3079 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3081 SetLastNtError(_SEH2_GetExceptionCode());
3086 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3088 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3094 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3098 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3102 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3104 SetLastNtError(_SEH2_GetExceptionCode());
3109 if (!Hit
) Ret
= wndpl
.showCmd
;
3118 NtUserGetListBoxInfo(
3122 DECLARE_RETURN(DWORD
);
3124 DPRINT("Enter NtUserGetListBoxInfo\n");
3127 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3132 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3135 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3143 * The NtUserSetParent function changes the parent window of the specified
3147 * The new parent window and the child window must belong to the same
3148 * application. If the window identified by the hWndChild parameter is
3149 * visible, the system performs the appropriate redrawing and repainting.
3150 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3151 * or WS_POPUP window styles of the window whose parent is being changed.
3158 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3160 DECLARE_RETURN(HWND
);
3162 DPRINT("Enter NtUserSetParent\n");
3163 UserEnterExclusive();
3166 Check Parent first from user space, set it here.
3170 hWndNewParent
= IntGetDesktopWindow();
3172 else if (hWndNewParent
== HWND_MESSAGE
)
3174 hWndNewParent
= IntGetMessageWindow();
3177 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3180 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3186 * UserGetShellWindow
3188 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3193 HWND FASTCALL
UserGetShellWindow(VOID
)
3195 PWINSTATION_OBJECT WinStaObject
;
3198 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3203 if (!NT_SUCCESS(Status
))
3205 SetLastNtError(Status
);
3209 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3211 ObDereferenceObject(WinStaObject
);
3216 * NtUserSetShellWindowEx
3218 * This is undocumented function to set global shell window. The global
3219 * shell window has special handling of window position.
3225 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3227 PWINSTATION_OBJECT WinStaObject
;
3228 PWND WndShell
, WndListView
;
3229 DECLARE_RETURN(BOOL
);
3230 USER_REFERENCE_ENTRY Ref
;
3234 DPRINT("Enter NtUserSetShellWindowEx\n");
3235 UserEnterExclusive();
3237 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3242 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3247 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3252 if (!NT_SUCCESS(Status
))
3254 SetLastNtError(Status
);
3259 * Test if we are permitted to change the shell window.
3261 if (WinStaObject
->ShellWindow
)
3263 ObDereferenceObject(WinStaObject
);
3268 * Move shell window into background.
3270 if (hwndListView
&& hwndListView
!= hwndShell
)
3273 * Disabled for now to get Explorer working.
3274 * -- Filip, 01/nov/2003
3277 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3280 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3282 ObDereferenceObject(WinStaObject
);
3287 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3289 ObDereferenceObject(WinStaObject
);
3293 UserRefObjectCo(WndShell
, &Ref
);
3294 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3296 WinStaObject
->ShellWindow
= hwndShell
;
3297 WinStaObject
->ShellListView
= hwndListView
;
3299 ti
= GetW32ThreadInfo();
3302 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3303 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3306 UserDerefObjectCo(WndShell
);
3308 ObDereferenceObject(WinStaObject
);
3312 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3318 * NtUserGetSystemMenu
3320 * The NtUserGetSystemMenu function allows the application to access the
3321 * window menu (also known as the system menu or the control menu) for
3322 * copying and modifying.
3326 * Handle to the window that will own a copy of the window menu.
3328 * Specifies the action to be taken. If this parameter is FALSE,
3329 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3330 * currently in use. The copy is initially identical to the window menu
3331 * but it can be modified.
3332 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3333 * to the default state. The previous window menu, if any, is destroyed.
3336 * If the bRevert parameter is FALSE, the return value is a handle to a
3337 * copy of the window menu. If the bRevert parameter is TRUE, the return
3345 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3349 DECLARE_RETURN(HMENU
);
3351 DPRINT("Enter NtUserGetSystemMenu\n");
3354 if (!(Window
= UserGetWindowObject(hWnd
)))
3359 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3364 RETURN(Menu
->MenuInfo
.Self
);
3367 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3373 * NtUserSetSystemMenu
3380 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3382 BOOL Result
= FALSE
;
3385 DECLARE_RETURN(BOOL
);
3387 DPRINT("Enter NtUserSetSystemMenu\n");
3388 UserEnterExclusive();
3390 if (!(Window
= UserGetWindowObject(hWnd
)))
3398 * Assign new menu handle.
3400 if (!(Menu
= UserGetMenuObject(hMenu
)))
3405 Result
= IntSetSystemMenu(Window
, Menu
);
3411 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3417 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3419 PWND Window
, Parent
;
3420 PWINSTATION_OBJECT WindowStation
;
3424 if (hWnd
== IntGetDesktopWindow())
3426 EngSetLastError(STATUS_ACCESS_DENIED
);
3430 if (!(Window
= UserGetWindowObject(hWnd
)))
3435 if ((INT
)Index
>= 0)
3437 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3439 EngSetLastError(ERROR_INVALID_INDEX
);
3443 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3445 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3447 OldValue = (LONG)IntSetWindowProc( Wnd,
3450 if (!OldValue) return 0;
3453 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3460 OldValue
= (LONG
) Window
->ExStyle
;
3461 Style
.styleOld
= OldValue
;
3462 Style
.styleNew
= NewValue
;
3465 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3467 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3470 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3471 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3474 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3475 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3476 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3480 OldValue
= (LONG
) Window
->style
;
3481 Style
.styleOld
= OldValue
;
3482 Style
.styleNew
= NewValue
;
3483 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3484 Window
->style
= (DWORD
)Style
.styleNew
;
3485 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3490 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3491 Window
->fnid
& FNID_FREED
)
3493 EngSetLastError(ERROR_ACCESS_DENIED
);
3496 OldValue
= (LONG
)IntSetWindowProc(Window
,
3503 OldValue
= (LONG
) Window
->hModule
;
3504 Window
->hModule
= (HINSTANCE
) NewValue
;
3507 case GWL_HWNDPARENT
:
3508 Parent
= Window
->spwndParent
;
3509 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3510 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3512 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3516 OldValue
= (LONG
) Window
->IDMenu
;
3517 Window
->IDMenu
= (UINT
) NewValue
;
3521 OldValue
= Window
->dwUserData
;
3522 Window
->dwUserData
= NewValue
;
3526 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3527 EngSetLastError(ERROR_INVALID_INDEX
);
3537 * NtUserSetWindowLong
3539 * The NtUserSetWindowLong function changes an attribute of the specified
3540 * window. The function also sets the 32-bit (long) value at the specified
3541 * offset into the extra window memory.
3548 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3550 DECLARE_RETURN(LONG
);
3552 DPRINT("Enter NtUserSetWindowLong\n");
3553 UserEnterExclusive();
3555 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3558 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3564 * NtUserSetWindowWord
3566 * Legacy function similar to NtUserSetWindowLong.
3573 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3577 DECLARE_RETURN(WORD
);
3579 DPRINT("Enter NtUserSetWindowWord\n");
3580 UserEnterExclusive();
3582 if (!(Window
= UserGetWindowObject(hWnd
)))
3591 case GWL_HWNDPARENT
:
3592 RETURN( co_UserSetWindowLong(Window
->head
.h
, Index
, (UINT
)NewValue
, TRUE
));
3596 EngSetLastError(ERROR_INVALID_INDEX
);
3601 if (Index
> Window
->cbwndExtra
- sizeof(WORD
))
3603 EngSetLastError(ERROR_INVALID_PARAMETER
);
3607 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3608 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3613 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3622 NtUserGetWindowPlacement(HWND hWnd
,
3623 WINDOWPLACEMENT
*lpwndpl
)
3627 WINDOWPLACEMENT Safepl
;
3629 DECLARE_RETURN(BOOL
);
3631 DPRINT("Enter NtUserGetWindowPlacement\n");
3634 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3639 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3640 if(!NT_SUCCESS(Status
))
3642 SetLastNtError(Status
);
3645 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3651 if (0 == (Wnd
->style
& WS_VISIBLE
))
3653 Safepl
.showCmd
= SW_HIDE
;
3655 else if ((0 != (Wnd
->state2
& WNDS2_MAXIMIZEBUTTONDOWN
) ||
3656 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
3657 0 == (Wnd
->style
& WS_MINIMIZE
))
3659 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
3661 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
3663 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
3665 else if (0 != (Wnd
->style
& WS_VISIBLE
))
3667 Safepl
.showCmd
= SW_SHOWNORMAL
;
3670 Size
.x
= Wnd
->rcWindow
.left
;
3671 Size
.y
= Wnd
->rcWindow
.top
;
3672 WinPosInitInternalPos(Wnd
, &Size
,
3675 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
3676 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
3677 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
3679 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3680 if(!NT_SUCCESS(Status
))
3682 SetLastNtError(Status
);
3689 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
3695 QueryWindow based on KJK::Hyperion and James Tabor.
3697 0 = QWUniqueProcessId
3698 1 = QWUniqueThreadId
3701 4 = QWIsHung Implements IsHungAppWindow found
3704 9 = QWKillWindow When I called this with hWnd ==
3705 DesktopWindow, it shutdown the system
3712 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3716 DECLARE_RETURN(UINT
);
3718 DPRINT("Enter NtUserQueryWindow\n");
3721 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3728 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3729 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3732 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3733 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3736 case QUERY_WINDOW_ACTIVE
:
3737 Result
= (DWORD
)UserGetActiveWindow();
3740 case QUERY_WINDOW_FOCUS
:
3741 Result
= (DWORD
)IntGetFocusWindow();
3744 case QUERY_WINDOW_ISHUNG
:
3745 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
->MessageQueue
);
3748 case QUERY_WINDOW_REAL_ID
:
3749 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3752 Result
= (DWORD
)NULL
;
3759 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3769 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3771 UNICODE_STRING SafeMessageName
;
3774 DECLARE_RETURN(UINT
);
3776 DPRINT("Enter NtUserRegisterWindowMessage\n");
3777 UserEnterExclusive();
3779 if(MessageNameUnsafe
== NULL
)
3781 EngSetLastError(ERROR_INVALID_PARAMETER
);
3785 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3786 if(!NT_SUCCESS(Status
))
3788 SetLastNtError(Status
);
3792 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3793 if (SafeMessageName
.Buffer
)
3794 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3798 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3815 DECLARE_RETURN(BOOL
);
3817 DPRINT("Enter NtUserSetMenu\n");
3818 UserEnterExclusive();
3820 if (!(Window
= UserGetWindowObject(hWnd
)))
3825 if (! IntSetMenu(Window
, Menu
, &Changed
))
3830 if (Changed
&& Repaint
)
3832 USER_REFERENCE_ENTRY Ref
;
3834 UserRefObjectCo(Window
, &Ref
);
3835 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3836 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3838 UserDerefObjectCo(Window
);
3844 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3854 NtUserSetWindowFNID(HWND hWnd
,
3858 DECLARE_RETURN(BOOL
);
3860 DPRINT("Enter NtUserSetWindowFNID\n");
3861 UserEnterExclusive();
3863 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3868 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3870 EngSetLastError(ERROR_ACCESS_DENIED
);
3874 // From user land we only set these.
3875 if (fnID
!= FNID_DESTROY
)
3876 { // Hacked so we can mark desktop~!
3877 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
3880 EngSetLastError(ERROR_INVALID_PARAMETER
);
3889 DPRINT("Leave NtUserSetWindowFNID\n");
3898 NtUserWindowFromPoint(LONG X
, LONG Y
)
3902 PWND DesktopWindow
= NULL
, Window
= NULL
;
3904 DECLARE_RETURN(HWND
);
3905 USER_REFERENCE_ENTRY Ref
;
3907 DPRINT("Enter NtUserWindowFromPoint\n");
3908 UserEnterExclusive();
3910 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
3917 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
3918 //its possible this referencing is useless, thou it shouldnt hurt...
3919 UserRefObjectCo(DesktopWindow
, &Ref
);
3921 pti
= PsGetCurrentThreadWin32Thread();
3922 Window
= co_WinPosWindowFromPoint(DesktopWindow
, &pt
, &hittest
);
3926 Ret
= Window
->head
.h
;
3935 if (Window
) UserDereferenceObject(Window
);
3936 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
3938 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
3948 * Undocumented function that is called from DefWindowProc to set
3955 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
3958 LARGE_STRING SafeText
;
3959 UNICODE_STRING UnicodeString
;
3962 DPRINT("Enter NtUserDefSetText\n");
3964 if (WindowText
!= NULL
)
3968 SafeText
= ProbeForReadLargeString(WindowText
);
3970 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3973 SetLastNtError(_SEH2_GetExceptionCode());
3983 UserEnterExclusive();
3985 if(!(Wnd
= UserGetWindowObject(hWnd
)))
3991 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
3992 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
3993 // Now we know what the bAnsi is for.
3994 RtlInitUnicodeString(&UnicodeString
, NULL
);
3995 if (SafeText
.Buffer
)
4000 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4002 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4003 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4005 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4008 SetLastNtError(_SEH2_GetExceptionCode());
4011 if (!Ret
) goto Exit
;
4014 if (UnicodeString
.Length
!= 0)
4016 if (Wnd
->strName
.MaximumLength
> 0 &&
4017 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4019 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4021 Wnd
->strName
.Length
= UnicodeString
.Length
;
4022 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4023 RtlCopyMemory(Wnd
->strName
.Buffer
,
4024 UnicodeString
.Buffer
,
4025 UnicodeString
.Length
);
4030 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4031 buf
= Wnd
->strName
.Buffer
;
4032 Wnd
->strName
.Buffer
= NULL
;
4035 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4038 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4039 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4040 if (Wnd
->strName
.Buffer
!= NULL
)
4042 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4043 RtlCopyMemory(Wnd
->strName
.Buffer
,
4044 UnicodeString
.Buffer
,
4045 UnicodeString
.Length
);
4046 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4047 Wnd
->strName
.Length
= UnicodeString
.Length
;
4051 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4059 Wnd
->strName
.Length
= 0;
4060 if (Wnd
->strName
.Buffer
!= NULL
)
4061 Wnd
->strName
.Buffer
[0] = L
'\0';
4064 // HAX! FIXME! Windows does not do this in here!
4065 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4066 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4067 /* Send shell notifications */
4068 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4070 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4075 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4076 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4082 * NtUserInternalGetWindowText
4089 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4094 DECLARE_RETURN(INT
);
4096 DPRINT("Enter NtUserInternalGetWindowText\n");
4099 if(lpString
&& (nMaxCount
<= 1))
4101 EngSetLastError(ERROR_INVALID_PARAMETER
);
4105 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4110 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4113 const WCHAR Terminator
= L
'\0';
4115 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4117 Copy
= min(nMaxCount
- 1, Result
);
4120 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4121 if(!NT_SUCCESS(Status
))
4123 SetLastNtError(Status
);
4129 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4130 if(!NT_SUCCESS(Status
))
4132 SetLastNtError(Status
);
4142 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4150 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4156 // ASSERT(OwnerWnd);
4158 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
4163 while (win_array
[count
])
4165 while (--count
>= 0)
4167 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4169 if (pWnd
->spwndOwner
!= OwnerWnd
)
4174 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4176 /* In Windows, ShowOwnedPopups(TRUE) generates
4177 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4178 * regardless of the state of the owner
4180 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4186 if (pWnd
->style
& WS_VISIBLE
)
4188 /* In Windows, ShowOwnedPopups(FALSE) generates
4189 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4190 * regardless of the state of the owner
4192 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4198 ExFreePool( win_array
);
4203 * NtUserValidateHandleSecure
4211 NtUserValidateHandleSecure(
4219 PUSER_HANDLE_ENTRY entry
;
4220 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
4222 EngSetLastError(ERROR_INVALID_HANDLE
);
4225 uType
= entry
->type
;
4232 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
4238 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
4243 PACCELERATOR_TABLE Accel
;
4244 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
4249 PCURICON_OBJECT Cursor
;
4250 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
4256 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
4262 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
4268 return UserGetCallProcInfo( handle
, &Proc
);
4271 EngSetLastError(ERROR_INVALID_HANDLE
);
4275 { /* Is handle entry restricted? */