2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
5 * FILE: subsystems/win32/win32k/ntuser/window.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
10 DBG_DEFAULT_CHANNEL(UserWnd
);
12 /* HELPER FUNCTIONS ***********************************************************/
14 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
16 WORD Action
= LOWORD(wParam
);
17 WORD Flags
= HIWORD(wParam
);
19 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
21 EngSetLastError(ERROR_INVALID_PARAMETER
);
28 EngSetLastError(ERROR_INVALID_PARAMETER
);
32 if (Flags
& UISF_HIDEFOCUS
)
33 Wnd
->HideFocus
= TRUE
;
34 if (Flags
& UISF_HIDEACCEL
)
35 Wnd
->HideAccel
= TRUE
;
39 if (Flags
& UISF_HIDEFOCUS
)
40 Wnd
->HideFocus
= FALSE
;
41 if (Flags
& UISF_HIDEACCEL
)
42 Wnd
->HideAccel
= FALSE
;
49 PWND FASTCALL
IntGetWindowObject(HWND hWnd
)
53 if (!hWnd
) return NULL
;
55 Window
= UserGetWindowObject(hWnd
);
57 Window
->head
.cLockObj
++;
63 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
69 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
73 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
74 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
76 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
84 IntSetStyle( PWND pwnd
, ULONG set_bits
, ULONG clear_bits
)
86 ULONG styleOld
, styleNew
;
87 styleOld
= pwnd
->style
;
88 styleNew
= (pwnd
->style
| set_bits
) & ~clear_bits
;
89 if (styleNew
== styleOld
) return styleNew
;
90 pwnd
->style
= styleNew
;
91 if ((styleOld
^ styleNew
) & WS_VISIBLE
) DceResetActiveDCEs( pwnd
);
98 * The function determines whether the specified window handle identifies
103 * Handle to the window to test.
106 * If the window handle identifies an existing window, the return value
107 * is TRUE. If the window handle does not identify an existing window,
108 * the return value is FALSE.
112 IntIsWindow(HWND hWnd
)
116 if (!(Window
= UserGetWindowObject(hWnd
)))
123 IntIsWindowVisible(PWND Wnd
)
128 if (!(Wnd
->style
& WS_VISIBLE
))
133 if (Wnd
->spwndParent
!= NULL
)
134 Wnd
= Wnd
->spwndParent
;
143 IntGetParent(PWND Wnd
)
145 if (Wnd
->style
& WS_POPUP
)
147 return Wnd
->spwndOwner
;
149 else if (Wnd
->style
& WS_CHILD
)
151 return Wnd
->spwndParent
;
159 IntEnableWindow( HWND hWnd
, BOOL bEnable
)
165 if(!(pWnd
= UserGetWindowObject(hWnd
)))
170 /* check if updating is needed */
171 bIsDisabled
= !!(pWnd
->style
& WS_DISABLED
);
172 Update
= bIsDisabled
;
176 IntSetStyle( pWnd
, 0, WS_DISABLED
);
180 Update
= !bIsDisabled
;
182 co_IntSendMessage( hWnd
, WM_CANCELMODE
, 0, 0);
184 /* Remove keyboard focus from that window if it had focus */
185 if (hWnd
== IntGetThreadFocusWindow())
187 co_UserSetFocus(NULL
);
189 IntSetStyle( pWnd
, WS_DISABLED
, 0 );
194 IntNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, pWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
195 co_IntSendMessage(hWnd
, WM_ENABLE
, (LPARAM
)bEnable
, 0);
197 // Return nonzero if it was disabled, or zero if it wasn't:
204 * Compile a list of all child window handles from given window.
207 * This function is similar to Wine WIN_ListChildren. The caller
208 * must free the returned list with ExFreePool.
212 IntWinListChildren(PWND Window
)
216 UINT Index
, NumChildren
= 0;
218 if (!Window
) return NULL
;
220 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
223 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
226 ERR("Failed to allocate memory for children array\n");
227 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
230 for (Child
= Window
->spwndChild
, Index
= 0;
232 Child
= Child
->spwndNext
, ++Index
)
233 List
[Index
] = Child
->head
.h
;
239 /***********************************************************************
242 static void IntSendDestroyMsg(HWND hWnd
)
250 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
252 if (hWnd
== info
.hwndCaret
)
259 Window
= UserGetWindowObject(hWnd
);
262 // USER_REFERENCE_ENTRY Ref;
263 // UserRefObjectCo(Window, &Ref);
265 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
267 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
270 // UserDerefObjectCo(Window);
273 /* The window could already be destroyed here */
276 * Send the WM_DESTROY to the window.
279 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
282 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
283 * make sure that the window still exists when we come back.
292 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
295 /* start from the end (FIXME: is this needed?) */
296 for (i
= 0; pWndArray
[i
]; i
++)
301 if (IsWindow( pWndArray
[i
] ))
302 WIN_SendDestroyMsg( pWndArray
[i
] );
304 HeapFree(GetProcessHeap(), 0, pWndArray
);
308 TRACE("destroyed itself while in WM_DESTROY!\n");
314 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
316 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
320 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
322 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
323 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
326 if (Wnd
->strName
.Buffer
!= NULL
)
328 Wnd
->strName
.Length
= 0;
329 Wnd
->strName
.MaximumLength
= 0;
330 DesktopHeapFree(Wnd
->head
.rpdesk
,
331 Wnd
->strName
.Buffer
);
332 Wnd
->strName
.Buffer
= NULL
;
335 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
336 // WindowObject->Wnd = NULL;
339 /***********************************************************************
342 * Destroy storage associated to a window. "Internals" p.358
344 * This is the "functional" DestroyWindows function ei. all stuff
345 * done in CreateWindow is undone here and not in DestroyWindow:-P
348 static LRESULT
co_UserFreeWindow(PWND Window
,
349 PPROCESSINFO ProcessData
,
350 PTHREADINFO ThreadData
,
351 BOOLEAN SendMessages
)
357 BOOLEAN BelongsToThreadData
;
361 if(Window
->state2
& WNDS2_INDESTROY
)
363 TRACE("Tried to call IntDestroyWindow() twice\n");
366 Window
->state2
|= WNDS2_INDESTROY
;
367 Window
->style
&= ~WS_VISIBLE
;
369 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
371 /* remove the window already at this point from the thread window list so we
372 don't get into trouble when destroying the thread windows while we're still
373 in IntDestroyWindow() */
374 RemoveEntryList(&Window
->ThreadListEntry
);
376 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
378 IntDeRegisterShellHookWindow(Window
->head
.h
);
382 /* Send destroy messages */
383 IntSendDestroyMsg(Window
->head
.h
);
386 /* free child windows */
387 Children
= IntWinListChildren(Window
);
390 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
392 if ((Child
= IntGetWindowObject(*ChildHandle
)))
394 if(!IntWndBelongsToThread(Child
, ThreadData
))
396 /* send WM_DESTROY messages to windows not belonging to the same thread */
397 IntSendDestroyMsg(Child
->head
.h
);
400 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
402 UserDereferenceObject(Child
);
405 ExFreePool(Children
);
411 * Clear the update region to make sure no WM_PAINT messages will be
412 * generated for this window while processing the WM_NCDESTROY.
414 co_UserRedrawWindow(Window
, NULL
, 0,
415 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
416 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
417 if(BelongsToThreadData
)
418 co_IntSendMessage(Window
->head
.h
, WM_NCDESTROY
, 0, 0);
421 DestroyTimersForWindow(ThreadData
, Window
);
423 /* Unregister hot keys */
424 UnregisterWindowHotKeys (Window
);
426 /* flush the message queue */
427 MsqRemoveWindowMessagesFromQueue(Window
);
429 IntDereferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
431 /* from now on no messages can be sent to this window anymore */
432 Window
->state
|= WNDS_DESTROYED
;
433 Window
->fnid
|= FNID_FREED
;
435 /* don't remove the WINDOWSTATUS_DESTROYING bit */
437 /* reset shell window handles */
438 if(ThreadData
->rpdesk
)
440 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
441 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
443 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
444 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
447 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
451 WinPosCheckInternalPos(Window
->head
.h
);
452 if (Window
->head
.h
== GetCapture())
457 /* free resources associated with the window */
458 TIMER_RemoveWindowTimers(Window
->head
.h
);
461 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
463 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
465 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
469 if(Window
->SystemMenu
470 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
472 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
473 Window
->SystemMenu
= (HMENU
)0;
476 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
479 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
480 CLASS_RemoveWindow(Window
->Class
);
483 IntUnlinkWindow(Window
);
485 UserReferenceObject(Window
);
486 UserDeleteObject(Window
->head
.h
, otWindow
);
488 IntDestroyScrollBars(Window
);
490 /* dereference the class */
491 IntDereferenceClass(Window
->pcls
,
492 Window
->head
.pti
->pDeskInfo
,
493 Window
->head
.pti
->ppi
);
498 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
499 GreDeleteObject(Window
->hrgnClip
);
500 Window
->hrgnClip
= NULL
;
503 // ASSERT(Window != NULL);
504 UserFreeWindowInfo(Window
->head
.pti
, Window
);
506 UserDereferenceObject(Window
);
508 UserClipboardFreeWindow(Window
);
514 // Same as User32:IntGetWndProc.
517 IntGetWindowProc(PWND pWnd
,
522 WNDPROC gcpd
, Ret
= 0;
524 ASSERT(UserIsEnteredExclusive() == TRUE
);
528 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
530 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
532 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
535 Ret
= GETPFNCLIENTA(i
);
537 Ret
= GETPFNCLIENTW(i
);
543 if (Class
->fnid
== FNID_EDIT
)
544 Ret
= pWnd
->lpfnWndProc
;
547 Ret
= pWnd
->lpfnWndProc
;
549 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
553 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
554 Ret
= GETPFNCLIENTA(Class
->fnid
);
558 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
559 Ret
= GETPFNCLIENTW(Class
->fnid
);
562 if ( Ret
!= pWnd
->lpfnWndProc
)
565 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
568 gcpd
= (WNDPROC
)UserGetCPD(
570 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
573 return (gcpd
? gcpd
: Ret
);
577 IntSetWindowProc(PWND pWnd
,
582 PCALLPROCDATA CallProc
;
584 WNDPROC Ret
, chWndProc
= NULL
;
586 // Retrieve previous window proc.
587 Ret
= IntGetWindowProc(pWnd
, Ansi
);
591 if (IsCallProcHandle(NewWndProc
))
593 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, otCallProc
);
595 { // Reset new WndProc.
596 NewWndProc
= CallProc
->pfnClientPrevious
;
597 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
598 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
601 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
602 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
604 if (GETPFNCLIENTW(i
) == NewWndProc
)
606 chWndProc
= GETPFNSERVER(i
);
609 if (GETPFNCLIENTA(i
) == NewWndProc
)
611 chWndProc
= GETPFNSERVER(i
);
615 // If match, set/reset to Server Side and clear ansi.
618 pWnd
->lpfnWndProc
= chWndProc
;
619 pWnd
->Unicode
= TRUE
;
620 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
621 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
625 pWnd
->Unicode
= !Ansi
;
626 // Handle the state change in here.
628 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
630 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
632 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
633 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
635 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
637 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
641 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
642 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
646 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
647 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
650 // Now set the new window proc.
651 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
662 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
664 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
666 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
670 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
678 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
679 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Wnd
->head
.h
);
688 NewMenu
= IntGetMenuObject(Menu
);
693 IntReleaseMenuObject(OldMenu
);
695 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
698 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
700 /* Can't use the same menu for two windows */
703 IntReleaseMenuObject(OldMenu
);
705 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
711 Wnd
->IDMenu
= (UINT
) Menu
;
714 NewMenu
->MenuInfo
.Wnd
= Wnd
->head
.h
;
715 IntReleaseMenuObject(NewMenu
);
719 OldMenu
->MenuInfo
.Wnd
= NULL
;
720 IntReleaseMenuObject(OldMenu
);
727 /* INTERNAL ******************************************************************/
731 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
736 USER_REFERENCE_ENTRY Ref
;
737 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
739 while (!IsListEmpty(&WThread
->WindowListHead
))
741 Current
= WThread
->WindowListHead
.Flink
;
742 Wnd
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
744 TRACE("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
746 /* Window removes itself from the list */
749 * FIXME: It is critical that the window removes itself! If now, we will loop
753 //ASSERT(co_UserDestroyWindow(Wnd));
755 UserRefObjectCo(Wnd
, &Ref
); // FIXME: Temp HACK??
756 if (!co_UserDestroyWindow(Wnd
))
758 ERR("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
760 UserDerefObjectCo(Wnd
); // FIXME: Temp HACK??
764 PMENU_OBJECT FASTCALL
765 IntGetSystemMenu(PWND Window
, BOOL bRevert
, BOOL RetMenu
)
767 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
768 PTHREADINFO W32Thread
;
769 HMENU hNewMenu
, hSysMenu
;
770 ROSMENUITEMINFO ItemInfo
;
774 W32Thread
= PsGetCurrentThreadWin32Thread();
776 if(!W32Thread
->rpdesk
)
779 if(Window
->SystemMenu
)
781 Menu
= UserGetMenuObject(Window
->SystemMenu
);
784 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
785 Window
->SystemMenu
= (HMENU
)0;
789 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
791 /* Clone system menu */
792 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
796 NewMenu
= IntCloneMenu(Menu
);
799 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
800 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
801 NewMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
803 //IntReleaseMenuObject(NewMenu);
808 hSysMenu
= UserCreateMenu(FALSE
);
809 if (NULL
== hSysMenu
)
813 SysMenu
= IntGetMenuObject(hSysMenu
);
816 UserDestroyMenu(hSysMenu
);
819 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
820 SysMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
821 hNewMenu
= co_IntLoadSysMenuTemplate();
824 IntReleaseMenuObject(SysMenu
);
825 UserDestroyMenu(hSysMenu
);
828 Menu
= IntGetMenuObject(hNewMenu
);
831 IntReleaseMenuObject(SysMenu
);
832 UserDestroyMenu(hSysMenu
);
836 NewMenu
= IntCloneMenu(Menu
);
839 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
840 IntReleaseMenuObject(NewMenu
);
841 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
843 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
844 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
845 ItemInfo
.fType
= MF_POPUP
;
846 ItemInfo
.fState
= MFS_ENABLED
;
847 ItemInfo
.dwTypeData
= NULL
;
849 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
850 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
852 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
856 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
865 if(Window
->SystemMenu
)
866 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
874 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
879 while (Window
&& ((Window
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
881 if (Window
== Parent
)
886 Window
= Window
->spwndParent
;
893 Link the window into siblings list
894 children and parent are kept in place.
899 PWND WndInsertAfter
/* set to NULL if top sibling */
902 if ((Wnd
->spwndPrev
= WndInsertAfter
))
904 /* link after WndInsertAfter */
905 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
906 Wnd
->spwndNext
->spwndPrev
= Wnd
;
908 Wnd
->spwndPrev
->spwndNext
= Wnd
;
913 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
914 Wnd
->spwndNext
->spwndPrev
= Wnd
;
916 Wnd
->spwndParent
->spwndChild
= Wnd
;
921 Note: Wnd->spwndParent can be null if it is the desktop.
923 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
925 if (hWndPrev
== HWND_NOTOPMOST
)
927 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
928 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
929 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
930 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
933 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
935 if (hWndPrev
== HWND_BOTTOM
)
937 /* Link in the bottom of the list */
940 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
941 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
942 WndInsertAfter
= WndInsertAfter
->spwndNext
;
944 IntLinkWindow(Wnd
, WndInsertAfter
);
945 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
947 else if (hWndPrev
== HWND_TOPMOST
)
949 /* Link in the top of the list */
950 IntLinkWindow(Wnd
, NULL
);
952 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
954 else if (hWndPrev
== HWND_TOP
)
956 /* Link it after the last topmost window */
957 PWND WndInsertBefore
;
959 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
961 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
963 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
965 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
966 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
968 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
971 WndInsertBefore
= WndInsertBefore
->spwndNext
;
975 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
979 /* Link it after hWndPrev */
982 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
983 /* Are we called with an erroneous handle */
984 if(WndInsertAfter
== NULL
)
986 /* Link in a default position */
987 IntLinkHwnd(Wnd
, HWND_TOP
);
991 IntLinkWindow(Wnd
, WndInsertAfter
);
993 /* Fix the WS_EX_TOPMOST flag */
994 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
996 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1000 if(WndInsertAfter
->spwndNext
&&
1001 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1003 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1010 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1012 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1015 Wnd
= IntGetWindowObject(hWnd
);
1019 WndOldOwner
= Wnd
->spwndOwner
;
1021 ret
= WndOldOwner
? WndOldOwner
->head
.h
: 0;
1023 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1025 Wnd
->spwndOwner
= WndNewOwner
;
1029 Wnd
->spwndOwner
= NULL
;
1032 UserDereferenceObject(Wnd
);
1037 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1039 PWND WndOldParent
, pWndExam
;
1044 ASSERT(WndNewParent
);
1045 ASSERT_REFS_CO(Wnd
);
1046 ASSERT_REFS_CO(WndNewParent
);
1048 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1050 EngSetLastError(ERROR_ACCESS_DENIED
);
1054 /* Some applications try to set a child as a parent */
1055 if (IntIsChildWindow(Wnd
, WndNewParent
))
1057 EngSetLastError( ERROR_INVALID_PARAMETER
);
1061 pWndExam
= WndNewParent
; // Load parent Window to examine.
1062 // Now test for set parent to parent hit.
1065 if (Wnd
== pWndExam
)
1067 EngSetLastError(ERROR_INVALID_PARAMETER
);
1070 pWndExam
= pWndExam
->spwndParent
;
1074 * Windows hides the window first, then shows it again
1075 * including the WM_SHOWWINDOW messages and all
1077 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1079 /* Window must belong to current process */
1080 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1083 pt
.x
= Wnd
->rcWindow
.left
;
1084 pt
.y
= Wnd
->rcWindow
.top
;
1086 WndOldParent
= Wnd
->spwndParent
;
1088 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1090 if (WndNewParent
!= WndOldParent
)
1092 /* Unlink the window from the siblings list */
1093 IntUnlinkWindow(Wnd
);
1095 /* Set the new parent */
1096 Wnd
->spwndParent
= WndNewParent
;
1098 /* Link the window with its new siblings */
1099 IntLinkHwnd(Wnd
, HWND_TOP
);
1103 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1105 * SetParent additionally needs to make hwnd the top window
1106 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1107 * WM_WINDOWPOSCHANGED notification messages.
1109 co_WinPosSetWindowPos( Wnd
,
1110 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1111 pt
.x
, pt
.y
, 0, 0, SWP_NOSIZE
);
1113 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1115 return WndOldParent
;
1119 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1121 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1122 HWND hWndOldParent
= NULL
;
1123 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1125 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1127 EngSetLastError(ERROR_INVALID_PARAMETER
);
1131 if (hWndChild
== IntGetDesktopWindow())
1133 EngSetLastError(ERROR_ACCESS_DENIED
);
1139 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1146 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1152 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1157 UserRefObjectCo(Wnd
, &Ref
);
1158 UserRefObjectCo(WndParent
, &ParentRef
);
1160 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1162 UserDerefObjectCo(WndParent
);
1163 UserDerefObjectCo(Wnd
);
1167 hWndOldParent
= WndOldParent
->head
.h
;
1168 UserDereferenceObject(WndOldParent
);
1171 return( hWndOldParent
);
1175 IntSetSystemMenu(PWND Window
, PMENU_OBJECT Menu
)
1177 PMENU_OBJECT OldMenu
;
1178 if(Window
->SystemMenu
)
1180 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1183 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1184 IntReleaseMenuObject(OldMenu
);
1190 /* FIXME: Check window style, propably return FALSE? */
1191 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1192 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1195 Window
->SystemMenu
= (HMENU
)0;
1200 /* Unlink the window from siblings. children and parent are kept in place. */
1202 IntUnlinkWindow(PWND Wnd
)
1205 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1208 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1210 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1211 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1213 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1216 /* FUNCTIONS *****************************************************************/
1219 * As best as I can figure, this function is used by EnumWindows,
1220 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1222 * It's supposed to build a list of HWNDs to return to the caller.
1223 * We can figure out what kind of list by what parameters are
1231 NtUserBuildHwndList(
1244 return ERROR_INVALID_PARAMETER
;
1246 if (hwndParent
|| !dwThreadId
)
1249 PWND Parent
, Window
;
1253 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1255 return ERROR_INVALID_HANDLE
;
1260 Status
= IntValidateDesktopHandle(hDesktop
,
1264 if(!NT_SUCCESS(Status
))
1266 return ERROR_INVALID_HANDLE
;
1269 hwndParent
= Desktop
->DesktopWindow
;
1276 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1277 (Window
= Parent
->spwndChild
))
1279 BOOL bGoDown
= TRUE
;
1281 Status
= STATUS_SUCCESS
;
1286 if(dwCount
++ < *pBufSize
&& pWnd
)
1290 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1291 *pWnd
= Window
->head
.h
;
1294 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1296 Status
= _SEH2_GetExceptionCode();
1299 if(!NT_SUCCESS(Status
))
1301 SetLastNtError(Status
);
1305 if (Window
->spwndChild
&& bChildren
)
1307 Window
= Window
->spwndChild
;
1312 if (Window
->spwndNext
)
1314 Window
= Window
->spwndNext
;
1318 Window
= Window
->spwndParent
;
1319 if (Window
== Parent
)
1328 ObDereferenceObject(Desktop
);
1331 else // Build EnumThreadWindows list!
1334 PTHREADINFO W32Thread
;
1335 PLIST_ENTRY Current
;
1338 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1339 if (!NT_SUCCESS(Status
))
1341 ERR("Thread Id is not valid!\n");
1342 return ERROR_INVALID_PARAMETER
;
1344 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1346 ObDereferenceObject(Thread
);
1347 ERR("Thread is not initialized!\n");
1348 return ERROR_INVALID_PARAMETER
;
1351 Current
= W32Thread
->WindowListHead
.Flink
;
1352 while (Current
!= &(W32Thread
->WindowListHead
))
1354 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1357 if (dwCount
< *pBufSize
&& pWnd
)
1361 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1362 *pWnd
= Window
->head
.h
;
1365 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1367 Status
= _SEH2_GetExceptionCode();
1370 if (!NT_SUCCESS(Status
))
1372 ERR("Failure to build window list!\n");
1373 SetLastNtError(Status
);
1378 Current
= Window
->ThreadListEntry
.Flink
;
1381 ObDereferenceObject(Thread
);
1384 *pBufSize
= dwCount
;
1385 return STATUS_SUCCESS
;
1388 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1390 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1391 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1393 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1395 USER_REFERENCE_ENTRY Ref
;
1396 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1397 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1399 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1400 (LPARAM
)pWindow
->head
.h
);
1401 UserDerefObjectCo(pWindow
->spwndParent
);
1407 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1409 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1411 /* default positioning for overlapped windows */
1412 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1415 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1417 pMonitor
= UserGetPrimaryMonitor();
1419 /* Check if we don't have a monitor attached yet */
1420 if(pMonitor
== NULL
)
1428 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1430 if (IS_DEFAULT(Cs
->x
))
1432 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1434 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1436 Cs
->x
= ProcessParams
->StartingX
;
1437 Cs
->y
= ProcessParams
->StartingY
;
1441 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1442 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1443 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1444 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1446 /* reset counter and position */
1449 pMonitor
->cWndStack
= 0;
1451 pMonitor
->cWndStack
++;
1455 if (IS_DEFAULT(Cs
->cx
))
1457 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1459 Cs
->cx
= ProcessParams
->CountX
;
1460 Cs
->cy
= ProcessParams
->CountY
;
1464 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1465 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1468 /* neither x nor cx are default. Check the y values .
1469 * In the trace we see Outlook and Outlook Express using
1470 * cy set to CW_USEDEFAULT when opening the address book.
1472 else if (IS_DEFAULT(Cs
->cy
))
1474 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1475 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1480 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1481 if(IS_DEFAULT(Cs
->x
))
1486 if(IS_DEFAULT(Cs
->cx
))
1496 /* Allocates and initializes a window */
1497 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1498 PLARGE_STRING WindowName
,
1506 PTHREADINFO pti
= NULL
;
1507 PMENU_OBJECT SystemMenu
;
1509 BOOL bUnicodeWindow
;
1511 pti
= PsGetCurrentThreadWin32Thread();
1513 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1517 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1518 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1519 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1520 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1524 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1526 * Dialog boxes and message boxes do not inherit layout, so you must
1527 * set the layout explicitly.
1529 if ( Class
->fnid
!= FNID_DIALOG
)
1531 PPROCESSINFO ppi
= PsGetCurrentProcessWin32Process();
1532 if (ppi
->dwLayout
& LAYOUT_RTL
)
1534 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1540 /* Automatically add WS_EX_WINDOWEDGE */
1541 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1542 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1543 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1544 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1546 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1548 /* Is it a unicode window? */
1549 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1550 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1552 /* Allocate the new window */
1553 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1557 sizeof(WND
) + Class
->cbwndExtra
);
1564 TRACE("Created object with handle %X\n", hWnd
);
1566 if (NULL
== pti
->rpdesk
->DesktopWindow
)
1567 { /* HACK: Helper for win32csr/desktopbg.c */
1568 /* If there is no desktop window yet, we must be creating it */
1569 pti
->rpdesk
->DesktopWindow
= hWnd
;
1570 pti
->rpdesk
->pDeskInfo
->spwnd
= pWnd
;
1574 * Fill out the structure describing it.
1576 /* Remember, pWnd->head is setup in object.c ... */
1577 pWnd
->spwndParent
= ParentWindow
;
1578 pWnd
->spwndOwner
= OwnerWindow
;
1580 pWnd
->spwndLastActive
= pWnd
;
1581 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1583 pWnd
->hModule
= Cs
->hInstance
;
1584 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1585 pWnd
->ExStyle
= Cs
->dwExStyle
;
1586 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1587 pWnd
->pActCtx
= acbiBuffer
;
1588 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1589 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1591 IntReferenceMessageQueue(pWnd
->head
.pti
->MessageQueue
);
1592 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1594 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1595 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1598 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1599 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1601 /* BugBoy Comments: Comment below say that System classes are always created
1602 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1603 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1605 No where can I see in code or through testing does the window change back
1606 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1607 see what problems this would cause. */
1609 // Set WndProc from Class.
1610 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1612 // GetWindowProc, test for non server side default classes and set WndProc.
1613 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1617 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1618 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1622 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1623 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1627 // If not an Unicode caller, set Ansi creator bit.
1628 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1630 // Clone Class Ansi/Unicode proc type.
1631 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1633 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1634 pWnd
->Unicode
= FALSE
;
1638 * It seems there can be both an Ansi creator and Unicode Class Window
1639 * WndProc, unless the following overriding conditions occur:
1641 if ( !bUnicodeWindow
&&
1642 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1643 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1644 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1645 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1646 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1647 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1648 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1649 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1650 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1651 { // Override Class and set the window Ansi WndProc.
1652 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1653 pWnd
->Unicode
= FALSE
;
1656 { // Set the window Unicode WndProc.
1657 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1658 pWnd
->Unicode
= TRUE
;
1662 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1663 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1664 Dont understand why it does this. */
1665 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1667 PCALLPROCDATA CallProc
;
1668 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1672 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1673 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
1677 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1681 InitializeListHead(&pWnd
->PropListHead
);
1683 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1685 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1686 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1687 if (pWnd
->strName
.Buffer
== NULL
)
1692 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1693 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1694 pWnd
->strName
.Length
= WindowName
->Length
;
1695 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1698 /* Correct the window style. */
1699 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1701 pWnd
->style
|= WS_CLIPSIBLINGS
;
1702 if (!(pWnd
->style
& WS_POPUP
))
1704 pWnd
->style
|= WS_CAPTION
;
1708 /* WS_EX_WINDOWEDGE depends on some other styles */
1709 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1710 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1711 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1713 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1714 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1715 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1718 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1720 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1721 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1723 /* Create system menu */
1724 if ((Cs
->style
& WS_SYSMENU
)) // && (dwStyle & WS_CAPTION) == WS_CAPTION)
1726 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1729 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1730 IntReleaseMenuObject(SystemMenu
);
1734 /* Set the window menu */
1735 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1738 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1739 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1741 UNICODE_STRING MenuName
;
1744 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1746 MenuName
.Length
= 0;
1747 MenuName
.MaximumLength
= 0;
1748 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1752 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1754 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1755 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1759 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1761 /* Insert the window into the thread's window list. */
1762 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1764 /* Handle "CS_CLASSDC", it is tested first. */
1765 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1766 { /* One DCE per class to have CLASS. */
1767 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1769 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1770 { /* Allocate a DCE for this window. */
1771 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1777 ERR("IntCreateWindow Allocation Error.\n");
1779 UserDereferenceObject(pWnd
);
1781 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1789 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1790 PUNICODE_STRING ClassName
,
1791 PLARGE_STRING WindowName
,
1795 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1796 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1797 PWINSTATION_OBJECT WinSta
;
1801 CBT_CREATEWNDW
* pCbtCreate
;
1803 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1805 DWORD dwShowMode
= SW_SHOW
;
1806 CREATESTRUCTW
*pCsw
= NULL
;
1807 PVOID pszClass
= NULL
, pszName
= NULL
;
1810 /* Get the current window station and reference it */
1811 pti
= GetW32ThreadInfo();
1812 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1814 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1815 return NULL
; // There is nothing to cleanup.
1817 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1818 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1823 /* Get the class and reference it */
1824 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
);
1827 ERR("Failed to find class %wZ\n", ClassName
);
1831 /* Now find the parent and the owner window */
1832 hWndParent
= IntGetDesktopWindow();
1835 if (Cs
->hwndParent
== HWND_MESSAGE
)
1837 Cs
->hwndParent
= hWndParent
= IntGetMessageWindow();
1839 else if (Cs
->hwndParent
)
1841 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1842 hWndOwner
= Cs
->hwndParent
;
1844 hWndParent
= Cs
->hwndParent
;
1846 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1848 ERR("Cannot create a child window without a parrent!\n");
1849 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1850 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1853 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1854 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1856 /* FIXME: Is this correct? */
1858 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
1860 /* Fix the position and the size of the window */
1863 UserRefObjectCo(ParentWindow
, &ParentRef
);
1864 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
1867 /* Allocate and initialize the new window */
1868 Window
= IntCreateWindow(Cs
,
1876 ERR("IntCreateWindow failed!\n");
1880 hWnd
= UserHMGetHandle(Window
);
1881 hwndInsertAfter
= HWND_TOP
;
1883 UserRefObjectCo(Window
, &Ref
);
1884 UserDereferenceObject(Window
);
1885 ObDereferenceObject(WinSta
);
1887 //// Check for a hook to eliminate overhead. ////
1888 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
1890 // Allocate the calling structures Justin Case this goes Global.
1891 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
1892 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
1893 if (!pCsw
|| !pCbtCreate
)
1895 ERR("UserHeapAlloc() failed!\n");
1899 /* Fill the new CREATESTRUCTW */
1900 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
1901 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
1903 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
1904 if (!IS_ATOM(ClassName
->Buffer
))
1906 if (Window
->state
& WNDS_ANSICREATOR
)
1908 ANSI_STRING AnsiString
;
1909 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
1910 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
1913 ERR("UserHeapAlloc() failed!\n");
1916 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
1917 AnsiString
.Buffer
= (PCHAR
)pszClass
;
1918 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
1922 UNICODE_STRING UnicodeString
;
1923 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
1924 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
1927 ERR("UserHeapAlloc() failed!\n");
1930 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
1931 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
1932 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
1934 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
1936 if (WindowName
->Length
)
1938 UNICODE_STRING Name
;
1939 Name
.Buffer
= WindowName
->Buffer
;
1940 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
1941 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
1943 if (Window
->state
& WNDS_ANSICREATOR
)
1945 ANSI_STRING AnsiString
;
1946 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
1947 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
1950 ERR("UserHeapAlloc() failed!\n");
1953 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
1954 AnsiString
.Buffer
= (PCHAR
)pszName
;
1955 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
1959 UNICODE_STRING UnicodeString
;
1960 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
1961 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
1964 ERR("UserHeapAlloc() failed!\n");
1967 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
1968 UnicodeString
.Buffer
= (PWSTR
)pszName
;
1969 RtlCopyUnicodeString(&UnicodeString
, &Name
);
1971 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
1974 pCbtCreate
->lpcs
= pCsw
;
1975 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
1977 //// Call the WH_CBT hook ////
1978 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
1981 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
1984 // Write back changes.
1989 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
1992 /* NCCREATE and WM_NCCALCSIZE need the original values */
1993 Cs
->lpszName
= (LPCWSTR
) WindowName
;
1994 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
1996 /* Send the WM_GETMINMAXINFO message */
2000 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2002 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2004 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2005 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2006 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2007 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2008 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2011 Window
->rcWindow
.left
= Cs
->x
;
2012 Window
->rcWindow
.top
= Cs
->y
;
2013 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2014 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2015 if (0 != (Window
->style
& WS_CHILD
) && ParentWindow
)
2017 // ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2018 RECTL_vOffsetRect(&Window
->rcWindow
,
2019 ParentWindow
->rcClient
.left
,
2020 ParentWindow
->rcClient
.top
);
2022 Window
->rcClient
= Window
->rcWindow
;
2024 /* Link the window */
2025 if (NULL
!= ParentWindow
)
2027 /* Link the window into the siblings list */
2028 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2029 IntLinkHwnd(Window
, HWND_BOTTOM
);
2031 IntLinkHwnd(Window
, hwndInsertAfter
);
2034 /* Send the NCCREATE message */
2035 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2038 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2042 /* Send the WM_NCCALCSIZE message */
2043 MaxPos
.x
= Window
->rcWindow
.left
;
2044 MaxPos
.y
= Window
->rcWindow
.top
;
2046 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2048 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2049 MaxPos
.y
- Window
->rcWindow
.top
);
2052 /* Send the WM_CREATE message. */
2053 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2054 if (Result
== (LRESULT
)-1)
2056 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2060 /* Send the EVENT_OBJECT_CREATE event */
2061 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2063 /* By setting the flag below it can be examined to determine if the window
2064 was created successfully and a valid pwnd was passed back to caller since
2065 from here the function has to succeed. */
2066 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2068 /* Send the WM_SIZE and WM_MOVE messages. */
2069 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2071 co_WinPosSendSizeMove(Window
);
2074 /* Show or maybe minimize or maximize the window. */
2076 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2077 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2082 SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2084 co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2086 SwFlag
= ((Window
->style
& WS_CHILD
) || UserGetActiveWindow()) ?
2087 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
:
2088 SWP_NOZORDER
| SWP_FRAMECHANGED
;
2090 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2091 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2094 /* Send the WM_PARENTNOTIFY message */
2095 IntSendParentNotify(Window
, WM_CREATE
);
2097 /* Notify the shell that a new window was created */
2098 if ((!hWndParent
) && (!hWndOwner
))
2100 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2103 /* Initialize and show the window's scrollbars */
2104 if (Window
->style
& WS_VSCROLL
)
2106 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2108 if (Window
->style
& WS_HSCROLL
)
2110 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2113 /* Show the new window */
2114 if (Cs
->style
& WS_VISIBLE
)
2116 if (Window
->style
& WS_MAXIMIZE
)
2117 dwShowMode
= SW_SHOW
;
2118 else if (Window
->style
& WS_MINIMIZE
)
2119 dwShowMode
= SW_SHOWMINIMIZED
;
2121 co_WinPosShowWindow(Window
, dwShowMode
);
2123 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2125 ASSERT(ParentWindow
);
2128 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2129 /* ShowWindow won't activate child windows */
2130 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2134 TRACE("co_UserCreateWindowEx(): Created window %X\n", hWnd
);
2140 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2141 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2143 co_UserDestroyWindow(Window
);
2145 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2148 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2149 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2150 if (pszName
) UserHeapFree(pszName
);
2151 if (pszClass
) UserHeapFree(pszClass
);
2155 UserDerefObjectCo(Window
);
2157 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2164 ProbeAndCaptureLargeString(
2165 OUT PLARGE_STRING plstrSafe
,
2166 IN PLARGE_STRING plstrUnsafe
)
2168 LARGE_STRING lstrTemp
;
2169 PVOID pvBuffer
= NULL
;
2173 /* Probe and copy the string */
2174 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2175 lstrTemp
= *plstrUnsafe
;
2177 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2180 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2184 if (lstrTemp
.Length
!= 0)
2186 /* Allocate a buffer from paged pool */
2187 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2190 return STATUS_NO_MEMORY
;
2195 /* Probe and copy the buffer */
2196 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2197 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2199 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2201 /* Cleanup and fail */
2202 ExFreePool(pvBuffer
);
2203 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2208 /* Set the output string */
2209 plstrSafe
->Buffer
= pvBuffer
;
2210 plstrSafe
->Length
= lstrTemp
.Length
;
2211 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2213 return STATUS_SUCCESS
;
2217 * \todo Allow passing plstrClassName as ANSI.
2221 NtUserCreateWindowEx(
2223 PLARGE_STRING plstrClassName
,
2224 PLARGE_STRING plstrClsVersion
,
2225 PLARGE_STRING plstrWindowName
,
2233 HINSTANCE hInstance
,
2239 LARGE_STRING lstrWindowName
;
2240 LARGE_STRING lstrClassName
;
2241 UNICODE_STRING ustrClassName
;
2246 lstrWindowName
.Buffer
= NULL
;
2247 lstrClassName
.Buffer
= NULL
;
2249 ASSERT(plstrWindowName
);
2251 /* Copy the window name to kernel mode */
2252 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2253 if (!NT_SUCCESS(Status
))
2255 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2256 SetLastNtError(Status
);
2260 plstrWindowName
= &lstrWindowName
;
2262 /* Check if the class is an atom */
2263 if (IS_ATOM(plstrClassName
))
2265 /* It is, pass the atom in the UNICODE_STRING */
2266 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2267 ustrClassName
.Length
= 0;
2268 ustrClassName
.MaximumLength
= 0;
2272 /* It's not, capture the class name */
2273 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2274 if (!NT_SUCCESS(Status
))
2276 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2277 /* Set last error, cleanup and return */
2278 SetLastNtError(Status
);
2282 /* We pass it on as a UNICODE_STRING */
2283 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2284 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2285 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2288 /* Fill the CREATESTRUCTW */
2289 /* we will keep here the original parameters */
2291 Cs
.lpCreateParams
= lpParam
;
2292 Cs
.hInstance
= hInstance
;
2294 Cs
.hwndParent
= hWndParent
;
2299 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2300 if (IS_ATOM(plstrClassName
))
2301 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2303 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2304 Cs
.dwExStyle
= dwExStyle
;
2306 UserEnterExclusive();
2308 /* Call the internal function */
2309 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
);
2313 ERR("co_UserCreateWindowEx failed!\n");
2315 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2320 if (lstrWindowName
.Buffer
)
2322 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2324 if (lstrClassName
.Buffer
)
2326 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2333 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2339 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2341 hWnd
= Window
->head
.h
;
2343 TRACE("co_UserDestroyWindow \n");
2345 /* Check for owner thread */
2346 if ( (Window
->head
.pti
->pEThread
!= PsGetCurrentThread()) ||
2347 Window
->head
.pti
!= PsGetCurrentThreadWin32Thread() )
2349 EngSetLastError(ERROR_ACCESS_DENIED
);
2353 /* If window was created successfully and it is hooked */
2354 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2356 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2358 ERR("Destroy Window WH_CBT Call Hook return!\n");
2363 /* Inform the parent */
2364 if (Window
->style
& WS_CHILD
)
2366 IntSendParentNotify(Window
, WM_DESTROY
);
2369 /* Look whether the focus is within the tree of windows we will
2372 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2374 if (UserGetActiveWindow() == Window
->head
.h
)
2376 co_WinPosActivateOtherWindow(Window
);
2380 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2381 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2382 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2383 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2384 if (Window
->head
.pti
->MessageQueue
->CaptureWindow
== Window
->head
.h
)
2385 Window
->head
.pti
->MessageQueue
->CaptureWindow
= NULL
;
2388 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2391 ti
= PsGetCurrentThreadWin32Thread();
2393 if ((ti
!= NULL
) & (ti
->pDeskInfo
!= NULL
))
2395 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2397 ERR("Destroying the ShellWindow!\n");
2398 ti
->pDeskInfo
->hShellWindow
= NULL
;
2402 IntEngWindowChanged(Window
, WOC_DELETE
);
2404 if (!IntIsWindow(Window
->head
.h
))
2409 /* Recursively destroy owned windows */
2411 if (! (Window
->style
& WS_CHILD
))
2415 BOOL GotOne
= FALSE
;
2418 PWND Child
, Desktop
;
2420 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2421 UserGetWindowObject(IntGetDesktopWindow());
2422 Children
= IntWinListChildren(Desktop
);
2426 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2428 Child
= UserGetWindowObject(*ChildHandle
);
2431 if (Child
->spwndOwner
!= Window
)
2436 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2438 USER_REFERENCE_ENTRY ChildRef
;
2439 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2440 co_UserDestroyWindow(Child
);
2441 UserDerefObjectCo(Child
); // Temp HACK?
2447 if (Child
->spwndOwner
!= NULL
)
2449 Child
->spwndOwner
= NULL
;
2453 ExFreePool(Children
);
2462 /* Generate mouse move message for the next window */
2463 msg
.message
= WM_MOUSEMOVE
;
2464 msg
.wParam
= UserGetMouseButtonsState();
2465 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2466 msg
.pt
= gpsi
->ptCursor
;
2467 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2469 if (!IntIsWindow(Window
->head
.h
))
2474 /* Destroy the window storage */
2475 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2485 NtUserDestroyWindow(HWND Wnd
)
2488 DECLARE_RETURN(BOOLEAN
);
2490 USER_REFERENCE_ENTRY Ref
;
2492 TRACE("Enter NtUserDestroyWindow\n");
2493 UserEnterExclusive();
2495 if (!(Window
= UserGetWindowObject(Wnd
)))
2500 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2501 ret
= co_UserDestroyWindow(Window
);
2502 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2507 TRACE("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2513 static HWND FASTCALL
2514 IntFindWindow(PWND Parent
,
2517 PUNICODE_STRING WindowName
)
2519 BOOL CheckWindowName
;
2522 UNICODE_STRING CurrentWindowName
;
2526 CheckWindowName
= WindowName
->Buffer
!= 0;
2528 if((List
= IntWinListChildren(Parent
)))
2533 /* skip handles before and including ChildAfter */
2534 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2538 /* search children */
2542 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2547 /* Do not send WM_GETTEXT messages in the kernel mode version!
2548 The user mode version however calls GetWindowText() which will
2549 send WM_GETTEXT messages to windows belonging to its processes */
2550 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2552 // FIXME: LARGE_STRING truncated
2553 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2554 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2555 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2556 if(!CheckWindowName
||
2557 (Child
->strName
.Length
< 0xFFFF &&
2558 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2560 Ret
= Child
->head
.h
;
2573 * Searches a window's children for a window with the specified
2576 * hwndParent = The window whose childs are to be searched.
2578 * HWND_MESSAGE = message-only windows
2580 * hwndChildAfter = Search starts after this child window.
2581 * NULL = start from beginning
2583 * ucClassName = Class name to search for
2584 * Reguired parameter.
2586 * ucWindowName = Window name
2587 * ->Buffer == NULL = don't care
2590 * The HWND of the window if it was found, otherwise NULL
2596 NtUserFindWindowEx(HWND hwndParent
,
2597 HWND hwndChildAfter
,
2598 PUNICODE_STRING ucClassName
,
2599 PUNICODE_STRING ucWindowName
,
2602 PWND Parent
, ChildAfter
;
2603 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2604 HWND Desktop
, Ret
= NULL
;
2605 BOOL DoMessageWnd
= FALSE
;
2606 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2607 DECLARE_RETURN(HWND
);
2609 TRACE("Enter NtUserFindWindowEx\n");
2612 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2616 if (ucClassName
!= NULL
)
2618 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2619 if (ClassName
.Length
!= 0)
2621 ProbeForRead(ClassName
.Buffer
,
2625 else if (!IS_ATOM(ClassName
.Buffer
))
2627 EngSetLastError(ERROR_INVALID_PARAMETER
);
2631 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2638 if (ucWindowName
!= NULL
)
2640 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2641 if (WindowName
.Length
!= 0)
2643 ProbeForRead(WindowName
.Buffer
,
2649 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2651 SetLastNtError(_SEH2_GetExceptionCode());
2652 _SEH2_YIELD(RETURN(NULL
));
2656 if (ucClassName
!= NULL
)
2658 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2659 !IS_ATOM(ClassName
.Buffer
))
2661 EngSetLastError(ERROR_INVALID_PARAMETER
);
2664 else if (ClassAtom
== (RTL_ATOM
)0)
2666 /* LastError code was set by IntGetAtomFromStringOrAtom */
2672 Desktop
= IntGetCurrentThreadDesktopWindow();
2674 if(hwndParent
== NULL
)
2676 hwndParent
= Desktop
;
2677 DoMessageWnd
= TRUE
;
2679 else if(hwndParent
== HWND_MESSAGE
)
2681 hwndParent
= IntGetMessageWindow();
2684 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2690 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2697 if(Parent
->head
.h
== Desktop
)
2700 PWND TopLevelWindow
;
2701 BOOLEAN CheckWindowName
;
2702 BOOLEAN WindowMatches
;
2703 BOOLEAN ClassMatches
;
2705 /* windows searches through all top-level windows if the parent is the desktop
2708 if((List
= IntWinListChildren(Parent
)))
2714 /* skip handles before and including ChildAfter */
2715 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2719 CheckWindowName
= WindowName
.Buffer
!= 0;
2721 /* search children */
2724 UNICODE_STRING ustr
;
2726 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2731 /* Do not send WM_GETTEXT messages in the kernel mode version!
2732 The user mode version however calls GetWindowText() which will
2733 send WM_GETTEXT messages to windows belonging to its processes */
2734 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2735 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
2736 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
2737 WindowMatches
= !CheckWindowName
||
2738 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2739 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2740 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2741 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2743 if (WindowMatches
&& ClassMatches
)
2745 Ret
= TopLevelWindow
->head
.h
;
2749 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2751 /* window returns the handle of the top-level window, in case it found
2753 Ret
= TopLevelWindow
->head
.h
;
2763 ERR("FindWindowEx: Not Desktop Parent!\n");
2764 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2767 if (Ret
== NULL
&& DoMessageWnd
)
2771 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2773 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2777 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2779 SetLastNtError(_SEH2_GetExceptionCode());
2787 TRACE("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2796 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
2798 PWND WndAncestor
, Parent
;
2800 if (Wnd
->head
.h
== IntGetDesktopWindow())
2809 WndAncestor
= Wnd
->spwndParent
;
2820 if(!(Parent
= WndAncestor
->spwndParent
))
2824 if(IntIsDesktopWindow(Parent
))
2829 WndAncestor
= Parent
;
2842 Parent
= IntGetParent(WndAncestor
);
2849 WndAncestor
= Parent
;
2867 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2869 PWND Window
, Ancestor
;
2870 DECLARE_RETURN(HWND
);
2872 TRACE("Enter NtUserGetAncestor\n");
2873 UserEnterExclusive();
2875 if (!(Window
= UserGetWindowObject(hWnd
)))
2880 Ancestor
= UserGetAncestor(Window
, Type
);
2881 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
2883 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
2886 TRACE("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
2894 NtUserGetComboBoxInfo(
2899 DECLARE_RETURN(BOOL
);
2901 TRACE("Enter NtUserGetComboBoxInfo\n");
2904 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2913 sizeof(COMBOBOXINFO
),
2917 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2919 SetLastNtError(_SEH2_GetExceptionCode());
2920 _SEH2_YIELD(RETURN(FALSE
));
2924 // Pass the user pointer, it was already probed.
2925 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
2928 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
2936 NtUserGetListBoxInfo(
2940 DECLARE_RETURN(DWORD
);
2942 TRACE("Enter NtUserGetListBoxInfo\n");
2945 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2950 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
2953 TRACE("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
2961 * The NtUserSetParent function changes the parent window of the specified
2965 * The new parent window and the child window must belong to the same
2966 * application. If the window identified by the hWndChild parameter is
2967 * visible, the system performs the appropriate redrawing and repainting.
2968 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
2969 * or WS_POPUP window styles of the window whose parent is being changed.
2976 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
2978 DECLARE_RETURN(HWND
);
2980 TRACE("Enter NtUserSetParent\n");
2981 UserEnterExclusive();
2984 Check Parent first from user space, set it here.
2988 hWndNewParent
= IntGetDesktopWindow();
2990 else if (hWndNewParent
== HWND_MESSAGE
)
2992 hWndNewParent
= IntGetMessageWindow();
2995 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
2998 TRACE("Leave NtUserSetParent, ret=%i\n",_ret_
);
3004 * UserGetShellWindow
3006 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3011 HWND FASTCALL
UserGetShellWindow(VOID
)
3013 PWINSTATION_OBJECT WinStaObject
;
3016 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3021 if (!NT_SUCCESS(Status
))
3023 SetLastNtError(Status
);
3027 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3029 ObDereferenceObject(WinStaObject
);
3034 * NtUserSetShellWindowEx
3036 * This is undocumented function to set global shell window. The global
3037 * shell window has special handling of window position.
3043 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3045 PWINSTATION_OBJECT WinStaObject
;
3046 PWND WndShell
, WndListView
;
3047 DECLARE_RETURN(BOOL
);
3048 USER_REFERENCE_ENTRY Ref
;
3052 TRACE("Enter NtUserSetShellWindowEx\n");
3053 UserEnterExclusive();
3055 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3060 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3065 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3070 if (!NT_SUCCESS(Status
))
3072 SetLastNtError(Status
);
3077 * Test if we are permitted to change the shell window.
3079 if (WinStaObject
->ShellWindow
)
3081 ObDereferenceObject(WinStaObject
);
3086 * Move shell window into background.
3088 if (hwndListView
&& hwndListView
!= hwndShell
)
3091 * Disabled for now to get Explorer working.
3092 * -- Filip, 01/nov/2003
3095 co_WinPosSetWindowPos(hwndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3098 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3100 ObDereferenceObject(WinStaObject
);
3105 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3107 ObDereferenceObject(WinStaObject
);
3111 UserRefObjectCo(WndShell
, &Ref
);
3112 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3114 WinStaObject
->ShellWindow
= hwndShell
;
3115 WinStaObject
->ShellListView
= hwndListView
;
3117 ti
= GetW32ThreadInfo();
3120 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3121 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3124 UserDerefObjectCo(WndShell
);
3126 ObDereferenceObject(WinStaObject
);
3130 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3136 * NtUserGetSystemMenu
3138 * The NtUserGetSystemMenu function allows the application to access the
3139 * window menu (also known as the system menu or the control menu) for
3140 * copying and modifying.
3144 * Handle to the window that will own a copy of the window menu.
3146 * Specifies the action to be taken. If this parameter is FALSE,
3147 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3148 * currently in use. The copy is initially identical to the window menu
3149 * but it can be modified.
3150 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3151 * to the default state. The previous window menu, if any, is destroyed.
3154 * If the bRevert parameter is FALSE, the return value is a handle to a
3155 * copy of the window menu. If the bRevert parameter is TRUE, the return
3163 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3167 DECLARE_RETURN(HMENU
);
3169 TRACE("Enter NtUserGetSystemMenu\n");
3172 if (!(Window
= UserGetWindowObject(hWnd
)))
3177 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3182 RETURN(Menu
->MenuInfo
.Self
);
3185 TRACE("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3191 * NtUserSetSystemMenu
3198 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3200 BOOL Result
= FALSE
;
3203 DECLARE_RETURN(BOOL
);
3205 TRACE("Enter NtUserSetSystemMenu\n");
3206 UserEnterExclusive();
3208 if (!(Window
= UserGetWindowObject(hWnd
)))
3216 * Assign new menu handle.
3218 if (!(Menu
= UserGetMenuObject(hMenu
)))
3223 Result
= IntSetSystemMenu(Window
, Menu
);
3229 TRACE("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3234 // Fixes wine Win test_window_styles and todo tests...
3235 static BOOL FASTCALL
3236 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3238 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3240 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3247 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3249 PWND Window
, Parent
;
3250 PWINSTATION_OBJECT WindowStation
;
3254 if (hWnd
== IntGetDesktopWindow())
3256 EngSetLastError(STATUS_ACCESS_DENIED
);
3260 if (!(Window
= UserGetWindowObject(hWnd
)))
3265 if ((INT
)Index
>= 0)
3267 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3269 EngSetLastError(ERROR_INVALID_INDEX
);
3273 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3275 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3277 OldValue = (LONG)IntSetWindowProc( Wnd,
3280 if (!OldValue) return 0;
3283 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3290 OldValue
= (LONG
) Window
->ExStyle
;
3291 Style
.styleOld
= OldValue
;
3292 Style
.styleNew
= NewValue
;
3294 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3297 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3299 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3302 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3303 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3305 /* WS_EX_WINDOWEDGE depends on some other styles */
3306 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3307 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3309 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3311 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3312 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3316 OldValue
= (LONG
) Window
->style
;
3317 Style
.styleOld
= OldValue
;
3318 Style
.styleNew
= NewValue
;
3319 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3321 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3322 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3323 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3324 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3325 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3327 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3329 Window
->style
= (DWORD
)Style
.styleNew
;
3330 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3335 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3336 Window
->fnid
& FNID_FREED
)
3338 EngSetLastError(ERROR_ACCESS_DENIED
);
3341 OldValue
= (LONG
)IntSetWindowProc(Window
,
3348 OldValue
= (LONG
) Window
->hModule
;
3349 Window
->hModule
= (HINSTANCE
) NewValue
;
3352 case GWL_HWNDPARENT
:
3353 Parent
= Window
->spwndParent
;
3354 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3355 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3357 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3361 OldValue
= (LONG
) Window
->IDMenu
;
3362 Window
->IDMenu
= (UINT
) NewValue
;
3366 OldValue
= Window
->dwUserData
;
3367 Window
->dwUserData
= NewValue
;
3371 ERR("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3372 EngSetLastError(ERROR_INVALID_INDEX
);
3382 * NtUserSetWindowLong
3384 * The NtUserSetWindowLong function changes an attribute of the specified
3385 * window. The function also sets the 32-bit (long) value at the specified
3386 * offset into the extra window memory.
3393 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3395 DECLARE_RETURN(LONG
);
3397 TRACE("Enter NtUserSetWindowLong\n");
3398 UserEnterExclusive();
3400 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3403 TRACE("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3409 * NtUserSetWindowWord
3411 * Legacy function similar to NtUserSetWindowLong.
3418 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3422 DECLARE_RETURN(WORD
);
3424 TRACE("Enter NtUserSetWindowWord\n");
3425 UserEnterExclusive();
3427 if (!(Window
= UserGetWindowObject(hWnd
)))
3436 case GWL_HWNDPARENT
:
3437 RETURN( (WORD
)co_UserSetWindowLong(Window
->head
.h
, Index
, (UINT
)NewValue
, TRUE
));
3441 EngSetLastError(ERROR_INVALID_INDEX
);
3446 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3448 EngSetLastError(ERROR_INVALID_PARAMETER
);
3452 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3453 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3458 TRACE("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3464 QueryWindow based on KJK::Hyperion and James Tabor.
3466 0 = QWUniqueProcessId
3467 1 = QWUniqueThreadId
3470 4 = QWIsHung Implements IsHungAppWindow found
3473 9 = QWKillWindow When I called this with hWnd ==
3474 DesktopWindow, it shutdown the system
3481 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3485 DECLARE_RETURN(UINT
);
3487 TRACE("Enter NtUserQueryWindow\n");
3490 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3497 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3498 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3501 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3502 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3505 case QUERY_WINDOW_ACTIVE
:
3506 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3509 case QUERY_WINDOW_FOCUS
:
3510 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3513 case QUERY_WINDOW_ISHUNG
:
3514 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
->MessageQueue
);
3517 case QUERY_WINDOW_REAL_ID
:
3518 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3522 Result
= (DWORD
)NULL
;
3529 TRACE("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3539 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3541 UNICODE_STRING SafeMessageName
;
3544 DECLARE_RETURN(UINT
);
3546 TRACE("Enter NtUserRegisterWindowMessage\n");
3547 UserEnterExclusive();
3549 if(MessageNameUnsafe
== NULL
)
3551 EngSetLastError(ERROR_INVALID_PARAMETER
);
3555 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3556 if(!NT_SUCCESS(Status
))
3558 SetLastNtError(Status
);
3562 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3563 if (SafeMessageName
.Buffer
)
3564 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3568 TRACE("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3585 DECLARE_RETURN(BOOL
);
3587 TRACE("Enter NtUserSetMenu\n");
3588 UserEnterExclusive();
3590 if (!(Window
= UserGetWindowObject(hWnd
)))
3595 if (! IntSetMenu(Window
, Menu
, &Changed
))
3600 if (Changed
&& Repaint
)
3602 USER_REFERENCE_ENTRY Ref
;
3604 UserRefObjectCo(Window
, &Ref
);
3605 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3606 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3608 UserDerefObjectCo(Window
);
3614 TRACE("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3623 NtUserSetWindowFNID(HWND hWnd
,
3627 DECLARE_RETURN(BOOL
);
3629 TRACE("Enter NtUserSetWindowFNID\n");
3630 UserEnterExclusive();
3632 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3637 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3639 EngSetLastError(ERROR_ACCESS_DENIED
);
3643 // From user land we only set these.
3644 if (fnID
!= FNID_DESTROY
)
3645 { // Hacked so we can mark desktop~!
3646 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
3649 EngSetLastError(ERROR_INVALID_PARAMETER
);
3658 TRACE("Leave NtUserSetWindowFNID\n");
3666 * Undocumented function that is called from DefWindowProc to set
3673 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
3676 LARGE_STRING SafeText
;
3677 UNICODE_STRING UnicodeString
;
3680 TRACE("Enter NtUserDefSetText\n");
3682 if (WindowText
!= NULL
)
3686 SafeText
= ProbeForReadLargeString(WindowText
);
3688 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3691 SetLastNtError(_SEH2_GetExceptionCode());
3701 UserEnterExclusive();
3703 if(!(Wnd
= UserGetWindowObject(hWnd
)))
3709 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
3710 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
3711 // Now we know what the bAnsi is for.
3712 RtlInitUnicodeString(&UnicodeString
, NULL
);
3713 if (SafeText
.Buffer
)
3718 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
3720 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
3721 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
3723 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3726 SetLastNtError(_SEH2_GetExceptionCode());
3729 if (!Ret
) goto Exit
;
3732 if (UnicodeString
.Length
!= 0)
3734 if (Wnd
->strName
.MaximumLength
> 0 &&
3735 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
3737 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
3739 Wnd
->strName
.Length
= UnicodeString
.Length
;
3740 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
3741 RtlCopyMemory(Wnd
->strName
.Buffer
,
3742 UnicodeString
.Buffer
,
3743 UnicodeString
.Length
);
3748 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
3749 buf
= Wnd
->strName
.Buffer
;
3750 Wnd
->strName
.Buffer
= NULL
;
3753 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
3756 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
3757 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
3758 if (Wnd
->strName
.Buffer
!= NULL
)
3760 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
3761 RtlCopyMemory(Wnd
->strName
.Buffer
,
3762 UnicodeString
.Buffer
,
3763 UnicodeString
.Length
);
3764 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
3765 Wnd
->strName
.Length
= UnicodeString
.Length
;
3769 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3777 Wnd
->strName
.Length
= 0;
3778 if (Wnd
->strName
.Buffer
!= NULL
)
3779 Wnd
->strName
.Buffer
[0] = L
'\0';
3782 // FIXME: HAX! Windows does not do this in here!
3783 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
3784 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
3785 /* Send shell notifications */
3786 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
3788 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
3793 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
3794 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
3800 * NtUserInternalGetWindowText
3807 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
3812 DECLARE_RETURN(INT
);
3814 TRACE("Enter NtUserInternalGetWindowText\n");
3817 if(lpString
&& (nMaxCount
<= 1))
3819 EngSetLastError(ERROR_INVALID_PARAMETER
);
3823 if(!(Wnd
= UserGetWindowObject(hWnd
)))
3828 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
3831 const WCHAR Terminator
= L
'\0';
3833 WCHAR
*Buffer
= (WCHAR
*)lpString
;
3835 Copy
= min(nMaxCount
- 1, Result
);
3838 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
3839 if(!NT_SUCCESS(Status
))
3841 SetLastNtError(Status
);
3847 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
3848 if(!NT_SUCCESS(Status
))
3850 SetLastNtError(Status
);
3860 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
3868 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
3874 // ASSERT(OwnerWnd);
3876 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
3881 while (win_array
[count
])
3883 while (--count
>= 0)