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
++;
62 PWND FASTCALL
VerifyWnd(PWND pWnd
)
67 if (!pWnd
) return NULL
;
71 hWnd
= UserHMGetHandle(pWnd
);
73 State2
= pWnd
->state2
;
75 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
77 _SEH2_YIELD(return NULL
);
81 if ( UserObjectInDestroy(hWnd
) ||
82 State
& WNDS_DESTROYED
||
83 State2
& WNDS2_INDESTROY
)
89 PWND FASTCALL
ValidateHwndNoErr(HWND hWnd
)
91 if (hWnd
) return (PWND
)UserGetObjectNoErr(gHandleTable
, hWnd
, otWindow
);
96 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
102 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
106 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, otWindow
);
107 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
109 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
117 IntSetStyle( PWND pwnd
, ULONG set_bits
, ULONG clear_bits
)
119 ULONG styleOld
, styleNew
;
120 styleOld
= pwnd
->style
;
121 styleNew
= (pwnd
->style
| set_bits
) & ~clear_bits
;
122 if (styleNew
== styleOld
) return styleNew
;
123 pwnd
->style
= styleNew
;
124 if ((styleOld
^ styleNew
) & WS_VISIBLE
) DceResetActiveDCEs( pwnd
);
131 * The function determines whether the specified window handle identifies
132 * an existing window.
136 * Handle to the window to test.
139 * If the window handle identifies an existing window, the return value
140 * is TRUE. If the window handle does not identify an existing window,
141 * the return value is FALSE.
145 IntIsWindow(HWND hWnd
)
149 if (!(Window
= UserGetWindowObject(hWnd
)))
156 IntIsWindowVisible(PWND Wnd
)
161 if (!(Wnd
->style
& WS_VISIBLE
))
166 if (Wnd
->spwndParent
!= NULL
)
167 Wnd
= Wnd
->spwndParent
;
176 IntGetParent(PWND Wnd
)
178 if (Wnd
->style
& WS_POPUP
)
180 return Wnd
->spwndOwner
;
182 else if (Wnd
->style
& WS_CHILD
)
184 return Wnd
->spwndParent
;
192 IntEnableWindow( HWND hWnd
, BOOL bEnable
)
198 if(!(pWnd
= UserGetWindowObject(hWnd
)))
203 /* check if updating is needed */
204 bIsDisabled
= !!(pWnd
->style
& WS_DISABLED
);
205 Update
= bIsDisabled
;
209 IntSetStyle( pWnd
, 0, WS_DISABLED
);
213 Update
= !bIsDisabled
;
215 co_IntSendMessage( hWnd
, WM_CANCELMODE
, 0, 0);
217 /* Remove keyboard focus from that window if it had focus */
218 if (hWnd
== IntGetThreadFocusWindow())
220 co_UserSetFocus(NULL
);
222 IntSetStyle( pWnd
, WS_DISABLED
, 0 );
227 IntNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, pWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
228 co_IntSendMessage(hWnd
, WM_ENABLE
, (LPARAM
)bEnable
, 0);
230 // Return nonzero if it was disabled, or zero if it wasn't:
237 * Compile a list of all child window handles from given window.
240 * This function is similar to Wine WIN_ListChildren. The caller
241 * must free the returned list with ExFreePool.
245 IntWinListChildren(PWND Window
)
249 UINT Index
, NumChildren
= 0;
251 if (!Window
) return NULL
;
253 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
256 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
259 ERR("Failed to allocate memory for children array\n");
260 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
263 for (Child
= Window
->spwndChild
, Index
= 0;
265 Child
= Child
->spwndNext
, ++Index
)
266 List
[Index
] = Child
->head
.h
;
272 /***********************************************************************
275 static void IntSendDestroyMsg(HWND hWnd
)
283 if (GetGUIThreadInfo(GetCurrentThreadId(), &info
))
285 if (hWnd
== info
.hwndCaret
)
292 Window
= UserGetWindowObject(hWnd
);
295 // USER_REFERENCE_ENTRY Ref;
296 // UserRefObjectCo(Window, &Ref);
298 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
300 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (LPARAM
) hWnd
);
303 // UserDerefObjectCo(Window);
306 /* The window could already be destroyed here */
309 * Send the WM_DESTROY to the window.
312 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
315 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
316 * make sure that the window still exists when we come back.
325 if (!(pWndArray
= WIN_ListChildren( hwnd
)))
328 /* start from the end (FIXME: is this needed?) */
329 for (i
= 0; pWndArray
[i
]; i
++)
334 if (IsWindow( pWndArray
[i
] ))
335 WIN_SendDestroyMsg( pWndArray
[i
] );
337 HeapFree(GetProcessHeap(), 0, pWndArray
);
341 TRACE("destroyed itself while in WM_DESTROY!\n");
347 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
349 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
353 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
355 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
356 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
359 if (Wnd
->strName
.Buffer
!= NULL
)
361 Wnd
->strName
.Length
= 0;
362 Wnd
->strName
.MaximumLength
= 0;
363 DesktopHeapFree(Wnd
->head
.rpdesk
,
364 Wnd
->strName
.Buffer
);
365 Wnd
->strName
.Buffer
= NULL
;
368 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
369 // WindowObject->Wnd = NULL;
372 /***********************************************************************
375 * Destroy storage associated to a window. "Internals" p.358
377 * This is the "functional" DestroyWindows function ei. all stuff
378 * done in CreateWindow is undone here and not in DestroyWindow:-P
381 static LRESULT
co_UserFreeWindow(PWND Window
,
382 PPROCESSINFO ProcessData
,
383 PTHREADINFO ThreadData
,
384 BOOLEAN SendMessages
)
390 BOOLEAN BelongsToThreadData
;
394 if(Window
->state2
& WNDS2_INDESTROY
)
396 TRACE("Tried to call IntDestroyWindow() twice\n");
399 Window
->state2
|= WNDS2_INDESTROY
;
400 Window
->style
&= ~WS_VISIBLE
;
402 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
404 /* remove the window already at this point from the thread window list so we
405 don't get into trouble when destroying the thread windows while we're still
406 in IntDestroyWindow() */
407 RemoveEntryList(&Window
->ThreadListEntry
);
409 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
411 IntDeRegisterShellHookWindow(Window
->head
.h
);
415 /* Send destroy messages */
416 IntSendDestroyMsg(Window
->head
.h
);
419 /* free child windows */
420 Children
= IntWinListChildren(Window
);
423 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
425 if ((Child
= IntGetWindowObject(*ChildHandle
)))
427 if(!IntWndBelongsToThread(Child
, ThreadData
))
429 /* send WM_DESTROY messages to windows not belonging to the same thread */
430 IntSendDestroyMsg(Child
->head
.h
);
433 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
435 UserDereferenceObject(Child
);
438 ExFreePool(Children
);
444 * Clear the update region to make sure no WM_PAINT messages will be
445 * generated for this window while processing the WM_NCDESTROY.
447 co_UserRedrawWindow(Window
, NULL
, 0,
448 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
449 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
450 if(BelongsToThreadData
)
451 co_IntSendMessage(Window
->head
.h
, WM_NCDESTROY
, 0, 0);
454 DestroyTimersForWindow(ThreadData
, Window
);
456 /* Unregister hot keys */
457 UnregisterWindowHotKeys (Window
);
459 /* flush the message queue */
460 MsqRemoveWindowMessagesFromQueue(Window
);
462 IntDereferenceMessageQueue(Window
->head
.pti
->MessageQueue
);
464 /* from now on no messages can be sent to this window anymore */
465 Window
->state
|= WNDS_DESTROYED
;
466 Window
->fnid
|= FNID_FREED
;
468 /* don't remove the WINDOWSTATUS_DESTROYING bit */
470 /* reset shell window handles */
471 if(ThreadData
->rpdesk
)
473 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
474 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
476 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
477 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
480 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
484 WinPosCheckInternalPos(Window
->head
.h
);
485 if (Window
->head
.h
== GetCapture())
490 /* free resources associated with the window */
491 TIMER_RemoveWindowTimers(Window
->head
.h
);
494 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
496 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
498 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
502 if(Window
->SystemMenu
503 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
505 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
506 Window
->SystemMenu
= (HMENU
)0;
509 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
512 WINPROC_FreeProc(Window
->winproc
, WIN_PROC_WINDOW
);
513 CLASS_RemoveWindow(Window
->Class
);
516 IntUnlinkWindow(Window
);
518 UserReferenceObject(Window
);
519 UserDeleteObject(Window
->head
.h
, otWindow
);
521 IntDestroyScrollBars(Window
);
523 /* dereference the class */
524 IntDereferenceClass(Window
->pcls
,
525 Window
->head
.pti
->pDeskInfo
,
526 Window
->head
.pti
->ppi
);
531 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
532 GreDeleteObject(Window
->hrgnClip
);
533 Window
->hrgnClip
= NULL
;
536 // ASSERT(Window != NULL);
537 UserFreeWindowInfo(Window
->head
.pti
, Window
);
539 UserDereferenceObject(Window
);
541 UserClipboardFreeWindow(Window
);
547 // Same as User32:IntGetWndProc.
550 IntGetWindowProc(PWND pWnd
,
555 WNDPROC gcpd
, Ret
= 0;
557 ASSERT(UserIsEnteredExclusive() == TRUE
);
561 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
563 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
565 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
568 Ret
= GETPFNCLIENTA(i
);
570 Ret
= GETPFNCLIENTW(i
);
576 if (Class
->fnid
== FNID_EDIT
)
577 Ret
= pWnd
->lpfnWndProc
;
580 Ret
= pWnd
->lpfnWndProc
;
582 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
586 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
587 Ret
= GETPFNCLIENTA(Class
->fnid
);
591 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
592 Ret
= GETPFNCLIENTW(Class
->fnid
);
595 if ( Ret
!= pWnd
->lpfnWndProc
)
598 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
601 gcpd
= (WNDPROC
)UserGetCPD(
603 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
606 return (gcpd
? gcpd
: Ret
);
610 IntSetWindowProc(PWND pWnd
,
615 PCALLPROCDATA CallProc
;
617 WNDPROC Ret
, chWndProc
= NULL
;
619 // Retrieve previous window proc.
620 Ret
= IntGetWindowProc(pWnd
, Ansi
);
624 if (IsCallProcHandle(NewWndProc
))
626 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, otCallProc
);
628 { // Reset new WndProc.
629 NewWndProc
= CallProc
->pfnClientPrevious
;
630 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
631 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
634 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
635 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
637 if (GETPFNCLIENTW(i
) == NewWndProc
)
639 chWndProc
= GETPFNSERVER(i
);
642 if (GETPFNCLIENTA(i
) == NewWndProc
)
644 chWndProc
= GETPFNSERVER(i
);
648 // If match, set/reset to Server Side and clear ansi.
651 pWnd
->lpfnWndProc
= chWndProc
;
652 pWnd
->Unicode
= TRUE
;
653 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
654 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
658 pWnd
->Unicode
= !Ansi
;
659 // Handle the state change in here.
661 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
663 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
665 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
666 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
668 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
670 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
674 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
675 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
679 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
680 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
683 // Now set the new window proc.
684 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
695 PMENU_OBJECT OldMenu
, NewMenu
= NULL
;
697 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
699 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
703 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
711 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
712 ASSERT(NULL
== OldMenu
|| OldMenu
->MenuInfo
.Wnd
== Wnd
->head
.h
);
721 NewMenu
= IntGetMenuObject(Menu
);
726 IntReleaseMenuObject(OldMenu
);
728 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
731 if (NULL
!= NewMenu
->MenuInfo
.Wnd
)
733 /* Can't use the same menu for two windows */
736 IntReleaseMenuObject(OldMenu
);
738 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
744 Wnd
->IDMenu
= (UINT
) Menu
;
747 NewMenu
->MenuInfo
.Wnd
= Wnd
->head
.h
;
748 IntReleaseMenuObject(NewMenu
);
752 OldMenu
->MenuInfo
.Wnd
= NULL
;
753 IntReleaseMenuObject(OldMenu
);
760 /* INTERNAL ******************************************************************/
764 co_DestroyThreadWindows(struct _ETHREAD
*Thread
)
769 USER_REFERENCE_ENTRY Ref
;
770 WThread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
;
772 while (!IsListEmpty(&WThread
->WindowListHead
))
774 Current
= WThread
->WindowListHead
.Flink
;
775 Wnd
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
777 TRACE("thread cleanup: while destroy wnds, wnd=0x%x\n",Wnd
);
779 /* Window removes itself from the list */
782 * FIXME: It is critical that the window removes itself! If now, we will loop
786 //ASSERT(co_UserDestroyWindow(Wnd));
788 UserRefObjectCo(Wnd
, &Ref
); // FIXME: Temp HACK??
789 if (!co_UserDestroyWindow(Wnd
))
791 ERR("Unable to destroy window 0x%x at thread cleanup... This is _VERY_ bad!\n", Wnd
);
793 UserDerefObjectCo(Wnd
); // FIXME: Temp HACK??
797 PMENU_OBJECT FASTCALL
798 IntGetSystemMenu(PWND Window
, BOOL bRevert
, BOOL RetMenu
)
800 PMENU_OBJECT Menu
, NewMenu
= NULL
, SysMenu
= NULL
, ret
= NULL
;
801 PTHREADINFO W32Thread
;
802 HMENU hNewMenu
, hSysMenu
;
803 ROSMENUITEMINFO ItemInfo
;
807 W32Thread
= PsGetCurrentThreadWin32Thread();
809 if(!W32Thread
->rpdesk
)
812 if(Window
->SystemMenu
)
814 Menu
= UserGetMenuObject(Window
->SystemMenu
);
817 IntDestroyMenuObject(Menu
, TRUE
, TRUE
);
818 Window
->SystemMenu
= (HMENU
)0;
822 if(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
)
824 /* Clone system menu */
825 Menu
= UserGetMenuObject(W32Thread
->rpdesk
->rpwinstaParent
->SystemMenuTemplate
);
829 NewMenu
= IntCloneMenu(Menu
);
832 Window
->SystemMenu
= NewMenu
->MenuInfo
.Self
;
833 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
834 NewMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
836 //IntReleaseMenuObject(NewMenu);
841 hSysMenu
= UserCreateMenu(FALSE
);
842 if (NULL
== hSysMenu
)
846 SysMenu
= IntGetMenuObject(hSysMenu
);
849 UserDestroyMenu(hSysMenu
);
852 SysMenu
->MenuInfo
.Flags
|= MF_SYSMENU
;
853 SysMenu
->MenuInfo
.Wnd
= Window
->head
.h
;
854 hNewMenu
= co_IntLoadSysMenuTemplate();
857 IntReleaseMenuObject(SysMenu
);
858 UserDestroyMenu(hSysMenu
);
861 Menu
= IntGetMenuObject(hNewMenu
);
864 IntReleaseMenuObject(SysMenu
);
865 UserDestroyMenu(hSysMenu
);
869 NewMenu
= IntCloneMenu(Menu
);
872 NewMenu
->MenuInfo
.Flags
|= MF_SYSMENU
| MF_POPUP
;
873 IntReleaseMenuObject(NewMenu
);
874 UserSetMenuDefaultItem(NewMenu
, SC_CLOSE
, FALSE
);
876 ItemInfo
.cbSize
= sizeof(MENUITEMINFOW
);
877 ItemInfo
.fMask
= MIIM_FTYPE
| MIIM_STRING
| MIIM_STATE
| MIIM_SUBMENU
;
878 ItemInfo
.fType
= MF_POPUP
;
879 ItemInfo
.fState
= MFS_ENABLED
;
880 ItemInfo
.dwTypeData
= NULL
;
882 ItemInfo
.hSubMenu
= NewMenu
->MenuInfo
.Self
;
883 IntInsertMenuItem(SysMenu
, (UINT
) -1, TRUE
, &ItemInfo
);
885 Window
->SystemMenu
= SysMenu
->MenuInfo
.Self
;
889 IntDestroyMenuObject(Menu
, FALSE
, TRUE
);
898 if(Window
->SystemMenu
)
899 return IntGetMenuObject((HMENU
)Window
->SystemMenu
);
907 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
912 while (Window
&& ((Window
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
914 if (Window
== Parent
)
919 Window
= Window
->spwndParent
;
926 Link the window into siblings list
927 children and parent are kept in place.
932 PWND WndInsertAfter
/* set to NULL if top sibling */
935 if ((Wnd
->spwndPrev
= WndInsertAfter
))
937 /* link after WndInsertAfter */
938 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
939 Wnd
->spwndNext
->spwndPrev
= Wnd
;
941 Wnd
->spwndPrev
->spwndNext
= Wnd
;
946 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
947 Wnd
->spwndNext
->spwndPrev
= Wnd
;
949 Wnd
->spwndParent
->spwndChild
= Wnd
;
954 Note: Wnd->spwndParent can be null if it is the desktop.
956 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
958 if (hWndPrev
== HWND_NOTOPMOST
)
960 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
961 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
962 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
963 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
966 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
968 if (hWndPrev
== HWND_BOTTOM
)
970 /* Link in the bottom of the list */
973 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
974 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
975 WndInsertAfter
= WndInsertAfter
->spwndNext
;
977 IntLinkWindow(Wnd
, WndInsertAfter
);
978 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
980 else if (hWndPrev
== HWND_TOPMOST
)
982 /* Link in the top of the list */
983 IntLinkWindow(Wnd
, NULL
);
985 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
987 else if (hWndPrev
== HWND_TOP
)
989 /* Link it after the last topmost window */
990 PWND WndInsertBefore
;
992 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
994 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
996 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
998 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
999 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
1001 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1004 WndInsertBefore
= WndInsertBefore
->spwndNext
;
1008 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
1012 /* Link it after hWndPrev */
1013 PWND WndInsertAfter
;
1015 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1016 /* Are we called with an erroneous handle */
1017 if(WndInsertAfter
== NULL
)
1019 /* Link in a default position */
1020 IntLinkHwnd(Wnd
, HWND_TOP
);
1024 IntLinkWindow(Wnd
, WndInsertAfter
);
1026 /* Fix the WS_EX_TOPMOST flag */
1027 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1029 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1033 if(WndInsertAfter
->spwndNext
&&
1034 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1036 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1043 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1045 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1048 Wnd
= IntGetWindowObject(hWnd
);
1052 WndOldOwner
= Wnd
->spwndOwner
;
1054 ret
= WndOldOwner
? WndOldOwner
->head
.h
: 0;
1056 if((WndNewOwner
= UserGetWindowObject(hWndNewOwner
)))
1058 Wnd
->spwndOwner
= WndNewOwner
;
1062 Wnd
->spwndOwner
= NULL
;
1065 UserDereferenceObject(Wnd
);
1070 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1072 PWND WndOldParent
, pWndExam
;
1075 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1078 ASSERT(WndNewParent
);
1079 ASSERT_REFS_CO(Wnd
);
1080 ASSERT_REFS_CO(WndNewParent
);
1082 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1084 EngSetLastError(ERROR_ACCESS_DENIED
);
1088 /* Some applications try to set a child as a parent */
1089 if (IntIsChildWindow(Wnd
, WndNewParent
))
1091 EngSetLastError( ERROR_INVALID_PARAMETER
);
1095 pWndExam
= WndNewParent
; // Load parent Window to examine.
1096 // Now test for set parent to parent hit.
1099 if (Wnd
== pWndExam
)
1101 EngSetLastError(ERROR_INVALID_PARAMETER
);
1104 pWndExam
= pWndExam
->spwndParent
;
1108 * Windows hides the window first, then shows it again
1109 * including the WM_SHOWWINDOW messages and all
1111 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1113 /* Window must belong to current process */
1114 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1117 WndOldParent
= Wnd
->spwndParent
;
1119 if ( WndOldParent
&&
1120 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1121 pt
.x
= Wnd
->rcWindow
.right
;
1123 pt
.x
= Wnd
->rcWindow
.left
;
1124 pt
.y
= Wnd
->rcWindow
.top
;
1126 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1128 if (WndNewParent
!= WndOldParent
)
1130 /* Unlink the window from the siblings list */
1131 IntUnlinkWindow(Wnd
);
1133 /* Set the new parent */
1134 Wnd
->spwndParent
= WndNewParent
;
1136 if ( Wnd
->style
& WS_CHILD
&&
1138 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1140 ERR("SetParent Top Most from Pop up!\n");
1141 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1144 /* Link the window with its new siblings */
1146 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1147 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1151 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1152 swFlags
|= SWP_NOACTIVATE
;
1154 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1156 * SetParent additionally needs to make hwnd the top window
1157 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1158 * WM_WINDOWPOSCHANGED notification messages.
1160 co_WinPosSetWindowPos( Wnd
,
1161 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1162 pt
.x
, pt
.y
, 0, 0, swFlags
);
1164 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1166 return WndOldParent
;
1170 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1172 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1173 HWND hWndOldParent
= NULL
;
1174 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1176 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1178 EngSetLastError(ERROR_INVALID_PARAMETER
);
1182 if (hWndChild
== IntGetDesktopWindow())
1184 EngSetLastError(ERROR_ACCESS_DENIED
);
1190 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1197 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1203 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1208 UserRefObjectCo(Wnd
, &Ref
);
1209 UserRefObjectCo(WndParent
, &ParentRef
);
1210 //ERR("Enter co_IntSetParent\n");
1211 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1212 //ERR("Leave co_IntSetParent\n");
1213 UserDerefObjectCo(WndParent
);
1214 UserDerefObjectCo(Wnd
);
1218 hWndOldParent
= WndOldParent
->head
.h
;
1219 UserDereferenceObject(WndOldParent
);
1222 return( hWndOldParent
);
1226 IntSetSystemMenu(PWND Window
, PMENU_OBJECT Menu
)
1228 PMENU_OBJECT OldMenu
;
1229 if(Window
->SystemMenu
)
1231 OldMenu
= IntGetMenuObject(Window
->SystemMenu
);
1234 OldMenu
->MenuInfo
.Flags
&= ~ MF_SYSMENU
;
1235 IntReleaseMenuObject(OldMenu
);
1241 /* FIXME: Check window style, propably return FALSE? */
1242 Window
->SystemMenu
= Menu
->MenuInfo
.Self
;
1243 Menu
->MenuInfo
.Flags
|= MF_SYSMENU
;
1246 Window
->SystemMenu
= (HMENU
)0;
1251 /* Unlink the window from siblings. children and parent are kept in place. */
1253 IntUnlinkWindow(PWND Wnd
)
1256 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1259 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1261 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1262 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1264 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1267 /* FUNCTIONS *****************************************************************/
1270 * As best as I can figure, this function is used by EnumWindows,
1271 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1273 * It's supposed to build a list of HWNDs to return to the caller.
1274 * We can figure out what kind of list by what parameters are
1282 NtUserBuildHwndList(
1295 return ERROR_INVALID_PARAMETER
;
1297 if (hwndParent
|| !dwThreadId
)
1300 PWND Parent
, Window
;
1304 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1306 return ERROR_INVALID_HANDLE
;
1311 Status
= IntValidateDesktopHandle(hDesktop
,
1315 if(!NT_SUCCESS(Status
))
1317 return ERROR_INVALID_HANDLE
;
1320 hwndParent
= Desktop
->DesktopWindow
;
1327 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1328 (Window
= Parent
->spwndChild
))
1330 BOOL bGoDown
= TRUE
;
1332 Status
= STATUS_SUCCESS
;
1337 if(dwCount
++ < *pBufSize
&& pWnd
)
1341 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1342 *pWnd
= Window
->head
.h
;
1345 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1347 Status
= _SEH2_GetExceptionCode();
1350 if(!NT_SUCCESS(Status
))
1352 SetLastNtError(Status
);
1356 if (Window
->spwndChild
&& bChildren
)
1358 Window
= Window
->spwndChild
;
1363 if (Window
->spwndNext
)
1365 Window
= Window
->spwndNext
;
1369 Window
= Window
->spwndParent
;
1370 if (Window
== Parent
)
1379 ObDereferenceObject(Desktop
);
1382 else // Build EnumThreadWindows list!
1385 PTHREADINFO W32Thread
;
1386 PLIST_ENTRY Current
;
1389 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1390 if (!NT_SUCCESS(Status
))
1392 ERR("Thread Id is not valid!\n");
1393 return ERROR_INVALID_PARAMETER
;
1395 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1397 ObDereferenceObject(Thread
);
1398 ERR("Thread is not initialized!\n");
1399 return ERROR_INVALID_PARAMETER
;
1402 Current
= W32Thread
->WindowListHead
.Flink
;
1403 while (Current
!= &(W32Thread
->WindowListHead
))
1405 Window
= CONTAINING_RECORD(Current
, WND
, ThreadListEntry
);
1408 if (dwCount
< *pBufSize
&& pWnd
)
1412 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1413 *pWnd
= Window
->head
.h
;
1416 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1418 Status
= _SEH2_GetExceptionCode();
1421 if (!NT_SUCCESS(Status
))
1423 ERR("Failure to build window list!\n");
1424 SetLastNtError(Status
);
1429 Current
= Window
->ThreadListEntry
.Flink
;
1432 ObDereferenceObject(Thread
);
1435 *pBufSize
= dwCount
;
1436 return STATUS_SUCCESS
;
1439 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1441 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1442 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1444 if (pWindow
->spwndParent
&& pWindow
->spwndParent
!= UserGetDesktopWindow())
1446 USER_REFERENCE_ENTRY Ref
;
1447 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1448 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1450 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1451 (LPARAM
)pWindow
->head
.h
);
1452 UserDerefObjectCo(pWindow
->spwndParent
);
1458 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1460 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1462 /* default positioning for overlapped windows */
1463 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1466 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1468 pMonitor
= UserGetPrimaryMonitor();
1470 /* Check if we don't have a monitor attached yet */
1471 if(pMonitor
== NULL
)
1479 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1481 if (IS_DEFAULT(Cs
->x
))
1483 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1485 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1487 Cs
->x
= ProcessParams
->StartingX
;
1488 Cs
->y
= ProcessParams
->StartingY
;
1492 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1493 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1494 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1495 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1497 /* reset counter and position */
1500 pMonitor
->cWndStack
= 0;
1502 pMonitor
->cWndStack
++;
1506 if (IS_DEFAULT(Cs
->cx
))
1508 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1510 Cs
->cx
= ProcessParams
->CountX
;
1511 Cs
->cy
= ProcessParams
->CountY
;
1515 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1516 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1519 /* neither x nor cx are default. Check the y values .
1520 * In the trace we see Outlook and Outlook Express using
1521 * cy set to CW_USEDEFAULT when opening the address book.
1523 else if (IS_DEFAULT(Cs
->cy
))
1525 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1526 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1531 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1532 if(IS_DEFAULT(Cs
->x
))
1537 if(IS_DEFAULT(Cs
->cx
))
1547 /* Allocates and initializes a window */
1548 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1549 PLARGE_STRING WindowName
,
1557 PTHREADINFO pti
= NULL
;
1558 PMENU_OBJECT SystemMenu
;
1560 BOOL bUnicodeWindow
;
1562 pti
= PsGetCurrentThreadWin32Thread();
1564 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1568 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1569 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1570 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1571 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1575 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1577 * Dialog boxes and message boxes do not inherit layout, so you must
1578 * set the layout explicitly.
1580 if ( Class
->fnid
!= FNID_DIALOG
)
1582 PPROCESSINFO ppi
= PsGetCurrentProcessWin32Process();
1583 if (ppi
->dwLayout
& LAYOUT_RTL
)
1585 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1591 /* Automatically add WS_EX_WINDOWEDGE */
1592 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1593 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1594 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1595 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1597 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1599 /* Is it a unicode window? */
1600 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1601 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1603 /* Allocate the new window */
1604 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1608 sizeof(WND
) + Class
->cbwndExtra
);
1615 TRACE("Created object with handle %X\n", hWnd
);
1617 if (NULL
== pti
->rpdesk
->DesktopWindow
)
1618 { /* HACK: Helper for win32csr/desktopbg.c */
1619 /* If there is no desktop window yet, we must be creating it */
1620 pti
->rpdesk
->DesktopWindow
= hWnd
;
1621 pti
->rpdesk
->pDeskInfo
->spwnd
= pWnd
;
1625 * Fill out the structure describing it.
1627 /* Remember, pWnd->head is setup in object.c ... */
1628 pWnd
->spwndParent
= ParentWindow
;
1629 pWnd
->spwndOwner
= OwnerWindow
;
1631 pWnd
->spwndLastActive
= pWnd
;
1632 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1634 pWnd
->hModule
= Cs
->hInstance
;
1635 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1636 pWnd
->ExStyle
= Cs
->dwExStyle
;
1637 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1638 pWnd
->pActCtx
= acbiBuffer
;
1639 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1640 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1642 IntReferenceMessageQueue(pWnd
->head
.pti
->MessageQueue
);
1643 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1645 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1646 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1649 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1650 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1652 /* BugBoy Comments: Comment below say that System classes are always created
1653 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1654 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1656 No where can I see in code or through testing does the window change back
1657 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1658 see what problems this would cause. */
1660 // Set WndProc from Class.
1661 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1663 // GetWindowProc, test for non server side default classes and set WndProc.
1664 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1668 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1669 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1673 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1674 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1678 // If not an Unicode caller, set Ansi creator bit.
1679 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1681 // Clone Class Ansi/Unicode proc type.
1682 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1684 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1685 pWnd
->Unicode
= FALSE
;
1689 * It seems there can be both an Ansi creator and Unicode Class Window
1690 * WndProc, unless the following overriding conditions occur:
1692 if ( !bUnicodeWindow
&&
1693 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1694 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1695 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1696 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1697 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1698 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1699 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1700 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1701 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1702 { // Override Class and set the window Ansi WndProc.
1703 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1704 pWnd
->Unicode
= FALSE
;
1707 { // Set the window Unicode WndProc.
1708 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1709 pWnd
->Unicode
= TRUE
;
1713 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1714 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1715 Dont understand why it does this. */
1716 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1718 PCALLPROCDATA CallProc
;
1719 CallProc
= CreateCallProc(NULL
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1723 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1724 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %x\n",hWnd
);
1728 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1732 InitializeListHead(&pWnd
->PropListHead
);
1734 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1736 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1737 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1738 if (pWnd
->strName
.Buffer
== NULL
)
1743 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1744 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1745 pWnd
->strName
.Length
= WindowName
->Length
;
1746 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1749 /* Correct the window style. */
1750 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1752 pWnd
->style
|= WS_CLIPSIBLINGS
;
1753 if (!(pWnd
->style
& WS_POPUP
))
1755 pWnd
->style
|= WS_CAPTION
;
1759 /* WS_EX_WINDOWEDGE depends on some other styles */
1760 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1761 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1762 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1764 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1765 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1766 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1769 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1771 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1772 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1774 /* Create system menu */
1775 if ((Cs
->style
& WS_SYSMENU
)) // && (dwStyle & WS_CAPTION) == WS_CAPTION)
1777 SystemMenu
= IntGetSystemMenu(pWnd
, TRUE
, TRUE
);
1780 pWnd
->SystemMenu
= SystemMenu
->MenuInfo
.Self
;
1781 IntReleaseMenuObject(SystemMenu
);
1785 /* Set the window menu */
1786 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1789 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1790 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1792 UNICODE_STRING MenuName
;
1795 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1797 MenuName
.Length
= 0;
1798 MenuName
.MaximumLength
= 0;
1799 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1803 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1805 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1806 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1810 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1812 /* Insert the window into the thread's window list. */
1813 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1815 /* Handle "CS_CLASSDC", it is tested first. */
1816 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1817 { /* One DCE per class to have CLASS. */
1818 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1820 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1821 { /* Allocate a DCE for this window. */
1822 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1828 ERR("IntCreateWindow Allocation Error.\n");
1830 UserDereferenceObject(pWnd
);
1832 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1840 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1841 PUNICODE_STRING ClassName
,
1842 PLARGE_STRING WindowName
,
1846 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1847 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1848 PWINSTATION_OBJECT WinSta
;
1852 CBT_CREATEWNDW
* pCbtCreate
;
1854 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1856 DWORD dwShowMode
= SW_SHOW
;
1857 CREATESTRUCTW
*pCsw
= NULL
;
1858 PVOID pszClass
= NULL
, pszName
= NULL
;
1861 /* Get the current window station and reference it */
1862 pti
= GetW32ThreadInfo();
1863 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1865 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1866 return NULL
; // There is nothing to cleanup.
1868 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1869 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1874 /* Get the class and reference it */
1875 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
);
1878 ERR("Failed to find class %wZ\n", ClassName
);
1882 /* Now find the parent and the owner window */
1883 hWndParent
= IntGetDesktopWindow();
1886 if (Cs
->hwndParent
== HWND_MESSAGE
)
1888 Cs
->hwndParent
= hWndParent
= IntGetMessageWindow();
1890 else if (Cs
->hwndParent
)
1892 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1893 hWndOwner
= Cs
->hwndParent
;
1895 hWndParent
= Cs
->hwndParent
;
1897 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1899 ERR("Cannot create a child window without a parrent!\n");
1900 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1901 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1904 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1905 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1907 /* FIXME: Is this correct? */
1909 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
1911 /* Fix the position and the size of the window */
1914 UserRefObjectCo(ParentWindow
, &ParentRef
);
1915 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
1918 /* Allocate and initialize the new window */
1919 Window
= IntCreateWindow(Cs
,
1927 ERR("IntCreateWindow failed!\n");
1931 hWnd
= UserHMGetHandle(Window
);
1932 hwndInsertAfter
= HWND_TOP
;
1934 UserRefObjectCo(Window
, &Ref
);
1935 UserDereferenceObject(Window
);
1936 ObDereferenceObject(WinSta
);
1938 //// Check for a hook to eliminate overhead. ////
1939 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
1941 // Allocate the calling structures Justin Case this goes Global.
1942 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
1943 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
1944 if (!pCsw
|| !pCbtCreate
)
1946 ERR("UserHeapAlloc() failed!\n");
1950 /* Fill the new CREATESTRUCTW */
1951 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
1952 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
1954 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
1955 if (!IS_ATOM(ClassName
->Buffer
))
1957 if (Window
->state
& WNDS_ANSICREATOR
)
1959 ANSI_STRING AnsiString
;
1960 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
1961 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
1964 ERR("UserHeapAlloc() failed!\n");
1967 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
1968 AnsiString
.Buffer
= (PCHAR
)pszClass
;
1969 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
1973 UNICODE_STRING UnicodeString
;
1974 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
1975 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
1978 ERR("UserHeapAlloc() failed!\n");
1981 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
1982 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
1983 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
1985 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
1987 if (WindowName
->Length
)
1989 UNICODE_STRING Name
;
1990 Name
.Buffer
= WindowName
->Buffer
;
1991 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
1992 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
1994 if (Window
->state
& WNDS_ANSICREATOR
)
1996 ANSI_STRING AnsiString
;
1997 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
1998 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2001 ERR("UserHeapAlloc() failed!\n");
2004 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2005 AnsiString
.Buffer
= (PCHAR
)pszName
;
2006 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2010 UNICODE_STRING UnicodeString
;
2011 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2012 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2015 ERR("UserHeapAlloc() failed!\n");
2018 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2019 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2020 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2022 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2025 pCbtCreate
->lpcs
= pCsw
;
2026 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2028 //// Call the WH_CBT hook ////
2029 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2032 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2035 // Write back changes.
2040 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2043 /* NCCREATE and WM_NCCALCSIZE need the original values */
2044 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2045 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2047 /* Send the WM_GETMINMAXINFO message */
2051 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2053 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
2055 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2056 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2057 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2058 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2059 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2062 Window
->rcWindow
.left
= Cs
->x
;
2063 Window
->rcWindow
.top
= Cs
->y
;
2064 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2065 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2066 if (0 != (Window
->style
& WS_CHILD
) && ParentWindow
)
2068 // ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2069 RECTL_vOffsetRect(&Window
->rcWindow
,
2070 ParentWindow
->rcClient
.left
,
2071 ParentWindow
->rcClient
.top
);
2073 Window
->rcClient
= Window
->rcWindow
;
2075 /* Link the window */
2076 if (NULL
!= ParentWindow
)
2078 /* Link the window into the siblings list */
2079 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2080 IntLinkHwnd(Window
, HWND_BOTTOM
);
2082 IntLinkHwnd(Window
, hwndInsertAfter
);
2085 /* Send the NCCREATE message */
2086 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2089 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2093 /* Send the WM_NCCALCSIZE message */
2094 MaxPos
.x
= Window
->rcWindow
.left
;
2095 MaxPos
.y
= Window
->rcWindow
.top
;
2097 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2099 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2100 MaxPos
.y
- Window
->rcWindow
.top
);
2103 /* Send the WM_CREATE message. */
2104 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2105 if (Result
== (LRESULT
)-1)
2107 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2111 /* Send the EVENT_OBJECT_CREATE event */
2112 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2114 /* By setting the flag below it can be examined to determine if the window
2115 was created successfully and a valid pwnd was passed back to caller since
2116 from here the function has to succeed. */
2117 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2119 /* Send the WM_SIZE and WM_MOVE messages. */
2120 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2122 co_WinPosSendSizeMove(Window
);
2125 /* Show or maybe minimize or maximize the window. */
2127 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2128 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2131 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2133 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2134 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2135 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2136 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2137 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2140 /* Send the WM_PARENTNOTIFY message */
2141 IntSendParentNotify(Window
, WM_CREATE
);
2143 /* Notify the shell that a new window was created */
2144 if ((!hWndParent
) && (!hWndOwner
))
2146 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (LPARAM
)hWnd
);
2149 /* Initialize and show the window's scrollbars */
2150 if (Window
->style
& WS_VSCROLL
)
2152 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2154 if (Window
->style
& WS_HSCROLL
)
2156 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2159 /* Show the new window */
2160 if (Cs
->style
& WS_VISIBLE
)
2162 if (Window
->style
& WS_MAXIMIZE
)
2163 dwShowMode
= SW_SHOW
;
2164 else if (Window
->style
& WS_MINIMIZE
)
2165 dwShowMode
= SW_SHOWMINIMIZED
;
2167 co_WinPosShowWindow(Window
, dwShowMode
);
2169 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2171 ASSERT(ParentWindow
);
2174 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2175 /* ShowWindow won't activate child windows */
2176 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2180 TRACE("co_UserCreateWindowEx(): Created window %X\n", hWnd
);
2186 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2187 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2189 co_UserDestroyWindow(Window
);
2191 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2194 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2195 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2196 if (pszName
) UserHeapFree(pszName
);
2197 if (pszClass
) UserHeapFree(pszClass
);
2201 UserDerefObjectCo(Window
);
2203 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2210 ProbeAndCaptureLargeString(
2211 OUT PLARGE_STRING plstrSafe
,
2212 IN PLARGE_STRING plstrUnsafe
)
2214 LARGE_STRING lstrTemp
;
2215 PVOID pvBuffer
= NULL
;
2219 /* Probe and copy the string */
2220 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2221 lstrTemp
= *plstrUnsafe
;
2223 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2226 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2230 if (lstrTemp
.Length
!= 0)
2232 /* Allocate a buffer from paged pool */
2233 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2236 return STATUS_NO_MEMORY
;
2241 /* Probe and copy the buffer */
2242 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2243 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2245 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2247 /* Cleanup and fail */
2248 ExFreePool(pvBuffer
);
2249 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2254 /* Set the output string */
2255 plstrSafe
->Buffer
= pvBuffer
;
2256 plstrSafe
->Length
= lstrTemp
.Length
;
2257 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2259 return STATUS_SUCCESS
;
2263 * \todo Allow passing plstrClassName as ANSI.
2267 NtUserCreateWindowEx(
2269 PLARGE_STRING plstrClassName
,
2270 PLARGE_STRING plstrClsVersion
,
2271 PLARGE_STRING plstrWindowName
,
2279 HINSTANCE hInstance
,
2285 LARGE_STRING lstrWindowName
;
2286 LARGE_STRING lstrClassName
;
2287 UNICODE_STRING ustrClassName
;
2292 lstrWindowName
.Buffer
= NULL
;
2293 lstrClassName
.Buffer
= NULL
;
2295 ASSERT(plstrWindowName
);
2297 /* Copy the window name to kernel mode */
2298 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2299 if (!NT_SUCCESS(Status
))
2301 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2302 SetLastNtError(Status
);
2306 plstrWindowName
= &lstrWindowName
;
2308 /* Check if the class is an atom */
2309 if (IS_ATOM(plstrClassName
))
2311 /* It is, pass the atom in the UNICODE_STRING */
2312 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2313 ustrClassName
.Length
= 0;
2314 ustrClassName
.MaximumLength
= 0;
2318 /* It's not, capture the class name */
2319 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2320 if (!NT_SUCCESS(Status
))
2322 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2323 /* Set last error, cleanup and return */
2324 SetLastNtError(Status
);
2328 /* We pass it on as a UNICODE_STRING */
2329 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2330 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2331 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2334 /* Fill the CREATESTRUCTW */
2335 /* we will keep here the original parameters */
2337 Cs
.lpCreateParams
= lpParam
;
2338 Cs
.hInstance
= hInstance
;
2340 Cs
.hwndParent
= hWndParent
;
2345 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2346 if (IS_ATOM(plstrClassName
))
2347 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2349 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2350 Cs
.dwExStyle
= dwExStyle
;
2352 UserEnterExclusive();
2354 /* Call the internal function */
2355 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
);
2359 ERR("co_UserCreateWindowEx failed!\n");
2361 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2366 if (lstrWindowName
.Buffer
)
2368 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2370 if (lstrClassName
.Buffer
)
2372 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2379 BOOLEAN FASTCALL
co_UserDestroyWindow(PWND Window
)
2385 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2387 hWnd
= Window
->head
.h
;
2388 ti
= PsGetCurrentThreadWin32Thread();
2390 TRACE("co_UserDestroyWindow \n");
2392 /* Check for owner thread */
2393 if ( (Window
->head
.pti
->pEThread
!= PsGetCurrentThread()) ||
2394 Window
->head
.pti
!= PsGetCurrentThreadWin32Thread() )
2396 EngSetLastError(ERROR_ACCESS_DENIED
);
2400 /* If window was created successfully and it is hooked */
2401 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2403 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2405 ERR("Destroy Window WH_CBT Call Hook return!\n");
2410 /* Inform the parent */
2411 if (Window
->style
& WS_CHILD
)
2413 IntSendParentNotify(Window
, WM_DESTROY
);
2416 /* Look whether the focus is within the tree of windows we will
2419 if (!co_WinPosShowWindow(Window
, SW_HIDE
))
2421 if (ti
->MessageQueue
->spwndActive
== Window
&& ti
->MessageQueue
== IntGetFocusMessageQueue())
2422 { //ERR("DestroyWindow AOW\n");
2423 co_WinPosActivateOtherWindow(Window
);
2427 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2428 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2429 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2430 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2431 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2432 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2433 if (Window
->head
.pti
->MessageQueue
->CaptureWindow
== Window
->head
.h
)
2434 Window
->head
.pti
->MessageQueue
->CaptureWindow
= NULL
;
2437 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2440 if ((ti
!= NULL
) & (ti
->pDeskInfo
!= NULL
))
2442 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2444 ERR("Destroying the ShellWindow!\n");
2445 ti
->pDeskInfo
->hShellWindow
= NULL
;
2449 IntEngWindowChanged(Window
, WOC_DELETE
);
2451 if (!IntIsWindow(Window
->head
.h
))
2456 /* Recursively destroy owned windows */
2458 if (! (Window
->style
& WS_CHILD
))
2462 BOOL GotOne
= FALSE
;
2465 PWND Child
, Desktop
;
2467 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2468 UserGetWindowObject(IntGetDesktopWindow());
2469 Children
= IntWinListChildren(Desktop
);
2473 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2475 Child
= UserGetWindowObject(*ChildHandle
);
2478 if (Child
->spwndOwner
!= Window
)
2483 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2485 USER_REFERENCE_ENTRY ChildRef
;
2486 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2487 co_UserDestroyWindow(Child
);
2488 UserDerefObjectCo(Child
); // Temp HACK?
2494 if (Child
->spwndOwner
!= NULL
)
2496 Child
->spwndOwner
= NULL
;
2500 ExFreePool(Children
);
2509 /* Generate mouse move message for the next window */
2510 msg
.message
= WM_MOUSEMOVE
;
2511 msg
.wParam
= UserGetMouseButtonsState();
2512 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2513 msg
.pt
= gpsi
->ptCursor
;
2514 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2516 if (!IntIsWindow(Window
->head
.h
))
2521 /* Destroy the window storage */
2522 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2532 NtUserDestroyWindow(HWND Wnd
)
2535 DECLARE_RETURN(BOOLEAN
);
2537 USER_REFERENCE_ENTRY Ref
;
2539 TRACE("Enter NtUserDestroyWindow\n");
2540 UserEnterExclusive();
2542 if (!(Window
= UserGetWindowObject(Wnd
)))
2547 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2548 ret
= co_UserDestroyWindow(Window
);
2549 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2554 TRACE("Leave NtUserDestroyWindow, ret=%i\n",_ret_
);
2560 static HWND FASTCALL
2561 IntFindWindow(PWND Parent
,
2564 PUNICODE_STRING WindowName
)
2566 BOOL CheckWindowName
;
2569 UNICODE_STRING CurrentWindowName
;
2573 CheckWindowName
= WindowName
->Buffer
!= 0;
2575 if((List
= IntWinListChildren(Parent
)))
2580 /* skip handles before and including ChildAfter */
2581 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2585 /* search children */
2589 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2594 /* Do not send WM_GETTEXT messages in the kernel mode version!
2595 The user mode version however calls GetWindowText() which will
2596 send WM_GETTEXT messages to windows belonging to its processes */
2597 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2599 // FIXME: LARGE_STRING truncated
2600 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2601 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2602 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2603 if(!CheckWindowName
||
2604 (Child
->strName
.Length
< 0xFFFF &&
2605 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2607 Ret
= Child
->head
.h
;
2620 * Searches a window's children for a window with the specified
2623 * hwndParent = The window whose childs are to be searched.
2625 * HWND_MESSAGE = message-only windows
2627 * hwndChildAfter = Search starts after this child window.
2628 * NULL = start from beginning
2630 * ucClassName = Class name to search for
2631 * Reguired parameter.
2633 * ucWindowName = Window name
2634 * ->Buffer == NULL = don't care
2637 * The HWND of the window if it was found, otherwise NULL
2643 NtUserFindWindowEx(HWND hwndParent
,
2644 HWND hwndChildAfter
,
2645 PUNICODE_STRING ucClassName
,
2646 PUNICODE_STRING ucWindowName
,
2649 PWND Parent
, ChildAfter
;
2650 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2651 HWND Desktop
, Ret
= NULL
;
2652 BOOL DoMessageWnd
= FALSE
;
2653 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2654 DECLARE_RETURN(HWND
);
2656 TRACE("Enter NtUserFindWindowEx\n");
2659 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2663 if (ucClassName
!= NULL
)
2665 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2666 if (ClassName
.Length
!= 0)
2668 ProbeForRead(ClassName
.Buffer
,
2672 else if (!IS_ATOM(ClassName
.Buffer
))
2674 EngSetLastError(ERROR_INVALID_PARAMETER
);
2678 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2685 if (ucWindowName
!= NULL
)
2687 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2688 if (WindowName
.Length
!= 0)
2690 ProbeForRead(WindowName
.Buffer
,
2696 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2698 SetLastNtError(_SEH2_GetExceptionCode());
2699 _SEH2_YIELD(RETURN(NULL
));
2703 if (ucClassName
!= NULL
)
2705 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2706 !IS_ATOM(ClassName
.Buffer
))
2708 EngSetLastError(ERROR_INVALID_PARAMETER
);
2711 else if (ClassAtom
== (RTL_ATOM
)0)
2713 /* LastError code was set by IntGetAtomFromStringOrAtom */
2719 Desktop
= IntGetCurrentThreadDesktopWindow();
2721 if(hwndParent
== NULL
)
2723 hwndParent
= Desktop
;
2724 DoMessageWnd
= TRUE
;
2726 else if(hwndParent
== HWND_MESSAGE
)
2728 hwndParent
= IntGetMessageWindow();
2731 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2737 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2744 if(Parent
->head
.h
== Desktop
)
2747 PWND TopLevelWindow
;
2748 BOOLEAN CheckWindowName
;
2749 BOOLEAN WindowMatches
;
2750 BOOLEAN ClassMatches
;
2752 /* windows searches through all top-level windows if the parent is the desktop
2755 if((List
= IntWinListChildren(Parent
)))
2761 /* skip handles before and including ChildAfter */
2762 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2766 CheckWindowName
= WindowName
.Buffer
!= 0;
2768 /* search children */
2771 UNICODE_STRING ustr
;
2773 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2778 /* Do not send WM_GETTEXT messages in the kernel mode version!
2779 The user mode version however calls GetWindowText() which will
2780 send WM_GETTEXT messages to windows belonging to its processes */
2781 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2782 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
2783 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
2784 WindowMatches
= !CheckWindowName
||
2785 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2786 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2787 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2788 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2790 if (WindowMatches
&& ClassMatches
)
2792 Ret
= TopLevelWindow
->head
.h
;
2796 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2798 /* window returns the handle of the top-level window, in case it found
2800 Ret
= TopLevelWindow
->head
.h
;
2810 ERR("FindWindowEx: Not Desktop Parent!\n");
2811 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2814 if (Ret
== NULL
&& DoMessageWnd
)
2818 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2820 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2824 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2826 SetLastNtError(_SEH2_GetExceptionCode());
2834 TRACE("Leave NtUserFindWindowEx, ret %i\n",_ret_
);
2843 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
2845 PWND WndAncestor
, Parent
;
2847 if (Wnd
->head
.h
== IntGetDesktopWindow())
2856 WndAncestor
= Wnd
->spwndParent
;
2867 if(!(Parent
= WndAncestor
->spwndParent
))
2871 if(IntIsDesktopWindow(Parent
))
2876 WndAncestor
= Parent
;
2889 Parent
= IntGetParent(WndAncestor
);
2896 WndAncestor
= Parent
;
2914 NtUserGetAncestor(HWND hWnd
, UINT Type
)
2916 PWND Window
, Ancestor
;
2917 DECLARE_RETURN(HWND
);
2919 TRACE("Enter NtUserGetAncestor\n");
2920 UserEnterExclusive();
2922 if (!(Window
= UserGetWindowObject(hWnd
)))
2927 Ancestor
= UserGetAncestor(Window
, Type
);
2928 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
2930 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
2933 TRACE("Leave NtUserGetAncestor, ret=%i\n",_ret_
);
2941 NtUserGetComboBoxInfo(
2946 DECLARE_RETURN(BOOL
);
2948 TRACE("Enter NtUserGetComboBoxInfo\n");
2951 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2960 sizeof(COMBOBOXINFO
),
2964 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2966 SetLastNtError(_SEH2_GetExceptionCode());
2967 _SEH2_YIELD(RETURN(FALSE
));
2971 // Pass the user pointer, it was already probed.
2972 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
2975 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
2983 NtUserGetListBoxInfo(
2987 DECLARE_RETURN(DWORD
);
2989 TRACE("Enter NtUserGetListBoxInfo\n");
2992 if (!(Wnd
= UserGetWindowObject(hWnd
)))
2997 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3000 TRACE("Leave NtUserGetListBoxInfo, ret=%i\n",_ret_
);
3008 * The NtUserSetParent function changes the parent window of the specified
3012 * The new parent window and the child window must belong to the same
3013 * application. If the window identified by the hWndChild parameter is
3014 * visible, the system performs the appropriate redrawing and repainting.
3015 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3016 * or WS_POPUP window styles of the window whose parent is being changed.
3023 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3025 DECLARE_RETURN(HWND
);
3027 TRACE("Enter NtUserSetParent\n");
3028 UserEnterExclusive();
3031 Check Parent first from user space, set it here.
3035 hWndNewParent
= IntGetDesktopWindow();
3037 else if (hWndNewParent
== HWND_MESSAGE
)
3039 hWndNewParent
= IntGetMessageWindow();
3042 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3045 TRACE("Leave NtUserSetParent, ret=%i\n",_ret_
);
3051 * UserGetShellWindow
3053 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3058 HWND FASTCALL
UserGetShellWindow(VOID
)
3060 PWINSTATION_OBJECT WinStaObject
;
3063 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3068 if (!NT_SUCCESS(Status
))
3070 SetLastNtError(Status
);
3074 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3076 ObDereferenceObject(WinStaObject
);
3081 * NtUserSetShellWindowEx
3083 * This is undocumented function to set global shell window. The global
3084 * shell window has special handling of window position.
3090 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3092 PWINSTATION_OBJECT WinStaObject
;
3093 PWND WndShell
, WndListView
;
3094 DECLARE_RETURN(BOOL
);
3095 USER_REFERENCE_ENTRY Ref
;
3099 TRACE("Enter NtUserSetShellWindowEx\n");
3100 UserEnterExclusive();
3102 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3107 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3112 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3117 if (!NT_SUCCESS(Status
))
3119 SetLastNtError(Status
);
3124 * Test if we are permitted to change the shell window.
3126 if (WinStaObject
->ShellWindow
)
3128 ObDereferenceObject(WinStaObject
);
3133 * Move shell window into background.
3135 if (hwndListView
&& hwndListView
!= hwndShell
)
3138 * Disabled for now to get Explorer working.
3139 * -- Filip, 01/nov/2003
3142 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3145 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3147 ObDereferenceObject(WinStaObject
);
3152 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3154 ObDereferenceObject(WinStaObject
);
3158 UserRefObjectCo(WndShell
, &Ref
);
3159 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3161 WinStaObject
->ShellWindow
= hwndShell
;
3162 WinStaObject
->ShellListView
= hwndListView
;
3164 ti
= GetW32ThreadInfo();
3167 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3168 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3171 UserDerefObjectCo(WndShell
);
3173 ObDereferenceObject(WinStaObject
);
3177 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3183 * NtUserGetSystemMenu
3185 * The NtUserGetSystemMenu function allows the application to access the
3186 * window menu (also known as the system menu or the control menu) for
3187 * copying and modifying.
3191 * Handle to the window that will own a copy of the window menu.
3193 * Specifies the action to be taken. If this parameter is FALSE,
3194 * NtUserGetSystemMenu returns a handle to the copy of the window menu
3195 * currently in use. The copy is initially identical to the window menu
3196 * but it can be modified.
3197 * If this parameter is TRUE, GetSystemMenu resets the window menu back
3198 * to the default state. The previous window menu, if any, is destroyed.
3201 * If the bRevert parameter is FALSE, the return value is a handle to a
3202 * copy of the window menu. If the bRevert parameter is TRUE, the return
3210 NtUserGetSystemMenu(HWND hWnd
, BOOL bRevert
)
3214 DECLARE_RETURN(HMENU
);
3216 TRACE("Enter NtUserGetSystemMenu\n");
3219 if (!(Window
= UserGetWindowObject(hWnd
)))
3224 if (!(Menu
= IntGetSystemMenu(Window
, bRevert
, FALSE
)))
3229 RETURN(Menu
->MenuInfo
.Self
);
3232 TRACE("Leave NtUserGetSystemMenu, ret=%i\n",_ret_
);
3238 * NtUserSetSystemMenu
3245 NtUserSetSystemMenu(HWND hWnd
, HMENU hMenu
)
3247 BOOL Result
= FALSE
;
3250 DECLARE_RETURN(BOOL
);
3252 TRACE("Enter NtUserSetSystemMenu\n");
3253 UserEnterExclusive();
3255 if (!(Window
= UserGetWindowObject(hWnd
)))
3263 * Assign new menu handle.
3265 if (!(Menu
= UserGetMenuObject(hMenu
)))
3270 Result
= IntSetSystemMenu(Window
, Menu
);
3276 TRACE("Leave NtUserSetSystemMenu, ret=%i\n",_ret_
);
3281 // Fixes wine Win test_window_styles and todo tests...
3282 static BOOL FASTCALL
3283 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3285 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3287 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3294 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3296 PWND Window
, Parent
;
3297 PWINSTATION_OBJECT WindowStation
;
3301 if (hWnd
== IntGetDesktopWindow())
3303 EngSetLastError(STATUS_ACCESS_DENIED
);
3307 if (!(Window
= UserGetWindowObject(hWnd
)))
3312 if ((INT
)Index
>= 0)
3314 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3316 EngSetLastError(ERROR_INVALID_INDEX
);
3320 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3322 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3324 OldValue = (LONG)IntSetWindowProc( Wnd,
3327 if (!OldValue) return 0;
3330 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3337 OldValue
= (LONG
) Window
->ExStyle
;
3338 Style
.styleOld
= OldValue
;
3339 Style
.styleNew
= NewValue
;
3341 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3344 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3346 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3349 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3350 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3352 /* WS_EX_WINDOWEDGE depends on some other styles */
3353 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3354 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3356 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3358 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3359 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3363 OldValue
= (LONG
) Window
->style
;
3364 Style
.styleOld
= OldValue
;
3365 Style
.styleNew
= NewValue
;
3366 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3368 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3369 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3370 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3371 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3372 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3374 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3376 Window
->style
= (DWORD
)Style
.styleNew
;
3377 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3382 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3383 Window
->fnid
& FNID_FREED
)
3385 EngSetLastError(ERROR_ACCESS_DENIED
);
3388 OldValue
= (LONG
)IntSetWindowProc(Window
,
3395 OldValue
= (LONG
) Window
->hModule
;
3396 Window
->hModule
= (HINSTANCE
) NewValue
;
3399 case GWL_HWNDPARENT
:
3400 Parent
= Window
->spwndParent
;
3401 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3402 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3404 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3408 OldValue
= (LONG
) Window
->IDMenu
;
3409 Window
->IDMenu
= (UINT
) NewValue
;
3413 OldValue
= Window
->dwUserData
;
3414 Window
->dwUserData
= NewValue
;
3418 ERR("NtUserSetWindowLong(): Unsupported index %d\n", Index
);
3419 EngSetLastError(ERROR_INVALID_INDEX
);
3429 * NtUserSetWindowLong
3431 * The NtUserSetWindowLong function changes an attribute of the specified
3432 * window. The function also sets the 32-bit (long) value at the specified
3433 * offset into the extra window memory.
3440 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3442 DECLARE_RETURN(LONG
);
3444 TRACE("Enter NtUserSetWindowLong\n");
3445 UserEnterExclusive();
3447 RETURN( co_UserSetWindowLong(hWnd
, Index
, NewValue
, Ansi
));
3450 TRACE("Leave NtUserSetWindowLong, ret=%i\n",_ret_
);
3456 * NtUserSetWindowWord
3458 * Legacy function similar to NtUserSetWindowLong.
3465 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3469 DECLARE_RETURN(WORD
);
3471 TRACE("Enter NtUserSetWindowWord\n");
3472 UserEnterExclusive();
3474 if (!(Window
= UserGetWindowObject(hWnd
)))
3483 case GWL_HWNDPARENT
:
3484 RETURN( (WORD
)co_UserSetWindowLong(Window
->head
.h
, Index
, (UINT
)NewValue
, TRUE
));
3488 EngSetLastError(ERROR_INVALID_INDEX
);
3493 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3495 EngSetLastError(ERROR_INVALID_PARAMETER
);
3499 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3500 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3505 TRACE("Leave NtUserSetWindowWord, ret=%i\n",_ret_
);
3511 QueryWindow based on KJK::Hyperion and James Tabor.
3513 0 = QWUniqueProcessId
3514 1 = QWUniqueThreadId
3517 4 = QWIsHung Implements IsHungAppWindow found
3520 9 = QWKillWindow When I called this with hWnd ==
3521 DesktopWindow, it shutdown the system
3528 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3532 DECLARE_RETURN(UINT
);
3534 TRACE("Enter NtUserQueryWindow\n");
3537 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3544 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3545 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3548 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3549 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3552 case QUERY_WINDOW_ACTIVE
:
3553 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3556 case QUERY_WINDOW_FOCUS
:
3557 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3560 case QUERY_WINDOW_ISHUNG
:
3561 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
->MessageQueue
);
3564 case QUERY_WINDOW_REAL_ID
:
3565 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3568 case QUERY_WINDOW_FOREGROUND
:
3569 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3573 Result
= (DWORD
)NULL
;
3580 TRACE("Leave NtUserQueryWindow, ret=%i\n",_ret_
);
3590 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3592 UNICODE_STRING SafeMessageName
;
3595 DECLARE_RETURN(UINT
);
3597 TRACE("Enter NtUserRegisterWindowMessage\n");
3598 UserEnterExclusive();
3600 if(MessageNameUnsafe
== NULL
)
3602 EngSetLastError(ERROR_INVALID_PARAMETER
);
3606 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3607 if(!NT_SUCCESS(Status
))
3609 SetLastNtError(Status
);
3613 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3614 if (SafeMessageName
.Buffer
)
3615 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3619 TRACE("Leave NtUserRegisterWindowMessage, ret=%i\n",_ret_
);
3636 DECLARE_RETURN(BOOL
);
3638 TRACE("Enter NtUserSetMenu\n");
3639 UserEnterExclusive();
3641 if (!(Window
= UserGetWindowObject(hWnd
)))
3646 if (! IntSetMenu(Window
, Menu
, &Changed
))
3651 if (Changed
&& Repaint
)
3653 USER_REFERENCE_ENTRY Ref
;
3655 UserRefObjectCo(Window
, &Ref
);
3656 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3657 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3659 UserDerefObjectCo(Window
);
3665 TRACE("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3674 NtUserSetWindowFNID(HWND hWnd
,
3678 DECLARE_RETURN(BOOL
);
3680 TRACE("Enter NtUserSetWindowFNID\n");
3681 UserEnterExclusive();
3683 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3688 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3690 EngSetLastError(ERROR_ACCESS_DENIED
);
3694 // From user land we only set these.
3695 if (fnID
!= FNID_DESTROY
)
3696 { // Hacked so we can mark desktop~!
3697 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
3700 EngSetLastError(ERROR_INVALID_PARAMETER
);
3709 TRACE("Leave NtUserSetWindowFNID\n");
3717 * Undocumented function that is called from DefWindowProc to set
3724 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
3727 LARGE_STRING SafeText
;
3728 UNICODE_STRING UnicodeString
;
3731 TRACE("Enter NtUserDefSetText\n");
3733 if (WindowText
!= NULL
)
3737 SafeText
= ProbeForReadLargeString(WindowText
);
3739 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3742 SetLastNtError(_SEH2_GetExceptionCode());
3752 UserEnterExclusive();
3754 if(!(Wnd
= UserGetWindowObject(hWnd
)))
3760 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
3761 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
3762 // Now we know what the bAnsi is for.
3763 RtlInitUnicodeString(&UnicodeString
, NULL
);
3764 if (SafeText
.Buffer
)
3769 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
3771 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
3772 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
3774 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3777 SetLastNtError(_SEH2_GetExceptionCode());
3780 if (!Ret
) goto Exit
;
3783 if (UnicodeString
.Length
!= 0)
3785 if (Wnd
->strName
.MaximumLength
> 0 &&
3786 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
3788 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
3790 Wnd
->strName
.Length
= UnicodeString
.Length
;
3791 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
3792 RtlCopyMemory(Wnd
->strName
.Buffer
,
3793 UnicodeString
.Buffer
,
3794 UnicodeString
.Length
);
3799 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
3800 buf
= Wnd
->strName
.Buffer
;
3801 Wnd
->strName
.Buffer
= NULL
;
3804 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
3807 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
3808 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
3809 if (Wnd
->strName
.Buffer
!= NULL
)
3811 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
3812 RtlCopyMemory(Wnd
->strName
.Buffer
,
3813 UnicodeString
.Buffer
,
3814 UnicodeString
.Length
);
3815 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
3816 Wnd
->strName
.Length
= UnicodeString
.Length
;
3820 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3828 Wnd
->strName
.Length
= 0;
3829 if (Wnd
->strName
.Buffer
!= NULL
)
3830 Wnd
->strName
.Buffer
[0] = L
'\0';
3833 // FIXME: HAX! Windows does not do this in here!
3834 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
3835 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
3836 /* Send shell notifications */
3837 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
3839 co_IntShellHookNotify(HSHELL_REDRAW
, (LPARAM
) hWnd
);
3844 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
3845 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
3851 * NtUserInternalGetWindowText
3858 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
3863 DECLARE_RETURN(INT
);
3865 TRACE("Enter NtUserInternalGetWindowText\n");
3868 if(lpString
&& (nMaxCount
<= 1))
3870 EngSetLastError(ERROR_INVALID_PARAMETER
);
3874 if(!(Wnd
= UserGetWindowObject(hWnd
)))
3879 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
3882 const WCHAR Terminator
= L
'\0';
3884 WCHAR
*Buffer
= (WCHAR
*)lpString
;
3886 Copy
= min(nMaxCount
- 1, Result
);
3889 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
3890 if(!NT_SUCCESS(Status
))
3892 SetLastNtError(Status
);
3898 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
3899 if(!NT_SUCCESS(Status
))
3901 SetLastNtError(Status
);
3911 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
3919 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
3925 // ASSERT(OwnerWnd);
3927 win_array
= IntWinListChildren(UserGetWindowObject(IntGetDesktopWindow()));
3932 while (win_array
[count
])
3934 while (--count
>= 0)
3936 if (!(pWnd
= UserGetWindowObject( win_array
[count
] )))
3938 if (pWnd
->spwndOwner
!= OwnerWnd
)
3943 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
3945 /* In Windows, ShowOwnedPopups(TRUE) generates
3946 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
3947 * regardless of the state of the owner
3949 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
3955 if (pWnd
->style
& WS_VISIBLE
)
3957 /* In Windows, ShowOwnedPopups(FALSE) generates
3958 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
3959 * regardless of the state of the owner
3961 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
3967 ExFreePool( win_array
);