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.
37 return STATUS_SUCCESS
;
43 * Cleanup windowing implementation.
47 CleanupWindowImpl(VOID
)
49 return STATUS_SUCCESS
;
52 /* HELPER FUNCTIONS ***********************************************************/
54 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
56 WORD Action
= LOWORD(wParam
);
57 WORD Flags
= HIWORD(wParam
);
59 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
61 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
68 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
72 if (Flags
& UISF_HIDEFOCUS
)
73 Wnd
->HideFocus
= TRUE
;
74 if (Flags
& UISF_HIDEACCEL
)
75 Wnd
->HideAccel
= TRUE
;
79 if (Flags
& UISF_HIDEFOCUS
)
80 Wnd
->HideFocus
= FALSE
;
81 if (Flags
& UISF_HIDEACCEL
)
82 Wnd
->HideAccel
= FALSE
;
89 PWND FASTCALL
IntGetWindowObject(HWND hWnd
)
93 if (!hWnd
) return NULL
;
95 Window
= UserGetWindowObject(hWnd
);
98 ASSERT(Window
->head
.cLockObj
>= 0);
100 Window
->head
.cLockObj
++;
106 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
111 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
113 ti
= GetW32ThreadInfo();
116 SetLastWin32Error(ERROR_ACCESS_DENIED
);
123 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
127 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
128 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
130 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
134 ASSERT(Window
->head
.cLockObj
>= 0);
143 * The function determines whether the specified window handle identifies
144 * an existing window.
148 * Handle to the window to test.
151 * If the window handle identifies an existing window, the return value
152 * is TRUE. If the window handle does not identify an existing window,
153 * the return value is FALSE.
157 IntIsWindow(HWND hWnd
)
161 if (!(Window
= UserGetWindowObject(hWnd
)))
169 IntGetParent(PWND Wnd
)
171 if (Wnd
->style
& WS_POPUP
)
173 return Wnd
->spwndOwner
;
175 else if (Wnd
->style
& WS_CHILD
)
177 return Wnd
->spwndParent
;
186 * Compile a list of all child window handles from given window.
189 * This function is similar to Wine WIN_ListChildren. The caller
190 * must free the returned list with ExFreePool.
194 IntWinListChildren(PWND Window
)
198 UINT Index
, NumChildren
= 0;
200 if (!Window
) return NULL
;
202 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
205 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
208 DPRINT1("Failed to allocate memory for children array\n");
209 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
212 for (Child
= Window
->spwndChild
, Index
= 0;
214 Child
= Child
->spwndNext
, ++Index
)
215 List
[Index
] = Child
->head
.h
;
221 /***********************************************************************
224 static void IntSendDestroyMsg(HWND hWnd
)
232 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
234 if (hWnd
== info
.hwndCaret
)
241 Window
= UserGetWindowObject(hWnd
);
244 // USER_REFERENCE_ENTRY Ref;
245 // UserRefObjectCo(Window, &Ref);
247 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
249 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
252 // UserDerefObjectCo(Window);
255 /* The window could already be destroyed here */
258 * Send the WM_DESTROY to the window.
261 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
264 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
265 * make sure that the window still exists when we come back.
274 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
277 /* start from the end (FIXME: is this needed?) */
278 for (i
= 0; pWndArray
[i
]; i
++)
283 if (IsWindow( pWndArray
[i
] ))
284 WIN_SendDestroyMsg( pWndArray
[i
] );
286 HeapFree(GetProcessHeap(), 0, pWndArray
);
290 DPRINT("destroyed itself while in WM_DESTROY!\n");
296 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
298 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
302 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
304 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
305 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
308 if (Wnd
->strName
.Buffer
!= NULL
)
310 Wnd
->strName
.Length
= 0;
311 Wnd
->strName
.MaximumLength
= 0;
312 DesktopHeapFree(Wnd
->head
.rpdesk
,
313 Wnd
->strName
.Buffer
);
314 Wnd
->strName
.Buffer
= NULL
;
317 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
318 // WindowObject->Wnd = NULL;
321 /***********************************************************************
324 * Destroy storage associated to a window. "Internals" p.358
326 * This is the "functional" DestroyWindows function ei. all stuff
327 * done in CreateWindow is undone here and not in DestroyWindow:-P
330 static LRESULT
co_UserFreeWindow(PWND Window
,
331 PPROCESSINFO ProcessData
,
332 PTHREADINFO ThreadData
,
333 BOOLEAN SendMessages
)
339 BOOLEAN BelongsToThreadData
;
343 if(Window
->state2
& WNDS2_INDESTROY
)
345 DPRINT("Tried to call IntDestroyWindow() twice\n");
348 Window
->state2
|= WNDS2_INDESTROY
;
349 Window
->style
&= ~WS_VISIBLE
;
351 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
353 /* remove the window already at this point from the thread window list so we
354 don't get into trouble when destroying the thread windows while we're still
355 in IntDestroyWindow() */
356 RemoveEntryList(&Window
->ThreadListEntry
);
358 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
360 IntDeRegisterShellHookWindow(Window
->head
.h
);
364 /* Send destroy messages */
365 IntSendDestroyMsg(Window
->head
.h
);
368 /* free child windows */
369 Children
= IntWinListChildren(Window
);
372 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
374 if ((Child
= IntGetWindowObject(*ChildHandle
)))
376 if(!IntWndBelongsToThread(Child
, ThreadData
))
378 /* send WM_DESTROY messages to windows not belonging to the same thread */
379 IntSendDestroyMsg(Child
->head
.h
);
382 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
384 UserDereferenceObject(Child
);
387 ExFreePool(Children
);
393 * Clear the update region to make sure no WM_PAINT messages will be
394 * generated for this window while processing the WM_NCDESTROY.
396 co_UserRedrawWindow(Window
, NULL
, 0,
397 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
398 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
399 if(BelongsToThreadData
)
400 co_IntSendMessage(Window
->head
.h
, WM_NCDESTROY
, 0, 0);
403 DestroyTimersForWindow(ThreadData
, Window
);
405 /* flush the message queue */
406 MsqRemoveWindowMessagesFromQueue(Window
);
408 /* from now on no messages can be sent to this window anymore */
409 Window
->state
|= WNDS_DESTROYED
;
410 Window
->fnid
|= FNID_FREED
;
412 /* don't remove the WINDOWSTATUS_DESTROYING bit */
414 /* reset shell window handles */
415 if(ThreadData
->rpdesk
)
417 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
418 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
420 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
421 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
424 /* Unregister hot keys */
425 UnregisterWindowHotKeys (Window
);
427 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
431 WinPosCheckInternalPos(Window
->head
.h
);
432 if (Window
->head
.h
== GetCapture())
437 /* free resources associated with the window */
438 TIMER_RemoveWindowTimers(Window
->head
.h
);
441 if (!(Window
->style
& WS_CHILD
) && Window
->IDMenu
442 && (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
444 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
448 if(Window
->SystemMenu
449 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
451 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
452 Window
->SystemMenu
= (HMENU
)0;
455 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
458 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
459 CLASS_RemoveWindow(Window
->Class
);
462 IntUnlinkWindow(Window
);
464 UserReferenceObject(Window
);
465 UserDeleteObject(Window
->head
.h
, otWindow
);
467 IntDestroyScrollBars(Window
);
469 /* dereference the class */
470 IntDereferenceClass(Window
->pcls
,
471 Window
->head
.pti
->pDeskInfo
,
472 Window
->head
.pti
->ppi
);
477 GreDeleteObject(Window
->hrgnClip
);
480 // ASSERT(Window != NULL);
481 UserFreeWindowInfo(Window
->head
.pti
, Window
);
483 UserDereferenceObject(Window
);
485 IntClipboardFreeWindow(Window
);
491 IntGetWindowBorderMeasures(PWND Wnd
, UINT
*cx
, UINT
*cy
)
493 if(HAS_DLGFRAME(Wnd
->style
, Wnd
->ExStyle
) && !(Wnd
->style
& WS_MINIMIZE
))
495 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
496 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
500 if(HAS_THICKFRAME(Wnd
->style
, Wnd
->ExStyle
)&& !(Wnd
->style
& WS_MINIMIZE
))
502 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
503 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
505 else if(HAS_THINFRAME(Wnd
->style
, Wnd
->ExStyle
))
507 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
508 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
518 // Same as User32:IntGetWndProc.
521 IntGetWindowProc(PWND pWnd
,
526 WNDPROC gcpd
, Ret
= 0;
528 ASSERT(UserIsEnteredExclusive() == TRUE
);
532 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
534 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
536 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
539 Ret
= GETPFNCLIENTA(i
);
541 Ret
= GETPFNCLIENTW(i
);
547 if (Class
->fnid
== FNID_EDIT
)
548 Ret
= pWnd
->lpfnWndProc
;
551 Ret
= pWnd
->lpfnWndProc
;
553 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
557 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
558 Ret
= GETPFNCLIENTA(Class
->fnid
);
562 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
563 Ret
= GETPFNCLIENTW(Class
->fnid
);
566 if ( Ret
!= pWnd
->lpfnWndProc
)
569 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
572 gcpd
= (WNDPROC
)UserGetCPD(
574 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
577 return (gcpd
? gcpd
: Ret
);
581 IntSetWindowProc(PWND pWnd
,
586 PCALLPROCDATA CallProc
;
588 WNDPROC Ret
, chWndProc
= NULL
;
590 // Retrieve previous window proc.
591 Ret
= IntGetWindowProc(pWnd
, Ansi
);
595 if (IsCallProcHandle(NewWndProc
))
597 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, otCallProc
);
599 { // Reset new WndProc.
600 NewWndProc
= CallProc
->pfnClientPrevious
;
601 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
602 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
605 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
606 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
608 if (GETPFNCLIENTW(i
) == NewWndProc
)
610 chWndProc
= GETPFNSERVER(i
);
613 if (GETPFNCLIENTA(i
) == NewWndProc
)
615 chWndProc
= GETPFNSERVER(i
);
619 // If match, set/reset to Server Side and clear ansi.
622 pWnd
->lpfnWndProc
= chWndProc
;
623 pWnd
->Unicode
= TRUE
;
624 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
625 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
629 pWnd
->Unicode
= !Ansi
;
630 // Handle the state change in here.
632 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
634 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
636 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
637 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
639 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
641 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
645 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
646 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
650 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
651 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
654 // Now set the new window proc.
655 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
660 // Move this to user space!
662 IntGetWindowInfo(PWND Wnd
, PWINDOWINFO pwi
)
664 pwi
->cbSize
= sizeof(WINDOWINFO
);
665 pwi
->rcWindow
= Wnd
->rcWindow
;
666 pwi
->rcClient
= Wnd
->rcClient
;
667 pwi
->dwStyle
= Wnd
->style
;
668 pwi
->dwExStyle
= Wnd
->ExStyle
;
669 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Wnd
->head
.h
); /* WS_ACTIVECAPTION */
670 IntGetWindowBorderMeasures(Wnd
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
671 pwi
->atomWindowType
= (Wnd
->pcls
? Wnd
->pcls
->atomClassName
: 0);
672 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
682 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
684 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
686 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
690 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
698 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
699 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Wnd
->head
.h
);
708 NewMenu
= IntGetMenuObject(Menu
);
713 IntReleaseMenuObject(OldMenu
);
715 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
718 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
720 /* Can't use the same menu for two windows */
723 IntReleaseMenuObject(OldMenu
);
725 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
731 Wnd
->IDMenu
= (UINT
) Menu
;
734 NewMenu
->MenuInfo
.Wnd
= Wnd
->head
.h
;
735 IntReleaseMenuObject(NewMenu
);
739 OldMenu
->MenuInfo
.Wnd
= NULL
;
740 IntReleaseMenuObject(OldMenu
);
747 /* INTERNAL ******************************************************************/
751 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
756 USER_REFERENCE_ENTRY Ref
;
757 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
759 while (!IsListEmpty(&WThread
->WindowListHead
))
761 Current
= WThread
->WindowListHead
.Flink
;
762 Wnd
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
764 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
766 /* window removes itself from the list */
769 fixme: it is critical that the window removes itself! if now, we will loop
773 //ASSERT(co_UserDestroyWindow(Wnd));
775 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
776 if (!co_UserDestroyWindow(Wnd
))
778 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
780 UserDerefObjectCo(Wnd
);//faxme: temp hack??
788 * Returns client window rectangle relative to the upper-left corner of client area.
790 * \note Does not check the validity of the parameters
793 IntGetClientRect(PWND Window
, RECTL
*Rect
)
798 Rect
->left
= Rect
->top
= 0;
799 Rect
->right
= Window
->rcClient
.right
- Window
->rcClient
.left
;
800 Rect
->bottom
= Window
->rcClient
.bottom
- Window
->rcClient
.top
;
806 IntGetFocusWindow(VOID
)
808 PUSER_MESSAGE_QUEUE Queue
;
809 PDESKTOP pdo
= IntGetActiveDesktop();
814 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
819 return(Queue
->FocusWindow
);
823 PMENU_OBJECT FASTCALL
824 IntGetSystemMenu(PWND Window
, BOOL bRevert
, BOOL RetMenu
)
826 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
827 PTHREADINFO W32Thread
;
828 HMENU hNewMenu
, hSysMenu
;
829 ROSMENUITEMINFO ItemInfo
;
833 W32Thread
= PsGetCurrentThreadWin32Thread();
835 if(!W32Thread
->rpdesk
)
838 if(Window
->SystemMenu
)
840 Menu
= UserGetMenuObject(Window
->SystemMenu
);
843 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
844 Window
->SystemMenu
= (HMENU
)0;
848 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
850 /* clone system menu */
851 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
855 NewMenu
= IntCloneMenu(Menu
);
858 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
859 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
860 NewMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
862 //IntReleaseMenuObject(NewMenu);
867 hSysMenu
= UserCreateMenu(FALSE
);
868 if (NULL
== hSysMenu
)
872 SysMenu
= IntGetMenuObject(hSysMenu
);
875 UserDestroyMenu(hSysMenu
);
878 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
879 SysMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
880 hNewMenu
= co_IntLoadSysMenuTemplate();
883 IntReleaseMenuObject(SysMenu
);
884 UserDestroyMenu(hSysMenu
);
887 Menu
= IntGetMenuObject(hNewMenu
);
890 IntReleaseMenuObject(SysMenu
);
891 UserDestroyMenu(hSysMenu
);
895 NewMenu
= IntCloneMenu(Menu
);
898 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
899 IntReleaseMenuObject(NewMenu
);
900 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
902 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
903 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
904 ItemInfo
.fType
= MF_POPUP
;
905 ItemInfo
.fState
= MFS_ENABLED
;
906 ItemInfo
.dwTypeData
= NULL
;
908 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
909 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
911 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
915 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
924 if(Window
->SystemMenu
)
925 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
933 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
940 if (Window
== Parent
)
944 if(!(Window
->style
& WS_CHILD
))
949 Window
= Window
->spwndParent
;
956 IntIsWindowVisible(PWND BaseWindow
)
963 if(!(Window
->style
& WS_CHILD
))
967 if(!(Window
->style
& WS_VISIBLE
))
972 Window
= Window
->spwndParent
;
975 if(Window
&& Window
->style
& WS_VISIBLE
)
985 link the window into siblings list
986 children and parent are kept in place.
991 PWND WndInsertAfter
/* set to NULL if top sibling */
994 if ((Wnd
->spwndPrev
= WndInsertAfter
))
996 /* link after WndInsertAfter */
997 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
998 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1000 Wnd
->spwndPrev
->spwndNext
= Wnd
;
1005 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
1006 Wnd
->spwndNext
->spwndPrev
= Wnd
;
1008 Wnd
->spwndParent
->spwndChild
= Wnd
;
1013 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
1015 if (hWndPrev
== HWND_NOTOPMOST
)
1017 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1018 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
1019 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1020 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
1023 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
1025 if (hWndPrev
== HWND_BOTTOM
)
1027 /* Link in the bottom of the list */
1028 PWND WndInsertAfter
;
1030 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
1031 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
1032 WndInsertAfter
= WndInsertAfter
->spwndNext
;
1034 IntLinkWindow(Wnd
, WndInsertAfter
);
1035 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1037 else if (hWndPrev
== HWND_TOPMOST
)
1039 /* Link in the top of the list */
1040 IntLinkWindow(Wnd
, NULL
);
1042 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1044 else if (hWndPrev
== HWND_TOP
)
1046 /* Link it after the last topmost window */
1047 PWND WndInsertBefore
;
1049 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
1051 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
1053 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
1055 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
1056 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
1058 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1061 WndInsertBefore
= WndInsertBefore
->spwndNext
;
1065 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
1069 /* Link it after hWndPrev */
1070 PWND WndInsertAfter
;
1072 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1073 /* Are we called with an erroneous handle */
1074 if(WndInsertAfter
== NULL
)
1076 /* Link in a default position */
1077 IntLinkHwnd(Wnd
, HWND_TOP
);
1081 IntLinkWindow(Wnd
, WndInsertAfter
);
1083 /* Fix the WS_EX_TOPMOST flag */
1084 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1086 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1090 if(WndInsertAfter
->spwndNext
&&
1091 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1093 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1100 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1102 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1105 Wnd
= IntGetWindowObject(hWnd
);
1109 WndOldOwner
= Wnd
->spwndOwner
;
1111 ret
= WndOldOwner
? WndOldOwner
->head
.h
: 0;
1113 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1115 Wnd
->spwndOwner
= WndNewOwner
;
1119 Wnd
->spwndOwner
= NULL
;
1122 UserDereferenceObject(Wnd
);
1127 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1133 ASSERT(WndNewParent
);
1134 ASSERT_REFS_CO(Wnd
);
1135 ASSERT_REFS_CO(WndNewParent
);
1137 /* Some applications try to set a child as a parent */
1138 if (IntIsChildWindow(Wnd
, WndNewParent
))
1140 SetLastWin32Error( ERROR_INVALID_PARAMETER
);
1145 * Windows hides the window first, then shows it again
1146 * including the WM_SHOWWINDOW messages and all
1148 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1150 /* Window must belong to current process */
1151 if (Wnd
->head
.pti
->pEThread
->ThreadsProcess
!= PsGetCurrentProcess())
1154 WndOldParent
= Wnd
->spwndParent
;
1156 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1158 if (WndNewParent
!= WndOldParent
)
1160 /* Unlink the window from the siblings list */
1161 IntUnlinkWindow(Wnd
);
1163 /* Set the new parent */
1164 Wnd
->spwndParent
= WndNewParent
;
1166 /* Link the window with its new siblings*/
1167 IntLinkHwnd(Wnd
, HWND_TOP
);
1171 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1173 * SetParent additionally needs to make hwnd the top window
1174 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1175 * WM_WINDOWPOSCHANGED notification messages.
1177 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1178 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1179 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1182 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1183 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1186 return WndOldParent
;
1190 IntSetSystemMenu(PWND Window
, PMENU_OBJECT Menu
)
1192 PMENU_OBJECT OldMenu
;
1193 if(Window
->SystemMenu
)
1195 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1198 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1199 IntReleaseMenuObject(OldMenu
);
1205 /* FIXME check window style, propably return FALSE ? */
1206 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1207 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1210 Window
->SystemMenu
= (HMENU
)0;
1215 /* unlink the window from siblings. children and parent are kept in place. */
1217 IntUnlinkWindow(PWND Wnd
)
1220 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1223 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1225 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1226 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1228 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1233 IntGetWindowPlacement(PWND Wnd
, WINDOWPLACEMENT
*lpwndpl
)
1237 if (!Wnd
) return FALSE
;
1239 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1245 if (0 == (Wnd
->style
& WS_VISIBLE
))
1247 lpwndpl
->showCmd
= SW_HIDE
;
1249 else if (0 != (Wnd
->state2
& WNDS2_MAXIMIZEBUTTONDOWN
) ||
1250 0 != (Wnd
->style
& WS_MAXIMIZE
))
1252 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1254 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1256 lpwndpl
->showCmd
= SW_MINIMIZE
;
1258 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1260 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1263 Size
.x
= Wnd
->rcWindow
.left
;
1264 Size
.y
= Wnd
->rcWindow
.top
;
1265 WinPosInitInternalPos(Wnd
, &Size
,
1268 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1269 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1270 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1276 /* FUNCTIONS *****************************************************************/
1282 NtUserAlterWindowStyle(DWORD Unknown0
,
1292 * As best as I can figure, this function is used by EnumWindows,
1293 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1295 * It's supposed to build a list of HWNDs to return to the caller.
1296 * We can figure out what kind of list by what parameters are
1304 NtUserBuildHwndList(
1317 return ERROR_INVALID_PARAMETER
;
1319 if (hwndParent
|| !dwThreadId
)
1322 PWND Parent
, Window
;
1326 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1328 return ERROR_INVALID_HANDLE
;
1333 Status
= IntValidateDesktopHandle(hDesktop
,
1337 if(!NT_SUCCESS(Status
))
1339 return ERROR_INVALID_HANDLE
;
1342 hwndParent
= Desktop
->DesktopWindow
;
1349 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1350 (Window
= Parent
->spwndChild
))
1352 BOOL bGoDown
= TRUE
;
1354 Status
= STATUS_SUCCESS
;
1359 if(dwCount
++ < *pBufSize
&& pWnd
)
1363 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1364 *pWnd
= Window
->head
.h
;
1367 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1369 Status
= _SEH2_GetExceptionCode();
1372 if(!NT_SUCCESS(Status
))
1374 SetLastNtError(Status
);
1378 if (Window
->spwndChild
&& bChildren
)
1380 Window
= Window
->spwndChild
;
1385 if (Window
->spwndNext
)
1387 Window
= Window
->spwndNext
;
1391 Window
= Window
->spwndParent
;
1392 if (Window
== Parent
)
1401 ObDereferenceObject(Desktop
);
1407 PTHREADINFO W32Thread
;
1408 PLIST_ENTRY Current
;
1411 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1412 if(!NT_SUCCESS(Status
))
1414 return ERROR_INVALID_PARAMETER
;
1416 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1418 ObDereferenceObject(Thread
);
1419 DPRINT("Thread is not a GUI Thread!\n");
1420 return ERROR_INVALID_PARAMETER
;
1423 Current
= W32Thread
->WindowListHead
.Flink
;
1424 while(Current
!= &(W32Thread
->WindowListHead
))
1426 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1429 if(bChildren
|| Window
->spwndOwner
!= NULL
)
1431 if(dwCount
< *pBufSize
&& pWnd
)
1433 Status
= MmCopyToCaller(pWnd
++, &Window
->head
.h
, sizeof(HWND
));
1434 if(!NT_SUCCESS(Status
))
1436 SetLastNtError(Status
);
1442 Current
= Current
->Flink
;
1445 ObDereferenceObject(Thread
);
1448 *pBufSize
= dwCount
;
1449 return STATUS_SUCCESS
;
1457 NtUserChildWindowFromPointEx(HWND hwndParent
,
1467 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1475 if(Parent
->head
.h
!= IntGetDesktopWindow())
1477 Pt
.x
+= Parent
->rcClient
.left
;
1478 Pt
.y
+= Parent
->rcClient
.top
;
1481 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1486 Ret
= Parent
->head
.h
;
1487 if((List
= IntWinListChildren(Parent
)))
1489 for(phWnd
= List
; *phWnd
; phWnd
++)
1492 if((Child
= UserGetWindowObject(*phWnd
)))
1494 if(!(Child
->style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1498 if((Child
->style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1502 if((Child
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1506 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1508 Ret
= Child
->head
.h
;
1519 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1521 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1522 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1524 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1526 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1528 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1529 (LPARAM
)pWindow
->head
.h
);
1535 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1537 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1539 /* default positioning for overlapped windows */
1540 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1543 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1545 pMonitor
= IntGetPrimaryMonitor();
1548 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1550 if (IS_DEFAULT(Cs
->x
))
1552 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1554 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1556 Cs
->x
= ProcessParams
->StartingX
;
1557 Cs
->y
= ProcessParams
->StartingY
;
1561 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1562 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1563 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1564 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1566 /* reset counter and position */
1569 pMonitor
->cWndStack
= 0;
1571 pMonitor
->cWndStack
++;
1575 if (IS_DEFAULT(Cs
->cx
))
1577 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1579 Cs
->cx
= ProcessParams
->CountX
;
1580 Cs
->cy
= ProcessParams
->CountY
;
1584 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1585 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1588 /* neither x nor cx are default. Check the y values .
1589 * In the trace we see Outlook and Outlook Express using
1590 * cy set to CW_USEDEFAULT when opening the address book.
1592 else if (IS_DEFAULT(Cs
->cy
))
1594 DPRINT("Strange use of CW_USEDEFAULT in nHeight\n");
1595 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1600 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1601 if(IS_DEFAULT(Cs
->x
))
1606 if(IS_DEFAULT(Cs
->cx
))
1616 /* Allocates and initializes a window*/
1617 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1618 PLARGE_STRING WindowName
,
1625 PTHREADINFO pti
= NULL
;
1626 PMENU_OBJECT SystemMenu
;
1628 BOOL bUnicodeWindow
;
1630 pti
= PsGetCurrentThreadWin32Thread();
1632 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1636 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1637 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1638 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1639 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1643 Note from MSDN http://msdn.microsoft.com/en-us/library/aa913269.aspx :
1645 Dialog boxes and message boxes do not inherit layout, so you must
1646 set the layout explicitly.
1648 if ( Class
&& Class
->fnid
!= FNID_DIALOG
)
1650 PPROCESSINFO ppi
= PsGetCurrentProcessWin32Process();
1651 if (ppi
->dwLayout
& LAYOUT_RTL
)
1653 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1659 /* Automatically add WS_EX_WINDOWEDGE */
1660 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1661 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1662 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1663 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1665 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1667 /* Is it a unicode window? */
1668 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1669 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1671 /* Allocate the new window */
1672 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1676 sizeof(WND
) + Class
->cbwndExtra
);
1683 DPRINT("Created object with handle %X\n", hWnd
);
1685 if (NULL
== pti
->rpdesk
->DesktopWindow
)
1687 /* If there is no desktop window yet, we must be creating it */
1688 pti
->rpdesk
->DesktopWindow
= hWnd
;
1689 pti
->rpdesk
->pDeskInfo
->spwnd
= pWnd
;
1693 * Fill out the structure describing it.
1695 /* Remember, pWnd->head is setup in object.c ...*/
1696 pWnd
->spwndParent
= ParentWindow
;
1697 pWnd
->spwndOwner
= OwnerWindow
;
1699 pWnd
->hWndLastActive
= hWnd
;
1700 pWnd
->state2
|= WNDS2_WIN40COMPAT
;
1702 pWnd
->hModule
= Cs
->hInstance
;
1703 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1704 pWnd
->ExStyle
= Cs
->dwExStyle
;
1705 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1707 IntReferenceMessageQueue(pWnd
->head
.pti
->MessageQueue
);
1708 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1710 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1711 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1714 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1715 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1717 /* BugBoy Comments: Comment below say that System classes are always created
1718 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1719 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1721 No where can I see in code or through testing does the window change back
1722 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1723 see what problems this would cause.*/
1725 // Set WndProc from Class.
1726 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1728 // GetWindowProc, test for non server side default classes and set WndProc.
1729 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1733 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1734 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1738 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1739 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1743 // If not an Unicode caller, set Ansi creator bit.
1744 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1746 // Clone Class Ansi/Unicode proc type.
1747 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1749 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1750 pWnd
->Unicode
= FALSE
;
1754 It seems there can be both an Ansi creator and Unicode Class Window
1755 WndProc, unless the following overriding conditions occur:
1757 if ( !bUnicodeWindow
&&
1758 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1759 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1760 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1761 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1762 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1763 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1764 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1765 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1766 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1767 { // Override Class and set the window Ansi WndProc.
1768 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1769 pWnd
->Unicode
= FALSE
;
1772 { // Set the window Unicode WndProc.
1773 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1774 pWnd
->Unicode
= TRUE
;
1778 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1779 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1780 Dont understand why it does this. */
1781 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1783 PCALLPROCDATA CallProc
;
1784 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1788 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1789 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
1793 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1797 InitializeListHead(&pWnd
->PropListHead
);
1799 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1801 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1802 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1803 if (pWnd
->strName
.Buffer
== NULL
)
1808 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1809 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1810 pWnd
->strName
.Length
= WindowName
->Length
;
1813 /* Correct the window style. */
1814 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1816 pWnd
->style
|= WS_CLIPSIBLINGS
;
1817 if (!(pWnd
->style
& WS_POPUP
))
1819 pWnd
->style
|= WS_CAPTION
;
1820 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1824 if ((pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
) ||
1825 (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
1826 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1828 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1830 /* create system menu */
1831 if((Cs
->style
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1833 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1836 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1837 IntReleaseMenuObject(SystemMenu
);
1841 /* Set the window menu */
1842 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1845 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1846 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1848 UNICODE_STRING MenuName
;
1851 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1853 MenuName
.Length
= 0;
1854 MenuName
.MaximumLength
= 0;
1855 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1859 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1861 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1862 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1866 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1868 /* Insert the window into the thread's window list. */
1869 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1871 /* Handle "CS_CLASSDC", it is tested first. */
1872 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1873 { /* One DCE per class to have CLASS. */
1874 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1876 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1877 { /* Allocate a DCE for this window. */
1878 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1886 UserDereferenceObject(pWnd
);
1888 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1896 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1897 PUNICODE_STRING ClassName
,
1898 PLARGE_STRING WindowName
)
1900 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1901 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1903 PWINSTATION_OBJECT WinSta
;
1907 CBT_CREATEWNDW
* pCbtCreate
;
1909 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1911 DWORD dwShowMode
= SW_SHOW
;
1912 CREATESTRUCTW
*pCsw
;
1913 PVOID pszClass
= NULL
, pszName
= NULL
;
1914 DECLARE_RETURN(PWND
);
1916 /* Get the current window station and reference it */
1917 pti
= GetW32ThreadInfo();
1918 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1920 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1921 return NULL
; //There is nothing to cleanup
1923 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1924 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1929 /* Get the class and reference it*/
1930 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
);
1933 DPRINT1("Failed to find class %wZ\n", ClassName
);
1937 /* Now find the parent and the owner window */
1938 hWndParent
= IntGetDesktopWindow();
1941 if (Cs
->hwndParent
== HWND_MESSAGE
)
1943 Cs
->hwndParent
= hWndParent
= IntGetMessageWindow();
1945 else if (Cs
->hwndParent
)
1947 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1948 hWndOwner
= Cs
->hwndParent
;
1950 hWndParent
= Cs
->hwndParent
;
1952 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1954 DPRINT1("Cannot create a child window without a parrent!\n");
1955 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1956 RETURN(NULL
); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1959 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1960 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1962 /* FIXME: is this correct?*/
1964 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
1966 /* Fix the position and the size of the window */
1969 UserRefObjectCo(ParentWindow
, &ParentRef
);
1970 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
1973 /* Allocate and initialize the new window */
1974 Window
= IntCreateWindow(Cs
,
1981 DPRINT1("IntCreateWindow failed!\n");
1985 hWnd
= UserHMGetHandle(Window
);
1987 UserRefObjectCo(Window
, &Ref
);
1988 ObDereferenceObject(WinSta
);
1990 //// Call the WH_CBT hook ////
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 pCsw
->lpCreateParams
= Cs
->lpCreateParams
;
1998 pCsw
->hInstance
= Cs
->hInstance
;
1999 pCsw
->hMenu
= Cs
->hMenu
;
2000 pCsw
->hwndParent
= Cs
->hwndParent
;
2005 pCsw
->dwExStyle
= Cs
->dwExStyle
;
2006 dwStyle
= Cs
->style
; // Save it anyway.
2007 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2008 pCsw
->lpszName
= Cs
->lpszName
;
2009 pCsw
->lpszClass
= Cs
->lpszClass
;
2011 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2012 if (!IS_ATOM(ClassName
->Buffer
))
2014 if (Window
->state
& WNDS_ANSICREATOR
)
2016 ANSI_STRING AnsiString
;
2017 AnsiString
.MaximumLength
= RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2018 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2019 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2020 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2021 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2025 UNICODE_STRING UnicodeString
;
2026 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2027 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2028 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2029 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2030 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2032 if (pszClass
) pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2034 if (WindowName
->Length
)
2036 UNICODE_STRING Name
;
2037 Name
.Buffer
= WindowName
->Buffer
;
2038 Name
.Length
= WindowName
->Length
;
2039 Name
.MaximumLength
= WindowName
->MaximumLength
;
2041 if (Window
->state
& WNDS_ANSICREATOR
)
2043 ANSI_STRING AnsiString
;
2044 AnsiString
.MaximumLength
= RtlUnicodeStringToAnsiSize(&Name
)+sizeof(CHAR
);
2045 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2046 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2047 AnsiString
.Buffer
= (PCHAR
)pszName
;
2048 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2052 UNICODE_STRING UnicodeString
;
2053 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2054 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2055 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2056 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2057 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2059 if (pszName
) pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2062 pCbtCreate
->lpcs
= pCsw
;
2063 pCbtCreate
->hwndInsertAfter
= HWND_TOP
;
2065 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2068 DPRINT1("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2069 RETURN( (PWND
) NULL
);
2071 // Write back changes.
2076 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2078 /* NCCREATE and WM_NCCALCSIZE need the original values */
2079 Cs
->style
= dwStyle
;
2080 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2081 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2083 /* Send the WM_GETMINMAXINFO message*/
2087 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
2089 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2091 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2092 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2093 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2094 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2095 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2098 Window
->rcWindow
.left
= Cs
->x
;
2099 Window
->rcWindow
.top
= Cs
->y
;
2100 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2101 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2102 if (0 != (Window
->style
& WS_CHILD
) && ParentWindow
)
2104 RECTL_vOffsetRect(&Window
->rcWindow
,
2105 ParentWindow
->rcClient
.left
,
2106 ParentWindow
->rcClient
.top
);
2108 Window
->rcClient
= Window
->rcWindow
;
2111 /* Link the window*/
2112 if (NULL
!= ParentWindow
)
2114 /* link the window into the siblings list */
2115 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2116 IntLinkHwnd(Window
, HWND_BOTTOM
);
2118 IntLinkHwnd(Window
, HWND_TOP
);
2121 /* Send the NCCREATE message */
2122 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2125 DPRINT1("co_UserCreateWindowEx(): NCCREATE message failed\n");
2129 /* Send the WM_NCCALCSIZE message */
2130 MaxPos
.x
= Window
->rcWindow
.left
;
2131 MaxPos
.y
= Window
->rcWindow
.top
;
2133 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2135 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2136 MaxPos
.y
- Window
->rcWindow
.top
);
2139 /* Send the WM_CREATE message. */
2140 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2141 if (Result
== (LRESULT
)-1)
2143 DPRINT1("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2147 /* Send the EVENT_OBJECT_CREATE event*/
2148 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2150 /* By setting the flag below it can be examined to determine if the window
2151 was created successfully and a valid pwnd was passed back to caller since
2152 from here the function has to succeed. */
2153 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2155 /* Send the WM_SIZE and WM_MOVE messages. */
2156 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2158 co_WinPosSendSizeMove(Window
);
2161 /* Show or maybe minimize or maximize the window. */
2162 if (Window
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2167 SwFlag
= (Window
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2169 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2171 SwFlag
= ((Window
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2172 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2173 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2175 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2176 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2179 /* Send the WM_PARENTNOTIFY message */
2180 IntSendParentNotify(Window
, WM_CREATE
);
2182 /* Notify the shell that a new window was created */
2183 if ((!hWndParent
) && (!hWndOwner
))
2185 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2188 /* Initialize and show the window's scrollbars */
2189 if (Window
->style
& WS_VSCROLL
)
2191 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2193 if (Window
->style
& WS_HSCROLL
)
2195 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2198 /* Show the new window */
2199 if (Cs
->style
& WS_VISIBLE
)
2201 if (Window
->style
& WS_MAXIMIZE
)
2202 dwShowMode
= SW_SHOW
;
2203 else if (Window
->style
& WS_MINIMIZE
)
2204 dwShowMode
= SW_SHOWMINIMIZED
;
2206 co_WinPosShowWindow(Window
, dwShowMode
);
2208 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2210 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2211 /* ShowWindow won't activate child windows */
2212 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2216 DPRINT("co_UserCreateWindowEx(): Created window %X\n", hWnd
);
2222 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2224 co_UserDestroyWindow(Window
);
2226 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2229 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2230 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2231 if (pszName
) UserHeapFree(pszName
);
2232 if (pszClass
) UserHeapFree(pszClass
);
2236 UserDerefObjectCo(Window
);
2237 UserDereferenceObject(Window
);
2239 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2246 ProbeAndCaptureLargeString(
2247 OUT PLARGE_STRING plstrSafe
,
2248 IN PLARGE_STRING plstrUnsafe
)
2250 LARGE_STRING lstrTemp
;
2251 PVOID pvBuffer
= NULL
;
2255 /* Probe and copy the string */
2256 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2257 lstrTemp
= *plstrUnsafe
;
2259 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2262 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2266 if (lstrTemp
.Length
!= 0)
2268 /* Allocate a buffer from paged pool */
2269 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2272 return STATUS_NO_MEMORY
;
2277 /* Probe and copy the buffer */
2278 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2279 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2281 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2283 /* Cleanup and fail */
2284 ExFreePool(pvBuffer
);
2285 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2290 /* Set the output string */
2291 plstrSafe
->Buffer
= pvBuffer
;
2292 plstrSafe
->Length
= lstrTemp
.Length
;
2293 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2295 return STATUS_SUCCESS
;
2299 * \todo Allow passing plstrClassName as ANSI.
2303 NtUserCreateWindowEx(
2305 PLARGE_STRING plstrClassName
,
2306 PLARGE_STRING plstrClsVersion
,
2307 PLARGE_STRING plstrWindowName
,
2315 HINSTANCE hInstance
,
2321 LARGE_STRING lstrWindowName
;
2322 LARGE_STRING lstrClassName
;
2323 UNICODE_STRING ustrClassName
;
2328 lstrWindowName
.Buffer
= NULL
;
2329 lstrClassName
.Buffer
= NULL
;
2331 /* Check if we got a Window name */
2332 if (plstrWindowName
)
2334 /* Copy the string to kernel mode */
2335 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2336 if (!NT_SUCCESS(Status
))
2338 DPRINT1("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2339 SetLastNtError(Status
);
2342 plstrWindowName
= &lstrWindowName
;
2345 /* Check if the class is an atom */
2346 if (IS_ATOM(plstrClassName
))
2348 /* It is, pass the atom in the UNICODE_STRING */
2349 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2350 ustrClassName
.Length
= 0;
2351 ustrClassName
.MaximumLength
= 0;
2355 /* It's not, capture the class name */
2356 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2357 if (!NT_SUCCESS(Status
))
2359 DPRINT1("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2360 /* Set last error, cleanup and return */
2361 SetLastNtError(Status
);
2365 /* We pass it on as a UNICODE_STRING */
2366 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2367 ustrClassName
.Length
= lstrClassName
.Length
;
2368 ustrClassName
.MaximumLength
= lstrClassName
.MaximumLength
;
2371 /* Fill the CREATESTRUCTW */
2372 /* we will keep here the original parameters */
2374 Cs
.lpCreateParams
= lpParam
;
2375 Cs
.hInstance
= hInstance
;
2377 Cs
.hwndParent
= hWndParent
;
2382 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2383 if (IS_ATOM(plstrClassName
))
2384 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2386 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2387 Cs
.dwExStyle
= dwExStyle
;
2389 UserEnterExclusive();
2391 /* Call the internal function */
2392 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
);
2396 DPRINT1("co_UserCreateWindowEx failed!\n");
2398 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2403 if (lstrWindowName
.Buffer
)
2405 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2407 if (lstrClassName
.Buffer
)
2409 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2419 NtUserDeferWindowPos(HDWP WinPosInfo
,
2421 HWND WndInsertAfter
,
2434 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2440 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2442 hWnd
= Window
->head
.h
;
2444 DPRINT("co_UserDestroyWindow \n");
2446 /* Check for owner thread */
2447 if ( (Window
->head
.pti
->pEThread
!= PsGetCurrentThread()) ||
2448 Window
->head
.pti
!= PsGetCurrentThreadWin32Thread() )
2450 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2454 /* If window was created successfully and it is hooked */
2455 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2457 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2459 DPRINT1("Destroy Window WH_CBT Call Hook return!\n");
2464 /* Inform the parent */
2465 if (Window
->style
& WS_CHILD
)
2467 IntSendParentNotify(Window
, WM_DESTROY
);
2470 /* Look whether the focus is within the tree of windows we will
2473 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2475 if (UserGetActiveWindow() == Window
->head
.h
)
2477 co_WinPosActivateOtherWindow(Window
);
2481 if (Window
->head
.pti
->MessageQueue
->ActiveWindow
== Window
->head
.h
)
2482 Window
->head
.pti
->MessageQueue
->ActiveWindow
= NULL
;
2483 if (Window
->head
.pti
->MessageQueue
->FocusWindow
== Window
->head
.h
)
2484 Window
->head
.pti
->MessageQueue
->FocusWindow
= NULL
;
2485 if (Window
->head
.pti
->MessageQueue
->CaptureWindow
== Window
->head
.h
)
2486 Window
->head
.pti
->MessageQueue
->CaptureWindow
= NULL
;
2489 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2492 ti
= PsGetCurrentThreadWin32Thread();
2494 if ((ti
!= NULL
) & (ti
->pDeskInfo
!= NULL
))
2496 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2498 DPRINT1("Destroying the ShellWindow!\n");
2499 ti
->pDeskInfo
->hShellWindow
= NULL
;
2503 IntDereferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
2505 IntEngWindowChanged(Window
, WOC_DELETE
);
2507 if (!IntIsWindow(Window
->head
.h
))
2512 /* Recursively destroy owned windows */
2514 if (! (Window
->style
& WS_CHILD
))
2518 BOOL GotOne
= FALSE
;
2521 PWND Child
, Desktop
;
2523 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2524 UserGetWindowObject(IntGetDesktopWindow());
2525 Children
= IntWinListChildren(Desktop
);
2529 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2531 Child
= UserGetWindowObject(*ChildHandle
);
2534 if (Child
->spwndOwner
!= Window
)
2539 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2541 USER_REFERENCE_ENTRY ChildRef
;
2542 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2543 co_UserDestroyWindow(Child
);
2544 UserDerefObjectCo(Child
);//temp hack?
2550 if (Child
->spwndOwner
!= NULL
)
2552 Child
->spwndOwner
= NULL
;
2556 ExFreePool(Children
);
2565 /* Generate mouse move message for the next window */
2566 msg
.message
= WM_MOUSEMOVE
;
2567 msg
.wParam
= IntGetSysCursorInfo()->ButtonsDown
;
2568 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2569 msg
.pt
= gpsi
->ptCursor
;
2570 MsqInsertMouseMessage(&msg
);
2572 if (!IntIsWindow(Window
->head
.h
))
2577 /* Destroy the window storage */
2578 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2588 NtUserDestroyWindow(HWND Wnd
)
2591 DECLARE_RETURN(BOOLEAN
);
2593 USER_REFERENCE_ENTRY Ref
;
2595 DPRINT("Enter NtUserDestroyWindow\n");
2596 UserEnterExclusive();
2598 if (!(Window
= UserGetWindowObject(Wnd
)))
2603 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2604 ret
= co_UserDestroyWindow(Window
);
2605 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2610 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2622 NtUserDrawMenuBarTemp(
2629 /* we'll use this function just for caching the menu bar */
2639 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2649 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2655 NtUserFillWindow(HWND hWndPaint
,
2666 static HWND FASTCALL
2667 IntFindWindow(PWND Parent
,
2670 PUNICODE_STRING WindowName
)
2672 BOOL CheckWindowName
;
2675 UNICODE_STRING CurrentWindowName
;
2679 CheckWindowName
= WindowName
->Length
!= 0;
2681 if((List
= IntWinListChildren(Parent
)))
2686 /* skip handles before and including ChildAfter */
2687 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2691 /* search children */
2695 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2700 /* Do not send WM_GETTEXT messages in the kernel mode version!
2701 The user mode version however calls GetWindowText() which will
2702 send WM_GETTEXT messages to windows belonging to its processes */
2703 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2705 // HACK: use UNICODE_STRING instead of LARGE_STRING
2706 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2707 CurrentWindowName
.Length
= Child
->strName
.Length
;
2708 CurrentWindowName
.MaximumLength
= Child
->strName
.MaximumLength
;
2709 if(!CheckWindowName
||
2710 (Child
->strName
.Length
< 0xFFFF &&
2711 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2713 Ret
= Child
->head
.h
;
2726 * Searches a window's children for a window with the specified
2729 * hwndParent = The window whose childs are to be searched.
2731 * HWND_MESSAGE = message-only windows
2733 * hwndChildAfter = Search starts after this child window.
2734 * NULL = start from beginning
2736 * ucClassName = Class name to search for
2737 * Reguired parameter.
2739 * ucWindowName = Window name
2740 * ->Buffer == NULL = don't care
2743 * The HWND of the window if it was found, otherwise NULL
2749 NtUserFindWindowEx(HWND hwndParent
,
2750 HWND hwndChildAfter
,
2751 PUNICODE_STRING ucClassName
,
2752 PUNICODE_STRING ucWindowName
,
2755 PWND Parent
, ChildAfter
;
2756 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2757 HWND Desktop
, Ret
= NULL
;
2758 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2759 DECLARE_RETURN(HWND
);
2761 DPRINT("Enter NtUserFindWindowEx\n");
2764 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2768 if (ucClassName
!= NULL
)
2770 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2771 if (ClassName
.Length
!= 0)
2773 ProbeForRead(ClassName
.Buffer
,
2777 else if (!IS_ATOM(ClassName
.Buffer
))
2779 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2783 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2790 if (ucWindowName
!= NULL
)
2792 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2793 if (WindowName
.Length
!= 0)
2795 ProbeForRead(WindowName
.Buffer
,
2801 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2803 SetLastNtError(_SEH2_GetExceptionCode());
2804 _SEH2_YIELD(RETURN(NULL
));
2808 if (ucClassName
!= NULL
)
2810 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2811 !IS_ATOM(ClassName
.Buffer
))
2813 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2816 else if (ClassAtom
== (RTL_ATOM
)0)
2818 /* LastError code was set by IntGetAtomFromStringOrAtom */
2824 Desktop
= IntGetCurrentThreadDesktopWindow();
2826 if(hwndParent
== NULL
)
2827 hwndParent
= Desktop
;
2828 else if(hwndParent
== HWND_MESSAGE
)
2830 hwndParent
= IntGetMessageWindow();
2833 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2839 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2846 if(Parent
->head
.h
== Desktop
)
2849 PWND TopLevelWindow
;
2850 BOOLEAN CheckWindowName
;
2851 BOOLEAN WindowMatches
;
2852 BOOLEAN ClassMatches
;
2854 /* windows searches through all top-level windows if the parent is the desktop
2857 if((List
= IntWinListChildren(Parent
)))
2863 /* skip handles before and including ChildAfter */
2864 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2868 CheckWindowName
= WindowName
.Length
!= 0;
2870 /* search children */
2873 UNICODE_STRING ustr
;
2875 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2880 /* Do not send WM_GETTEXT messages in the kernel mode version!
2881 The user mode version however calls GetWindowText() which will
2882 send WM_GETTEXT messages to windows belonging to its processes */
2883 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2884 ustr
.Length
= TopLevelWindow
->strName
.Length
;
2885 ustr
.MaximumLength
= TopLevelWindow
->strName
.MaximumLength
;
2886 WindowMatches
= !CheckWindowName
||
2887 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2888 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2889 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2890 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2892 if (WindowMatches
&& ClassMatches
)
2894 Ret
= TopLevelWindow
->head
.h
;
2898 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2900 /* window returns the handle of the top-level window, in case it found
2902 Ret
= TopLevelWindow
->head
.h
;
2911 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2915 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2917 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2918 search the message-only windows. Should this also be done if
2919 Parent is the desktop window??? */
2922 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2924 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2929 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2931 SetLastNtError(_SEH2_GetExceptionCode());
2939 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2949 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
2960 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
2962 PWND WndAncestor
, Parent
;
2964 if (Wnd
->head
.h
== IntGetDesktopWindow())
2973 WndAncestor
= Wnd
->spwndParent
;
2984 if(!(Parent
= WndAncestor
->spwndParent
))
2988 if(IntIsDesktopWindow(Parent
))
2993 WndAncestor
= Parent
;
3006 Parent
= IntGetParent(WndAncestor
);
3013 WndAncestor
= Parent
;
3031 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3033 PWND Window
, Ancestor
;
3034 DECLARE_RETURN(HWND
);
3036 DPRINT("Enter NtUserGetAncestor\n");
3037 UserEnterExclusive();
3039 if (!(Window
= UserGetWindowObject(hWnd
)))
3044 Ancestor
= UserGetAncestor(Window
, Type
);
3045 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3047 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3050 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3058 NtUserGetComboBoxInfo(
3063 DECLARE_RETURN(BOOL
);
3065 DPRINT("Enter NtUserGetComboBoxInfo\n");
3068 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3077 sizeof(COMBOBOXINFO
),
3081 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3083 SetLastNtError(_SEH2_GetExceptionCode());
3084 _SEH2_YIELD(RETURN(FALSE
));
3088 // Pass the user pointer, it was already probed.
3089 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3092 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3102 NtUserGetInternalWindowPos( HWND hWnd
,
3109 WINDOWPLACEMENT wndpl
;
3113 if (!(Window
= UserGetWindowObject(hWnd
)))
3123 ProbeForWrite(rectWnd
,
3129 ProbeForWrite(ptIcon
,
3135 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3137 SetLastNtError(_SEH2_GetExceptionCode());
3142 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3144 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3150 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3154 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3158 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3160 SetLastNtError(_SEH2_GetExceptionCode());
3165 if (!Hit
) Ret
= wndpl
.showCmd
;
3174 NtUserGetListBoxInfo(
3178 DECLARE_RETURN(DWORD
);
3180 DPRINT("Enter NtUserGetListBoxInfo\n");
3183 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3188 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3191 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3198 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3200 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3201 HWND hWndOldParent
= NULL
;
3202 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3204 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3206 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3210 if (hWndChild
== IntGetDesktopWindow())
3212 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3218 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3225 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3231 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3236 UserRefObjectCo(Wnd
, &Ref
);
3237 UserRefObjectCo(WndParent
, &ParentRef
);
3239 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3241 UserDerefObjectCo(WndParent
);
3242 UserDerefObjectCo(Wnd
);
3246 hWndOldParent
= WndOldParent
->head
.h
;
3247 UserDereferenceObject(WndOldParent
);
3250 return( hWndOldParent
);
3256 * The NtUserSetParent function changes the parent window of the specified
3260 * The new parent window and the child window must belong to the same
3261 * application. If the window identified by the hWndChild parameter is
3262 * visible, the system performs the appropriate redrawing and repainting.
3263 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3264 * or WS_POPUP window styles of the window whose parent is being changed.
3271 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3273 DECLARE_RETURN(HWND
);
3275 DPRINT("Enter NtUserSetParent\n");
3276 UserEnterExclusive();
3279 Check Parent first from user space, set it here.
3283 hWndNewParent
= IntGetDesktopWindow();
3285 else if (hWndNewParent
== HWND_MESSAGE
)
3287 hWndNewParent
= IntGetMessageWindow();
3290 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3293 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3299 * UserGetShellWindow
3301 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3306 HWND FASTCALL
UserGetShellWindow(VOID
)
3308 PWINSTATION_OBJECT WinStaObject
;
3311 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3316 if (!NT_SUCCESS(Status
))
3318 SetLastNtError(Status
);
3322 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3324 ObDereferenceObject(WinStaObject
);
3329 * NtUserSetShellWindowEx
3331 * This is undocumented function to set global shell window. The global
3332 * shell window has special handling of window position.
3338 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3340 PWINSTATION_OBJECT WinStaObject
;
3341 PWND WndShell
, WndListView
;
3342 DECLARE_RETURN(BOOL
);
3343 USER_REFERENCE_ENTRY Ref
;
3347 DPRINT("Enter NtUserSetShellWindowEx\n");
3348 UserEnterExclusive();
3350 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3355 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3360 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3365 if (!NT_SUCCESS(Status
))
3367 SetLastNtError(Status
);
3372 * Test if we are permitted to change the shell window.
3374 if (WinStaObject
->ShellWindow
)
3376 ObDereferenceObject(WinStaObject
);
3381 * Move shell window into background.
3383 if (hwndListView
&& hwndListView
!= hwndShell
)
3386 * Disabled for now to get Explorer working.
3387 * -- Filip, 01/nov/2003
3390 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3393 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3395 ObDereferenceObject(WinStaObject
);
3400 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3402 ObDereferenceObject(WinStaObject
);
3406 UserRefObjectCo(WndShell
, &Ref
);
3407 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3409 WinStaObject
->ShellWindow
= hwndShell
;
3410 WinStaObject
->ShellListView
= hwndListView
;
3412 ti
= GetW32ThreadInfo();
3413 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3415 UserDerefObjectCo(WndShell
);
3417 ObDereferenceObject(WinStaObject
);
3421 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3427 * NtUserGetSystemMenu
3429 * The NtUserGetSystemMenu function allows the application to access the
3430 * window menu (also known as the system menu or the control menu) for
3431 * copying and modifying.
3435 * Handle to the window that will own a copy of the window menu.
3437 * Specifies the action to be taken. If this parameter is FALSE,
3438 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3439 * currently in use. The copy is initially identical to the window menu
3440 * but it can be modified.
3441 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3442 * to the default state. The previous window menu, if any, is destroyed.
3445 * If the bRevert parameter is FALSE, the return value is a handle to a
3446 * copy of the window menu. If the bRevert parameter is TRUE, the return
3454 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3458 DECLARE_RETURN(HMENU
);
3460 DPRINT("Enter NtUserGetSystemMenu\n");
3463 if (!(Window
= UserGetWindowObject(hWnd
)))
3468 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3473 RETURN(Menu
->MenuInfo
.Self
);
3476 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3482 * NtUserSetSystemMenu
3489 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3491 BOOL Result
= FALSE
;
3494 DECLARE_RETURN(BOOL
);
3496 DPRINT("Enter NtUserSetSystemMenu\n");
3497 UserEnterExclusive();
3499 if (!(Window
= UserGetWindowObject(hWnd
)))
3507 * Assign new menu handle.
3509 if (!(Menu
= UserGetMenuObject(hMenu
)))
3514 Result
= IntSetSystemMenu(Window
, Menu
);
3520 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3526 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3528 PWND Window
, Parent
;
3529 PWINSTATION_OBJECT WindowStation
;
3533 if (hWnd
== IntGetDesktopWindow())
3535 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3539 if (!(Window
= UserGetWindowObject(hWnd
)))
3544 if ((INT
)Index
>= 0)
3546 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3548 SetLastWin32Error(ERROR_INVALID_INDEX
);
3552 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3554 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3556 OldValue = (LONG)IntSetWindowProc( Wnd,
3559 if (!OldValue) return 0;
3562 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3569 OldValue
= (LONG
) Window
->ExStyle
;
3570 Style
.styleOld
= OldValue
;
3571 Style
.styleNew
= NewValue
;
3574 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3576 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3579 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3580 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3583 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3584 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3585 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3589 OldValue
= (LONG
) Window
->style
;
3590 Style
.styleOld
= OldValue
;
3591 Style
.styleNew
= NewValue
;
3592 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3593 Window
->style
= (DWORD
)Style
.styleNew
;
3594 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3599 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3600 Window
->fnid
& FNID_FREED
)
3602 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3605 OldValue
= (LONG
)IntSetWindowProc(Window
,
3612 OldValue
= (LONG
) Window
->hModule
;
3613 Window
->hModule
= (HINSTANCE
) NewValue
;
3616 case GWL_HWNDPARENT
:
3617 Parent
= Window
->spwndParent
;
3618 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3619 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3621 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3625 OldValue
= (LONG
) Window
->IDMenu
;
3626 Window
->IDMenu
= (UINT
) NewValue
;
3630 OldValue
= Window
->dwUserData
;
3631 Window
->dwUserData
= NewValue
;
3635 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3636 SetLastWin32Error(ERROR_INVALID_INDEX
);
3646 * NtUserSetWindowLong
3648 * The NtUserSetWindowLong function changes an attribute of the specified
3649 * window. The function also sets the 32-bit (long) value at the specified
3650 * offset into the extra window memory.
3657 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3659 DECLARE_RETURN(LONG
);
3661 DPRINT("Enter NtUserSetWindowLong\n");
3662 UserEnterExclusive();
3664 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3667 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3673 * NtUserSetWindowWord
3675 * Legacy function similar to NtUserSetWindowLong.
3682 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3686 DECLARE_RETURN(WORD
);
3688 DPRINT("Enter NtUserSetWindowWord\n");
3689 UserEnterExclusive();
3691 if (!(Window
= UserGetWindowObject(hWnd
)))
3700 case GWL_HWNDPARENT
:
3701 RETURN( co_UserSetWindowLong(Window
->head
.h
, Index
, (UINT
)NewValue
, TRUE
));
3705 SetLastWin32Error(ERROR_INVALID_INDEX
);
3710 if (Index
> Window
->cbwndExtra
- sizeof(WORD
))
3712 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3716 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3717 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3722 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3731 NtUserGetWindowPlacement(HWND hWnd
,
3732 WINDOWPLACEMENT
*lpwndpl
)
3736 WINDOWPLACEMENT Safepl
;
3738 DECLARE_RETURN(BOOL
);
3740 DPRINT("Enter NtUserGetWindowPlacement\n");
3743 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3748 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3749 if(!NT_SUCCESS(Status
))
3751 SetLastNtError(Status
);
3754 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3760 if (0 == (Wnd
->style
& WS_VISIBLE
))
3762 Safepl
.showCmd
= SW_HIDE
;
3764 else if ((0 != (Wnd
->state2
& WNDS2_MAXIMIZEBUTTONDOWN
) ||
3765 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
3766 0 == (Wnd
->style
& WS_MINIMIZE
))
3768 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
3770 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
3772 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
3774 else if (0 != (Wnd
->style
& WS_VISIBLE
))
3776 Safepl
.showCmd
= SW_SHOWNORMAL
;
3779 Size
.x
= Wnd
->rcWindow
.left
;
3780 Size
.y
= Wnd
->rcWindow
.top
;
3781 WinPosInitInternalPos(Wnd
, &Size
,
3784 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
3785 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
3786 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
3788 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3789 if(!NT_SUCCESS(Status
))
3791 SetLastNtError(Status
);
3798 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
3808 NtUserLockWindowUpdate(HWND hWnd
)
3828 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3829 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3830 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3834 QueryWindow based on KJK::Hyperion and James Tabor.
3836 0 = QWUniqueProcessId
3837 1 = QWUniqueThreadId
3840 4 = QWIsHung Implements IsHungAppWindow found
3843 9 = QWKillWindow When I called this with hWnd ==
3844 DesktopWindow, it shutdown the system
3851 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3855 DECLARE_RETURN(UINT
);
3857 DPRINT("Enter NtUserQueryWindow\n");
3860 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3867 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3868 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3871 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3872 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3875 case QUERY_WINDOW_ACTIVE
:
3876 Result
= (DWORD
)UserGetActiveWindow();
3879 case QUERY_WINDOW_FOCUS
:
3880 Result
= (DWORD
)IntGetFocusWindow();
3883 case QUERY_WINDOW_ISHUNG
:
3884 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
->MessageQueue
);
3887 case QUERY_WINDOW_REAL_ID
:
3888 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3891 Result
= (DWORD
)NULL
;
3898 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3908 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3922 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3924 UNICODE_STRING SafeMessageName
;
3927 DECLARE_RETURN(UINT
);
3929 DPRINT("Enter NtUserRegisterWindowMessage\n");
3930 UserEnterExclusive();
3932 if(MessageNameUnsafe
== NULL
)
3934 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3938 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3939 if(!NT_SUCCESS(Status
))
3941 SetLastNtError(Status
);
3945 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3946 if (SafeMessageName
.Buffer
)
3947 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3951 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3961 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3974 NtUserSetInternalWindowPos(
3991 NtUserSetLayeredWindowAttributes(HWND hwnd
,
4005 NtUserSetLogonNotifyWindow(HWND hWnd
)
4024 DECLARE_RETURN(BOOL
);
4026 DPRINT("Enter NtUserSetMenu\n");
4027 UserEnterExclusive();
4029 if (!(Window
= UserGetWindowObject(hWnd
)))
4034 if (! IntSetMenu(Window
, Menu
, &Changed
))
4039 if (Changed
&& Repaint
)
4041 USER_REFERENCE_ENTRY Ref
;
4043 UserRefObjectCo(Window
, &Ref
);
4044 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4045 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4047 UserDerefObjectCo(Window
);
4053 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4063 NtUserSetWindowFNID(HWND hWnd
,
4067 DECLARE_RETURN(BOOL
);
4069 DPRINT("Enter NtUserSetWindowFNID\n");
4070 UserEnterExclusive();
4072 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4078 { // From user land we only set these.
4079 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
4084 Wnd
->pcls
->fnid
|= fnID
;
4089 DPRINT("Leave NtUserSetWindowFNID\n");
4099 NtUserSetWindowPlacement(HWND hWnd
,
4100 WINDOWPLACEMENT
*lpwndpl
)
4103 WINDOWPLACEMENT Safepl
;
4105 DECLARE_RETURN(BOOL
);
4106 USER_REFERENCE_ENTRY Ref
;
4108 DPRINT("Enter NtUserSetWindowPlacement\n");
4109 UserEnterExclusive();
4111 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4116 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4117 if(!NT_SUCCESS(Status
))
4119 SetLastNtError(Status
);
4122 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4127 UserRefObjectCo(Wnd
, &Ref
);
4129 if ((Wnd
->style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4131 co_WinPosSetWindowPos(Wnd
, NULL
,
4132 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4133 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4134 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4135 SWP_NOZORDER
| SWP_NOACTIVATE
);
4138 /* FIXME - change window status */
4139 co_WinPosShowWindow(Wnd
, Safepl
.showCmd
);
4141 Wnd
->InternalPosInitialized
= TRUE
;
4142 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4143 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4144 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4146 UserDerefObjectCo(Wnd
);
4150 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4162 HWND hWndInsertAfter
,
4169 DECLARE_RETURN(BOOL
);
4172 USER_REFERENCE_ENTRY Ref
;
4174 DPRINT("Enter NtUserSetWindowPos\n");
4175 UserEnterExclusive();
4177 if (!(Window
= UserGetWindowObject(hWnd
)))
4182 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
4183 if (!(uFlags
& SWP_NOMOVE
))
4185 if (X
< -32768) X
= -32768;
4186 else if (X
> 32767) X
= 32767;
4187 if (Y
< -32768) Y
= -32768;
4188 else if (Y
> 32767) Y
= 32767;
4190 if (!(uFlags
& SWP_NOSIZE
))
4193 else if (cx
> 32767) cx
= 32767;
4195 else if (cy
> 32767) cy
= 32767;
4198 UserRefObjectCo(Window
, &Ref
);
4199 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4200 UserDerefObjectCo(Window
);
4205 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4212 IntGetWindowRgn(PWND Window
, HRGN hRgn
)
4227 /* Create a new window region using the window rectangle */
4228 VisRgn
= IntSysCreateRectRgnIndirect(&Window
->rcWindow
);
4229 NtGdiOffsetRgn(VisRgn
, -Window
->rcWindow
.left
, -Window
->rcWindow
.top
);
4230 /* if there's a region assigned to the window, combine them both */
4231 if(Window
->hrgnClip
&& !(Window
->style
& WS_MINIMIZE
))
4232 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->hrgnClip
, RGN_AND
);
4233 /* Copy the region into hRgn */
4234 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4236 if((pRgn
= RGNOBJAPI_Lock(hRgn
, NULL
)))
4238 Ret
= REGION_Complexity(pRgn
);
4239 RGNOBJAPI_Unlock(pRgn
);
4244 REGION_FreeRgnByHandle(VisRgn
);
4250 IntGetWindowRgnBox(PWND Window
, RECTL
*Rect
)
4265 /* Create a new window region using the window rectangle */
4266 VisRgn
= IntSysCreateRectRgnIndirect(&Window
->rcWindow
);
4267 NtGdiOffsetRgn(VisRgn
, -Window
->rcWindow
.left
, -Window
->rcWindow
.top
);
4268 /* if there's a region assigned to the window, combine them both */
4269 if(Window
->hrgnClip
&& !(Window
->style
& WS_MINIMIZE
))
4270 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->hrgnClip
, RGN_AND
);
4272 if((pRgn
= RGNOBJAPI_Lock(VisRgn
, NULL
)))
4274 Ret
= REGION_Complexity(pRgn
);
4275 *Rect
= pRgn
->rdh
.rcBound
;
4276 RGNOBJAPI_Unlock(pRgn
);
4281 REGION_FreeRgnByHandle(VisRgn
);
4298 DECLARE_RETURN(INT
);
4300 DPRINT("Enter NtUserSetWindowRgn\n");
4301 UserEnterExclusive();
4303 if (!(Window
= UserGetWindowObject(hWnd
)))
4308 if (hRgn
) // The region will be deleted in user32.
4310 if (GDIOBJ_ValidateHandle(hRgn
, GDI_OBJECT_TYPE_REGION
))
4312 hrgnCopy
= IntSysCreateRectRgn(0, 0, 0, 0);
4313 NtGdiCombineRgn(hrgnCopy
, hRgn
, 0, RGN_COPY
);
4319 hrgnCopy
= (HRGN
) 1;
4321 if (Window
->hrgnClip
)
4323 /* Delete no longer needed region handle */
4324 GreDeleteObject(Window
->hrgnClip
);
4326 Window
->hrgnClip
= hrgnCopy
;
4328 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4332 USER_REFERENCE_ENTRY Ref
;
4333 UserRefObjectCo(Window
, &Ref
);
4334 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4335 UserDerefObjectCo(Window
);
4341 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4351 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4355 DECLARE_RETURN(BOOL
);
4356 USER_REFERENCE_ENTRY Ref
;
4358 DPRINT("Enter NtUserShowWindow\n");
4359 UserEnterExclusive();
4361 if (!(Window
= UserGetWindowObject(hWnd
)))
4366 UserRefObjectCo(Window
, &Ref
);
4367 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4368 UserDerefObjectCo(Window
);
4373 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4383 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4389 return NtUserShowWindow(hWnd
, nCmdShow
);
4399 NtUserUpdateLayeredWindow(
4407 BLENDFUNCTION
*pblend
,
4420 NtUserWindowFromPhysicalPoint(POINT Point
)
4431 NtUserWindowFromPoint(LONG X
, LONG Y
)
4435 PWND DesktopWindow
= NULL
, Window
= NULL
;
4436 DECLARE_RETURN(HWND
);
4437 USER_REFERENCE_ENTRY Ref
;
4439 DPRINT("Enter NtUserWindowFromPoint\n");
4440 UserEnterExclusive();
4442 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4449 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4450 //its possible this referencing is useless, thou it shouldnt hurt...
4451 UserRefObjectCo(DesktopWindow
, &Ref
);
4453 pti
= PsGetCurrentThreadWin32Thread();
4454 co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4458 Ret
= Window
->head
.h
;
4467 if (Window
) UserDereferenceObject(Window
);
4468 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4470 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4480 * Undocumented function that is called from DefWindowProc to set
4487 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4490 LARGE_STRING SafeText
;
4491 UNICODE_STRING UnicodeString
;
4494 DPRINT("Enter NtUserDefSetText\n");
4496 if (WindowText
!= NULL
)
4500 SafeText
= ProbeForReadLargeString(WindowText
);
4502 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4505 SetLastNtError(_SEH2_GetExceptionCode());
4515 UserEnterExclusive();
4517 if(!(Wnd
= UserGetWindowObject(hWnd
)))
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 (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
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
)
4626 DECLARE_RETURN(INT
);
4628 DPRINT("Enter NtUserInternalGetWindowText\n");
4631 if(lpString
&& (nMaxCount
<= 1))
4633 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4637 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4642 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4645 const WCHAR Terminator
= L
'\0';
4647 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4649 Copy
= min(nMaxCount
- 1, Result
);
4652 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4653 if(!NT_SUCCESS(Status
))
4655 SetLastNtError(Status
);
4661 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4662 if(!NT_SUCCESS(Status
))
4664 SetLastNtError(Status
);
4674 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4682 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4688 // ASSERT(OwnerWnd);
4690 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
4695 while (win_array
[count
])
4697 while (--count
>= 0)
4699 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4701 if (pWnd
->spwndOwner
!= OwnerWnd
)
4706 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4708 /* In Windows, ShowOwnedPopups(TRUE) generates
4709 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4710 * regardless of the state of the owner
4712 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4718 if (pWnd
->style
& WS_VISIBLE
)
4720 /* In Windows, ShowOwnedPopups(FALSE) generates
4721 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4722 * regardless of the state of the owner
4724 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4730 ExFreePool( win_array
);
4735 * NtUserValidateHandleSecure
4743 NtUserValidateHandleSecure(
4751 PUSER_HANDLE_ENTRY entry
;
4752 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
4754 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4757 uType
= entry
->type
;
4764 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
4770 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
4775 PACCELERATOR_TABLE Accel
;
4776 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
4781 PCURICON_OBJECT Cursor
;
4782 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
4788 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
4794 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
4800 return UserGetCallProcInfo( handle
, &Proc
);
4803 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4807 { /* Is handle entry restricted? */