2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 * COPYRIGHT: See COPYING in the top level directory
21 * PROJECT: ReactOS kernel
23 * FILE: subsys/win32k/ntuser/window.c
24 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 06-06-2001 CSH Created
29 /* INCLUDES ******************************************************************/
37 /* dialog resources appear to pass this in 16 bits, handle them properly */
38 #define CW_USEDEFAULT16 (0x8000)
40 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
42 /* PRIVATE FUNCTIONS **********************************************************/
47 * Initialize windowing implementation.
53 return STATUS_SUCCESS
;
59 * Cleanup windowing implementation.
63 CleanupWindowImpl(VOID
)
65 return STATUS_SUCCESS
;
68 /* HELPER FUNCTIONS ***********************************************************/
70 BOOL FASTCALL
UserUpdateUiState(PWINDOW Wnd
, WPARAM wParam
)
72 WORD Action
= LOWORD(wParam
);
73 WORD Flags
= HIWORD(wParam
);
75 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
77 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
84 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
88 if (Flags
& UISF_HIDEFOCUS
)
89 Wnd
->HideFocus
= TRUE
;
90 if (Flags
& UISF_HIDEACCEL
)
91 Wnd
->HideAccel
= TRUE
;
95 if (Flags
& UISF_HIDEFOCUS
)
96 Wnd
->HideFocus
= FALSE
;
97 if (Flags
& UISF_HIDEACCEL
)
98 Wnd
->HideAccel
= FALSE
;
105 PWINDOW_OBJECT FASTCALL
IntGetWindowObject(HWND hWnd
)
107 PWINDOW_OBJECT Window
;
109 if (!hWnd
) return NULL
;
111 Window
= UserGetWindowObject(hWnd
);
114 ASSERT(USER_BODY_TO_HEADER(Window
)->RefCount
>= 0);
116 USER_BODY_TO_HEADER(Window
)->RefCount
++;
122 PWINDOW_OBJECT FASTCALL
UserGetWindowObject(HWND hWnd
)
125 PWINDOW_OBJECT Window
;
127 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
129 ti
= GetW32ThreadInfo();
132 SetLastWin32Error(ERROR_ACCESS_DENIED
);
139 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
143 Window
= (PWINDOW_OBJECT
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
144 if (!Window
|| 0 != (Window
->Status
& WINDOWSTATUS_DESTROYED
))
146 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
150 ASSERT(USER_BODY_TO_HEADER(Window
)->RefCount
>= 0);
158 * The function determines whether the specified window handle identifies
159 * an existing window.
163 * Handle to the window to test.
166 * If the window handle identifies an existing window, the return value
167 * is TRUE. If the window handle does not identify an existing window,
168 * the return value is FALSE.
172 IntIsWindow(HWND hWnd
)
174 PWINDOW_OBJECT Window
;
176 if (!(Window
= UserGetWindowObject(hWnd
)))
185 Caller must NOT dereference retval!
186 But if caller want the returned value to persist spanning a co_ call,
187 it must reference the value (because the owner is not garanteed to
188 exist just because the owned window exist)!
190 PWINDOW_OBJECT FASTCALL
191 IntGetParent(PWINDOW_OBJECT Wnd
)
193 if (Wnd
->Wnd
->Style
& WS_POPUP
)
195 return UserGetWindowObject(Wnd
->hOwner
);
197 else if (Wnd
->Wnd
->Style
& WS_CHILD
)
207 Caller must NOT dereference retval!
208 But if caller want the returned value to persist spanning a co_ call,
209 it must reference the value (because the owner is not garanteed to
210 exist just because the owned window exist)!
212 PWINDOW_OBJECT FASTCALL
213 IntGetOwner(PWINDOW_OBJECT Wnd
)
215 return UserGetWindowObject(Wnd
->hOwner
);
223 * Compile a list of all child window handles from given window.
226 * This function is similar to Wine WIN_ListChildren. The caller
227 * must free the returned list with ExFreePool.
231 IntWinListChildren(PWINDOW_OBJECT Window
)
233 PWINDOW_OBJECT Child
;
235 UINT Index
, NumChildren
= 0;
237 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
240 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
243 DPRINT1("Failed to allocate memory for children array\n");
244 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
247 for (Child
= Window
->FirstChild
, Index
= 0;
249 Child
= Child
->NextSibling
, ++Index
)
250 List
[Index
] = Child
->hSelf
;
256 /***********************************************************************
259 static void IntSendDestroyMsg(HWND hWnd
)
262 PWINDOW_OBJECT Window
;
267 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
269 if (hWnd
== info
.hwndCaret
)
276 Window
= UserGetWindowObject(hWnd
);
279 // USER_REFERENCE_ENTRY Ref;
280 // UserRefObjectCo(Window, &Ref);
282 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
284 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
287 // UserDerefObjectCo(Window);
290 /* The window could already be destroyed here */
293 * Send the WM_DESTROY to the window.
296 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
299 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
300 * make sure that the window still exists when we come back.
309 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
312 /* start from the end (FIXME: is this needed?) */
313 for (i
= 0; pWndArray
[i
]; i
++)
318 if (IsWindow( pWndArray
[i
] ))
319 WIN_SendDestroyMsg( pWndArray
[i
] );
321 HeapFree(GetProcessHeap(), 0, pWndArray
);
325 DPRINT("destroyed itself while in WM_DESTROY!\n");
331 UserFreeWindowInfo(PW32THREADINFO ti
, PWINDOW_OBJECT WindowObject
)
333 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
334 PWINDOW Wnd
= WindowObject
->Wnd
;
336 if (ClientInfo
->CallbackWnd
.pvWnd
== DesktopHeapAddressToUser(WindowObject
->Wnd
))
338 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
339 ClientInfo
->CallbackWnd
.pvWnd
= NULL
;
342 if (Wnd
->WindowName
.Buffer
!= NULL
)
344 Wnd
->WindowName
.Length
= 0;
345 Wnd
->WindowName
.MaximumLength
= 0;
346 DesktopHeapFree(Wnd
->pdesktop
,
347 Wnd
->WindowName
.Buffer
);
348 Wnd
->WindowName
.Buffer
= NULL
;
351 DesktopHeapFree(Wnd
->pdesktop
, Wnd
);
352 WindowObject
->Wnd
= NULL
;
355 /***********************************************************************
358 * Destroy storage associated to a window. "Internals" p.358
360 * This is the "functional" DestroyWindows function ei. all stuff
361 * done in CreateWindow is undone here and not in DestroyWindow:-P
364 static LRESULT
co_UserFreeWindow(PWINDOW_OBJECT Window
,
365 PW32PROCESS ProcessData
,
366 PTHREADINFO ThreadData
,
367 BOOLEAN SendMessages
)
371 PWINDOW_OBJECT Child
;
373 BOOLEAN BelongsToThreadData
;
380 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
382 DPRINT("Tried to call IntDestroyWindow() twice\n");
385 Window
->Status
|= WINDOWSTATUS_DESTROYING
;
386 Wnd
->Style
&= ~WS_VISIBLE
;
387 /* remove the window already at this point from the thread window list so we
388 don't get into trouble when destroying the thread windows while we're still
389 in IntDestroyWindow() */
390 RemoveEntryList(&Window
->ThreadListEntry
);
392 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
394 IntDeRegisterShellHookWindow(Window
->hSelf
);
398 /* Send destroy messages */
399 IntSendDestroyMsg(Window
->hSelf
);
402 /* free child windows */
403 Children
= IntWinListChildren(Window
);
406 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
408 if ((Child
= IntGetWindowObject(*ChildHandle
)))
410 if(!IntWndBelongsToThread(Child
, ThreadData
))
412 /* send WM_DESTROY messages to windows not belonging to the same thread */
413 IntSendDestroyMsg(Child
->hSelf
);
416 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
418 UserDereferenceObject(Child
);
421 ExFreePool(Children
);
427 * Clear the update region to make sure no WM_PAINT messages will be
428 * generated for this window while processing the WM_NCDESTROY.
430 co_UserRedrawWindow(Window
, NULL
, 0,
431 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
432 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
433 if(BelongsToThreadData
)
434 co_IntSendMessage(Window
->hSelf
, WM_NCDESTROY
, 0, 0);
436 MsqRemoveTimersWindow(ThreadData
->MessageQueue
, Window
->hSelf
);
438 /* flush the message queue */
439 MsqRemoveWindowMessagesFromQueue(Window
);
441 /* from now on no messages can be sent to this window anymore */
442 Window
->Status
|= WINDOWSTATUS_DESTROYED
;
443 /* don't remove the WINDOWSTATUS_DESTROYING bit */
445 /* reset shell window handles */
446 if(ThreadData
->Desktop
)
448 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellWindow
)
449 ThreadData
->Desktop
->WindowStation
->ShellWindow
= NULL
;
451 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellListView
)
452 ThreadData
->Desktop
->WindowStation
->ShellListView
= NULL
;
455 /* Unregister hot keys */
456 UnregisterWindowHotKeys (Window
);
458 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
462 WinPosCheckInternalPos(Window
->hSelf
);
463 if (Window
->hSelf
== GetCapture())
468 /* free resources associated with the window */
469 TIMER_RemoveWindowTimers(Window
->hSelf
);
472 if (!(Wnd
->Style
& WS_CHILD
) && Wnd
->IDMenu
473 && (Menu
= UserGetMenuObject((HMENU
)Wnd
->IDMenu
)))
475 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
479 if(Window
->SystemMenu
480 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
482 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
483 Window
->SystemMenu
= (HMENU
)0;
486 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
489 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
490 CLASS_RemoveWindow(Window
->Class
);
493 IntUnlinkWindow(Window
);
495 UserReferenceObject(Window
);
496 UserDeleteObject(Window
->hSelf
, otWindow
);
498 IntDestroyScrollBars(Window
);
500 /* dereference the class */
501 IntDereferenceClass(Wnd
->Class
,
502 Window
->ti
->pDeskInfo
,
506 if(Window
->WindowRegion
)
508 GreDeleteObject(Window
->WindowRegion
);
511 ASSERT(Window
->Wnd
!= NULL
);
512 UserFreeWindowInfo(Window
->ti
, Window
);
514 UserDereferenceObject(Window
);
516 IntClipboardFreeWindow(Window
);
522 IntGetWindowBorderMeasures(PWINDOW_OBJECT Window
, UINT
*cx
, UINT
*cy
)
524 PWINDOW Wnd
= Window
->Wnd
;
525 if(HAS_DLGFRAME(Wnd
->Style
, Wnd
->ExStyle
) && !(Wnd
->Style
& WS_MINIMIZE
))
527 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
528 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
532 if(HAS_THICKFRAME(Wnd
->Style
, Wnd
->ExStyle
)&& !(Wnd
->Style
& WS_MINIMIZE
))
534 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
535 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
537 else if(HAS_THINFRAME(Wnd
->Style
, Wnd
->ExStyle
))
539 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
540 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
550 IntGetWindowProc(IN PWINDOW_OBJECT Window
,
553 PWINDOW Wnd
= Window
->Wnd
;
555 ASSERT(UserIsEnteredExclusive() == TRUE
);
559 return (Ansi
? Wnd
->WndProcExtra
: Wnd
->WndProc
);
563 if (!Ansi
== Wnd
->Unicode
)
569 if (Wnd
->CallProc
!= NULL
)
571 return GetCallProcHandle(Wnd
->CallProc
);
573 /* BUGBOY Comments: Maybe theres something Im not undestanding here, but why would a CallProc be created
574 on a function that I thought is only suppose to return the current Windows Proc? */
577 PCALLPROC NewCallProc
, CallProc
;
579 NewCallProc
= UserFindCallProc(Wnd
->Class
,
582 if (NewCallProc
== NULL
)
584 NewCallProc
= CreateCallProc(Wnd
->ti
->pDeskInfo
,
588 if (NewCallProc
== NULL
)
590 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
594 UserAddCallProcToClass(Wnd
->Class
,
598 CallProc
= Wnd
->CallProc
;
599 Wnd
->CallProc
= NewCallProc
;
601 return GetCallProcHandle((CallProc
== NULL
? NewCallProc
: CallProc
));
608 IntGetWindowInfo(PWINDOW_OBJECT Window
, PWINDOWINFO pwi
)
610 PWINDOW Wnd
= Window
->Wnd
;
612 pwi
->cbSize
= sizeof(WINDOWINFO
);
613 pwi
->rcWindow
= Window
->Wnd
->WindowRect
;
614 pwi
->rcClient
= Window
->Wnd
->ClientRect
;
615 pwi
->dwStyle
= Wnd
->Style
;
616 pwi
->dwExStyle
= Wnd
->ExStyle
;
617 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Window
->hSelf
); /* WS_ACTIVECAPTION */
618 IntGetWindowBorderMeasures(Window
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
619 pwi
->atomWindowType
= (Wnd
->Class
? Wnd
->Class
->Atom
: 0);
620 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
626 PWINDOW_OBJECT Window
,
630 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
631 PWINDOW Wnd
= Window
->Wnd
;
633 if ((Wnd
->Style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
635 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
639 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
647 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
648 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Window
->hSelf
);
657 NewMenu
= IntGetMenuObject(Menu
);
662 IntReleaseMenuObject(OldMenu
);
664 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
667 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
669 /* Can't use the same menu for two windows */
672 IntReleaseMenuObject(OldMenu
);
674 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
680 Wnd
->IDMenu
= (UINT
) Menu
;
683 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
684 IntReleaseMenuObject(NewMenu
);
688 OldMenu
->MenuInfo
.Wnd
= NULL
;
689 IntReleaseMenuObject(OldMenu
);
696 /* INTERNAL ******************************************************************/
700 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
705 USER_REFERENCE_ENTRY Ref
;
706 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
708 while (!IsListEmpty(&WThread
->WindowListHead
))
710 Current
= WThread
->WindowListHead
.Flink
;
711 Wnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
713 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
715 /* window removes itself from the list */
718 fixme: it is critical that the window removes itself! if now, we will loop
722 //ASSERT(co_UserDestroyWindow(Wnd));
724 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
725 if (!co_UserDestroyWindow(Wnd
))
727 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
729 UserDerefObjectCo(Wnd
);//faxme: temp hack??
737 * Returns client window rectangle relative to the upper-left corner of client area.
739 * \note Does not check the validity of the parameters
742 IntGetClientRect(PWINDOW_OBJECT Window
, RECTL
*Rect
)
747 Rect
->left
= Rect
->top
= 0;
748 Rect
->right
= Window
->Wnd
->ClientRect
.right
- Window
->Wnd
->ClientRect
.left
;
749 Rect
->bottom
= Window
->Wnd
->ClientRect
.bottom
- Window
->Wnd
->ClientRect
.top
;
755 IntGetFocusWindow(VOID
)
757 PUSER_MESSAGE_QUEUE Queue
;
758 PDESKTOP pdo
= IntGetActiveDesktop();
763 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
768 return(Queue
->FocusWindow
);
772 PMENU_OBJECT FASTCALL
773 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
)
775 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
776 PTHREADINFO W32Thread
;
777 HMENU hNewMenu
, hSysMenu
;
778 ROSMENUITEMINFO ItemInfo
;
782 W32Thread
= PsGetCurrentThreadWin32Thread();
784 if(!W32Thread
->Desktop
)
787 if(Window
->SystemMenu
)
789 Menu
= UserGetMenuObject(Window
->SystemMenu
);
792 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
793 Window
->SystemMenu
= (HMENU
)0;
797 if(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
)
799 /* clone system menu */
800 Menu
= UserGetMenuObject(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
);
804 NewMenu
= IntCloneMenu(Menu
);
807 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
808 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
809 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
811 //IntReleaseMenuObject(NewMenu);
816 hSysMenu
= UserCreateMenu(FALSE
);
817 if (NULL
== hSysMenu
)
821 SysMenu
= IntGetMenuObject(hSysMenu
);
824 UserDestroyMenu(hSysMenu
);
827 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
828 SysMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
829 hNewMenu
= co_IntLoadSysMenuTemplate();
832 IntReleaseMenuObject(SysMenu
);
833 UserDestroyMenu(hSysMenu
);
836 Menu
= IntGetMenuObject(hNewMenu
);
839 IntReleaseMenuObject(SysMenu
);
840 UserDestroyMenu(hSysMenu
);
844 NewMenu
= IntCloneMenu(Menu
);
847 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
848 IntReleaseMenuObject(NewMenu
);
849 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
851 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
852 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
853 ItemInfo
.fType
= MF_POPUP
;
854 ItemInfo
.fState
= MFS_ENABLED
;
855 ItemInfo
.dwTypeData
= NULL
;
857 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
858 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
860 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
864 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
873 if(Window
->SystemMenu
)
874 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
882 IntIsChildWindow(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT BaseWindow
)
884 PWINDOW_OBJECT Window
;
891 if (Window
== Parent
)
895 if(!(Wnd
->Style
& WS_CHILD
))
900 Window
= Window
->Parent
;
907 IntIsWindowVisible(PWINDOW_OBJECT BaseWindow
)
909 PWINDOW_OBJECT Window
;
916 if(!(Wnd
->Style
& WS_CHILD
))
920 if(!(Wnd
->Style
& WS_VISIBLE
))
925 Window
= Window
->Parent
;
928 if(Window
&& Wnd
->Style
& WS_VISIBLE
)
937 /* link the window into siblings and parent. children are kept in place. */
941 PWINDOW_OBJECT WndParent
,
942 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
945 PWINDOW_OBJECT Parent
;
947 Wnd
->Parent
= WndParent
;
948 Wnd
->Wnd
->Parent
= WndParent
? WndParent
->Wnd
: NULL
;
949 if ((Wnd
->PrevSibling
= WndPrevSibling
))
951 /* link after WndPrevSibling */
952 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
953 Wnd
->NextSibling
->PrevSibling
= Wnd
;
954 else if ((Parent
= Wnd
->Parent
))
956 if(Parent
->LastChild
== WndPrevSibling
)
957 Parent
->LastChild
= Wnd
;
959 Wnd
->PrevSibling
->NextSibling
= Wnd
;
964 Parent
= Wnd
->Parent
;
965 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
966 Wnd
->NextSibling
->PrevSibling
= Wnd
;
969 Parent
->LastChild
= Wnd
;
970 Parent
->FirstChild
= Wnd
;
975 Parent
->FirstChild
= Wnd
;
982 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
984 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
987 Wnd
= IntGetWindowObject(hWnd
);
991 WndOldOwner
= IntGetWindowObject(Wnd
->hOwner
);
994 ret
= WndOldOwner
->hSelf
;
995 UserDereferenceObject(WndOldOwner
);
1002 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1004 Wnd
->hOwner
= hWndNewOwner
;
1005 Wnd
->Wnd
->Owner
= WndNewOwner
->Wnd
;
1010 Wnd
->Wnd
->Owner
= NULL
;
1013 UserDereferenceObject(Wnd
);
1017 PWINDOW_OBJECT FASTCALL
1018 co_IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
1020 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
1021 // HWND hWnd, hWndNewParent;
1025 ASSERT(WndNewParent
);
1026 ASSERT_REFS_CO(Wnd
);
1027 ASSERT_REFS_CO(WndNewParent
);
1029 // hWnd = Wnd->hSelf;
1030 // hWndNewParent = WndNewParent->hSelf;
1033 * Windows hides the window first, then shows it again
1034 * including the WM_SHOWWINDOW messages and all
1036 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1038 // /* Validate that window and parent still exist */
1039 // if (!IntIsWindow(hWnd) || !IntIsWindow(hWndNewParent))
1042 /* Window must belong to current process */
1043 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
1046 WndOldParent
= Wnd
->Parent
;
1048 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1050 if (WndNewParent
!= WndOldParent
)
1052 IntUnlinkWindow(Wnd
);
1054 if (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1056 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
1057 Sibling
= WndNewParent
->FirstChild
;
1058 while (NULL
!= Sibling
&& 0 != (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1060 InsertAfter
= Sibling
;
1061 Sibling
= Sibling
->NextSibling
;
1064 if (NULL
== InsertAfter
)
1066 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1070 // UserReferenceObject(InsertAfter);
1071 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1072 // UserDereferenceObject(InsertAfter);
1077 * SetParent additionally needs to make hwnd the top window
1078 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1079 * WM_WINDOWPOSCHANGED notification messages.
1081 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1082 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1083 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1086 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1087 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1091 * Validate that the old parent still exist, since it migth have been
1092 * destroyed during the last callbacks to user-mode
1096 // if(!IntIsWindow(WndOldParent->hSelf))
1098 // UserDereferenceObject(WndOldParent);
1102 /* don't dereference the window object here, it must be done by the caller
1103 of IntSetParent() */
1104 // return WndOldParent;
1107 return WndOldParent
;//NULL;
1111 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
1113 PMENU_OBJECT OldMenu
;
1114 if(Window
->SystemMenu
)
1116 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1119 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1120 IntReleaseMenuObject(OldMenu
);
1126 /* FIXME check window style, propably return FALSE ? */
1127 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1128 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1131 Window
->SystemMenu
= (HMENU
)0;
1137 /* unlink the window from siblings and parent. children are kept in place. */
1139 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1141 PWINDOW_OBJECT WndParent
= Wnd
->Parent
;
1143 if (Wnd
->NextSibling
)
1144 Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1145 else if (WndParent
&& WndParent
->LastChild
== Wnd
)
1146 WndParent
->LastChild
= Wnd
->PrevSibling
;
1148 if (Wnd
->PrevSibling
)
1149 Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1150 else if (WndParent
&& WndParent
->FirstChild
== Wnd
)
1151 WndParent
->FirstChild
= Wnd
->NextSibling
;
1153 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1155 Wnd
->Wnd
->Parent
= NULL
;
1161 PWINDOW_OBJECT Window
, Child
;
1163 if(!(Window
= UserGetWindowObject(IntGetDesktopWindow())))
1168 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1170 if(Child
->hOwner
&& Child
->Wnd
->Style
& WS_VISIBLE
)
1173 * The desktop has a popup window if one of them has
1174 * an owner window and is visible
1184 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1186 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1192 IntGetWindowPlacement(PWINDOW_OBJECT Window
, WINDOWPLACEMENT
*lpwndpl
)
1198 if (!Wnd
) return FALSE
;
1200 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1206 if (0 == (Wnd
->Style
& WS_VISIBLE
))
1208 lpwndpl
->showCmd
= SW_HIDE
;
1210 else if (0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
1211 0 != (Wnd
->Style
& WS_MAXIMIZE
))
1213 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1215 else if (0 != (Wnd
->Style
& WS_MINIMIZE
))
1217 lpwndpl
->showCmd
= SW_MINIMIZE
;
1219 else if (0 != (Wnd
->Style
& WS_VISIBLE
))
1221 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1224 Size
.x
= Wnd
->WindowRect
.left
;
1225 Size
.y
= Wnd
->WindowRect
.top
;
1226 WinPosInitInternalPos(Window
, &Size
,
1229 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1230 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1231 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1237 /* FUNCTIONS *****************************************************************/
1243 NtUserAlterWindowStyle(DWORD Unknown0
,
1253 * As best as I can figure, this function is used by EnumWindows,
1254 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1256 * It's supposed to build a list of HWNDs to return to the caller.
1257 * We can figure out what kind of list by what parameters are
1265 NtUserBuildHwndList(
1278 return ERROR_INVALID_PARAMETER
;
1280 if (hwndParent
|| !dwThreadId
)
1283 PWINDOW_OBJECT Parent
, Window
;
1287 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1289 return ERROR_INVALID_HANDLE
;
1294 Status
= IntValidateDesktopHandle(hDesktop
,
1298 if(!NT_SUCCESS(Status
))
1300 return ERROR_INVALID_HANDLE
;
1303 hwndParent
= Desktop
->DesktopWindow
;
1310 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1311 (Window
= Parent
->FirstChild
))
1313 BOOL bGoDown
= TRUE
;
1315 Status
= STATUS_SUCCESS
;
1320 if(dwCount
++ < *pBufSize
&& pWnd
)
1324 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1325 *pWnd
= Window
->hSelf
;
1328 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1330 Status
= _SEH2_GetExceptionCode();
1333 if(!NT_SUCCESS(Status
))
1335 SetLastNtError(Status
);
1339 if (Window
->FirstChild
&& bChildren
)
1341 Window
= Window
->FirstChild
;
1346 if (Window
->NextSibling
)
1348 Window
= Window
->NextSibling
;
1352 Window
= Window
->Parent
;
1353 if (Window
== Parent
)
1362 ObDereferenceObject(Desktop
);
1368 PTHREADINFO W32Thread
;
1369 PLIST_ENTRY Current
;
1370 PWINDOW_OBJECT Window
;
1372 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1373 if(!NT_SUCCESS(Status
))
1375 return ERROR_INVALID_PARAMETER
;
1377 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1379 ObDereferenceObject(Thread
);
1380 DPRINT("Thread is not a GUI Thread!\n");
1381 return ERROR_INVALID_PARAMETER
;
1384 Current
= W32Thread
->WindowListHead
.Flink
;
1385 while(Current
!= &(W32Thread
->WindowListHead
))
1387 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1390 if(bChildren
|| Window
->hOwner
!= NULL
)
1392 if(dwCount
< *pBufSize
&& pWnd
)
1394 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1395 if(!NT_SUCCESS(Status
))
1397 SetLastNtError(Status
);
1403 Current
= Current
->Flink
;
1406 ObDereferenceObject(Thread
);
1409 *pBufSize
= dwCount
;
1410 return STATUS_SUCCESS
;
1418 NtUserChildWindowFromPointEx(HWND hwndParent
,
1423 PWINDOW_OBJECT Parent
;
1428 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1436 if(Parent
->hSelf
!= IntGetDesktopWindow())
1438 Pt
.x
+= Parent
->Wnd
->ClientRect
.left
;
1439 Pt
.y
+= Parent
->Wnd
->ClientRect
.top
;
1442 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1447 Ret
= Parent
->hSelf
;
1448 if((List
= IntWinListChildren(Parent
)))
1450 for(phWnd
= List
; *phWnd
; phWnd
++)
1452 PWINDOW_OBJECT Child
;
1454 if((Child
= UserGetWindowObject(*phWnd
)))
1456 ChildWnd
= Child
->Wnd
;
1457 if(!(ChildWnd
->Style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1461 if((ChildWnd
->Style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1465 if((ChildWnd
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1469 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1484 * calculates the default position of a window
1487 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT Window
, RECTL
*rc
, BOOL IncPos
)
1494 RECTL_bIntersectRect(rc
, rc
, &Parent
->Wnd
->ClientRect
);
1498 Pos
.x
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1499 Pos
.y
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1500 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1501 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1503 /* reset counter and position */
1506 Parent
->TiledCounter
= 0;
1508 Parent
->TiledCounter
++;
1519 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1520 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1524 rc
->right
= rc
->left
+ Sz
.cx
;
1525 rc
->bottom
= rc
->top
+ Sz
.cy
;
1534 co_IntCreateWindowEx(DWORD dwExStyle
,
1535 PUNICODE_STRING ClassName
,
1536 PUNICODE_STRING WindowName
,
1544 HINSTANCE hInstance
,
1547 BOOL bUnicodeWindow
)
1549 PWINSTATION_OBJECT WinSta
;
1551 PWINDOWCLASS
*ClassLink
, Class
= NULL
;
1553 PWINDOW_OBJECT Window
= NULL
;
1554 PWINDOW_OBJECT ParentWindow
= NULL
, OwnerWindow
;
1555 HWND ParentWindowHandle
;
1556 HWND OwnerWindowHandle
;
1557 PMENU_OBJECT SystemMenu
;
1561 PW32THREADINFO ti
= NULL
;
1564 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1570 CBT_CREATEWNDW CbtCreate
;
1573 DECLARE_RETURN(HWND
);
1575 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1578 pti
= PsGetCurrentThreadWin32Thread();
1579 ParentWindowHandle
= pti
->Desktop
->DesktopWindow
;
1580 OwnerWindowHandle
= NULL
;
1582 if (hWndParent
== HWND_MESSAGE
)
1585 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1586 * message window (style: WS_POPUP|WS_DISABLED)
1588 DPRINT1("FIXME - Parent is HWND_MESSAGE\n");
1589 // ParentWindowHandle set already.
1591 else if (hWndParent
)
1593 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1595 PWINDOW_OBJECT Par
= UserGetWindowObject(hWndParent
), Root
;
1596 if (Par
&& (Root
= UserGetAncestor(Par
, GA_ROOT
)))
1597 OwnerWindowHandle
= Root
->hSelf
;
1600 ParentWindowHandle
= hWndParent
;
1602 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1604 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1605 RETURN( (HWND
)0); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1608 // if (NULL != ParentWindowHandle)
1610 ParentWindow
= UserGetWindowObject(ParentWindowHandle
);
1612 if (ParentWindow
) UserRefObjectCo(ParentWindow
, &ParentRef
);
1616 // ParentWindow = NULL;
1619 /* FIXME: parent must belong to the current process */
1621 /* Check the window station. */
1622 ti
= GetW32ThreadInfo();
1623 if (ti
== NULL
|| pti
->Desktop
== NULL
)
1625 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1629 /* Check the class. */
1631 ClassAtom
= IntGetClassAtom(ClassName
,
1637 if (ClassAtom
== (RTL_ATOM
)0)
1639 if (IS_ATOM(ClassName
->Buffer
))
1641 DPRINT1("Class 0x%p not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1645 DPRINT1("Class \"%wZ\" not found\n", ClassName
);
1648 SetLastWin32Error(ERROR_CANNOT_FIND_WND_CLASS
);
1652 Class
= IntReferenceClass(Class
,
1657 DPRINT1("Failed to reference window class!\n");
1661 WinSta
= pti
->Desktop
->WindowStation
;
1663 //FIXME: Reference thread/desktop instead
1664 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1666 /* Create the window object. */
1667 Window
= (PWINDOW_OBJECT
)
1668 UserCreateObject(gHandleTable
, (PHANDLE
)&hWnd
,
1669 otWindow
, sizeof(WINDOW_OBJECT
));
1672 Window
->Wnd
= DesktopHeapAlloc(pti
->Desktop
,
1673 sizeof(WINDOW
) + Class
->WndExtra
);
1676 RtlZeroMemory(Window
->Wnd
,
1677 sizeof(WINDOW
) + Class
->WndExtra
);
1678 Window
->Wnd
->hdr
.Handle
= hWnd
; /* FIXME: Remove hack */
1683 Wnd
->pdesktop
= pti
->Desktop
;
1684 Wnd
->hWndLastActive
= hWnd
;
1687 DPRINT("Created object with handle %X\n", hWnd
);
1691 ObDereferenceObject(WinSta
);
1692 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1696 UserRefObjectCo(Window
, &Ref
);
1698 ObDereferenceObject(WinSta
);
1700 if (NULL
== pti
->Desktop
->DesktopWindow
)
1702 /* If there is no desktop window yet, we must be creating it */
1703 pti
->Desktop
->DesktopWindow
= hWnd
;
1704 pti
->Desktop
->DesktopInfo
->Wnd
= Wnd
;
1708 * Fill out the structure describing it.
1714 Window
->SystemMenu
= (HMENU
)0;
1715 Wnd
->ContextHelpId
= 0;
1717 Wnd
->Instance
= hInstance
;
1718 Window
->hSelf
= hWnd
;
1720 Window
->MessageQueue
= pti
->MessageQueue
;
1721 IntReferenceMessageQueue(Window
->MessageQueue
);
1722 Window
->Parent
= ParentWindow
;
1723 Wnd
->Parent
= ParentWindow
? ParentWindow
->Wnd
: NULL
;
1724 if (Wnd
->Parent
!= NULL
&& hWndParent
!= 0)
1726 Wnd
->HideFocus
= Wnd
->Parent
->HideFocus
;
1727 Wnd
->HideAccel
= Wnd
->Parent
->HideAccel
;
1730 if((OwnerWindow
= UserGetWindowObject(OwnerWindowHandle
)))
1732 Window
->hOwner
= OwnerWindowHandle
;
1733 Wnd
->Owner
= OwnerWindow
->Wnd
;
1738 Window
->hOwner
= NULL
;
1745 Wnd
->IsSystem
= Wnd
->Class
->System
;
1747 /* BugBoy Comments: Comment below say that System classes are always created as UNICODE.
1748 In windows, creating a window with the ANSI version of CreateWindow sets the window
1749 to ansi as verified by testing with IsUnicodeWindow API.
1751 No where can I see in code or through testing does the window change back to ANSI
1752 after being created as UNICODE in ROS. I didnt do more testing to see what problems this would cause.*/
1753 // See NtUserDefSetText! We convert to Unicode all the time and never use Mix. (jt)
1754 if (Wnd
->Class
->System
)
1756 /* NOTE: Always create a unicode window for system classes! */
1757 Wnd
->Unicode
= TRUE
;
1758 Wnd
->WndProc
= Wnd
->Class
->WndProc
;
1759 Wnd
->WndProcExtra
= Wnd
->Class
->WndProcExtra
;
1763 Wnd
->Unicode
= Wnd
->Class
->Unicode
;
1764 Wnd
->WndProc
= Wnd
->Class
->WndProc
;
1765 Wnd
->CallProc
= NULL
;
1768 Window
->OwnerThread
= PsGetCurrentThread();
1769 Window
->FirstChild
= NULL
;
1770 Window
->LastChild
= NULL
;
1771 Window
->PrevSibling
= NULL
;
1772 Window
->NextSibling
= NULL
;
1773 Wnd
->ExtraDataSize
= Wnd
->Class
->WndExtra
;
1775 InitializeListHead(&Wnd
->PropListHead
);
1776 InitializeListHead(&Window
->WndObjListHead
);
1778 if (NULL
!= WindowName
->Buffer
&& WindowName
->Length
> 0)
1780 Wnd
->WindowName
.Buffer
= DesktopHeapAlloc(Wnd
->pdesktop
,
1781 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1782 if (Wnd
->WindowName
.Buffer
== NULL
)
1784 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1788 Wnd
->WindowName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1791 RtlCopyMemory(Wnd
->WindowName
.Buffer
,
1793 WindowName
->Length
);
1794 Wnd
->WindowName
.Length
= WindowName
->Length
;
1796 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1798 WindowName
->Length
= 0;
1799 Wnd
->WindowName
.Buffer
[0] = L
'\0';
1805 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1806 * tested for WS_POPUP
1808 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1809 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1810 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1811 dwExStyle
|= WS_EX_WINDOWEDGE
;
1813 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1815 /* Correct the window style. */
1816 if (!(dwStyle
& WS_CHILD
))
1818 dwStyle
|= WS_CLIPSIBLINGS
;
1819 DPRINT("3: Style is now %lx\n", dwStyle
);
1820 if (!(dwStyle
& WS_POPUP
))
1822 dwStyle
|= WS_CAPTION
;
1823 Window
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1824 DPRINT("4: Style is now %lx\n", dwStyle
);
1828 /* create system menu */
1829 if((dwStyle
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1831 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
1834 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1835 IntReleaseMenuObject(SystemMenu
);
1839 /* Set the window menu */
1840 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1843 IntSetMenu(Window
, hMenu
, &MenuChanged
);
1846 hMenu
= Wnd
->Class
->hMenu
;
1847 if (hMenu
) IntSetMenu(Window
, hMenu
, &MenuChanged
);
1851 Wnd
->IDMenu
= (UINT
) hMenu
;
1853 /* Insert the window into the thread's window list. */
1854 InsertTailList (&pti
->WindowListHead
, &Window
->ThreadListEntry
);
1856 /* Handle "CS_CLASSDC", it is tested first. */
1857 if ((Wnd
->Class
->Style
& CS_CLASSDC
) && !(Wnd
->Class
->Dce
)) // One DCE per class to have CLASS.
1858 Wnd
->Class
->Dce
= DceAllocDCE(Window
, DCE_CLASS_DC
);
1859 /* Allocate a DCE for this window. */
1860 else if ( Wnd
->Class
->Style
& CS_OWNDC
)
1861 Window
->Dce
= DceAllocDCE(Window
, DCE_WINDOW_DC
);
1868 Wnd
->ExStyle
= dwExStyle
;
1869 Wnd
->Style
= dwStyle
& ~WS_VISIBLE
;
1872 Cs
.lpCreateParams
= lpParam
;
1873 Cs
.hInstance
= hInstance
;
1875 Cs
.hwndParent
= hWndParent
; //Pass the original Parent handle!
1880 Cs
.style
= Wnd
->Style
;
1881 Cs
.lpszName
= (LPCWSTR
) WindowName
;
1882 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
1883 Cs
.dwExStyle
= dwExStyle
;
1884 CbtCreate
.lpcs
= &Cs
;
1885 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1886 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) &CbtCreate
))
1888 /* FIXME - Delete window object and remove it from the thread windows list */
1889 /* FIXME - delete allocated DCE */
1890 DPRINT1("CBT-hook returned !0\n");
1891 RETURN( (HWND
) NULL
);
1899 /* default positioning for overlapped windows */
1900 if(!(Wnd
->Style
& (WS_POPUP
| WS_CHILD
)))
1903 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1904 BOOL CalculatedDefPosSize
= FALSE
;
1906 IntGetDesktopWorkArea(((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
, &WorkArea
);
1909 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1911 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1913 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, Window
, &rc
, TRUE
);
1915 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1917 ProcessParams
->WindowFlags
&= ~STARTF_USEPOSITION
;
1918 Pos
.x
= WorkArea
.left
+ ProcessParams
->StartingX
;
1919 Pos
.y
= WorkArea
.top
+ ProcessParams
->StartingY
;
1928 According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
1929 y is something else. and Quote!
1932 /* Never believe Microsoft's documentation... CreateWindowEx doc says
1933 * that if an overlapped window is created with WS_VISIBLE style bit
1934 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
1935 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
1938 * 1) not only it checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
1939 * 2) it does not ignore the y parameter as the docs claim; instead, it
1940 * uses it as second parameter to ShowWindow() unless y is either
1941 * CW_USEDEFAULT or CW_USEDEFAULT16.
1943 * The fact that we didn't do 2) caused bogus windows pop up when wine
1944 * was running apps that were using this obscure feature. Example -
1945 * calc.exe that comes with Win98 (only Win98, it's different from
1946 * the one that comes with Win95 and NT)
1948 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
1953 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1955 if(!CalculatedDefPosSize
)
1957 IntCalcDefPosSize(ParentWindow
, Window
, &rc
, FALSE
);
1959 if(ProcessParams
->WindowFlags
& STARTF_USESIZE
)
1961 ProcessParams
->WindowFlags
&= ~STARTF_USESIZE
;
1962 Size
.cx
= ProcessParams
->CountX
;
1963 Size
.cy
= ProcessParams
->CountY
;
1967 Size
.cx
= rc
.right
- rc
.left
;
1968 Size
.cy
= rc
.bottom
- rc
.top
;
1971 /* move the window if necessary */
1973 Pos
.x
= max(rc
.left
, 0);
1975 Pos
.y
= max(rc
.top
, 0);
1980 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
1981 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1986 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1993 /* Initialize the window dimensions. */
1994 Wnd
->WindowRect
.left
= Pos
.x
;
1995 Wnd
->WindowRect
.top
= Pos
.y
;
1996 Wnd
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1997 Wnd
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1998 if (0 != (Wnd
->Style
& WS_CHILD
) && ParentWindow
)
2000 RECTL_vOffsetRect(&(Wnd
->WindowRect
), ParentWindow
->Wnd
->ClientRect
.left
,
2001 ParentWindow
->Wnd
->ClientRect
.top
);
2003 Wnd
->ClientRect
= Wnd
->WindowRect
;
2006 * Get the size and position of the window.
2008 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
2010 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2012 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
2013 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
,
2015 if (MaxSize
.x
< Size
.cx
)
2016 Size
.cx
= MaxSize
.x
;
2017 if (MaxSize
.y
< Size
.cy
)
2018 Size
.cy
= MaxSize
.y
;
2019 if (Size
.cx
< MinTrack
.x
)
2020 Size
.cx
= MinTrack
.x
;
2021 if (Size
.cy
< MinTrack
.y
)
2022 Size
.cy
= MinTrack
.y
;
2029 Wnd
->WindowRect
.left
= Pos
.x
;
2030 Wnd
->WindowRect
.top
= Pos
.y
;
2031 Wnd
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
2032 Wnd
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
2033 if (0 != (Wnd
->Style
& WS_CHILD
) && ParentWindow
)
2035 RECTL_vOffsetRect(&(Wnd
->WindowRect
), ParentWindow
->Wnd
->ClientRect
.left
,
2036 ParentWindow
->Wnd
->ClientRect
.top
);
2038 Wnd
->ClientRect
= Wnd
->WindowRect
;
2040 /* FIXME: Initialize the window menu. */
2042 /* Send a NCCREATE message. */
2048 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
2049 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, Size
.cx
, Size
.cy
);
2050 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
2051 Result
= co_IntSendMessage(Window
->hSelf
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
2054 /* FIXME: Cleanup. */
2055 DPRINT1("IntCreateWindowEx(): NCCREATE message failed. No cleanup performed!\n");
2059 /* Calculate the non-client size. */
2060 MaxPos
.x
= Window
->Wnd
->WindowRect
.left
;
2061 MaxPos
.y
= Window
->Wnd
->WindowRect
.top
;
2064 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
2065 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
2066 Result
= co_WinPosGetNonClientSize(Window
,
2067 &Window
->Wnd
->WindowRect
,
2068 &Window
->Wnd
->ClientRect
);
2070 RECTL_vOffsetRect(&Window
->Wnd
->WindowRect
,
2071 MaxPos
.x
- Window
->Wnd
->WindowRect
.left
,
2072 MaxPos
.y
- Window
->Wnd
->WindowRect
.top
);
2075 if (NULL
!= ParentWindow
)
2077 /* link the window into the parent's child list */
2078 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2080 PWINDOW_OBJECT PrevSibling
;
2082 PrevSibling
= ParentWindow
->LastChild
;
2084 /* link window as bottom sibling */
2085 IntLinkWindow(Window
, ParentWindow
, PrevSibling
/*prev sibling*/);
2089 /* link window as top sibling (but after topmost siblings) */
2090 PWINDOW_OBJECT InsertAfter
, Sibling
;
2091 if (!(dwExStyle
& WS_EX_TOPMOST
))
2094 Sibling
= ParentWindow
->FirstChild
;
2095 while (Sibling
&& (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
2097 InsertAfter
= Sibling
;
2098 Sibling
= Sibling
->NextSibling
;
2106 IntLinkWindow(Window
, ParentWindow
, InsertAfter
/* prev sibling */);
2111 /* Send the WM_CREATE message. */
2112 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
2113 Result
= co_IntSendMessage(Window
->hSelf
, WM_CREATE
, 0, (LPARAM
) &Cs
);
2115 if (Result
== (LRESULT
)-1)
2117 /* FIXME: Cleanup. */
2118 DPRINT1("IntCreateWindowEx(): send CREATE message failed. No cleanup performed!\n");
2119 IntUnlinkWindow(Window
);
2123 Result
= IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, 0);
2125 if (Result
== (LRESULT
)-1)
2127 /* FIXME: Cleanup. */
2128 DPRINT1("IntCreateWindowEx(): event CREATE hook failed. No cleanup performed!\n");
2129 IntUnlinkWindow(Window
);
2133 /* Send move and size messages. */
2134 if (!(Window
->Flags
& WINDOWOBJECT_NEED_SIZE
))
2138 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
2140 if ((Window
->Wnd
->ClientRect
.right
- Window
->Wnd
->ClientRect
.left
) < 0 ||
2141 (Window
->Wnd
->ClientRect
.bottom
- Window
->Wnd
->ClientRect
.top
) < 0)
2143 DPRINT("Sending bogus WM_SIZE\n");
2146 lParam
= MAKE_LONG(Window
->Wnd
->ClientRect
.right
-
2147 Window
->Wnd
->ClientRect
.left
,
2148 Window
->Wnd
->ClientRect
.bottom
-
2149 Window
->Wnd
->ClientRect
.top
);
2150 co_IntSendMessage(Window
->hSelf
, WM_SIZE
, SIZE_RESTORED
,
2153 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
2155 if (0 != (Wnd
->Style
& WS_CHILD
) && ParentWindow
)
2157 lParam
= MAKE_LONG(Wnd
->ClientRect
.left
- ParentWindow
->Wnd
->ClientRect
.left
,
2158 Wnd
->ClientRect
.top
- ParentWindow
->Wnd
->ClientRect
.top
);
2162 lParam
= MAKE_LONG(Wnd
->ClientRect
.left
,
2163 Wnd
->ClientRect
.top
);
2166 co_IntSendMessage(Window
->hSelf
, WM_MOVE
, 0, lParam
);
2168 /* Call WNDOBJ change procs */
2169 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
2172 /* Show or maybe minimize or maximize the window. */
2173 if (Wnd
->Style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2178 SwFlag
= (Wnd
->Style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
2181 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2183 SwFlag
= ((Wnd
->Style
& WS_CHILD
) || UserGetActiveWindow()) ?
2184 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2185 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2187 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
2188 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
2189 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2190 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2193 /* Notify the parent window of a new child. */
2194 if ((Wnd
->Style
& WS_CHILD
) &&
2195 (!(Wnd
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
2197 DPRINT("IntCreateWindow(): About to notify parent\n");
2198 co_IntSendMessage(ParentWindow
->hSelf
,
2200 MAKEWPARAM(WM_CREATE
, Wnd
->IDMenu
),
2201 (LPARAM
)Window
->hSelf
);
2204 if ((!hWndParent
) && (!HasOwner
))
2206 DPRINT("Sending CREATED notify\n");
2207 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2211 DPRINT("Not sending CREATED notify, %x %d\n", ParentWindow
, HasOwner
);
2214 /* Initialize and show the window's scrollbars */
2215 if (Wnd
->Style
& WS_VSCROLL
)
2217 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2219 if (Wnd
->Style
& WS_HSCROLL
)
2221 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2224 if (dwStyle
& WS_VISIBLE
)
2226 if (Wnd
->Style
& WS_MAXIMIZE
)
2227 dwShowMode
= SW_SHOW
;
2228 else if (Wnd
->Style
& WS_MINIMIZE
)
2229 dwShowMode
= SW_SHOWMINIMIZED
;
2231 DPRINT("IntCreateWindow(): About to show window\n");
2232 co_WinPosShowWindow(Window
, dwShowMode
);
2234 if (Wnd
->ExStyle
& WS_EX_MDICHILD
)
2236 co_IntSendMessage(ParentWindow
->hSelf
, WM_MDIREFRESHMENU
, 0, 0);
2237 /* ShowWindow won't activate child windows */
2238 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2242 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xC007,
2243 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
2244 Dont understand why it does this. */
2245 if (ClassAtom
== 0XC007)
2248 //CallProc = CreateCallProc(NULL, Wnd->WndProc, bUnicodeWindow, Wnd->ti->ppi);
2249 CallProc
= CreateCallProc(NULL
, Wnd
->WndProc
, Wnd
->Unicode
, Wnd
->ti
->ppi
);
2253 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2254 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
2258 UserAddCallProcToClass(Wnd
->Class
, CallProc
);
2259 Wnd
->CallProc
= CallProc
;
2260 Wnd
->IsSystem
= FALSE
;
2264 DPRINT("IntCreateWindow(): = %X\n", hWnd
);
2265 DPRINT("WindowObject->SystemMenu = 0x%x\n", Window
->SystemMenu
);
2269 if (!_ret_
&& Window
&& Window
->Wnd
&& ti
)
2270 UserFreeWindowInfo(ti
, Window
);
2273 UserDerefObjectCo(Window
);
2274 UserDereferenceObject(Window
);
2276 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2277 if (!_ret_
&& ti
!= NULL
)
2281 IntDereferenceClass(Class
,
2290 NtUserCreateWindowEx(DWORD dwExStyle
,
2291 PUNICODE_STRING UnsafeClassName
,
2292 PUNICODE_STRING UnsafeWindowName
,
2300 HINSTANCE hInstance
,
2303 BOOL bUnicodeWindow
,
2307 UNICODE_STRING WindowName
;
2308 UNICODE_STRING ClassName
;
2310 DECLARE_RETURN(HWND
);
2312 DPRINT("Enter NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2313 UserEnterExclusive();
2315 /* Get the class name (string or atom) */
2316 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
2317 if (! NT_SUCCESS(Status
))
2319 SetLastNtError(Status
);
2322 if (ClassName
.Length
!= 0)
2324 Status
= IntSafeCopyUnicodeStringTerminateNULL(&ClassName
, UnsafeClassName
);
2325 if (! NT_SUCCESS(Status
))
2327 SetLastNtError(Status
);
2331 else if (! IS_ATOM(ClassName
.Buffer
))
2333 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2337 /* safely copy the window name */
2338 if (NULL
!= UnsafeWindowName
)
2340 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
2341 if (! NT_SUCCESS(Status
))
2343 if (! IS_ATOM(ClassName
.Buffer
))
2345 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2347 SetLastNtError(Status
);
2353 RtlInitUnicodeString(&WindowName
, NULL
);
2356 NewWindow
= co_IntCreateWindowEx(dwExStyle
, &ClassName
, &WindowName
, dwStyle
, x
, y
, nWidth
, nHeight
,
2357 hWndParent
, hMenu
, hInstance
, lpParam
, dwShowMode
, bUnicodeWindow
);
2359 if (WindowName
.Buffer
)
2361 ExFreePoolWithTag(WindowName
.Buffer
, TAG_STRING
);
2363 if (! IS_ATOM(ClassName
.Buffer
))
2365 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2371 DPRINT("Leave NtUserCreateWindowEx, ret=%i\n",_ret_
);
2380 NtUserDeferWindowPos(HDWP WinPosInfo
,
2382 HWND WndInsertAfter
,
2395 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2400 ASSERT_REFS_CO(Window
); //fixme: temp hack?
2404 /* Check for owner thread */
2405 if ((Window
->OwnerThread
!= PsGetCurrentThread()))
2407 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2411 /* Look whether the focus is within the tree of windows we will
2414 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2416 if (UserGetActiveWindow() == Window
->hSelf
)
2418 co_WinPosActivateOtherWindow(Window
);
2422 if (Window
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2423 Window
->MessageQueue
->ActiveWindow
= NULL
;
2424 if (Window
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2425 Window
->MessageQueue
->FocusWindow
= NULL
;
2426 if (Window
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2427 Window
->MessageQueue
->CaptureWindow
= NULL
;
2429 IntDereferenceMessageQueue(Window
->MessageQueue
);
2433 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hwnd
, 0, TRUE
))
2439 IntEngWindowChanged(Window
, WOC_DELETE
);
2440 isChild
= (0 != (Wnd
->Style
& WS_CHILD
));
2446 if (! USER_IsExitingThread(GetCurrentThreadId()))
2448 send_parent_notify(hwnd
, WM_DESTROY
);
2451 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2453 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2454 /* FIXME: clean up palette - see "Internals" p.352 */
2458 if (!IntIsWindow(Window
->hSelf
))
2463 /* Recursively destroy owned windows */
2468 BOOL GotOne
= FALSE
;
2471 PWINDOW_OBJECT Child
, Desktop
;
2473 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2474 UserGetWindowObject(IntGetDesktopWindow());
2475 Children
= IntWinListChildren(Desktop
);
2479 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2481 Child
= UserGetWindowObject(*ChildHandle
);
2484 if (Child
->hOwner
!= Window
->hSelf
)
2489 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2491 USER_REFERENCE_ENTRY ChildRef
;
2492 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2493 co_UserDestroyWindow(Child
);
2494 UserDerefObjectCo(Child
);//temp hack?
2500 if (Child
->hOwner
!= NULL
)
2502 Child
->hOwner
= NULL
;
2503 Child
->Wnd
->Owner
= NULL
;
2507 ExFreePool(Children
);
2516 if (!IntIsWindow(Window
->hSelf
))
2521 /* Destroy the window storage */
2522 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2534 NtUserDestroyWindow(HWND Wnd
)
2536 PWINDOW_OBJECT Window
;
2537 DECLARE_RETURN(BOOLEAN
);
2539 USER_REFERENCE_ENTRY Ref
;
2541 DPRINT("Enter NtUserDestroyWindow\n");
2542 UserEnterExclusive();
2544 if (!(Window
= UserGetWindowObject(Wnd
)))
2549 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2550 ret
= co_UserDestroyWindow(Window
);
2551 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2556 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2568 NtUserDrawMenuBarTemp(
2575 /* we'll use this function just for caching the menu bar */
2585 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2595 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2601 NtUserFillWindow(HWND hWndPaint
,
2612 static HWND FASTCALL
2613 IntFindWindow(PWINDOW_OBJECT Parent
,
2614 PWINDOW_OBJECT ChildAfter
,
2616 PUNICODE_STRING WindowName
)
2618 BOOL CheckWindowName
;
2624 CheckWindowName
= WindowName
->Length
!= 0;
2626 if((List
= IntWinListChildren(Parent
)))
2631 /* skip handles before and including ChildAfter */
2632 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2636 /* search children */
2639 PWINDOW_OBJECT Child
;
2640 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2645 /* Do not send WM_GETTEXT messages in the kernel mode version!
2646 The user mode version however calls GetWindowText() which will
2647 send WM_GETTEXT messages to windows belonging to its processes */
2648 if((!CheckWindowName
|| !RtlCompareUnicodeString(WindowName
, &(Child
->Wnd
->WindowName
), TRUE
)) &&
2649 (!ClassAtom
|| Child
->Wnd
->Class
->Atom
== ClassAtom
))
2664 * Searches a window's children for a window with the specified
2667 * hwndParent = The window whose childs are to be searched.
2669 * HWND_MESSAGE = message-only windows
2671 * hwndChildAfter = Search starts after this child window.
2672 * NULL = start from beginning
2674 * ucClassName = Class name to search for
2675 * Reguired parameter.
2677 * ucWindowName = Window name
2678 * ->Buffer == NULL = don't care
2681 * The HWND of the window if it was found, otherwise NULL
2687 NtUserFindWindowEx(HWND hwndParent
,
2688 HWND hwndChildAfter
,
2689 PUNICODE_STRING ucClassName
,
2690 PUNICODE_STRING ucWindowName
,
2693 PWINDOW_OBJECT Parent
, ChildAfter
;
2694 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2695 HWND Desktop
, Ret
= NULL
;
2696 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2697 DECLARE_RETURN(HWND
);
2699 DPRINT("Enter NtUserFindWindowEx\n");
2702 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2706 if (ucClassName
!= NULL
)
2708 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2709 if (ClassName
.Length
!= 0)
2711 ProbeForRead(ClassName
.Buffer
,
2715 else if (!IS_ATOM(ClassName
.Buffer
))
2717 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2721 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2728 if (ucWindowName
!= NULL
)
2730 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2731 if (WindowName
.Length
!= 0)
2733 ProbeForRead(WindowName
.Buffer
,
2739 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2741 SetLastNtError(_SEH2_GetExceptionCode());
2742 _SEH2_YIELD(RETURN(NULL
));
2746 if (ucClassName
!= NULL
)
2748 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2749 !IS_ATOM(ClassName
.Buffer
))
2751 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2754 else if (ClassAtom
== (RTL_ATOM
)0)
2756 /* LastError code was set by IntGetAtomFromStringOrAtom */
2762 Desktop
= IntGetCurrentThreadDesktopWindow();
2764 if(hwndParent
== NULL
)
2765 hwndParent
= Desktop
;
2767 else if(hwndParent == HWND_MESSAGE)
2769 hwndParent = IntGetMessageWindow();
2773 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2779 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2786 if(Parent
->hSelf
== Desktop
)
2789 PWINDOW_OBJECT TopLevelWindow
;
2790 BOOLEAN CheckWindowName
;
2791 BOOLEAN WindowMatches
;
2792 BOOLEAN ClassMatches
;
2794 /* windows searches through all top-level windows if the parent is the desktop
2797 if((List
= IntWinListChildren(Parent
)))
2803 /* skip handles before and including ChildAfter */
2804 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2808 CheckWindowName
= WindowName
.Length
!= 0;
2810 /* search children */
2813 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2818 /* Do not send WM_GETTEXT messages in the kernel mode version!
2819 The user mode version however calls GetWindowText() which will
2820 send WM_GETTEXT messages to windows belonging to its processes */
2821 WindowMatches
= !CheckWindowName
|| !RtlCompareUnicodeString(
2822 &WindowName
, &TopLevelWindow
->Wnd
->WindowName
, TRUE
);
2823 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2824 ClassAtom
== TopLevelWindow
->Wnd
->Class
->Atom
;
2826 if (WindowMatches
&& ClassMatches
)
2828 Ret
= TopLevelWindow
->hSelf
;
2832 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2834 /* window returns the handle of the top-level window, in case it found
2836 Ret
= TopLevelWindow
->hSelf
;
2845 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2849 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2851 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2852 search the message-only windows. Should this also be done if
2853 Parent is the desktop window??? */
2854 PWINDOW_OBJECT MsgWindows
;
2856 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2858 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2863 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2865 SetLastNtError(_SEH2_GetExceptionCode());
2873 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2883 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
2894 PWINDOW_OBJECT FASTCALL
UserGetAncestor(PWINDOW_OBJECT Wnd
, UINT Type
)
2896 PWINDOW_OBJECT WndAncestor
, Parent
;
2898 if (Wnd
->hSelf
== IntGetDesktopWindow())
2907 WndAncestor
= Wnd
->Parent
;
2918 if(!(Parent
= WndAncestor
->Parent
))
2922 if(IntIsDesktopWindow(Parent
))
2927 WndAncestor
= Parent
;
2938 PWINDOW_OBJECT Parent
, Old
;
2941 Parent
= IntGetParent(WndAncestor
);
2949 // UserDereferenceObject(Parent);
2951 WndAncestor
= Parent
;
2971 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2973 PWINDOW_OBJECT Window
, Ancestor
;
2974 DECLARE_RETURN(HWND
);
2976 DPRINT("Enter NtUserGetAncestor\n");
2977 UserEnterExclusive();
2979 if (!(Window
= UserGetWindowObject(hWnd
)))
2984 Ancestor
= UserGetAncestor(Window
, Type
);
2985 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
2987 RETURN(Ancestor
? Ancestor
->hSelf
: NULL
);
2990 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
2998 NtUserGetComboBoxInfo(
3003 DECLARE_RETURN(BOOL
);
3005 DPRINT("Enter NtUserGetComboBoxInfo\n");
3008 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3017 sizeof(COMBOBOXINFO
),
3021 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3023 SetLastNtError(_SEH2_GetExceptionCode());
3024 _SEH2_YIELD(RETURN(FALSE
));
3028 // Pass the user pointer, it was already probed.
3029 RETURN( (BOOL
) co_IntSendMessage( Wnd
->hSelf
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3032 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3042 NtUserGetInternalWindowPos( HWND hWnd
,
3046 PWINDOW_OBJECT Window
;
3050 WINDOWPLACEMENT wndpl
;
3054 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3065 ProbeForWrite(rectWnd
,
3071 ProbeForWrite(ptIcon
,
3077 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3079 SetLastNtError(_SEH2_GetExceptionCode());
3084 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3086 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3092 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3096 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3100 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3102 SetLastNtError(_SEH2_GetExceptionCode());
3107 if (!Hit
) Ret
= wndpl
.showCmd
;
3116 NtUserGetListBoxInfo(
3120 DECLARE_RETURN(DWORD
);
3122 DPRINT("Enter NtUserGetListBoxInfo\n");
3125 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3130 RETURN( (DWORD
) co_IntSendMessage( Wnd
->hSelf
, LB_GETLISTBOXINFO
, 0, 0 ));
3133 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3140 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3142 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3143 HWND hWndOldParent
= NULL
;
3144 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3146 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3148 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3152 if (hWndChild
== IntGetDesktopWindow())
3154 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3160 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3167 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3173 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3178 UserRefObjectCo(Wnd
, &Ref
);
3179 UserRefObjectCo(WndParent
, &ParentRef
);
3181 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3183 UserDerefObjectCo(WndParent
);
3184 UserDerefObjectCo(Wnd
);
3188 hWndOldParent
= WndOldParent
->hSelf
;
3189 UserDereferenceObject(WndOldParent
);
3192 return( hWndOldParent
);
3200 * The NtUserSetParent function changes the parent window of the specified
3204 * The new parent window and the child window must belong to the same
3205 * application. If the window identified by the hWndChild parameter is
3206 * visible, the system performs the appropriate redrawing and repainting.
3207 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3208 * or WS_POPUP window styles of the window whose parent is being changed.
3215 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3217 DECLARE_RETURN(HWND
);
3219 DPRINT("Enter NtUserSetParent\n");
3220 UserEnterExclusive();
3222 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3225 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3233 * UserGetShellWindow
3235 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3240 HWND FASTCALL
UserGetShellWindow()
3242 PWINSTATION_OBJECT WinStaObject
;
3245 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3250 if (!NT_SUCCESS(Status
))
3252 SetLastNtError(Status
);
3256 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3258 ObDereferenceObject(WinStaObject
);
3263 * NtUserSetShellWindowEx
3265 * This is undocumented function to set global shell window. The global
3266 * shell window has special handling of window position.
3272 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3274 PWINSTATION_OBJECT WinStaObject
;
3275 PWINDOW_OBJECT WndShell
;
3276 DECLARE_RETURN(BOOL
);
3277 USER_REFERENCE_ENTRY Ref
;
3281 DPRINT("Enter NtUserSetShellWindowEx\n");
3282 UserEnterExclusive();
3284 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3289 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3294 if (!NT_SUCCESS(Status
))
3296 SetLastNtError(Status
);
3301 * Test if we are permitted to change the shell window.
3303 if (WinStaObject
->ShellWindow
)
3305 ObDereferenceObject(WinStaObject
);
3310 * Move shell window into background.
3312 if (hwndListView
&& hwndListView
!= hwndShell
)
3315 * Disabled for now to get Explorer working.
3316 * -- Filip, 01/nov/2003
3319 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3322 if (UserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3324 ObDereferenceObject(WinStaObject
);
3329 if (UserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3331 ObDereferenceObject(WinStaObject
);
3335 UserRefObjectCo(WndShell
, &Ref
);
3336 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3338 WinStaObject
->ShellWindow
= hwndShell
;
3339 WinStaObject
->ShellListView
= hwndListView
;
3341 ti
= GetW32ThreadInfo();
3342 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3344 UserDerefObjectCo(WndShell
);
3346 ObDereferenceObject(WinStaObject
);
3350 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3356 * NtUserGetSystemMenu
3358 * The NtUserGetSystemMenu function allows the application to access the
3359 * window menu (also known as the system menu or the control menu) for
3360 * copying and modifying.
3364 * Handle to the window that will own a copy of the window menu.
3366 * Specifies the action to be taken. If this parameter is FALSE,
3367 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3368 * currently in use. The copy is initially identical to the window menu
3369 * but it can be modified.
3370 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3371 * to the default state. The previous window menu, if any, is destroyed.
3374 * If the bRevert parameter is FALSE, the return value is a handle to a
3375 * copy of the window menu. If the bRevert parameter is TRUE, the return
3383 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3385 PWINDOW_OBJECT Window
;
3387 DECLARE_RETURN(HMENU
);
3389 DPRINT("Enter NtUserGetSystemMenu\n");
3392 if (!(Window
= UserGetWindowObject(hWnd
)))
3397 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3402 RETURN(Menu
->MenuInfo
.Self
);
3405 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3411 * NtUserSetSystemMenu
3418 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3420 BOOL Result
= FALSE
;
3421 PWINDOW_OBJECT Window
;
3423 DECLARE_RETURN(BOOL
);
3425 DPRINT("Enter NtUserSetSystemMenu\n");
3426 UserEnterExclusive();
3428 if (!(Window
= UserGetWindowObject(hWnd
)))
3436 * Assign new menu handle.
3438 if (!(Menu
= UserGetMenuObject(hMenu
)))
3443 Result
= IntSetSystemMenu(Window
, Menu
);
3449 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3458 UserGetWindow(HWND hWnd
, UINT Relationship
)
3460 PWINDOW_OBJECT Parent
, Window
;
3461 HWND hWndResult
= NULL
;
3463 if (!(Window
= UserGetWindowObject(hWnd
)))
3466 switch (Relationship
)
3469 if((Parent
= Window
->Parent
))
3471 if (Parent
->FirstChild
)
3472 hWndResult
= Parent
->FirstChild
->hSelf
;
3477 if((Parent
= Window
->Parent
))
3479 if (Parent
->LastChild
)
3480 hWndResult
= Parent
->LastChild
->hSelf
;
3485 if (Window
->NextSibling
)
3486 hWndResult
= Window
->NextSibling
->hSelf
;
3490 if (Window
->PrevSibling
)
3491 hWndResult
= Window
->PrevSibling
->hSelf
;
3495 if((Parent
= UserGetWindowObject(Window
->hOwner
)))
3497 hWndResult
= Parent
->hSelf
;
3501 if (Window
->FirstChild
)
3502 hWndResult
= Window
->FirstChild
->hSelf
;
3514 * The NtUserGetWindow function retrieves a handle to a window that has the
3515 * specified relationship (Z order or owner) to the specified window.
3522 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3524 DECLARE_RETURN(HWND
);
3526 DPRINT("Enter NtUserGetWindow\n");
3529 RETURN(UserGetWindow(hWnd
, Relationship
));
3532 DPRINT("Leave NtUserGetWindow, ret=%i\n",_ret_
);
3541 * NtUserGetWindowLong
3543 * The NtUserGetWindowLong function retrieves information about the specified
3544 * window. The function also retrieves the 32-bit (long) value at the
3545 * specified offset into the extra window memory.
3552 UserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3554 PWINDOW_OBJECT Window
, Parent
;
3558 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3560 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3568 * WndProc is only available to the owner process
3570 if (GWL_WNDPROC
== Index
3571 && Window
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3573 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3577 if ((INT
)Index
>= 0)
3579 if ((Index
+ sizeof(LONG
)) > Window
->Wnd
->ExtraDataSize
)
3581 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3584 Result
= *((LONG
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3591 Result
= Wnd
->ExStyle
;
3595 Result
= Wnd
->Style
;
3599 Result
= (LONG
)IntGetWindowProc(Window
,
3604 Result
= (LONG
) Wnd
->Instance
;
3607 case GWL_HWNDPARENT
:
3608 Parent
= Window
->Parent
;
3611 if (Parent
&& Parent
->hSelf
== IntGetDesktopWindow())
3612 Result
= (LONG
) UserGetWindow(Window
->hSelf
, GW_OWNER
);
3614 Result
= (LONG
) Parent
->hSelf
;
3619 Result
= (LONG
) Wnd
->IDMenu
;
3623 Result
= Wnd
->UserData
;
3627 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3628 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3641 * NtUserGetWindowLong
3643 * The NtUserGetWindowLong function retrieves information about the specified
3644 * window. The function also retrieves the 32-bit (long) value at the
3645 * specified offset into the extra window memory.
3652 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3654 DECLARE_RETURN(LONG
);
3656 DPRINT("Enter NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3657 UserEnterExclusive();
3659 RETURN(UserGetWindowLong(hWnd
, Index
, Ansi
));
3662 DPRINT("Leave NtUserGetWindowLong, ret=%i\n",_ret_
);
3668 IntSetWindowProc(PWINDOW_OBJECT Window
,
3674 PWINDOW Wnd
= Window
->Wnd
;
3676 /* resolve any callproc handle if possible */
3677 if (IsCallProcHandle(NewWndProc
))
3679 WNDPROC_INFO wpInfo
;
3681 if (UserGetCallProcInfo((HANDLE
)NewWndProc
,
3684 NewWndProc
= wpInfo
.WindowProc
;
3685 /* FIXME - what if wpInfo.IsUnicode doesn't match Ansi? */
3689 /* attempt to get the previous window proc */
3692 Ret
= (Ansi
? Wnd
->WndProcExtra
: Wnd
->WndProc
);
3696 if (!Ansi
== Wnd
->Unicode
)
3702 CallProc
= UserFindCallProc(Wnd
->Class
,
3705 if (CallProc
== NULL
)
3707 CallProc
= CreateCallProc(NULL
,
3711 if (CallProc
== NULL
)
3713 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3717 UserAddCallProcToClass(Wnd
->Class
,
3720 /* BugBoy Comments: Added this if else, see below comments */
3727 Ret
= GetCallProcHandle(Wnd
->CallProc
);
3730 Wnd
->CallProc
= CallProc
;
3732 /* BugBoy Comments: Above sets the current CallProc for the
3733 window and below we set the Ret value to it.
3734 SetWindowLong for WNDPROC should return the previous proc
3735 Ret = GetCallProcHandle(Wnd->CallProc); */
3739 if (Wnd
->Class
->System
)
3741 /* check if the new procedure matches with the one in the
3742 window class. If so, we need to restore both procedures! */
3743 Wnd
->IsSystem
= (NewWndProc
== Wnd
->Class
->WndProc
||
3744 NewWndProc
== Wnd
->Class
->WndProcExtra
);
3748 Wnd
->WndProc
= Wnd
->Class
->WndProc
;
3749 Wnd
->WndProcExtra
= Wnd
->Class
->WndProcExtra
;
3750 Wnd
->Unicode
= !Ansi
;
3755 ASSERT(!Wnd
->IsSystem
);
3757 /* update the window procedure */
3758 Wnd
->WndProc
= NewWndProc
;
3759 Wnd
->Unicode
= !Ansi
;
3766 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3768 PWINDOW_OBJECT Window
, Parent
;
3770 PWINSTATION_OBJECT WindowStation
;
3774 if (hWnd
== IntGetDesktopWindow())
3776 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3780 if (!(Window
= UserGetWindowObject(hWnd
)))
3787 if (!Wnd
) return 0; // No go on zero.
3789 if ((INT
)Index
>= 0)
3791 if ((Index
+ sizeof(LONG
)) > Wnd
->ExtraDataSize
)
3793 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3796 OldValue
= *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
));
3797 *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
)) = NewValue
;
3804 OldValue
= (LONG
) Wnd
->ExStyle
;
3805 Style
.styleOld
= OldValue
;
3806 Style
.styleNew
= NewValue
;
3809 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3811 WindowStation
= ((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
->WindowStation
;
3814 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3815 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3818 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3819 Wnd
->ExStyle
= (DWORD
)Style
.styleNew
;
3820 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3824 OldValue
= (LONG
) Wnd
->Style
;
3825 Style
.styleOld
= OldValue
;
3826 Style
.styleNew
= NewValue
;
3827 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3828 Wnd
->Style
= (DWORD
)Style
.styleNew
;
3829 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3834 /* FIXME: should check if window belongs to current process */
3835 OldValue
= (LONG
)IntSetWindowProc(Window
,
3842 OldValue
= (LONG
) Wnd
->Instance
;
3843 Wnd
->Instance
= (HINSTANCE
) NewValue
;
3846 case GWL_HWNDPARENT
:
3847 Parent
= Window
->Parent
;
3848 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
3849 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
3851 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
3855 OldValue
= (LONG
) Wnd
->IDMenu
;
3856 Wnd
->IDMenu
= (UINT
) NewValue
;
3860 OldValue
= Wnd
->UserData
;
3861 Wnd
->UserData
= NewValue
;
3865 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3866 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3878 * NtUserSetWindowLong
3880 * The NtUserSetWindowLong function changes an attribute of the specified
3881 * window. The function also sets the 32-bit (long) value at the specified
3882 * offset into the extra window memory.
3889 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3891 DECLARE_RETURN(LONG
);
3893 DPRINT("Enter NtUserSetWindowLong\n");
3894 UserEnterExclusive();
3896 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3899 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3905 * NtUserSetWindowWord
3907 * Legacy function similar to NtUserSetWindowLong.
3914 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3916 PWINDOW_OBJECT Window
;
3918 DECLARE_RETURN(WORD
);
3920 DPRINT("Enter NtUserSetWindowWord\n");
3921 UserEnterExclusive();
3923 if (!(Window
= UserGetWindowObject(hWnd
)))
3932 case GWL_HWNDPARENT
:
3933 RETURN( co_UserSetWindowLong(Window
->hSelf
, Index
, (UINT
)NewValue
, TRUE
));
3937 SetLastWin32Error(ERROR_INVALID_INDEX
);
3942 if (Index
> Window
->Wnd
->ExtraDataSize
- sizeof(WORD
))
3944 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3948 OldValue
= *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3949 *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
)) = NewValue
;
3954 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3963 NtUserGetWindowPlacement(HWND hWnd
,
3964 WINDOWPLACEMENT
*lpwndpl
)
3966 PWINDOW_OBJECT Window
;
3969 WINDOWPLACEMENT Safepl
;
3971 DECLARE_RETURN(BOOL
);
3973 DPRINT("Enter NtUserGetWindowPlacement\n");
3976 if (!(Window
= UserGetWindowObject(hWnd
)))
3982 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3983 if(!NT_SUCCESS(Status
))
3985 SetLastNtError(Status
);
3988 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3994 if (0 == (Wnd
->Style
& WS_VISIBLE
))
3996 Safepl
.showCmd
= SW_HIDE
;
3998 else if (0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
3999 0 != (Wnd
->Style
& WS_MAXIMIZE
))
4001 Safepl
.showCmd
= SW_MAXIMIZE
;
4003 else if (0 != (Wnd
->Style
& WS_MINIMIZE
))
4005 Safepl
.showCmd
= SW_MINIMIZE
;
4007 else if (0 != (Wnd
->Style
& WS_VISIBLE
))
4009 Safepl
.showCmd
= SW_SHOWNORMAL
;
4012 Size
.x
= Wnd
->WindowRect
.left
;
4013 Size
.y
= Wnd
->WindowRect
.top
;
4014 WinPosInitInternalPos(Window
, &Size
,
4017 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
4018 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
4019 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
4021 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
4022 if(!NT_SUCCESS(Status
))
4024 SetLastNtError(Status
);
4031 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
4041 NtUserLockWindowUpdate(HWND hWnd
)
4061 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
4062 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
4063 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
4067 QueryWindow based on KJK::Hyperion and James Tabor.
4069 0 = QWUniqueProcessId
4070 1 = QWUniqueThreadId
4073 4 = QWIsHung Implements IsHungAppWindow found
4076 9 = QWKillWindow When I called this with hWnd ==
4077 DesktopWindow, it shutdown the system
4084 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
4086 PWINDOW_OBJECT Window
;
4088 DECLARE_RETURN(UINT
);
4090 DPRINT("Enter NtUserQueryWindow\n");
4093 if (!(Window
= UserGetWindowObject(hWnd
)))
4100 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
4101 Result
= (DWORD
)IntGetWndProcessId(Window
);
4104 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
4105 Result
= (DWORD
)IntGetWndThreadId(Window
);
4108 case QUERY_WINDOW_ACTIVE
:
4109 Result
= (DWORD
)UserGetActiveWindow();
4112 case QUERY_WINDOW_FOCUS
:
4113 Result
= (DWORD
)IntGetFocusWindow();
4116 case QUERY_WINDOW_ISHUNG
:
4117 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
4121 Result
= (DWORD
)NULL
;
4128 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
4138 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
4152 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4154 UNICODE_STRING SafeMessageName
;
4157 DECLARE_RETURN(UINT
);
4159 DPRINT("Enter NtUserRegisterWindowMessage\n");
4160 UserEnterExclusive();
4162 if(MessageNameUnsafe
== NULL
)
4164 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4168 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4169 if(!NT_SUCCESS(Status
))
4171 SetLastNtError(Status
);
4175 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4177 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4181 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
4191 NtUserSetImeOwnerWindow(DWORD Unknown0
,
4204 NtUserSetInternalWindowPos(
4221 NtUserSetLayeredWindowAttributes(HWND hwnd
,
4235 NtUserSetLogonNotifyWindow(HWND hWnd
)
4252 PWINDOW_OBJECT Window
;
4254 DECLARE_RETURN(BOOL
);
4256 DPRINT("Enter NtUserSetMenu\n");
4257 UserEnterExclusive();
4259 if (!(Window
= UserGetWindowObject(hWnd
)))
4264 if (! IntSetMenu(Window
, Menu
, &Changed
))
4269 if (Changed
&& Repaint
)
4271 USER_REFERENCE_ENTRY Ref
;
4273 UserRefObjectCo(Window
, &Ref
);
4274 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4275 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4277 UserDerefObjectCo(Window
);
4283 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4293 NtUserSetWindowFNID(HWND hWnd
,
4296 PWINDOW_OBJECT Window
;
4298 DECLARE_RETURN(BOOL
);
4300 DPRINT("Enter NtUserSetWindowFNID\n");
4301 UserEnterExclusive();
4303 if (!(Window
= UserGetWindowObject(hWnd
)))
4310 { // From user land we only set these.
4311 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
4316 Wnd
->Class
->fnID
|= fnID
;
4321 DPRINT("Leave NtUserSetWindowFNID\n");
4331 NtUserSetWindowPlacement(HWND hWnd
,
4332 WINDOWPLACEMENT
*lpwndpl
)
4334 PWINDOW_OBJECT Window
;
4336 WINDOWPLACEMENT Safepl
;
4338 DECLARE_RETURN(BOOL
);
4339 USER_REFERENCE_ENTRY Ref
;
4341 DPRINT("Enter NtUserSetWindowPlacement\n");
4342 UserEnterExclusive();
4344 if (!(Window
= UserGetWindowObject(hWnd
)))
4350 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4351 if(!NT_SUCCESS(Status
))
4353 SetLastNtError(Status
);
4356 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4361 UserRefObjectCo(Window
, &Ref
);
4363 if ((Wnd
->Style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4365 co_WinPosSetWindowPos(Window
, NULL
,
4366 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4367 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4368 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4369 SWP_NOZORDER
| SWP_NOACTIVATE
);
4372 /* FIXME - change window status */
4373 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
4375 Wnd
->InternalPosInitialized
= TRUE
;
4376 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4377 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4378 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4380 UserDerefObjectCo(Window
);
4384 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4396 HWND hWndInsertAfter
,
4403 DECLARE_RETURN(BOOL
);
4404 PWINDOW_OBJECT Window
;
4406 USER_REFERENCE_ENTRY Ref
;
4408 DPRINT("Enter NtUserSetWindowPos\n");
4409 UserEnterExclusive();
4411 if (!(Window
= UserGetWindowObject(hWnd
)))
4416 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
4417 if (!(uFlags
& SWP_NOMOVE
))
4419 if (X
< -32768) X
= -32768;
4420 else if (X
> 32767) X
= 32767;
4421 if (Y
< -32768) Y
= -32768;
4422 else if (Y
> 32767) Y
= 32767;
4424 if (!(uFlags
& SWP_NOSIZE
))
4427 else if (cx
> 32767) cx
= 32767;
4429 else if (cy
> 32767) cy
= 32767;
4432 UserRefObjectCo(Window
, &Ref
);
4433 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4434 UserDerefObjectCo(Window
);
4439 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4446 IntGetWindowRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
4464 /* Create a new window region using the window rectangle */
4465 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->WindowRect
);
4466 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->WindowRect
.left
, -Window
->Wnd
->WindowRect
.top
);
4467 /* if there's a region assigned to the window, combine them both */
4468 if(Window
->WindowRegion
&& !(Wnd
->Style
& WS_MINIMIZE
))
4469 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4470 /* Copy the region into hRgn */
4471 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4473 if((pRgn
= REGION_LockRgn(hRgn
)))
4475 Ret
= pRgn
->rdh
.iType
;
4476 REGION_UnlockRgn(pRgn
);
4481 GreDeleteObject(VisRgn
);
4487 IntGetWindowRgnBox(PWINDOW_OBJECT Window
, RECTL
*Rect
)
4505 /* Create a new window region using the window rectangle */
4506 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->WindowRect
);
4507 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->WindowRect
.left
, -Window
->Wnd
->WindowRect
.top
);
4508 /* if there's a region assigned to the window, combine them both */
4509 if(Window
->WindowRegion
&& !(Wnd
->Style
& WS_MINIMIZE
))
4510 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4512 if((pRgn
= REGION_LockRgn(VisRgn
)))
4514 Ret
= pRgn
->rdh
.iType
;
4515 *Rect
= pRgn
->rdh
.rcBound
;
4516 REGION_UnlockRgn(pRgn
);
4521 GreDeleteObject(VisRgn
);
4536 PWINDOW_OBJECT Window
;
4537 DECLARE_RETURN(INT
);
4539 DPRINT("Enter NtUserSetWindowRgn\n");
4540 UserEnterExclusive();
4542 if (!(Window
= UserGetWindowObject(hWnd
)))
4547 /* FIXME - Verify if hRgn is a valid handle!!!!
4548 Propably make this operation thread-safe, but maybe it's not necessary */
4550 if(Window
->WindowRegion
)
4552 /* Delete no longer needed region handle */
4553 GreDeleteObject(Window
->WindowRegion
);
4555 Window
->WindowRegion
= hRgn
;
4557 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4561 USER_REFERENCE_ENTRY Ref
;
4562 UserRefObjectCo(Window
, &Ref
);
4563 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4564 UserDerefObjectCo(Window
);
4570 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4580 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4582 PWINDOW_OBJECT Window
;
4584 DECLARE_RETURN(BOOL
);
4585 USER_REFERENCE_ENTRY Ref
;
4587 DPRINT("Enter NtUserShowWindow\n");
4588 UserEnterExclusive();
4590 if (!(Window
= UserGetWindowObject(hWnd
)))
4595 UserRefObjectCo(Window
, &Ref
);
4596 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4597 UserDerefObjectCo(Window
);
4602 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4612 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4618 return NtUserShowWindow(hWnd
, nCmdShow
);
4628 NtUserUpdateLayeredWindow(
4636 BLENDFUNCTION
*pblend
,
4649 NtUserWindowFromPoint(LONG X
, LONG Y
)
4653 PWINDOW_OBJECT DesktopWindow
= NULL
, Window
= NULL
;
4654 DECLARE_RETURN(HWND
);
4655 USER_REFERENCE_ENTRY Ref
;
4657 DPRINT("Enter NtUserWindowFromPoint\n");
4658 UserEnterExclusive();
4660 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4668 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4669 //its possible this referencing is useless, thou it shouldnt hurt...
4670 UserRefObjectCo(DesktopWindow
, &Ref
);
4672 pti
= PsGetCurrentThreadWin32Thread();
4673 Hit
= co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4677 Ret
= Window
->hSelf
;
4686 if (Window
) UserDereferenceObject(Window
);
4687 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4689 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4699 * Undocumented function that is called from DefWindowProc to set
4706 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4708 PWINDOW_OBJECT Window
;
4710 LARGE_STRING SafeText
;
4711 UNICODE_STRING UnicodeString
;
4714 DPRINT("Enter NtUserDefSetText\n");
4716 if (WindowText
!= NULL
)
4720 SafeText
= ProbeForReadLargeString(WindowText
);
4722 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4725 SetLastNtError(_SEH2_GetExceptionCode());
4735 UserEnterExclusive();
4737 if(!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4744 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4745 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4746 // Now we know what the bAnsi is for.
4747 RtlInitUnicodeString(&UnicodeString
, NULL
);
4748 if (SafeText
.Buffer
)
4753 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4755 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4756 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4758 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4761 SetLastNtError(_SEH2_GetExceptionCode());
4764 if (!Ret
) goto Exit
;
4767 if (UnicodeString
.Length
!= 0)
4769 if (Wnd
->WindowName
.MaximumLength
> 0 &&
4770 UnicodeString
.Length
<= Wnd
->WindowName
.MaximumLength
- sizeof(UNICODE_NULL
))
4772 ASSERT(Wnd
->WindowName
.Buffer
!= NULL
);
4774 Wnd
->WindowName
.Length
= UnicodeString
.Length
;
4775 Wnd
->WindowName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4776 RtlCopyMemory(Wnd
->WindowName
.Buffer
,
4777 UnicodeString
.Buffer
,
4778 UnicodeString
.Length
);
4783 Wnd
->WindowName
.MaximumLength
= Wnd
->WindowName
.Length
= 0;
4784 buf
= Wnd
->WindowName
.Buffer
;
4785 Wnd
->WindowName
.Buffer
= NULL
;
4788 DesktopHeapFree(Wnd
->pdesktop
, buf
);
4791 Wnd
->WindowName
.Buffer
= DesktopHeapAlloc(Wnd
->pdesktop
,
4792 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4793 if (Wnd
->WindowName
.Buffer
!= NULL
)
4795 Wnd
->WindowName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4796 RtlCopyMemory(Wnd
->WindowName
.Buffer
,
4797 UnicodeString
.Buffer
,
4798 UnicodeString
.Length
);
4799 Wnd
->WindowName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4800 Wnd
->WindowName
.Length
= UnicodeString
.Length
;
4804 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4812 Wnd
->WindowName
.Length
= 0;
4813 if (Wnd
->WindowName
.Buffer
!= NULL
)
4814 Wnd
->WindowName
.Buffer
[0] = L
'\0';
4817 // HAX! FIXME! Windows does not do this in here!
4818 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4819 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4820 /* Send shell notifications */
4821 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
4823 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4828 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4829 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4835 * NtUserInternalGetWindowText
4842 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4844 PWINDOW_OBJECT Window
;
4848 DECLARE_RETURN(INT
);
4850 DPRINT("Enter NtUserInternalGetWindowText\n");
4853 if(lpString
&& (nMaxCount
<= 1))
4855 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4859 if(!(Window
= UserGetWindowObject(hWnd
)))
4865 Result
= Wnd
->WindowName
.Length
/ sizeof(WCHAR
);
4868 const WCHAR Terminator
= L
'\0';
4870 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4872 Copy
= min(nMaxCount
- 1, Result
);
4875 Status
= MmCopyToCaller(Buffer
, Wnd
->WindowName
.Buffer
, Copy
* sizeof(WCHAR
));
4876 if(!NT_SUCCESS(Status
))
4878 SetLastNtError(Status
);
4884 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4885 if(!NT_SUCCESS(Status
))
4887 SetLastNtError(Status
);
4897 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4905 IntShowOwnedPopups(PWINDOW_OBJECT OwnerWnd
, BOOL fShow
)
4908 PWINDOW_OBJECT pWnd
;
4911 // ASSERT(OwnerWnd);
4913 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
4918 while (win_array
[count
])
4920 while (--count
>= 0)
4922 if (UserGetWindow( win_array
[count
], GW_OWNER
) != OwnerWnd
->hSelf
)
4924 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4926 // if (pWnd == WND_OTHER_PROCESS) continue;
4930 if (pWnd
->Flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
)
4932 /* In Windows, ShowOwnedPopups(TRUE) generates
4933 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4934 * regardless of the state of the owner
4936 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4942 if (pWnd
->Wnd
->Style
& WS_VISIBLE
)
4944 /* In Windows, ShowOwnedPopups(FALSE) generates
4945 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4946 * regardless of the state of the owner
4948 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4954 ExFreePool( win_array
);
4959 * NtUserValidateHandleSecure
4967 NtUserValidateHandleSecure(
4975 PUSER_HANDLE_ENTRY entry
;
4976 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
4978 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4981 uType
= entry
->type
;
4987 PWINDOW_OBJECT Window
;
4988 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
4994 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
4999 PACCELERATOR_TABLE Accel
;
5000 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
5005 PCURICON_OBJECT Cursor
;
5006 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
5012 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
5017 PMONITOR_OBJECT Monitor
;
5018 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
5024 return UserGetCallProcInfo( handle
, &Proc
);
5027 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5031 { /* Is handle entry restricted? */