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;
1026 * Windows hides the window first, then shows it again
1027 * including the WM_SHOWWINDOW messages and all
1029 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1031 // /* Validate that window and parent still exist */
1032 // if (!IntIsWindow(hWnd) || !IntIsWindow(hWndNewParent))
1035 /* Window must belong to current process */
1036 if (Wnd
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
1039 WndOldParent
= Wnd
->Parent
;
1041 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* caller must deref */
1043 if (WndNewParent
!= WndOldParent
)
1045 IntUnlinkWindow(Wnd
);
1047 if (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1049 /* Not a TOPMOST window, put after TOPMOSTs of new parent */
1050 Sibling
= WndNewParent
->FirstChild
;
1051 while (NULL
!= Sibling
&& 0 != (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
1053 InsertAfter
= Sibling
;
1054 Sibling
= Sibling
->NextSibling
;
1057 if (NULL
== InsertAfter
)
1059 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1063 // UserReferenceObject(InsertAfter);
1064 IntLinkWindow(Wnd
, WndNewParent
, InsertAfter
/*prev sibling*/);
1065 // UserDereferenceObject(InsertAfter);
1070 * SetParent additionally needs to make hwnd the top window
1071 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1072 * WM_WINDOWPOSCHANGED notification messages.
1074 co_WinPosSetWindowPos(Wnd
, (0 == (Wnd
->Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1075 0, 0, 0, 0, SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
1076 | (WasVisible
? SWP_SHOWWINDOW
: 0));
1079 * FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
1080 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE
1084 * Validate that the old parent still exist, since it migth have been
1085 * destroyed during the last callbacks to user-mode
1089 // if(!IntIsWindow(WndOldParent->hSelf))
1091 // UserDereferenceObject(WndOldParent);
1095 /* don't dereference the window object here, it must be done by the caller
1096 of IntSetParent() */
1097 // return WndOldParent;
1100 return WndOldParent
;//NULL;
1104 IntSetSystemMenu(PWINDOW_OBJECT Window
, PMENU_OBJECT Menu
)
1106 PMENU_OBJECT OldMenu
;
1107 if(Window
->SystemMenu
)
1109 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1112 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1113 IntReleaseMenuObject(OldMenu
);
1119 /* FIXME check window style, propably return FALSE ? */
1120 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1121 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1124 Window
->SystemMenu
= (HMENU
)0;
1130 /* unlink the window from siblings and parent. children are kept in place. */
1132 IntUnlinkWindow(PWINDOW_OBJECT Wnd
)
1134 PWINDOW_OBJECT WndParent
= Wnd
->Parent
;
1136 if (Wnd
->NextSibling
)
1137 Wnd
->NextSibling
->PrevSibling
= Wnd
->PrevSibling
;
1138 else if (WndParent
&& WndParent
->LastChild
== Wnd
)
1139 WndParent
->LastChild
= Wnd
->PrevSibling
;
1141 if (Wnd
->PrevSibling
)
1142 Wnd
->PrevSibling
->NextSibling
= Wnd
->NextSibling
;
1143 else if (WndParent
&& WndParent
->FirstChild
== Wnd
)
1144 WndParent
->FirstChild
= Wnd
->NextSibling
;
1146 Wnd
->PrevSibling
= Wnd
->NextSibling
= Wnd
->Parent
= NULL
;
1148 Wnd
->Wnd
->spwndParent
= NULL
;
1154 PWINDOW_OBJECT Window
, Child
;
1156 if(!(Window
= UserGetWindowObject(IntGetDesktopWindow())))
1161 for(Child
= Window
->FirstChild
; Child
; Child
= Child
->NextSibling
)
1163 if(Child
->hOwner
&& Child
->Wnd
->style
& WS_VISIBLE
)
1166 * The desktop has a popup window if one of them has
1167 * an owner window and is visible
1177 IntIsWindowInDestroy(PWINDOW_OBJECT Window
)
1179 return ((Window
->Status
& WINDOWSTATUS_DESTROYING
) == WINDOWSTATUS_DESTROYING
);
1185 IntGetWindowPlacement(PWINDOW_OBJECT Window
, WINDOWPLACEMENT
*lpwndpl
)
1191 if (!Wnd
) return FALSE
;
1193 if(lpwndpl
->length
!= sizeof(WINDOWPLACEMENT
))
1199 if (0 == (Wnd
->style
& WS_VISIBLE
))
1201 lpwndpl
->showCmd
= SW_HIDE
;
1203 else if (0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
1204 0 != (Wnd
->style
& WS_MAXIMIZE
))
1206 lpwndpl
->showCmd
= SW_MAXIMIZE
;
1208 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
1210 lpwndpl
->showCmd
= SW_MINIMIZE
;
1212 else if (0 != (Wnd
->style
& WS_VISIBLE
))
1214 lpwndpl
->showCmd
= SW_SHOWNORMAL
;
1217 Size
.x
= Wnd
->rcWindow
.left
;
1218 Size
.y
= Wnd
->rcWindow
.top
;
1219 WinPosInitInternalPos(Window
, &Size
,
1222 lpwndpl
->rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
1223 lpwndpl
->ptMinPosition
= Wnd
->InternalPos
.IconPos
;
1224 lpwndpl
->ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
1230 /* FUNCTIONS *****************************************************************/
1236 NtUserAlterWindowStyle(DWORD Unknown0
,
1246 * As best as I can figure, this function is used by EnumWindows,
1247 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1249 * It's supposed to build a list of HWNDs to return to the caller.
1250 * We can figure out what kind of list by what parameters are
1258 NtUserBuildHwndList(
1271 return ERROR_INVALID_PARAMETER
;
1273 if (hwndParent
|| !dwThreadId
)
1276 PWINDOW_OBJECT Parent
, Window
;
1280 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1282 return ERROR_INVALID_HANDLE
;
1287 Status
= IntValidateDesktopHandle(hDesktop
,
1291 if(!NT_SUCCESS(Status
))
1293 return ERROR_INVALID_HANDLE
;
1296 hwndParent
= Desktop
->DesktopWindow
;
1303 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1304 (Window
= Parent
->FirstChild
))
1306 BOOL bGoDown
= TRUE
;
1308 Status
= STATUS_SUCCESS
;
1313 if(dwCount
++ < *pBufSize
&& pWnd
)
1317 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1318 *pWnd
= Window
->hSelf
;
1321 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1323 Status
= _SEH2_GetExceptionCode();
1326 if(!NT_SUCCESS(Status
))
1328 SetLastNtError(Status
);
1332 if (Window
->FirstChild
&& bChildren
)
1334 Window
= Window
->FirstChild
;
1339 if (Window
->NextSibling
)
1341 Window
= Window
->NextSibling
;
1345 Window
= Window
->Parent
;
1346 if (Window
== Parent
)
1355 ObDereferenceObject(Desktop
);
1361 PTHREADINFO W32Thread
;
1362 PLIST_ENTRY Current
;
1363 PWINDOW_OBJECT Window
;
1365 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1366 if(!NT_SUCCESS(Status
))
1368 return ERROR_INVALID_PARAMETER
;
1370 if(!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1372 ObDereferenceObject(Thread
);
1373 DPRINT("Thread is not a GUI Thread!\n");
1374 return ERROR_INVALID_PARAMETER
;
1377 Current
= W32Thread
->WindowListHead
.Flink
;
1378 while(Current
!= &(W32Thread
->WindowListHead
))
1380 Window
= CONTAINING_RECORD(Current
, WINDOW_OBJECT
, ThreadListEntry
);
1383 if(bChildren
|| Window
->hOwner
!= NULL
)
1385 if(dwCount
< *pBufSize
&& pWnd
)
1387 Status
= MmCopyToCaller(pWnd
++, &Window
->hSelf
, sizeof(HWND
));
1388 if(!NT_SUCCESS(Status
))
1390 SetLastNtError(Status
);
1396 Current
= Current
->Flink
;
1399 ObDereferenceObject(Thread
);
1402 *pBufSize
= dwCount
;
1403 return STATUS_SUCCESS
;
1411 NtUserChildWindowFromPointEx(HWND hwndParent
,
1416 PWINDOW_OBJECT Parent
;
1421 if(!(Parent
= UserGetWindowObject(hwndParent
)))
1429 if(Parent
->hSelf
!= IntGetDesktopWindow())
1431 Pt
.x
+= Parent
->Wnd
->rcClient
.left
;
1432 Pt
.y
+= Parent
->Wnd
->rcClient
.top
;
1435 if(!IntPtInWindow(Parent
, Pt
.x
, Pt
.y
))
1440 Ret
= Parent
->hSelf
;
1441 if((List
= IntWinListChildren(Parent
)))
1443 for(phWnd
= List
; *phWnd
; phWnd
++)
1445 PWINDOW_OBJECT Child
;
1447 if((Child
= UserGetWindowObject(*phWnd
)))
1449 ChildWnd
= Child
->Wnd
;
1450 if(!(ChildWnd
->style
& WS_VISIBLE
) && (uiFlags
& CWP_SKIPINVISIBLE
))
1454 if((ChildWnd
->style
& WS_DISABLED
) && (uiFlags
& CWP_SKIPDISABLED
))
1458 if((ChildWnd
->ExStyle
& WS_EX_TRANSPARENT
) && (uiFlags
& CWP_SKIPTRANSPARENT
))
1462 if(IntPtInWindow(Child
, Pt
.x
, Pt
.y
))
1477 * calculates the default position of a window
1480 IntCalcDefPosSize(PWINDOW_OBJECT Parent
, PWINDOW_OBJECT Window
, RECTL
*rc
, BOOL IncPos
)
1487 RECTL_bIntersectRect(rc
, rc
, &Parent
->Wnd
->rcClient
);
1491 Pos
.x
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1492 Pos
.y
= Parent
->TiledCounter
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1493 if(Pos
.x
> ((rc
->right
- rc
->left
) / 4) ||
1494 Pos
.y
> ((rc
->bottom
- rc
->top
) / 4))
1496 /* reset counter and position */
1499 Parent
->TiledCounter
= 0;
1501 Parent
->TiledCounter
++;
1512 Sz
.cx
= EngMulDiv(rc
->right
- rc
->left
, 3, 4);
1513 Sz
.cy
= EngMulDiv(rc
->bottom
- rc
->top
, 3, 4);
1517 rc
->right
= rc
->left
+ Sz
.cx
;
1518 rc
->bottom
= rc
->top
+ Sz
.cy
;
1527 co_IntCreateWindowEx(DWORD dwExStyle
,
1528 PUNICODE_STRING ClassName
,
1529 PUNICODE_STRING WindowName
,
1537 HINSTANCE hInstance
,
1540 BOOL bUnicodeWindow
)
1542 PWINSTATION_OBJECT WinSta
;
1544 PCLS
*ClassLink
, Class
= NULL
;
1546 PWINDOW_OBJECT Window
= NULL
;
1547 PWINDOW_OBJECT ParentWindow
= NULL
, OwnerWindow
;
1548 HWND ParentWindowHandle
= NULL
;
1549 HWND OwnerWindowHandle
;
1550 PMENU_OBJECT SystemMenu
;
1554 PTHREADINFO ti
= NULL
;
1557 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1563 CBT_CREATEWNDW CbtCreate
;
1566 DECLARE_RETURN(PWND
);
1568 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1571 pti
= PsGetCurrentThreadWin32Thread();
1575 ParentWindowHandle
= pti
->Desktop
->DesktopWindow
;
1578 OwnerWindowHandle
= NULL
;
1580 if (hWndParent
== HWND_MESSAGE
)
1583 * native ole32.OleInitialize uses HWND_MESSAGE to create the
1584 * message window (style: WS_POPUP|WS_DISABLED)
1586 ParentWindowHandle
= IntGetMessageWindow();
1587 DPRINT("Parent is HWND_MESSAGE 0x%x\n", ParentWindowHandle
);
1589 else if (hWndParent
)
1591 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1593 PWINDOW_OBJECT Par
= UserGetWindowObject(hWndParent
), Root
;
1594 if (Par
&& (Root
= UserGetAncestor(Par
, GA_ROOT
)))
1595 OwnerWindowHandle
= Root
->hSelf
;
1598 ParentWindowHandle
= hWndParent
;
1600 else if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1602 SetLastWin32Error(ERROR_TLW_WITH_WSCHILD
);
1603 RETURN( (PWND
)0); /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1606 if (ParentWindowHandle
)
1608 ParentWindow
= UserGetWindowObject(ParentWindowHandle
);
1610 if (ParentWindow
) UserRefObjectCo(ParentWindow
, &ParentRef
);
1614 ParentWindow
= NULL
;
1617 /* FIXME: parent must belong to the current process */
1619 /* Check the window station. */
1620 ti
= GetW32ThreadInfo();
1621 if (ti
== NULL
|| pti
->Desktop
== NULL
)
1623 DPRINT1("Thread is not attached to a desktop! Cannot create window!\n");
1627 /* Check the class. */
1629 ClassAtom
= IntGetClassAtom(ClassName
,
1635 if (ClassAtom
== (RTL_ATOM
)0)
1637 if (IS_ATOM(ClassName
->Buffer
))
1639 DPRINT1("Class 0x%p not found\n", (DWORD_PTR
) ClassName
->Buffer
);
1643 DPRINT1("Class \"%wZ\" not found\n", ClassName
);
1646 SetLastWin32Error(ERROR_CANNOT_FIND_WND_CLASS
);
1650 Class
= IntReferenceClass(Class
,
1655 DPRINT1("Failed to reference window class!\n");
1659 WinSta
= pti
->Desktop
->WindowStation
;
1661 //FIXME: Reference thread/desktop instead
1662 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1664 /* Create the window object. */
1665 Window
= (PWINDOW_OBJECT
) UserCreateObject( gHandleTable
,
1668 sizeof(WINDOW_OBJECT
));
1671 Window
->Wnd
= DesktopHeapAlloc(pti
->Desktop
,
1672 sizeof(WND
) + Class
->cbwndExtra
);
1675 RtlZeroMemory(Window
->Wnd
,
1676 sizeof(WND
) + Class
->cbwndExtra
);
1677 Window
->Wnd
->head
.h
= hWnd
;
1681 Wnd
->head
.rpdesk
= pti
->Desktop
;
1682 Wnd
->hWndLastActive
= hWnd
;
1683 Wnd
->state2
|= WNDS2_WIN40COMPAT
;
1686 DPRINT("Created object with handle %X\n", hWnd
);
1690 ObDereferenceObject(WinSta
);
1691 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1695 UserRefObjectCo(Window
, &Ref
);
1697 ObDereferenceObject(WinSta
);
1699 if (NULL
== pti
->Desktop
->DesktopWindow
)
1701 /* If there is no desktop window yet, we must be creating it */
1702 pti
->Desktop
->DesktopWindow
= hWnd
;
1703 pti
->Desktop
->DesktopInfo
->Wnd
= Wnd
;
1707 * Fill out the structure describing it.
1713 Window
->SystemMenu
= (HMENU
)0;
1715 Wnd
->hModule
= hInstance
;
1716 Window
->hSelf
= hWnd
;
1718 Window
->MessageQueue
= pti
->MessageQueue
;
1719 IntReferenceMessageQueue(Window
->MessageQueue
);
1720 Window
->Parent
= ParentWindow
;
1721 Wnd
->spwndParent
= ParentWindow
? ParentWindow
->Wnd
: NULL
;
1722 if (Wnd
->spwndParent
!= NULL
&& hWndParent
!= 0)
1724 Wnd
->HideFocus
= Wnd
->spwndParent
->HideFocus
;
1725 Wnd
->HideAccel
= Wnd
->spwndParent
->HideAccel
;
1728 if((OwnerWindow
= UserGetWindowObject(OwnerWindowHandle
)))
1730 Window
->hOwner
= OwnerWindowHandle
;
1731 Wnd
->spwndOwner
= OwnerWindow
->Wnd
;
1736 Window
->hOwner
= NULL
;
1737 Wnd
->spwndOwner
= NULL
;
1741 Wnd
->dwUserData
= 0;
1743 Wnd
->IsSystem
= Wnd
->pcls
->System
;
1745 /* BugBoy Comments: Comment below say that System classes are always created as UNICODE.
1746 In windows, creating a window with the ANSI version of CreateWindow sets the window
1747 to ansi as verified by testing with IsUnicodeWindow API.
1749 No where can I see in code or through testing does the window change back to ANSI
1750 after being created as UNICODE in ROS. I didnt do more testing to see what problems this would cause.*/
1751 // See NtUserDefSetText! We convert to Unicode all the time and never use Mix. (jt)
1752 if (Wnd
->pcls
->System
)
1754 /* NOTE: Always create a unicode window for system classes! */
1755 Wnd
->Unicode
= TRUE
;
1756 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
1757 Wnd
->WndProcExtra
= Wnd
->pcls
->WndProcExtra
;
1761 Wnd
->Unicode
= Wnd
->pcls
->Unicode
;
1762 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
1763 Wnd
->CallProc
= NULL
;
1766 Window
->OwnerThread
= PsGetCurrentThread();
1767 Window
->FirstChild
= NULL
;
1768 Window
->LastChild
= NULL
;
1769 Window
->PrevSibling
= NULL
;
1770 Window
->NextSibling
= NULL
;
1771 Wnd
->cbwndExtra
= Wnd
->pcls
->cbwndExtra
;
1773 InitializeListHead(&Wnd
->PropListHead
);
1774 InitializeListHead(&Window
->WndObjListHead
);
1776 if ( NULL
!= WindowName
->Buffer
&& WindowName
->Length
> 0 )
1778 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
1779 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1780 if (Wnd
->strName
.Buffer
== NULL
)
1782 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1786 Wnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1789 RtlCopyMemory(Wnd
->strName
.Buffer
,
1791 WindowName
->Length
);
1792 Wnd
->strName
.Length
= WindowName
->Length
;
1794 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1796 WindowName
->Length
= 0;
1797 Wnd
->strName
.Buffer
[0] = L
'\0';
1803 * This has been tested for WS_CHILD | WS_VISIBLE. It has not been
1804 * tested for WS_POPUP
1806 if ((dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1807 ((!(dwExStyle
& WS_EX_STATICEDGE
)) &&
1808 (dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1809 dwExStyle
|= WS_EX_WINDOWEDGE
;
1811 dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1813 /* Correct the window style. */
1814 if (!(dwStyle
& WS_CHILD
))
1816 dwStyle
|= WS_CLIPSIBLINGS
;
1817 DPRINT("3: Style is now %lx\n", dwStyle
);
1818 if (!(dwStyle
& WS_POPUP
))
1820 dwStyle
|= WS_CAPTION
;
1821 Window
->Flags
|= WINDOWOBJECT_NEED_SIZE
;
1822 DPRINT("4: Style is now %lx\n", dwStyle
);
1826 /* create system menu */
1827 if((dwStyle
& WS_SYSMENU
) )//&& (dwStyle & WS_CAPTION) == WS_CAPTION)
1829 SystemMenu
= IntGetSystemMenu(Window
, TRUE
, TRUE
);
1832 Window
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1833 IntReleaseMenuObject(SystemMenu
);
1837 /* Set the window menu */
1838 if ((dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1841 IntSetMenu(Window
, hMenu
, &MenuChanged
);
1842 else if (Wnd
->pcls
->lpszMenuName
) // Take it from the parent.
1844 UNICODE_STRING MenuName
;
1845 if (IS_INTRESOURCE(Wnd
->pcls
->lpszMenuName
))
1847 MenuName
.Length
= 0;
1848 MenuName
.MaximumLength
= 0;
1849 MenuName
.Buffer
= Wnd
->pcls
->lpszMenuName
;
1853 RtlInitUnicodeString( &MenuName
, Wnd
->pcls
->lpszMenuName
);
1855 hMenu
= co_IntCallLoadMenu( Wnd
->pcls
->hModule
, &MenuName
);
1856 if (hMenu
) IntSetMenu(Window
, hMenu
, &MenuChanged
);
1860 Wnd
->IDMenu
= (UINT
) hMenu
;
1862 /* Insert the window into the thread's window list. */
1863 InsertTailList (&pti
->WindowListHead
, &Window
->ThreadListEntry
);
1865 /* Handle "CS_CLASSDC", it is tested first. */
1866 if ((Wnd
->pcls
->style
& CS_CLASSDC
) && !(Wnd
->pcls
->pdce
)) // One DCE per class to have CLASS.
1867 Wnd
->pcls
->pdce
= DceAllocDCE(Window
, DCE_CLASS_DC
);
1868 /* Allocate a DCE for this window. */
1869 else if ( Wnd
->pcls
->style
& CS_OWNDC
)
1870 Window
->Dce
= DceAllocDCE(Window
, DCE_WINDOW_DC
);
1877 Wnd
->ExStyle
= dwExStyle
;
1878 Wnd
->style
= dwStyle
& ~WS_VISIBLE
;
1881 Cs
.lpCreateParams
= lpParam
;
1882 Cs
.hInstance
= hInstance
;
1884 Cs
.hwndParent
= hWndParent
; //Pass the original Parent handle!
1889 Cs
.style
= Wnd
->style
;
1890 // Cs.lpszName = (LPCWSTR) WindowName->Buffer;
1891 // Cs.lpszClass = (LPCWSTR) ClassName->Buffer;
1892 Cs
.lpszName
= (LPCWSTR
) WindowName
;
1893 Cs
.lpszClass
= (LPCWSTR
) ClassName
;
1894 Cs
.dwExStyle
= dwExStyle
;
1895 CbtCreate
.lpcs
= &Cs
;
1896 CbtCreate
.hwndInsertAfter
= HWND_TOP
;
1897 if (ISITHOOKED(WH_CBT
))
1899 if (co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) &CbtCreate
))
1901 /* FIXME - Delete window object and remove it from the thread windows list */
1902 /* FIXME - delete allocated DCE */
1903 DPRINT1("CBT-hook returned !0\n");
1904 RETURN( (PWND
) NULL
);
1911 // FIXME: Need to set the Z order in the window link list if the hook callback changed it!
1912 // hwndInsertAfter = CbtCreate.hwndInsertAfter;
1914 /* default positioning for overlapped windows */
1915 if(!(Wnd
->style
& (WS_POPUP
| WS_CHILD
)))
1918 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1919 BOOL CalculatedDefPosSize
= FALSE
;
1921 IntGetDesktopWorkArea(((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
, &WorkArea
);
1924 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1926 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
1928 CalculatedDefPosSize
= IntCalcDefPosSize(ParentWindow
, Window
, &rc
, TRUE
);
1930 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1932 ProcessParams
->WindowFlags
&= ~STARTF_USEPOSITION
;
1933 Pos
.x
= WorkArea
.left
+ ProcessParams
->StartingX
;
1934 Pos
.y
= WorkArea
.top
+ ProcessParams
->StartingY
;
1943 According to wine, the ShowMode is set to y if x == CW_USEDEFAULT(16) and
1944 y is something else. and Quote!
1947 /* Never believe Microsoft's documentation... CreateWindowEx doc says
1948 * that if an overlapped window is created with WS_VISIBLE style bit
1949 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
1950 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
1953 * 1) not only it checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
1954 * 2) it does not ignore the y parameter as the docs claim; instead, it
1955 * uses it as second parameter to ShowWindow() unless y is either
1956 * CW_USEDEFAULT or CW_USEDEFAULT16.
1958 * The fact that we didn't do 2) caused bogus windows pop up when wine
1959 * was running apps that were using this obscure feature. Example -
1960 * calc.exe that comes with Win98 (only Win98, it's different from
1961 * the one that comes with Win95 and NT)
1963 if(y
!= CW_USEDEFAULT
&& y
!= CW_USEDEFAULT16
)
1968 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
1970 if(!CalculatedDefPosSize
)
1972 IntCalcDefPosSize(ParentWindow
, Window
, &rc
, FALSE
);
1974 if(ProcessParams
->WindowFlags
& STARTF_USESIZE
)
1976 ProcessParams
->WindowFlags
&= ~STARTF_USESIZE
;
1977 Size
.cx
= ProcessParams
->CountX
;
1978 Size
.cy
= ProcessParams
->CountY
;
1982 Size
.cx
= rc
.right
- rc
.left
;
1983 Size
.cy
= rc
.bottom
- rc
.top
;
1986 /* move the window if necessary */
1988 Pos
.x
= max(rc
.left
, 0);
1990 Pos
.y
= max(rc
.top
, 0);
1995 /* if CW_USEDEFAULT(16) is set for non-overlapped windows, both values are set to zero) */
1996 if(x
== CW_USEDEFAULT
|| x
== CW_USEDEFAULT16
)
2001 if(nWidth
== CW_USEDEFAULT
|| nWidth
== CW_USEDEFAULT16
)
2008 /* Initialize the window dimensions. */
2009 Wnd
->rcWindow
.left
= Pos
.x
;
2010 Wnd
->rcWindow
.top
= Pos
.y
;
2011 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
2012 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
2013 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2015 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2016 ParentWindow
->Wnd
->rcClient
.top
);
2018 Wnd
->rcClient
= Wnd
->rcWindow
;
2021 * Get the size and position of the window.
2023 if ((dwStyle
& WS_THICKFRAME
) || !(dwStyle
& (WS_POPUP
| WS_CHILD
)))
2025 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2027 /* WinPosGetMinMaxInfo sends the WM_GETMINMAXINFO message */
2028 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
,
2030 if (MaxSize
.x
< Size
.cx
)
2031 Size
.cx
= MaxSize
.x
;
2032 if (MaxSize
.y
< Size
.cy
)
2033 Size
.cy
= MaxSize
.y
;
2034 if (Size
.cx
< MinTrack
.x
)
2035 Size
.cx
= MinTrack
.x
;
2036 if (Size
.cy
< MinTrack
.y
)
2037 Size
.cy
= MinTrack
.y
;
2044 Wnd
->rcWindow
.left
= Pos
.x
;
2045 Wnd
->rcWindow
.top
= Pos
.y
;
2046 Wnd
->rcWindow
.right
= Pos
.x
+ Size
.cx
;
2047 Wnd
->rcWindow
.bottom
= Pos
.y
+ Size
.cy
;
2048 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2050 RECTL_vOffsetRect(&(Wnd
->rcWindow
), ParentWindow
->Wnd
->rcClient
.left
,
2051 ParentWindow
->Wnd
->rcClient
.top
);
2053 Wnd
->rcClient
= Wnd
->rcWindow
;
2055 /* FIXME: Initialize the window menu. */
2057 /* Send a NCCREATE message. */
2063 DPRINT("[win32k.window] IntCreateWindowEx style %d, exstyle %d, parent %d\n", Cs
.style
, Cs
.dwExStyle
, Cs
.hwndParent
);
2064 DPRINT("IntCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, Size
.cx
, Size
.cy
);
2065 DPRINT("IntCreateWindowEx(): About to send NCCREATE message.\n");
2066 Result
= co_IntSendMessage(Window
->hSelf
, WM_NCCREATE
, 0, (LPARAM
) &Cs
);
2069 /* FIXME: Cleanup. */
2070 DPRINT1("IntCreateWindowEx(): NCCREATE message failed. No cleanup performed!\n");
2074 /* Calculate the non-client size. */
2075 MaxPos
.x
= Window
->Wnd
->rcWindow
.left
;
2076 MaxPos
.y
= Window
->Wnd
->rcWindow
.top
;
2079 DPRINT("IntCreateWindowEx(): About to get non-client size.\n");
2080 /* WinPosGetNonClientSize SENDS THE WM_NCCALCSIZE message */
2081 Result
= co_WinPosGetNonClientSize(Window
,
2082 &Window
->Wnd
->rcWindow
,
2083 &Window
->Wnd
->rcClient
);
2085 RECTL_vOffsetRect(&Window
->Wnd
->rcWindow
,
2086 MaxPos
.x
- Window
->Wnd
->rcWindow
.left
,
2087 MaxPos
.y
- Window
->Wnd
->rcWindow
.top
);
2090 if (NULL
!= ParentWindow
)
2092 /* link the window into the parent's child list */
2093 if ((dwStyle
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2095 PWINDOW_OBJECT PrevSibling
;
2097 PrevSibling
= ParentWindow
->LastChild
;
2099 /* link window as bottom sibling */
2100 IntLinkWindow(Window
, ParentWindow
, PrevSibling
/*prev sibling*/);
2104 /* link window as top sibling (but after topmost siblings) */
2105 PWINDOW_OBJECT InsertAfter
, Sibling
;
2106 if (!(dwExStyle
& WS_EX_TOPMOST
))
2109 Sibling
= ParentWindow
->FirstChild
;
2110 while (Sibling
&& (Sibling
->Wnd
->ExStyle
& WS_EX_TOPMOST
))
2112 InsertAfter
= Sibling
;
2113 Sibling
= Sibling
->NextSibling
;
2121 IntLinkWindow(Window
, ParentWindow
, InsertAfter
/* prev sibling */);
2126 /* Send the WM_CREATE message. */
2127 DPRINT("IntCreateWindowEx(): about to send CREATE message.\n");
2128 Result
= co_IntSendMessage(Window
->hSelf
, WM_CREATE
, 0, (LPARAM
) &Cs
);
2130 if (Result
== (LRESULT
)-1)
2132 /* FIXME: Cleanup. */
2133 DPRINT1("IntCreateWindowEx(): send CREATE message failed. No cleanup performed!\n");
2134 IntUnlinkWindow(Window
);
2138 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
->Wnd
, OBJID_WINDOW
, 0);
2140 /* Send move and size messages. */
2141 if (!(Window
->Flags
& WINDOWOBJECT_NEED_SIZE
))
2145 DPRINT("IntCreateWindow(): About to send WM_SIZE\n");
2147 if ((Window
->Wnd
->rcClient
.right
- Window
->Wnd
->rcClient
.left
) < 0 ||
2148 (Window
->Wnd
->rcClient
.bottom
- Window
->Wnd
->rcClient
.top
) < 0)
2150 DPRINT("Sending bogus WM_SIZE\n");
2153 lParam
= MAKE_LONG(Window
->Wnd
->rcClient
.right
-
2154 Window
->Wnd
->rcClient
.left
,
2155 Window
->Wnd
->rcClient
.bottom
-
2156 Window
->Wnd
->rcClient
.top
);
2157 co_IntSendMessage(Window
->hSelf
, WM_SIZE
, SIZE_RESTORED
,
2160 DPRINT("IntCreateWindow(): About to send WM_MOVE\n");
2162 if (0 != (Wnd
->style
& WS_CHILD
) && ParentWindow
)
2164 lParam
= MAKE_LONG(Wnd
->rcClient
.left
- ParentWindow
->Wnd
->rcClient
.left
,
2165 Wnd
->rcClient
.top
- ParentWindow
->Wnd
->rcClient
.top
);
2169 lParam
= MAKE_LONG(Wnd
->rcClient
.left
,
2173 co_IntSendMessage(Window
->hSelf
, WM_MOVE
, 0, lParam
);
2175 /* Call WNDOBJ change procs */
2176 IntEngWindowChanged(Window
, WOC_RGN_CLIENT
);
2179 /* Show or maybe minimize or maximize the window. */
2180 if (Wnd
->style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2185 SwFlag
= (Wnd
->style
& WS_MINIMIZE
) ? SW_MINIMIZE
:
2188 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2190 SwFlag
= ((Wnd
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2191 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2192 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2194 DPRINT("IntCreateWindow(): About to minimize/maximize\n");
2195 DPRINT("%d,%d %dx%d\n", NewPos
.left
, NewPos
.top
, NewPos
.right
, NewPos
.bottom
);
2196 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2197 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2200 /* Notify the parent window of a new child. */
2201 if ((Wnd
->style
& WS_CHILD
) &&
2202 (!(Wnd
->ExStyle
& WS_EX_NOPARENTNOTIFY
)) && ParentWindow
)
2204 DPRINT("IntCreateWindow(): About to notify parent\n");
2205 co_IntSendMessage(ParentWindow
->hSelf
,
2207 MAKEWPARAM(WM_CREATE
, Wnd
->IDMenu
),
2208 (LPARAM
)Window
->hSelf
);
2211 if ((!hWndParent
) && (!HasOwner
))
2213 DPRINT("Sending CREATED notify\n");
2214 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2218 DPRINT("Not sending CREATED notify, %x %d\n", ParentWindow
, HasOwner
);
2221 /* Initialize and show the window's scrollbars */
2222 if (Wnd
->style
& WS_VSCROLL
)
2224 co_UserShowScrollBar(Window
, SB_VERT
, TRUE
);
2226 if (Wnd
->style
& WS_HSCROLL
)
2228 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
);
2231 if (dwStyle
& WS_VISIBLE
)
2233 if (Wnd
->style
& WS_MAXIMIZE
)
2234 dwShowMode
= SW_SHOW
;
2235 else if (Wnd
->style
& WS_MINIMIZE
)
2236 dwShowMode
= SW_SHOWMINIMIZED
;
2238 DPRINT("IntCreateWindow(): About to show window\n");
2239 co_WinPosShowWindow(Window
, dwShowMode
);
2241 if (Wnd
->ExStyle
& WS_EX_MDICHILD
)
2243 co_IntSendMessage(ParentWindow
->hSelf
, WM_MDIREFRESHMENU
, 0, 0);
2244 /* ShowWindow won't activate child windows */
2245 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2249 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
2250 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
2251 Dont understand why it does this. */
2252 if (ClassAtom
== gpsi
->atomSysClass
[ICLS_EDIT
])
2254 PCALLPROCDATA CallProc
;
2255 //CallProc = CreateCallProc(NULL, Wnd->lpfnWndProc, bUnicodeWindow, Wnd->ti->ppi);
2256 CallProc
= CreateCallProc(NULL
, Wnd
->lpfnWndProc
, Wnd
->Unicode
, Wnd
->head
.pti
->ppi
);
2260 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
2261 DPRINT1("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
2265 UserAddCallProcToClass(Wnd
->pcls
, CallProc
);
2266 Wnd
->CallProc
= CallProc
;
2267 Wnd
->IsSystem
= FALSE
;
2271 DPRINT("IntCreateWindow(): = %X\n", hWnd
);
2272 DPRINT("WindowObject->SystemMenu = 0x%x\n", Window
->SystemMenu
);
2276 if (!_ret_
&& Window
&& Window
->Wnd
&& ti
)
2277 UserFreeWindowInfo(ti
, Window
);
2280 UserDerefObjectCo(Window
);
2281 UserDereferenceObject(Window
);
2283 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2284 if (!_ret_
&& ti
!= NULL
)
2288 IntDereferenceClass(Class
,
2297 NtUserCreateWindowEx(DWORD dwExStyle
,
2298 PUNICODE_STRING UnsafeClassName
,
2299 PUNICODE_STRING UnsafeWindowName
,
2307 HINSTANCE hInstance
,
2310 BOOL bUnicodeWindow
,
2314 UNICODE_STRING WindowName
;
2315 UNICODE_STRING ClassName
;
2316 HWND NewWindow
= NULL
;
2318 DECLARE_RETURN(HWND
);
2320 DPRINT("Enter NtUserCreateWindowEx(): (%d,%d-%d,%d)\n", x
, y
, nWidth
, nHeight
);
2321 UserEnterExclusive();
2323 /* Get the class name (string or atom) */
2324 Status
= MmCopyFromCaller(&ClassName
, UnsafeClassName
, sizeof(UNICODE_STRING
));
2325 if (! NT_SUCCESS(Status
))
2327 SetLastNtError(Status
);
2330 if (ClassName
.Length
!= 0)
2332 Status
= IntSafeCopyUnicodeStringTerminateNULL(&ClassName
, UnsafeClassName
);
2333 if (! NT_SUCCESS(Status
))
2335 SetLastNtError(Status
);
2339 else if (! IS_ATOM(ClassName
.Buffer
))
2341 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2345 /* safely copy the window name */
2346 if (NULL
!= UnsafeWindowName
)
2348 Status
= IntSafeCopyUnicodeString(&WindowName
, UnsafeWindowName
);
2349 if (! NT_SUCCESS(Status
))
2351 if (! IS_ATOM(ClassName
.Buffer
))
2353 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2355 SetLastNtError(Status
);
2361 RtlInitUnicodeString(&WindowName
, NULL
);
2364 pNewWindow
= co_IntCreateWindowEx( dwExStyle
,
2379 if (pNewWindow
) NewWindow
= UserHMGetHandle(pNewWindow
);
2381 if (WindowName
.Buffer
)
2383 ExFreePoolWithTag(WindowName
.Buffer
, TAG_STRING
);
2385 if (! IS_ATOM(ClassName
.Buffer
))
2387 ExFreePoolWithTag(ClassName
.Buffer
, TAG_STRING
);
2393 DPRINT("Leave NtUserCreateWindowEx, ret=%i\n",_ret_
);
2402 NtUserDeferWindowPos(HDWP WinPosInfo
,
2404 HWND WndInsertAfter
,
2417 BOOLEAN FASTCALL
co_UserDestroyWindow(PWINDOW_OBJECT Window
)
2423 ASSERT_REFS_CO(Window
); // FIXME: temp hack?
2425 hWnd
= Window
->hSelf
;
2429 if (!Wnd
) return TRUE
; // FIXME: Need to finish object rewrite or lock the thread when killing the window!
2431 /* Check for owner thread */
2432 if ((Window
->OwnerThread
!= PsGetCurrentThread()))
2434 SetLastWin32Error(ERROR_ACCESS_DENIED
);
2439 if (ISITHOOKED(WH_CBT
))
2441 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0)) return FALSE
;
2444 /* Look whether the focus is within the tree of windows we will
2447 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2449 if (UserGetActiveWindow() == Window
->hSelf
)
2451 co_WinPosActivateOtherWindow(Window
);
2455 if (Window
->MessageQueue
->ActiveWindow
== Window
->hSelf
)
2456 Window
->MessageQueue
->ActiveWindow
= NULL
;
2457 if (Window
->MessageQueue
->FocusWindow
== Window
->hSelf
)
2458 Window
->MessageQueue
->FocusWindow
= NULL
;
2459 if (Window
->MessageQueue
->CaptureWindow
== Window
->hSelf
)
2460 Window
->MessageQueue
->CaptureWindow
= NULL
;
2462 IntDereferenceMessageQueue(Window
->MessageQueue
);
2464 IntEngWindowChanged(Window
, WOC_DELETE
);
2465 isChild
= (0 != (Wnd
->style
& WS_CHILD
));
2471 if (! USER_IsExitingThread(GetCurrentThreadId()))
2473 send_parent_notify(hwnd
, WM_DESTROY
);
2476 else if (NULL
!= GetWindow(Wnd
, GW_OWNER
))
2478 co_HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2479 /* FIXME: clean up palette - see "Internals" p.352 */
2483 if (!IntIsWindow(Window
->hSelf
))
2488 /* Recursively destroy owned windows */
2493 BOOL GotOne
= FALSE
;
2496 PWINDOW_OBJECT Child
, Desktop
;
2498 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2499 UserGetWindowObject(IntGetDesktopWindow());
2500 Children
= IntWinListChildren(Desktop
);
2504 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2506 Child
= UserGetWindowObject(*ChildHandle
);
2509 if (Child
->hOwner
!= Window
->hSelf
)
2514 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2516 USER_REFERENCE_ENTRY ChildRef
;
2517 UserRefObjectCo(Child
, &ChildRef
);//temp hack?
2518 co_UserDestroyWindow(Child
);
2519 UserDerefObjectCo(Child
);//temp hack?
2525 if (Child
->hOwner
!= NULL
)
2527 Child
->hOwner
= NULL
;
2528 Child
->Wnd
->spwndOwner
= NULL
;
2532 ExFreePool(Children
);
2541 if (!IntIsWindow(Window
->hSelf
))
2546 /* Destroy the window storage */
2547 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2559 NtUserDestroyWindow(HWND Wnd
)
2561 PWINDOW_OBJECT Window
;
2562 DECLARE_RETURN(BOOLEAN
);
2564 USER_REFERENCE_ENTRY Ref
;
2566 DPRINT("Enter NtUserDestroyWindow\n");
2567 UserEnterExclusive();
2569 if (!(Window
= UserGetWindowObject(Wnd
)))
2574 UserRefObjectCo(Window
, &Ref
);//faxme: dunno if win should be reffed during destroy..
2575 ret
= co_UserDestroyWindow(Window
);
2576 UserDerefObjectCo(Window
);//faxme: dunno if win should be reffed during destroy..
2581 DPRINT("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2593 NtUserDrawMenuBarTemp(
2600 /* we'll use this function just for caching the menu bar */
2610 NtUserEndDeferWindowPosEx(DWORD Unknown0
,
2620 * FillWindow: Called from User; Dialog, Edit and ListBox procs during a WM_ERASEBKGND.
2626 NtUserFillWindow(HWND hWndPaint
,
2637 static HWND FASTCALL
2638 IntFindWindow(PWINDOW_OBJECT Parent
,
2639 PWINDOW_OBJECT ChildAfter
,
2641 PUNICODE_STRING WindowName
)
2643 BOOL CheckWindowName
;
2649 CheckWindowName
= WindowName
->Length
!= 0;
2651 if((List
= IntWinListChildren(Parent
)))
2656 /* skip handles before and including ChildAfter */
2657 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2661 /* search children */
2664 PWINDOW_OBJECT Child
;
2665 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2670 /* Do not send WM_GETTEXT messages in the kernel mode version!
2671 The user mode version however calls GetWindowText() which will
2672 send WM_GETTEXT messages to windows belonging to its processes */
2673 if((!CheckWindowName
|| !RtlCompareUnicodeString(WindowName
, &(Child
->Wnd
->strName
), TRUE
)) &&
2674 (!ClassAtom
|| Child
->Wnd
->pcls
->atomClassName
== ClassAtom
))
2689 * Searches a window's children for a window with the specified
2692 * hwndParent = The window whose childs are to be searched.
2694 * HWND_MESSAGE = message-only windows
2696 * hwndChildAfter = Search starts after this child window.
2697 * NULL = start from beginning
2699 * ucClassName = Class name to search for
2700 * Reguired parameter.
2702 * ucWindowName = Window name
2703 * ->Buffer == NULL = don't care
2706 * The HWND of the window if it was found, otherwise NULL
2712 NtUserFindWindowEx(HWND hwndParent
,
2713 HWND hwndChildAfter
,
2714 PUNICODE_STRING ucClassName
,
2715 PUNICODE_STRING ucWindowName
,
2718 PWINDOW_OBJECT Parent
, ChildAfter
;
2719 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2720 HWND Desktop
, Ret
= NULL
;
2721 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2722 DECLARE_RETURN(HWND
);
2724 DPRINT("Enter NtUserFindWindowEx\n");
2727 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2731 if (ucClassName
!= NULL
)
2733 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2734 if (ClassName
.Length
!= 0)
2736 ProbeForRead(ClassName
.Buffer
,
2740 else if (!IS_ATOM(ClassName
.Buffer
))
2742 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2746 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2753 if (ucWindowName
!= NULL
)
2755 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2756 if (WindowName
.Length
!= 0)
2758 ProbeForRead(WindowName
.Buffer
,
2764 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2766 SetLastNtError(_SEH2_GetExceptionCode());
2767 _SEH2_YIELD(RETURN(NULL
));
2771 if (ucClassName
!= NULL
)
2773 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2774 !IS_ATOM(ClassName
.Buffer
))
2776 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
2779 else if (ClassAtom
== (RTL_ATOM
)0)
2781 /* LastError code was set by IntGetAtomFromStringOrAtom */
2787 Desktop
= IntGetCurrentThreadDesktopWindow();
2789 if(hwndParent
== NULL
)
2790 hwndParent
= Desktop
;
2791 else if(hwndParent
== HWND_MESSAGE
)
2793 hwndParent
= IntGetMessageWindow();
2796 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2802 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2809 if(Parent
->hSelf
== Desktop
)
2812 PWINDOW_OBJECT TopLevelWindow
;
2813 BOOLEAN CheckWindowName
;
2814 BOOLEAN WindowMatches
;
2815 BOOLEAN ClassMatches
;
2817 /* windows searches through all top-level windows if the parent is the desktop
2820 if((List
= IntWinListChildren(Parent
)))
2826 /* skip handles before and including ChildAfter */
2827 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->hSelf
))
2831 CheckWindowName
= WindowName
.Length
!= 0;
2833 /* search children */
2836 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2841 /* Do not send WM_GETTEXT messages in the kernel mode version!
2842 The user mode version however calls GetWindowText() which will
2843 send WM_GETTEXT messages to windows belonging to its processes */
2844 WindowMatches
= !CheckWindowName
|| !RtlCompareUnicodeString(
2845 &WindowName
, &TopLevelWindow
->Wnd
->strName
, TRUE
);
2846 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2847 ClassAtom
== TopLevelWindow
->Wnd
->pcls
->atomClassName
;
2849 if (WindowMatches
&& ClassMatches
)
2851 Ret
= TopLevelWindow
->hSelf
;
2855 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2857 /* window returns the handle of the top-level window, in case it found
2859 Ret
= TopLevelWindow
->hSelf
;
2868 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2872 if(Ret
== NULL
&& hwndParent
== NULL
&& hwndChildAfter
== NULL
)
2874 /* FIXME - if both hwndParent and hwndChildAfter are NULL, we also should
2875 search the message-only windows. Should this also be done if
2876 Parent is the desktop window??? */
2877 PWINDOW_OBJECT MsgWindows
;
2879 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2881 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2886 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2888 SetLastNtError(_SEH2_GetExceptionCode());
2896 DPRINT("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2906 NtUserFlashWindowEx(IN PFLASHWINFO pfwi
)
2917 PWINDOW_OBJECT FASTCALL
UserGetAncestor(PWINDOW_OBJECT Wnd
, UINT Type
)
2919 PWINDOW_OBJECT WndAncestor
, Parent
;
2921 if (Wnd
->hSelf
== IntGetDesktopWindow())
2930 WndAncestor
= Wnd
->Parent
;
2941 if(!(Parent
= WndAncestor
->Parent
))
2945 if(IntIsDesktopWindow(Parent
))
2950 WndAncestor
= Parent
;
2961 PWINDOW_OBJECT Parent
, Old
;
2964 Parent
= IntGetParent(WndAncestor
);
2972 // UserDereferenceObject(Parent);
2974 WndAncestor
= Parent
;
2994 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2996 PWINDOW_OBJECT Window
, Ancestor
;
2997 DECLARE_RETURN(HWND
);
2999 DPRINT("Enter NtUserGetAncestor\n");
3000 UserEnterExclusive();
3002 if (!(Window
= UserGetWindowObject(hWnd
)))
3007 Ancestor
= UserGetAncestor(Window
, Type
);
3008 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3010 RETURN(Ancestor
? Ancestor
->hSelf
: NULL
);
3013 DPRINT("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
3021 NtUserGetComboBoxInfo(
3026 DECLARE_RETURN(BOOL
);
3028 DPRINT("Enter NtUserGetComboBoxInfo\n");
3031 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3040 sizeof(COMBOBOXINFO
),
3044 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3046 SetLastNtError(_SEH2_GetExceptionCode());
3047 _SEH2_YIELD(RETURN(FALSE
));
3051 // Pass the user pointer, it was already probed.
3052 RETURN( (BOOL
) co_IntSendMessage( Wnd
->hSelf
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3055 DPRINT("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3065 NtUserGetInternalWindowPos( HWND hWnd
,
3069 PWINDOW_OBJECT Window
;
3073 WINDOWPLACEMENT wndpl
;
3077 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3088 ProbeForWrite(rectWnd
,
3094 ProbeForWrite(ptIcon
,
3100 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3102 SetLastNtError(_SEH2_GetExceptionCode());
3107 wndpl
.length
= sizeof(WINDOWPLACEMENT
);
3109 if (IntGetWindowPlacement(Window
, &wndpl
) && !Hit
)
3115 RtlCopyMemory(rectWnd
, &wndpl
.rcNormalPosition
, sizeof(RECT
));
3119 RtlCopyMemory(ptIcon
, &wndpl
.ptMinPosition
, sizeof(POINT
));
3123 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3125 SetLastNtError(_SEH2_GetExceptionCode());
3130 if (!Hit
) Ret
= wndpl
.showCmd
;
3139 NtUserGetListBoxInfo(
3143 DECLARE_RETURN(DWORD
);
3145 DPRINT("Enter NtUserGetListBoxInfo\n");
3148 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3153 RETURN( (DWORD
) co_IntSendMessage( Wnd
->hSelf
, LB_GETLISTBOXINFO
, 0, 0 ));
3156 DPRINT("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3163 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3165 PWINDOW_OBJECT Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
3166 HWND hWndOldParent
= NULL
;
3167 USER_REFERENCE_ENTRY Ref
, ParentRef
;
3169 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
3171 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3175 if (hWndChild
== IntGetDesktopWindow())
3177 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3183 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
3190 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
3196 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
3201 UserRefObjectCo(Wnd
, &Ref
);
3202 UserRefObjectCo(WndParent
, &ParentRef
);
3204 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
3206 UserDerefObjectCo(WndParent
);
3207 UserDerefObjectCo(Wnd
);
3211 hWndOldParent
= WndOldParent
->hSelf
;
3212 UserDereferenceObject(WndOldParent
);
3215 return( hWndOldParent
);
3223 * The NtUserSetParent function changes the parent window of the specified
3227 * The new parent window and the child window must belong to the same
3228 * application. If the window identified by the hWndChild parameter is
3229 * visible, the system performs the appropriate redrawing and repainting.
3230 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3231 * or WS_POPUP window styles of the window whose parent is being changed.
3238 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3240 DECLARE_RETURN(HWND
);
3242 DPRINT("Enter NtUserSetParent\n");
3243 UserEnterExclusive();
3246 Check Parent first from user space, set it here.
3250 hWndNewParent
= IntGetDesktopWindow();
3252 else if (hWndNewParent
== HWND_MESSAGE
)
3254 hWndNewParent
= IntGetMessageWindow();
3257 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3260 DPRINT("Leave NtUserSetParent, ret=%i\n",_ret_
);
3268 * UserGetShellWindow
3270 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3275 HWND FASTCALL
UserGetShellWindow(VOID
)
3277 PWINSTATION_OBJECT WinStaObject
;
3280 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3285 if (!NT_SUCCESS(Status
))
3287 SetLastNtError(Status
);
3291 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3293 ObDereferenceObject(WinStaObject
);
3298 * NtUserSetShellWindowEx
3300 * This is undocumented function to set global shell window. The global
3301 * shell window has special handling of window position.
3307 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3309 PWINSTATION_OBJECT WinStaObject
;
3310 PWINDOW_OBJECT WndShell
;
3311 DECLARE_RETURN(BOOL
);
3312 USER_REFERENCE_ENTRY Ref
;
3316 DPRINT("Enter NtUserSetShellWindowEx\n");
3317 UserEnterExclusive();
3319 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3324 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3329 if (!NT_SUCCESS(Status
))
3331 SetLastNtError(Status
);
3336 * Test if we are permitted to change the shell window.
3338 if (WinStaObject
->ShellWindow
)
3340 ObDereferenceObject(WinStaObject
);
3345 * Move shell window into background.
3347 if (hwndListView
&& hwndListView
!= hwndShell
)
3350 * Disabled for now to get Explorer working.
3351 * -- Filip, 01/nov/2003
3354 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3357 if (UserGetWindowLong(hwndListView
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3359 ObDereferenceObject(WinStaObject
);
3364 if (UserGetWindowLong(hwndShell
, GWL_EXSTYLE
, FALSE
) & WS_EX_TOPMOST
)
3366 ObDereferenceObject(WinStaObject
);
3370 UserRefObjectCo(WndShell
, &Ref
);
3371 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3373 WinStaObject
->ShellWindow
= hwndShell
;
3374 WinStaObject
->ShellListView
= hwndListView
;
3376 ti
= GetW32ThreadInfo();
3377 if (ti
->pDeskInfo
) ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3379 UserDerefObjectCo(WndShell
);
3381 ObDereferenceObject(WinStaObject
);
3385 DPRINT("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3391 * NtUserGetSystemMenu
3393 * The NtUserGetSystemMenu function allows the application to access the
3394 * window menu (also known as the system menu or the control menu) for
3395 * copying and modifying.
3399 * Handle to the window that will own a copy of the window menu.
3401 * Specifies the action to be taken. If this parameter is FALSE,
3402 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3403 * currently in use. The copy is initially identical to the window menu
3404 * but it can be modified.
3405 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3406 * to the default state. The previous window menu, if any, is destroyed.
3409 * If the bRevert parameter is FALSE, the return value is a handle to a
3410 * copy of the window menu. If the bRevert parameter is TRUE, the return
3418 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3420 PWINDOW_OBJECT Window
;
3422 DECLARE_RETURN(HMENU
);
3424 DPRINT("Enter NtUserGetSystemMenu\n");
3427 if (!(Window
= UserGetWindowObject(hWnd
)))
3432 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3437 RETURN(Menu
->MenuInfo
.Self
);
3440 DPRINT("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3446 * NtUserSetSystemMenu
3453 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3455 BOOL Result
= FALSE
;
3456 PWINDOW_OBJECT Window
;
3458 DECLARE_RETURN(BOOL
);
3460 DPRINT("Enter NtUserSetSystemMenu\n");
3461 UserEnterExclusive();
3463 if (!(Window
= UserGetWindowObject(hWnd
)))
3471 * Assign new menu handle.
3473 if (!(Menu
= UserGetMenuObject(hMenu
)))
3478 Result
= IntSetSystemMenu(Window
, Menu
);
3484 DPRINT("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3493 UserGetWindow(HWND hWnd
, UINT Relationship
)
3495 PWINDOW_OBJECT Parent
, Window
;
3496 HWND hWndResult
= NULL
;
3498 if (!(Window
= UserGetWindowObject(hWnd
)))
3501 switch (Relationship
)
3504 if((Parent
= Window
->Parent
))
3506 if (Parent
->FirstChild
)
3507 hWndResult
= Parent
->FirstChild
->hSelf
;
3512 if((Parent
= Window
->Parent
))
3514 if (Parent
->LastChild
)
3515 hWndResult
= Parent
->LastChild
->hSelf
;
3520 if (Window
->NextSibling
)
3521 hWndResult
= Window
->NextSibling
->hSelf
;
3525 if (Window
->PrevSibling
)
3526 hWndResult
= Window
->PrevSibling
->hSelf
;
3530 if((Parent
= UserGetWindowObject(Window
->hOwner
)))
3532 hWndResult
= Parent
->hSelf
;
3536 if (Window
->FirstChild
)
3537 hWndResult
= Window
->FirstChild
->hSelf
;
3549 * The NtUserGetWindow function retrieves a handle to a window that has the
3550 * specified relationship (Z order or owner) to the specified window.
3557 NtUserGetWindow(HWND hWnd
, UINT Relationship
)
3559 DECLARE_RETURN(HWND
);
3561 DPRINT("Enter NtUserGetWindow\n");
3564 RETURN(UserGetWindow(hWnd
, Relationship
));
3567 DPRINT("Leave NtUserGetWindow, ret=%i\n",_ret_
);
3576 * NtUserGetWindowLong
3578 * The NtUserGetWindowLong function retrieves information about the specified
3579 * window. The function also retrieves the 32-bit (long) value at the
3580 * specified offset into the extra window memory.
3587 UserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3589 PWINDOW_OBJECT Window
, Parent
;
3593 DPRINT("NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3595 if (!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
3603 * WndProc is only available to the owner process
3605 if (GWL_WNDPROC
== Index
3606 && Window
->OwnerThread
->ThreadsProcess
!= PsGetCurrentProcess())
3608 SetLastWin32Error(ERROR_ACCESS_DENIED
);
3612 if ((INT
)Index
>= 0)
3614 if ((Index
+ sizeof(LONG
)) > Window
->Wnd
->cbwndExtra
)
3616 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3619 Result
= *((LONG
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3626 Result
= Wnd
->ExStyle
;
3630 Result
= Wnd
->style
;
3634 Result
= (LONG
)IntGetWindowProc(Window
,
3639 Result
= (LONG
) Wnd
->hModule
;
3642 case GWL_HWNDPARENT
:
3643 Parent
= Window
->Parent
;
3646 if (Parent
&& Parent
->hSelf
== IntGetDesktopWindow())
3647 Result
= (LONG
) UserGetWindow(Window
->hSelf
, GW_OWNER
);
3649 Result
= (LONG
) Parent
->hSelf
;
3654 Result
= (LONG
) Wnd
->IDMenu
;
3658 Result
= Wnd
->dwUserData
;
3662 DPRINT1("NtUserGetWindowLong(): Unsupported index %d\n", Index
);
3663 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3676 * NtUserGetWindowLong
3678 * The NtUserGetWindowLong function retrieves information about the specified
3679 * window. The function also retrieves the 32-bit (long) value at the
3680 * specified offset into the extra window memory.
3687 NtUserGetWindowLong(HWND hWnd
, DWORD Index
, BOOL Ansi
)
3689 DECLARE_RETURN(LONG
);
3691 DPRINT("Enter NtUserGetWindowLong(%x,%d,%d)\n", hWnd
, (INT
)Index
, Ansi
);
3692 UserEnterExclusive();
3694 RETURN(UserGetWindowLong(hWnd
, Index
, Ansi
));
3697 DPRINT("Leave NtUserGetWindowLong, ret=%i\n",_ret_
);
3703 IntSetWindowProc(PWINDOW_OBJECT Window
,
3708 PCALLPROCDATA CallProc
;
3709 PWND Wnd
= Window
->Wnd
;
3711 /* resolve any callproc handle if possible */
3712 if (IsCallProcHandle(NewWndProc
))
3714 WNDPROC_INFO wpInfo
;
3716 if (UserGetCallProcInfo((HANDLE
)NewWndProc
,
3719 NewWndProc
= wpInfo
.WindowProc
;
3720 /* FIXME - what if wpInfo.IsUnicode doesn't match Ansi? */
3724 /* attempt to get the previous window proc */
3727 Ret
= (Ansi
? Wnd
->WndProcExtra
: Wnd
->lpfnWndProc
);
3731 if (!Ansi
== Wnd
->Unicode
)
3733 Ret
= Wnd
->lpfnWndProc
;
3737 CallProc
= UserFindCallProc(Wnd
->pcls
,
3740 if (CallProc
== NULL
)
3742 CallProc
= CreateCallProc(NULL
,
3745 Wnd
->head
.pti
->ppi
);
3746 if (CallProc
== NULL
)
3748 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
3752 UserAddCallProcToClass(Wnd
->pcls
,
3755 /* BugBoy Comments: Added this if else, see below comments */
3758 Ret
= Wnd
->lpfnWndProc
;
3762 Ret
= GetCallProcHandle(Wnd
->CallProc
);
3765 Wnd
->CallProc
= CallProc
;
3767 /* BugBoy Comments: Above sets the current CallProc for the
3768 window and below we set the Ret value to it.
3769 SetWindowLong for WNDPROC should return the previous proc
3770 Ret = GetCallProcHandle(Wnd->CallProc); */
3774 if (Wnd
->pcls
->System
)
3776 /* check if the new procedure matches with the one in the
3777 window class. If so, we need to restore both procedures! */
3778 Wnd
->IsSystem
= (NewWndProc
== Wnd
->pcls
->lpfnWndProc
||
3779 NewWndProc
== Wnd
->pcls
->WndProcExtra
);
3783 Wnd
->lpfnWndProc
= Wnd
->pcls
->lpfnWndProc
;
3784 Wnd
->WndProcExtra
= Wnd
->pcls
->WndProcExtra
;
3785 Wnd
->Unicode
= !Ansi
;
3790 ASSERT(!Wnd
->IsSystem
);
3792 /* update the window procedure */
3793 Wnd
->lpfnWndProc
= NewWndProc
;
3794 Wnd
->Unicode
= !Ansi
;
3801 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3803 PWINDOW_OBJECT Window
, Parent
;
3805 PWINSTATION_OBJECT WindowStation
;
3809 if (hWnd
== IntGetDesktopWindow())
3811 SetLastWin32Error(STATUS_ACCESS_DENIED
);
3815 if (!(Window
= UserGetWindowObject(hWnd
)))
3822 if (!Wnd
) return 0; // No go on zero.
3824 if ((INT
)Index
>= 0)
3826 if ((Index
+ sizeof(LONG
)) > Wnd
->cbwndExtra
)
3828 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3831 OldValue
= *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
));
3832 *((LONG
*)((PCHAR
)(Wnd
+ 1) + Index
)) = NewValue
;
3839 OldValue
= (LONG
) Wnd
->ExStyle
;
3840 Style
.styleOld
= OldValue
;
3841 Style
.styleNew
= NewValue
;
3844 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3846 WindowStation
= ((PTHREADINFO
)Window
->OwnerThread
->Tcb
.Win32Thread
)->Desktop
->WindowStation
;
3849 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3850 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3853 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3854 Wnd
->ExStyle
= (DWORD
)Style
.styleNew
;
3855 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3859 OldValue
= (LONG
) Wnd
->style
;
3860 Style
.styleOld
= OldValue
;
3861 Style
.styleNew
= NewValue
;
3862 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3863 Wnd
->style
= (DWORD
)Style
.styleNew
;
3864 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3869 /* FIXME: should check if window belongs to current process */
3870 OldValue
= (LONG
)IntSetWindowProc(Window
,
3877 OldValue
= (LONG
) Wnd
->hModule
;
3878 Wnd
->hModule
= (HINSTANCE
) NewValue
;
3881 case GWL_HWNDPARENT
:
3882 Parent
= Window
->Parent
;
3883 if (Parent
&& (Parent
->hSelf
== IntGetDesktopWindow()))
3884 OldValue
= (LONG
) IntSetOwner(Window
->hSelf
, (HWND
) NewValue
);
3886 OldValue
= (LONG
) co_UserSetParent(Window
->hSelf
, (HWND
) NewValue
);
3890 OldValue
= (LONG
) Wnd
->IDMenu
;
3891 Wnd
->IDMenu
= (UINT
) NewValue
;
3895 OldValue
= Wnd
->dwUserData
;
3896 Wnd
->dwUserData
= NewValue
;
3900 DPRINT1("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3901 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3913 * NtUserSetWindowLong
3915 * The NtUserSetWindowLong function changes an attribute of the specified
3916 * window. The function also sets the 32-bit (long) value at the specified
3917 * offset into the extra window memory.
3924 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3926 DECLARE_RETURN(LONG
);
3928 DPRINT("Enter NtUserSetWindowLong\n");
3929 UserEnterExclusive();
3931 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3934 DPRINT("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3940 * NtUserSetWindowWord
3942 * Legacy function similar to NtUserSetWindowLong.
3949 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3951 PWINDOW_OBJECT Window
;
3953 DECLARE_RETURN(WORD
);
3955 DPRINT("Enter NtUserSetWindowWord\n");
3956 UserEnterExclusive();
3958 if (!(Window
= UserGetWindowObject(hWnd
)))
3967 case GWL_HWNDPARENT
:
3968 RETURN( co_UserSetWindowLong(Window
->hSelf
, Index
, (UINT
)NewValue
, TRUE
));
3972 SetLastWin32Error(ERROR_INVALID_INDEX
);
3977 if (Index
> Window
->Wnd
->cbwndExtra
- sizeof(WORD
))
3979 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
3983 OldValue
= *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
));
3984 *((WORD
*)((PCHAR
)(Window
->Wnd
+ 1) + Index
)) = NewValue
;
3989 DPRINT("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3998 NtUserGetWindowPlacement(HWND hWnd
,
3999 WINDOWPLACEMENT
*lpwndpl
)
4001 PWINDOW_OBJECT Window
;
4004 WINDOWPLACEMENT Safepl
;
4006 DECLARE_RETURN(BOOL
);
4008 DPRINT("Enter NtUserGetWindowPlacement\n");
4011 if (!(Window
= UserGetWindowObject(hWnd
)))
4017 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4018 if(!NT_SUCCESS(Status
))
4020 SetLastNtError(Status
);
4023 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4029 if (0 == (Wnd
->style
& WS_VISIBLE
))
4031 Safepl
.showCmd
= SW_HIDE
;
4033 else if ((0 != (Window
->Flags
& WINDOWOBJECT_RESTOREMAX
) ||
4034 0 != (Wnd
->style
& WS_MAXIMIZE
)) &&
4035 0 == (Wnd
->style
& WS_MINIMIZE
))
4037 Safepl
.showCmd
= SW_SHOWMAXIMIZED
;
4039 else if (0 != (Wnd
->style
& WS_MINIMIZE
))
4041 Safepl
.showCmd
= SW_SHOWMINIMIZED
;
4043 else if (0 != (Wnd
->style
& WS_VISIBLE
))
4045 Safepl
.showCmd
= SW_SHOWNORMAL
;
4048 Size
.x
= Wnd
->rcWindow
.left
;
4049 Size
.y
= Wnd
->rcWindow
.top
;
4050 WinPosInitInternalPos(Window
, &Size
,
4053 Safepl
.rcNormalPosition
= Wnd
->InternalPos
.NormalRect
;
4054 Safepl
.ptMinPosition
= Wnd
->InternalPos
.IconPos
;
4055 Safepl
.ptMaxPosition
= Wnd
->InternalPos
.MaxPos
;
4057 Status
= MmCopyToCaller(lpwndpl
, &Safepl
, sizeof(WINDOWPLACEMENT
));
4058 if(!NT_SUCCESS(Status
))
4060 SetLastNtError(Status
);
4067 DPRINT("Leave NtUserGetWindowPlacement, ret=%i\n",_ret_
);
4077 NtUserLockWindowUpdate(HWND hWnd
)
4097 return NtUserSetWindowPos(hWnd
, 0, X
, Y
, nWidth
, nHeight
,
4098 (bRepaint
? SWP_NOZORDER
| SWP_NOACTIVATE
:
4099 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
));
4103 QueryWindow based on KJK::Hyperion and James Tabor.
4105 0 = QWUniqueProcessId
4106 1 = QWUniqueThreadId
4109 4 = QWIsHung Implements IsHungAppWindow found
4112 9 = QWKillWindow When I called this with hWnd ==
4113 DesktopWindow, it shutdown the system
4120 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
4122 PWINDOW_OBJECT Window
;
4124 DECLARE_RETURN(UINT
);
4126 DPRINT("Enter NtUserQueryWindow\n");
4129 if (!(Window
= UserGetWindowObject(hWnd
)))
4136 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
4137 Result
= (DWORD
)IntGetWndProcessId(Window
);
4140 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
4141 Result
= (DWORD
)IntGetWndThreadId(Window
);
4144 case QUERY_WINDOW_ACTIVE
:
4145 Result
= (DWORD
)UserGetActiveWindow();
4148 case QUERY_WINDOW_FOCUS
:
4149 Result
= (DWORD
)IntGetFocusWindow();
4152 case QUERY_WINDOW_ISHUNG
:
4153 Result
= (DWORD
)MsqIsHung(Window
->MessageQueue
);
4157 Result
= (DWORD
)NULL
;
4164 DPRINT("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
4174 NtUserRealChildWindowFromPoint(DWORD Unknown0
,
4188 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4190 UNICODE_STRING SafeMessageName
;
4193 DECLARE_RETURN(UINT
);
4195 DPRINT("Enter NtUserRegisterWindowMessage\n");
4196 UserEnterExclusive();
4198 if(MessageNameUnsafe
== NULL
)
4200 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4204 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4205 if(!NT_SUCCESS(Status
))
4207 SetLastNtError(Status
);
4211 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4213 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4217 DPRINT("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
4227 NtUserSetImeOwnerWindow(DWORD Unknown0
,
4240 NtUserSetInternalWindowPos(
4257 NtUserSetLayeredWindowAttributes(HWND hwnd
,
4271 NtUserSetLogonNotifyWindow(HWND hWnd
)
4288 PWINDOW_OBJECT Window
;
4290 DECLARE_RETURN(BOOL
);
4292 DPRINT("Enter NtUserSetMenu\n");
4293 UserEnterExclusive();
4295 if (!(Window
= UserGetWindowObject(hWnd
)))
4300 if (! IntSetMenu(Window
, Menu
, &Changed
))
4305 if (Changed
&& Repaint
)
4307 USER_REFERENCE_ENTRY Ref
;
4309 UserRefObjectCo(Window
, &Ref
);
4310 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
4311 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
4313 UserDerefObjectCo(Window
);
4319 DPRINT("Leave NtUserSetMenu, ret=%i\n",_ret_
);
4329 NtUserSetWindowFNID(HWND hWnd
,
4332 PWINDOW_OBJECT Window
;
4334 DECLARE_RETURN(BOOL
);
4336 DPRINT("Enter NtUserSetWindowFNID\n");
4337 UserEnterExclusive();
4339 if (!(Window
= UserGetWindowObject(hWnd
)))
4346 { // From user land we only set these.
4347 if ((fnID
!= FNID_DESTROY
) || ((fnID
< FNID_BUTTON
) && (fnID
> FNID_IME
)) )
4352 Wnd
->pcls
->fnid
|= fnID
;
4357 DPRINT("Leave NtUserSetWindowFNID\n");
4367 NtUserSetWindowPlacement(HWND hWnd
,
4368 WINDOWPLACEMENT
*lpwndpl
)
4370 PWINDOW_OBJECT Window
;
4372 WINDOWPLACEMENT Safepl
;
4374 DECLARE_RETURN(BOOL
);
4375 USER_REFERENCE_ENTRY Ref
;
4377 DPRINT("Enter NtUserSetWindowPlacement\n");
4378 UserEnterExclusive();
4380 if (!(Window
= UserGetWindowObject(hWnd
)))
4386 Status
= MmCopyFromCaller(&Safepl
, lpwndpl
, sizeof(WINDOWPLACEMENT
));
4387 if(!NT_SUCCESS(Status
))
4389 SetLastNtError(Status
);
4392 if(Safepl
.length
!= sizeof(WINDOWPLACEMENT
))
4397 UserRefObjectCo(Window
, &Ref
);
4399 if ((Wnd
->style
& (WS_MAXIMIZE
| WS_MINIMIZE
)) == 0)
4401 co_WinPosSetWindowPos(Window
, NULL
,
4402 Safepl
.rcNormalPosition
.left
, Safepl
.rcNormalPosition
.top
,
4403 Safepl
.rcNormalPosition
.right
- Safepl
.rcNormalPosition
.left
,
4404 Safepl
.rcNormalPosition
.bottom
- Safepl
.rcNormalPosition
.top
,
4405 SWP_NOZORDER
| SWP_NOACTIVATE
);
4408 /* FIXME - change window status */
4409 co_WinPosShowWindow(Window
, Safepl
.showCmd
);
4411 Wnd
->InternalPosInitialized
= TRUE
;
4412 Wnd
->InternalPos
.NormalRect
= Safepl
.rcNormalPosition
;
4413 Wnd
->InternalPos
.IconPos
= Safepl
.ptMinPosition
;
4414 Wnd
->InternalPos
.MaxPos
= Safepl
.ptMaxPosition
;
4416 UserDerefObjectCo(Window
);
4420 DPRINT("Leave NtUserSetWindowPlacement, ret=%i\n",_ret_
);
4432 HWND hWndInsertAfter
,
4439 DECLARE_RETURN(BOOL
);
4440 PWINDOW_OBJECT Window
;
4442 USER_REFERENCE_ENTRY Ref
;
4444 DPRINT("Enter NtUserSetWindowPos\n");
4445 UserEnterExclusive();
4447 if (!(Window
= UserGetWindowObject(hWnd
)))
4452 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
4453 if (!(uFlags
& SWP_NOMOVE
))
4455 if (X
< -32768) X
= -32768;
4456 else if (X
> 32767) X
= 32767;
4457 if (Y
< -32768) Y
= -32768;
4458 else if (Y
> 32767) Y
= 32767;
4460 if (!(uFlags
& SWP_NOSIZE
))
4463 else if (cx
> 32767) cx
= 32767;
4465 else if (cy
> 32767) cy
= 32767;
4468 UserRefObjectCo(Window
, &Ref
);
4469 ret
= co_WinPosSetWindowPos(Window
, hWndInsertAfter
, X
, Y
, cx
, cy
, uFlags
);
4470 UserDerefObjectCo(Window
);
4475 DPRINT("Leave NtUserSetWindowPos, ret=%i\n",_ret_
);
4482 IntGetWindowRgn(PWINDOW_OBJECT Window
, HRGN hRgn
)
4500 /* Create a new window region using the window rectangle */
4501 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4502 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4503 /* if there's a region assigned to the window, combine them both */
4504 if(Window
->WindowRegion
&& !(Wnd
->style
& WS_MINIMIZE
))
4505 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4506 /* Copy the region into hRgn */
4507 NtGdiCombineRgn(hRgn
, VisRgn
, NULL
, RGN_COPY
);
4509 if((pRgn
= REGION_LockRgn(hRgn
)))
4511 Ret
= pRgn
->rdh
.iType
;
4512 REGION_UnlockRgn(pRgn
);
4517 GreDeleteObject(VisRgn
);
4523 IntGetWindowRgnBox(PWINDOW_OBJECT Window
, RECTL
*Rect
)
4541 /* Create a new window region using the window rectangle */
4542 VisRgn
= UnsafeIntCreateRectRgnIndirect(&Window
->Wnd
->rcWindow
);
4543 NtGdiOffsetRgn(VisRgn
, -Window
->Wnd
->rcWindow
.left
, -Window
->Wnd
->rcWindow
.top
);
4544 /* if there's a region assigned to the window, combine them both */
4545 if(Window
->WindowRegion
&& !(Wnd
->style
& WS_MINIMIZE
))
4546 NtGdiCombineRgn(VisRgn
, VisRgn
, Window
->WindowRegion
, RGN_AND
);
4548 if((pRgn
= REGION_LockRgn(VisRgn
)))
4550 Ret
= pRgn
->rdh
.iType
;
4551 *Rect
= pRgn
->rdh
.rcBound
;
4552 REGION_UnlockRgn(pRgn
);
4557 GreDeleteObject(VisRgn
);
4572 PWINDOW_OBJECT Window
;
4573 DECLARE_RETURN(INT
);
4575 DPRINT("Enter NtUserSetWindowRgn\n");
4576 UserEnterExclusive();
4578 if (!(Window
= UserGetWindowObject(hWnd
)))
4583 /* FIXME - Verify if hRgn is a valid handle!!!!
4584 Propably make this operation thread-safe, but maybe it's not necessary */
4586 if(Window
->WindowRegion
)
4588 /* Delete no longer needed region handle */
4589 GreDeleteObject(Window
->WindowRegion
);
4591 Window
->WindowRegion
= hRgn
;
4593 /* FIXME - send WM_WINDOWPOSCHANGING and WM_WINDOWPOSCHANGED messages to the window */
4597 USER_REFERENCE_ENTRY Ref
;
4598 UserRefObjectCo(Window
, &Ref
);
4599 co_UserRedrawWindow(Window
, NULL
, NULL
, RDW_INVALIDATE
);
4600 UserDerefObjectCo(Window
);
4606 DPRINT("Leave NtUserSetWindowRgn, ret=%i\n",_ret_
);
4616 NtUserShowWindow(HWND hWnd
, LONG nCmdShow
)
4618 PWINDOW_OBJECT Window
;
4620 DECLARE_RETURN(BOOL
);
4621 USER_REFERENCE_ENTRY Ref
;
4623 DPRINT("Enter NtUserShowWindow\n");
4624 UserEnterExclusive();
4626 if (!(Window
= UserGetWindowObject(hWnd
)))
4631 UserRefObjectCo(Window
, &Ref
);
4632 ret
= co_WinPosShowWindow(Window
, nCmdShow
);
4633 UserDerefObjectCo(Window
);
4638 DPRINT("Leave NtUserShowWindow, ret=%i\n",_ret_
);
4648 NtUserShowWindowAsync(HWND hWnd
, LONG nCmdShow
)
4654 return NtUserShowWindow(hWnd
, nCmdShow
);
4664 NtUserUpdateLayeredWindow(
4672 BLENDFUNCTION
*pblend
,
4685 NtUserWindowFromPhysicalPoint(POINT Point
)
4696 NtUserWindowFromPoint(LONG X
, LONG Y
)
4700 PWINDOW_OBJECT DesktopWindow
= NULL
, Window
= NULL
;
4701 DECLARE_RETURN(HWND
);
4702 USER_REFERENCE_ENTRY Ref
;
4704 DPRINT("Enter NtUserWindowFromPoint\n");
4705 UserEnterExclusive();
4707 if ((DesktopWindow
= UserGetWindowObject(IntGetDesktopWindow())))
4715 //hmm... threads live on desktops thus we have a reference on the desktop and indirectly the desktop window
4716 //its possible this referencing is useless, thou it shouldnt hurt...
4717 UserRefObjectCo(DesktopWindow
, &Ref
);
4719 pti
= PsGetCurrentThreadWin32Thread();
4720 Hit
= co_WinPosWindowFromPoint(DesktopWindow
, pti
->MessageQueue
, &pt
, &Window
);
4724 Ret
= Window
->hSelf
;
4733 if (Window
) UserDereferenceObject(Window
);
4734 if (DesktopWindow
) UserDerefObjectCo(DesktopWindow
);
4736 DPRINT("Leave NtUserWindowFromPoint, ret=%i\n",_ret_
);
4746 * Undocumented function that is called from DefWindowProc to set
4753 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4755 PWINDOW_OBJECT Window
;
4757 LARGE_STRING SafeText
;
4758 UNICODE_STRING UnicodeString
;
4761 DPRINT("Enter NtUserDefSetText\n");
4763 if (WindowText
!= NULL
)
4767 SafeText
= ProbeForReadLargeString(WindowText
);
4769 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4772 SetLastNtError(_SEH2_GetExceptionCode());
4782 UserEnterExclusive();
4784 if(!(Window
= UserGetWindowObject(hWnd
)) || !Window
->Wnd
)
4791 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4792 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4793 // Now we know what the bAnsi is for.
4794 RtlInitUnicodeString(&UnicodeString
, NULL
);
4795 if (SafeText
.Buffer
)
4800 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4802 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4803 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4805 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4808 SetLastNtError(_SEH2_GetExceptionCode());
4811 if (!Ret
) goto Exit
;
4814 if (UnicodeString
.Length
!= 0)
4816 if (Wnd
->strName
.MaximumLength
> 0 &&
4817 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4819 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4821 Wnd
->strName
.Length
= UnicodeString
.Length
;
4822 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4823 RtlCopyMemory(Wnd
->strName
.Buffer
,
4824 UnicodeString
.Buffer
,
4825 UnicodeString
.Length
);
4830 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4831 buf
= Wnd
->strName
.Buffer
;
4832 Wnd
->strName
.Buffer
= NULL
;
4835 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4838 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4839 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4840 if (Wnd
->strName
.Buffer
!= NULL
)
4842 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4843 RtlCopyMemory(Wnd
->strName
.Buffer
,
4844 UnicodeString
.Buffer
,
4845 UnicodeString
.Length
);
4846 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4847 Wnd
->strName
.Length
= UnicodeString
.Length
;
4851 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
4859 Wnd
->strName
.Length
= 0;
4860 if (Wnd
->strName
.Buffer
!= NULL
)
4861 Wnd
->strName
.Buffer
[0] = L
'\0';
4864 // HAX! FIXME! Windows does not do this in here!
4865 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4866 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4867 /* Send shell notifications */
4868 if (!IntGetOwner(Window
) && !IntGetParent(Window
))
4870 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
4875 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4876 DPRINT("Leave NtUserDefSetText, ret=%i\n", Ret
);
4882 * NtUserInternalGetWindowText
4889 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4891 PWINDOW_OBJECT Window
;
4895 DECLARE_RETURN(INT
);
4897 DPRINT("Enter NtUserInternalGetWindowText\n");
4900 if(lpString
&& (nMaxCount
<= 1))
4902 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
4906 if(!(Window
= UserGetWindowObject(hWnd
)))
4912 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4915 const WCHAR Terminator
= L
'\0';
4917 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4919 Copy
= min(nMaxCount
- 1, Result
);
4922 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4923 if(!NT_SUCCESS(Status
))
4925 SetLastNtError(Status
);
4931 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4932 if(!NT_SUCCESS(Status
))
4934 SetLastNtError(Status
);
4944 DPRINT("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4952 IntShowOwnedPopups(PWINDOW_OBJECT OwnerWnd
, BOOL fShow
)
4955 PWINDOW_OBJECT pWnd
;
4958 // ASSERT(OwnerWnd);
4960 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
4965 while (win_array
[count
])
4967 while (--count
>= 0)
4969 if (UserGetWindow( win_array
[count
], GW_OWNER
) != OwnerWnd
->hSelf
)
4971 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
4973 // if (pWnd == WND_OTHER_PROCESS) continue;
4977 if (pWnd
->Wnd
->state
& WNDS_HIDDENPOPUP
)
4979 /* In Windows, ShowOwnedPopups(TRUE) generates
4980 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4981 * regardless of the state of the owner
4983 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4989 if (pWnd
->Wnd
->style
& WS_VISIBLE
)
4991 /* In Windows, ShowOwnedPopups(FALSE) generates
4992 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4993 * regardless of the state of the owner
4995 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
5001 ExFreePool( win_array
);
5006 * NtUserValidateHandleSecure
5014 NtUserValidateHandleSecure(
5022 PUSER_HANDLE_ENTRY entry
;
5023 if (!(entry
= handle_to_entry(gHandleTable
, handle
)))
5025 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5028 uType
= entry
->type
;
5034 PWINDOW_OBJECT Window
;
5035 if ((Window
= UserGetWindowObject((HWND
) handle
))) return TRUE
;
5041 if ((Menu
= UserGetMenuObject((HMENU
) handle
))) return TRUE
;
5046 PACCELERATOR_TABLE Accel
;
5047 if ((Accel
= UserGetAccelObject((HACCEL
) handle
))) return TRUE
;
5052 PCURICON_OBJECT Cursor
;
5053 if ((Cursor
= UserGetCurIconObject((HCURSOR
) handle
))) return TRUE
;
5059 if ((Hook
= IntGetHookObject((HHOOK
) handle
))) return TRUE
;
5064 PMONITOR_OBJECT Monitor
;
5065 if ((Monitor
= UserGetMonitorObject((HMONITOR
) handle
))) return TRUE
;
5071 return UserGetCallProcInfo( handle
, &Proc
);
5074 SetLastWin32Error(ERROR_INVALID_HANDLE
);
5078 { /* Is handle entry restricted? */