2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
5 * FILE: subsystems/win32/win32k/ntuser/window.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * 06-06-2001 CSH Created
11 /* INCLUDES ******************************************************************/
19 /* dialog resources appear to pass this in 16 bits, handle them properly */
20 #define CW_USEDEFAULT16 (0x8000)
22 #define POINT_IN_RECT(p, r) (((r.bottom >= p.y) && (r.top <= p.y))&&((r.left <= p.x )&&( r.right >= p.x )))
24 /* PRIVATE FUNCTIONS **********************************************************/
29 * Initialize windowing implementation.
35 return STATUS_SUCCESS
;
41 * Cleanup windowing implementation.
45 CleanupWindowImpl(VOID
)
47 return STATUS_SUCCESS
;
50 /* HELPER FUNCTIONS ***********************************************************/
52 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
54 WORD Action
= LOWORD(wParam
);
55 WORD Flags
= HIWORD(wParam
);
57 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
59 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
66 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
70 if (Flags
& UISF_HIDEFOCUS
)
71 Wnd
->HideFocus
= TRUE
;
72 if (Flags
& UISF_HIDEACCEL
)
73 Wnd
->HideAccel
= TRUE
;
77 if (Flags
& UISF_HIDEFOCUS
)
78 Wnd
->HideFocus
= FALSE
;
79 if (Flags
& UISF_HIDEACCEL
)
80 Wnd
->HideAccel
= FALSE
;
87 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(PTHREADINFO ti
, PWINDOW_OBJECT WindowObject
)
319 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
320 PWND Wnd
= WindowObject
->Wnd
;
324 if (ClientInfo
->CallbackWnd
.pvWnd
== DesktopHeapAddressToUser(WindowObject
->Wnd
))
326 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
327 ClientInfo
->CallbackWnd
.pvWnd
= NULL
;
330 if (Wnd
->strName
.Buffer
!= NULL
)
332 Wnd
->strName
.Length
= 0;
333 Wnd
->strName
.MaximumLength
= 0;
334 DesktopHeapFree(Wnd
->head
.rpdesk
,
335 Wnd
->strName
.Buffer
);
336 Wnd
->strName
.Buffer
= NULL
;
339 DesktopHeapFree(Wnd
->head
.rpdesk
, Wnd
);
340 WindowObject
->Wnd
= NULL
;
343 /***********************************************************************
346 * Destroy storage associated to a window. "Internals" p.358
348 * This is the "functional" DestroyWindows function ei. all stuff
349 * done in CreateWindow is undone here and not in DestroyWindow:-P
352 static LRESULT
co_UserFreeWindow(PWINDOW_OBJECT Window
,
353 PPROCESSINFO ProcessData
,
354 PTHREADINFO ThreadData
,
355 BOOLEAN SendMessages
)
359 PWINDOW_OBJECT Child
;
361 BOOLEAN BelongsToThreadData
;
368 if(Window
->Status
& WINDOWSTATUS_DESTROYING
)
370 DPRINT("Tried to call IntDestroyWindow() twice\n");
373 Window
->Status
|= WINDOWSTATUS_DESTROYING
;
374 Wnd
->style
&= ~WS_VISIBLE
;
376 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Wnd
, OBJID_WINDOW
, 0);
378 /* remove the window already at this point from the thread window list so we
379 don't get into trouble when destroying the thread windows while we're still
380 in IntDestroyWindow() */
381 RemoveEntryList(&Window
->ThreadListEntry
);
383 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
385 IntDeRegisterShellHookWindow(Window
->hSelf
);
389 /* Send destroy messages */
390 IntSendDestroyMsg(Window
->hSelf
);
393 /* free child windows */
394 Children
= IntWinListChildren(Window
);
397 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
399 if ((Child
= IntGetWindowObject(*ChildHandle
)))
401 if(!IntWndBelongsToThread(Child
, ThreadData
))
403 /* send WM_DESTROY messages to windows not belonging to the same thread */
404 IntSendDestroyMsg(Child
->hSelf
);
407 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
409 UserDereferenceObject(Child
);
412 ExFreePool(Children
);
418 * Clear the update region to make sure no WM_PAINT messages will be
419 * generated for this window while processing the WM_NCDESTROY.
421 co_UserRedrawWindow(Window
, NULL
, 0,
422 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
423 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
424 if(BelongsToThreadData
)
425 co_IntSendMessage(Window
->hSelf
, WM_NCDESTROY
, 0, 0);
427 MsqRemoveTimersWindow(ThreadData
->MessageQueue
, Window
->hSelf
);
429 /* flush the message queue */
430 MsqRemoveWindowMessagesFromQueue(Window
);
432 /* from now on no messages can be sent to this window anymore */
433 Window
->Status
|= WINDOWSTATUS_DESTROYED
;
434 Wnd
->state
|= WNDS_DESTROYED
;
436 /* don't remove the WINDOWSTATUS_DESTROYING bit */
438 /* reset shell window handles */
439 if(ThreadData
->Desktop
)
441 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellWindow
)
442 ThreadData
->Desktop
->WindowStation
->ShellWindow
= NULL
;
444 if (Window
->hSelf
== ThreadData
->Desktop
->WindowStation
->ShellListView
)
445 ThreadData
->Desktop
->WindowStation
->ShellListView
= NULL
;
448 /* Unregister hot keys */
449 UnregisterWindowHotKeys (Window
);
451 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
455 WinPosCheckInternalPos(Window
->hSelf
);
456 if (Window
->hSelf
== GetCapture())
461 /* free resources associated with the window */
462 TIMER_RemoveWindowTimers(Window
->hSelf
);
465 if (!(Wnd
->style
& WS_CHILD
) && Wnd
->IDMenu
466 && (Menu
= UserGetMenuObject((HMENU
)Wnd
->IDMenu
)))
468 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
472 if(Window
->SystemMenu
473 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
475 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
476 Window
->SystemMenu
= (HMENU
)0;
479 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
482 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
483 CLASS_RemoveWindow(Window
->Class
);
486 IntUnlinkWindow(Window
);
488 UserReferenceObject(Window
);
489 UserDeleteObject(Window
->hSelf
, otWindow
);
491 IntDestroyScrollBars(Window
);
493 /* dereference the class */
494 IntDereferenceClass(Wnd
->pcls
,
495 Window
->ti
->pDeskInfo
,
499 if(Window
->WindowRegion
)
501 GreDeleteObject(Window
->WindowRegion
);
504 ASSERT(Window
->Wnd
!= NULL
);
505 UserFreeWindowInfo(Window
->ti
, Window
);
507 UserDereferenceObject(Window
);
509 IntClipboardFreeWindow(Window
);
515 IntGetWindowBorderMeasures(PWINDOW_OBJECT Window
, UINT
*cx
, UINT
*cy
)
517 PWND Wnd
= Window
->Wnd
;
518 if(HAS_DLGFRAME(Wnd
->style
, Wnd
->ExStyle
) && !(Wnd
->style
& WS_MINIMIZE
))
520 *cx
= UserGetSystemMetrics(SM_CXDLGFRAME
);
521 *cy
= UserGetSystemMetrics(SM_CYDLGFRAME
);
525 if(HAS_THICKFRAME(Wnd
->style
, Wnd
->ExStyle
)&& !(Wnd
->style
& WS_MINIMIZE
))
527 *cx
= UserGetSystemMetrics(SM_CXFRAME
);
528 *cy
= UserGetSystemMetrics(SM_CYFRAME
);
530 else if(HAS_THINFRAME(Wnd
->style
, Wnd
->ExStyle
))
532 *cx
= UserGetSystemMetrics(SM_CXBORDER
);
533 *cy
= UserGetSystemMetrics(SM_CYBORDER
);
543 IntGetWindowProc(IN PWINDOW_OBJECT Window
,
546 PWND Wnd
= Window
->Wnd
;
548 ASSERT(UserIsEnteredExclusive() == TRUE
);
552 return (Ansi
? Wnd
->WndProcExtra
: Wnd
->lpfnWndProc
);
556 if (!Ansi
== Wnd
->Unicode
)
558 return Wnd
->lpfnWndProc
;
562 if (Wnd
->CallProc
!= NULL
)
564 return GetCallProcHandle(Wnd
->CallProc
);
566 /* BUGBOY Comments: Maybe theres something Im not undestanding here, but why would a CallProc be created
567 on a function that I thought is only suppose to return the current Windows Proc? */
570 PCALLPROCDATA NewCallProc
, CallProc
;
572 NewCallProc
= UserFindCallProc(Wnd
->pcls
,
575 if (NewCallProc
== NULL
)
577 NewCallProc
= CreateCallProc(Wnd
->head
.pti
->pDeskInfo
,
581 if (NewCallProc
== NULL
)
583 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
587 UserAddCallProcToClass(Wnd
->pcls
,
591 CallProc
= Wnd
->CallProc
;
592 Wnd
->CallProc
= NewCallProc
;
594 return GetCallProcHandle((CallProc
== NULL
? NewCallProc
: CallProc
));
601 IntGetWindowInfo(PWINDOW_OBJECT Window
, PWINDOWINFO pwi
)
603 PWND Wnd
= Window
->Wnd
;
605 pwi
->cbSize
= sizeof(WINDOWINFO
);
606 pwi
->rcWindow
= Window
->Wnd
->rcWindow
;
607 pwi
->rcClient
= Window
->Wnd
->rcClient
;
608 pwi
->dwStyle
= Wnd
->style
;
609 pwi
->dwExStyle
= Wnd
->ExStyle
;
610 pwi
->dwWindowStatus
= (UserGetForegroundWindow() == Window
->hSelf
); /* WS_ACTIVECAPTION */
611 IntGetWindowBorderMeasures(Window
, &pwi
->cxWindowBorders
, &pwi
->cyWindowBorders
);
612 pwi
->atomWindowType
= (Wnd
->pcls
? Wnd
->pcls
->atomClassName
: 0);
613 pwi
->wCreatorVersion
= 0x400; /* FIXME - return a real version number */
619 PWINDOW_OBJECT Window
,
623 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
624 PWND Wnd
= Window
->Wnd
;
626 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
628 SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE
);
632 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
640 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
641 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Window
->hSelf
);
650 NewMenu
= IntGetMenuObject(Menu
);
655 IntReleaseMenuObject(OldMenu
);
657 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
660 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
662 /* Can't use the same menu for two windows */
665 IntReleaseMenuObject(OldMenu
);
667 SetLastWin32Error(ERROR_INVALID_MENU_HANDLE
);
673 Wnd
->IDMenu
= (UINT
) Menu
;
676 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
677 IntReleaseMenuObject(NewMenu
);
681 OldMenu
->MenuInfo
.Wnd
= NULL
;
682 IntReleaseMenuObject(OldMenu
);
689 /* INTERNAL ******************************************************************/
693 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
698 USER_REFERENCE_ENTRY Ref
;
699 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
701 while (!IsListEmpty(&WThread
->WindowListHead
))
703 Current
= WThread
->WindowListHead
.Flink
;
704 Wnd
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
706 DPRINT("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
708 /* window removes itself from the list */
711 fixme: it is critical that the window removes itself! if now, we will loop
715 //ASSERT(co_UserDestroyWindow(Wnd));
717 UserRefObjectCo(Wnd
, &Ref
);//faxme: temp hack??
718 if (!co_UserDestroyWindow(Wnd
))
720 DPRINT1("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
722 UserDerefObjectCo(Wnd
);//faxme: temp hack??
730 * Returns client window rectangle relative to the upper-left corner of client area.
732 * \note Does not check the validity of the parameters
735 IntGetClientRect(PWINDOW_OBJECT Window
, RECTL
*Rect
)
740 Rect
->left
= Rect
->top
= 0;
741 Rect
->right
= Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
;
742 Rect
->bottom
= Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
;
748 IntGetFocusWindow(VOID
)
750 PUSER_MESSAGE_QUEUE Queue
;
751 PDESKTOP pdo
= IntGetActiveDesktop();
756 Queue
= (PUSER_MESSAGE_QUEUE
)pdo
->ActiveMessageQueue
;
761 return(Queue
->FocusWindow
);
765 PMENU_OBJECT FASTCALL
766 IntGetSystemMenu(PWINDOW_OBJECT Window
, BOOL bRevert
, BOOL RetMenu
)
768 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
769 PTHREADINFO W32Thread
;
770 HMENU hNewMenu
, hSysMenu
;
771 ROSMENUITEMINFO ItemInfo
;
775 W32Thread
= PsGetCurrentThreadWin32Thread();
777 if(!W32Thread
->Desktop
)
780 if(Window
->SystemMenu
)
782 Menu
= UserGetMenuObject(Window
->SystemMenu
);
785 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
786 Window
->SystemMenu
= (HMENU
)0;
790 if(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
)
792 /* clone system menu */
793 Menu
= UserGetMenuObject(W32Thread
->Desktop
->WindowStation
->SystemMenuTemplate
);
797 NewMenu
= IntCloneMenu(Menu
);
800 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
801 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
802 NewMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
804 //IntReleaseMenuObject(NewMenu);
809 hSysMenu
= UserCreateMenu(FALSE
);
810 if (NULL
== hSysMenu
)
814 SysMenu
= IntGetMenuObject(hSysMenu
);
817 UserDestroyMenu(hSysMenu
);
820 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
821 SysMenu
->MenuInfo
.Wnd
= Window
->hSelf
;
822 hNewMenu
= co_IntLoadSysMenuTemplate();
825 IntReleaseMenuObject(SysMenu
);
826 UserDestroyMenu(hSysMenu
);
829 Menu
= IntGetMenuObject(hNewMenu
);
832 IntReleaseMenuObject(SysMenu
);
833 UserDestroyMenu(hSysMenu
);
837 NewMenu
= IntCloneMenu(Menu
);
840 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
841 IntReleaseMenuObject(NewMenu
);
842 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
844 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
845 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
846 ItemInfo
.fType
= MF_POPUP
;
847 ItemInfo
.fState
= MFS_ENABLED
;
848 ItemInfo
.dwTypeData
= NULL
;
850 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
851 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
853 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
857 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
866 if(Window
->SystemMenu
)
867 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
875 IntIsChildWindow(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT BaseWindow
)
877 PWINDOW_OBJECT Window
;
884 if (Window
== Parent
)
888 if(!(Wnd
->style
& WS_CHILD
))
893 Window
= Window
->Parent
;
900 IntIsWindowVisible(PWINDOW_OBJECT BaseWindow
)
902 PWINDOW_OBJECT Window
;
909 if(!(Wnd
->style
& WS_CHILD
))
913 if(!(Wnd
->style
& WS_VISIBLE
))
918 Window
= Window
->Parent
;
921 if(Window
&& Wnd
->style
& WS_VISIBLE
)
930 /* link the window into siblings and parent. children are kept in place. */
934 PWINDOW_OBJECT WndParent
,
935 PWINDOW_OBJECT WndPrevSibling
/* set to NULL if top sibling */
938 PWINDOW_OBJECT Parent
;
940 Wnd
->Parent
= WndParent
;
941 Wnd
->Wnd
->spwndParent
= WndParent
? WndParent
->Wnd
: NULL
;
942 if ((Wnd
->PrevSibling
= WndPrevSibling
))
944 /* link after WndPrevSibling */
945 if ((Wnd
->NextSibling
= WndPrevSibling
->NextSibling
))
946 Wnd
->NextSibling
->PrevSibling
= Wnd
;
947 else if ((Parent
= Wnd
->Parent
))
949 if(Parent
->LastChild
== WndPrevSibling
)
950 Parent
->LastChild
= Wnd
;
952 Wnd
->PrevSibling
->NextSibling
= Wnd
;
957 Parent
= Wnd
->Parent
;
958 if ((Wnd
->NextSibling
= WndParent
->FirstChild
))
959 Wnd
->NextSibling
->PrevSibling
= Wnd
;
962 Parent
->LastChild
= Wnd
;
963 Parent
->FirstChild
= Wnd
;
968 Parent
->FirstChild
= Wnd
;
975 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
977 PWINDOW_OBJECT Wnd
, WndOldOwner
, WndNewOwner
;
980 Wnd
= IntGetWindowObject(hWnd
);
984 WndOldOwner
= IntGetWindowObject(Wnd
->hOwner
);
987 ret
= WndOldOwner
->hSelf
;
988 UserDereferenceObject(WndOldOwner
);
995 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
997 Wnd
->hOwner
= hWndNewOwner
;
998 Wnd
->Wnd
->spwndOwner
= WndNewOwner
->Wnd
;
1003 Wnd
->Wnd
->spwndOwner
= NULL
;
1006 UserDereferenceObject(Wnd
);
1010 PWINDOW_OBJECT FASTCALL
1011 co_IntSetParent(PWINDOW_OBJECT Wnd
, PWINDOW_OBJECT WndNewParent
)
1013 PWINDOW_OBJECT WndOldParent
, Sibling
, InsertAfter
;
1014 // HWND hWnd, hWndNewParent;
1018 ASSERT(WndNewParent
);
1019 ASSERT_REFS_CO(Wnd
);
1020 ASSERT_REFS_CO(WndNewParent
);
1022 // hWnd = Wnd->hSelf;
1023 // hWndNewParent = WndNewParent->hSelf;
1025 /* Some applications try to set a child as a parent */
1026 if (IntIsChildWindow(Wnd
, WndNewParent
))
1028 SetLastWin32Error( ERROR_INVALID_PARAMETER
);
1033 * Windows hides the window first, then shows it again
1034 * including the WM_SHOWWINDOW messages and all
1036 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1038 // /* Validate that window and parent still exist */
1039 // if (!IntIsWindow(hWnd) || !IntIsWindow(hWndNewParent))
1042 /* Window must belong to current process */
1043 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
1046 WndOldParent
= Wnd
->Parent
;
1048 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1050 if (WndNewParent
!= WndOldParent
)
1052 IntUnlinkWindow(Wnd
);
1054 if (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1056 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
1057 Sibling
= WndNewParent
->FirstChild
;
1058 while (NULL
!= Sibling
&& 0 != (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1060 InsertAfter
= Sibling
;
1061 Sibling
= Sibling
->NextSibling
;
1064 if (NULL
== InsertAfter
)
1066 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1070 // UserReferenceObject(InsertAfter);
1071 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1072 // UserDereferenceObject(InsertAfter);
1077 * SetParent additionally needs to make hwnd the top window
1078 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1079 * WM_WINDOWPOSCHANGED notification messages.
1081 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1082 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1083 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1086 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1087 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1091 * Validate that the old parent still exist, since it migth have been
1092 * destroyed during the last callbacks to user-mode
1096 // if(!IntIsWindow(WndOldParent->hSelf))
1098 // UserDereferenceObject(WndOldParent);
1102 /* don't dereference the window object here, it must be done by the caller
1103 of IntSetParent() */
1104 // return WndOldParent;
1107 return WndOldParent
;//NULL;
1111 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
1113 PMENU_OBJECT OldMenu
;
1114 if(Window
->SystemMenu
)
1116 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1119 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1120 IntReleaseMenuObject(OldMenu
);
1126 /* FIXME check window style, propably return FALSE ? */
1127 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1128 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1131 Window
->SystemMenu
= (HMENU
)0;
1137 /* unlink the window from siblings and parent. children are kept in place. */
1139 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1141 PWINDOW_OBJECT WndParent
= Wnd
->Parent
;
1143 if (Wnd
->NextSibling
)
1144 Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1145 else if (WndParent
&& WndParent
->LastChild
== Wnd
)
1146 WndParent
->LastChild
= Wnd
->PrevSibling
;
1148 if (Wnd
->PrevSibling
)
1149 Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1150 else if (WndParent
&& WndParent
->FirstChild
== Wnd
)
1151 WndParent
->FirstChild
= Wnd
->NextSibling
;
1153 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1155 Wnd
->Wnd
->spwndParent
= NULL
;
1161 PWINDOW_OBJECT Window
, Child
;
1163 if(!(Window
= UserGetWindowObject(IntGetDesktopWindow())))
1168 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1170 if(Child
->hOwner
&& Child
->Wnd
->style
& WS_VISIBLE
)
1173 * The desktop has a popup window if one of them has
1174 * an owner window and is visible
1184 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1186 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1192 IntGetWindowPlacement(PWINDOW_OBJECT Window
, WINDOWPLACEMENT
*lpwndpl
)
1198 if (!Wnd
) return FALSE
;
1200 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1206 if (0 == (Wnd
->style
& WS_VISIBLE
))
1208 lpwndpl
->showCmd
= SW_HIDE
;
1210 else if (0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
1211 0 != (Wnd
->style
& WS_MAXIMIZE
))
1213 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1215 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1217 lpwndpl
->showCmd
= SW_MINIMIZE
;
1219 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1221 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1224 Size
.x
= Wnd
->rcWindow
.left
;
1225 Size
.y
= Wnd
->rcWindow
.top
;
1226 WinPosInitInternalPos(Window
, &Size
,
1229 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1230 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1231 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1237 /* FUNCTIONS *****************************************************************/
1243 NtUserAlterWindowStyle(DWORD Unknown0
,
1253 * As best as I can figure, this function is used by EnumWindows,
1254 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1256 * It's supposed to build a list of HWNDs to return to the caller.
1257 * We can figure out what kind of list by what parameters are
1265 NtUserBuildHwndList(
1278 return ERROR_INVALID_PARAMETER
;
1280 if (hwndParent
|| !dwThreadId
)
1283 PWINDOW_OBJECT Parent
, Window
;
1287 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1289 return ERROR_INVALID_HANDLE
;
1294 Status
= IntValidateDesktopHandle(hDesktop
,
1298 if(!NT_SUCCESS(Status
))
1300 return ERROR_INVALID_HANDLE
;
1303 hwndParent
= Desktop
->DesktopWindow
;
1310 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1311 (Window
= Parent
->FirstChild
))
1313 BOOL bGoDown
= TRUE
;
1315 Status
= STATUS_SUCCESS
;
1320 if(dwCount
++ < *pBufSize
&& pWnd
)
1324 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1325 *pWnd
= Window
->hSelf
;
1328 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1330 Status
= _SEH2_GetExceptionCode();
1333 if(!NT_SUCCESS(Status
))
1335 SetLastNtError(Status
);
1339 if (Window
->FirstChild
&& bChildren
)
1341 Window
= Window
->FirstChild
;
1346 if (Window
->NextSibling
)
1348 Window
= Window
->NextSibling
;
1352 Window
= Window
->Parent
;
1353 if (Window
== Parent
)
1362 ObDereferenceObject(Desktop
);
1368 PTHREADINFO W32Thread
;
1369 PLIST_ENTRY Current
;
1370 PWINDOW_OBJECT Window
;
1372 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1373 if(!NT_SUCCESS(Status
))
1375 return ERROR_INVALID_PARAMETER
;
1377 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1379 ObDereferenceObject(Thread
);
1380 DPRINT("Thread is not a GUI Thread!\n");
1381 return ERROR_INVALID_PARAMETER
;
1384 Current
= W32Thread
->WindowListHead
.Flink
;
1385 while(Current
!= &(W32Thread
->WindowListHead
))
1387 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1390 if(bChildren
|| Window
->hOwner
!= NULL
)
1392 if(dwCount
< *pBufSize
&& pWnd
)
1394 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1395 if(!NT_SUCCESS(Status
))
1397 SetLastNtError(Status
);
1403 Current
= Current
->Flink
;
1406 ObDereferenceObject(Thread
);
1409 *pBufSize
= dwCount
;
1410 return STATUS_SUCCESS
;
1418 NtUserChildWindowFromPointEx(HWND hwndParent
,
1423 PWINDOW_OBJECT Parent
;
1428 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1436 if(Parent
->hSelf
!= IntGetDesktopWindow())
1438 Pt
.x
+= Parent
->Wnd
->rcClient
.left
;
1439 Pt
.y
+= Parent
->Wnd
->rcClient
.top
;
1442 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1447 Ret
= Parent
->hSelf
;
1448 if((List
= IntWinListChildren(Parent
)))
1450 for(phWnd
= List
; *phWnd
; phWnd
++)
1452 PWINDOW_OBJECT Child
;
1454 if((Child
= UserGetWindowObject(*phWnd
)))
1456 ChildWnd
= Child
->Wnd
;
1457 if(!(ChildWnd
->style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1461 if((ChildWnd
->style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1465 if((ChildWnd
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1469 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1484 * calculates the default position of a window
1487 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT Window
, RECTL
*rc
, BOOL IncPos
)
1494 RECTL_bIntersectRect(rc
, rc
, &Parent
->Wnd
->rcClient
);
1498 Pos
.x
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1499 Pos
.y
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1500 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1501 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1503 /* reset counter and position */
1506 Parent
->TiledCounter
= 0;
1508 Parent
->TiledCounter
++;
1519 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1520 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1524 rc
->right
= rc
->left
+ Sz
.cx
;
1525 rc
->bottom
= rc
->top
+ Sz
.cy
;
1534 co_IntCreateWindowEx(DWORD dwExStyle
,
1535 PUNICODE_STRING ClassName
,
1536 PUNICODE_STRING WindowName
,
1544 HINSTANCE hInstance
,
1547 BOOL bUnicodeWindow
)
1549 PWINSTATION_OBJECT WinSta
;
1551 PCLS
*ClassLink
, Class
= NULL
;
1553 PWINDOW_OBJECT Window
= NULL
;
1554 PWINDOW_OBJECT ParentWindow
= NULL
, OwnerWindow
;
1555 HWND ParentWindowHandle
= NULL
;
1556 HWND OwnerWindowHandle
;
1557 PMENU_OBJECT SystemMenu
;
1561 PTHREADINFO ti
= NULL
;
1564 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1570 CBT_CREATEWNDW CbtCreate
;
1573 DECLARE_RETURN(PWND
);
1575 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1578 pti
= PsGetCurrentThreadWin32Thread();
1582 ParentWindowHandle
= pti
->Desktop
->DesktopWindow
;
1585 OwnerWindowHandle
= NULL
;
1587 if (hWndParent
== HWND_MESSAGE
)
1590 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1591 * message window (style: WS_POPUP|WS_DISABLED)
1593 ParentWindowHandle
= IntGetMessageWindow();
1594 DPRINT("Parent is HWND_MESSAGE 0x%x\n", ParentWindowHandle
);
1596 else if (hWndParent
)
1598 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1600 PWINDOW_OBJECT Par
= UserGetWindowObject(hWndParent
), Root
;
1601 if (Par
&& (Root
= UserGetAncestor(Par
, GA_ROOT
)))
1602 OwnerWindowHandle
= Root
->hSelf
;
1605 ParentWindowHandle
= hWndParent
;
1607 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1609 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1610 RETURN( (PWND
)0); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1613 if (ParentWindowHandle
)
1615 ParentWindow
= UserGetWindowObject(ParentWindowHandle
);
1617 if (ParentWindow
) UserRefObjectCo(ParentWindow
, &ParentRef
);
1621 ParentWindow
= NULL
;
1624 /* FIXME: parent must belong to the current process */
1626 /* Check the window station. */
1627 ti
= GetW32ThreadInfo();
1628 if (ti
== NULL
|| pti
->Desktop
== NULL
)
1630 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1634 /* Check the class. */
1636 ClassAtom
= IntGetClassAtom(ClassName
,
1642 if (ClassAtom
== (RTL_ATOM
)0)
1644 if (IS_ATOM(ClassName
->Buffer
))
1646 DPRINT1("Class 0x%p not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1650 DPRINT1("Class \"%wZ\" not found\n", ClassName
);
1653 SetLastWin32Error(ERROR_CANNOT_FIND_WND_CLASS
);
1657 Class
= IntReferenceClass(Class
,
1662 DPRINT1("Failed to reference window class!\n");
1666 WinSta
= pti
->Desktop
->WindowStation
;
1668 //FIXME: Reference thread/desktop instead
1669 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1671 /* Create the window object. */
1672 Window
= (PWINDOW_OBJECT
) UserCreateObject( gHandleTable
,
1675 sizeof(WINDOW_OBJECT
));
1678 Window
->Wnd
= DesktopHeapAlloc(pti
->Desktop
,
1679 sizeof(WND
) + Class
->cbwndExtra
);
1682 RtlZeroMemory(Window
->Wnd
,
1683 sizeof(WND
) + Class
->cbwndExtra
);
1684 Window
->Wnd
->head
.h
= hWnd
;
1688 Wnd
->head
.rpdesk
= pti
->Desktop
;
1689 Wnd
->hWndLastActive
= hWnd
;
1690 Wnd
->state2
|= WNDS2_WIN40COMPAT
;
1693 DPRINT("Created object with handle %X\n", hWnd
);
1697 ObDereferenceObject(WinSta
);
1698 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1702 UserRefObjectCo(Window
, &Ref
);
1704 ObDereferenceObject(WinSta
);
1706 if (NULL
== pti
->Desktop
->DesktopWindow
)
1708 /* If there is no desktop window yet, we must be creating it */
1709 pti
->Desktop
->DesktopWindow
= hWnd
;
1710 pti
->Desktop
->DesktopInfo
->Wnd
= Wnd
;
1714 * Fill out the structure describing it.
1720 Window
->SystemMenu
= (HMENU
)0;
1722 Wnd
->hModule
= hInstance
;
1723 Window
->hSelf
= hWnd
;
1725 Window
->MessageQueue
= pti
->MessageQueue
;
1726 IntReferenceMessageQueue(Window
->MessageQueue
);
1727 Window
->Parent
= ParentWindow
;
1728 Wnd
->spwndParent
= ParentWindow
? ParentWindow
->Wnd
: NULL
;
1729 if (Wnd
->spwndParent
!= NULL
&& hWndParent
!= 0)
1731 Wnd
->HideFocus
= Wnd
->spwndParent
->HideFocus
;
1732 Wnd
->HideAccel
= Wnd
->spwndParent
->HideAccel
;
1735 if((OwnerWindow
= UserGetWindowObject(OwnerWindowHandle
)))
1737 Window
->hOwner
= OwnerWindowHandle
;
1738 Wnd
->spwndOwner
= OwnerWindow
->Wnd
;
1743 Window
->hOwner
= NULL
;
1744 Wnd
->spwndOwner
= NULL
;
1748 Wnd
->dwUserData
= 0;
1750 Wnd
->IsSystem
= Wnd
->pcls
->System
;
1752 /* BugBoy Comments: Comment below say that System classes are always created as UNICODE.
1753 In windows, creating a window with the ANSI version of CreateWindow sets the window
1754 to ansi as verified by testing with IsUnicodeWindow API.
1756 No where can I see in code or through testing does the window change back to ANSI
1757 after being created as UNICODE in ROS. I didnt do more testing to see what problems this would cause.*/
1758 // See NtUserDefSetText! We convert to Unicode all the time and never use Mix. (jt)
1759 if (Wnd
->pcls
->System
)
1761 /* NOTE: Always create a unicode window for system classes! */
1762 Wnd
->Unicode
= TRUE
;
1763 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
1764 Wnd
->WndProcExtra
= Wnd
->pcls
->WndProcExtra
;
1768 Wnd
->Unicode
= Wnd
->pcls
->Unicode
;
1769 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
1770 Wnd
->CallProc
= NULL
;
1773 Window
->OwnerThread
= PsGetCurrentThread();
1774 Window
->FirstChild
= NULL
;
1775 Window
->LastChild
= NULL
;
1776 Window
->PrevSibling
= NULL
;
1777 Window
->NextSibling
= NULL
;
1778 Wnd
->cbwndExtra
= Wnd
->pcls
->cbwndExtra
;
1780 InitializeListHead(&Wnd
->PropListHead
);
1781 InitializeListHead(&Window
->WndObjListHead
);
1783 if ( NULL
!= WindowName
->Buffer
&& WindowName
->Length
> 0 )
1785 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
1786 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1787 if (Wnd
->strName
.Buffer
== NULL
)
1789 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1793 Wnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1796 RtlCopyMemory(Wnd
->strName
.Buffer
,
1798 WindowName
->Length
);
1799 Wnd
->strName
.Length
= WindowName
->Length
;
1801 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1803 WindowName
->Length
= 0;
1804 Wnd
->strName
.Buffer
[0] = L
'\0';
1810 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1811 * tested for WS_POPUP
1813 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1814 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1815 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1816 dwExStyle
|= WS_EX_WINDOWEDGE
;
1818 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1820 /* Correct the window style. */
1821 if (!(dwStyle
& WS_CHILD
))
1823 dwStyle
|= WS_CLIPSIBLINGS
;
1824 DPRINT("3: Style is now %lx\n", dwStyle
);
1825 if (!(dwStyle
& WS_POPUP
))
1827 dwStyle
|= WS_CAPTION
;
1828 Window
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1829 DPRINT("4: Style is now %lx\n", dwStyle
);
1833 /* create system menu */
1834 if((dwStyle
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1836 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
1839 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1840 IntReleaseMenuObject(SystemMenu
);
1844 /* Set the window menu */
1845 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1848 IntSetMenu(Window
, hMenu
, &MenuChanged
);
1849 else if (Wnd
->pcls
->lpszMenuName
) // Take it from the parent.
1851 UNICODE_STRING MenuName
;
1852 if (IS_INTRESOURCE(Wnd
->pcls
->lpszMenuName
))
1854 MenuName
.Length
= 0;
1855 MenuName
.MaximumLength
= 0;
1856 MenuName
.Buffer
= Wnd
->pcls
->lpszMenuName
;
1860 RtlInitUnicodeString( &MenuName
, Wnd
->pcls
->lpszMenuName
);
1862 hMenu
= co_IntCallLoadMenu( Wnd
->pcls
->hModule
, &MenuName
);
1863 if (hMenu
) IntSetMenu(Window
, hMenu
, &MenuChanged
);
1867 Wnd
->IDMenu
= (UINT
) hMenu
;
1869 /* Insert the window into the thread's window list. */
1870 InsertTailList (&pti
->WindowListHead
, &Window
->ThreadListEntry
);
1872 /* Handle "CS_CLASSDC", it is tested first. */
1873 if ((Wnd
->pcls
->style
& CS_CLASSDC
) && !(Wnd
->pcls
->pdce
)) // One DCE per class to have CLASS.
1874 Wnd
->pcls
->pdce
= DceAllocDCE(Window
, DCE_CLASS_DC
);
1875 /* Allocate a DCE for this window. */
1876 else if ( Wnd
->pcls
->style
& CS_OWNDC
)
1877 Window
->Dce
= DceAllocDCE(Window
, DCE_WINDOW_DC
);
1884 Wnd
->ExStyle
= dwExStyle
;
1885 Wnd
->style
= dwStyle
& ~WS_VISIBLE
;
1888 Cs
.lpCreateParams
= lpParam
;
1889 Cs
.hInstance
= hInstance
;
1891 Cs
.hwndParent
= hWndParent
; //Pass the original Parent handle!
1896 Cs
.style
= Wnd
->style
;
1897 // Cs.lpszName = (LPCWSTR) WindowName->Buffer;
1898 // Cs.lpszClass = (LPCWSTR) ClassName->Buffer;
1899 Cs
.lpszName
= (LPCWSTR
) WindowName
;
1900 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
1901 Cs
.dwExStyle
= dwExStyle
;
1902 CbtCreate
.lpcs
= &Cs
;
1903 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1904 if (ISITHOOKED(WH_CBT
))
1906 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) &CbtCreate
))
1908 /* FIXME - Delete window object and remove it from the thread windows list */
1909 /* FIXME - delete allocated DCE */
1910 DPRINT1("CBT-hook returned !0\n");
1911 RETURN( (PWND
) NULL
);
1918 // FIXME: Need to set the Z order in the window link list if the hook callback changed it!
1919 // hwndInsertAfter = CbtCreate.hwndInsertAfter;
1921 /* default positioning for overlapped windows */
1922 if(!(Wnd
->style
& (WS_POPUP
| WS_CHILD
)))
1925 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1926 BOOL CalculatedDefPosSize
= FALSE
;
1928 IntGetDesktopWorkArea(((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
, &WorkArea
);
1931 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1933 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1935 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, Window
, &rc
, TRUE
);
1937 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1939 ProcessParams
->WindowFlags
&= ~STARTF_USEPOSITION
;
1940 Pos
.x
= WorkArea
.left
+ ProcessParams
->StartingX
;
1941 Pos
.y
= WorkArea
.top
+ ProcessParams
->StartingY
;
1950 According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
1951 y is something else. and Quote!
1954 /* Never believe Microsoft's documentation... CreateWindowEx doc says
1955 * that if an overlapped window is created with WS_VISIBLE style bit
1956 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
1957 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
1960 * 1) not only it checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
1961 * 2) it does not ignore the y parameter as the docs claim; instead, it
1962 * uses it as second parameter to ShowWindow() unless y is either
1963 * CW_USEDEFAULT or CW_USEDEFAULT16.
1965 * The fact that we didn't do 2) caused bogus windows pop up when wine
1966 * was running apps that were using this obscure feature. Example -
1967 * calc.exe that comes with Win98 (only Win98, it's different from
1968 * the one that comes with Win95 and NT)
1970 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
1975 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1977 if(!CalculatedDefPosSize
)
1979 IntCalcDefPosSize(ParentWindow
, Window
, &rc
, FALSE
);
1981 if(ProcessParams
->WindowFlags
& STARTF_USESIZE
)
1983 ProcessParams
->WindowFlags
&= ~STARTF_USESIZE
;
1984 Size
.cx
= ProcessParams
->CountX
;
1985 Size
.cy
= ProcessParams
->CountY
;
1989 Size
.cx
= rc
.right
- rc
.left
;
1990 Size
.cy
= rc
.bottom
- rc
.top
;
1993 /* move the window if necessary */
1995 Pos
.x
= max(rc
.left
, 0);
1997 Pos
.y
= max(rc
.top
, 0);
2002 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
2003 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
2008 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
2015 /* Initialize the window dimensions. */
2016 Wnd
->rcWindow
.left
= Pos
.x
;
2017 Wnd
->rcWindow
.top
= Pos
.y
;
2018 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
2019 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
2020 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2022 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2023 ParentWindow
->Wnd
->rcClient
.top
);
2025 Wnd
->rcClient
= Wnd
->rcWindow
;
2028 * Get the size and position of the window.
2030 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
2032 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2034 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
2035 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
,
2037 if (MaxSize
.x
< Size
.cx
)
2038 Size
.cx
= MaxSize
.x
;
2039 if (MaxSize
.y
< Size
.cy
)
2040 Size
.cy
= MaxSize
.y
;
2041 if (Size
.cx
< MinTrack
.x
)
2042 Size
.cx
= MinTrack
.x
;
2043 if (Size
.cy
< MinTrack
.y
)
2044 Size
.cy
= MinTrack
.y
;
2051 Wnd
->rcWindow
.left
= Pos
.x
;
2052 Wnd
->rcWindow
.top
= Pos
.y
;
2053 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
2054 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
2055 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2057 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2058 ParentWindow
->Wnd
->rcClient
.top
);
2060 Wnd
->rcClient
= Wnd
->rcWindow
;
2062 /* FIXME: Initialize the window menu. */
2064 /* Send a NCCREATE message. */
2070 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
2071 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, Size
.cx
, Size
.cy
);
2072 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
2073 Result
= co_IntSendMessage(Window
->hSelf
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
2076 /* FIXME: Cleanup. */
2077 DPRINT1("IntCreateWindowEx(): NCCREATE message failed. No cleanup performed!\n");
2081 /* Calculate the non-client size. */
2082 MaxPos
.x
= Window
->Wnd
->rcWindow
.left
;
2083 MaxPos
.y
= Window
->Wnd
->rcWindow
.top
;
2086 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
2087 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
2088 Result
= co_WinPosGetNonClientSize(Window
,
2089 &Window
->Wnd
->rcWindow
,
2090 &Window
->Wnd
->rcClient
);
2092 RECTL_vOffsetRect(&Window
->Wnd
->rcWindow
,
2093 MaxPos
.x
- Window
->Wnd
->rcWindow
.left
,
2094 MaxPos
.y
- Window
->Wnd
->rcWindow
.top
);
2097 if (NULL
!= ParentWindow
)
2099 /* link the window into the parent's child list */
2100 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2102 PWINDOW_OBJECT PrevSibling
;
2104 PrevSibling
= ParentWindow
->LastChild
;
2106 /* link window as bottom sibling */
2107 IntLinkWindow(Window
, ParentWindow
, PrevSibling
/*prev sibling*/);
2111 /* link window as top sibling (but after topmost siblings) */
2112 PWINDOW_OBJECT InsertAfter
, Sibling
;
2113 if (!(dwExStyle
& WS_EX_TOPMOST
))
2116 Sibling
= ParentWindow
->FirstChild
;
2117 while (Sibling
&& (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
2119 InsertAfter
= Sibling
;
2120 Sibling
= Sibling
->NextSibling
;
2128 IntLinkWindow(Window
, ParentWindow
, InsertAfter
/* prev sibling */);
2133 /* Send the WM_CREATE message. */
2134 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
2135 Result
= co_IntSendMessage(Window
->hSelf
, WM_CREATE
, 0, (LPARAM
) &Cs
);
2137 if (Result
== (LRESULT
)-1)
2139 /* FIXME: Cleanup. */
2140 DPRINT1("IntCreateWindowEx(): send CREATE message failed. No cleanup performed!\n");
2141 IntUnlinkWindow(Window
);
2145 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
->Wnd
, OBJID_WINDOW
, 0);
2147 /* Send move and size messages. */
2148 if (!(Window
->Flags
& WINDOWOBJECT_NEED_SIZE
))
2152 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
2154 if ((Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
) < 0 ||
2155 (Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
) < 0)
2157 DPRINT("Sending bogus WM_SIZE\n");
2160 lParam
= MAKE_LONG(Window
->Wnd
->rcClient
.right
-
2161 Window
->Wnd
->rcClient
.left
,
2162 Window
->Wnd
->rcClient
.bottom
-
2163 Window
->Wnd
->rcClient
.top
);
2164 co_IntSendMessage(Window
->hSelf
, WM_SIZE
, SIZE_RESTORED
,
2167 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
2169 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2171 lParam
= MAKE_LONG(Wnd
->rcClient
.left
- ParentWindow
->Wnd
->rcClient
.left
,
2172 Wnd
->rcClient
.top
- ParentWindow
->Wnd
->rcClient
.top
);
2176 lParam
= MAKE_LONG(Wnd
->rcClient
.left
,
2180 co_IntSendMessage(Window
->hSelf
, WM_MOVE
, 0, lParam
);
2182 /* Call WNDOBJ change procs */
2183 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
2186 /* Show or maybe minimize or maximize the window. */
2187 if (Wnd
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2192 SwFlag
= (Wnd
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
2195 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2197 SwFlag
= ((Wnd
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2198 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2199 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2201 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
2202 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
2203 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2204 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2207 /* Notify the parent window of a new child. */
2208 if ((Wnd
->style
& WS_CHILD
) &&
2209 (!(Wnd
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
2211 DPRINT("IntCreateWindow(): About to notify parent\n");
2212 co_IntSendMessage(ParentWindow
->hSelf
,
2214 MAKEWPARAM(WM_CREATE
, Wnd
->IDMenu
),
2215 (LPARAM
)Window
->hSelf
);
2218 if ((!hWndParent
) && (!HasOwner
))
2220 DPRINT("Sending CREATED notify\n");
2221 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2225 DPRINT("Not sending CREATED notify, %x %d\n", ParentWindow
, HasOwner
);
2228 /* Initialize and show the window's scrollbars */
2229 if (Wnd
->style
& WS_VSCROLL
)
2231 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2233 if (Wnd
->style
& WS_HSCROLL
)
2235 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2238 if (dwStyle
& WS_VISIBLE
)
2240 if (Wnd
->style
& WS_MAXIMIZE
)
2241 dwShowMode
= SW_SHOW
;
2242 else if (Wnd
->style
& WS_MINIMIZE
)
2243 dwShowMode
= SW_SHOWMINIMIZED
;
2245 DPRINT("IntCreateWindow(): About to show window\n");
2246 co_WinPosShowWindow(Window
, dwShowMode
);
2248 if (Wnd
->ExStyle
& WS_EX_MDICHILD
)
2250 co_IntSendMessage(ParentWindow
->hSelf
, WM_MDIREFRESHMENU
, 0, 0);
2251 /* ShowWindow won't activate child windows */
2252 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2256 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
2257 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
2258 Dont understand why it does this. */
2259 if (ClassAtom
== gpsi
->atomSysClass
[ICLS_EDIT
])
2261 PCALLPROCDATA CallProc
;
2262 //CallProc = CreateCallProc(NULL, Wnd->lpfnWndProc, bUnicodeWindow, Wnd->ti->ppi);
2263 CallProc
= CreateCallProc(NULL
, Wnd
->lpfnWndProc
, Wnd
->Unicode
, Wnd
->head
.pti
->ppi
);
2267 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2268 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
2272 UserAddCallProcToClass(Wnd
->pcls
, CallProc
);
2273 Wnd
->CallProc
= CallProc
;
2274 Wnd
->IsSystem
= FALSE
;
2278 DPRINT("IntCreateWindow(): = %X\n", hWnd
);
2279 DPRINT("WindowObject->SystemMenu = 0x%x\n", Window
->SystemMenu
);
2283 if (!_ret_
&& Window
&& Window
->Wnd
&& ti
)
2284 UserFreeWindowInfo(ti
, Window
);
2287 UserDerefObjectCo(Window
);
2288 UserDereferenceObject(Window
);
2290 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2291 if (!_ret_
&& ti
!= NULL
)
2295 IntDereferenceClass(Class
,
2304 NtUserCreateWindowEx(DWORD dwExStyle
,
2305 PUNICODE_STRING UnsafeClassName
,
2306 PUNICODE_STRING UnsafeWindowName
,
2314 HINSTANCE hInstance
,
2317 BOOL bUnicodeWindow
,
2321 UNICODE_STRING WindowName
;
2322 UNICODE_STRING ClassName
;
2323 HWND NewWindow
= NULL
;
2325 DECLARE_RETURN(HWND
);
2327 DPRINT("Enter NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2328 UserEnterExclusive();
2330 /* Get the class name (string or atom) */
2331 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
2332 if (! NT_SUCCESS(Status
))
2334 SetLastNtError(Status
);
2337 if (ClassName
.Length
!= 0)
2339 Status
= IntSafeCopyUnicodeStringTerminateNULL(&ClassName
, UnsafeClassName
);
2340 if (! NT_SUCCESS(Status
))
2342 SetLastNtError(Status
);
2346 else if (! IS_ATOM(ClassName
.Buffer
))
2348 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2352 /* safely copy the window name */
2353 if (NULL
!= UnsafeWindowName
)
2355 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
2356 if (! NT_SUCCESS(Status
))
2358 if (! IS_ATOM(ClassName
.Buffer
))
2360 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2362 SetLastNtError(Status
);
2368 RtlInitUnicodeString(&WindowName
, NULL
);
2371 pNewWindow
= co_IntCreateWindowEx( dwExStyle
,
2386 if (pNewWindow
) NewWindow
= UserHMGetHandle(pNewWindow
);
2388 if (WindowName
.Buffer
)
2390 ExFreePoolWithTag(WindowName
.Buffer
, TAG_STRING
);
2392 if (! IS_ATOM(ClassName
.Buffer
))
2394 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2400 DPRINT("Leave NtUserCreateWindowEx, ret=%i\n",_ret_
);
2409 NtUserDeferWindowPos(HDWP WinPosInfo
,
2411 HWND WndInsertAfter
,
2424 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2430 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2432 hWnd
= Window
->hSelf
;
2436 if (!Wnd
) return TRUE
; // FIXME: Need to finish object rewrite or lock the thread when killing the window!
2438 /* Check for owner thread */
2439 if ((Window
->OwnerThread
!= PsGetCurrentThread()))
2441 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2446 if (ISITHOOKED(WH_CBT
))
2448 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0)) return FALSE
;
2451 /* Look whether the focus is within the tree of windows we will
2454 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2456 if (UserGetActiveWindow() == Window
->hSelf
)
2458 co_WinPosActivateOtherWindow(Window
);
2462 if (Window
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2463 Window
->MessageQueue
->ActiveWindow
= NULL
;
2464 if (Window
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2465 Window
->MessageQueue
->FocusWindow
= NULL
;
2466 if (Window
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2467 Window
->MessageQueue
->CaptureWindow
= NULL
;
2469 IntDereferenceMessageQueue(Window
->MessageQueue
);
2471 IntEngWindowChanged(Window
, WOC_DELETE
);
2472 isChild
= (0 != (Wnd
->style
& WS_CHILD
));
2478 if (! USER_IsExitingThread(GetCurrentThreadId()))
2480 send_parent_notify(hwnd
, WM_DESTROY
);
2483 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2485 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2486 /* FIXME: clean up palette - see "Internals" p.352 */
2490 if (!IntIsWindow(Window
->hSelf
))
2495 /* Recursively destroy owned windows */
2500 BOOL GotOne
= FALSE
;
2503 PWINDOW_OBJECT Child
, Desktop
;
2505 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2506 UserGetWindowObject(IntGetDesktopWindow());
2507 Children
= IntWinListChildren(Desktop
);
2511 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2513 Child
= UserGetWindowObject(*ChildHandle
);
2516 if (Child
->hOwner
!= Window
->hSelf
)
2521 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2523 USER_REFERENCE_ENTRY ChildRef
;
2524 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2525 co_UserDestroyWindow(Child
);
2526 UserDerefObjectCo(Child
);//temp hack?
2532 if (Child
->hOwner
!= NULL
)
2534 Child
->hOwner
= NULL
;
2535 Child
->Wnd
->spwndOwner
= NULL
;
2539 ExFreePool(Children
);
2548 if (!IntIsWindow(Window
->hSelf
))
2553 /* Destroy the window storage */
2554 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2566 NtUserDestroyWindow(HWND Wnd
)
2568 PWINDOW_OBJECT Window
;
2569 DECLARE_RETURN(BOOLEAN
);
2571 USER_REFERENCE_ENTRY Ref
;
2573 DPRINT("Enter NtUserDestroyWindow\n");
2574 UserEnterExclusive();
2576 if (!(Window
= UserGetWindowObject(Wnd
)))
2581 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2582 ret
= co_UserDestroyWindow(Window
);
2583 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2588 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2600 NtUserDrawMenuBarTemp(
2607 /* we'll use this function just for caching the menu bar */
2617 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2627 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2633 NtUserFillWindow(HWND hWndPaint
,
2644 static HWND FASTCALL
2645 IntFindWindow(PWINDOW_OBJECT Parent
,
2646 PWINDOW_OBJECT ChildAfter
,
2648 PUNICODE_STRING WindowName
)
2650 BOOL CheckWindowName
;
2656 CheckWindowName
= WindowName
->Length
!= 0;
2658 if((List
= IntWinListChildren(Parent
)))
2663 /* skip handles before and including ChildAfter */
2664 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2668 /* search children */
2671 PWINDOW_OBJECT Child
;
2672 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2677 /* Do not send WM_GETTEXT messages in the kernel mode version!
2678 The user mode version however calls GetWindowText() which will
2679 send WM_GETTEXT messages to windows belonging to its processes */
2680 if((!CheckWindowName
|| !RtlCompareUnicodeString(WindowName
, &(Child
->Wnd
->strName
), TRUE
)) &&
2681 (!ClassAtom
|| Child
->Wnd
->pcls
->atomClassName
== ClassAtom
))
2696 * Searches a window's children for a window with the specified
2699 * hwndParent = The window whose childs are to be searched.
2701 * HWND_MESSAGE = message-only windows
2703 * hwndChildAfter = Search starts after this child window.
2704 * NULL = start from beginning
2706 * ucClassName = Class name to search for
2707 * Reguired parameter.
2709 * ucWindowName = Window name
2710 * ->Buffer == NULL = don't care
2713 * The HWND of the window if it was found, otherwise NULL
2719 NtUserFindWindowEx(HWND hwndParent
,
2720 HWND hwndChildAfter
,
2721 PUNICODE_STRING ucClassName
,
2722 PUNICODE_STRING ucWindowName
,
2725 PWINDOW_OBJECT Parent
, ChildAfter
;
2726 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2727 HWND Desktop
, Ret
= NULL
;
2728 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2729 DECLARE_RETURN(HWND
);
2731 DPRINT("Enter NtUserFindWindowEx\n");
2734 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2738 if (ucClassName
!= NULL
)
2740 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2741 if (ClassName
.Length
!= 0)
2743 ProbeForRead(ClassName
.Buffer
,
2747 else if (!IS_ATOM(ClassName
.Buffer
))
2749 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2753 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2760 if (ucWindowName
!= NULL
)
2762 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2763 if (WindowName
.Length
!= 0)
2765 ProbeForRead(WindowName
.Buffer
,
2771 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2773 SetLastNtError(_SEH2_GetExceptionCode());
2774 _SEH2_YIELD(RETURN(NULL
));
2778 if (ucClassName
!= NULL
)
2780 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2781 !IS_ATOM(ClassName
.Buffer
))
2783 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2786 else if (ClassAtom
== (RTL_ATOM
)0)
2788 /* LastError code was set by IntGetAtomFromStringOrAtom */
2794 Desktop
= IntGetCurrentThreadDesktopWindow();
2796 if(hwndParent
== NULL
)
2797 hwndParent
= Desktop
;
2798 else if(hwndParent
== HWND_MESSAGE
)
2800 hwndParent
= IntGetMessageWindow();
2803 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2809 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2816 if(Parent
->hSelf
== Desktop
)
2819 PWINDOW_OBJECT TopLevelWindow
;
2820 BOOLEAN CheckWindowName
;
2821 BOOLEAN WindowMatches
;
2822 BOOLEAN ClassMatches
;
2824 /* windows searches through all top-level windows if the parent is the desktop
2827 if((List
= IntWinListChildren(Parent
)))
2833 /* skip handles before and including ChildAfter */
2834 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2838 CheckWindowName
= WindowName
.Length
!= 0;
2840 /* search children */
2843 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2848 /* Do not send WM_GETTEXT messages in the kernel mode version!
2849 The user mode version however calls GetWindowText() which will
2850 send WM_GETTEXT messages to windows belonging to its processes */
2851 WindowMatches
= !CheckWindowName
|| !RtlCompareUnicodeString(
2852 &WindowName
, &TopLevelWindow
->Wnd
->strName
, TRUE
);
2853 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2854 ClassAtom
== TopLevelWindow
->Wnd
->pcls
->atomClassName
;
2856 if (WindowMatches
&& ClassMatches
)
2858 Ret
= TopLevelWindow
->hSelf
;
2862 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2864 /* window returns the handle of the top-level window, in case it found
2866 Ret
= TopLevelWindow
->hSelf
;
2875 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2879 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2881 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2882 search the message-only windows. Should this also be done if
2883 Parent is the desktop window??? */
2884 PWINDOW_OBJECT MsgWindows
;
2886 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2888 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2893 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2895 SetLastNtError(_SEH2_GetExceptionCode());
2903 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2913 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
2924 PWINDOW_OBJECT FASTCALL
UserGetAncestor(PWINDOW_OBJECT Wnd
, UINT Type
)
2926 PWINDOW_OBJECT WndAncestor
, Parent
;
2928 if (Wnd
->hSelf
== IntGetDesktopWindow())
2937 WndAncestor
= Wnd
->Parent
;
2948 if(!(Parent
= WndAncestor
->Parent
))
2952 if(IntIsDesktopWindow(Parent
))
2957 WndAncestor
= Parent
;
2968 PWINDOW_OBJECT Parent
, Old
;
2971 Parent
= IntGetParent(WndAncestor
);
2979 // UserDereferenceObject(Parent);
2981 WndAncestor
= Parent
;
3001 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3003 PWINDOW_OBJECT Window
, Ancestor
;
3004 DECLARE_RETURN(HWND
);
3006 DPRINT("Enter NtUserGetAncestor\n");
3007 UserEnterExclusive();
3009 if (!(Window
= UserGetWindowObject(hWnd
)))
3014 Ancestor
= UserGetAncestor(Window
, Type
);
3015 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3017 RETURN(Ancestor
? Ancestor
->hSelf
: NULL
);
3020 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3028 NtUserGetComboBoxInfo(
3033 DECLARE_RETURN(BOOL
);
3035 DPRINT("Enter NtUserGetComboBoxInfo\n");
3038 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3047 sizeof(COMBOBOXINFO
),
3051 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3053 SetLastNtError(_SEH2_GetExceptionCode());
3054 _SEH2_YIELD(RETURN(FALSE
));
3058 // Pass the user pointer, it was already probed.
3059 RETURN( (BOOL
) co_IntSendMessage( Wnd
->hSelf
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3062 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3072 NtUserGetInternalWindowPos( HWND hWnd
,
3076 PWINDOW_OBJECT Window
;
3080 WINDOWPLACEMENT wndpl
;
3084 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3095 ProbeForWrite(rectWnd
,
3101 ProbeForWrite(ptIcon
,
3107 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3109 SetLastNtError(_SEH2_GetExceptionCode());
3114 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3116 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3122 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3126 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3130 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3132 SetLastNtError(_SEH2_GetExceptionCode());
3137 if (!Hit
) Ret
= wndpl
.showCmd
;
3146 NtUserGetListBoxInfo(
3150 DECLARE_RETURN(DWORD
);
3152 DPRINT("Enter NtUserGetListBoxInfo\n");
3155 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3160 RETURN( (DWORD
) co_IntSendMessage( Wnd
->hSelf
, LB_GETLISTBOXINFO
, 0, 0 ));
3163 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3170 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3172 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3173 HWND hWndOldParent
= NULL
;
3174 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3176 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3178 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3182 if (hWndChild
== IntGetDesktopWindow())
3184 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3190 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3197 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3203 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3208 UserRefObjectCo(Wnd
, &Ref
);
3209 UserRefObjectCo(WndParent
, &ParentRef
);
3211 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3213 UserDerefObjectCo(WndParent
);
3214 UserDerefObjectCo(Wnd
);
3218 hWndOldParent
= WndOldParent
->hSelf
;
3219 UserDereferenceObject(WndOldParent
);
3222 return( hWndOldParent
);
3230 * The NtUserSetParent function changes the parent window of the specified
3234 * The new parent window and the child window must belong to the same
3235 * application. If the window identified by the hWndChild parameter is
3236 * visible, the system performs the appropriate redrawing and repainting.
3237 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3238 * or WS_POPUP window styles of the window whose parent is being changed.
3245 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3247 DECLARE_RETURN(HWND
);
3249 DPRINT("Enter NtUserSetParent\n");
3250 UserEnterExclusive();
3253 Check Parent first from user space, set it here.
3257 hWndNewParent
= IntGetDesktopWindow();
3259 else if (hWndNewParent
== HWND_MESSAGE
)
3261 hWndNewParent
= IntGetMessageWindow();
3264 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3267 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3275 * UserGetShellWindow
3277 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3282 HWND FASTCALL
UserGetShellWindow(VOID
)
3284 PWINSTATION_OBJECT WinStaObject
;
3287 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3292 if (!NT_SUCCESS(Status
))
3294 SetLastNtError(Status
);
3298 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3300 ObDereferenceObject(WinStaObject
);
3305 * NtUserSetShellWindowEx
3307 * This is undocumented function to set global shell window. The global
3308 * shell window has special handling of window position.
3314 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3316 PWINSTATION_OBJECT WinStaObject
;
3317 PWINDOW_OBJECT WndShell
;
3318 DECLARE_RETURN(BOOL
);
3319 USER_REFERENCE_ENTRY Ref
;
3323 DPRINT("Enter NtUserSetShellWindowEx\n");
3324 UserEnterExclusive();
3326 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3331 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3336 if (!NT_SUCCESS(Status
))
3338 SetLastNtError(Status
);
3343 * Test if we are permitted to change the shell window.
3345 if (WinStaObject
->ShellWindow
)
3347 ObDereferenceObject(WinStaObject
);
3352 * Move shell window into background.
3354 if (hwndListView
&& hwndListView
!= hwndShell
)
3357 * Disabled for now to get Explorer working.
3358 * -- Filip, 01/nov/2003
3361 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3364 if (UserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3366 ObDereferenceObject(WinStaObject
);
3371 if (UserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3373 ObDereferenceObject(WinStaObject
);
3377 UserRefObjectCo(WndShell
, &Ref
);
3378 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3380 WinStaObject
->ShellWindow
= hwndShell
;
3381 WinStaObject
->ShellListView
= hwndListView
;
3383 ti
= GetW32ThreadInfo();
3384 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3386 UserDerefObjectCo(WndShell
);
3388 ObDereferenceObject(WinStaObject
);
3392 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3398 * NtUserGetSystemMenu
3400 * The NtUserGetSystemMenu function allows the application to access the
3401 * window menu (also known as the system menu or the control menu) for
3402 * copying and modifying.
3406 * Handle to the window that will own a copy of the window menu.
3408 * Specifies the action to be taken. If this parameter is FALSE,
3409 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3410 * currently in use. The copy is initially identical to the window menu
3411 * but it can be modified.
3412 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3413 * to the default state. The previous window menu, if any, is destroyed.
3416 * If the bRevert parameter is FALSE, the return value is a handle to a
3417 * copy of the window menu. If the bRevert parameter is TRUE, the return
3425 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3427 PWINDOW_OBJECT Window
;
3429 DECLARE_RETURN(HMENU
);
3431 DPRINT("Enter NtUserGetSystemMenu\n");
3434 if (!(Window
= UserGetWindowObject(hWnd
)))
3439 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3444 RETURN(Menu
->MenuInfo
.Self
);
3447 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3453 * NtUserSetSystemMenu
3460 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3462 BOOL Result
= FALSE
;
3463 PWINDOW_OBJECT Window
;
3465 DECLARE_RETURN(BOOL
);
3467 DPRINT("Enter NtUserSetSystemMenu\n");
3468 UserEnterExclusive();
3470 if (!(Window
= UserGetWindowObject(hWnd
)))
3478 * Assign new menu handle.
3480 if (!(Menu
= UserGetMenuObject(hMenu
)))
3485 Result
= IntSetSystemMenu(Window
, Menu
);
3491 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3500 UserGetWindow(HWND hWnd
, UINT Relationship
)
3502 PWINDOW_OBJECT Parent
, Window
;
3503 HWND hWndResult
= NULL
;
3505 if (!(Window
= UserGetWindowObject(hWnd
)))
3508 switch (Relationship
)
3511 if((Parent
= Window
->Parent
))
3513 if (Parent
->FirstChild
)
3514 hWndResult
= Parent
->FirstChild
->hSelf
;
3519 if((Parent
= Window
->Parent
))
3521 if (Parent
->LastChild
)
3522 hWndResult
= Parent
->LastChild
->hSelf
;
3527 if (Window
->NextSibling
)
3528 hWndResult
= Window
->NextSibling
->hSelf
;
3532 if (Window
->PrevSibling
)
3533 hWndResult
= Window
->PrevSibling
->hSelf
;
3537 if((Parent
= UserGetWindowObject(Window
->hOwner
)))
3539 hWndResult
= Parent
->hSelf
;
3543 if (Window
->FirstChild
)
3544 hWndResult
= Window
->FirstChild
->hSelf
;
3556 * The NtUserGetWindow function retrieves a handle to a window that has the
3557 * specified relationship (Z order or owner) to the specified window.
3564 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3566 DECLARE_RETURN(HWND
);
3568 DPRINT("Enter NtUserGetWindow\n");
3571 RETURN(UserGetWindow(hWnd
, Relationship
));
3574 DPRINT("Leave NtUserGetWindow, ret=%i\n",_ret_
);
3583 * NtUserGetWindowLong
3585 * The NtUserGetWindowLong function retrieves information about the specified
3586 * window. The function also retrieves the 32-bit (long) value at the
3587 * specified offset into the extra window memory.
3594 UserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3596 PWINDOW_OBJECT Window
, Parent
;
3600 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3602 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3610 * WndProc is only available to the owner process
3612 if (GWL_WNDPROC
== Index
3613 && Window
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3615 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3619 if ((INT
)Index
>= 0)
3621 if ((Index
+ sizeof(LONG
)) > Window
->Wnd
->cbwndExtra
)
3623 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3626 Result
= *((LONG
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3633 Result
= Wnd
->ExStyle
;
3637 Result
= Wnd
->style
;
3641 Result
= (LONG
)IntGetWindowProc(Window
,
3646 Result
= (LONG
) Wnd
->hModule
;
3649 case GWL_HWNDPARENT
:
3650 Parent
= Window
->Parent
;
3653 if (Parent
&& Parent
->hSelf
== IntGetDesktopWindow())
3654 Result
= (LONG
) UserGetWindow(Window
->hSelf
, GW_OWNER
);
3656 Result
= (LONG
) Parent
->hSelf
;
3661 Result
= (LONG
) Wnd
->IDMenu
;
3665 Result
= Wnd
->dwUserData
;
3669 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3670 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3683 * NtUserGetWindowLong
3685 * The NtUserGetWindowLong function retrieves information about the specified
3686 * window. The function also retrieves the 32-bit (long) value at the
3687 * specified offset into the extra window memory.
3694 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3696 DECLARE_RETURN(LONG
);
3698 DPRINT("Enter NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3699 UserEnterExclusive();
3701 RETURN(UserGetWindowLong(hWnd
, Index
, Ansi
));
3704 DPRINT("Leave NtUserGetWindowLong, ret=%i\n",_ret_
);
3710 IntSetWindowProc(PWINDOW_OBJECT Window
,
3715 PCALLPROCDATA CallProc
;
3716 PWND Wnd
= Window
->Wnd
;
3718 /* resolve any callproc handle if possible */
3719 if (IsCallProcHandle(NewWndProc
))
3721 WNDPROC_INFO wpInfo
;
3723 if (UserGetCallProcInfo((HANDLE
)NewWndProc
,
3726 NewWndProc
= wpInfo
.WindowProc
;
3727 /* FIXME - what if wpInfo.IsUnicode doesn't match Ansi? */
3731 /* attempt to get the previous window proc */
3734 Ret
= (Ansi
? Wnd
->WndProcExtra
: Wnd
->lpfnWndProc
);
3738 if (!Ansi
== Wnd
->Unicode
)
3740 Ret
= Wnd
->lpfnWndProc
;
3744 CallProc
= UserFindCallProc(Wnd
->pcls
,
3747 if (CallProc
== NULL
)
3749 CallProc
= CreateCallProc(NULL
,
3752 Wnd
->head
.pti
->ppi
);
3753 if (CallProc
== NULL
)
3755 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3759 UserAddCallProcToClass(Wnd
->pcls
,
3762 /* BugBoy Comments: Added this if else, see below comments */
3765 Ret
= Wnd
->lpfnWndProc
;
3769 Ret
= GetCallProcHandle(Wnd
->CallProc
);
3772 Wnd
->CallProc
= CallProc
;
3774 /* BugBoy Comments: Above sets the current CallProc for the
3775 window and below we set the Ret value to it.
3776 SetWindowLong for WNDPROC should return the previous proc
3777 Ret = GetCallProcHandle(Wnd->CallProc); */
3781 if (Wnd
->pcls
->System
)
3783 /* check if the new procedure matches with the one in the
3784 window class. If so, we need to restore both procedures! */
3785 Wnd
->IsSystem
= (NewWndProc
== Wnd
->pcls
->lpfnWndProc
||
3786 NewWndProc
== Wnd
->pcls
->WndProcExtra
);
3790 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
3791 Wnd
->WndProcExtra
= Wnd
->pcls
->WndProcExtra
;
3792 Wnd
->Unicode
= !Ansi
;
3797 ASSERT(!Wnd
->IsSystem
);
3799 /* update the window procedure */
3800 Wnd
->lpfnWndProc
= NewWndProc
;
3801 Wnd
->Unicode
= !Ansi
;
3808 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3810 PWINDOW_OBJECT Window
, Parent
;
3812 PWINSTATION_OBJECT WindowStation
;
3816 if (hWnd
== IntGetDesktopWindow())
3818 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3822 if (!(Window
= UserGetWindowObject(hWnd
)))
3829 if (!Wnd
) return 0; // No go on zero.
3831 if ((INT
)Index
>= 0)
3833 if ((Index
+ sizeof(LONG
)) > Wnd
->cbwndExtra
)
3835 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3838 OldValue
= *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
));
3839 *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
)) = NewValue
;
3846 OldValue
= (LONG
) Wnd
->ExStyle
;
3847 Style
.styleOld
= OldValue
;
3848 Style
.styleNew
= NewValue
;
3851 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3853 WindowStation
= ((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
->WindowStation
;
3856 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3857 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3860 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3861 Wnd
->ExStyle
= (DWORD
)Style
.styleNew
;
3862 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3866 OldValue
= (LONG
) Wnd
->style
;
3867 Style
.styleOld
= OldValue
;
3868 Style
.styleNew
= NewValue
;
3869 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3870 Wnd
->style
= (DWORD
)Style
.styleNew
;
3871 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3876 /* FIXME: should check if window belongs to current process */
3877 OldValue
= (LONG
)IntSetWindowProc(Window
,
3884 OldValue
= (LONG
) Wnd
->hModule
;
3885 Wnd
->hModule
= (HINSTANCE
) NewValue
;
3888 case GWL_HWNDPARENT
:
3889 Parent
= Window
->Parent
;
3890 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
3891 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
3893 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
3897 OldValue
= (LONG
) Wnd
->IDMenu
;
3898 Wnd
->IDMenu
= (UINT
) NewValue
;
3902 OldValue
= Wnd
->dwUserData
;
3903 Wnd
->dwUserData
= NewValue
;
3907 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3908 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3920 * NtUserSetWindowLong
3922 * The NtUserSetWindowLong function changes an attribute of the specified
3923 * window. The function also sets the 32-bit (long) value at the specified
3924 * offset into the extra window memory.
3931 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3933 DECLARE_RETURN(LONG
);
3935 DPRINT("Enter NtUserSetWindowLong\n");
3936 UserEnterExclusive();
3938 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3941 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3947 * NtUserSetWindowWord
3949 * Legacy function similar to NtUserSetWindowLong.
3956 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3958 PWINDOW_OBJECT Window
;
3960 DECLARE_RETURN(WORD
);
3962 DPRINT("Enter NtUserSetWindowWord\n");
3963 UserEnterExclusive();
3965 if (!(Window
= UserGetWindowObject(hWnd
)))
3974 case GWL_HWNDPARENT
:
3975 RETURN( co_UserSetWindowLong(Window
->hSelf
, Index
, (UINT
)NewValue
, TRUE
));
3979 SetLastWin32Error(ERROR_INVALID_INDEX
);
3984 if (Index
> Window
->Wnd
->cbwndExtra
- sizeof(WORD
))
3986 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3990 OldValue
= *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3991 *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
)) = NewValue
;
3996 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
4005 NtUserGetWindowPlacement(HWND hWnd
,
4006 WINDOWPLACEMENT
*lpwndpl
)
4008 PWINDOW_OBJECT Window
;
4011 WINDOWPLACEMENT Safepl
;
4013 DECLARE_RETURN(BOOL
);
4015 DPRINT("Enter NtUserGetWindowPlacement\n");
4018 if (!(Window
= UserGetWindowObject(hWnd
)))
4024 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4025 if(!NT_SUCCESS(Status
))
4027 SetLastNtError(Status
);
4030 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4036 if (0 == (Wnd
->style
& WS_VISIBLE
))
4038 Safepl
.showCmd
= SW_HIDE
;
4040 else if ((0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
4041 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
4042 0 == (Wnd
->style
& WS_MINIMIZE
))
4044 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
4046 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
4048 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
4050 else if (0 != (Wnd
->style
& WS_VISIBLE
))
4052 Safepl
.showCmd
= SW_SHOWNORMAL
;
4055 Size
.x
= Wnd
->rcWindow
.left
;
4056 Size
.y
= Wnd
->rcWindow
.top
;
4057 WinPosInitInternalPos(Window
, &Size
,
4060 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
4061 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
4062 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
4064 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
4065 if(!NT_SUCCESS(Status
))
4067 SetLastNtError(Status
);
4074 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
4084 NtUserLockWindowUpdate(HWND hWnd
)
4104 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
4105 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
4106 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
4110 QueryWindow based on KJK::Hyperion and James Tabor.
4112 0 = QWUniqueProcessId
4113 1 = QWUniqueThreadId
4116 4 = QWIsHung Implements IsHungAppWindow found
4119 9 = QWKillWindow When I called this with hWnd ==
4120 DesktopWindow, it shutdown the system
4127 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
4129 PWINDOW_OBJECT Window
;
4131 DECLARE_RETURN(UINT
);
4133 DPRINT("Enter NtUserQueryWindow\n");
4136 if (!(Window
= UserGetWindowObject(hWnd
)))
4143 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
4144 Result
= (DWORD
)IntGetWndProcessId(Window
);
4147 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
4148 Result
= (DWORD
)IntGetWndThreadId(Window
);
4151 case QUERY_WINDOW_ACTIVE
:
4152 Result
= (DWORD
)UserGetActiveWindow();
4155 case QUERY_WINDOW_FOCUS
:
4156 Result
= (DWORD
)IntGetFocusWindow();
4159 case QUERY_WINDOW_ISHUNG
:
4160 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
4164 Result
= (DWORD
)NULL
;
4171 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
4181 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
4195 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4197 UNICODE_STRING SafeMessageName
;
4200 DECLARE_RETURN(UINT
);
4202 DPRINT("Enter NtUserRegisterWindowMessage\n");
4203 UserEnterExclusive();
4205 if(MessageNameUnsafe
== NULL
)
4207 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4211 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4212 if(!NT_SUCCESS(Status
))
4214 SetLastNtError(Status
);
4218 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4220 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4224 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
4234 NtUserSetImeOwnerWindow(DWORD Unknown0
,
4247 NtUserSetInternalWindowPos(
4264 NtUserSetLayeredWindowAttributes(HWND hwnd
,
4278 NtUserSetLogonNotifyWindow(HWND hWnd
)
4295 PWINDOW_OBJECT Window
;
4297 DECLARE_RETURN(BOOL
);
4299 DPRINT("Enter NtUserSetMenu\n");
4300 UserEnterExclusive();
4302 if (!(Window
= UserGetWindowObject(hWnd
)))
4307 if (! IntSetMenu(Window
, Menu
, &Changed
))
4312 if (Changed
&& Repaint
)
4314 USER_REFERENCE_ENTRY Ref
;
4316 UserRefObjectCo(Window
, &Ref
);
4317 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4318 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4320 UserDerefObjectCo(Window
);
4326 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4336 NtUserSetWindowFNID(HWND hWnd
,
4339 PWINDOW_OBJECT Window
;
4341 DECLARE_RETURN(BOOL
);
4343 DPRINT("Enter NtUserSetWindowFNID\n");
4344 UserEnterExclusive();
4346 if (!(Window
= UserGetWindowObject(hWnd
)))
4353 { // From user land we only set these.
4354 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
4359 Wnd
->pcls
->fnid
|= fnID
;
4364 DPRINT("Leave NtUserSetWindowFNID\n");
4374 NtUserSetWindowPlacement(HWND hWnd
,
4375 WINDOWPLACEMENT
*lpwndpl
)
4377 PWINDOW_OBJECT Window
;
4379 WINDOWPLACEMENT Safepl
;
4381 DECLARE_RETURN(BOOL
);
4382 USER_REFERENCE_ENTRY Ref
;
4384 DPRINT("Enter NtUserSetWindowPlacement\n");
4385 UserEnterExclusive();
4387 if (!(Window
= UserGetWindowObject(hWnd
)))
4393 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4394 if(!NT_SUCCESS(Status
))
4396 SetLastNtError(Status
);
4399 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4404 UserRefObjectCo(Window
, &Ref
);
4406 if ((Wnd
->style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4408 co_WinPosSetWindowPos(Window
, NULL
,
4409 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4410 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4411 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4412 SWP_NOZORDER
| SWP_NOACTIVATE
);
4415 /* FIXME - change window status */
4416 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
4418 Wnd
->InternalPosInitialized
= TRUE
;
4419 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4420 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4421 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4423 UserDerefObjectCo(Window
);
4427 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4439 HWND hWndInsertAfter
,
4446 DECLARE_RETURN(BOOL
);
4447 PWINDOW_OBJECT Window
;
4449 USER_REFERENCE_ENTRY Ref
;
4451 DPRINT("Enter NtUserSetWindowPos\n");
4452 UserEnterExclusive();
4454 if (!(Window
= UserGetWindowObject(hWnd
)))
4459 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
4460 if (!(uFlags
& SWP_NOMOVE
))
4462 if (X
< -32768) X
= -32768;
4463 else if (X
> 32767) X
= 32767;
4464 if (Y
< -32768) Y
= -32768;
4465 else if (Y
> 32767) Y
= 32767;
4467 if (!(uFlags
& SWP_NOSIZE
))
4470 else if (cx
> 32767) cx
= 32767;
4472 else if (cy
> 32767) cy
= 32767;
4475 UserRefObjectCo(Window
, &Ref
);
4476 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4477 UserDerefObjectCo(Window
);
4482 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4489 IntGetWindowRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
4507 /* Create a new window region using the window rectangle */
4508 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4509 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4510 /* if there's a region assigned to the window, combine them both */
4511 if(Window
->WindowRegion
&& !(Wnd
->style
& WS_MINIMIZE
))
4512 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4513 /* Copy the region into hRgn */
4514 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4516 if((pRgn
= REGION_LockRgn(hRgn
)))
4518 Ret
= pRgn
->rdh
.iType
;
4519 REGION_UnlockRgn(pRgn
);
4524 GreDeleteObject(VisRgn
);
4530 IntGetWindowRgnBox(PWINDOW_OBJECT Window
, RECTL
*Rect
)
4548 /* Create a new window region using the window rectangle */
4549 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4550 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4551 /* if there's a region assigned to the window, combine them both */
4552 if(Window
->WindowRegion
&& !(Wnd
->style
& WS_MINIMIZE
))
4553 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4555 if((pRgn
= REGION_LockRgn(VisRgn
)))
4557 Ret
= pRgn
->rdh
.iType
;
4558 *Rect
= pRgn
->rdh
.rcBound
;
4559 REGION_UnlockRgn(pRgn
);
4564 GreDeleteObject(VisRgn
);
4579 PWINDOW_OBJECT Window
;
4580 DECLARE_RETURN(INT
);
4582 DPRINT("Enter NtUserSetWindowRgn\n");
4583 UserEnterExclusive();
4585 if (!(Window
= UserGetWindowObject(hWnd
)))
4590 /* FIXME - Verify if hRgn is a valid handle!!!!
4591 Propably make this operation thread-safe, but maybe it's not necessary */
4593 if(Window
->WindowRegion
)
4595 /* Delete no longer needed region handle */
4596 GreDeleteObject(Window
->WindowRegion
);
4598 Window
->WindowRegion
= hRgn
;
4600 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4604 USER_REFERENCE_ENTRY Ref
;
4605 UserRefObjectCo(Window
, &Ref
);
4606 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4607 UserDerefObjectCo(Window
);
4613 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4623 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4625 PWINDOW_OBJECT Window
;
4627 DECLARE_RETURN(BOOL
);
4628 USER_REFERENCE_ENTRY Ref
;
4630 DPRINT("Enter NtUserShowWindow\n");
4631 UserEnterExclusive();
4633 if (!(Window
= UserGetWindowObject(hWnd
)))
4638 UserRefObjectCo(Window
, &Ref
);
4639 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4640 UserDerefObjectCo(Window
);
4645 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4655 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4661 return NtUserShowWindow(hWnd
, nCmdShow
);
4671 NtUserUpdateLayeredWindow(
4679 BLENDFUNCTION
*pblend
,
4692 NtUserWindowFromPhysicalPoint(POINT Point
)
4703 NtUserWindowFromPoint(LONG X
, LONG Y
)
4707 PWINDOW_OBJECT DesktopWindow
= NULL
, Window
= NULL
;
4708 DECLARE_RETURN(HWND
);
4709 USER_REFERENCE_ENTRY Ref
;
4711 DPRINT("Enter NtUserWindowFromPoint\n");
4712 UserEnterExclusive();
4714 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4722 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4723 //its possible this referencing is useless, thou it shouldnt hurt...
4724 UserRefObjectCo(DesktopWindow
, &Ref
);
4726 pti
= PsGetCurrentThreadWin32Thread();
4727 Hit
= co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4731 Ret
= Window
->hSelf
;
4740 if (Window
) UserDereferenceObject(Window
);
4741 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4743 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4753 * Undocumented function that is called from DefWindowProc to set
4760 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4762 PWINDOW_OBJECT Window
;
4764 LARGE_STRING SafeText
;
4765 UNICODE_STRING UnicodeString
;
4768 DPRINT("Enter NtUserDefSetText\n");
4770 if (WindowText
!= NULL
)
4774 SafeText
= ProbeForReadLargeString(WindowText
);
4776 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4779 SetLastNtError(_SEH2_GetExceptionCode());
4789 UserEnterExclusive();
4791 if(!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4798 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4799 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4800 // Now we know what the bAnsi is for.
4801 RtlInitUnicodeString(&UnicodeString
, NULL
);
4802 if (SafeText
.Buffer
)
4807 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4809 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4810 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4812 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4815 SetLastNtError(_SEH2_GetExceptionCode());
4818 if (!Ret
) goto Exit
;
4821 if (UnicodeString
.Length
!= 0)
4823 if (Wnd
->strName
.MaximumLength
> 0 &&
4824 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4826 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4828 Wnd
->strName
.Length
= UnicodeString
.Length
;
4829 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4830 RtlCopyMemory(Wnd
->strName
.Buffer
,
4831 UnicodeString
.Buffer
,
4832 UnicodeString
.Length
);
4837 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4838 buf
= Wnd
->strName
.Buffer
;
4839 Wnd
->strName
.Buffer
= NULL
;
4842 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4845 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4846 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4847 if (Wnd
->strName
.Buffer
!= NULL
)
4849 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4850 RtlCopyMemory(Wnd
->strName
.Buffer
,
4851 UnicodeString
.Buffer
,
4852 UnicodeString
.Length
);
4853 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4854 Wnd
->strName
.Length
= UnicodeString
.Length
;
4858 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4866 Wnd
->strName
.Length
= 0;
4867 if (Wnd
->strName
.Buffer
!= NULL
)
4868 Wnd
->strName
.Buffer
[0] = L
'\0';
4871 // HAX! FIXME! Windows does not do this in here!
4872 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4873 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4874 /* Send shell notifications */
4875 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
4877 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4882 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4883 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4889 * NtUserInternalGetWindowText
4896 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4898 PWINDOW_OBJECT Window
;
4902 DECLARE_RETURN(INT
);
4904 DPRINT("Enter NtUserInternalGetWindowText\n");
4907 if(lpString
&& (nMaxCount
<= 1))
4909 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4913 if(!(Window
= UserGetWindowObject(hWnd
)))
4919 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4922 const WCHAR Terminator
= L
'\0';
4924 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4926 Copy
= min(nMaxCount
- 1, Result
);
4929 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4930 if(!NT_SUCCESS(Status
))
4932 SetLastNtError(Status
);
4938 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4939 if(!NT_SUCCESS(Status
))
4941 SetLastNtError(Status
);
4951 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4959 IntShowOwnedPopups(PWINDOW_OBJECT OwnerWnd
, BOOL fShow
)
4962 PWINDOW_OBJECT pWnd
;
4965 // ASSERT(OwnerWnd);
4967 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
4972 while (win_array
[count
])
4974 while (--count
>= 0)
4976 if (UserGetWindow( win_array
[count
], GW_OWNER
) != OwnerWnd
->hSelf
)
4978 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4980 // if (pWnd == WND_OTHER_PROCESS) continue;
4984 if (pWnd
->Wnd
->state
& WNDS_HIDDENPOPUP
)
4986 /* In Windows, ShowOwnedPopups(TRUE) generates
4987 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4988 * regardless of the state of the owner
4990 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4996 if (pWnd
->Wnd
->style
& WS_VISIBLE
)
4998 /* In Windows, ShowOwnedPopups(FALSE) generates
4999 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
5000 * regardless of the state of the owner
5002 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
5008 ExFreePool( win_array
);
5013 * NtUserValidateHandleSecure
5021 NtUserValidateHandleSecure(
5029 PUSER_HANDLE_ENTRY entry
;
5030 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
5032 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5035 uType
= entry
->type
;
5041 PWINDOW_OBJECT Window
;
5042 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
5048 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
5053 PACCELERATOR_TABLE Accel
;
5054 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
5059 PCURICON_OBJECT Cursor
;
5060 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
5066 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
5071 PMONITOR_OBJECT Monitor
;
5072 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
5078 return UserGetCallProcInfo( handle
, &Proc
);
5081 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5085 { /* Is handle entry restricted? */