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 ******************************************************************/
19 /* dialog resources appear to pass this in 16 bits, handle them properly */
20 #define CW_USEDEFAULT16 (0x8000)
22 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
24 /* PRIVATE FUNCTIONS **********************************************************/
29 * Initialize windowing implementation.
35 return STATUS_SUCCESS
;
41 * Cleanup windowing implementation.
45 CleanupWindowImpl(VOID
)
47 return STATUS_SUCCESS
;
50 /* HELPER FUNCTIONS ***********************************************************/
52 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
54 WORD Action
= LOWORD(wParam
);
55 WORD Flags
= HIWORD(wParam
);
57 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
59 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
66 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
70 if (Flags
& UISF_HIDEFOCUS
)
71 Wnd
->HideFocus
= TRUE
;
72 if (Flags
& UISF_HIDEACCEL
)
73 Wnd
->HideAccel
= TRUE
;
77 if (Flags
& UISF_HIDEFOCUS
)
78 Wnd
->HideFocus
= FALSE
;
79 if (Flags
& UISF_HIDEACCEL
)
80 Wnd
->HideAccel
= FALSE
;
87 PWINDOW_OBJECT FASTCALL
IntGetWindowObject(HWND hWnd
)
89 PWINDOW_OBJECT Window
;
91 if (!hWnd
) return NULL
;
93 Window
= UserGetWindowObject(hWnd
);
96 ASSERT(USER_BODY_TO_HEADER(Window
)->RefCount
>= 0);
98 USER_BODY_TO_HEADER(Window
)->RefCount
++;
104 PWINDOW_OBJECT FASTCALL
UserGetWindowObject(HWND hWnd
)
107 PWINDOW_OBJECT Window
;
109 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
111 ti
= GetW32ThreadInfo();
114 SetLastWin32Error(ERROR_ACCESS_DENIED
);
121 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
125 Window
= (PWINDOW_OBJECT
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
126 if (!Window
|| 0 != (Window
->Status
& WINDOWSTATUS_DESTROYED
))
128 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
132 ASSERT(USER_BODY_TO_HEADER(Window
)->RefCount
>= 0);
140 * The function determines whether the specified window handle identifies
141 * an existing window.
145 * Handle to the window to test.
148 * If the window handle identifies an existing window, the return value
149 * is TRUE. If the window handle does not identify an existing window,
150 * the return value is FALSE.
154 IntIsWindow(HWND hWnd
)
156 PWINDOW_OBJECT Window
;
158 if (!(Window
= UserGetWindowObject(hWnd
)))
167 Caller must NOT dereference retval!
168 But if caller want the returned value to persist spanning a co_ call,
169 it must reference the value (because the owner is not garanteed to
170 exist just because the owned window exist)!
172 PWINDOW_OBJECT FASTCALL
173 IntGetParent(PWINDOW_OBJECT Wnd
)
175 if (!Wnd
->Wnd
) return NULL
;
177 if (Wnd
->Wnd
->style
& WS_POPUP
)
179 return UserGetWindowObject(Wnd
->hOwner
);
181 else if (Wnd
->Wnd
->style
& WS_CHILD
)
191 Caller must NOT dereference retval!
192 But if caller want the returned value to persist spanning a co_ call,
193 it must reference the value (because the owner is not garanteed to
194 exist just because the owned window exist)!
196 PWINDOW_OBJECT FASTCALL
197 IntGetOwner(PWINDOW_OBJECT Wnd
)
199 return UserGetWindowObject(Wnd
->hOwner
);
207 * Compile a list of all child window handles from given window.
210 * This function is similar to Wine WIN_ListChildren. The caller
211 * must free the returned list with ExFreePool.
215 IntWinListChildren(PWINDOW_OBJECT Window
)
217 PWINDOW_OBJECT Child
;
219 UINT Index
, NumChildren
= 0;
221 if (!Window
) return NULL
;
223 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
226 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
229 DPRINT1("Failed to allocate memory for children array\n");
230 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
233 for (Child
= Window
->FirstChild
, Index
= 0;
235 Child
= Child
->NextSibling
, ++Index
)
236 List
[Index
] = Child
->hSelf
;
242 /***********************************************************************
245 static void IntSendDestroyMsg(HWND hWnd
)
248 PWINDOW_OBJECT Window
;
253 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
255 if (hWnd
== info
.hwndCaret
)
262 Window
= UserGetWindowObject(hWnd
);
265 // USER_REFERENCE_ENTRY Ref;
266 // UserRefObjectCo(Window, &Ref);
268 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
270 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
273 // UserDerefObjectCo(Window);
276 /* The window could already be destroyed here */
279 * Send the WM_DESTROY to the window.
282 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
285 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
286 * make sure that the window still exists when we come back.
295 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
298 /* start from the end (FIXME: is this needed?) */
299 for (i
= 0; pWndArray
[i
]; i
++)
304 if (IsWindow( pWndArray
[i
] ))
305 WIN_SendDestroyMsg( pWndArray
[i
] );
307 HeapFree(GetProcessHeap(), 0, pWndArray
);
311 DPRINT("destroyed itself while in WM_DESTROY!\n");
317 UserFreeWindowInfo(PTHREADINFO ti
, PWINDOW_OBJECT WindowObject
)
319 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
320 PWND Wnd
= WindowObject
->Wnd
;
324 if (ClientInfo
->CallbackWnd
.pvWnd
== DesktopHeapAddressToUser(WindowObject
->Wnd
))
326 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
327 ClientInfo
->CallbackWnd
.pvWnd
= NULL
;
330 if (Wnd
->strName
.Buffer
!= NULL
)
332 Wnd
->strName
.Length
= 0;
333 Wnd
->strName
.MaximumLength
= 0;
334 DesktopHeapFree(Wnd
->head
.rpdesk
,
335 Wnd
->strName
.Buffer
);
336 Wnd
->strName
.Buffer
= NULL
;
339 DesktopHeapFree(Wnd
->head
.rpdesk
, Wnd
);
340 WindowObject
->Wnd
= NULL
;
343 /***********************************************************************
346 * Destroy storage associated to a window. "Internals" p.358
348 * This is the "functional" DestroyWindows function ei. all stuff
349 * done in CreateWindow is undone here and not in DestroyWindow:-P
352 static LRESULT
co_UserFreeWindow(PWINDOW_OBJECT Window
,
353 PPROCESSINFO ProcessData
,
354 PTHREADINFO ThreadData
,
355 BOOLEAN SendMessages
)
359 PWINDOW_OBJECT Child
;
361 BOOLEAN BelongsToThreadData
;
368 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
370 DPRINT("Tried to call IntDestroyWindow() twice\n");
373 Window
->Status
|= WINDOWSTATUS_DESTROYING
;
374 Wnd
->style
&= ~WS_VISIBLE
;
376 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Wnd
, OBJID_WINDOW
, 0);
378 /* remove the window already at this point from the thread window list so we
379 don't get into trouble when destroying the thread windows while we're still
380 in IntDestroyWindow() */
381 RemoveEntryList(&Window
->ThreadListEntry
);
383 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
385 IntDeRegisterShellHookWindow(Window
->hSelf
);
389 /* Send destroy messages */
390 IntSendDestroyMsg(Window
->hSelf
);
393 /* free child windows */
394 Children
= IntWinListChildren(Window
);
397 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
399 if ((Child
= IntGetWindowObject(*ChildHandle
)))
401 if(!IntWndBelongsToThread(Child
, ThreadData
))
403 /* send WM_DESTROY messages to windows not belonging to the same thread */
404 IntSendDestroyMsg(Child
->hSelf
);
407 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
409 UserDereferenceObject(Child
);
412 ExFreePool(Children
);
418 * Clear the update region to make sure no WM_PAINT messages will be
419 * generated for this window while processing the WM_NCDESTROY.
421 co_UserRedrawWindow(Window
, NULL
, 0,
422 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
423 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
424 if(BelongsToThreadData
)
425 co_IntSendMessage(Window
->hSelf
, WM_NCDESTROY
, 0, 0);
427 MsqRemoveTimersWindow(ThreadData
->MessageQueue
, Window
->hSelf
);
428 HOOK_DestroyThreadHooks(ThreadData
->pEThread
); // This is needed here too!
430 /* flush the message queue */
431 MsqRemoveWindowMessagesFromQueue(Window
);
433 /* from now on no messages can be sent to this window anymore */
434 Window
->Status
|= WINDOWSTATUS_DESTROYED
;
435 Wnd
->state
|= WNDS_DESTROYED
;
436 Wnd
->fnid
|= FNID_FREED
;
438 /* don't remove the WINDOWSTATUS_DESTROYING bit */
440 /* reset shell window handles */
441 if(ThreadData
->Desktop
)
443 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellWindow
)
444 ThreadData
->Desktop
->WindowStation
->ShellWindow
= NULL
;
446 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellListView
)
447 ThreadData
->Desktop
->WindowStation
->ShellListView
= NULL
;
450 /* Unregister hot keys */
451 UnregisterWindowHotKeys (Window
);
453 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
457 WinPosCheckInternalPos(Window
->hSelf
);
458 if (Window
->hSelf
== GetCapture())
463 /* free resources associated with the window */
464 TIMER_RemoveWindowTimers(Window
->hSelf
);
467 if (!(Wnd
->style
& WS_CHILD
) && Wnd
->IDMenu
468 && (Menu
= UserGetMenuObject((HMENU
)Wnd
->IDMenu
)))
470 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
474 if(Window
->SystemMenu
475 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
477 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
478 Window
->SystemMenu
= (HMENU
)0;
481 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
484 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
485 CLASS_RemoveWindow(Window
->Class
);
488 IntUnlinkWindow(Window
);
490 UserReferenceObject(Window
);
491 UserDeleteObject(Window
->hSelf
, otWindow
);
493 IntDestroyScrollBars(Window
);
495 /* dereference the class */
496 IntDereferenceClass(Wnd
->pcls
,
497 Window
->ti
->pDeskInfo
,
501 if(Window
->WindowRegion
)
503 GreDeleteObject(Window
->WindowRegion
);
506 ASSERT(Window
->Wnd
!= NULL
);
507 UserFreeWindowInfo(Window
->ti
, Window
);
509 UserDereferenceObject(Window
);
511 IntClipboardFreeWindow(Window
);
517 IntGetWindowBorderMeasures(PWINDOW_OBJECT Window
, UINT
*cx
, UINT
*cy
)
519 PWND Wnd
= Window
->Wnd
;
520 if(HAS_DLGFRAME(Wnd
->style
, Wnd
->ExStyle
) && !(Wnd
->style
& WS_MINIMIZE
))
522 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
523 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
527 if(HAS_THICKFRAME(Wnd
->style
, Wnd
->ExStyle
)&& !(Wnd
->style
& WS_MINIMIZE
))
529 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
530 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
532 else if(HAS_THINFRAME(Wnd
->style
, Wnd
->ExStyle
))
534 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
535 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
545 // Same as User32:IntGetWndProc.
548 IntGetWindowProc(PWND pWnd
,
553 WNDPROC gcpd
, Ret
= 0;
555 ASSERT(UserIsEnteredExclusive() == TRUE
);
559 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
561 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
563 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
566 Ret
= GETPFNCLIENTA(i
);
568 Ret
= GETPFNCLIENTW(i
);
574 if (Class
->fnid
== FNID_EDIT
)
575 Ret
= pWnd
->lpfnWndProc
;
578 Ret
= pWnd
->lpfnWndProc
;
580 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
584 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
585 Ret
= GETPFNCLIENTA(Class
->fnid
);
589 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
590 Ret
= GETPFNCLIENTW(Class
->fnid
);
593 if ( Ret
!= pWnd
->lpfnWndProc
)
596 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
599 gcpd
= (WNDPROC
)UserGetCPD(
601 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
604 return (gcpd
? gcpd
: Ret
);
608 IntSetWindowProc(PWND pWnd
,
613 PCALLPROCDATA CallProc
;
615 WNDPROC Ret
, chWndProc
= NULL
;
617 // Retrieve previous window proc.
618 Ret
= IntGetWindowProc(pWnd
, Ansi
);
622 if (IsCallProcHandle(NewWndProc
))
624 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, otCallProc
);
626 { // Reset new WndProc.
627 NewWndProc
= CallProc
->pfnClientPrevious
;
628 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
629 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
632 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
633 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
635 if (GETPFNCLIENTW(i
) == NewWndProc
)
637 chWndProc
= GETPFNSERVER(i
);
640 if (GETPFNCLIENTA(i
) == NewWndProc
)
642 chWndProc
= GETPFNSERVER(i
);
646 // If match, set/reset to Server Side and clear ansi.
649 pWnd
->lpfnWndProc
= chWndProc
;
650 pWnd
->Unicode
= TRUE
;
651 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
652 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
656 pWnd
->Unicode
= !Ansi
;
657 // Handle the state change in here.
659 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
661 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
663 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
664 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
666 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
668 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
672 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
673 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
677 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
678 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
681 // Now set the new window proc.
682 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
687 // Move this to user space!
689 IntGetWindowInfo(PWINDOW_OBJECT Window
, PWINDOWINFO pwi
)
691 PWND Wnd
= Window
->Wnd
;
693 pwi
->cbSize
= sizeof(WINDOWINFO
);
694 pwi
->rcWindow
= Window
->Wnd
->rcWindow
;
695 pwi
->rcClient
= Window
->Wnd
->rcClient
;
696 pwi
->dwStyle
= Wnd
->style
;
697 pwi
->dwExStyle
= Wnd
->ExStyle
;
698 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Window
->hSelf
); /* WS_ACTIVECAPTION */
699 IntGetWindowBorderMeasures(Window
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
700 pwi
->atomWindowType
= (Wnd
->pcls
? Wnd
->pcls
->atomClassName
: 0);
701 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
707 PWINDOW_OBJECT Window
,
711 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
712 PWND Wnd
= Window
->Wnd
;
714 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
716 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
720 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
728 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
729 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Window
->hSelf
);
738 NewMenu
= IntGetMenuObject(Menu
);
743 IntReleaseMenuObject(OldMenu
);
745 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
748 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
750 /* Can't use the same menu for two windows */
753 IntReleaseMenuObject(OldMenu
);
755 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
761 Wnd
->IDMenu
= (UINT
) Menu
;
764 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
765 IntReleaseMenuObject(NewMenu
);
769 OldMenu
->MenuInfo
.Wnd
= NULL
;
770 IntReleaseMenuObject(OldMenu
);
777 /* INTERNAL ******************************************************************/
781 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
786 USER_REFERENCE_ENTRY Ref
;
787 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
789 while (!IsListEmpty(&WThread
->WindowListHead
))
791 Current
= WThread
->WindowListHead
.Flink
;
792 Wnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
794 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
796 /* window removes itself from the list */
799 fixme: it is critical that the window removes itself! if now, we will loop
803 //ASSERT(co_UserDestroyWindow(Wnd));
805 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
806 if (!co_UserDestroyWindow(Wnd
))
808 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
810 UserDerefObjectCo(Wnd
);//faxme: temp hack??
818 * Returns client window rectangle relative to the upper-left corner of client area.
820 * \note Does not check the validity of the parameters
823 IntGetClientRect(PWINDOW_OBJECT Window
, RECTL
*Rect
)
828 Rect
->left
= Rect
->top
= 0;
829 Rect
->right
= Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
;
830 Rect
->bottom
= Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
;
836 IntGetFocusWindow(VOID
)
838 PUSER_MESSAGE_QUEUE Queue
;
839 PDESKTOP pdo
= IntGetActiveDesktop();
844 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
849 return(Queue
->FocusWindow
);
853 PMENU_OBJECT FASTCALL
854 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
)
856 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
857 PTHREADINFO W32Thread
;
858 HMENU hNewMenu
, hSysMenu
;
859 ROSMENUITEMINFO ItemInfo
;
863 W32Thread
= PsGetCurrentThreadWin32Thread();
865 if(!W32Thread
->Desktop
)
868 if(Window
->SystemMenu
)
870 Menu
= UserGetMenuObject(Window
->SystemMenu
);
873 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
874 Window
->SystemMenu
= (HMENU
)0;
878 if(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
)
880 /* clone system menu */
881 Menu
= UserGetMenuObject(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
);
885 NewMenu
= IntCloneMenu(Menu
);
888 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
889 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
890 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
892 //IntReleaseMenuObject(NewMenu);
897 hSysMenu
= UserCreateMenu(FALSE
);
898 if (NULL
== hSysMenu
)
902 SysMenu
= IntGetMenuObject(hSysMenu
);
905 UserDestroyMenu(hSysMenu
);
908 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
909 SysMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
910 hNewMenu
= co_IntLoadSysMenuTemplate();
913 IntReleaseMenuObject(SysMenu
);
914 UserDestroyMenu(hSysMenu
);
917 Menu
= IntGetMenuObject(hNewMenu
);
920 IntReleaseMenuObject(SysMenu
);
921 UserDestroyMenu(hSysMenu
);
925 NewMenu
= IntCloneMenu(Menu
);
928 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
929 IntReleaseMenuObject(NewMenu
);
930 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
932 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
933 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
934 ItemInfo
.fType
= MF_POPUP
;
935 ItemInfo
.fState
= MFS_ENABLED
;
936 ItemInfo
.dwTypeData
= NULL
;
938 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
939 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
941 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
945 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
954 if(Window
->SystemMenu
)
955 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
963 IntIsChildWindow(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT BaseWindow
)
965 PWINDOW_OBJECT Window
;
972 if (Window
== Parent
)
976 if(!(Wnd
->style
& WS_CHILD
))
981 Window
= Window
->Parent
;
988 IntIsWindowVisible(PWINDOW_OBJECT BaseWindow
)
990 PWINDOW_OBJECT Window
;
997 if(!(Wnd
->style
& WS_CHILD
))
1001 if(!(Wnd
->style
& WS_VISIBLE
))
1006 Window
= Window
->Parent
;
1009 if(Window
&& Wnd
->style
& WS_VISIBLE
)
1018 /* link the window into siblings and parent. children are kept in place. */
1022 PWINDOW_OBJECT WndParent
,
1023 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
1026 PWINDOW_OBJECT Parent
;
1028 Wnd
->Parent
= WndParent
;
1029 Wnd
->Wnd
->spwndParent
= WndParent
? WndParent
->Wnd
: NULL
;
1030 if ((Wnd
->PrevSibling
= WndPrevSibling
))
1032 /* link after WndPrevSibling */
1033 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
1034 Wnd
->NextSibling
->PrevSibling
= Wnd
;
1035 else if ((Parent
= Wnd
->Parent
))
1037 if(Parent
->LastChild
== WndPrevSibling
)
1038 Parent
->LastChild
= Wnd
;
1040 Wnd
->PrevSibling
->NextSibling
= Wnd
;
1045 Parent
= Wnd
->Parent
;
1046 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
1047 Wnd
->NextSibling
->PrevSibling
= Wnd
;
1050 Parent
->LastChild
= Wnd
;
1051 Parent
->FirstChild
= Wnd
;
1056 Parent
->FirstChild
= Wnd
;
1063 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1065 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
1068 Wnd
= IntGetWindowObject(hWnd
);
1072 WndOldOwner
= IntGetWindowObject(Wnd
->hOwner
);
1075 ret
= WndOldOwner
->hSelf
;
1076 UserDereferenceObject(WndOldOwner
);
1083 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1085 Wnd
->hOwner
= hWndNewOwner
;
1086 Wnd
->Wnd
->spwndOwner
= WndNewOwner
->Wnd
;
1091 Wnd
->Wnd
->spwndOwner
= NULL
;
1094 UserDereferenceObject(Wnd
);
1098 PWINDOW_OBJECT FASTCALL
1099 co_IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
1101 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
1102 // HWND hWnd, hWndNewParent;
1106 ASSERT(WndNewParent
);
1107 ASSERT_REFS_CO(Wnd
);
1108 ASSERT_REFS_CO(WndNewParent
);
1110 // hWnd = Wnd->hSelf;
1111 // hWndNewParent = WndNewParent->hSelf;
1113 /* Some applications try to set a child as a parent */
1114 if (IntIsChildWindow(Wnd
, WndNewParent
))
1116 SetLastWin32Error( ERROR_INVALID_PARAMETER
);
1121 * Windows hides the window first, then shows it again
1122 * including the WM_SHOWWINDOW messages and all
1124 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1126 // /* Validate that window and parent still exist */
1127 // if (!IntIsWindow(hWnd) || !IntIsWindow(hWndNewParent))
1130 /* Window must belong to current process */
1131 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
1134 WndOldParent
= Wnd
->Parent
;
1136 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1138 if (WndNewParent
!= WndOldParent
)
1140 IntUnlinkWindow(Wnd
);
1142 if (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1144 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
1145 Sibling
= WndNewParent
->FirstChild
;
1146 while (NULL
!= Sibling
&& 0 != (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1148 InsertAfter
= Sibling
;
1149 Sibling
= Sibling
->NextSibling
;
1152 if (NULL
== InsertAfter
)
1154 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1158 // UserReferenceObject(InsertAfter);
1159 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1160 // UserDereferenceObject(InsertAfter);
1165 * SetParent additionally needs to make hwnd the top window
1166 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1167 * WM_WINDOWPOSCHANGED notification messages.
1169 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1170 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1171 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1174 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1175 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1179 * Validate that the old parent still exist, since it migth have been
1180 * destroyed during the last callbacks to user-mode
1184 // if(!IntIsWindow(WndOldParent->hSelf))
1186 // UserDereferenceObject(WndOldParent);
1190 /* don't dereference the window object here, it must be done by the caller
1191 of IntSetParent() */
1192 // return WndOldParent;
1195 return WndOldParent
;//NULL;
1199 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
1201 PMENU_OBJECT OldMenu
;
1202 if(Window
->SystemMenu
)
1204 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1207 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1208 IntReleaseMenuObject(OldMenu
);
1214 /* FIXME check window style, propably return FALSE ? */
1215 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1216 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1219 Window
->SystemMenu
= (HMENU
)0;
1225 /* unlink the window from siblings and parent. children are kept in place. */
1227 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1229 PWINDOW_OBJECT WndParent
= Wnd
->Parent
;
1231 if (Wnd
->NextSibling
)
1232 Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1233 else if (WndParent
&& WndParent
->LastChild
== Wnd
)
1234 WndParent
->LastChild
= Wnd
->PrevSibling
;
1236 if (Wnd
->PrevSibling
)
1237 Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1238 else if (WndParent
&& WndParent
->FirstChild
== Wnd
)
1239 WndParent
->FirstChild
= Wnd
->NextSibling
;
1241 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1243 Wnd
->Wnd
->spwndParent
= NULL
;
1249 PWINDOW_OBJECT Window
, Child
;
1251 if(!(Window
= UserGetWindowObject(IntGetDesktopWindow())))
1256 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1258 if(Child
->hOwner
&& Child
->Wnd
->style
& WS_VISIBLE
)
1261 * The desktop has a popup window if one of them has
1262 * an owner window and is visible
1272 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1274 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1280 IntGetWindowPlacement(PWINDOW_OBJECT Window
, WINDOWPLACEMENT
*lpwndpl
)
1286 if (!Wnd
) return FALSE
;
1288 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1294 if (0 == (Wnd
->style
& WS_VISIBLE
))
1296 lpwndpl
->showCmd
= SW_HIDE
;
1298 else if (0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
1299 0 != (Wnd
->style
& WS_MAXIMIZE
))
1301 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1303 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1305 lpwndpl
->showCmd
= SW_MINIMIZE
;
1307 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1309 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1312 Size
.x
= Wnd
->rcWindow
.left
;
1313 Size
.y
= Wnd
->rcWindow
.top
;
1314 WinPosInitInternalPos(Window
, &Size
,
1317 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1318 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1319 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1325 /* FUNCTIONS *****************************************************************/
1331 NtUserAlterWindowStyle(DWORD Unknown0
,
1341 * As best as I can figure, this function is used by EnumWindows,
1342 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1344 * It's supposed to build a list of HWNDs to return to the caller.
1345 * We can figure out what kind of list by what parameters are
1353 NtUserBuildHwndList(
1366 return ERROR_INVALID_PARAMETER
;
1368 if (hwndParent
|| !dwThreadId
)
1371 PWINDOW_OBJECT Parent
, Window
;
1375 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1377 return ERROR_INVALID_HANDLE
;
1382 Status
= IntValidateDesktopHandle(hDesktop
,
1386 if(!NT_SUCCESS(Status
))
1388 return ERROR_INVALID_HANDLE
;
1391 hwndParent
= Desktop
->DesktopWindow
;
1398 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1399 (Window
= Parent
->FirstChild
))
1401 BOOL bGoDown
= TRUE
;
1403 Status
= STATUS_SUCCESS
;
1408 if(dwCount
++ < *pBufSize
&& pWnd
)
1412 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1413 *pWnd
= Window
->hSelf
;
1416 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1418 Status
= _SEH2_GetExceptionCode();
1421 if(!NT_SUCCESS(Status
))
1423 SetLastNtError(Status
);
1427 if (Window
->FirstChild
&& bChildren
)
1429 Window
= Window
->FirstChild
;
1434 if (Window
->NextSibling
)
1436 Window
= Window
->NextSibling
;
1440 Window
= Window
->Parent
;
1441 if (Window
== Parent
)
1450 ObDereferenceObject(Desktop
);
1456 PTHREADINFO W32Thread
;
1457 PLIST_ENTRY Current
;
1458 PWINDOW_OBJECT Window
;
1460 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1461 if(!NT_SUCCESS(Status
))
1463 return ERROR_INVALID_PARAMETER
;
1465 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1467 ObDereferenceObject(Thread
);
1468 DPRINT("Thread is not a GUI Thread!\n");
1469 return ERROR_INVALID_PARAMETER
;
1472 Current
= W32Thread
->WindowListHead
.Flink
;
1473 while(Current
!= &(W32Thread
->WindowListHead
))
1475 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1478 if(bChildren
|| Window
->hOwner
!= NULL
)
1480 if(dwCount
< *pBufSize
&& pWnd
)
1482 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1483 if(!NT_SUCCESS(Status
))
1485 SetLastNtError(Status
);
1491 Current
= Current
->Flink
;
1494 ObDereferenceObject(Thread
);
1497 *pBufSize
= dwCount
;
1498 return STATUS_SUCCESS
;
1506 NtUserChildWindowFromPointEx(HWND hwndParent
,
1511 PWINDOW_OBJECT Parent
;
1516 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1524 if(Parent
->hSelf
!= IntGetDesktopWindow())
1526 Pt
.x
+= Parent
->Wnd
->rcClient
.left
;
1527 Pt
.y
+= Parent
->Wnd
->rcClient
.top
;
1530 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1535 Ret
= Parent
->hSelf
;
1536 if((List
= IntWinListChildren(Parent
)))
1538 for(phWnd
= List
; *phWnd
; phWnd
++)
1540 PWINDOW_OBJECT Child
;
1542 if((Child
= UserGetWindowObject(*phWnd
)))
1544 ChildWnd
= Child
->Wnd
;
1545 if(!(ChildWnd
->style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1549 if((ChildWnd
->style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1553 if((ChildWnd
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1557 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1572 * calculates the default position of a window
1575 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT Window
, RECTL
*rc
, BOOL IncPos
)
1582 RECTL_bIntersectRect(rc
, rc
, &Parent
->Wnd
->rcClient
);
1586 Pos
.x
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1587 Pos
.y
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1588 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1589 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1591 /* reset counter and position */
1594 Parent
->TiledCounter
= 0;
1596 Parent
->TiledCounter
++;
1607 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1608 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1612 rc
->right
= rc
->left
+ Sz
.cx
;
1613 rc
->bottom
= rc
->top
+ Sz
.cy
;
1622 co_IntCreateWindowEx(DWORD dwExStyle
,
1623 PUNICODE_STRING ClassName
,
1624 PUNICODE_STRING WindowName
,
1632 HINSTANCE hInstance
,
1635 BOOL bUnicodeWindow
)
1637 PWINSTATION_OBJECT WinSta
;
1639 PCLS
*ClassLink
, Class
= NULL
;
1641 PWINDOW_OBJECT Window
= NULL
;
1642 PWINDOW_OBJECT ParentWindow
= NULL
, OwnerWindow
;
1643 HWND ParentWindowHandle
= NULL
;
1644 HWND OwnerWindowHandle
;
1645 PMENU_OBJECT SystemMenu
;
1649 PTHREADINFO ti
= NULL
;
1652 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1658 CBT_CREATEWNDW CbtCreate
;
1661 DECLARE_RETURN(PWND
);
1663 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1666 pti
= PsGetCurrentThreadWin32Thread();
1670 ParentWindowHandle
= pti
->Desktop
->DesktopWindow
;
1674 if ( !(pti
->ppi
->W32PF_flags
& W32PF_CLASSESREGISTERED
))
1676 UserRegisterSystemClasses();
1679 OwnerWindowHandle
= NULL
;
1681 DPRINT("co_IntCreateWindowEx %wZ\n", ClassName
);
1683 if (hWndParent
== HWND_MESSAGE
)
1686 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1687 * message window (style: WS_POPUP|WS_DISABLED)
1689 ParentWindowHandle
= IntGetMessageWindow();
1690 DPRINT("Parent is HWND_MESSAGE 0x%x\n", ParentWindowHandle
);
1692 else if (hWndParent
)
1694 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1696 PWINDOW_OBJECT Par
= UserGetWindowObject(hWndParent
), Root
;
1697 if (Par
&& (Root
= UserGetAncestor(Par
, GA_ROOT
)))
1698 OwnerWindowHandle
= Root
->hSelf
;
1701 ParentWindowHandle
= hWndParent
;
1703 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1705 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1706 RETURN( (PWND
)0); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1709 if (ParentWindowHandle
)
1711 ParentWindow
= UserGetWindowObject(ParentWindowHandle
);
1713 if (ParentWindow
) UserRefObjectCo(ParentWindow
, &ParentRef
);
1717 ParentWindow
= NULL
;
1720 /* FIXME: parent must belong to the current process */
1722 /* Check the window station. */
1723 ti
= GetW32ThreadInfo();
1724 if (ti
== NULL
|| pti
->Desktop
== NULL
)
1726 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1730 /* Check the class. */
1732 DPRINT("Class %wZ\n", ClassName
);
1734 ClassAtom
= IntGetClassAtom(ClassName
,
1740 if (ClassAtom
== (RTL_ATOM
)0)
1742 if (IS_ATOM(ClassName
->Buffer
))
1744 DPRINT1("Class 0x%p not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1748 DPRINT1("Class \"%wZ\" not found\n", ClassName
);
1751 SetLastWin32Error(ERROR_CANNOT_FIND_WND_CLASS
);
1754 DPRINT("ClassAtom %x\n", ClassAtom
);
1755 Class
= IntReferenceClass(Class
,
1760 DPRINT1("Failed to reference window class!\n");
1764 WinSta
= pti
->Desktop
->WindowStation
;
1766 //FIXME: Reference thread/desktop instead
1767 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1769 /* Create the window object. */
1770 Window
= (PWINDOW_OBJECT
) UserCreateObject( gHandleTable
,
1773 sizeof(WINDOW_OBJECT
));
1776 Window
->Wnd
= DesktopHeapAlloc(pti
->Desktop
,
1777 sizeof(WND
) + Class
->cbwndExtra
);
1780 RtlZeroMemory(Window
->Wnd
,
1781 sizeof(WND
) + Class
->cbwndExtra
);
1782 Window
->Wnd
->head
.h
= hWnd
;
1787 Wnd
->head
.rpdesk
= pti
->Desktop
;
1788 Wnd
->hWndLastActive
= hWnd
;
1789 Wnd
->state2
|= WNDS2_WIN40COMPAT
;
1792 DPRINT("Created object with handle %X\n", hWnd
);
1796 ObDereferenceObject(WinSta
);
1797 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1801 UserRefObjectCo(Window
, &Ref
);
1803 ObDereferenceObject(WinSta
);
1805 if (NULL
== pti
->Desktop
->DesktopWindow
)
1807 /* If there is no desktop window yet, we must be creating it */
1808 pti
->Desktop
->DesktopWindow
= hWnd
;
1809 pti
->Desktop
->DesktopInfo
->Wnd
= Wnd
;
1813 * Fill out the structure describing it.
1819 Window
->SystemMenu
= (HMENU
)0;
1821 Wnd
->hModule
= hInstance
;
1822 Window
->hSelf
= hWnd
;
1824 Window
->MessageQueue
= pti
->MessageQueue
;
1825 IntReferenceMessageQueue(Window
->MessageQueue
);
1826 Window
->Parent
= ParentWindow
;
1827 Wnd
->spwndParent
= ParentWindow
? ParentWindow
->Wnd
: NULL
;
1828 if (Wnd
->spwndParent
!= NULL
&& hWndParent
!= 0)
1830 Wnd
->HideFocus
= Wnd
->spwndParent
->HideFocus
;
1831 Wnd
->HideAccel
= Wnd
->spwndParent
->HideAccel
;
1834 if((OwnerWindow
= UserGetWindowObject(OwnerWindowHandle
)))
1836 Window
->hOwner
= OwnerWindowHandle
;
1837 Wnd
->spwndOwner
= OwnerWindow
->Wnd
;
1842 Window
->hOwner
= NULL
;
1843 Wnd
->spwndOwner
= NULL
;
1847 Wnd
->dwUserData
= 0;
1849 if (Wnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1850 Wnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1852 /* BugBoy Comments: Comment below say that System classes are always created
1853 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1854 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1856 No where can I see in code or through testing does the window change back
1857 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1858 see what problems this would cause.*/
1860 // Set WndProc from Class.
1861 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
1863 // GetWindowProc, test for non server side default classes and set WndProc.
1864 if ( Wnd
->pcls
->fnid
<= FNID_GHOST
&& Wnd
->pcls
->fnid
>= FNID_BUTTON
)
1868 if (GETPFNCLIENTA(Wnd
->pcls
->fnid
) == Wnd
->lpfnWndProc
)
1869 Wnd
->lpfnWndProc
= GETPFNCLIENTW(Wnd
->pcls
->fnid
);
1873 if (GETPFNCLIENTW(Wnd
->pcls
->fnid
) == Wnd
->lpfnWndProc
)
1874 Wnd
->lpfnWndProc
= GETPFNCLIENTA(Wnd
->pcls
->fnid
);
1878 // If not an Unicode caller, set Ansi creator bit.
1879 if (!bUnicodeWindow
) Wnd
->state
|= WNDS_ANSICREATOR
;
1881 // Clone Class Ansi/Unicode proc type.
1882 if (Wnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1884 Wnd
->state
|= WNDS_ANSIWINDOWPROC
;
1885 Wnd
->Unicode
= FALSE
;
1889 It seems there can be both an Ansi creator and Unicode Class Window
1890 WndProc, unless the following overriding conditions occur:
1892 if ( !bUnicodeWindow
&&
1893 ( ClassAtom
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1894 ClassAtom
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1895 ClassAtom
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1896 ClassAtom
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1897 ClassAtom
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1898 ClassAtom
== gpsi
->atomSysClass
[ICLS_IME
] ||
1899 ClassAtom
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1900 ClassAtom
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1901 ClassAtom
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1902 { // Override Class and set the window Ansi WndProc.
1903 Wnd
->state
|= WNDS_ANSIWINDOWPROC
;
1904 Wnd
->Unicode
= FALSE
;
1907 { // Set the window Unicode WndProc.
1908 Wnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1909 Wnd
->Unicode
= TRUE
;
1913 Window
->OwnerThread
= PsGetCurrentThread();
1914 Window
->FirstChild
= NULL
;
1915 Window
->LastChild
= NULL
;
1916 Window
->PrevSibling
= NULL
;
1917 Window
->NextSibling
= NULL
;
1918 Wnd
->cbwndExtra
= Wnd
->pcls
->cbwndExtra
;
1920 InitializeListHead(&Wnd
->PropListHead
);
1921 InitializeListHead(&Window
->WndObjListHead
);
1923 if ( NULL
!= WindowName
->Buffer
&& WindowName
->Length
> 0 )
1925 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
1926 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1927 if (Wnd
->strName
.Buffer
== NULL
)
1929 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1933 Wnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1936 RtlCopyMemory(Wnd
->strName
.Buffer
,
1938 WindowName
->Length
);
1939 Wnd
->strName
.Length
= WindowName
->Length
;
1941 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1943 WindowName
->Length
= 0;
1944 Wnd
->strName
.Buffer
[0] = L
'\0';
1950 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1951 * tested for WS_POPUP
1953 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1954 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1955 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1956 dwExStyle
|= WS_EX_WINDOWEDGE
;
1958 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1960 /* Correct the window style. */
1961 if (!(dwStyle
& WS_CHILD
))
1963 dwStyle
|= WS_CLIPSIBLINGS
;
1964 DPRINT("3: Style is now %lx\n", dwStyle
);
1965 if (!(dwStyle
& WS_POPUP
))
1967 dwStyle
|= WS_CAPTION
;
1968 Window
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1969 DPRINT("4: Style is now %lx\n", dwStyle
);
1973 /* create system menu */
1974 if((dwStyle
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1976 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
1979 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1980 IntReleaseMenuObject(SystemMenu
);
1984 /* Set the window menu */
1985 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1988 IntSetMenu(Window
, hMenu
, &MenuChanged
);
1989 else if (Wnd
->pcls
->lpszMenuName
) // Take it from the parent.
1991 UNICODE_STRING MenuName
;
1992 if (IS_INTRESOURCE(Wnd
->pcls
->lpszMenuName
))
1994 MenuName
.Length
= 0;
1995 MenuName
.MaximumLength
= 0;
1996 MenuName
.Buffer
= Wnd
->pcls
->lpszMenuName
;
2000 RtlInitUnicodeString( &MenuName
, Wnd
->pcls
->lpszMenuName
);
2002 hMenu
= co_IntCallLoadMenu( Wnd
->pcls
->hModule
, &MenuName
);
2003 if (hMenu
) IntSetMenu(Window
, hMenu
, &MenuChanged
);
2007 Wnd
->IDMenu
= (UINT
) hMenu
;
2009 /* Insert the window into the thread's window list. */
2010 InsertTailList (&pti
->WindowListHead
, &Window
->ThreadListEntry
);
2012 /* Handle "CS_CLASSDC", it is tested first. */
2013 if ((Wnd
->pcls
->style
& CS_CLASSDC
) && !(Wnd
->pcls
->pdce
)) // One DCE per class to have CLASS.
2014 Wnd
->pcls
->pdce
= DceAllocDCE(Window
, DCE_CLASS_DC
);
2015 /* Allocate a DCE for this window. */
2016 else if ( Wnd
->pcls
->style
& CS_OWNDC
)
2017 Window
->Dce
= DceAllocDCE(Window
, DCE_WINDOW_DC
);
2024 Wnd
->ExStyle
= dwExStyle
;
2025 Wnd
->style
= dwStyle
& ~WS_VISIBLE
;
2028 Cs
.lpCreateParams
= lpParam
;
2029 Cs
.hInstance
= hInstance
;
2031 Cs
.hwndParent
= hWndParent
; //Pass the original Parent handle!
2036 Cs
.style
= Wnd
->style
;
2037 // Cs.lpszName = (LPCWSTR) WindowName->Buffer;
2038 // Cs.lpszClass = (LPCWSTR) ClassName->Buffer;
2039 Cs
.lpszName
= (LPCWSTR
) WindowName
;
2040 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
2041 Cs
.dwExStyle
= dwExStyle
;
2042 CbtCreate
.lpcs
= &Cs
;
2043 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
2044 if (ISITHOOKED(WH_CBT
))
2046 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) &CbtCreate
))
2048 /* FIXME - Delete window object and remove it from the thread windows list */
2049 /* FIXME - delete allocated DCE */
2050 DPRINT1("CBT-hook returned !0\n");
2051 RETURN( (PWND
) NULL
);
2058 // FIXME: Need to set the Z order in the window link list if the hook callback changed it!
2059 // hwndInsertAfter = CbtCreate.hwndInsertAfter;
2061 /* default positioning for overlapped windows */
2062 if(!(Wnd
->style
& (WS_POPUP
| WS_CHILD
)))
2065 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
2066 BOOL CalculatedDefPosSize
= FALSE
;
2068 IntGetDesktopWorkArea(((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
, &WorkArea
);
2071 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
2073 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
2075 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, Window
, &rc
, TRUE
);
2077 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
2079 ProcessParams
->WindowFlags
&= ~STARTF_USEPOSITION
;
2080 Pos
.x
= WorkArea
.left
+ ProcessParams
->StartingX
;
2081 Pos
.y
= WorkArea
.top
+ ProcessParams
->StartingY
;
2090 According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
2091 y is something else. and Quote!
2094 /* Never believe Microsoft's documentation... CreateWindowEx doc says
2095 * that if an overlapped window is created with WS_VISIBLE style bit
2096 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
2097 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
2100 * 1) not only it checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
2101 * 2) it does not ignore the y parameter as the docs claim; instead, it
2102 * uses it as second parameter to ShowWindow() unless y is either
2103 * CW_USEDEFAULT or CW_USEDEFAULT16.
2105 * The fact that we didn't do 2) caused bogus windows pop up when wine
2106 * was running apps that were using this obscure feature. Example -
2107 * calc.exe that comes with Win98 (only Win98, it's different from
2108 * the one that comes with Win95 and NT)
2110 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
2115 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
2117 if(!CalculatedDefPosSize
)
2119 IntCalcDefPosSize(ParentWindow
, Window
, &rc
, FALSE
);
2121 if(ProcessParams
->WindowFlags
& STARTF_USESIZE
)
2123 ProcessParams
->WindowFlags
&= ~STARTF_USESIZE
;
2124 Size
.cx
= ProcessParams
->CountX
;
2125 Size
.cy
= ProcessParams
->CountY
;
2129 Size
.cx
= rc
.right
- rc
.left
;
2130 Size
.cy
= rc
.bottom
- rc
.top
;
2133 /* move the window if necessary */
2135 Pos
.x
= max(rc
.left
, 0);
2137 Pos
.y
= max(rc
.top
, 0);
2142 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
2143 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
2148 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
2155 /* Initialize the window dimensions. */
2156 Wnd
->rcWindow
.left
= Pos
.x
;
2157 Wnd
->rcWindow
.top
= Pos
.y
;
2158 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
2159 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
2160 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2162 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2163 ParentWindow
->Wnd
->rcClient
.top
);
2165 Wnd
->rcClient
= Wnd
->rcWindow
;
2168 * Get the size and position of the window.
2170 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
2172 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2174 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
2175 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
,
2177 if (MaxSize
.x
< Size
.cx
)
2178 Size
.cx
= MaxSize
.x
;
2179 if (MaxSize
.y
< Size
.cy
)
2180 Size
.cy
= MaxSize
.y
;
2181 if (Size
.cx
< MinTrack
.x
)
2182 Size
.cx
= MinTrack
.x
;
2183 if (Size
.cy
< MinTrack
.y
)
2184 Size
.cy
= MinTrack
.y
;
2191 Wnd
->rcWindow
.left
= Pos
.x
;
2192 Wnd
->rcWindow
.top
= Pos
.y
;
2193 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
2194 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
2195 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2197 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2198 ParentWindow
->Wnd
->rcClient
.top
);
2200 Wnd
->rcClient
= Wnd
->rcWindow
;
2202 /* FIXME: Initialize the window menu. */
2204 /* Send a NCCREATE message. */
2210 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
2211 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, Size
.cx
, Size
.cy
);
2212 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
2213 Result
= co_IntSendMessage(Window
->hSelf
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
2216 /* FIXME: Cleanup. */
2217 DPRINT1("IntCreateWindowEx(): NCCREATE message failed. No cleanup performed!\n");
2221 /* Calculate the non-client size. */
2222 MaxPos
.x
= Window
->Wnd
->rcWindow
.left
;
2223 MaxPos
.y
= Window
->Wnd
->rcWindow
.top
;
2226 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
2227 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
2228 Result
= co_WinPosGetNonClientSize(Window
,
2229 &Window
->Wnd
->rcWindow
,
2230 &Window
->Wnd
->rcClient
);
2232 RECTL_vOffsetRect(&Window
->Wnd
->rcWindow
,
2233 MaxPos
.x
- Window
->Wnd
->rcWindow
.left
,
2234 MaxPos
.y
- Window
->Wnd
->rcWindow
.top
);
2237 if (NULL
!= ParentWindow
)
2239 /* link the window into the parent's child list */
2240 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2242 PWINDOW_OBJECT PrevSibling
;
2244 PrevSibling
= ParentWindow
->LastChild
;
2246 /* link window as bottom sibling */
2247 IntLinkWindow(Window
, ParentWindow
, PrevSibling
/*prev sibling*/);
2251 /* link window as top sibling (but after topmost siblings) */
2252 PWINDOW_OBJECT InsertAfter
, Sibling
;
2253 if (!(dwExStyle
& WS_EX_TOPMOST
))
2256 Sibling
= ParentWindow
->FirstChild
;
2257 while (Sibling
&& (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
2259 InsertAfter
= Sibling
;
2260 Sibling
= Sibling
->NextSibling
;
2268 IntLinkWindow(Window
, ParentWindow
, InsertAfter
/* prev sibling */);
2273 /* Send the WM_CREATE message. */
2274 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
2275 Result
= co_IntSendMessage(Window
->hSelf
, WM_CREATE
, 0, (LPARAM
) &Cs
);
2277 if (Result
== (LRESULT
)-1)
2279 /* FIXME: Cleanup. */
2280 DPRINT1("IntCreateWindowEx(): send CREATE message failed. No cleanup performed!\n");
2281 IntUnlinkWindow(Window
);
2285 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
->Wnd
, OBJID_WINDOW
, 0);
2287 /* Send move and size messages. */
2288 if (!(Window
->Flags
& WINDOWOBJECT_NEED_SIZE
))
2292 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
2294 if ((Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
) < 0 ||
2295 (Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
) < 0)
2297 DPRINT("Sending bogus WM_SIZE\n");
2300 lParam
= MAKE_LONG(Window
->Wnd
->rcClient
.right
-
2301 Window
->Wnd
->rcClient
.left
,
2302 Window
->Wnd
->rcClient
.bottom
-
2303 Window
->Wnd
->rcClient
.top
);
2304 co_IntSendMessage(Window
->hSelf
, WM_SIZE
, SIZE_RESTORED
,
2307 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
2309 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2311 lParam
= MAKE_LONG(Wnd
->rcClient
.left
- ParentWindow
->Wnd
->rcClient
.left
,
2312 Wnd
->rcClient
.top
- ParentWindow
->Wnd
->rcClient
.top
);
2316 lParam
= MAKE_LONG(Wnd
->rcClient
.left
,
2320 co_IntSendMessage(Window
->hSelf
, WM_MOVE
, 0, lParam
);
2322 /* Call WNDOBJ change procs */
2323 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
2326 /* Show or maybe minimize or maximize the window. */
2327 if (Wnd
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2332 SwFlag
= (Wnd
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
2335 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2337 SwFlag
= ((Wnd
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2338 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2339 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2341 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
2342 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
2343 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2344 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2347 /* Notify the parent window of a new child. */
2348 if ((Wnd
->style
& WS_CHILD
) &&
2349 (!(Wnd
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
2351 DPRINT("IntCreateWindow(): About to notify parent\n");
2352 co_IntSendMessage(ParentWindow
->hSelf
,
2354 MAKEWPARAM(WM_CREATE
, Wnd
->IDMenu
),
2355 (LPARAM
)Window
->hSelf
);
2358 if ((!hWndParent
) && (!HasOwner
))
2360 DPRINT("Sending CREATED notify\n");
2361 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2365 DPRINT("Not sending CREATED notify, %x %d\n", ParentWindow
, HasOwner
);
2368 /* Initialize and show the window's scrollbars */
2369 if (Wnd
->style
& WS_VSCROLL
)
2371 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2373 if (Wnd
->style
& WS_HSCROLL
)
2375 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2378 if (dwStyle
& WS_VISIBLE
)
2380 if (Wnd
->style
& WS_MAXIMIZE
)
2381 dwShowMode
= SW_SHOW
;
2382 else if (Wnd
->style
& WS_MINIMIZE
)
2383 dwShowMode
= SW_SHOWMINIMIZED
;
2385 DPRINT("IntCreateWindow(): About to show window\n");
2386 co_WinPosShowWindow(Window
, dwShowMode
);
2388 if (Wnd
->ExStyle
& WS_EX_MDICHILD
)
2390 co_IntSendMessage(ParentWindow
->hSelf
, WM_MDIREFRESHMENU
, 0, 0);
2391 /* ShowWindow won't activate child windows */
2392 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2396 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
2397 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
2398 Dont understand why it does this. */
2399 if (ClassAtom
== gpsi
->atomSysClass
[ICLS_EDIT
])
2401 PCALLPROCDATA CallProc
;
2402 //CallProc = CreateCallProc(NULL, Wnd->lpfnWndProc, bUnicodeWindow, Wnd->ti->ppi);
2403 CallProc
= CreateCallProc(NULL
, Wnd
->lpfnWndProc
, Wnd
->Unicode
, Wnd
->head
.pti
->ppi
);
2407 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2408 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
2412 UserAddCallProcToClass(Wnd
->pcls
, CallProc
);
2416 DPRINT("IntCreateWindow(): = %X\n", hWnd
);
2417 DPRINT("WindowObject->SystemMenu = 0x%x\n", Window
->SystemMenu
);
2421 if (!_ret_
&& Window
&& Window
->Wnd
&& ti
)
2422 UserFreeWindowInfo(ti
, Window
);
2425 UserDerefObjectCo(Window
);
2426 UserDereferenceObject(Window
);
2428 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2429 if (!_ret_
&& ti
!= NULL
)
2433 IntDereferenceClass(Class
,
2442 NtUserCreateWindowEx(DWORD dwExStyle
,
2443 PUNICODE_STRING UnsafeClassName
,
2444 PUNICODE_STRING UnsafeWindowName
,
2452 HINSTANCE hInstance
,
2455 BOOL bUnicodeWindow
,
2459 UNICODE_STRING WindowName
;
2460 UNICODE_STRING ClassName
;
2461 HWND NewWindow
= NULL
;
2463 DECLARE_RETURN(HWND
);
2465 DPRINT("Enter NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2466 UserEnterExclusive();
2468 /* Get the class name (string or atom) */
2469 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
2470 if (! NT_SUCCESS(Status
))
2472 SetLastNtError(Status
);
2475 if (ClassName
.Length
!= 0)
2477 Status
= IntSafeCopyUnicodeStringTerminateNULL(&ClassName
, UnsafeClassName
);
2478 if (! NT_SUCCESS(Status
))
2480 SetLastNtError(Status
);
2484 else if (! IS_ATOM(ClassName
.Buffer
))
2486 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2490 /* safely copy the window name */
2491 if (NULL
!= UnsafeWindowName
)
2493 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
2494 if (! NT_SUCCESS(Status
))
2496 if (! IS_ATOM(ClassName
.Buffer
))
2498 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2500 SetLastNtError(Status
);
2506 RtlInitUnicodeString(&WindowName
, NULL
);
2509 pNewWindow
= co_IntCreateWindowEx( dwExStyle
,
2524 if (pNewWindow
) NewWindow
= UserHMGetHandle(pNewWindow
);
2526 if (WindowName
.Buffer
)
2528 ExFreePoolWithTag(WindowName
.Buffer
, TAG_STRING
);
2530 if (! IS_ATOM(ClassName
.Buffer
))
2532 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2538 DPRINT("Leave NtUserCreateWindowEx, ret=%i\n",_ret_
);
2547 NtUserDeferWindowPos(HDWP WinPosInfo
,
2549 HWND WndInsertAfter
,
2562 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2568 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2570 hWnd
= Window
->hSelf
;
2574 if (!Wnd
) return TRUE
; // FIXME: Need to finish object rewrite or lock the thread when killing the window!
2576 DPRINT("co_UserDestroyWindow \n");
2578 /* Check for owner thread */
2579 if ((Window
->OwnerThread
!= PsGetCurrentThread()))
2581 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2586 if (ISITHOOKED(WH_CBT
))
2588 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0)) return FALSE
;
2591 /* Look whether the focus is within the tree of windows we will
2594 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2596 if (UserGetActiveWindow() == Window
->hSelf
)
2598 co_WinPosActivateOtherWindow(Window
);
2602 if (Window
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2603 Window
->MessageQueue
->ActiveWindow
= NULL
;
2604 if (Window
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2605 Window
->MessageQueue
->FocusWindow
= NULL
;
2606 if (Window
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2607 Window
->MessageQueue
->CaptureWindow
= NULL
;
2609 IntDereferenceMessageQueue(Window
->MessageQueue
);
2611 IntEngWindowChanged(Window
, WOC_DELETE
);
2612 isChild
= (0 != (Wnd
->style
& WS_CHILD
));
2618 if (! USER_IsExitingThread(GetCurrentThreadId()))
2620 send_parent_notify(hwnd
, WM_DESTROY
);
2623 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2625 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2626 /* FIXME: clean up palette - see "Internals" p.352 */
2630 if (!IntIsWindow(Window
->hSelf
))
2635 /* Recursively destroy owned windows */
2640 BOOL GotOne
= FALSE
;
2643 PWINDOW_OBJECT Child
, Desktop
;
2645 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2646 UserGetWindowObject(IntGetDesktopWindow());
2647 Children
= IntWinListChildren(Desktop
);
2651 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2653 Child
= UserGetWindowObject(*ChildHandle
);
2656 if (Child
->hOwner
!= Window
->hSelf
)
2661 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2663 USER_REFERENCE_ENTRY ChildRef
;
2664 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2665 co_UserDestroyWindow(Child
);
2666 UserDerefObjectCo(Child
);//temp hack?
2672 if (Child
->hOwner
!= NULL
)
2674 Child
->hOwner
= NULL
;
2675 Child
->Wnd
->spwndOwner
= NULL
;
2679 ExFreePool(Children
);
2688 if (!IntIsWindow(Window
->hSelf
))
2693 /* Destroy the window storage */
2694 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2704 NtUserDestroyWindow(HWND Wnd
)
2706 PWINDOW_OBJECT Window
;
2707 DECLARE_RETURN(BOOLEAN
);
2709 USER_REFERENCE_ENTRY Ref
;
2711 DPRINT("Enter NtUserDestroyWindow\n");
2712 UserEnterExclusive();
2714 if (!(Window
= UserGetWindowObject(Wnd
)))
2719 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2720 ret
= co_UserDestroyWindow(Window
);
2721 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2726 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2738 NtUserDrawMenuBarTemp(
2745 /* we'll use this function just for caching the menu bar */
2755 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2765 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2771 NtUserFillWindow(HWND hWndPaint
,
2782 static HWND FASTCALL
2783 IntFindWindow(PWINDOW_OBJECT Parent
,
2784 PWINDOW_OBJECT ChildAfter
,
2786 PUNICODE_STRING WindowName
)
2788 BOOL CheckWindowName
;
2794 CheckWindowName
= WindowName
->Length
!= 0;
2796 if((List
= IntWinListChildren(Parent
)))
2801 /* skip handles before and including ChildAfter */
2802 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2806 /* search children */
2809 PWINDOW_OBJECT Child
;
2810 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2815 /* Do not send WM_GETTEXT messages in the kernel mode version!
2816 The user mode version however calls GetWindowText() which will
2817 send WM_GETTEXT messages to windows belonging to its processes */
2818 if((!CheckWindowName
|| !RtlCompareUnicodeString(WindowName
, &(Child
->Wnd
->strName
), TRUE
)) &&
2819 (!ClassAtom
|| Child
->Wnd
->pcls
->atomClassName
== ClassAtom
))
2834 * Searches a window's children for a window with the specified
2837 * hwndParent = The window whose childs are to be searched.
2839 * HWND_MESSAGE = message-only windows
2841 * hwndChildAfter = Search starts after this child window.
2842 * NULL = start from beginning
2844 * ucClassName = Class name to search for
2845 * Reguired parameter.
2847 * ucWindowName = Window name
2848 * ->Buffer == NULL = don't care
2851 * The HWND of the window if it was found, otherwise NULL
2857 NtUserFindWindowEx(HWND hwndParent
,
2858 HWND hwndChildAfter
,
2859 PUNICODE_STRING ucClassName
,
2860 PUNICODE_STRING ucWindowName
,
2863 PWINDOW_OBJECT Parent
, ChildAfter
;
2864 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2865 HWND Desktop
, Ret
= NULL
;
2866 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2867 DECLARE_RETURN(HWND
);
2869 DPRINT("Enter NtUserFindWindowEx\n");
2872 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2876 if (ucClassName
!= NULL
)
2878 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2879 if (ClassName
.Length
!= 0)
2881 ProbeForRead(ClassName
.Buffer
,
2885 else if (!IS_ATOM(ClassName
.Buffer
))
2887 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2891 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2898 if (ucWindowName
!= NULL
)
2900 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2901 if (WindowName
.Length
!= 0)
2903 ProbeForRead(WindowName
.Buffer
,
2909 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2911 SetLastNtError(_SEH2_GetExceptionCode());
2912 _SEH2_YIELD(RETURN(NULL
));
2916 if (ucClassName
!= NULL
)
2918 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2919 !IS_ATOM(ClassName
.Buffer
))
2921 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2924 else if (ClassAtom
== (RTL_ATOM
)0)
2926 /* LastError code was set by IntGetAtomFromStringOrAtom */
2932 Desktop
= IntGetCurrentThreadDesktopWindow();
2934 if(hwndParent
== NULL
)
2935 hwndParent
= Desktop
;
2936 else if(hwndParent
== HWND_MESSAGE
)
2938 hwndParent
= IntGetMessageWindow();
2941 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2947 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2954 if(Parent
->hSelf
== Desktop
)
2957 PWINDOW_OBJECT TopLevelWindow
;
2958 BOOLEAN CheckWindowName
;
2959 BOOLEAN WindowMatches
;
2960 BOOLEAN ClassMatches
;
2962 /* windows searches through all top-level windows if the parent is the desktop
2965 if((List
= IntWinListChildren(Parent
)))
2971 /* skip handles before and including ChildAfter */
2972 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2976 CheckWindowName
= WindowName
.Length
!= 0;
2978 /* search children */
2981 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2986 /* Do not send WM_GETTEXT messages in the kernel mode version!
2987 The user mode version however calls GetWindowText() which will
2988 send WM_GETTEXT messages to windows belonging to its processes */
2989 WindowMatches
= !CheckWindowName
|| !RtlCompareUnicodeString(
2990 &WindowName
, &TopLevelWindow
->Wnd
->strName
, TRUE
);
2991 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2992 ClassAtom
== TopLevelWindow
->Wnd
->pcls
->atomClassName
;
2994 if (WindowMatches
&& ClassMatches
)
2996 Ret
= TopLevelWindow
->hSelf
;
3000 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3002 /* window returns the handle of the top-level window, in case it found
3004 Ret
= TopLevelWindow
->hSelf
;
3013 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3017 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
3019 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
3020 search the message-only windows. Should this also be done if
3021 Parent is the desktop window??? */
3022 PWINDOW_OBJECT MsgWindows
;
3024 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3026 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3031 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3033 SetLastNtError(_SEH2_GetExceptionCode());
3041 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
3051 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
3062 PWINDOW_OBJECT FASTCALL
UserGetAncestor(PWINDOW_OBJECT Wnd
, UINT Type
)
3064 PWINDOW_OBJECT WndAncestor
, Parent
;
3066 if (Wnd
->hSelf
== IntGetDesktopWindow())
3075 WndAncestor
= Wnd
->Parent
;
3086 if(!(Parent
= WndAncestor
->Parent
))
3090 if(IntIsDesktopWindow(Parent
))
3095 WndAncestor
= Parent
;
3106 PWINDOW_OBJECT Parent
, Old
;
3109 Parent
= IntGetParent(WndAncestor
);
3117 // UserDereferenceObject(Parent);
3119 WndAncestor
= Parent
;
3137 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3139 PWINDOW_OBJECT Window
, Ancestor
;
3140 DECLARE_RETURN(HWND
);
3142 DPRINT("Enter NtUserGetAncestor\n");
3143 UserEnterExclusive();
3145 if (!(Window
= UserGetWindowObject(hWnd
)))
3150 Ancestor
= UserGetAncestor(Window
, Type
);
3151 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3153 RETURN(Ancestor
? Ancestor
->hSelf
: NULL
);
3156 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3164 NtUserGetComboBoxInfo(
3169 DECLARE_RETURN(BOOL
);
3171 DPRINT("Enter NtUserGetComboBoxInfo\n");
3174 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3183 sizeof(COMBOBOXINFO
),
3187 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3189 SetLastNtError(_SEH2_GetExceptionCode());
3190 _SEH2_YIELD(RETURN(FALSE
));
3194 // Pass the user pointer, it was already probed.
3195 RETURN( (BOOL
) co_IntSendMessage( Wnd
->hSelf
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3198 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3208 NtUserGetInternalWindowPos( HWND hWnd
,
3212 PWINDOW_OBJECT Window
;
3216 WINDOWPLACEMENT wndpl
;
3220 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3231 ProbeForWrite(rectWnd
,
3237 ProbeForWrite(ptIcon
,
3243 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3245 SetLastNtError(_SEH2_GetExceptionCode());
3250 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3252 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3258 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3262 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3266 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3268 SetLastNtError(_SEH2_GetExceptionCode());
3273 if (!Hit
) Ret
= wndpl
.showCmd
;
3282 NtUserGetListBoxInfo(
3286 DECLARE_RETURN(DWORD
);
3288 DPRINT("Enter NtUserGetListBoxInfo\n");
3291 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3296 RETURN( (DWORD
) co_IntSendMessage( Wnd
->hSelf
, LB_GETLISTBOXINFO
, 0, 0 ));
3299 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3306 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3308 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3309 HWND hWndOldParent
= NULL
;
3310 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3312 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3314 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3318 if (hWndChild
== IntGetDesktopWindow())
3320 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3326 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3333 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3339 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3344 UserRefObjectCo(Wnd
, &Ref
);
3345 UserRefObjectCo(WndParent
, &ParentRef
);
3347 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3349 UserDerefObjectCo(WndParent
);
3350 UserDerefObjectCo(Wnd
);
3354 hWndOldParent
= WndOldParent
->hSelf
;
3355 UserDereferenceObject(WndOldParent
);
3358 return( hWndOldParent
);
3364 * The NtUserSetParent function changes the parent window of the specified
3368 * The new parent window and the child window must belong to the same
3369 * application. If the window identified by the hWndChild parameter is
3370 * visible, the system performs the appropriate redrawing and repainting.
3371 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3372 * or WS_POPUP window styles of the window whose parent is being changed.
3379 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3381 DECLARE_RETURN(HWND
);
3383 DPRINT("Enter NtUserSetParent\n");
3384 UserEnterExclusive();
3387 Check Parent first from user space, set it here.
3391 hWndNewParent
= IntGetDesktopWindow();
3393 else if (hWndNewParent
== HWND_MESSAGE
)
3395 hWndNewParent
= IntGetMessageWindow();
3398 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3401 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3407 * UserGetShellWindow
3409 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3414 HWND FASTCALL
UserGetShellWindow(VOID
)
3416 PWINSTATION_OBJECT WinStaObject
;
3419 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3424 if (!NT_SUCCESS(Status
))
3426 SetLastNtError(Status
);
3430 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3432 ObDereferenceObject(WinStaObject
);
3437 * NtUserSetShellWindowEx
3439 * This is undocumented function to set global shell window. The global
3440 * shell window has special handling of window position.
3446 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3448 PWINSTATION_OBJECT WinStaObject
;
3449 PWINDOW_OBJECT WndShell
;
3450 DECLARE_RETURN(BOOL
);
3451 USER_REFERENCE_ENTRY Ref
;
3455 DPRINT("Enter NtUserSetShellWindowEx\n");
3456 UserEnterExclusive();
3458 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3463 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3468 if (!NT_SUCCESS(Status
))
3470 SetLastNtError(Status
);
3475 * Test if we are permitted to change the shell window.
3477 if (WinStaObject
->ShellWindow
)
3479 ObDereferenceObject(WinStaObject
);
3484 * Move shell window into background.
3486 if (hwndListView
&& hwndListView
!= hwndShell
)
3489 * Disabled for now to get Explorer working.
3490 * -- Filip, 01/nov/2003
3493 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3496 if (UserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3498 ObDereferenceObject(WinStaObject
);
3503 if (UserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3505 ObDereferenceObject(WinStaObject
);
3509 UserRefObjectCo(WndShell
, &Ref
);
3510 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3512 WinStaObject
->ShellWindow
= hwndShell
;
3513 WinStaObject
->ShellListView
= hwndListView
;
3515 ti
= GetW32ThreadInfo();
3516 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3518 UserDerefObjectCo(WndShell
);
3520 ObDereferenceObject(WinStaObject
);
3524 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3530 * NtUserGetSystemMenu
3532 * The NtUserGetSystemMenu function allows the application to access the
3533 * window menu (also known as the system menu or the control menu) for
3534 * copying and modifying.
3538 * Handle to the window that will own a copy of the window menu.
3540 * Specifies the action to be taken. If this parameter is FALSE,
3541 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3542 * currently in use. The copy is initially identical to the window menu
3543 * but it can be modified.
3544 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3545 * to the default state. The previous window menu, if any, is destroyed.
3548 * If the bRevert parameter is FALSE, the return value is a handle to a
3549 * copy of the window menu. If the bRevert parameter is TRUE, the return
3557 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3559 PWINDOW_OBJECT Window
;
3561 DECLARE_RETURN(HMENU
);
3563 DPRINT("Enter NtUserGetSystemMenu\n");
3566 if (!(Window
= UserGetWindowObject(hWnd
)))
3571 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3576 RETURN(Menu
->MenuInfo
.Self
);
3579 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3585 * NtUserSetSystemMenu
3592 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3594 BOOL Result
= FALSE
;
3595 PWINDOW_OBJECT Window
;
3597 DECLARE_RETURN(BOOL
);
3599 DPRINT("Enter NtUserSetSystemMenu\n");
3600 UserEnterExclusive();
3602 if (!(Window
= UserGetWindowObject(hWnd
)))
3610 * Assign new menu handle.
3612 if (!(Menu
= UserGetMenuObject(hMenu
)))
3617 Result
= IntSetSystemMenu(Window
, Menu
);
3623 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3629 UserGetWindow(HWND hWnd
, UINT Relationship
)
3631 PWINDOW_OBJECT Parent
, Window
;
3632 HWND hWndResult
= NULL
;
3634 if (!(Window
= UserGetWindowObject(hWnd
)))
3637 switch (Relationship
)
3640 if((Parent
= Window
->Parent
))
3642 if (Parent
->FirstChild
)
3643 hWndResult
= Parent
->FirstChild
->hSelf
;
3648 if((Parent
= Window
->Parent
))
3650 if (Parent
->LastChild
)
3651 hWndResult
= Parent
->LastChild
->hSelf
;
3656 if (Window
->NextSibling
)
3657 hWndResult
= Window
->NextSibling
->hSelf
;
3661 if (Window
->PrevSibling
)
3662 hWndResult
= Window
->PrevSibling
->hSelf
;
3666 if((Parent
= UserGetWindowObject(Window
->hOwner
)))
3668 hWndResult
= Parent
->hSelf
;
3672 if (Window
->FirstChild
)
3673 hWndResult
= Window
->FirstChild
->hSelf
;
3683 * The NtUserGetWindow function retrieves a handle to a window that has the
3684 * specified relationship (Z order or owner) to the specified window.
3691 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3693 DECLARE_RETURN(HWND
);
3695 DPRINT("Enter NtUserGetWindow\n");
3698 RETURN(UserGetWindow(hWnd
, Relationship
));
3701 DPRINT("Leave NtUserGetWindow, ret=%i\n",_ret_
);
3707 * NtUserGetWindowLong
3709 * The NtUserGetWindowLong function retrieves information about the specified
3710 * window. The function also retrieves the 32-bit (long) value at the
3711 * specified offset into the extra window memory.
3718 UserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3720 PWINDOW_OBJECT Window
, Parent
;
3724 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3726 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3734 * WndProc is only available to the owner process
3736 if (GWL_WNDPROC
== Index
3737 && Window
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3739 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3743 if ((INT
)Index
>= 0)
3745 if ((Index
+ sizeof(LONG
)) > Window
->Wnd
->cbwndExtra
)
3747 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3750 Result
= *((LONG
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3757 Result
= Wnd
->ExStyle
;
3761 Result
= Wnd
->style
;
3765 Result
= (LONG
)IntGetWindowProc(Wnd
, Ansi
);
3769 Result
= (LONG
) Wnd
->hModule
;
3772 case GWL_HWNDPARENT
:
3773 Parent
= Window
->Parent
;
3776 if (Parent
&& Parent
->hSelf
== IntGetDesktopWindow())
3777 Result
= (LONG
) UserGetWindow(Window
->hSelf
, GW_OWNER
);
3779 Result
= (LONG
) Parent
->hSelf
;
3784 Result
= (LONG
) Wnd
->IDMenu
;
3788 Result
= Wnd
->dwUserData
;
3792 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3793 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3803 * NtUserGetWindowLong
3805 * The NtUserGetWindowLong function retrieves information about the specified
3806 * window. The function also retrieves the 32-bit (long) value at the
3807 * specified offset into the extra window memory.
3814 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3816 DECLARE_RETURN(LONG
);
3818 DPRINT("Enter NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3819 UserEnterExclusive();
3821 RETURN(UserGetWindowLong(hWnd
, Index
, Ansi
));
3824 DPRINT("Leave NtUserGetWindowLong, ret=%i\n",_ret_
);
3832 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3834 PWINDOW_OBJECT Window
, Parent
;
3836 PWINSTATION_OBJECT WindowStation
;
3840 if (hWnd
== IntGetDesktopWindow())
3842 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3846 if (!(Window
= UserGetWindowObject(hWnd
)))
3853 if (!Wnd
) return 0; // No go on zero.
3855 if ((INT
)Index
>= 0)
3857 if ((Index
+ sizeof(LONG
)) > Wnd
->cbwndExtra
)
3859 SetLastWin32Error(ERROR_INVALID_INDEX
);
3863 OldValue
= *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
));
3865 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3867 OldValue = (LONG)IntSetWindowProc( Wnd,
3870 if (!OldValue) return 0;
3873 *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
)) = NewValue
;
3880 OldValue
= (LONG
) Wnd
->ExStyle
;
3881 Style
.styleOld
= OldValue
;
3882 Style
.styleNew
= NewValue
;
3885 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3887 WindowStation
= ((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
->WindowStation
;
3890 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3891 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3894 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3895 Wnd
->ExStyle
= (DWORD
)Style
.styleNew
;
3896 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3900 OldValue
= (LONG
) Wnd
->style
;
3901 Style
.styleOld
= OldValue
;
3902 Style
.styleNew
= NewValue
;
3903 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3904 Wnd
->style
= (DWORD
)Style
.styleNew
;
3905 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3910 if ( Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3911 Wnd
->fnid
& FNID_FREED
)
3913 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3916 OldValue
= (LONG
)IntSetWindowProc(Wnd
,
3923 OldValue
= (LONG
) Wnd
->hModule
;
3924 Wnd
->hModule
= (HINSTANCE
) NewValue
;
3927 case GWL_HWNDPARENT
:
3928 Parent
= Window
->Parent
;
3929 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
3930 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
3932 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
3936 OldValue
= (LONG
) Wnd
->IDMenu
;
3937 Wnd
->IDMenu
= (UINT
) NewValue
;
3941 OldValue
= Wnd
->dwUserData
;
3942 Wnd
->dwUserData
= NewValue
;
3946 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3947 SetLastWin32Error(ERROR_INVALID_INDEX
);
3957 * NtUserSetWindowLong
3959 * The NtUserSetWindowLong function changes an attribute of the specified
3960 * window. The function also sets the 32-bit (long) value at the specified
3961 * offset into the extra window memory.
3968 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3970 DECLARE_RETURN(LONG
);
3972 DPRINT("Enter NtUserSetWindowLong\n");
3973 UserEnterExclusive();
3975 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3978 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3984 * NtUserSetWindowWord
3986 * Legacy function similar to NtUserSetWindowLong.
3993 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3995 PWINDOW_OBJECT Window
;
3997 DECLARE_RETURN(WORD
);
3999 DPRINT("Enter NtUserSetWindowWord\n");
4000 UserEnterExclusive();
4002 if (!(Window
= UserGetWindowObject(hWnd
)))
4011 case GWL_HWNDPARENT
:
4012 RETURN( co_UserSetWindowLong(Window
->hSelf
, Index
, (UINT
)NewValue
, TRUE
));
4016 SetLastWin32Error(ERROR_INVALID_INDEX
);
4021 if (Index
> Window
->Wnd
->cbwndExtra
- sizeof(WORD
))
4023 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4027 OldValue
= *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
4028 *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
)) = NewValue
;
4033 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
4042 NtUserGetWindowPlacement(HWND hWnd
,
4043 WINDOWPLACEMENT
*lpwndpl
)
4045 PWINDOW_OBJECT Window
;
4048 WINDOWPLACEMENT Safepl
;
4050 DECLARE_RETURN(BOOL
);
4052 DPRINT("Enter NtUserGetWindowPlacement\n");
4055 if (!(Window
= UserGetWindowObject(hWnd
)))
4061 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4062 if(!NT_SUCCESS(Status
))
4064 SetLastNtError(Status
);
4067 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4073 if (0 == (Wnd
->style
& WS_VISIBLE
))
4075 Safepl
.showCmd
= SW_HIDE
;
4077 else if ((0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
4078 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
4079 0 == (Wnd
->style
& WS_MINIMIZE
))
4081 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
4083 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
4085 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
4087 else if (0 != (Wnd
->style
& WS_VISIBLE
))
4089 Safepl
.showCmd
= SW_SHOWNORMAL
;
4092 Size
.x
= Wnd
->rcWindow
.left
;
4093 Size
.y
= Wnd
->rcWindow
.top
;
4094 WinPosInitInternalPos(Window
, &Size
,
4097 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
4098 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
4099 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
4101 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
4102 if(!NT_SUCCESS(Status
))
4104 SetLastNtError(Status
);
4111 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
4121 NtUserLockWindowUpdate(HWND hWnd
)
4141 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
4142 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
4143 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
4147 QueryWindow based on KJK::Hyperion and James Tabor.
4149 0 = QWUniqueProcessId
4150 1 = QWUniqueThreadId
4153 4 = QWIsHung Implements IsHungAppWindow found
4156 9 = QWKillWindow When I called this with hWnd ==
4157 DesktopWindow, it shutdown the system
4164 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
4166 PWINDOW_OBJECT Window
;
4169 DECLARE_RETURN(UINT
);
4171 DPRINT("Enter NtUserQueryWindow\n");
4174 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4183 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
4184 Result
= (DWORD
)IntGetWndProcessId(Window
);
4187 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
4188 Result
= (DWORD
)IntGetWndThreadId(Window
);
4191 case QUERY_WINDOW_ACTIVE
:
4192 Result
= (DWORD
)UserGetActiveWindow();
4195 case QUERY_WINDOW_FOCUS
:
4196 Result
= (DWORD
)IntGetFocusWindow();
4199 case QUERY_WINDOW_ISHUNG
:
4200 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
4203 case QUERY_WINDOW_REAL_ID
:
4204 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
4207 Result
= (DWORD
)NULL
;
4214 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
4224 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
4238 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4240 UNICODE_STRING SafeMessageName
;
4243 DECLARE_RETURN(UINT
);
4245 DPRINT("Enter NtUserRegisterWindowMessage\n");
4246 UserEnterExclusive();
4248 if(MessageNameUnsafe
== NULL
)
4250 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4254 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4255 if(!NT_SUCCESS(Status
))
4257 SetLastNtError(Status
);
4261 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4263 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4267 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
4277 NtUserSetImeOwnerWindow(DWORD Unknown0
,
4290 NtUserSetInternalWindowPos(
4307 NtUserSetLayeredWindowAttributes(HWND hwnd
,
4321 NtUserSetLogonNotifyWindow(HWND hWnd
)
4338 PWINDOW_OBJECT Window
;
4340 DECLARE_RETURN(BOOL
);
4342 DPRINT("Enter NtUserSetMenu\n");
4343 UserEnterExclusive();
4345 if (!(Window
= UserGetWindowObject(hWnd
)))
4350 if (! IntSetMenu(Window
, Menu
, &Changed
))
4355 if (Changed
&& Repaint
)
4357 USER_REFERENCE_ENTRY Ref
;
4359 UserRefObjectCo(Window
, &Ref
);
4360 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4361 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4363 UserDerefObjectCo(Window
);
4369 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4379 NtUserSetWindowFNID(HWND hWnd
,
4382 PWINDOW_OBJECT Window
;
4384 DECLARE_RETURN(BOOL
);
4386 DPRINT("Enter NtUserSetWindowFNID\n");
4387 UserEnterExclusive();
4389 if (!(Window
= UserGetWindowObject(hWnd
)))
4396 { // From user land we only set these.
4397 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
4402 Wnd
->pcls
->fnid
|= fnID
;
4407 DPRINT("Leave NtUserSetWindowFNID\n");
4417 NtUserSetWindowPlacement(HWND hWnd
,
4418 WINDOWPLACEMENT
*lpwndpl
)
4420 PWINDOW_OBJECT Window
;
4422 WINDOWPLACEMENT Safepl
;
4424 DECLARE_RETURN(BOOL
);
4425 USER_REFERENCE_ENTRY Ref
;
4427 DPRINT("Enter NtUserSetWindowPlacement\n");
4428 UserEnterExclusive();
4430 if (!(Window
= UserGetWindowObject(hWnd
)))
4436 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4437 if(!NT_SUCCESS(Status
))
4439 SetLastNtError(Status
);
4442 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4447 UserRefObjectCo(Window
, &Ref
);
4449 if ((Wnd
->style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4451 co_WinPosSetWindowPos(Window
, NULL
,
4452 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4453 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4454 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4455 SWP_NOZORDER
| SWP_NOACTIVATE
);
4458 /* FIXME - change window status */
4459 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
4461 Wnd
->InternalPosInitialized
= TRUE
;
4462 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4463 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4464 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4466 UserDerefObjectCo(Window
);
4470 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4482 HWND hWndInsertAfter
,
4489 DECLARE_RETURN(BOOL
);
4490 PWINDOW_OBJECT Window
;
4492 USER_REFERENCE_ENTRY Ref
;
4494 DPRINT("Enter NtUserSetWindowPos\n");
4495 UserEnterExclusive();
4497 if (!(Window
= UserGetWindowObject(hWnd
)))
4502 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
4503 if (!(uFlags
& SWP_NOMOVE
))
4505 if (X
< -32768) X
= -32768;
4506 else if (X
> 32767) X
= 32767;
4507 if (Y
< -32768) Y
= -32768;
4508 else if (Y
> 32767) Y
= 32767;
4510 if (!(uFlags
& SWP_NOSIZE
))
4513 else if (cx
> 32767) cx
= 32767;
4515 else if (cy
> 32767) cy
= 32767;
4518 UserRefObjectCo(Window
, &Ref
);
4519 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4520 UserDerefObjectCo(Window
);
4525 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4532 IntGetWindowRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
4550 /* Create a new window region using the window rectangle */
4551 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4552 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4553 /* if there's a region assigned to the window, combine them both */
4554 if(Window
->WindowRegion
&& !(Wnd
->style
& WS_MINIMIZE
))
4555 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4556 /* Copy the region into hRgn */
4557 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4559 if((pRgn
= REGION_LockRgn(hRgn
)))
4561 Ret
= pRgn
->rdh
.iType
;
4562 REGION_UnlockRgn(pRgn
);
4567 GreDeleteObject(VisRgn
);
4573 IntGetWindowRgnBox(PWINDOW_OBJECT Window
, RECTL
*Rect
)
4591 /* Create a new window region using the window rectangle */
4592 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4593 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4594 /* if there's a region assigned to the window, combine them both */
4595 if(Window
->WindowRegion
&& !(Wnd
->style
& WS_MINIMIZE
))
4596 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4598 if((pRgn
= REGION_LockRgn(VisRgn
)))
4600 Ret
= pRgn
->rdh
.iType
;
4601 *Rect
= pRgn
->rdh
.rcBound
;
4602 REGION_UnlockRgn(pRgn
);
4607 GreDeleteObject(VisRgn
);
4622 PWINDOW_OBJECT Window
;
4623 DECLARE_RETURN(INT
);
4625 DPRINT("Enter NtUserSetWindowRgn\n");
4626 UserEnterExclusive();
4628 if (!(Window
= UserGetWindowObject(hWnd
)))
4633 /* FIXME - Verify if hRgn is a valid handle!!!!
4634 Propably make this operation thread-safe, but maybe it's not necessary */
4636 if(Window
->WindowRegion
)
4638 /* Delete no longer needed region handle */
4639 GreDeleteObject(Window
->WindowRegion
);
4641 Window
->WindowRegion
= hRgn
;
4643 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4647 USER_REFERENCE_ENTRY Ref
;
4648 UserRefObjectCo(Window
, &Ref
);
4649 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4650 UserDerefObjectCo(Window
);
4656 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4666 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4668 PWINDOW_OBJECT Window
;
4670 DECLARE_RETURN(BOOL
);
4671 USER_REFERENCE_ENTRY Ref
;
4673 DPRINT("Enter NtUserShowWindow\n");
4674 UserEnterExclusive();
4676 if (!(Window
= UserGetWindowObject(hWnd
)))
4681 UserRefObjectCo(Window
, &Ref
);
4682 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4683 UserDerefObjectCo(Window
);
4688 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4698 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4704 return NtUserShowWindow(hWnd
, nCmdShow
);
4714 NtUserUpdateLayeredWindow(
4722 BLENDFUNCTION
*pblend
,
4735 NtUserWindowFromPhysicalPoint(POINT Point
)
4746 NtUserWindowFromPoint(LONG X
, LONG Y
)
4750 PWINDOW_OBJECT DesktopWindow
= NULL
, Window
= NULL
;
4751 DECLARE_RETURN(HWND
);
4752 USER_REFERENCE_ENTRY Ref
;
4754 DPRINT("Enter NtUserWindowFromPoint\n");
4755 UserEnterExclusive();
4757 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4765 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4766 //its possible this referencing is useless, thou it shouldnt hurt...
4767 UserRefObjectCo(DesktopWindow
, &Ref
);
4769 pti
= PsGetCurrentThreadWin32Thread();
4770 Hit
= co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4774 Ret
= Window
->hSelf
;
4783 if (Window
) UserDereferenceObject(Window
);
4784 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4786 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4796 * Undocumented function that is called from DefWindowProc to set
4803 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4805 PWINDOW_OBJECT Window
;
4807 LARGE_STRING SafeText
;
4808 UNICODE_STRING UnicodeString
;
4811 DPRINT("Enter NtUserDefSetText\n");
4813 if (WindowText
!= NULL
)
4817 SafeText
= ProbeForReadLargeString(WindowText
);
4819 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4822 SetLastNtError(_SEH2_GetExceptionCode());
4832 UserEnterExclusive();
4834 if(!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4841 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4842 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4843 // Now we know what the bAnsi is for.
4844 RtlInitUnicodeString(&UnicodeString
, NULL
);
4845 if (SafeText
.Buffer
)
4850 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4852 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4853 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4855 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4858 SetLastNtError(_SEH2_GetExceptionCode());
4861 if (!Ret
) goto Exit
;
4864 if (UnicodeString
.Length
!= 0)
4866 if (Wnd
->strName
.MaximumLength
> 0 &&
4867 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4869 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4871 Wnd
->strName
.Length
= UnicodeString
.Length
;
4872 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4873 RtlCopyMemory(Wnd
->strName
.Buffer
,
4874 UnicodeString
.Buffer
,
4875 UnicodeString
.Length
);
4880 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4881 buf
= Wnd
->strName
.Buffer
;
4882 Wnd
->strName
.Buffer
= NULL
;
4885 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4888 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4889 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4890 if (Wnd
->strName
.Buffer
!= NULL
)
4892 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4893 RtlCopyMemory(Wnd
->strName
.Buffer
,
4894 UnicodeString
.Buffer
,
4895 UnicodeString
.Length
);
4896 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4897 Wnd
->strName
.Length
= UnicodeString
.Length
;
4901 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4909 Wnd
->strName
.Length
= 0;
4910 if (Wnd
->strName
.Buffer
!= NULL
)
4911 Wnd
->strName
.Buffer
[0] = L
'\0';
4914 // HAX! FIXME! Windows does not do this in here!
4915 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4916 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4917 /* Send shell notifications */
4918 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
4920 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4925 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4926 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4932 * NtUserInternalGetWindowText
4939 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4941 PWINDOW_OBJECT Window
;
4945 DECLARE_RETURN(INT
);
4947 DPRINT("Enter NtUserInternalGetWindowText\n");
4950 if(lpString
&& (nMaxCount
<= 1))
4952 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4956 if(!(Window
= UserGetWindowObject(hWnd
)))
4962 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4965 const WCHAR Terminator
= L
'\0';
4967 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4969 Copy
= min(nMaxCount
- 1, Result
);
4972 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4973 if(!NT_SUCCESS(Status
))
4975 SetLastNtError(Status
);
4981 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4982 if(!NT_SUCCESS(Status
))
4984 SetLastNtError(Status
);
4994 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
5002 IntShowOwnedPopups(PWINDOW_OBJECT OwnerWnd
, BOOL fShow
)
5005 PWINDOW_OBJECT pWnd
;
5008 // ASSERT(OwnerWnd);
5010 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
5015 while (win_array
[count
])
5017 while (--count
>= 0)
5019 if (UserGetWindow( win_array
[count
], GW_OWNER
) != OwnerWnd
->hSelf
)
5021 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
5023 // if (pWnd == WND_OTHER_PROCESS) continue;
5027 if (pWnd
->Wnd
->state
& WNDS_HIDDENPOPUP
)
5029 /* In Windows, ShowOwnedPopups(TRUE) generates
5030 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
5031 * regardless of the state of the owner
5033 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
5039 if (pWnd
->Wnd
->style
& WS_VISIBLE
)
5041 /* In Windows, ShowOwnedPopups(FALSE) generates
5042 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
5043 * regardless of the state of the owner
5045 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
5051 ExFreePool( win_array
);
5056 * NtUserValidateHandleSecure
5064 NtUserValidateHandleSecure(
5072 PUSER_HANDLE_ENTRY entry
;
5073 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
5075 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5078 uType
= entry
->type
;
5084 PWINDOW_OBJECT Window
;
5085 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
5091 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
5096 PACCELERATOR_TABLE Accel
;
5097 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
5102 PCURICON_OBJECT Cursor
;
5103 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
5109 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
5114 PMONITOR_OBJECT Monitor
;
5115 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
5121 return UserGetCallProcInfo( handle
, &Proc
);
5124 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5128 { /* Is handle entry restricted? */