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
)
69 if (!pWnd
) return NULL
;
73 hWnd
= UserHMGetHandle(pWnd
);
75 State2
= pWnd
->state2
;
77 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
79 _SEH2_YIELD(return NULL
);
83 if ( UserObjectInDestroy(hWnd
) ||
84 State
& WNDS_DESTROYED
||
85 State2
& WNDS2_INDESTROY
)
91 PWND FASTCALL
ValidateHwndNoErr(HWND hWnd
)
93 if (hWnd
) return (PWND
)UserGetObjectNoErr(gHandleTable
, hWnd
, TYPE_WINDOW
);
98 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
104 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
108 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, TYPE_WINDOW
);
109 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
111 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
119 IntSetStyle( PWND pwnd
, ULONG set_bits
, ULONG clear_bits
)
121 ULONG styleOld
, styleNew
;
122 styleOld
= pwnd
->style
;
123 styleNew
= (pwnd
->style
| set_bits
) & ~clear_bits
;
124 if (styleNew
== styleOld
) return styleNew
;
125 pwnd
->style
= styleNew
;
126 if ((styleOld
^ styleNew
) & WS_VISIBLE
) // State Change.
128 if (styleOld
& WS_VISIBLE
) pwnd
->head
.pti
->cVisWindows
--;
129 if (styleNew
& WS_VISIBLE
) pwnd
->head
.pti
->cVisWindows
++;
130 DceResetActiveDCEs( pwnd
);
138 * The function determines whether the specified window handle identifies
139 * an existing window.
143 * Handle to the window to test.
146 * If the window handle identifies an existing window, the return value
147 * is TRUE. If the window handle does not identify an existing window,
148 * the return value is FALSE.
152 IntIsWindow(HWND hWnd
)
156 if (!(Window
= UserGetWindowObject(hWnd
)))
165 IntIsWindowVisible(PWND Wnd
)
170 if (!Temp
) return TRUE
;
171 if (!(Temp
->style
& WS_VISIBLE
)) break;
172 if (Temp
->style
& WS_MINIMIZE
&& Temp
!= Wnd
) break;
173 if (Temp
->fnid
== FNID_DESKTOP
) return TRUE
;
174 Temp
= Temp
->spwndParent
;
180 IntGetParent(PWND Wnd
)
182 if (Wnd
->style
& WS_POPUP
)
184 return Wnd
->spwndOwner
;
186 else if (Wnd
->style
& WS_CHILD
)
188 return Wnd
->spwndParent
;
196 IntEnableWindow( HWND hWnd
, BOOL bEnable
)
202 if(!(pWnd
= UserGetWindowObject(hWnd
)))
207 /* check if updating is needed */
208 bIsDisabled
= !!(pWnd
->style
& WS_DISABLED
);
209 Update
= bIsDisabled
;
213 IntSetStyle( pWnd
, 0, WS_DISABLED
);
217 Update
= !bIsDisabled
;
219 co_IntSendMessage( hWnd
, WM_CANCELMODE
, 0, 0);
221 /* Remove keyboard focus from that window if it had focus */
222 if (hWnd
== IntGetThreadFocusWindow())
224 TRACE("IntEnableWindow SF NULL\n");
225 co_UserSetFocus(NULL
);
227 IntSetStyle( pWnd
, WS_DISABLED
, 0 );
232 IntNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, pWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
233 co_IntSendMessage(hWnd
, WM_ENABLE
, (LPARAM
)bEnable
, 0);
235 // Return nonzero if it was disabled, or zero if it wasn't:
242 * Compile a list of all child window handles from given window.
245 * This function is similar to Wine WIN_ListChildren. The caller
246 * must free the returned list with ExFreePool.
250 IntWinListChildren(PWND Window
)
254 UINT Index
, NumChildren
= 0;
256 if (!Window
) return NULL
;
258 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
261 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
264 ERR("Failed to allocate memory for children array\n");
265 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
268 for (Child
= Window
->spwndChild
, Index
= 0;
270 Child
= Child
->spwndNext
, ++Index
)
271 List
[Index
] = Child
->head
.h
;
278 IntGetNonChildAncestor(PWND pWnd
)
280 while(pWnd
&& (pWnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
281 pWnd
= pWnd
->spwndParent
;
286 IntIsTopLevelWindow(PWND pWnd
)
288 if ( pWnd
->spwndParent
&&
289 pWnd
->spwndParent
== co_GetDesktopWindow(pWnd
) ) return TRUE
;
294 IntValidateOwnerDepth(PWND Wnd
, PWND Owner
)
299 if ( !Owner
) return gNestedWindowLimit
>= Depth
;
300 if (Owner
== Wnd
) break;
301 Owner
= Owner
->spwndOwner
;
308 IntGetWindow(HWND hWnd
,
314 Wnd
= ValidateHwndNoErr(hWnd
);
322 if (Wnd
->spwndOwner
!= NULL
)
323 FoundWnd
= Wnd
->spwndOwner
;
327 if(Wnd
->spwndParent
!= NULL
)
329 FoundWnd
= Wnd
->spwndParent
;
330 if (FoundWnd
->spwndChild
!= NULL
)
331 FoundWnd
= FoundWnd
->spwndChild
;
335 if (Wnd
->spwndNext
!= NULL
)
336 FoundWnd
= Wnd
->spwndNext
;
340 if (Wnd
->spwndPrev
!= NULL
)
341 FoundWnd
= Wnd
->spwndPrev
;
345 if (Wnd
->spwndChild
!= NULL
)
346 FoundWnd
= Wnd
->spwndChild
;
351 while ( FoundWnd
->spwndNext
!= NULL
)
352 FoundWnd
= FoundWnd
->spwndNext
;
360 if (FoundWnd
!= NULL
)
361 Ret
= UserHMGetHandle(FoundWnd
);
365 /***********************************************************************
368 static void IntSendDestroyMsg(HWND hWnd
)
373 ti
= PsGetCurrentThreadWin32Thread();
374 Window
= UserGetWindowObject(hWnd
);
378 /* Look whether the focus is within the tree of windows we will
382 if ( ti
->MessageQueue
->spwndActive
== Window
|| // Fixes CORE-106 RegSvr32 exit and return focus to CMD.
383 (ti
->MessageQueue
->spwndActive
== NULL
&& ti
->MessageQueue
== IntGetFocusMessageQueue()) )
385 co_WinPosActivateOtherWindow(Window
);
388 /* Fixes CMD properties closing and returning focus to CMD */
389 if (ti
->MessageQueue
->spwndFocus
== Window
)
391 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
393 co_UserSetFocus(Window
->spwndParent
);
397 co_UserSetFocus(NULL
);
401 if (ti
->MessageQueue
->CaretInfo
->hWnd
== UserHMGetHandle(Window
))
403 co_IntDestroyCaret(ti
);
408 * Send the WM_DESTROY to the window.
411 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
414 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
415 * make sure that the window still exists when we come back.
418 if (IntIsWindow(hWnd
))
423 if (!(pWndArray
= IntWinListChildren( Window
))) return;
425 for (i
= 0; pWndArray
[i
]; i
++)
427 if (IntIsWindow( pWndArray
[i
] )) IntSendDestroyMsg( pWndArray
[i
] );
429 ExFreePoolWithTag(pWndArray
, USERTAG_WINDOWLIST
);
433 TRACE("destroyed itself while in WM_DESTROY!\n");
438 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
440 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
444 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
446 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
447 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
450 if (Wnd
->strName
.Buffer
!= NULL
)
452 Wnd
->strName
.Length
= 0;
453 Wnd
->strName
.MaximumLength
= 0;
454 DesktopHeapFree(Wnd
->head
.rpdesk
,
455 Wnd
->strName
.Buffer
);
456 Wnd
->strName
.Buffer
= NULL
;
459 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
460 // WindowObject->hWnd = NULL;
463 /***********************************************************************
466 * Destroy storage associated to a window. "Internals" p.358
468 * This is the "functional" DestroyWindows function ei. all stuff
469 * done in CreateWindow is undone here and not in DestroyWindow:-P
472 LRESULT
co_UserFreeWindow(PWND Window
,
473 PPROCESSINFO ProcessData
,
474 PTHREADINFO ThreadData
,
475 BOOLEAN SendMessages
)
481 BOOLEAN BelongsToThreadData
;
485 if(Window
->state2
& WNDS2_INDESTROY
)
487 TRACE("Tried to call IntDestroyWindow() twice\n");
490 Window
->state2
|= WNDS2_INDESTROY
;
491 Window
->style
&= ~WS_VISIBLE
;
492 Window
->head
.pti
->cVisWindows
--;
495 /* remove the window already at this point from the thread window list so we
496 don't get into trouble when destroying the thread windows while we're still
497 in IntDestroyWindow() */
498 RemoveEntryList(&Window
->ThreadListEntry
);
500 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
502 IntDeRegisterShellHookWindow(UserHMGetHandle(Window
));
504 /* free child windows */
505 Children
= IntWinListChildren(Window
);
508 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
510 if ((Child
= IntGetWindowObject(*ChildHandle
)))
512 if(!IntWndBelongsToThread(Child
, ThreadData
))
514 /* send WM_DESTROY messages to windows not belonging to the same thread */
515 co_IntSendMessage( UserHMGetHandle(Child
), WM_ASYNC_DESTROYWINDOW
, 0, 0 );
518 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
520 UserDereferenceObject(Child
);
523 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
529 * Clear the update region to make sure no WM_PAINT messages will be
530 * generated for this window while processing the WM_NCDESTROY.
532 co_UserRedrawWindow(Window
, NULL
, 0,
533 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
534 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
535 if(BelongsToThreadData
)
536 co_IntSendMessage(UserHMGetHandle(Window
), WM_NCDESTROY
, 0, 0);
539 DestroyTimersForWindow(ThreadData
, Window
);
541 /* Unregister hot keys */
542 UnregisterWindowHotKeys(Window
);
544 /* flush the message queue */
545 MsqRemoveWindowMessagesFromQueue(Window
);
547 /* from now on no messages can be sent to this window anymore */
548 Window
->state
|= WNDS_DESTROYED
;
549 Window
->fnid
|= FNID_FREED
;
551 /* don't remove the WINDOWSTATUS_DESTROYING bit */
553 /* reset shell window handles */
554 if(ThreadData
->rpdesk
)
556 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
557 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
559 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
560 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
563 /* Fixes dialog test_focus breakage due to r66237. */
564 if (ThreadData
->MessageQueue
->spwndFocus
== Window
)
565 ThreadData
->MessageQueue
->spwndFocus
= NULL
;
567 if (ThreadData
->MessageQueue
->spwndActive
== Window
)
568 ThreadData
->MessageQueue
->spwndActive
= NULL
;
570 if (ThreadData
->MessageQueue
->spwndCapture
== Window
)
575 //// Now kill those remaining "PAINTING BUG: Thread marked as containing dirty windows" spam!!!
576 if ( Window
->hrgnUpdate
!= NULL
|| Window
->state
& WNDS_INTERNALPAINT
)
578 MsqDecPaintCountQueue(Window
->head
.pti
);
579 if (Window
->hrgnUpdate
> HRGN_WINDOW
&& GreIsHandleValid(Window
->hrgnUpdate
))
581 GreDeleteObject(Window
->hrgnUpdate
);
583 Window
->hrgnUpdate
= NULL
;
584 Window
->state
&= ~WNDS_INTERNALPAINT
;
587 if (Window
->state
& (WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
))
589 Window
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
);
592 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
594 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
596 IntDestroyMenuObject(Menu
, TRUE
);
600 if(Window
->SystemMenu
601 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
603 IntDestroyMenuObject(Menu
, TRUE
);
604 Window
->SystemMenu
= (HMENU
)0;
607 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
609 IntUnlinkWindow(Window
);
611 if (Window
->PropListItems
)
613 IntRemoveWindowProp(Window
);
614 TRACE("Window->PropListItems %lu\n",Window
->PropListItems
);
615 ASSERT(Window
->PropListItems
==0);
618 UserReferenceObject(Window
);
619 UserDeleteObject(UserHMGetHandle(Window
), TYPE_WINDOW
);
621 IntDestroyScrollBars(Window
);
623 if (Window
->pcls
->atomClassName
== gaGuiConsoleWndClass
)
625 /* Count only console windows manually */
626 co_IntUserManualGuiCheck(FALSE
);
629 /* dereference the class */
630 NT_ASSERT(Window
->head
.pti
!= NULL
);
631 IntDereferenceClass(Window
->pcls
,
632 Window
->head
.pti
->pDeskInfo
,
633 Window
->head
.pti
->ppi
);
638 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
639 GreDeleteObject(Window
->hrgnClip
);
640 Window
->hrgnClip
= NULL
;
642 Window
->head
.pti
->cWindows
--;
644 // ASSERT(Window != NULL);
645 UserFreeWindowInfo(Window
->head
.pti
, Window
);
647 UserDereferenceObject(Window
);
649 UserClipboardFreeWindow(Window
);
655 // Same as User32:IntGetWndProc.
658 IntGetWindowProc(PWND pWnd
,
663 WNDPROC gcpd
, Ret
= 0;
665 ASSERT(UserIsEnteredExclusive() == TRUE
);
669 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
671 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
673 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
676 Ret
= GETPFNCLIENTA(i
);
678 Ret
= GETPFNCLIENTW(i
);
684 if (Class
->fnid
== FNID_EDIT
)
685 Ret
= pWnd
->lpfnWndProc
;
688 Ret
= pWnd
->lpfnWndProc
;
690 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
694 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
695 Ret
= GETPFNCLIENTA(Class
->fnid
);
699 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
700 Ret
= GETPFNCLIENTW(Class
->fnid
);
703 if ( Ret
!= pWnd
->lpfnWndProc
)
706 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
709 gcpd
= (WNDPROC
)UserGetCPD(
711 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
714 return (gcpd
? gcpd
: Ret
);
718 IntSetWindowProc(PWND pWnd
,
723 PCALLPROCDATA CallProc
;
725 WNDPROC Ret
, chWndProc
= NULL
;
727 // Retrieve previous window proc.
728 Ret
= IntGetWindowProc(pWnd
, Ansi
);
732 if (IsCallProcHandle(NewWndProc
))
734 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
736 { // Reset new WndProc.
737 NewWndProc
= CallProc
->pfnClientPrevious
;
738 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
739 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
742 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
743 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
745 if (GETPFNCLIENTW(i
) == NewWndProc
)
747 chWndProc
= GETPFNSERVER(i
);
750 if (GETPFNCLIENTA(i
) == NewWndProc
)
752 chWndProc
= GETPFNSERVER(i
);
756 // If match, set/reset to Server Side and clear ansi.
759 pWnd
->lpfnWndProc
= chWndProc
;
760 pWnd
->Unicode
= TRUE
;
761 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
762 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
766 pWnd
->Unicode
= !Ansi
;
767 // Handle the state change in here.
769 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
771 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
773 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
774 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
776 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
778 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
782 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
783 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
787 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
788 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
791 // Now set the new window proc.
792 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
803 PMENU OldMenu
, NewMenu
= NULL
;
805 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
807 ERR("SetMenu: Invalid handle 0x%p!\n",UserHMGetHandle(Wnd
));
808 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
812 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
820 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
821 ASSERT(NULL
== OldMenu
|| OldMenu
->hWnd
== Wnd
->head
.h
);
830 NewMenu
= IntGetMenuObject(Menu
);
835 IntReleaseMenuObject(OldMenu
);
837 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
840 if (NULL
!= NewMenu
->hWnd
)
842 /* Can't use the same menu for two windows */
845 IntReleaseMenuObject(OldMenu
);
847 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
853 Wnd
->IDMenu
= (UINT
) Menu
;
856 NewMenu
->hWnd
= Wnd
->head
.h
;
857 IntReleaseMenuObject(NewMenu
);
861 OldMenu
->hWnd
= NULL
;
862 IntReleaseMenuObject(OldMenu
);
869 /* INTERNAL ******************************************************************/
872 // This fixes a check for children messages that need paint while searching the parents messages!
873 // Fixes wine msg:test_paint_messages:WmParentErasePaint ..
876 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
878 PWND Window
= BaseWindow
;
881 if ( Window
== NULL
|| (Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
884 Window
= Window
->spwndParent
;
886 while(Parent
!= Window
);
892 Link the window into siblings list
893 children and parent are kept in place.
898 PWND WndInsertAfter
/* set to NULL if top sibling */
901 if ((Wnd
->spwndPrev
= WndInsertAfter
))
903 /* link after WndInsertAfter */
904 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
905 Wnd
->spwndNext
->spwndPrev
= Wnd
;
907 Wnd
->spwndPrev
->spwndNext
= Wnd
;
912 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
913 Wnd
->spwndNext
->spwndPrev
= Wnd
;
915 Wnd
->spwndParent
->spwndChild
= Wnd
;
920 Note: Wnd->spwndParent can be null if it is the desktop.
922 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
924 if (hWndPrev
== HWND_NOTOPMOST
)
926 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
927 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
928 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
929 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
932 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
934 if (hWndPrev
== HWND_BOTTOM
)
936 /* Link in the bottom of the list */
939 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
940 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
941 WndInsertAfter
= WndInsertAfter
->spwndNext
;
943 IntLinkWindow(Wnd
, WndInsertAfter
);
944 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
946 else if (hWndPrev
== HWND_TOPMOST
)
948 /* Link in the top of the list */
949 IntLinkWindow(Wnd
, NULL
);
951 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
953 else if (hWndPrev
== HWND_TOP
)
955 /* Link it after the last topmost window */
956 PWND WndInsertBefore
;
958 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
960 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
962 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
964 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
965 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
967 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
970 WndInsertBefore
= WndInsertBefore
->spwndNext
;
974 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
978 /* Link it after hWndPrev */
981 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
982 /* Are we called with an erroneous handle */
983 if(WndInsertAfter
== NULL
)
985 /* Link in a default position */
986 IntLinkHwnd(Wnd
, HWND_TOP
);
990 IntLinkWindow(Wnd
, WndInsertAfter
);
992 /* Fix the WS_EX_TOPMOST flag */
993 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
995 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
999 if(WndInsertAfter
->spwndNext
&&
1000 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
1002 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1006 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
1010 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
1014 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
1017 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
1018 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1020 //ERR("ProcessOwnerSwap Old out.\n");
1021 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
1027 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
1030 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1032 //ERR("ProcessOwnerSwap New in.\n");
1033 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1037 // FIXME: System Tray checks.
1041 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1043 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1046 Wnd
= IntGetWindowObject(hWnd
);
1050 WndOldOwner
= Wnd
->spwndOwner
;
1052 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1053 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1055 if (!WndNewOwner
&& hWndNewOwner
)
1057 EngSetLastError(ERROR_INVALID_PARAMETER
);
1062 /* if parent belongs to a different thread and the window isn't */
1063 /* top-level, attach the two threads */
1064 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1066 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1070 Wnd
->spwndOwner
= WndNewOwner
;
1074 Wnd
->spwndOwner
= NULL
;
1079 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1080 EngSetLastError(ERROR_INVALID_PARAMETER
);
1084 UserDereferenceObject(Wnd
);
1089 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1091 PWND WndOldParent
, pWndExam
;
1094 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1097 ASSERT(WndNewParent
);
1098 ASSERT_REFS_CO(Wnd
);
1099 ASSERT_REFS_CO(WndNewParent
);
1101 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1103 EngSetLastError(ERROR_ACCESS_DENIED
);
1107 /* Some applications try to set a child as a parent */
1108 if (IntIsChildWindow(Wnd
, WndNewParent
))
1110 TRACE("IntSetParent try to set a child as a parent.\n");
1111 EngSetLastError( ERROR_INVALID_PARAMETER
);
1115 pWndExam
= WndNewParent
; // Load parent Window to examine.
1116 // Now test for set parent to parent hit.
1119 if (Wnd
== pWndExam
)
1121 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1122 EngSetLastError(ERROR_INVALID_PARAMETER
);
1125 pWndExam
= pWndExam
->spwndParent
;
1129 * Windows hides the window first, then shows it again
1130 * including the WM_SHOWWINDOW messages and all
1132 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1134 /* Window must belong to current process */
1135 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1137 ERR("IntSetParent Window must belong to current process!\n");
1141 WndOldParent
= Wnd
->spwndParent
;
1143 if ( WndOldParent
&&
1144 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1145 pt
.x
= Wnd
->rcWindow
.right
;
1147 pt
.x
= Wnd
->rcWindow
.left
;
1148 pt
.y
= Wnd
->rcWindow
.top
;
1150 IntScreenToClient(WndOldParent
, &pt
);
1152 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1154 if (WndNewParent
!= WndOldParent
)
1156 /* Unlink the window from the siblings list */
1157 IntUnlinkWindow(Wnd
);
1158 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1160 /* Set the new parent */
1161 Wnd
->spwndParent
= WndNewParent
;
1163 if ( Wnd
->style
& WS_CHILD
&&
1165 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1167 ERR("SetParent Top Most from Pop up!\n");
1168 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1171 /* Link the window with its new siblings */
1173 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1174 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1178 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1179 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1181 Wnd
->style
|= WS_CLIPSIBLINGS
;
1182 DceResetActiveDCEs(Wnd
);
1185 /* if parent belongs to a different thread and the window isn't */
1186 /* top-level, attach the two threads */
1187 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1189 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1191 if (WndOldParent
&& (Wnd
->head
.pti
!= WndOldParent
->head
.pti
))
1193 //ERR("SetParent Old out.\n");
1194 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1197 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1199 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1201 //ERR("SetParent New in.\n");
1202 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1207 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1208 swFlags
|= SWP_NOACTIVATE
;
1210 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1212 * SetParent additionally needs to make hwnd the top window
1213 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1214 * WM_WINDOWPOSCHANGED notification messages.
1216 //ERR("IntSetParent SetWindowPos 1\n");
1217 co_WinPosSetWindowPos( Wnd
,
1218 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1219 pt
.x
, pt
.y
, 0, 0, swFlags
);
1220 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1221 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1223 return WndOldParent
;
1227 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1229 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1230 HWND hWndOldParent
= NULL
;
1231 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1233 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1235 EngSetLastError(ERROR_INVALID_PARAMETER
);
1239 if (hWndChild
== IntGetDesktopWindow())
1241 ERR("UserSetParent Access Denied!\n");
1242 EngSetLastError(ERROR_ACCESS_DENIED
);
1248 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1250 ERR("UserSetParent Bad New Parent!\n");
1256 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1262 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1264 ERR("UserSetParent Bad Child!\n");
1268 UserRefObjectCo(Wnd
, &Ref
);
1269 UserRefObjectCo(WndParent
, &ParentRef
);
1270 //ERR("Enter co_IntSetParent\n");
1271 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1272 //ERR("Leave co_IntSetParent\n");
1273 UserDerefObjectCo(WndParent
);
1274 UserDerefObjectCo(Wnd
);
1278 hWndOldParent
= WndOldParent
->head
.h
;
1279 UserDereferenceObject(WndOldParent
);
1282 return( hWndOldParent
);
1285 /* Unlink the window from siblings. children and parent are kept in place. */
1287 IntUnlinkWindow(PWND Wnd
)
1290 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1293 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1295 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1296 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1298 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1301 /* FUNCTIONS *****************************************************************/
1304 * As best as I can figure, this function is used by EnumWindows,
1305 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1307 * It's supposed to build a list of HWNDs to return to the caller.
1308 * We can figure out what kind of list by what parameters are
1316 NtUserBuildHwndList(
1329 return ERROR_INVALID_PARAMETER
;
1331 if (hwndParent
|| !dwThreadId
)
1334 PWND Parent
, Window
;
1338 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1340 return ERROR_INVALID_HANDLE
;
1345 Status
= IntValidateDesktopHandle(hDesktop
,
1349 if(!NT_SUCCESS(Status
))
1351 return ERROR_INVALID_HANDLE
;
1354 hwndParent
= Desktop
->DesktopWindow
;
1361 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1362 (Window
= Parent
->spwndChild
))
1364 BOOL bGoDown
= TRUE
;
1366 Status
= STATUS_SUCCESS
;
1371 if(dwCount
++ < *pBufSize
&& pWnd
)
1375 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1376 *pWnd
= Window
->head
.h
;
1379 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1381 Status
= _SEH2_GetExceptionCode();
1384 if(!NT_SUCCESS(Status
))
1386 SetLastNtError(Status
);
1390 if (Window
->spwndChild
&& bChildren
)
1392 Window
= Window
->spwndChild
;
1397 if (Window
->spwndNext
)
1399 Window
= Window
->spwndNext
;
1403 Window
= Window
->spwndParent
;
1404 if (Window
== Parent
)
1413 ObDereferenceObject(Desktop
);
1416 else // Build EnumThreadWindows list!
1419 PTHREADINFO W32Thread
;
1423 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1424 if (!NT_SUCCESS(Status
))
1426 ERR("Thread Id is not valid!\n");
1427 return ERROR_INVALID_PARAMETER
;
1429 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1431 ObDereferenceObject(Thread
);
1432 TRACE("Tried to enumerate windows of a non gui thread\n");
1433 return ERROR_INVALID_PARAMETER
;
1436 // Do not use Thread link list due to co_UserFreeWindow!!!
1437 // Current = W32Thread->WindowListHead.Flink;
1438 // Fixes Api:CreateWindowEx tests!!!
1439 List
= IntWinListChildren(UserGetDesktopWindow());
1443 for (i
= 0; List
[i
]; i
++)
1445 Window
= ValidateHwndNoErr(List
[i
]);
1446 if (Window
&& Window
->head
.pti
== W32Thread
)
1448 if (dwCount
< *pBufSize
&& pWnd
)
1452 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1453 *pWnd
= Window
->head
.h
;
1456 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1458 Status
= _SEH2_GetExceptionCode();
1461 if (!NT_SUCCESS(Status
))
1463 ERR("Failure to build window list!\n");
1464 SetLastNtError(Status
);
1471 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
1474 ObDereferenceObject(Thread
);
1477 *pBufSize
= dwCount
;
1478 return STATUS_SUCCESS
;
1481 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1483 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1484 !(pWindow
->ExStyle
& WS_EX_NOPARENTNOTIFY
))
1486 if (VerifyWnd(pWindow
->spwndParent
) && pWindow
->spwndParent
!= UserGetDesktopWindow())
1488 USER_REFERENCE_ENTRY Ref
;
1489 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1490 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1492 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1493 (LPARAM
)pWindow
->head
.h
);
1494 UserDerefObjectCo(pWindow
->spwndParent
);
1500 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1502 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1504 /* default positioning for overlapped windows */
1505 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1508 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1510 pMonitor
= UserGetPrimaryMonitor();
1512 /* Check if we don't have a monitor attached yet */
1513 if(pMonitor
== NULL
)
1521 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1523 if (IS_DEFAULT(Cs
->x
))
1525 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1527 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1529 Cs
->x
= ProcessParams
->StartingX
;
1530 Cs
->y
= ProcessParams
->StartingY
;
1534 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1535 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1536 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1537 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1539 /* reset counter and position */
1542 pMonitor
->cWndStack
= 0;
1544 pMonitor
->cWndStack
++;
1548 if (IS_DEFAULT(Cs
->cx
))
1550 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1552 Cs
->cx
= ProcessParams
->CountX
;
1553 Cs
->cy
= ProcessParams
->CountY
;
1557 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1558 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1561 /* neither x nor cx are default. Check the y values .
1562 * In the trace we see Outlook and Outlook Express using
1563 * cy set to CW_USEDEFAULT when opening the address book.
1565 else if (IS_DEFAULT(Cs
->cy
))
1567 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1568 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1573 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1574 if(IS_DEFAULT(Cs
->x
))
1579 if(IS_DEFAULT(Cs
->cx
))
1589 /* Allocates and initializes a window */
1590 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1591 PLARGE_STRING WindowName
,
1596 PDESKTOP pdeskCreated
)
1600 PTHREADINFO pti
= NULL
;
1602 BOOL bUnicodeWindow
;
1604 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1606 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1607 { // Need both here for wine win.c test_CreateWindow.
1608 //if (Cs->hwndParent && ParentWindow)
1609 if (ParentWindow
) // It breaks more tests..... WIP.
1611 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1612 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1613 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1614 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1618 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1620 * Dialog boxes and message boxes do not inherit layout, so you must
1621 * set the layout explicitly.
1623 if ( Class
->fnid
!= FNID_DIALOG
)
1625 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1627 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1633 /* Automatically add WS_EX_WINDOWEDGE */
1634 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1635 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1636 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1637 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1639 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1641 /* Is it a unicode window? */
1642 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1643 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1645 /* Allocate the new window */
1646 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1647 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1651 sizeof(WND
) + Class
->cbwndExtra
);
1658 TRACE("Created window object with handle %p\n", hWnd
);
1660 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1661 { /* HACK: Helper for win32csr/desktopbg.c */
1662 /* If there is no desktop window yet, we must be creating it */
1663 TRACE("CreateWindow setting desktop.\n");
1664 pdeskCreated
->DesktopWindow
= hWnd
;
1665 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1669 * Fill out the structure describing it.
1671 /* Remember, pWnd->head is setup in object.c ... */
1672 pWnd
->spwndParent
= ParentWindow
;
1673 pWnd
->spwndOwner
= OwnerWindow
;
1675 pWnd
->spwndLastActive
= pWnd
;
1676 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1678 pWnd
->hModule
= Cs
->hInstance
;
1679 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1680 pWnd
->ExStyle
= Cs
->dwExStyle
;
1681 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1682 pWnd
->pActCtx
= acbiBuffer
;
1683 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1684 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1686 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1688 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1689 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1692 pWnd
->head
.pti
->cWindows
++;
1694 if (Class
->spicn
&& !Class
->spicnSm
)
1696 HICON IconSmHandle
= NULL
;
1697 if((Class
->spicn
->CURSORF_flags
& (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1698 == (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1700 IconSmHandle
= co_IntCopyImage(
1701 UserHMGetHandle(Class
->spicn
),
1703 UserGetSystemMetrics( SM_CXSMICON
),
1704 UserGetSystemMetrics( SM_CYSMICON
),
1705 LR_COPYFROMRESOURCE
);
1709 /* Retry without copying from resource */
1710 IconSmHandle
= co_IntCopyImage(
1711 UserHMGetHandle(Class
->spicn
),
1713 UserGetSystemMetrics( SM_CXSMICON
),
1714 UserGetSystemMetrics( SM_CYSMICON
),
1720 Class
->spicnSm
= UserGetCurIconObject(IconSmHandle
);
1721 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1725 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1726 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1728 /* BugBoy Comments: Comment below say that System classes are always created
1729 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1730 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1732 No where can I see in code or through testing does the window change back
1733 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1734 see what problems this would cause. */
1736 // Set WndProc from Class.
1737 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1739 // GetWindowProc, test for non server side default classes and set WndProc.
1740 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1744 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1745 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1749 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1750 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1754 // If not an Unicode caller, set Ansi creator bit.
1755 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1757 // Clone Class Ansi/Unicode proc type.
1758 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1760 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1761 pWnd
->Unicode
= FALSE
;
1765 * It seems there can be both an Ansi creator and Unicode Class Window
1766 * WndProc, unless the following overriding conditions occur:
1768 if ( !bUnicodeWindow
&&
1769 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1770 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1771 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1772 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1773 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1774 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1775 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1776 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1777 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1778 { // Override Class and set the window Ansi WndProc.
1779 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1780 pWnd
->Unicode
= FALSE
;
1783 { // Set the window Unicode WndProc.
1784 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1785 pWnd
->Unicode
= TRUE
;
1789 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1790 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1791 Dont understand why it does this. */
1792 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1794 PCALLPROCDATA CallProc
;
1795 CallProc
= CreateCallProc(pWnd
->head
.rpdesk
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1799 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1800 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1804 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1808 InitializeListHead(&pWnd
->PropListHead
);
1809 pWnd
->PropListItems
= 0;
1811 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1813 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1814 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1815 if (pWnd
->strName
.Buffer
== NULL
)
1820 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1821 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1822 pWnd
->strName
.Length
= WindowName
->Length
;
1823 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1826 /* Correct the window style. */
1827 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1829 pWnd
->style
|= WS_CLIPSIBLINGS
;
1830 if (!(pWnd
->style
& WS_POPUP
))
1832 pWnd
->style
|= WS_CAPTION
;
1836 /* WS_EX_WINDOWEDGE depends on some other styles */
1837 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1838 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1839 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1841 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1842 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1843 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1846 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1848 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1849 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1851 /* Set the window menu */
1852 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1856 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1858 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1860 UNICODE_STRING MenuName
;
1863 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1865 MenuName
.Length
= 0;
1866 MenuName
.MaximumLength
= 0;
1867 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1871 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1873 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1874 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1878 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1881 if ( ParentWindow
&&
1882 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1883 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1885 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1887 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1889 EngSetLastError(ERROR_INVALID_PARAMETER
);
1892 if ( pWnd
->spwndOwner
&&
1893 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1895 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1897 if ( pWnd
->spwndOwner
&&
1898 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1899 pti
!= pWnd
->spwndOwner
->head
.pti
)
1901 //ERR("CreateWindow Owner in.\n");
1902 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1906 /* Insert the window into the thread's window list. */
1907 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1909 /* Handle "CS_CLASSDC", it is tested first. */
1910 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1911 { /* One DCE per class to have CLASS. */
1912 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1914 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1915 { /* Allocate a DCE for this window. */
1916 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1922 ERR("IntCreateWindow Allocation Error.\n");
1923 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1926 UserDereferenceObject(pWnd
);
1934 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1935 PUNICODE_STRING ClassName
,
1936 PLARGE_STRING WindowName
,
1940 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1941 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1942 PWINSTATION_OBJECT WinSta
;
1945 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1946 CBT_CREATEWNDW
* pCbtCreate
;
1948 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1950 DWORD dwShowMode
= SW_SHOW
;
1951 CREATESTRUCTW
*pCsw
= NULL
;
1952 PVOID pszClass
= NULL
, pszName
= NULL
;
1955 /* Get the current window station and reference it */
1956 pti
= GetW32ThreadInfo();
1957 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1959 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1960 return NULL
; // There is nothing to cleanup.
1962 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1963 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1968 /* Get the class and reference it */
1969 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
1972 ERR("Failed to find class %wZ\n", ClassName
);
1976 /* Now find the parent and the owner window */
1977 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
1980 if (Cs
->hwndParent
== HWND_MESSAGE
)
1982 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
1984 else if (Cs
->hwndParent
)
1986 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1987 hWndOwner
= Cs
->hwndParent
;
1989 hWndParent
= Cs
->hwndParent
;
1991 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1993 ERR("Cannot create a child window without a parrent!\n");
1994 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1995 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1998 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1999 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
2001 /* FIXME: Is this correct? */
2003 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
2005 /* Fix the position and the size of the window */
2008 UserRefObjectCo(ParentWindow
, &ParentRef
);
2009 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
2012 /* Allocate and initialize the new window */
2013 Window
= IntCreateWindow(Cs
,
2022 ERR("IntCreateWindow failed!\n");
2026 hWnd
= UserHMGetHandle(Window
);
2027 hwndInsertAfter
= HWND_TOP
;
2029 UserRefObjectCo(Window
, &Ref
);
2030 UserDereferenceObject(Window
);
2031 ObDereferenceObject(WinSta
);
2033 //// Check for a hook to eliminate overhead. ////
2034 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2036 // Allocate the calling structures Justin Case this goes Global.
2037 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2038 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2039 if (!pCsw
|| !pCbtCreate
)
2041 ERR("UserHeapAlloc() failed!\n");
2045 /* Fill the new CREATESTRUCTW */
2046 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2047 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2049 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2050 if (!IS_ATOM(ClassName
->Buffer
))
2052 if (Window
->state
& WNDS_ANSICREATOR
)
2054 ANSI_STRING AnsiString
;
2055 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2056 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2059 ERR("UserHeapAlloc() failed!\n");
2062 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2063 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2064 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2068 UNICODE_STRING UnicodeString
;
2069 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2070 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2073 ERR("UserHeapAlloc() failed!\n");
2076 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2077 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2078 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2080 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2082 if (WindowName
->Length
)
2084 UNICODE_STRING Name
;
2085 Name
.Buffer
= WindowName
->Buffer
;
2086 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2087 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2089 if (Window
->state
& WNDS_ANSICREATOR
)
2091 ANSI_STRING AnsiString
;
2092 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2093 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2096 ERR("UserHeapAlloc() failed!\n");
2099 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2100 AnsiString
.Buffer
= (PCHAR
)pszName
;
2101 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2105 UNICODE_STRING UnicodeString
;
2106 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2107 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2110 ERR("UserHeapAlloc() failed!\n");
2113 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2114 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2115 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2117 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2120 pCbtCreate
->lpcs
= pCsw
;
2121 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2123 //// Call the WH_CBT hook ////
2124 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2127 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2130 // Write back changes.
2135 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2138 /* NCCREATE and WM_NCCALCSIZE need the original values */
2139 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2140 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2142 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2144 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2146 Cs
->x
+= ParentWindow
->rcClient
.left
;
2147 Cs
->y
+= ParentWindow
->rcClient
.top
;
2151 /* Send the WM_GETMINMAXINFO message */
2155 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2157 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2158 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2159 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2160 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2161 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2164 Window
->rcWindow
.left
= Cs
->x
;
2165 Window
->rcWindow
.top
= Cs
->y
;
2166 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2167 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2169 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2171 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2172 RECTL_vOffsetRect(&Window->rcWindow,
2173 ParentWindow->rcClient.left,
2174 ParentWindow->rcClient.top);
2177 /* correct child window coordinates if mirroring on parent is enabled */
2178 if (ParentWindow
!= NULL
)
2180 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2181 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2183 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2184 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2188 Window
->rcClient
= Window
->rcWindow
;
2190 /* Link the window */
2191 if (NULL
!= ParentWindow
)
2193 /* Link the window into the siblings list */
2194 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2195 IntLinkHwnd(Window
, HWND_BOTTOM
);
2197 IntLinkHwnd(Window
, hwndInsertAfter
);
2200 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2202 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2203 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2206 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2208 if ( !IntIsTopLevelWindow(Window
) )
2210 if (pti
!= Window
->spwndParent
->head
.pti
)
2212 //ERR("CreateWindow Parent in.\n");
2213 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2218 /* Send the NCCREATE message */
2219 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2222 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2226 /* Send the WM_NCCALCSIZE message */
2229 MaxPos
.x
= Window
->rcWindow
.left
;
2230 MaxPos
.y
= Window
->rcWindow
.top
;
2232 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2233 //rc = Window->rcWindow;
2234 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2235 //Window->rcClient = rc;
2237 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2238 MaxPos
.y
- Window
->rcWindow
.top
);
2241 /* Send the WM_CREATE message. */
2242 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2243 if (Result
== (LRESULT
)-1)
2245 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2249 /* Send the EVENT_OBJECT_CREATE event */
2250 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2252 /* By setting the flag below it can be examined to determine if the window
2253 was created successfully and a valid pwnd was passed back to caller since
2254 from here the function has to succeed. */
2255 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2257 /* Send the WM_SIZE and WM_MOVE messages. */
2258 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2260 co_WinPosSendSizeMove(Window
);
2263 /* Show or maybe minimize or maximize the window. */
2265 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2266 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2269 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2271 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2272 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2273 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2274 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2275 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2278 /* Send the WM_PARENTNOTIFY message */
2279 IntSendParentNotify(Window
, WM_CREATE
);
2281 /* Notify the shell that a new window was created */
2282 if (Window
->spwndParent
== UserGetDesktopWindow() &&
2283 Window
->spwndOwner
== NULL
&&
2284 (Window
->style
& WS_VISIBLE
) &&
2285 (!(Window
->ExStyle
& WS_EX_TOOLWINDOW
) ||
2286 (Window
->ExStyle
& WS_EX_APPWINDOW
)))
2288 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2291 /* Initialize and show the window's scrollbars */
2292 if (Window
->style
& WS_VSCROLL
)
2294 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2296 if (Window
->style
& WS_HSCROLL
)
2298 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2301 /* Show the new window */
2302 if (Cs
->style
& WS_VISIBLE
)
2304 if (Window
->style
& WS_MAXIMIZE
)
2305 dwShowMode
= SW_SHOW
;
2306 else if (Window
->style
& WS_MINIMIZE
)
2307 dwShowMode
= SW_SHOWMINIMIZED
;
2309 co_WinPosShowWindow(Window
, dwShowMode
);
2311 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2313 ASSERT(ParentWindow
);
2316 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2317 /* ShowWindow won't activate child windows */
2318 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2322 if (Class
->atomClassName
== gaGuiConsoleWndClass
)
2324 /* Count only console windows manually */
2325 co_IntUserManualGuiCheck(TRUE
);
2328 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2334 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2335 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2337 co_UserDestroyWindow(Window
);
2339 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2342 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2343 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2344 if (pszName
) UserHeapFree(pszName
);
2345 if (pszClass
) UserHeapFree(pszClass
);
2349 UserDerefObjectCo(Window
);
2351 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2358 ProbeAndCaptureLargeString(
2359 OUT PLARGE_STRING plstrSafe
,
2360 IN PLARGE_STRING plstrUnsafe
)
2362 LARGE_STRING lstrTemp
;
2363 PVOID pvBuffer
= NULL
;
2367 /* Probe and copy the string */
2368 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2369 lstrTemp
= *plstrUnsafe
;
2371 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2374 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2378 if (lstrTemp
.Length
!= 0)
2380 /* Allocate a buffer from paged pool */
2381 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2384 return STATUS_NO_MEMORY
;
2389 /* Probe and copy the buffer */
2390 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2391 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2393 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2395 /* Cleanup and fail */
2396 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2397 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2402 /* Set the output string */
2403 plstrSafe
->Buffer
= pvBuffer
;
2404 plstrSafe
->Length
= lstrTemp
.Length
;
2405 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2407 return STATUS_SUCCESS
;
2411 * \todo Allow passing plstrClassName as ANSI.
2415 NtUserCreateWindowEx(
2417 PLARGE_STRING plstrClassName
,
2418 PLARGE_STRING plstrClsVersion
,
2419 PLARGE_STRING plstrWindowName
,
2427 HINSTANCE hInstance
,
2433 LARGE_STRING lstrWindowName
;
2434 LARGE_STRING lstrClassName
;
2435 UNICODE_STRING ustrClassName
;
2440 lstrWindowName
.Buffer
= NULL
;
2441 lstrClassName
.Buffer
= NULL
;
2443 ASSERT(plstrWindowName
);
2445 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2447 /* check hMenu is valid handle */
2448 if (hMenu
&& !UserGetMenuObject(hMenu
))
2450 ERR("NtUserCreateWindowEx: Got an invalid menu handle!\n");
2451 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
2456 /* Copy the window name to kernel mode */
2457 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2458 if (!NT_SUCCESS(Status
))
2460 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2461 SetLastNtError(Status
);
2465 plstrWindowName
= &lstrWindowName
;
2467 /* Check if the class is an atom */
2468 if (IS_ATOM(plstrClassName
))
2470 /* It is, pass the atom in the UNICODE_STRING */
2471 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2472 ustrClassName
.Length
= 0;
2473 ustrClassName
.MaximumLength
= 0;
2477 /* It's not, capture the class name */
2478 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2479 if (!NT_SUCCESS(Status
))
2481 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2482 /* Set last error, cleanup and return */
2483 SetLastNtError(Status
);
2487 /* We pass it on as a UNICODE_STRING */
2488 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2489 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2490 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2493 /* Fill the CREATESTRUCTW */
2494 /* we will keep here the original parameters */
2496 Cs
.lpCreateParams
= lpParam
;
2497 Cs
.hInstance
= hInstance
;
2499 Cs
.hwndParent
= hWndParent
;
2504 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2505 Cs
.lpszClass
= ustrClassName
.Buffer
;
2506 Cs
.dwExStyle
= dwExStyle
;
2508 UserEnterExclusive();
2510 /* Call the internal function */
2511 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
);
2515 ERR("co_UserCreateWindowEx failed!\n");
2517 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2522 if (lstrWindowName
.Buffer
)
2524 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2526 if (lstrClassName
.Buffer
)
2528 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2535 BOOLEAN
co_UserDestroyWindow(PVOID Object
)
2541 PWND Window
= Object
;
2543 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2545 hWnd
= Window
->head
.h
;
2546 ti
= PsGetCurrentThreadWin32Thread();
2548 TRACE("co_UserDestroyWindow \n");
2550 /* Check for owner thread */
2551 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2553 /* Check if we are destroying the desktop window */
2554 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2556 EngSetLastError(ERROR_ACCESS_DENIED
);
2561 /* If window was created successfully and it is hooked */
2562 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2564 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2566 ERR("Destroy Window WH_CBT Call Hook return!\n");
2571 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2573 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2575 if (Window
->spwndOwner
)
2577 //ERR("DestroyWindow Owner out.\n");
2578 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2583 /* Inform the parent */
2584 if (Window
->style
& WS_CHILD
)
2586 IntSendParentNotify(Window
, WM_DESTROY
);
2589 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
2591 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
2594 /* Hide the window */
2595 if (Window
->style
& WS_VISIBLE
)
2597 if (Window
->style
& WS_CHILD
)
2599 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
2600 co_WinPosShowWindow(Window
, SW_HIDE
);
2604 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2608 // Adjust last active.
2609 if ((pwndTemp
= Window
->spwndOwner
))
2611 while (pwndTemp
->spwndOwner
)
2612 pwndTemp
= pwndTemp
->spwndOwner
;
2614 if (pwndTemp
->spwndLastActive
== Window
)
2615 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2618 if (Window
->spwndParent
&& IntIsWindow(UserHMGetHandle(Window
)))
2620 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2622 if (!IntIsTopLevelWindow(Window
))
2624 //ERR("DestroyWindow Parent out.\n");
2625 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2630 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2631 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2632 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2633 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2634 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2635 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2636 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2637 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2640 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2643 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2645 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2647 ERR("Destroying the ShellWindow!\n");
2648 ti
->pDeskInfo
->hShellWindow
= NULL
;
2652 IntEngWindowChanged(Window
, WOC_DELETE
);
2654 if (!IntIsWindow(UserHMGetHandle(Window
)))
2659 /* Recursively destroy owned windows */
2661 if (! (Window
->style
& WS_CHILD
))
2665 BOOL GotOne
= FALSE
;
2668 PWND Child
, Desktop
;
2670 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2671 UserGetWindowObject(IntGetDesktopWindow());
2672 Children
= IntWinListChildren(Desktop
);
2676 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2678 Child
= UserGetWindowObject(*ChildHandle
);
2681 if (Child
->spwndOwner
!= Window
)
2686 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2688 USER_REFERENCE_ENTRY ChildRef
;
2689 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2690 co_UserDestroyWindow(Child
);
2691 UserDerefObjectCo(Child
); // Temp HACK?
2697 if (Child
->spwndOwner
!= NULL
)
2699 Child
->spwndOwner
= NULL
;
2703 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2712 /* Generate mouse move message for the next window */
2713 msg
.message
= WM_MOUSEMOVE
;
2714 msg
.wParam
= UserGetMouseButtonsState();
2715 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2716 msg
.pt
= gpsi
->ptCursor
;
2717 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2719 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2721 /* Send destroy messages */
2723 IntSendDestroyMsg(UserHMGetHandle(Window
));
2725 if (!IntIsWindow(UserHMGetHandle(Window
)))
2730 /* Destroy the window storage */
2731 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2741 NtUserDestroyWindow(HWND Wnd
)
2744 DECLARE_RETURN(BOOLEAN
);
2746 USER_REFERENCE_ENTRY Ref
;
2748 TRACE("Enter NtUserDestroyWindow\n");
2749 UserEnterExclusive();
2751 if (!(Window
= UserGetWindowObject(Wnd
)))
2756 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2757 ret
= co_UserDestroyWindow(Window
);
2758 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2763 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2769 static HWND FASTCALL
2770 IntFindWindow(PWND Parent
,
2773 PUNICODE_STRING WindowName
)
2775 BOOL CheckWindowName
;
2778 UNICODE_STRING CurrentWindowName
;
2782 CheckWindowName
= WindowName
->Buffer
!= 0;
2784 if((List
= IntWinListChildren(Parent
)))
2789 /* skip handles before and including ChildAfter */
2790 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2794 /* search children */
2798 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2803 /* Do not send WM_GETTEXT messages in the kernel mode version!
2804 The user mode version however calls GetWindowText() which will
2805 send WM_GETTEXT messages to windows belonging to its processes */
2806 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2808 // FIXME: LARGE_STRING truncated
2809 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2810 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2811 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2812 if(!CheckWindowName
||
2813 (Child
->strName
.Length
< 0xFFFF &&
2814 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2816 Ret
= Child
->head
.h
;
2821 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2829 * Searches a window's children for a window with the specified
2832 * hwndParent = The window whose childs are to be searched.
2834 * HWND_MESSAGE = message-only windows
2836 * hwndChildAfter = Search starts after this child window.
2837 * NULL = start from beginning
2839 * ucClassName = Class name to search for
2840 * Reguired parameter.
2842 * ucWindowName = Window name
2843 * ->Buffer == NULL = don't care
2846 * The HWND of the window if it was found, otherwise NULL
2852 NtUserFindWindowEx(HWND hwndParent
,
2853 HWND hwndChildAfter
,
2854 PUNICODE_STRING ucClassName
,
2855 PUNICODE_STRING ucWindowName
,
2858 PWND Parent
, ChildAfter
;
2859 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2860 HWND Desktop
, Ret
= NULL
;
2861 BOOL DoMessageWnd
= FALSE
;
2862 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2863 DECLARE_RETURN(HWND
);
2865 TRACE("Enter NtUserFindWindowEx\n");
2868 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2872 if (ucClassName
!= NULL
)
2874 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2875 if (ClassName
.Length
!= 0)
2877 ProbeForRead(ClassName
.Buffer
,
2881 else if (!IS_ATOM(ClassName
.Buffer
))
2883 EngSetLastError(ERROR_INVALID_PARAMETER
);
2887 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2894 if (ucWindowName
!= NULL
)
2896 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2897 if (WindowName
.Length
!= 0)
2899 ProbeForRead(WindowName
.Buffer
,
2905 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2907 SetLastNtError(_SEH2_GetExceptionCode());
2908 _SEH2_YIELD(RETURN(NULL
));
2912 if (ucClassName
!= NULL
)
2914 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2915 !IS_ATOM(ClassName
.Buffer
))
2917 EngSetLastError(ERROR_INVALID_PARAMETER
);
2920 else if (ClassAtom
== (RTL_ATOM
)0)
2922 /* LastError code was set by IntGetAtomFromStringOrAtom */
2928 Desktop
= IntGetCurrentThreadDesktopWindow();
2930 if(hwndParent
== NULL
)
2932 hwndParent
= Desktop
;
2933 DoMessageWnd
= TRUE
;
2935 else if(hwndParent
== HWND_MESSAGE
)
2937 hwndParent
= IntGetMessageWindow();
2940 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2946 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2953 if(Parent
->head
.h
== Desktop
)
2956 PWND TopLevelWindow
;
2957 BOOLEAN CheckWindowName
;
2958 BOOLEAN WindowMatches
;
2959 BOOLEAN ClassMatches
;
2961 /* windows searches through all top-level windows if the parent is the desktop
2964 if((List
= IntWinListChildren(Parent
)))
2970 /* skip handles before and including ChildAfter */
2971 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2975 CheckWindowName
= WindowName
.Buffer
!= 0;
2977 /* search children */
2980 UNICODE_STRING ustr
;
2982 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2987 /* Do not send WM_GETTEXT messages in the kernel mode version!
2988 The user mode version however calls GetWindowText() which will
2989 send WM_GETTEXT messages to windows belonging to its processes */
2990 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2991 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
2992 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
2993 WindowMatches
= !CheckWindowName
||
2994 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2995 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2996 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2997 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2999 if (WindowMatches
&& ClassMatches
)
3001 Ret
= TopLevelWindow
->head
.h
;
3005 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3007 /* window returns the handle of the top-level window, in case it found
3009 Ret
= TopLevelWindow
->head
.h
;
3014 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3019 ERR("FindWindowEx: Not Desktop Parent!\n");
3020 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3023 if (Ret
== NULL
&& DoMessageWnd
)
3027 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3029 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3033 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3035 SetLastNtError(_SEH2_GetExceptionCode());
3043 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3052 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3054 PWND WndAncestor
, Parent
;
3056 if (Wnd
->head
.h
== IntGetDesktopWindow())
3065 WndAncestor
= Wnd
->spwndParent
;
3076 if(!(Parent
= WndAncestor
->spwndParent
))
3080 if(IntIsDesktopWindow(Parent
))
3085 WndAncestor
= Parent
;
3096 Parent
= IntGetParent(WndAncestor
);
3103 WndAncestor
= Parent
;
3121 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3123 PWND Window
, Ancestor
;
3124 DECLARE_RETURN(HWND
);
3126 TRACE("Enter NtUserGetAncestor\n");
3127 UserEnterExclusive();
3129 if (!(Window
= UserGetWindowObject(hWnd
)))
3134 Ancestor
= UserGetAncestor(Window
, Type
);
3135 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3137 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3140 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3146 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3148 /* combo state struct */
3162 INT fixedOwnerDrawHeight
;
3163 INT droppedWidth
; /* last two are not used unless set */
3164 INT editHeight
; /* explicitly */
3166 } HEADCOMBO
,*LPHEADCOMBO
;
3168 // Window Extra data container.
3169 typedef struct _WND2CBOX
3173 } WND2CBOX
, *PWND2CBOX
;
3175 #define CBF_BUTTONDOWN 0x0002
3181 NtUserGetComboBoxInfo(
3187 BOOL NotSameppi
= FALSE
;
3189 DECLARE_RETURN(BOOL
);
3191 TRACE("Enter NtUserGetComboBoxInfo\n");
3194 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3200 ProbeForWrite(pcbi
, sizeof(COMBOBOXINFO
), 1);
3202 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3204 SetLastNtError(_SEH2_GetExceptionCode());
3205 _SEH2_YIELD(RETURN(FALSE
));
3209 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3211 EngSetLastError(ERROR_INVALID_PARAMETER
);
3215 // Pass the user pointer, it was already probed.
3216 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3218 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3221 ppi
= PsGetCurrentProcessWin32Process();
3222 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3225 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3230 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3231 pcbi
->rcItem
= lphc
->textRect
;
3232 pcbi
->rcButton
= lphc
->buttonRect
;
3233 pcbi
->stateButton
= 0;
3234 if (lphc
->wState
& CBF_BUTTONDOWN
)
3235 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3236 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3237 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3238 pcbi
->hwndCombo
= lphc
->self
;
3239 pcbi
->hwndItem
= lphc
->hWndEdit
;
3240 pcbi
->hwndList
= lphc
->hWndLBox
;
3242 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3245 SetLastNtError(_SEH2_GetExceptionCode());
3252 if (NotSameppi
) KeDetachProcess();
3253 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3259 //// ReactOS work around! Keep it the sames as in Listbox.c
3261 /* Listbox structure */
3264 HWND self
; /* Our own window handle */
3265 HWND owner
; /* Owner window to send notifications to */
3266 UINT style
; /* Window style */
3267 INT width
; /* Window width */
3268 INT height
; /* Window height */
3269 VOID
*items
; /* Array of items */
3270 INT nb_items
; /* Number of items */
3271 INT top_item
; /* Top visible item */
3272 INT selected_item
; /* Selected item */
3273 INT focus_item
; /* Item that has the focus */
3274 INT anchor_item
; /* Anchor item for extended selection */
3275 INT item_height
; /* Default item height */
3276 INT page_size
; /* Items per listbox page */
3277 INT column_width
; /* Column width for multi-column listboxes */
3280 // Window Extra data container.
3281 typedef struct _WND2LB
3291 NtUserGetListBoxInfo(
3296 BOOL NotSameppi
= FALSE
;
3298 DECLARE_RETURN(DWORD
);
3300 TRACE("Enter NtUserGetListBoxInfo\n");
3303 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3308 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3310 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3313 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3314 ppi
= PsGetCurrentProcessWin32Process();
3315 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3318 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3323 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3324 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3325 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3326 Ret
= descr
->page_size
* descr
->column_width
;
3328 Ret
= descr
->page_size
;
3330 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3333 SetLastNtError(_SEH2_GetExceptionCode());
3340 if (NotSameppi
) KeDetachProcess();
3341 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3349 * The NtUserSetParent function changes the parent window of the specified
3353 * The new parent window and the child window must belong to the same
3354 * application. If the window identified by the hWndChild parameter is
3355 * visible, the system performs the appropriate redrawing and repainting.
3356 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3357 * or WS_POPUP window styles of the window whose parent is being changed.
3364 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3366 DECLARE_RETURN(HWND
);
3368 TRACE("Enter NtUserSetParent\n");
3369 UserEnterExclusive();
3372 Check Parent first from user space, set it here.
3376 hWndNewParent
= IntGetDesktopWindow();
3378 else if (hWndNewParent
== HWND_MESSAGE
)
3380 hWndNewParent
= IntGetMessageWindow();
3383 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3386 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3392 * UserGetShellWindow
3394 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3399 HWND FASTCALL
UserGetShellWindow(VOID
)
3401 PWINSTATION_OBJECT WinStaObject
;
3404 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3410 if (!NT_SUCCESS(Status
))
3412 SetLastNtError(Status
);
3416 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3418 ObDereferenceObject(WinStaObject
);
3423 * NtUserSetShellWindowEx
3425 * This is undocumented function to set global shell window. The global
3426 * shell window has special handling of window position.
3432 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3434 PWINSTATION_OBJECT WinStaObject
;
3435 PWND WndShell
, WndListView
;
3436 DECLARE_RETURN(BOOL
);
3437 USER_REFERENCE_ENTRY Ref
;
3441 TRACE("Enter NtUserSetShellWindowEx\n");
3442 UserEnterExclusive();
3444 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3449 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3454 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3460 if (!NT_SUCCESS(Status
))
3462 SetLastNtError(Status
);
3467 * Test if we are permitted to change the shell window.
3469 if (WinStaObject
->ShellWindow
)
3471 ObDereferenceObject(WinStaObject
);
3476 * Move shell window into background.
3478 if (hwndListView
&& hwndListView
!= hwndShell
)
3481 * Disabled for now to get Explorer working.
3482 * -- Filip, 01/nov/2003
3485 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3488 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3490 ObDereferenceObject(WinStaObject
);
3495 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3497 ObDereferenceObject(WinStaObject
);
3501 UserRefObjectCo(WndShell
, &Ref
);
3502 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3503 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3505 WinStaObject
->ShellWindow
= hwndShell
;
3506 WinStaObject
->ShellListView
= hwndListView
;
3508 ti
= GetW32ThreadInfo();
3511 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3512 ti
->pDeskInfo
->spwndShell
= WndShell
;
3513 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3516 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3518 UserDerefObjectCo(WndShell
);
3520 ObDereferenceObject(WinStaObject
);
3524 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3529 // Fixes wine Win test_window_styles and todo tests...
3530 static BOOL FASTCALL
3531 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3533 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3535 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3542 co_IntSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
, BOOL bAlter
)
3544 PWND Window
, Parent
;
3545 PWINSTATION_OBJECT WindowStation
;
3549 if (!(Window
= UserGetWindowObject(hWnd
)))
3554 if ((INT
)Index
>= 0)
3556 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3558 EngSetLastError(ERROR_INVALID_INDEX
);
3562 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3564 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3566 OldValue = (LONG)IntSetWindowProc( Wnd,
3569 if (!OldValue) return 0;
3572 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3579 OldValue
= (LONG
) Window
->ExStyle
;
3580 Style
.styleOld
= OldValue
;
3581 Style
.styleNew
= NewValue
;
3583 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3586 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3588 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3591 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3592 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3594 /* WS_EX_WINDOWEDGE depends on some other styles */
3595 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3596 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3598 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3600 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3602 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3606 OldValue
= (LONG
) Window
->style
;
3607 Style
.styleOld
= OldValue
;
3608 Style
.styleNew
= NewValue
;
3611 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3613 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3614 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3615 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3616 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3617 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3619 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3621 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3623 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3624 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3625 DceResetActiveDCEs( Window
);
3627 Window
->style
= (DWORD
)Style
.styleNew
;
3630 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3635 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3636 Window
->fnid
& FNID_FREED
)
3638 EngSetLastError(ERROR_ACCESS_DENIED
);
3641 OldValue
= (LONG
)IntSetWindowProc(Window
,
3648 OldValue
= (LONG
) Window
->hModule
;
3649 Window
->hModule
= (HINSTANCE
) NewValue
;
3652 case GWL_HWNDPARENT
:
3653 Parent
= Window
->spwndParent
;
3654 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3655 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3657 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3661 OldValue
= (LONG
) Window
->IDMenu
;
3662 Window
->IDMenu
= (UINT
) NewValue
;
3666 OldValue
= Window
->dwUserData
;
3667 Window
->dwUserData
= NewValue
;
3671 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3672 EngSetLastError(ERROR_INVALID_INDEX
);
3683 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3685 return co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3689 * NtUserSetWindowLong
3691 * The NtUserSetWindowLong function changes an attribute of the specified
3692 * window. The function also sets the 32-bit (long) value at the specified
3693 * offset into the extra window memory.
3700 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3704 UserEnterExclusive();
3706 if (hWnd
== IntGetDesktopWindow())
3708 EngSetLastError(STATUS_ACCESS_DENIED
);
3713 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3721 NtUserAlterWindowStyle(HWND hWnd
, DWORD Index
, LONG NewValue
)
3725 UserEnterExclusive();
3727 if (hWnd
== IntGetDesktopWindow())
3729 EngSetLastError(STATUS_ACCESS_DENIED
);
3734 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, FALSE
, TRUE
);
3743 * NtUserSetWindowWord
3745 * Legacy function similar to NtUserSetWindowLong.
3752 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3756 DECLARE_RETURN(WORD
);
3758 TRACE("Enter NtUserSetWindowWord\n");
3759 UserEnterExclusive();
3761 if (hWnd
== IntGetDesktopWindow())
3763 EngSetLastError(STATUS_ACCESS_DENIED
);
3767 if (!(Window
= UserGetWindowObject(hWnd
)))
3776 case GWL_HWNDPARENT
:
3777 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3781 EngSetLastError(ERROR_INVALID_INDEX
);
3786 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3788 EngSetLastError(ERROR_INVALID_PARAMETER
);
3792 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3793 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3798 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3804 QueryWindow based on KJK::Hyperion and James Tabor.
3806 0 = QWUniqueProcessId
3807 1 = QWUniqueThreadId
3810 4 = QWIsHung Implements IsHungAppWindow found
3813 9 = QWKillWindow When I called this with hWnd ==
3814 DesktopWindow, it shutdown the system
3821 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3823 /* Console Leader Process CID Window offsets */
3824 #define GWLP_CONSOLE_LEADER_PID 0
3825 #define GWLP_CONSOLE_LEADER_TID 4
3829 DECLARE_RETURN(UINT
);
3831 TRACE("Enter NtUserQueryWindow\n");
3834 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3841 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3843 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3844 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3846 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
3847 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
3851 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3856 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3858 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3859 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3861 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
3862 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
3866 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3871 case QUERY_WINDOW_ACTIVE
:
3872 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3875 case QUERY_WINDOW_FOCUS
:
3876 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3879 case QUERY_WINDOW_ISHUNG
:
3880 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
);
3883 case QUERY_WINDOW_REAL_ID
:
3884 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3887 case QUERY_WINDOW_FOREGROUND
:
3888 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3892 Result
= (DWORD
)NULL
;
3899 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
3908 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3910 UNICODE_STRING SafeMessageName
;
3913 DECLARE_RETURN(UINT
);
3915 TRACE("Enter NtUserRegisterWindowMessage\n");
3916 UserEnterExclusive();
3918 if(MessageNameUnsafe
== NULL
)
3920 EngSetLastError(ERROR_INVALID_PARAMETER
);
3924 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3925 if(!NT_SUCCESS(Status
))
3927 SetLastNtError(Status
);
3931 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3932 if (SafeMessageName
.Buffer
)
3933 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3937 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
3953 DECLARE_RETURN(BOOL
);
3955 TRACE("Enter NtUserSetMenu\n");
3956 UserEnterExclusive();
3958 if (!(Window
= UserGetWindowObject(hWnd
)))
3963 if (! IntSetMenu(Window
, Menu
, &Changed
))
3968 if (Changed
&& Repaint
)
3970 USER_REFERENCE_ENTRY Ref
;
3972 UserRefObjectCo(Window
, &Ref
);
3973 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3974 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3976 UserDerefObjectCo(Window
);
3982 TRACE("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3991 NtUserSetWindowFNID(HWND hWnd
,
3995 DECLARE_RETURN(BOOL
);
3997 TRACE("Enter NtUserSetWindowFNID\n");
3998 UserEnterExclusive();
4000 if (!(Wnd
= UserGetWindowObject(hWnd
)))
4005 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
4007 EngSetLastError(ERROR_ACCESS_DENIED
);
4011 // From user land we only set these.
4012 if (fnID
!= FNID_DESTROY
)
4014 /* HACK: The minimum should be FNID_BUTTON, but menu code relies on this */
4015 if (fnID
< FNID_FIRST
|| fnID
> FNID_GHOST
||
4018 EngSetLastError(ERROR_INVALID_PARAMETER
);
4027 TRACE("Leave NtUserSetWindowFNID\n");
4035 * Undocumented function that is called from DefWindowProc to set
4042 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4045 LARGE_STRING SafeText
;
4046 UNICODE_STRING UnicodeString
;
4049 TRACE("Enter NtUserDefSetText\n");
4051 if (WindowText
!= NULL
)
4055 SafeText
= ProbeForReadLargeString(WindowText
);
4057 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4060 SetLastNtError(_SEH2_GetExceptionCode());
4070 UserEnterExclusive();
4072 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4078 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4079 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4080 // Now we know what the bAnsi is for.
4081 RtlInitUnicodeString(&UnicodeString
, NULL
);
4082 if (SafeText
.Buffer
)
4087 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4089 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4090 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4092 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4095 SetLastNtError(_SEH2_GetExceptionCode());
4098 if (!Ret
) goto Exit
;
4101 if (UnicodeString
.Length
!= 0)
4103 if (Wnd
->strName
.MaximumLength
> 0 &&
4104 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4106 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4108 Wnd
->strName
.Length
= UnicodeString
.Length
;
4109 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4110 RtlCopyMemory(Wnd
->strName
.Buffer
,
4111 UnicodeString
.Buffer
,
4112 UnicodeString
.Length
);
4117 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4118 buf
= Wnd
->strName
.Buffer
;
4119 Wnd
->strName
.Buffer
= NULL
;
4122 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4125 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4126 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4127 if (Wnd
->strName
.Buffer
!= NULL
)
4129 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4130 RtlCopyMemory(Wnd
->strName
.Buffer
,
4131 UnicodeString
.Buffer
,
4132 UnicodeString
.Length
);
4133 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4134 Wnd
->strName
.Length
= UnicodeString
.Length
;
4138 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4146 Wnd
->strName
.Length
= 0;
4147 if (Wnd
->strName
.Buffer
!= NULL
)
4148 Wnd
->strName
.Buffer
[0] = L
'\0';
4151 // FIXME: HAX! Windows does not do this in here!
4152 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4153 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4154 /* Send shell notifications */
4155 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4157 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4162 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4163 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4169 * NtUserInternalGetWindowText
4176 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4181 DECLARE_RETURN(INT
);
4183 TRACE("Enter NtUserInternalGetWindowText\n");
4186 if(lpString
&& (nMaxCount
<= 1))
4188 EngSetLastError(ERROR_INVALID_PARAMETER
);
4192 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4197 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4200 const WCHAR Terminator
= L
'\0';
4202 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4204 Copy
= min(nMaxCount
- 1, Result
);
4207 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4208 if(!NT_SUCCESS(Status
))
4210 SetLastNtError(Status
);
4216 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4217 if(!NT_SUCCESS(Status
))
4219 SetLastNtError(Status
);
4229 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4239 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4245 // ASSERT(OwnerWnd);
4247 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4248 win_array
= IntWinListChildren(OwnerWnd
);
4253 while (win_array
[count
])
4255 while (--count
>= 0)
4257 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4259 if (pWnd
->spwndOwner
!= OwnerWnd
)
4264 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4266 /* In Windows, ShowOwnedPopups(TRUE) generates
4267 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4268 * regardless of the state of the owner
4270 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4276 if (pWnd
->style
& WS_VISIBLE
)
4278 /* In Windows, ShowOwnedPopups(FALSE) generates
4279 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4280 * regardless of the state of the owner
4282 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4288 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4289 TRACE("Leave ShowOwnedPopups\n");