2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
5 * FILE: subsystems/win32/win32k/ntuser/window.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
10 DBG_DEFAULT_CHANNEL(UserWnd
);
12 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 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
577 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
579 IntDestroyMenuObject(Menu
, TRUE
);
583 if(Window
->SystemMenu
584 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
586 IntDestroyMenuObject(Menu
, TRUE
);
587 Window
->SystemMenu
= (HMENU
)0;
590 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
592 IntUnlinkWindow(Window
);
594 if (Window
->PropListItems
)
596 IntRemoveWindowProp(Window
);
597 TRACE("Window->PropListItems %d\n",Window
->PropListItems
);
598 ASSERT(Window
->PropListItems
==0);
601 UserReferenceObject(Window
);
602 UserDeleteObject(UserHMGetHandle(Window
), TYPE_WINDOW
);
604 IntDestroyScrollBars(Window
);
606 if (Window
->pcls
->atomClassName
== gaGuiConsoleWndClass
)
608 /* Count only console windows manually */
609 co_IntUserManualGuiCheck(FALSE
);
612 /* dereference the class */
613 IntDereferenceClass(Window
->pcls
,
614 Window
->head
.pti
->pDeskInfo
,
615 Window
->head
.pti
->ppi
);
620 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
621 GreDeleteObject(Window
->hrgnClip
);
622 Window
->hrgnClip
= NULL
;
624 Window
->head
.pti
->cWindows
--;
626 // ASSERT(Window != NULL);
627 UserFreeWindowInfo(Window
->head
.pti
, Window
);
629 UserDereferenceObject(Window
);
631 UserClipboardFreeWindow(Window
);
637 // Same as User32:IntGetWndProc.
640 IntGetWindowProc(PWND pWnd
,
645 WNDPROC gcpd
, Ret
= 0;
647 ASSERT(UserIsEnteredExclusive() == TRUE
);
651 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
653 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
655 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
658 Ret
= GETPFNCLIENTA(i
);
660 Ret
= GETPFNCLIENTW(i
);
666 if (Class
->fnid
== FNID_EDIT
)
667 Ret
= pWnd
->lpfnWndProc
;
670 Ret
= pWnd
->lpfnWndProc
;
672 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
676 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
677 Ret
= GETPFNCLIENTA(Class
->fnid
);
681 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
682 Ret
= GETPFNCLIENTW(Class
->fnid
);
685 if ( Ret
!= pWnd
->lpfnWndProc
)
688 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
691 gcpd
= (WNDPROC
)UserGetCPD(
693 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
696 return (gcpd
? gcpd
: Ret
);
700 IntSetWindowProc(PWND pWnd
,
705 PCALLPROCDATA CallProc
;
707 WNDPROC Ret
, chWndProc
= NULL
;
709 // Retrieve previous window proc.
710 Ret
= IntGetWindowProc(pWnd
, Ansi
);
714 if (IsCallProcHandle(NewWndProc
))
716 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
718 { // Reset new WndProc.
719 NewWndProc
= CallProc
->pfnClientPrevious
;
720 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
721 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
724 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
725 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
727 if (GETPFNCLIENTW(i
) == NewWndProc
)
729 chWndProc
= GETPFNSERVER(i
);
732 if (GETPFNCLIENTA(i
) == NewWndProc
)
734 chWndProc
= GETPFNSERVER(i
);
738 // If match, set/reset to Server Side and clear ansi.
741 pWnd
->lpfnWndProc
= chWndProc
;
742 pWnd
->Unicode
= TRUE
;
743 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
744 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
748 pWnd
->Unicode
= !Ansi
;
749 // Handle the state change in here.
751 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
753 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
755 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
756 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
758 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
760 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
764 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
765 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
769 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
770 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
773 // Now set the new window proc.
774 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
785 PMENU OldMenu
, NewMenu
= NULL
;
787 if ((Wnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
789 ERR("SetMenu: Invalid handle 0x%p!\n",UserHMGetHandle(Wnd
));
790 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
794 *Changed
= (Wnd
->IDMenu
!= (UINT
) Menu
);
802 OldMenu
= IntGetMenuObject((HMENU
) Wnd
->IDMenu
);
803 ASSERT(NULL
== OldMenu
|| OldMenu
->hWnd
== Wnd
->head
.h
);
812 NewMenu
= IntGetMenuObject(Menu
);
817 IntReleaseMenuObject(OldMenu
);
819 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
822 if (NULL
!= NewMenu
->hWnd
)
824 /* Can't use the same menu for two windows */
827 IntReleaseMenuObject(OldMenu
);
829 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
835 Wnd
->IDMenu
= (UINT
) Menu
;
838 NewMenu
->hWnd
= Wnd
->head
.h
;
839 IntReleaseMenuObject(NewMenu
);
843 OldMenu
->hWnd
= NULL
;
844 IntReleaseMenuObject(OldMenu
);
851 /* INTERNAL ******************************************************************/
855 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
860 while (Window
&& ((Window
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
))
862 if (Window
== Parent
)
867 Window
= Window
->spwndParent
;
874 Link the window into siblings list
875 children and parent are kept in place.
880 PWND WndInsertAfter
/* set to NULL if top sibling */
883 if ((Wnd
->spwndPrev
= WndInsertAfter
))
885 /* link after WndInsertAfter */
886 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
887 Wnd
->spwndNext
->spwndPrev
= Wnd
;
889 Wnd
->spwndPrev
->spwndNext
= Wnd
;
894 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
895 Wnd
->spwndNext
->spwndPrev
= Wnd
;
897 Wnd
->spwndParent
->spwndChild
= Wnd
;
902 Note: Wnd->spwndParent can be null if it is the desktop.
904 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
906 if (hWndPrev
== HWND_NOTOPMOST
)
908 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
909 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
910 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
911 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
914 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
916 if (hWndPrev
== HWND_BOTTOM
)
918 /* Link in the bottom of the list */
921 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
922 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
923 WndInsertAfter
= WndInsertAfter
->spwndNext
;
925 IntLinkWindow(Wnd
, WndInsertAfter
);
926 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
928 else if (hWndPrev
== HWND_TOPMOST
)
930 /* Link in the top of the list */
931 IntLinkWindow(Wnd
, NULL
);
933 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
935 else if (hWndPrev
== HWND_TOP
)
937 /* Link it after the last topmost window */
938 PWND WndInsertBefore
;
940 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
942 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
944 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
946 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
947 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
949 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
952 WndInsertBefore
= WndInsertBefore
->spwndNext
;
956 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
960 /* Link it after hWndPrev */
963 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
964 /* Are we called with an erroneous handle */
965 if(WndInsertAfter
== NULL
)
967 /* Link in a default position */
968 IntLinkHwnd(Wnd
, HWND_TOP
);
972 IntLinkWindow(Wnd
, WndInsertAfter
);
974 /* Fix the WS_EX_TOPMOST flag */
975 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
977 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
981 if(WndInsertAfter
->spwndNext
&&
982 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
984 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
988 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
992 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
996 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
999 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
1000 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1002 //ERR("ProcessOwnerSwap Old out.\n");
1003 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
1009 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
1012 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
1014 //ERR("ProcessOwnerSwap New in.\n");
1015 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
1019 // FIXME: System Tray checks.
1023 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
1025 PWND Wnd
, WndOldOwner
, WndNewOwner
;
1028 Wnd
= IntGetWindowObject(hWnd
);
1032 WndOldOwner
= Wnd
->spwndOwner
;
1034 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1035 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1037 if (!WndNewOwner
&& hWndNewOwner
)
1039 EngSetLastError(ERROR_INVALID_PARAMETER
);
1044 /* if parent belongs to a different thread and the window isn't */
1045 /* top-level, attach the two threads */
1046 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1048 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1052 Wnd
->spwndOwner
= WndNewOwner
;
1056 Wnd
->spwndOwner
= NULL
;
1061 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1062 EngSetLastError(ERROR_INVALID_PARAMETER
);
1066 UserDereferenceObject(Wnd
);
1071 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1073 PWND WndOldParent
, pWndExam
;
1076 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1079 ASSERT(WndNewParent
);
1080 ASSERT_REFS_CO(Wnd
);
1081 ASSERT_REFS_CO(WndNewParent
);
1083 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1085 EngSetLastError(ERROR_ACCESS_DENIED
);
1089 /* Some applications try to set a child as a parent */
1090 if (IntIsChildWindow(Wnd
, WndNewParent
))
1092 TRACE("IntSetParent try to set a child as a parent.\n");
1093 EngSetLastError( ERROR_INVALID_PARAMETER
);
1097 pWndExam
= WndNewParent
; // Load parent Window to examine.
1098 // Now test for set parent to parent hit.
1101 if (Wnd
== pWndExam
)
1103 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1104 EngSetLastError(ERROR_INVALID_PARAMETER
);
1107 pWndExam
= pWndExam
->spwndParent
;
1111 * Windows hides the window first, then shows it again
1112 * including the WM_SHOWWINDOW messages and all
1114 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1116 /* Window must belong to current process */
1117 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1119 ERR("IntSetParent Window must belong to current process!\n");
1123 WndOldParent
= Wnd
->spwndParent
;
1125 if ( WndOldParent
&&
1126 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1127 pt
.x
= Wnd
->rcWindow
.right
;
1129 pt
.x
= Wnd
->rcWindow
.left
;
1130 pt
.y
= Wnd
->rcWindow
.top
;
1132 IntScreenToClient(WndOldParent
, &pt
);
1134 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1136 if (WndNewParent
!= WndOldParent
)
1138 /* Unlink the window from the siblings list */
1139 IntUnlinkWindow(Wnd
);
1140 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1142 /* Set the new parent */
1143 Wnd
->spwndParent
= WndNewParent
;
1145 if ( Wnd
->style
& WS_CHILD
&&
1147 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1149 ERR("SetParent Top Most from Pop up!\n");
1150 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1153 /* Link the window with its new siblings */
1155 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1156 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1160 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1161 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1163 Wnd
->style
|= WS_CLIPSIBLINGS
;
1164 DceResetActiveDCEs(Wnd
);
1167 /* if parent belongs to a different thread and the window isn't */
1168 /* top-level, attach the two threads */
1169 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1171 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1173 if (Wnd
->head
.pti
!= WndOldParent
->head
.pti
)
1175 //ERR("SetParent Old out.\n");
1176 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1179 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1181 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1183 //ERR("SetParent New in.\n");
1184 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1189 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1190 swFlags
|= SWP_NOACTIVATE
;
1192 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1194 * SetParent additionally needs to make hwnd the top window
1195 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1196 * WM_WINDOWPOSCHANGED notification messages.
1198 //ERR("IntSetParent SetWindowPos 1\n");
1199 co_WinPosSetWindowPos( Wnd
,
1200 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1201 pt
.x
, pt
.y
, 0, 0, swFlags
);
1202 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1203 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1205 return WndOldParent
;
1209 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1211 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1212 HWND hWndOldParent
= NULL
;
1213 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1215 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1217 EngSetLastError(ERROR_INVALID_PARAMETER
);
1221 if (hWndChild
== IntGetDesktopWindow())
1223 ERR("UserSetParent Access Denied!\n");
1224 EngSetLastError(ERROR_ACCESS_DENIED
);
1230 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1232 ERR("UserSetParent Bad New Parent!\n");
1238 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1244 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1246 ERR("UserSetParent Bad Child!\n");
1250 UserRefObjectCo(Wnd
, &Ref
);
1251 UserRefObjectCo(WndParent
, &ParentRef
);
1252 //ERR("Enter co_IntSetParent\n");
1253 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1254 //ERR("Leave co_IntSetParent\n");
1255 UserDerefObjectCo(WndParent
);
1256 UserDerefObjectCo(Wnd
);
1260 hWndOldParent
= WndOldParent
->head
.h
;
1261 UserDereferenceObject(WndOldParent
);
1264 return( hWndOldParent
);
1267 /* Unlink the window from siblings. children and parent are kept in place. */
1269 IntUnlinkWindow(PWND Wnd
)
1272 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1275 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1277 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1278 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1280 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1283 /* FUNCTIONS *****************************************************************/
1286 * As best as I can figure, this function is used by EnumWindows,
1287 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1289 * It's supposed to build a list of HWNDs to return to the caller.
1290 * We can figure out what kind of list by what parameters are
1298 NtUserBuildHwndList(
1311 return ERROR_INVALID_PARAMETER
;
1313 if (hwndParent
|| !dwThreadId
)
1316 PWND Parent
, Window
;
1320 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1322 return ERROR_INVALID_HANDLE
;
1327 Status
= IntValidateDesktopHandle(hDesktop
,
1331 if(!NT_SUCCESS(Status
))
1333 return ERROR_INVALID_HANDLE
;
1336 hwndParent
= Desktop
->DesktopWindow
;
1343 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1344 (Window
= Parent
->spwndChild
))
1346 BOOL bGoDown
= TRUE
;
1348 Status
= STATUS_SUCCESS
;
1353 if(dwCount
++ < *pBufSize
&& pWnd
)
1357 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1358 *pWnd
= Window
->head
.h
;
1361 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1363 Status
= _SEH2_GetExceptionCode();
1366 if(!NT_SUCCESS(Status
))
1368 SetLastNtError(Status
);
1372 if (Window
->spwndChild
&& bChildren
)
1374 Window
= Window
->spwndChild
;
1379 if (Window
->spwndNext
)
1381 Window
= Window
->spwndNext
;
1385 Window
= Window
->spwndParent
;
1386 if (Window
== Parent
)
1395 ObDereferenceObject(Desktop
);
1398 else // Build EnumThreadWindows list!
1401 PTHREADINFO W32Thread
;
1405 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1406 if (!NT_SUCCESS(Status
))
1408 ERR("Thread Id is not valid!\n");
1409 return ERROR_INVALID_PARAMETER
;
1411 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1413 ObDereferenceObject(Thread
);
1414 TRACE("Tried to enumerate windows of a non gui thread\n");
1415 return ERROR_INVALID_PARAMETER
;
1418 // Do not use Thread link list due to co_UserFreeWindow!!!
1419 // Current = W32Thread->WindowListHead.Flink;
1420 // Fixes Api:CreateWindowEx tests!!!
1421 List
= IntWinListChildren(UserGetDesktopWindow());
1425 for (i
= 0; List
[i
]; i
++)
1427 Window
= ValidateHwndNoErr(List
[i
]);
1428 if (Window
&& Window
->head
.pti
== W32Thread
)
1430 if (dwCount
< *pBufSize
&& pWnd
)
1434 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1435 *pWnd
= Window
->head
.h
;
1438 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1440 Status
= _SEH2_GetExceptionCode();
1443 if (!NT_SUCCESS(Status
))
1445 ERR("Failure to build window list!\n");
1446 SetLastNtError(Status
);
1455 ObDereferenceObject(Thread
);
1458 *pBufSize
= dwCount
;
1459 return STATUS_SUCCESS
;
1462 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1464 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1465 !(pWindow
->style
& WS_EX_NOPARENTNOTIFY
))
1467 if (VerifyWnd(pWindow
->spwndParent
) && pWindow
->spwndParent
!= UserGetDesktopWindow())
1469 USER_REFERENCE_ENTRY Ref
;
1470 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1471 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1473 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1474 (LPARAM
)pWindow
->head
.h
);
1475 UserDerefObjectCo(pWindow
->spwndParent
);
1481 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1483 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1485 /* default positioning for overlapped windows */
1486 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1489 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1491 pMonitor
= UserGetPrimaryMonitor();
1493 /* Check if we don't have a monitor attached yet */
1494 if(pMonitor
== NULL
)
1502 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1504 if (IS_DEFAULT(Cs
->x
))
1506 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1508 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1510 Cs
->x
= ProcessParams
->StartingX
;
1511 Cs
->y
= ProcessParams
->StartingY
;
1515 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1516 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1517 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1518 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1520 /* reset counter and position */
1523 pMonitor
->cWndStack
= 0;
1525 pMonitor
->cWndStack
++;
1529 if (IS_DEFAULT(Cs
->cx
))
1531 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1533 Cs
->cx
= ProcessParams
->CountX
;
1534 Cs
->cy
= ProcessParams
->CountY
;
1538 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1539 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1542 /* neither x nor cx are default. Check the y values .
1543 * In the trace we see Outlook and Outlook Express using
1544 * cy set to CW_USEDEFAULT when opening the address book.
1546 else if (IS_DEFAULT(Cs
->cy
))
1548 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1549 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1554 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1555 if(IS_DEFAULT(Cs
->x
))
1560 if(IS_DEFAULT(Cs
->cx
))
1570 /* Allocates and initializes a window */
1571 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1572 PLARGE_STRING WindowName
,
1577 PDESKTOP pdeskCreated
)
1581 PTHREADINFO pti
= NULL
;
1583 BOOL bUnicodeWindow
;
1585 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1587 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1588 { // Need both here for wine win.c test_CreateWindow.
1589 //if (Cs->hwndParent && ParentWindow)
1590 if (ParentWindow
) // It breaks more tests..... WIP.
1592 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1593 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1594 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1595 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1599 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1601 * Dialog boxes and message boxes do not inherit layout, so you must
1602 * set the layout explicitly.
1604 if ( Class
->fnid
!= FNID_DIALOG
)
1606 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1608 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1614 /* Automatically add WS_EX_WINDOWEDGE */
1615 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1616 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1617 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1618 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1620 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1622 /* Is it a unicode window? */
1623 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1624 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1626 /* Allocate the new window */
1627 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1628 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1632 sizeof(WND
) + Class
->cbwndExtra
);
1639 TRACE("Created window object with handle %p\n", hWnd
);
1641 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1642 { /* HACK: Helper for win32csr/desktopbg.c */
1643 /* If there is no desktop window yet, we must be creating it */
1644 TRACE("CreateWindow setting desktop.\n");
1645 pdeskCreated
->DesktopWindow
= hWnd
;
1646 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1650 * Fill out the structure describing it.
1652 /* Remember, pWnd->head is setup in object.c ... */
1653 pWnd
->spwndParent
= ParentWindow
;
1654 pWnd
->spwndOwner
= OwnerWindow
;
1656 pWnd
->spwndLastActive
= pWnd
;
1657 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1659 pWnd
->hModule
= Cs
->hInstance
;
1660 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1661 pWnd
->ExStyle
= Cs
->dwExStyle
;
1662 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1663 pWnd
->pActCtx
= acbiBuffer
;
1664 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1665 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1667 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1669 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1670 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1673 pWnd
->head
.pti
->cWindows
++;
1675 if (Class
->spicn
&& !Class
->spicnSm
)
1677 HICON IconSmHandle
= NULL
;
1678 if((Class
->spicn
->CURSORF_flags
& (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1679 == (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1681 IconSmHandle
= co_IntCopyImage(
1682 UserHMGetHandle(Class
->spicn
),
1684 UserGetSystemMetrics( SM_CXSMICON
),
1685 UserGetSystemMetrics( SM_CYSMICON
),
1686 LR_COPYFROMRESOURCE
);
1690 /* Retry without copying from resource */
1691 IconSmHandle
= co_IntCopyImage(
1692 UserHMGetHandle(Class
->spicn
),
1694 UserGetSystemMetrics( SM_CXSMICON
),
1695 UserGetSystemMetrics( SM_CYSMICON
),
1701 Class
->spicnSm
= UserGetCurIconObject(IconSmHandle
);
1702 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1706 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1707 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1709 /* BugBoy Comments: Comment below say that System classes are always created
1710 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1711 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1713 No where can I see in code or through testing does the window change back
1714 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1715 see what problems this would cause. */
1717 // Set WndProc from Class.
1718 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1720 // GetWindowProc, test for non server side default classes and set WndProc.
1721 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1725 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1726 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1730 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1731 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1735 // If not an Unicode caller, set Ansi creator bit.
1736 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1738 // Clone Class Ansi/Unicode proc type.
1739 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1741 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1742 pWnd
->Unicode
= FALSE
;
1746 * It seems there can be both an Ansi creator and Unicode Class Window
1747 * WndProc, unless the following overriding conditions occur:
1749 if ( !bUnicodeWindow
&&
1750 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1751 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1752 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1753 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1754 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1755 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1756 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1757 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1758 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1759 { // Override Class and set the window Ansi WndProc.
1760 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1761 pWnd
->Unicode
= FALSE
;
1764 { // Set the window Unicode WndProc.
1765 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1766 pWnd
->Unicode
= TRUE
;
1770 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1771 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1772 Dont understand why it does this. */
1773 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1775 PCALLPROCDATA CallProc
;
1776 CallProc
= CreateCallProc(pWnd
->head
.rpdesk
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1780 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1781 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1785 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1789 InitializeListHead(&pWnd
->PropListHead
);
1790 pWnd
->PropListItems
= 0;
1792 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1794 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1795 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1796 if (pWnd
->strName
.Buffer
== NULL
)
1801 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1802 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1803 pWnd
->strName
.Length
= WindowName
->Length
;
1804 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1807 /* Correct the window style. */
1808 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1810 pWnd
->style
|= WS_CLIPSIBLINGS
;
1811 if (!(pWnd
->style
& WS_POPUP
))
1813 pWnd
->style
|= WS_CAPTION
;
1817 /* WS_EX_WINDOWEDGE depends on some other styles */
1818 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1819 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1820 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1822 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1823 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1824 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1827 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1829 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1830 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1832 /* Set the window menu */
1833 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1837 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1839 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1841 UNICODE_STRING MenuName
;
1844 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1846 MenuName
.Length
= 0;
1847 MenuName
.MaximumLength
= 0;
1848 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1852 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1854 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1855 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1859 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1862 if ( ParentWindow
&&
1863 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1864 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1866 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1868 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1870 EngSetLastError(ERROR_INVALID_PARAMETER
);
1873 if ( pWnd
->spwndOwner
&&
1874 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1876 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1878 if ( pWnd
->spwndOwner
&&
1879 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1880 pti
!= pWnd
->spwndOwner
->head
.pti
)
1882 //ERR("CreateWindow Owner in.\n");
1883 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1887 /* Insert the window into the thread's window list. */
1888 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1890 /* Handle "CS_CLASSDC", it is tested first. */
1891 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1892 { /* One DCE per class to have CLASS. */
1893 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1895 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1896 { /* Allocate a DCE for this window. */
1897 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1903 ERR("IntCreateWindow Allocation Error.\n");
1904 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1907 UserDereferenceObject(pWnd
);
1915 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1916 PUNICODE_STRING ClassName
,
1917 PLARGE_STRING WindowName
,
1921 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1922 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1923 PWINSTATION_OBJECT WinSta
;
1926 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1927 CBT_CREATEWNDW
* pCbtCreate
;
1929 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1931 DWORD dwShowMode
= SW_SHOW
;
1932 CREATESTRUCTW
*pCsw
= NULL
;
1933 PVOID pszClass
= NULL
, pszName
= NULL
;
1936 /* Get the current window station and reference it */
1937 pti
= GetW32ThreadInfo();
1938 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1940 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1941 return NULL
; // There is nothing to cleanup.
1943 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1944 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1949 /* Get the class and reference it */
1950 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
1953 ERR("Failed to find class %wZ\n", ClassName
);
1957 /* Now find the parent and the owner window */
1958 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
1961 if (Cs
->hwndParent
== HWND_MESSAGE
)
1963 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
1965 else if (Cs
->hwndParent
)
1967 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1968 hWndOwner
= Cs
->hwndParent
;
1970 hWndParent
= Cs
->hwndParent
;
1972 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1974 ERR("Cannot create a child window without a parrent!\n");
1975 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1976 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1979 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1980 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1982 /* FIXME: Is this correct? */
1984 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
1986 /* Fix the position and the size of the window */
1989 UserRefObjectCo(ParentWindow
, &ParentRef
);
1990 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
1993 /* Allocate and initialize the new window */
1994 Window
= IntCreateWindow(Cs
,
2003 ERR("IntCreateWindow failed!\n");
2007 hWnd
= UserHMGetHandle(Window
);
2008 hwndInsertAfter
= HWND_TOP
;
2010 UserRefObjectCo(Window
, &Ref
);
2011 UserDereferenceObject(Window
);
2012 ObDereferenceObject(WinSta
);
2014 //// Check for a hook to eliminate overhead. ////
2015 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2017 // Allocate the calling structures Justin Case this goes Global.
2018 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2019 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2020 if (!pCsw
|| !pCbtCreate
)
2022 ERR("UserHeapAlloc() failed!\n");
2026 /* Fill the new CREATESTRUCTW */
2027 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2028 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2030 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2031 if (!IS_ATOM(ClassName
->Buffer
))
2033 if (Window
->state
& WNDS_ANSICREATOR
)
2035 ANSI_STRING AnsiString
;
2036 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2037 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2040 ERR("UserHeapAlloc() failed!\n");
2043 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2044 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2045 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2049 UNICODE_STRING UnicodeString
;
2050 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2051 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2054 ERR("UserHeapAlloc() failed!\n");
2057 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2058 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2059 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2061 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2063 if (WindowName
->Length
)
2065 UNICODE_STRING Name
;
2066 Name
.Buffer
= WindowName
->Buffer
;
2067 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2068 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2070 if (Window
->state
& WNDS_ANSICREATOR
)
2072 ANSI_STRING AnsiString
;
2073 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2074 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2077 ERR("UserHeapAlloc() failed!\n");
2080 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2081 AnsiString
.Buffer
= (PCHAR
)pszName
;
2082 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2086 UNICODE_STRING UnicodeString
;
2087 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2088 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2091 ERR("UserHeapAlloc() failed!\n");
2094 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2095 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2096 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2098 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2101 pCbtCreate
->lpcs
= pCsw
;
2102 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2104 //// Call the WH_CBT hook ////
2105 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2108 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2111 // Write back changes.
2116 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2119 /* NCCREATE and WM_NCCALCSIZE need the original values */
2120 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2121 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2123 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2125 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2127 Cs
->x
+= ParentWindow
->rcClient
.left
;
2128 Cs
->y
+= ParentWindow
->rcClient
.top
;
2132 /* Send the WM_GETMINMAXINFO message */
2136 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2138 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2139 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2140 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2141 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2142 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2145 Window
->rcWindow
.left
= Cs
->x
;
2146 Window
->rcWindow
.top
= Cs
->y
;
2147 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2148 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2150 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2152 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2153 RECTL_vOffsetRect(&Window->rcWindow,
2154 ParentWindow->rcClient.left,
2155 ParentWindow->rcClient.top);
2158 /* correct child window coordinates if mirroring on parent is enabled */
2159 if (ParentWindow
!= NULL
)
2161 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2162 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2164 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2165 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2169 Window
->rcClient
= Window
->rcWindow
;
2171 /* Link the window */
2172 if (NULL
!= ParentWindow
)
2174 /* Link the window into the siblings list */
2175 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2176 IntLinkHwnd(Window
, HWND_BOTTOM
);
2178 IntLinkHwnd(Window
, hwndInsertAfter
);
2181 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2183 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2184 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2187 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2189 if ( !IntIsTopLevelWindow(Window
) )
2191 if (pti
!= Window
->spwndParent
->head
.pti
)
2193 //ERR("CreateWindow Parent in.\n");
2194 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2199 /* Send the NCCREATE message */
2200 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2203 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2207 /* Send the WM_NCCALCSIZE message */
2210 MaxPos
.x
= Window
->rcWindow
.left
;
2211 MaxPos
.y
= Window
->rcWindow
.top
;
2213 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2214 //rc = Window->rcWindow;
2215 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2216 //Window->rcClient = rc;
2218 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2219 MaxPos
.y
- Window
->rcWindow
.top
);
2222 /* Send the WM_CREATE message. */
2223 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2224 if (Result
== (LRESULT
)-1)
2226 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2230 /* Send the EVENT_OBJECT_CREATE event */
2231 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2233 /* By setting the flag below it can be examined to determine if the window
2234 was created successfully and a valid pwnd was passed back to caller since
2235 from here the function has to succeed. */
2236 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2238 /* Send the WM_SIZE and WM_MOVE messages. */
2239 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2241 co_WinPosSendSizeMove(Window
);
2244 /* Show or maybe minimize or maximize the window. */
2246 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2247 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2250 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2252 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2253 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2254 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2255 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2256 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2259 /* Send the WM_PARENTNOTIFY message */
2260 IntSendParentNotify(Window
, WM_CREATE
);
2262 /* Notify the shell that a new window was created */
2263 if (Window
->spwndParent
== UserGetDesktopWindow() &&
2264 Window
->spwndOwner
== NULL
&&
2265 (Window
->style
& WS_VISIBLE
) &&
2266 (!(Window
->ExStyle
& WS_EX_TOOLWINDOW
) ||
2267 (Window
->ExStyle
& WS_EX_APPWINDOW
)))
2269 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2272 /* Initialize and show the window's scrollbars */
2273 if (Window
->style
& WS_VSCROLL
)
2275 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2277 if (Window
->style
& WS_HSCROLL
)
2279 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2282 /* Show the new window */
2283 if (Cs
->style
& WS_VISIBLE
)
2285 if (Window
->style
& WS_MAXIMIZE
)
2286 dwShowMode
= SW_SHOW
;
2287 else if (Window
->style
& WS_MINIMIZE
)
2288 dwShowMode
= SW_SHOWMINIMIZED
;
2290 co_WinPosShowWindow(Window
, dwShowMode
);
2292 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2294 ASSERT(ParentWindow
);
2297 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2298 /* ShowWindow won't activate child windows */
2299 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2303 if (Class
->atomClassName
== gaGuiConsoleWndClass
)
2305 /* Count only console windows manually */
2306 co_IntUserManualGuiCheck(TRUE
);
2309 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2315 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2316 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2318 co_UserDestroyWindow(Window
);
2320 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2323 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2324 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2325 if (pszName
) UserHeapFree(pszName
);
2326 if (pszClass
) UserHeapFree(pszClass
);
2330 UserDerefObjectCo(Window
);
2332 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2339 ProbeAndCaptureLargeString(
2340 OUT PLARGE_STRING plstrSafe
,
2341 IN PLARGE_STRING plstrUnsafe
)
2343 LARGE_STRING lstrTemp
;
2344 PVOID pvBuffer
= NULL
;
2348 /* Probe and copy the string */
2349 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2350 lstrTemp
= *plstrUnsafe
;
2352 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2355 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2359 if (lstrTemp
.Length
!= 0)
2361 /* Allocate a buffer from paged pool */
2362 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2365 return STATUS_NO_MEMORY
;
2370 /* Probe and copy the buffer */
2371 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2372 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2374 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2376 /* Cleanup and fail */
2377 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2378 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2383 /* Set the output string */
2384 plstrSafe
->Buffer
= pvBuffer
;
2385 plstrSafe
->Length
= lstrTemp
.Length
;
2386 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2388 return STATUS_SUCCESS
;
2392 * \todo Allow passing plstrClassName as ANSI.
2396 NtUserCreateWindowEx(
2398 PLARGE_STRING plstrClassName
,
2399 PLARGE_STRING plstrClsVersion
,
2400 PLARGE_STRING plstrWindowName
,
2408 HINSTANCE hInstance
,
2414 LARGE_STRING lstrWindowName
;
2415 LARGE_STRING lstrClassName
;
2416 UNICODE_STRING ustrClassName
;
2421 lstrWindowName
.Buffer
= NULL
;
2422 lstrClassName
.Buffer
= NULL
;
2424 ASSERT(plstrWindowName
);
2426 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2428 /* check hMenu is valid handle */
2429 if (hMenu
&& !UserGetMenuObject(hMenu
))
2431 ERR("NtUserCreateWindowEx: Got an invalid menu handle!\n");
2432 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
2437 /* Copy the window name to kernel mode */
2438 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2439 if (!NT_SUCCESS(Status
))
2441 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2442 SetLastNtError(Status
);
2446 plstrWindowName
= &lstrWindowName
;
2448 /* Check if the class is an atom */
2449 if (IS_ATOM(plstrClassName
))
2451 /* It is, pass the atom in the UNICODE_STRING */
2452 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2453 ustrClassName
.Length
= 0;
2454 ustrClassName
.MaximumLength
= 0;
2458 /* It's not, capture the class name */
2459 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2460 if (!NT_SUCCESS(Status
))
2462 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2463 /* Set last error, cleanup and return */
2464 SetLastNtError(Status
);
2468 /* We pass it on as a UNICODE_STRING */
2469 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2470 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2471 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2474 /* Fill the CREATESTRUCTW */
2475 /* we will keep here the original parameters */
2477 Cs
.lpCreateParams
= lpParam
;
2478 Cs
.hInstance
= hInstance
;
2480 Cs
.hwndParent
= hWndParent
;
2485 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2486 if (IS_ATOM(plstrClassName
))
2487 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
;
2489 Cs
.lpszClass
= (LPCWSTR
) plstrClassName
->Buffer
;
2490 Cs
.dwExStyle
= dwExStyle
;
2492 UserEnterExclusive();
2494 /* Call the internal function */
2495 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
);
2499 ERR("co_UserCreateWindowEx failed!\n");
2501 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2506 if (lstrWindowName
.Buffer
)
2508 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2510 if (lstrClassName
.Buffer
)
2512 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2519 BOOLEAN
co_UserDestroyWindow(PVOID Object
)
2525 PWND Window
= Object
;
2527 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2529 hWnd
= Window
->head
.h
;
2530 ti
= PsGetCurrentThreadWin32Thread();
2532 TRACE("co_UserDestroyWindow \n");
2534 /* Check for owner thread */
2535 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2537 /* Check if we are destroying the desktop window */
2538 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2540 EngSetLastError(ERROR_ACCESS_DENIED
);
2545 /* If window was created successfully and it is hooked */
2546 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2548 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2550 ERR("Destroy Window WH_CBT Call Hook return!\n");
2555 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2557 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2559 if (Window
->spwndOwner
)
2561 //ERR("DestroyWindow Owner out.\n");
2562 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2567 /* Inform the parent */
2568 if (Window
->style
& WS_CHILD
)
2570 IntSendParentNotify(Window
, WM_DESTROY
);
2573 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
2575 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
2578 /* Hide the window */
2579 if (Window
->style
& WS_VISIBLE
)
2581 if (Window
->style
& WS_CHILD
)
2583 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
2584 co_WinPosShowWindow(Window
, SW_HIDE
);
2588 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2592 // Adjust last active.
2593 if ((pwndTemp
= Window
->spwndOwner
))
2595 while (pwndTemp
->spwndOwner
)
2596 pwndTemp
= pwndTemp
->spwndOwner
;
2598 if (pwndTemp
->spwndLastActive
== Window
)
2599 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2602 if (Window
->spwndParent
&& IntIsWindow(UserHMGetHandle(Window
)))
2604 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2606 if (!IntIsTopLevelWindow(Window
))
2608 //ERR("DestroyWindow Parent out.\n");
2609 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2614 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2615 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2616 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2617 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2618 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2619 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2620 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2621 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2624 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2627 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2629 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2631 ERR("Destroying the ShellWindow!\n");
2632 ti
->pDeskInfo
->hShellWindow
= NULL
;
2636 IntEngWindowChanged(Window
, WOC_DELETE
);
2638 if (!IntIsWindow(UserHMGetHandle(Window
)))
2643 /* Recursively destroy owned windows */
2645 if (! (Window
->style
& WS_CHILD
))
2649 BOOL GotOne
= FALSE
;
2652 PWND Child
, Desktop
;
2654 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2655 UserGetWindowObject(IntGetDesktopWindow());
2656 Children
= IntWinListChildren(Desktop
);
2660 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2662 Child
= UserGetWindowObject(*ChildHandle
);
2665 if (Child
->spwndOwner
!= Window
)
2670 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2672 USER_REFERENCE_ENTRY ChildRef
;
2673 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2674 co_UserDestroyWindow(Child
);
2675 UserDerefObjectCo(Child
); // Temp HACK?
2681 if (Child
->spwndOwner
!= NULL
)
2683 Child
->spwndOwner
= NULL
;
2687 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2696 /* Generate mouse move message for the next window */
2697 msg
.message
= WM_MOUSEMOVE
;
2698 msg
.wParam
= UserGetMouseButtonsState();
2699 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2700 msg
.pt
= gpsi
->ptCursor
;
2701 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2703 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2705 /* Send destroy messages */
2707 IntSendDestroyMsg(UserHMGetHandle(Window
));
2709 if (!IntIsWindow(UserHMGetHandle(Window
)))
2714 /* Destroy the window storage */
2715 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2725 NtUserDestroyWindow(HWND Wnd
)
2728 DECLARE_RETURN(BOOLEAN
);
2730 USER_REFERENCE_ENTRY Ref
;
2732 TRACE("Enter NtUserDestroyWindow\n");
2733 UserEnterExclusive();
2735 if (!(Window
= UserGetWindowObject(Wnd
)))
2740 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2741 ret
= co_UserDestroyWindow(Window
);
2742 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2747 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2753 static HWND FASTCALL
2754 IntFindWindow(PWND Parent
,
2757 PUNICODE_STRING WindowName
)
2759 BOOL CheckWindowName
;
2762 UNICODE_STRING CurrentWindowName
;
2766 CheckWindowName
= WindowName
->Buffer
!= 0;
2768 if((List
= IntWinListChildren(Parent
)))
2773 /* skip handles before and including ChildAfter */
2774 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2778 /* search children */
2782 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2787 /* Do not send WM_GETTEXT messages in the kernel mode version!
2788 The user mode version however calls GetWindowText() which will
2789 send WM_GETTEXT messages to windows belonging to its processes */
2790 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2792 // FIXME: LARGE_STRING truncated
2793 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2794 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2795 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2796 if(!CheckWindowName
||
2797 (Child
->strName
.Length
< 0xFFFF &&
2798 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2800 Ret
= Child
->head
.h
;
2805 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2813 * Searches a window's children for a window with the specified
2816 * hwndParent = The window whose childs are to be searched.
2818 * HWND_MESSAGE = message-only windows
2820 * hwndChildAfter = Search starts after this child window.
2821 * NULL = start from beginning
2823 * ucClassName = Class name to search for
2824 * Reguired parameter.
2826 * ucWindowName = Window name
2827 * ->Buffer == NULL = don't care
2830 * The HWND of the window if it was found, otherwise NULL
2836 NtUserFindWindowEx(HWND hwndParent
,
2837 HWND hwndChildAfter
,
2838 PUNICODE_STRING ucClassName
,
2839 PUNICODE_STRING ucWindowName
,
2842 PWND Parent
, ChildAfter
;
2843 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2844 HWND Desktop
, Ret
= NULL
;
2845 BOOL DoMessageWnd
= FALSE
;
2846 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2847 DECLARE_RETURN(HWND
);
2849 TRACE("Enter NtUserFindWindowEx\n");
2852 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2856 if (ucClassName
!= NULL
)
2858 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2859 if (ClassName
.Length
!= 0)
2861 ProbeForRead(ClassName
.Buffer
,
2865 else if (!IS_ATOM(ClassName
.Buffer
))
2867 EngSetLastError(ERROR_INVALID_PARAMETER
);
2871 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2878 if (ucWindowName
!= NULL
)
2880 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2881 if (WindowName
.Length
!= 0)
2883 ProbeForRead(WindowName
.Buffer
,
2889 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2891 SetLastNtError(_SEH2_GetExceptionCode());
2892 _SEH2_YIELD(RETURN(NULL
));
2896 if (ucClassName
!= NULL
)
2898 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2899 !IS_ATOM(ClassName
.Buffer
))
2901 EngSetLastError(ERROR_INVALID_PARAMETER
);
2904 else if (ClassAtom
== (RTL_ATOM
)0)
2906 /* LastError code was set by IntGetAtomFromStringOrAtom */
2912 Desktop
= IntGetCurrentThreadDesktopWindow();
2914 if(hwndParent
== NULL
)
2916 hwndParent
= Desktop
;
2917 DoMessageWnd
= TRUE
;
2919 else if(hwndParent
== HWND_MESSAGE
)
2921 hwndParent
= IntGetMessageWindow();
2924 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2930 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2937 if(Parent
->head
.h
== Desktop
)
2940 PWND TopLevelWindow
;
2941 BOOLEAN CheckWindowName
;
2942 BOOLEAN WindowMatches
;
2943 BOOLEAN ClassMatches
;
2945 /* windows searches through all top-level windows if the parent is the desktop
2948 if((List
= IntWinListChildren(Parent
)))
2954 /* skip handles before and including ChildAfter */
2955 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2959 CheckWindowName
= WindowName
.Buffer
!= 0;
2961 /* search children */
2964 UNICODE_STRING ustr
;
2966 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2971 /* Do not send WM_GETTEXT messages in the kernel mode version!
2972 The user mode version however calls GetWindowText() which will
2973 send WM_GETTEXT messages to windows belonging to its processes */
2974 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2975 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
2976 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
2977 WindowMatches
= !CheckWindowName
||
2978 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2979 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2980 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2981 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2983 if (WindowMatches
&& ClassMatches
)
2985 Ret
= TopLevelWindow
->head
.h
;
2989 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2991 /* window returns the handle of the top-level window, in case it found
2993 Ret
= TopLevelWindow
->head
.h
;
2998 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3003 ERR("FindWindowEx: Not Desktop Parent!\n");
3004 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3007 if (Ret
== NULL
&& DoMessageWnd
)
3011 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3013 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3017 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3019 SetLastNtError(_SEH2_GetExceptionCode());
3027 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3036 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3038 PWND WndAncestor
, Parent
;
3040 if (Wnd
->head
.h
== IntGetDesktopWindow())
3049 WndAncestor
= Wnd
->spwndParent
;
3060 if(!(Parent
= WndAncestor
->spwndParent
))
3064 if(IntIsDesktopWindow(Parent
))
3069 WndAncestor
= Parent
;
3080 Parent
= IntGetParent(WndAncestor
);
3087 WndAncestor
= Parent
;
3105 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3107 PWND Window
, Ancestor
;
3108 DECLARE_RETURN(HWND
);
3110 TRACE("Enter NtUserGetAncestor\n");
3111 UserEnterExclusive();
3113 if (!(Window
= UserGetWindowObject(hWnd
)))
3118 Ancestor
= UserGetAncestor(Window
, Type
);
3119 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3121 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3124 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3130 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3132 /* combo state struct */
3146 INT fixedOwnerDrawHeight
;
3147 INT droppedWidth
; /* last two are not used unless set */
3148 INT editHeight
; /* explicitly */
3150 } HEADCOMBO
,*LPHEADCOMBO
;
3152 // Window Extra data container.
3153 typedef struct _WND2CBOX
3157 } WND2CBOX
, *PWND2CBOX
;
3159 #define CBF_BUTTONDOWN 0x0002
3165 NtUserGetComboBoxInfo(
3171 BOOL NotSameppi
= FALSE
;
3173 DECLARE_RETURN(BOOL
);
3175 TRACE("Enter NtUserGetComboBoxInfo\n");
3178 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3187 sizeof(COMBOBOXINFO
),
3191 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3193 SetLastNtError(_SEH2_GetExceptionCode());
3194 _SEH2_YIELD(RETURN(FALSE
));
3198 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3200 EngSetLastError(ERROR_INVALID_PARAMETER
);
3204 // Pass the user pointer, it was already probed.
3205 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3207 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3210 ppi
= PsGetCurrentProcessWin32Process();
3211 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3214 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3219 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3220 pcbi
->rcItem
= lphc
->textRect
;
3221 pcbi
->rcButton
= lphc
->buttonRect
;
3222 pcbi
->stateButton
= 0;
3223 if (lphc
->wState
& CBF_BUTTONDOWN
)
3224 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3225 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3226 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3227 pcbi
->hwndCombo
= lphc
->self
;
3228 pcbi
->hwndItem
= lphc
->hWndEdit
;
3229 pcbi
->hwndList
= lphc
->hWndLBox
;
3231 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3234 SetLastNtError(_SEH2_GetExceptionCode());
3241 if (NotSameppi
) KeDetachProcess();
3242 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3248 //// ReactOS work around! Keep it the sames as in Listbox.c
3250 /* Listbox structure */
3253 HWND self
; /* Our own window handle */
3254 HWND owner
; /* Owner window to send notifications to */
3255 UINT style
; /* Window style */
3256 INT width
; /* Window width */
3257 INT height
; /* Window height */
3258 VOID
*items
; /* Array of items */
3259 INT nb_items
; /* Number of items */
3260 INT top_item
; /* Top visible item */
3261 INT selected_item
; /* Selected item */
3262 INT focus_item
; /* Item that has the focus */
3263 INT anchor_item
; /* Anchor item for extended selection */
3264 INT item_height
; /* Default item height */
3265 INT page_size
; /* Items per listbox page */
3266 INT column_width
; /* Column width for multi-column listboxes */
3269 // Window Extra data container.
3270 typedef struct _WND2LB
3280 NtUserGetListBoxInfo(
3285 BOOL NotSameppi
= FALSE
;
3287 DECLARE_RETURN(DWORD
);
3289 TRACE("Enter NtUserGetListBoxInfo\n");
3292 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3297 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3299 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3302 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3303 ppi
= PsGetCurrentProcessWin32Process();
3304 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3307 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3312 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3313 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3314 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3315 Ret
= descr
->page_size
* descr
->column_width
;
3317 Ret
= descr
->page_size
;
3319 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3322 SetLastNtError(_SEH2_GetExceptionCode());
3329 if (NotSameppi
) KeDetachProcess();
3330 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3338 * The NtUserSetParent function changes the parent window of the specified
3342 * The new parent window and the child window must belong to the same
3343 * application. If the window identified by the hWndChild parameter is
3344 * visible, the system performs the appropriate redrawing and repainting.
3345 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3346 * or WS_POPUP window styles of the window whose parent is being changed.
3353 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3355 DECLARE_RETURN(HWND
);
3357 TRACE("Enter NtUserSetParent\n");
3358 UserEnterExclusive();
3361 Check Parent first from user space, set it here.
3365 hWndNewParent
= IntGetDesktopWindow();
3367 else if (hWndNewParent
== HWND_MESSAGE
)
3369 hWndNewParent
= IntGetMessageWindow();
3372 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3375 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3381 * UserGetShellWindow
3383 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3388 HWND FASTCALL
UserGetShellWindow(VOID
)
3390 PWINSTATION_OBJECT WinStaObject
;
3393 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3399 if (!NT_SUCCESS(Status
))
3401 SetLastNtError(Status
);
3405 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3407 ObDereferenceObject(WinStaObject
);
3412 * NtUserSetShellWindowEx
3414 * This is undocumented function to set global shell window. The global
3415 * shell window has special handling of window position.
3421 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3423 PWINSTATION_OBJECT WinStaObject
;
3424 PWND WndShell
, WndListView
;
3425 DECLARE_RETURN(BOOL
);
3426 USER_REFERENCE_ENTRY Ref
;
3430 TRACE("Enter NtUserSetShellWindowEx\n");
3431 UserEnterExclusive();
3433 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3438 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3443 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3449 if (!NT_SUCCESS(Status
))
3451 SetLastNtError(Status
);
3456 * Test if we are permitted to change the shell window.
3458 if (WinStaObject
->ShellWindow
)
3460 ObDereferenceObject(WinStaObject
);
3465 * Move shell window into background.
3467 if (hwndListView
&& hwndListView
!= hwndShell
)
3470 * Disabled for now to get Explorer working.
3471 * -- Filip, 01/nov/2003
3474 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3477 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3479 ObDereferenceObject(WinStaObject
);
3484 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3486 ObDereferenceObject(WinStaObject
);
3490 UserRefObjectCo(WndShell
, &Ref
);
3491 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3492 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3494 WinStaObject
->ShellWindow
= hwndShell
;
3495 WinStaObject
->ShellListView
= hwndListView
;
3497 ti
= GetW32ThreadInfo();
3500 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3501 ti
->pDeskInfo
->spwndShell
= WndShell
;
3502 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3505 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3507 UserDerefObjectCo(WndShell
);
3509 ObDereferenceObject(WinStaObject
);
3513 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3518 // Fixes wine Win test_window_styles and todo tests...
3519 static BOOL FASTCALL
3520 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3522 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3524 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3531 co_IntSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
, BOOL bAlter
)
3533 PWND Window
, Parent
;
3534 PWINSTATION_OBJECT WindowStation
;
3538 if (!(Window
= UserGetWindowObject(hWnd
)))
3543 if ((INT
)Index
>= 0)
3545 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3547 EngSetLastError(ERROR_INVALID_INDEX
);
3551 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3553 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3555 OldValue = (LONG)IntSetWindowProc( Wnd,
3558 if (!OldValue) return 0;
3561 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3568 OldValue
= (LONG
) Window
->ExStyle
;
3569 Style
.styleOld
= OldValue
;
3570 Style
.styleNew
= NewValue
;
3572 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3575 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3577 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3580 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3581 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3583 /* WS_EX_WINDOWEDGE depends on some other styles */
3584 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3585 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3587 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3589 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3591 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3595 OldValue
= (LONG
) Window
->style
;
3596 Style
.styleOld
= OldValue
;
3597 Style
.styleNew
= NewValue
;
3600 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3602 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3603 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3604 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3605 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3606 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3608 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3610 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3612 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3613 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3614 DceResetActiveDCEs( Window
);
3616 Window
->style
= (DWORD
)Style
.styleNew
;
3619 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3624 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3625 Window
->fnid
& FNID_FREED
)
3627 EngSetLastError(ERROR_ACCESS_DENIED
);
3630 OldValue
= (LONG
)IntSetWindowProc(Window
,
3637 OldValue
= (LONG
) Window
->hModule
;
3638 Window
->hModule
= (HINSTANCE
) NewValue
;
3641 case GWL_HWNDPARENT
:
3642 Parent
= Window
->spwndParent
;
3643 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3644 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3646 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3650 OldValue
= (LONG
) Window
->IDMenu
;
3651 Window
->IDMenu
= (UINT
) NewValue
;
3655 OldValue
= Window
->dwUserData
;
3656 Window
->dwUserData
= NewValue
;
3660 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3661 EngSetLastError(ERROR_INVALID_INDEX
);
3672 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3674 return co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3678 * NtUserSetWindowLong
3680 * The NtUserSetWindowLong function changes an attribute of the specified
3681 * window. The function also sets the 32-bit (long) value at the specified
3682 * offset into the extra window memory.
3689 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3693 UserEnterExclusive();
3695 if (hWnd
== IntGetDesktopWindow())
3697 EngSetLastError(STATUS_ACCESS_DENIED
);
3702 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3710 NtUserAlterWindowStyle(HWND hWnd
, DWORD Index
, LONG NewValue
)
3714 UserEnterExclusive();
3716 if (hWnd
== IntGetDesktopWindow())
3718 EngSetLastError(STATUS_ACCESS_DENIED
);
3723 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, FALSE
, TRUE
);
3732 * NtUserSetWindowWord
3734 * Legacy function similar to NtUserSetWindowLong.
3741 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3745 DECLARE_RETURN(WORD
);
3747 TRACE("Enter NtUserSetWindowWord\n");
3748 UserEnterExclusive();
3750 if (hWnd
== IntGetDesktopWindow())
3752 EngSetLastError(STATUS_ACCESS_DENIED
);
3756 if (!(Window
= UserGetWindowObject(hWnd
)))
3765 case GWL_HWNDPARENT
:
3766 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3770 EngSetLastError(ERROR_INVALID_INDEX
);
3775 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3777 EngSetLastError(ERROR_INVALID_PARAMETER
);
3781 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3782 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3787 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3793 QueryWindow based on KJK::Hyperion and James Tabor.
3795 0 = QWUniqueProcessId
3796 1 = QWUniqueThreadId
3799 4 = QWIsHung Implements IsHungAppWindow found
3802 9 = QWKillWindow When I called this with hWnd ==
3803 DesktopWindow, it shutdown the system
3810 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3812 /* Console Leader Process CID Window offsets */
3813 #define GWLP_CONSOLE_LEADER_PID 0
3814 #define GWLP_CONSOLE_LEADER_TID 4
3818 DECLARE_RETURN(UINT
);
3820 TRACE("Enter NtUserQueryWindow\n");
3823 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3830 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3832 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3833 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3835 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
3836 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
3840 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3845 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3847 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3848 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3850 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
3851 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
3855 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3860 case QUERY_WINDOW_ACTIVE
:
3861 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3864 case QUERY_WINDOW_FOCUS
:
3865 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3868 case QUERY_WINDOW_ISHUNG
:
3869 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
);
3872 case QUERY_WINDOW_REAL_ID
:
3873 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3876 case QUERY_WINDOW_FOREGROUND
:
3877 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3881 Result
= (DWORD
)NULL
;
3888 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
3897 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3899 UNICODE_STRING SafeMessageName
;
3902 DECLARE_RETURN(UINT
);
3904 TRACE("Enter NtUserRegisterWindowMessage\n");
3905 UserEnterExclusive();
3907 if(MessageNameUnsafe
== NULL
)
3909 EngSetLastError(ERROR_INVALID_PARAMETER
);
3913 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3914 if(!NT_SUCCESS(Status
))
3916 SetLastNtError(Status
);
3920 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3921 if (SafeMessageName
.Buffer
)
3922 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3926 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
3942 DECLARE_RETURN(BOOL
);
3944 TRACE("Enter NtUserSetMenu\n");
3945 UserEnterExclusive();
3947 if (!(Window
= UserGetWindowObject(hWnd
)))
3952 if (! IntSetMenu(Window
, Menu
, &Changed
))
3957 if (Changed
&& Repaint
)
3959 USER_REFERENCE_ENTRY Ref
;
3961 UserRefObjectCo(Window
, &Ref
);
3962 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
3963 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_FRAMECHANGED
);
3965 UserDerefObjectCo(Window
);
3971 TRACE("Leave NtUserSetMenu, ret=%i\n",_ret_
);
3980 NtUserSetWindowFNID(HWND hWnd
,
3984 DECLARE_RETURN(BOOL
);
3986 TRACE("Enter NtUserSetWindowFNID\n");
3987 UserEnterExclusive();
3989 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3994 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3996 EngSetLastError(ERROR_ACCESS_DENIED
);
4000 // From user land we only set these.
4001 if (fnID
!= FNID_DESTROY
)
4002 { // Hacked so we can mark desktop~!
4003 if ( (/*(fnID < FNID_BUTTON)*/ (fnID
< FNID_FIRST
) && (fnID
> FNID_GHOST
)) ||
4006 EngSetLastError(ERROR_INVALID_PARAMETER
);
4015 TRACE("Leave NtUserSetWindowFNID\n");
4023 * Undocumented function that is called from DefWindowProc to set
4030 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4033 LARGE_STRING SafeText
;
4034 UNICODE_STRING UnicodeString
;
4037 TRACE("Enter NtUserDefSetText\n");
4039 if (WindowText
!= NULL
)
4043 SafeText
= ProbeForReadLargeString(WindowText
);
4045 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4048 SetLastNtError(_SEH2_GetExceptionCode());
4058 UserEnterExclusive();
4060 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4066 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4067 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4068 // Now we know what the bAnsi is for.
4069 RtlInitUnicodeString(&UnicodeString
, NULL
);
4070 if (SafeText
.Buffer
)
4075 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4077 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4078 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4080 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4083 SetLastNtError(_SEH2_GetExceptionCode());
4086 if (!Ret
) goto Exit
;
4089 if (UnicodeString
.Length
!= 0)
4091 if (Wnd
->strName
.MaximumLength
> 0 &&
4092 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4094 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4096 Wnd
->strName
.Length
= UnicodeString
.Length
;
4097 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4098 RtlCopyMemory(Wnd
->strName
.Buffer
,
4099 UnicodeString
.Buffer
,
4100 UnicodeString
.Length
);
4105 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4106 buf
= Wnd
->strName
.Buffer
;
4107 Wnd
->strName
.Buffer
= NULL
;
4110 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4113 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4114 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4115 if (Wnd
->strName
.Buffer
!= NULL
)
4117 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4118 RtlCopyMemory(Wnd
->strName
.Buffer
,
4119 UnicodeString
.Buffer
,
4120 UnicodeString
.Length
);
4121 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4122 Wnd
->strName
.Length
= UnicodeString
.Length
;
4126 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4134 Wnd
->strName
.Length
= 0;
4135 if (Wnd
->strName
.Buffer
!= NULL
)
4136 Wnd
->strName
.Buffer
[0] = L
'\0';
4139 // FIXME: HAX! Windows does not do this in here!
4140 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4141 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4142 /* Send shell notifications */
4143 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4145 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4150 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4151 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4157 * NtUserInternalGetWindowText
4164 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4169 DECLARE_RETURN(INT
);
4171 TRACE("Enter NtUserInternalGetWindowText\n");
4174 if(lpString
&& (nMaxCount
<= 1))
4176 EngSetLastError(ERROR_INVALID_PARAMETER
);
4180 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4185 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4188 const WCHAR Terminator
= L
'\0';
4190 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4192 Copy
= min(nMaxCount
- 1, Result
);
4195 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4196 if(!NT_SUCCESS(Status
))
4198 SetLastNtError(Status
);
4204 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4205 if(!NT_SUCCESS(Status
))
4207 SetLastNtError(Status
);
4217 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4227 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4233 // ASSERT(OwnerWnd);
4235 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4236 win_array
= IntWinListChildren(OwnerWnd
);
4241 while (win_array
[count
])
4243 while (--count
>= 0)
4245 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4247 if (pWnd
->spwndOwner
!= OwnerWnd
)
4252 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4254 /* In Windows, ShowOwnedPopups(TRUE) generates
4255 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4256 * regardless of the state of the owner
4258 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4264 if (pWnd
->style
& WS_VISIBLE
)
4266 /* In Windows, ShowOwnedPopups(FALSE) generates
4267 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4268 * regardless of the state of the owner
4270 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4276 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4277 TRACE("Leave ShowOwnedPopups\n");