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
,
506 if(Window
->WindowRegion
)
508 NtGdiDeleteObject(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
);
575 PCALLPROC NewCallProc
, CallProc
;
577 NewCallProc
= UserFindCallProc(Wnd
->Class
,
580 if (NewCallProc
== NULL
)
582 NewCallProc
= CreateCallProc(Wnd
->ti
->Desktop
,
586 if (NewCallProc
== NULL
)
588 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
592 UserAddCallProcToClass(Wnd
->Class
,
596 CallProc
= Wnd
->CallProc
;
597 Wnd
->CallProc
= NewCallProc
;
599 return GetCallProcHandle((CallProc
== NULL
? NewCallProc
: CallProc
));
606 IntGetWindowInfo(PWINDOW_OBJECT Window
, PWINDOWINFO pwi
)
608 PWINDOW Wnd
= Window
->Wnd
;
610 pwi
->cbSize
= sizeof(WINDOWINFO
);
611 pwi
->rcWindow
= Window
->Wnd
->WindowRect
;
612 pwi
->rcClient
= Window
->Wnd
->ClientRect
;
613 pwi
->dwStyle
= Wnd
->Style
;
614 pwi
->dwExStyle
= Wnd
->ExStyle
;
615 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Window
->hSelf
); /* WS_ACTIVECAPTION */
616 IntGetWindowBorderMeasures(Window
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
617 pwi
->atomWindowType
= (Wnd
->Class
? Wnd
->Class
->Atom
: 0);
618 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
624 PWINDOW_OBJECT Window
,
628 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
629 PWINDOW Wnd
= Window
->Wnd
;
631 if ((Wnd
->Style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
633 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
637 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
645 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
646 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Window
->hSelf
);
655 NewMenu
= IntGetMenuObject(Menu
);
660 IntReleaseMenuObject(OldMenu
);
662 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
665 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
667 /* Can't use the same menu for two windows */
670 IntReleaseMenuObject(OldMenu
);
672 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
678 Wnd
->IDMenu
= (UINT
) Menu
;
681 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
682 IntReleaseMenuObject(NewMenu
);
686 OldMenu
->MenuInfo
.Wnd
= NULL
;
687 IntReleaseMenuObject(OldMenu
);
694 /* INTERNAL ******************************************************************/
698 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
703 USER_REFERENCE_ENTRY Ref
;
704 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
706 while (!IsListEmpty(&WThread
->WindowListHead
))
708 Current
= WThread
->WindowListHead
.Flink
;
709 Wnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
711 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
713 /* window removes itself from the list */
716 fixme: it is critical that the window removes itself! if now, we will loop
720 //ASSERT(co_UserDestroyWindow(Wnd));
722 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
723 if (!co_UserDestroyWindow(Wnd
))
725 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
727 UserDerefObjectCo(Wnd
);//faxme: temp hack??
735 * Returns client window rectangle relative to the upper-left corner of client area.
737 * \note Does not check the validity of the parameters
740 IntGetClientRect(PWINDOW_OBJECT Window
, PRECT Rect
)
745 Rect
->left
= Rect
->top
= 0;
746 Rect
->right
= Window
->Wnd
->ClientRect
.right
- Window
->Wnd
->ClientRect
.left
;
747 Rect
->bottom
= Window
->Wnd
->ClientRect
.bottom
- Window
->Wnd
->ClientRect
.top
;
753 IntGetFocusWindow(VOID
)
755 PUSER_MESSAGE_QUEUE Queue
;
756 PDESKTOP pdo
= IntGetActiveDesktop();
761 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
766 return(Queue
->FocusWindow
);
770 PMENU_OBJECT FASTCALL
771 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
)
773 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
774 PTHREADINFO W32Thread
;
775 HMENU hNewMenu
, hSysMenu
;
776 ROSMENUITEMINFO ItemInfo
;
780 W32Thread
= PsGetCurrentThreadWin32Thread();
782 if(!W32Thread
->Desktop
)
785 if(Window
->SystemMenu
)
787 Menu
= UserGetMenuObject(Window
->SystemMenu
);
790 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
791 Window
->SystemMenu
= (HMENU
)0;
795 if(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
)
797 /* clone system menu */
798 Menu
= UserGetMenuObject(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
);
802 NewMenu
= IntCloneMenu(Menu
);
805 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
806 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
807 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
809 //IntReleaseMenuObject(NewMenu);
814 hSysMenu
= UserCreateMenu(FALSE
);
815 if (NULL
== hSysMenu
)
819 SysMenu
= IntGetMenuObject(hSysMenu
);
822 UserDestroyMenu(hSysMenu
);
825 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
826 SysMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
827 hNewMenu
= co_IntLoadSysMenuTemplate();
830 IntReleaseMenuObject(SysMenu
);
831 UserDestroyMenu(hSysMenu
);
834 Menu
= IntGetMenuObject(hNewMenu
);
837 IntReleaseMenuObject(SysMenu
);
838 UserDestroyMenu(hSysMenu
);
842 NewMenu
= IntCloneMenu(Menu
);
845 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
846 IntReleaseMenuObject(NewMenu
);
847 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
849 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
850 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
851 ItemInfo
.fType
= MF_POPUP
;
852 ItemInfo
.fState
= MFS_ENABLED
;
853 ItemInfo
.dwTypeData
= NULL
;
855 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
856 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
858 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
862 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
871 if(Window
->SystemMenu
)
872 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
880 IntIsChildWindow(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT BaseWindow
)
882 PWINDOW_OBJECT Window
;
889 if (Window
== Parent
)
893 if(!(Wnd
->Style
& WS_CHILD
))
898 Window
= Window
->Parent
;
905 IntIsWindowVisible(PWINDOW_OBJECT BaseWindow
)
907 PWINDOW_OBJECT Window
;
914 if(!(Wnd
->Style
& WS_CHILD
))
918 if(!(Wnd
->Style
& WS_VISIBLE
))
923 Window
= Window
->Parent
;
926 if(Window
&& Wnd
->Style
& WS_VISIBLE
)
935 /* link the window into siblings and parent. children are kept in place. */
939 PWINDOW_OBJECT WndParent
,
940 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
943 PWINDOW_OBJECT Parent
;
945 Wnd
->Parent
= WndParent
;
946 Wnd
->Wnd
->Parent
= WndParent
? WndParent
->Wnd
: NULL
;
947 if ((Wnd
->PrevSibling
= WndPrevSibling
))
949 /* link after WndPrevSibling */
950 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
951 Wnd
->NextSibling
->PrevSibling
= Wnd
;
952 else if ((Parent
= Wnd
->Parent
))
954 if(Parent
->LastChild
== WndPrevSibling
)
955 Parent
->LastChild
= Wnd
;
957 Wnd
->PrevSibling
->NextSibling
= Wnd
;
962 Parent
= Wnd
->Parent
;
963 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
964 Wnd
->NextSibling
->PrevSibling
= Wnd
;
967 Parent
->LastChild
= Wnd
;
968 Parent
->FirstChild
= Wnd
;
973 Parent
->FirstChild
= Wnd
;
980 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
982 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
985 Wnd
= IntGetWindowObject(hWnd
);
989 WndOldOwner
= IntGetWindowObject(Wnd
->hOwner
);
992 ret
= WndOldOwner
->hSelf
;
993 UserDereferenceObject(WndOldOwner
);
1000 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1002 Wnd
->hOwner
= hWndNewOwner
;
1003 Wnd
->Wnd
->Owner
= WndNewOwner
->Wnd
;
1008 Wnd
->Wnd
->Owner
= NULL
;
1011 UserDereferenceObject(Wnd
);
1015 PWINDOW_OBJECT FASTCALL
1016 co_IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
1018 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
1019 // HWND hWnd, hWndNewParent;
1023 ASSERT(WndNewParent
);
1024 ASSERT_REFS_CO(Wnd
);
1025 ASSERT_REFS_CO(WndNewParent
);
1027 // hWnd = Wnd->hSelf;
1028 // hWndNewParent = WndNewParent->hSelf;
1031 * Windows hides the window first, then shows it again
1032 * including the WM_SHOWWINDOW messages and all
1034 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1036 // /* Validate that window and parent still exist */
1037 // if (!IntIsWindow(hWnd) || !IntIsWindow(hWndNewParent))
1040 /* Window must belong to current process */
1041 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
1044 WndOldParent
= Wnd
->Parent
;
1046 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1048 if (WndNewParent
!= WndOldParent
)
1050 IntUnlinkWindow(Wnd
);
1052 if (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1054 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
1055 Sibling
= WndNewParent
->FirstChild
;
1056 while (NULL
!= Sibling
&& 0 != (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1058 InsertAfter
= Sibling
;
1059 Sibling
= Sibling
->NextSibling
;
1062 if (NULL
== InsertAfter
)
1064 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1068 // UserReferenceObject(InsertAfter);
1069 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1070 // UserDereferenceObject(InsertAfter);
1075 * SetParent additionally needs to make hwnd the top window
1076 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1077 * WM_WINDOWPOSCHANGED notification messages.
1079 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1080 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1081 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1084 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1085 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1089 * Validate that the old parent still exist, since it migth have been
1090 * destroyed during the last callbacks to user-mode
1094 // if(!IntIsWindow(WndOldParent->hSelf))
1096 // UserDereferenceObject(WndOldParent);
1100 /* don't dereference the window object here, it must be done by the caller
1101 of IntSetParent() */
1102 // return WndOldParent;
1105 return WndOldParent
;//NULL;
1109 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
1111 PMENU_OBJECT OldMenu
;
1112 if(Window
->SystemMenu
)
1114 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1117 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1118 IntReleaseMenuObject(OldMenu
);
1124 /* FIXME check window style, propably return FALSE ? */
1125 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1126 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1129 Window
->SystemMenu
= (HMENU
)0;
1135 /* unlink the window from siblings and parent. children are kept in place. */
1137 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1139 PWINDOW_OBJECT WndParent
= Wnd
->Parent
;
1141 if (Wnd
->NextSibling
)
1142 Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1143 else if (WndParent
&& WndParent
->LastChild
== Wnd
)
1144 WndParent
->LastChild
= Wnd
->PrevSibling
;
1146 if (Wnd
->PrevSibling
)
1147 Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1148 else if (WndParent
&& WndParent
->FirstChild
== Wnd
)
1149 WndParent
->FirstChild
= Wnd
->NextSibling
;
1151 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1153 Wnd
->Wnd
->Parent
= NULL
;
1159 PWINDOW_OBJECT Window
, Child
;
1161 if(!(Window
= UserGetWindowObject(IntGetDesktopWindow())))
1166 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1168 if(Child
->hOwner
&& Child
->Wnd
->Style
& WS_VISIBLE
)
1171 * The desktop has a popup window if one of them has
1172 * an owner window and is visible
1182 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1184 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1187 /* FUNCTIONS *****************************************************************/
1193 NtUserAlterWindowStyle(DWORD Unknown0
,
1203 * As best as I can figure, this function is used by EnumWindows,
1204 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1206 * It's supposed to build a list of HWNDs to return to the caller.
1207 * We can figure out what kind of list by what parameters are
1215 NtUserBuildHwndList(
1228 return ERROR_INVALID_PARAMETER
;
1230 if (hwndParent
|| !dwThreadId
)
1233 PWINDOW_OBJECT Parent
, Window
;
1237 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1239 return ERROR_INVALID_HANDLE
;
1244 Status
= IntValidateDesktopHandle(hDesktop
,
1248 if(!NT_SUCCESS(Status
))
1250 return ERROR_INVALID_HANDLE
;
1253 hwndParent
= Desktop
->DesktopWindow
;
1260 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1261 (Window
= Parent
->FirstChild
))
1263 BOOL bGoDown
= TRUE
;
1265 Status
= STATUS_SUCCESS
;
1270 if(dwCount
++ < *pBufSize
&& pWnd
)
1274 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1275 *pWnd
= Window
->hSelf
;
1278 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1280 Status
= _SEH2_GetExceptionCode();
1283 if(!NT_SUCCESS(Status
))
1285 SetLastNtError(Status
);
1289 if (Window
->FirstChild
&& bChildren
)
1291 Window
= Window
->FirstChild
;
1296 if (Window
->NextSibling
)
1298 Window
= Window
->NextSibling
;
1302 Window
= Window
->Parent
;
1303 if (Window
== Parent
)
1312 ObDereferenceObject(Desktop
);
1318 PTHREADINFO W32Thread
;
1319 PLIST_ENTRY Current
;
1320 PWINDOW_OBJECT Window
;
1322 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1323 if(!NT_SUCCESS(Status
))
1325 return ERROR_INVALID_PARAMETER
;
1327 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1329 ObDereferenceObject(Thread
);
1330 DPRINT("Thread is not a GUI Thread!\n");
1331 return ERROR_INVALID_PARAMETER
;
1334 Current
= W32Thread
->WindowListHead
.Flink
;
1335 while(Current
!= &(W32Thread
->WindowListHead
))
1337 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1340 if(bChildren
|| Window
->hOwner
!= NULL
)
1342 if(dwCount
< *pBufSize
&& pWnd
)
1344 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1345 if(!NT_SUCCESS(Status
))
1347 SetLastNtError(Status
);
1353 Current
= Current
->Flink
;
1356 ObDereferenceObject(Thread
);
1359 *pBufSize
= dwCount
;
1360 return STATUS_SUCCESS
;
1368 NtUserChildWindowFromPointEx(HWND hwndParent
,
1373 PWINDOW_OBJECT Parent
;
1378 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1386 if(Parent
->hSelf
!= IntGetDesktopWindow())
1388 Pt
.x
+= Parent
->Wnd
->ClientRect
.left
;
1389 Pt
.y
+= Parent
->Wnd
->ClientRect
.top
;
1392 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1397 Ret
= Parent
->hSelf
;
1398 if((List
= IntWinListChildren(Parent
)))
1400 for(phWnd
= List
; *phWnd
; phWnd
++)
1402 PWINDOW_OBJECT Child
;
1404 if((Child
= UserGetWindowObject(*phWnd
)))
1406 ChildWnd
= Child
->Wnd
;
1407 if(!(ChildWnd
->Style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1411 if((ChildWnd
->Style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1415 if((ChildWnd
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1419 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1434 * calculates the default position of a window
1437 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT Window
, RECT
*rc
, BOOL IncPos
)
1444 IntGdiIntersectRect(rc
, rc
, &Parent
->Wnd
->ClientRect
);
1448 Pos
.x
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1449 Pos
.y
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1450 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1451 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1453 /* reset counter and position */
1456 Parent
->TiledCounter
= 0;
1458 Parent
->TiledCounter
++;
1469 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1470 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1474 rc
->right
= rc
->left
+ Sz
.cx
;
1475 rc
->bottom
= rc
->top
+ Sz
.cy
;
1484 co_IntCreateWindowEx(DWORD dwExStyle
,
1485 PUNICODE_STRING ClassName
,
1486 PUNICODE_STRING WindowName
,
1494 HINSTANCE hInstance
,
1497 BOOL bUnicodeWindow
)
1499 PWINSTATION_OBJECT WinSta
;
1501 PWINDOWCLASS
*ClassLink
, Class
= NULL
;
1503 PWINDOW_OBJECT Window
= NULL
;
1504 PWINDOW_OBJECT ParentWindow
= NULL
, OwnerWindow
;
1505 HWND ParentWindowHandle
;
1506 HWND OwnerWindowHandle
;
1507 PMENU_OBJECT SystemMenu
;
1511 PW32THREADINFO ti
= NULL
;
1514 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1520 CBT_CREATEWNDW CbtCreate
;
1523 DECLARE_RETURN(HWND
);
1525 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1528 pti
= PsGetCurrentThreadWin32Thread();
1529 ParentWindowHandle
= pti
->Desktop
->DesktopWindow
;
1530 OwnerWindowHandle
= NULL
;
1532 if (hWndParent
== HWND_MESSAGE
)
1535 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1536 * message window (style: WS_POPUP|WS_DISABLED)
1538 DPRINT1("FIXME - Parent is HWND_MESSAGE\n");
1539 // ParentWindowHandle set already.
1541 else if (hWndParent
)
1543 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1545 PWINDOW_OBJECT Par
= UserGetWindowObject(hWndParent
), Root
;
1546 if (Par
&& (Root
= UserGetAncestor(Par
, GA_ROOT
)))
1547 OwnerWindowHandle
= Root
->hSelf
;
1550 ParentWindowHandle
= hWndParent
;
1552 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1554 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1555 RETURN( (HWND
)0); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1558 // if (NULL != ParentWindowHandle)
1560 ParentWindow
= UserGetWindowObject(ParentWindowHandle
);
1562 if (ParentWindow
) UserRefObjectCo(ParentWindow
, &ParentRef
);
1566 // ParentWindow = NULL;
1569 /* FIXME: parent must belong to the current process */
1571 /* Check the window station. */
1572 ti
= GetW32ThreadInfo();
1573 if (ti
== NULL
|| pti
->Desktop
== NULL
)
1575 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1579 /* Check the class. */
1581 ClassAtom
= IntGetClassAtom(ClassName
,
1587 if (ClassAtom
== (RTL_ATOM
)0)
1589 if (IS_ATOM(ClassName
->Buffer
))
1591 DPRINT1("Class 0x%p not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1595 DPRINT1("Class \"%wZ\" not found\n", ClassName
);
1598 SetLastWin32Error(ERROR_CANNOT_FIND_WND_CLASS
);
1602 Class
= IntReferenceClass(Class
,
1607 DPRINT1("Failed to reference window class!\n");
1611 WinSta
= pti
->Desktop
->WindowStation
;
1613 //FIXME: Reference thread/desktop instead
1614 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1616 /* Create the window object. */
1617 Window
= (PWINDOW_OBJECT
)
1618 UserCreateObject(gHandleTable
, (PHANDLE
)&hWnd
,
1619 otWindow
, sizeof(WINDOW_OBJECT
));
1622 Window
->Wnd
= DesktopHeapAlloc(pti
->Desktop
,
1623 sizeof(WINDOW
) + Class
->WndExtra
);
1626 RtlZeroMemory(Window
->Wnd
,
1627 sizeof(WINDOW
) + Class
->WndExtra
);
1628 Window
->Wnd
->hdr
.Handle
= hWnd
; /* FIXME: Remove hack */
1633 Wnd
->pdesktop
= pti
->Desktop
;
1634 Wnd
->hWndLastActive
= hWnd
;
1637 DPRINT("Created object with handle %X\n", hWnd
);
1641 ObDereferenceObject(WinSta
);
1642 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1646 UserRefObjectCo(Window
, &Ref
);
1648 ObDereferenceObject(WinSta
);
1650 if (NULL
== pti
->Desktop
->DesktopWindow
)
1652 /* If there is no desktop window yet, we must be creating it */
1653 pti
->Desktop
->DesktopWindow
= hWnd
;
1654 pti
->Desktop
->DesktopInfo
->Wnd
= Wnd
;
1658 * Fill out the structure describing it.
1664 Window
->SystemMenu
= (HMENU
)0;
1665 Wnd
->ContextHelpId
= 0;
1667 Wnd
->Instance
= hInstance
;
1668 Window
->hSelf
= hWnd
;
1670 Window
->MessageQueue
= pti
->MessageQueue
;
1671 IntReferenceMessageQueue(Window
->MessageQueue
);
1672 Window
->Parent
= ParentWindow
;
1673 Wnd
->Parent
= ParentWindow
? ParentWindow
->Wnd
: NULL
;
1674 if (Wnd
->Parent
!= NULL
&& hWndParent
!= 0)
1676 Wnd
->HideFocus
= Wnd
->Parent
->HideFocus
;
1677 Wnd
->HideAccel
= Wnd
->Parent
->HideAccel
;
1680 if((OwnerWindow
= UserGetWindowObject(OwnerWindowHandle
)))
1682 Window
->hOwner
= OwnerWindowHandle
;
1683 Wnd
->Owner
= OwnerWindow
->Wnd
;
1688 Window
->hOwner
= NULL
;
1695 Wnd
->IsSystem
= Wnd
->Class
->System
;
1696 if (Wnd
->Class
->System
)
1698 /* NOTE: Always create a unicode window for system classes! */
1699 Wnd
->Unicode
= TRUE
;
1700 Wnd
->WndProc
= Wnd
->Class
->WndProc
;
1701 Wnd
->WndProcExtra
= Wnd
->Class
->WndProcExtra
;
1705 Wnd
->Unicode
= Wnd
->Class
->Unicode
;
1706 Wnd
->WndProc
= Wnd
->Class
->WndProc
;
1707 Wnd
->CallProc
= NULL
;
1710 Window
->OwnerThread
= PsGetCurrentThread();
1711 Window
->FirstChild
= NULL
;
1712 Window
->LastChild
= NULL
;
1713 Window
->PrevSibling
= NULL
;
1714 Window
->NextSibling
= NULL
;
1715 Wnd
->ExtraDataSize
= Wnd
->Class
->WndExtra
;
1717 InitializeListHead(&Wnd
->PropListHead
);
1718 InitializeListHead(&Window
->WndObjListHead
);
1720 if (NULL
!= WindowName
->Buffer
&& WindowName
->Length
> 0)
1722 Wnd
->WindowName
.Buffer
= DesktopHeapAlloc(Wnd
->pdesktop
,
1723 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1724 if (Wnd
->WindowName
.Buffer
== NULL
)
1726 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1730 Wnd
->WindowName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1733 RtlCopyMemory(Wnd
->WindowName
.Buffer
,
1735 WindowName
->Length
);
1736 Wnd
->WindowName
.Length
= WindowName
->Length
;
1738 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1740 WindowName
->Length
= 0;
1741 Wnd
->WindowName
.Buffer
[0] = L
'\0';
1747 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1748 * tested for WS_POPUP
1750 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1751 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1752 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1753 dwExStyle
|= WS_EX_WINDOWEDGE
;
1755 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1757 /* Correct the window style. */
1758 if (!(dwStyle
& WS_CHILD
))
1760 dwStyle
|= WS_CLIPSIBLINGS
;
1761 DPRINT("3: Style is now %lx\n", dwStyle
);
1762 if (!(dwStyle
& WS_POPUP
))
1764 dwStyle
|= WS_CAPTION
;
1765 Window
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1766 DPRINT("4: Style is now %lx\n", dwStyle
);
1770 /* create system menu */
1771 if((dwStyle
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1773 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
1776 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1777 IntReleaseMenuObject(SystemMenu
);
1781 /* Set the window menu */
1782 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1785 IntSetMenu(Window
, hMenu
, &MenuChanged
);
1788 hMenu
= Wnd
->Class
->hMenu
;
1789 if (hMenu
) IntSetMenu(Window
, hMenu
, &MenuChanged
);
1793 Wnd
->IDMenu
= (UINT
) hMenu
;
1795 /* Insert the window into the thread's window list. */
1796 InsertTailList (&pti
->WindowListHead
, &Window
->ThreadListEntry
);
1798 /* Handle "CS_CLASSDC", it is tested first. */
1799 if ((Wnd
->Class
->Style
& CS_CLASSDC
) && !(Wnd
->Class
->Dce
)) // One DCE per class to have CLASS.
1800 Wnd
->Class
->Dce
= DceAllocDCE(Window
, DCE_CLASS_DC
);
1801 /* Allocate a DCE for this window. */
1802 else if ( Wnd
->Class
->Style
& CS_OWNDC
)
1803 Window
->Dce
= DceAllocDCE(Window
, DCE_WINDOW_DC
);
1810 Wnd
->ExStyle
= dwExStyle
;
1811 Wnd
->Style
= dwStyle
& ~WS_VISIBLE
;
1814 Cs
.lpCreateParams
= lpParam
;
1815 Cs
.hInstance
= hInstance
;
1817 Cs
.hwndParent
= hWndParent
; //Pass the original Parent handle!
1822 Cs
.style
= Wnd
->Style
;
1823 Cs
.lpszName
= (LPCWSTR
) WindowName
;
1824 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
1825 Cs
.dwExStyle
= dwExStyle
;
1826 CbtCreate
.lpcs
= &Cs
;
1827 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1828 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) &CbtCreate
))
1830 /* FIXME - Delete window object and remove it from the thread windows list */
1831 /* FIXME - delete allocated DCE */
1832 DPRINT1("CBT-hook returned !0\n");
1833 RETURN( (HWND
) NULL
);
1841 /* default positioning for overlapped windows */
1842 if(!(Wnd
->Style
& (WS_POPUP
| WS_CHILD
)))
1845 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1846 BOOL CalculatedDefPosSize
= FALSE
;
1848 IntGetDesktopWorkArea(((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
, &WorkArea
);
1851 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1853 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1855 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, Window
, &rc
, TRUE
);
1857 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1859 ProcessParams
->WindowFlags
&= ~STARTF_USEPOSITION
;
1860 Pos
.x
= WorkArea
.left
+ ProcessParams
->StartingX
;
1861 Pos
.y
= WorkArea
.top
+ ProcessParams
->StartingY
;
1870 According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
1871 y is something else. and Quote!
1874 /* Never believe Microsoft's documentation... CreateWindowEx doc says
1875 * that if an overlapped window is created with WS_VISIBLE style bit
1876 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
1877 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
1880 * 1) not only it checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
1881 * 2) it does not ignore the y parameter as the docs claim; instead, it
1882 * uses it as second parameter to ShowWindow() unless y is either
1883 * CW_USEDEFAULT or CW_USEDEFAULT16.
1885 * The fact that we didn't do 2) caused bogus windows pop up when wine
1886 * was running apps that were using this obscure feature. Example -
1887 * calc.exe that comes with Win98 (only Win98, it's different from
1888 * the one that comes with Win95 and NT)
1890 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
1895 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1897 if(!CalculatedDefPosSize
)
1899 IntCalcDefPosSize(ParentWindow
, Window
, &rc
, FALSE
);
1901 if(ProcessParams
->WindowFlags
& STARTF_USESIZE
)
1903 ProcessParams
->WindowFlags
&= ~STARTF_USESIZE
;
1904 Size
.cx
= ProcessParams
->CountX
;
1905 Size
.cy
= ProcessParams
->CountY
;
1909 Size
.cx
= rc
.right
- rc
.left
;
1910 Size
.cy
= rc
.bottom
- rc
.top
;
1913 /* move the window if necessary */
1915 Pos
.x
= max(rc
.left
, 0);
1917 Pos
.y
= max(rc
.top
, 0);
1922 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
1923 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1928 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1935 /* Initialize the window dimensions. */
1936 Wnd
->WindowRect
.left
= Pos
.x
;
1937 Wnd
->WindowRect
.top
= Pos
.y
;
1938 Wnd
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1939 Wnd
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1940 if (0 != (Wnd
->Style
& WS_CHILD
) && ParentWindow
)
1942 IntGdiOffsetRect(&(Wnd
->WindowRect
), ParentWindow
->Wnd
->ClientRect
.left
,
1943 ParentWindow
->Wnd
->ClientRect
.top
);
1945 Wnd
->ClientRect
= Wnd
->WindowRect
;
1948 * Get the size and position of the window.
1950 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
1952 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1954 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
1955 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
,
1957 if (MaxSize
.x
< Size
.cx
)
1958 Size
.cx
= MaxSize
.x
;
1959 if (MaxSize
.y
< Size
.cy
)
1960 Size
.cy
= MaxSize
.y
;
1961 if (Size
.cx
< MinTrack
.x
)
1962 Size
.cx
= MinTrack
.x
;
1963 if (Size
.cy
< MinTrack
.y
)
1964 Size
.cy
= MinTrack
.y
;
1971 Wnd
->WindowRect
.left
= Pos
.x
;
1972 Wnd
->WindowRect
.top
= Pos
.y
;
1973 Wnd
->WindowRect
.right
= Pos
.x
+ Size
.cx
;
1974 Wnd
->WindowRect
.bottom
= Pos
.y
+ Size
.cy
;
1975 if (0 != (Wnd
->Style
& WS_CHILD
) && ParentWindow
)
1977 IntGdiOffsetRect(&(Wnd
->WindowRect
), ParentWindow
->Wnd
->ClientRect
.left
,
1978 ParentWindow
->Wnd
->ClientRect
.top
);
1980 Wnd
->ClientRect
= Wnd
->WindowRect
;
1982 /* FIXME: Initialize the window menu. */
1984 /* Send a NCCREATE message. */
1990 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
1991 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, Size
.cx
, Size
.cy
);
1992 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
1993 Result
= co_IntSendMessage(Window
->hSelf
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
1996 /* FIXME: Cleanup. */
1997 DPRINT1("IntCreateWindowEx(): NCCREATE message failed. No cleanup performed!\n");
2001 /* Calculate the non-client size. */
2002 MaxPos
.x
= Window
->Wnd
->WindowRect
.left
;
2003 MaxPos
.y
= Window
->Wnd
->WindowRect
.top
;
2006 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
2007 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
2008 Result
= co_WinPosGetNonClientSize(Window
,
2009 &Window
->Wnd
->WindowRect
,
2010 &Window
->Wnd
->ClientRect
);
2012 IntGdiOffsetRect(&Window
->Wnd
->WindowRect
,
2013 MaxPos
.x
- Window
->Wnd
->WindowRect
.left
,
2014 MaxPos
.y
- Window
->Wnd
->WindowRect
.top
);
2017 if (NULL
!= ParentWindow
)
2019 /* link the window into the parent's child list */
2020 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2022 PWINDOW_OBJECT PrevSibling
;
2024 PrevSibling
= ParentWindow
->LastChild
;
2026 /* link window as bottom sibling */
2027 IntLinkWindow(Window
, ParentWindow
, PrevSibling
/*prev sibling*/);
2031 /* link window as top sibling (but after topmost siblings) */
2032 PWINDOW_OBJECT InsertAfter
, Sibling
;
2033 if (!(dwExStyle
& WS_EX_TOPMOST
))
2036 Sibling
= ParentWindow
->FirstChild
;
2037 while (Sibling
&& (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
2039 InsertAfter
= Sibling
;
2040 Sibling
= Sibling
->NextSibling
;
2048 IntLinkWindow(Window
, ParentWindow
, InsertAfter
/* prev sibling */);
2053 /* Send the WM_CREATE message. */
2054 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
2055 Result
= co_IntSendMessage(Window
->hSelf
, WM_CREATE
, 0, (LPARAM
) &Cs
);
2057 if (Result
== (LRESULT
)-1)
2059 /* FIXME: Cleanup. */
2060 DPRINT1("IntCreateWindowEx(): send CREATE message failed. No cleanup performed!\n");
2061 IntUnlinkWindow(Window
);
2065 Result
= IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, 0);
2067 if (Result
== (LRESULT
)-1)
2069 /* FIXME: Cleanup. */
2070 DPRINT1("IntCreateWindowEx(): event CREATE hook failed. No cleanup performed!\n");
2071 IntUnlinkWindow(Window
);
2075 /* Send move and size messages. */
2076 if (!(Window
->Flags
& WINDOWOBJECT_NEED_SIZE
))
2080 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
2082 if ((Window
->Wnd
->ClientRect
.right
- Window
->Wnd
->ClientRect
.left
) < 0 ||
2083 (Window
->Wnd
->ClientRect
.bottom
- Window
->Wnd
->ClientRect
.top
) < 0)
2085 DPRINT("Sending bogus WM_SIZE\n");
2088 lParam
= MAKE_LONG(Window
->Wnd
->ClientRect
.right
-
2089 Window
->Wnd
->ClientRect
.left
,
2090 Window
->Wnd
->ClientRect
.bottom
-
2091 Window
->Wnd
->ClientRect
.top
);
2092 co_IntSendMessage(Window
->hSelf
, WM_SIZE
, SIZE_RESTORED
,
2095 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
2097 if (0 != (Wnd
->Style
& WS_CHILD
) && ParentWindow
)
2099 lParam
= MAKE_LONG(Wnd
->ClientRect
.left
- ParentWindow
->Wnd
->ClientRect
.left
,
2100 Wnd
->ClientRect
.top
- ParentWindow
->Wnd
->ClientRect
.top
);
2104 lParam
= MAKE_LONG(Wnd
->ClientRect
.left
,
2105 Wnd
->ClientRect
.top
);
2108 co_IntSendMessage(Window
->hSelf
, WM_MOVE
, 0, lParam
);
2110 /* Call WNDOBJ change procs */
2111 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
2114 /* Show or maybe minimize or maximize the window. */
2115 if (Wnd
->Style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2120 SwFlag
= (Wnd
->Style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
2123 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2125 SwFlag
= ((Wnd
->Style
& WS_CHILD
) || UserGetActiveWindow()) ?
2126 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2127 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2129 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
2130 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
2131 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2132 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2135 /* Notify the parent window of a new child. */
2136 if ((Wnd
->Style
& WS_CHILD
) &&
2137 (!(Wnd
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
2139 DPRINT("IntCreateWindow(): About to notify parent\n");
2140 co_IntSendMessage(ParentWindow
->hSelf
,
2142 MAKEWPARAM(WM_CREATE
, Wnd
->IDMenu
),
2143 (LPARAM
)Window
->hSelf
);
2146 if ((!hWndParent
) && (!HasOwner
))
2148 DPRINT("Sending CREATED notify\n");
2149 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2153 DPRINT("Not sending CREATED notify, %x %d\n", ParentWindow
, HasOwner
);
2156 /* Initialize and show the window's scrollbars */
2157 if (Wnd
->Style
& WS_VSCROLL
)
2159 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2161 if (Wnd
->Style
& WS_HSCROLL
)
2163 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2166 if (dwStyle
& WS_VISIBLE
)
2168 if (Wnd
->Style
& WS_MAXIMIZE
)
2169 dwShowMode
= SW_SHOW
;
2170 else if (Wnd
->Style
& WS_MINIMIZE
)
2171 dwShowMode
= SW_SHOWMINIMIZED
;
2173 DPRINT("IntCreateWindow(): About to show window\n");
2174 co_WinPosShowWindow(Window
, dwShowMode
);
2176 if (Wnd
->ExStyle
& WS_EX_MDICHILD
)
2178 co_IntSendMessage(ParentWindow
->hSelf
, WM_MDIREFRESHMENU
, 0, 0);
2179 /* ShowWindow won't activate child windows */
2180 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2184 DPRINT("IntCreateWindow(): = %X\n", hWnd
);
2185 DPRINT("WindowObject->SystemMenu = 0x%x\n", Window
->SystemMenu
);
2189 if (!_ret_
&& Window
&& Window
->Wnd
&& ti
)
2190 UserFreeWindowInfo(ti
, Window
);
2193 UserDerefObjectCo(Window
);
2194 UserDereferenceObject(Window
);
2196 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2197 if (!_ret_
&& ti
!= NULL
)
2201 IntDereferenceClass(Class
,
2210 NtUserCreateWindowEx(DWORD dwExStyle
,
2211 PUNICODE_STRING UnsafeClassName
,
2212 PUNICODE_STRING UnsafeWindowName
,
2220 HINSTANCE hInstance
,
2223 BOOL bUnicodeWindow
,
2227 UNICODE_STRING WindowName
;
2228 UNICODE_STRING ClassName
;
2230 DECLARE_RETURN(HWND
);
2232 DPRINT("Enter NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2233 UserEnterExclusive();
2235 /* Get the class name (string or atom) */
2236 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
2237 if (! NT_SUCCESS(Status
))
2239 SetLastNtError(Status
);
2242 if (ClassName
.Length
!= 0)
2244 Status
= IntSafeCopyUnicodeStringTerminateNULL(&ClassName
, UnsafeClassName
);
2245 if (! NT_SUCCESS(Status
))
2247 SetLastNtError(Status
);
2251 else if (! IS_ATOM(ClassName
.Buffer
))
2253 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2257 /* safely copy the window name */
2258 if (NULL
!= UnsafeWindowName
)
2260 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
2261 if (! NT_SUCCESS(Status
))
2263 if (! IS_ATOM(ClassName
.Buffer
))
2265 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2267 SetLastNtError(Status
);
2273 RtlInitUnicodeString(&WindowName
, NULL
);
2276 NewWindow
= co_IntCreateWindowEx(dwExStyle
, &ClassName
, &WindowName
, dwStyle
, x
, y
, nWidth
, nHeight
,
2277 hWndParent
, hMenu
, hInstance
, lpParam
, dwShowMode
, bUnicodeWindow
);
2279 if (WindowName
.Buffer
)
2281 ExFreePoolWithTag(WindowName
.Buffer
, TAG_STRING
);
2283 if (! IS_ATOM(ClassName
.Buffer
))
2285 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2291 DPRINT("Leave NtUserCreateWindowEx, ret=%i\n",_ret_
);
2300 NtUserDeferWindowPos(HDWP WinPosInfo
,
2302 HWND WndInsertAfter
,
2315 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2320 ASSERT_REFS_CO(Window
); //fixme: temp hack?
2324 /* Check for owner thread */
2325 if ((Window
->OwnerThread
!= PsGetCurrentThread()))
2327 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2331 /* Look whether the focus is within the tree of windows we will
2334 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2336 if (UserGetActiveWindow() == Window
->hSelf
)
2338 co_WinPosActivateOtherWindow(Window
);
2342 if (Window
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2343 Window
->MessageQueue
->ActiveWindow
= NULL
;
2344 if (Window
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2345 Window
->MessageQueue
->FocusWindow
= NULL
;
2346 if (Window
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2347 Window
->MessageQueue
->CaptureWindow
= NULL
;
2349 IntDereferenceMessageQueue(Window
->MessageQueue
);
2353 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hwnd
, 0, TRUE
))
2359 IntEngWindowChanged(Window
, WOC_DELETE
);
2360 isChild
= (0 != (Wnd
->Style
& WS_CHILD
));
2366 if (! USER_IsExitingThread(GetCurrentThreadId()))
2368 send_parent_notify(hwnd
, WM_DESTROY
);
2371 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2373 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2374 /* FIXME: clean up palette - see "Internals" p.352 */
2378 if (!IntIsWindow(Window
->hSelf
))
2383 /* Recursively destroy owned windows */
2388 BOOL GotOne
= FALSE
;
2391 PWINDOW_OBJECT Child
, Desktop
;
2393 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2394 UserGetWindowObject(IntGetDesktopWindow());
2395 Children
= IntWinListChildren(Desktop
);
2399 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2401 Child
= UserGetWindowObject(*ChildHandle
);
2404 if (Child
->hOwner
!= Window
->hSelf
)
2409 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2411 USER_REFERENCE_ENTRY ChildRef
;
2412 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2413 co_UserDestroyWindow(Child
);
2414 UserDerefObjectCo(Child
);//temp hack?
2420 if (Child
->hOwner
!= NULL
)
2422 Child
->hOwner
= NULL
;
2423 Child
->Wnd
->Owner
= NULL
;
2427 ExFreePool(Children
);
2436 if (!IntIsWindow(Window
->hSelf
))
2441 /* Destroy the window storage */
2442 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2454 NtUserDestroyWindow(HWND Wnd
)
2456 PWINDOW_OBJECT Window
;
2457 DECLARE_RETURN(BOOLEAN
);
2459 USER_REFERENCE_ENTRY Ref
;
2461 DPRINT("Enter NtUserDestroyWindow\n");
2462 UserEnterExclusive();
2464 if (!(Window
= UserGetWindowObject(Wnd
)))
2469 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2470 ret
= co_UserDestroyWindow(Window
);
2471 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2476 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2488 NtUserDrawMenuBarTemp(
2495 /* we'll use this function just for caching the menu bar */
2505 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2515 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2521 NtUserFillWindow(HWND hWndPaint
,
2532 static HWND FASTCALL
2533 IntFindWindow(PWINDOW_OBJECT Parent
,
2534 PWINDOW_OBJECT ChildAfter
,
2536 PUNICODE_STRING WindowName
)
2538 BOOL CheckWindowName
;
2544 CheckWindowName
= WindowName
->Length
!= 0;
2546 if((List
= IntWinListChildren(Parent
)))
2551 /* skip handles before and including ChildAfter */
2552 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2556 /* search children */
2559 PWINDOW_OBJECT Child
;
2560 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2565 /* Do not send WM_GETTEXT messages in the kernel mode version!
2566 The user mode version however calls GetWindowText() which will
2567 send WM_GETTEXT messages to windows belonging to its processes */
2568 if((!CheckWindowName
|| !RtlCompareUnicodeString(WindowName
, &(Child
->Wnd
->WindowName
), TRUE
)) &&
2569 (!ClassAtom
|| Child
->Wnd
->Class
->Atom
== ClassAtom
))
2584 * Searches a window's children for a window with the specified
2587 * hwndParent = The window whose childs are to be searched.
2589 * HWND_MESSAGE = message-only windows
2591 * hwndChildAfter = Search starts after this child window.
2592 * NULL = start from beginning
2594 * ucClassName = Class name to search for
2595 * Reguired parameter.
2597 * ucWindowName = Window name
2598 * ->Buffer == NULL = don't care
2601 * The HWND of the window if it was found, otherwise NULL
2607 NtUserFindWindowEx(HWND hwndParent
,
2608 HWND hwndChildAfter
,
2609 PUNICODE_STRING ucClassName
,
2610 PUNICODE_STRING ucWindowName
,
2613 PWINDOW_OBJECT Parent
, ChildAfter
;
2614 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2615 HWND Desktop
, Ret
= NULL
;
2616 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2617 DECLARE_RETURN(HWND
);
2619 DPRINT("Enter NtUserFindWindowEx\n");
2622 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2626 if (ucClassName
!= NULL
)
2628 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2629 if (ClassName
.Length
!= 0)
2631 ProbeForRead(ClassName
.Buffer
,
2635 else if (!IS_ATOM(ClassName
.Buffer
))
2637 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2641 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2648 if (ucWindowName
!= NULL
)
2650 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2651 if (WindowName
.Length
!= 0)
2653 ProbeForRead(WindowName
.Buffer
,
2659 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2661 SetLastNtError(_SEH2_GetExceptionCode());
2662 _SEH2_YIELD(RETURN(NULL
));
2666 if (ucClassName
!= NULL
)
2668 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2669 !IS_ATOM(ClassName
.Buffer
))
2671 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2674 else if (ClassAtom
== (RTL_ATOM
)0)
2676 /* LastError code was set by IntGetAtomFromStringOrAtom */
2682 Desktop
= IntGetCurrentThreadDesktopWindow();
2684 if(hwndParent
== NULL
)
2685 hwndParent
= Desktop
;
2687 else if(hwndParent == HWND_MESSAGE)
2689 hwndParent = IntGetMessageWindow();
2693 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2699 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2706 if(Parent
->hSelf
== Desktop
)
2709 PWINDOW_OBJECT TopLevelWindow
;
2710 BOOLEAN CheckWindowName
;
2711 BOOLEAN WindowMatches
;
2712 BOOLEAN ClassMatches
;
2714 /* windows searches through all top-level windows if the parent is the desktop
2717 if((List
= IntWinListChildren(Parent
)))
2723 /* skip handles before and including ChildAfter */
2724 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2728 CheckWindowName
= WindowName
.Length
!= 0;
2730 /* search children */
2733 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2738 /* Do not send WM_GETTEXT messages in the kernel mode version!
2739 The user mode version however calls GetWindowText() which will
2740 send WM_GETTEXT messages to windows belonging to its processes */
2741 WindowMatches
= !CheckWindowName
|| !RtlCompareUnicodeString(
2742 &WindowName
, &TopLevelWindow
->Wnd
->WindowName
, TRUE
);
2743 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2744 ClassAtom
== TopLevelWindow
->Wnd
->Class
->Atom
;
2746 if (WindowMatches
&& ClassMatches
)
2748 Ret
= TopLevelWindow
->hSelf
;
2752 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2754 /* window returns the handle of the top-level window, in case it found
2756 Ret
= TopLevelWindow
->hSelf
;
2765 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2769 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2771 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2772 search the message-only windows. Should this also be done if
2773 Parent is the desktop window??? */
2774 PWINDOW_OBJECT MsgWindows
;
2776 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2778 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2783 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2785 SetLastNtError(_SEH2_GetExceptionCode());
2793 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2803 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
2814 PWINDOW_OBJECT FASTCALL
UserGetAncestor(PWINDOW_OBJECT Wnd
, UINT Type
)
2816 PWINDOW_OBJECT WndAncestor
, Parent
;
2818 if (Wnd
->hSelf
== IntGetDesktopWindow())
2827 WndAncestor
= Wnd
->Parent
;
2838 if(!(Parent
= WndAncestor
->Parent
))
2842 if(IntIsDesktopWindow(Parent
))
2847 WndAncestor
= Parent
;
2858 PWINDOW_OBJECT Parent
, Old
;
2861 Parent
= IntGetParent(WndAncestor
);
2869 // UserDereferenceObject(Parent);
2871 WndAncestor
= Parent
;
2891 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2893 PWINDOW_OBJECT Window
, Ancestor
;
2894 DECLARE_RETURN(HWND
);
2896 DPRINT("Enter NtUserGetAncestor\n");
2897 UserEnterExclusive();
2899 if (!(Window
= UserGetWindowObject(hWnd
)))
2904 Ancestor
= UserGetAncestor(Window
, Type
);
2905 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
2907 RETURN(Ancestor
? Ancestor
->hSelf
: NULL
);
2910 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
2918 NtUserGetComboBoxInfo(
2923 DECLARE_RETURN(BOOL
);
2925 DPRINT("Enter NtUserGetComboBoxInfo\n");
2928 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2937 sizeof(COMBOBOXINFO
),
2941 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2943 SetLastNtError(_SEH2_GetExceptionCode());
2944 _SEH2_YIELD(RETURN(FALSE
));
2948 // Pass the user pointer, it was already probed.
2949 RETURN( (BOOL
) co_IntSendMessage( Wnd
->hSelf
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
2952 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
2962 NtUserGetInternalWindowPos( HWND hwnd
,
2973 NtUserGetListBoxInfo(
2977 DECLARE_RETURN(DWORD
);
2979 DPRINT("Enter NtUserGetListBoxInfo\n");
2982 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2987 RETURN( (DWORD
) co_IntSendMessage( Wnd
->hSelf
, LB_GETLISTBOXINFO
, 0, 0 ));
2990 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
2997 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2999 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3000 HWND hWndOldParent
= NULL
;
3001 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3003 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3005 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3009 if (hWndChild
== IntGetDesktopWindow())
3011 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3017 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3024 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3030 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3035 UserRefObjectCo(Wnd
, &Ref
);
3036 UserRefObjectCo(WndParent
, &ParentRef
);
3038 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3040 UserDerefObjectCo(WndParent
);
3041 UserDerefObjectCo(Wnd
);
3045 hWndOldParent
= WndOldParent
->hSelf
;
3046 UserDereferenceObject(WndOldParent
);
3049 return( hWndOldParent
);
3057 * The NtUserSetParent function changes the parent window of the specified
3061 * The new parent window and the child window must belong to the same
3062 * application. If the window identified by the hWndChild parameter is
3063 * visible, the system performs the appropriate redrawing and repainting.
3064 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3065 * or WS_POPUP window styles of the window whose parent is being changed.
3072 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3074 DECLARE_RETURN(HWND
);
3076 DPRINT("Enter NtUserSetParent\n");
3077 UserEnterExclusive();
3079 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3082 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3090 * UserGetShellWindow
3092 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3097 HWND FASTCALL
UserGetShellWindow()
3099 PWINSTATION_OBJECT WinStaObject
;
3102 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3107 if (!NT_SUCCESS(Status
))
3109 SetLastNtError(Status
);
3113 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3115 ObDereferenceObject(WinStaObject
);
3120 * NtUserSetShellWindowEx
3122 * This is undocumented function to set global shell window. The global
3123 * shell window has special handling of window position.
3129 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3131 PWINSTATION_OBJECT WinStaObject
;
3132 PWINDOW_OBJECT WndShell
;
3133 DECLARE_RETURN(BOOL
);
3134 USER_REFERENCE_ENTRY Ref
;
3138 DPRINT("Enter NtUserSetShellWindowEx\n");
3139 UserEnterExclusive();
3141 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3146 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3151 if (!NT_SUCCESS(Status
))
3153 SetLastNtError(Status
);
3158 * Test if we are permitted to change the shell window.
3160 if (WinStaObject
->ShellWindow
)
3162 ObDereferenceObject(WinStaObject
);
3167 * Move shell window into background.
3169 if (hwndListView
&& hwndListView
!= hwndShell
)
3172 * Disabled for now to get Explorer working.
3173 * -- Filip, 01/nov/2003
3176 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3179 if (UserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3181 ObDereferenceObject(WinStaObject
);
3186 if (UserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3188 ObDereferenceObject(WinStaObject
);
3192 UserRefObjectCo(WndShell
, &Ref
);
3193 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3195 WinStaObject
->ShellWindow
= hwndShell
;
3196 WinStaObject
->ShellListView
= hwndListView
;
3198 ti
= GetW32ThreadInfo();
3199 if (ti
->Desktop
) ti
->Desktop
->hShellWindow
= hwndShell
;
3201 UserDerefObjectCo(WndShell
);
3203 ObDereferenceObject(WinStaObject
);
3207 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3213 * NtUserGetSystemMenu
3215 * The NtUserGetSystemMenu function allows the application to access the
3216 * window menu (also known as the system menu or the control menu) for
3217 * copying and modifying.
3221 * Handle to the window that will own a copy of the window menu.
3223 * Specifies the action to be taken. If this parameter is FALSE,
3224 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3225 * currently in use. The copy is initially identical to the window menu
3226 * but it can be modified.
3227 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3228 * to the default state. The previous window menu, if any, is destroyed.
3231 * If the bRevert parameter is FALSE, the return value is a handle to a
3232 * copy of the window menu. If the bRevert parameter is TRUE, the return
3240 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3242 PWINDOW_OBJECT Window
;
3244 DECLARE_RETURN(HMENU
);
3246 DPRINT("Enter NtUserGetSystemMenu\n");
3249 if (!(Window
= UserGetWindowObject(hWnd
)))
3254 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3259 RETURN(Menu
->MenuInfo
.Self
);
3262 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3268 * NtUserSetSystemMenu
3275 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3277 BOOL Result
= FALSE
;
3278 PWINDOW_OBJECT Window
;
3280 DECLARE_RETURN(BOOL
);
3282 DPRINT("Enter NtUserSetSystemMenu\n");
3283 UserEnterExclusive();
3285 if (!(Window
= UserGetWindowObject(hWnd
)))
3293 * Assign new menu handle.
3295 if (!(Menu
= UserGetMenuObject(hMenu
)))
3300 Result
= IntSetSystemMenu(Window
, Menu
);
3306 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3315 UserGetWindow(HWND hWnd
, UINT Relationship
)
3317 PWINDOW_OBJECT Parent
, Window
;
3318 HWND hWndResult
= NULL
;
3320 if (!(Window
= UserGetWindowObject(hWnd
)))
3323 switch (Relationship
)
3326 if((Parent
= Window
->Parent
))
3328 if (Parent
->FirstChild
)
3329 hWndResult
= Parent
->FirstChild
->hSelf
;
3334 if((Parent
= Window
->Parent
))
3336 if (Parent
->LastChild
)
3337 hWndResult
= Parent
->LastChild
->hSelf
;
3342 if (Window
->NextSibling
)
3343 hWndResult
= Window
->NextSibling
->hSelf
;
3347 if (Window
->PrevSibling
)
3348 hWndResult
= Window
->PrevSibling
->hSelf
;
3352 if((Parent
= UserGetWindowObject(Window
->hOwner
)))
3354 hWndResult
= Parent
->hSelf
;
3358 if (Window
->FirstChild
)
3359 hWndResult
= Window
->FirstChild
->hSelf
;
3371 * The NtUserGetWindow function retrieves a handle to a window that has the
3372 * specified relationship (Z order or owner) to the specified window.
3379 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3381 DECLARE_RETURN(HWND
);
3383 DPRINT("Enter NtUserGetWindow\n");
3386 RETURN(UserGetWindow(hWnd
, Relationship
));
3389 DPRINT("Leave NtUserGetWindow, ret=%i\n",_ret_
);
3398 * NtUserGetWindowLong
3400 * The NtUserGetWindowLong function retrieves information about the specified
3401 * window. The function also retrieves the 32-bit (long) value at the
3402 * specified offset into the extra window memory.
3409 UserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3411 PWINDOW_OBJECT Window
, Parent
;
3415 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3417 if (!(Window
= UserGetWindowObject(hWnd
)))
3425 * WndProc is only available to the owner process
3427 if (GWL_WNDPROC
== Index
3428 && Window
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3430 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3434 if ((INT
)Index
>= 0)
3436 if ((Index
+ sizeof(LONG
)) > Window
->Wnd
->ExtraDataSize
)
3438 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3441 Result
= *((LONG
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3448 Result
= Wnd
->ExStyle
;
3452 Result
= Wnd
->Style
;
3456 Result
= (LONG
)IntGetWindowProc(Window
,
3461 Result
= (LONG
) Wnd
->Instance
;
3464 case GWL_HWNDPARENT
:
3465 Parent
= Window
->Parent
;
3468 if (Parent
&& Parent
->hSelf
== IntGetDesktopWindow())
3469 Result
= (LONG
) UserGetWindow(Window
->hSelf
, GW_OWNER
);
3471 Result
= (LONG
) Parent
->hSelf
;
3476 Result
= (LONG
) Wnd
->IDMenu
;
3480 Result
= Wnd
->UserData
;
3484 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3485 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3498 * NtUserGetWindowLong
3500 * The NtUserGetWindowLong function retrieves information about the specified
3501 * window. The function also retrieves the 32-bit (long) value at the
3502 * specified offset into the extra window memory.
3509 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3511 DECLARE_RETURN(LONG
);
3513 DPRINT("Enter NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3514 UserEnterExclusive();
3516 RETURN(UserGetWindowLong(hWnd
, Index
, Ansi
));
3519 DPRINT("Leave NtUserGetWindowLong, ret=%i\n",_ret_
);
3525 IntSetWindowProc(PWINDOW_OBJECT Window
,
3531 PWINDOW Wnd
= Window
->Wnd
;
3533 /* resolve any callproc handle if possible */
3534 if (IsCallProcHandle(NewWndProc
))
3536 WNDPROC_INFO wpInfo
;
3538 if (UserGetCallProcInfo((HANDLE
)NewWndProc
,
3541 NewWndProc
= wpInfo
.WindowProc
;
3542 /* FIXME - what if wpInfo.IsUnicode doesn't match Ansi? */
3546 /* attempt to get the previous window proc */
3549 Ret
= (Ansi
? Wnd
->WndProcExtra
: Wnd
->WndProc
);
3553 if (!Ansi
== Wnd
->Unicode
)
3559 CallProc
= UserFindCallProc(Wnd
->Class
,
3562 if (CallProc
== NULL
)
3564 CallProc
= CreateCallProc(NULL
,
3568 if (CallProc
== NULL
)
3570 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3574 UserAddCallProcToClass(Wnd
->Class
,
3578 Wnd
->CallProc
= CallProc
;
3580 Ret
= GetCallProcHandle(Wnd
->CallProc
);
3584 if (Wnd
->Class
->System
)
3586 /* check if the new procedure matches with the one in the
3587 window class. If so, we need to restore both procedures! */
3588 Wnd
->IsSystem
= (NewWndProc
== Wnd
->Class
->WndProc
||
3589 NewWndProc
== Wnd
->Class
->WndProcExtra
);
3593 Wnd
->WndProc
= Wnd
->Class
->WndProc
;
3594 Wnd
->WndProcExtra
= Wnd
->Class
->WndProcExtra
;
3595 Wnd
->Unicode
= !Ansi
;
3600 ASSERT(!Wnd
->IsSystem
);
3602 /* update the window procedure */
3603 Wnd
->WndProc
= NewWndProc
;
3604 Wnd
->Unicode
= !Ansi
;
3611 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3613 PWINDOW_OBJECT Window
, Parent
;
3615 PWINSTATION_OBJECT WindowStation
;
3619 if (hWnd
== IntGetDesktopWindow())
3621 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3625 if (!(Window
= UserGetWindowObject(hWnd
)))
3632 if (!Wnd
) return 0; // No go on zero.
3634 if ((INT
)Index
>= 0)
3636 if ((Index
+ sizeof(LONG
)) > Wnd
->ExtraDataSize
)
3638 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3641 OldValue
= *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
));
3642 *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
)) = NewValue
;
3649 OldValue
= (LONG
) Wnd
->ExStyle
;
3650 Style
.styleOld
= OldValue
;
3651 Style
.styleNew
= NewValue
;
3654 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3656 WindowStation
= ((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
->WindowStation
;
3659 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3660 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3663 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3664 Wnd
->ExStyle
= (DWORD
)Style
.styleNew
;
3665 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3669 OldValue
= (LONG
) Wnd
->Style
;
3670 Style
.styleOld
= OldValue
;
3671 Style
.styleNew
= NewValue
;
3672 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3673 Wnd
->Style
= (DWORD
)Style
.styleNew
;
3674 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3679 /* FIXME: should check if window belongs to current process */
3680 OldValue
= (LONG
)IntSetWindowProc(Window
,
3687 OldValue
= (LONG
) Wnd
->Instance
;
3688 Wnd
->Instance
= (HINSTANCE
) NewValue
;
3691 case GWL_HWNDPARENT
:
3692 Parent
= Window
->Parent
;
3693 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
3694 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
3696 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
3700 OldValue
= (LONG
) Wnd
->IDMenu
;
3701 Wnd
->IDMenu
= (UINT
) NewValue
;
3705 OldValue
= Wnd
->UserData
;
3706 Wnd
->UserData
= NewValue
;
3710 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3711 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3723 * NtUserSetWindowLong
3725 * The NtUserSetWindowLong function changes an attribute of the specified
3726 * window. The function also sets the 32-bit (long) value at the specified
3727 * offset into the extra window memory.
3734 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3736 DECLARE_RETURN(LONG
);
3738 DPRINT("Enter NtUserSetWindowLong\n");
3739 UserEnterExclusive();
3741 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3744 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3750 * NtUserSetWindowWord
3752 * Legacy function similar to NtUserSetWindowLong.
3759 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3761 PWINDOW_OBJECT Window
;
3763 DECLARE_RETURN(WORD
);
3765 DPRINT("Enter NtUserSetWindowWord\n");
3766 UserEnterExclusive();
3768 if (!(Window
= UserGetWindowObject(hWnd
)))
3777 case GWL_HWNDPARENT
:
3778 RETURN( co_UserSetWindowLong(Window
->hSelf
, Index
, (UINT
)NewValue
, TRUE
));
3782 SetLastWin32Error(ERROR_INVALID_INDEX
);
3787 if (Index
> Window
->Wnd
->ExtraDataSize
- sizeof(WORD
))
3789 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3793 OldValue
= *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3794 *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
)) = NewValue
;
3799 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3808 NtUserGetWindowPlacement(HWND hWnd
,
3809 WINDOWPLACEMENT
*lpwndpl
)
3811 PWINDOW_OBJECT Window
;
3814 WINDOWPLACEMENT Safepl
;
3816 DECLARE_RETURN(BOOL
);
3818 DPRINT("Enter NtUserGetWindowPlacement\n");
3821 if (!(Window
= UserGetWindowObject(hWnd
)))
3827 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
3828 if(!NT_SUCCESS(Status
))
3830 SetLastNtError(Status
);
3833 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
3839 if (0 == (Wnd
->Style
& WS_VISIBLE
))
3841 Safepl
.showCmd
= SW_HIDE
;
3843 else if (0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
3844 0 != (Wnd
->Style
& WS_MAXIMIZE
))
3846 Safepl
.showCmd
= SW_MAXIMIZE
;
3848 else if (0 != (Wnd
->Style
& WS_MINIMIZE
))
3850 Safepl
.showCmd
= SW_MINIMIZE
;
3852 else if (0 != (Wnd
->Style
& WS_VISIBLE
))
3854 Safepl
.showCmd
= SW_SHOWNORMAL
;
3857 Size
.x
= Wnd
->WindowRect
.left
;
3858 Size
.y
= Wnd
->WindowRect
.top
;
3859 WinPosInitInternalPos(Window
, &Size
,
3862 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
3863 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
3864 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
3866 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
3867 if(!NT_SUCCESS(Status
))
3869 SetLastNtError(Status
);
3876 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
3886 NtUserLockWindowUpdate(HWND hWnd
)
3906 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
3907 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
3908 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
3912 QueryWindow based on KJK::Hyperion and James Tabor.
3914 0 = QWUniqueProcessId
3915 1 = QWUniqueThreadId
3918 4 = QWIsHung Implements IsHungAppWindow found
3921 9 = QWKillWindow When I called this with hWnd ==
3922 DesktopWindow, it shutdown the system
3929 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3931 PWINDOW_OBJECT Window
;
3933 DECLARE_RETURN(UINT
);
3935 DPRINT("Enter NtUserQueryWindow\n");
3938 if (!(Window
= UserGetWindowObject(hWnd
)))
3945 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3946 Result
= (DWORD
)IntGetWndProcessId(Window
);
3949 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3950 Result
= (DWORD
)IntGetWndThreadId(Window
);
3953 case QUERY_WINDOW_ACTIVE
:
3954 Result
= (DWORD
)UserGetActiveWindow();
3957 case QUERY_WINDOW_FOCUS
:
3958 Result
= (DWORD
)IntGetFocusWindow();
3961 case QUERY_WINDOW_ISHUNG
:
3962 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
3966 Result
= (DWORD
)NULL
;
3973 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3983 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
3997 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3999 UNICODE_STRING SafeMessageName
;
4002 DECLARE_RETURN(UINT
);
4004 DPRINT("Enter NtUserRegisterWindowMessage\n");
4005 UserEnterExclusive();
4007 if(MessageNameUnsafe
== NULL
)
4009 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4013 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4014 if(!NT_SUCCESS(Status
))
4016 SetLastNtError(Status
);
4020 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4022 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4026 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
4036 NtUserSetImeOwnerWindow(DWORD Unknown0
,
4049 NtUserSetInternalWindowPos(
4066 NtUserSetLayeredWindowAttributes(HWND hwnd
,
4080 NtUserSetLogonNotifyWindow(HWND hWnd
)
4097 PWINDOW_OBJECT Window
;
4099 DECLARE_RETURN(BOOL
);
4101 DPRINT("Enter NtUserSetMenu\n");
4102 UserEnterExclusive();
4104 if (!(Window
= UserGetWindowObject(hWnd
)))
4109 if (! IntSetMenu(Window
, Menu
, &Changed
))
4114 if (Changed
&& Repaint
)
4116 USER_REFERENCE_ENTRY Ref
;
4118 UserRefObjectCo(Window
, &Ref
);
4119 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4120 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4122 UserDerefObjectCo(Window
);
4128 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4138 NtUserSetWindowFNID(HWND hWnd
,
4141 PWINDOW_OBJECT Window
;
4143 DECLARE_RETURN(BOOL
);
4145 DPRINT("Enter NtUserSetWindowFNID\n");
4146 UserEnterExclusive();
4148 if (!(Window
= UserGetWindowObject(hWnd
)))
4155 { // From user land we only set these.
4156 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
4161 Wnd
->Class
->fnID
|= fnID
;
4166 DPRINT("Leave NtUserSetWindowFNID\n");
4176 NtUserSetWindowPlacement(HWND hWnd
,
4177 WINDOWPLACEMENT
*lpwndpl
)
4179 PWINDOW_OBJECT Window
;
4181 WINDOWPLACEMENT Safepl
;
4183 DECLARE_RETURN(BOOL
);
4184 USER_REFERENCE_ENTRY Ref
;
4186 DPRINT("Enter NtUserSetWindowPlacement\n");
4187 UserEnterExclusive();
4189 if (!(Window
= UserGetWindowObject(hWnd
)))
4195 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4196 if(!NT_SUCCESS(Status
))
4198 SetLastNtError(Status
);
4201 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4206 UserRefObjectCo(Window
, &Ref
);
4208 if ((Wnd
->Style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4210 co_WinPosSetWindowPos(Window
, NULL
,
4211 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4212 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4213 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4214 SWP_NOZORDER
| SWP_NOACTIVATE
);
4217 /* FIXME - change window status */
4218 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
4220 Wnd
->InternalPosInitialized
= TRUE
;
4221 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4222 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4223 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4225 UserDerefObjectCo(Window
);
4229 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4241 HWND hWndInsertAfter
,
4248 DECLARE_RETURN(BOOL
);
4249 PWINDOW_OBJECT Window
;
4251 USER_REFERENCE_ENTRY Ref
;
4253 DPRINT("Enter NtUserSetWindowPos\n");
4254 UserEnterExclusive();
4256 if (!(Window
= UserGetWindowObject(hWnd
)))
4261 UserRefObjectCo(Window
, &Ref
);
4262 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4263 UserDerefObjectCo(Window
);
4268 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4275 IntGetWindowRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
4293 /* Create a new window region using the window rectangle */
4294 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->WindowRect
);
4295 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->WindowRect
.left
, -Window
->Wnd
->WindowRect
.top
);
4296 /* if there's a region assigned to the window, combine them both */
4297 if(Window
->WindowRegion
&& !(Wnd
->Style
& WS_MINIMIZE
))
4298 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4299 /* Copy the region into hRgn */
4300 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4302 if((pRgn
= REGION_LockRgn(hRgn
)))
4304 Ret
= pRgn
->rdh
.iType
;
4305 REGION_UnlockRgn(pRgn
);
4310 NtGdiDeleteObject(VisRgn
);
4316 IntGetWindowRgnBox(PWINDOW_OBJECT Window
, RECT
*Rect
)
4334 /* Create a new window region using the window rectangle */
4335 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->WindowRect
);
4336 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->WindowRect
.left
, -Window
->Wnd
->WindowRect
.top
);
4337 /* if there's a region assigned to the window, combine them both */
4338 if(Window
->WindowRegion
&& !(Wnd
->Style
& WS_MINIMIZE
))
4339 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4341 if((pRgn
= REGION_LockRgn(VisRgn
)))
4343 Ret
= pRgn
->rdh
.iType
;
4344 *Rect
= pRgn
->rdh
.rcBound
;
4345 REGION_UnlockRgn(pRgn
);
4350 NtGdiDeleteObject(VisRgn
);
4365 PWINDOW_OBJECT Window
;
4366 DECLARE_RETURN(INT
);
4368 DPRINT("Enter NtUserSetWindowRgn\n");
4369 UserEnterExclusive();
4371 if (!(Window
= UserGetWindowObject(hWnd
)))
4376 /* FIXME - Verify if hRgn is a valid handle!!!!
4377 Propably make this operation thread-safe, but maybe it's not necessary */
4379 if(Window
->WindowRegion
)
4381 /* Delete no longer needed region handle */
4382 NtGdiDeleteObject(Window
->WindowRegion
);
4384 Window
->WindowRegion
= hRgn
;
4386 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4390 USER_REFERENCE_ENTRY Ref
;
4391 UserRefObjectCo(Window
, &Ref
);
4392 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4393 UserDerefObjectCo(Window
);
4399 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4409 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4411 PWINDOW_OBJECT Window
;
4413 DECLARE_RETURN(BOOL
);
4414 USER_REFERENCE_ENTRY Ref
;
4416 DPRINT("Enter NtUserShowWindow\n");
4417 UserEnterExclusive();
4419 if (!(Window
= UserGetWindowObject(hWnd
)))
4424 UserRefObjectCo(Window
, &Ref
);
4425 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4426 UserDerefObjectCo(Window
);
4431 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4441 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4447 return NtUserShowWindow(hWnd
, nCmdShow
);
4457 NtUserUpdateLayeredWindow(
4465 BLENDFUNCTION
*pblend
,
4478 NtUserWindowFromPoint(LONG X
, LONG Y
)
4482 PWINDOW_OBJECT DesktopWindow
= NULL
, Window
= NULL
;
4483 DECLARE_RETURN(HWND
);
4484 USER_REFERENCE_ENTRY Ref
;
4486 DPRINT("Enter NtUserWindowFromPoint\n");
4487 UserEnterExclusive();
4489 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4497 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4498 //its possible this referencing is useless, thou it shouldnt hurt...
4499 UserRefObjectCo(DesktopWindow
, &Ref
);
4501 pti
= PsGetCurrentThreadWin32Thread();
4502 Hit
= co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4506 Ret
= Window
->hSelf
;
4515 if (Window
) UserDereferenceObject(Window
);
4516 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4518 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4528 * Undocumented function that is called from DefWindowProc to set
4536 NtUserDefSetText(HWND hWnd
, PUNICODE_STRING WindowText
)
4538 PWINDOW_OBJECT Window
;
4540 UNICODE_STRING SafeText
;
4543 DPRINT("Enter NtUserDefSetText\n");
4545 RtlInitUnicodeString(&SafeText
, NULL
);
4546 if (WindowText
!= NULL
)
4550 SafeText
= ProbeForReadUnicodeString(WindowText
);
4551 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4553 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4556 SetLastNtError(_SEH2_GetExceptionCode());
4564 UserEnterExclusive();
4566 if(!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4573 if (SafeText
.Length
!= 0)
4575 if (Wnd
->WindowName
.MaximumLength
> 0 &&
4576 SafeText
.Length
<= Wnd
->WindowName
.MaximumLength
- sizeof(UNICODE_NULL
))
4578 ASSERT(Wnd
->WindowName
.Buffer
!= NULL
);
4582 Wnd
->WindowName
.Length
= SafeText
.Length
;
4583 Wnd
->WindowName
.Buffer
[SafeText
.Length
/ sizeof(WCHAR
)] = L
'\0';
4584 RtlCopyMemory(Wnd
->WindowName
.Buffer
,
4588 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4591 SetLastNtError(_SEH2_GetExceptionCode());
4598 Wnd
->WindowName
.MaximumLength
= Wnd
->WindowName
.Length
= 0;
4599 buf
= Wnd
->WindowName
.Buffer
;
4600 Wnd
->WindowName
.Buffer
= NULL
;
4603 DesktopHeapFree(Wnd
->pdesktop
, buf
);
4606 Wnd
->WindowName
.Buffer
= DesktopHeapAlloc(Wnd
->pdesktop
,
4607 SafeText
.Length
+ sizeof(UNICODE_NULL
));
4608 if (Wnd
->WindowName
.Buffer
!= NULL
)
4612 Wnd
->WindowName
.Buffer
[SafeText
.Length
/ sizeof(WCHAR
)] = L
'\0';
4613 RtlCopyMemory(Wnd
->WindowName
.Buffer
,
4616 Wnd
->WindowName
.MaximumLength
= SafeText
.Length
+ sizeof(UNICODE_NULL
);
4617 Wnd
->WindowName
.Length
= SafeText
.Length
;
4619 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4621 Wnd
->WindowName
.Buffer
= NULL
;
4622 DesktopHeapFree(Wnd
->pdesktop
, Wnd
->WindowName
.Buffer
);
4624 SetLastNtError(_SEH2_GetExceptionCode());
4630 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4637 Wnd
->WindowName
.Length
= 0;
4638 if (Wnd
->WindowName
.Buffer
!= NULL
)
4639 Wnd
->WindowName
.Buffer
[0] = L
'\0';
4642 // HAX! FIXME! Windows does not do this in here!
4643 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4644 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4645 /* Send shell notifications */
4646 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
4648 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4653 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4659 * NtUserInternalGetWindowText
4666 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4668 PWINDOW_OBJECT Window
;
4672 DECLARE_RETURN(INT
);
4674 DPRINT("Enter NtUserInternalGetWindowText\n");
4677 if(lpString
&& (nMaxCount
<= 1))
4679 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4683 if(!(Window
= UserGetWindowObject(hWnd
)))
4689 Result
= Wnd
->WindowName
.Length
/ sizeof(WCHAR
);
4692 const WCHAR Terminator
= L
'\0';
4694 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4696 Copy
= min(nMaxCount
- 1, Result
);
4699 Status
= MmCopyToCaller(Buffer
, Wnd
->WindowName
.Buffer
, Copy
* sizeof(WCHAR
));
4700 if(!NT_SUCCESS(Status
))
4702 SetLastNtError(Status
);
4708 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4709 if(!NT_SUCCESS(Status
))
4711 SetLastNtError(Status
);
4721 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4729 IntShowOwnedPopups(PWINDOW_OBJECT OwnerWnd
, BOOL fShow
)
4732 PWINDOW_OBJECT pWnd
;
4735 // ASSERT(OwnerWnd);
4737 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
4742 while (win_array
[count
])
4744 while (--count
>= 0)
4746 if (UserGetWindow( win_array
[count
], GW_OWNER
) != OwnerWnd
->hSelf
)
4748 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4750 // if (pWnd == WND_OTHER_PROCESS) continue;
4754 if (pWnd
->Flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
)
4756 /* In Windows, ShowOwnedPopups(TRUE) generates
4757 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4758 * regardless of the state of the owner
4760 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4766 if (pWnd
->Wnd
->Style
& WS_VISIBLE
)
4768 /* In Windows, ShowOwnedPopups(FALSE) generates
4769 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4770 * regardless of the state of the owner
4772 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4778 ExFreePool( win_array
);
4783 * NtUserValidateHandleSecure
4791 NtUserValidateHandleSecure(
4799 PUSER_HANDLE_ENTRY entry
;
4800 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
4802 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4805 uType
= entry
->type
;
4811 PWINDOW_OBJECT Window
;
4812 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
4818 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
4823 PACCELERATOR_TABLE Accel
;
4824 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
4829 PCURICON_OBJECT Cursor
;
4830 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
4836 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
4841 PMONITOR_OBJECT Monitor
;
4842 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
4848 return UserGetCallProcInfo( handle
, &Proc
);
4851 SetLastWin32Error(ERROR_INVALID_HANDLE
);
4855 { /* Is handle entry restricted? */