2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
5 * FILE: subsystems/win32/win32k/ntuser/window.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
11 /* INCLUDES ******************************************************************/
19 /* dialog resources appear to pass this in 16 bits, handle them properly */
20 #define CW_USEDEFAULT16 (0x8000)
22 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
24 /* PRIVATE FUNCTIONS **********************************************************/
29 * Initialize windowing implementation.
35 return STATUS_SUCCESS
;
41 * Cleanup windowing implementation.
45 CleanupWindowImpl(VOID
)
47 return STATUS_SUCCESS
;
50 /* HELPER FUNCTIONS ***********************************************************/
52 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
54 WORD Action
= LOWORD(wParam
);
55 WORD Flags
= HIWORD(wParam
);
57 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
59 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
66 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
70 if (Flags
& UISF_HIDEFOCUS
)
71 Wnd
->HideFocus
= TRUE
;
72 if (Flags
& UISF_HIDEACCEL
)
73 Wnd
->HideAccel
= TRUE
;
77 if (Flags
& UISF_HIDEFOCUS
)
78 Wnd
->HideFocus
= FALSE
;
79 if (Flags
& UISF_HIDEACCEL
)
80 Wnd
->HideAccel
= FALSE
;
87 PWND FASTCALL
IntGetWindowObject(HWND hWnd
)
91 if (!hWnd
) return NULL
;
93 Window
= UserGetWindowObject(hWnd
);
96 ASSERT(Window
->head
.cLockObj
>= 0);
98 Window
->head
.cLockObj
++;
104 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
109 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
111 ti
= GetW32ThreadInfo();
114 SetLastWin32Error(ERROR_ACCESS_DENIED
);
121 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
125 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
126 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
128 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
132 ASSERT(Window
->head
.cLockObj
>= 0);
141 * The function determines whether the specified window handle identifies
142 * an existing window.
146 * Handle to the window to test.
149 * If the window handle identifies an existing window, the return value
150 * is TRUE. If the window handle does not identify an existing window,
151 * the return value is FALSE.
155 IntIsWindow(HWND hWnd
)
159 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
;
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
, 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);
402 DestroyTimersForWindow(ThreadData
, Window
);
403 HOOK_DestroyThreadHooks(ThreadData
->pEThread
); // This is needed here too!
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
);
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
;
1231 IntIsWindowInDestroy(PWND Window
)
1233 return ((Window
->state2
& WNDS2_INDESTROY
) == WNDS2_INDESTROY
);
1239 IntGetWindowPlacement(PWND Wnd
, WINDOWPLACEMENT
*lpwndpl
)
1243 if (!Wnd
) return FALSE
;
1245 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1251 if (0 == (Wnd
->style
& WS_VISIBLE
))
1253 lpwndpl
->showCmd
= SW_HIDE
;
1255 else if (0 != (Wnd
->state2
& WNDS2_MAXIMIZEBUTTONDOWN
) ||
1256 0 != (Wnd
->style
& WS_MAXIMIZE
))
1258 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1260 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1262 lpwndpl
->showCmd
= SW_MINIMIZE
;
1264 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1266 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1269 Size
.x
= Wnd
->rcWindow
.left
;
1270 Size
.y
= Wnd
->rcWindow
.top
;
1271 WinPosInitInternalPos(Wnd
, &Size
,
1274 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1275 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1276 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1282 /* FUNCTIONS *****************************************************************/
1288 NtUserAlterWindowStyle(DWORD Unknown0
,
1298 * As best as I can figure, this function is used by EnumWindows,
1299 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1301 * It's supposed to build a list of HWNDs to return to the caller.
1302 * We can figure out what kind of list by what parameters are
1310 NtUserBuildHwndList(
1323 return ERROR_INVALID_PARAMETER
;
1325 if (hwndParent
|| !dwThreadId
)
1328 PWND Parent
, Window
;
1332 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1334 return ERROR_INVALID_HANDLE
;
1339 Status
= IntValidateDesktopHandle(hDesktop
,
1343 if(!NT_SUCCESS(Status
))
1345 return ERROR_INVALID_HANDLE
;
1348 hwndParent
= Desktop
->DesktopWindow
;
1355 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1356 (Window
= Parent
->spwndChild
))
1358 BOOL bGoDown
= TRUE
;
1360 Status
= STATUS_SUCCESS
;
1365 if(dwCount
++ < *pBufSize
&& pWnd
)
1369 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1370 *pWnd
= Window
->head
.h
;
1373 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1375 Status
= _SEH2_GetExceptionCode();
1378 if(!NT_SUCCESS(Status
))
1380 SetLastNtError(Status
);
1384 if (Window
->spwndChild
&& bChildren
)
1386 Window
= Window
->spwndChild
;
1391 if (Window
->spwndNext
)
1393 Window
= Window
->spwndNext
;
1397 Window
= Window
->spwndParent
;
1398 if (Window
== Parent
)
1407 ObDereferenceObject(Desktop
);
1413 PTHREADINFO W32Thread
;
1414 PLIST_ENTRY Current
;
1417 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1418 if(!NT_SUCCESS(Status
))
1420 return ERROR_INVALID_PARAMETER
;
1422 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1424 ObDereferenceObject(Thread
);
1425 DPRINT("Thread is not a GUI Thread!\n");
1426 return ERROR_INVALID_PARAMETER
;
1429 Current
= W32Thread
->WindowListHead
.Flink
;
1430 while(Current
!= &(W32Thread
->WindowListHead
))
1432 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1435 if(bChildren
|| Window
->spwndOwner
!= NULL
)
1437 if(dwCount
< *pBufSize
&& pWnd
)
1439 Status
= MmCopyToCaller(pWnd
++, &Window
->head
.h
, sizeof(HWND
));
1440 if(!NT_SUCCESS(Status
))
1442 SetLastNtError(Status
);
1448 Current
= Current
->Flink
;
1451 ObDereferenceObject(Thread
);
1454 *pBufSize
= dwCount
;
1455 return STATUS_SUCCESS
;
1463 NtUserChildWindowFromPointEx(HWND hwndParent
,
1473 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1481 if(Parent
->head
.h
!= IntGetDesktopWindow())
1483 Pt
.x
+= Parent
->rcClient
.left
;
1484 Pt
.y
+= Parent
->rcClient
.top
;
1487 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1492 Ret
= Parent
->head
.h
;
1493 if((List
= IntWinListChildren(Parent
)))
1495 for(phWnd
= List
; *phWnd
; phWnd
++)
1498 if((Child
= UserGetWindowObject(*phWnd
)))
1500 if(!(Child
->style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1504 if((Child
->style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1508 if((Child
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1512 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1514 Ret
= Child
->head
.h
;
1525 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1527 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1528 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1530 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1532 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1534 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1535 (LPARAM
)pWindow
->head
.h
);
1541 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1543 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1545 /* default positioning for overlapped windows */
1546 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1549 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1551 pMonitor
= IntGetPrimaryMonitor();
1554 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1556 if (IS_DEFAULT(Cs
->x
))
1558 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1560 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1562 Cs
->x
= ProcessParams
->StartingX
;
1563 Cs
->y
= ProcessParams
->StartingY
;
1567 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1568 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1569 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1570 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1572 /* reset counter and position */
1575 pMonitor
->cWndStack
= 0;
1577 pMonitor
->cWndStack
++;
1581 if (IS_DEFAULT(Cs
->cx
))
1583 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1585 Cs
->cx
= ProcessParams
->CountX
;
1586 Cs
->cy
= ProcessParams
->CountY
;
1590 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1591 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1594 /* neither x nor cx are default. Check the y values .
1595 * In the trace we see Outlook and Outlook Express using
1596 * cy set to CW_USEDEFAULT when opening the address book.
1598 else if (IS_DEFAULT(Cs
->cy
))
1600 DPRINT("Strange use of CW_USEDEFAULT in nHeight\n");
1601 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1606 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1607 if(IS_DEFAULT(Cs
->x
))
1612 if(IS_DEFAULT(Cs
->cx
))
1622 /* Allocates and initializes a window*/
1623 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1624 PLARGE_STRING WindowName
,
1631 PTHREADINFO pti
= NULL
;
1632 PMENU_OBJECT SystemMenu
;
1634 BOOL bUnicodeWindow
;
1636 pti
= PsGetCurrentThreadWin32Thread();
1638 /* Automatically add WS_EX_WINDOWEDGE */
1639 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1640 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1641 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1642 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1644 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1646 /* Is it a unicode window? */
1647 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1648 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1650 /* Allocate the new window */
1651 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1655 sizeof(WND
) + Class
->cbwndExtra
);
1662 DPRINT("Created object with handle %X\n", hWnd
);
1664 if (NULL
== pti
->rpdesk
->DesktopWindow
)
1666 /* If there is no desktop window yet, we must be creating it */
1667 pti
->rpdesk
->DesktopWindow
= hWnd
;
1668 pti
->rpdesk
->pDeskInfo
->spwnd
= pWnd
;
1672 * Fill out the structure describing it.
1674 /* Remember, pWnd->head is setup in object.c ...*/
1675 pWnd
->spwndParent
= ParentWindow
;
1676 pWnd
->spwndOwner
= OwnerWindow
;
1678 pWnd
->hWndLastActive
= hWnd
;
1679 pWnd
->state2
|= WNDS2_WIN40COMPAT
;
1681 pWnd
->hModule
= Cs
->hInstance
;
1682 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1683 pWnd
->ExStyle
= Cs
->dwExStyle
;
1684 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1686 IntReferenceMessageQueue(pWnd
->head
.pti
->MessageQueue
);
1687 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1689 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1690 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1693 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1694 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1696 /* BugBoy Comments: Comment below say that System classes are always created
1697 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1698 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1700 No where can I see in code or through testing does the window change back
1701 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1702 see what problems this would cause.*/
1704 // Set WndProc from Class.
1705 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1707 // GetWindowProc, test for non server side default classes and set WndProc.
1708 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1712 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1713 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1717 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1718 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1722 // If not an Unicode caller, set Ansi creator bit.
1723 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1725 // Clone Class Ansi/Unicode proc type.
1726 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1728 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1729 pWnd
->Unicode
= FALSE
;
1733 It seems there can be both an Ansi creator and Unicode Class Window
1734 WndProc, unless the following overriding conditions occur:
1736 if ( !bUnicodeWindow
&&
1737 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1738 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1739 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1740 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1741 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1742 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1743 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1744 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1745 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1746 { // Override Class and set the window Ansi WndProc.
1747 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1748 pWnd
->Unicode
= FALSE
;
1751 { // Set the window Unicode WndProc.
1752 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1753 pWnd
->Unicode
= TRUE
;
1757 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1758 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1759 Dont understand why it does this. */
1760 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1762 PCALLPROCDATA CallProc
;
1763 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1767 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
1768 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
1772 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1776 InitializeListHead(&pWnd
->PropListHead
);
1778 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1780 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1781 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1782 if (pWnd
->strName
.Buffer
== NULL
)
1787 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1788 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1789 pWnd
->strName
.Length
= WindowName
->Length
;
1792 /* Correct the window style. */
1793 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1795 pWnd
->style
|= WS_CLIPSIBLINGS
;
1796 if (!(pWnd
->style
& WS_POPUP
))
1798 pWnd
->style
|= WS_CAPTION
;
1799 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1803 if ((pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
) ||
1804 (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
1805 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1807 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1809 /* create system menu */
1810 if((Cs
->style
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1812 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1815 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1816 IntReleaseMenuObject(SystemMenu
);
1820 /* Set the window menu */
1821 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1824 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1825 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1827 UNICODE_STRING MenuName
;
1830 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1832 MenuName
.Length
= 0;
1833 MenuName
.MaximumLength
= 0;
1834 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1838 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1840 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1841 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1845 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1847 /* Insert the window into the thread's window list. */
1848 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1850 /* Handle "CS_CLASSDC", it is tested first. */
1851 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1852 { /* One DCE per class to have CLASS. */
1853 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1855 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1856 { /* Allocate a DCE for this window. */
1857 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1865 UserDereferenceObject(pWnd
);
1867 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1875 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1876 PUNICODE_STRING ClassName
,
1877 PLARGE_STRING WindowName
)
1879 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1880 HWND hWnd
, hWndParent
, hWndOwner
;
1882 PWINSTATION_OBJECT WinSta
;
1886 CBT_CREATEWNDW CbtCreate
;
1888 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1890 DWORD dwShowMode
= SW_SHOW
;
1891 DECLARE_RETURN(PWND
);
1893 /* Get the current window station and reference it */
1894 pti
= GetW32ThreadInfo();
1895 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1897 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1898 return NULL
; //There is nothing to cleanup
1900 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1901 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1903 /* Get the class and reference it*/
1904 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
);
1907 DPRINT1("Failed to find class %wZ\n", ClassName
);
1911 /* Now find the parent and the owner window */
1912 hWndParent
= IntGetDesktopWindow();
1915 if (Cs
->hwndParent
== HWND_MESSAGE
)
1917 Cs
->hwndParent
= hWndParent
= IntGetMessageWindow();
1919 else if (Cs
->hwndParent
)
1921 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1922 hWndOwner
= Cs
->hwndParent
;
1924 hWndParent
= Cs
->hwndParent
;
1926 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1928 DPRINT1("Cannot create a child window without a parrent!\n");
1929 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1930 RETURN(NULL
); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1933 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1934 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1936 /* FIXME: is this correct?*/
1938 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
1940 /* Fix the position and the size of the window */
1943 UserRefObjectCo(ParentWindow
, &ParentRef
);
1944 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
1947 /* Allocate and initialize the new window */
1948 Window
= IntCreateWindow(Cs
,
1955 DPRINT1("IntCreateWindow failed!\n");
1959 hWnd
= Window
->head
.h
;
1961 UserRefObjectCo(Window
, &Ref
);
1962 ObDereferenceObject(WinSta
);
1964 /* Call the WH_CBT hook */
1965 dwStyle
= Cs
->style
;
1966 Cs
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
1967 CbtCreate
.lpcs
= Cs
;
1968 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1970 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) &CbtCreate
))
1972 DPRINT1("HCBT_CREATEWND hook failed!\n");
1973 RETURN( (PWND
) NULL
);
1976 Cs
->style
= dwStyle
; /* NCCREATE and WM_NCCALCSIZE need the original values*/
1978 /* Send the WM_GETMINMAXINFO message*/
1982 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
1984 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1986 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
1987 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
1988 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
1989 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
1990 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
1993 Window
->rcWindow
.left
= Cs
->x
;
1994 Window
->rcWindow
.top
= Cs
->y
;
1995 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
1996 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
1997 if (0 != (Window
->style
& WS_CHILD
) && ParentWindow
)
1999 RECTL_vOffsetRect(&Window
->rcWindow
,
2000 ParentWindow
->rcClient
.left
,
2001 ParentWindow
->rcClient
.top
);
2003 Window
->rcClient
= Window
->rcWindow
;
2006 /* Link the window*/
2007 if (NULL
!= ParentWindow
)
2009 /* link the window into the siblings list */
2010 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2011 IntLinkHwnd(Window
, HWND_BOTTOM
);
2013 IntLinkHwnd(Window
, HWND_TOP
);
2016 /* Send the NCCREATE message */
2017 Result
= co_IntSendMessage(Window
->head
.h
, WM_NCCREATE
, 0, (LPARAM
) Cs
);
2020 DPRINT1("co_UserCreateWindowEx(): NCCREATE message failed\n");
2024 /* Send the WM_NCCALCSIZE message */
2025 MaxPos
.x
= Window
->rcWindow
.left
;
2026 MaxPos
.y
= Window
->rcWindow
.top
;
2028 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2030 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2031 MaxPos
.y
- Window
->rcWindow
.top
);
2034 /* Send the WM_CREATE message. */
2035 Result
= co_IntSendMessage(Window
->head
.h
, WM_CREATE
, 0, (LPARAM
) Cs
);
2036 if (Result
== (LRESULT
)-1)
2038 DPRINT1("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2042 /* Send the EVENT_OBJECT_CREATE event*/
2043 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, 0);
2045 /* By setting the flag below it can be examined to determine if the window
2046 was created successfully and a valid pwnd was passed back to caller since
2047 from here the function has to succeed. */
2048 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2050 /* Send the WM_SIZE and WM_MOVE messages. */
2051 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2053 co_WinPosSendSizeMove(Window
);
2056 /* Show or maybe minimize or maximize the window. */
2057 if (Window
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2062 SwFlag
= (Window
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2064 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2066 SwFlag
= ((Window
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2067 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2068 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2070 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2071 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2074 /* Send the WM_PARENTNOTIFY message */
2075 IntSendParentNotify(Window
, WM_CREATE
);
2077 /* Notify the shell that a new window was created */
2078 if ((!hWndParent
) && (!hWndOwner
))
2080 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2083 /* Initialize and show the window's scrollbars */
2084 if (Window
->style
& WS_VSCROLL
)
2086 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2088 if (Window
->style
& WS_HSCROLL
)
2090 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2093 /* Show the new window */
2094 if (Cs
->style
& WS_VISIBLE
)
2096 if (Window
->style
& WS_MAXIMIZE
)
2097 dwShowMode
= SW_SHOW
;
2098 else if (Window
->style
& WS_MINIMIZE
)
2099 dwShowMode
= SW_SHOWMINIMIZED
;
2101 co_WinPosShowWindow(Window
, dwShowMode
);
2103 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2105 co_IntSendMessage(ParentWindow
->head
.h
, WM_MDIREFRESHMENU
, 0, 0);
2106 /* ShowWindow won't activate child windows */
2107 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2111 DPRINT("co_UserCreateWindowEx(): Created window %X\n", hWnd
);
2117 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2119 co_UserDestroyWindow(Window
);
2121 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2126 UserDerefObjectCo(Window
);
2127 UserDereferenceObject(Window
);
2129 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2136 ProbeAndCaptureLargeString(
2137 OUT PLARGE_STRING plstrSafe
,
2138 IN PLARGE_STRING plstrUnsafe
)
2140 LARGE_STRING lstrTemp
;
2141 PVOID pvBuffer
= NULL
;
2145 /* Probe and copy the string */
2146 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2147 lstrTemp
= *plstrUnsafe
;
2149 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2152 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2156 if (lstrTemp
.Length
!= 0)
2158 /* Allocate a buffer from paged pool */
2159 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2162 return STATUS_NO_MEMORY
;
2167 /* Probe and copy the buffer */
2168 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2169 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2171 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2173 /* Cleanup and fail */
2174 ExFreePool(pvBuffer
);
2175 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2180 /* Set the output string */
2181 plstrSafe
->Buffer
= pvBuffer
;
2182 plstrSafe
->Length
= lstrTemp
.Length
;
2183 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2185 return STATUS_SUCCESS
;
2189 * \todo Allow passing plstrClassName as ANSI.
2193 NtUserCreateWindowEx(
2195 PLARGE_STRING plstrClassName
,
2196 PLARGE_STRING plstrClsVersion
,
2197 PLARGE_STRING plstrWindowName
,
2205 HINSTANCE hInstance
,
2211 LARGE_STRING lstrWindowName
;
2212 LARGE_STRING lstrClassName
;
2213 UNICODE_STRING ustrClassName
;
2218 lstrWindowName
.Buffer
= NULL
;
2219 lstrClassName
.Buffer
= NULL
;
2221 /* Check if we got a Window name */
2222 if (plstrWindowName
)
2224 /* Copy the string to kernel mode */
2225 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2226 if (!NT_SUCCESS(Status
))
2228 DPRINT1("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2229 SetLastNtError(Status
);
2232 plstrWindowName
= &lstrWindowName
;
2235 /* Check if the class is an atom */
2236 if (IS_ATOM(plstrClassName
))
2238 /* It is, pass the atom in the UNICODE_STRING */
2239 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2240 ustrClassName
.Length
= 0;
2241 ustrClassName
.MaximumLength
= 0;
2245 /* It's not, capture the class name */
2246 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2247 if (!NT_SUCCESS(Status
))
2249 DPRINT1("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2250 /* Set last error, cleanup and return */
2251 SetLastNtError(Status
);
2255 /* We pass it on as a UNICODE_STRING */
2256 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2257 ustrClassName
.Length
= lstrClassName
.Length
;
2258 ustrClassName
.MaximumLength
= lstrClassName
.MaximumLength
;
2261 /* Fill the CREATESTRUCTW */
2262 /* we will keep here the original parameters */
2264 Cs
.lpCreateParams
= lpParam
;
2265 Cs
.hInstance
= hInstance
;
2267 Cs
.hwndParent
= hWndParent
;
2272 // Cs.lpszName = (LPCWSTR) WindowName->Buffer;
2273 // Cs.lpszClass = (LPCWSTR) ClassName->Buffer;
2274 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
;
2275 Cs
.lpszClass
= (LPCWSTR
) &ustrClassName
;
2276 Cs
.dwExStyle
= dwExStyle
;
2278 UserEnterExclusive();
2280 /* Call the internal function */
2281 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
);
2285 DPRINT1("co_UserCreateWindowEx failed!\n");
2287 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2292 if (lstrWindowName
.Buffer
)
2294 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2296 if (lstrClassName
.Buffer
)
2298 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2308 NtUserDeferWindowPos(HDWP WinPosInfo
,
2310 HWND WndInsertAfter
,
2323 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2329 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2331 hWnd
= Window
->head
.h
;
2333 DPRINT("co_UserDestroyWindow \n");
2335 /* Check for owner thread */
2336 if ( (Window
->head
.pti
->pEThread
!= PsGetCurrentThread()) ||
2337 Window
->head
.pti
!= PsGetCurrentThreadWin32Thread() )
2339 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2343 /* If window was created successfully and it is hooked */
2344 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2346 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0)) return FALSE
;
2349 /* Inform the parent */
2350 if (Window
->style
& WS_CHILD
)
2352 IntSendParentNotify(Window
, WM_DESTROY
);
2355 /* Look whether the focus is within the tree of windows we will
2358 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2360 if (UserGetActiveWindow() == Window
->head
.h
)
2362 co_WinPosActivateOtherWindow(Window
);
2366 if (Window
->head
.pti
->MessageQueue
->ActiveWindow
== Window
->head
.h
)
2367 Window
->head
.pti
->MessageQueue
->ActiveWindow
= NULL
;
2368 if (Window
->head
.pti
->MessageQueue
->FocusWindow
== Window
->head
.h
)
2369 Window
->head
.pti
->MessageQueue
->FocusWindow
= NULL
;
2370 if (Window
->head
.pti
->MessageQueue
->CaptureWindow
== Window
->head
.h
)
2371 Window
->head
.pti
->MessageQueue
->CaptureWindow
= NULL
;
2374 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2377 ti
= PsGetCurrentThreadWin32Thread();
2379 if ((ti
!= NULL
) & (ti
->pDeskInfo
!= NULL
))
2381 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2383 DPRINT1("Destroying the ShellWindow!\n");
2384 ti
->pDeskInfo
->hShellWindow
= NULL
;
2388 IntDereferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
2390 IntEngWindowChanged(Window
, WOC_DELETE
);
2392 if (!IntIsWindow(Window
->head
.h
))
2397 /* Recursively destroy owned windows */
2399 if (! (Window
->style
& WS_CHILD
))
2403 BOOL GotOne
= FALSE
;
2406 PWND Child
, Desktop
;
2408 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2409 UserGetWindowObject(IntGetDesktopWindow());
2410 Children
= IntWinListChildren(Desktop
);
2414 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2416 Child
= UserGetWindowObject(*ChildHandle
);
2419 if (Child
->spwndOwner
!= Window
)
2424 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2426 USER_REFERENCE_ENTRY ChildRef
;
2427 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2428 co_UserDestroyWindow(Child
);
2429 UserDerefObjectCo(Child
);//temp hack?
2435 if (Child
->spwndOwner
!= NULL
)
2437 Child
->spwndOwner
= NULL
;
2441 ExFreePool(Children
);
2450 /* Generate mouse move message for the next window */
2451 msg
.message
= WM_MOUSEMOVE
;
2452 msg
.wParam
= IntGetSysCursorInfo()->ButtonsDown
;
2453 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2454 msg
.pt
= gpsi
->ptCursor
;
2455 MsqInsertSystemMessage(&msg
);
2457 if (!IntIsWindow(Window
->head
.h
))
2462 /* Destroy the window storage */
2463 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2473 NtUserDestroyWindow(HWND Wnd
)
2476 DECLARE_RETURN(BOOLEAN
);
2478 USER_REFERENCE_ENTRY Ref
;
2480 DPRINT("Enter NtUserDestroyWindow\n");
2481 UserEnterExclusive();
2483 if (!(Window
= UserGetWindowObject(Wnd
)))
2488 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2489 ret
= co_UserDestroyWindow(Window
);
2490 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2495 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2507 NtUserDrawMenuBarTemp(
2514 /* we'll use this function just for caching the menu bar */
2524 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2534 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2540 NtUserFillWindow(HWND hWndPaint
,
2551 static HWND FASTCALL
2552 IntFindWindow(PWND Parent
,
2555 PUNICODE_STRING WindowName
)
2557 BOOL CheckWindowName
;
2560 UNICODE_STRING CurrentWindowName
;
2564 CheckWindowName
= WindowName
->Length
!= 0;
2566 if((List
= IntWinListChildren(Parent
)))
2571 /* skip handles before and including ChildAfter */
2572 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2576 /* search children */
2580 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2585 /* Do not send WM_GETTEXT messages in the kernel mode version!
2586 The user mode version however calls GetWindowText() which will
2587 send WM_GETTEXT messages to windows belonging to its processes */
2588 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2590 // HACK: use UNICODE_STRING instead of LARGE_STRING
2591 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2592 CurrentWindowName
.Length
= Child
->strName
.Length
;
2593 CurrentWindowName
.MaximumLength
= Child
->strName
.MaximumLength
;
2594 if(!CheckWindowName
||
2595 (Child
->strName
.Length
< 0xFFFF &&
2596 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2598 Ret
= Child
->head
.h
;
2611 * Searches a window's children for a window with the specified
2614 * hwndParent = The window whose childs are to be searched.
2616 * HWND_MESSAGE = message-only windows
2618 * hwndChildAfter = Search starts after this child window.
2619 * NULL = start from beginning
2621 * ucClassName = Class name to search for
2622 * Reguired parameter.
2624 * ucWindowName = Window name
2625 * ->Buffer == NULL = don't care
2628 * The HWND of the window if it was found, otherwise NULL
2634 NtUserFindWindowEx(HWND hwndParent
,
2635 HWND hwndChildAfter
,
2636 PUNICODE_STRING ucClassName
,
2637 PUNICODE_STRING ucWindowName
,
2640 PWND Parent
, ChildAfter
;
2641 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2642 HWND Desktop
, Ret
= NULL
;
2643 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2644 DECLARE_RETURN(HWND
);
2646 DPRINT("Enter NtUserFindWindowEx\n");
2649 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2653 if (ucClassName
!= NULL
)
2655 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2656 if (ClassName
.Length
!= 0)
2658 ProbeForRead(ClassName
.Buffer
,
2662 else if (!IS_ATOM(ClassName
.Buffer
))
2664 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2668 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2675 if (ucWindowName
!= NULL
)
2677 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2678 if (WindowName
.Length
!= 0)
2680 ProbeForRead(WindowName
.Buffer
,
2686 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2688 SetLastNtError(_SEH2_GetExceptionCode());
2689 _SEH2_YIELD(RETURN(NULL
));
2693 if (ucClassName
!= NULL
)
2695 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2696 !IS_ATOM(ClassName
.Buffer
))
2698 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2701 else if (ClassAtom
== (RTL_ATOM
)0)
2703 /* LastError code was set by IntGetAtomFromStringOrAtom */
2709 Desktop
= IntGetCurrentThreadDesktopWindow();
2711 if(hwndParent
== NULL
)
2712 hwndParent
= Desktop
;
2713 else if(hwndParent
== HWND_MESSAGE
)
2715 hwndParent
= IntGetMessageWindow();
2718 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2724 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2731 if(Parent
->head
.h
== Desktop
)
2734 PWND TopLevelWindow
;
2735 BOOLEAN CheckWindowName
;
2736 BOOLEAN WindowMatches
;
2737 BOOLEAN ClassMatches
;
2739 /* windows searches through all top-level windows if the parent is the desktop
2742 if((List
= IntWinListChildren(Parent
)))
2748 /* skip handles before and including ChildAfter */
2749 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2753 CheckWindowName
= WindowName
.Length
!= 0;
2755 /* search children */
2758 UNICODE_STRING ustr
;
2760 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2765 /* Do not send WM_GETTEXT messages in the kernel mode version!
2766 The user mode version however calls GetWindowText() which will
2767 send WM_GETTEXT messages to windows belonging to its processes */
2768 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2769 ustr
.Length
= TopLevelWindow
->strName
.Length
;
2770 ustr
.MaximumLength
= TopLevelWindow
->strName
.MaximumLength
;
2771 WindowMatches
= !CheckWindowName
||
2772 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2773 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2774 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2775 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2777 if (WindowMatches
&& ClassMatches
)
2779 Ret
= TopLevelWindow
->head
.h
;
2783 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2785 /* window returns the handle of the top-level window, in case it found
2787 Ret
= TopLevelWindow
->head
.h
;
2796 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2800 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2802 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2803 search the message-only windows. Should this also be done if
2804 Parent is the desktop window??? */
2807 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2809 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2814 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2816 SetLastNtError(_SEH2_GetExceptionCode());
2824 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2834 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
2845 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
2847 PWND WndAncestor
, Parent
;
2849 if (Wnd
->head
.h
== IntGetDesktopWindow())
2858 WndAncestor
= Wnd
->spwndParent
;
2869 if(!(Parent
= WndAncestor
->spwndParent
))
2873 if(IntIsDesktopWindow(Parent
))
2878 WndAncestor
= Parent
;
2891 Parent
= IntGetParent(WndAncestor
);
2898 WndAncestor
= Parent
;
2916 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2918 PWND Window
, Ancestor
;
2919 DECLARE_RETURN(HWND
);
2921 DPRINT("Enter NtUserGetAncestor\n");
2922 UserEnterExclusive();
2924 if (!(Window
= UserGetWindowObject(hWnd
)))
2929 Ancestor
= UserGetAncestor(Window
, Type
);
2930 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
2932 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
2935 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
2943 NtUserGetComboBoxInfo(
2948 DECLARE_RETURN(BOOL
);
2950 DPRINT("Enter NtUserGetComboBoxInfo\n");
2953 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2962 sizeof(COMBOBOXINFO
),
2966 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2968 SetLastNtError(_SEH2_GetExceptionCode());
2969 _SEH2_YIELD(RETURN(FALSE
));
2973 // Pass the user pointer, it was already probed.
2974 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
2977 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
2987 NtUserGetInternalWindowPos( HWND hWnd
,
2994 WINDOWPLACEMENT wndpl
;
2998 if (!(Window
= UserGetWindowObject(hWnd
)))
3008 ProbeForWrite(rectWnd
,
3014 ProbeForWrite(ptIcon
,
3020 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3022 SetLastNtError(_SEH2_GetExceptionCode());
3027 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3029 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3035 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3039 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3043 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3045 SetLastNtError(_SEH2_GetExceptionCode());
3050 if (!Hit
) Ret
= wndpl
.showCmd
;
3059 NtUserGetListBoxInfo(
3063 DECLARE_RETURN(DWORD
);
3065 DPRINT("Enter NtUserGetListBoxInfo\n");
3068 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3073 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3076 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3083 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3085 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3086 HWND hWndOldParent
= NULL
;
3087 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3089 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3091 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3095 if (hWndChild
== IntGetDesktopWindow())
3097 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3103 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3110 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3116 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3121 UserRefObjectCo(Wnd
, &Ref
);
3122 UserRefObjectCo(WndParent
, &ParentRef
);
3124 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3126 UserDerefObjectCo(WndParent
);
3127 UserDerefObjectCo(Wnd
);
3131 hWndOldParent
= WndOldParent
->head
.h
;
3132 UserDereferenceObject(WndOldParent
);
3135 return( hWndOldParent
);
3141 * The NtUserSetParent function changes the parent window of the specified
3145 * The new parent window and the child window must belong to the same
3146 * application. If the window identified by the hWndChild parameter is
3147 * visible, the system performs the appropriate redrawing and repainting.
3148 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3149 * or WS_POPUP window styles of the window whose parent is being changed.
3156 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3158 DECLARE_RETURN(HWND
);
3160 DPRINT("Enter NtUserSetParent\n");
3161 UserEnterExclusive();
3164 Check Parent first from user space, set it here.
3168 hWndNewParent
= IntGetDesktopWindow();
3170 else if (hWndNewParent
== HWND_MESSAGE
)
3172 hWndNewParent
= IntGetMessageWindow();
3175 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3178 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3184 * UserGetShellWindow
3186 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3191 HWND FASTCALL
UserGetShellWindow(VOID
)
3193 PWINSTATION_OBJECT WinStaObject
;
3196 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3201 if (!NT_SUCCESS(Status
))
3203 SetLastNtError(Status
);
3207 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3209 ObDereferenceObject(WinStaObject
);
3214 * NtUserSetShellWindowEx
3216 * This is undocumented function to set global shell window. The global
3217 * shell window has special handling of window position.
3223 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3225 PWINSTATION_OBJECT WinStaObject
;
3226 PWND WndShell
, WndListView
;
3227 DECLARE_RETURN(BOOL
);
3228 USER_REFERENCE_ENTRY Ref
;
3232 DPRINT("Enter NtUserSetShellWindowEx\n");
3233 UserEnterExclusive();
3235 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3240 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3245 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3250 if (!NT_SUCCESS(Status
))
3252 SetLastNtError(Status
);
3257 * Test if we are permitted to change the shell window.
3259 if (WinStaObject
->ShellWindow
)
3261 ObDereferenceObject(WinStaObject
);
3266 * Move shell window into background.
3268 if (hwndListView
&& hwndListView
!= hwndShell
)
3271 * Disabled for now to get Explorer working.
3272 * -- Filip, 01/nov/2003
3275 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3278 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3280 ObDereferenceObject(WinStaObject
);
3285 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3287 ObDereferenceObject(WinStaObject
);
3291 UserRefObjectCo(WndShell
, &Ref
);
3292 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3294 WinStaObject
->ShellWindow
= hwndShell
;
3295 WinStaObject
->ShellListView
= hwndListView
;
3297 ti
= GetW32ThreadInfo();
3298 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3300 UserDerefObjectCo(WndShell
);
3302 ObDereferenceObject(WinStaObject
);
3306 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3312 * NtUserGetSystemMenu
3314 * The NtUserGetSystemMenu function allows the application to access the
3315 * window menu (also known as the system menu or the control menu) for
3316 * copying and modifying.
3320 * Handle to the window that will own a copy of the window menu.
3322 * Specifies the action to be taken. If this parameter is FALSE,
3323 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3324 * currently in use. The copy is initially identical to the window menu
3325 * but it can be modified.
3326 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3327 * to the default state. The previous window menu, if any, is destroyed.
3330 * If the bRevert parameter is FALSE, the return value is a handle to a
3331 * copy of the window menu. If the bRevert parameter is TRUE, the return
3339 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3343 DECLARE_RETURN(HMENU
);
3345 DPRINT("Enter NtUserGetSystemMenu\n");
3348 if (!(Window
= UserGetWindowObject(hWnd
)))
3353 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3358 RETURN(Menu
->MenuInfo
.Self
);
3361 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3367 * NtUserSetSystemMenu
3374 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3376 BOOL Result
= FALSE
;
3379 DECLARE_RETURN(BOOL
);
3381 DPRINT("Enter NtUserSetSystemMenu\n");
3382 UserEnterExclusive();
3384 if (!(Window
= UserGetWindowObject(hWnd
)))
3392 * Assign new menu handle.
3394 if (!(Menu
= UserGetMenuObject(hMenu
)))
3399 Result
= IntSetSystemMenu(Window
, Menu
);
3405 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3411 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3413 PWND Window
, Parent
;
3414 PWINSTATION_OBJECT WindowStation
;
3418 if (hWnd
== IntGetDesktopWindow())
3420 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3424 if (!(Window
= UserGetWindowObject(hWnd
)))
3429 if ((INT
)Index
>= 0)
3431 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3433 SetLastWin32Error(ERROR_INVALID_INDEX
);
3437 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3439 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3441 OldValue = (LONG)IntSetWindowProc( Wnd,
3444 if (!OldValue) return 0;
3447 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3454 OldValue
= (LONG
) Window
->ExStyle
;
3455 Style
.styleOld
= OldValue
;
3456 Style
.styleNew
= NewValue
;
3459 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3461 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3464 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3465 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3468 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3469 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3470 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3474 OldValue
= (LONG
) Window
->style
;
3475 Style
.styleOld
= OldValue
;
3476 Style
.styleNew
= NewValue
;
3477 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3478 Window
->style
= (DWORD
)Style
.styleNew
;
3479 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3484 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3485 Window
->fnid
& FNID_FREED
)
3487 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3490 OldValue
= (LONG
)IntSetWindowProc(Window
,
3497 OldValue
= (LONG
) Window
->hModule
;
3498 Window
->hModule
= (HINSTANCE
) NewValue
;
3501 case GWL_HWNDPARENT
:
3502 Parent
= Window
->spwndParent
;
3503 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3504 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3506 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3510 OldValue
= (LONG
) Window
->IDMenu
;
3511 Window
->IDMenu
= (UINT
) NewValue
;
3515 OldValue
= Window
->dwUserData
;
3516 Window
->dwUserData
= NewValue
;
3520 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3521 SetLastWin32Error(ERROR_INVALID_INDEX
);
3531 * NtUserSetWindowLong
3533 * The NtUserSetWindowLong function changes an attribute of the specified
3534 * window. The function also sets the 32-bit (long) value at the specified
3535 * offset into the extra window memory.
3542 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3544 DECLARE_RETURN(LONG
);
3546 DPRINT("Enter NtUserSetWindowLong\n");
3547 UserEnterExclusive();
3549 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3552 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3558 * NtUserSetWindowWord
3560 * Legacy function similar to NtUserSetWindowLong.
3567 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3571 DECLARE_RETURN(WORD
);
3573 DPRINT("Enter NtUserSetWindowWord\n");
3574 UserEnterExclusive();
3576 if (!(Window
= UserGetWindowObject(hWnd
)))
3585 case GWL_HWNDPARENT
:
3586 RETURN( co_UserSetWindowLong(Window
->head
.h
, Index
, (UINT
)NewValue
, TRUE
));
3590 SetLastWin32Error(ERROR_INVALID_INDEX
);
3595 if (Index
> Window
->cbwndExtra
- sizeof(WORD
))
3597 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3601 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3602 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3607 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3616 NtUserGetWindowPlacement(HWND hWnd
,
3617 WINDOWPLACEMENT
*lpwndpl
)
3621 WINDOWPLACEMENT Safepl
;
3623 DECLARE_RETURN(BOOL
);
3625 DPRINT("Enter NtUserGetWindowPlacement\n");
3628 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3633 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3634 if(!NT_SUCCESS(Status
))
3636 SetLastNtError(Status
);
3639 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3645 if (0 == (Wnd
->style
& WS_VISIBLE
))
3647 Safepl
.showCmd
= SW_HIDE
;
3649 else if ((0 != (Wnd
->state2
& WNDS2_MAXIMIZEBUTTONDOWN
) ||
3650 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
3651 0 == (Wnd
->style
& WS_MINIMIZE
))
3653 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
3655 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
3657 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
3659 else if (0 != (Wnd
->style
& WS_VISIBLE
))
3661 Safepl
.showCmd
= SW_SHOWNORMAL
;
3664 Size
.x
= Wnd
->rcWindow
.left
;
3665 Size
.y
= Wnd
->rcWindow
.top
;
3666 WinPosInitInternalPos(Wnd
, &Size
,
3669 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
3670 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
3671 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
3673 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3674 if(!NT_SUCCESS(Status
))
3676 SetLastNtError(Status
);
3683 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
3693 NtUserLockWindowUpdate(HWND hWnd
)
3713 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3714 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3715 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3719 QueryWindow based on KJK::Hyperion and James Tabor.
3721 0 = QWUniqueProcessId
3722 1 = QWUniqueThreadId
3725 4 = QWIsHung Implements IsHungAppWindow found
3728 9 = QWKillWindow When I called this with hWnd ==
3729 DesktopWindow, it shutdown the system
3736 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3740 DECLARE_RETURN(UINT
);
3742 DPRINT("Enter NtUserQueryWindow\n");
3745 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3752 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3753 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3756 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3757 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3760 case QUERY_WINDOW_ACTIVE
:
3761 Result
= (DWORD
)UserGetActiveWindow();
3764 case QUERY_WINDOW_FOCUS
:
3765 Result
= (DWORD
)IntGetFocusWindow();
3768 case QUERY_WINDOW_ISHUNG
:
3769 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
->MessageQueue
);
3772 case QUERY_WINDOW_REAL_ID
:
3773 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3776 Result
= (DWORD
)NULL
;
3783 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3793 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3807 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3809 UNICODE_STRING SafeMessageName
;
3812 DECLARE_RETURN(UINT
);
3814 DPRINT("Enter NtUserRegisterWindowMessage\n");
3815 UserEnterExclusive();
3817 if(MessageNameUnsafe
== NULL
)
3819 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3823 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3824 if(!NT_SUCCESS(Status
))
3826 SetLastNtError(Status
);
3830 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3831 if (SafeMessageName
.Buffer
)
3832 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3836 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3846 NtUserSetImeOwnerWindow(DWORD Unknown0
,
3859 NtUserSetInternalWindowPos(
3876 NtUserSetLayeredWindowAttributes(HWND hwnd
,
3890 NtUserSetLogonNotifyWindow(HWND hWnd
)
3909 DECLARE_RETURN(BOOL
);
3911 DPRINT("Enter NtUserSetMenu\n");
3912 UserEnterExclusive();
3914 if (!(Window
= UserGetWindowObject(hWnd
)))
3919 if (! IntSetMenu(Window
, Menu
, &Changed
))
3924 if (Changed
&& Repaint
)
3926 USER_REFERENCE_ENTRY Ref
;
3928 UserRefObjectCo(Window
, &Ref
);
3929 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3930 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3932 UserDerefObjectCo(Window
);
3938 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3948 NtUserSetWindowFNID(HWND hWnd
,
3952 DECLARE_RETURN(BOOL
);
3954 DPRINT("Enter NtUserSetWindowFNID\n");
3955 UserEnterExclusive();
3957 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3963 { // From user land we only set these.
3964 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
3969 Wnd
->pcls
->fnid
|= fnID
;
3974 DPRINT("Leave NtUserSetWindowFNID\n");
3984 NtUserSetWindowPlacement(HWND hWnd
,
3985 WINDOWPLACEMENT
*lpwndpl
)
3988 WINDOWPLACEMENT Safepl
;
3990 DECLARE_RETURN(BOOL
);
3991 USER_REFERENCE_ENTRY Ref
;
3993 DPRINT("Enter NtUserSetWindowPlacement\n");
3994 UserEnterExclusive();
3996 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4001 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4002 if(!NT_SUCCESS(Status
))
4004 SetLastNtError(Status
);
4007 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4012 UserRefObjectCo(Wnd
, &Ref
);
4014 if ((Wnd
->style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4016 co_WinPosSetWindowPos(Wnd
, NULL
,
4017 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4018 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4019 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4020 SWP_NOZORDER
| SWP_NOACTIVATE
);
4023 /* FIXME - change window status */
4024 co_WinPosShowWindow(Wnd
, Safepl
.showCmd
);
4026 Wnd
->InternalPosInitialized
= TRUE
;
4027 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4028 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4029 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4031 UserDerefObjectCo(Wnd
);
4035 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4047 HWND hWndInsertAfter
,
4054 DECLARE_RETURN(BOOL
);
4057 USER_REFERENCE_ENTRY Ref
;
4059 DPRINT("Enter NtUserSetWindowPos\n");
4060 UserEnterExclusive();
4062 if (!(Window
= UserGetWindowObject(hWnd
)))
4067 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
4068 if (!(uFlags
& SWP_NOMOVE
))
4070 if (X
< -32768) X
= -32768;
4071 else if (X
> 32767) X
= 32767;
4072 if (Y
< -32768) Y
= -32768;
4073 else if (Y
> 32767) Y
= 32767;
4075 if (!(uFlags
& SWP_NOSIZE
))
4078 else if (cx
> 32767) cx
= 32767;
4080 else if (cy
> 32767) cy
= 32767;
4083 UserRefObjectCo(Window
, &Ref
);
4084 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4085 UserDerefObjectCo(Window
);
4090 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4097 IntGetWindowRgn(PWND Window
, HRGN hRgn
)
4112 /* Create a new window region using the window rectangle */
4113 VisRgn
= IntSysCreateRectRgnIndirect(&Window
->rcWindow
);
4114 NtGdiOffsetRgn(VisRgn
, -Window
->rcWindow
.left
, -Window
->rcWindow
.top
);
4115 /* if there's a region assigned to the window, combine them both */
4116 if(Window
->hrgnClip
&& !(Window
->style
& WS_MINIMIZE
))
4117 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->hrgnClip
, RGN_AND
);
4118 /* Copy the region into hRgn */
4119 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4121 if((pRgn
= RGNOBJAPI_Lock(hRgn
, NULL
)))
4123 Ret
= REGION_Complexity(pRgn
);
4124 RGNOBJAPI_Unlock(pRgn
);
4129 REGION_FreeRgnByHandle(VisRgn
);
4135 IntGetWindowRgnBox(PWND Window
, RECTL
*Rect
)
4150 /* Create a new window region using the window rectangle */
4151 VisRgn
= IntSysCreateRectRgnIndirect(&Window
->rcWindow
);
4152 NtGdiOffsetRgn(VisRgn
, -Window
->rcWindow
.left
, -Window
->rcWindow
.top
);
4153 /* if there's a region assigned to the window, combine them both */
4154 if(Window
->hrgnClip
&& !(Window
->style
& WS_MINIMIZE
))
4155 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->hrgnClip
, RGN_AND
);
4157 if((pRgn
= RGNOBJAPI_Lock(VisRgn
, NULL
)))
4159 Ret
= REGION_Complexity(pRgn
);
4160 *Rect
= pRgn
->rdh
.rcBound
;
4161 RGNOBJAPI_Unlock(pRgn
);
4166 REGION_FreeRgnByHandle(VisRgn
);
4183 DECLARE_RETURN(INT
);
4185 DPRINT("Enter NtUserSetWindowRgn\n");
4186 UserEnterExclusive();
4188 if (!(Window
= UserGetWindowObject(hWnd
)))
4193 if (hRgn
) // The region will be deleted in user32.
4195 if (GDIOBJ_ValidateHandle(hRgn
, GDI_OBJECT_TYPE_REGION
))
4197 hrgnCopy
= IntSysCreateRectRgn(0, 0, 0, 0);
4198 NtGdiCombineRgn(hrgnCopy
, hRgn
, 0, RGN_COPY
);
4204 hrgnCopy
= (HRGN
) 1;
4206 if (Window
->hrgnClip
)
4208 /* Delete no longer needed region handle */
4209 GreDeleteObject(Window
->hrgnClip
);
4211 Window
->hrgnClip
= hrgnCopy
;
4213 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4217 USER_REFERENCE_ENTRY Ref
;
4218 UserRefObjectCo(Window
, &Ref
);
4219 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4220 UserDerefObjectCo(Window
);
4226 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4236 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4240 DECLARE_RETURN(BOOL
);
4241 USER_REFERENCE_ENTRY Ref
;
4243 DPRINT("Enter NtUserShowWindow\n");
4244 UserEnterExclusive();
4246 if (!(Window
= UserGetWindowObject(hWnd
)))
4251 UserRefObjectCo(Window
, &Ref
);
4252 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4253 UserDerefObjectCo(Window
);
4258 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4268 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4274 return NtUserShowWindow(hWnd
, nCmdShow
);
4284 NtUserUpdateLayeredWindow(
4292 BLENDFUNCTION
*pblend
,
4305 NtUserWindowFromPhysicalPoint(POINT Point
)
4316 NtUserWindowFromPoint(LONG X
, LONG Y
)
4320 PWND DesktopWindow
= NULL
, Window
= NULL
;
4321 DECLARE_RETURN(HWND
);
4322 USER_REFERENCE_ENTRY Ref
;
4324 DPRINT("Enter NtUserWindowFromPoint\n");
4325 UserEnterExclusive();
4327 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4334 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4335 //its possible this referencing is useless, thou it shouldnt hurt...
4336 UserRefObjectCo(DesktopWindow
, &Ref
);
4338 pti
= PsGetCurrentThreadWin32Thread();
4339 co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4343 Ret
= Window
->head
.h
;
4352 if (Window
) UserDereferenceObject(Window
);
4353 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4355 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4365 * Undocumented function that is called from DefWindowProc to set
4372 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4375 LARGE_STRING SafeText
;
4376 UNICODE_STRING UnicodeString
;
4379 DPRINT("Enter NtUserDefSetText\n");
4381 if (WindowText
!= NULL
)
4385 SafeText
= ProbeForReadLargeString(WindowText
);
4387 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4390 SetLastNtError(_SEH2_GetExceptionCode());
4400 UserEnterExclusive();
4402 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4408 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4409 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4410 // Now we know what the bAnsi is for.
4411 RtlInitUnicodeString(&UnicodeString
, NULL
);
4412 if (SafeText
.Buffer
)
4417 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4419 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4420 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4422 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4425 SetLastNtError(_SEH2_GetExceptionCode());
4428 if (!Ret
) goto Exit
;
4431 if (UnicodeString
.Length
!= 0)
4433 if (Wnd
->strName
.MaximumLength
> 0 &&
4434 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4436 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4438 Wnd
->strName
.Length
= UnicodeString
.Length
;
4439 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4440 RtlCopyMemory(Wnd
->strName
.Buffer
,
4441 UnicodeString
.Buffer
,
4442 UnicodeString
.Length
);
4447 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4448 buf
= Wnd
->strName
.Buffer
;
4449 Wnd
->strName
.Buffer
= NULL
;
4452 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4455 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4456 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4457 if (Wnd
->strName
.Buffer
!= NULL
)
4459 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4460 RtlCopyMemory(Wnd
->strName
.Buffer
,
4461 UnicodeString
.Buffer
,
4462 UnicodeString
.Length
);
4463 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4464 Wnd
->strName
.Length
= UnicodeString
.Length
;
4468 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4476 Wnd
->strName
.Length
= 0;
4477 if (Wnd
->strName
.Buffer
!= NULL
)
4478 Wnd
->strName
.Buffer
[0] = L
'\0';
4481 // HAX! FIXME! Windows does not do this in here!
4482 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4483 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4484 /* Send shell notifications */
4485 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4487 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4492 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4493 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4499 * NtUserInternalGetWindowText
4506 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4511 DECLARE_RETURN(INT
);
4513 DPRINT("Enter NtUserInternalGetWindowText\n");
4516 if(lpString
&& (nMaxCount
<= 1))
4518 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4522 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4527 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4530 const WCHAR Terminator
= L
'\0';
4532 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4534 Copy
= min(nMaxCount
- 1, Result
);
4537 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4538 if(!NT_SUCCESS(Status
))
4540 SetLastNtError(Status
);
4546 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4547 if(!NT_SUCCESS(Status
))
4549 SetLastNtError(Status
);
4559 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4567 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4573 // ASSERT(OwnerWnd);
4575 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
4580 while (win_array
[count
])
4582 while (--count
>= 0)
4584 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4586 if (pWnd
->spwndOwner
!= OwnerWnd
)
4591 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4593 /* In Windows, ShowOwnedPopups(TRUE) generates
4594 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4595 * regardless of the state of the owner
4597 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4603 if (pWnd
->style
& WS_VISIBLE
)
4605 /* In Windows, ShowOwnedPopups(FALSE) generates
4606 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4607 * regardless of the state of the owner
4609 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4615 ExFreePool( win_array
);
4620 * NtUserValidateHandleSecure
4628 NtUserValidateHandleSecure(
4636 PUSER_HANDLE_ENTRY entry
;
4637 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
4639 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4642 uType
= entry
->type
;
4649 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
4655 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
4660 PACCELERATOR_TABLE Accel
;
4661 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
4666 PCURICON_OBJECT Cursor
;
4667 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
4673 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
4679 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
4685 return UserGetCallProcInfo( handle
, &Proc
);
4688 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4692 { /* Is handle entry restricted? */