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 (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
670 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
671 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
675 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
676 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
679 // Now set the new window proc.
680 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
685 // Move this to user space!
687 IntGetWindowInfo(PWINDOW_OBJECT Window
, PWINDOWINFO pwi
)
689 PWND Wnd
= Window
->Wnd
;
691 pwi
->cbSize
= sizeof(WINDOWINFO
);
692 pwi
->rcWindow
= Window
->Wnd
->rcWindow
;
693 pwi
->rcClient
= Window
->Wnd
->rcClient
;
694 pwi
->dwStyle
= Wnd
->style
;
695 pwi
->dwExStyle
= Wnd
->ExStyle
;
696 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Window
->hSelf
); /* WS_ACTIVECAPTION */
697 IntGetWindowBorderMeasures(Window
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
698 pwi
->atomWindowType
= (Wnd
->pcls
? Wnd
->pcls
->atomClassName
: 0);
699 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
705 PWINDOW_OBJECT Window
,
709 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
710 PWND Wnd
= Window
->Wnd
;
712 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
714 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
718 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
726 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
727 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Window
->hSelf
);
736 NewMenu
= IntGetMenuObject(Menu
);
741 IntReleaseMenuObject(OldMenu
);
743 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
746 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
748 /* Can't use the same menu for two windows */
751 IntReleaseMenuObject(OldMenu
);
753 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
759 Wnd
->IDMenu
= (UINT
) Menu
;
762 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
763 IntReleaseMenuObject(NewMenu
);
767 OldMenu
->MenuInfo
.Wnd
= NULL
;
768 IntReleaseMenuObject(OldMenu
);
775 /* INTERNAL ******************************************************************/
779 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
784 USER_REFERENCE_ENTRY Ref
;
785 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
787 while (!IsListEmpty(&WThread
->WindowListHead
))
789 Current
= WThread
->WindowListHead
.Flink
;
790 Wnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
792 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
794 /* window removes itself from the list */
797 fixme: it is critical that the window removes itself! if now, we will loop
801 //ASSERT(co_UserDestroyWindow(Wnd));
803 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
804 if (!co_UserDestroyWindow(Wnd
))
806 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
808 UserDerefObjectCo(Wnd
);//faxme: temp hack??
816 * Returns client window rectangle relative to the upper-left corner of client area.
818 * \note Does not check the validity of the parameters
821 IntGetClientRect(PWINDOW_OBJECT Window
, RECTL
*Rect
)
826 Rect
->left
= Rect
->top
= 0;
827 Rect
->right
= Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
;
828 Rect
->bottom
= Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
;
834 IntGetFocusWindow(VOID
)
836 PUSER_MESSAGE_QUEUE Queue
;
837 PDESKTOP pdo
= IntGetActiveDesktop();
842 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
847 return(Queue
->FocusWindow
);
851 PMENU_OBJECT FASTCALL
852 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
)
854 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
855 PTHREADINFO W32Thread
;
856 HMENU hNewMenu
, hSysMenu
;
857 ROSMENUITEMINFO ItemInfo
;
861 W32Thread
= PsGetCurrentThreadWin32Thread();
863 if(!W32Thread
->Desktop
)
866 if(Window
->SystemMenu
)
868 Menu
= UserGetMenuObject(Window
->SystemMenu
);
871 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
872 Window
->SystemMenu
= (HMENU
)0;
876 if(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
)
878 /* clone system menu */
879 Menu
= UserGetMenuObject(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
);
883 NewMenu
= IntCloneMenu(Menu
);
886 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
887 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
888 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
890 //IntReleaseMenuObject(NewMenu);
895 hSysMenu
= UserCreateMenu(FALSE
);
896 if (NULL
== hSysMenu
)
900 SysMenu
= IntGetMenuObject(hSysMenu
);
903 UserDestroyMenu(hSysMenu
);
906 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
907 SysMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
908 hNewMenu
= co_IntLoadSysMenuTemplate();
911 IntReleaseMenuObject(SysMenu
);
912 UserDestroyMenu(hSysMenu
);
915 Menu
= IntGetMenuObject(hNewMenu
);
918 IntReleaseMenuObject(SysMenu
);
919 UserDestroyMenu(hSysMenu
);
923 NewMenu
= IntCloneMenu(Menu
);
926 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
927 IntReleaseMenuObject(NewMenu
);
928 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
930 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
931 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
932 ItemInfo
.fType
= MF_POPUP
;
933 ItemInfo
.fState
= MFS_ENABLED
;
934 ItemInfo
.dwTypeData
= NULL
;
936 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
937 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
939 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
943 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
952 if(Window
->SystemMenu
)
953 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
961 IntIsChildWindow(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT BaseWindow
)
963 PWINDOW_OBJECT Window
;
970 if (Window
== Parent
)
974 if(!(Wnd
->style
& WS_CHILD
))
979 Window
= Window
->Parent
;
986 IntIsWindowVisible(PWINDOW_OBJECT BaseWindow
)
988 PWINDOW_OBJECT Window
;
995 if(!(Wnd
->style
& WS_CHILD
))
999 if(!(Wnd
->style
& WS_VISIBLE
))
1004 Window
= Window
->Parent
;
1007 if(Window
&& Wnd
->style
& WS_VISIBLE
)
1016 /* link the window into siblings and parent. children are kept in place. */
1020 PWINDOW_OBJECT WndParent
,
1021 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
1024 PWINDOW_OBJECT Parent
;
1026 Wnd
->Parent
= WndParent
;
1027 Wnd
->Wnd
->spwndParent
= WndParent
? WndParent
->Wnd
: NULL
;
1028 if ((Wnd
->PrevSibling
= WndPrevSibling
))
1030 /* link after WndPrevSibling */
1031 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
1032 Wnd
->NextSibling
->PrevSibling
= Wnd
;
1033 else if ((Parent
= Wnd
->Parent
))
1035 if(Parent
->LastChild
== WndPrevSibling
)
1036 Parent
->LastChild
= Wnd
;
1038 Wnd
->PrevSibling
->NextSibling
= Wnd
;
1043 Parent
= Wnd
->Parent
;
1044 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
1045 Wnd
->NextSibling
->PrevSibling
= Wnd
;
1048 Parent
->LastChild
= Wnd
;
1049 Parent
->FirstChild
= Wnd
;
1054 Parent
->FirstChild
= Wnd
;
1061 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1063 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
1066 Wnd
= IntGetWindowObject(hWnd
);
1070 WndOldOwner
= IntGetWindowObject(Wnd
->hOwner
);
1073 ret
= WndOldOwner
->hSelf
;
1074 UserDereferenceObject(WndOldOwner
);
1081 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1083 Wnd
->hOwner
= hWndNewOwner
;
1084 Wnd
->Wnd
->spwndOwner
= WndNewOwner
->Wnd
;
1089 Wnd
->Wnd
->spwndOwner
= NULL
;
1092 UserDereferenceObject(Wnd
);
1096 PWINDOW_OBJECT FASTCALL
1097 co_IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
1099 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
1100 // HWND hWnd, hWndNewParent;
1104 ASSERT(WndNewParent
);
1105 ASSERT_REFS_CO(Wnd
);
1106 ASSERT_REFS_CO(WndNewParent
);
1108 // hWnd = Wnd->hSelf;
1109 // hWndNewParent = WndNewParent->hSelf;
1111 /* Some applications try to set a child as a parent */
1112 if (IntIsChildWindow(Wnd
, WndNewParent
))
1114 SetLastWin32Error( ERROR_INVALID_PARAMETER
);
1119 * Windows hides the window first, then shows it again
1120 * including the WM_SHOWWINDOW messages and all
1122 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1124 // /* Validate that window and parent still exist */
1125 // if (!IntIsWindow(hWnd) || !IntIsWindow(hWndNewParent))
1128 /* Window must belong to current process */
1129 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
1132 WndOldParent
= Wnd
->Parent
;
1134 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1136 if (WndNewParent
!= WndOldParent
)
1138 IntUnlinkWindow(Wnd
);
1140 if (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1142 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
1143 Sibling
= WndNewParent
->FirstChild
;
1144 while (NULL
!= Sibling
&& 0 != (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1146 InsertAfter
= Sibling
;
1147 Sibling
= Sibling
->NextSibling
;
1150 if (NULL
== InsertAfter
)
1152 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1156 // UserReferenceObject(InsertAfter);
1157 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1158 // UserDereferenceObject(InsertAfter);
1163 * SetParent additionally needs to make hwnd the top window
1164 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1165 * WM_WINDOWPOSCHANGED notification messages.
1167 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1168 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1169 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1172 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1173 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1177 * Validate that the old parent still exist, since it migth have been
1178 * destroyed during the last callbacks to user-mode
1182 // if(!IntIsWindow(WndOldParent->hSelf))
1184 // UserDereferenceObject(WndOldParent);
1188 /* don't dereference the window object here, it must be done by the caller
1189 of IntSetParent() */
1190 // return WndOldParent;
1193 return WndOldParent
;//NULL;
1197 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
1199 PMENU_OBJECT OldMenu
;
1200 if(Window
->SystemMenu
)
1202 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1205 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1206 IntReleaseMenuObject(OldMenu
);
1212 /* FIXME check window style, propably return FALSE ? */
1213 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1214 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1217 Window
->SystemMenu
= (HMENU
)0;
1223 /* unlink the window from siblings and parent. children are kept in place. */
1225 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1227 PWINDOW_OBJECT WndParent
= Wnd
->Parent
;
1229 if (Wnd
->NextSibling
)
1230 Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1231 else if (WndParent
&& WndParent
->LastChild
== Wnd
)
1232 WndParent
->LastChild
= Wnd
->PrevSibling
;
1234 if (Wnd
->PrevSibling
)
1235 Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1236 else if (WndParent
&& WndParent
->FirstChild
== Wnd
)
1237 WndParent
->FirstChild
= Wnd
->NextSibling
;
1239 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1241 Wnd
->Wnd
->spwndParent
= NULL
;
1247 PWINDOW_OBJECT Window
, Child
;
1249 if(!(Window
= UserGetWindowObject(IntGetDesktopWindow())))
1254 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1256 if(Child
->hOwner
&& Child
->Wnd
->style
& WS_VISIBLE
)
1259 * The desktop has a popup window if one of them has
1260 * an owner window and is visible
1270 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1272 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1278 IntGetWindowPlacement(PWINDOW_OBJECT Window
, WINDOWPLACEMENT
*lpwndpl
)
1284 if (!Wnd
) return FALSE
;
1286 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1292 if (0 == (Wnd
->style
& WS_VISIBLE
))
1294 lpwndpl
->showCmd
= SW_HIDE
;
1296 else if (0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
1297 0 != (Wnd
->style
& WS_MAXIMIZE
))
1299 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1301 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1303 lpwndpl
->showCmd
= SW_MINIMIZE
;
1305 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1307 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1310 Size
.x
= Wnd
->rcWindow
.left
;
1311 Size
.y
= Wnd
->rcWindow
.top
;
1312 WinPosInitInternalPos(Window
, &Size
,
1315 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1316 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1317 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1323 /* FUNCTIONS *****************************************************************/
1329 NtUserAlterWindowStyle(DWORD Unknown0
,
1339 * As best as I can figure, this function is used by EnumWindows,
1340 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1342 * It's supposed to build a list of HWNDs to return to the caller.
1343 * We can figure out what kind of list by what parameters are
1351 NtUserBuildHwndList(
1364 return ERROR_INVALID_PARAMETER
;
1366 if (hwndParent
|| !dwThreadId
)
1369 PWINDOW_OBJECT Parent
, Window
;
1373 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1375 return ERROR_INVALID_HANDLE
;
1380 Status
= IntValidateDesktopHandle(hDesktop
,
1384 if(!NT_SUCCESS(Status
))
1386 return ERROR_INVALID_HANDLE
;
1389 hwndParent
= Desktop
->DesktopWindow
;
1396 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1397 (Window
= Parent
->FirstChild
))
1399 BOOL bGoDown
= TRUE
;
1401 Status
= STATUS_SUCCESS
;
1406 if(dwCount
++ < *pBufSize
&& pWnd
)
1410 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1411 *pWnd
= Window
->hSelf
;
1414 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1416 Status
= _SEH2_GetExceptionCode();
1419 if(!NT_SUCCESS(Status
))
1421 SetLastNtError(Status
);
1425 if (Window
->FirstChild
&& bChildren
)
1427 Window
= Window
->FirstChild
;
1432 if (Window
->NextSibling
)
1434 Window
= Window
->NextSibling
;
1438 Window
= Window
->Parent
;
1439 if (Window
== Parent
)
1448 ObDereferenceObject(Desktop
);
1454 PTHREADINFO W32Thread
;
1455 PLIST_ENTRY Current
;
1456 PWINDOW_OBJECT Window
;
1458 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1459 if(!NT_SUCCESS(Status
))
1461 return ERROR_INVALID_PARAMETER
;
1463 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1465 ObDereferenceObject(Thread
);
1466 DPRINT("Thread is not a GUI Thread!\n");
1467 return ERROR_INVALID_PARAMETER
;
1470 Current
= W32Thread
->WindowListHead
.Flink
;
1471 while(Current
!= &(W32Thread
->WindowListHead
))
1473 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1476 if(bChildren
|| Window
->hOwner
!= NULL
)
1478 if(dwCount
< *pBufSize
&& pWnd
)
1480 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1481 if(!NT_SUCCESS(Status
))
1483 SetLastNtError(Status
);
1489 Current
= Current
->Flink
;
1492 ObDereferenceObject(Thread
);
1495 *pBufSize
= dwCount
;
1496 return STATUS_SUCCESS
;
1504 NtUserChildWindowFromPointEx(HWND hwndParent
,
1509 PWINDOW_OBJECT Parent
;
1514 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1522 if(Parent
->hSelf
!= IntGetDesktopWindow())
1524 Pt
.x
+= Parent
->Wnd
->rcClient
.left
;
1525 Pt
.y
+= Parent
->Wnd
->rcClient
.top
;
1528 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1533 Ret
= Parent
->hSelf
;
1534 if((List
= IntWinListChildren(Parent
)))
1536 for(phWnd
= List
; *phWnd
; phWnd
++)
1538 PWINDOW_OBJECT Child
;
1540 if((Child
= UserGetWindowObject(*phWnd
)))
1542 ChildWnd
= Child
->Wnd
;
1543 if(!(ChildWnd
->style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1547 if((ChildWnd
->style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1551 if((ChildWnd
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1555 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1570 * calculates the default position of a window
1573 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT Window
, RECTL
*rc
, BOOL IncPos
)
1580 RECTL_bIntersectRect(rc
, rc
, &Parent
->Wnd
->rcClient
);
1584 Pos
.x
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1585 Pos
.y
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1586 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1587 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1589 /* reset counter and position */
1592 Parent
->TiledCounter
= 0;
1594 Parent
->TiledCounter
++;
1605 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1606 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1610 rc
->right
= rc
->left
+ Sz
.cx
;
1611 rc
->bottom
= rc
->top
+ Sz
.cy
;
1620 co_IntCreateWindowEx(DWORD dwExStyle
,
1621 PUNICODE_STRING ClassName
,
1622 PUNICODE_STRING WindowName
,
1630 HINSTANCE hInstance
,
1633 BOOL bUnicodeWindow
)
1635 PWINSTATION_OBJECT WinSta
;
1637 PCLS
*ClassLink
, Class
= NULL
;
1639 PWINDOW_OBJECT Window
= NULL
;
1640 PWINDOW_OBJECT ParentWindow
= NULL
, OwnerWindow
;
1641 HWND ParentWindowHandle
= NULL
;
1642 HWND OwnerWindowHandle
;
1643 PMENU_OBJECT SystemMenu
;
1647 PTHREADINFO ti
= NULL
;
1650 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1656 CBT_CREATEWNDW CbtCreate
;
1659 DECLARE_RETURN(PWND
);
1661 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1664 pti
= PsGetCurrentThreadWin32Thread();
1668 ParentWindowHandle
= pti
->Desktop
->DesktopWindow
;
1672 if ( !(pti
->ppi
->W32PF_flags
& W32PF_CLASSESREGISTERED
))
1674 UserRegisterSystemClasses();
1677 OwnerWindowHandle
= NULL
;
1679 DPRINT("co_IntCreateWindowEx %wZ\n", ClassName
);
1681 if (hWndParent
== HWND_MESSAGE
)
1684 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1685 * message window (style: WS_POPUP|WS_DISABLED)
1687 ParentWindowHandle
= IntGetMessageWindow();
1688 DPRINT("Parent is HWND_MESSAGE 0x%x\n", ParentWindowHandle
);
1690 else if (hWndParent
)
1692 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1694 PWINDOW_OBJECT Par
= UserGetWindowObject(hWndParent
), Root
;
1695 if (Par
&& (Root
= UserGetAncestor(Par
, GA_ROOT
)))
1696 OwnerWindowHandle
= Root
->hSelf
;
1699 ParentWindowHandle
= hWndParent
;
1701 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1703 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1704 RETURN( (PWND
)0); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1707 if (ParentWindowHandle
)
1709 ParentWindow
= UserGetWindowObject(ParentWindowHandle
);
1711 if (ParentWindow
) UserRefObjectCo(ParentWindow
, &ParentRef
);
1715 ParentWindow
= NULL
;
1718 /* FIXME: parent must belong to the current process */
1720 /* Check the window station. */
1721 ti
= GetW32ThreadInfo();
1722 if (ti
== NULL
|| pti
->Desktop
== NULL
)
1724 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1728 /* Check the class. */
1730 DPRINT("Class %wZ\n", ClassName
);
1732 ClassAtom
= IntGetClassAtom(ClassName
,
1738 if (ClassAtom
== (RTL_ATOM
)0)
1740 if (IS_ATOM(ClassName
->Buffer
))
1742 DPRINT1("Class 0x%p not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1746 DPRINT1("Class \"%wZ\" not found\n", ClassName
);
1749 SetLastWin32Error(ERROR_CANNOT_FIND_WND_CLASS
);
1752 DPRINT("ClassAtom %x\n", ClassAtom
);
1753 Class
= IntReferenceClass(Class
,
1758 DPRINT1("Failed to reference window class!\n");
1762 WinSta
= pti
->Desktop
->WindowStation
;
1764 //FIXME: Reference thread/desktop instead
1765 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1767 /* Create the window object. */
1768 Window
= (PWINDOW_OBJECT
) UserCreateObject( gHandleTable
,
1771 sizeof(WINDOW_OBJECT
));
1774 Window
->Wnd
= DesktopHeapAlloc(pti
->Desktop
,
1775 sizeof(WND
) + Class
->cbwndExtra
);
1778 RtlZeroMemory(Window
->Wnd
,
1779 sizeof(WND
) + Class
->cbwndExtra
);
1780 Window
->Wnd
->head
.h
= hWnd
;
1785 Wnd
->head
.rpdesk
= pti
->Desktop
;
1786 Wnd
->hWndLastActive
= hWnd
;
1787 Wnd
->state2
|= WNDS2_WIN40COMPAT
;
1790 DPRINT("Created object with handle %X\n", hWnd
);
1794 ObDereferenceObject(WinSta
);
1795 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1799 UserRefObjectCo(Window
, &Ref
);
1801 ObDereferenceObject(WinSta
);
1803 if (NULL
== pti
->Desktop
->DesktopWindow
)
1805 /* If there is no desktop window yet, we must be creating it */
1806 pti
->Desktop
->DesktopWindow
= hWnd
;
1807 pti
->Desktop
->DesktopInfo
->Wnd
= Wnd
;
1811 * Fill out the structure describing it.
1817 Window
->SystemMenu
= (HMENU
)0;
1819 Wnd
->hModule
= hInstance
;
1820 Window
->hSelf
= hWnd
;
1822 Window
->MessageQueue
= pti
->MessageQueue
;
1823 IntReferenceMessageQueue(Window
->MessageQueue
);
1824 Window
->Parent
= ParentWindow
;
1825 Wnd
->spwndParent
= ParentWindow
? ParentWindow
->Wnd
: NULL
;
1826 if (Wnd
->spwndParent
!= NULL
&& hWndParent
!= 0)
1828 Wnd
->HideFocus
= Wnd
->spwndParent
->HideFocus
;
1829 Wnd
->HideAccel
= Wnd
->spwndParent
->HideAccel
;
1832 if((OwnerWindow
= UserGetWindowObject(OwnerWindowHandle
)))
1834 Window
->hOwner
= OwnerWindowHandle
;
1835 Wnd
->spwndOwner
= OwnerWindow
->Wnd
;
1840 Window
->hOwner
= NULL
;
1841 Wnd
->spwndOwner
= NULL
;
1845 Wnd
->dwUserData
= 0;
1847 if (Wnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1848 Wnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1850 /* BugBoy Comments: Comment below say that System classes are always created
1851 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1852 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1854 No where can I see in code or through testing does the window change back
1855 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1856 see what problems this would cause.*/
1858 // Set WndProc from Class.
1859 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
1861 // GetWindowProc, test for non server side default classes and set WndProc.
1862 if ( Wnd
->pcls
->fnid
<= FNID_GHOST
&& Wnd
->pcls
->fnid
>= FNID_BUTTON
)
1866 if (GETPFNCLIENTA(Wnd
->pcls
->fnid
) == Wnd
->lpfnWndProc
)
1867 Wnd
->lpfnWndProc
= GETPFNCLIENTW(Wnd
->pcls
->fnid
);
1871 if (GETPFNCLIENTW(Wnd
->pcls
->fnid
) == Wnd
->lpfnWndProc
)
1872 Wnd
->lpfnWndProc
= GETPFNCLIENTA(Wnd
->pcls
->fnid
);
1876 // If not an Unicode caller, set Ansi creator bit.
1877 if (!bUnicodeWindow
) Wnd
->state
|= WNDS_ANSICREATOR
;
1879 // Clone Class Ansi/Unicode proc type.
1880 if (Wnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1882 Wnd
->state
|= WNDS_ANSIWINDOWPROC
;
1883 Wnd
->Unicode
= FALSE
;
1887 It seems there can be both an Ansi creator and Unicode Class Window
1888 WndProc, unless the following overriding conditions occur:
1890 if ( !bUnicodeWindow
&&
1891 ( ClassAtom
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1892 ClassAtom
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1893 ClassAtom
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1894 ClassAtom
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1895 ClassAtom
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1896 ClassAtom
== gpsi
->atomSysClass
[ICLS_IME
] ||
1897 ClassAtom
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1898 ClassAtom
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1899 ClassAtom
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1900 { // Override Class and set the window Ansi WndProc.
1901 Wnd
->state
|= WNDS_ANSIWINDOWPROC
;
1902 Wnd
->Unicode
= FALSE
;
1905 { // Set the window Unicode WndProc.
1906 Wnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1907 Wnd
->Unicode
= TRUE
;
1911 Window
->OwnerThread
= PsGetCurrentThread();
1912 Window
->FirstChild
= NULL
;
1913 Window
->LastChild
= NULL
;
1914 Window
->PrevSibling
= NULL
;
1915 Window
->NextSibling
= NULL
;
1916 Wnd
->cbwndExtra
= Wnd
->pcls
->cbwndExtra
;
1918 InitializeListHead(&Wnd
->PropListHead
);
1919 InitializeListHead(&Window
->WndObjListHead
);
1921 if ( NULL
!= WindowName
->Buffer
&& WindowName
->Length
> 0 )
1923 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
1924 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1925 if (Wnd
->strName
.Buffer
== NULL
)
1927 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1931 Wnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1934 RtlCopyMemory(Wnd
->strName
.Buffer
,
1936 WindowName
->Length
);
1937 Wnd
->strName
.Length
= WindowName
->Length
;
1939 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1941 WindowName
->Length
= 0;
1942 Wnd
->strName
.Buffer
[0] = L
'\0';
1948 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1949 * tested for WS_POPUP
1951 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1952 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1953 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1954 dwExStyle
|= WS_EX_WINDOWEDGE
;
1956 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1958 /* Correct the window style. */
1959 if (!(dwStyle
& WS_CHILD
))
1961 dwStyle
|= WS_CLIPSIBLINGS
;
1962 DPRINT("3: Style is now %lx\n", dwStyle
);
1963 if (!(dwStyle
& WS_POPUP
))
1965 dwStyle
|= WS_CAPTION
;
1966 Window
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1967 DPRINT("4: Style is now %lx\n", dwStyle
);
1971 /* create system menu */
1972 if((dwStyle
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1974 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
1977 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1978 IntReleaseMenuObject(SystemMenu
);
1982 /* Set the window menu */
1983 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1986 IntSetMenu(Window
, hMenu
, &MenuChanged
);
1987 else if (Wnd
->pcls
->lpszMenuName
) // Take it from the parent.
1989 UNICODE_STRING MenuName
;
1990 if (IS_INTRESOURCE(Wnd
->pcls
->lpszMenuName
))
1992 MenuName
.Length
= 0;
1993 MenuName
.MaximumLength
= 0;
1994 MenuName
.Buffer
= Wnd
->pcls
->lpszMenuName
;
1998 RtlInitUnicodeString( &MenuName
, Wnd
->pcls
->lpszMenuName
);
2000 hMenu
= co_IntCallLoadMenu( Wnd
->pcls
->hModule
, &MenuName
);
2001 if (hMenu
) IntSetMenu(Window
, hMenu
, &MenuChanged
);
2005 Wnd
->IDMenu
= (UINT
) hMenu
;
2007 /* Insert the window into the thread's window list. */
2008 InsertTailList (&pti
->WindowListHead
, &Window
->ThreadListEntry
);
2010 /* Handle "CS_CLASSDC", it is tested first. */
2011 if ((Wnd
->pcls
->style
& CS_CLASSDC
) && !(Wnd
->pcls
->pdce
)) // One DCE per class to have CLASS.
2012 Wnd
->pcls
->pdce
= DceAllocDCE(Window
, DCE_CLASS_DC
);
2013 /* Allocate a DCE for this window. */
2014 else if ( Wnd
->pcls
->style
& CS_OWNDC
)
2015 Window
->Dce
= DceAllocDCE(Window
, DCE_WINDOW_DC
);
2022 Wnd
->ExStyle
= dwExStyle
;
2023 Wnd
->style
= dwStyle
& ~WS_VISIBLE
;
2026 Cs
.lpCreateParams
= lpParam
;
2027 Cs
.hInstance
= hInstance
;
2029 Cs
.hwndParent
= hWndParent
; //Pass the original Parent handle!
2034 Cs
.style
= Wnd
->style
;
2035 // Cs.lpszName = (LPCWSTR) WindowName->Buffer;
2036 // Cs.lpszClass = (LPCWSTR) ClassName->Buffer;
2037 Cs
.lpszName
= (LPCWSTR
) WindowName
;
2038 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
2039 Cs
.dwExStyle
= dwExStyle
;
2040 CbtCreate
.lpcs
= &Cs
;
2041 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
2042 if (ISITHOOKED(WH_CBT
))
2044 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) &CbtCreate
))
2046 /* FIXME - Delete window object and remove it from the thread windows list */
2047 /* FIXME - delete allocated DCE */
2048 DPRINT1("CBT-hook returned !0\n");
2049 RETURN( (PWND
) NULL
);
2056 // FIXME: Need to set the Z order in the window link list if the hook callback changed it!
2057 // hwndInsertAfter = CbtCreate.hwndInsertAfter;
2059 /* default positioning for overlapped windows */
2060 if(!(Wnd
->style
& (WS_POPUP
| WS_CHILD
)))
2063 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
2064 BOOL CalculatedDefPosSize
= FALSE
;
2066 IntGetDesktopWorkArea(((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
, &WorkArea
);
2069 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
2071 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
2073 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, Window
, &rc
, TRUE
);
2075 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
2077 ProcessParams
->WindowFlags
&= ~STARTF_USEPOSITION
;
2078 Pos
.x
= WorkArea
.left
+ ProcessParams
->StartingX
;
2079 Pos
.y
= WorkArea
.top
+ ProcessParams
->StartingY
;
2088 According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
2089 y is something else. and Quote!
2092 /* Never believe Microsoft's documentation... CreateWindowEx doc says
2093 * that if an overlapped window is created with WS_VISIBLE style bit
2094 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
2095 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
2098 * 1) not only it checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
2099 * 2) it does not ignore the y parameter as the docs claim; instead, it
2100 * uses it as second parameter to ShowWindow() unless y is either
2101 * CW_USEDEFAULT or CW_USEDEFAULT16.
2103 * The fact that we didn't do 2) caused bogus windows pop up when wine
2104 * was running apps that were using this obscure feature. Example -
2105 * calc.exe that comes with Win98 (only Win98, it's different from
2106 * the one that comes with Win95 and NT)
2108 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
2113 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
2115 if(!CalculatedDefPosSize
)
2117 IntCalcDefPosSize(ParentWindow
, Window
, &rc
, FALSE
);
2119 if(ProcessParams
->WindowFlags
& STARTF_USESIZE
)
2121 ProcessParams
->WindowFlags
&= ~STARTF_USESIZE
;
2122 Size
.cx
= ProcessParams
->CountX
;
2123 Size
.cy
= ProcessParams
->CountY
;
2127 Size
.cx
= rc
.right
- rc
.left
;
2128 Size
.cy
= rc
.bottom
- rc
.top
;
2131 /* move the window if necessary */
2133 Pos
.x
= max(rc
.left
, 0);
2135 Pos
.y
= max(rc
.top
, 0);
2140 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
2141 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
2146 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
2153 /* Initialize the window dimensions. */
2154 Wnd
->rcWindow
.left
= Pos
.x
;
2155 Wnd
->rcWindow
.top
= Pos
.y
;
2156 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
2157 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
2158 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2160 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2161 ParentWindow
->Wnd
->rcClient
.top
);
2163 Wnd
->rcClient
= Wnd
->rcWindow
;
2166 * Get the size and position of the window.
2168 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
2170 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2172 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
2173 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
,
2175 if (MaxSize
.x
< Size
.cx
)
2176 Size
.cx
= MaxSize
.x
;
2177 if (MaxSize
.y
< Size
.cy
)
2178 Size
.cy
= MaxSize
.y
;
2179 if (Size
.cx
< MinTrack
.x
)
2180 Size
.cx
= MinTrack
.x
;
2181 if (Size
.cy
< MinTrack
.y
)
2182 Size
.cy
= MinTrack
.y
;
2189 Wnd
->rcWindow
.left
= Pos
.x
;
2190 Wnd
->rcWindow
.top
= Pos
.y
;
2191 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
2192 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
2193 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2195 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2196 ParentWindow
->Wnd
->rcClient
.top
);
2198 Wnd
->rcClient
= Wnd
->rcWindow
;
2200 /* FIXME: Initialize the window menu. */
2202 /* Send a NCCREATE message. */
2208 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
2209 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, Size
.cx
, Size
.cy
);
2210 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
2211 Result
= co_IntSendMessage(Window
->hSelf
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
2214 /* FIXME: Cleanup. */
2215 DPRINT1("IntCreateWindowEx(): NCCREATE message failed. No cleanup performed!\n");
2219 /* Calculate the non-client size. */
2220 MaxPos
.x
= Window
->Wnd
->rcWindow
.left
;
2221 MaxPos
.y
= Window
->Wnd
->rcWindow
.top
;
2224 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
2225 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
2226 Result
= co_WinPosGetNonClientSize(Window
,
2227 &Window
->Wnd
->rcWindow
,
2228 &Window
->Wnd
->rcClient
);
2230 RECTL_vOffsetRect(&Window
->Wnd
->rcWindow
,
2231 MaxPos
.x
- Window
->Wnd
->rcWindow
.left
,
2232 MaxPos
.y
- Window
->Wnd
->rcWindow
.top
);
2235 if (NULL
!= ParentWindow
)
2237 /* link the window into the parent's child list */
2238 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2240 PWINDOW_OBJECT PrevSibling
;
2242 PrevSibling
= ParentWindow
->LastChild
;
2244 /* link window as bottom sibling */
2245 IntLinkWindow(Window
, ParentWindow
, PrevSibling
/*prev sibling*/);
2249 /* link window as top sibling (but after topmost siblings) */
2250 PWINDOW_OBJECT InsertAfter
, Sibling
;
2251 if (!(dwExStyle
& WS_EX_TOPMOST
))
2254 Sibling
= ParentWindow
->FirstChild
;
2255 while (Sibling
&& (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
2257 InsertAfter
= Sibling
;
2258 Sibling
= Sibling
->NextSibling
;
2266 IntLinkWindow(Window
, ParentWindow
, InsertAfter
/* prev sibling */);
2271 /* Send the WM_CREATE message. */
2272 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
2273 Result
= co_IntSendMessage(Window
->hSelf
, WM_CREATE
, 0, (LPARAM
) &Cs
);
2275 if (Result
== (LRESULT
)-1)
2277 /* FIXME: Cleanup. */
2278 DPRINT1("IntCreateWindowEx(): send CREATE message failed. No cleanup performed!\n");
2279 IntUnlinkWindow(Window
);
2283 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
->Wnd
, OBJID_WINDOW
, 0);
2285 /* Send move and size messages. */
2286 if (!(Window
->Flags
& WINDOWOBJECT_NEED_SIZE
))
2290 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
2292 if ((Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
) < 0 ||
2293 (Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
) < 0)
2295 DPRINT("Sending bogus WM_SIZE\n");
2298 lParam
= MAKE_LONG(Window
->Wnd
->rcClient
.right
-
2299 Window
->Wnd
->rcClient
.left
,
2300 Window
->Wnd
->rcClient
.bottom
-
2301 Window
->Wnd
->rcClient
.top
);
2302 co_IntSendMessage(Window
->hSelf
, WM_SIZE
, SIZE_RESTORED
,
2305 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
2307 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2309 lParam
= MAKE_LONG(Wnd
->rcClient
.left
- ParentWindow
->Wnd
->rcClient
.left
,
2310 Wnd
->rcClient
.top
- ParentWindow
->Wnd
->rcClient
.top
);
2314 lParam
= MAKE_LONG(Wnd
->rcClient
.left
,
2318 co_IntSendMessage(Window
->hSelf
, WM_MOVE
, 0, lParam
);
2320 /* Call WNDOBJ change procs */
2321 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
2324 /* Show or maybe minimize or maximize the window. */
2325 if (Wnd
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2330 SwFlag
= (Wnd
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
2333 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2335 SwFlag
= ((Wnd
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2336 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2337 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2339 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
2340 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
2341 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2342 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2345 /* Notify the parent window of a new child. */
2346 if ((Wnd
->style
& WS_CHILD
) &&
2347 (!(Wnd
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
2349 DPRINT("IntCreateWindow(): About to notify parent\n");
2350 co_IntSendMessage(ParentWindow
->hSelf
,
2352 MAKEWPARAM(WM_CREATE
, Wnd
->IDMenu
),
2353 (LPARAM
)Window
->hSelf
);
2356 if ((!hWndParent
) && (!HasOwner
))
2358 DPRINT("Sending CREATED notify\n");
2359 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2363 DPRINT("Not sending CREATED notify, %x %d\n", ParentWindow
, HasOwner
);
2366 /* Initialize and show the window's scrollbars */
2367 if (Wnd
->style
& WS_VSCROLL
)
2369 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2371 if (Wnd
->style
& WS_HSCROLL
)
2373 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2376 if (dwStyle
& WS_VISIBLE
)
2378 if (Wnd
->style
& WS_MAXIMIZE
)
2379 dwShowMode
= SW_SHOW
;
2380 else if (Wnd
->style
& WS_MINIMIZE
)
2381 dwShowMode
= SW_SHOWMINIMIZED
;
2383 DPRINT("IntCreateWindow(): About to show window\n");
2384 co_WinPosShowWindow(Window
, dwShowMode
);
2386 if (Wnd
->ExStyle
& WS_EX_MDICHILD
)
2388 co_IntSendMessage(ParentWindow
->hSelf
, WM_MDIREFRESHMENU
, 0, 0);
2389 /* ShowWindow won't activate child windows */
2390 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2394 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
2395 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
2396 Dont understand why it does this. */
2397 if (ClassAtom
== gpsi
->atomSysClass
[ICLS_EDIT
])
2399 PCALLPROCDATA CallProc
;
2400 //CallProc = CreateCallProc(NULL, Wnd->lpfnWndProc, bUnicodeWindow, Wnd->ti->ppi);
2401 CallProc
= CreateCallProc(NULL
, Wnd
->lpfnWndProc
, Wnd
->Unicode
, Wnd
->head
.pti
->ppi
);
2405 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2406 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
2410 UserAddCallProcToClass(Wnd
->pcls
, CallProc
);
2414 DPRINT("IntCreateWindow(): = %X\n", hWnd
);
2415 DPRINT("WindowObject->SystemMenu = 0x%x\n", Window
->SystemMenu
);
2419 if (!_ret_
&& Window
&& Window
->Wnd
&& ti
)
2420 UserFreeWindowInfo(ti
, Window
);
2423 UserDerefObjectCo(Window
);
2424 UserDereferenceObject(Window
);
2426 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2427 if (!_ret_
&& ti
!= NULL
)
2431 IntDereferenceClass(Class
,
2440 NtUserCreateWindowEx(DWORD dwExStyle
,
2441 PUNICODE_STRING UnsafeClassName
,
2442 PUNICODE_STRING UnsafeWindowName
,
2450 HINSTANCE hInstance
,
2453 BOOL bUnicodeWindow
,
2457 UNICODE_STRING WindowName
;
2458 UNICODE_STRING ClassName
;
2459 HWND NewWindow
= NULL
;
2461 DECLARE_RETURN(HWND
);
2463 DPRINT("Enter NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2464 UserEnterExclusive();
2466 /* Get the class name (string or atom) */
2467 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
2468 if (! NT_SUCCESS(Status
))
2470 SetLastNtError(Status
);
2473 if (ClassName
.Length
!= 0)
2475 Status
= IntSafeCopyUnicodeStringTerminateNULL(&ClassName
, UnsafeClassName
);
2476 if (! NT_SUCCESS(Status
))
2478 SetLastNtError(Status
);
2482 else if (! IS_ATOM(ClassName
.Buffer
))
2484 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2488 /* safely copy the window name */
2489 if (NULL
!= UnsafeWindowName
)
2491 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
2492 if (! NT_SUCCESS(Status
))
2494 if (! IS_ATOM(ClassName
.Buffer
))
2496 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2498 SetLastNtError(Status
);
2504 RtlInitUnicodeString(&WindowName
, NULL
);
2507 pNewWindow
= co_IntCreateWindowEx( dwExStyle
,
2522 if (pNewWindow
) NewWindow
= UserHMGetHandle(pNewWindow
);
2524 if (WindowName
.Buffer
)
2526 ExFreePoolWithTag(WindowName
.Buffer
, TAG_STRING
);
2528 if (! IS_ATOM(ClassName
.Buffer
))
2530 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2536 DPRINT("Leave NtUserCreateWindowEx, ret=%i\n",_ret_
);
2545 NtUserDeferWindowPos(HDWP WinPosInfo
,
2547 HWND WndInsertAfter
,
2560 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2566 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2568 hWnd
= Window
->hSelf
;
2572 if (!Wnd
) return TRUE
; // FIXME: Need to finish object rewrite or lock the thread when killing the window!
2574 DPRINT("co_UserDestroyWindow \n");
2576 /* Check for owner thread */
2577 if ((Window
->OwnerThread
!= PsGetCurrentThread()))
2579 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2584 if (ISITHOOKED(WH_CBT
))
2586 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0)) return FALSE
;
2589 /* Look whether the focus is within the tree of windows we will
2592 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2594 if (UserGetActiveWindow() == Window
->hSelf
)
2596 co_WinPosActivateOtherWindow(Window
);
2600 if (Window
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2601 Window
->MessageQueue
->ActiveWindow
= NULL
;
2602 if (Window
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2603 Window
->MessageQueue
->FocusWindow
= NULL
;
2604 if (Window
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2605 Window
->MessageQueue
->CaptureWindow
= NULL
;
2607 IntDereferenceMessageQueue(Window
->MessageQueue
);
2609 IntEngWindowChanged(Window
, WOC_DELETE
);
2610 isChild
= (0 != (Wnd
->style
& WS_CHILD
));
2616 if (! USER_IsExitingThread(GetCurrentThreadId()))
2618 send_parent_notify(hwnd
, WM_DESTROY
);
2621 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2623 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2624 /* FIXME: clean up palette - see "Internals" p.352 */
2628 if (!IntIsWindow(Window
->hSelf
))
2633 /* Recursively destroy owned windows */
2638 BOOL GotOne
= FALSE
;
2641 PWINDOW_OBJECT Child
, Desktop
;
2643 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2644 UserGetWindowObject(IntGetDesktopWindow());
2645 Children
= IntWinListChildren(Desktop
);
2649 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2651 Child
= UserGetWindowObject(*ChildHandle
);
2654 if (Child
->hOwner
!= Window
->hSelf
)
2659 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2661 USER_REFERENCE_ENTRY ChildRef
;
2662 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2663 co_UserDestroyWindow(Child
);
2664 UserDerefObjectCo(Child
);//temp hack?
2670 if (Child
->hOwner
!= NULL
)
2672 Child
->hOwner
= NULL
;
2673 Child
->Wnd
->spwndOwner
= NULL
;
2677 ExFreePool(Children
);
2686 if (!IntIsWindow(Window
->hSelf
))
2691 /* Destroy the window storage */
2692 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2702 NtUserDestroyWindow(HWND Wnd
)
2704 PWINDOW_OBJECT Window
;
2705 DECLARE_RETURN(BOOLEAN
);
2707 USER_REFERENCE_ENTRY Ref
;
2709 DPRINT("Enter NtUserDestroyWindow\n");
2710 UserEnterExclusive();
2712 if (!(Window
= UserGetWindowObject(Wnd
)))
2717 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2718 ret
= co_UserDestroyWindow(Window
);
2719 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2724 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2736 NtUserDrawMenuBarTemp(
2743 /* we'll use this function just for caching the menu bar */
2753 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2763 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2769 NtUserFillWindow(HWND hWndPaint
,
2780 static HWND FASTCALL
2781 IntFindWindow(PWINDOW_OBJECT Parent
,
2782 PWINDOW_OBJECT ChildAfter
,
2784 PUNICODE_STRING WindowName
)
2786 BOOL CheckWindowName
;
2792 CheckWindowName
= WindowName
->Length
!= 0;
2794 if((List
= IntWinListChildren(Parent
)))
2799 /* skip handles before and including ChildAfter */
2800 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2804 /* search children */
2807 PWINDOW_OBJECT Child
;
2808 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2813 /* Do not send WM_GETTEXT messages in the kernel mode version!
2814 The user mode version however calls GetWindowText() which will
2815 send WM_GETTEXT messages to windows belonging to its processes */
2816 if((!CheckWindowName
|| !RtlCompareUnicodeString(WindowName
, &(Child
->Wnd
->strName
), TRUE
)) &&
2817 (!ClassAtom
|| Child
->Wnd
->pcls
->atomClassName
== ClassAtom
))
2832 * Searches a window's children for a window with the specified
2835 * hwndParent = The window whose childs are to be searched.
2837 * HWND_MESSAGE = message-only windows
2839 * hwndChildAfter = Search starts after this child window.
2840 * NULL = start from beginning
2842 * ucClassName = Class name to search for
2843 * Reguired parameter.
2845 * ucWindowName = Window name
2846 * ->Buffer == NULL = don't care
2849 * The HWND of the window if it was found, otherwise NULL
2855 NtUserFindWindowEx(HWND hwndParent
,
2856 HWND hwndChildAfter
,
2857 PUNICODE_STRING ucClassName
,
2858 PUNICODE_STRING ucWindowName
,
2861 PWINDOW_OBJECT Parent
, ChildAfter
;
2862 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2863 HWND Desktop
, Ret
= NULL
;
2864 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2865 DECLARE_RETURN(HWND
);
2867 DPRINT("Enter NtUserFindWindowEx\n");
2870 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2874 if (ucClassName
!= NULL
)
2876 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2877 if (ClassName
.Length
!= 0)
2879 ProbeForRead(ClassName
.Buffer
,
2883 else if (!IS_ATOM(ClassName
.Buffer
))
2885 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2889 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2896 if (ucWindowName
!= NULL
)
2898 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2899 if (WindowName
.Length
!= 0)
2901 ProbeForRead(WindowName
.Buffer
,
2907 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2909 SetLastNtError(_SEH2_GetExceptionCode());
2910 _SEH2_YIELD(RETURN(NULL
));
2914 if (ucClassName
!= NULL
)
2916 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2917 !IS_ATOM(ClassName
.Buffer
))
2919 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2922 else if (ClassAtom
== (RTL_ATOM
)0)
2924 /* LastError code was set by IntGetAtomFromStringOrAtom */
2930 Desktop
= IntGetCurrentThreadDesktopWindow();
2932 if(hwndParent
== NULL
)
2933 hwndParent
= Desktop
;
2934 else if(hwndParent
== HWND_MESSAGE
)
2936 hwndParent
= IntGetMessageWindow();
2939 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2945 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2952 if(Parent
->hSelf
== Desktop
)
2955 PWINDOW_OBJECT TopLevelWindow
;
2956 BOOLEAN CheckWindowName
;
2957 BOOLEAN WindowMatches
;
2958 BOOLEAN ClassMatches
;
2960 /* windows searches through all top-level windows if the parent is the desktop
2963 if((List
= IntWinListChildren(Parent
)))
2969 /* skip handles before and including ChildAfter */
2970 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2974 CheckWindowName
= WindowName
.Length
!= 0;
2976 /* search children */
2979 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2984 /* Do not send WM_GETTEXT messages in the kernel mode version!
2985 The user mode version however calls GetWindowText() which will
2986 send WM_GETTEXT messages to windows belonging to its processes */
2987 WindowMatches
= !CheckWindowName
|| !RtlCompareUnicodeString(
2988 &WindowName
, &TopLevelWindow
->Wnd
->strName
, TRUE
);
2989 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2990 ClassAtom
== TopLevelWindow
->Wnd
->pcls
->atomClassName
;
2992 if (WindowMatches
&& ClassMatches
)
2994 Ret
= TopLevelWindow
->hSelf
;
2998 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3000 /* window returns the handle of the top-level window, in case it found
3002 Ret
= TopLevelWindow
->hSelf
;
3011 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3015 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
3017 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
3018 search the message-only windows. Should this also be done if
3019 Parent is the desktop window??? */
3020 PWINDOW_OBJECT MsgWindows
;
3022 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3024 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3029 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3031 SetLastNtError(_SEH2_GetExceptionCode());
3039 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
3049 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
3060 PWINDOW_OBJECT FASTCALL
UserGetAncestor(PWINDOW_OBJECT Wnd
, UINT Type
)
3062 PWINDOW_OBJECT WndAncestor
, Parent
;
3064 if (Wnd
->hSelf
== IntGetDesktopWindow())
3073 WndAncestor
= Wnd
->Parent
;
3084 if(!(Parent
= WndAncestor
->Parent
))
3088 if(IntIsDesktopWindow(Parent
))
3093 WndAncestor
= Parent
;
3104 PWINDOW_OBJECT Parent
, Old
;
3107 Parent
= IntGetParent(WndAncestor
);
3115 // UserDereferenceObject(Parent);
3117 WndAncestor
= Parent
;
3135 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3137 PWINDOW_OBJECT Window
, Ancestor
;
3138 DECLARE_RETURN(HWND
);
3140 DPRINT("Enter NtUserGetAncestor\n");
3141 UserEnterExclusive();
3143 if (!(Window
= UserGetWindowObject(hWnd
)))
3148 Ancestor
= UserGetAncestor(Window
, Type
);
3149 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3151 RETURN(Ancestor
? Ancestor
->hSelf
: NULL
);
3154 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3162 NtUserGetComboBoxInfo(
3167 DECLARE_RETURN(BOOL
);
3169 DPRINT("Enter NtUserGetComboBoxInfo\n");
3172 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3181 sizeof(COMBOBOXINFO
),
3185 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3187 SetLastNtError(_SEH2_GetExceptionCode());
3188 _SEH2_YIELD(RETURN(FALSE
));
3192 // Pass the user pointer, it was already probed.
3193 RETURN( (BOOL
) co_IntSendMessage( Wnd
->hSelf
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3196 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3206 NtUserGetInternalWindowPos( HWND hWnd
,
3210 PWINDOW_OBJECT Window
;
3214 WINDOWPLACEMENT wndpl
;
3218 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3229 ProbeForWrite(rectWnd
,
3235 ProbeForWrite(ptIcon
,
3241 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3243 SetLastNtError(_SEH2_GetExceptionCode());
3248 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3250 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3256 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3260 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3264 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3266 SetLastNtError(_SEH2_GetExceptionCode());
3271 if (!Hit
) Ret
= wndpl
.showCmd
;
3280 NtUserGetListBoxInfo(
3284 DECLARE_RETURN(DWORD
);
3286 DPRINT("Enter NtUserGetListBoxInfo\n");
3289 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3294 RETURN( (DWORD
) co_IntSendMessage( Wnd
->hSelf
, LB_GETLISTBOXINFO
, 0, 0 ));
3297 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3304 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3306 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3307 HWND hWndOldParent
= NULL
;
3308 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3310 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3312 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3316 if (hWndChild
== IntGetDesktopWindow())
3318 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3324 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3331 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3337 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3342 UserRefObjectCo(Wnd
, &Ref
);
3343 UserRefObjectCo(WndParent
, &ParentRef
);
3345 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3347 UserDerefObjectCo(WndParent
);
3348 UserDerefObjectCo(Wnd
);
3352 hWndOldParent
= WndOldParent
->hSelf
;
3353 UserDereferenceObject(WndOldParent
);
3356 return( hWndOldParent
);
3362 * The NtUserSetParent function changes the parent window of the specified
3366 * The new parent window and the child window must belong to the same
3367 * application. If the window identified by the hWndChild parameter is
3368 * visible, the system performs the appropriate redrawing and repainting.
3369 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3370 * or WS_POPUP window styles of the window whose parent is being changed.
3377 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3379 DECLARE_RETURN(HWND
);
3381 DPRINT("Enter NtUserSetParent\n");
3382 UserEnterExclusive();
3385 Check Parent first from user space, set it here.
3389 hWndNewParent
= IntGetDesktopWindow();
3391 else if (hWndNewParent
== HWND_MESSAGE
)
3393 hWndNewParent
= IntGetMessageWindow();
3396 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3399 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3405 * UserGetShellWindow
3407 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3412 HWND FASTCALL
UserGetShellWindow(VOID
)
3414 PWINSTATION_OBJECT WinStaObject
;
3417 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3422 if (!NT_SUCCESS(Status
))
3424 SetLastNtError(Status
);
3428 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3430 ObDereferenceObject(WinStaObject
);
3435 * NtUserSetShellWindowEx
3437 * This is undocumented function to set global shell window. The global
3438 * shell window has special handling of window position.
3444 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3446 PWINSTATION_OBJECT WinStaObject
;
3447 PWINDOW_OBJECT WndShell
;
3448 DECLARE_RETURN(BOOL
);
3449 USER_REFERENCE_ENTRY Ref
;
3453 DPRINT("Enter NtUserSetShellWindowEx\n");
3454 UserEnterExclusive();
3456 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3461 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3466 if (!NT_SUCCESS(Status
))
3468 SetLastNtError(Status
);
3473 * Test if we are permitted to change the shell window.
3475 if (WinStaObject
->ShellWindow
)
3477 ObDereferenceObject(WinStaObject
);
3482 * Move shell window into background.
3484 if (hwndListView
&& hwndListView
!= hwndShell
)
3487 * Disabled for now to get Explorer working.
3488 * -- Filip, 01/nov/2003
3491 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3494 if (UserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3496 ObDereferenceObject(WinStaObject
);
3501 if (UserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3503 ObDereferenceObject(WinStaObject
);
3507 UserRefObjectCo(WndShell
, &Ref
);
3508 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3510 WinStaObject
->ShellWindow
= hwndShell
;
3511 WinStaObject
->ShellListView
= hwndListView
;
3513 ti
= GetW32ThreadInfo();
3514 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3516 UserDerefObjectCo(WndShell
);
3518 ObDereferenceObject(WinStaObject
);
3522 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3528 * NtUserGetSystemMenu
3530 * The NtUserGetSystemMenu function allows the application to access the
3531 * window menu (also known as the system menu or the control menu) for
3532 * copying and modifying.
3536 * Handle to the window that will own a copy of the window menu.
3538 * Specifies the action to be taken. If this parameter is FALSE,
3539 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3540 * currently in use. The copy is initially identical to the window menu
3541 * but it can be modified.
3542 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3543 * to the default state. The previous window menu, if any, is destroyed.
3546 * If the bRevert parameter is FALSE, the return value is a handle to a
3547 * copy of the window menu. If the bRevert parameter is TRUE, the return
3555 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3557 PWINDOW_OBJECT Window
;
3559 DECLARE_RETURN(HMENU
);
3561 DPRINT("Enter NtUserGetSystemMenu\n");
3564 if (!(Window
= UserGetWindowObject(hWnd
)))
3569 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3574 RETURN(Menu
->MenuInfo
.Self
);
3577 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3583 * NtUserSetSystemMenu
3590 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3592 BOOL Result
= FALSE
;
3593 PWINDOW_OBJECT Window
;
3595 DECLARE_RETURN(BOOL
);
3597 DPRINT("Enter NtUserSetSystemMenu\n");
3598 UserEnterExclusive();
3600 if (!(Window
= UserGetWindowObject(hWnd
)))
3608 * Assign new menu handle.
3610 if (!(Menu
= UserGetMenuObject(hMenu
)))
3615 Result
= IntSetSystemMenu(Window
, Menu
);
3621 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3627 UserGetWindow(HWND hWnd
, UINT Relationship
)
3629 PWINDOW_OBJECT Parent
, Window
;
3630 HWND hWndResult
= NULL
;
3632 if (!(Window
= UserGetWindowObject(hWnd
)))
3635 switch (Relationship
)
3638 if((Parent
= Window
->Parent
))
3640 if (Parent
->FirstChild
)
3641 hWndResult
= Parent
->FirstChild
->hSelf
;
3646 if((Parent
= Window
->Parent
))
3648 if (Parent
->LastChild
)
3649 hWndResult
= Parent
->LastChild
->hSelf
;
3654 if (Window
->NextSibling
)
3655 hWndResult
= Window
->NextSibling
->hSelf
;
3659 if (Window
->PrevSibling
)
3660 hWndResult
= Window
->PrevSibling
->hSelf
;
3664 if((Parent
= UserGetWindowObject(Window
->hOwner
)))
3666 hWndResult
= Parent
->hSelf
;
3670 if (Window
->FirstChild
)
3671 hWndResult
= Window
->FirstChild
->hSelf
;
3681 * The NtUserGetWindow function retrieves a handle to a window that has the
3682 * specified relationship (Z order or owner) to the specified window.
3689 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3691 DECLARE_RETURN(HWND
);
3693 DPRINT("Enter NtUserGetWindow\n");
3696 RETURN(UserGetWindow(hWnd
, Relationship
));
3699 DPRINT("Leave NtUserGetWindow, ret=%i\n",_ret_
);
3705 * NtUserGetWindowLong
3707 * The NtUserGetWindowLong function retrieves information about the specified
3708 * window. The function also retrieves the 32-bit (long) value at the
3709 * specified offset into the extra window memory.
3716 UserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3718 PWINDOW_OBJECT Window
, Parent
;
3722 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3724 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3732 * WndProc is only available to the owner process
3734 if (GWL_WNDPROC
== Index
3735 && Window
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3737 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3741 if ((INT
)Index
>= 0)
3743 if ((Index
+ sizeof(LONG
)) > Window
->Wnd
->cbwndExtra
)
3745 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3748 Result
= *((LONG
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3755 Result
= Wnd
->ExStyle
;
3759 Result
= Wnd
->style
;
3763 Result
= (LONG
)IntGetWindowProc(Wnd
, Ansi
);
3767 Result
= (LONG
) Wnd
->hModule
;
3770 case GWL_HWNDPARENT
:
3771 Parent
= Window
->Parent
;
3774 if (Parent
&& Parent
->hSelf
== IntGetDesktopWindow())
3775 Result
= (LONG
) UserGetWindow(Window
->hSelf
, GW_OWNER
);
3777 Result
= (LONG
) Parent
->hSelf
;
3782 Result
= (LONG
) Wnd
->IDMenu
;
3786 Result
= Wnd
->dwUserData
;
3790 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3791 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3801 * NtUserGetWindowLong
3803 * The NtUserGetWindowLong function retrieves information about the specified
3804 * window. The function also retrieves the 32-bit (long) value at the
3805 * specified offset into the extra window memory.
3812 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3814 DECLARE_RETURN(LONG
);
3816 DPRINT("Enter NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3817 UserEnterExclusive();
3819 RETURN(UserGetWindowLong(hWnd
, Index
, Ansi
));
3822 DPRINT("Leave NtUserGetWindowLong, ret=%i\n",_ret_
);
3830 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3832 PWINDOW_OBJECT Window
, Parent
;
3834 PWINSTATION_OBJECT WindowStation
;
3838 if (hWnd
== IntGetDesktopWindow())
3840 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3844 if (!(Window
= UserGetWindowObject(hWnd
)))
3851 if (!Wnd
) return 0; // No go on zero.
3853 if ((INT
)Index
>= 0)
3855 if ((Index
+ sizeof(LONG
)) > Wnd
->cbwndExtra
)
3857 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3861 OldValue
= *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
));
3863 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3865 OldValue = (LONG)IntSetWindowProc( Wnd,
3868 if (!OldValue) return 0;
3871 *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
)) = NewValue
;
3878 OldValue
= (LONG
) Wnd
->ExStyle
;
3879 Style
.styleOld
= OldValue
;
3880 Style
.styleNew
= NewValue
;
3883 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3885 WindowStation
= ((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
->WindowStation
;
3888 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3889 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3892 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3893 Wnd
->ExStyle
= (DWORD
)Style
.styleNew
;
3894 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3898 OldValue
= (LONG
) Wnd
->style
;
3899 Style
.styleOld
= OldValue
;
3900 Style
.styleNew
= NewValue
;
3901 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3902 Wnd
->style
= (DWORD
)Style
.styleNew
;
3903 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3908 if ( Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3909 Wnd
->fnid
& FNID_FREED
)
3911 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3914 OldValue
= (LONG
)IntSetWindowProc(Wnd
,
3921 OldValue
= (LONG
) Wnd
->hModule
;
3922 Wnd
->hModule
= (HINSTANCE
) NewValue
;
3925 case GWL_HWNDPARENT
:
3926 Parent
= Window
->Parent
;
3927 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
3928 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
3930 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
3934 OldValue
= (LONG
) Wnd
->IDMenu
;
3935 Wnd
->IDMenu
= (UINT
) NewValue
;
3939 OldValue
= Wnd
->dwUserData
;
3940 Wnd
->dwUserData
= NewValue
;
3944 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3945 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3955 * NtUserSetWindowLong
3957 * The NtUserSetWindowLong function changes an attribute of the specified
3958 * window. The function also sets the 32-bit (long) value at the specified
3959 * offset into the extra window memory.
3966 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3968 DECLARE_RETURN(LONG
);
3970 DPRINT("Enter NtUserSetWindowLong\n");
3971 UserEnterExclusive();
3973 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3976 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3982 * NtUserSetWindowWord
3984 * Legacy function similar to NtUserSetWindowLong.
3991 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3993 PWINDOW_OBJECT Window
;
3995 DECLARE_RETURN(WORD
);
3997 DPRINT("Enter NtUserSetWindowWord\n");
3998 UserEnterExclusive();
4000 if (!(Window
= UserGetWindowObject(hWnd
)))
4009 case GWL_HWNDPARENT
:
4010 RETURN( co_UserSetWindowLong(Window
->hSelf
, Index
, (UINT
)NewValue
, TRUE
));
4014 SetLastWin32Error(ERROR_INVALID_INDEX
);
4019 if (Index
> Window
->Wnd
->cbwndExtra
- sizeof(WORD
))
4021 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4025 OldValue
= *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
4026 *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
)) = NewValue
;
4031 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
4040 NtUserGetWindowPlacement(HWND hWnd
,
4041 WINDOWPLACEMENT
*lpwndpl
)
4043 PWINDOW_OBJECT Window
;
4046 WINDOWPLACEMENT Safepl
;
4048 DECLARE_RETURN(BOOL
);
4050 DPRINT("Enter NtUserGetWindowPlacement\n");
4053 if (!(Window
= UserGetWindowObject(hWnd
)))
4059 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4060 if(!NT_SUCCESS(Status
))
4062 SetLastNtError(Status
);
4065 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4071 if (0 == (Wnd
->style
& WS_VISIBLE
))
4073 Safepl
.showCmd
= SW_HIDE
;
4075 else if ((0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
4076 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
4077 0 == (Wnd
->style
& WS_MINIMIZE
))
4079 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
4081 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
4083 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
4085 else if (0 != (Wnd
->style
& WS_VISIBLE
))
4087 Safepl
.showCmd
= SW_SHOWNORMAL
;
4090 Size
.x
= Wnd
->rcWindow
.left
;
4091 Size
.y
= Wnd
->rcWindow
.top
;
4092 WinPosInitInternalPos(Window
, &Size
,
4095 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
4096 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
4097 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
4099 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
4100 if(!NT_SUCCESS(Status
))
4102 SetLastNtError(Status
);
4109 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
4119 NtUserLockWindowUpdate(HWND hWnd
)
4139 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
4140 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
4141 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
4145 QueryWindow based on KJK::Hyperion and James Tabor.
4147 0 = QWUniqueProcessId
4148 1 = QWUniqueThreadId
4151 4 = QWIsHung Implements IsHungAppWindow found
4154 9 = QWKillWindow When I called this with hWnd ==
4155 DesktopWindow, it shutdown the system
4162 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
4164 PWINDOW_OBJECT Window
;
4167 DECLARE_RETURN(UINT
);
4169 DPRINT("Enter NtUserQueryWindow\n");
4172 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4181 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
4182 Result
= (DWORD
)IntGetWndProcessId(Window
);
4185 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
4186 Result
= (DWORD
)IntGetWndThreadId(Window
);
4189 case QUERY_WINDOW_ACTIVE
:
4190 Result
= (DWORD
)UserGetActiveWindow();
4193 case QUERY_WINDOW_FOCUS
:
4194 Result
= (DWORD
)IntGetFocusWindow();
4197 case QUERY_WINDOW_ISHUNG
:
4198 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
4201 case QUERY_WINDOW_REAL_ID
:
4202 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
4205 Result
= (DWORD
)NULL
;
4212 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
4222 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
4236 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4238 UNICODE_STRING SafeMessageName
;
4241 DECLARE_RETURN(UINT
);
4243 DPRINT("Enter NtUserRegisterWindowMessage\n");
4244 UserEnterExclusive();
4246 if(MessageNameUnsafe
== NULL
)
4248 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4252 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4253 if(!NT_SUCCESS(Status
))
4255 SetLastNtError(Status
);
4259 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4261 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4265 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
4275 NtUserSetImeOwnerWindow(DWORD Unknown0
,
4288 NtUserSetInternalWindowPos(
4305 NtUserSetLayeredWindowAttributes(HWND hwnd
,
4319 NtUserSetLogonNotifyWindow(HWND hWnd
)
4336 PWINDOW_OBJECT Window
;
4338 DECLARE_RETURN(BOOL
);
4340 DPRINT("Enter NtUserSetMenu\n");
4341 UserEnterExclusive();
4343 if (!(Window
= UserGetWindowObject(hWnd
)))
4348 if (! IntSetMenu(Window
, Menu
, &Changed
))
4353 if (Changed
&& Repaint
)
4355 USER_REFERENCE_ENTRY Ref
;
4357 UserRefObjectCo(Window
, &Ref
);
4358 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4359 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4361 UserDerefObjectCo(Window
);
4367 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4377 NtUserSetWindowFNID(HWND hWnd
,
4380 PWINDOW_OBJECT Window
;
4382 DECLARE_RETURN(BOOL
);
4384 DPRINT("Enter NtUserSetWindowFNID\n");
4385 UserEnterExclusive();
4387 if (!(Window
= UserGetWindowObject(hWnd
)))
4394 { // From user land we only set these.
4395 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
4400 Wnd
->pcls
->fnid
|= fnID
;
4405 DPRINT("Leave NtUserSetWindowFNID\n");
4415 NtUserSetWindowPlacement(HWND hWnd
,
4416 WINDOWPLACEMENT
*lpwndpl
)
4418 PWINDOW_OBJECT Window
;
4420 WINDOWPLACEMENT Safepl
;
4422 DECLARE_RETURN(BOOL
);
4423 USER_REFERENCE_ENTRY Ref
;
4425 DPRINT("Enter NtUserSetWindowPlacement\n");
4426 UserEnterExclusive();
4428 if (!(Window
= UserGetWindowObject(hWnd
)))
4434 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4435 if(!NT_SUCCESS(Status
))
4437 SetLastNtError(Status
);
4440 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4445 UserRefObjectCo(Window
, &Ref
);
4447 if ((Wnd
->style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4449 co_WinPosSetWindowPos(Window
, NULL
,
4450 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4451 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4452 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4453 SWP_NOZORDER
| SWP_NOACTIVATE
);
4456 /* FIXME - change window status */
4457 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
4459 Wnd
->InternalPosInitialized
= TRUE
;
4460 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4461 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4462 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4464 UserDerefObjectCo(Window
);
4468 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4480 HWND hWndInsertAfter
,
4487 DECLARE_RETURN(BOOL
);
4488 PWINDOW_OBJECT Window
;
4490 USER_REFERENCE_ENTRY Ref
;
4492 DPRINT("Enter NtUserSetWindowPos\n");
4493 UserEnterExclusive();
4495 if (!(Window
= UserGetWindowObject(hWnd
)))
4500 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
4501 if (!(uFlags
& SWP_NOMOVE
))
4503 if (X
< -32768) X
= -32768;
4504 else if (X
> 32767) X
= 32767;
4505 if (Y
< -32768) Y
= -32768;
4506 else if (Y
> 32767) Y
= 32767;
4508 if (!(uFlags
& SWP_NOSIZE
))
4511 else if (cx
> 32767) cx
= 32767;
4513 else if (cy
> 32767) cy
= 32767;
4516 UserRefObjectCo(Window
, &Ref
);
4517 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4518 UserDerefObjectCo(Window
);
4523 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4530 IntGetWindowRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
4548 /* Create a new window region using the window rectangle */
4549 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4550 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4551 /* if there's a region assigned to the window, combine them both */
4552 if(Window
->WindowRegion
&& !(Wnd
->style
& WS_MINIMIZE
))
4553 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4554 /* Copy the region into hRgn */
4555 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4557 if((pRgn
= REGION_LockRgn(hRgn
)))
4559 Ret
= pRgn
->rdh
.iType
;
4560 REGION_UnlockRgn(pRgn
);
4565 GreDeleteObject(VisRgn
);
4571 IntGetWindowRgnBox(PWINDOW_OBJECT Window
, RECTL
*Rect
)
4589 /* Create a new window region using the window rectangle */
4590 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4591 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4592 /* if there's a region assigned to the window, combine them both */
4593 if(Window
->WindowRegion
&& !(Wnd
->style
& WS_MINIMIZE
))
4594 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4596 if((pRgn
= REGION_LockRgn(VisRgn
)))
4598 Ret
= pRgn
->rdh
.iType
;
4599 *Rect
= pRgn
->rdh
.rcBound
;
4600 REGION_UnlockRgn(pRgn
);
4605 GreDeleteObject(VisRgn
);
4620 PWINDOW_OBJECT Window
;
4621 DECLARE_RETURN(INT
);
4623 DPRINT("Enter NtUserSetWindowRgn\n");
4624 UserEnterExclusive();
4626 if (!(Window
= UserGetWindowObject(hWnd
)))
4631 /* FIXME - Verify if hRgn is a valid handle!!!!
4632 Propably make this operation thread-safe, but maybe it's not necessary */
4634 if(Window
->WindowRegion
)
4636 /* Delete no longer needed region handle */
4637 GreDeleteObject(Window
->WindowRegion
);
4639 Window
->WindowRegion
= hRgn
;
4641 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4645 USER_REFERENCE_ENTRY Ref
;
4646 UserRefObjectCo(Window
, &Ref
);
4647 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4648 UserDerefObjectCo(Window
);
4654 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4664 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4666 PWINDOW_OBJECT Window
;
4668 DECLARE_RETURN(BOOL
);
4669 USER_REFERENCE_ENTRY Ref
;
4671 DPRINT("Enter NtUserShowWindow\n");
4672 UserEnterExclusive();
4674 if (!(Window
= UserGetWindowObject(hWnd
)))
4679 UserRefObjectCo(Window
, &Ref
);
4680 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4681 UserDerefObjectCo(Window
);
4686 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4696 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4702 return NtUserShowWindow(hWnd
, nCmdShow
);
4712 NtUserUpdateLayeredWindow(
4720 BLENDFUNCTION
*pblend
,
4733 NtUserWindowFromPhysicalPoint(POINT Point
)
4744 NtUserWindowFromPoint(LONG X
, LONG Y
)
4748 PWINDOW_OBJECT DesktopWindow
= NULL
, Window
= NULL
;
4749 DECLARE_RETURN(HWND
);
4750 USER_REFERENCE_ENTRY Ref
;
4752 DPRINT("Enter NtUserWindowFromPoint\n");
4753 UserEnterExclusive();
4755 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4763 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4764 //its possible this referencing is useless, thou it shouldnt hurt...
4765 UserRefObjectCo(DesktopWindow
, &Ref
);
4767 pti
= PsGetCurrentThreadWin32Thread();
4768 Hit
= co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4772 Ret
= Window
->hSelf
;
4781 if (Window
) UserDereferenceObject(Window
);
4782 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4784 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4794 * Undocumented function that is called from DefWindowProc to set
4801 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4803 PWINDOW_OBJECT Window
;
4805 LARGE_STRING SafeText
;
4806 UNICODE_STRING UnicodeString
;
4809 DPRINT("Enter NtUserDefSetText\n");
4811 if (WindowText
!= NULL
)
4815 SafeText
= ProbeForReadLargeString(WindowText
);
4817 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4820 SetLastNtError(_SEH2_GetExceptionCode());
4830 UserEnterExclusive();
4832 if(!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4839 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4840 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4841 // Now we know what the bAnsi is for.
4842 RtlInitUnicodeString(&UnicodeString
, NULL
);
4843 if (SafeText
.Buffer
)
4848 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4850 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4851 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4853 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4856 SetLastNtError(_SEH2_GetExceptionCode());
4859 if (!Ret
) goto Exit
;
4862 if (UnicodeString
.Length
!= 0)
4864 if (Wnd
->strName
.MaximumLength
> 0 &&
4865 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4867 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4869 Wnd
->strName
.Length
= UnicodeString
.Length
;
4870 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4871 RtlCopyMemory(Wnd
->strName
.Buffer
,
4872 UnicodeString
.Buffer
,
4873 UnicodeString
.Length
);
4878 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4879 buf
= Wnd
->strName
.Buffer
;
4880 Wnd
->strName
.Buffer
= NULL
;
4883 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4886 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4887 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4888 if (Wnd
->strName
.Buffer
!= NULL
)
4890 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4891 RtlCopyMemory(Wnd
->strName
.Buffer
,
4892 UnicodeString
.Buffer
,
4893 UnicodeString
.Length
);
4894 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4895 Wnd
->strName
.Length
= UnicodeString
.Length
;
4899 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4907 Wnd
->strName
.Length
= 0;
4908 if (Wnd
->strName
.Buffer
!= NULL
)
4909 Wnd
->strName
.Buffer
[0] = L
'\0';
4912 // HAX! FIXME! Windows does not do this in here!
4913 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4914 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4915 /* Send shell notifications */
4916 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
4918 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4923 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4924 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4930 * NtUserInternalGetWindowText
4937 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4939 PWINDOW_OBJECT Window
;
4943 DECLARE_RETURN(INT
);
4945 DPRINT("Enter NtUserInternalGetWindowText\n");
4948 if(lpString
&& (nMaxCount
<= 1))
4950 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4954 if(!(Window
= UserGetWindowObject(hWnd
)))
4960 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4963 const WCHAR Terminator
= L
'\0';
4965 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4967 Copy
= min(nMaxCount
- 1, Result
);
4970 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4971 if(!NT_SUCCESS(Status
))
4973 SetLastNtError(Status
);
4979 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4980 if(!NT_SUCCESS(Status
))
4982 SetLastNtError(Status
);
4992 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
5000 IntShowOwnedPopups(PWINDOW_OBJECT OwnerWnd
, BOOL fShow
)
5003 PWINDOW_OBJECT pWnd
;
5006 // ASSERT(OwnerWnd);
5008 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
5013 while (win_array
[count
])
5015 while (--count
>= 0)
5017 if (UserGetWindow( win_array
[count
], GW_OWNER
) != OwnerWnd
->hSelf
)
5019 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
5021 // if (pWnd == WND_OTHER_PROCESS) continue;
5025 if (pWnd
->Wnd
->state
& WNDS_HIDDENPOPUP
)
5027 /* In Windows, ShowOwnedPopups(TRUE) generates
5028 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
5029 * regardless of the state of the owner
5031 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
5037 if (pWnd
->Wnd
->style
& WS_VISIBLE
)
5039 /* In Windows, ShowOwnedPopups(FALSE) generates
5040 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
5041 * regardless of the state of the owner
5043 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
5049 ExFreePool( win_array
);
5054 * NtUserValidateHandleSecure
5062 NtUserValidateHandleSecure(
5070 PUSER_HANDLE_ENTRY entry
;
5071 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
5073 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5076 uType
= entry
->type
;
5082 PWINDOW_OBJECT Window
;
5083 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
5089 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
5094 PACCELERATOR_TABLE Accel
;
5095 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
5100 PCURICON_OBJECT Cursor
;
5101 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
5107 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
5112 PMONITOR_OBJECT Monitor
;
5113 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
5119 return UserGetCallProcInfo( handle
, &Proc
);
5122 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5126 { /* Is handle entry restricted? */