2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
5 * FILE: win32ss/user/ntuser/window.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
10 DBG_DEFAULT_CHANNEL(UserWnd
);
12 INT gNestedWindowLimit
= 50;
14 /* HELPER FUNCTIONS ***********************************************************/
16 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
18 WORD Action
= LOWORD(wParam
);
19 WORD Flags
= HIWORD(wParam
);
21 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
23 EngSetLastError(ERROR_INVALID_PARAMETER
);
30 EngSetLastError(ERROR_INVALID_PARAMETER
);
34 if (Flags
& UISF_HIDEFOCUS
)
35 Wnd
->HideFocus
= TRUE
;
36 if (Flags
& UISF_HIDEACCEL
)
37 Wnd
->HideAccel
= TRUE
;
41 if (Flags
& UISF_HIDEFOCUS
)
42 Wnd
->HideFocus
= FALSE
;
43 if (Flags
& UISF_HIDEACCEL
)
44 Wnd
->HideAccel
= FALSE
;
51 PWND FASTCALL
IntGetWindowObject(HWND hWnd
)
55 if (!hWnd
) return NULL
;
57 Window
= UserGetWindowObject(hWnd
);
59 Window
->head
.cLockObj
++;
64 PWND FASTCALL
VerifyWnd(PWND pWnd
)
70 if (!pWnd
) return NULL
;
72 Error
= EngGetLastError();
76 hWnd
= UserHMGetHandle(pWnd
);
78 State2
= pWnd
->state2
;
80 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
82 EngSetLastError(Error
);
83 _SEH2_YIELD(return NULL
);
87 if ( UserObjectInDestroy(hWnd
) ||
88 State
& WNDS_DESTROYED
||
89 State2
& WNDS2_INDESTROY
)
92 EngSetLastError(Error
);
96 PWND FASTCALL
ValidateHwndNoErr(HWND hWnd
)
98 if (hWnd
) return (PWND
)UserGetObjectNoErr(gHandleTable
, hWnd
, TYPE_WINDOW
);
103 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
109 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
113 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, TYPE_WINDOW
);
114 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
116 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
124 IntSetStyle( PWND pwnd
, ULONG set_bits
, ULONG clear_bits
)
126 ULONG styleOld
, styleNew
;
127 styleOld
= pwnd
->style
;
128 styleNew
= (pwnd
->style
| set_bits
) & ~clear_bits
;
129 if (styleNew
== styleOld
) return styleNew
;
130 pwnd
->style
= styleNew
;
131 if ((styleOld
^ styleNew
) & WS_VISIBLE
) // State Change.
133 if (styleOld
& WS_VISIBLE
) pwnd
->head
.pti
->cVisWindows
--;
134 if (styleNew
& WS_VISIBLE
) pwnd
->head
.pti
->cVisWindows
++;
135 DceResetActiveDCEs( pwnd
);
143 * The function determines whether the specified window handle identifies
144 * an existing window.
148 * Handle to the window to test.
151 * If the window handle identifies an existing window, the return value
152 * is TRUE. If the window handle does not identify an existing window,
153 * the return value is FALSE.
157 IntIsWindow(HWND hWnd
)
161 if (!(Window
= UserGetWindowObject(hWnd
)))
170 IntIsWindowVisible(PWND Wnd
)
175 if (!Temp
) return TRUE
;
176 if (!(Temp
->style
& WS_VISIBLE
)) break;
177 if (Temp
->style
& WS_MINIMIZE
&& Temp
!= Wnd
) break;
178 if (Temp
->fnid
== FNID_DESKTOP
) return TRUE
;
179 Temp
= Temp
->spwndParent
;
185 IntGetParent(PWND Wnd
)
187 if (Wnd
->style
& WS_POPUP
)
189 return Wnd
->spwndOwner
;
191 else if (Wnd
->style
& WS_CHILD
)
193 return Wnd
->spwndParent
;
201 IntEnableWindow( HWND hWnd
, BOOL bEnable
)
207 if(!(pWnd
= UserGetWindowObject(hWnd
)))
212 /* check if updating is needed */
213 bIsDisabled
= !!(pWnd
->style
& WS_DISABLED
);
214 Update
= bIsDisabled
;
218 IntSetStyle( pWnd
, 0, WS_DISABLED
);
222 Update
= !bIsDisabled
;
224 co_IntSendMessage( hWnd
, WM_CANCELMODE
, 0, 0);
226 /* Remove keyboard focus from that window if it had focus */
227 if (hWnd
== IntGetThreadFocusWindow())
229 TRACE("IntEnableWindow SF NULL\n");
230 co_UserSetFocus(NULL
);
232 IntSetStyle( pWnd
, WS_DISABLED
, 0 );
237 IntNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, pWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
238 co_IntSendMessage(hWnd
, WM_ENABLE
, (LPARAM
)bEnable
, 0);
240 // Return nonzero if it was disabled, or zero if it wasn't:
247 * Compile a list of all child window handles from given window.
250 * This function is similar to Wine WIN_ListChildren. The caller
251 * must free the returned list with ExFreePool.
255 IntWinListChildren(PWND Window
)
259 UINT Index
, NumChildren
= 0;
261 if (!Window
) return NULL
;
263 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
268 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
271 ERR("Failed to allocate memory for children array\n");
272 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
277 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
279 List
[Index
++] = Child
->head
.h
;
287 IntWinListOwnedPopups(PWND Window
)
291 UINT Index
, NumChildren
= 0;
293 Desktop
= co_GetDesktopWindow(Window
);
297 for (Child
= Desktop
->spwndChild
; Child
; Child
= Child
->spwndNext
)
300 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
303 ERR("Failed to allocate memory for children array\n");
304 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
309 for (Child
= Desktop
->spwndChild
; Child
; Child
= Child
->spwndNext
)
311 if (Child
->spwndOwner
== Window
)
312 List
[Index
++] = Child
->head
.h
;
320 IntGetNonChildAncestor(PWND pWnd
)
322 while(pWnd
&& (pWnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
323 pWnd
= pWnd
->spwndParent
;
328 IntIsTopLevelWindow(PWND pWnd
)
330 if ( pWnd
->spwndParent
&&
331 pWnd
->spwndParent
== co_GetDesktopWindow(pWnd
) ) return TRUE
;
336 IntValidateOwnerDepth(PWND Wnd
, PWND Owner
)
341 if ( !Owner
) return gNestedWindowLimit
>= Depth
;
342 if (Owner
== Wnd
) break;
343 Owner
= Owner
->spwndOwner
;
350 IntGetWindow(HWND hWnd
,
356 Wnd
= ValidateHwndNoErr(hWnd
);
364 if (Wnd
->spwndOwner
!= NULL
)
365 FoundWnd
= Wnd
->spwndOwner
;
369 if(Wnd
->spwndParent
!= NULL
)
371 FoundWnd
= Wnd
->spwndParent
;
372 if (FoundWnd
->spwndChild
!= NULL
)
373 FoundWnd
= FoundWnd
->spwndChild
;
377 if (Wnd
->spwndNext
!= NULL
)
378 FoundWnd
= Wnd
->spwndNext
;
382 if (Wnd
->spwndPrev
!= NULL
)
383 FoundWnd
= Wnd
->spwndPrev
;
387 if (Wnd
->spwndChild
!= NULL
)
388 FoundWnd
= Wnd
->spwndChild
;
393 while ( FoundWnd
->spwndNext
!= NULL
)
394 FoundWnd
= FoundWnd
->spwndNext
;
402 if (FoundWnd
!= NULL
)
403 Ret
= UserHMGetHandle(FoundWnd
);
407 DWORD FASTCALL
IntGetWindowContextHelpId( PWND pWnd
)
413 HelpId
= (DWORD
)(DWORD_PTR
)UserGetProp(pWnd
, gpsi
->atomContextHelpIdProp
, TRUE
);
415 pWnd
= IntGetParent(pWnd
);
417 while (pWnd
&& pWnd
->fnid
!= FNID_DESKTOP
);
424 IntRemoveTrackMouseEvent(
427 /***********************************************************************
430 static void IntSendDestroyMsg(HWND hWnd
)
435 ti
= PsGetCurrentThreadWin32Thread();
436 Window
= UserGetWindowObject(hWnd
);
441 * Look whether the focus is within the tree of windows
442 * we will be destroying.
445 if ( ti
->MessageQueue
->spwndActive
== Window
|| // Fixes CORE-106 RegSvr32 exit and return focus to CMD.
446 (ti
->MessageQueue
->spwndActive
== NULL
&& ti
->MessageQueue
== IntGetFocusMessageQueue()) )
448 co_WinPosActivateOtherWindow(Window
);
451 /* Fixes CMD properties closing and returning focus to CMD */
452 if (ti
->MessageQueue
->spwndFocus
== Window
)
454 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
456 co_UserSetFocus(Window
->spwndParent
);
460 co_UserSetFocus(NULL
);
464 if (ti
->MessageQueue
->CaretInfo
.hWnd
== UserHMGetHandle(Window
))
466 co_IntDestroyCaret(ti
);
469 /* If the window being destroyed is currently tracked... */
470 if (ti
->rpdesk
->spwndTrack
== Window
)
472 IntRemoveTrackMouseEvent(ti
->rpdesk
);
476 /* If the window being destroyed is the current clipboard owner... */
477 if (ti
->ppi
->prpwinsta
!= NULL
&& Window
== ti
->ppi
->prpwinsta
->spwndClipOwner
)
479 /* ... make it release the clipboard */
480 UserClipboardRelease(Window
);
483 /* Send the WM_DESTROY to the window */
484 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
487 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
488 * make sure that the window still exists when we come back.
490 if (IntIsWindow(hWnd
))
495 if (!(pWndArray
= IntWinListChildren( Window
))) return;
497 for (i
= 0; pWndArray
[i
]; i
++)
499 if (IntIsWindow( pWndArray
[i
] )) IntSendDestroyMsg( pWndArray
[i
] );
501 ExFreePoolWithTag(pWndArray
, USERTAG_WINDOWLIST
);
505 TRACE("destroyed itself while in WM_DESTROY!\n");
510 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
512 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
516 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
518 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
519 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
522 if (Wnd
->strName
.Buffer
!= NULL
)
524 Wnd
->strName
.Length
= 0;
525 Wnd
->strName
.MaximumLength
= 0;
526 DesktopHeapFree(Wnd
->head
.rpdesk
,
527 Wnd
->strName
.Buffer
);
528 Wnd
->strName
.Buffer
= NULL
;
531 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
532 // WindowObject->hWnd = NULL;
535 /***********************************************************************
538 * Destroy storage associated to a window. "Internals" p.358
540 * This is the "functional" DestroyWindows function i.e. all stuff
541 * done in CreateWindow is undone here and not in DestroyWindow :-P
543 LRESULT
co_UserFreeWindow(PWND Window
,
544 PPROCESSINFO ProcessData
,
545 PTHREADINFO ThreadData
,
546 BOOLEAN SendMessages
)
552 BOOLEAN BelongsToThreadData
;
556 if(Window
->state2
& WNDS2_INDESTROY
)
558 TRACE("Tried to call co_UserFreeWindow() twice\n");
561 Window
->state2
|= WNDS2_INDESTROY
;
562 Window
->style
&= ~WS_VISIBLE
;
563 Window
->head
.pti
->cVisWindows
--;
566 /* remove the window already at this point from the thread window list so we
567 don't get into trouble when destroying the thread windows while we're still
568 in co_UserFreeWindow() */
569 RemoveEntryList(&Window
->ThreadListEntry
);
571 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
573 IntDeRegisterShellHookWindow(UserHMGetHandle(Window
));
575 /* free child windows */
576 Children
= IntWinListChildren(Window
);
579 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
581 if ((Child
= IntGetWindowObject(*ChildHandle
)))
583 if (!IntWndBelongsToThread(Child
, ThreadData
))
585 /* send WM_DESTROY messages to windows not belonging to the same thread */
586 co_IntSendMessage( UserHMGetHandle(Child
), WM_ASYNC_DESTROYWINDOW
, 0, 0 );
589 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
591 UserDereferenceObject(Child
);
594 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
600 * Clear the update region to make sure no WM_PAINT messages will be
601 * generated for this window while processing the WM_NCDESTROY.
603 co_UserRedrawWindow(Window
, NULL
, 0,
604 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
605 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
606 if (BelongsToThreadData
)
607 co_IntSendMessage(UserHMGetHandle(Window
), WM_NCDESTROY
, 0, 0);
610 UserClipboardFreeWindow(Window
);
612 DestroyTimersForWindow(ThreadData
, Window
);
614 /* Unregister hot keys */
615 UnregisterWindowHotKeys(Window
);
617 /* flush the message queue */
618 MsqRemoveWindowMessagesFromQueue(Window
);
620 /* from now on no messages can be sent to this window anymore */
621 Window
->state
|= WNDS_DESTROYED
;
622 Window
->fnid
|= FNID_FREED
;
624 /* don't remove the WINDOWSTATUS_DESTROYING bit */
626 /* reset shell window handles */
627 if (ThreadData
->rpdesk
)
629 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
630 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
632 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
633 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
636 /* Fixes dialog test_focus breakage due to r66237. */
637 if (ThreadData
->MessageQueue
->spwndFocus
== Window
)
638 ThreadData
->MessageQueue
->spwndFocus
= NULL
;
640 if (ThreadData
->MessageQueue
->spwndActive
== Window
)
641 ThreadData
->MessageQueue
->spwndActive
= NULL
;
643 if (ThreadData
->MessageQueue
->spwndCapture
== Window
)
648 //// Now kill those remaining "PAINTING BUG: Thread marked as containing dirty windows" spam!!!
649 if ( Window
->hrgnUpdate
!= NULL
|| Window
->state
& WNDS_INTERNALPAINT
)
651 MsqDecPaintCountQueue(Window
->head
.pti
);
652 if (Window
->hrgnUpdate
> HRGN_WINDOW
&& GreIsHandleValid(Window
->hrgnUpdate
))
654 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
655 GreDeleteObject(Window
->hrgnUpdate
);
657 Window
->hrgnUpdate
= NULL
;
658 Window
->state
&= ~WNDS_INTERNALPAINT
;
661 if (Window
->state
& (WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
))
663 Window
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
);
666 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
668 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
670 TRACE("UFW: IDMenu %p\n",Window
->IDMenu
);
671 IntDestroyMenuObject(Menu
, TRUE
);
675 if (Window
->SystemMenu
676 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
678 IntDestroyMenuObject(Menu
, TRUE
);
679 Window
->SystemMenu
= (HMENU
)0;
682 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
684 IntUnlinkWindow(Window
);
686 if (Window
->PropListItems
)
688 UserRemoveWindowProps(Window
);
689 TRACE("Window->PropListItems %lu\n",Window
->PropListItems
);
690 ASSERT(Window
->PropListItems
==0);
693 UserReferenceObject(Window
);
694 UserMarkObjectDestroy(Window
);
696 IntDestroyScrollBars(Window
);
698 if (Window
->pcls
->atomClassName
== gaGuiConsoleWndClass
)
700 /* Count only console windows manually */
701 co_IntUserManualGuiCheck(FALSE
);
704 /* dereference the class */
705 NT_ASSERT(Window
->head
.pti
!= NULL
);
706 IntDereferenceClass(Window
->pcls
,
707 Window
->head
.pti
->pDeskInfo
,
708 Window
->head
.pti
->ppi
);
711 if (Window
->hrgnClip
)
713 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
714 GreDeleteObject(Window
->hrgnClip
);
715 Window
->hrgnClip
= NULL
;
717 Window
->head
.pti
->cWindows
--;
719 // ASSERT(Window != NULL);
720 UserFreeWindowInfo(Window
->head
.pti
, Window
);
722 UserDereferenceObject(Window
);
723 UserDeleteObject(UserHMGetHandle(Window
), TYPE_WINDOW
);
729 // Same as User32:IntGetWndProc.
732 IntGetWindowProc(PWND pWnd
,
737 WNDPROC gcpd
, Ret
= 0;
739 ASSERT(UserIsEnteredExclusive() == TRUE
);
743 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
745 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
747 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
750 Ret
= GETPFNCLIENTA(i
);
752 Ret
= GETPFNCLIENTW(i
);
758 if (Class
->fnid
== FNID_EDIT
)
759 Ret
= pWnd
->lpfnWndProc
;
762 Ret
= pWnd
->lpfnWndProc
;
764 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
768 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
769 Ret
= GETPFNCLIENTA(Class
->fnid
);
773 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
774 Ret
= GETPFNCLIENTW(Class
->fnid
);
777 if ( Ret
!= pWnd
->lpfnWndProc
)
780 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
783 gcpd
= (WNDPROC
)UserGetCPD(
785 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
788 return (gcpd
? gcpd
: Ret
);
792 IntSetWindowProc(PWND pWnd
,
797 PCALLPROCDATA CallProc
;
799 WNDPROC Ret
, chWndProc
= NULL
;
801 // Retrieve previous window proc.
802 Ret
= IntGetWindowProc(pWnd
, Ansi
);
806 if (IsCallProcHandle(NewWndProc
))
808 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
810 { // Reset new WndProc.
811 NewWndProc
= CallProc
->pfnClientPrevious
;
812 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
813 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
816 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
817 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
819 if (GETPFNCLIENTW(i
) == NewWndProc
)
821 chWndProc
= GETPFNSERVER(i
);
824 if (GETPFNCLIENTA(i
) == NewWndProc
)
826 chWndProc
= GETPFNSERVER(i
);
830 // If match, set/reset to Server Side and clear ansi.
833 pWnd
->lpfnWndProc
= chWndProc
;
834 pWnd
->Unicode
= TRUE
;
835 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
836 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
840 pWnd
->Unicode
= !Ansi
;
841 // Handle the state change in here.
843 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
845 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
847 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
848 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
850 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
852 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
856 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
857 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
861 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
862 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
865 // Now set the new window proc.
866 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
872 /* INTERNAL ******************************************************************/
875 // This fixes a check for children messages that need paint while searching the parents messages!
876 // Fixes wine msg:test_paint_messages:WmParentErasePaint ..
879 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
881 PWND Window
= BaseWindow
;
884 if ( Window
== NULL
|| (Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
887 Window
= Window
->spwndParent
;
889 while(Parent
!= Window
);
894 /* Link the window into siblings list. Children and parent are kept in place. */
898 PWND WndInsertAfter
/* Set to NULL if top sibling */
901 if (Wnd
== WndInsertAfter
)
903 ERR("IntLinkWindow -- Trying to link window 0x%p to itself!!\n", Wnd
);
907 Wnd
->spwndPrev
= WndInsertAfter
;
910 /* Link after WndInsertAfter */
911 ASSERT(Wnd
!= WndInsertAfter
->spwndNext
);
912 Wnd
->spwndNext
= WndInsertAfter
->spwndNext
;
914 Wnd
->spwndNext
->spwndPrev
= Wnd
;
916 ASSERT(Wnd
!= Wnd
->spwndPrev
);
917 Wnd
->spwndPrev
->spwndNext
= Wnd
;
921 /* Link at the top */
922 ASSERT(Wnd
!= Wnd
->spwndParent
->spwndChild
);
923 Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
;
925 Wnd
->spwndNext
->spwndPrev
= Wnd
;
927 Wnd
->spwndParent
->spwndChild
= Wnd
;
932 Note: Wnd->spwndParent can be null if it is the desktop.
934 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
936 if (hWndPrev
== HWND_NOTOPMOST
)
938 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) && (Wnd
->ExStyle2
& WS_EX2_LINKED
))
939 return; /* nothing to do */
940 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
941 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
944 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
946 if (hWndPrev
== HWND_BOTTOM
)
948 /* Link in the bottom of the list */
951 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
952 while (WndInsertAfter
&& WndInsertAfter
->spwndNext
)
954 WndInsertAfter
= WndInsertAfter
->spwndNext
;
957 IntLinkWindow(Wnd
, WndInsertAfter
);
958 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
960 else if (hWndPrev
== HWND_TOPMOST
)
962 /* Link in the top of the list */
963 IntLinkWindow(Wnd
, NULL
);
964 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
966 else if (hWndPrev
== HWND_TOP
)
968 /* Link it after the last topmost window */
969 PWND WndInsertBefore
;
971 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
973 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
975 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
977 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
))
980 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
982 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
985 WndInsertBefore
= WndInsertBefore
->spwndNext
;
989 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
993 /* Link it after hWndPrev */
996 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
997 /* Are we called with an erroneous handle */
998 if (WndInsertAfter
== NULL
)
1000 /* Link in a default position */
1001 IntLinkHwnd(Wnd
, HWND_TOP
);
1005 if (Wnd
== WndInsertAfter
)
1006 ERR("IntLinkHwnd -- Trying to link window 0x%p to itself!!\n", Wnd
);
1007 IntLinkWindow(Wnd
, WndInsertAfter
);
1009 /* Fix the WS_EX_TOPMOST flag */
1010 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1012 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1016 if (WndInsertAfter
->spwndNext
&&
1017 (WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
))
1019 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1023 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
1027 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
1031 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
1034 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
1035 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1037 //ERR("ProcessOwnerSwap Old out.\n");
1038 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
1044 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
1047 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1049 //ERR("ProcessOwnerSwap New in.\n");
1050 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1054 // FIXME: System Tray checks.
1058 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1060 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1063 Wnd
= IntGetWindowObject(hWnd
);
1067 WndOldOwner
= Wnd
->spwndOwner
;
1069 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1070 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1072 if (!WndNewOwner
&& hWndNewOwner
)
1074 EngSetLastError(ERROR_INVALID_PARAMETER
);
1079 /* if parent belongs to a different thread and the window isn't */
1080 /* top-level, attach the two threads */
1081 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1083 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1087 Wnd
->spwndOwner
= WndNewOwner
;
1091 Wnd
->spwndOwner
= NULL
;
1096 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1097 EngSetLastError(ERROR_INVALID_PARAMETER
);
1101 UserDereferenceObject(Wnd
);
1106 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1108 PWND WndOldParent
, pWndExam
;
1111 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1114 ASSERT(WndNewParent
);
1115 ASSERT_REFS_CO(Wnd
);
1116 ASSERT_REFS_CO(WndNewParent
);
1118 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1120 EngSetLastError(ERROR_ACCESS_DENIED
);
1124 /* Some applications try to set a child as a parent */
1125 if (IntIsChildWindow(Wnd
, WndNewParent
))
1127 TRACE("IntSetParent try to set a child as a parent.\n");
1128 EngSetLastError( ERROR_INVALID_PARAMETER
);
1132 pWndExam
= WndNewParent
; // Load parent Window to examine.
1133 // Now test for set parent to parent hit.
1136 if (Wnd
== pWndExam
)
1138 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1139 EngSetLastError(ERROR_INVALID_PARAMETER
);
1142 pWndExam
= pWndExam
->spwndParent
;
1146 * Windows hides the window first, then shows it again
1147 * including the WM_SHOWWINDOW messages and all
1149 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1151 /* Window must belong to current process */
1152 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1154 ERR("IntSetParent Window must belong to current process!\n");
1158 WndOldParent
= Wnd
->spwndParent
;
1160 if ( WndOldParent
&&
1161 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1162 pt
.x
= Wnd
->rcWindow
.right
;
1164 pt
.x
= Wnd
->rcWindow
.left
;
1165 pt
.y
= Wnd
->rcWindow
.top
;
1167 IntScreenToClient(WndOldParent
, &pt
);
1169 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1171 if (WndNewParent
!= WndOldParent
)
1173 /* Unlink the window from the siblings list */
1174 IntUnlinkWindow(Wnd
);
1175 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1177 /* Set the new parent */
1178 Wnd
->spwndParent
= WndNewParent
;
1180 if ( Wnd
->style
& WS_CHILD
&&
1182 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1184 ERR("SetParent Top Most from Pop up!\n");
1185 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1188 /* Link the window with its new siblings */
1190 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1191 UserIsDesktopWindow(WndNewParent
) ) ? HWND_TOP
: HWND_TOPMOST
) );
1194 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1195 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1197 Wnd
->style
|= WS_CLIPSIBLINGS
;
1198 DceResetActiveDCEs(Wnd
);
1201 /* if parent belongs to a different thread and the window isn't */
1202 /* top-level, attach the two threads */
1203 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1205 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1207 if (WndOldParent
&& (Wnd
->head
.pti
!= WndOldParent
->head
.pti
))
1209 //ERR("SetParent Old out.\n");
1210 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1213 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1215 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1217 //ERR("SetParent New in.\n");
1218 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1223 if (UserIsMessageWindow(WndOldParent
) || UserIsMessageWindow(WndNewParent
))
1224 swFlags
|= SWP_NOACTIVATE
;
1226 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1228 * SetParent additionally needs to make hwnd the top window
1229 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1230 * WM_WINDOWPOSCHANGED notification messages.
1232 //ERR("IntSetParent SetWindowPos 1\n");
1233 co_WinPosSetWindowPos( Wnd
,
1234 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1235 pt
.x
, pt
.y
, 0, 0, swFlags
);
1236 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1237 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1239 return WndOldParent
;
1243 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1245 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1246 HWND hWndOldParent
= NULL
;
1247 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1249 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1251 EngSetLastError(ERROR_INVALID_PARAMETER
);
1255 if (hWndChild
== IntGetDesktopWindow())
1257 ERR("UserSetParent Access Denied!\n");
1258 EngSetLastError(ERROR_ACCESS_DENIED
);
1264 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1266 ERR("UserSetParent Bad New Parent!\n");
1272 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1278 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1280 ERR("UserSetParent Bad Child!\n");
1284 UserRefObjectCo(Wnd
, &Ref
);
1285 UserRefObjectCo(WndParent
, &ParentRef
);
1286 //ERR("Enter co_IntSetParent\n");
1287 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1288 //ERR("Leave co_IntSetParent\n");
1289 UserDerefObjectCo(WndParent
);
1290 UserDerefObjectCo(Wnd
);
1294 hWndOldParent
= WndOldParent
->head
.h
;
1295 UserDereferenceObject(WndOldParent
);
1298 return( hWndOldParent
);
1301 /* Unlink the window from siblings. Children and parent are kept in place. */
1303 IntUnlinkWindow(PWND Wnd
)
1305 ASSERT(Wnd
!= Wnd
->spwndNext
);
1306 ASSERT(Wnd
!= Wnd
->spwndPrev
);
1309 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1312 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1314 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1315 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1317 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1320 /* FUNCTIONS *****************************************************************/
1323 * As best as I can figure, this function is used by EnumWindows,
1324 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1326 * It's supposed to build a list of HWNDs to return to the caller.
1327 * We can figure out what kind of list by what parameters are
1335 NtUserBuildHwndList(
1348 return ERROR_INVALID_PARAMETER
;
1350 if (hwndParent
|| !dwThreadId
)
1353 PWND Parent
, Window
;
1357 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1359 return ERROR_INVALID_HANDLE
;
1364 Status
= IntValidateDesktopHandle(hDesktop
,
1368 if(!NT_SUCCESS(Status
))
1370 return ERROR_INVALID_HANDLE
;
1373 hwndParent
= Desktop
->DesktopWindow
;
1380 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1381 (Window
= Parent
->spwndChild
))
1383 BOOL bGoDown
= TRUE
;
1385 Status
= STATUS_SUCCESS
;
1390 if(dwCount
++ < *pBufSize
&& pWnd
)
1394 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1395 *pWnd
= Window
->head
.h
;
1398 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1400 Status
= _SEH2_GetExceptionCode();
1403 if(!NT_SUCCESS(Status
))
1405 SetLastNtError(Status
);
1409 if (Window
->spwndChild
&& bChildren
)
1411 Window
= Window
->spwndChild
;
1416 if (Window
->spwndNext
)
1418 Window
= Window
->spwndNext
;
1422 Window
= Window
->spwndParent
;
1423 if (Window
== Parent
)
1432 ObDereferenceObject(Desktop
);
1435 else // Build EnumThreadWindows list!
1438 PTHREADINFO W32Thread
;
1442 Status
= PsLookupThreadByThreadId(UlongToHandle(dwThreadId
), &Thread
);
1443 if (!NT_SUCCESS(Status
))
1445 ERR("Thread Id is not valid!\n");
1446 return ERROR_INVALID_PARAMETER
;
1448 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1450 ObDereferenceObject(Thread
);
1451 TRACE("Tried to enumerate windows of a non gui thread\n");
1452 return ERROR_INVALID_PARAMETER
;
1455 // Do not use Thread link list due to co_UserFreeWindow!!!
1456 // Current = W32Thread->WindowListHead.Flink;
1457 // Fixes Api:CreateWindowEx tests!!!
1458 List
= IntWinListChildren(UserGetDesktopWindow());
1462 for (i
= 0; List
[i
]; i
++)
1464 Window
= ValidateHwndNoErr(List
[i
]);
1465 if (Window
&& Window
->head
.pti
== W32Thread
)
1467 if (dwCount
< *pBufSize
&& pWnd
)
1471 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1472 *pWnd
= Window
->head
.h
;
1475 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1477 Status
= _SEH2_GetExceptionCode();
1480 if (!NT_SUCCESS(Status
))
1482 ERR("Failure to build window list!\n");
1483 SetLastNtError(Status
);
1490 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
1493 ObDereferenceObject(Thread
);
1496 *pBufSize
= dwCount
;
1497 return STATUS_SUCCESS
;
1500 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1502 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1503 !(pWindow
->ExStyle
& WS_EX_NOPARENTNOTIFY
))
1505 if (VerifyWnd(pWindow
->spwndParent
) && !UserIsDesktopWindow(pWindow
->spwndParent
))
1507 USER_REFERENCE_ENTRY Ref
;
1508 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1509 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1511 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1512 (LPARAM
)pWindow
->head
.h
);
1513 UserDerefObjectCo(pWindow
->spwndParent
);
1519 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1521 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1523 /* default positioning for overlapped windows */
1524 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1527 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1529 pMonitor
= UserGetPrimaryMonitor();
1531 /* Check if we don't have a monitor attached yet */
1532 if(pMonitor
== NULL
)
1540 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1542 if (IS_DEFAULT(Cs
->x
))
1544 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1546 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1548 Cs
->x
= ProcessParams
->StartingX
;
1549 Cs
->y
= ProcessParams
->StartingY
;
1553 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1554 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1555 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1556 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1558 /* reset counter and position */
1561 pMonitor
->cWndStack
= 0;
1563 pMonitor
->cWndStack
++;
1567 if (IS_DEFAULT(Cs
->cx
))
1569 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1571 Cs
->cx
= ProcessParams
->CountX
;
1572 Cs
->cy
= ProcessParams
->CountY
;
1576 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1577 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1580 /* neither x nor cx are default. Check the y values .
1581 * In the trace we see Outlook and Outlook Express using
1582 * cy set to CW_USEDEFAULT when opening the address book.
1584 else if (IS_DEFAULT(Cs
->cy
))
1586 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1587 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1592 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1593 if(IS_DEFAULT(Cs
->x
))
1598 if(IS_DEFAULT(Cs
->cx
))
1608 /* Allocates and initializes a window */
1609 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1610 PLARGE_STRING WindowName
,
1615 PDESKTOP pdeskCreated
)
1619 PTHREADINFO pti
= NULL
;
1621 BOOL bUnicodeWindow
;
1623 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1625 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1626 { // Need both here for wine win.c test_CreateWindow.
1627 //if (Cs->hwndParent && ParentWindow)
1628 if (ParentWindow
) // It breaks more tests..... WIP.
1630 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1631 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1632 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1633 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1637 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1639 * Dialog boxes and message boxes do not inherit layout, so you must
1640 * set the layout explicitly.
1642 if ( Class
->fnid
!= FNID_DIALOG
)
1644 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1646 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1652 /* Automatically add WS_EX_WINDOWEDGE */
1653 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1654 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1655 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1656 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1658 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1660 /* Is it a unicode window? */
1661 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1662 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1664 /* Allocate the new window */
1665 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1666 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1670 sizeof(WND
) + Class
->cbwndExtra
);
1677 TRACE("Created window object with handle %p\n", hWnd
);
1679 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1680 { /* HACK: Helper for win32csr/desktopbg.c */
1681 /* If there is no desktop window yet, we must be creating it */
1682 TRACE("CreateWindow setting desktop.\n");
1683 pdeskCreated
->DesktopWindow
= hWnd
;
1684 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1688 * Fill out the structure describing it.
1690 /* Remember, pWnd->head is setup in object.c ... */
1691 pWnd
->spwndParent
= ParentWindow
;
1692 pWnd
->spwndOwner
= OwnerWindow
;
1694 pWnd
->spwndLastActive
= pWnd
;
1695 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1697 pWnd
->hModule
= Cs
->hInstance
;
1698 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1699 pWnd
->ExStyle
= Cs
->dwExStyle
;
1700 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1701 pWnd
->pActCtx
= acbiBuffer
;
1702 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1703 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1705 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1707 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1708 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1711 pWnd
->head
.pti
->cWindows
++;
1713 if (Class
->spicn
&& !Class
->spicnSm
)
1715 HICON IconSmHandle
= NULL
;
1716 if((Class
->spicn
->CURSORF_flags
& (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1717 == (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1719 IconSmHandle
= co_IntCopyImage(
1720 UserHMGetHandle(Class
->spicn
),
1722 UserGetSystemMetrics( SM_CXSMICON
),
1723 UserGetSystemMetrics( SM_CYSMICON
),
1724 LR_COPYFROMRESOURCE
);
1728 /* Retry without copying from resource */
1729 IconSmHandle
= co_IntCopyImage(
1730 UserHMGetHandle(Class
->spicn
),
1732 UserGetSystemMetrics( SM_CXSMICON
),
1733 UserGetSystemMetrics( SM_CYSMICON
),
1739 Class
->spicnSm
= UserGetCurIconObject(IconSmHandle
);
1740 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1744 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1745 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1747 /* BugBoy Comments: Comment below say that System classes are always created
1748 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1749 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1751 No where can I see in code or through testing does the window change back
1752 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1753 see what problems this would cause. */
1755 // Set WndProc from Class.
1756 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1758 // GetWindowProc, test for non server side default classes and set WndProc.
1759 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1763 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1764 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1768 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1769 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1773 // If not an Unicode caller, set Ansi creator bit.
1774 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1776 // Clone Class Ansi/Unicode proc type.
1777 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1779 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1780 pWnd
->Unicode
= FALSE
;
1784 * It seems there can be both an Ansi creator and Unicode Class Window
1785 * WndProc, unless the following overriding conditions occur:
1787 if ( !bUnicodeWindow
&&
1788 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1789 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1790 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1791 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1792 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1793 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1794 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1795 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1796 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1797 { // Override Class and set the window Ansi WndProc.
1798 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1799 pWnd
->Unicode
= FALSE
;
1802 { // Set the window Unicode WndProc.
1803 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1804 pWnd
->Unicode
= TRUE
;
1808 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1809 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1810 Dont understand why it does this. */
1811 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1813 PCALLPROCDATA CallProc
;
1814 CallProc
= CreateCallProc(pWnd
->head
.rpdesk
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1818 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1819 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1823 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1827 InitializeListHead(&pWnd
->PropListHead
);
1828 pWnd
->PropListItems
= 0;
1830 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1832 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1833 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1834 if (pWnd
->strName
.Buffer
== NULL
)
1839 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1840 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1841 pWnd
->strName
.Length
= WindowName
->Length
;
1842 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1845 /* Correct the window style. */
1846 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1848 pWnd
->style
|= WS_CLIPSIBLINGS
;
1849 if (!(pWnd
->style
& WS_POPUP
))
1851 pWnd
->style
|= WS_CAPTION
;
1855 /* WS_EX_WINDOWEDGE depends on some other styles */
1856 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1857 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1858 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1860 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1861 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1862 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1865 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1867 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1868 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1870 /* Set the window menu */
1871 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1875 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1877 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1879 UNICODE_STRING MenuName
;
1882 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1884 MenuName
.Length
= 0;
1885 MenuName
.MaximumLength
= 0;
1886 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1890 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1892 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1893 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1897 pWnd
->IDMenu
= (UINT_PTR
)Cs
->hMenu
;
1900 if ( ParentWindow
&&
1901 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1902 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1904 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1906 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1908 EngSetLastError(ERROR_INVALID_PARAMETER
);
1911 if ( pWnd
->spwndOwner
&&
1912 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1914 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1916 if ( pWnd
->spwndOwner
&&
1917 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1918 pti
!= pWnd
->spwndOwner
->head
.pti
)
1920 //ERR("CreateWindow Owner in.\n");
1921 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1925 /* Insert the window into the thread's window list. */
1926 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1928 /* Handle "CS_CLASSDC", it is tested first. */
1929 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1930 { /* One DCE per class to have CLASS. */
1931 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1933 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1934 { /* Allocate a DCE for this window. */
1935 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1941 ERR("IntCreateWindow Allocation Error.\n");
1942 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1945 UserDereferenceObject(pWnd
);
1953 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1954 PUNICODE_STRING ClassName
,
1955 PLARGE_STRING WindowName
,
1959 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1960 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1961 PWINSTATION_OBJECT WinSta
;
1964 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1965 CBT_CREATEWNDW
* pCbtCreate
;
1967 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1969 DWORD dwShowMode
= SW_SHOW
;
1970 CREATESTRUCTW
*pCsw
= NULL
;
1971 PVOID pszClass
= NULL
, pszName
= NULL
;
1974 /* Get the current window station and reference it */
1975 pti
= GetW32ThreadInfo();
1976 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1978 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1979 return NULL
; // There is nothing to cleanup.
1981 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1982 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1987 /* Get the class and reference it */
1988 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
1991 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
1992 ERR("Failed to find class %wZ\n", ClassName
);
1996 /* Now find the parent and the owner window */
1997 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
2000 if (Cs
->hwndParent
== HWND_MESSAGE
)
2002 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
2004 else if (Cs
->hwndParent
)
2006 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
2007 hWndOwner
= Cs
->hwndParent
;
2009 hWndParent
= Cs
->hwndParent
;
2011 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2013 ERR("Cannot create a child window without a parent!\n");
2014 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
2015 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
2018 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
2019 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
2021 if (hWndParent
&& !ParentWindow
)
2023 ERR("Got invalid parent window handle\n");
2026 else if (hWndOwner
&& !OwnerWindow
)
2028 ERR("Got invalid owner window handle\n");
2029 ParentWindow
= NULL
;
2035 if (IntIsDesktopWindow(OwnerWindow
)) OwnerWindow
= NULL
;
2036 else if (ParentWindow
&& !IntIsDesktopWindow(ParentWindow
))
2038 ERR("an owned window must be created as top-level\n");
2039 EngSetLastError( STATUS_ACCESS_DENIED
);
2042 else /* owner must be a top-level window */
2044 while ((OwnerWindow
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
&& !IntIsDesktopWindow(OwnerWindow
->spwndParent
))
2045 OwnerWindow
= OwnerWindow
->spwndParent
;
2049 /* Fix the position and the size of the window */
2052 UserRefObjectCo(ParentWindow
, &ParentRef
);
2053 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2056 /* Allocate and initialize the new window */
2057 Window
= IntCreateWindow(Cs
,
2066 ERR("IntCreateWindow failed!\n");
2070 hWnd
= UserHMGetHandle(Window
);
2071 hwndInsertAfter
= HWND_TOP
;
2073 UserRefObjectCo(Window
, &Ref
);
2074 UserDereferenceObject(Window
);
2075 ObDereferenceObject(WinSta
);
2077 //// Check for a hook to eliminate overhead. ////
2078 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2080 // Allocate the calling structures Justin Case this goes Global.
2081 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2082 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2083 if (!pCsw
|| !pCbtCreate
)
2085 ERR("UserHeapAlloc() failed!\n");
2089 /* Fill the new CREATESTRUCTW */
2090 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2091 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2093 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2094 if (!IS_ATOM(ClassName
->Buffer
))
2096 if (Window
->state
& WNDS_ANSICREATOR
)
2098 ANSI_STRING AnsiString
;
2099 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2100 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2103 ERR("UserHeapAlloc() failed!\n");
2106 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2107 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2108 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2112 UNICODE_STRING UnicodeString
;
2113 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2114 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2117 ERR("UserHeapAlloc() failed!\n");
2120 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2121 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2122 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2124 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2126 if (WindowName
->Length
)
2128 UNICODE_STRING Name
;
2129 Name
.Buffer
= WindowName
->Buffer
;
2130 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2131 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2133 if (Window
->state
& WNDS_ANSICREATOR
)
2135 ANSI_STRING AnsiString
;
2136 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2137 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2140 ERR("UserHeapAlloc() failed!\n");
2143 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2144 AnsiString
.Buffer
= (PCHAR
)pszName
;
2145 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2149 UNICODE_STRING UnicodeString
;
2150 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2151 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2154 ERR("UserHeapAlloc() failed!\n");
2157 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2158 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2159 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2161 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2164 pCbtCreate
->lpcs
= pCsw
;
2165 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2167 //// Call the WH_CBT hook ////
2168 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2171 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2174 // Write back changes.
2179 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2182 /* NCCREATE and WM_NCCALCSIZE need the original values */
2183 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2184 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2186 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2188 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2190 Cs
->x
+= ParentWindow
->rcClient
.left
;
2191 Cs
->y
+= ParentWindow
->rcClient
.top
;
2195 /* Send the WM_GETMINMAXINFO message */
2199 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2201 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2202 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2203 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2204 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2205 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2208 Window
->rcWindow
.left
= Cs
->x
;
2209 Window
->rcWindow
.top
= Cs
->y
;
2210 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2211 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2213 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2215 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2216 RECTL_vOffsetRect(&Window->rcWindow,
2217 ParentWindow->rcClient.left,
2218 ParentWindow->rcClient.top);
2221 /* correct child window coordinates if mirroring on parent is enabled */
2222 if (ParentWindow
!= NULL
)
2224 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2225 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2227 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2228 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2232 Window
->rcClient
= Window
->rcWindow
;
2234 /* Link the window */
2235 if (NULL
!= ParentWindow
)
2237 /* Link the window into the siblings list */
2238 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2239 IntLinkHwnd(Window
, HWND_BOTTOM
);
2241 IntLinkHwnd(Window
, hwndInsertAfter
);
2244 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2246 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2247 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2250 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2252 if ( !IntIsTopLevelWindow(Window
) )
2254 if (pti
!= Window
->spwndParent
->head
.pti
)
2256 //ERR("CreateWindow Parent in.\n");
2257 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2262 /* Send the NCCREATE message */
2263 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2266 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2270 /* Send the WM_NCCALCSIZE message */
2273 MaxPos
.x
= Window
->rcWindow
.left
;
2274 MaxPos
.y
= Window
->rcWindow
.top
;
2276 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2277 //rc = Window->rcWindow;
2278 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2279 //Window->rcClient = rc;
2281 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2282 MaxPos
.y
- Window
->rcWindow
.top
);
2285 /* Send the WM_CREATE message. */
2286 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2287 if (Result
== (LRESULT
)-1)
2289 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2293 /* Send the EVENT_OBJECT_CREATE event */
2294 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2296 /* By setting the flag below it can be examined to determine if the window
2297 was created successfully and a valid pwnd was passed back to caller since
2298 from here the function has to succeed. */
2299 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2301 /* Send the WM_SIZE and WM_MOVE messages. */
2302 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2304 co_WinPosSendSizeMove(Window
);
2307 /* Show or maybe minimize or maximize the window. */
2309 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2310 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2313 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2315 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2316 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2317 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2318 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2319 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2322 /* Send the WM_PARENTNOTIFY message */
2323 IntSendParentNotify(Window
, WM_CREATE
);
2325 /* Notify the shell that a new window was created */
2326 if (UserIsDesktopWindow(Window
->spwndParent
) &&
2327 Window
->spwndOwner
== NULL
&&
2328 (Window
->style
& WS_VISIBLE
) &&
2329 (!(Window
->ExStyle
& WS_EX_TOOLWINDOW
) ||
2330 (Window
->ExStyle
& WS_EX_APPWINDOW
)))
2332 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2335 /* Initialize and show the window's scrollbars */
2336 if (Window
->style
& WS_VSCROLL
)
2338 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2340 if (Window
->style
& WS_HSCROLL
)
2342 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2345 /* Show the new window */
2346 if (Cs
->style
& WS_VISIBLE
)
2348 if (Window
->style
& WS_MAXIMIZE
)
2349 dwShowMode
= SW_SHOW
;
2350 else if (Window
->style
& WS_MINIMIZE
)
2351 dwShowMode
= SW_SHOWMINIMIZED
;
2353 co_WinPosShowWindow(Window
, dwShowMode
);
2355 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2357 ASSERT(ParentWindow
);
2360 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2361 /* ShowWindow won't activate child windows */
2362 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2366 if (Class
->atomClassName
== gaGuiConsoleWndClass
)
2368 /* Count only console windows manually */
2369 co_IntUserManualGuiCheck(TRUE
);
2372 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2378 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2379 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2381 co_UserDestroyWindow(Window
);
2383 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2386 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2387 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2388 if (pszName
) UserHeapFree(pszName
);
2389 if (pszClass
) UserHeapFree(pszClass
);
2393 UserDerefObjectCo(Window
);
2395 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2397 // See CORE-13717, not setting error on success.
2399 EngSetLastError(ERROR_SUCCESS
);
2406 ProbeAndCaptureLargeString(
2407 OUT PLARGE_STRING plstrSafe
,
2408 IN PLARGE_STRING plstrUnsafe
)
2410 LARGE_STRING lstrTemp
;
2411 PVOID pvBuffer
= NULL
;
2415 /* Probe and copy the string */
2416 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2417 lstrTemp
= *plstrUnsafe
;
2419 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2422 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2426 if (lstrTemp
.Length
!= 0)
2428 /* Allocate a buffer from paged pool */
2429 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2432 return STATUS_NO_MEMORY
;
2437 /* Probe and copy the buffer */
2438 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2439 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2441 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2443 /* Cleanup and fail */
2444 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2445 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2450 /* Set the output string */
2451 plstrSafe
->Buffer
= pvBuffer
;
2452 plstrSafe
->Length
= lstrTemp
.Length
;
2453 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2455 return STATUS_SUCCESS
;
2459 * \todo Allow passing plstrClassName as ANSI.
2463 NtUserCreateWindowEx(
2465 PLARGE_STRING plstrClassName
,
2466 PLARGE_STRING plstrClsVersion
,
2467 PLARGE_STRING plstrWindowName
,
2475 HINSTANCE hInstance
,
2481 LARGE_STRING lstrWindowName
;
2482 LARGE_STRING lstrClassName
;
2483 LARGE_STRING lstrClsVersion
;
2484 UNICODE_STRING ustrClassName
;
2485 UNICODE_STRING ustrClsVersion
;
2490 lstrWindowName
.Buffer
= NULL
;
2491 lstrClassName
.Buffer
= NULL
;
2492 lstrClsVersion
.Buffer
= NULL
;
2494 ASSERT(plstrWindowName
);
2496 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2498 /* check hMenu is valid handle */
2499 if (hMenu
&& !UserGetMenuObject(hMenu
))
2501 ERR("NtUserCreateWindowEx: Got an invalid menu handle!\n");
2502 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
2507 /* Copy the window name to kernel mode */
2508 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2509 if (!NT_SUCCESS(Status
))
2511 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2512 SetLastNtError(Status
);
2516 plstrWindowName
= &lstrWindowName
;
2518 /* Check if the class is an atom */
2519 if (IS_ATOM(plstrClassName
))
2521 /* It is, pass the atom in the UNICODE_STRING */
2522 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2523 ustrClassName
.Length
= 0;
2524 ustrClassName
.MaximumLength
= 0;
2528 /* It's not, capture the class name */
2529 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2530 if (!NT_SUCCESS(Status
))
2532 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2533 /* Set last error, cleanup and return */
2534 SetLastNtError(Status
);
2538 /* We pass it on as a UNICODE_STRING */
2539 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2540 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2541 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2544 /* Check if the class version is an atom */
2545 if (IS_ATOM(plstrClsVersion
))
2547 /* It is, pass the atom in the UNICODE_STRING */
2548 ustrClsVersion
.Buffer
= (PVOID
)plstrClsVersion
;
2549 ustrClsVersion
.Length
= 0;
2550 ustrClsVersion
.MaximumLength
= 0;
2554 /* It's not, capture the class name */
2555 Status
= ProbeAndCaptureLargeString(&lstrClsVersion
, plstrClsVersion
);
2556 if (!NT_SUCCESS(Status
))
2558 ERR("NtUserCreateWindowEx: failed to capture plstrClsVersion\n");
2559 /* Set last error, cleanup and return */
2560 SetLastNtError(Status
);
2564 /* We pass it on as a UNICODE_STRING */
2565 ustrClsVersion
.Buffer
= lstrClsVersion
.Buffer
;
2566 ustrClsVersion
.Length
= (USHORT
)min(lstrClsVersion
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2567 ustrClsVersion
.MaximumLength
= (USHORT
)min(lstrClsVersion
.MaximumLength
, MAXUSHORT
);
2570 /* Fill the CREATESTRUCTW */
2571 /* we will keep here the original parameters */
2573 Cs
.lpCreateParams
= lpParam
;
2574 Cs
.hInstance
= hInstance
;
2576 Cs
.hwndParent
= hWndParent
;
2581 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2582 Cs
.lpszClass
= ustrClassName
.Buffer
;
2583 Cs
.dwExStyle
= dwExStyle
;
2585 UserEnterExclusive();
2587 /* Call the internal function */
2588 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClsVersion
, plstrWindowName
, acbiBuffer
);
2592 ERR("co_UserCreateWindowEx failed!\n");
2594 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2599 if (lstrWindowName
.Buffer
)
2601 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2603 if (lstrClassName
.Buffer
)
2605 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2607 if (lstrClsVersion
.Buffer
)
2609 ExFreePoolWithTag(lstrClsVersion
.Buffer
, TAG_STRING
);
2616 BOOLEAN
co_UserDestroyWindow(PVOID Object
)
2622 PWND Window
= Object
;
2624 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2626 hWnd
= Window
->head
.h
;
2627 ti
= PsGetCurrentThreadWin32Thread();
2629 TRACE("co_UserDestroyWindow \n");
2631 /* Check for owner thread */
2632 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2634 /* Check if we are destroying the desktop window */
2635 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2637 EngSetLastError(ERROR_ACCESS_DENIED
);
2642 /* If window was created successfully and it is hooked */
2643 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2645 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2647 ERR("Destroy Window WH_CBT Call Hook return!\n");
2652 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2654 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2656 if (Window
->spwndOwner
)
2658 //ERR("DestroyWindow Owner out.\n");
2659 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2664 /* Inform the parent */
2665 if (Window
->style
& WS_CHILD
)
2667 IntSendParentNotify(Window
, WM_DESTROY
);
2670 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
2672 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
2675 /* Hide the window */
2676 if (Window
->style
& WS_VISIBLE
)
2678 if (Window
->style
& WS_CHILD
)
2680 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
2681 co_WinPosShowWindow(Window
, SW_HIDE
);
2685 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2689 /* Adjust last active */
2690 if ((pwndTemp
= Window
->spwndOwner
))
2692 while (pwndTemp
->spwndOwner
)
2693 pwndTemp
= pwndTemp
->spwndOwner
;
2695 if (pwndTemp
->spwndLastActive
== Window
)
2696 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2699 if (Window
->spwndParent
&& IntIsWindow(UserHMGetHandle(Window
)))
2701 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2703 if (!IntIsTopLevelWindow(Window
))
2705 //ERR("DestroyWindow Parent out.\n");
2706 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2711 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2712 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2713 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2714 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2715 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2716 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2717 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2718 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2721 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2724 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2726 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2728 ERR("Destroying the ShellWindow!\n");
2729 ti
->pDeskInfo
->hShellWindow
= NULL
;
2733 IntEngWindowChanged(Window
, WOC_DELETE
);
2735 if (!IntIsWindow(UserHMGetHandle(Window
)))
2740 /* Recursively destroy owned windows */
2742 if (! (Window
->style
& WS_CHILD
))
2746 BOOL GotOne
= FALSE
;
2749 PWND Child
, Desktop
;
2751 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2752 UserGetWindowObject(IntGetDesktopWindow());
2753 Children
= IntWinListChildren(Desktop
);
2757 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2759 Child
= UserGetWindowObject(*ChildHandle
);
2762 if (Child
->spwndOwner
!= Window
)
2767 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2769 USER_REFERENCE_ENTRY ChildRef
;
2770 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2771 co_UserDestroyWindow(Child
);
2772 UserDerefObjectCo(Child
); // Temp HACK?
2778 if (Child
->spwndOwner
!= NULL
)
2780 Child
->spwndOwner
= NULL
;
2784 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2793 /* Generate mouse move message for the next window */
2794 msg
.message
= WM_MOUSEMOVE
;
2795 msg
.wParam
= UserGetMouseButtonsState();
2796 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2797 msg
.pt
= gpsi
->ptCursor
;
2798 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2800 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2802 /* Send destroy messages */
2803 IntSendDestroyMsg(UserHMGetHandle(Window
));
2805 if (!IntIsWindow(UserHMGetHandle(Window
)))
2810 /* Destroy the window storage */
2811 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2821 NtUserDestroyWindow(HWND Wnd
)
2824 DECLARE_RETURN(BOOLEAN
);
2826 USER_REFERENCE_ENTRY Ref
;
2828 TRACE("Enter NtUserDestroyWindow\n");
2829 UserEnterExclusive();
2831 if (!(Window
= UserGetWindowObject(Wnd
)))
2836 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2837 ret
= co_UserDestroyWindow(Window
);
2838 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2843 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2849 static HWND FASTCALL
2850 IntFindWindow(PWND Parent
,
2853 PUNICODE_STRING WindowName
)
2855 BOOL CheckWindowName
;
2858 UNICODE_STRING CurrentWindowName
;
2862 CheckWindowName
= WindowName
->Buffer
!= 0;
2864 if((List
= IntWinListChildren(Parent
)))
2869 /* skip handles before and including ChildAfter */
2870 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2874 /* search children */
2878 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2883 /* Do not send WM_GETTEXT messages in the kernel mode version!
2884 The user mode version however calls GetWindowText() which will
2885 send WM_GETTEXT messages to windows belonging to its processes */
2886 if (!ClassAtom
|| Child
->pcls
->atomNVClassName
== ClassAtom
)
2888 // FIXME: LARGE_STRING truncated
2889 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2890 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2891 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2892 if(!CheckWindowName
||
2893 (Child
->strName
.Length
< 0xFFFF &&
2894 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2896 Ret
= Child
->head
.h
;
2901 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2909 * Searches a window's children for a window with the specified
2912 * hwndParent = The window whose childs are to be searched.
2914 * HWND_MESSAGE = message-only windows
2916 * hwndChildAfter = Search starts after this child window.
2917 * NULL = start from beginning
2919 * ucClassName = Class name to search for
2920 * Reguired parameter.
2922 * ucWindowName = Window name
2923 * ->Buffer == NULL = don't care
2926 * The HWND of the window if it was found, otherwise NULL
2932 NtUserFindWindowEx(HWND hwndParent
,
2933 HWND hwndChildAfter
,
2934 PUNICODE_STRING ucClassName
,
2935 PUNICODE_STRING ucWindowName
,
2938 PWND Parent
, ChildAfter
;
2939 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2940 HWND Desktop
, Ret
= NULL
;
2941 BOOL DoMessageWnd
= FALSE
;
2942 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2943 DECLARE_RETURN(HWND
);
2945 TRACE("Enter NtUserFindWindowEx\n");
2948 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2952 if (ucClassName
!= NULL
)
2954 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2955 if (ClassName
.Length
!= 0)
2957 ProbeForRead(ClassName
.Buffer
,
2961 else if (!IS_ATOM(ClassName
.Buffer
))
2963 EngSetLastError(ERROR_INVALID_PARAMETER
);
2967 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2970 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
2975 if (ucWindowName
!= NULL
)
2977 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2978 if (WindowName
.Length
!= 0)
2980 ProbeForRead(WindowName
.Buffer
,
2986 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2988 SetLastNtError(_SEH2_GetExceptionCode());
2989 _SEH2_YIELD(RETURN(NULL
));
2993 if (ucClassName
!= NULL
)
2995 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2996 !IS_ATOM(ClassName
.Buffer
))
2998 EngSetLastError(ERROR_INVALID_PARAMETER
);
3001 else if (ClassAtom
== (RTL_ATOM
)0)
3003 /* LastError code was set by IntGetAtomFromStringOrAtom */
3009 Desktop
= IntGetCurrentThreadDesktopWindow();
3011 if(hwndParent
== NULL
)
3013 hwndParent
= Desktop
;
3014 DoMessageWnd
= TRUE
;
3016 else if(hwndParent
== HWND_MESSAGE
)
3018 hwndParent
= IntGetMessageWindow();
3021 if(!(Parent
= UserGetWindowObject(hwndParent
)))
3027 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
3034 if(Parent
->head
.h
== Desktop
)
3037 PWND TopLevelWindow
;
3038 BOOLEAN CheckWindowName
;
3039 BOOLEAN WindowMatches
;
3040 BOOLEAN ClassMatches
;
3042 /* windows searches through all top-level windows if the parent is the desktop
3045 if((List
= IntWinListChildren(Parent
)))
3051 /* skip handles before and including ChildAfter */
3052 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
3056 CheckWindowName
= WindowName
.Buffer
!= 0;
3058 /* search children */
3061 UNICODE_STRING ustr
;
3063 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
3068 /* Do not send WM_GETTEXT messages in the kernel mode version!
3069 The user mode version however calls GetWindowText() which will
3070 send WM_GETTEXT messages to windows belonging to its processes */
3071 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
3072 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
3073 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
3074 WindowMatches
= !CheckWindowName
||
3075 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
3076 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
3077 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
3078 ClassAtom
== TopLevelWindow
->pcls
->atomNVClassName
;
3080 if (WindowMatches
&& ClassMatches
)
3082 Ret
= TopLevelWindow
->head
.h
;
3086 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3088 /* window returns the handle of the top-level window, in case it found
3090 Ret
= TopLevelWindow
->head
.h
;
3095 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3100 TRACE("FindWindowEx: Not Desktop Parent!\n");
3101 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3104 if (Ret
== NULL
&& DoMessageWnd
)
3108 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3110 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3114 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3116 SetLastNtError(_SEH2_GetExceptionCode());
3124 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3133 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3135 PWND WndAncestor
, Parent
;
3137 if (Wnd
->head
.h
== IntGetDesktopWindow())
3146 WndAncestor
= Wnd
->spwndParent
;
3157 if(!(Parent
= WndAncestor
->spwndParent
))
3161 if(IntIsDesktopWindow(Parent
))
3166 WndAncestor
= Parent
;
3177 Parent
= IntGetParent(WndAncestor
);
3184 WndAncestor
= Parent
;
3202 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3204 PWND Window
, Ancestor
;
3205 DECLARE_RETURN(HWND
);
3207 TRACE("Enter NtUserGetAncestor\n");
3208 UserEnterExclusive();
3210 if (!(Window
= UserGetWindowObject(hWnd
)))
3215 Ancestor
= UserGetAncestor(Window
, Type
);
3216 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3218 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3221 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3227 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3229 /* combo state struct */
3243 INT fixedOwnerDrawHeight
;
3244 INT droppedWidth
; /* last two are not used unless set */
3245 INT editHeight
; /* explicitly */
3247 } HEADCOMBO
,*LPHEADCOMBO
;
3249 // Window Extra data container.
3250 typedef struct _WND2CBOX
3254 } WND2CBOX
, *PWND2CBOX
;
3256 #define CBF_BUTTONDOWN 0x0002
3262 NtUserGetComboBoxInfo(
3268 BOOL NotSameppi
= FALSE
;
3270 DECLARE_RETURN(BOOL
);
3272 TRACE("Enter NtUserGetComboBoxInfo\n");
3275 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3281 ProbeForWrite(pcbi
, sizeof(COMBOBOXINFO
), 1);
3283 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3285 SetLastNtError(_SEH2_GetExceptionCode());
3286 _SEH2_YIELD(RETURN(FALSE
));
3290 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3292 EngSetLastError(ERROR_INVALID_PARAMETER
);
3296 // Pass the user pointer, it was already probed.
3297 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3299 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3302 ppi
= PsGetCurrentProcessWin32Process();
3303 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3306 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3311 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3312 pcbi
->rcItem
= lphc
->textRect
;
3313 pcbi
->rcButton
= lphc
->buttonRect
;
3314 pcbi
->stateButton
= 0;
3315 if (lphc
->wState
& CBF_BUTTONDOWN
)
3316 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3317 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3318 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3319 pcbi
->hwndCombo
= lphc
->self
;
3320 pcbi
->hwndItem
= lphc
->hWndEdit
;
3321 pcbi
->hwndList
= lphc
->hWndLBox
;
3323 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3326 SetLastNtError(_SEH2_GetExceptionCode());
3333 if (NotSameppi
) KeDetachProcess();
3334 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3340 //// ReactOS work around! Keep it the sames as in Listbox.c
3342 /* Listbox structure */
3345 HWND self
; /* Our own window handle */
3346 HWND owner
; /* Owner window to send notifications to */
3347 UINT style
; /* Window style */
3348 INT width
; /* Window width */
3349 INT height
; /* Window height */
3350 VOID
*items
; /* Array of items */
3351 INT nb_items
; /* Number of items */
3352 INT top_item
; /* Top visible item */
3353 INT selected_item
; /* Selected item */
3354 INT focus_item
; /* Item that has the focus */
3355 INT anchor_item
; /* Anchor item for extended selection */
3356 INT item_height
; /* Default item height */
3357 INT page_size
; /* Items per listbox page */
3358 INT column_width
; /* Column width for multi-column listboxes */
3361 // Window Extra data container.
3362 typedef struct _WND2LB
3372 NtUserGetListBoxInfo(
3377 BOOL NotSameppi
= FALSE
;
3379 DECLARE_RETURN(DWORD
);
3381 TRACE("Enter NtUserGetListBoxInfo\n");
3384 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3389 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3391 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3394 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3395 ppi
= PsGetCurrentProcessWin32Process();
3396 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3399 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3404 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3405 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3406 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3407 Ret
= descr
->page_size
* descr
->column_width
;
3409 Ret
= descr
->page_size
;
3411 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3414 SetLastNtError(_SEH2_GetExceptionCode());
3421 if (NotSameppi
) KeDetachProcess();
3422 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3430 * The NtUserSetParent function changes the parent window of the specified
3434 * The new parent window and the child window must belong to the same
3435 * application. If the window identified by the hWndChild parameter is
3436 * visible, the system performs the appropriate redrawing and repainting.
3437 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3438 * or WS_POPUP window styles of the window whose parent is being changed.
3445 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3447 DECLARE_RETURN(HWND
);
3449 TRACE("Enter NtUserSetParent\n");
3450 UserEnterExclusive();
3453 Check Parent first from user space, set it here.
3457 hWndNewParent
= IntGetDesktopWindow();
3459 else if (hWndNewParent
== HWND_MESSAGE
)
3461 hWndNewParent
= IntGetMessageWindow();
3464 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3467 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3473 * UserGetShellWindow
3475 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3480 HWND FASTCALL
UserGetShellWindow(VOID
)
3482 PWINSTATION_OBJECT WinStaObject
;
3485 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3491 if (!NT_SUCCESS(Status
))
3493 SetLastNtError(Status
);
3497 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3499 ObDereferenceObject(WinStaObject
);
3504 * NtUserSetShellWindowEx
3506 * This is undocumented function to set global shell window. The global
3507 * shell window has special handling of window position.
3513 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3515 PWINSTATION_OBJECT WinStaObject
;
3516 PWND WndShell
, WndListView
;
3517 DECLARE_RETURN(BOOL
);
3518 USER_REFERENCE_ENTRY Ref
;
3522 TRACE("Enter NtUserSetShellWindowEx\n");
3523 UserEnterExclusive();
3525 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3530 if (!(WndListView
= UserGetWindowObject(hwndListView
)))
3535 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3541 if (!NT_SUCCESS(Status
))
3543 SetLastNtError(Status
);
3548 * Test if we are permitted to change the shell window.
3550 if (WinStaObject
->ShellWindow
)
3552 ObDereferenceObject(WinStaObject
);
3557 * Move shell window into background.
3559 if (hwndListView
&& hwndListView
!= hwndShell
)
3562 * Disabled for now to get Explorer working.
3563 * -- Filip, 01/nov/2003
3566 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3569 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3571 ObDereferenceObject(WinStaObject
);
3576 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3578 ObDereferenceObject(WinStaObject
);
3582 UserRefObjectCo(WndShell
, &Ref
);
3583 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3584 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3586 WinStaObject
->ShellWindow
= hwndShell
;
3587 WinStaObject
->ShellListView
= hwndListView
;
3589 ti
= GetW32ThreadInfo();
3592 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3593 ti
->pDeskInfo
->spwndShell
= WndShell
;
3594 ti
->pDeskInfo
->spwndBkGnd
= WndListView
;
3595 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3598 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3600 UserDerefObjectCo(WndShell
);
3602 ObDereferenceObject(WinStaObject
);
3606 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3611 // Fixes wine Win test_window_styles and todo tests...
3612 static BOOL FASTCALL
3613 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3615 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3617 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3624 co_IntSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
, ULONG Size
, BOOL bAlter
)
3626 PWND Window
, Parent
;
3627 PWINSTATION_OBJECT WindowStation
;
3631 if (!(Window
= UserGetWindowObject(hWnd
)))
3636 if ((INT
)Index
>= 0)
3638 if ((Index
+ Size
) > Window
->cbwndExtra
)
3640 EngSetLastError(ERROR_INVALID_INDEX
);
3645 if (Size
== sizeof(LONG
))
3647 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3648 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = (LONG
)NewValue
;
3653 OldValue
= *((LONG_PTR
*)((PCHAR
)(Window
+ 1) + Index
));
3655 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3657 OldValue = (LONG_PTR)IntSetWindowProc( Wnd, (WNDPROC)NewValue, Ansi);
3658 if (!OldValue) return 0;
3661 *((LONG_PTR
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3668 if (Size
== sizeof(LONG
))
3670 if ((Index
!= GWL_STYLE
) &&
3671 (Index
!= GWL_EXSTYLE
) &&
3672 (Index
!= GWL_ID
) &&
3673 (Index
!= GWL_USERDATA
))
3675 ERR("NtUserSetWindowLong(): Index requires pointer size: %lu\n", Index
);
3676 EngSetLastError(ERROR_INVALID_INDEX
);
3684 case GWL_EXSTYLE
: // LONG
3685 OldValue
= (LONG
) Window
->ExStyle
;
3686 Style
.styleOld
= OldValue
;
3687 Style
.styleNew
= NewValue
;
3689 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3692 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3694 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3697 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3698 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3700 /* WS_EX_WINDOWEDGE depends on some other styles */
3701 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3702 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3704 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3706 if (!(Window
->ExStyle
& WS_EX_LAYERED
))
3708 SetLayeredStatus(Window
, 0);
3711 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3713 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3716 case GWL_STYLE
: // LONG
3717 OldValue
= (LONG
) Window
->style
;
3718 Style
.styleOld
= OldValue
;
3719 Style
.styleNew
= NewValue
;
3722 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3724 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3725 if (UserIsDesktopWindow(Window
->spwndParent
)) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3726 /* WS_MINIMIZE can't be reset */
3727 if (OldValue
& WS_MINIMIZE
) Style
.styleNew
|= WS_MINIMIZE
;
3728 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3729 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3730 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3732 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3734 if ((OldValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3736 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
3738 //// From child to non-child it should be null already.
3739 ERR("IDMenu going null! %d\n",Window
->IDMenu
);
3740 Window
->IDMenu
= 0; // Window->spmenu = 0;
3745 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3747 PMENU pMenu
= UserGetMenuObject(UlongToHandle(Window
->IDMenu
));
3748 Window
->state
&= ~WNDS_HASMENU
;
3751 ERR("IDMenu released 0x%p\n",pMenu
);
3752 // ROS may not hold a lock after setting menu to window. But it should!
3753 //IntReleaseMenuObject(pMenu);
3758 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3760 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3761 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3762 DceResetActiveDCEs( Window
);
3764 Window
->style
= (DWORD
)Style
.styleNew
;
3767 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3770 case GWLP_WNDPROC
: // LONG_PTR
3772 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3773 Window
->fnid
& FNID_FREED
)
3775 EngSetLastError(ERROR_ACCESS_DENIED
);
3778 OldValue
= (LONG_PTR
)IntSetWindowProc(Window
,
3784 case GWLP_HINSTANCE
: // LONG_PTR
3785 OldValue
= (LONG_PTR
) Window
->hModule
;
3786 Window
->hModule
= (HINSTANCE
) NewValue
;
3789 case GWLP_HWNDPARENT
: // LONG_PTR
3790 Parent
= Window
->spwndParent
;
3791 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3792 OldValue
= (LONG_PTR
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3794 OldValue
= (LONG_PTR
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3797 case GWLP_ID
: // LONG
3798 OldValue
= (LONG
) Window
->IDMenu
;
3799 Window
->IDMenu
= (UINT
) NewValue
;
3802 case GWLP_USERDATA
: // LONG or LONG_PTR
3803 OldValue
= Window
->dwUserData
;
3804 Window
->dwUserData
= NewValue
;
3808 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3809 EngSetLastError(ERROR_INVALID_INDEX
);
3819 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3821 return (LONG
)co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG
), FALSE
);
3825 co_UserSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
)
3827 return co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG_PTR
), FALSE
);
3831 * NtUserSetWindowLong
3833 * The NtUserSetWindowLong function changes an attribute of the specified
3834 * window. The function also sets the 32-bit (long) value at the specified
3835 * offset into the extra window memory.
3842 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3846 UserEnterExclusive();
3848 if (hWnd
== IntGetDesktopWindow())
3850 EngSetLastError(STATUS_ACCESS_DENIED
);
3855 ret
= (LONG
)co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG
), FALSE
);
3864 NtUserSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
)
3868 UserEnterExclusive();
3870 if (hWnd
== IntGetDesktopWindow())
3872 EngSetLastError(STATUS_ACCESS_DENIED
);
3877 ret
= co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG_PTR
), FALSE
);
3886 NtUserAlterWindowStyle(HWND hWnd
, DWORD Index
, LONG NewValue
)
3890 UserEnterExclusive();
3892 if (hWnd
== IntGetDesktopWindow())
3894 EngSetLastError(STATUS_ACCESS_DENIED
);
3899 ret
= co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, FALSE
, sizeof(LONG
), TRUE
);
3908 * NtUserSetWindowWord
3910 * Legacy function similar to NtUserSetWindowLong.
3917 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3921 DECLARE_RETURN(WORD
);
3923 TRACE("Enter NtUserSetWindowWord\n");
3924 UserEnterExclusive();
3926 if (hWnd
== IntGetDesktopWindow())
3928 EngSetLastError(STATUS_ACCESS_DENIED
);
3932 if (!(Window
= UserGetWindowObject(hWnd
)))
3941 case GWL_HWNDPARENT
:
3942 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3946 EngSetLastError(ERROR_INVALID_INDEX
);
3951 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3953 EngSetLastError(ERROR_INVALID_PARAMETER
);
3957 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3958 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3963 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3969 QueryWindow based on KJK::Hyperion and James Tabor.
3971 0 = QWUniqueProcessId
3972 1 = QWUniqueThreadId
3975 4 = QWIsHung Implements IsHungAppWindow found
3978 9 = QWKillWindow When I called this with hWnd ==
3979 DesktopWindow, it shutdown the system
3986 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3988 /* Console Leader Process CID Window offsets */
3989 #define GWLP_CONSOLE_LEADER_PID 0
3990 #define GWLP_CONSOLE_LEADER_TID 4
3994 DECLARE_RETURN(UINT
);
3996 TRACE("Enter NtUserQueryWindow\n");
3999 if (!(pWnd
= UserGetWindowObject(hWnd
)))
4006 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
4008 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
4009 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
4011 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
4012 Result
= (DWORD_PTR
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
4016 Result
= (DWORD_PTR
)IntGetWndProcessId(pWnd
);
4021 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
4023 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
4024 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
4026 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
4027 Result
= (DWORD_PTR
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
4031 Result
= (DWORD_PTR
)IntGetWndThreadId(pWnd
);
4036 case QUERY_WINDOW_ACTIVE
:
4037 Result
= (DWORD_PTR
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
4040 case QUERY_WINDOW_FOCUS
:
4041 Result
= (DWORD_PTR
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
4044 case QUERY_WINDOW_ISHUNG
:
4045 Result
= (DWORD_PTR
)MsqIsHung(pWnd
->head
.pti
);
4048 case QUERY_WINDOW_REAL_ID
:
4049 Result
= (DWORD_PTR
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
4052 case QUERY_WINDOW_FOREGROUND
:
4053 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
4064 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
4073 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4075 UNICODE_STRING SafeMessageName
;
4078 DECLARE_RETURN(UINT
);
4080 TRACE("Enter NtUserRegisterWindowMessage\n");
4081 UserEnterExclusive();
4083 if(MessageNameUnsafe
== NULL
)
4085 EngSetLastError(ERROR_INVALID_PARAMETER
);
4089 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4090 if(!NT_SUCCESS(Status
))
4092 SetLastNtError(Status
);
4096 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4097 if (SafeMessageName
.Buffer
)
4098 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4102 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
4111 NtUserSetWindowFNID(HWND hWnd
,
4115 DECLARE_RETURN(BOOL
);
4117 TRACE("Enter NtUserSetWindowFNID\n");
4118 UserEnterExclusive();
4120 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4125 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
4127 EngSetLastError(ERROR_ACCESS_DENIED
);
4131 // From user land we only set these.
4132 if (fnID
!= FNID_DESTROY
)
4134 /* HACK: The minimum should be FNID_BUTTON, but menu code relies on this */
4135 if (fnID
< FNID_FIRST
|| fnID
> FNID_GHOST
||
4138 EngSetLastError(ERROR_INVALID_PARAMETER
);
4147 TRACE("Leave NtUserSetWindowFNID\n");
4153 DefSetText(PWND Wnd
, PCWSTR WindowText
)
4155 UNICODE_STRING UnicodeString
;
4158 RtlInitUnicodeString(&UnicodeString
, WindowText
);
4160 if (UnicodeString
.Length
!= 0)
4162 if (Wnd
->strName
.MaximumLength
> 0 &&
4163 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4165 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4167 Wnd
->strName
.Length
= UnicodeString
.Length
;
4168 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4169 RtlCopyMemory(Wnd
->strName
.Buffer
,
4170 UnicodeString
.Buffer
,
4171 UnicodeString
.Length
);
4176 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4177 buf
= Wnd
->strName
.Buffer
;
4178 Wnd
->strName
.Buffer
= NULL
;
4181 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4184 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4185 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4186 if (Wnd
->strName
.Buffer
!= NULL
)
4188 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4189 RtlCopyMemory(Wnd
->strName
.Buffer
,
4190 UnicodeString
.Buffer
,
4191 UnicodeString
.Length
);
4192 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4193 Wnd
->strName
.Length
= UnicodeString
.Length
;
4197 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4204 Wnd
->strName
.Length
= 0;
4205 if (Wnd
->strName
.Buffer
!= NULL
)
4206 Wnd
->strName
.Buffer
[0] = L
'\0';
4209 // FIXME: HAX! Windows does not do this in here!
4210 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4211 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4212 /* Send shell notifications */
4213 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4215 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) UserHMGetHandle(Wnd
), FALSE
); // FIXME Flashing?
4220 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4227 * Undocumented function that is called from DefWindowProc to set
4234 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4237 LARGE_STRING SafeText
;
4238 UNICODE_STRING UnicodeString
;
4241 TRACE("Enter NtUserDefSetText\n");
4243 if (WindowText
!= NULL
)
4247 SafeText
= ProbeForReadLargeString(WindowText
);
4249 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4252 SetLastNtError(_SEH2_GetExceptionCode());
4262 UserEnterExclusive();
4264 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4270 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4271 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4272 // Now we know what the bAnsi is for.
4273 RtlInitUnicodeString(&UnicodeString
, NULL
);
4274 if (SafeText
.Buffer
)
4279 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4281 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4282 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4284 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4287 SetLastNtError(_SEH2_GetExceptionCode());
4290 if (!Ret
) goto Exit
;
4293 if (UnicodeString
.Length
!= 0)
4295 if (Wnd
->strName
.MaximumLength
> 0 &&
4296 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4298 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4300 Wnd
->strName
.Length
= UnicodeString
.Length
;
4301 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4302 RtlCopyMemory(Wnd
->strName
.Buffer
,
4303 UnicodeString
.Buffer
,
4304 UnicodeString
.Length
);
4309 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4310 buf
= Wnd
->strName
.Buffer
;
4311 Wnd
->strName
.Buffer
= NULL
;
4314 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4317 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4318 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4319 if (Wnd
->strName
.Buffer
!= NULL
)
4321 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4322 RtlCopyMemory(Wnd
->strName
.Buffer
,
4323 UnicodeString
.Buffer
,
4324 UnicodeString
.Length
);
4325 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4326 Wnd
->strName
.Length
= UnicodeString
.Length
;
4330 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4338 Wnd
->strName
.Length
= 0;
4339 if (Wnd
->strName
.Buffer
!= NULL
)
4340 Wnd
->strName
.Buffer
[0] = L
'\0';
4343 // FIXME: HAX! Windows does not do this in here!
4344 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4345 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4346 /* Send shell notifications */
4347 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4349 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4354 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4355 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4361 * NtUserInternalGetWindowText
4368 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4373 DECLARE_RETURN(INT
);
4375 TRACE("Enter NtUserInternalGetWindowText\n");
4378 if(lpString
&& (nMaxCount
<= 1))
4380 EngSetLastError(ERROR_INVALID_PARAMETER
);
4384 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4389 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4392 const WCHAR Terminator
= L
'\0';
4394 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4396 Copy
= min(nMaxCount
- 1, Result
);
4399 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4400 if(!NT_SUCCESS(Status
))
4402 SetLastNtError(Status
);
4408 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4409 if(!NT_SUCCESS(Status
))
4411 SetLastNtError(Status
);
4421 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4431 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4437 // ASSERT(OwnerWnd);
4439 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4441 /* NOTE: Popups are not children */
4442 win_array
= IntWinListOwnedPopups(OwnerWnd
);
4447 while (win_array
[count
])
4449 while (--count
>= 0)
4451 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4453 if (pWnd
->spwndOwner
!= OwnerWnd
)
4458 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4460 /* In Windows, ShowOwnedPopups(TRUE) generates
4461 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4462 * regardless of the state of the owner
4464 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4465 pWnd
->state
&= ~WNDS_HIDDENPOPUP
;
4471 if (pWnd
->style
& WS_VISIBLE
)
4473 /* In Windows, ShowOwnedPopups(FALSE) generates
4474 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4475 * regardless of the state of the owner
4477 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4478 pWnd
->state
|= WNDS_HIDDENPOPUP
;
4483 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4484 TRACE("Leave ShowOwnedPopups\n");