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
, NumOwned
= 0;
293 Desktop
= co_GetDesktopWindow(Window
);
297 for (Child
= Desktop
->spwndChild
; Child
; Child
= Child
->spwndNext
)
299 if (Child
->spwndOwner
== Window
)
303 List
= ExAllocatePoolWithTag(PagedPool
, (NumOwned
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
306 ERR("Failed to allocate memory for children array\n");
307 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
312 for (Child
= Desktop
->spwndChild
; Child
; Child
= Child
->spwndNext
)
314 if (Child
->spwndOwner
== Window
)
315 List
[Index
++] = Child
->head
.h
;
323 IntGetNonChildAncestor(PWND pWnd
)
325 while(pWnd
&& (pWnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
326 pWnd
= pWnd
->spwndParent
;
331 IntIsTopLevelWindow(PWND pWnd
)
333 if ( pWnd
->spwndParent
&&
334 pWnd
->spwndParent
== co_GetDesktopWindow(pWnd
) ) return TRUE
;
339 IntValidateOwnerDepth(PWND Wnd
, PWND Owner
)
344 if ( !Owner
) return gNestedWindowLimit
>= Depth
;
345 if (Owner
== Wnd
) break;
346 Owner
= Owner
->spwndOwner
;
353 IntGetWindow(HWND hWnd
,
359 Wnd
= ValidateHwndNoErr(hWnd
);
367 if (Wnd
->spwndOwner
!= NULL
)
368 FoundWnd
= Wnd
->spwndOwner
;
372 if(Wnd
->spwndParent
!= NULL
)
374 FoundWnd
= Wnd
->spwndParent
;
375 if (FoundWnd
->spwndChild
!= NULL
)
376 FoundWnd
= FoundWnd
->spwndChild
;
380 if (Wnd
->spwndNext
!= NULL
)
381 FoundWnd
= Wnd
->spwndNext
;
385 if (Wnd
->spwndPrev
!= NULL
)
386 FoundWnd
= Wnd
->spwndPrev
;
390 if (Wnd
->spwndChild
!= NULL
)
391 FoundWnd
= Wnd
->spwndChild
;
396 while ( FoundWnd
->spwndNext
!= NULL
)
397 FoundWnd
= FoundWnd
->spwndNext
;
405 if (FoundWnd
!= NULL
)
406 Ret
= UserHMGetHandle(FoundWnd
);
410 DWORD FASTCALL
IntGetWindowContextHelpId( PWND pWnd
)
416 HelpId
= (DWORD
)(DWORD_PTR
)UserGetProp(pWnd
, gpsi
->atomContextHelpIdProp
, TRUE
);
418 pWnd
= IntGetParent(pWnd
);
420 while (pWnd
&& pWnd
->fnid
!= FNID_DESKTOP
);
427 IntRemoveTrackMouseEvent(
430 /***********************************************************************
433 static void IntSendDestroyMsg(HWND hWnd
)
438 ti
= PsGetCurrentThreadWin32Thread();
439 Window
= UserGetWindowObject(hWnd
);
444 * Look whether the focus is within the tree of windows
445 * we will be destroying.
448 if ( ti
->MessageQueue
->spwndActive
== Window
|| // Fixes CORE-106 RegSvr32 exit and return focus to CMD.
449 (ti
->MessageQueue
->spwndActive
== NULL
&& ti
->MessageQueue
== IntGetFocusMessageQueue()) )
451 co_WinPosActivateOtherWindow(Window
);
454 /* Fixes CMD properties closing and returning focus to CMD */
455 if (ti
->MessageQueue
->spwndFocus
== Window
)
457 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
459 co_UserSetFocus(Window
->spwndParent
);
463 co_UserSetFocus(NULL
);
467 if (ti
->MessageQueue
->CaretInfo
.hWnd
== UserHMGetHandle(Window
))
469 co_IntDestroyCaret(ti
);
472 /* If the window being destroyed is currently tracked... */
473 if (ti
->rpdesk
->spwndTrack
== Window
)
475 IntRemoveTrackMouseEvent(ti
->rpdesk
);
479 /* If the window being destroyed is the current clipboard owner... */
480 if (ti
->ppi
->prpwinsta
!= NULL
&& Window
== ti
->ppi
->prpwinsta
->spwndClipOwner
)
482 /* ... make it release the clipboard */
483 UserClipboardRelease(Window
);
486 /* Send the WM_DESTROY to the window */
487 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
490 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
491 * make sure that the window still exists when we come back.
493 if (IntIsWindow(hWnd
))
498 if (!(pWndArray
= IntWinListChildren( Window
))) return;
500 for (i
= 0; pWndArray
[i
]; i
++)
502 if (IntIsWindow( pWndArray
[i
] )) IntSendDestroyMsg( pWndArray
[i
] );
504 ExFreePoolWithTag(pWndArray
, USERTAG_WINDOWLIST
);
508 TRACE("destroyed itself while in WM_DESTROY!\n");
513 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
515 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
519 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
521 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
522 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
525 if (Wnd
->strName
.Buffer
!= NULL
)
527 Wnd
->strName
.Length
= 0;
528 Wnd
->strName
.MaximumLength
= 0;
529 DesktopHeapFree(Wnd
->head
.rpdesk
,
530 Wnd
->strName
.Buffer
);
531 Wnd
->strName
.Buffer
= NULL
;
534 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
535 // WindowObject->hWnd = NULL;
538 /***********************************************************************
541 * Destroy storage associated to a window. "Internals" p.358
543 * This is the "functional" DestroyWindows function i.e. all stuff
544 * done in CreateWindow is undone here and not in DestroyWindow :-P
546 LRESULT
co_UserFreeWindow(PWND Window
,
547 PPROCESSINFO ProcessData
,
548 PTHREADINFO ThreadData
,
549 BOOLEAN SendMessages
)
555 BOOLEAN BelongsToThreadData
;
559 if(Window
->state2
& WNDS2_INDESTROY
)
561 TRACE("Tried to call co_UserFreeWindow() twice\n");
564 Window
->state2
|= WNDS2_INDESTROY
;
565 Window
->style
&= ~WS_VISIBLE
;
566 Window
->head
.pti
->cVisWindows
--;
569 /* remove the window already at this point from the thread window list so we
570 don't get into trouble when destroying the thread windows while we're still
571 in co_UserFreeWindow() */
572 RemoveEntryList(&Window
->ThreadListEntry
);
574 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
576 IntDeRegisterShellHookWindow(UserHMGetHandle(Window
));
578 /* free child windows */
579 Children
= IntWinListChildren(Window
);
582 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
584 if ((Child
= IntGetWindowObject(*ChildHandle
)))
586 if (!IntWndBelongsToThread(Child
, ThreadData
))
588 /* send WM_DESTROY messages to windows not belonging to the same thread */
589 co_IntSendMessage( UserHMGetHandle(Child
), WM_ASYNC_DESTROYWINDOW
, 0, 0 );
592 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
594 UserDereferenceObject(Child
);
597 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
603 * Clear the update region to make sure no WM_PAINT messages will be
604 * generated for this window while processing the WM_NCDESTROY.
606 co_UserRedrawWindow(Window
, NULL
, 0,
607 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
608 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
609 if (BelongsToThreadData
)
610 co_IntSendMessage(UserHMGetHandle(Window
), WM_NCDESTROY
, 0, 0);
613 UserClipboardFreeWindow(Window
);
615 DestroyTimersForWindow(ThreadData
, Window
);
617 /* Unregister hot keys */
618 UnregisterWindowHotKeys(Window
);
620 /* flush the message queue */
621 MsqRemoveWindowMessagesFromQueue(Window
);
623 /* from now on no messages can be sent to this window anymore */
624 Window
->state
|= WNDS_DESTROYED
;
625 Window
->fnid
|= FNID_FREED
;
627 /* don't remove the WINDOWSTATUS_DESTROYING bit */
629 /* reset shell window handles */
630 if (ThreadData
->rpdesk
)
632 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
633 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
635 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
636 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
639 /* Fixes dialog test_focus breakage due to r66237. */
640 if (ThreadData
->MessageQueue
->spwndFocus
== Window
)
641 ThreadData
->MessageQueue
->spwndFocus
= NULL
;
643 if (ThreadData
->MessageQueue
->spwndActive
== Window
)
644 ThreadData
->MessageQueue
->spwndActive
= NULL
;
646 if (ThreadData
->MessageQueue
->spwndCapture
== Window
)
651 //// Now kill those remaining "PAINTING BUG: Thread marked as containing dirty windows" spam!!!
652 if ( Window
->hrgnUpdate
!= NULL
|| Window
->state
& WNDS_INTERNALPAINT
)
654 MsqDecPaintCountQueue(Window
->head
.pti
);
655 if (Window
->hrgnUpdate
> HRGN_WINDOW
&& GreIsHandleValid(Window
->hrgnUpdate
))
657 IntGdiSetRegionOwner(Window
->hrgnUpdate
, GDI_OBJ_HMGR_POWNED
);
658 GreDeleteObject(Window
->hrgnUpdate
);
660 Window
->hrgnUpdate
= NULL
;
661 Window
->state
&= ~WNDS_INTERNALPAINT
;
664 if (Window
->state
& (WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
))
666 Window
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
);
669 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
671 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
673 TRACE("UFW: IDMenu %p\n",Window
->IDMenu
);
674 IntDestroyMenuObject(Menu
, TRUE
);
678 if (Window
->SystemMenu
679 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
681 IntDestroyMenuObject(Menu
, TRUE
);
682 Window
->SystemMenu
= (HMENU
)0;
685 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
687 IntUnlinkWindow(Window
);
689 if (Window
->PropListItems
)
691 UserRemoveWindowProps(Window
);
692 TRACE("Window->PropListItems %lu\n",Window
->PropListItems
);
693 ASSERT(Window
->PropListItems
==0);
696 UserReferenceObject(Window
);
697 UserMarkObjectDestroy(Window
);
699 IntDestroyScrollBars(Window
);
701 if (Window
->pcls
->atomClassName
== gaGuiConsoleWndClass
)
703 /* Count only console windows manually */
704 co_IntUserManualGuiCheck(FALSE
);
707 /* dereference the class */
708 NT_ASSERT(Window
->head
.pti
!= NULL
);
709 IntDereferenceClass(Window
->pcls
,
710 Window
->head
.pti
->pDeskInfo
,
711 Window
->head
.pti
->ppi
);
714 if (Window
->hrgnClip
)
716 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
717 GreDeleteObject(Window
->hrgnClip
);
718 Window
->hrgnClip
= NULL
;
720 Window
->head
.pti
->cWindows
--;
722 // ASSERT(Window != NULL);
723 UserFreeWindowInfo(Window
->head
.pti
, Window
);
725 UserDereferenceObject(Window
);
726 UserDeleteObject(UserHMGetHandle(Window
), TYPE_WINDOW
);
732 // Same as User32:IntGetWndProc.
735 IntGetWindowProc(PWND pWnd
,
740 WNDPROC gcpd
, Ret
= 0;
742 ASSERT(UserIsEnteredExclusive() == TRUE
);
746 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
748 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
750 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
753 Ret
= GETPFNCLIENTA(i
);
755 Ret
= GETPFNCLIENTW(i
);
761 if (Class
->fnid
== FNID_EDIT
)
762 Ret
= pWnd
->lpfnWndProc
;
765 Ret
= pWnd
->lpfnWndProc
;
767 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
771 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
772 Ret
= GETPFNCLIENTA(Class
->fnid
);
776 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
777 Ret
= GETPFNCLIENTW(Class
->fnid
);
780 if ( Ret
!= pWnd
->lpfnWndProc
)
783 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
786 gcpd
= (WNDPROC
)UserGetCPD(
788 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
791 return (gcpd
? gcpd
: Ret
);
795 IntSetWindowProc(PWND pWnd
,
800 PCALLPROCDATA CallProc
;
802 WNDPROC Ret
, chWndProc
= NULL
;
804 // Retrieve previous window proc.
805 Ret
= IntGetWindowProc(pWnd
, Ansi
);
809 if (IsCallProcHandle(NewWndProc
))
811 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
813 { // Reset new WndProc.
814 NewWndProc
= CallProc
->pfnClientPrevious
;
815 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
816 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
819 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
820 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
822 if (GETPFNCLIENTW(i
) == NewWndProc
)
824 chWndProc
= GETPFNSERVER(i
);
827 if (GETPFNCLIENTA(i
) == NewWndProc
)
829 chWndProc
= GETPFNSERVER(i
);
833 // If match, set/reset to Server Side and clear ansi.
836 pWnd
->lpfnWndProc
= chWndProc
;
837 pWnd
->Unicode
= TRUE
;
838 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
839 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
843 pWnd
->Unicode
= !Ansi
;
844 // Handle the state change in here.
846 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
848 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
850 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
851 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
853 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
855 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
859 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
860 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
864 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
865 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
868 // Now set the new window proc.
869 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
875 /* INTERNAL ******************************************************************/
878 // This fixes a check for children messages that need paint while searching the parents messages!
879 // Fixes wine msg:test_paint_messages:WmParentErasePaint ..
882 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
884 PWND Window
= BaseWindow
;
887 if ( Window
== NULL
|| (Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
890 Window
= Window
->spwndParent
;
892 while(Parent
!= Window
);
897 /* Link the window into siblings list. Children and parent are kept in place. */
901 PWND WndInsertAfter
/* Set to NULL if top sibling */
904 if (Wnd
== WndInsertAfter
)
906 ERR("IntLinkWindow -- Trying to link window 0x%p to itself!!\n", Wnd
);
910 Wnd
->spwndPrev
= WndInsertAfter
;
913 /* Link after WndInsertAfter */
914 ASSERT(Wnd
!= WndInsertAfter
->spwndNext
);
915 Wnd
->spwndNext
= WndInsertAfter
->spwndNext
;
917 Wnd
->spwndNext
->spwndPrev
= Wnd
;
919 ASSERT(Wnd
!= Wnd
->spwndPrev
);
920 Wnd
->spwndPrev
->spwndNext
= Wnd
;
924 /* Link at the top */
925 ASSERT(Wnd
!= Wnd
->spwndParent
->spwndChild
);
926 Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
;
928 Wnd
->spwndNext
->spwndPrev
= Wnd
;
930 Wnd
->spwndParent
->spwndChild
= Wnd
;
935 Note: Wnd->spwndParent can be null if it is the desktop.
937 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
939 if (hWndPrev
== HWND_NOTOPMOST
)
941 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) && (Wnd
->ExStyle2
& WS_EX2_LINKED
))
942 return; /* nothing to do */
943 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
944 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
947 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
949 if (hWndPrev
== HWND_BOTTOM
)
951 /* Link in the bottom of the list */
954 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
955 while (WndInsertAfter
&& WndInsertAfter
->spwndNext
)
957 WndInsertAfter
= WndInsertAfter
->spwndNext
;
960 IntLinkWindow(Wnd
, WndInsertAfter
);
961 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
963 else if (hWndPrev
== HWND_TOPMOST
)
965 /* Link in the top of the list */
966 IntLinkWindow(Wnd
, NULL
);
967 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
969 else if (hWndPrev
== HWND_TOP
)
971 /* Link it after the last topmost window */
972 PWND WndInsertBefore
;
974 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
976 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
978 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
980 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
))
983 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
985 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
988 WndInsertBefore
= WndInsertBefore
->spwndNext
;
992 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
996 /* Link it after hWndPrev */
999 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
1000 /* Are we called with an erroneous handle */
1001 if (WndInsertAfter
== NULL
)
1003 /* Link in a default position */
1004 IntLinkHwnd(Wnd
, HWND_TOP
);
1008 if (Wnd
== WndInsertAfter
)
1009 ERR("IntLinkHwnd -- Trying to link window 0x%p to itself!!\n", Wnd
);
1010 IntLinkWindow(Wnd
, WndInsertAfter
);
1012 /* Fix the WS_EX_TOPMOST flag */
1013 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
1015 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
1019 if (WndInsertAfter
->spwndNext
&&
1020 (WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
))
1022 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1026 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
1030 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
1034 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
1037 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
1038 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1040 //ERR("ProcessOwnerSwap Old out.\n");
1041 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
1047 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
1050 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1052 //ERR("ProcessOwnerSwap New in.\n");
1053 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1057 // FIXME: System Tray checks.
1061 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1063 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1066 Wnd
= IntGetWindowObject(hWnd
);
1070 WndOldOwner
= Wnd
->spwndOwner
;
1072 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1073 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1075 if (!WndNewOwner
&& hWndNewOwner
)
1077 EngSetLastError(ERROR_INVALID_PARAMETER
);
1082 /* if parent belongs to a different thread and the window isn't */
1083 /* top-level, attach the two threads */
1084 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1086 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1090 Wnd
->spwndOwner
= WndNewOwner
;
1094 Wnd
->spwndOwner
= NULL
;
1099 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1100 EngSetLastError(ERROR_INVALID_PARAMETER
);
1104 UserDereferenceObject(Wnd
);
1109 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1111 PWND WndOldParent
, pWndExam
;
1114 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1117 ASSERT(WndNewParent
);
1118 ASSERT_REFS_CO(Wnd
);
1119 ASSERT_REFS_CO(WndNewParent
);
1121 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1123 EngSetLastError(ERROR_ACCESS_DENIED
);
1127 /* Some applications try to set a child as a parent */
1128 if (IntIsChildWindow(Wnd
, WndNewParent
))
1130 TRACE("IntSetParent try to set a child as a parent.\n");
1131 EngSetLastError( ERROR_INVALID_PARAMETER
);
1135 pWndExam
= WndNewParent
; // Load parent Window to examine.
1136 // Now test for set parent to parent hit.
1139 if (Wnd
== pWndExam
)
1141 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1142 EngSetLastError(ERROR_INVALID_PARAMETER
);
1145 pWndExam
= pWndExam
->spwndParent
;
1149 * Windows hides the window first, then shows it again
1150 * including the WM_SHOWWINDOW messages and all
1152 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1154 /* Window must belong to current process */
1155 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1157 ERR("IntSetParent Window must belong to current process!\n");
1161 WndOldParent
= Wnd
->spwndParent
;
1163 if ( WndOldParent
&&
1164 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1165 pt
.x
= Wnd
->rcWindow
.right
;
1167 pt
.x
= Wnd
->rcWindow
.left
;
1168 pt
.y
= Wnd
->rcWindow
.top
;
1170 IntScreenToClient(WndOldParent
, &pt
);
1172 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1174 if (WndNewParent
!= WndOldParent
)
1176 /* Unlink the window from the siblings list */
1177 IntUnlinkWindow(Wnd
);
1178 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1180 /* Set the new parent */
1181 Wnd
->spwndParent
= WndNewParent
;
1183 if ( Wnd
->style
& WS_CHILD
&&
1185 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1187 ERR("SetParent Top Most from Pop up!\n");
1188 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1191 /* Link the window with its new siblings */
1193 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1194 UserIsDesktopWindow(WndNewParent
) ) ? HWND_TOP
: HWND_TOPMOST
) );
1197 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1198 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1200 Wnd
->style
|= WS_CLIPSIBLINGS
;
1201 DceResetActiveDCEs(Wnd
);
1204 /* if parent belongs to a different thread and the window isn't */
1205 /* top-level, attach the two threads */
1206 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1208 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1210 if (WndOldParent
&& (Wnd
->head
.pti
!= WndOldParent
->head
.pti
))
1212 //ERR("SetParent Old out.\n");
1213 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1216 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1218 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1220 //ERR("SetParent New in.\n");
1221 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1226 if (UserIsMessageWindow(WndOldParent
) || UserIsMessageWindow(WndNewParent
))
1227 swFlags
|= SWP_NOACTIVATE
;
1229 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1231 * SetParent additionally needs to make hwnd the top window
1232 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1233 * WM_WINDOWPOSCHANGED notification messages.
1235 //ERR("IntSetParent SetWindowPos 1\n");
1236 co_WinPosSetWindowPos( Wnd
,
1237 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1238 pt
.x
, pt
.y
, 0, 0, swFlags
);
1239 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1240 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1242 return WndOldParent
;
1246 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1248 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1249 HWND hWndOldParent
= NULL
;
1250 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1252 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1254 EngSetLastError(ERROR_INVALID_PARAMETER
);
1258 if (hWndChild
== IntGetDesktopWindow())
1260 ERR("UserSetParent Access Denied!\n");
1261 EngSetLastError(ERROR_ACCESS_DENIED
);
1267 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1269 ERR("UserSetParent Bad New Parent!\n");
1275 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1281 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1283 ERR("UserSetParent Bad Child!\n");
1287 UserRefObjectCo(Wnd
, &Ref
);
1288 UserRefObjectCo(WndParent
, &ParentRef
);
1289 //ERR("Enter co_IntSetParent\n");
1290 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1291 //ERR("Leave co_IntSetParent\n");
1292 UserDerefObjectCo(WndParent
);
1293 UserDerefObjectCo(Wnd
);
1297 hWndOldParent
= WndOldParent
->head
.h
;
1298 UserDereferenceObject(WndOldParent
);
1301 return( hWndOldParent
);
1304 /* Unlink the window from siblings. Children and parent are kept in place. */
1306 IntUnlinkWindow(PWND Wnd
)
1308 ASSERT(Wnd
!= Wnd
->spwndNext
);
1309 ASSERT(Wnd
!= Wnd
->spwndPrev
);
1312 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1315 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1317 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1318 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1320 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1323 /* FUNCTIONS *****************************************************************/
1326 * As best as I can figure, this function is used by EnumWindows,
1327 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1329 * It's supposed to build a list of HWNDs to return to the caller.
1330 * We can figure out what kind of list by what parameters are
1338 NtUserBuildHwndList(
1351 return ERROR_INVALID_PARAMETER
;
1353 if (hwndParent
|| !dwThreadId
)
1356 PWND Parent
, Window
;
1360 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1362 return ERROR_INVALID_HANDLE
;
1367 Status
= IntValidateDesktopHandle(hDesktop
,
1371 if(!NT_SUCCESS(Status
))
1373 return ERROR_INVALID_HANDLE
;
1376 hwndParent
= Desktop
->DesktopWindow
;
1383 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1384 (Window
= Parent
->spwndChild
))
1386 BOOL bGoDown
= TRUE
;
1388 Status
= STATUS_SUCCESS
;
1393 if(dwCount
++ < *pBufSize
&& pWnd
)
1397 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1398 *pWnd
= Window
->head
.h
;
1401 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1403 Status
= _SEH2_GetExceptionCode();
1406 if(!NT_SUCCESS(Status
))
1408 SetLastNtError(Status
);
1412 if (Window
->spwndChild
&& bChildren
)
1414 Window
= Window
->spwndChild
;
1419 if (Window
->spwndNext
)
1421 Window
= Window
->spwndNext
;
1425 Window
= Window
->spwndParent
;
1426 if (Window
== Parent
)
1435 ObDereferenceObject(Desktop
);
1438 else // Build EnumThreadWindows list!
1441 PTHREADINFO W32Thread
;
1445 Status
= PsLookupThreadByThreadId(UlongToHandle(dwThreadId
), &Thread
);
1446 if (!NT_SUCCESS(Status
))
1448 ERR("Thread Id is not valid!\n");
1449 return ERROR_INVALID_PARAMETER
;
1451 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1453 ObDereferenceObject(Thread
);
1454 TRACE("Tried to enumerate windows of a non gui thread\n");
1455 return ERROR_INVALID_PARAMETER
;
1458 // Do not use Thread link list due to co_UserFreeWindow!!!
1459 // Current = W32Thread->WindowListHead.Flink;
1460 // Fixes Api:CreateWindowEx tests!!!
1461 List
= IntWinListChildren(UserGetDesktopWindow());
1465 for (i
= 0; List
[i
]; i
++)
1467 Window
= ValidateHwndNoErr(List
[i
]);
1468 if (Window
&& Window
->head
.pti
== W32Thread
)
1470 if (dwCount
< *pBufSize
&& pWnd
)
1474 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1475 *pWnd
= Window
->head
.h
;
1478 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1480 Status
= _SEH2_GetExceptionCode();
1483 if (!NT_SUCCESS(Status
))
1485 ERR("Failure to build window list!\n");
1486 SetLastNtError(Status
);
1493 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
1496 ObDereferenceObject(Thread
);
1499 *pBufSize
= dwCount
;
1500 return STATUS_SUCCESS
;
1503 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1505 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1506 !(pWindow
->ExStyle
& WS_EX_NOPARENTNOTIFY
))
1508 if (VerifyWnd(pWindow
->spwndParent
) && !UserIsDesktopWindow(pWindow
->spwndParent
))
1510 USER_REFERENCE_ENTRY Ref
;
1511 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1512 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1514 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1515 (LPARAM
)pWindow
->head
.h
);
1516 UserDerefObjectCo(pWindow
->spwndParent
);
1522 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1524 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1526 /* default positioning for overlapped windows */
1527 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1530 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1532 pMonitor
= UserGetPrimaryMonitor();
1534 /* Check if we don't have a monitor attached yet */
1535 if(pMonitor
== NULL
)
1543 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1545 if (IS_DEFAULT(Cs
->x
))
1547 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1549 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1551 Cs
->x
= ProcessParams
->StartingX
;
1552 Cs
->y
= ProcessParams
->StartingY
;
1556 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1557 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1558 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1559 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1561 /* reset counter and position */
1564 pMonitor
->cWndStack
= 0;
1566 pMonitor
->cWndStack
++;
1570 if (IS_DEFAULT(Cs
->cx
))
1572 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1574 Cs
->cx
= ProcessParams
->CountX
;
1575 Cs
->cy
= ProcessParams
->CountY
;
1579 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1580 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1583 /* neither x nor cx are default. Check the y values .
1584 * In the trace we see Outlook and Outlook Express using
1585 * cy set to CW_USEDEFAULT when opening the address book.
1587 else if (IS_DEFAULT(Cs
->cy
))
1589 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1590 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1595 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1596 if(IS_DEFAULT(Cs
->x
))
1601 if(IS_DEFAULT(Cs
->cx
))
1611 /* Allocates and initializes a window */
1612 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1613 PLARGE_STRING WindowName
,
1618 PDESKTOP pdeskCreated
,
1623 PTHREADINFO pti
= NULL
;
1625 BOOL bUnicodeWindow
;
1627 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1629 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1630 { // Need both here for wine win.c test_CreateWindow.
1631 //if (Cs->hwndParent && ParentWindow)
1632 if (ParentWindow
) // It breaks more tests..... WIP.
1634 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1635 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1636 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1637 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1641 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1643 * Dialog boxes and message boxes do not inherit layout, so you must
1644 * set the layout explicitly.
1646 if ( Class
->fnid
!= FNID_DIALOG
)
1648 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1650 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1656 /* Automatically add WS_EX_WINDOWEDGE */
1657 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1658 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1659 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1660 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1662 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1664 /* Is it a unicode window? */
1665 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1666 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1668 /* Allocate the new window */
1669 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1670 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1674 sizeof(WND
) + Class
->cbwndExtra
);
1681 TRACE("Created window object with handle %p\n", hWnd
);
1683 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1684 { /* HACK: Helper for win32csr/desktopbg.c */
1685 /* If there is no desktop window yet, we must be creating it */
1686 TRACE("CreateWindow setting desktop.\n");
1687 pdeskCreated
->DesktopWindow
= hWnd
;
1688 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1692 * Fill out the structure describing it.
1694 /* Remember, pWnd->head is setup in object.c ... */
1695 pWnd
->spwndParent
= ParentWindow
;
1696 pWnd
->spwndOwner
= OwnerWindow
;
1698 pWnd
->spwndLastActive
= pWnd
;
1699 // Ramp up compatible version sets.
1700 if ( dwVer
>= WINVER_WIN31
)
1702 pWnd
->state2
|= WNDS2_WIN31COMPAT
;
1703 if ( dwVer
>= WINVER_WINNT4
)
1705 pWnd
->state2
|= WNDS2_WIN40COMPAT
;
1706 if ( dwVer
>= WINVER_WIN2K
)
1708 pWnd
->state2
|= WNDS2_WIN50COMPAT
;
1713 pWnd
->hModule
= Cs
->hInstance
;
1714 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1715 pWnd
->ExStyle
= Cs
->dwExStyle
;
1716 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1717 pWnd
->pActCtx
= acbiBuffer
;
1718 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1719 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1721 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1723 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1724 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1727 pWnd
->head
.pti
->cWindows
++;
1729 if (Class
->spicn
&& !Class
->spicnSm
)
1731 HICON IconSmHandle
= NULL
;
1732 if((Class
->spicn
->CURSORF_flags
& (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1733 == (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1735 IconSmHandle
= co_IntCopyImage(
1736 UserHMGetHandle(Class
->spicn
),
1738 UserGetSystemMetrics( SM_CXSMICON
),
1739 UserGetSystemMetrics( SM_CYSMICON
),
1740 LR_COPYFROMRESOURCE
);
1744 /* Retry without copying from resource */
1745 IconSmHandle
= co_IntCopyImage(
1746 UserHMGetHandle(Class
->spicn
),
1748 UserGetSystemMetrics( SM_CXSMICON
),
1749 UserGetSystemMetrics( SM_CYSMICON
),
1755 Class
->spicnSm
= UserGetCurIconObject(IconSmHandle
);
1756 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1760 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1761 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1763 /* BugBoy Comments: Comment below say that System classes are always created
1764 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1765 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1767 No where can I see in code or through testing does the window change back
1768 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1769 see what problems this would cause. */
1771 // Set WndProc from Class.
1772 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1774 // GetWindowProc, test for non server side default classes and set WndProc.
1775 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1779 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1780 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1784 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1785 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1789 // If not an Unicode caller, set Ansi creator bit.
1790 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1792 // Clone Class Ansi/Unicode proc type.
1793 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1795 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1796 pWnd
->Unicode
= FALSE
;
1800 * It seems there can be both an Ansi creator and Unicode Class Window
1801 * WndProc, unless the following overriding conditions occur:
1803 if ( !bUnicodeWindow
&&
1804 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1805 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1806 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1807 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1808 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1809 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1810 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1811 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1812 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1813 { // Override Class and set the window Ansi WndProc.
1814 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1815 pWnd
->Unicode
= FALSE
;
1818 { // Set the window Unicode WndProc.
1819 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1820 pWnd
->Unicode
= TRUE
;
1824 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1825 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1826 Dont understand why it does this. */
1827 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1829 PCALLPROCDATA CallProc
;
1830 CallProc
= CreateCallProc(pWnd
->head
.rpdesk
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1834 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1835 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1839 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1843 InitializeListHead(&pWnd
->PropListHead
);
1844 pWnd
->PropListItems
= 0;
1846 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1848 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1849 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1850 if (pWnd
->strName
.Buffer
== NULL
)
1855 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1856 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1857 pWnd
->strName
.Length
= WindowName
->Length
;
1858 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1861 /* Correct the window style. */
1862 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1864 pWnd
->style
|= WS_CLIPSIBLINGS
;
1865 if (!(pWnd
->style
& WS_POPUP
))
1867 pWnd
->style
|= WS_CAPTION
;
1871 /* WS_EX_WINDOWEDGE depends on some other styles */
1872 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1873 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1874 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1876 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1877 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1878 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1881 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1883 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1884 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1886 /* Set the window menu */
1887 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1891 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1893 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1895 UNICODE_STRING MenuName
;
1898 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1900 MenuName
.Length
= 0;
1901 MenuName
.MaximumLength
= 0;
1902 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1906 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1908 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1909 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1913 pWnd
->IDMenu
= (UINT_PTR
)Cs
->hMenu
;
1916 if ( ParentWindow
&&
1917 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1918 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1920 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1922 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1924 EngSetLastError(ERROR_INVALID_PARAMETER
);
1927 if ( pWnd
->spwndOwner
&&
1928 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1930 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1932 if ( pWnd
->spwndOwner
&&
1933 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1934 pti
!= pWnd
->spwndOwner
->head
.pti
)
1936 //ERR("CreateWindow Owner in.\n");
1937 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1941 /* Insert the window into the thread's window list. */
1942 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1944 /* Handle "CS_CLASSDC", it is tested first. */
1945 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1946 { /* One DCE per class to have CLASS. */
1947 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1949 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1950 { /* Allocate a DCE for this window. */
1951 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1957 ERR("IntCreateWindow Allocation Error.\n");
1958 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1961 UserDereferenceObject(pWnd
);
1969 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1970 PUNICODE_STRING ClassName
,
1971 PLARGE_STRING WindowName
,
1976 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1977 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1978 PWINSTATION_OBJECT WinSta
;
1981 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1982 CBT_CREATEWNDW
* pCbtCreate
;
1984 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1986 DWORD dwShowMode
= SW_SHOW
;
1987 CREATESTRUCTW
*pCsw
= NULL
;
1988 PVOID pszClass
= NULL
, pszName
= NULL
;
1991 /* Get the current window station and reference it */
1992 pti
= GetW32ThreadInfo();
1993 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1995 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1996 return NULL
; // There is nothing to cleanup.
1998 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1999 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
2004 /* Get the class and reference it */
2005 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
2008 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
2009 ERR("Failed to find class %wZ\n", ClassName
);
2013 /* Now find the parent and the owner window */
2014 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
2017 if (Cs
->hwndParent
== HWND_MESSAGE
)
2019 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
2021 else if (Cs
->hwndParent
)
2023 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
2024 hWndOwner
= Cs
->hwndParent
;
2026 hWndParent
= Cs
->hwndParent
;
2028 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2030 ERR("Cannot create a child window without a parent!\n");
2031 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
2032 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
2034 else if (Cs
->lpszClass
!= (LPCWSTR
)MAKEINTATOM(gpsi
->atomSysClass
[ICLS_DESKTOP
]) &&
2035 (IS_INTRESOURCE(Cs
->lpszClass
) ||
2036 Cs
->lpszClass
!= (LPCWSTR
)MAKEINTATOM(gpsi
->atomSysClass
[ICLS_HWNDMESSAGE
]) ||
2037 _wcsicmp(Cs
->lpszClass
, L
"Message") != 0))
2039 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
2041 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
2045 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
2046 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
2048 if (hWndParent
&& !ParentWindow
)
2050 ERR("Got invalid parent window handle\n");
2053 else if (hWndOwner
&& !OwnerWindow
)
2055 ERR("Got invalid owner window handle\n");
2056 ParentWindow
= NULL
;
2062 if (IntIsDesktopWindow(OwnerWindow
)) OwnerWindow
= NULL
;
2063 else if (ParentWindow
&& !IntIsDesktopWindow(ParentWindow
))
2065 ERR("an owned window must be created as top-level\n");
2066 EngSetLastError( STATUS_ACCESS_DENIED
);
2069 else /* owner must be a top-level window */
2071 while ((OwnerWindow
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
&& !IntIsDesktopWindow(OwnerWindow
->spwndParent
))
2072 OwnerWindow
= OwnerWindow
->spwndParent
;
2076 /* Fix the position and the size of the window */
2079 UserRefObjectCo(ParentWindow
, &ParentRef
);
2080 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2083 /* Allocate and initialize the new window */
2084 Window
= IntCreateWindow(Cs
,
2094 ERR("IntCreateWindow failed!\n");
2098 hWnd
= UserHMGetHandle(Window
);
2099 hwndInsertAfter
= HWND_TOP
;
2101 UserRefObjectCo(Window
, &Ref
);
2102 UserDereferenceObject(Window
);
2103 ObDereferenceObject(WinSta
);
2105 //// Check for a hook to eliminate overhead. ////
2106 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2108 // Allocate the calling structures Justin Case this goes Global.
2109 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2110 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2111 if (!pCsw
|| !pCbtCreate
)
2113 ERR("UserHeapAlloc() failed!\n");
2117 /* Fill the new CREATESTRUCTW */
2118 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2119 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2121 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2122 if (!IS_ATOM(ClassName
->Buffer
))
2124 if (Window
->state
& WNDS_ANSICREATOR
)
2126 ANSI_STRING AnsiString
;
2127 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2128 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2131 ERR("UserHeapAlloc() failed!\n");
2134 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2135 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2136 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2140 UNICODE_STRING UnicodeString
;
2141 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2142 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2145 ERR("UserHeapAlloc() failed!\n");
2148 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2149 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2150 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2152 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2154 if (WindowName
->Length
)
2156 UNICODE_STRING Name
;
2157 Name
.Buffer
= WindowName
->Buffer
;
2158 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2159 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2161 if (Window
->state
& WNDS_ANSICREATOR
)
2163 ANSI_STRING AnsiString
;
2164 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2165 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2168 ERR("UserHeapAlloc() failed!\n");
2171 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2172 AnsiString
.Buffer
= (PCHAR
)pszName
;
2173 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2177 UNICODE_STRING UnicodeString
;
2178 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2179 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2182 ERR("UserHeapAlloc() failed!\n");
2185 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2186 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2187 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2189 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2192 pCbtCreate
->lpcs
= pCsw
;
2193 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2195 //// Call the WH_CBT hook ////
2196 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2199 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2202 // Write back changes.
2207 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2210 /* NCCREATE and WM_NCCALCSIZE need the original values */
2211 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2212 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2214 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2216 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2218 Cs
->x
+= ParentWindow
->rcClient
.left
;
2219 Cs
->y
+= ParentWindow
->rcClient
.top
;
2223 /* Send the WM_GETMINMAXINFO message */
2227 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2229 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2230 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2231 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2232 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2233 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2236 Window
->rcWindow
.left
= Cs
->x
;
2237 Window
->rcWindow
.top
= Cs
->y
;
2238 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2239 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2241 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2243 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2244 RECTL_vOffsetRect(&Window->rcWindow,
2245 ParentWindow->rcClient.left,
2246 ParentWindow->rcClient.top);
2249 /* correct child window coordinates if mirroring on parent is enabled */
2250 if (ParentWindow
!= NULL
)
2252 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2253 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2255 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2256 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2260 Window
->rcClient
= Window
->rcWindow
;
2262 /* Link the window */
2263 if (NULL
!= ParentWindow
)
2265 /* Link the window into the siblings list */
2266 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2267 IntLinkHwnd(Window
, HWND_BOTTOM
);
2269 IntLinkHwnd(Window
, hwndInsertAfter
);
2272 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2274 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2275 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2278 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2280 if ( !IntIsTopLevelWindow(Window
) )
2282 if (pti
!= Window
->spwndParent
->head
.pti
)
2284 //ERR("CreateWindow Parent in.\n");
2285 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2290 /* Send the NCCREATE message */
2291 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2294 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2298 /* Send the WM_NCCALCSIZE message */
2301 MaxPos
.x
= Window
->rcWindow
.left
;
2302 MaxPos
.y
= Window
->rcWindow
.top
;
2304 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2305 //rc = Window->rcWindow;
2306 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2307 //Window->rcClient = rc;
2309 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2310 MaxPos
.y
- Window
->rcWindow
.top
);
2313 /* Send the WM_CREATE message. */
2314 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2315 if (Result
== (LRESULT
)-1)
2317 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2321 /* Send the EVENT_OBJECT_CREATE event */
2322 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2324 /* By setting the flag below it can be examined to determine if the window
2325 was created successfully and a valid pwnd was passed back to caller since
2326 from here the function has to succeed. */
2327 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2329 /* Send the WM_SIZE and WM_MOVE messages. */
2330 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2332 co_WinPosSendSizeMove(Window
);
2335 /* Show or maybe minimize or maximize the window. */
2337 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2338 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2341 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2343 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2344 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2345 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2346 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2347 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2350 /* Send the WM_PARENTNOTIFY message */
2351 IntSendParentNotify(Window
, WM_CREATE
);
2353 /* Notify the shell that a new window was created */
2354 if (UserIsDesktopWindow(Window
->spwndParent
) &&
2355 Window
->spwndOwner
== NULL
&&
2356 (Window
->style
& WS_VISIBLE
) &&
2357 (!(Window
->ExStyle
& WS_EX_TOOLWINDOW
) ||
2358 (Window
->ExStyle
& WS_EX_APPWINDOW
)))
2360 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2363 /* Initialize and show the window's scrollbars */
2364 if (Window
->style
& WS_VSCROLL
)
2366 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2368 if (Window
->style
& WS_HSCROLL
)
2370 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2373 /* Show the new window */
2374 if (Cs
->style
& WS_VISIBLE
)
2376 if (Window
->style
& WS_MAXIMIZE
)
2377 dwShowMode
= SW_SHOW
;
2378 else if (Window
->style
& WS_MINIMIZE
)
2379 dwShowMode
= SW_SHOWMINIMIZED
;
2381 co_WinPosShowWindow(Window
, dwShowMode
);
2383 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2385 ASSERT(ParentWindow
);
2388 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2389 /* ShowWindow won't activate child windows */
2390 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2394 if (Class
->atomClassName
== gaGuiConsoleWndClass
)
2396 /* Count only console windows manually */
2397 co_IntUserManualGuiCheck(TRUE
);
2400 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2406 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2407 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2409 co_UserDestroyWindow(Window
);
2411 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2414 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2415 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2416 if (pszName
) UserHeapFree(pszName
);
2417 if (pszClass
) UserHeapFree(pszClass
);
2421 UserDerefObjectCo(Window
);
2423 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2425 // See CORE-13717, not setting error on success.
2427 EngSetLastError(ERROR_SUCCESS
);
2434 ProbeAndCaptureLargeString(
2435 OUT PLARGE_STRING plstrSafe
,
2436 IN PLARGE_STRING plstrUnsafe
)
2438 LARGE_STRING lstrTemp
;
2439 PVOID pvBuffer
= NULL
;
2443 /* Probe and copy the string */
2444 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2445 lstrTemp
= *plstrUnsafe
;
2447 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2450 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2454 if (lstrTemp
.Length
!= 0)
2456 /* Allocate a buffer from paged pool */
2457 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2460 return STATUS_NO_MEMORY
;
2465 /* Probe and copy the buffer */
2466 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2467 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2469 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2471 /* Cleanup and fail */
2472 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2473 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2478 /* Set the output string */
2479 plstrSafe
->Buffer
= pvBuffer
;
2480 plstrSafe
->Length
= lstrTemp
.Length
;
2481 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2483 return STATUS_SUCCESS
;
2487 * \todo Allow passing plstrClassName as ANSI.
2491 NtUserCreateWindowEx(
2493 PLARGE_STRING plstrClassName
,
2494 PLARGE_STRING plstrClsVersion
,
2495 PLARGE_STRING plstrWindowName
,
2503 HINSTANCE hInstance
,
2509 LARGE_STRING lstrWindowName
;
2510 LARGE_STRING lstrClassName
;
2511 LARGE_STRING lstrClsVersion
;
2512 UNICODE_STRING ustrClassName
;
2513 UNICODE_STRING ustrClsVersion
;
2518 lstrWindowName
.Buffer
= NULL
;
2519 lstrClassName
.Buffer
= NULL
;
2520 lstrClsVersion
.Buffer
= NULL
;
2522 ASSERT(plstrWindowName
);
2524 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2526 /* check hMenu is valid handle */
2527 if (hMenu
&& !UserGetMenuObject(hMenu
))
2529 ERR("NtUserCreateWindowEx: Got an invalid menu handle!\n");
2530 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
2535 /* Copy the window name to kernel mode */
2536 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2537 if (!NT_SUCCESS(Status
))
2539 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2540 SetLastNtError(Status
);
2544 plstrWindowName
= &lstrWindowName
;
2546 /* Check if the class is an atom */
2547 if (IS_ATOM(plstrClassName
))
2549 /* It is, pass the atom in the UNICODE_STRING */
2550 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2551 ustrClassName
.Length
= 0;
2552 ustrClassName
.MaximumLength
= 0;
2556 /* It's not, capture the class name */
2557 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2558 if (!NT_SUCCESS(Status
))
2560 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2561 /* Set last error, cleanup and return */
2562 SetLastNtError(Status
);
2566 /* We pass it on as a UNICODE_STRING */
2567 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2568 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2569 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2572 /* Check if the class version is an atom */
2573 if (IS_ATOM(plstrClsVersion
))
2575 /* It is, pass the atom in the UNICODE_STRING */
2576 ustrClsVersion
.Buffer
= (PVOID
)plstrClsVersion
;
2577 ustrClsVersion
.Length
= 0;
2578 ustrClsVersion
.MaximumLength
= 0;
2582 /* It's not, capture the class name */
2583 Status
= ProbeAndCaptureLargeString(&lstrClsVersion
, plstrClsVersion
);
2584 if (!NT_SUCCESS(Status
))
2586 ERR("NtUserCreateWindowEx: failed to capture plstrClsVersion\n");
2587 /* Set last error, cleanup and return */
2588 SetLastNtError(Status
);
2592 /* We pass it on as a UNICODE_STRING */
2593 ustrClsVersion
.Buffer
= lstrClsVersion
.Buffer
;
2594 ustrClsVersion
.Length
= (USHORT
)min(lstrClsVersion
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2595 ustrClsVersion
.MaximumLength
= (USHORT
)min(lstrClsVersion
.MaximumLength
, MAXUSHORT
);
2598 /* Fill the CREATESTRUCTW */
2599 /* we will keep here the original parameters */
2601 Cs
.lpCreateParams
= lpParam
;
2602 Cs
.hInstance
= hInstance
;
2604 Cs
.hwndParent
= hWndParent
;
2609 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2610 Cs
.lpszClass
= ustrClassName
.Buffer
;
2611 Cs
.dwExStyle
= dwExStyle
;
2613 UserEnterExclusive();
2615 /* Call the internal function */
2616 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClsVersion
, plstrWindowName
, acbiBuffer
, dwFlags
);
2620 ERR("co_UserCreateWindowEx failed!\n");
2622 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2627 if (lstrWindowName
.Buffer
)
2629 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2631 if (lstrClassName
.Buffer
)
2633 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2635 if (lstrClsVersion
.Buffer
)
2637 ExFreePoolWithTag(lstrClsVersion
.Buffer
, TAG_STRING
);
2644 BOOLEAN
co_UserDestroyWindow(PVOID Object
)
2650 PWND Window
= Object
;
2652 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2654 hWnd
= Window
->head
.h
;
2655 ti
= PsGetCurrentThreadWin32Thread();
2657 TRACE("co_UserDestroyWindow(Window = 0x%p, hWnd = 0x%p)\n", Window
, hWnd
);
2659 /* Check for owner thread */
2660 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2662 /* Check if we are destroying the desktop window */
2663 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2665 EngSetLastError(ERROR_ACCESS_DENIED
);
2670 /* If window was created successfully and it is hooked */
2671 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2673 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2675 ERR("Destroy Window WH_CBT Call Hook return!\n");
2680 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2682 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2684 if (Window
->spwndOwner
)
2686 //ERR("DestroyWindow Owner out.\n");
2687 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2692 /* Inform the parent */
2693 if (Window
->style
& WS_CHILD
)
2695 IntSendParentNotify(Window
, WM_DESTROY
);
2698 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
2700 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
2703 /* Hide the window */
2704 if (Window
->style
& WS_VISIBLE
)
2706 if (Window
->style
& WS_CHILD
)
2708 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
2709 co_WinPosShowWindow(Window
, SW_HIDE
);
2713 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2717 /* Adjust last active */
2718 if ((pwndTemp
= Window
->spwndOwner
))
2720 while (pwndTemp
->spwndOwner
)
2721 pwndTemp
= pwndTemp
->spwndOwner
;
2723 if (pwndTemp
->spwndLastActive
== Window
)
2724 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2727 if (Window
->spwndParent
&& IntIsWindow(UserHMGetHandle(Window
)))
2729 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2731 if (!IntIsTopLevelWindow(Window
))
2733 //ERR("DestroyWindow Parent out.\n");
2734 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2739 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2740 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2741 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2742 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2743 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2744 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2745 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2746 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2749 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2752 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2754 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2756 ERR("Destroying the ShellWindow!\n");
2757 ti
->pDeskInfo
->hShellWindow
= NULL
;
2761 IntEngWindowChanged(Window
, WOC_DELETE
);
2763 if (!IntIsWindow(UserHMGetHandle(Window
)))
2768 /* Recursively destroy owned windows */
2769 if (!(Window
->style
& WS_CHILD
))
2775 List
= IntWinListOwnedPopups(Window
);
2778 for (phWnd
= List
; *phWnd
; ++phWnd
)
2780 pWnd
= ValidateHwndNoErr(*phWnd
);
2783 ASSERT(pWnd
->spwndOwner
== Window
);
2784 ASSERT(pWnd
!= Window
);
2786 pWnd
->spwndOwner
= NULL
;
2787 if (IntWndBelongsToThread(pWnd
, PsGetCurrentThreadWin32Thread()))
2789 USER_REFERENCE_ENTRY Ref
;
2790 UserRefObjectCo(pWnd
, &Ref
); // Temp HACK?
2791 co_UserDestroyWindow(pWnd
);
2792 UserDerefObjectCo(pWnd
); // Temp HACK?
2796 ERR("IntWndBelongsToThread(0x%p) is FALSE, ignoring.\n", pWnd
);
2800 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2804 /* Generate mouse move message for the next window */
2805 msg
.message
= WM_MOUSEMOVE
;
2806 msg
.wParam
= UserGetMouseButtonsState();
2807 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2808 msg
.pt
= gpsi
->ptCursor
;
2809 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2811 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2813 /* Send destroy messages */
2814 IntSendDestroyMsg(UserHMGetHandle(Window
));
2816 if (!IntIsWindow(UserHMGetHandle(Window
)))
2821 /* Destroy the window storage */
2822 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2832 NtUserDestroyWindow(HWND Wnd
)
2835 DECLARE_RETURN(BOOLEAN
);
2837 USER_REFERENCE_ENTRY Ref
;
2839 TRACE("Enter NtUserDestroyWindow\n");
2840 UserEnterExclusive();
2842 if (!(Window
= UserGetWindowObject(Wnd
)))
2847 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2848 ret
= co_UserDestroyWindow(Window
);
2849 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2854 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2860 static HWND FASTCALL
2861 IntFindWindow(PWND Parent
,
2864 PUNICODE_STRING WindowName
)
2866 BOOL CheckWindowName
;
2869 UNICODE_STRING CurrentWindowName
;
2873 CheckWindowName
= WindowName
->Buffer
!= 0;
2875 if((List
= IntWinListChildren(Parent
)))
2880 /* skip handles before and including ChildAfter */
2881 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2885 /* search children */
2889 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2894 /* Do not send WM_GETTEXT messages in the kernel mode version!
2895 The user mode version however calls GetWindowText() which will
2896 send WM_GETTEXT messages to windows belonging to its processes */
2897 if (!ClassAtom
|| Child
->pcls
->atomNVClassName
== ClassAtom
)
2899 // FIXME: LARGE_STRING truncated
2900 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2901 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2902 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2903 if(!CheckWindowName
||
2904 (Child
->strName
.Length
< 0xFFFF &&
2905 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2907 Ret
= Child
->head
.h
;
2912 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2920 * Searches a window's children for a window with the specified
2923 * hwndParent = The window whose childs are to be searched.
2925 * HWND_MESSAGE = message-only windows
2927 * hwndChildAfter = Search starts after this child window.
2928 * NULL = start from beginning
2930 * ucClassName = Class name to search for
2931 * Reguired parameter.
2933 * ucWindowName = Window name
2934 * ->Buffer == NULL = don't care
2937 * The HWND of the window if it was found, otherwise NULL
2943 NtUserFindWindowEx(HWND hwndParent
,
2944 HWND hwndChildAfter
,
2945 PUNICODE_STRING ucClassName
,
2946 PUNICODE_STRING ucWindowName
,
2949 PWND Parent
, ChildAfter
;
2950 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2951 HWND Desktop
, Ret
= NULL
;
2952 BOOL DoMessageWnd
= FALSE
;
2953 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2954 DECLARE_RETURN(HWND
);
2956 TRACE("Enter NtUserFindWindowEx\n");
2959 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2963 if (ucClassName
!= NULL
)
2965 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2966 if (ClassName
.Length
!= 0)
2968 ProbeForRead(ClassName
.Buffer
,
2972 else if (!IS_ATOM(ClassName
.Buffer
))
2974 EngSetLastError(ERROR_INVALID_PARAMETER
);
2978 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2981 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
2986 if (ucWindowName
!= NULL
)
2988 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2989 if (WindowName
.Length
!= 0)
2991 ProbeForRead(WindowName
.Buffer
,
2997 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2999 SetLastNtError(_SEH2_GetExceptionCode());
3000 _SEH2_YIELD(RETURN(NULL
));
3004 if (ucClassName
!= NULL
)
3006 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
3007 !IS_ATOM(ClassName
.Buffer
))
3009 EngSetLastError(ERROR_INVALID_PARAMETER
);
3012 else if (ClassAtom
== (RTL_ATOM
)0)
3014 /* LastError code was set by IntGetAtomFromStringOrAtom */
3020 Desktop
= IntGetCurrentThreadDesktopWindow();
3022 if(hwndParent
== NULL
)
3024 hwndParent
= Desktop
;
3025 DoMessageWnd
= TRUE
;
3027 else if(hwndParent
== HWND_MESSAGE
)
3029 hwndParent
= IntGetMessageWindow();
3032 if(!(Parent
= UserGetWindowObject(hwndParent
)))
3038 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
3045 if(Parent
->head
.h
== Desktop
)
3048 PWND TopLevelWindow
;
3049 BOOLEAN CheckWindowName
;
3050 BOOLEAN WindowMatches
;
3051 BOOLEAN ClassMatches
;
3053 /* windows searches through all top-level windows if the parent is the desktop
3056 if((List
= IntWinListChildren(Parent
)))
3062 /* skip handles before and including ChildAfter */
3063 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
3067 CheckWindowName
= WindowName
.Buffer
!= 0;
3069 /* search children */
3072 UNICODE_STRING ustr
;
3074 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
3079 /* Do not send WM_GETTEXT messages in the kernel mode version!
3080 The user mode version however calls GetWindowText() which will
3081 send WM_GETTEXT messages to windows belonging to its processes */
3082 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
3083 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
3084 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
3085 WindowMatches
= !CheckWindowName
||
3086 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
3087 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
3088 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
3089 ClassAtom
== TopLevelWindow
->pcls
->atomNVClassName
;
3091 if (WindowMatches
&& ClassMatches
)
3093 Ret
= TopLevelWindow
->head
.h
;
3097 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3099 /* window returns the handle of the top-level window, in case it found
3101 Ret
= TopLevelWindow
->head
.h
;
3106 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3111 TRACE("FindWindowEx: Not Desktop Parent!\n");
3112 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3115 if (Ret
== NULL
&& DoMessageWnd
)
3119 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3121 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3125 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3127 SetLastNtError(_SEH2_GetExceptionCode());
3135 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3144 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3146 PWND WndAncestor
, Parent
;
3148 if (Wnd
->head
.h
== IntGetDesktopWindow())
3157 WndAncestor
= Wnd
->spwndParent
;
3168 if(!(Parent
= WndAncestor
->spwndParent
))
3172 if(IntIsDesktopWindow(Parent
))
3177 WndAncestor
= Parent
;
3188 Parent
= IntGetParent(WndAncestor
);
3195 WndAncestor
= Parent
;
3213 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3215 PWND Window
, Ancestor
;
3216 DECLARE_RETURN(HWND
);
3218 TRACE("Enter NtUserGetAncestor\n");
3219 UserEnterExclusive();
3221 if (!(Window
= UserGetWindowObject(hWnd
)))
3226 Ancestor
= UserGetAncestor(Window
, Type
);
3227 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3229 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3232 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3238 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3240 /* combo state struct */
3254 INT fixedOwnerDrawHeight
;
3255 INT droppedWidth
; /* last two are not used unless set */
3256 INT editHeight
; /* explicitly */
3258 } HEADCOMBO
,*LPHEADCOMBO
;
3260 // Window Extra data container.
3261 typedef struct _WND2CBOX
3265 } WND2CBOX
, *PWND2CBOX
;
3267 #define CBF_BUTTONDOWN 0x0002
3273 NtUserGetComboBoxInfo(
3279 BOOL NotSameppi
= FALSE
;
3281 DECLARE_RETURN(BOOL
);
3283 TRACE("Enter NtUserGetComboBoxInfo\n");
3286 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3292 ProbeForWrite(pcbi
, sizeof(COMBOBOXINFO
), 1);
3294 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3296 SetLastNtError(_SEH2_GetExceptionCode());
3297 _SEH2_YIELD(RETURN(FALSE
));
3301 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3303 EngSetLastError(ERROR_INVALID_PARAMETER
);
3307 // Pass the user pointer, it was already probed.
3308 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3310 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3313 ppi
= PsGetCurrentProcessWin32Process();
3314 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3317 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3322 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3323 pcbi
->rcItem
= lphc
->textRect
;
3324 pcbi
->rcButton
= lphc
->buttonRect
;
3325 pcbi
->stateButton
= 0;
3326 if (lphc
->wState
& CBF_BUTTONDOWN
)
3327 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3328 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3329 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3330 pcbi
->hwndCombo
= lphc
->self
;
3331 pcbi
->hwndItem
= lphc
->hWndEdit
;
3332 pcbi
->hwndList
= lphc
->hWndLBox
;
3334 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3337 SetLastNtError(_SEH2_GetExceptionCode());
3344 if (NotSameppi
) KeDetachProcess();
3345 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3351 //// ReactOS work around! Keep it the sames as in Listbox.c
3353 /* Listbox structure */
3356 HWND self
; /* Our own window handle */
3357 HWND owner
; /* Owner window to send notifications to */
3358 UINT style
; /* Window style */
3359 INT width
; /* Window width */
3360 INT height
; /* Window height */
3361 VOID
*items
; /* Array of items */
3362 INT nb_items
; /* Number of items */
3363 INT top_item
; /* Top visible item */
3364 INT selected_item
; /* Selected item */
3365 INT focus_item
; /* Item that has the focus */
3366 INT anchor_item
; /* Anchor item for extended selection */
3367 INT item_height
; /* Default item height */
3368 INT page_size
; /* Items per listbox page */
3369 INT column_width
; /* Column width for multi-column listboxes */
3372 // Window Extra data container.
3373 typedef struct _WND2LB
3383 NtUserGetListBoxInfo(
3388 BOOL NotSameppi
= FALSE
;
3390 DECLARE_RETURN(DWORD
);
3392 TRACE("Enter NtUserGetListBoxInfo\n");
3395 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3400 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3402 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3405 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3406 ppi
= PsGetCurrentProcessWin32Process();
3407 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3410 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3415 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3416 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3417 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3418 Ret
= descr
->page_size
* descr
->column_width
;
3420 Ret
= descr
->page_size
;
3422 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3425 SetLastNtError(_SEH2_GetExceptionCode());
3432 if (NotSameppi
) KeDetachProcess();
3433 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3441 * The NtUserSetParent function changes the parent window of the specified
3445 * The new parent window and the child window must belong to the same
3446 * application. If the window identified by the hWndChild parameter is
3447 * visible, the system performs the appropriate redrawing and repainting.
3448 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3449 * or WS_POPUP window styles of the window whose parent is being changed.
3456 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3458 DECLARE_RETURN(HWND
);
3460 TRACE("Enter NtUserSetParent\n");
3461 UserEnterExclusive();
3464 Check Parent first from user space, set it here.
3468 hWndNewParent
= IntGetDesktopWindow();
3470 else if (hWndNewParent
== HWND_MESSAGE
)
3472 hWndNewParent
= IntGetMessageWindow();
3475 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3478 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3484 * UserGetShellWindow
3486 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3491 HWND FASTCALL
UserGetShellWindow(VOID
)
3493 PWINSTATION_OBJECT WinStaObject
;
3496 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3502 if (!NT_SUCCESS(Status
))
3504 SetLastNtError(Status
);
3508 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3510 ObDereferenceObject(WinStaObject
);
3515 * NtUserSetShellWindowEx
3517 * This is undocumented function to set global shell window. The global
3518 * shell window has special handling of window position.
3524 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3526 PWINSTATION_OBJECT WinStaObject
;
3527 PWND WndShell
, WndListView
;
3528 DECLARE_RETURN(BOOL
);
3529 USER_REFERENCE_ENTRY Ref
;
3533 TRACE("Enter NtUserSetShellWindowEx\n");
3534 UserEnterExclusive();
3536 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3541 if (!(WndListView
= UserGetWindowObject(hwndListView
)))
3546 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3552 if (!NT_SUCCESS(Status
))
3554 SetLastNtError(Status
);
3559 * Test if we are permitted to change the shell window.
3561 if (WinStaObject
->ShellWindow
)
3563 ObDereferenceObject(WinStaObject
);
3568 * Move shell window into background.
3570 if (hwndListView
&& hwndListView
!= hwndShell
)
3573 * Disabled for now to get Explorer working.
3574 * -- Filip, 01/nov/2003
3577 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3580 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3582 ObDereferenceObject(WinStaObject
);
3587 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3589 ObDereferenceObject(WinStaObject
);
3593 UserRefObjectCo(WndShell
, &Ref
);
3594 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3595 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3597 WinStaObject
->ShellWindow
= hwndShell
;
3598 WinStaObject
->ShellListView
= hwndListView
;
3600 ti
= GetW32ThreadInfo();
3603 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3604 ti
->pDeskInfo
->spwndShell
= WndShell
;
3605 ti
->pDeskInfo
->spwndBkGnd
= WndListView
;
3606 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3609 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3611 UserDerefObjectCo(WndShell
);
3613 ObDereferenceObject(WinStaObject
);
3617 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3622 // Fixes wine Win test_window_styles and todo tests...
3623 static BOOL FASTCALL
3624 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3626 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3628 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3635 co_IntSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
, ULONG Size
, BOOL bAlter
)
3637 PWND Window
, Parent
;
3638 PWINSTATION_OBJECT WindowStation
;
3642 if (!(Window
= UserGetWindowObject(hWnd
)))
3647 if ((INT
)Index
>= 0)
3649 if ((Index
+ Size
) > Window
->cbwndExtra
)
3651 EngSetLastError(ERROR_INVALID_INDEX
);
3656 if (Size
== sizeof(LONG
))
3658 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3659 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = (LONG
)NewValue
;
3664 OldValue
= *((LONG_PTR
*)((PCHAR
)(Window
+ 1) + Index
));
3666 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3668 OldValue = (LONG_PTR)IntSetWindowProc( Wnd, (WNDPROC)NewValue, Ansi);
3669 if (!OldValue) return 0;
3672 *((LONG_PTR
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3679 if (Size
== sizeof(LONG
))
3681 if ((Index
!= GWL_STYLE
) &&
3682 (Index
!= GWL_EXSTYLE
) &&
3683 (Index
!= GWL_ID
) &&
3684 (Index
!= GWL_USERDATA
))
3686 ERR("NtUserSetWindowLong(): Index requires pointer size: %lu\n", Index
);
3687 EngSetLastError(ERROR_INVALID_INDEX
);
3695 case GWL_EXSTYLE
: // LONG
3696 OldValue
= (LONG
) Window
->ExStyle
;
3697 Style
.styleOld
= OldValue
;
3698 Style
.styleNew
= NewValue
;
3700 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3703 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3705 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3708 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3709 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3711 /* WS_EX_WINDOWEDGE depends on some other styles */
3712 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3713 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3715 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3717 if (!(Window
->ExStyle
& WS_EX_LAYERED
))
3719 SetLayeredStatus(Window
, 0);
3722 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3724 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3727 case GWL_STYLE
: // LONG
3728 OldValue
= (LONG
) Window
->style
;
3729 Style
.styleOld
= OldValue
;
3730 Style
.styleNew
= NewValue
;
3733 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3735 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3736 if (UserIsDesktopWindow(Window
->spwndParent
)) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3737 /* WS_MINIMIZE can't be reset */
3738 if (OldValue
& WS_MINIMIZE
) Style
.styleNew
|= WS_MINIMIZE
;
3739 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3740 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3741 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3743 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3745 if ((OldValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3747 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
3749 //// From child to non-child it should be null already.
3750 ERR("IDMenu going null! %d\n",Window
->IDMenu
);
3751 Window
->IDMenu
= 0; // Window->spmenu = 0;
3756 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3758 PMENU pMenu
= UserGetMenuObject(UlongToHandle(Window
->IDMenu
));
3759 Window
->state
&= ~WNDS_HASMENU
;
3762 ERR("IDMenu released 0x%p\n",pMenu
);
3763 // ROS may not hold a lock after setting menu to window. But it should!
3764 //IntReleaseMenuObject(pMenu);
3769 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3771 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3772 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3773 DceResetActiveDCEs( Window
);
3775 Window
->style
= (DWORD
)Style
.styleNew
;
3778 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3781 case GWLP_WNDPROC
: // LONG_PTR
3783 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3784 Window
->fnid
& FNID_FREED
)
3786 EngSetLastError(ERROR_ACCESS_DENIED
);
3789 OldValue
= (LONG_PTR
)IntSetWindowProc(Window
,
3795 case GWLP_HINSTANCE
: // LONG_PTR
3796 OldValue
= (LONG_PTR
) Window
->hModule
;
3797 Window
->hModule
= (HINSTANCE
) NewValue
;
3800 case GWLP_HWNDPARENT
: // LONG_PTR
3801 Parent
= Window
->spwndParent
;
3802 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3803 OldValue
= (LONG_PTR
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3805 OldValue
= (LONG_PTR
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3808 case GWLP_ID
: // LONG
3809 OldValue
= (LONG
) Window
->IDMenu
;
3810 Window
->IDMenu
= (UINT
) NewValue
;
3813 case GWLP_USERDATA
: // LONG or LONG_PTR
3814 OldValue
= Window
->dwUserData
;
3815 Window
->dwUserData
= NewValue
;
3819 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3820 EngSetLastError(ERROR_INVALID_INDEX
);
3830 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3832 return (LONG
)co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG
), FALSE
);
3836 co_UserSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
)
3838 return co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG_PTR
), FALSE
);
3842 * NtUserSetWindowLong
3844 * The NtUserSetWindowLong function changes an attribute of the specified
3845 * window. The function also sets the 32-bit (long) value at the specified
3846 * offset into the extra window memory.
3853 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3857 UserEnterExclusive();
3859 if (hWnd
== IntGetDesktopWindow())
3861 EngSetLastError(STATUS_ACCESS_DENIED
);
3866 ret
= (LONG
)co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG
), FALSE
);
3875 NtUserSetWindowLongPtr(HWND hWnd
, DWORD Index
, LONG_PTR NewValue
, BOOL Ansi
)
3879 UserEnterExclusive();
3881 if (hWnd
== IntGetDesktopWindow())
3883 EngSetLastError(STATUS_ACCESS_DENIED
);
3888 ret
= co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, Ansi
, sizeof(LONG_PTR
), FALSE
);
3897 NtUserAlterWindowStyle(HWND hWnd
, DWORD Index
, LONG NewValue
)
3901 UserEnterExclusive();
3903 if (hWnd
== IntGetDesktopWindow())
3905 EngSetLastError(STATUS_ACCESS_DENIED
);
3910 ret
= co_IntSetWindowLongPtr(hWnd
, Index
, NewValue
, FALSE
, sizeof(LONG
), TRUE
);
3919 * NtUserSetWindowWord
3921 * Legacy function similar to NtUserSetWindowLong.
3928 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3932 DECLARE_RETURN(WORD
);
3934 TRACE("Enter NtUserSetWindowWord\n");
3935 UserEnterExclusive();
3937 if (hWnd
== IntGetDesktopWindow())
3939 EngSetLastError(STATUS_ACCESS_DENIED
);
3943 if (!(Window
= UserGetWindowObject(hWnd
)))
3952 case GWL_HWNDPARENT
:
3953 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3957 EngSetLastError(ERROR_INVALID_INDEX
);
3962 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3964 EngSetLastError(ERROR_INVALID_PARAMETER
);
3968 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3969 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3974 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3980 QueryWindow based on KJK::Hyperion and James Tabor.
3982 0 = QWUniqueProcessId
3983 1 = QWUniqueThreadId
3986 4 = QWIsHung Implements IsHungAppWindow found
3989 9 = QWKillWindow When I called this with hWnd ==
3990 DesktopWindow, it shutdown the system
3997 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3999 /* Console Leader Process CID Window offsets */
4000 #define GWLP_CONSOLE_LEADER_PID 0
4001 #define GWLP_CONSOLE_LEADER_TID 4
4005 DECLARE_RETURN(UINT
);
4007 TRACE("Enter NtUserQueryWindow\n");
4010 if (!(pWnd
= UserGetWindowObject(hWnd
)))
4017 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
4019 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
4020 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
4022 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
4023 Result
= (DWORD_PTR
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
4027 Result
= (DWORD_PTR
)IntGetWndProcessId(pWnd
);
4032 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
4034 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
4035 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
4037 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
4038 Result
= (DWORD_PTR
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
4042 Result
= (DWORD_PTR
)IntGetWndThreadId(pWnd
);
4047 case QUERY_WINDOW_ACTIVE
:
4048 Result
= (DWORD_PTR
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
4051 case QUERY_WINDOW_FOCUS
:
4052 Result
= (DWORD_PTR
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
4055 case QUERY_WINDOW_ISHUNG
:
4056 Result
= (DWORD_PTR
)MsqIsHung(pWnd
->head
.pti
);
4059 case QUERY_WINDOW_REAL_ID
:
4060 Result
= (DWORD_PTR
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
4063 case QUERY_WINDOW_FOREGROUND
:
4064 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
4075 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
4084 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
4086 UNICODE_STRING SafeMessageName
;
4089 DECLARE_RETURN(UINT
);
4091 TRACE("Enter NtUserRegisterWindowMessage\n");
4092 UserEnterExclusive();
4094 if(MessageNameUnsafe
== NULL
)
4096 EngSetLastError(ERROR_INVALID_PARAMETER
);
4100 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
4101 if(!NT_SUCCESS(Status
))
4103 SetLastNtError(Status
);
4107 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
4108 if (SafeMessageName
.Buffer
)
4109 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
4113 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
4122 NtUserSetWindowFNID(HWND hWnd
,
4126 DECLARE_RETURN(BOOL
);
4128 TRACE("Enter NtUserSetWindowFNID\n");
4129 UserEnterExclusive();
4131 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4136 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
4138 EngSetLastError(ERROR_ACCESS_DENIED
);
4142 // From user land we only set these.
4143 if (fnID
!= FNID_DESTROY
)
4145 /* HACK: The minimum should be FNID_BUTTON, but menu code relies on this */
4146 if (fnID
< FNID_FIRST
|| fnID
> FNID_GHOST
||
4149 EngSetLastError(ERROR_INVALID_PARAMETER
);
4158 TRACE("Leave NtUserSetWindowFNID\n");
4164 DefSetText(PWND Wnd
, PCWSTR WindowText
)
4166 UNICODE_STRING UnicodeString
;
4169 RtlInitUnicodeString(&UnicodeString
, WindowText
);
4171 if (UnicodeString
.Length
!= 0)
4173 if (Wnd
->strName
.MaximumLength
> 0 &&
4174 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4176 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4178 Wnd
->strName
.Length
= UnicodeString
.Length
;
4179 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4180 RtlCopyMemory(Wnd
->strName
.Buffer
,
4181 UnicodeString
.Buffer
,
4182 UnicodeString
.Length
);
4187 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4188 buf
= Wnd
->strName
.Buffer
;
4189 Wnd
->strName
.Buffer
= NULL
;
4192 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4195 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4196 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4197 if (Wnd
->strName
.Buffer
!= NULL
)
4199 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4200 RtlCopyMemory(Wnd
->strName
.Buffer
,
4201 UnicodeString
.Buffer
,
4202 UnicodeString
.Length
);
4203 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4204 Wnd
->strName
.Length
= UnicodeString
.Length
;
4208 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4215 Wnd
->strName
.Length
= 0;
4216 if (Wnd
->strName
.Buffer
!= NULL
)
4217 Wnd
->strName
.Buffer
[0] = L
'\0';
4220 // FIXME: HAX! Windows does not do this in here!
4221 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4222 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4223 /* Send shell notifications */
4224 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4226 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) UserHMGetHandle(Wnd
), FALSE
); // FIXME Flashing?
4231 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4238 * Undocumented function that is called from DefWindowProc to set
4245 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4248 LARGE_STRING SafeText
;
4249 UNICODE_STRING UnicodeString
;
4252 TRACE("Enter NtUserDefSetText\n");
4254 if (WindowText
!= NULL
)
4258 SafeText
= ProbeForReadLargeString(WindowText
);
4260 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4263 SetLastNtError(_SEH2_GetExceptionCode());
4273 UserEnterExclusive();
4275 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4281 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4282 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4283 // Now we know what the bAnsi is for.
4284 RtlInitUnicodeString(&UnicodeString
, NULL
);
4285 if (SafeText
.Buffer
)
4290 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4292 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4293 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4295 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4298 SetLastNtError(_SEH2_GetExceptionCode());
4301 if (!Ret
) goto Exit
;
4304 if (UnicodeString
.Length
!= 0)
4306 if (Wnd
->strName
.MaximumLength
> 0 &&
4307 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4309 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4311 Wnd
->strName
.Length
= UnicodeString
.Length
;
4312 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4313 RtlCopyMemory(Wnd
->strName
.Buffer
,
4314 UnicodeString
.Buffer
,
4315 UnicodeString
.Length
);
4320 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4321 buf
= Wnd
->strName
.Buffer
;
4322 Wnd
->strName
.Buffer
= NULL
;
4325 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4328 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4329 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4330 if (Wnd
->strName
.Buffer
!= NULL
)
4332 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4333 RtlCopyMemory(Wnd
->strName
.Buffer
,
4334 UnicodeString
.Buffer
,
4335 UnicodeString
.Length
);
4336 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4337 Wnd
->strName
.Length
= UnicodeString
.Length
;
4341 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4349 Wnd
->strName
.Length
= 0;
4350 if (Wnd
->strName
.Buffer
!= NULL
)
4351 Wnd
->strName
.Buffer
[0] = L
'\0';
4354 // FIXME: HAX! Windows does not do this in here!
4355 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4356 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4357 /* Send shell notifications */
4358 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4360 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4365 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4366 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4372 * NtUserInternalGetWindowText
4379 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4384 DECLARE_RETURN(INT
);
4386 TRACE("Enter NtUserInternalGetWindowText\n");
4389 if(lpString
&& (nMaxCount
<= 1))
4391 EngSetLastError(ERROR_INVALID_PARAMETER
);
4395 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4400 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4403 const WCHAR Terminator
= L
'\0';
4405 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4407 Copy
= min(nMaxCount
- 1, Result
);
4410 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4411 if(!NT_SUCCESS(Status
))
4413 SetLastNtError(Status
);
4419 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4420 if(!NT_SUCCESS(Status
))
4422 SetLastNtError(Status
);
4432 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4442 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4448 // ASSERT(OwnerWnd);
4450 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4452 /* NOTE: Popups are not children */
4453 win_array
= IntWinListOwnedPopups(OwnerWnd
);
4458 while (win_array
[count
])
4460 while (--count
>= 0)
4462 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4464 if (pWnd
->spwndOwner
!= OwnerWnd
)
4469 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4471 /* In Windows, ShowOwnedPopups(TRUE) generates
4472 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4473 * regardless of the state of the owner
4475 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4476 pWnd
->state
&= ~WNDS_HIDDENPOPUP
;
4482 if (pWnd
->style
& WS_VISIBLE
)
4484 /* In Windows, ShowOwnedPopups(FALSE) generates
4485 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4486 * regardless of the state of the owner
4488 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4489 pWnd
->state
|= WNDS_HIDDENPOPUP
;
4494 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4495 TRACE("Leave ShowOwnedPopups\n");