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
);
429 /* flush the message queue */
430 MsqRemoveWindowMessagesFromQueue(Window
);
432 /* from now on no messages can be sent to this window anymore */
433 Window
->Status
|= WINDOWSTATUS_DESTROYED
;
434 Wnd
->state
|= WNDS_DESTROYED
;
435 Wnd
->fnid
|= FNID_FREED
;
437 /* don't remove the WINDOWSTATUS_DESTROYING bit */
439 /* reset shell window handles */
440 if(ThreadData
->Desktop
)
442 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellWindow
)
443 ThreadData
->Desktop
->WindowStation
->ShellWindow
= NULL
;
445 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellListView
)
446 ThreadData
->Desktop
->WindowStation
->ShellListView
= NULL
;
449 /* Unregister hot keys */
450 UnregisterWindowHotKeys (Window
);
452 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
456 WinPosCheckInternalPos(Window
->hSelf
);
457 if (Window
->hSelf
== GetCapture())
462 /* free resources associated with the window */
463 TIMER_RemoveWindowTimers(Window
->hSelf
);
466 if (!(Wnd
->style
& WS_CHILD
) && Wnd
->IDMenu
467 && (Menu
= UserGetMenuObject((HMENU
)Wnd
->IDMenu
)))
469 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
473 if(Window
->SystemMenu
474 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
476 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
477 Window
->SystemMenu
= (HMENU
)0;
480 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
483 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
484 CLASS_RemoveWindow(Window
->Class
);
487 IntUnlinkWindow(Window
);
489 UserReferenceObject(Window
);
490 UserDeleteObject(Window
->hSelf
, otWindow
);
492 IntDestroyScrollBars(Window
);
494 /* dereference the class */
495 IntDereferenceClass(Wnd
->pcls
,
496 Window
->ti
->pDeskInfo
,
500 if(Window
->WindowRegion
)
502 GreDeleteObject(Window
->WindowRegion
);
505 ASSERT(Window
->Wnd
!= NULL
);
506 UserFreeWindowInfo(Window
->ti
, Window
);
508 UserDereferenceObject(Window
);
510 IntClipboardFreeWindow(Window
);
516 IntGetWindowBorderMeasures(PWINDOW_OBJECT Window
, UINT
*cx
, UINT
*cy
)
518 PWND Wnd
= Window
->Wnd
;
519 if(HAS_DLGFRAME(Wnd
->style
, Wnd
->ExStyle
) && !(Wnd
->style
& WS_MINIMIZE
))
521 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
522 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
526 if(HAS_THICKFRAME(Wnd
->style
, Wnd
->ExStyle
)&& !(Wnd
->style
& WS_MINIMIZE
))
528 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
529 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
531 else if(HAS_THINFRAME(Wnd
->style
, Wnd
->ExStyle
))
533 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
534 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
544 // Same as User32:IntGetWndProc.
547 IntGetWindowProc(PWND pWnd
,
552 WNDPROC gcpd
, Ret
= 0;
554 ASSERT(UserIsEnteredExclusive() == TRUE
);
558 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
560 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
562 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
565 Ret
= GETPFNCLIENTA(i
);
567 Ret
= GETPFNCLIENTW(i
);
573 if (Class
->fnid
== FNID_EDIT
)
574 Ret
= pWnd
->lpfnWndProc
;
577 Ret
= pWnd
->lpfnWndProc
;
579 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
583 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
584 Ret
= GETPFNCLIENTA(Class
->fnid
);
588 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
589 Ret
= GETPFNCLIENTW(Class
->fnid
);
592 if ( Ret
!= pWnd
->lpfnWndProc
)
595 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
598 gcpd
= (WNDPROC
)UserGetCPD(
600 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
603 return (gcpd
? gcpd
: Ret
);
607 IntSetWindowProc(PWND pWnd
,
612 PCALLPROCDATA CallProc
;
614 WNDPROC Ret
, chWndProc
= NULL
;
616 // Retrieve previous window proc.
617 Ret
= IntGetWindowProc(pWnd
, Ansi
);
621 if (IsCallProcHandle(NewWndProc
))
623 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, otCallProc
);
625 { // Reset new WndProc.
626 NewWndProc
= CallProc
->pfnClientPrevious
;
627 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
628 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
631 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
632 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
634 if (GETPFNCLIENTW(i
) == NewWndProc
)
636 chWndProc
= GETPFNSERVER(i
);
639 if (GETPFNCLIENTA(i
) == NewWndProc
)
641 chWndProc
= GETPFNSERVER(i
);
645 // If match, set/reset to Server Side and clear ansi.
648 pWnd
->lpfnWndProc
= chWndProc
;
649 pWnd
->Unicode
= TRUE
;
650 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
651 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
655 pWnd
->Unicode
= !Ansi
;
656 // Handle the state change in here.
658 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
660 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
662 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
663 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
665 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
669 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
670 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
674 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
675 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
678 // Now set the new window proc.
679 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
684 // Move this to user space!
686 IntGetWindowInfo(PWINDOW_OBJECT Window
, PWINDOWINFO pwi
)
688 PWND Wnd
= Window
->Wnd
;
690 pwi
->cbSize
= sizeof(WINDOWINFO
);
691 pwi
->rcWindow
= Window
->Wnd
->rcWindow
;
692 pwi
->rcClient
= Window
->Wnd
->rcClient
;
693 pwi
->dwStyle
= Wnd
->style
;
694 pwi
->dwExStyle
= Wnd
->ExStyle
;
695 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Window
->hSelf
); /* WS_ACTIVECAPTION */
696 IntGetWindowBorderMeasures(Window
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
697 pwi
->atomWindowType
= (Wnd
->pcls
? Wnd
->pcls
->atomClassName
: 0);
698 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
704 PWINDOW_OBJECT Window
,
708 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
709 PWND Wnd
= Window
->Wnd
;
711 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
713 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
717 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
725 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
726 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Window
->hSelf
);
735 NewMenu
= IntGetMenuObject(Menu
);
740 IntReleaseMenuObject(OldMenu
);
742 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
745 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
747 /* Can't use the same menu for two windows */
750 IntReleaseMenuObject(OldMenu
);
752 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
758 Wnd
->IDMenu
= (UINT
) Menu
;
761 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
762 IntReleaseMenuObject(NewMenu
);
766 OldMenu
->MenuInfo
.Wnd
= NULL
;
767 IntReleaseMenuObject(OldMenu
);
774 /* INTERNAL ******************************************************************/
778 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
783 USER_REFERENCE_ENTRY Ref
;
784 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
786 while (!IsListEmpty(&WThread
->WindowListHead
))
788 Current
= WThread
->WindowListHead
.Flink
;
789 Wnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
791 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
793 /* window removes itself from the list */
796 fixme: it is critical that the window removes itself! if now, we will loop
800 //ASSERT(co_UserDestroyWindow(Wnd));
802 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
803 if (!co_UserDestroyWindow(Wnd
))
805 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
807 UserDerefObjectCo(Wnd
);//faxme: temp hack??
815 * Returns client window rectangle relative to the upper-left corner of client area.
817 * \note Does not check the validity of the parameters
820 IntGetClientRect(PWINDOW_OBJECT Window
, RECTL
*Rect
)
825 Rect
->left
= Rect
->top
= 0;
826 Rect
->right
= Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
;
827 Rect
->bottom
= Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
;
833 IntGetFocusWindow(VOID
)
835 PUSER_MESSAGE_QUEUE Queue
;
836 PDESKTOP pdo
= IntGetActiveDesktop();
841 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
846 return(Queue
->FocusWindow
);
850 PMENU_OBJECT FASTCALL
851 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
)
853 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
854 PTHREADINFO W32Thread
;
855 HMENU hNewMenu
, hSysMenu
;
856 ROSMENUITEMINFO ItemInfo
;
860 W32Thread
= PsGetCurrentThreadWin32Thread();
862 if(!W32Thread
->Desktop
)
865 if(Window
->SystemMenu
)
867 Menu
= UserGetMenuObject(Window
->SystemMenu
);
870 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
871 Window
->SystemMenu
= (HMENU
)0;
875 if(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
)
877 /* clone system menu */
878 Menu
= UserGetMenuObject(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
);
882 NewMenu
= IntCloneMenu(Menu
);
885 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
886 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
887 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
889 //IntReleaseMenuObject(NewMenu);
894 hSysMenu
= UserCreateMenu(FALSE
);
895 if (NULL
== hSysMenu
)
899 SysMenu
= IntGetMenuObject(hSysMenu
);
902 UserDestroyMenu(hSysMenu
);
905 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
906 SysMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
907 hNewMenu
= co_IntLoadSysMenuTemplate();
910 IntReleaseMenuObject(SysMenu
);
911 UserDestroyMenu(hSysMenu
);
914 Menu
= IntGetMenuObject(hNewMenu
);
917 IntReleaseMenuObject(SysMenu
);
918 UserDestroyMenu(hSysMenu
);
922 NewMenu
= IntCloneMenu(Menu
);
925 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
926 IntReleaseMenuObject(NewMenu
);
927 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
929 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
930 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
931 ItemInfo
.fType
= MF_POPUP
;
932 ItemInfo
.fState
= MFS_ENABLED
;
933 ItemInfo
.dwTypeData
= NULL
;
935 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
936 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
938 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
942 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
951 if(Window
->SystemMenu
)
952 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
960 IntIsChildWindow(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT BaseWindow
)
962 PWINDOW_OBJECT Window
;
969 if (Window
== Parent
)
973 if(!(Wnd
->style
& WS_CHILD
))
978 Window
= Window
->Parent
;
985 IntIsWindowVisible(PWINDOW_OBJECT BaseWindow
)
987 PWINDOW_OBJECT Window
;
994 if(!(Wnd
->style
& WS_CHILD
))
998 if(!(Wnd
->style
& WS_VISIBLE
))
1003 Window
= Window
->Parent
;
1006 if(Window
&& Wnd
->style
& WS_VISIBLE
)
1015 /* link the window into siblings and parent. children are kept in place. */
1019 PWINDOW_OBJECT WndParent
,
1020 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
1023 PWINDOW_OBJECT Parent
;
1025 Wnd
->Parent
= WndParent
;
1026 Wnd
->Wnd
->spwndParent
= WndParent
? WndParent
->Wnd
: NULL
;
1027 if ((Wnd
->PrevSibling
= WndPrevSibling
))
1029 /* link after WndPrevSibling */
1030 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
1031 Wnd
->NextSibling
->PrevSibling
= Wnd
;
1032 else if ((Parent
= Wnd
->Parent
))
1034 if(Parent
->LastChild
== WndPrevSibling
)
1035 Parent
->LastChild
= Wnd
;
1037 Wnd
->PrevSibling
->NextSibling
= Wnd
;
1042 Parent
= Wnd
->Parent
;
1043 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
1044 Wnd
->NextSibling
->PrevSibling
= Wnd
;
1047 Parent
->LastChild
= Wnd
;
1048 Parent
->FirstChild
= Wnd
;
1053 Parent
->FirstChild
= Wnd
;
1060 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1062 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
1065 Wnd
= IntGetWindowObject(hWnd
);
1069 WndOldOwner
= IntGetWindowObject(Wnd
->hOwner
);
1072 ret
= WndOldOwner
->hSelf
;
1073 UserDereferenceObject(WndOldOwner
);
1080 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1082 Wnd
->hOwner
= hWndNewOwner
;
1083 Wnd
->Wnd
->spwndOwner
= WndNewOwner
->Wnd
;
1088 Wnd
->Wnd
->spwndOwner
= NULL
;
1091 UserDereferenceObject(Wnd
);
1095 PWINDOW_OBJECT FASTCALL
1096 co_IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
1098 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
1099 // HWND hWnd, hWndNewParent;
1103 ASSERT(WndNewParent
);
1104 ASSERT_REFS_CO(Wnd
);
1105 ASSERT_REFS_CO(WndNewParent
);
1107 // hWnd = Wnd->hSelf;
1108 // hWndNewParent = WndNewParent->hSelf;
1110 /* Some applications try to set a child as a parent */
1111 if (IntIsChildWindow(Wnd
, WndNewParent
))
1113 SetLastWin32Error( ERROR_INVALID_PARAMETER
);
1118 * Windows hides the window first, then shows it again
1119 * including the WM_SHOWWINDOW messages and all
1121 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1123 // /* Validate that window and parent still exist */
1124 // if (!IntIsWindow(hWnd) || !IntIsWindow(hWndNewParent))
1127 /* Window must belong to current process */
1128 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
1131 WndOldParent
= Wnd
->Parent
;
1133 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1135 if (WndNewParent
!= WndOldParent
)
1137 IntUnlinkWindow(Wnd
);
1139 if (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1141 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
1142 Sibling
= WndNewParent
->FirstChild
;
1143 while (NULL
!= Sibling
&& 0 != (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1145 InsertAfter
= Sibling
;
1146 Sibling
= Sibling
->NextSibling
;
1149 if (NULL
== InsertAfter
)
1151 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1155 // UserReferenceObject(InsertAfter);
1156 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1157 // UserDereferenceObject(InsertAfter);
1162 * SetParent additionally needs to make hwnd the top window
1163 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1164 * WM_WINDOWPOSCHANGED notification messages.
1166 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1167 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1168 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1171 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1172 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1176 * Validate that the old parent still exist, since it migth have been
1177 * destroyed during the last callbacks to user-mode
1181 // if(!IntIsWindow(WndOldParent->hSelf))
1183 // UserDereferenceObject(WndOldParent);
1187 /* don't dereference the window object here, it must be done by the caller
1188 of IntSetParent() */
1189 // return WndOldParent;
1192 return WndOldParent
;//NULL;
1196 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
1198 PMENU_OBJECT OldMenu
;
1199 if(Window
->SystemMenu
)
1201 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1204 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1205 IntReleaseMenuObject(OldMenu
);
1211 /* FIXME check window style, propably return FALSE ? */
1212 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1213 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1216 Window
->SystemMenu
= (HMENU
)0;
1222 /* unlink the window from siblings and parent. children are kept in place. */
1224 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1226 PWINDOW_OBJECT WndParent
= Wnd
->Parent
;
1228 if (Wnd
->NextSibling
)
1229 Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1230 else if (WndParent
&& WndParent
->LastChild
== Wnd
)
1231 WndParent
->LastChild
= Wnd
->PrevSibling
;
1233 if (Wnd
->PrevSibling
)
1234 Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1235 else if (WndParent
&& WndParent
->FirstChild
== Wnd
)
1236 WndParent
->FirstChild
= Wnd
->NextSibling
;
1238 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1240 Wnd
->Wnd
->spwndParent
= NULL
;
1246 PWINDOW_OBJECT Window
, Child
;
1248 if(!(Window
= UserGetWindowObject(IntGetDesktopWindow())))
1253 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1255 if(Child
->hOwner
&& Child
->Wnd
->style
& WS_VISIBLE
)
1258 * The desktop has a popup window if one of them has
1259 * an owner window and is visible
1269 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1271 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1277 IntGetWindowPlacement(PWINDOW_OBJECT Window
, WINDOWPLACEMENT
*lpwndpl
)
1283 if (!Wnd
) return FALSE
;
1285 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1291 if (0 == (Wnd
->style
& WS_VISIBLE
))
1293 lpwndpl
->showCmd
= SW_HIDE
;
1295 else if (0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
1296 0 != (Wnd
->style
& WS_MAXIMIZE
))
1298 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1300 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1302 lpwndpl
->showCmd
= SW_MINIMIZE
;
1304 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1306 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1309 Size
.x
= Wnd
->rcWindow
.left
;
1310 Size
.y
= Wnd
->rcWindow
.top
;
1311 WinPosInitInternalPos(Window
, &Size
,
1314 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1315 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1316 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1322 /* FUNCTIONS *****************************************************************/
1328 NtUserAlterWindowStyle(DWORD Unknown0
,
1338 * As best as I can figure, this function is used by EnumWindows,
1339 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1341 * It's supposed to build a list of HWNDs to return to the caller.
1342 * We can figure out what kind of list by what parameters are
1350 NtUserBuildHwndList(
1363 return ERROR_INVALID_PARAMETER
;
1365 if (hwndParent
|| !dwThreadId
)
1368 PWINDOW_OBJECT Parent
, Window
;
1372 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1374 return ERROR_INVALID_HANDLE
;
1379 Status
= IntValidateDesktopHandle(hDesktop
,
1383 if(!NT_SUCCESS(Status
))
1385 return ERROR_INVALID_HANDLE
;
1388 hwndParent
= Desktop
->DesktopWindow
;
1395 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1396 (Window
= Parent
->FirstChild
))
1398 BOOL bGoDown
= TRUE
;
1400 Status
= STATUS_SUCCESS
;
1405 if(dwCount
++ < *pBufSize
&& pWnd
)
1409 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1410 *pWnd
= Window
->hSelf
;
1413 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1415 Status
= _SEH2_GetExceptionCode();
1418 if(!NT_SUCCESS(Status
))
1420 SetLastNtError(Status
);
1424 if (Window
->FirstChild
&& bChildren
)
1426 Window
= Window
->FirstChild
;
1431 if (Window
->NextSibling
)
1433 Window
= Window
->NextSibling
;
1437 Window
= Window
->Parent
;
1438 if (Window
== Parent
)
1447 ObDereferenceObject(Desktop
);
1453 PTHREADINFO W32Thread
;
1454 PLIST_ENTRY Current
;
1455 PWINDOW_OBJECT Window
;
1457 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1458 if(!NT_SUCCESS(Status
))
1460 return ERROR_INVALID_PARAMETER
;
1462 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1464 ObDereferenceObject(Thread
);
1465 DPRINT("Thread is not a GUI Thread!\n");
1466 return ERROR_INVALID_PARAMETER
;
1469 Current
= W32Thread
->WindowListHead
.Flink
;
1470 while(Current
!= &(W32Thread
->WindowListHead
))
1472 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1475 if(bChildren
|| Window
->hOwner
!= NULL
)
1477 if(dwCount
< *pBufSize
&& pWnd
)
1479 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1480 if(!NT_SUCCESS(Status
))
1482 SetLastNtError(Status
);
1488 Current
= Current
->Flink
;
1491 ObDereferenceObject(Thread
);
1494 *pBufSize
= dwCount
;
1495 return STATUS_SUCCESS
;
1503 NtUserChildWindowFromPointEx(HWND hwndParent
,
1508 PWINDOW_OBJECT Parent
;
1513 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1521 if(Parent
->hSelf
!= IntGetDesktopWindow())
1523 Pt
.x
+= Parent
->Wnd
->rcClient
.left
;
1524 Pt
.y
+= Parent
->Wnd
->rcClient
.top
;
1527 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1532 Ret
= Parent
->hSelf
;
1533 if((List
= IntWinListChildren(Parent
)))
1535 for(phWnd
= List
; *phWnd
; phWnd
++)
1537 PWINDOW_OBJECT Child
;
1539 if((Child
= UserGetWindowObject(*phWnd
)))
1541 ChildWnd
= Child
->Wnd
;
1542 if(!(ChildWnd
->style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1546 if((ChildWnd
->style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1550 if((ChildWnd
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1554 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1569 * calculates the default position of a window
1572 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT Window
, RECTL
*rc
, BOOL IncPos
)
1579 RECTL_bIntersectRect(rc
, rc
, &Parent
->Wnd
->rcClient
);
1583 Pos
.x
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1584 Pos
.y
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1585 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1586 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1588 /* reset counter and position */
1591 Parent
->TiledCounter
= 0;
1593 Parent
->TiledCounter
++;
1604 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1605 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1609 rc
->right
= rc
->left
+ Sz
.cx
;
1610 rc
->bottom
= rc
->top
+ Sz
.cy
;
1619 co_IntCreateWindowEx(DWORD dwExStyle
,
1620 PUNICODE_STRING ClassName
,
1621 PUNICODE_STRING WindowName
,
1629 HINSTANCE hInstance
,
1632 BOOL bUnicodeWindow
)
1634 PWINSTATION_OBJECT WinSta
;
1636 PCLS
*ClassLink
, Class
= NULL
;
1638 PWINDOW_OBJECT Window
= NULL
;
1639 PWINDOW_OBJECT ParentWindow
= NULL
, OwnerWindow
;
1640 HWND ParentWindowHandle
= NULL
;
1641 HWND OwnerWindowHandle
;
1642 PMENU_OBJECT SystemMenu
;
1646 PTHREADINFO ti
= NULL
;
1649 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1655 CBT_CREATEWNDW CbtCreate
;
1658 DECLARE_RETURN(PWND
);
1660 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1663 pti
= PsGetCurrentThreadWin32Thread();
1667 ParentWindowHandle
= pti
->Desktop
->DesktopWindow
;
1671 if ( !(pti
->ppi
->W32PF_flags
& W32PF_CLASSESREGISTERED
))
1673 UserRegisterSystemClasses();
1676 OwnerWindowHandle
= NULL
;
1678 DPRINT("co_IntCreateWindowEx %wZ\n", ClassName
);
1680 if (hWndParent
== HWND_MESSAGE
)
1683 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1684 * message window (style: WS_POPUP|WS_DISABLED)
1686 ParentWindowHandle
= IntGetMessageWindow();
1687 DPRINT("Parent is HWND_MESSAGE 0x%x\n", ParentWindowHandle
);
1689 else if (hWndParent
)
1691 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1693 PWINDOW_OBJECT Par
= UserGetWindowObject(hWndParent
), Root
;
1694 if (Par
&& (Root
= UserGetAncestor(Par
, GA_ROOT
)))
1695 OwnerWindowHandle
= Root
->hSelf
;
1698 ParentWindowHandle
= hWndParent
;
1700 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1702 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1703 RETURN( (PWND
)0); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1706 if (ParentWindowHandle
)
1708 ParentWindow
= UserGetWindowObject(ParentWindowHandle
);
1710 if (ParentWindow
) UserRefObjectCo(ParentWindow
, &ParentRef
);
1714 ParentWindow
= NULL
;
1717 /* FIXME: parent must belong to the current process */
1719 /* Check the window station. */
1720 ti
= GetW32ThreadInfo();
1721 if (ti
== NULL
|| pti
->Desktop
== NULL
)
1723 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1727 /* Check the class. */
1729 DPRINT("Class %wZ\n", ClassName
);
1731 ClassAtom
= IntGetClassAtom(ClassName
,
1737 if (ClassAtom
== (RTL_ATOM
)0)
1739 if (IS_ATOM(ClassName
->Buffer
))
1741 DPRINT1("Class 0x%p not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1745 DPRINT1("Class \"%wZ\" not found\n", ClassName
);
1748 SetLastWin32Error(ERROR_CANNOT_FIND_WND_CLASS
);
1751 DPRINT("ClassAtom %x\n", ClassAtom
);
1752 Class
= IntReferenceClass(Class
,
1757 DPRINT1("Failed to reference window class!\n");
1761 WinSta
= pti
->Desktop
->WindowStation
;
1763 //FIXME: Reference thread/desktop instead
1764 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1766 /* Create the window object. */
1767 Window
= (PWINDOW_OBJECT
) UserCreateObject( gHandleTable
,
1770 sizeof(WINDOW_OBJECT
));
1773 Window
->Wnd
= DesktopHeapAlloc(pti
->Desktop
,
1774 sizeof(WND
) + Class
->cbwndExtra
);
1777 RtlZeroMemory(Window
->Wnd
,
1778 sizeof(WND
) + Class
->cbwndExtra
);
1779 Window
->Wnd
->head
.h
= hWnd
;
1784 Wnd
->head
.rpdesk
= pti
->Desktop
;
1785 Wnd
->hWndLastActive
= hWnd
;
1786 Wnd
->state2
|= WNDS2_WIN40COMPAT
;
1789 DPRINT("Created object with handle %X\n", hWnd
);
1793 ObDereferenceObject(WinSta
);
1794 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1798 UserRefObjectCo(Window
, &Ref
);
1800 ObDereferenceObject(WinSta
);
1802 if (NULL
== pti
->Desktop
->DesktopWindow
)
1804 /* If there is no desktop window yet, we must be creating it */
1805 pti
->Desktop
->DesktopWindow
= hWnd
;
1806 pti
->Desktop
->DesktopInfo
->Wnd
= Wnd
;
1810 * Fill out the structure describing it.
1816 Window
->SystemMenu
= (HMENU
)0;
1818 Wnd
->hModule
= hInstance
;
1819 Window
->hSelf
= hWnd
;
1821 Window
->MessageQueue
= pti
->MessageQueue
;
1822 IntReferenceMessageQueue(Window
->MessageQueue
);
1823 Window
->Parent
= ParentWindow
;
1824 Wnd
->spwndParent
= ParentWindow
? ParentWindow
->Wnd
: NULL
;
1825 if (Wnd
->spwndParent
!= NULL
&& hWndParent
!= 0)
1827 Wnd
->HideFocus
= Wnd
->spwndParent
->HideFocus
;
1828 Wnd
->HideAccel
= Wnd
->spwndParent
->HideAccel
;
1831 if((OwnerWindow
= UserGetWindowObject(OwnerWindowHandle
)))
1833 Window
->hOwner
= OwnerWindowHandle
;
1834 Wnd
->spwndOwner
= OwnerWindow
->Wnd
;
1839 Window
->hOwner
= NULL
;
1840 Wnd
->spwndOwner
= NULL
;
1844 Wnd
->dwUserData
= 0;
1846 if (Wnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1847 Wnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1849 /* BugBoy Comments: Comment below say that System classes are always created
1850 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1851 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1853 No where can I see in code or through testing does the window change back
1854 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1855 see what problems this would cause.*/
1857 // Set WndProc from Class.
1858 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
1860 // GetWindowProc, test for non server side default classes and set WndProc.
1861 if ( Wnd
->pcls
->fnid
<= FNID_GHOST
&& Wnd
->pcls
->fnid
>= FNID_BUTTON
)
1865 if (GETPFNCLIENTA(Wnd
->pcls
->fnid
) == Wnd
->lpfnWndProc
)
1866 Wnd
->lpfnWndProc
= GETPFNCLIENTW(Wnd
->pcls
->fnid
);
1870 if (GETPFNCLIENTW(Wnd
->pcls
->fnid
) == Wnd
->lpfnWndProc
)
1871 Wnd
->lpfnWndProc
= GETPFNCLIENTA(Wnd
->pcls
->fnid
);
1875 // If not an Unicode caller, set Ansi creator bit.
1876 if (!bUnicodeWindow
) Wnd
->state
|= WNDS_ANSICREATOR
;
1878 // Clone Class Ansi/Unicode proc type.
1879 if (Wnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1881 Wnd
->state
|= WNDS_ANSIWINDOWPROC
;
1882 Wnd
->Unicode
= FALSE
;
1886 It seems there can be both an Ansi creator and Unicode Class Window
1887 WndProc, unless the following overriding conditions occur:
1889 if ( !bUnicodeWindow
&&
1890 ( ClassAtom
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1891 ClassAtom
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1892 ClassAtom
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1893 ClassAtom
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1894 ClassAtom
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1895 ClassAtom
== gpsi
->atomSysClass
[ICLS_IME
] ||
1896 ClassAtom
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1897 ClassAtom
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1898 ClassAtom
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1899 { // Override Class and set the window Ansi WndProc.
1900 Wnd
->state
|= WNDS_ANSIWINDOWPROC
;
1901 Wnd
->Unicode
= FALSE
;
1904 { // Set the window Unicode WndProc.
1905 Wnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1906 Wnd
->Unicode
= TRUE
;
1910 Window
->OwnerThread
= PsGetCurrentThread();
1911 Window
->FirstChild
= NULL
;
1912 Window
->LastChild
= NULL
;
1913 Window
->PrevSibling
= NULL
;
1914 Window
->NextSibling
= NULL
;
1915 Wnd
->cbwndExtra
= Wnd
->pcls
->cbwndExtra
;
1917 InitializeListHead(&Wnd
->PropListHead
);
1918 InitializeListHead(&Window
->WndObjListHead
);
1920 if ( NULL
!= WindowName
->Buffer
&& WindowName
->Length
> 0 )
1922 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
1923 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1924 if (Wnd
->strName
.Buffer
== NULL
)
1926 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1930 Wnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1933 RtlCopyMemory(Wnd
->strName
.Buffer
,
1935 WindowName
->Length
);
1936 Wnd
->strName
.Length
= WindowName
->Length
;
1938 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1940 WindowName
->Length
= 0;
1941 Wnd
->strName
.Buffer
[0] = L
'\0';
1947 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1948 * tested for WS_POPUP
1950 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1951 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1952 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1953 dwExStyle
|= WS_EX_WINDOWEDGE
;
1955 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1957 /* Correct the window style. */
1958 if (!(dwStyle
& WS_CHILD
))
1960 dwStyle
|= WS_CLIPSIBLINGS
;
1961 DPRINT("3: Style is now %lx\n", dwStyle
);
1962 if (!(dwStyle
& WS_POPUP
))
1964 dwStyle
|= WS_CAPTION
;
1965 Window
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1966 DPRINT("4: Style is now %lx\n", dwStyle
);
1970 /* create system menu */
1971 if((dwStyle
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1973 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
1976 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1977 IntReleaseMenuObject(SystemMenu
);
1981 /* Set the window menu */
1982 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1985 IntSetMenu(Window
, hMenu
, &MenuChanged
);
1986 else if (Wnd
->pcls
->lpszMenuName
) // Take it from the parent.
1988 UNICODE_STRING MenuName
;
1989 if (IS_INTRESOURCE(Wnd
->pcls
->lpszMenuName
))
1991 MenuName
.Length
= 0;
1992 MenuName
.MaximumLength
= 0;
1993 MenuName
.Buffer
= Wnd
->pcls
->lpszMenuName
;
1997 RtlInitUnicodeString( &MenuName
, Wnd
->pcls
->lpszMenuName
);
1999 hMenu
= co_IntCallLoadMenu( Wnd
->pcls
->hModule
, &MenuName
);
2000 if (hMenu
) IntSetMenu(Window
, hMenu
, &MenuChanged
);
2004 Wnd
->IDMenu
= (UINT
) hMenu
;
2006 /* Insert the window into the thread's window list. */
2007 InsertTailList (&pti
->WindowListHead
, &Window
->ThreadListEntry
);
2009 /* Handle "CS_CLASSDC", it is tested first. */
2010 if ((Wnd
->pcls
->style
& CS_CLASSDC
) && !(Wnd
->pcls
->pdce
)) // One DCE per class to have CLASS.
2011 Wnd
->pcls
->pdce
= DceAllocDCE(Window
, DCE_CLASS_DC
);
2012 /* Allocate a DCE for this window. */
2013 else if ( Wnd
->pcls
->style
& CS_OWNDC
)
2014 Window
->Dce
= DceAllocDCE(Window
, DCE_WINDOW_DC
);
2021 Wnd
->ExStyle
= dwExStyle
;
2022 Wnd
->style
= dwStyle
& ~WS_VISIBLE
;
2025 Cs
.lpCreateParams
= lpParam
;
2026 Cs
.hInstance
= hInstance
;
2028 Cs
.hwndParent
= hWndParent
; //Pass the original Parent handle!
2033 Cs
.style
= Wnd
->style
;
2034 // Cs.lpszName = (LPCWSTR) WindowName->Buffer;
2035 // Cs.lpszClass = (LPCWSTR) ClassName->Buffer;
2036 Cs
.lpszName
= (LPCWSTR
) WindowName
;
2037 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
2038 Cs
.dwExStyle
= dwExStyle
;
2039 CbtCreate
.lpcs
= &Cs
;
2040 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
2041 if (ISITHOOKED(WH_CBT
))
2043 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) &CbtCreate
))
2045 /* FIXME - Delete window object and remove it from the thread windows list */
2046 /* FIXME - delete allocated DCE */
2047 DPRINT1("CBT-hook returned !0\n");
2048 RETURN( (PWND
) NULL
);
2055 // FIXME: Need to set the Z order in the window link list if the hook callback changed it!
2056 // hwndInsertAfter = CbtCreate.hwndInsertAfter;
2058 /* default positioning for overlapped windows */
2059 if(!(Wnd
->style
& (WS_POPUP
| WS_CHILD
)))
2062 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
2063 BOOL CalculatedDefPosSize
= FALSE
;
2065 IntGetDesktopWorkArea(((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
, &WorkArea
);
2068 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
2070 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
2072 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, Window
, &rc
, TRUE
);
2074 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
2076 ProcessParams
->WindowFlags
&= ~STARTF_USEPOSITION
;
2077 Pos
.x
= WorkArea
.left
+ ProcessParams
->StartingX
;
2078 Pos
.y
= WorkArea
.top
+ ProcessParams
->StartingY
;
2087 According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
2088 y is something else. and Quote!
2091 /* Never believe Microsoft's documentation... CreateWindowEx doc says
2092 * that if an overlapped window is created with WS_VISIBLE style bit
2093 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
2094 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
2097 * 1) not only it checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
2098 * 2) it does not ignore the y parameter as the docs claim; instead, it
2099 * uses it as second parameter to ShowWindow() unless y is either
2100 * CW_USEDEFAULT or CW_USEDEFAULT16.
2102 * The fact that we didn't do 2) caused bogus windows pop up when wine
2103 * was running apps that were using this obscure feature. Example -
2104 * calc.exe that comes with Win98 (only Win98, it's different from
2105 * the one that comes with Win95 and NT)
2107 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
2112 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
2114 if(!CalculatedDefPosSize
)
2116 IntCalcDefPosSize(ParentWindow
, Window
, &rc
, FALSE
);
2118 if(ProcessParams
->WindowFlags
& STARTF_USESIZE
)
2120 ProcessParams
->WindowFlags
&= ~STARTF_USESIZE
;
2121 Size
.cx
= ProcessParams
->CountX
;
2122 Size
.cy
= ProcessParams
->CountY
;
2126 Size
.cx
= rc
.right
- rc
.left
;
2127 Size
.cy
= rc
.bottom
- rc
.top
;
2130 /* move the window if necessary */
2132 Pos
.x
= max(rc
.left
, 0);
2134 Pos
.y
= max(rc
.top
, 0);
2139 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
2140 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
2145 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
2152 /* Initialize the window dimensions. */
2153 Wnd
->rcWindow
.left
= Pos
.x
;
2154 Wnd
->rcWindow
.top
= Pos
.y
;
2155 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
2156 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
2157 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2159 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2160 ParentWindow
->Wnd
->rcClient
.top
);
2162 Wnd
->rcClient
= Wnd
->rcWindow
;
2165 * Get the size and position of the window.
2167 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
2169 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2171 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
2172 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
,
2174 if (MaxSize
.x
< Size
.cx
)
2175 Size
.cx
= MaxSize
.x
;
2176 if (MaxSize
.y
< Size
.cy
)
2177 Size
.cy
= MaxSize
.y
;
2178 if (Size
.cx
< MinTrack
.x
)
2179 Size
.cx
= MinTrack
.x
;
2180 if (Size
.cy
< MinTrack
.y
)
2181 Size
.cy
= MinTrack
.y
;
2188 Wnd
->rcWindow
.left
= Pos
.x
;
2189 Wnd
->rcWindow
.top
= Pos
.y
;
2190 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
2191 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
2192 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2194 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2195 ParentWindow
->Wnd
->rcClient
.top
);
2197 Wnd
->rcClient
= Wnd
->rcWindow
;
2199 /* FIXME: Initialize the window menu. */
2201 /* Send a NCCREATE message. */
2207 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
2208 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, Size
.cx
, Size
.cy
);
2209 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
2210 Result
= co_IntSendMessage(Window
->hSelf
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
2213 /* FIXME: Cleanup. */
2214 DPRINT1("IntCreateWindowEx(): NCCREATE message failed. No cleanup performed!\n");
2218 /* Calculate the non-client size. */
2219 MaxPos
.x
= Window
->Wnd
->rcWindow
.left
;
2220 MaxPos
.y
= Window
->Wnd
->rcWindow
.top
;
2223 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
2224 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
2225 Result
= co_WinPosGetNonClientSize(Window
,
2226 &Window
->Wnd
->rcWindow
,
2227 &Window
->Wnd
->rcClient
);
2229 RECTL_vOffsetRect(&Window
->Wnd
->rcWindow
,
2230 MaxPos
.x
- Window
->Wnd
->rcWindow
.left
,
2231 MaxPos
.y
- Window
->Wnd
->rcWindow
.top
);
2234 if (NULL
!= ParentWindow
)
2236 /* link the window into the parent's child list */
2237 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2239 PWINDOW_OBJECT PrevSibling
;
2241 PrevSibling
= ParentWindow
->LastChild
;
2243 /* link window as bottom sibling */
2244 IntLinkWindow(Window
, ParentWindow
, PrevSibling
/*prev sibling*/);
2248 /* link window as top sibling (but after topmost siblings) */
2249 PWINDOW_OBJECT InsertAfter
, Sibling
;
2250 if (!(dwExStyle
& WS_EX_TOPMOST
))
2253 Sibling
= ParentWindow
->FirstChild
;
2254 while (Sibling
&& (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
2256 InsertAfter
= Sibling
;
2257 Sibling
= Sibling
->NextSibling
;
2265 IntLinkWindow(Window
, ParentWindow
, InsertAfter
/* prev sibling */);
2270 /* Send the WM_CREATE message. */
2271 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
2272 Result
= co_IntSendMessage(Window
->hSelf
, WM_CREATE
, 0, (LPARAM
) &Cs
);
2274 if (Result
== (LRESULT
)-1)
2276 /* FIXME: Cleanup. */
2277 DPRINT1("IntCreateWindowEx(): send CREATE message failed. No cleanup performed!\n");
2278 IntUnlinkWindow(Window
);
2282 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
->Wnd
, OBJID_WINDOW
, 0);
2284 /* Send move and size messages. */
2285 if (!(Window
->Flags
& WINDOWOBJECT_NEED_SIZE
))
2289 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
2291 if ((Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
) < 0 ||
2292 (Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
) < 0)
2294 DPRINT("Sending bogus WM_SIZE\n");
2297 lParam
= MAKE_LONG(Window
->Wnd
->rcClient
.right
-
2298 Window
->Wnd
->rcClient
.left
,
2299 Window
->Wnd
->rcClient
.bottom
-
2300 Window
->Wnd
->rcClient
.top
);
2301 co_IntSendMessage(Window
->hSelf
, WM_SIZE
, SIZE_RESTORED
,
2304 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
2306 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2308 lParam
= MAKE_LONG(Wnd
->rcClient
.left
- ParentWindow
->Wnd
->rcClient
.left
,
2309 Wnd
->rcClient
.top
- ParentWindow
->Wnd
->rcClient
.top
);
2313 lParam
= MAKE_LONG(Wnd
->rcClient
.left
,
2317 co_IntSendMessage(Window
->hSelf
, WM_MOVE
, 0, lParam
);
2319 /* Call WNDOBJ change procs */
2320 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
2323 /* Show or maybe minimize or maximize the window. */
2324 if (Wnd
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2329 SwFlag
= (Wnd
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
2332 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2334 SwFlag
= ((Wnd
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2335 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2336 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2338 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
2339 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
2340 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2341 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2344 /* Notify the parent window of a new child. */
2345 if ((Wnd
->style
& WS_CHILD
) &&
2346 (!(Wnd
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
2348 DPRINT("IntCreateWindow(): About to notify parent\n");
2349 co_IntSendMessage(ParentWindow
->hSelf
,
2351 MAKEWPARAM(WM_CREATE
, Wnd
->IDMenu
),
2352 (LPARAM
)Window
->hSelf
);
2355 if ((!hWndParent
) && (!HasOwner
))
2357 DPRINT("Sending CREATED notify\n");
2358 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2362 DPRINT("Not sending CREATED notify, %x %d\n", ParentWindow
, HasOwner
);
2365 /* Initialize and show the window's scrollbars */
2366 if (Wnd
->style
& WS_VSCROLL
)
2368 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2370 if (Wnd
->style
& WS_HSCROLL
)
2372 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2375 if (dwStyle
& WS_VISIBLE
)
2377 if (Wnd
->style
& WS_MAXIMIZE
)
2378 dwShowMode
= SW_SHOW
;
2379 else if (Wnd
->style
& WS_MINIMIZE
)
2380 dwShowMode
= SW_SHOWMINIMIZED
;
2382 DPRINT("IntCreateWindow(): About to show window\n");
2383 co_WinPosShowWindow(Window
, dwShowMode
);
2385 if (Wnd
->ExStyle
& WS_EX_MDICHILD
)
2387 co_IntSendMessage(ParentWindow
->hSelf
, WM_MDIREFRESHMENU
, 0, 0);
2388 /* ShowWindow won't activate child windows */
2389 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2393 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
2394 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
2395 Dont understand why it does this. */
2396 if (ClassAtom
== gpsi
->atomSysClass
[ICLS_EDIT
])
2398 PCALLPROCDATA CallProc
;
2399 //CallProc = CreateCallProc(NULL, Wnd->lpfnWndProc, bUnicodeWindow, Wnd->ti->ppi);
2400 CallProc
= CreateCallProc(NULL
, Wnd
->lpfnWndProc
, Wnd
->Unicode
, Wnd
->head
.pti
->ppi
);
2404 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2405 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
2409 UserAddCallProcToClass(Wnd
->pcls
, CallProc
);
2413 DPRINT("IntCreateWindow(): = %X\n", hWnd
);
2414 DPRINT("WindowObject->SystemMenu = 0x%x\n", Window
->SystemMenu
);
2418 if (!_ret_
&& Window
&& Window
->Wnd
&& ti
)
2419 UserFreeWindowInfo(ti
, Window
);
2422 UserDerefObjectCo(Window
);
2423 UserDereferenceObject(Window
);
2425 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2426 if (!_ret_
&& ti
!= NULL
)
2430 IntDereferenceClass(Class
,
2439 NtUserCreateWindowEx(DWORD dwExStyle
,
2440 PUNICODE_STRING UnsafeClassName
,
2441 PUNICODE_STRING UnsafeWindowName
,
2449 HINSTANCE hInstance
,
2452 BOOL bUnicodeWindow
,
2456 UNICODE_STRING WindowName
;
2457 UNICODE_STRING ClassName
;
2458 HWND NewWindow
= NULL
;
2460 DECLARE_RETURN(HWND
);
2462 DPRINT("Enter NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2463 UserEnterExclusive();
2465 /* Get the class name (string or atom) */
2466 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
2467 if (! NT_SUCCESS(Status
))
2469 SetLastNtError(Status
);
2472 if (ClassName
.Length
!= 0)
2474 Status
= IntSafeCopyUnicodeStringTerminateNULL(&ClassName
, UnsafeClassName
);
2475 if (! NT_SUCCESS(Status
))
2477 SetLastNtError(Status
);
2481 else if (! IS_ATOM(ClassName
.Buffer
))
2483 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2487 /* safely copy the window name */
2488 if (NULL
!= UnsafeWindowName
)
2490 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
2491 if (! NT_SUCCESS(Status
))
2493 if (! IS_ATOM(ClassName
.Buffer
))
2495 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2497 SetLastNtError(Status
);
2503 RtlInitUnicodeString(&WindowName
, NULL
);
2506 pNewWindow
= co_IntCreateWindowEx( dwExStyle
,
2521 if (pNewWindow
) NewWindow
= UserHMGetHandle(pNewWindow
);
2523 if (WindowName
.Buffer
)
2525 ExFreePoolWithTag(WindowName
.Buffer
, TAG_STRING
);
2527 if (! IS_ATOM(ClassName
.Buffer
))
2529 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2535 DPRINT("Leave NtUserCreateWindowEx, ret=%i\n",_ret_
);
2544 NtUserDeferWindowPos(HDWP WinPosInfo
,
2546 HWND WndInsertAfter
,
2559 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2565 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2567 hWnd
= Window
->hSelf
;
2571 if (!Wnd
) return TRUE
; // FIXME: Need to finish object rewrite or lock the thread when killing the window!
2573 DPRINT("co_UserDestroyWindow \n");
2575 /* Check for owner thread */
2576 if ((Window
->OwnerThread
!= PsGetCurrentThread()))
2578 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2583 if (ISITHOOKED(WH_CBT
))
2585 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0)) return FALSE
;
2588 /* Look whether the focus is within the tree of windows we will
2591 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2593 if (UserGetActiveWindow() == Window
->hSelf
)
2595 co_WinPosActivateOtherWindow(Window
);
2599 if (Window
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2600 Window
->MessageQueue
->ActiveWindow
= NULL
;
2601 if (Window
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2602 Window
->MessageQueue
->FocusWindow
= NULL
;
2603 if (Window
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2604 Window
->MessageQueue
->CaptureWindow
= NULL
;
2606 IntDereferenceMessageQueue(Window
->MessageQueue
);
2608 IntEngWindowChanged(Window
, WOC_DELETE
);
2609 isChild
= (0 != (Wnd
->style
& WS_CHILD
));
2615 if (! USER_IsExitingThread(GetCurrentThreadId()))
2617 send_parent_notify(hwnd
, WM_DESTROY
);
2620 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2622 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2623 /* FIXME: clean up palette - see "Internals" p.352 */
2627 if (!IntIsWindow(Window
->hSelf
))
2632 /* Recursively destroy owned windows */
2637 BOOL GotOne
= FALSE
;
2640 PWINDOW_OBJECT Child
, Desktop
;
2642 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2643 UserGetWindowObject(IntGetDesktopWindow());
2644 Children
= IntWinListChildren(Desktop
);
2648 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2650 Child
= UserGetWindowObject(*ChildHandle
);
2653 if (Child
->hOwner
!= Window
->hSelf
)
2658 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2660 USER_REFERENCE_ENTRY ChildRef
;
2661 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2662 co_UserDestroyWindow(Child
);
2663 UserDerefObjectCo(Child
);//temp hack?
2669 if (Child
->hOwner
!= NULL
)
2671 Child
->hOwner
= NULL
;
2672 Child
->Wnd
->spwndOwner
= NULL
;
2676 ExFreePool(Children
);
2685 if (!IntIsWindow(Window
->hSelf
))
2690 /* Destroy the window storage */
2691 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2701 NtUserDestroyWindow(HWND Wnd
)
2703 PWINDOW_OBJECT Window
;
2704 DECLARE_RETURN(BOOLEAN
);
2706 USER_REFERENCE_ENTRY Ref
;
2708 DPRINT("Enter NtUserDestroyWindow\n");
2709 UserEnterExclusive();
2711 if (!(Window
= UserGetWindowObject(Wnd
)))
2716 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2717 ret
= co_UserDestroyWindow(Window
);
2718 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2723 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2735 NtUserDrawMenuBarTemp(
2742 /* we'll use this function just for caching the menu bar */
2752 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2762 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2768 NtUserFillWindow(HWND hWndPaint
,
2779 static HWND FASTCALL
2780 IntFindWindow(PWINDOW_OBJECT Parent
,
2781 PWINDOW_OBJECT ChildAfter
,
2783 PUNICODE_STRING WindowName
)
2785 BOOL CheckWindowName
;
2791 CheckWindowName
= WindowName
->Length
!= 0;
2793 if((List
= IntWinListChildren(Parent
)))
2798 /* skip handles before and including ChildAfter */
2799 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2803 /* search children */
2806 PWINDOW_OBJECT Child
;
2807 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2812 /* Do not send WM_GETTEXT messages in the kernel mode version!
2813 The user mode version however calls GetWindowText() which will
2814 send WM_GETTEXT messages to windows belonging to its processes */
2815 if((!CheckWindowName
|| !RtlCompareUnicodeString(WindowName
, &(Child
->Wnd
->strName
), TRUE
)) &&
2816 (!ClassAtom
|| Child
->Wnd
->pcls
->atomClassName
== ClassAtom
))
2831 * Searches a window's children for a window with the specified
2834 * hwndParent = The window whose childs are to be searched.
2836 * HWND_MESSAGE = message-only windows
2838 * hwndChildAfter = Search starts after this child window.
2839 * NULL = start from beginning
2841 * ucClassName = Class name to search for
2842 * Reguired parameter.
2844 * ucWindowName = Window name
2845 * ->Buffer == NULL = don't care
2848 * The HWND of the window if it was found, otherwise NULL
2854 NtUserFindWindowEx(HWND hwndParent
,
2855 HWND hwndChildAfter
,
2856 PUNICODE_STRING ucClassName
,
2857 PUNICODE_STRING ucWindowName
,
2860 PWINDOW_OBJECT Parent
, ChildAfter
;
2861 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2862 HWND Desktop
, Ret
= NULL
;
2863 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2864 DECLARE_RETURN(HWND
);
2866 DPRINT("Enter NtUserFindWindowEx\n");
2869 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2873 if (ucClassName
!= NULL
)
2875 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2876 if (ClassName
.Length
!= 0)
2878 ProbeForRead(ClassName
.Buffer
,
2882 else if (!IS_ATOM(ClassName
.Buffer
))
2884 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2888 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2895 if (ucWindowName
!= NULL
)
2897 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2898 if (WindowName
.Length
!= 0)
2900 ProbeForRead(WindowName
.Buffer
,
2906 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2908 SetLastNtError(_SEH2_GetExceptionCode());
2909 _SEH2_YIELD(RETURN(NULL
));
2913 if (ucClassName
!= NULL
)
2915 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2916 !IS_ATOM(ClassName
.Buffer
))
2918 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2921 else if (ClassAtom
== (RTL_ATOM
)0)
2923 /* LastError code was set by IntGetAtomFromStringOrAtom */
2929 Desktop
= IntGetCurrentThreadDesktopWindow();
2931 if(hwndParent
== NULL
)
2932 hwndParent
= Desktop
;
2933 else if(hwndParent
== HWND_MESSAGE
)
2935 hwndParent
= IntGetMessageWindow();
2938 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2944 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2951 if(Parent
->hSelf
== Desktop
)
2954 PWINDOW_OBJECT TopLevelWindow
;
2955 BOOLEAN CheckWindowName
;
2956 BOOLEAN WindowMatches
;
2957 BOOLEAN ClassMatches
;
2959 /* windows searches through all top-level windows if the parent is the desktop
2962 if((List
= IntWinListChildren(Parent
)))
2968 /* skip handles before and including ChildAfter */
2969 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2973 CheckWindowName
= WindowName
.Length
!= 0;
2975 /* search children */
2978 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2983 /* Do not send WM_GETTEXT messages in the kernel mode version!
2984 The user mode version however calls GetWindowText() which will
2985 send WM_GETTEXT messages to windows belonging to its processes */
2986 WindowMatches
= !CheckWindowName
|| !RtlCompareUnicodeString(
2987 &WindowName
, &TopLevelWindow
->Wnd
->strName
, TRUE
);
2988 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2989 ClassAtom
== TopLevelWindow
->Wnd
->pcls
->atomClassName
;
2991 if (WindowMatches
&& ClassMatches
)
2993 Ret
= TopLevelWindow
->hSelf
;
2997 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2999 /* window returns the handle of the top-level window, in case it found
3001 Ret
= TopLevelWindow
->hSelf
;
3010 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3014 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
3016 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
3017 search the message-only windows. Should this also be done if
3018 Parent is the desktop window??? */
3019 PWINDOW_OBJECT MsgWindows
;
3021 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3023 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3028 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3030 SetLastNtError(_SEH2_GetExceptionCode());
3038 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
3048 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
3059 PWINDOW_OBJECT FASTCALL
UserGetAncestor(PWINDOW_OBJECT Wnd
, UINT Type
)
3061 PWINDOW_OBJECT WndAncestor
, Parent
;
3063 if (Wnd
->hSelf
== IntGetDesktopWindow())
3072 WndAncestor
= Wnd
->Parent
;
3083 if(!(Parent
= WndAncestor
->Parent
))
3087 if(IntIsDesktopWindow(Parent
))
3092 WndAncestor
= Parent
;
3103 PWINDOW_OBJECT Parent
, Old
;
3106 Parent
= IntGetParent(WndAncestor
);
3114 // UserDereferenceObject(Parent);
3116 WndAncestor
= Parent
;
3134 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3136 PWINDOW_OBJECT Window
, Ancestor
;
3137 DECLARE_RETURN(HWND
);
3139 DPRINT("Enter NtUserGetAncestor\n");
3140 UserEnterExclusive();
3142 if (!(Window
= UserGetWindowObject(hWnd
)))
3147 Ancestor
= UserGetAncestor(Window
, Type
);
3148 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3150 RETURN(Ancestor
? Ancestor
->hSelf
: NULL
);
3153 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3161 NtUserGetComboBoxInfo(
3166 DECLARE_RETURN(BOOL
);
3168 DPRINT("Enter NtUserGetComboBoxInfo\n");
3171 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3180 sizeof(COMBOBOXINFO
),
3184 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3186 SetLastNtError(_SEH2_GetExceptionCode());
3187 _SEH2_YIELD(RETURN(FALSE
));
3191 // Pass the user pointer, it was already probed.
3192 RETURN( (BOOL
) co_IntSendMessage( Wnd
->hSelf
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3195 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3205 NtUserGetInternalWindowPos( HWND hWnd
,
3209 PWINDOW_OBJECT Window
;
3213 WINDOWPLACEMENT wndpl
;
3217 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3228 ProbeForWrite(rectWnd
,
3234 ProbeForWrite(ptIcon
,
3240 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3242 SetLastNtError(_SEH2_GetExceptionCode());
3247 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3249 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3255 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3259 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3263 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3265 SetLastNtError(_SEH2_GetExceptionCode());
3270 if (!Hit
) Ret
= wndpl
.showCmd
;
3279 NtUserGetListBoxInfo(
3283 DECLARE_RETURN(DWORD
);
3285 DPRINT("Enter NtUserGetListBoxInfo\n");
3288 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3293 RETURN( (DWORD
) co_IntSendMessage( Wnd
->hSelf
, LB_GETLISTBOXINFO
, 0, 0 ));
3296 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3303 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3305 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3306 HWND hWndOldParent
= NULL
;
3307 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3309 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3311 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3315 if (hWndChild
== IntGetDesktopWindow())
3317 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3323 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3330 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3336 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3341 UserRefObjectCo(Wnd
, &Ref
);
3342 UserRefObjectCo(WndParent
, &ParentRef
);
3344 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3346 UserDerefObjectCo(WndParent
);
3347 UserDerefObjectCo(Wnd
);
3351 hWndOldParent
= WndOldParent
->hSelf
;
3352 UserDereferenceObject(WndOldParent
);
3355 return( hWndOldParent
);
3361 * The NtUserSetParent function changes the parent window of the specified
3365 * The new parent window and the child window must belong to the same
3366 * application. If the window identified by the hWndChild parameter is
3367 * visible, the system performs the appropriate redrawing and repainting.
3368 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3369 * or WS_POPUP window styles of the window whose parent is being changed.
3376 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3378 DECLARE_RETURN(HWND
);
3380 DPRINT("Enter NtUserSetParent\n");
3381 UserEnterExclusive();
3384 Check Parent first from user space, set it here.
3388 hWndNewParent
= IntGetDesktopWindow();
3390 else if (hWndNewParent
== HWND_MESSAGE
)
3392 hWndNewParent
= IntGetMessageWindow();
3395 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3398 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3404 * UserGetShellWindow
3406 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3411 HWND FASTCALL
UserGetShellWindow(VOID
)
3413 PWINSTATION_OBJECT WinStaObject
;
3416 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3421 if (!NT_SUCCESS(Status
))
3423 SetLastNtError(Status
);
3427 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3429 ObDereferenceObject(WinStaObject
);
3434 * NtUserSetShellWindowEx
3436 * This is undocumented function to set global shell window. The global
3437 * shell window has special handling of window position.
3443 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3445 PWINSTATION_OBJECT WinStaObject
;
3446 PWINDOW_OBJECT WndShell
;
3447 DECLARE_RETURN(BOOL
);
3448 USER_REFERENCE_ENTRY Ref
;
3452 DPRINT("Enter NtUserSetShellWindowEx\n");
3453 UserEnterExclusive();
3455 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3460 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3465 if (!NT_SUCCESS(Status
))
3467 SetLastNtError(Status
);
3472 * Test if we are permitted to change the shell window.
3474 if (WinStaObject
->ShellWindow
)
3476 ObDereferenceObject(WinStaObject
);
3481 * Move shell window into background.
3483 if (hwndListView
&& hwndListView
!= hwndShell
)
3486 * Disabled for now to get Explorer working.
3487 * -- Filip, 01/nov/2003
3490 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3493 if (UserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3495 ObDereferenceObject(WinStaObject
);
3500 if (UserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3502 ObDereferenceObject(WinStaObject
);
3506 UserRefObjectCo(WndShell
, &Ref
);
3507 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3509 WinStaObject
->ShellWindow
= hwndShell
;
3510 WinStaObject
->ShellListView
= hwndListView
;
3512 ti
= GetW32ThreadInfo();
3513 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3515 UserDerefObjectCo(WndShell
);
3517 ObDereferenceObject(WinStaObject
);
3521 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3527 * NtUserGetSystemMenu
3529 * The NtUserGetSystemMenu function allows the application to access the
3530 * window menu (also known as the system menu or the control menu) for
3531 * copying and modifying.
3535 * Handle to the window that will own a copy of the window menu.
3537 * Specifies the action to be taken. If this parameter is FALSE,
3538 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3539 * currently in use. The copy is initially identical to the window menu
3540 * but it can be modified.
3541 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3542 * to the default state. The previous window menu, if any, is destroyed.
3545 * If the bRevert parameter is FALSE, the return value is a handle to a
3546 * copy of the window menu. If the bRevert parameter is TRUE, the return
3554 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3556 PWINDOW_OBJECT Window
;
3558 DECLARE_RETURN(HMENU
);
3560 DPRINT("Enter NtUserGetSystemMenu\n");
3563 if (!(Window
= UserGetWindowObject(hWnd
)))
3568 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3573 RETURN(Menu
->MenuInfo
.Self
);
3576 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3582 * NtUserSetSystemMenu
3589 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3591 BOOL Result
= FALSE
;
3592 PWINDOW_OBJECT Window
;
3594 DECLARE_RETURN(BOOL
);
3596 DPRINT("Enter NtUserSetSystemMenu\n");
3597 UserEnterExclusive();
3599 if (!(Window
= UserGetWindowObject(hWnd
)))
3607 * Assign new menu handle.
3609 if (!(Menu
= UserGetMenuObject(hMenu
)))
3614 Result
= IntSetSystemMenu(Window
, Menu
);
3620 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3626 UserGetWindow(HWND hWnd
, UINT Relationship
)
3628 PWINDOW_OBJECT Parent
, Window
;
3629 HWND hWndResult
= NULL
;
3631 if (!(Window
= UserGetWindowObject(hWnd
)))
3634 switch (Relationship
)
3637 if((Parent
= Window
->Parent
))
3639 if (Parent
->FirstChild
)
3640 hWndResult
= Parent
->FirstChild
->hSelf
;
3645 if((Parent
= Window
->Parent
))
3647 if (Parent
->LastChild
)
3648 hWndResult
= Parent
->LastChild
->hSelf
;
3653 if (Window
->NextSibling
)
3654 hWndResult
= Window
->NextSibling
->hSelf
;
3658 if (Window
->PrevSibling
)
3659 hWndResult
= Window
->PrevSibling
->hSelf
;
3663 if((Parent
= UserGetWindowObject(Window
->hOwner
)))
3665 hWndResult
= Parent
->hSelf
;
3669 if (Window
->FirstChild
)
3670 hWndResult
= Window
->FirstChild
->hSelf
;
3680 * The NtUserGetWindow function retrieves a handle to a window that has the
3681 * specified relationship (Z order or owner) to the specified window.
3688 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3690 DECLARE_RETURN(HWND
);
3692 DPRINT("Enter NtUserGetWindow\n");
3695 RETURN(UserGetWindow(hWnd
, Relationship
));
3698 DPRINT("Leave NtUserGetWindow, ret=%i\n",_ret_
);
3704 * NtUserGetWindowLong
3706 * The NtUserGetWindowLong function retrieves information about the specified
3707 * window. The function also retrieves the 32-bit (long) value at the
3708 * specified offset into the extra window memory.
3715 UserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3717 PWINDOW_OBJECT Window
, Parent
;
3721 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3723 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3731 * WndProc is only available to the owner process
3733 if (GWL_WNDPROC
== Index
3734 && Window
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3736 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3740 if ((INT
)Index
>= 0)
3742 if ((Index
+ sizeof(LONG
)) > Window
->Wnd
->cbwndExtra
)
3744 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3747 Result
= *((LONG
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3754 Result
= Wnd
->ExStyle
;
3758 Result
= Wnd
->style
;
3762 Result
= (LONG
)IntGetWindowProc(Wnd
, Ansi
);
3766 Result
= (LONG
) Wnd
->hModule
;
3769 case GWL_HWNDPARENT
:
3770 Parent
= Window
->Parent
;
3773 if (Parent
&& Parent
->hSelf
== IntGetDesktopWindow())
3774 Result
= (LONG
) UserGetWindow(Window
->hSelf
, GW_OWNER
);
3776 Result
= (LONG
) Parent
->hSelf
;
3781 Result
= (LONG
) Wnd
->IDMenu
;
3785 Result
= Wnd
->dwUserData
;
3789 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3790 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3800 * NtUserGetWindowLong
3802 * The NtUserGetWindowLong function retrieves information about the specified
3803 * window. The function also retrieves the 32-bit (long) value at the
3804 * specified offset into the extra window memory.
3811 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3813 DECLARE_RETURN(LONG
);
3815 DPRINT("Enter NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3816 UserEnterExclusive();
3818 RETURN(UserGetWindowLong(hWnd
, Index
, Ansi
));
3821 DPRINT("Leave NtUserGetWindowLong, ret=%i\n",_ret_
);
3829 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3831 PWINDOW_OBJECT Window
, Parent
;
3833 PWINSTATION_OBJECT WindowStation
;
3837 if (hWnd
== IntGetDesktopWindow())
3839 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3843 if (!(Window
= UserGetWindowObject(hWnd
)))
3850 if (!Wnd
) return 0; // No go on zero.
3852 if ((INT
)Index
>= 0)
3854 if ((Index
+ sizeof(LONG
)) > Wnd
->cbwndExtra
)
3856 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3860 OldValue
= *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
));
3862 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3864 OldValue = (LONG)IntSetWindowProc( Wnd,
3867 if (!OldValue) return 0;
3870 *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
)) = NewValue
;
3877 OldValue
= (LONG
) Wnd
->ExStyle
;
3878 Style
.styleOld
= OldValue
;
3879 Style
.styleNew
= NewValue
;
3882 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3884 WindowStation
= ((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
->WindowStation
;
3887 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3888 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3891 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3892 Wnd
->ExStyle
= (DWORD
)Style
.styleNew
;
3893 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3897 OldValue
= (LONG
) Wnd
->style
;
3898 Style
.styleOld
= OldValue
;
3899 Style
.styleNew
= NewValue
;
3900 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3901 Wnd
->style
= (DWORD
)Style
.styleNew
;
3902 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3907 if ( Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3908 Wnd
->fnid
& FNID_FREED
)
3910 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3913 OldValue
= (LONG
)IntSetWindowProc(Wnd
,
3920 OldValue
= (LONG
) Wnd
->hModule
;
3921 Wnd
->hModule
= (HINSTANCE
) NewValue
;
3924 case GWL_HWNDPARENT
:
3925 Parent
= Window
->Parent
;
3926 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
3927 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
3929 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
3933 OldValue
= (LONG
) Wnd
->IDMenu
;
3934 Wnd
->IDMenu
= (UINT
) NewValue
;
3938 OldValue
= Wnd
->dwUserData
;
3939 Wnd
->dwUserData
= NewValue
;
3943 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3944 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3954 * NtUserSetWindowLong
3956 * The NtUserSetWindowLong function changes an attribute of the specified
3957 * window. The function also sets the 32-bit (long) value at the specified
3958 * offset into the extra window memory.
3965 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3967 DECLARE_RETURN(LONG
);
3969 DPRINT("Enter NtUserSetWindowLong\n");
3970 UserEnterExclusive();
3972 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3975 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3981 * NtUserSetWindowWord
3983 * Legacy function similar to NtUserSetWindowLong.
3990 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3992 PWINDOW_OBJECT Window
;
3994 DECLARE_RETURN(WORD
);
3996 DPRINT("Enter NtUserSetWindowWord\n");
3997 UserEnterExclusive();
3999 if (!(Window
= UserGetWindowObject(hWnd
)))
4008 case GWL_HWNDPARENT
:
4009 RETURN( co_UserSetWindowLong(Window
->hSelf
, Index
, (UINT
)NewValue
, TRUE
));
4013 SetLastWin32Error(ERROR_INVALID_INDEX
);
4018 if (Index
> Window
->Wnd
->cbwndExtra
- sizeof(WORD
))
4020 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4024 OldValue
= *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
4025 *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
)) = NewValue
;
4030 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
4039 NtUserGetWindowPlacement(HWND hWnd
,
4040 WINDOWPLACEMENT
*lpwndpl
)
4042 PWINDOW_OBJECT Window
;
4045 WINDOWPLACEMENT Safepl
;
4047 DECLARE_RETURN(BOOL
);
4049 DPRINT("Enter NtUserGetWindowPlacement\n");
4052 if (!(Window
= UserGetWindowObject(hWnd
)))
4058 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4059 if(!NT_SUCCESS(Status
))
4061 SetLastNtError(Status
);
4064 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4070 if (0 == (Wnd
->style
& WS_VISIBLE
))
4072 Safepl
.showCmd
= SW_HIDE
;
4074 else if ((0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
4075 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
4076 0 == (Wnd
->style
& WS_MINIMIZE
))
4078 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
4080 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
4082 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
4084 else if (0 != (Wnd
->style
& WS_VISIBLE
))
4086 Safepl
.showCmd
= SW_SHOWNORMAL
;
4089 Size
.x
= Wnd
->rcWindow
.left
;
4090 Size
.y
= Wnd
->rcWindow
.top
;
4091 WinPosInitInternalPos(Window
, &Size
,
4094 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
4095 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
4096 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
4098 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
4099 if(!NT_SUCCESS(Status
))
4101 SetLastNtError(Status
);
4108 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
4118 NtUserLockWindowUpdate(HWND hWnd
)
4138 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
4139 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
4140 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
4144 QueryWindow based on KJK::Hyperion and James Tabor.
4146 0 = QWUniqueProcessId
4147 1 = QWUniqueThreadId
4150 4 = QWIsHung Implements IsHungAppWindow found
4153 9 = QWKillWindow When I called this with hWnd ==
4154 DesktopWindow, it shutdown the system
4161 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
4163 PWINDOW_OBJECT Window
;
4166 DECLARE_RETURN(UINT
);
4168 DPRINT("Enter NtUserQueryWindow\n");
4171 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4180 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
4181 Result
= (DWORD
)IntGetWndProcessId(Window
);
4184 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
4185 Result
= (DWORD
)IntGetWndThreadId(Window
);
4188 case QUERY_WINDOW_ACTIVE
:
4189 Result
= (DWORD
)UserGetActiveWindow();
4192 case QUERY_WINDOW_FOCUS
:
4193 Result
= (DWORD
)IntGetFocusWindow();
4196 case QUERY_WINDOW_ISHUNG
:
4197 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
4200 case QUERY_WINDOW_REAL_ID
:
4201 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
4204 Result
= (DWORD
)NULL
;
4211 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
4221 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
4235 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4237 UNICODE_STRING SafeMessageName
;
4240 DECLARE_RETURN(UINT
);
4242 DPRINT("Enter NtUserRegisterWindowMessage\n");
4243 UserEnterExclusive();
4245 if(MessageNameUnsafe
== NULL
)
4247 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4251 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4252 if(!NT_SUCCESS(Status
))
4254 SetLastNtError(Status
);
4258 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4260 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4264 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
4274 NtUserSetImeOwnerWindow(DWORD Unknown0
,
4287 NtUserSetInternalWindowPos(
4304 NtUserSetLayeredWindowAttributes(HWND hwnd
,
4318 NtUserSetLogonNotifyWindow(HWND hWnd
)
4335 PWINDOW_OBJECT Window
;
4337 DECLARE_RETURN(BOOL
);
4339 DPRINT("Enter NtUserSetMenu\n");
4340 UserEnterExclusive();
4342 if (!(Window
= UserGetWindowObject(hWnd
)))
4347 if (! IntSetMenu(Window
, Menu
, &Changed
))
4352 if (Changed
&& Repaint
)
4354 USER_REFERENCE_ENTRY Ref
;
4356 UserRefObjectCo(Window
, &Ref
);
4357 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4358 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4360 UserDerefObjectCo(Window
);
4366 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4376 NtUserSetWindowFNID(HWND hWnd
,
4379 PWINDOW_OBJECT Window
;
4381 DECLARE_RETURN(BOOL
);
4383 DPRINT("Enter NtUserSetWindowFNID\n");
4384 UserEnterExclusive();
4386 if (!(Window
= UserGetWindowObject(hWnd
)))
4393 { // From user land we only set these.
4394 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
4399 Wnd
->pcls
->fnid
|= fnID
;
4404 DPRINT("Leave NtUserSetWindowFNID\n");
4414 NtUserSetWindowPlacement(HWND hWnd
,
4415 WINDOWPLACEMENT
*lpwndpl
)
4417 PWINDOW_OBJECT Window
;
4419 WINDOWPLACEMENT Safepl
;
4421 DECLARE_RETURN(BOOL
);
4422 USER_REFERENCE_ENTRY Ref
;
4424 DPRINT("Enter NtUserSetWindowPlacement\n");
4425 UserEnterExclusive();
4427 if (!(Window
= UserGetWindowObject(hWnd
)))
4433 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4434 if(!NT_SUCCESS(Status
))
4436 SetLastNtError(Status
);
4439 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4444 UserRefObjectCo(Window
, &Ref
);
4446 if ((Wnd
->style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4448 co_WinPosSetWindowPos(Window
, NULL
,
4449 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4450 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4451 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4452 SWP_NOZORDER
| SWP_NOACTIVATE
);
4455 /* FIXME - change window status */
4456 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
4458 Wnd
->InternalPosInitialized
= TRUE
;
4459 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4460 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4461 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4463 UserDerefObjectCo(Window
);
4467 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4479 HWND hWndInsertAfter
,
4486 DECLARE_RETURN(BOOL
);
4487 PWINDOW_OBJECT Window
;
4489 USER_REFERENCE_ENTRY Ref
;
4491 DPRINT("Enter NtUserSetWindowPos\n");
4492 UserEnterExclusive();
4494 if (!(Window
= UserGetWindowObject(hWnd
)))
4499 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
4500 if (!(uFlags
& SWP_NOMOVE
))
4502 if (X
< -32768) X
= -32768;
4503 else if (X
> 32767) X
= 32767;
4504 if (Y
< -32768) Y
= -32768;
4505 else if (Y
> 32767) Y
= 32767;
4507 if (!(uFlags
& SWP_NOSIZE
))
4510 else if (cx
> 32767) cx
= 32767;
4512 else if (cy
> 32767) cy
= 32767;
4515 UserRefObjectCo(Window
, &Ref
);
4516 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4517 UserDerefObjectCo(Window
);
4522 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4529 IntGetWindowRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
4547 /* Create a new window region using the window rectangle */
4548 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4549 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4550 /* if there's a region assigned to the window, combine them both */
4551 if(Window
->WindowRegion
&& !(Wnd
->style
& WS_MINIMIZE
))
4552 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4553 /* Copy the region into hRgn */
4554 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4556 if((pRgn
= REGION_LockRgn(hRgn
)))
4558 Ret
= pRgn
->rdh
.iType
;
4559 REGION_UnlockRgn(pRgn
);
4564 GreDeleteObject(VisRgn
);
4570 IntGetWindowRgnBox(PWINDOW_OBJECT Window
, RECTL
*Rect
)
4588 /* Create a new window region using the window rectangle */
4589 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4590 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4591 /* if there's a region assigned to the window, combine them both */
4592 if(Window
->WindowRegion
&& !(Wnd
->style
& WS_MINIMIZE
))
4593 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4595 if((pRgn
= REGION_LockRgn(VisRgn
)))
4597 Ret
= pRgn
->rdh
.iType
;
4598 *Rect
= pRgn
->rdh
.rcBound
;
4599 REGION_UnlockRgn(pRgn
);
4604 GreDeleteObject(VisRgn
);
4619 PWINDOW_OBJECT Window
;
4620 DECLARE_RETURN(INT
);
4622 DPRINT("Enter NtUserSetWindowRgn\n");
4623 UserEnterExclusive();
4625 if (!(Window
= UserGetWindowObject(hWnd
)))
4630 /* FIXME - Verify if hRgn is a valid handle!!!!
4631 Propably make this operation thread-safe, but maybe it's not necessary */
4633 if(Window
->WindowRegion
)
4635 /* Delete no longer needed region handle */
4636 GreDeleteObject(Window
->WindowRegion
);
4638 Window
->WindowRegion
= hRgn
;
4640 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4644 USER_REFERENCE_ENTRY Ref
;
4645 UserRefObjectCo(Window
, &Ref
);
4646 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4647 UserDerefObjectCo(Window
);
4653 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4663 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4665 PWINDOW_OBJECT Window
;
4667 DECLARE_RETURN(BOOL
);
4668 USER_REFERENCE_ENTRY Ref
;
4670 DPRINT("Enter NtUserShowWindow\n");
4671 UserEnterExclusive();
4673 if (!(Window
= UserGetWindowObject(hWnd
)))
4678 UserRefObjectCo(Window
, &Ref
);
4679 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4680 UserDerefObjectCo(Window
);
4685 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4695 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4701 return NtUserShowWindow(hWnd
, nCmdShow
);
4711 NtUserUpdateLayeredWindow(
4719 BLENDFUNCTION
*pblend
,
4732 NtUserWindowFromPhysicalPoint(POINT Point
)
4743 NtUserWindowFromPoint(LONG X
, LONG Y
)
4747 PWINDOW_OBJECT DesktopWindow
= NULL
, Window
= NULL
;
4748 DECLARE_RETURN(HWND
);
4749 USER_REFERENCE_ENTRY Ref
;
4751 DPRINT("Enter NtUserWindowFromPoint\n");
4752 UserEnterExclusive();
4754 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4762 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4763 //its possible this referencing is useless, thou it shouldnt hurt...
4764 UserRefObjectCo(DesktopWindow
, &Ref
);
4766 pti
= PsGetCurrentThreadWin32Thread();
4767 Hit
= co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4771 Ret
= Window
->hSelf
;
4780 if (Window
) UserDereferenceObject(Window
);
4781 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4783 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4793 * Undocumented function that is called from DefWindowProc to set
4800 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4802 PWINDOW_OBJECT Window
;
4804 LARGE_STRING SafeText
;
4805 UNICODE_STRING UnicodeString
;
4808 DPRINT("Enter NtUserDefSetText\n");
4810 if (WindowText
!= NULL
)
4814 SafeText
= ProbeForReadLargeString(WindowText
);
4816 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4819 SetLastNtError(_SEH2_GetExceptionCode());
4829 UserEnterExclusive();
4831 if(!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4838 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4839 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4840 // Now we know what the bAnsi is for.
4841 RtlInitUnicodeString(&UnicodeString
, NULL
);
4842 if (SafeText
.Buffer
)
4847 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4849 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4850 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4852 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4855 SetLastNtError(_SEH2_GetExceptionCode());
4858 if (!Ret
) goto Exit
;
4861 if (UnicodeString
.Length
!= 0)
4863 if (Wnd
->strName
.MaximumLength
> 0 &&
4864 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4866 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4868 Wnd
->strName
.Length
= UnicodeString
.Length
;
4869 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4870 RtlCopyMemory(Wnd
->strName
.Buffer
,
4871 UnicodeString
.Buffer
,
4872 UnicodeString
.Length
);
4877 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4878 buf
= Wnd
->strName
.Buffer
;
4879 Wnd
->strName
.Buffer
= NULL
;
4882 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4885 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4886 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4887 if (Wnd
->strName
.Buffer
!= NULL
)
4889 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4890 RtlCopyMemory(Wnd
->strName
.Buffer
,
4891 UnicodeString
.Buffer
,
4892 UnicodeString
.Length
);
4893 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4894 Wnd
->strName
.Length
= UnicodeString
.Length
;
4898 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4906 Wnd
->strName
.Length
= 0;
4907 if (Wnd
->strName
.Buffer
!= NULL
)
4908 Wnd
->strName
.Buffer
[0] = L
'\0';
4911 // HAX! FIXME! Windows does not do this in here!
4912 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4913 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4914 /* Send shell notifications */
4915 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
4917 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4922 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4923 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4929 * NtUserInternalGetWindowText
4936 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4938 PWINDOW_OBJECT Window
;
4942 DECLARE_RETURN(INT
);
4944 DPRINT("Enter NtUserInternalGetWindowText\n");
4947 if(lpString
&& (nMaxCount
<= 1))
4949 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4953 if(!(Window
= UserGetWindowObject(hWnd
)))
4959 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4962 const WCHAR Terminator
= L
'\0';
4964 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4966 Copy
= min(nMaxCount
- 1, Result
);
4969 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4970 if(!NT_SUCCESS(Status
))
4972 SetLastNtError(Status
);
4978 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4979 if(!NT_SUCCESS(Status
))
4981 SetLastNtError(Status
);
4991 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4999 IntShowOwnedPopups(PWINDOW_OBJECT OwnerWnd
, BOOL fShow
)
5002 PWINDOW_OBJECT pWnd
;
5005 // ASSERT(OwnerWnd);
5007 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
5012 while (win_array
[count
])
5014 while (--count
>= 0)
5016 if (UserGetWindow( win_array
[count
], GW_OWNER
) != OwnerWnd
->hSelf
)
5018 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
5020 // if (pWnd == WND_OTHER_PROCESS) continue;
5024 if (pWnd
->Wnd
->state
& WNDS_HIDDENPOPUP
)
5026 /* In Windows, ShowOwnedPopups(TRUE) generates
5027 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
5028 * regardless of the state of the owner
5030 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
5036 if (pWnd
->Wnd
->style
& WS_VISIBLE
)
5038 /* In Windows, ShowOwnedPopups(FALSE) generates
5039 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
5040 * regardless of the state of the owner
5042 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
5048 ExFreePool( win_array
);
5053 * NtUserValidateHandleSecure
5061 NtUserValidateHandleSecure(
5069 PUSER_HANDLE_ENTRY entry
;
5070 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
5072 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5075 uType
= entry
->type
;
5081 PWINDOW_OBJECT Window
;
5082 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
5088 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
5093 PACCELERATOR_TABLE Accel
;
5094 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
5099 PCURICON_OBJECT Cursor
;
5100 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
5106 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
5111 PMONITOR_OBJECT Monitor
;
5112 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
5118 return UserGetCallProcInfo( handle
, &Proc
);
5121 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5125 { /* Is handle entry restricted? */