2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
5 * FILE: subsystems/win32/win32k/ntuser/window.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
11 /* INCLUDES ******************************************************************/
18 /* dialog resources appear to pass this in 16 bits, handle them properly */
19 #define CW_USEDEFAULT16 (0x8000)
21 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
23 /* PRIVATE FUNCTIONS **********************************************************/
28 * Initialize windowing implementation.
36 return STATUS_SUCCESS
;
42 * Cleanup windowing implementation.
46 CleanupWindowImpl(VOID
)
48 return STATUS_SUCCESS
;
51 /* HELPER FUNCTIONS ***********************************************************/
53 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
55 WORD Action
= LOWORD(wParam
);
56 WORD Flags
= HIWORD(wParam
);
58 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
60 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
67 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
71 if (Flags
& UISF_HIDEFOCUS
)
72 Wnd
->HideFocus
= TRUE
;
73 if (Flags
& UISF_HIDEACCEL
)
74 Wnd
->HideAccel
= TRUE
;
78 if (Flags
& UISF_HIDEFOCUS
)
79 Wnd
->HideFocus
= FALSE
;
80 if (Flags
& UISF_HIDEACCEL
)
81 Wnd
->HideAccel
= FALSE
;
88 PWND FASTCALL
IntGetWindowObject(HWND hWnd
)
92 if (!hWnd
) return NULL
;
94 Window
= UserGetWindowObject(hWnd
);
97 ASSERT(Window
->head
.cLockObj
>= 0);
99 Window
->head
.cLockObj
++;
105 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
110 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
112 ti
= GetW32ThreadInfo();
115 SetLastWin32Error(ERROR_ACCESS_DENIED
);
122 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
126 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
127 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
129 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
133 ASSERT(Window
->head
.cLockObj
>= 0);
142 * The function determines whether the specified window handle identifies
143 * an existing window.
147 * Handle to the window to test.
150 * If the window handle identifies an existing window, the return value
151 * is TRUE. If the window handle does not identify an existing window,
152 * the return value is FALSE.
156 IntIsWindow(HWND hWnd
)
160 if (!(Window
= UserGetWindowObject(hWnd
)))
168 IntGetParent(PWND Wnd
)
170 if (Wnd
->style
& WS_POPUP
)
172 return Wnd
->spwndOwner
;
174 else if (Wnd
->style
& WS_CHILD
)
176 return Wnd
->spwndParent
;
185 * Compile a list of all child window handles from given window.
188 * This function is similar to Wine WIN_ListChildren. The caller
189 * must free the returned list with ExFreePool.
193 IntWinListChildren(PWND Window
)
197 UINT Index
, NumChildren
= 0;
199 if (!Window
) return NULL
;
201 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
204 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
207 DPRINT1("Failed to allocate memory for children array\n");
208 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
211 for (Child
= Window
->spwndChild
, Index
= 0;
213 Child
= Child
->spwndNext
, ++Index
)
214 List
[Index
] = Child
->head
.h
;
220 /***********************************************************************
223 static void IntSendDestroyMsg(HWND hWnd
)
231 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
233 if (hWnd
== info
.hwndCaret
)
240 Window
= UserGetWindowObject(hWnd
);
243 // USER_REFERENCE_ENTRY Ref;
244 // UserRefObjectCo(Window, &Ref);
246 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
248 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
251 // UserDerefObjectCo(Window);
254 /* The window could already be destroyed here */
257 * Send the WM_DESTROY to the window.
260 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
263 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
264 * make sure that the window still exists when we come back.
273 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
276 /* start from the end (FIXME: is this needed?) */
277 for (i
= 0; pWndArray
[i
]; i
++)
282 if (IsWindow( pWndArray
[i
] ))
283 WIN_SendDestroyMsg( pWndArray
[i
] );
285 HeapFree(GetProcessHeap(), 0, pWndArray
);
289 DPRINT("destroyed itself while in WM_DESTROY!\n");
295 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
297 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
301 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
303 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
304 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
307 if (Wnd
->strName
.Buffer
!= NULL
)
309 Wnd
->strName
.Length
= 0;
310 Wnd
->strName
.MaximumLength
= 0;
311 DesktopHeapFree(Wnd
->head
.rpdesk
,
312 Wnd
->strName
.Buffer
);
313 Wnd
->strName
.Buffer
= NULL
;
316 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
317 // WindowObject->Wnd = NULL;
320 /***********************************************************************
323 * Destroy storage associated to a window. "Internals" p.358
325 * This is the "functional" DestroyWindows function ei. all stuff
326 * done in CreateWindow is undone here and not in DestroyWindow:-P
329 static LRESULT
co_UserFreeWindow(PWND Window
,
330 PPROCESSINFO ProcessData
,
331 PTHREADINFO ThreadData
,
332 BOOLEAN SendMessages
)
338 BOOLEAN BelongsToThreadData
;
342 if(Window
->state2
& WNDS2_INDESTROY
)
344 DPRINT("Tried to call IntDestroyWindow() twice\n");
347 Window
->state2
|= WNDS2_INDESTROY
;
348 Window
->style
&= ~WS_VISIBLE
;
350 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
352 /* remove the window already at this point from the thread window list so we
353 don't get into trouble when destroying the thread windows while we're still
354 in IntDestroyWindow() */
355 RemoveEntryList(&Window
->ThreadListEntry
);
357 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
359 IntDeRegisterShellHookWindow(Window
->head
.h
);
363 /* Send destroy messages */
364 IntSendDestroyMsg(Window
->head
.h
);
367 /* free child windows */
368 Children
= IntWinListChildren(Window
);
371 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
373 if ((Child
= IntGetWindowObject(*ChildHandle
)))
375 if(!IntWndBelongsToThread(Child
, ThreadData
))
377 /* send WM_DESTROY messages to windows not belonging to the same thread */
378 IntSendDestroyMsg(Child
->head
.h
);
381 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
383 UserDereferenceObject(Child
);
386 ExFreePool(Children
);
392 * Clear the update region to make sure no WM_PAINT messages will be
393 * generated for this window while processing the WM_NCDESTROY.
395 co_UserRedrawWindow(Window
, NULL
, 0,
396 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
397 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
398 if(BelongsToThreadData
)
399 co_IntSendMessage(Window
->head
.h
, WM_NCDESTROY
, 0, 0);
402 DestroyTimersForWindow(ThreadData
, Window
);
404 /* Unregister hot keys */
405 UnregisterWindowHotKeys (Window
);
407 /* flush the message queue */
408 MsqRemoveWindowMessagesFromQueue(Window
);
410 /* from now on no messages can be sent to this window anymore */
411 Window
->state
|= WNDS_DESTROYED
;
412 Window
->fnid
|= FNID_FREED
;
414 /* don't remove the WINDOWSTATUS_DESTROYING bit */
416 /* reset shell window handles */
417 if(ThreadData
->rpdesk
)
419 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
420 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
422 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
423 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
426 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
430 WinPosCheckInternalPos(Window
->head
.h
);
431 if (Window
->head
.h
== GetCapture())
436 /* free resources associated with the window */
437 TIMER_RemoveWindowTimers(Window
->head
.h
);
440 if (!(Window
->style
& WS_CHILD
) && Window
->IDMenu
441 && (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
443 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
447 if(Window
->SystemMenu
448 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
450 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
451 Window
->SystemMenu
= (HMENU
)0;
454 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
457 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
458 CLASS_RemoveWindow(Window
->Class
);
461 IntUnlinkWindow(Window
);
463 UserReferenceObject(Window
);
464 UserDeleteObject(Window
->head
.h
, otWindow
);
466 IntDestroyScrollBars(Window
);
468 /* dereference the class */
469 IntDereferenceClass(Window
->pcls
,
470 Window
->head
.pti
->pDeskInfo
,
471 Window
->head
.pti
->ppi
);
476 GreDeleteObject(Window
->hrgnClip
);
479 // ASSERT(Window != NULL);
480 UserFreeWindowInfo(Window
->head
.pti
, Window
);
482 UserDereferenceObject(Window
);
484 IntClipboardFreeWindow(Window
);
490 IntGetWindowBorderMeasures(PWND Wnd
, UINT
*cx
, UINT
*cy
)
492 if(HAS_DLGFRAME(Wnd
->style
, Wnd
->ExStyle
) && !(Wnd
->style
& WS_MINIMIZE
))
494 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
495 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
499 if(HAS_THICKFRAME(Wnd
->style
, Wnd
->ExStyle
)&& !(Wnd
->style
& WS_MINIMIZE
))
501 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
502 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
504 else if(HAS_THINFRAME(Wnd
->style
, Wnd
->ExStyle
))
506 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
507 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
517 // Same as User32:IntGetWndProc.
520 IntGetWindowProc(PWND pWnd
,
525 WNDPROC gcpd
, Ret
= 0;
527 ASSERT(UserIsEnteredExclusive() == TRUE
);
531 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
533 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
535 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
538 Ret
= GETPFNCLIENTA(i
);
540 Ret
= GETPFNCLIENTW(i
);
546 if (Class
->fnid
== FNID_EDIT
)
547 Ret
= pWnd
->lpfnWndProc
;
550 Ret
= pWnd
->lpfnWndProc
;
552 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
556 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
557 Ret
= GETPFNCLIENTA(Class
->fnid
);
561 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
562 Ret
= GETPFNCLIENTW(Class
->fnid
);
565 if ( Ret
!= pWnd
->lpfnWndProc
)
568 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
571 gcpd
= (WNDPROC
)UserGetCPD(
573 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
576 return (gcpd
? gcpd
: Ret
);
580 IntSetWindowProc(PWND pWnd
,
585 PCALLPROCDATA CallProc
;
587 WNDPROC Ret
, chWndProc
= NULL
;
589 // Retrieve previous window proc.
590 Ret
= IntGetWindowProc(pWnd
, Ansi
);
594 if (IsCallProcHandle(NewWndProc
))
596 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, otCallProc
);
598 { // Reset new WndProc.
599 NewWndProc
= CallProc
->pfnClientPrevious
;
600 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
601 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
604 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
605 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
607 if (GETPFNCLIENTW(i
) == NewWndProc
)
609 chWndProc
= GETPFNSERVER(i
);
612 if (GETPFNCLIENTA(i
) == NewWndProc
)
614 chWndProc
= GETPFNSERVER(i
);
618 // If match, set/reset to Server Side and clear ansi.
621 pWnd
->lpfnWndProc
= chWndProc
;
622 pWnd
->Unicode
= TRUE
;
623 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
624 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
628 pWnd
->Unicode
= !Ansi
;
629 // Handle the state change in here.
631 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
633 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
635 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
636 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
638 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
640 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
644 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
645 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
649 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
650 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
653 // Now set the new window proc.
654 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
659 // Move this to user space!
661 IntGetWindowInfo(PWND Wnd
, PWINDOWINFO pwi
)
663 pwi
->cbSize
= sizeof(WINDOWINFO
);
664 pwi
->rcWindow
= Wnd
->rcWindow
;
665 pwi
->rcClient
= Wnd
->rcClient
;
666 pwi
->dwStyle
= Wnd
->style
;
667 pwi
->dwExStyle
= Wnd
->ExStyle
;
668 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Wnd
->head
.h
); /* WS_ACTIVECAPTION */
669 IntGetWindowBorderMeasures(Wnd
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
670 pwi
->atomWindowType
= (Wnd
->pcls
? Wnd
->pcls
->atomClassName
: 0);
671 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
681 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
683 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
685 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
689 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
697 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
698 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Wnd
->head
.h
);
707 NewMenu
= IntGetMenuObject(Menu
);
712 IntReleaseMenuObject(OldMenu
);
714 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
717 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
719 /* Can't use the same menu for two windows */
722 IntReleaseMenuObject(OldMenu
);
724 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
730 Wnd
->IDMenu
= (UINT
) Menu
;
733 NewMenu
->MenuInfo
.Wnd
= Wnd
->head
.h
;
734 IntReleaseMenuObject(NewMenu
);
738 OldMenu
->MenuInfo
.Wnd
= NULL
;
739 IntReleaseMenuObject(OldMenu
);
746 /* INTERNAL ******************************************************************/
750 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
755 USER_REFERENCE_ENTRY Ref
;
756 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
758 while (!IsListEmpty(&WThread
->WindowListHead
))
760 Current
= WThread
->WindowListHead
.Flink
;
761 Wnd
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
763 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
765 /* window removes itself from the list */
768 fixme: it is critical that the window removes itself! if now, we will loop
772 //ASSERT(co_UserDestroyWindow(Wnd));
774 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
775 if (!co_UserDestroyWindow(Wnd
))
777 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
779 UserDerefObjectCo(Wnd
);//faxme: temp hack??
787 * Returns client window rectangle relative to the upper-left corner of client area.
789 * \note Does not check the validity of the parameters
792 IntGetClientRect(PWND Window
, RECTL
*Rect
)
797 Rect
->left
= Rect
->top
= 0;
798 Rect
->right
= Window
->rcClient
.right
- Window
->rcClient
.left
;
799 Rect
->bottom
= Window
->rcClient
.bottom
- Window
->rcClient
.top
;
805 IntGetFocusWindow(VOID
)
807 PUSER_MESSAGE_QUEUE Queue
;
808 PDESKTOP pdo
= IntGetActiveDesktop();
813 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
818 return(Queue
->FocusWindow
);
822 PMENU_OBJECT FASTCALL
823 IntGetSystemMenu(PWND Window
, BOOL bRevert
, BOOL RetMenu
)
825 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
826 PTHREADINFO W32Thread
;
827 HMENU hNewMenu
, hSysMenu
;
828 ROSMENUITEMINFO ItemInfo
;
832 W32Thread
= PsGetCurrentThreadWin32Thread();
834 if(!W32Thread
->rpdesk
)
837 if(Window
->SystemMenu
)
839 Menu
= UserGetMenuObject(Window
->SystemMenu
);
842 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
843 Window
->SystemMenu
= (HMENU
)0;
847 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
849 /* clone system menu */
850 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
854 NewMenu
= IntCloneMenu(Menu
);
857 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
858 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
859 NewMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
861 //IntReleaseMenuObject(NewMenu);
866 hSysMenu
= UserCreateMenu(FALSE
);
867 if (NULL
== hSysMenu
)
871 SysMenu
= IntGetMenuObject(hSysMenu
);
874 UserDestroyMenu(hSysMenu
);
877 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
878 SysMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
879 hNewMenu
= co_IntLoadSysMenuTemplate();
882 IntReleaseMenuObject(SysMenu
);
883 UserDestroyMenu(hSysMenu
);
886 Menu
= IntGetMenuObject(hNewMenu
);
889 IntReleaseMenuObject(SysMenu
);
890 UserDestroyMenu(hSysMenu
);
894 NewMenu
= IntCloneMenu(Menu
);
897 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
898 IntReleaseMenuObject(NewMenu
);
899 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
901 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
902 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
903 ItemInfo
.fType
= MF_POPUP
;
904 ItemInfo
.fState
= MFS_ENABLED
;
905 ItemInfo
.dwTypeData
= NULL
;
907 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
908 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
910 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
914 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
923 if(Window
->SystemMenu
)
924 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
932 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
939 if (Window
== Parent
)
943 if(!(Window
->style
& WS_CHILD
))
948 Window
= Window
->spwndParent
;
955 IntIsWindowVisible(PWND BaseWindow
)
962 if(!(Window
->style
& WS_CHILD
))
966 if(!(Window
->style
& WS_VISIBLE
))
971 Window
= Window
->spwndParent
;
974 if(Window
&& Window
->style
& WS_VISIBLE
)
984 link the window into siblings list
985 children and parent are kept in place.
990 PWND WndInsertAfter
/* set to NULL if top sibling */
993 if ((Wnd
->spwndPrev
= WndInsertAfter
))
995 /* link after WndInsertAfter */
996 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
997 Wnd
->spwndNext
->spwndPrev
= Wnd
;
999 Wnd
->spwndPrev
->spwndNext
= Wnd
;
1004 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
1005 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1007 Wnd
->spwndParent
->spwndChild
= Wnd
;
1012 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
1014 if (hWndPrev
== HWND_NOTOPMOST
)
1016 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1017 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
1018 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1019 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
1022 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
1024 if (hWndPrev
== HWND_BOTTOM
)
1026 /* Link in the bottom of the list */
1027 PWND WndInsertAfter
;
1029 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
1030 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
1031 WndInsertAfter
= WndInsertAfter
->spwndNext
;
1033 IntLinkWindow(Wnd
, WndInsertAfter
);
1034 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1036 else if (hWndPrev
== HWND_TOPMOST
)
1038 /* Link in the top of the list */
1039 IntLinkWindow(Wnd
, NULL
);
1041 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1043 else if (hWndPrev
== HWND_TOP
)
1045 /* Link it after the last topmost window */
1046 PWND WndInsertBefore
;
1048 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
1050 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
1052 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
1054 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
1055 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
1057 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1060 WndInsertBefore
= WndInsertBefore
->spwndNext
;
1064 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
1068 /* Link it after hWndPrev */
1069 PWND WndInsertAfter
;
1071 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1072 /* Are we called with an erroneous handle */
1073 if(WndInsertAfter
== NULL
)
1075 /* Link in a default position */
1076 IntLinkHwnd(Wnd
, HWND_TOP
);
1080 IntLinkWindow(Wnd
, WndInsertAfter
);
1082 /* Fix the WS_EX_TOPMOST flag */
1083 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1085 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1089 if(WndInsertAfter
->spwndNext
&&
1090 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1092 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1099 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1101 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1104 Wnd
= IntGetWindowObject(hWnd
);
1108 WndOldOwner
= Wnd
->spwndOwner
;
1110 ret
= WndOldOwner
? WndOldOwner
->head
.h
: 0;
1112 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1114 Wnd
->spwndOwner
= WndNewOwner
;
1118 Wnd
->spwndOwner
= NULL
;
1121 UserDereferenceObject(Wnd
);
1126 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1132 ASSERT(WndNewParent
);
1133 ASSERT_REFS_CO(Wnd
);
1134 ASSERT_REFS_CO(WndNewParent
);
1136 /* Some applications try to set a child as a parent */
1137 if (IntIsChildWindow(Wnd
, WndNewParent
))
1139 SetLastWin32Error( ERROR_INVALID_PARAMETER
);
1144 * Windows hides the window first, then shows it again
1145 * including the WM_SHOWWINDOW messages and all
1147 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1149 /* Window must belong to current process */
1150 if (Wnd
->head
.pti
->pEThread
->ThreadsProcess
!= PsGetCurrentProcess())
1153 WndOldParent
= Wnd
->spwndParent
;
1155 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1157 if (WndNewParent
!= WndOldParent
)
1159 /* Unlink the window from the siblings list */
1160 IntUnlinkWindow(Wnd
);
1162 /* Set the new parent */
1163 Wnd
->spwndParent
= WndNewParent
;
1165 /* Link the window with its new siblings*/
1166 IntLinkHwnd(Wnd
, HWND_TOP
);
1170 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1172 * SetParent additionally needs to make hwnd the top window
1173 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1174 * WM_WINDOWPOSCHANGED notification messages.
1176 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1177 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1178 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1181 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1182 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1185 return WndOldParent
;
1189 IntSetSystemMenu(PWND Window
, PMENU_OBJECT Menu
)
1191 PMENU_OBJECT OldMenu
;
1192 if(Window
->SystemMenu
)
1194 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1197 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1198 IntReleaseMenuObject(OldMenu
);
1204 /* FIXME check window style, propably return FALSE ? */
1205 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1206 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1209 Window
->SystemMenu
= (HMENU
)0;
1214 /* unlink the window from siblings. children and parent are kept in place. */
1216 IntUnlinkWindow(PWND Wnd
)
1219 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1222 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1224 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1225 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1227 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1232 IntGetWindowPlacement(PWND Wnd
, WINDOWPLACEMENT
*lpwndpl
)
1236 if (!Wnd
) return FALSE
;
1238 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1244 if (0 == (Wnd
->style
& WS_VISIBLE
))
1246 lpwndpl
->showCmd
= SW_HIDE
;
1248 else if (0 != (Wnd
->state2
& WNDS2_MAXIMIZEBUTTONDOWN
) ||
1249 0 != (Wnd
->style
& WS_MAXIMIZE
))
1251 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1253 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1255 lpwndpl
->showCmd
= SW_MINIMIZE
;
1257 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1259 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1262 Size
.x
= Wnd
->rcWindow
.left
;
1263 Size
.y
= Wnd
->rcWindow
.top
;
1264 WinPosInitInternalPos(Wnd
, &Size
,
1267 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1268 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1269 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1275 /* FUNCTIONS *****************************************************************/
1281 NtUserAlterWindowStyle(DWORD Unknown0
,
1291 * As best as I can figure, this function is used by EnumWindows,
1292 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1294 * It's supposed to build a list of HWNDs to return to the caller.
1295 * We can figure out what kind of list by what parameters are
1303 NtUserBuildHwndList(
1316 return ERROR_INVALID_PARAMETER
;
1318 if (hwndParent
|| !dwThreadId
)
1321 PWND Parent
, Window
;
1325 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1327 return ERROR_INVALID_HANDLE
;
1332 Status
= IntValidateDesktopHandle(hDesktop
,
1336 if(!NT_SUCCESS(Status
))
1338 return ERROR_INVALID_HANDLE
;
1341 hwndParent
= Desktop
->DesktopWindow
;
1348 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1349 (Window
= Parent
->spwndChild
))
1351 BOOL bGoDown
= TRUE
;
1353 Status
= STATUS_SUCCESS
;
1358 if(dwCount
++ < *pBufSize
&& pWnd
)
1362 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1363 *pWnd
= Window
->head
.h
;
1366 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1368 Status
= _SEH2_GetExceptionCode();
1371 if(!NT_SUCCESS(Status
))
1373 SetLastNtError(Status
);
1377 if (Window
->spwndChild
&& bChildren
)
1379 Window
= Window
->spwndChild
;
1384 if (Window
->spwndNext
)
1386 Window
= Window
->spwndNext
;
1390 Window
= Window
->spwndParent
;
1391 if (Window
== Parent
)
1400 ObDereferenceObject(Desktop
);
1406 PTHREADINFO W32Thread
;
1407 PLIST_ENTRY Current
;
1410 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1411 if(!NT_SUCCESS(Status
))
1413 return ERROR_INVALID_PARAMETER
;
1415 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1417 ObDereferenceObject(Thread
);
1418 DPRINT("Thread is not a GUI Thread!\n");
1419 return ERROR_INVALID_PARAMETER
;
1422 Current
= W32Thread
->WindowListHead
.Flink
;
1423 while(Current
!= &(W32Thread
->WindowListHead
))
1425 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1428 if(bChildren
|| Window
->spwndOwner
!= NULL
)
1430 if(dwCount
< *pBufSize
&& pWnd
)
1432 Status
= MmCopyToCaller(pWnd
++, &Window
->head
.h
, sizeof(HWND
));
1433 if(!NT_SUCCESS(Status
))
1435 SetLastNtError(Status
);
1441 Current
= Current
->Flink
;
1444 ObDereferenceObject(Thread
);
1447 *pBufSize
= dwCount
;
1448 return STATUS_SUCCESS
;
1456 NtUserChildWindowFromPointEx(HWND hwndParent
,
1466 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1474 if(Parent
->head
.h
!= IntGetDesktopWindow())
1476 Pt
.x
+= Parent
->rcClient
.left
;
1477 Pt
.y
+= Parent
->rcClient
.top
;
1480 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1485 Ret
= Parent
->head
.h
;
1486 if((List
= IntWinListChildren(Parent
)))
1488 for(phWnd
= List
; *phWnd
; phWnd
++)
1491 if((Child
= UserGetWindowObject(*phWnd
)))
1493 if(!(Child
->style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1497 if((Child
->style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1501 if((Child
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1505 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1507 Ret
= Child
->head
.h
;
1518 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1520 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1521 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1523 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1525 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1527 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1528 (LPARAM
)pWindow
->head
.h
);
1534 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1536 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1538 /* default positioning for overlapped windows */
1539 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1542 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1544 pMonitor
= IntGetPrimaryMonitor();
1547 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1549 if (IS_DEFAULT(Cs
->x
))
1551 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1553 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1555 Cs
->x
= ProcessParams
->StartingX
;
1556 Cs
->y
= ProcessParams
->StartingY
;
1560 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1561 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1562 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1563 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1565 /* reset counter and position */
1568 pMonitor
->cWndStack
= 0;
1570 pMonitor
->cWndStack
++;
1574 if (IS_DEFAULT(Cs
->cx
))
1576 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1578 Cs
->cx
= ProcessParams
->CountX
;
1579 Cs
->cy
= ProcessParams
->CountY
;
1583 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1584 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1587 /* neither x nor cx are default. Check the y values .
1588 * In the trace we see Outlook and Outlook Express using
1589 * cy set to CW_USEDEFAULT when opening the address book.
1591 else if (IS_DEFAULT(Cs
->cy
))
1593 DPRINT("Strange use of CW_USEDEFAULT in nHeight\n");
1594 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1599 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1600 if(IS_DEFAULT(Cs
->x
))
1605 if(IS_DEFAULT(Cs
->cx
))
1615 /* Allocates and initializes a window*/
1616 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1617 PLARGE_STRING WindowName
,
1624 PTHREADINFO pti
= NULL
;
1625 PMENU_OBJECT SystemMenu
;
1627 BOOL bUnicodeWindow
;
1629 pti
= PsGetCurrentThreadWin32Thread();
1631 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1635 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1636 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1637 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1638 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1642 Note from MSDN http://msdn.microsoft.com/en-us/library/aa913269.aspx :
1644 Dialog boxes and message boxes do not inherit layout, so you must
1645 set the layout explicitly.
1647 if ( Class
&& Class
->fnid
!= FNID_DIALOG
)
1649 PPROCESSINFO ppi
= PsGetCurrentProcessWin32Process();
1650 if (ppi
->dwLayout
& LAYOUT_RTL
)
1652 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1658 /* Automatically add WS_EX_WINDOWEDGE */
1659 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1660 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1661 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1662 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1664 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1666 /* Is it a unicode window? */
1667 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1668 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1670 /* Allocate the new window */
1671 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1675 sizeof(WND
) + Class
->cbwndExtra
);
1682 DPRINT("Created object with handle %X\n", hWnd
);
1684 if (NULL
== pti
->rpdesk
->DesktopWindow
)
1686 /* If there is no desktop window yet, we must be creating it */
1687 pti
->rpdesk
->DesktopWindow
= hWnd
;
1688 pti
->rpdesk
->pDeskInfo
->spwnd
= pWnd
;
1692 * Fill out the structure describing it.
1694 /* Remember, pWnd->head is setup in object.c ...*/
1695 pWnd
->spwndParent
= ParentWindow
;
1696 pWnd
->spwndOwner
= OwnerWindow
;
1698 pWnd
->hWndLastActive
= hWnd
;
1699 pWnd
->state2
|= WNDS2_WIN40COMPAT
;
1701 pWnd
->hModule
= Cs
->hInstance
;
1702 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1703 pWnd
->ExStyle
= Cs
->dwExStyle
;
1704 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1706 IntReferenceMessageQueue(pWnd
->head
.pti
->MessageQueue
);
1707 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1709 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1710 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1713 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1714 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1716 /* BugBoy Comments: Comment below say that System classes are always created
1717 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1718 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1720 No where can I see in code or through testing does the window change back
1721 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1722 see what problems this would cause.*/
1724 // Set WndProc from Class.
1725 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1727 // GetWindowProc, test for non server side default classes and set WndProc.
1728 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1732 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1733 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1737 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1738 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1742 // If not an Unicode caller, set Ansi creator bit.
1743 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1745 // Clone Class Ansi/Unicode proc type.
1746 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1748 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1749 pWnd
->Unicode
= FALSE
;
1753 It seems there can be both an Ansi creator and Unicode Class Window
1754 WndProc, unless the following overriding conditions occur:
1756 if ( !bUnicodeWindow
&&
1757 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1758 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1759 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1760 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1761 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1762 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1763 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1764 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1765 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1766 { // Override Class and set the window Ansi WndProc.
1767 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1768 pWnd
->Unicode
= FALSE
;
1771 { // Set the window Unicode WndProc.
1772 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1773 pWnd
->Unicode
= TRUE
;
1777 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1778 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1779 Dont understand why it does this. */
1780 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1782 PCALLPROCDATA CallProc
;
1783 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1787 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1788 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
1792 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1796 InitializeListHead(&pWnd
->PropListHead
);
1798 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1800 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1801 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1802 if (pWnd
->strName
.Buffer
== NULL
)
1807 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1808 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1809 pWnd
->strName
.Length
= WindowName
->Length
;
1812 /* Correct the window style. */
1813 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1815 pWnd
->style
|= WS_CLIPSIBLINGS
;
1816 if (!(pWnd
->style
& WS_POPUP
))
1818 pWnd
->style
|= WS_CAPTION
;
1819 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1823 if ((pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
) ||
1824 (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
1825 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1827 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1829 /* create system menu */
1830 if((Cs
->style
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1832 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1835 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1836 IntReleaseMenuObject(SystemMenu
);
1840 /* Set the window menu */
1841 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1844 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1845 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1847 UNICODE_STRING MenuName
;
1850 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1852 MenuName
.Length
= 0;
1853 MenuName
.MaximumLength
= 0;
1854 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1858 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1860 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1861 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1865 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1867 /* Insert the window into the thread's window list. */
1868 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1870 /* Handle "CS_CLASSDC", it is tested first. */
1871 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1872 { /* One DCE per class to have CLASS. */
1873 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1875 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1876 { /* Allocate a DCE for this window. */
1877 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1885 UserDereferenceObject(pWnd
);
1887 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1895 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1896 PUNICODE_STRING ClassName
,
1897 PLARGE_STRING WindowName
)
1899 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1900 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1901 PWINSTATION_OBJECT WinSta
;
1905 CBT_CREATEWNDW
* pCbtCreate
;
1907 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1909 DWORD dwShowMode
= SW_SHOW
;
1910 CREATESTRUCTW
*pCsw
= NULL
;
1911 PVOID pszClass
= NULL
, pszName
= NULL
;
1912 DECLARE_RETURN(PWND
);
1914 /* Get the current window station and reference it */
1915 pti
= GetW32ThreadInfo();
1916 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1918 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1919 return NULL
; //There is nothing to cleanup
1921 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1922 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1927 /* Get the class and reference it*/
1928 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
);
1931 DPRINT1("Failed to find class %wZ\n", ClassName
);
1935 /* Now find the parent and the owner window */
1936 hWndParent
= IntGetDesktopWindow();
1939 if (Cs
->hwndParent
== HWND_MESSAGE
)
1941 Cs
->hwndParent
= hWndParent
= IntGetMessageWindow();
1943 else if (Cs
->hwndParent
)
1945 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1946 hWndOwner
= Cs
->hwndParent
;
1948 hWndParent
= Cs
->hwndParent
;
1950 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1952 DPRINT1("Cannot create a child window without a parrent!\n");
1953 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1954 RETURN(NULL
); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1957 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1958 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1960 /* FIXME: is this correct?*/
1962 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
1964 /* Fix the position and the size of the window */
1967 UserRefObjectCo(ParentWindow
, &ParentRef
);
1968 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
1971 /* Allocate and initialize the new window */
1972 Window
= IntCreateWindow(Cs
,
1979 DPRINT1("IntCreateWindow failed!\n");
1983 hWnd
= UserHMGetHandle(Window
);
1984 hwndInsertAfter
= HWND_TOP
;
1986 UserRefObjectCo(Window
, &Ref
);
1987 ObDereferenceObject(WinSta
);
1989 //// Check for a hook to eliminate overhead. ////
1990 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
1992 // Allocate the calling structures Justin Case this goes Global.
1993 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
1994 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
1996 /* Fill the new CREATESTRUCTW */
1997 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
1998 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2000 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2001 if (!IS_ATOM(ClassName
->Buffer
))
2003 if (Window
->state
& WNDS_ANSICREATOR
)
2005 ANSI_STRING AnsiString
;
2006 AnsiString
.MaximumLength
= RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2007 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2008 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2009 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2010 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2014 UNICODE_STRING UnicodeString
;
2015 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2016 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2017 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2018 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2019 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2021 if (pszClass
) pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2023 if (WindowName
->Length
)
2025 UNICODE_STRING Name
;
2026 Name
.Buffer
= WindowName
->Buffer
;
2027 Name
.Length
= WindowName
->Length
;
2028 Name
.MaximumLength
= WindowName
->MaximumLength
;
2030 if (Window
->state
& WNDS_ANSICREATOR
)
2032 ANSI_STRING AnsiString
;
2033 AnsiString
.MaximumLength
= RtlUnicodeStringToAnsiSize(&Name
)+sizeof(CHAR
);
2034 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2035 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2036 AnsiString
.Buffer
= (PCHAR
)pszName
;
2037 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2041 UNICODE_STRING UnicodeString
;
2042 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2043 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2044 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2045 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2046 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2048 if (pszName
) pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2051 pCbtCreate
->lpcs
= pCsw
;
2052 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2054 //// Call the WH_CBT hook ////
2055 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2058 DPRINT1("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2059 RETURN( (PWND
) NULL
);
2061 // Write back changes.
2066 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2069 /* NCCREATE and WM_NCCALCSIZE need the original values */
2070 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2071 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2073 /* Send the WM_GETMINMAXINFO message*/
2077 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2079 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2081 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2082 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2083 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2084 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2085 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2088 Window
->rcWindow
.left
= Cs
->x
;
2089 Window
->rcWindow
.top
= Cs
->y
;
2090 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2091 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2092 if (0 != (Window
->style
& WS_CHILD
) && ParentWindow
)
2094 RECTL_vOffsetRect(&Window
->rcWindow
,
2095 ParentWindow
->rcClient
.left
,
2096 ParentWindow
->rcClient
.top
);
2098 Window
->rcClient
= Window
->rcWindow
;
2101 /* Link the window*/
2102 if (NULL
!= ParentWindow
)
2104 /* link the window into the siblings list */
2105 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2106 IntLinkHwnd(Window
, HWND_BOTTOM
);
2108 IntLinkHwnd(Window
, hwndInsertAfter
);
2111 /* Send the NCCREATE message */
2112 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2115 DPRINT1("co_UserCreateWindowEx(): NCCREATE message failed\n");
2119 /* Send the WM_NCCALCSIZE message */
2120 MaxPos
.x
= Window
->rcWindow
.left
;
2121 MaxPos
.y
= Window
->rcWindow
.top
;
2123 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2125 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2126 MaxPos
.y
- Window
->rcWindow
.top
);
2129 /* Send the WM_CREATE message. */
2130 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2131 if (Result
== (LRESULT
)-1)
2133 DPRINT1("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2137 /* Send the EVENT_OBJECT_CREATE event*/
2138 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2140 /* By setting the flag below it can be examined to determine if the window
2141 was created successfully and a valid pwnd was passed back to caller since
2142 from here the function has to succeed. */
2143 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2145 /* Send the WM_SIZE and WM_MOVE messages. */
2146 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2148 co_WinPosSendSizeMove(Window
);
2151 /* Show or maybe minimize or maximize the window. */
2152 if (Window
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2157 SwFlag
= (Window
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2159 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2161 SwFlag
= ((Window
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2162 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2163 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2165 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2166 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2169 /* Send the WM_PARENTNOTIFY message */
2170 IntSendParentNotify(Window
, WM_CREATE
);
2172 /* Notify the shell that a new window was created */
2173 if ((!hWndParent
) && (!hWndOwner
))
2175 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2178 /* Initialize and show the window's scrollbars */
2179 if (Window
->style
& WS_VSCROLL
)
2181 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2183 if (Window
->style
& WS_HSCROLL
)
2185 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2188 /* Show the new window */
2189 if (Cs
->style
& WS_VISIBLE
)
2191 if (Window
->style
& WS_MAXIMIZE
)
2192 dwShowMode
= SW_SHOW
;
2193 else if (Window
->style
& WS_MINIMIZE
)
2194 dwShowMode
= SW_SHOWMINIMIZED
;
2196 co_WinPosShowWindow(Window
, dwShowMode
);
2198 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2200 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2201 /* ShowWindow won't activate child windows */
2202 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2206 DPRINT("co_UserCreateWindowEx(): Created window %X\n", hWnd
);
2212 DPRINT("co_UserCreateWindowEx(): Error Created window!\n");
2213 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2215 co_UserDestroyWindow(Window
);
2217 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2220 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2221 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2222 if (pszName
) UserHeapFree(pszName
);
2223 if (pszClass
) UserHeapFree(pszClass
);
2227 UserDerefObjectCo(Window
);
2228 UserDereferenceObject(Window
);
2230 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2237 ProbeAndCaptureLargeString(
2238 OUT PLARGE_STRING plstrSafe
,
2239 IN PLARGE_STRING plstrUnsafe
)
2241 LARGE_STRING lstrTemp
;
2242 PVOID pvBuffer
= NULL
;
2246 /* Probe and copy the string */
2247 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2248 lstrTemp
= *plstrUnsafe
;
2250 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2253 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2257 if (lstrTemp
.Length
!= 0)
2259 /* Allocate a buffer from paged pool */
2260 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2263 return STATUS_NO_MEMORY
;
2268 /* Probe and copy the buffer */
2269 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2270 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2272 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2274 /* Cleanup and fail */
2275 ExFreePool(pvBuffer
);
2276 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2281 /* Set the output string */
2282 plstrSafe
->Buffer
= pvBuffer
;
2283 plstrSafe
->Length
= lstrTemp
.Length
;
2284 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2286 return STATUS_SUCCESS
;
2290 * \todo Allow passing plstrClassName as ANSI.
2294 NtUserCreateWindowEx(
2296 PLARGE_STRING plstrClassName
,
2297 PLARGE_STRING plstrClsVersion
,
2298 PLARGE_STRING plstrWindowName
,
2306 HINSTANCE hInstance
,
2312 LARGE_STRING lstrWindowName
;
2313 LARGE_STRING lstrClassName
;
2314 UNICODE_STRING ustrClassName
;
2319 lstrWindowName
.Buffer
= NULL
;
2320 lstrClassName
.Buffer
= NULL
;
2322 /* Check if we got a Window name */
2323 if (plstrWindowName
)
2325 /* Copy the string to kernel mode */
2326 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2327 if (!NT_SUCCESS(Status
))
2329 DPRINT1("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2330 SetLastNtError(Status
);
2333 plstrWindowName
= &lstrWindowName
;
2336 /* Check if the class is an atom */
2337 if (IS_ATOM(plstrClassName
))
2339 /* It is, pass the atom in the UNICODE_STRING */
2340 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2341 ustrClassName
.Length
= 0;
2342 ustrClassName
.MaximumLength
= 0;
2346 /* It's not, capture the class name */
2347 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2348 if (!NT_SUCCESS(Status
))
2350 DPRINT1("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2351 /* Set last error, cleanup and return */
2352 SetLastNtError(Status
);
2356 /* We pass it on as a UNICODE_STRING */
2357 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2358 ustrClassName
.Length
= lstrClassName
.Length
;
2359 ustrClassName
.MaximumLength
= lstrClassName
.MaximumLength
;
2362 /* Fill the CREATESTRUCTW */
2363 /* we will keep here the original parameters */
2365 Cs
.lpCreateParams
= lpParam
;
2366 Cs
.hInstance
= hInstance
;
2368 Cs
.hwndParent
= hWndParent
;
2373 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2374 if (IS_ATOM(plstrClassName
))
2375 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2377 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2378 Cs
.dwExStyle
= dwExStyle
;
2380 UserEnterExclusive();
2382 /* Call the internal function */
2383 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
);
2387 DPRINT1("co_UserCreateWindowEx failed!\n");
2389 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2394 if (lstrWindowName
.Buffer
)
2396 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2398 if (lstrClassName
.Buffer
)
2400 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2410 NtUserDeferWindowPos(HDWP WinPosInfo
,
2412 HWND WndInsertAfter
,
2425 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2431 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2433 hWnd
= Window
->head
.h
;
2435 DPRINT("co_UserDestroyWindow \n");
2437 /* Check for owner thread */
2438 if ( (Window
->head
.pti
->pEThread
!= PsGetCurrentThread()) ||
2439 Window
->head
.pti
!= PsGetCurrentThreadWin32Thread() )
2441 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2445 /* If window was created successfully and it is hooked */
2446 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2448 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2450 DPRINT1("Destroy Window WH_CBT Call Hook return!\n");
2455 /* Inform the parent */
2456 if (Window
->style
& WS_CHILD
)
2458 IntSendParentNotify(Window
, WM_DESTROY
);
2461 /* Look whether the focus is within the tree of windows we will
2464 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2466 if (UserGetActiveWindow() == Window
->head
.h
)
2468 co_WinPosActivateOtherWindow(Window
);
2472 if (Window
->head
.pti
->MessageQueue
->ActiveWindow
== Window
->head
.h
)
2473 Window
->head
.pti
->MessageQueue
->ActiveWindow
= NULL
;
2474 if (Window
->head
.pti
->MessageQueue
->FocusWindow
== Window
->head
.h
)
2475 Window
->head
.pti
->MessageQueue
->FocusWindow
= NULL
;
2476 if (Window
->head
.pti
->MessageQueue
->CaptureWindow
== Window
->head
.h
)
2477 Window
->head
.pti
->MessageQueue
->CaptureWindow
= NULL
;
2480 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2483 ti
= PsGetCurrentThreadWin32Thread();
2485 if ((ti
!= NULL
) & (ti
->pDeskInfo
!= NULL
))
2487 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2489 DPRINT1("Destroying the ShellWindow!\n");
2490 ti
->pDeskInfo
->hShellWindow
= NULL
;
2494 IntDereferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
2496 IntEngWindowChanged(Window
, WOC_DELETE
);
2498 if (!IntIsWindow(Window
->head
.h
))
2503 /* Recursively destroy owned windows */
2505 if (! (Window
->style
& WS_CHILD
))
2509 BOOL GotOne
= FALSE
;
2512 PWND Child
, Desktop
;
2514 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2515 UserGetWindowObject(IntGetDesktopWindow());
2516 Children
= IntWinListChildren(Desktop
);
2520 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2522 Child
= UserGetWindowObject(*ChildHandle
);
2525 if (Child
->spwndOwner
!= Window
)
2530 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2532 USER_REFERENCE_ENTRY ChildRef
;
2533 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2534 co_UserDestroyWindow(Child
);
2535 UserDerefObjectCo(Child
);//temp hack?
2541 if (Child
->spwndOwner
!= NULL
)
2543 Child
->spwndOwner
= NULL
;
2547 ExFreePool(Children
);
2556 /* Generate mouse move message for the next window */
2557 msg
.message
= WM_MOUSEMOVE
;
2558 msg
.wParam
= IntGetSysCursorInfo()->ButtonsDown
;
2559 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2560 msg
.pt
= gpsi
->ptCursor
;
2561 co_MsqInsertMouseMessage(&msg
);
2563 if (!IntIsWindow(Window
->head
.h
))
2568 /* Destroy the window storage */
2569 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2579 NtUserDestroyWindow(HWND Wnd
)
2582 DECLARE_RETURN(BOOLEAN
);
2584 USER_REFERENCE_ENTRY Ref
;
2586 DPRINT("Enter NtUserDestroyWindow\n");
2587 UserEnterExclusive();
2589 if (!(Window
= UserGetWindowObject(Wnd
)))
2594 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2595 ret
= co_UserDestroyWindow(Window
);
2596 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2601 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2613 NtUserDrawMenuBarTemp(
2620 /* we'll use this function just for caching the menu bar */
2630 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2640 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2646 NtUserFillWindow(HWND hWndPaint
,
2657 static HWND FASTCALL
2658 IntFindWindow(PWND Parent
,
2661 PUNICODE_STRING WindowName
)
2663 BOOL CheckWindowName
;
2666 UNICODE_STRING CurrentWindowName
;
2670 CheckWindowName
= WindowName
->Length
!= 0;
2672 if((List
= IntWinListChildren(Parent
)))
2677 /* skip handles before and including ChildAfter */
2678 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2682 /* search children */
2686 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2691 /* Do not send WM_GETTEXT messages in the kernel mode version!
2692 The user mode version however calls GetWindowText() which will
2693 send WM_GETTEXT messages to windows belonging to its processes */
2694 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2696 // HACK: use UNICODE_STRING instead of LARGE_STRING
2697 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2698 CurrentWindowName
.Length
= Child
->strName
.Length
;
2699 CurrentWindowName
.MaximumLength
= Child
->strName
.MaximumLength
;
2700 if(!CheckWindowName
||
2701 (Child
->strName
.Length
< 0xFFFF &&
2702 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2704 Ret
= Child
->head
.h
;
2717 * Searches a window's children for a window with the specified
2720 * hwndParent = The window whose childs are to be searched.
2722 * HWND_MESSAGE = message-only windows
2724 * hwndChildAfter = Search starts after this child window.
2725 * NULL = start from beginning
2727 * ucClassName = Class name to search for
2728 * Reguired parameter.
2730 * ucWindowName = Window name
2731 * ->Buffer == NULL = don't care
2734 * The HWND of the window if it was found, otherwise NULL
2740 NtUserFindWindowEx(HWND hwndParent
,
2741 HWND hwndChildAfter
,
2742 PUNICODE_STRING ucClassName
,
2743 PUNICODE_STRING ucWindowName
,
2746 PWND Parent
, ChildAfter
;
2747 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2748 HWND Desktop
, Ret
= NULL
;
2749 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2750 DECLARE_RETURN(HWND
);
2752 DPRINT("Enter NtUserFindWindowEx\n");
2755 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2759 if (ucClassName
!= NULL
)
2761 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2762 if (ClassName
.Length
!= 0)
2764 ProbeForRead(ClassName
.Buffer
,
2768 else if (!IS_ATOM(ClassName
.Buffer
))
2770 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2774 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2781 if (ucWindowName
!= NULL
)
2783 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2784 if (WindowName
.Length
!= 0)
2786 ProbeForRead(WindowName
.Buffer
,
2792 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2794 SetLastNtError(_SEH2_GetExceptionCode());
2795 _SEH2_YIELD(RETURN(NULL
));
2799 if (ucClassName
!= NULL
)
2801 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2802 !IS_ATOM(ClassName
.Buffer
))
2804 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2807 else if (ClassAtom
== (RTL_ATOM
)0)
2809 /* LastError code was set by IntGetAtomFromStringOrAtom */
2815 Desktop
= IntGetCurrentThreadDesktopWindow();
2817 if(hwndParent
== NULL
)
2818 hwndParent
= Desktop
;
2819 else if(hwndParent
== HWND_MESSAGE
)
2821 hwndParent
= IntGetMessageWindow();
2824 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2830 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2837 if(Parent
->head
.h
== Desktop
)
2840 PWND TopLevelWindow
;
2841 BOOLEAN CheckWindowName
;
2842 BOOLEAN WindowMatches
;
2843 BOOLEAN ClassMatches
;
2845 /* windows searches through all top-level windows if the parent is the desktop
2848 if((List
= IntWinListChildren(Parent
)))
2854 /* skip handles before and including ChildAfter */
2855 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2859 CheckWindowName
= WindowName
.Length
!= 0;
2861 /* search children */
2864 UNICODE_STRING ustr
;
2866 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2871 /* Do not send WM_GETTEXT messages in the kernel mode version!
2872 The user mode version however calls GetWindowText() which will
2873 send WM_GETTEXT messages to windows belonging to its processes */
2874 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2875 ustr
.Length
= TopLevelWindow
->strName
.Length
;
2876 ustr
.MaximumLength
= TopLevelWindow
->strName
.MaximumLength
;
2877 WindowMatches
= !CheckWindowName
||
2878 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2879 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2880 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2881 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2883 if (WindowMatches
&& ClassMatches
)
2885 Ret
= TopLevelWindow
->head
.h
;
2889 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2891 /* window returns the handle of the top-level window, in case it found
2893 Ret
= TopLevelWindow
->head
.h
;
2902 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2906 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2908 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2909 search the message-only windows. Should this also be done if
2910 Parent is the desktop window??? */
2913 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2915 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2920 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2922 SetLastNtError(_SEH2_GetExceptionCode());
2930 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2940 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
2951 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
2953 PWND WndAncestor
, Parent
;
2955 if (Wnd
->head
.h
== IntGetDesktopWindow())
2964 WndAncestor
= Wnd
->spwndParent
;
2975 if(!(Parent
= WndAncestor
->spwndParent
))
2979 if(IntIsDesktopWindow(Parent
))
2984 WndAncestor
= Parent
;
2997 Parent
= IntGetParent(WndAncestor
);
3004 WndAncestor
= Parent
;
3022 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3024 PWND Window
, Ancestor
;
3025 DECLARE_RETURN(HWND
);
3027 DPRINT("Enter NtUserGetAncestor\n");
3028 UserEnterExclusive();
3030 if (!(Window
= UserGetWindowObject(hWnd
)))
3035 Ancestor
= UserGetAncestor(Window
, Type
);
3036 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3038 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3041 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3049 NtUserGetComboBoxInfo(
3054 DECLARE_RETURN(BOOL
);
3056 DPRINT("Enter NtUserGetComboBoxInfo\n");
3059 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3068 sizeof(COMBOBOXINFO
),
3072 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3074 SetLastNtError(_SEH2_GetExceptionCode());
3075 _SEH2_YIELD(RETURN(FALSE
));
3079 // Pass the user pointer, it was already probed.
3080 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3083 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3093 NtUserGetInternalWindowPos( HWND hWnd
,
3100 WINDOWPLACEMENT wndpl
;
3104 if (!(Window
= UserGetWindowObject(hWnd
)))
3114 ProbeForWrite(rectWnd
,
3120 ProbeForWrite(ptIcon
,
3126 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3128 SetLastNtError(_SEH2_GetExceptionCode());
3133 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3135 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3141 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3145 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3149 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3151 SetLastNtError(_SEH2_GetExceptionCode());
3156 if (!Hit
) Ret
= wndpl
.showCmd
;
3165 NtUserGetListBoxInfo(
3169 DECLARE_RETURN(DWORD
);
3171 DPRINT("Enter NtUserGetListBoxInfo\n");
3174 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3179 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3182 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3189 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3191 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3192 HWND hWndOldParent
= NULL
;
3193 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3195 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3197 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3201 if (hWndChild
== IntGetDesktopWindow())
3203 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3209 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3216 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3222 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3227 UserRefObjectCo(Wnd
, &Ref
);
3228 UserRefObjectCo(WndParent
, &ParentRef
);
3230 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3232 UserDerefObjectCo(WndParent
);
3233 UserDerefObjectCo(Wnd
);
3237 hWndOldParent
= WndOldParent
->head
.h
;
3238 UserDereferenceObject(WndOldParent
);
3241 return( hWndOldParent
);
3247 * The NtUserSetParent function changes the parent window of the specified
3251 * The new parent window and the child window must belong to the same
3252 * application. If the window identified by the hWndChild parameter is
3253 * visible, the system performs the appropriate redrawing and repainting.
3254 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3255 * or WS_POPUP window styles of the window whose parent is being changed.
3262 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3264 DECLARE_RETURN(HWND
);
3266 DPRINT("Enter NtUserSetParent\n");
3267 UserEnterExclusive();
3270 Check Parent first from user space, set it here.
3274 hWndNewParent
= IntGetDesktopWindow();
3276 else if (hWndNewParent
== HWND_MESSAGE
)
3278 hWndNewParent
= IntGetMessageWindow();
3281 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3284 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3290 * UserGetShellWindow
3292 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3297 HWND FASTCALL
UserGetShellWindow(VOID
)
3299 PWINSTATION_OBJECT WinStaObject
;
3302 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3307 if (!NT_SUCCESS(Status
))
3309 SetLastNtError(Status
);
3313 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3315 ObDereferenceObject(WinStaObject
);
3320 * NtUserSetShellWindowEx
3322 * This is undocumented function to set global shell window. The global
3323 * shell window has special handling of window position.
3329 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3331 PWINSTATION_OBJECT WinStaObject
;
3332 PWND WndShell
, WndListView
;
3333 DECLARE_RETURN(BOOL
);
3334 USER_REFERENCE_ENTRY Ref
;
3338 DPRINT("Enter NtUserSetShellWindowEx\n");
3339 UserEnterExclusive();
3341 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3346 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3351 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3356 if (!NT_SUCCESS(Status
))
3358 SetLastNtError(Status
);
3363 * Test if we are permitted to change the shell window.
3365 if (WinStaObject
->ShellWindow
)
3367 ObDereferenceObject(WinStaObject
);
3372 * Move shell window into background.
3374 if (hwndListView
&& hwndListView
!= hwndShell
)
3377 * Disabled for now to get Explorer working.
3378 * -- Filip, 01/nov/2003
3381 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3384 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3386 ObDereferenceObject(WinStaObject
);
3391 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3393 ObDereferenceObject(WinStaObject
);
3397 UserRefObjectCo(WndShell
, &Ref
);
3398 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3400 WinStaObject
->ShellWindow
= hwndShell
;
3401 WinStaObject
->ShellListView
= hwndListView
;
3403 ti
= GetW32ThreadInfo();
3404 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3406 UserDerefObjectCo(WndShell
);
3408 ObDereferenceObject(WinStaObject
);
3412 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3418 * NtUserGetSystemMenu
3420 * The NtUserGetSystemMenu function allows the application to access the
3421 * window menu (also known as the system menu or the control menu) for
3422 * copying and modifying.
3426 * Handle to the window that will own a copy of the window menu.
3428 * Specifies the action to be taken. If this parameter is FALSE,
3429 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3430 * currently in use. The copy is initially identical to the window menu
3431 * but it can be modified.
3432 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3433 * to the default state. The previous window menu, if any, is destroyed.
3436 * If the bRevert parameter is FALSE, the return value is a handle to a
3437 * copy of the window menu. If the bRevert parameter is TRUE, the return
3445 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3449 DECLARE_RETURN(HMENU
);
3451 DPRINT("Enter NtUserGetSystemMenu\n");
3454 if (!(Window
= UserGetWindowObject(hWnd
)))
3459 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3464 RETURN(Menu
->MenuInfo
.Self
);
3467 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3473 * NtUserSetSystemMenu
3480 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3482 BOOL Result
= FALSE
;
3485 DECLARE_RETURN(BOOL
);
3487 DPRINT("Enter NtUserSetSystemMenu\n");
3488 UserEnterExclusive();
3490 if (!(Window
= UserGetWindowObject(hWnd
)))
3498 * Assign new menu handle.
3500 if (!(Menu
= UserGetMenuObject(hMenu
)))
3505 Result
= IntSetSystemMenu(Window
, Menu
);
3511 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3517 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3519 PWND Window
, Parent
;
3520 PWINSTATION_OBJECT WindowStation
;
3524 if (hWnd
== IntGetDesktopWindow())
3526 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3530 if (!(Window
= UserGetWindowObject(hWnd
)))
3535 if ((INT
)Index
>= 0)
3537 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3539 SetLastWin32Error(ERROR_INVALID_INDEX
);
3543 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3545 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3547 OldValue = (LONG)IntSetWindowProc( Wnd,
3550 if (!OldValue) return 0;
3553 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3560 OldValue
= (LONG
) Window
->ExStyle
;
3561 Style
.styleOld
= OldValue
;
3562 Style
.styleNew
= NewValue
;
3565 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3567 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3570 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3571 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3574 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3575 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3576 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3580 OldValue
= (LONG
) Window
->style
;
3581 Style
.styleOld
= OldValue
;
3582 Style
.styleNew
= NewValue
;
3583 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3584 Window
->style
= (DWORD
)Style
.styleNew
;
3585 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3590 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3591 Window
->fnid
& FNID_FREED
)
3593 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3596 OldValue
= (LONG
)IntSetWindowProc(Window
,
3603 OldValue
= (LONG
) Window
->hModule
;
3604 Window
->hModule
= (HINSTANCE
) NewValue
;
3607 case GWL_HWNDPARENT
:
3608 Parent
= Window
->spwndParent
;
3609 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3610 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3612 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3616 OldValue
= (LONG
) Window
->IDMenu
;
3617 Window
->IDMenu
= (UINT
) NewValue
;
3621 OldValue
= Window
->dwUserData
;
3622 Window
->dwUserData
= NewValue
;
3626 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3627 SetLastWin32Error(ERROR_INVALID_INDEX
);
3637 * NtUserSetWindowLong
3639 * The NtUserSetWindowLong function changes an attribute of the specified
3640 * window. The function also sets the 32-bit (long) value at the specified
3641 * offset into the extra window memory.
3648 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3650 DECLARE_RETURN(LONG
);
3652 DPRINT("Enter NtUserSetWindowLong\n");
3653 UserEnterExclusive();
3655 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3658 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3664 * NtUserSetWindowWord
3666 * Legacy function similar to NtUserSetWindowLong.
3673 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3677 DECLARE_RETURN(WORD
);
3679 DPRINT("Enter NtUserSetWindowWord\n");
3680 UserEnterExclusive();
3682 if (!(Window
= UserGetWindowObject(hWnd
)))
3691 case GWL_HWNDPARENT
:
3692 RETURN( co_UserSetWindowLong(Window
->head
.h
, Index
, (UINT
)NewValue
, TRUE
));
3696 SetLastWin32Error(ERROR_INVALID_INDEX
);
3701 if (Index
> Window
->cbwndExtra
- sizeof(WORD
))
3703 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3707 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3708 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3713 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3722 NtUserGetWindowPlacement(HWND hWnd
,
3723 WINDOWPLACEMENT
*lpwndpl
)
3727 WINDOWPLACEMENT Safepl
;
3729 DECLARE_RETURN(BOOL
);
3731 DPRINT("Enter NtUserGetWindowPlacement\n");
3734 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3739 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3740 if(!NT_SUCCESS(Status
))
3742 SetLastNtError(Status
);
3745 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3751 if (0 == (Wnd
->style
& WS_VISIBLE
))
3753 Safepl
.showCmd
= SW_HIDE
;
3755 else if ((0 != (Wnd
->state2
& WNDS2_MAXIMIZEBUTTONDOWN
) ||
3756 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
3757 0 == (Wnd
->style
& WS_MINIMIZE
))
3759 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
3761 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
3763 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
3765 else if (0 != (Wnd
->style
& WS_VISIBLE
))
3767 Safepl
.showCmd
= SW_SHOWNORMAL
;
3770 Size
.x
= Wnd
->rcWindow
.left
;
3771 Size
.y
= Wnd
->rcWindow
.top
;
3772 WinPosInitInternalPos(Wnd
, &Size
,
3775 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
3776 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
3777 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
3779 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3780 if(!NT_SUCCESS(Status
))
3782 SetLastNtError(Status
);
3789 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
3799 NtUserLockWindowUpdate(HWND hWnd
)
3819 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3820 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3821 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3825 QueryWindow based on KJK::Hyperion and James Tabor.
3827 0 = QWUniqueProcessId
3828 1 = QWUniqueThreadId
3831 4 = QWIsHung Implements IsHungAppWindow found
3834 9 = QWKillWindow When I called this with hWnd ==
3835 DesktopWindow, it shutdown the system
3842 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3846 DECLARE_RETURN(UINT
);
3848 DPRINT("Enter NtUserQueryWindow\n");
3851 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3858 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3859 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3862 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3863 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3866 case QUERY_WINDOW_ACTIVE
:
3867 Result
= (DWORD
)UserGetActiveWindow();
3870 case QUERY_WINDOW_FOCUS
:
3871 Result
= (DWORD
)IntGetFocusWindow();
3874 case QUERY_WINDOW_ISHUNG
:
3875 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
->MessageQueue
);
3878 case QUERY_WINDOW_REAL_ID
:
3879 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3882 Result
= (DWORD
)NULL
;
3889 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3899 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3913 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3915 UNICODE_STRING SafeMessageName
;
3918 DECLARE_RETURN(UINT
);
3920 DPRINT("Enter NtUserRegisterWindowMessage\n");
3921 UserEnterExclusive();
3923 if(MessageNameUnsafe
== NULL
)
3925 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3929 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3930 if(!NT_SUCCESS(Status
))
3932 SetLastNtError(Status
);
3936 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3937 if (SafeMessageName
.Buffer
)
3938 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3942 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3952 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3965 NtUserSetInternalWindowPos(
3982 NtUserSetLayeredWindowAttributes(HWND hwnd
,
3996 NtUserSetLogonNotifyWindow(HWND hWnd
)
4015 DECLARE_RETURN(BOOL
);
4017 DPRINT("Enter NtUserSetMenu\n");
4018 UserEnterExclusive();
4020 if (!(Window
= UserGetWindowObject(hWnd
)))
4025 if (! IntSetMenu(Window
, Menu
, &Changed
))
4030 if (Changed
&& Repaint
)
4032 USER_REFERENCE_ENTRY Ref
;
4034 UserRefObjectCo(Window
, &Ref
);
4035 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4036 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4038 UserDerefObjectCo(Window
);
4044 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4054 NtUserSetWindowFNID(HWND hWnd
,
4058 DECLARE_RETURN(BOOL
);
4060 DPRINT("Enter NtUserSetWindowFNID\n");
4061 UserEnterExclusive();
4063 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4069 { // From user land we only set these.
4070 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
4075 Wnd
->pcls
->fnid
|= fnID
;
4080 DPRINT("Leave NtUserSetWindowFNID\n");
4090 NtUserSetWindowPlacement(HWND hWnd
,
4091 WINDOWPLACEMENT
*lpwndpl
)
4094 WINDOWPLACEMENT Safepl
;
4096 DECLARE_RETURN(BOOL
);
4097 USER_REFERENCE_ENTRY Ref
;
4099 DPRINT("Enter NtUserSetWindowPlacement\n");
4100 UserEnterExclusive();
4102 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4107 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4108 if(!NT_SUCCESS(Status
))
4110 SetLastNtError(Status
);
4113 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4118 UserRefObjectCo(Wnd
, &Ref
);
4120 if ((Wnd
->style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4122 co_WinPosSetWindowPos(Wnd
, NULL
,
4123 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4124 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4125 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4126 SWP_NOZORDER
| SWP_NOACTIVATE
);
4129 /* FIXME - change window status */
4130 co_WinPosShowWindow(Wnd
, Safepl
.showCmd
);
4132 Wnd
->InternalPosInitialized
= TRUE
;
4133 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4134 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4135 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4137 UserDerefObjectCo(Wnd
);
4141 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4153 HWND hWndInsertAfter
,
4160 DECLARE_RETURN(BOOL
);
4163 USER_REFERENCE_ENTRY Ref
;
4165 DPRINT("Enter NtUserSetWindowPos\n");
4166 UserEnterExclusive();
4168 if (!(Window
= UserGetWindowObject(hWnd
)))
4173 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
4174 if (!(uFlags
& SWP_NOMOVE
))
4176 if (X
< -32768) X
= -32768;
4177 else if (X
> 32767) X
= 32767;
4178 if (Y
< -32768) Y
= -32768;
4179 else if (Y
> 32767) Y
= 32767;
4181 if (!(uFlags
& SWP_NOSIZE
))
4184 else if (cx
> 32767) cx
= 32767;
4186 else if (cy
> 32767) cy
= 32767;
4189 UserRefObjectCo(Window
, &Ref
);
4190 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4191 UserDerefObjectCo(Window
);
4196 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4203 IntGetWindowRgn(PWND Window
, HRGN hRgn
)
4218 /* Create a new window region using the window rectangle */
4219 VisRgn
= IntSysCreateRectRgnIndirect(&Window
->rcWindow
);
4220 NtGdiOffsetRgn(VisRgn
, -Window
->rcWindow
.left
, -Window
->rcWindow
.top
);
4221 /* if there's a region assigned to the window, combine them both */
4222 if(Window
->hrgnClip
&& !(Window
->style
& WS_MINIMIZE
))
4223 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->hrgnClip
, RGN_AND
);
4224 /* Copy the region into hRgn */
4225 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4227 if((pRgn
= RGNOBJAPI_Lock(hRgn
, NULL
)))
4229 Ret
= REGION_Complexity(pRgn
);
4230 RGNOBJAPI_Unlock(pRgn
);
4235 REGION_FreeRgnByHandle(VisRgn
);
4241 IntGetWindowRgnBox(PWND Window
, RECTL
*Rect
)
4256 /* Create a new window region using the window rectangle */
4257 VisRgn
= IntSysCreateRectRgnIndirect(&Window
->rcWindow
);
4258 NtGdiOffsetRgn(VisRgn
, -Window
->rcWindow
.left
, -Window
->rcWindow
.top
);
4259 /* if there's a region assigned to the window, combine them both */
4260 if(Window
->hrgnClip
&& !(Window
->style
& WS_MINIMIZE
))
4261 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->hrgnClip
, RGN_AND
);
4263 if((pRgn
= RGNOBJAPI_Lock(VisRgn
, NULL
)))
4265 Ret
= REGION_Complexity(pRgn
);
4266 *Rect
= pRgn
->rdh
.rcBound
;
4267 RGNOBJAPI_Unlock(pRgn
);
4272 REGION_FreeRgnByHandle(VisRgn
);
4289 DECLARE_RETURN(INT
);
4291 DPRINT("Enter NtUserSetWindowRgn\n");
4292 UserEnterExclusive();
4294 if (!(Window
= UserGetWindowObject(hWnd
)))
4299 if (hRgn
) // The region will be deleted in user32.
4301 if (GDIOBJ_ValidateHandle(hRgn
, GDI_OBJECT_TYPE_REGION
))
4303 hrgnCopy
= IntSysCreateRectRgn(0, 0, 0, 0);
4304 NtGdiCombineRgn(hrgnCopy
, hRgn
, 0, RGN_COPY
);
4310 hrgnCopy
= (HRGN
) 1;
4312 if (Window
->hrgnClip
)
4314 /* Delete no longer needed region handle */
4315 GreDeleteObject(Window
->hrgnClip
);
4317 Window
->hrgnClip
= hrgnCopy
;
4319 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4323 USER_REFERENCE_ENTRY Ref
;
4324 UserRefObjectCo(Window
, &Ref
);
4325 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4326 UserDerefObjectCo(Window
);
4332 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4342 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4346 DECLARE_RETURN(BOOL
);
4347 USER_REFERENCE_ENTRY Ref
;
4349 DPRINT("Enter NtUserShowWindow\n");
4350 UserEnterExclusive();
4352 if (!(Window
= UserGetWindowObject(hWnd
)))
4357 UserRefObjectCo(Window
, &Ref
);
4358 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4359 UserDerefObjectCo(Window
);
4364 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4374 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4380 return NtUserShowWindow(hWnd
, nCmdShow
);
4390 NtUserUpdateLayeredWindow(
4398 BLENDFUNCTION
*pblend
,
4411 NtUserWindowFromPhysicalPoint(POINT Point
)
4422 NtUserWindowFromPoint(LONG X
, LONG Y
)
4426 PWND DesktopWindow
= NULL
, Window
= NULL
;
4427 DECLARE_RETURN(HWND
);
4428 USER_REFERENCE_ENTRY Ref
;
4430 DPRINT("Enter NtUserWindowFromPoint\n");
4431 UserEnterExclusive();
4433 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4440 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4441 //its possible this referencing is useless, thou it shouldnt hurt...
4442 UserRefObjectCo(DesktopWindow
, &Ref
);
4444 pti
= PsGetCurrentThreadWin32Thread();
4445 co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4449 Ret
= Window
->head
.h
;
4458 if (Window
) UserDereferenceObject(Window
);
4459 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4461 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4471 * Undocumented function that is called from DefWindowProc to set
4478 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4481 LARGE_STRING SafeText
;
4482 UNICODE_STRING UnicodeString
;
4485 DPRINT("Enter NtUserDefSetText\n");
4487 if (WindowText
!= NULL
)
4491 SafeText
= ProbeForReadLargeString(WindowText
);
4493 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4496 SetLastNtError(_SEH2_GetExceptionCode());
4506 UserEnterExclusive();
4508 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4514 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4515 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4516 // Now we know what the bAnsi is for.
4517 RtlInitUnicodeString(&UnicodeString
, NULL
);
4518 if (SafeText
.Buffer
)
4523 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4525 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4526 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4528 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4531 SetLastNtError(_SEH2_GetExceptionCode());
4534 if (!Ret
) goto Exit
;
4537 if (UnicodeString
.Length
!= 0)
4539 if (Wnd
->strName
.MaximumLength
> 0 &&
4540 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4542 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4544 Wnd
->strName
.Length
= UnicodeString
.Length
;
4545 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4546 RtlCopyMemory(Wnd
->strName
.Buffer
,
4547 UnicodeString
.Buffer
,
4548 UnicodeString
.Length
);
4553 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4554 buf
= Wnd
->strName
.Buffer
;
4555 Wnd
->strName
.Buffer
= NULL
;
4558 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4561 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4562 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4563 if (Wnd
->strName
.Buffer
!= NULL
)
4565 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4566 RtlCopyMemory(Wnd
->strName
.Buffer
,
4567 UnicodeString
.Buffer
,
4568 UnicodeString
.Length
);
4569 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4570 Wnd
->strName
.Length
= UnicodeString
.Length
;
4574 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4582 Wnd
->strName
.Length
= 0;
4583 if (Wnd
->strName
.Buffer
!= NULL
)
4584 Wnd
->strName
.Buffer
[0] = L
'\0';
4587 // HAX! FIXME! Windows does not do this in here!
4588 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4589 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4590 /* Send shell notifications */
4591 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4593 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4598 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4599 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4605 * NtUserInternalGetWindowText
4612 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4617 DECLARE_RETURN(INT
);
4619 DPRINT("Enter NtUserInternalGetWindowText\n");
4622 if(lpString
&& (nMaxCount
<= 1))
4624 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4628 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4633 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4636 const WCHAR Terminator
= L
'\0';
4638 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4640 Copy
= min(nMaxCount
- 1, Result
);
4643 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4644 if(!NT_SUCCESS(Status
))
4646 SetLastNtError(Status
);
4652 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4653 if(!NT_SUCCESS(Status
))
4655 SetLastNtError(Status
);
4665 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4673 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4679 // ASSERT(OwnerWnd);
4681 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
4686 while (win_array
[count
])
4688 while (--count
>= 0)
4690 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4692 if (pWnd
->spwndOwner
!= OwnerWnd
)
4697 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4699 /* In Windows, ShowOwnedPopups(TRUE) generates
4700 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4701 * regardless of the state of the owner
4703 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4709 if (pWnd
->style
& WS_VISIBLE
)
4711 /* In Windows, ShowOwnedPopups(FALSE) generates
4712 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4713 * regardless of the state of the owner
4715 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4721 ExFreePool( win_array
);
4726 * NtUserValidateHandleSecure
4734 NtUserValidateHandleSecure(
4742 PUSER_HANDLE_ENTRY entry
;
4743 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
4745 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4748 uType
= entry
->type
;
4755 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
4761 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
4766 PACCELERATOR_TABLE Accel
;
4767 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
4772 PCURICON_OBJECT Cursor
;
4773 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
4779 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
4785 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
4791 return UserGetCallProcInfo( handle
, &Proc
);
4794 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4798 { /* Is handle entry restricted? */