2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
5 * FILE: subsystems/win32/win32k/ntuser/window.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
11 /* INCLUDES ******************************************************************/
19 /* dialog resources appear to pass this in 16 bits, handle them properly */
20 #define CW_USEDEFAULT16 (0x8000)
22 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
24 /* PRIVATE FUNCTIONS **********************************************************/
29 * Initialize windowing implementation.
35 return STATUS_SUCCESS
;
41 * Cleanup windowing implementation.
45 CleanupWindowImpl(VOID
)
47 return STATUS_SUCCESS
;
50 /* HELPER FUNCTIONS ***********************************************************/
52 BOOL FASTCALL
UserUpdateUiState(PWINDOW Wnd
, WPARAM wParam
)
54 WORD Action
= LOWORD(wParam
);
55 WORD Flags
= HIWORD(wParam
);
57 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
59 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
66 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
70 if (Flags
& UISF_HIDEFOCUS
)
71 Wnd
->HideFocus
= TRUE
;
72 if (Flags
& UISF_HIDEACCEL
)
73 Wnd
->HideAccel
= TRUE
;
77 if (Flags
& UISF_HIDEFOCUS
)
78 Wnd
->HideFocus
= FALSE
;
79 if (Flags
& UISF_HIDEACCEL
)
80 Wnd
->HideAccel
= FALSE
;
87 PWINDOW_OBJECT FASTCALL
IntGetWindowObject(HWND hWnd
)
89 PWINDOW_OBJECT Window
;
91 if (!hWnd
) return NULL
;
93 Window
= UserGetWindowObject(hWnd
);
96 ASSERT(USER_BODY_TO_HEADER(Window
)->RefCount
>= 0);
98 USER_BODY_TO_HEADER(Window
)->RefCount
++;
104 PWINDOW_OBJECT FASTCALL
UserGetWindowObject(HWND hWnd
)
107 PWINDOW_OBJECT Window
;
109 if (PsGetCurrentProcess() != PsInitialSystemProcess
)
111 ti
= GetW32ThreadInfo();
114 SetLastWin32Error(ERROR_ACCESS_DENIED
);
121 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
125 Window
= (PWINDOW_OBJECT
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
126 if (!Window
|| 0 != (Window
->Status
& WINDOWSTATUS_DESTROYED
))
128 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
132 ASSERT(USER_BODY_TO_HEADER(Window
)->RefCount
>= 0);
140 * The function determines whether the specified window handle identifies
141 * an existing window.
145 * Handle to the window to test.
148 * If the window handle identifies an existing window, the return value
149 * is TRUE. If the window handle does not identify an existing window,
150 * the return value is FALSE.
154 IntIsWindow(HWND hWnd
)
156 PWINDOW_OBJECT Window
;
158 if (!(Window
= UserGetWindowObject(hWnd
)))
167 Caller must NOT dereference retval!
168 But if caller want the returned value to persist spanning a co_ call,
169 it must reference the value (because the owner is not garanteed to
170 exist just because the owned window exist)!
172 PWINDOW_OBJECT FASTCALL
173 IntGetParent(PWINDOW_OBJECT Wnd
)
175 if (!Wnd
->Wnd
) return NULL
;
177 if (Wnd
->Wnd
->style
& WS_POPUP
)
179 return UserGetWindowObject(Wnd
->hOwner
);
181 else if (Wnd
->Wnd
->style
& WS_CHILD
)
191 Caller must NOT dereference retval!
192 But if caller want the returned value to persist spanning a co_ call,
193 it must reference the value (because the owner is not garanteed to
194 exist just because the owned window exist)!
196 PWINDOW_OBJECT FASTCALL
197 IntGetOwner(PWINDOW_OBJECT Wnd
)
199 return UserGetWindowObject(Wnd
->hOwner
);
207 * Compile a list of all child window handles from given window.
210 * This function is similar to Wine WIN_ListChildren. The caller
211 * must free the returned list with ExFreePool.
215 IntWinListChildren(PWINDOW_OBJECT Window
)
217 PWINDOW_OBJECT Child
;
219 UINT Index
, NumChildren
= 0;
221 if (!Window
) return NULL
;
223 for (Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
226 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), TAG_WINLIST
);
229 DPRINT1("Failed to allocate memory for children array\n");
230 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
233 for (Child
= Window
->FirstChild
, Index
= 0;
235 Child
= Child
->NextSibling
, ++Index
)
236 List
[Index
] = Child
->hSelf
;
242 /***********************************************************************
245 static void IntSendDestroyMsg(HWND hWnd
)
248 PWINDOW_OBJECT Window
;
253 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
255 if (hWnd
== info
.hwndCaret
)
262 Window
= UserGetWindowObject(hWnd
);
265 // USER_REFERENCE_ENTRY Ref;
266 // UserRefObjectCo(Window, &Ref);
268 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
270 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
273 // UserDerefObjectCo(Window);
276 /* The window could already be destroyed here */
279 * Send the WM_DESTROY to the window.
282 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
285 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
286 * make sure that the window still exists when we come back.
295 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
298 /* start from the end (FIXME: is this needed?) */
299 for (i
= 0; pWndArray
[i
]; i
++)
304 if (IsWindow( pWndArray
[i
] ))
305 WIN_SendDestroyMsg( pWndArray
[i
] );
307 HeapFree(GetProcessHeap(), 0, pWndArray
);
311 DPRINT("destroyed itself while in WM_DESTROY!\n");
317 UserFreeWindowInfo(PW32THREADINFO ti
, PWINDOW_OBJECT WindowObject
)
319 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
320 PWINDOW Wnd
= WindowObject
->Wnd
;
322 if (ClientInfo
->CallbackWnd
.pvWnd
== DesktopHeapAddressToUser(WindowObject
->Wnd
))
324 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
325 ClientInfo
->CallbackWnd
.pvWnd
= NULL
;
328 if (Wnd
->strName
.Buffer
!= NULL
)
330 Wnd
->strName
.Length
= 0;
331 Wnd
->strName
.MaximumLength
= 0;
332 DesktopHeapFree(Wnd
->pdesktop
,
333 Wnd
->strName
.Buffer
);
334 Wnd
->strName
.Buffer
= NULL
;
337 DesktopHeapFree(Wnd
->pdesktop
, Wnd
);
338 WindowObject
->Wnd
= NULL
;
341 /***********************************************************************
344 * Destroy storage associated to a window. "Internals" p.358
346 * This is the "functional" DestroyWindows function ei. all stuff
347 * done in CreateWindow is undone here and not in DestroyWindow:-P
350 static LRESULT
co_UserFreeWindow(PWINDOW_OBJECT Window
,
351 PW32PROCESS ProcessData
,
352 PTHREADINFO ThreadData
,
353 BOOLEAN SendMessages
)
357 PWINDOW_OBJECT Child
;
359 BOOLEAN BelongsToThreadData
;
366 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
368 DPRINT("Tried to call IntDestroyWindow() twice\n");
371 Window
->Status
|= WINDOWSTATUS_DESTROYING
;
372 Wnd
->style
&= ~WS_VISIBLE
;
373 /* remove the window already at this point from the thread window list so we
374 don't get into trouble when destroying the thread windows while we're still
375 in IntDestroyWindow() */
376 RemoveEntryList(&Window
->ThreadListEntry
);
378 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
380 IntDeRegisterShellHookWindow(Window
->hSelf
);
382 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
->hSelf
, OBJID_WINDOW
, 0);
386 /* Send destroy messages */
387 IntSendDestroyMsg(Window
->hSelf
);
390 /* free child windows */
391 Children
= IntWinListChildren(Window
);
394 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
396 if ((Child
= IntGetWindowObject(*ChildHandle
)))
398 if(!IntWndBelongsToThread(Child
, ThreadData
))
400 /* send WM_DESTROY messages to windows not belonging to the same thread */
401 IntSendDestroyMsg(Child
->hSelf
);
404 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
406 UserDereferenceObject(Child
);
409 ExFreePool(Children
);
415 * Clear the update region to make sure no WM_PAINT messages will be
416 * generated for this window while processing the WM_NCDESTROY.
418 co_UserRedrawWindow(Window
, NULL
, 0,
419 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
420 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
421 if(BelongsToThreadData
)
422 co_IntSendMessage(Window
->hSelf
, WM_NCDESTROY
, 0, 0);
424 MsqRemoveTimersWindow(ThreadData
->MessageQueue
, Window
->hSelf
);
426 /* flush the message queue */
427 MsqRemoveWindowMessagesFromQueue(Window
);
429 /* from now on no messages can be sent to this window anymore */
430 Window
->Status
|= WINDOWSTATUS_DESTROYED
;
431 /* don't remove the WINDOWSTATUS_DESTROYING bit */
433 /* reset shell window handles */
434 if(ThreadData
->Desktop
)
436 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellWindow
)
437 ThreadData
->Desktop
->WindowStation
->ShellWindow
= NULL
;
439 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellListView
)
440 ThreadData
->Desktop
->WindowStation
->ShellListView
= NULL
;
443 /* Unregister hot keys */
444 UnregisterWindowHotKeys (Window
);
446 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
450 WinPosCheckInternalPos(Window
->hSelf
);
451 if (Window
->hSelf
== GetCapture())
456 /* free resources associated with the window */
457 TIMER_RemoveWindowTimers(Window
->hSelf
);
460 if (!(Wnd
->style
& WS_CHILD
) && Wnd
->IDMenu
461 && (Menu
= UserGetMenuObject((HMENU
)Wnd
->IDMenu
)))
463 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
467 if(Window
->SystemMenu
468 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
470 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
471 Window
->SystemMenu
= (HMENU
)0;
474 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
477 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
478 CLASS_RemoveWindow(Window
->Class
);
481 IntUnlinkWindow(Window
);
483 UserReferenceObject(Window
);
484 UserDeleteObject(Window
->hSelf
, otWindow
);
486 IntDestroyScrollBars(Window
);
488 /* dereference the class */
489 IntDereferenceClass(Wnd
->pcls
,
490 Window
->ti
->pDeskInfo
,
494 if(Window
->WindowRegion
)
496 GreDeleteObject(Window
->WindowRegion
);
499 ASSERT(Window
->Wnd
!= NULL
);
500 UserFreeWindowInfo(Window
->ti
, Window
);
502 UserDereferenceObject(Window
);
504 IntClipboardFreeWindow(Window
);
510 IntGetWindowBorderMeasures(PWINDOW_OBJECT Window
, UINT
*cx
, UINT
*cy
)
512 PWINDOW Wnd
= Window
->Wnd
;
513 if(HAS_DLGFRAME(Wnd
->style
, Wnd
->ExStyle
) && !(Wnd
->style
& WS_MINIMIZE
))
515 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
516 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
520 if(HAS_THICKFRAME(Wnd
->style
, Wnd
->ExStyle
)&& !(Wnd
->style
& WS_MINIMIZE
))
522 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
523 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
525 else if(HAS_THINFRAME(Wnd
->style
, Wnd
->ExStyle
))
527 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
528 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
538 IntGetWindowProc(IN PWINDOW_OBJECT Window
,
541 PWINDOW Wnd
= Window
->Wnd
;
543 ASSERT(UserIsEnteredExclusive() == TRUE
);
547 return (Ansi
? Wnd
->WndProcExtra
: Wnd
->lpfnWndProc
);
551 if (!Ansi
== Wnd
->Unicode
)
553 return Wnd
->lpfnWndProc
;
557 if (Wnd
->CallProc
!= NULL
)
559 return GetCallProcHandle(Wnd
->CallProc
);
561 /* BUGBOY Comments: Maybe theres something Im not undestanding here, but why would a CallProc be created
562 on a function that I thought is only suppose to return the current Windows Proc? */
565 PCALLPROC NewCallProc
, CallProc
;
567 NewCallProc
= UserFindCallProc(Wnd
->pcls
,
570 if (NewCallProc
== NULL
)
572 NewCallProc
= CreateCallProc(Wnd
->ti
->pDeskInfo
,
576 if (NewCallProc
== NULL
)
578 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
582 UserAddCallProcToClass(Wnd
->pcls
,
586 CallProc
= Wnd
->CallProc
;
587 Wnd
->CallProc
= NewCallProc
;
589 return GetCallProcHandle((CallProc
== NULL
? NewCallProc
: CallProc
));
596 IntGetWindowInfo(PWINDOW_OBJECT Window
, PWINDOWINFO pwi
)
598 PWINDOW Wnd
= Window
->Wnd
;
600 pwi
->cbSize
= sizeof(WINDOWINFO
);
601 pwi
->rcWindow
= Window
->Wnd
->rcWindow
;
602 pwi
->rcClient
= Window
->Wnd
->rcClient
;
603 pwi
->dwStyle
= Wnd
->style
;
604 pwi
->dwExStyle
= Wnd
->ExStyle
;
605 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Window
->hSelf
); /* WS_ACTIVECAPTION */
606 IntGetWindowBorderMeasures(Window
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
607 pwi
->atomWindowType
= (Wnd
->pcls
? Wnd
->pcls
->atomClassName
: 0);
608 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
614 PWINDOW_OBJECT Window
,
618 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
619 PWINDOW Wnd
= Window
->Wnd
;
621 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
623 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
627 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
635 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
636 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Window
->hSelf
);
645 NewMenu
= IntGetMenuObject(Menu
);
650 IntReleaseMenuObject(OldMenu
);
652 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
655 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
657 /* Can't use the same menu for two windows */
660 IntReleaseMenuObject(OldMenu
);
662 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
668 Wnd
->IDMenu
= (UINT
) Menu
;
671 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
672 IntReleaseMenuObject(NewMenu
);
676 OldMenu
->MenuInfo
.Wnd
= NULL
;
677 IntReleaseMenuObject(OldMenu
);
684 /* INTERNAL ******************************************************************/
688 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
693 USER_REFERENCE_ENTRY Ref
;
694 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
696 while (!IsListEmpty(&WThread
->WindowListHead
))
698 Current
= WThread
->WindowListHead
.Flink
;
699 Wnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
701 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
703 /* window removes itself from the list */
706 fixme: it is critical that the window removes itself! if now, we will loop
710 //ASSERT(co_UserDestroyWindow(Wnd));
712 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
713 if (!co_UserDestroyWindow(Wnd
))
715 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
717 UserDerefObjectCo(Wnd
);//faxme: temp hack??
725 * Returns client window rectangle relative to the upper-left corner of client area.
727 * \note Does not check the validity of the parameters
730 IntGetClientRect(PWINDOW_OBJECT Window
, RECTL
*Rect
)
735 Rect
->left
= Rect
->top
= 0;
736 Rect
->right
= Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
;
737 Rect
->bottom
= Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
;
743 IntGetFocusWindow(VOID
)
745 PUSER_MESSAGE_QUEUE Queue
;
746 PDESKTOP pdo
= IntGetActiveDesktop();
751 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
756 return(Queue
->FocusWindow
);
760 PMENU_OBJECT FASTCALL
761 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
)
763 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
764 PTHREADINFO W32Thread
;
765 HMENU hNewMenu
, hSysMenu
;
766 ROSMENUITEMINFO ItemInfo
;
770 W32Thread
= PsGetCurrentThreadWin32Thread();
772 if(!W32Thread
->Desktop
)
775 if(Window
->SystemMenu
)
777 Menu
= UserGetMenuObject(Window
->SystemMenu
);
780 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
781 Window
->SystemMenu
= (HMENU
)0;
785 if(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
)
787 /* clone system menu */
788 Menu
= UserGetMenuObject(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
);
792 NewMenu
= IntCloneMenu(Menu
);
795 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
796 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
797 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
799 //IntReleaseMenuObject(NewMenu);
804 hSysMenu
= UserCreateMenu(FALSE
);
805 if (NULL
== hSysMenu
)
809 SysMenu
= IntGetMenuObject(hSysMenu
);
812 UserDestroyMenu(hSysMenu
);
815 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
816 SysMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
817 hNewMenu
= co_IntLoadSysMenuTemplate();
820 IntReleaseMenuObject(SysMenu
);
821 UserDestroyMenu(hSysMenu
);
824 Menu
= IntGetMenuObject(hNewMenu
);
827 IntReleaseMenuObject(SysMenu
);
828 UserDestroyMenu(hSysMenu
);
832 NewMenu
= IntCloneMenu(Menu
);
835 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
836 IntReleaseMenuObject(NewMenu
);
837 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
839 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
840 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
841 ItemInfo
.fType
= MF_POPUP
;
842 ItemInfo
.fState
= MFS_ENABLED
;
843 ItemInfo
.dwTypeData
= NULL
;
845 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
846 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
848 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
852 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
861 if(Window
->SystemMenu
)
862 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
870 IntIsChildWindow(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT BaseWindow
)
872 PWINDOW_OBJECT Window
;
879 if (Window
== Parent
)
883 if(!(Wnd
->style
& WS_CHILD
))
888 Window
= Window
->Parent
;
895 IntIsWindowVisible(PWINDOW_OBJECT BaseWindow
)
897 PWINDOW_OBJECT Window
;
904 if(!(Wnd
->style
& WS_CHILD
))
908 if(!(Wnd
->style
& WS_VISIBLE
))
913 Window
= Window
->Parent
;
916 if(Window
&& Wnd
->style
& WS_VISIBLE
)
925 /* link the window into siblings and parent. children are kept in place. */
929 PWINDOW_OBJECT WndParent
,
930 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
933 PWINDOW_OBJECT Parent
;
935 Wnd
->Parent
= WndParent
;
936 Wnd
->Wnd
->spwndParent
= WndParent
? WndParent
->Wnd
: NULL
;
937 if ((Wnd
->PrevSibling
= WndPrevSibling
))
939 /* link after WndPrevSibling */
940 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
941 Wnd
->NextSibling
->PrevSibling
= Wnd
;
942 else if ((Parent
= Wnd
->Parent
))
944 if(Parent
->LastChild
== WndPrevSibling
)
945 Parent
->LastChild
= Wnd
;
947 Wnd
->PrevSibling
->NextSibling
= Wnd
;
952 Parent
= Wnd
->Parent
;
953 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
954 Wnd
->NextSibling
->PrevSibling
= Wnd
;
957 Parent
->LastChild
= Wnd
;
958 Parent
->FirstChild
= Wnd
;
963 Parent
->FirstChild
= Wnd
;
970 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
972 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
975 Wnd
= IntGetWindowObject(hWnd
);
979 WndOldOwner
= IntGetWindowObject(Wnd
->hOwner
);
982 ret
= WndOldOwner
->hSelf
;
983 UserDereferenceObject(WndOldOwner
);
990 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
992 Wnd
->hOwner
= hWndNewOwner
;
993 Wnd
->Wnd
->spwndOwner
= WndNewOwner
->Wnd
;
998 Wnd
->Wnd
->spwndOwner
= NULL
;
1001 UserDereferenceObject(Wnd
);
1005 PWINDOW_OBJECT FASTCALL
1006 co_IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
1008 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
1009 // HWND hWnd, hWndNewParent;
1013 ASSERT(WndNewParent
);
1014 ASSERT_REFS_CO(Wnd
);
1015 ASSERT_REFS_CO(WndNewParent
);
1017 // hWnd = Wnd->hSelf;
1018 // hWndNewParent = WndNewParent->hSelf;
1021 * Windows hides the window first, then shows it again
1022 * including the WM_SHOWWINDOW messages and all
1024 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1026 // /* Validate that window and parent still exist */
1027 // if (!IntIsWindow(hWnd) || !IntIsWindow(hWndNewParent))
1030 /* Window must belong to current process */
1031 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
1034 WndOldParent
= Wnd
->Parent
;
1036 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1038 if (WndNewParent
!= WndOldParent
)
1040 IntUnlinkWindow(Wnd
);
1042 if (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1044 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
1045 Sibling
= WndNewParent
->FirstChild
;
1046 while (NULL
!= Sibling
&& 0 != (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1048 InsertAfter
= Sibling
;
1049 Sibling
= Sibling
->NextSibling
;
1052 if (NULL
== InsertAfter
)
1054 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1058 // UserReferenceObject(InsertAfter);
1059 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1060 // UserDereferenceObject(InsertAfter);
1065 * SetParent additionally needs to make hwnd the top window
1066 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1067 * WM_WINDOWPOSCHANGED notification messages.
1069 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1070 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1071 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1074 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1075 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1079 * Validate that the old parent still exist, since it migth have been
1080 * destroyed during the last callbacks to user-mode
1084 // if(!IntIsWindow(WndOldParent->hSelf))
1086 // UserDereferenceObject(WndOldParent);
1090 /* don't dereference the window object here, it must be done by the caller
1091 of IntSetParent() */
1092 // return WndOldParent;
1095 return WndOldParent
;//NULL;
1099 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
1101 PMENU_OBJECT OldMenu
;
1102 if(Window
->SystemMenu
)
1104 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1107 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1108 IntReleaseMenuObject(OldMenu
);
1114 /* FIXME check window style, propably return FALSE ? */
1115 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1116 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1119 Window
->SystemMenu
= (HMENU
)0;
1125 /* unlink the window from siblings and parent. children are kept in place. */
1127 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1129 PWINDOW_OBJECT WndParent
= Wnd
->Parent
;
1131 if (Wnd
->NextSibling
)
1132 Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1133 else if (WndParent
&& WndParent
->LastChild
== Wnd
)
1134 WndParent
->LastChild
= Wnd
->PrevSibling
;
1136 if (Wnd
->PrevSibling
)
1137 Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1138 else if (WndParent
&& WndParent
->FirstChild
== Wnd
)
1139 WndParent
->FirstChild
= Wnd
->NextSibling
;
1141 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1143 Wnd
->Wnd
->spwndParent
= NULL
;
1149 PWINDOW_OBJECT Window
, Child
;
1151 if(!(Window
= UserGetWindowObject(IntGetDesktopWindow())))
1156 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1158 if(Child
->hOwner
&& Child
->Wnd
->style
& WS_VISIBLE
)
1161 * The desktop has a popup window if one of them has
1162 * an owner window and is visible
1172 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1174 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1180 IntGetWindowPlacement(PWINDOW_OBJECT Window
, WINDOWPLACEMENT
*lpwndpl
)
1186 if (!Wnd
) return FALSE
;
1188 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1194 if (0 == (Wnd
->style
& WS_VISIBLE
))
1196 lpwndpl
->showCmd
= SW_HIDE
;
1198 else if (0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
1199 0 != (Wnd
->style
& WS_MAXIMIZE
))
1201 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1203 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1205 lpwndpl
->showCmd
= SW_MINIMIZE
;
1207 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1209 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1212 Size
.x
= Wnd
->rcWindow
.left
;
1213 Size
.y
= Wnd
->rcWindow
.top
;
1214 WinPosInitInternalPos(Window
, &Size
,
1217 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1218 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1219 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1225 /* FUNCTIONS *****************************************************************/
1231 NtUserAlterWindowStyle(DWORD Unknown0
,
1241 * As best as I can figure, this function is used by EnumWindows,
1242 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1244 * It's supposed to build a list of HWNDs to return to the caller.
1245 * We can figure out what kind of list by what parameters are
1253 NtUserBuildHwndList(
1266 return ERROR_INVALID_PARAMETER
;
1268 if (hwndParent
|| !dwThreadId
)
1271 PWINDOW_OBJECT Parent
, Window
;
1275 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1277 return ERROR_INVALID_HANDLE
;
1282 Status
= IntValidateDesktopHandle(hDesktop
,
1286 if(!NT_SUCCESS(Status
))
1288 return ERROR_INVALID_HANDLE
;
1291 hwndParent
= Desktop
->DesktopWindow
;
1298 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1299 (Window
= Parent
->FirstChild
))
1301 BOOL bGoDown
= TRUE
;
1303 Status
= STATUS_SUCCESS
;
1308 if(dwCount
++ < *pBufSize
&& pWnd
)
1312 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1313 *pWnd
= Window
->hSelf
;
1316 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1318 Status
= _SEH2_GetExceptionCode();
1321 if(!NT_SUCCESS(Status
))
1323 SetLastNtError(Status
);
1327 if (Window
->FirstChild
&& bChildren
)
1329 Window
= Window
->FirstChild
;
1334 if (Window
->NextSibling
)
1336 Window
= Window
->NextSibling
;
1340 Window
= Window
->Parent
;
1341 if (Window
== Parent
)
1350 ObDereferenceObject(Desktop
);
1356 PTHREADINFO W32Thread
;
1357 PLIST_ENTRY Current
;
1358 PWINDOW_OBJECT Window
;
1360 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1361 if(!NT_SUCCESS(Status
))
1363 return ERROR_INVALID_PARAMETER
;
1365 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1367 ObDereferenceObject(Thread
);
1368 DPRINT("Thread is not a GUI Thread!\n");
1369 return ERROR_INVALID_PARAMETER
;
1372 Current
= W32Thread
->WindowListHead
.Flink
;
1373 while(Current
!= &(W32Thread
->WindowListHead
))
1375 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1378 if(bChildren
|| Window
->hOwner
!= NULL
)
1380 if(dwCount
< *pBufSize
&& pWnd
)
1382 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1383 if(!NT_SUCCESS(Status
))
1385 SetLastNtError(Status
);
1391 Current
= Current
->Flink
;
1394 ObDereferenceObject(Thread
);
1397 *pBufSize
= dwCount
;
1398 return STATUS_SUCCESS
;
1406 NtUserChildWindowFromPointEx(HWND hwndParent
,
1411 PWINDOW_OBJECT Parent
;
1416 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1424 if(Parent
->hSelf
!= IntGetDesktopWindow())
1426 Pt
.x
+= Parent
->Wnd
->rcClient
.left
;
1427 Pt
.y
+= Parent
->Wnd
->rcClient
.top
;
1430 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1435 Ret
= Parent
->hSelf
;
1436 if((List
= IntWinListChildren(Parent
)))
1438 for(phWnd
= List
; *phWnd
; phWnd
++)
1440 PWINDOW_OBJECT Child
;
1442 if((Child
= UserGetWindowObject(*phWnd
)))
1444 ChildWnd
= Child
->Wnd
;
1445 if(!(ChildWnd
->style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1449 if((ChildWnd
->style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1453 if((ChildWnd
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1457 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1472 * calculates the default position of a window
1475 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT Window
, RECTL
*rc
, BOOL IncPos
)
1482 RECTL_bIntersectRect(rc
, rc
, &Parent
->Wnd
->rcClient
);
1486 Pos
.x
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1487 Pos
.y
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1488 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1489 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1491 /* reset counter and position */
1494 Parent
->TiledCounter
= 0;
1496 Parent
->TiledCounter
++;
1507 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1508 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1512 rc
->right
= rc
->left
+ Sz
.cx
;
1513 rc
->bottom
= rc
->top
+ Sz
.cy
;
1522 co_IntCreateWindowEx(DWORD dwExStyle
,
1523 PUNICODE_STRING ClassName
,
1524 PUNICODE_STRING WindowName
,
1532 HINSTANCE hInstance
,
1535 BOOL bUnicodeWindow
)
1537 PWINSTATION_OBJECT WinSta
;
1539 PWINDOWCLASS
*ClassLink
, Class
= NULL
;
1541 PWINDOW_OBJECT Window
= NULL
;
1542 PWINDOW_OBJECT ParentWindow
= NULL
, OwnerWindow
;
1543 HWND ParentWindowHandle
= NULL
;
1544 HWND OwnerWindowHandle
;
1545 PMENU_OBJECT SystemMenu
;
1549 PW32THREADINFO ti
= NULL
;
1552 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1558 CBT_CREATEWNDW CbtCreate
;
1561 DECLARE_RETURN(PWINDOW
);
1563 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1566 pti
= PsGetCurrentThreadWin32Thread();
1570 ParentWindowHandle
= pti
->Desktop
->DesktopWindow
;
1573 OwnerWindowHandle
= NULL
;
1575 if (hWndParent
== HWND_MESSAGE
)
1578 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1579 * message window (style: WS_POPUP|WS_DISABLED)
1581 ParentWindowHandle
= IntGetMessageWindow();
1582 DPRINT("Parent is HWND_MESSAGE 0x%x\n", ParentWindowHandle
);
1584 else if (hWndParent
)
1586 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1588 PWINDOW_OBJECT Par
= UserGetWindowObject(hWndParent
), Root
;
1589 if (Par
&& (Root
= UserGetAncestor(Par
, GA_ROOT
)))
1590 OwnerWindowHandle
= Root
->hSelf
;
1593 ParentWindowHandle
= hWndParent
;
1595 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1597 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1598 RETURN( (PWINDOW
)0); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1601 if (ParentWindowHandle
)
1603 ParentWindow
= UserGetWindowObject(ParentWindowHandle
);
1605 if (ParentWindow
) UserRefObjectCo(ParentWindow
, &ParentRef
);
1609 ParentWindow
= NULL
;
1612 /* FIXME: parent must belong to the current process */
1614 /* Check the window station. */
1615 ti
= GetW32ThreadInfo();
1616 if (ti
== NULL
|| pti
->Desktop
== NULL
)
1618 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1619 RETURN( (PWINDOW
)0);
1622 /* Check the class. */
1624 ClassAtom
= IntGetClassAtom(ClassName
,
1630 if (ClassAtom
== (RTL_ATOM
)0)
1632 if (IS_ATOM(ClassName
->Buffer
))
1634 DPRINT1("Class 0x%p not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1638 DPRINT1("Class \"%wZ\" not found\n", ClassName
);
1641 SetLastWin32Error(ERROR_CANNOT_FIND_WND_CLASS
);
1645 Class
= IntReferenceClass(Class
,
1650 DPRINT1("Failed to reference window class!\n");
1654 WinSta
= pti
->Desktop
->WindowStation
;
1656 //FIXME: Reference thread/desktop instead
1657 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1659 /* Create the window object. */
1660 Window
= (PWINDOW_OBJECT
) UserCreateObject( gHandleTable
,
1663 sizeof(WINDOW_OBJECT
));
1666 Window
->Wnd
= DesktopHeapAlloc(pti
->Desktop
,
1667 sizeof(WINDOW
) + Class
->cbwndExtra
);
1670 RtlZeroMemory(Window
->Wnd
,
1671 sizeof(WINDOW
) + Class
->cbwndExtra
);
1672 Window
->Wnd
->hdr
.Handle
= hWnd
; /* FIXME: Remove hack , are you sure?*/
1677 Wnd
->pdesktop
= pti
->Desktop
;
1678 Wnd
->hWndLastActive
= hWnd
;
1681 DPRINT("Created object with handle %X\n", hWnd
);
1685 ObDereferenceObject(WinSta
);
1686 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1687 RETURN( (PWINDOW
)0);
1690 UserRefObjectCo(Window
, &Ref
);
1692 ObDereferenceObject(WinSta
);
1694 if (NULL
== pti
->Desktop
->DesktopWindow
)
1696 /* If there is no desktop window yet, we must be creating it */
1697 pti
->Desktop
->DesktopWindow
= hWnd
;
1698 pti
->Desktop
->DesktopInfo
->Wnd
= Wnd
;
1702 * Fill out the structure describing it.
1708 Window
->SystemMenu
= (HMENU
)0;
1709 Wnd
->ContextHelpId
= 0;
1711 Wnd
->hModule
= hInstance
;
1712 Window
->hSelf
= hWnd
;
1714 Window
->MessageQueue
= pti
->MessageQueue
;
1715 IntReferenceMessageQueue(Window
->MessageQueue
);
1716 Window
->Parent
= ParentWindow
;
1717 Wnd
->spwndParent
= ParentWindow
? ParentWindow
->Wnd
: NULL
;
1718 if (Wnd
->spwndParent
!= NULL
&& hWndParent
!= 0)
1720 Wnd
->HideFocus
= Wnd
->spwndParent
->HideFocus
;
1721 Wnd
->HideAccel
= Wnd
->spwndParent
->HideAccel
;
1724 if((OwnerWindow
= UserGetWindowObject(OwnerWindowHandle
)))
1726 Window
->hOwner
= OwnerWindowHandle
;
1727 Wnd
->spwndOwner
= OwnerWindow
->Wnd
;
1732 Window
->hOwner
= NULL
;
1733 Wnd
->spwndOwner
= NULL
;
1737 Wnd
->dwUserData
= 0;
1739 Wnd
->IsSystem
= Wnd
->pcls
->System
;
1741 /* BugBoy Comments: Comment below say that System classes are always created as UNICODE.
1742 In windows, creating a window with the ANSI version of CreateWindow sets the window
1743 to ansi as verified by testing with IsUnicodeWindow API.
1745 No where can I see in code or through testing does the window change back to ANSI
1746 after being created as UNICODE in ROS. I didnt do more testing to see what problems this would cause.*/
1747 // See NtUserDefSetText! We convert to Unicode all the time and never use Mix. (jt)
1748 if (Wnd
->pcls
->System
)
1750 /* NOTE: Always create a unicode window for system classes! */
1751 Wnd
->Unicode
= TRUE
;
1752 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
1753 Wnd
->WndProcExtra
= Wnd
->pcls
->WndProcExtra
;
1757 Wnd
->Unicode
= Wnd
->pcls
->Unicode
;
1758 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
1759 Wnd
->CallProc
= NULL
;
1762 Window
->OwnerThread
= PsGetCurrentThread();
1763 Window
->FirstChild
= NULL
;
1764 Window
->LastChild
= NULL
;
1765 Window
->PrevSibling
= NULL
;
1766 Window
->NextSibling
= NULL
;
1767 Wnd
->cbwndExtra
= Wnd
->pcls
->cbwndExtra
;
1769 InitializeListHead(&Wnd
->PropListHead
);
1770 InitializeListHead(&Window
->WndObjListHead
);
1772 if ( NULL
!= WindowName
->Buffer
&& WindowName
->Length
> 0 )
1774 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->pdesktop
,
1775 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1776 if (Wnd
->strName
.Buffer
== NULL
)
1778 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1779 RETURN( (PWINDOW
)0);
1782 Wnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1785 RtlCopyMemory(Wnd
->strName
.Buffer
,
1787 WindowName
->Length
);
1788 Wnd
->strName
.Length
= WindowName
->Length
;
1790 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1792 WindowName
->Length
= 0;
1793 Wnd
->strName
.Buffer
[0] = L
'\0';
1799 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1800 * tested for WS_POPUP
1802 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1803 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1804 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1805 dwExStyle
|= WS_EX_WINDOWEDGE
;
1807 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1809 /* Correct the window style. */
1810 if (!(dwStyle
& WS_CHILD
))
1812 dwStyle
|= WS_CLIPSIBLINGS
;
1813 DPRINT("3: Style is now %lx\n", dwStyle
);
1814 if (!(dwStyle
& WS_POPUP
))
1816 dwStyle
|= WS_CAPTION
;
1817 Window
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1818 DPRINT("4: Style is now %lx\n", dwStyle
);
1822 /* create system menu */
1823 if((dwStyle
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1825 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
1828 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1829 IntReleaseMenuObject(SystemMenu
);
1833 /* Set the window menu */
1834 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1837 IntSetMenu(Window
, hMenu
, &MenuChanged
);
1840 hMenu
= Wnd
->pcls
->hMenu
;
1841 if (hMenu
) IntSetMenu(Window
, hMenu
, &MenuChanged
);
1845 Wnd
->IDMenu
= (UINT
) hMenu
;
1847 /* Insert the window into the thread's window list. */
1848 InsertTailList (&pti
->WindowListHead
, &Window
->ThreadListEntry
);
1850 /* Handle "CS_CLASSDC", it is tested first. */
1851 if ((Wnd
->pcls
->style
& CS_CLASSDC
) && !(Wnd
->pcls
->pdce
)) // One DCE per class to have CLASS.
1852 Wnd
->pcls
->pdce
= DceAllocDCE(Window
, DCE_CLASS_DC
);
1853 /* Allocate a DCE for this window. */
1854 else if ( Wnd
->pcls
->style
& CS_OWNDC
)
1855 Window
->Dce
= DceAllocDCE(Window
, DCE_WINDOW_DC
);
1862 Wnd
->ExStyle
= dwExStyle
;
1863 Wnd
->style
= dwStyle
& ~WS_VISIBLE
;
1866 Cs
.lpCreateParams
= lpParam
;
1867 Cs
.hInstance
= hInstance
;
1869 Cs
.hwndParent
= hWndParent
; //Pass the original Parent handle!
1874 Cs
.style
= Wnd
->style
;
1875 // Cs.lpszName = (LPCWSTR) WindowName->Buffer;
1876 // Cs.lpszClass = (LPCWSTR) ClassName->Buffer;
1877 Cs
.lpszName
= (LPCWSTR
) WindowName
;
1878 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
1879 Cs
.dwExStyle
= dwExStyle
;
1880 CbtCreate
.lpcs
= &Cs
;
1881 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1882 if (ISITHOOKED(WH_CBT
))
1884 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) &CbtCreate
))
1886 /* FIXME - Delete window object and remove it from the thread windows list */
1887 /* FIXME - delete allocated DCE */
1888 DPRINT1("CBT-hook returned !0\n");
1889 RETURN( (PWINDOW
) NULL
);
1896 // FIXME: Need to set the Z order in the window link list if the hook callback changed it!
1897 // hwndInsertAfter = CbtCreate.hwndInsertAfter;
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
->rcWindow
.left
= Pos
.x
;
1995 Wnd
->rcWindow
.top
= Pos
.y
;
1996 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
1997 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
1998 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2000 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2001 ParentWindow
->Wnd
->rcClient
.top
);
2003 Wnd
->rcClient
= Wnd
->rcWindow
;
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
->rcWindow
.left
= Pos
.x
;
2030 Wnd
->rcWindow
.top
= Pos
.y
;
2031 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
2032 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
2033 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2035 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2036 ParentWindow
->Wnd
->rcClient
.top
);
2038 Wnd
->rcClient
= Wnd
->rcWindow
;
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
->rcWindow
.left
;
2061 MaxPos
.y
= Window
->Wnd
->rcWindow
.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
->rcWindow
,
2068 &Window
->Wnd
->rcClient
);
2070 RECTL_vOffsetRect(&Window
->Wnd
->rcWindow
,
2071 MaxPos
.x
- Window
->Wnd
->rcWindow
.left
,
2072 MaxPos
.y
- Window
->Wnd
->rcWindow
.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 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
->hSelf
, OBJID_WINDOW
, 0);
2125 /* Send move and size messages. */
2126 if (!(Window
->Flags
& WINDOWOBJECT_NEED_SIZE
))
2130 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
2132 if ((Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
) < 0 ||
2133 (Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
) < 0)
2135 DPRINT("Sending bogus WM_SIZE\n");
2138 lParam
= MAKE_LONG(Window
->Wnd
->rcClient
.right
-
2139 Window
->Wnd
->rcClient
.left
,
2140 Window
->Wnd
->rcClient
.bottom
-
2141 Window
->Wnd
->rcClient
.top
);
2142 co_IntSendMessage(Window
->hSelf
, WM_SIZE
, SIZE_RESTORED
,
2145 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
2147 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2149 lParam
= MAKE_LONG(Wnd
->rcClient
.left
- ParentWindow
->Wnd
->rcClient
.left
,
2150 Wnd
->rcClient
.top
- ParentWindow
->Wnd
->rcClient
.top
);
2154 lParam
= MAKE_LONG(Wnd
->rcClient
.left
,
2158 co_IntSendMessage(Window
->hSelf
, WM_MOVE
, 0, lParam
);
2160 /* Call WNDOBJ change procs */
2161 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
2164 /* Show or maybe minimize or maximize the window. */
2165 if (Wnd
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2170 SwFlag
= (Wnd
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
2173 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2175 SwFlag
= ((Wnd
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2176 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2177 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2179 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
2180 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
2181 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2182 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2185 /* Notify the parent window of a new child. */
2186 if ((Wnd
->style
& WS_CHILD
) &&
2187 (!(Wnd
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
2189 DPRINT("IntCreateWindow(): About to notify parent\n");
2190 co_IntSendMessage(ParentWindow
->hSelf
,
2192 MAKEWPARAM(WM_CREATE
, Wnd
->IDMenu
),
2193 (LPARAM
)Window
->hSelf
);
2196 if ((!hWndParent
) && (!HasOwner
))
2198 DPRINT("Sending CREATED notify\n");
2199 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2203 DPRINT("Not sending CREATED notify, %x %d\n", ParentWindow
, HasOwner
);
2206 /* Initialize and show the window's scrollbars */
2207 if (Wnd
->style
& WS_VSCROLL
)
2209 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2211 if (Wnd
->style
& WS_HSCROLL
)
2213 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2216 if (dwStyle
& WS_VISIBLE
)
2218 if (Wnd
->style
& WS_MAXIMIZE
)
2219 dwShowMode
= SW_SHOW
;
2220 else if (Wnd
->style
& WS_MINIMIZE
)
2221 dwShowMode
= SW_SHOWMINIMIZED
;
2223 DPRINT("IntCreateWindow(): About to show window\n");
2224 co_WinPosShowWindow(Window
, dwShowMode
);
2226 if (Wnd
->ExStyle
& WS_EX_MDICHILD
)
2228 co_IntSendMessage(ParentWindow
->hSelf
, WM_MDIREFRESHMENU
, 0, 0);
2229 /* ShowWindow won't activate child windows */
2230 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2234 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
2235 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
2236 Dont understand why it does this. */
2237 if (ClassAtom
== gpsi
->atomSysClass
[ICLS_EDIT
])
2240 //CallProc = CreateCallProc(NULL, Wnd->lpfnWndProc, bUnicodeWindow, Wnd->ti->ppi);
2241 CallProc
= CreateCallProc(NULL
, Wnd
->lpfnWndProc
, Wnd
->Unicode
, Wnd
->ti
->ppi
);
2245 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2246 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
2250 UserAddCallProcToClass(Wnd
->pcls
, CallProc
);
2251 Wnd
->CallProc
= CallProc
;
2252 Wnd
->IsSystem
= FALSE
;
2256 DPRINT("IntCreateWindow(): = %X\n", hWnd
);
2257 DPRINT("WindowObject->SystemMenu = 0x%x\n", Window
->SystemMenu
);
2261 if (!_ret_
&& Window
&& Window
->Wnd
&& ti
)
2262 UserFreeWindowInfo(ti
, Window
);
2265 UserDerefObjectCo(Window
);
2266 UserDereferenceObject(Window
);
2268 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2269 if (!_ret_
&& ti
!= NULL
)
2273 IntDereferenceClass(Class
,
2282 NtUserCreateWindowEx(DWORD dwExStyle
,
2283 PUNICODE_STRING UnsafeClassName
,
2284 PUNICODE_STRING UnsafeWindowName
,
2292 HINSTANCE hInstance
,
2295 BOOL bUnicodeWindow
,
2299 UNICODE_STRING WindowName
;
2300 UNICODE_STRING ClassName
;
2301 HWND NewWindow
= NULL
;
2303 DECLARE_RETURN(HWND
);
2305 DPRINT("Enter NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2306 UserEnterExclusive();
2308 /* Get the class name (string or atom) */
2309 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
2310 if (! NT_SUCCESS(Status
))
2312 SetLastNtError(Status
);
2315 if (ClassName
.Length
!= 0)
2317 Status
= IntSafeCopyUnicodeStringTerminateNULL(&ClassName
, UnsafeClassName
);
2318 if (! NT_SUCCESS(Status
))
2320 SetLastNtError(Status
);
2324 else if (! IS_ATOM(ClassName
.Buffer
))
2326 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2330 /* safely copy the window name */
2331 if (NULL
!= UnsafeWindowName
)
2333 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
2334 if (! NT_SUCCESS(Status
))
2336 if (! IS_ATOM(ClassName
.Buffer
))
2338 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2340 SetLastNtError(Status
);
2346 RtlInitUnicodeString(&WindowName
, NULL
);
2349 pNewWindow
= co_IntCreateWindowEx( dwExStyle
,
2364 if (pNewWindow
) NewWindow
= pNewWindow
->hdr
.Handle
;
2366 if (WindowName
.Buffer
)
2368 ExFreePoolWithTag(WindowName
.Buffer
, TAG_STRING
);
2370 if (! IS_ATOM(ClassName
.Buffer
))
2372 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2378 DPRINT("Leave NtUserCreateWindowEx, ret=%i\n",_ret_
);
2387 NtUserDeferWindowPos(HDWP WinPosInfo
,
2389 HWND WndInsertAfter
,
2402 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2408 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2410 hWnd
= Window
->hSelf
;
2414 if (!Wnd
) return TRUE
; // FIXME: Need to finish object rewrite or lock the thread when killing the window!
2416 /* Check for owner thread */
2417 if ((Window
->OwnerThread
!= PsGetCurrentThread()))
2419 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2424 if (ISITHOOKED(WH_CBT
))
2426 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0)) return FALSE
;
2429 /* Look whether the focus is within the tree of windows we will
2432 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2434 if (UserGetActiveWindow() == Window
->hSelf
)
2436 co_WinPosActivateOtherWindow(Window
);
2440 if (Window
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2441 Window
->MessageQueue
->ActiveWindow
= NULL
;
2442 if (Window
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2443 Window
->MessageQueue
->FocusWindow
= NULL
;
2444 if (Window
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2445 Window
->MessageQueue
->CaptureWindow
= NULL
;
2447 IntDereferenceMessageQueue(Window
->MessageQueue
);
2449 IntEngWindowChanged(Window
, WOC_DELETE
);
2450 isChild
= (0 != (Wnd
->style
& WS_CHILD
));
2456 if (! USER_IsExitingThread(GetCurrentThreadId()))
2458 send_parent_notify(hwnd
, WM_DESTROY
);
2461 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2463 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2464 /* FIXME: clean up palette - see "Internals" p.352 */
2468 if (!IntIsWindow(Window
->hSelf
))
2473 /* Recursively destroy owned windows */
2478 BOOL GotOne
= FALSE
;
2481 PWINDOW_OBJECT Child
, Desktop
;
2483 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2484 UserGetWindowObject(IntGetDesktopWindow());
2485 Children
= IntWinListChildren(Desktop
);
2489 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2491 Child
= UserGetWindowObject(*ChildHandle
);
2494 if (Child
->hOwner
!= Window
->hSelf
)
2499 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2501 USER_REFERENCE_ENTRY ChildRef
;
2502 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2503 co_UserDestroyWindow(Child
);
2504 UserDerefObjectCo(Child
);//temp hack?
2510 if (Child
->hOwner
!= NULL
)
2512 Child
->hOwner
= NULL
;
2513 Child
->Wnd
->spwndOwner
= NULL
;
2517 ExFreePool(Children
);
2526 if (!IntIsWindow(Window
->hSelf
))
2531 /* Destroy the window storage */
2532 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2544 NtUserDestroyWindow(HWND Wnd
)
2546 PWINDOW_OBJECT Window
;
2547 DECLARE_RETURN(BOOLEAN
);
2549 USER_REFERENCE_ENTRY Ref
;
2551 DPRINT("Enter NtUserDestroyWindow\n");
2552 UserEnterExclusive();
2554 if (!(Window
= UserGetWindowObject(Wnd
)))
2559 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2560 ret
= co_UserDestroyWindow(Window
);
2561 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2566 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2578 NtUserDrawMenuBarTemp(
2585 /* we'll use this function just for caching the menu bar */
2595 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2605 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2611 NtUserFillWindow(HWND hWndPaint
,
2622 static HWND FASTCALL
2623 IntFindWindow(PWINDOW_OBJECT Parent
,
2624 PWINDOW_OBJECT ChildAfter
,
2626 PUNICODE_STRING WindowName
)
2628 BOOL CheckWindowName
;
2634 CheckWindowName
= WindowName
->Length
!= 0;
2636 if((List
= IntWinListChildren(Parent
)))
2641 /* skip handles before and including ChildAfter */
2642 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2646 /* search children */
2649 PWINDOW_OBJECT Child
;
2650 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2655 /* Do not send WM_GETTEXT messages in the kernel mode version!
2656 The user mode version however calls GetWindowText() which will
2657 send WM_GETTEXT messages to windows belonging to its processes */
2658 if((!CheckWindowName
|| !RtlCompareUnicodeString(WindowName
, &(Child
->Wnd
->strName
), TRUE
)) &&
2659 (!ClassAtom
|| Child
->Wnd
->pcls
->atomClassName
== ClassAtom
))
2674 * Searches a window's children for a window with the specified
2677 * hwndParent = The window whose childs are to be searched.
2679 * HWND_MESSAGE = message-only windows
2681 * hwndChildAfter = Search starts after this child window.
2682 * NULL = start from beginning
2684 * ucClassName = Class name to search for
2685 * Reguired parameter.
2687 * ucWindowName = Window name
2688 * ->Buffer == NULL = don't care
2691 * The HWND of the window if it was found, otherwise NULL
2697 NtUserFindWindowEx(HWND hwndParent
,
2698 HWND hwndChildAfter
,
2699 PUNICODE_STRING ucClassName
,
2700 PUNICODE_STRING ucWindowName
,
2703 PWINDOW_OBJECT Parent
, ChildAfter
;
2704 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2705 HWND Desktop
, Ret
= NULL
;
2706 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2707 DECLARE_RETURN(HWND
);
2709 DPRINT("Enter NtUserFindWindowEx\n");
2712 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2716 if (ucClassName
!= NULL
)
2718 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2719 if (ClassName
.Length
!= 0)
2721 ProbeForRead(ClassName
.Buffer
,
2725 else if (!IS_ATOM(ClassName
.Buffer
))
2727 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2731 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2738 if (ucWindowName
!= NULL
)
2740 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2741 if (WindowName
.Length
!= 0)
2743 ProbeForRead(WindowName
.Buffer
,
2749 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2751 SetLastNtError(_SEH2_GetExceptionCode());
2752 _SEH2_YIELD(RETURN(NULL
));
2756 if (ucClassName
!= NULL
)
2758 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2759 !IS_ATOM(ClassName
.Buffer
))
2761 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2764 else if (ClassAtom
== (RTL_ATOM
)0)
2766 /* LastError code was set by IntGetAtomFromStringOrAtom */
2772 Desktop
= IntGetCurrentThreadDesktopWindow();
2774 if(hwndParent
== NULL
)
2775 hwndParent
= Desktop
;
2776 else if(hwndParent
== HWND_MESSAGE
)
2778 hwndParent
= IntGetMessageWindow();
2781 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2787 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2794 if(Parent
->hSelf
== Desktop
)
2797 PWINDOW_OBJECT TopLevelWindow
;
2798 BOOLEAN CheckWindowName
;
2799 BOOLEAN WindowMatches
;
2800 BOOLEAN ClassMatches
;
2802 /* windows searches through all top-level windows if the parent is the desktop
2805 if((List
= IntWinListChildren(Parent
)))
2811 /* skip handles before and including ChildAfter */
2812 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2816 CheckWindowName
= WindowName
.Length
!= 0;
2818 /* search children */
2821 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2826 /* Do not send WM_GETTEXT messages in the kernel mode version!
2827 The user mode version however calls GetWindowText() which will
2828 send WM_GETTEXT messages to windows belonging to its processes */
2829 WindowMatches
= !CheckWindowName
|| !RtlCompareUnicodeString(
2830 &WindowName
, &TopLevelWindow
->Wnd
->strName
, TRUE
);
2831 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2832 ClassAtom
== TopLevelWindow
->Wnd
->pcls
->atomClassName
;
2834 if (WindowMatches
&& ClassMatches
)
2836 Ret
= TopLevelWindow
->hSelf
;
2840 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2842 /* window returns the handle of the top-level window, in case it found
2844 Ret
= TopLevelWindow
->hSelf
;
2853 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2857 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2859 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2860 search the message-only windows. Should this also be done if
2861 Parent is the desktop window??? */
2862 PWINDOW_OBJECT MsgWindows
;
2864 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2866 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2871 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2873 SetLastNtError(_SEH2_GetExceptionCode());
2881 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2891 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
2902 PWINDOW_OBJECT FASTCALL
UserGetAncestor(PWINDOW_OBJECT Wnd
, UINT Type
)
2904 PWINDOW_OBJECT WndAncestor
, Parent
;
2906 if (Wnd
->hSelf
== IntGetDesktopWindow())
2915 WndAncestor
= Wnd
->Parent
;
2926 if(!(Parent
= WndAncestor
->Parent
))
2930 if(IntIsDesktopWindow(Parent
))
2935 WndAncestor
= Parent
;
2946 PWINDOW_OBJECT Parent
, Old
;
2949 Parent
= IntGetParent(WndAncestor
);
2957 // UserDereferenceObject(Parent);
2959 WndAncestor
= Parent
;
2979 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2981 PWINDOW_OBJECT Window
, Ancestor
;
2982 DECLARE_RETURN(HWND
);
2984 DPRINT("Enter NtUserGetAncestor\n");
2985 UserEnterExclusive();
2987 if (!(Window
= UserGetWindowObject(hWnd
)))
2992 Ancestor
= UserGetAncestor(Window
, Type
);
2993 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
2995 RETURN(Ancestor
? Ancestor
->hSelf
: NULL
);
2998 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3006 NtUserGetComboBoxInfo(
3011 DECLARE_RETURN(BOOL
);
3013 DPRINT("Enter NtUserGetComboBoxInfo\n");
3016 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3025 sizeof(COMBOBOXINFO
),
3029 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3031 SetLastNtError(_SEH2_GetExceptionCode());
3032 _SEH2_YIELD(RETURN(FALSE
));
3036 // Pass the user pointer, it was already probed.
3037 RETURN( (BOOL
) co_IntSendMessage( Wnd
->hSelf
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3040 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3050 NtUserGetInternalWindowPos( HWND hWnd
,
3054 PWINDOW_OBJECT Window
;
3058 WINDOWPLACEMENT wndpl
;
3062 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3073 ProbeForWrite(rectWnd
,
3079 ProbeForWrite(ptIcon
,
3085 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3087 SetLastNtError(_SEH2_GetExceptionCode());
3092 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3094 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3100 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3104 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3108 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3110 SetLastNtError(_SEH2_GetExceptionCode());
3115 if (!Hit
) Ret
= wndpl
.showCmd
;
3124 NtUserGetListBoxInfo(
3128 DECLARE_RETURN(DWORD
);
3130 DPRINT("Enter NtUserGetListBoxInfo\n");
3133 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3138 RETURN( (DWORD
) co_IntSendMessage( Wnd
->hSelf
, LB_GETLISTBOXINFO
, 0, 0 ));
3141 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3148 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3150 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3151 HWND hWndOldParent
= NULL
;
3152 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3154 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3156 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3160 if (hWndChild
== IntGetDesktopWindow())
3162 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3168 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3175 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3181 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3186 UserRefObjectCo(Wnd
, &Ref
);
3187 UserRefObjectCo(WndParent
, &ParentRef
);
3189 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3191 UserDerefObjectCo(WndParent
);
3192 UserDerefObjectCo(Wnd
);
3196 hWndOldParent
= WndOldParent
->hSelf
;
3197 UserDereferenceObject(WndOldParent
);
3200 return( hWndOldParent
);
3208 * The NtUserSetParent function changes the parent window of the specified
3212 * The new parent window and the child window must belong to the same
3213 * application. If the window identified by the hWndChild parameter is
3214 * visible, the system performs the appropriate redrawing and repainting.
3215 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3216 * or WS_POPUP window styles of the window whose parent is being changed.
3223 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3225 DECLARE_RETURN(HWND
);
3227 DPRINT("Enter NtUserSetParent\n");
3228 UserEnterExclusive();
3231 Check Parent first from user space, set it here.
3235 hWndNewParent
= IntGetDesktopWindow();
3237 else if (hWndNewParent
== HWND_MESSAGE
)
3239 hWndNewParent
= IntGetMessageWindow();
3242 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3245 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3253 * UserGetShellWindow
3255 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3260 HWND FASTCALL
UserGetShellWindow()
3262 PWINSTATION_OBJECT WinStaObject
;
3265 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3270 if (!NT_SUCCESS(Status
))
3272 SetLastNtError(Status
);
3276 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3278 ObDereferenceObject(WinStaObject
);
3283 * NtUserSetShellWindowEx
3285 * This is undocumented function to set global shell window. The global
3286 * shell window has special handling of window position.
3292 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3294 PWINSTATION_OBJECT WinStaObject
;
3295 PWINDOW_OBJECT WndShell
;
3296 DECLARE_RETURN(BOOL
);
3297 USER_REFERENCE_ENTRY Ref
;
3301 DPRINT("Enter NtUserSetShellWindowEx\n");
3302 UserEnterExclusive();
3304 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3309 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3314 if (!NT_SUCCESS(Status
))
3316 SetLastNtError(Status
);
3321 * Test if we are permitted to change the shell window.
3323 if (WinStaObject
->ShellWindow
)
3325 ObDereferenceObject(WinStaObject
);
3330 * Move shell window into background.
3332 if (hwndListView
&& hwndListView
!= hwndShell
)
3335 * Disabled for now to get Explorer working.
3336 * -- Filip, 01/nov/2003
3339 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3342 if (UserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3344 ObDereferenceObject(WinStaObject
);
3349 if (UserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3351 ObDereferenceObject(WinStaObject
);
3355 UserRefObjectCo(WndShell
, &Ref
);
3356 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3358 WinStaObject
->ShellWindow
= hwndShell
;
3359 WinStaObject
->ShellListView
= hwndListView
;
3361 ti
= GetW32ThreadInfo();
3362 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3364 UserDerefObjectCo(WndShell
);
3366 ObDereferenceObject(WinStaObject
);
3370 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3376 * NtUserGetSystemMenu
3378 * The NtUserGetSystemMenu function allows the application to access the
3379 * window menu (also known as the system menu or the control menu) for
3380 * copying and modifying.
3384 * Handle to the window that will own a copy of the window menu.
3386 * Specifies the action to be taken. If this parameter is FALSE,
3387 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3388 * currently in use. The copy is initially identical to the window menu
3389 * but it can be modified.
3390 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3391 * to the default state. The previous window menu, if any, is destroyed.
3394 * If the bRevert parameter is FALSE, the return value is a handle to a
3395 * copy of the window menu. If the bRevert parameter is TRUE, the return
3403 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3405 PWINDOW_OBJECT Window
;
3407 DECLARE_RETURN(HMENU
);
3409 DPRINT("Enter NtUserGetSystemMenu\n");
3412 if (!(Window
= UserGetWindowObject(hWnd
)))
3417 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3422 RETURN(Menu
->MenuInfo
.Self
);
3425 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3431 * NtUserSetSystemMenu
3438 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3440 BOOL Result
= FALSE
;
3441 PWINDOW_OBJECT Window
;
3443 DECLARE_RETURN(BOOL
);
3445 DPRINT("Enter NtUserSetSystemMenu\n");
3446 UserEnterExclusive();
3448 if (!(Window
= UserGetWindowObject(hWnd
)))
3456 * Assign new menu handle.
3458 if (!(Menu
= UserGetMenuObject(hMenu
)))
3463 Result
= IntSetSystemMenu(Window
, Menu
);
3469 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3478 UserGetWindow(HWND hWnd
, UINT Relationship
)
3480 PWINDOW_OBJECT Parent
, Window
;
3481 HWND hWndResult
= NULL
;
3483 if (!(Window
= UserGetWindowObject(hWnd
)))
3486 switch (Relationship
)
3489 if((Parent
= Window
->Parent
))
3491 if (Parent
->FirstChild
)
3492 hWndResult
= Parent
->FirstChild
->hSelf
;
3497 if((Parent
= Window
->Parent
))
3499 if (Parent
->LastChild
)
3500 hWndResult
= Parent
->LastChild
->hSelf
;
3505 if (Window
->NextSibling
)
3506 hWndResult
= Window
->NextSibling
->hSelf
;
3510 if (Window
->PrevSibling
)
3511 hWndResult
= Window
->PrevSibling
->hSelf
;
3515 if((Parent
= UserGetWindowObject(Window
->hOwner
)))
3517 hWndResult
= Parent
->hSelf
;
3521 if (Window
->FirstChild
)
3522 hWndResult
= Window
->FirstChild
->hSelf
;
3534 * The NtUserGetWindow function retrieves a handle to a window that has the
3535 * specified relationship (Z order or owner) to the specified window.
3542 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3544 DECLARE_RETURN(HWND
);
3546 DPRINT("Enter NtUserGetWindow\n");
3549 RETURN(UserGetWindow(hWnd
, Relationship
));
3552 DPRINT("Leave NtUserGetWindow, ret=%i\n",_ret_
);
3561 * NtUserGetWindowLong
3563 * The NtUserGetWindowLong function retrieves information about the specified
3564 * window. The function also retrieves the 32-bit (long) value at the
3565 * specified offset into the extra window memory.
3572 UserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3574 PWINDOW_OBJECT Window
, Parent
;
3578 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3580 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3588 * WndProc is only available to the owner process
3590 if (GWL_WNDPROC
== Index
3591 && Window
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3593 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3597 if ((INT
)Index
>= 0)
3599 if ((Index
+ sizeof(LONG
)) > Window
->Wnd
->cbwndExtra
)
3601 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3604 Result
= *((LONG
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3611 Result
= Wnd
->ExStyle
;
3615 Result
= Wnd
->style
;
3619 Result
= (LONG
)IntGetWindowProc(Window
,
3624 Result
= (LONG
) Wnd
->hModule
;
3627 case GWL_HWNDPARENT
:
3628 Parent
= Window
->Parent
;
3631 if (Parent
&& Parent
->hSelf
== IntGetDesktopWindow())
3632 Result
= (LONG
) UserGetWindow(Window
->hSelf
, GW_OWNER
);
3634 Result
= (LONG
) Parent
->hSelf
;
3639 Result
= (LONG
) Wnd
->IDMenu
;
3643 Result
= Wnd
->dwUserData
;
3647 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3648 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3661 * NtUserGetWindowLong
3663 * The NtUserGetWindowLong function retrieves information about the specified
3664 * window. The function also retrieves the 32-bit (long) value at the
3665 * specified offset into the extra window memory.
3672 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3674 DECLARE_RETURN(LONG
);
3676 DPRINT("Enter NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3677 UserEnterExclusive();
3679 RETURN(UserGetWindowLong(hWnd
, Index
, Ansi
));
3682 DPRINT("Leave NtUserGetWindowLong, ret=%i\n",_ret_
);
3688 IntSetWindowProc(PWINDOW_OBJECT Window
,
3694 PWINDOW Wnd
= Window
->Wnd
;
3696 /* resolve any callproc handle if possible */
3697 if (IsCallProcHandle(NewWndProc
))
3699 WNDPROC_INFO wpInfo
;
3701 if (UserGetCallProcInfo((HANDLE
)NewWndProc
,
3704 NewWndProc
= wpInfo
.WindowProc
;
3705 /* FIXME - what if wpInfo.IsUnicode doesn't match Ansi? */
3709 /* attempt to get the previous window proc */
3712 Ret
= (Ansi
? Wnd
->WndProcExtra
: Wnd
->lpfnWndProc
);
3716 if (!Ansi
== Wnd
->Unicode
)
3718 Ret
= Wnd
->lpfnWndProc
;
3722 CallProc
= UserFindCallProc(Wnd
->pcls
,
3725 if (CallProc
== NULL
)
3727 CallProc
= CreateCallProc(NULL
,
3731 if (CallProc
== NULL
)
3733 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3737 UserAddCallProcToClass(Wnd
->pcls
,
3740 /* BugBoy Comments: Added this if else, see below comments */
3743 Ret
= Wnd
->lpfnWndProc
;
3747 Ret
= GetCallProcHandle(Wnd
->CallProc
);
3750 Wnd
->CallProc
= CallProc
;
3752 /* BugBoy Comments: Above sets the current CallProc for the
3753 window and below we set the Ret value to it.
3754 SetWindowLong for WNDPROC should return the previous proc
3755 Ret = GetCallProcHandle(Wnd->CallProc); */
3759 if (Wnd
->pcls
->System
)
3761 /* check if the new procedure matches with the one in the
3762 window class. If so, we need to restore both procedures! */
3763 Wnd
->IsSystem
= (NewWndProc
== Wnd
->pcls
->lpfnWndProc
||
3764 NewWndProc
== Wnd
->pcls
->WndProcExtra
);
3768 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
3769 Wnd
->WndProcExtra
= Wnd
->pcls
->WndProcExtra
;
3770 Wnd
->Unicode
= !Ansi
;
3775 ASSERT(!Wnd
->IsSystem
);
3777 /* update the window procedure */
3778 Wnd
->lpfnWndProc
= NewWndProc
;
3779 Wnd
->Unicode
= !Ansi
;
3786 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3788 PWINDOW_OBJECT Window
, Parent
;
3790 PWINSTATION_OBJECT WindowStation
;
3794 if (hWnd
== IntGetDesktopWindow())
3796 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3800 if (!(Window
= UserGetWindowObject(hWnd
)))
3807 if (!Wnd
) return 0; // No go on zero.
3809 if ((INT
)Index
>= 0)
3811 if ((Index
+ sizeof(LONG
)) > Wnd
->cbwndExtra
)
3813 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3816 OldValue
= *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
));
3817 *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
)) = NewValue
;
3824 OldValue
= (LONG
) Wnd
->ExStyle
;
3825 Style
.styleOld
= OldValue
;
3826 Style
.styleNew
= NewValue
;
3829 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3831 WindowStation
= ((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
->WindowStation
;
3834 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3835 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3838 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3839 Wnd
->ExStyle
= (DWORD
)Style
.styleNew
;
3840 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3844 OldValue
= (LONG
) Wnd
->style
;
3845 Style
.styleOld
= OldValue
;
3846 Style
.styleNew
= NewValue
;
3847 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3848 Wnd
->style
= (DWORD
)Style
.styleNew
;
3849 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3854 /* FIXME: should check if window belongs to current process */
3855 OldValue
= (LONG
)IntSetWindowProc(Window
,
3862 OldValue
= (LONG
) Wnd
->hModule
;
3863 Wnd
->hModule
= (HINSTANCE
) NewValue
;
3866 case GWL_HWNDPARENT
:
3867 Parent
= Window
->Parent
;
3868 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
3869 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
3871 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
3875 OldValue
= (LONG
) Wnd
->IDMenu
;
3876 Wnd
->IDMenu
= (UINT
) NewValue
;
3880 OldValue
= Wnd
->dwUserData
;
3881 Wnd
->dwUserData
= NewValue
;
3885 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3886 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3898 * NtUserSetWindowLong
3900 * The NtUserSetWindowLong function changes an attribute of the specified
3901 * window. The function also sets the 32-bit (long) value at the specified
3902 * offset into the extra window memory.
3909 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3911 DECLARE_RETURN(LONG
);
3913 DPRINT("Enter NtUserSetWindowLong\n");
3914 UserEnterExclusive();
3916 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3919 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3925 * NtUserSetWindowWord
3927 * Legacy function similar to NtUserSetWindowLong.
3934 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3936 PWINDOW_OBJECT Window
;
3938 DECLARE_RETURN(WORD
);
3940 DPRINT("Enter NtUserSetWindowWord\n");
3941 UserEnterExclusive();
3943 if (!(Window
= UserGetWindowObject(hWnd
)))
3952 case GWL_HWNDPARENT
:
3953 RETURN( co_UserSetWindowLong(Window
->hSelf
, Index
, (UINT
)NewValue
, TRUE
));
3957 SetLastWin32Error(ERROR_INVALID_INDEX
);
3962 if (Index
> Window
->Wnd
->cbwndExtra
- sizeof(WORD
))
3964 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3968 OldValue
= *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3969 *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
)) = NewValue
;
3974 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3983 NtUserGetWindowPlacement(HWND hWnd
,
3984 WINDOWPLACEMENT
*lpwndpl
)
3986 PWINDOW_OBJECT Window
;
3989 WINDOWPLACEMENT Safepl
;
3991 DECLARE_RETURN(BOOL
);
3993 DPRINT("Enter NtUserGetWindowPlacement\n");
3996 if (!(Window
= UserGetWindowObject(hWnd
)))
4002 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4003 if(!NT_SUCCESS(Status
))
4005 SetLastNtError(Status
);
4008 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4014 if (0 == (Wnd
->style
& WS_VISIBLE
))
4016 Safepl
.showCmd
= SW_HIDE
;
4018 else if ((0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
4019 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
4020 0 == (Wnd
->style
& WS_MINIMIZE
))
4022 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
4024 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
4026 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
4028 else if (0 != (Wnd
->style
& WS_VISIBLE
))
4030 Safepl
.showCmd
= SW_SHOWNORMAL
;
4033 Size
.x
= Wnd
->rcWindow
.left
;
4034 Size
.y
= Wnd
->rcWindow
.top
;
4035 WinPosInitInternalPos(Window
, &Size
,
4038 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
4039 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
4040 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
4042 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
4043 if(!NT_SUCCESS(Status
))
4045 SetLastNtError(Status
);
4052 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
4062 NtUserLockWindowUpdate(HWND hWnd
)
4082 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
4083 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
4084 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
4088 QueryWindow based on KJK::Hyperion and James Tabor.
4090 0 = QWUniqueProcessId
4091 1 = QWUniqueThreadId
4094 4 = QWIsHung Implements IsHungAppWindow found
4097 9 = QWKillWindow When I called this with hWnd ==
4098 DesktopWindow, it shutdown the system
4105 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
4107 PWINDOW_OBJECT Window
;
4109 DECLARE_RETURN(UINT
);
4111 DPRINT("Enter NtUserQueryWindow\n");
4114 if (!(Window
= UserGetWindowObject(hWnd
)))
4121 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
4122 Result
= (DWORD
)IntGetWndProcessId(Window
);
4125 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
4126 Result
= (DWORD
)IntGetWndThreadId(Window
);
4129 case QUERY_WINDOW_ACTIVE
:
4130 Result
= (DWORD
)UserGetActiveWindow();
4133 case QUERY_WINDOW_FOCUS
:
4134 Result
= (DWORD
)IntGetFocusWindow();
4137 case QUERY_WINDOW_ISHUNG
:
4138 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
4142 Result
= (DWORD
)NULL
;
4149 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
4159 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
4173 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4175 UNICODE_STRING SafeMessageName
;
4178 DECLARE_RETURN(UINT
);
4180 DPRINT("Enter NtUserRegisterWindowMessage\n");
4181 UserEnterExclusive();
4183 if(MessageNameUnsafe
== NULL
)
4185 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4189 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4190 if(!NT_SUCCESS(Status
))
4192 SetLastNtError(Status
);
4196 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4198 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4202 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
4212 NtUserSetImeOwnerWindow(DWORD Unknown0
,
4225 NtUserSetInternalWindowPos(
4242 NtUserSetLayeredWindowAttributes(HWND hwnd
,
4256 NtUserSetLogonNotifyWindow(HWND hWnd
)
4273 PWINDOW_OBJECT Window
;
4275 DECLARE_RETURN(BOOL
);
4277 DPRINT("Enter NtUserSetMenu\n");
4278 UserEnterExclusive();
4280 if (!(Window
= UserGetWindowObject(hWnd
)))
4285 if (! IntSetMenu(Window
, Menu
, &Changed
))
4290 if (Changed
&& Repaint
)
4292 USER_REFERENCE_ENTRY Ref
;
4294 UserRefObjectCo(Window
, &Ref
);
4295 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4296 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4298 UserDerefObjectCo(Window
);
4304 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4314 NtUserSetWindowFNID(HWND hWnd
,
4317 PWINDOW_OBJECT Window
;
4319 DECLARE_RETURN(BOOL
);
4321 DPRINT("Enter NtUserSetWindowFNID\n");
4322 UserEnterExclusive();
4324 if (!(Window
= UserGetWindowObject(hWnd
)))
4331 { // From user land we only set these.
4332 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
4337 Wnd
->pcls
->fnid
|= fnID
;
4342 DPRINT("Leave NtUserSetWindowFNID\n");
4352 NtUserSetWindowPlacement(HWND hWnd
,
4353 WINDOWPLACEMENT
*lpwndpl
)
4355 PWINDOW_OBJECT Window
;
4357 WINDOWPLACEMENT Safepl
;
4359 DECLARE_RETURN(BOOL
);
4360 USER_REFERENCE_ENTRY Ref
;
4362 DPRINT("Enter NtUserSetWindowPlacement\n");
4363 UserEnterExclusive();
4365 if (!(Window
= UserGetWindowObject(hWnd
)))
4371 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4372 if(!NT_SUCCESS(Status
))
4374 SetLastNtError(Status
);
4377 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4382 UserRefObjectCo(Window
, &Ref
);
4384 if ((Wnd
->style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4386 co_WinPosSetWindowPos(Window
, NULL
,
4387 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4388 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4389 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4390 SWP_NOZORDER
| SWP_NOACTIVATE
);
4393 /* FIXME - change window status */
4394 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
4396 Wnd
->InternalPosInitialized
= TRUE
;
4397 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4398 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4399 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4401 UserDerefObjectCo(Window
);
4405 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4417 HWND hWndInsertAfter
,
4424 DECLARE_RETURN(BOOL
);
4425 PWINDOW_OBJECT Window
;
4427 USER_REFERENCE_ENTRY Ref
;
4429 DPRINT("Enter NtUserSetWindowPos\n");
4430 UserEnterExclusive();
4432 if (!(Window
= UserGetWindowObject(hWnd
)))
4437 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
4438 if (!(uFlags
& SWP_NOMOVE
))
4440 if (X
< -32768) X
= -32768;
4441 else if (X
> 32767) X
= 32767;
4442 if (Y
< -32768) Y
= -32768;
4443 else if (Y
> 32767) Y
= 32767;
4445 if (!(uFlags
& SWP_NOSIZE
))
4448 else if (cx
> 32767) cx
= 32767;
4450 else if (cy
> 32767) cy
= 32767;
4453 UserRefObjectCo(Window
, &Ref
);
4454 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4455 UserDerefObjectCo(Window
);
4460 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4467 IntGetWindowRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
4485 /* Create a new window region using the window rectangle */
4486 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4487 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4488 /* if there's a region assigned to the window, combine them both */
4489 if(Window
->WindowRegion
&& !(Wnd
->style
& WS_MINIMIZE
))
4490 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4491 /* Copy the region into hRgn */
4492 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4494 if((pRgn
= REGION_LockRgn(hRgn
)))
4496 Ret
= pRgn
->rdh
.iType
;
4497 REGION_UnlockRgn(pRgn
);
4502 GreDeleteObject(VisRgn
);
4508 IntGetWindowRgnBox(PWINDOW_OBJECT Window
, RECTL
*Rect
)
4526 /* Create a new window region using the window rectangle */
4527 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4528 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4529 /* if there's a region assigned to the window, combine them both */
4530 if(Window
->WindowRegion
&& !(Wnd
->style
& WS_MINIMIZE
))
4531 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4533 if((pRgn
= REGION_LockRgn(VisRgn
)))
4535 Ret
= pRgn
->rdh
.iType
;
4536 *Rect
= pRgn
->rdh
.rcBound
;
4537 REGION_UnlockRgn(pRgn
);
4542 GreDeleteObject(VisRgn
);
4557 PWINDOW_OBJECT Window
;
4558 DECLARE_RETURN(INT
);
4560 DPRINT("Enter NtUserSetWindowRgn\n");
4561 UserEnterExclusive();
4563 if (!(Window
= UserGetWindowObject(hWnd
)))
4568 /* FIXME - Verify if hRgn is a valid handle!!!!
4569 Propably make this operation thread-safe, but maybe it's not necessary */
4571 if(Window
->WindowRegion
)
4573 /* Delete no longer needed region handle */
4574 GreDeleteObject(Window
->WindowRegion
);
4576 Window
->WindowRegion
= hRgn
;
4578 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4582 USER_REFERENCE_ENTRY Ref
;
4583 UserRefObjectCo(Window
, &Ref
);
4584 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4585 UserDerefObjectCo(Window
);
4591 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4601 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4603 PWINDOW_OBJECT Window
;
4605 DECLARE_RETURN(BOOL
);
4606 USER_REFERENCE_ENTRY Ref
;
4608 DPRINT("Enter NtUserShowWindow\n");
4609 UserEnterExclusive();
4611 if (!(Window
= UserGetWindowObject(hWnd
)))
4616 UserRefObjectCo(Window
, &Ref
);
4617 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4618 UserDerefObjectCo(Window
);
4623 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4633 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4639 return NtUserShowWindow(hWnd
, nCmdShow
);
4649 NtUserUpdateLayeredWindow(
4657 BLENDFUNCTION
*pblend
,
4670 NtUserWindowFromPhysicalPoint(POINT Point
)
4681 NtUserWindowFromPoint(LONG X
, LONG Y
)
4685 PWINDOW_OBJECT DesktopWindow
= NULL
, Window
= NULL
;
4686 DECLARE_RETURN(HWND
);
4687 USER_REFERENCE_ENTRY Ref
;
4689 DPRINT("Enter NtUserWindowFromPoint\n");
4690 UserEnterExclusive();
4692 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4700 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4701 //its possible this referencing is useless, thou it shouldnt hurt...
4702 UserRefObjectCo(DesktopWindow
, &Ref
);
4704 pti
= PsGetCurrentThreadWin32Thread();
4705 Hit
= co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4709 Ret
= Window
->hSelf
;
4718 if (Window
) UserDereferenceObject(Window
);
4719 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4721 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4731 * Undocumented function that is called from DefWindowProc to set
4738 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4740 PWINDOW_OBJECT Window
;
4742 LARGE_STRING SafeText
;
4743 UNICODE_STRING UnicodeString
;
4746 DPRINT("Enter NtUserDefSetText\n");
4748 if (WindowText
!= NULL
)
4752 SafeText
= ProbeForReadLargeString(WindowText
);
4754 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4757 SetLastNtError(_SEH2_GetExceptionCode());
4767 UserEnterExclusive();
4769 if(!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4776 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4777 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4778 // Now we know what the bAnsi is for.
4779 RtlInitUnicodeString(&UnicodeString
, NULL
);
4780 if (SafeText
.Buffer
)
4785 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4787 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4788 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4790 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4793 SetLastNtError(_SEH2_GetExceptionCode());
4796 if (!Ret
) goto Exit
;
4799 if (UnicodeString
.Length
!= 0)
4801 if (Wnd
->strName
.MaximumLength
> 0 &&
4802 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4804 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4806 Wnd
->strName
.Length
= UnicodeString
.Length
;
4807 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4808 RtlCopyMemory(Wnd
->strName
.Buffer
,
4809 UnicodeString
.Buffer
,
4810 UnicodeString
.Length
);
4815 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4816 buf
= Wnd
->strName
.Buffer
;
4817 Wnd
->strName
.Buffer
= NULL
;
4820 DesktopHeapFree(Wnd
->pdesktop
, buf
);
4823 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->pdesktop
,
4824 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4825 if (Wnd
->strName
.Buffer
!= NULL
)
4827 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4828 RtlCopyMemory(Wnd
->strName
.Buffer
,
4829 UnicodeString
.Buffer
,
4830 UnicodeString
.Length
);
4831 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4832 Wnd
->strName
.Length
= UnicodeString
.Length
;
4836 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4844 Wnd
->strName
.Length
= 0;
4845 if (Wnd
->strName
.Buffer
!= NULL
)
4846 Wnd
->strName
.Buffer
[0] = L
'\0';
4849 // HAX! FIXME! Windows does not do this in here!
4850 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4851 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4852 /* Send shell notifications */
4853 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
4855 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4860 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4861 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4867 * NtUserInternalGetWindowText
4874 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4876 PWINDOW_OBJECT Window
;
4880 DECLARE_RETURN(INT
);
4882 DPRINT("Enter NtUserInternalGetWindowText\n");
4885 if(lpString
&& (nMaxCount
<= 1))
4887 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4891 if(!(Window
= UserGetWindowObject(hWnd
)))
4897 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4900 const WCHAR Terminator
= L
'\0';
4902 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4904 Copy
= min(nMaxCount
- 1, Result
);
4907 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4908 if(!NT_SUCCESS(Status
))
4910 SetLastNtError(Status
);
4916 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4917 if(!NT_SUCCESS(Status
))
4919 SetLastNtError(Status
);
4929 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4937 IntShowOwnedPopups(PWINDOW_OBJECT OwnerWnd
, BOOL fShow
)
4940 PWINDOW_OBJECT pWnd
;
4943 // ASSERT(OwnerWnd);
4945 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
4950 while (win_array
[count
])
4952 while (--count
>= 0)
4954 if (UserGetWindow( win_array
[count
], GW_OWNER
) != OwnerWnd
->hSelf
)
4956 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4958 // if (pWnd == WND_OTHER_PROCESS) continue;
4962 if (pWnd
->Flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
)
4964 /* In Windows, ShowOwnedPopups(TRUE) generates
4965 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4966 * regardless of the state of the owner
4968 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4974 if (pWnd
->Wnd
->style
& WS_VISIBLE
)
4976 /* In Windows, ShowOwnedPopups(FALSE) generates
4977 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4978 * regardless of the state of the owner
4980 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4986 ExFreePool( win_array
);
4991 * NtUserValidateHandleSecure
4999 NtUserValidateHandleSecure(
5007 PUSER_HANDLE_ENTRY entry
;
5008 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
5010 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5013 uType
= entry
->type
;
5019 PWINDOW_OBJECT Window
;
5020 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
5026 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
5031 PACCELERATOR_TABLE Accel
;
5032 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
5037 PCURICON_OBJECT Cursor
;
5038 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
5044 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
5049 PMONITOR_OBJECT Monitor
;
5050 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
5056 return UserGetCallProcInfo( handle
, &Proc
);
5059 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5063 { /* Is handle entry restricted? */