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(Window
->head
.cLockObj
>= 0);
98 Window
->head
.cLockObj
++;
106 PWINDOW_OBJECT FASTCALL
UserGetWindowObject(HWND hWnd
)
109 PWINDOW_OBJECT Window
;
111 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
113 ti
= GetW32ThreadInfo();
116 SetLastWin32Error(ERROR_ACCESS_DENIED
);
123 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
127 Window
= (PWINDOW_OBJECT
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
128 if (!Window
|| 0 != (Window
->state
& WINDOWSTATUS_DESTROYED
))
130 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
134 ASSERT(Window
->head
.cLockObj
>= 0);
145 * The function determines whether the specified window handle identifies
146 * an existing window.
150 * Handle to the window to test.
153 * If the window handle identifies an existing window, the return value
154 * is TRUE. If the window handle does not identify an existing window,
155 * the return value is FALSE.
159 IntIsWindow(HWND hWnd
)
161 PWINDOW_OBJECT Window
;
163 if (!(Window
= UserGetWindowObject(hWnd
)))
171 PWINDOW_OBJECT FASTCALL
172 IntGetParent(PWINDOW_OBJECT Wnd
)
174 if (Wnd
->Wnd
->style
& WS_POPUP
)
176 return Wnd
->spwndOwner
;
178 else if (Wnd
->Wnd
->style
& WS_CHILD
)
180 return Wnd
->spwndParent
;
190 * Compile a list of all child window handles from given window.
193 * This function is similar to Wine WIN_ListChildren. The caller
194 * must free the returned list with ExFreePool.
198 IntWinListChildren(PWINDOW_OBJECT Window
)
200 PWINDOW_OBJECT Child
;
202 UINT Index
, NumChildren
= 0;
204 if (!Window
) return NULL
;
206 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
209 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
212 DPRINT1("Failed to allocate memory for children array\n");
213 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
216 for (Child
= Window
->spwndChild
, Index
= 0;
218 Child
= Child
->spwndNext
, ++Index
)
219 List
[Index
] = Child
->hSelf
;
225 /***********************************************************************
228 static void IntSendDestroyMsg(HWND hWnd
)
231 PWINDOW_OBJECT Window
;
236 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
238 if (hWnd
== info
.hwndCaret
)
245 Window
= UserGetWindowObject(hWnd
);
248 // USER_REFERENCE_ENTRY Ref;
249 // UserRefObjectCo(Window, &Ref);
251 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
253 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
256 // UserDerefObjectCo(Window);
259 /* The window could already be destroyed here */
262 * Send the WM_DESTROY to the window.
265 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
268 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
269 * make sure that the window still exists when we come back.
278 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
281 /* start from the end (FIXME: is this needed?) */
282 for (i
= 0; pWndArray
[i
]; i
++)
287 if (IsWindow( pWndArray
[i
] ))
288 WIN_SendDestroyMsg( pWndArray
[i
] );
290 HeapFree(GetProcessHeap(), 0, pWndArray
);
294 DPRINT("destroyed itself while in WM_DESTROY!\n");
300 UserFreeWindowInfo(PTHREADINFO ti
, PWINDOW_OBJECT WindowObject
)
302 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
303 PWND Wnd
= WindowObject
->Wnd
;
307 if (ClientInfo
->CallbackWnd
.pvWnd
== DesktopHeapAddressToUser(WindowObject
->Wnd
))
309 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
310 ClientInfo
->CallbackWnd
.pvWnd
= NULL
;
313 if (Wnd
->strName
.Buffer
!= NULL
)
315 Wnd
->strName
.Length
= 0;
316 Wnd
->strName
.MaximumLength
= 0;
317 DesktopHeapFree(Wnd
->head
.rpdesk
,
318 Wnd
->strName
.Buffer
);
319 Wnd
->strName
.Buffer
= NULL
;
322 DesktopHeapFree(Wnd
->head
.rpdesk
, Wnd
);
323 WindowObject
->Wnd
= NULL
;
326 /***********************************************************************
329 * Destroy storage associated to a window. "Internals" p.358
331 * This is the "functional" DestroyWindows function ei. all stuff
332 * done in CreateWindow is undone here and not in DestroyWindow:-P
335 static LRESULT
co_UserFreeWindow(PWINDOW_OBJECT Window
,
336 PPROCESSINFO ProcessData
,
337 PTHREADINFO ThreadData
,
338 BOOLEAN SendMessages
)
342 PWINDOW_OBJECT Child
;
344 BOOLEAN BelongsToThreadData
;
351 if(Window
->state
& WINDOWSTATUS_DESTROYING
)
353 DPRINT("Tried to call IntDestroyWindow() twice\n");
356 Window
->state
|= WINDOWSTATUS_DESTROYING
;
357 Wnd
->style
&= ~WS_VISIBLE
;
359 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Wnd
, OBJID_WINDOW
, 0);
361 /* remove the window already at this point from the thread window list so we
362 don't get into trouble when destroying the thread windows while we're still
363 in IntDestroyWindow() */
364 RemoveEntryList(&Window
->ThreadListEntry
);
366 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
368 IntDeRegisterShellHookWindow(Window
->hSelf
);
372 /* Send destroy messages */
373 IntSendDestroyMsg(Window
->hSelf
);
376 /* free child windows */
377 Children
= IntWinListChildren(Window
);
380 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
382 if ((Child
= IntGetWindowObject(*ChildHandle
)))
384 if(!IntWndBelongsToThread(Child
, ThreadData
))
386 /* send WM_DESTROY messages to windows not belonging to the same thread */
387 IntSendDestroyMsg(Child
->hSelf
);
390 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
392 UserDereferenceObject(Child
);
395 ExFreePool(Children
);
401 * Clear the update region to make sure no WM_PAINT messages will be
402 * generated for this window while processing the WM_NCDESTROY.
404 co_UserRedrawWindow(Window
, NULL
, 0,
405 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
406 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
407 if(BelongsToThreadData
)
408 co_IntSendMessage(Window
->hSelf
, WM_NCDESTROY
, 0, 0);
410 DestroyTimersForWindow(ThreadData
, Window
);
411 HOOK_DestroyThreadHooks(ThreadData
->pEThread
); // This is needed here too!
413 /* flush the message queue */
414 MsqRemoveWindowMessagesFromQueue(Window
);
416 /* from now on no messages can be sent to this window anymore */
417 Window
->state
|= WINDOWSTATUS_DESTROYED
;
418 Wnd
->state
|= WNDS_DESTROYED
;
419 Wnd
->fnid
|= FNID_FREED
;
421 /* don't remove the WINDOWSTATUS_DESTROYING bit */
423 /* reset shell window handles */
424 if(ThreadData
->rpdesk
)
426 if (Window
->hSelf
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
427 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
429 if (Window
->hSelf
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
430 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
433 /* Unregister hot keys */
434 UnregisterWindowHotKeys (Window
);
436 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
440 WinPosCheckInternalPos(Window
->hSelf
);
441 if (Window
->hSelf
== GetCapture())
446 /* free resources associated with the window */
447 TIMER_RemoveWindowTimers(Window
->hSelf
);
450 if (!(Wnd
->style
& WS_CHILD
) && Wnd
->IDMenu
451 && (Menu
= UserGetMenuObject((HMENU
)Wnd
->IDMenu
)))
453 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
457 if(Window
->SystemMenu
458 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
460 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
461 Window
->SystemMenu
= (HMENU
)0;
464 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
467 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
468 CLASS_RemoveWindow(Window
->Class
);
471 IntUnlinkWindow(Window
);
473 UserReferenceObject(Window
);
474 UserDeleteObject(Window
->hSelf
, otWindow
);
476 IntDestroyScrollBars(Window
);
478 /* dereference the class */
479 IntDereferenceClass(Wnd
->pcls
,
480 Window
->pti
->pDeskInfo
,
486 GreDeleteObject(Window
->hrgnClip
);
489 ASSERT(Window
->Wnd
!= NULL
);
490 UserFreeWindowInfo(Window
->pti
, Window
);
492 UserDereferenceObject(Window
);
494 IntClipboardFreeWindow(Window
);
500 IntGetWindowBorderMeasures(PWINDOW_OBJECT Window
, UINT
*cx
, UINT
*cy
)
502 PWND Wnd
= Window
->Wnd
;
503 if(HAS_DLGFRAME(Wnd
->style
, Wnd
->ExStyle
) && !(Wnd
->style
& WS_MINIMIZE
))
505 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
506 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
510 if(HAS_THICKFRAME(Wnd
->style
, Wnd
->ExStyle
)&& !(Wnd
->style
& WS_MINIMIZE
))
512 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
513 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
515 else if(HAS_THINFRAME(Wnd
->style
, Wnd
->ExStyle
))
517 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
518 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
528 // Same as User32:IntGetWndProc.
531 IntGetWindowProc(PWND pWnd
,
536 WNDPROC gcpd
, Ret
= 0;
538 ASSERT(UserIsEnteredExclusive() == TRUE
);
542 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
544 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
546 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
549 Ret
= GETPFNCLIENTA(i
);
551 Ret
= GETPFNCLIENTW(i
);
557 if (Class
->fnid
== FNID_EDIT
)
558 Ret
= pWnd
->lpfnWndProc
;
561 Ret
= pWnd
->lpfnWndProc
;
563 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
567 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
568 Ret
= GETPFNCLIENTA(Class
->fnid
);
572 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
573 Ret
= GETPFNCLIENTW(Class
->fnid
);
576 if ( Ret
!= pWnd
->lpfnWndProc
)
579 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
582 gcpd
= (WNDPROC
)UserGetCPD(
584 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
587 return (gcpd
? gcpd
: Ret
);
591 IntSetWindowProc(PWND pWnd
,
596 PCALLPROCDATA CallProc
;
598 WNDPROC Ret
, chWndProc
= NULL
;
600 // Retrieve previous window proc.
601 Ret
= IntGetWindowProc(pWnd
, Ansi
);
605 if (IsCallProcHandle(NewWndProc
))
607 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, otCallProc
);
609 { // Reset new WndProc.
610 NewWndProc
= CallProc
->pfnClientPrevious
;
611 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
612 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
615 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
616 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
618 if (GETPFNCLIENTW(i
) == NewWndProc
)
620 chWndProc
= GETPFNSERVER(i
);
623 if (GETPFNCLIENTA(i
) == NewWndProc
)
625 chWndProc
= GETPFNSERVER(i
);
629 // If match, set/reset to Server Side and clear ansi.
632 pWnd
->lpfnWndProc
= chWndProc
;
633 pWnd
->Unicode
= TRUE
;
634 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
635 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
639 pWnd
->Unicode
= !Ansi
;
640 // Handle the state change in here.
642 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
644 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
646 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
647 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
649 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
651 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
655 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
656 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
660 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
661 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
664 // Now set the new window proc.
665 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
670 // Move this to user space!
672 IntGetWindowInfo(PWINDOW_OBJECT Window
, PWINDOWINFO pwi
)
674 PWND Wnd
= Window
->Wnd
;
676 pwi
->cbSize
= sizeof(WINDOWINFO
);
677 pwi
->rcWindow
= Window
->Wnd
->rcWindow
;
678 pwi
->rcClient
= Window
->Wnd
->rcClient
;
679 pwi
->dwStyle
= Wnd
->style
;
680 pwi
->dwExStyle
= Wnd
->ExStyle
;
681 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Window
->hSelf
); /* WS_ACTIVECAPTION */
682 IntGetWindowBorderMeasures(Window
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
683 pwi
->atomWindowType
= (Wnd
->pcls
? Wnd
->pcls
->atomClassName
: 0);
684 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
690 PWINDOW_OBJECT Window
,
694 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
695 PWND Wnd
= Window
->Wnd
;
697 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
699 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
703 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
711 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
712 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Window
->hSelf
);
721 NewMenu
= IntGetMenuObject(Menu
);
726 IntReleaseMenuObject(OldMenu
);
728 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
731 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
733 /* Can't use the same menu for two windows */
736 IntReleaseMenuObject(OldMenu
);
738 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
744 Wnd
->IDMenu
= (UINT
) Menu
;
747 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
748 IntReleaseMenuObject(NewMenu
);
752 OldMenu
->MenuInfo
.Wnd
= NULL
;
753 IntReleaseMenuObject(OldMenu
);
760 /* INTERNAL ******************************************************************/
764 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
769 USER_REFERENCE_ENTRY Ref
;
770 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
772 while (!IsListEmpty(&WThread
->WindowListHead
))
774 Current
= WThread
->WindowListHead
.Flink
;
775 Wnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
777 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
779 /* window removes itself from the list */
782 fixme: it is critical that the window removes itself! if now, we will loop
786 //ASSERT(co_UserDestroyWindow(Wnd));
788 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
789 if (!co_UserDestroyWindow(Wnd
))
791 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
793 UserDerefObjectCo(Wnd
);//faxme: temp hack??
801 * Returns client window rectangle relative to the upper-left corner of client area.
803 * \note Does not check the validity of the parameters
806 IntGetClientRect(PWINDOW_OBJECT Window
, RECTL
*Rect
)
811 Rect
->left
= Rect
->top
= 0;
812 Rect
->right
= Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
;
813 Rect
->bottom
= Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
;
819 IntGetFocusWindow(VOID
)
821 PUSER_MESSAGE_QUEUE Queue
;
822 PDESKTOP pdo
= IntGetActiveDesktop();
827 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
832 return(Queue
->FocusWindow
);
836 PMENU_OBJECT FASTCALL
837 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
)
839 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
840 PTHREADINFO W32Thread
;
841 HMENU hNewMenu
, hSysMenu
;
842 ROSMENUITEMINFO ItemInfo
;
846 W32Thread
= PsGetCurrentThreadWin32Thread();
848 if(!W32Thread
->rpdesk
)
851 if(Window
->SystemMenu
)
853 Menu
= UserGetMenuObject(Window
->SystemMenu
);
856 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
857 Window
->SystemMenu
= (HMENU
)0;
861 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
863 /* clone system menu */
864 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
868 NewMenu
= IntCloneMenu(Menu
);
871 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
872 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
873 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
875 //IntReleaseMenuObject(NewMenu);
880 hSysMenu
= UserCreateMenu(FALSE
);
881 if (NULL
== hSysMenu
)
885 SysMenu
= IntGetMenuObject(hSysMenu
);
888 UserDestroyMenu(hSysMenu
);
891 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
892 SysMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
893 hNewMenu
= co_IntLoadSysMenuTemplate();
896 IntReleaseMenuObject(SysMenu
);
897 UserDestroyMenu(hSysMenu
);
900 Menu
= IntGetMenuObject(hNewMenu
);
903 IntReleaseMenuObject(SysMenu
);
904 UserDestroyMenu(hSysMenu
);
908 NewMenu
= IntCloneMenu(Menu
);
911 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
912 IntReleaseMenuObject(NewMenu
);
913 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
915 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
916 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
917 ItemInfo
.fType
= MF_POPUP
;
918 ItemInfo
.fState
= MFS_ENABLED
;
919 ItemInfo
.dwTypeData
= NULL
;
921 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
922 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
924 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
928 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
937 if(Window
->SystemMenu
)
938 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
946 IntIsChildWindow(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT BaseWindow
)
948 PWINDOW_OBJECT Window
;
955 if (Window
== Parent
)
959 if(!(Wnd
->style
& WS_CHILD
))
964 Window
= Window
->spwndParent
;
971 IntIsWindowVisible(PWINDOW_OBJECT BaseWindow
)
973 PWINDOW_OBJECT Window
;
980 if(!(Wnd
->style
& WS_CHILD
))
984 if(!(Wnd
->style
& WS_VISIBLE
))
989 Window
= Window
->spwndParent
;
992 if(Window
&& Wnd
->style
& WS_VISIBLE
)
1001 static VOID FASTCALL
1004 PWND WndInsertAfter
) /* set to NULL if top sibling */
1006 if ((Wnd
->spwndPrev
= WndInsertAfter
))
1008 /* link after WndInsertAfter */
1009 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
1010 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1012 Wnd
->spwndPrev
->spwndNext
= Wnd
;
1017 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
1018 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1020 Wnd
->spwndParent
->spwndChild
= Wnd
;
1025 link the window into siblings list
1026 children and parent are kept in place.
1031 PWINDOW_OBJECT WndInsertAfter
/* set to NULL if top sibling */
1034 IntLinkWnd(Wnd
->Wnd
,
1035 WndInsertAfter
? WndInsertAfter
->Wnd
: NULL
);
1037 if ((Wnd
->spwndPrev
= WndInsertAfter
))
1039 /* link after WndInsertAfter */
1040 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
1041 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1043 Wnd
->spwndPrev
->spwndNext
= Wnd
;
1048 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
1049 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1051 Wnd
->spwndParent
->spwndChild
= Wnd
;
1056 VOID FASTCALL
IntLinkHwnd(PWINDOW_OBJECT Wnd
, HWND hWndPrev
)
1058 if (hWndPrev
== HWND_NOTOPMOST
)
1060 if (!(Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1061 (Wnd
->Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
1062 Wnd
->Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1063 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
1066 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
1068 if (hWndPrev
== HWND_BOTTOM
)
1070 /* Link in the bottom of the list */
1071 PWINDOW_OBJECT WndInsertAfter
;
1073 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
1074 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
1075 WndInsertAfter
= WndInsertAfter
->spwndNext
;
1077 IntLinkWindow(Wnd
, WndInsertAfter
);
1078 Wnd
->Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1080 else if (hWndPrev
== HWND_TOPMOST
)
1082 /* Link in the top of the list */
1083 IntLinkWindow(Wnd
, NULL
);
1085 Wnd
->Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1087 else if (hWndPrev
== HWND_TOP
)
1089 /* Link it after the last topmost window */
1090 PWINDOW_OBJECT WndInsertBefore
;
1092 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
1094 if (!(Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
1096 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
1098 if (!(WndInsertBefore
->Wnd
->ExStyle
& WS_EX_TOPMOST
)) break;
1099 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
1101 Wnd
->Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1104 WndInsertBefore
= WndInsertBefore
->spwndNext
;
1108 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
1112 /* Link it after hWndPrev */
1113 PWINDOW_OBJECT WndInsertAfter
;
1115 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1116 /* Are we called with an erroneous handle */
1117 if(WndInsertAfter
== NULL
)
1119 /* Link in a default position */
1120 IntLinkHwnd(Wnd
, HWND_TOP
);
1124 IntLinkWindow(Wnd
, WndInsertAfter
);
1126 /* Fix the WS_EX_TOPMOST flag */
1127 if (!(WndInsertAfter
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1129 Wnd
->Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1133 if(WndInsertAfter
->spwndNext
&&
1134 WndInsertAfter
->spwndNext
->Wnd
->ExStyle
& WS_EX_TOPMOST
)
1136 Wnd
->Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1143 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1145 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
1148 Wnd
= IntGetWindowObject(hWnd
);
1152 WndOldOwner
= Wnd
->spwndOwner
;
1154 ret
= WndOldOwner
? WndOldOwner
->hSelf
: 0;
1156 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1158 Wnd
->spwndOwner
= WndNewOwner
;
1159 Wnd
->Wnd
->spwndOwner
= WndNewOwner
->Wnd
;
1163 Wnd
->spwndOwner
= NULL
;
1164 Wnd
->Wnd
->spwndOwner
= NULL
;
1167 UserDereferenceObject(Wnd
);
1171 PWINDOW_OBJECT FASTCALL
1172 co_IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
1174 PWINDOW_OBJECT WndOldParent
;
1178 ASSERT(WndNewParent
);
1179 ASSERT_REFS_CO(Wnd
);
1180 ASSERT_REFS_CO(WndNewParent
);
1182 /* Some applications try to set a child as a parent */
1183 if (IntIsChildWindow(Wnd
, WndNewParent
))
1185 SetLastWin32Error( ERROR_INVALID_PARAMETER
);
1190 * Windows hides the window first, then shows it again
1191 * including the WM_SHOWWINDOW messages and all
1193 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1195 /* Window must belong to current process */
1196 if (Wnd
->pti
->pEThread
->ThreadsProcess
!= PsGetCurrentProcess())
1199 WndOldParent
= Wnd
->spwndParent
;
1201 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1203 if (WndNewParent
!= WndOldParent
)
1205 /* Unlink the window from the siblings list */
1206 IntUnlinkWindow(Wnd
);
1208 /* Set the new parent */
1209 Wnd
->spwndParent
= WndNewParent
;
1210 Wnd
->Wnd
->spwndParent
= WndNewParent
->Wnd
;
1212 /* Link the window with its new siblings*/
1213 IntLinkHwnd(Wnd
, HWND_TOP
);
1218 * SetParent additionally needs to make hwnd the top window
1219 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1220 * WM_WINDOWPOSCHANGED notification messages.
1222 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1223 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1224 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1227 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1228 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1231 return WndOldParent
;
1235 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
1237 PMENU_OBJECT OldMenu
;
1238 if(Window
->SystemMenu
)
1240 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1243 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1244 IntReleaseMenuObject(OldMenu
);
1250 /* FIXME check window style, propably return FALSE ? */
1251 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1252 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1255 Window
->SystemMenu
= (HMENU
)0;
1260 /* unlink the window from siblings. children and parent are kept in place. */
1262 IntUnlinkWnd(PWND Wnd
)
1265 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1268 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1270 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1271 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1273 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1277 /* unlink the window from siblings. children and parent are kept in place. */
1279 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1282 IntUnlinkWnd(Wnd
->Wnd
);
1285 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1288 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1290 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1291 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1293 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1297 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1299 return ((Window
->state
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1305 IntGetWindowPlacement(PWINDOW_OBJECT Window
, WINDOWPLACEMENT
*lpwndpl
)
1311 if (!Wnd
) return FALSE
;
1313 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1319 if (0 == (Wnd
->style
& WS_VISIBLE
))
1321 lpwndpl
->showCmd
= SW_HIDE
;
1323 else if (0 != (Window
->state
& WINDOWOBJECT_RESTOREMAX
) ||
1324 0 != (Wnd
->style
& WS_MAXIMIZE
))
1326 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1328 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1330 lpwndpl
->showCmd
= SW_MINIMIZE
;
1332 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1334 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1337 Size
.x
= Wnd
->rcWindow
.left
;
1338 Size
.y
= Wnd
->rcWindow
.top
;
1339 WinPosInitInternalPos(Window
, &Size
,
1342 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1343 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1344 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1350 /* FUNCTIONS *****************************************************************/
1356 NtUserAlterWindowStyle(DWORD Unknown0
,
1366 * As best as I can figure, this function is used by EnumWindows,
1367 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1369 * It's supposed to build a list of HWNDs to return to the caller.
1370 * We can figure out what kind of list by what parameters are
1378 NtUserBuildHwndList(
1391 return ERROR_INVALID_PARAMETER
;
1393 if (hwndParent
|| !dwThreadId
)
1396 PWINDOW_OBJECT Parent
, Window
;
1400 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1402 return ERROR_INVALID_HANDLE
;
1407 Status
= IntValidateDesktopHandle(hDesktop
,
1411 if(!NT_SUCCESS(Status
))
1413 return ERROR_INVALID_HANDLE
;
1416 hwndParent
= Desktop
->DesktopWindow
;
1423 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1424 (Window
= Parent
->spwndChild
))
1426 BOOL bGoDown
= TRUE
;
1428 Status
= STATUS_SUCCESS
;
1433 if(dwCount
++ < *pBufSize
&& pWnd
)
1437 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1438 *pWnd
= Window
->hSelf
;
1441 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1443 Status
= _SEH2_GetExceptionCode();
1446 if(!NT_SUCCESS(Status
))
1448 SetLastNtError(Status
);
1452 if (Window
->spwndChild
&& bChildren
)
1454 Window
= Window
->spwndChild
;
1459 if (Window
->spwndNext
)
1461 Window
= Window
->spwndNext
;
1465 Window
= Window
->spwndParent
;
1466 if (Window
== Parent
)
1475 ObDereferenceObject(Desktop
);
1481 PTHREADINFO W32Thread
;
1482 PLIST_ENTRY Current
;
1483 PWINDOW_OBJECT Window
;
1485 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1486 if(!NT_SUCCESS(Status
))
1488 return ERROR_INVALID_PARAMETER
;
1490 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1492 ObDereferenceObject(Thread
);
1493 DPRINT("Thread is not a GUI Thread!\n");
1494 return ERROR_INVALID_PARAMETER
;
1497 Current
= W32Thread
->WindowListHead
.Flink
;
1498 while(Current
!= &(W32Thread
->WindowListHead
))
1500 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1503 if(bChildren
|| Window
->spwndOwner
!= NULL
)
1505 if(dwCount
< *pBufSize
&& pWnd
)
1507 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1508 if(!NT_SUCCESS(Status
))
1510 SetLastNtError(Status
);
1516 Current
= Current
->Flink
;
1519 ObDereferenceObject(Thread
);
1522 *pBufSize
= dwCount
;
1523 return STATUS_SUCCESS
;
1531 NtUserChildWindowFromPointEx(HWND hwndParent
,
1536 PWINDOW_OBJECT Parent
;
1541 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1549 if(Parent
->hSelf
!= IntGetDesktopWindow())
1551 Pt
.x
+= Parent
->Wnd
->rcClient
.left
;
1552 Pt
.y
+= Parent
->Wnd
->rcClient
.top
;
1555 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1560 Ret
= Parent
->hSelf
;
1561 if((List
= IntWinListChildren(Parent
)))
1563 for(phWnd
= List
; *phWnd
; phWnd
++)
1565 PWINDOW_OBJECT Child
;
1567 if((Child
= UserGetWindowObject(*phWnd
)))
1569 ChildWnd
= Child
->Wnd
;
1570 if(!(ChildWnd
->style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1574 if((ChildWnd
->style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1578 if((ChildWnd
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1582 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1596 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWINDOW_OBJECT ParentWindow
, DWORD
* dwShowMode
)
1598 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1600 /* default positioning for overlapped windows */
1601 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1604 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1606 UserSystemParametersInfo(SPI_GETWORKAREA
, 0, &WorkArea
, 0);
1608 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1610 if (IS_DEFAULT(Cs
->x
))
1612 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1614 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1616 Cs
->x
= ProcessParams
->StartingX
;
1617 Cs
->y
= ProcessParams
->StartingY
;
1621 Cs
->x
= WorkArea
.left
;
1622 Cs
->y
= WorkArea
.top
;
1626 if (IS_DEFAULT(Cs
->cx
))
1628 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1630 Cs
->cx
= ProcessParams
->CountX
;
1631 Cs
->cy
= ProcessParams
->CountY
;
1635 Cs
->cx
= (WorkArea
.right
- WorkArea
.left
) * 3 / 4 - Cs
->x
;
1636 Cs
->cy
= (WorkArea
.bottom
- WorkArea
.top
) * 3 / 4 - Cs
->y
;
1639 /* neither x nor cx are default. Check the y values .
1640 * In the trace we see Outlook and Outlook Express using
1641 * cy set to CW_USEDEFAULT when opening the address book.
1643 else if (IS_DEFAULT(Cs
->cy
))
1645 DPRINT("Strange use of CW_USEDEFAULT in nHeight\n");
1646 Cs
->cy
= (WorkArea
.bottom
- WorkArea
.top
) * 3 / 4 - Cs
->y
;
1651 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1652 if(IS_DEFAULT(Cs
->x
))
1657 if(IS_DEFAULT(Cs
->cx
))
1667 /* Allocates and initializes a window*/
1668 PWINDOW_OBJECT FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1669 PLARGE_STRING WindowName
,
1671 PWINDOW_OBJECT ParentWindow
,
1672 PWINDOW_OBJECT OwnerWindow
)
1675 PWINDOW_OBJECT Window
;
1677 PTHREADINFO pti
= NULL
;
1678 PMENU_OBJECT SystemMenu
;
1680 BOOL bUnicodeWindow
;
1682 pti
= PsGetCurrentThreadWin32Thread();
1684 /* Automatically add WS_EX_WINDOWEDGE */
1685 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1686 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1687 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1688 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1690 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1692 /* Is it a unicode window? */
1693 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1694 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1696 /* Allocate the new window */
1697 Window
= (PWINDOW_OBJECT
) UserCreateObject( gHandleTable
,
1701 sizeof(WINDOW_OBJECT
));
1707 Wnd
= DesktopHeapAlloc(pti
->rpdesk
, sizeof(WND
) + Class
->cbwndExtra
);
1714 RtlZeroMemory(Wnd
, sizeof(WND
) + Class
->cbwndExtra
);
1716 DPRINT("Created object with handle %X\n", hWnd
);
1718 if (NULL
== pti
->rpdesk
->DesktopWindow
)
1720 /* If there is no desktop window yet, we must be creating it */
1721 pti
->rpdesk
->DesktopWindow
= hWnd
;
1722 pti
->rpdesk
->pDeskInfo
->spwnd
= Wnd
;
1726 * Fill out the structure describing it.
1730 Window
->hSelf
= hWnd
;
1731 Window
->spwndParent
= ParentWindow
;
1732 Window
->spwndOwner
= OwnerWindow
;
1735 Wnd
->head
.pti
= pti
;
1736 Wnd
->head
.rpdesk
= pti
->rpdesk
;
1738 Wnd
->hWndLastActive
= hWnd
;
1739 Wnd
->state2
|= WNDS2_WIN40COMPAT
;
1741 Wnd
->hModule
= Cs
->hInstance
;
1742 Wnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1743 Wnd
->ExStyle
= Cs
->dwExStyle
;
1744 Wnd
->cbwndExtra
= Wnd
->pcls
->cbwndExtra
;
1745 Wnd
->spwndOwner
= OwnerWindow
? OwnerWindow
->Wnd
: NULL
;
1746 Wnd
->spwndParent
= ParentWindow
? ParentWindow
->Wnd
: NULL
;
1748 IntReferenceMessageQueue(Window
->pti
->MessageQueue
);
1749 if (Wnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1751 Wnd
->HideFocus
= Wnd
->spwndParent
->HideFocus
;
1752 Wnd
->HideAccel
= Wnd
->spwndParent
->HideAccel
;
1755 if (Wnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1756 Wnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1758 /* BugBoy Comments: Comment below say that System classes are always created
1759 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1760 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1762 No where can I see in code or through testing does the window change back
1763 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1764 see what problems this would cause.*/
1766 // Set WndProc from Class.
1767 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
1769 // GetWindowProc, test for non server side default classes and set WndProc.
1770 if ( Wnd
->pcls
->fnid
<= FNID_GHOST
&& Wnd
->pcls
->fnid
>= FNID_BUTTON
)
1774 if (GETPFNCLIENTA(Wnd
->pcls
->fnid
) == Wnd
->lpfnWndProc
)
1775 Wnd
->lpfnWndProc
= GETPFNCLIENTW(Wnd
->pcls
->fnid
);
1779 if (GETPFNCLIENTW(Wnd
->pcls
->fnid
) == Wnd
->lpfnWndProc
)
1780 Wnd
->lpfnWndProc
= GETPFNCLIENTA(Wnd
->pcls
->fnid
);
1784 // If not an Unicode caller, set Ansi creator bit.
1785 if (!bUnicodeWindow
) Wnd
->state
|= WNDS_ANSICREATOR
;
1787 // Clone Class Ansi/Unicode proc type.
1788 if (Wnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1790 Wnd
->state
|= WNDS_ANSIWINDOWPROC
;
1791 Wnd
->Unicode
= FALSE
;
1795 It seems there can be both an Ansi creator and Unicode Class Window
1796 WndProc, unless the following overriding conditions occur:
1798 if ( !bUnicodeWindow
&&
1799 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1800 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1801 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1802 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1803 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1804 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1805 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1806 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1807 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1808 { // Override Class and set the window Ansi WndProc.
1809 Wnd
->state
|= WNDS_ANSIWINDOWPROC
;
1810 Wnd
->Unicode
= FALSE
;
1813 { // Set the window Unicode WndProc.
1814 Wnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1815 Wnd
->Unicode
= TRUE
;
1819 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1820 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1821 Dont understand why it does this. */
1822 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1824 PCALLPROCDATA CallProc
;
1825 //CallProc = CreateCallProc(NULL, Wnd->lpfnWndProc, bUnicodeWindow, Wnd->ti->ppi);
1826 CallProc
= CreateCallProc(NULL
, Wnd
->lpfnWndProc
, Wnd
->Unicode
, Wnd
->head
.pti
->ppi
);
1830 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1831 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
1835 UserAddCallProcToClass(Wnd
->pcls
, CallProc
);
1839 InitializeListHead(&Wnd
->PropListHead
);
1841 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1843 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
1844 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1845 if (Wnd
->strName
.Buffer
== NULL
)
1850 RtlCopyMemory(Wnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1851 Wnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1852 Wnd
->strName
.Length
= WindowName
->Length
;
1855 /* Correct the window style. */
1856 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1858 Wnd
->style
|= WS_CLIPSIBLINGS
;
1859 if (!(Wnd
->style
& WS_POPUP
))
1861 Wnd
->style
|= WS_CAPTION
;
1862 Window
->state
|= WINDOWOBJECT_NEED_SIZE
;
1866 if ((Wnd
->ExStyle
& WS_EX_DLGMODALFRAME
) ||
1867 (Wnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
1868 Wnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1870 Wnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1872 /* create system menu */
1873 if((Cs
->style
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1875 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
1878 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1879 IntReleaseMenuObject(SystemMenu
);
1883 /* Set the window menu */
1884 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1887 IntSetMenu(Window
, Cs
->hMenu
, &MenuChanged
);
1888 else if (Wnd
->pcls
->lpszMenuName
) // Take it from the parent.
1890 UNICODE_STRING MenuName
;
1893 if (IS_INTRESOURCE(Wnd
->pcls
->lpszMenuName
))
1895 MenuName
.Length
= 0;
1896 MenuName
.MaximumLength
= 0;
1897 MenuName
.Buffer
= Wnd
->pcls
->lpszMenuName
;
1901 RtlInitUnicodeString( &MenuName
, Wnd
->pcls
->lpszMenuName
);
1903 hMenu
= co_IntCallLoadMenu( Wnd
->pcls
->hModule
, &MenuName
);
1904 if (hMenu
) IntSetMenu(Window
, hMenu
, &MenuChanged
);
1908 Wnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1910 /* Insert the window into the thread's window list. */
1911 InsertTailList (&pti
->WindowListHead
, &Window
->ThreadListEntry
);
1913 /* Handle "CS_CLASSDC", it is tested first. */
1914 if ( (Wnd
->pcls
->style
& CS_CLASSDC
) && !(Wnd
->pcls
->pdce
) )
1915 { /* One DCE per class to have CLASS. */
1916 Wnd
->pcls
->pdce
= DceAllocDCE( Window
, DCE_CLASS_DC
);
1918 else if ( Wnd
->pcls
->style
& CS_OWNDC
)
1919 { /* Allocate a DCE for this window. */
1920 DceAllocDCE(Window
, DCE_WINDOW_DC
);
1928 UserDereferenceObject(Window
);
1931 DesktopHeapFree(Wnd
->head
.rpdesk
, Wnd
);
1933 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1941 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1942 PUNICODE_STRING ClassName
,
1943 PLARGE_STRING WindowName
)
1945 PWINDOW_OBJECT Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1946 HWND hWnd
, hWndParent
, hWndOwner
;
1948 PWINSTATION_OBJECT WinSta
;
1953 CBT_CREATEWNDW CbtCreate
;
1955 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1957 DWORD dwShowMode
= SW_SHOW
;
1958 DECLARE_RETURN(PWND
);
1960 /* Get the current window station and reference it */
1961 pti
= GetW32ThreadInfo();
1962 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1964 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1965 return NULL
; //There is nothing to cleanup
1967 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1968 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1970 /* Get the class and reference it*/
1971 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
);
1974 DPRINT1("Failed to find class %wZ\n", ClassName
);
1978 /* Now find the parent and the owner window */
1979 hWndParent
= IntGetDesktopWindow();
1982 if (Cs
->hwndParent
== HWND_MESSAGE
)
1984 Cs
->hwndParent
= hWndParent
= IntGetMessageWindow();
1986 else if (Cs
->hwndParent
)
1988 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1989 hWndOwner
= Cs
->hwndParent
;
1991 hWndParent
= Cs
->hwndParent
;
1993 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1995 DPRINT1("Cannot create a child window without a parrent!\n");
1996 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1997 RETURN(NULL
); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
2000 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
2001 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
2003 /* FIXME: is this correct?*/
2005 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
2007 /* Fix the position and the size of the window */
2010 UserRefObjectCo(ParentWindow
, &ParentRef
);
2011 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2014 /* Allocate and initialize the new window */
2015 Window
= IntCreateWindow(Cs
,
2022 DPRINT1("IntCreateWindow failed!\n");
2027 hWnd
= Window
->hSelf
;
2029 UserRefObjectCo(Window
, &Ref
);
2030 ObDereferenceObject(WinSta
);
2032 /* Call the WH_CBT hook */
2033 dwStyle
= Cs
->style
;
2034 Cs
->style
= Wnd
->style
; /* HCBT_CREATEWND needs the real window style */
2035 CbtCreate
.lpcs
= Cs
;
2036 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
2037 if (ISITHOOKED(WH_CBT
))
2039 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) &CbtCreate
))
2041 DPRINT1("HCBT_CREATEWND hook failed!\n");
2042 RETURN( (PWND
) NULL
);
2045 Cs
->style
= dwStyle
; /* NCCREATE and WM_NCCALCSIZE need the original values*/
2047 /* Send the WM_GETMINMAXINFO message*/
2051 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
2053 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2055 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2056 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2057 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2058 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2059 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2062 Wnd
->rcWindow
.left
= Cs
->x
;
2063 Wnd
->rcWindow
.top
= Cs
->y
;
2064 Wnd
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2065 Wnd
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2066 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2068 RECTL_vOffsetRect(&Wnd
->rcWindow
,
2069 ParentWindow
->Wnd
->rcClient
.left
,
2070 ParentWindow
->Wnd
->rcClient
.top
);
2072 Wnd
->rcClient
= Wnd
->rcWindow
;
2075 /* Link the window*/
2076 if (NULL
!= ParentWindow
)
2078 /* link the window into the siblings list */
2079 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2080 IntLinkHwnd(Window
, HWND_BOTTOM
);
2082 IntLinkHwnd(Window
, HWND_TOP
);
2085 /* Send the NCCREATE message */
2086 Result
= co_IntSendMessage(Window
->hSelf
, WM_NCCREATE
, 0, (LPARAM
) Cs
);
2089 DPRINT1("co_UserCreateWindowEx(): NCCREATE message failed\n");
2093 /* Send the WM_NCCALCSIZE message */
2094 MaxPos
.x
= Window
->Wnd
->rcWindow
.left
;
2095 MaxPos
.y
= Window
->Wnd
->rcWindow
.top
;
2097 Result
= co_WinPosGetNonClientSize(Window
, &Wnd
->rcWindow
, &Wnd
->rcClient
);
2099 RECTL_vOffsetRect(&Wnd
->rcWindow
, MaxPos
.x
- Wnd
->rcWindow
.left
,
2100 MaxPos
.y
- Wnd
->rcWindow
.top
);
2103 /* Send the WM_CREATE message. */
2104 Result
= co_IntSendMessage(Window
->hSelf
, WM_CREATE
, 0, (LPARAM
) Cs
);
2105 if (Result
== (LRESULT
)-1)
2107 DPRINT1("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2111 /* Send the EVENT_OBJECT_CREATE event*/
2112 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
->Wnd
, OBJID_WINDOW
, 0);
2114 /* By setting the flag below it can be examined to determine if the window
2115 was created successfully and a valid pwnd was passed back to caller since
2116 from here the function has to succeed. */
2117 Window
->Wnd
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2119 /* Send the WM_SIZE and WM_MOVE messages. */
2120 if (!(Window
->state
& WINDOWOBJECT_NEED_SIZE
))
2122 co_WinPosSendSizeMove(Window
);
2125 /* Show or maybe minimize or maximize the window. */
2126 if (Wnd
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2131 SwFlag
= (Wnd
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2133 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2135 SwFlag
= ((Wnd
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2136 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2137 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2139 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2140 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2143 /* Send the WM_PARENTNOTIFY message */
2144 if ((Wnd
->style
& WS_CHILD
) &&
2145 (!(Wnd
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
2147 co_IntSendMessage(ParentWindow
->hSelf
,
2149 MAKEWPARAM(WM_CREATE
, Wnd
->IDMenu
),
2150 (LPARAM
)Window
->hSelf
);
2153 /* Notify the shell that a new window was created */
2154 if ((!hWndParent
) && (!hWndOwner
))
2156 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2159 /* Initialize and show the window's scrollbars */
2160 if (Wnd
->style
& WS_VSCROLL
)
2162 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2164 if (Wnd
->style
& WS_HSCROLL
)
2166 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2169 /* Show the new window */
2170 if (Cs
->style
& WS_VISIBLE
)
2172 if (Wnd
->style
& WS_MAXIMIZE
)
2173 dwShowMode
= SW_SHOW
;
2174 else if (Wnd
->style
& WS_MINIMIZE
)
2175 dwShowMode
= SW_SHOWMINIMIZED
;
2177 co_WinPosShowWindow(Window
, dwShowMode
);
2179 if (Wnd
->ExStyle
& WS_EX_MDICHILD
)
2181 co_IntSendMessage(ParentWindow
->hSelf
, WM_MDIREFRESHMENU
, 0, 0);
2182 /* ShowWindow won't activate child windows */
2183 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2187 DPRINT("co_UserCreateWindowEx(): Created window %X\n", hWnd
);
2193 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2195 co_UserDestroyWindow(Window
);
2197 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2202 UserDerefObjectCo(Window
);
2203 UserDereferenceObject(Window
);
2205 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2212 ProbeAndCaptureLargeString(
2213 OUT PLARGE_STRING plstrSafe
,
2214 IN PLARGE_STRING plstrUnsafe
)
2216 LARGE_STRING lstrTemp
;
2217 PVOID pvBuffer
= NULL
;
2221 /* Probe and copy the string */
2222 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2223 lstrTemp
= *plstrUnsafe
;
2225 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2228 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2232 if (lstrTemp
.Length
!= 0)
2234 /* Allocate a buffer from paged pool */
2235 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2238 return STATUS_NO_MEMORY
;
2243 /* Probe and copy the buffer */
2244 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2245 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2247 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2249 /* Cleanup and fail */
2250 ExFreePool(pvBuffer
);
2251 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2256 /* Set the output string */
2257 plstrSafe
->Buffer
= pvBuffer
;
2258 plstrSafe
->Length
= lstrTemp
.Length
;
2259 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2261 return STATUS_SUCCESS
;
2265 * \todo Allow passing plstrClassName as ANSI.
2269 NtUserCreateWindowEx(
2271 PLARGE_STRING plstrClassName
,
2272 PLARGE_STRING plstrClsVersion
,
2273 PLARGE_STRING plstrWindowName
,
2281 HINSTANCE hInstance
,
2287 LARGE_STRING lstrWindowName
;
2288 LARGE_STRING lstrClassName
;
2289 UNICODE_STRING ustrClassName
;
2294 lstrWindowName
.Buffer
= NULL
;
2295 lstrClassName
.Buffer
= NULL
;
2297 /* Check if we got a Window name */
2298 if (plstrWindowName
)
2300 /* Copy the string to kernel mode */
2301 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2302 if (!NT_SUCCESS(Status
))
2304 DPRINT1("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2305 SetLastNtError(Status
);
2308 plstrWindowName
= &lstrWindowName
;
2311 /* Check if the class is an atom */
2312 if (IS_ATOM(plstrClassName
))
2314 /* It is, pass the atom in the UNICODE_STRING */
2315 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2316 ustrClassName
.Length
= 0;
2317 ustrClassName
.MaximumLength
= 0;
2321 /* It's not, capture the class name */
2322 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2323 if (!NT_SUCCESS(Status
))
2325 DPRINT1("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2326 /* Set last error, cleanup and return */
2327 SetLastNtError(Status
);
2331 /* We pass it on as a UNICODE_STRING */
2332 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2333 ustrClassName
.Length
= lstrClassName
.Length
;
2334 ustrClassName
.MaximumLength
= lstrClassName
.MaximumLength
;
2337 /* Fill the CREATESTRUCTW */
2338 /* we will keep here the original parameters */
2340 Cs
.lpCreateParams
= lpParam
;
2341 Cs
.hInstance
= hInstance
;
2343 Cs
.hwndParent
= hWndParent
;
2348 // Cs.lpszName = (LPCWSTR) WindowName->Buffer;
2349 // Cs.lpszClass = (LPCWSTR) ClassName->Buffer;
2350 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
;
2351 Cs
.lpszClass
= (LPCWSTR
) &ustrClassName
;
2352 Cs
.dwExStyle
= dwExStyle
;
2354 UserEnterExclusive();
2356 /* Call the internal function */
2357 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
);
2361 DPRINT1("co_UserCreateWindowEx failed!\n");
2363 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2368 if (lstrWindowName
.Buffer
)
2370 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2372 if (lstrClassName
.Buffer
)
2374 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2384 NtUserDeferWindowPos(HDWP WinPosInfo
,
2386 HWND WndInsertAfter
,
2399 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2407 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2409 hWnd
= Window
->hSelf
;
2413 if (!Wnd
) return TRUE
; // FIXME: Need to finish object rewrite or lock the thread when killing the window!
2415 DPRINT("co_UserDestroyWindow \n");
2417 /* Check for owner thread */
2418 if ( (Window
->pti
->pEThread
!= PsGetCurrentThread()) ||
2419 Wnd
->head
.pti
!= PsGetCurrentThreadWin32Thread() )
2421 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2425 /* If window was created successfully and it is hooked */
2426 if ((Wnd
->state2
& WNDS2_WMCREATEMSGPROCESSED
) && (ISITHOOKED(WH_CBT
)))
2428 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0)) return FALSE
;
2431 /* Look whether the focus is within the tree of windows we will
2434 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2436 if (UserGetActiveWindow() == Window
->hSelf
)
2438 co_WinPosActivateOtherWindow(Window
);
2442 if (Window
->pti
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2443 Window
->pti
->MessageQueue
->ActiveWindow
= NULL
;
2444 if (Window
->pti
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2445 Window
->pti
->MessageQueue
->FocusWindow
= NULL
;
2446 if (Window
->pti
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2447 Window
->pti
->MessageQueue
->CaptureWindow
= NULL
;
2450 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2453 ti
= PsGetCurrentThreadWin32Thread();
2455 if ((ti
!= NULL
) & (ti
->pDeskInfo
!= NULL
))
2457 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2459 DPRINT1("Destroying the ShellWindow!\n");
2460 ti
->pDeskInfo
->hShellWindow
= NULL
;
2464 IntDereferenceMessageQueue(Window
->pti
->MessageQueue
);
2466 IntEngWindowChanged(Window
, WOC_DELETE
);
2467 isChild
= (0 != (Wnd
->style
& WS_CHILD
));
2473 if (! USER_IsExitingThread(GetCurrentThreadId()))
2475 send_parent_notify(hwnd
, WM_DESTROY
);
2478 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2480 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2481 /* FIXME: clean up palette - see "Internals" p.352 */
2485 if (!IntIsWindow(Window
->hSelf
))
2490 /* Recursively destroy owned windows */
2495 BOOL GotOne
= FALSE
;
2498 PWINDOW_OBJECT Child
, Desktop
;
2500 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2501 UserGetWindowObject(IntGetDesktopWindow());
2502 Children
= IntWinListChildren(Desktop
);
2506 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2508 Child
= UserGetWindowObject(*ChildHandle
);
2511 if (Child
->spwndOwner
!= Window
)
2516 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2518 USER_REFERENCE_ENTRY ChildRef
;
2519 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2520 co_UserDestroyWindow(Child
);
2521 UserDerefObjectCo(Child
);//temp hack?
2527 if (Child
->spwndOwner
!= NULL
)
2529 Child
->spwndOwner
= NULL
;
2530 Child
->Wnd
->spwndOwner
= NULL
;
2534 ExFreePool(Children
);
2543 /* Generate mouse move message for the next window */
2544 msg
.message
= WM_MOUSEMOVE
;
2545 msg
.wParam
= IntGetSysCursorInfo()->ButtonsDown
;
2546 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2547 msg
.pt
= gpsi
->ptCursor
;
2548 MsqInsertSystemMessage(&msg
);
2550 if (!IntIsWindow(Window
->hSelf
))
2555 /* Destroy the window storage */
2556 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2566 NtUserDestroyWindow(HWND Wnd
)
2568 PWINDOW_OBJECT Window
;
2569 DECLARE_RETURN(BOOLEAN
);
2571 USER_REFERENCE_ENTRY Ref
;
2573 DPRINT("Enter NtUserDestroyWindow\n");
2574 UserEnterExclusive();
2576 if (!(Window
= UserGetWindowObject(Wnd
)))
2581 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2582 ret
= co_UserDestroyWindow(Window
);
2583 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2588 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2600 NtUserDrawMenuBarTemp(
2607 /* we'll use this function just for caching the menu bar */
2617 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2627 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2633 NtUserFillWindow(HWND hWndPaint
,
2644 static HWND FASTCALL
2645 IntFindWindow(PWINDOW_OBJECT Parent
,
2646 PWINDOW_OBJECT ChildAfter
,
2648 PUNICODE_STRING WindowName
)
2650 BOOL CheckWindowName
;
2653 UNICODE_STRING CurrentWindowName
;
2657 CheckWindowName
= WindowName
->Length
!= 0;
2659 if((List
= IntWinListChildren(Parent
)))
2664 /* skip handles before and including ChildAfter */
2665 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2669 /* search children */
2672 PWINDOW_OBJECT Child
;
2673 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2678 /* Do not send WM_GETTEXT messages in the kernel mode version!
2679 The user mode version however calls GetWindowText() which will
2680 send WM_GETTEXT messages to windows belonging to its processes */
2681 if (!ClassAtom
|| Child
->Wnd
->pcls
->atomClassName
== ClassAtom
)
2683 // HACK: use UNICODE_STRING instead of LARGE_STRING
2684 CurrentWindowName
.Buffer
= Child
->Wnd
->strName
.Buffer
;
2685 CurrentWindowName
.Length
= Child
->Wnd
->strName
.Length
;
2686 CurrentWindowName
.MaximumLength
= Child
->Wnd
->strName
.MaximumLength
;
2687 if(!CheckWindowName
||
2688 (Child
->Wnd
->strName
.Length
< 0xFFFF &&
2689 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2704 * Searches a window's children for a window with the specified
2707 * hwndParent = The window whose childs are to be searched.
2709 * HWND_MESSAGE = message-only windows
2711 * hwndChildAfter = Search starts after this child window.
2712 * NULL = start from beginning
2714 * ucClassName = Class name to search for
2715 * Reguired parameter.
2717 * ucWindowName = Window name
2718 * ->Buffer == NULL = don't care
2721 * The HWND of the window if it was found, otherwise NULL
2727 NtUserFindWindowEx(HWND hwndParent
,
2728 HWND hwndChildAfter
,
2729 PUNICODE_STRING ucClassName
,
2730 PUNICODE_STRING ucWindowName
,
2733 PWINDOW_OBJECT Parent
, ChildAfter
;
2734 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2735 HWND Desktop
, Ret
= NULL
;
2736 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2737 DECLARE_RETURN(HWND
);
2739 DPRINT("Enter NtUserFindWindowEx\n");
2742 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2746 if (ucClassName
!= NULL
)
2748 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2749 if (ClassName
.Length
!= 0)
2751 ProbeForRead(ClassName
.Buffer
,
2755 else if (!IS_ATOM(ClassName
.Buffer
))
2757 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2761 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2768 if (ucWindowName
!= NULL
)
2770 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2771 if (WindowName
.Length
!= 0)
2773 ProbeForRead(WindowName
.Buffer
,
2779 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2781 SetLastNtError(_SEH2_GetExceptionCode());
2782 _SEH2_YIELD(RETURN(NULL
));
2786 if (ucClassName
!= NULL
)
2788 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2789 !IS_ATOM(ClassName
.Buffer
))
2791 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2794 else if (ClassAtom
== (RTL_ATOM
)0)
2796 /* LastError code was set by IntGetAtomFromStringOrAtom */
2802 Desktop
= IntGetCurrentThreadDesktopWindow();
2804 if(hwndParent
== NULL
)
2805 hwndParent
= Desktop
;
2806 else if(hwndParent
== HWND_MESSAGE
)
2808 hwndParent
= IntGetMessageWindow();
2811 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2817 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2824 if(Parent
->hSelf
== Desktop
)
2827 PWINDOW_OBJECT TopLevelWindow
;
2828 BOOLEAN CheckWindowName
;
2829 BOOLEAN WindowMatches
;
2830 BOOLEAN ClassMatches
;
2832 /* windows searches through all top-level windows if the parent is the desktop
2835 if((List
= IntWinListChildren(Parent
)))
2841 /* skip handles before and including ChildAfter */
2842 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2846 CheckWindowName
= WindowName
.Length
!= 0;
2848 /* search children */
2851 UNICODE_STRING ustr
;
2853 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2858 /* Do not send WM_GETTEXT messages in the kernel mode version!
2859 The user mode version however calls GetWindowText() which will
2860 send WM_GETTEXT messages to windows belonging to its processes */
2861 ustr
.Buffer
= TopLevelWindow
->Wnd
->strName
.Buffer
;
2862 ustr
.Length
= TopLevelWindow
->Wnd
->strName
.Length
;
2863 ustr
.MaximumLength
= TopLevelWindow
->Wnd
->strName
.MaximumLength
;
2864 WindowMatches
= !CheckWindowName
||
2865 (TopLevelWindow
->Wnd
->strName
.Length
< 0xFFFF &&
2866 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2867 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2868 ClassAtom
== TopLevelWindow
->Wnd
->pcls
->atomClassName
;
2870 if (WindowMatches
&& ClassMatches
)
2872 Ret
= TopLevelWindow
->hSelf
;
2876 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2878 /* window returns the handle of the top-level window, in case it found
2880 Ret
= TopLevelWindow
->hSelf
;
2889 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2893 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2895 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2896 search the message-only windows. Should this also be done if
2897 Parent is the desktop window??? */
2898 PWINDOW_OBJECT MsgWindows
;
2900 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2902 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2907 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2909 SetLastNtError(_SEH2_GetExceptionCode());
2917 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2927 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
2938 PWINDOW_OBJECT FASTCALL
UserGetAncestor(PWINDOW_OBJECT Wnd
, UINT Type
)
2940 PWINDOW_OBJECT WndAncestor
, Parent
;
2942 if (Wnd
->hSelf
== IntGetDesktopWindow())
2951 WndAncestor
= Wnd
->spwndParent
;
2962 if(!(Parent
= WndAncestor
->spwndParent
))
2966 if(IntIsDesktopWindow(Parent
))
2971 WndAncestor
= Parent
;
2982 PWINDOW_OBJECT Parent
;
2984 Parent
= IntGetParent(WndAncestor
);
2991 WndAncestor
= Parent
;
3009 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3011 PWINDOW_OBJECT Window
, Ancestor
;
3012 DECLARE_RETURN(HWND
);
3014 DPRINT("Enter NtUserGetAncestor\n");
3015 UserEnterExclusive();
3017 if (!(Window
= UserGetWindowObject(hWnd
)))
3022 Ancestor
= UserGetAncestor(Window
, Type
);
3023 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3025 RETURN(Ancestor
? Ancestor
->hSelf
: NULL
);
3028 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3036 NtUserGetComboBoxInfo(
3041 DECLARE_RETURN(BOOL
);
3043 DPRINT("Enter NtUserGetComboBoxInfo\n");
3046 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3055 sizeof(COMBOBOXINFO
),
3059 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3061 SetLastNtError(_SEH2_GetExceptionCode());
3062 _SEH2_YIELD(RETURN(FALSE
));
3066 // Pass the user pointer, it was already probed.
3067 RETURN( (BOOL
) co_IntSendMessage( Wnd
->hSelf
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3070 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3080 NtUserGetInternalWindowPos( HWND hWnd
,
3084 PWINDOW_OBJECT Window
;
3087 WINDOWPLACEMENT wndpl
;
3091 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3101 ProbeForWrite(rectWnd
,
3107 ProbeForWrite(ptIcon
,
3113 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3115 SetLastNtError(_SEH2_GetExceptionCode());
3120 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3122 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3128 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3132 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3136 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3138 SetLastNtError(_SEH2_GetExceptionCode());
3143 if (!Hit
) Ret
= wndpl
.showCmd
;
3152 NtUserGetListBoxInfo(
3156 DECLARE_RETURN(DWORD
);
3158 DPRINT("Enter NtUserGetListBoxInfo\n");
3161 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3166 RETURN( (DWORD
) co_IntSendMessage( Wnd
->hSelf
, LB_GETLISTBOXINFO
, 0, 0 ));
3169 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3176 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3178 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3179 HWND hWndOldParent
= NULL
;
3180 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3182 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3184 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3188 if (hWndChild
== IntGetDesktopWindow())
3190 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3196 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3203 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3209 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3214 UserRefObjectCo(Wnd
, &Ref
);
3215 UserRefObjectCo(WndParent
, &ParentRef
);
3217 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3219 UserDerefObjectCo(WndParent
);
3220 UserDerefObjectCo(Wnd
);
3224 hWndOldParent
= WndOldParent
->hSelf
;
3225 UserDereferenceObject(WndOldParent
);
3228 return( hWndOldParent
);
3234 * The NtUserSetParent function changes the parent window of the specified
3238 * The new parent window and the child window must belong to the same
3239 * application. If the window identified by the hWndChild parameter is
3240 * visible, the system performs the appropriate redrawing and repainting.
3241 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3242 * or WS_POPUP window styles of the window whose parent is being changed.
3249 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3251 DECLARE_RETURN(HWND
);
3253 DPRINT("Enter NtUserSetParent\n");
3254 UserEnterExclusive();
3257 Check Parent first from user space, set it here.
3261 hWndNewParent
= IntGetDesktopWindow();
3263 else if (hWndNewParent
== HWND_MESSAGE
)
3265 hWndNewParent
= IntGetMessageWindow();
3268 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3271 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3277 * UserGetShellWindow
3279 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3284 HWND FASTCALL
UserGetShellWindow(VOID
)
3286 PWINSTATION_OBJECT WinStaObject
;
3289 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3294 if (!NT_SUCCESS(Status
))
3296 SetLastNtError(Status
);
3300 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3302 ObDereferenceObject(WinStaObject
);
3307 * NtUserSetShellWindowEx
3309 * This is undocumented function to set global shell window. The global
3310 * shell window has special handling of window position.
3316 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3318 PWINSTATION_OBJECT WinStaObject
;
3319 PWINDOW_OBJECT WndShell
, WndListView
;
3320 DECLARE_RETURN(BOOL
);
3321 USER_REFERENCE_ENTRY Ref
;
3325 DPRINT("Enter NtUserSetShellWindowEx\n");
3326 UserEnterExclusive();
3328 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3333 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3338 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3343 if (!NT_SUCCESS(Status
))
3345 SetLastNtError(Status
);
3350 * Test if we are permitted to change the shell window.
3352 if (WinStaObject
->ShellWindow
)
3354 ObDereferenceObject(WinStaObject
);
3359 * Move shell window into background.
3361 if (hwndListView
&& hwndListView
!= hwndShell
)
3364 * Disabled for now to get Explorer working.
3365 * -- Filip, 01/nov/2003
3368 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3371 if (WndListView
->Wnd
->ExStyle
& WS_EX_TOPMOST
)
3373 ObDereferenceObject(WinStaObject
);
3378 if (WndShell
->Wnd
->ExStyle
& WS_EX_TOPMOST
)
3380 ObDereferenceObject(WinStaObject
);
3384 UserRefObjectCo(WndShell
, &Ref
);
3385 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3387 WinStaObject
->ShellWindow
= hwndShell
;
3388 WinStaObject
->ShellListView
= hwndListView
;
3390 ti
= GetW32ThreadInfo();
3391 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3393 UserDerefObjectCo(WndShell
);
3395 ObDereferenceObject(WinStaObject
);
3399 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3405 * NtUserGetSystemMenu
3407 * The NtUserGetSystemMenu function allows the application to access the
3408 * window menu (also known as the system menu or the control menu) for
3409 * copying and modifying.
3413 * Handle to the window that will own a copy of the window menu.
3415 * Specifies the action to be taken. If this parameter is FALSE,
3416 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3417 * currently in use. The copy is initially identical to the window menu
3418 * but it can be modified.
3419 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3420 * to the default state. The previous window menu, if any, is destroyed.
3423 * If the bRevert parameter is FALSE, the return value is a handle to a
3424 * copy of the window menu. If the bRevert parameter is TRUE, the return
3432 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3434 PWINDOW_OBJECT Window
;
3436 DECLARE_RETURN(HMENU
);
3438 DPRINT("Enter NtUserGetSystemMenu\n");
3441 if (!(Window
= UserGetWindowObject(hWnd
)))
3446 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3451 RETURN(Menu
->MenuInfo
.Self
);
3454 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3460 * NtUserSetSystemMenu
3467 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3469 BOOL Result
= FALSE
;
3470 PWINDOW_OBJECT Window
;
3472 DECLARE_RETURN(BOOL
);
3474 DPRINT("Enter NtUserSetSystemMenu\n");
3475 UserEnterExclusive();
3477 if (!(Window
= UserGetWindowObject(hWnd
)))
3485 * Assign new menu handle.
3487 if (!(Menu
= UserGetMenuObject(hMenu
)))
3492 Result
= IntSetSystemMenu(Window
, Menu
);
3498 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3504 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3506 PWINDOW_OBJECT Window
, Parent
;
3508 PWINSTATION_OBJECT WindowStation
;
3512 if (hWnd
== IntGetDesktopWindow())
3514 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3518 if (!(Window
= UserGetWindowObject(hWnd
)))
3525 if (!Wnd
) return 0; // No go on zero.
3527 if ((INT
)Index
>= 0)
3529 if ((Index
+ sizeof(LONG
)) > Wnd
->cbwndExtra
)
3531 SetLastWin32Error(ERROR_INVALID_INDEX
);
3535 OldValue
= *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
));
3537 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3539 OldValue = (LONG)IntSetWindowProc( Wnd,
3542 if (!OldValue) return 0;
3545 *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
)) = NewValue
;
3552 OldValue
= (LONG
) Wnd
->ExStyle
;
3553 Style
.styleOld
= OldValue
;
3554 Style
.styleNew
= NewValue
;
3557 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3559 WindowStation
= Window
->pti
->rpdesk
->rpwinstaParent
;
3562 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3563 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3566 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3567 Wnd
->ExStyle
= (DWORD
)Style
.styleNew
;
3568 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3572 OldValue
= (LONG
) Wnd
->style
;
3573 Style
.styleOld
= OldValue
;
3574 Style
.styleNew
= NewValue
;
3575 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3576 Wnd
->style
= (DWORD
)Style
.styleNew
;
3577 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3582 if ( Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3583 Wnd
->fnid
& FNID_FREED
)
3585 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3588 OldValue
= (LONG
)IntSetWindowProc(Wnd
,
3595 OldValue
= (LONG
) Wnd
->hModule
;
3596 Wnd
->hModule
= (HINSTANCE
) NewValue
;
3599 case GWL_HWNDPARENT
:
3600 Parent
= Window
->spwndParent
;
3601 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
3602 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
3604 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
3608 OldValue
= (LONG
) Wnd
->IDMenu
;
3609 Wnd
->IDMenu
= (UINT
) NewValue
;
3613 OldValue
= Wnd
->dwUserData
;
3614 Wnd
->dwUserData
= NewValue
;
3618 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3619 SetLastWin32Error(ERROR_INVALID_INDEX
);
3629 * NtUserSetWindowLong
3631 * The NtUserSetWindowLong function changes an attribute of the specified
3632 * window. The function also sets the 32-bit (long) value at the specified
3633 * offset into the extra window memory.
3640 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3642 DECLARE_RETURN(LONG
);
3644 DPRINT("Enter NtUserSetWindowLong\n");
3645 UserEnterExclusive();
3647 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3650 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3656 * NtUserSetWindowWord
3658 * Legacy function similar to NtUserSetWindowLong.
3665 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3667 PWINDOW_OBJECT Window
;
3669 DECLARE_RETURN(WORD
);
3671 DPRINT("Enter NtUserSetWindowWord\n");
3672 UserEnterExclusive();
3674 if (!(Window
= UserGetWindowObject(hWnd
)))
3683 case GWL_HWNDPARENT
:
3684 RETURN( co_UserSetWindowLong(Window
->hSelf
, Index
, (UINT
)NewValue
, TRUE
));
3688 SetLastWin32Error(ERROR_INVALID_INDEX
);
3693 if (Index
> Window
->Wnd
->cbwndExtra
- sizeof(WORD
))
3695 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3699 OldValue
= *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3700 *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
)) = NewValue
;
3705 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3714 NtUserGetWindowPlacement(HWND hWnd
,
3715 WINDOWPLACEMENT
*lpwndpl
)
3717 PWINDOW_OBJECT Window
;
3720 WINDOWPLACEMENT Safepl
;
3722 DECLARE_RETURN(BOOL
);
3724 DPRINT("Enter NtUserGetWindowPlacement\n");
3727 if (!(Window
= UserGetWindowObject(hWnd
)))
3733 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3734 if(!NT_SUCCESS(Status
))
3736 SetLastNtError(Status
);
3739 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3745 if (0 == (Wnd
->style
& WS_VISIBLE
))
3747 Safepl
.showCmd
= SW_HIDE
;
3749 else if ((0 != (Window
->state
& WINDOWOBJECT_RESTOREMAX
) ||
3750 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
3751 0 == (Wnd
->style
& WS_MINIMIZE
))
3753 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
3755 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
3757 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
3759 else if (0 != (Wnd
->style
& WS_VISIBLE
))
3761 Safepl
.showCmd
= SW_SHOWNORMAL
;
3764 Size
.x
= Wnd
->rcWindow
.left
;
3765 Size
.y
= Wnd
->rcWindow
.top
;
3766 WinPosInitInternalPos(Window
, &Size
,
3769 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
3770 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
3771 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
3773 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3774 if(!NT_SUCCESS(Status
))
3776 SetLastNtError(Status
);
3783 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
3793 NtUserLockWindowUpdate(HWND hWnd
)
3813 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3814 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3815 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3819 QueryWindow based on KJK::Hyperion and James Tabor.
3821 0 = QWUniqueProcessId
3822 1 = QWUniqueThreadId
3825 4 = QWIsHung Implements IsHungAppWindow found
3828 9 = QWKillWindow When I called this with hWnd ==
3829 DesktopWindow, it shutdown the system
3836 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3838 PWINDOW_OBJECT Window
;
3841 DECLARE_RETURN(UINT
);
3843 DPRINT("Enter NtUserQueryWindow\n");
3846 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3855 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3856 Result
= (DWORD
)IntGetWndProcessId(Window
);
3859 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3860 Result
= (DWORD
)IntGetWndThreadId(Window
);
3863 case QUERY_WINDOW_ACTIVE
:
3864 Result
= (DWORD
)UserGetActiveWindow();
3867 case QUERY_WINDOW_FOCUS
:
3868 Result
= (DWORD
)IntGetFocusWindow();
3871 case QUERY_WINDOW_ISHUNG
:
3872 Result
= (DWORD
)MsqIsHung(Window
->pti
->MessageQueue
);
3875 case QUERY_WINDOW_REAL_ID
:
3876 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3879 Result
= (DWORD
)NULL
;
3886 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3896 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3910 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3912 UNICODE_STRING SafeMessageName
;
3915 DECLARE_RETURN(UINT
);
3917 DPRINT("Enter NtUserRegisterWindowMessage\n");
3918 UserEnterExclusive();
3920 if(MessageNameUnsafe
== NULL
)
3922 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3926 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3927 if(!NT_SUCCESS(Status
))
3929 SetLastNtError(Status
);
3933 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3934 if (SafeMessageName
.Buffer
)
3935 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3939 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3949 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3962 NtUserSetInternalWindowPos(
3979 NtUserSetLayeredWindowAttributes(HWND hwnd
,
3993 NtUserSetLogonNotifyWindow(HWND hWnd
)
4010 PWINDOW_OBJECT Window
;
4012 DECLARE_RETURN(BOOL
);
4014 DPRINT("Enter NtUserSetMenu\n");
4015 UserEnterExclusive();
4017 if (!(Window
= UserGetWindowObject(hWnd
)))
4022 if (! IntSetMenu(Window
, Menu
, &Changed
))
4027 if (Changed
&& Repaint
)
4029 USER_REFERENCE_ENTRY Ref
;
4031 UserRefObjectCo(Window
, &Ref
);
4032 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4033 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4035 UserDerefObjectCo(Window
);
4041 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4051 NtUserSetWindowFNID(HWND hWnd
,
4054 PWINDOW_OBJECT Window
;
4056 DECLARE_RETURN(BOOL
);
4058 DPRINT("Enter NtUserSetWindowFNID\n");
4059 UserEnterExclusive();
4061 if (!(Window
= UserGetWindowObject(hWnd
)))
4068 { // From user land we only set these.
4069 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
4074 Wnd
->pcls
->fnid
|= fnID
;
4079 DPRINT("Leave NtUserSetWindowFNID\n");
4089 NtUserSetWindowPlacement(HWND hWnd
,
4090 WINDOWPLACEMENT
*lpwndpl
)
4092 PWINDOW_OBJECT Window
;
4094 WINDOWPLACEMENT Safepl
;
4096 DECLARE_RETURN(BOOL
);
4097 USER_REFERENCE_ENTRY Ref
;
4099 DPRINT("Enter NtUserSetWindowPlacement\n");
4100 UserEnterExclusive();
4102 if (!(Window
= UserGetWindowObject(hWnd
)))
4108 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4109 if(!NT_SUCCESS(Status
))
4111 SetLastNtError(Status
);
4114 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4119 UserRefObjectCo(Window
, &Ref
);
4121 if ((Wnd
->style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4123 co_WinPosSetWindowPos(Window
, NULL
,
4124 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4125 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4126 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4127 SWP_NOZORDER
| SWP_NOACTIVATE
);
4130 /* FIXME - change window status */
4131 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
4133 Wnd
->InternalPosInitialized
= TRUE
;
4134 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4135 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4136 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4138 UserDerefObjectCo(Window
);
4142 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4154 HWND hWndInsertAfter
,
4161 DECLARE_RETURN(BOOL
);
4162 PWINDOW_OBJECT Window
;
4164 USER_REFERENCE_ENTRY Ref
;
4166 DPRINT("Enter NtUserSetWindowPos\n");
4167 UserEnterExclusive();
4169 if (!(Window
= UserGetWindowObject(hWnd
)))
4174 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
4175 if (!(uFlags
& SWP_NOMOVE
))
4177 if (X
< -32768) X
= -32768;
4178 else if (X
> 32767) X
= 32767;
4179 if (Y
< -32768) Y
= -32768;
4180 else if (Y
> 32767) Y
= 32767;
4182 if (!(uFlags
& SWP_NOSIZE
))
4185 else if (cx
> 32767) cx
= 32767;
4187 else if (cy
> 32767) cy
= 32767;
4190 UserRefObjectCo(Window
, &Ref
);
4191 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4192 UserDerefObjectCo(Window
);
4197 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4204 IntGetWindowRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
4222 /* Create a new window region using the window rectangle */
4223 VisRgn
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4224 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4225 /* if there's a region assigned to the window, combine them both */
4226 if(Window
->hrgnClip
&& !(Wnd
->style
& WS_MINIMIZE
))
4227 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->hrgnClip
, RGN_AND
);
4228 /* Copy the region into hRgn */
4229 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4231 if((pRgn
= RGNOBJAPI_Lock(hRgn
, NULL
)))
4233 Ret
= REGION_Complexity(pRgn
);
4234 RGNOBJAPI_Unlock(pRgn
);
4239 REGION_FreeRgnByHandle(VisRgn
);
4245 IntGetWindowRgnBox(PWINDOW_OBJECT Window
, RECTL
*Rect
)
4263 /* Create a new window region using the window rectangle */
4264 VisRgn
= IntSysCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4265 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4266 /* if there's a region assigned to the window, combine them both */
4267 if(Window
->hrgnClip
&& !(Wnd
->style
& WS_MINIMIZE
))
4268 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->hrgnClip
, RGN_AND
);
4270 if((pRgn
= RGNOBJAPI_Lock(VisRgn
, NULL
)))
4272 Ret
= REGION_Complexity(pRgn
);
4273 *Rect
= pRgn
->rdh
.rcBound
;
4274 RGNOBJAPI_Unlock(pRgn
);
4279 REGION_FreeRgnByHandle(VisRgn
);
4295 PWINDOW_OBJECT Window
;
4296 DECLARE_RETURN(INT
);
4298 DPRINT("Enter NtUserSetWindowRgn\n");
4299 UserEnterExclusive();
4301 if (!(Window
= UserGetWindowObject(hWnd
)))
4306 if (hRgn
) // The region will be deleted in user32.
4308 if (GDIOBJ_ValidateHandle(hRgn
, GDI_OBJECT_TYPE_REGION
))
4310 hrgnCopy
= IntSysCreateRectRgn(0, 0, 0, 0);
4311 NtGdiCombineRgn(hrgnCopy
, hRgn
, 0, RGN_COPY
);
4317 hrgnCopy
= (HRGN
) 1;
4319 if (Window
->hrgnClip
)
4321 /* Delete no longer needed region handle */
4322 GreDeleteObject(Window
->hrgnClip
);
4324 Window
->hrgnClip
= hrgnCopy
;
4326 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4330 USER_REFERENCE_ENTRY Ref
;
4331 UserRefObjectCo(Window
, &Ref
);
4332 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4333 UserDerefObjectCo(Window
);
4339 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4349 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4351 PWINDOW_OBJECT Window
;
4353 DECLARE_RETURN(BOOL
);
4354 USER_REFERENCE_ENTRY Ref
;
4356 DPRINT("Enter NtUserShowWindow\n");
4357 UserEnterExclusive();
4359 if (!(Window
= UserGetWindowObject(hWnd
)))
4364 UserRefObjectCo(Window
, &Ref
);
4365 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4366 UserDerefObjectCo(Window
);
4371 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4381 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4387 return NtUserShowWindow(hWnd
, nCmdShow
);
4397 NtUserUpdateLayeredWindow(
4405 BLENDFUNCTION
*pblend
,
4418 NtUserWindowFromPhysicalPoint(POINT Point
)
4429 NtUserWindowFromPoint(LONG X
, LONG Y
)
4433 PWINDOW_OBJECT DesktopWindow
= NULL
, Window
= NULL
;
4434 DECLARE_RETURN(HWND
);
4435 USER_REFERENCE_ENTRY Ref
;
4437 DPRINT("Enter NtUserWindowFromPoint\n");
4438 UserEnterExclusive();
4440 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4447 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4448 //its possible this referencing is useless, thou it shouldnt hurt...
4449 UserRefObjectCo(DesktopWindow
, &Ref
);
4451 pti
= PsGetCurrentThreadWin32Thread();
4452 co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4456 Ret
= Window
->hSelf
;
4465 if (Window
) UserDereferenceObject(Window
);
4466 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4468 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4478 * Undocumented function that is called from DefWindowProc to set
4485 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4487 PWINDOW_OBJECT Window
;
4489 LARGE_STRING SafeText
;
4490 UNICODE_STRING UnicodeString
;
4493 DPRINT("Enter NtUserDefSetText\n");
4495 if (WindowText
!= NULL
)
4499 SafeText
= ProbeForReadLargeString(WindowText
);
4501 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4504 SetLastNtError(_SEH2_GetExceptionCode());
4514 UserEnterExclusive();
4516 if(!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4523 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4524 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4525 // Now we know what the bAnsi is for.
4526 RtlInitUnicodeString(&UnicodeString
, NULL
);
4527 if (SafeText
.Buffer
)
4532 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4534 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4535 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4537 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4540 SetLastNtError(_SEH2_GetExceptionCode());
4543 if (!Ret
) goto Exit
;
4546 if (UnicodeString
.Length
!= 0)
4548 if (Wnd
->strName
.MaximumLength
> 0 &&
4549 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4551 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4553 Wnd
->strName
.Length
= UnicodeString
.Length
;
4554 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4555 RtlCopyMemory(Wnd
->strName
.Buffer
,
4556 UnicodeString
.Buffer
,
4557 UnicodeString
.Length
);
4562 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4563 buf
= Wnd
->strName
.Buffer
;
4564 Wnd
->strName
.Buffer
= NULL
;
4567 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4570 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4571 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4572 if (Wnd
->strName
.Buffer
!= NULL
)
4574 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4575 RtlCopyMemory(Wnd
->strName
.Buffer
,
4576 UnicodeString
.Buffer
,
4577 UnicodeString
.Length
);
4578 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4579 Wnd
->strName
.Length
= UnicodeString
.Length
;
4583 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4591 Wnd
->strName
.Length
= 0;
4592 if (Wnd
->strName
.Buffer
!= NULL
)
4593 Wnd
->strName
.Buffer
[0] = L
'\0';
4596 // HAX! FIXME! Windows does not do this in here!
4597 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4598 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4599 /* Send shell notifications */
4600 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
4602 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4607 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4608 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4614 * NtUserInternalGetWindowText
4621 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4623 PWINDOW_OBJECT Window
;
4627 DECLARE_RETURN(INT
);
4629 DPRINT("Enter NtUserInternalGetWindowText\n");
4632 if(lpString
&& (nMaxCount
<= 1))
4634 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4638 if(!(Window
= UserGetWindowObject(hWnd
)))
4644 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4647 const WCHAR Terminator
= L
'\0';
4649 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4651 Copy
= min(nMaxCount
- 1, Result
);
4654 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4655 if(!NT_SUCCESS(Status
))
4657 SetLastNtError(Status
);
4663 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4664 if(!NT_SUCCESS(Status
))
4666 SetLastNtError(Status
);
4676 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4684 IntShowOwnedPopups(PWINDOW_OBJECT OwnerWnd
, BOOL fShow
)
4687 PWINDOW_OBJECT pWnd
;
4690 // ASSERT(OwnerWnd);
4692 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
4697 while (win_array
[count
])
4699 while (--count
>= 0)
4701 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4703 if (pWnd
->spwndOwner
!= OwnerWnd
)
4708 if (pWnd
->Wnd
->state
& WNDS_HIDDENPOPUP
)
4710 /* In Windows, ShowOwnedPopups(TRUE) generates
4711 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4712 * regardless of the state of the owner
4714 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4720 if (pWnd
->Wnd
->style
& WS_VISIBLE
)
4722 /* In Windows, ShowOwnedPopups(FALSE) generates
4723 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4724 * regardless of the state of the owner
4726 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4732 ExFreePool( win_array
);
4737 * NtUserValidateHandleSecure
4745 NtUserValidateHandleSecure(
4753 PUSER_HANDLE_ENTRY entry
;
4754 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
4756 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4759 uType
= entry
->type
;
4765 PWINDOW_OBJECT Window
;
4766 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
4772 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
4777 PACCELERATOR_TABLE Accel
;
4778 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
4783 PCURICON_OBJECT Cursor
;
4784 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
4790 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
4796 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
4802 return UserGetCallProcInfo( handle
, &Proc
);
4805 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4809 { /* Is handle entry restricted? */