2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
5 * FILE: win32ss/user/ntuser/window.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
10 DBG_DEFAULT_CHANNEL(UserWnd
);
12 INT gNestedWindowLimit
= 50;
14 /* HELPER FUNCTIONS ***********************************************************/
16 BOOL FASTCALL
UserUpdateUiState(PWND Wnd
, WPARAM wParam
)
18 WORD Action
= LOWORD(wParam
);
19 WORD Flags
= HIWORD(wParam
);
21 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
23 EngSetLastError(ERROR_INVALID_PARAMETER
);
30 EngSetLastError(ERROR_INVALID_PARAMETER
);
34 if (Flags
& UISF_HIDEFOCUS
)
35 Wnd
->HideFocus
= TRUE
;
36 if (Flags
& UISF_HIDEACCEL
)
37 Wnd
->HideAccel
= TRUE
;
41 if (Flags
& UISF_HIDEFOCUS
)
42 Wnd
->HideFocus
= FALSE
;
43 if (Flags
& UISF_HIDEACCEL
)
44 Wnd
->HideAccel
= FALSE
;
51 PWND FASTCALL
IntGetWindowObject(HWND hWnd
)
55 if (!hWnd
) return NULL
;
57 Window
= UserGetWindowObject(hWnd
);
59 Window
->head
.cLockObj
++;
64 PWND FASTCALL
VerifyWnd(PWND pWnd
)
70 if (!pWnd
) return NULL
;
72 Error
= EngGetLastError();
76 hWnd
= UserHMGetHandle(pWnd
);
78 State2
= pWnd
->state2
;
80 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
82 EngSetLastError(Error
);
83 _SEH2_YIELD(return NULL
);
87 if ( UserObjectInDestroy(hWnd
) ||
88 State
& WNDS_DESTROYED
||
89 State2
& WNDS2_INDESTROY
)
92 EngSetLastError(Error
);
96 PWND FASTCALL
ValidateHwndNoErr(HWND hWnd
)
98 if (hWnd
) return (PWND
)UserGetObjectNoErr(gHandleTable
, hWnd
, TYPE_WINDOW
);
103 PWND FASTCALL
UserGetWindowObject(HWND hWnd
)
109 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
113 Window
= (PWND
)UserGetObject(gHandleTable
, hWnd
, TYPE_WINDOW
);
114 if (!Window
|| 0 != (Window
->state
& WNDS_DESTROYED
))
116 EngSetLastError(ERROR_INVALID_WINDOW_HANDLE
);
124 IntSetStyle( PWND pwnd
, ULONG set_bits
, ULONG clear_bits
)
126 ULONG styleOld
, styleNew
;
127 styleOld
= pwnd
->style
;
128 styleNew
= (pwnd
->style
| set_bits
) & ~clear_bits
;
129 if (styleNew
== styleOld
) return styleNew
;
130 pwnd
->style
= styleNew
;
131 if ((styleOld
^ styleNew
) & WS_VISIBLE
) // State Change.
133 if (styleOld
& WS_VISIBLE
) pwnd
->head
.pti
->cVisWindows
--;
134 if (styleNew
& WS_VISIBLE
) pwnd
->head
.pti
->cVisWindows
++;
135 DceResetActiveDCEs( pwnd
);
143 * The function determines whether the specified window handle identifies
144 * an existing window.
148 * Handle to the window to test.
151 * If the window handle identifies an existing window, the return value
152 * is TRUE. If the window handle does not identify an existing window,
153 * the return value is FALSE.
157 IntIsWindow(HWND hWnd
)
161 if (!(Window
= UserGetWindowObject(hWnd
)))
170 IntIsWindowVisible(PWND Wnd
)
175 if (!Temp
) return TRUE
;
176 if (!(Temp
->style
& WS_VISIBLE
)) break;
177 if (Temp
->style
& WS_MINIMIZE
&& Temp
!= Wnd
) break;
178 if (Temp
->fnid
== FNID_DESKTOP
) return TRUE
;
179 Temp
= Temp
->spwndParent
;
185 IntGetParent(PWND Wnd
)
187 if (Wnd
->style
& WS_POPUP
)
189 return Wnd
->spwndOwner
;
191 else if (Wnd
->style
& WS_CHILD
)
193 return Wnd
->spwndParent
;
201 IntEnableWindow( HWND hWnd
, BOOL bEnable
)
207 if(!(pWnd
= UserGetWindowObject(hWnd
)))
212 /* check if updating is needed */
213 bIsDisabled
= !!(pWnd
->style
& WS_DISABLED
);
214 Update
= bIsDisabled
;
218 IntSetStyle( pWnd
, 0, WS_DISABLED
);
222 Update
= !bIsDisabled
;
224 co_IntSendMessage( hWnd
, WM_CANCELMODE
, 0, 0);
226 /* Remove keyboard focus from that window if it had focus */
227 if (hWnd
== IntGetThreadFocusWindow())
229 TRACE("IntEnableWindow SF NULL\n");
230 co_UserSetFocus(NULL
);
232 IntSetStyle( pWnd
, WS_DISABLED
, 0 );
237 IntNotifyWinEvent(EVENT_OBJECT_STATECHANGE
, pWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
238 co_IntSendMessage(hWnd
, WM_ENABLE
, (LPARAM
)bEnable
, 0);
240 // Return nonzero if it was disabled, or zero if it wasn't:
247 * Compile a list of all child window handles from given window.
250 * This function is similar to Wine WIN_ListChildren. The caller
251 * must free the returned list with ExFreePool.
255 IntWinListChildren(PWND Window
)
259 UINT Index
, NumChildren
= 0;
261 if (!Window
) return NULL
;
263 for (Child
= Window
->spwndChild
; Child
; Child
= Child
->spwndNext
)
266 List
= ExAllocatePoolWithTag(PagedPool
, (NumChildren
+ 1) * sizeof(HWND
), USERTAG_WINDOWLIST
);
269 ERR("Failed to allocate memory for children array\n");
270 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
273 for (Child
= Window
->spwndChild
, Index
= 0;
275 Child
= Child
->spwndNext
, ++Index
)
276 List
[Index
] = Child
->head
.h
;
283 IntGetNonChildAncestor(PWND pWnd
)
285 while(pWnd
&& (pWnd
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
286 pWnd
= pWnd
->spwndParent
;
291 IntIsTopLevelWindow(PWND pWnd
)
293 if ( pWnd
->spwndParent
&&
294 pWnd
->spwndParent
== co_GetDesktopWindow(pWnd
) ) return TRUE
;
299 IntValidateOwnerDepth(PWND Wnd
, PWND Owner
)
304 if ( !Owner
) return gNestedWindowLimit
>= Depth
;
305 if (Owner
== Wnd
) break;
306 Owner
= Owner
->spwndOwner
;
313 IntGetWindow(HWND hWnd
,
319 Wnd
= ValidateHwndNoErr(hWnd
);
327 if (Wnd
->spwndOwner
!= NULL
)
328 FoundWnd
= Wnd
->spwndOwner
;
332 if(Wnd
->spwndParent
!= NULL
)
334 FoundWnd
= Wnd
->spwndParent
;
335 if (FoundWnd
->spwndChild
!= NULL
)
336 FoundWnd
= FoundWnd
->spwndChild
;
340 if (Wnd
->spwndNext
!= NULL
)
341 FoundWnd
= Wnd
->spwndNext
;
345 if (Wnd
->spwndPrev
!= NULL
)
346 FoundWnd
= Wnd
->spwndPrev
;
350 if (Wnd
->spwndChild
!= NULL
)
351 FoundWnd
= Wnd
->spwndChild
;
356 while ( FoundWnd
->spwndNext
!= NULL
)
357 FoundWnd
= FoundWnd
->spwndNext
;
365 if (FoundWnd
!= NULL
)
366 Ret
= UserHMGetHandle(FoundWnd
);
370 DWORD FASTCALL
IntGetWindowContextHelpId( PWND pWnd
)
376 HelpId
= (DWORD
)(DWORD_PTR
)UserGetProp(pWnd
, gpsi
->atomContextHelpIdProp
);
378 pWnd
= IntGetParent(pWnd
);
380 while (pWnd
&& pWnd
->fnid
!= FNID_DESKTOP
);
384 /***********************************************************************
387 static void IntSendDestroyMsg(HWND hWnd
)
392 ti
= PsGetCurrentThreadWin32Thread();
393 Window
= UserGetWindowObject(hWnd
);
397 /* Look whether the focus is within the tree of windows we will
401 if ( ti
->MessageQueue
->spwndActive
== Window
|| // Fixes CORE-106 RegSvr32 exit and return focus to CMD.
402 (ti
->MessageQueue
->spwndActive
== NULL
&& ti
->MessageQueue
== IntGetFocusMessageQueue()) )
404 co_WinPosActivateOtherWindow(Window
);
407 /* Fixes CMD properties closing and returning focus to CMD */
408 if (ti
->MessageQueue
->spwndFocus
== Window
)
410 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
412 co_UserSetFocus(Window
->spwndParent
);
416 co_UserSetFocus(NULL
);
420 if (ti
->MessageQueue
->CaretInfo
->hWnd
== UserHMGetHandle(Window
))
422 co_IntDestroyCaret(ti
);
427 * Send the WM_DESTROY to the window.
430 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
433 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
434 * make sure that the window still exists when we come back.
437 if (IntIsWindow(hWnd
))
442 if (!(pWndArray
= IntWinListChildren( Window
))) return;
444 for (i
= 0; pWndArray
[i
]; i
++)
446 if (IntIsWindow( pWndArray
[i
] )) IntSendDestroyMsg( pWndArray
[i
] );
448 ExFreePoolWithTag(pWndArray
, USERTAG_WINDOWLIST
);
452 TRACE("destroyed itself while in WM_DESTROY!\n");
457 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
459 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
463 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
465 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
466 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
469 if (Wnd
->strName
.Buffer
!= NULL
)
471 Wnd
->strName
.Length
= 0;
472 Wnd
->strName
.MaximumLength
= 0;
473 DesktopHeapFree(Wnd
->head
.rpdesk
,
474 Wnd
->strName
.Buffer
);
475 Wnd
->strName
.Buffer
= NULL
;
478 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
479 // WindowObject->hWnd = NULL;
482 /***********************************************************************
485 * Destroy storage associated to a window. "Internals" p.358
487 * This is the "functional" DestroyWindows function ei. all stuff
488 * done in CreateWindow is undone here and not in DestroyWindow:-P
491 LRESULT
co_UserFreeWindow(PWND Window
,
492 PPROCESSINFO ProcessData
,
493 PTHREADINFO ThreadData
,
494 BOOLEAN SendMessages
)
500 BOOLEAN BelongsToThreadData
;
504 if(Window
->state2
& WNDS2_INDESTROY
)
506 TRACE("Tried to call IntDestroyWindow() twice\n");
509 Window
->state2
|= WNDS2_INDESTROY
;
510 Window
->style
&= ~WS_VISIBLE
;
511 Window
->head
.pti
->cVisWindows
--;
514 /* remove the window already at this point from the thread window list so we
515 don't get into trouble when destroying the thread windows while we're still
516 in IntDestroyWindow() */
517 RemoveEntryList(&Window
->ThreadListEntry
);
519 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
521 IntDeRegisterShellHookWindow(UserHMGetHandle(Window
));
523 /* free child windows */
524 Children
= IntWinListChildren(Window
);
527 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
529 if ((Child
= IntGetWindowObject(*ChildHandle
)))
531 if(!IntWndBelongsToThread(Child
, ThreadData
))
533 /* send WM_DESTROY messages to windows not belonging to the same thread */
534 co_IntSendMessage( UserHMGetHandle(Child
), WM_ASYNC_DESTROYWINDOW
, 0, 0 );
537 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
539 UserDereferenceObject(Child
);
542 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
548 * Clear the update region to make sure no WM_PAINT messages will be
549 * generated for this window while processing the WM_NCDESTROY.
551 co_UserRedrawWindow(Window
, NULL
, 0,
552 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
553 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
554 if(BelongsToThreadData
)
555 co_IntSendMessage(UserHMGetHandle(Window
), WM_NCDESTROY
, 0, 0);
558 DestroyTimersForWindow(ThreadData
, Window
);
560 /* Unregister hot keys */
561 UnregisterWindowHotKeys(Window
);
563 /* flush the message queue */
564 MsqRemoveWindowMessagesFromQueue(Window
);
566 /* from now on no messages can be sent to this window anymore */
567 Window
->state
|= WNDS_DESTROYED
;
568 Window
->fnid
|= FNID_FREED
;
570 /* don't remove the WINDOWSTATUS_DESTROYING bit */
572 /* reset shell window handles */
573 if(ThreadData
->rpdesk
)
575 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
576 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
578 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
579 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
582 /* Fixes dialog test_focus breakage due to r66237. */
583 if (ThreadData
->MessageQueue
->spwndFocus
== Window
)
584 ThreadData
->MessageQueue
->spwndFocus
= NULL
;
586 if (ThreadData
->MessageQueue
->spwndActive
== Window
)
587 ThreadData
->MessageQueue
->spwndActive
= NULL
;
589 if (ThreadData
->MessageQueue
->spwndCapture
== Window
)
594 //// Now kill those remaining "PAINTING BUG: Thread marked as containing dirty windows" spam!!!
595 if ( Window
->hrgnUpdate
!= NULL
|| Window
->state
& WNDS_INTERNALPAINT
)
597 MsqDecPaintCountQueue(Window
->head
.pti
);
598 if (Window
->hrgnUpdate
> HRGN_WINDOW
&& GreIsHandleValid(Window
->hrgnUpdate
))
600 GreDeleteObject(Window
->hrgnUpdate
);
602 Window
->hrgnUpdate
= NULL
;
603 Window
->state
&= ~WNDS_INTERNALPAINT
;
606 if (Window
->state
& (WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
))
608 Window
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
);
611 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
613 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
615 TRACE("UFW: IDMenu %p\n",Window
->IDMenu
);
616 IntDestroyMenuObject(Menu
, TRUE
);
620 if(Window
->SystemMenu
621 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
623 IntDestroyMenuObject(Menu
, TRUE
);
624 Window
->SystemMenu
= (HMENU
)0;
627 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
629 IntUnlinkWindow(Window
);
631 if (Window
->PropListItems
)
633 UserRemoveWindowProps(Window
);
634 TRACE("Window->PropListItems %lu\n",Window
->PropListItems
);
635 ASSERT(Window
->PropListItems
==0);
638 UserReferenceObject(Window
);
639 UserDeleteObject(UserHMGetHandle(Window
), TYPE_WINDOW
);
641 IntDestroyScrollBars(Window
);
643 if (Window
->pcls
->atomClassName
== gaGuiConsoleWndClass
)
645 /* Count only console windows manually */
646 co_IntUserManualGuiCheck(FALSE
);
649 /* dereference the class */
650 NT_ASSERT(Window
->head
.pti
!= NULL
);
651 IntDereferenceClass(Window
->pcls
,
652 Window
->head
.pti
->pDeskInfo
,
653 Window
->head
.pti
->ppi
);
658 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
659 GreDeleteObject(Window
->hrgnClip
);
660 Window
->hrgnClip
= NULL
;
662 Window
->head
.pti
->cWindows
--;
664 // ASSERT(Window != NULL);
665 UserFreeWindowInfo(Window
->head
.pti
, Window
);
667 UserDereferenceObject(Window
);
669 UserClipboardFreeWindow(Window
);
675 // Same as User32:IntGetWndProc.
678 IntGetWindowProc(PWND pWnd
,
683 WNDPROC gcpd
, Ret
= 0;
685 ASSERT(UserIsEnteredExclusive() == TRUE
);
689 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
691 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
693 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
696 Ret
= GETPFNCLIENTA(i
);
698 Ret
= GETPFNCLIENTW(i
);
704 if (Class
->fnid
== FNID_EDIT
)
705 Ret
= pWnd
->lpfnWndProc
;
708 Ret
= pWnd
->lpfnWndProc
;
710 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
714 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
715 Ret
= GETPFNCLIENTA(Class
->fnid
);
719 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
720 Ret
= GETPFNCLIENTW(Class
->fnid
);
723 if ( Ret
!= pWnd
->lpfnWndProc
)
726 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
729 gcpd
= (WNDPROC
)UserGetCPD(
731 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
734 return (gcpd
? gcpd
: Ret
);
738 IntSetWindowProc(PWND pWnd
,
743 PCALLPROCDATA CallProc
;
745 WNDPROC Ret
, chWndProc
= NULL
;
747 // Retrieve previous window proc.
748 Ret
= IntGetWindowProc(pWnd
, Ansi
);
752 if (IsCallProcHandle(NewWndProc
))
754 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
756 { // Reset new WndProc.
757 NewWndProc
= CallProc
->pfnClientPrevious
;
758 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
759 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
762 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
763 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
765 if (GETPFNCLIENTW(i
) == NewWndProc
)
767 chWndProc
= GETPFNSERVER(i
);
770 if (GETPFNCLIENTA(i
) == NewWndProc
)
772 chWndProc
= GETPFNSERVER(i
);
776 // If match, set/reset to Server Side and clear ansi.
779 pWnd
->lpfnWndProc
= chWndProc
;
780 pWnd
->Unicode
= TRUE
;
781 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
782 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
786 pWnd
->Unicode
= !Ansi
;
787 // Handle the state change in here.
789 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
791 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
793 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
794 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
796 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
798 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
802 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
803 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
807 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
808 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
811 // Now set the new window proc.
812 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
818 /* INTERNAL ******************************************************************/
821 // This fixes a check for children messages that need paint while searching the parents messages!
822 // Fixes wine msg:test_paint_messages:WmParentErasePaint ..
825 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
827 PWND Window
= BaseWindow
;
830 if ( Window
== NULL
|| (Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
833 Window
= Window
->spwndParent
;
835 while(Parent
!= Window
);
841 Link the window into siblings list
842 children and parent are kept in place.
847 PWND WndInsertAfter
/* set to NULL if top sibling */
850 if ((Wnd
->spwndPrev
= WndInsertAfter
))
852 /* link after WndInsertAfter */
853 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
854 Wnd
->spwndNext
->spwndPrev
= Wnd
;
856 Wnd
->spwndPrev
->spwndNext
= Wnd
;
861 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
862 Wnd
->spwndNext
->spwndPrev
= Wnd
;
864 Wnd
->spwndParent
->spwndChild
= Wnd
;
869 Note: Wnd->spwndParent can be null if it is the desktop.
871 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
873 if (hWndPrev
== HWND_NOTOPMOST
)
875 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
876 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
877 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
878 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
881 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
883 if (hWndPrev
== HWND_BOTTOM
)
885 /* Link in the bottom of the list */
888 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
889 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
890 WndInsertAfter
= WndInsertAfter
->spwndNext
;
892 IntLinkWindow(Wnd
, WndInsertAfter
);
893 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
895 else if (hWndPrev
== HWND_TOPMOST
)
897 /* Link in the top of the list */
898 IntLinkWindow(Wnd
, NULL
);
900 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
902 else if (hWndPrev
== HWND_TOP
)
904 /* Link it after the last topmost window */
905 PWND WndInsertBefore
;
907 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
909 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
911 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
913 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
914 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
916 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
919 WndInsertBefore
= WndInsertBefore
->spwndNext
;
923 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
927 /* Link it after hWndPrev */
930 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
931 /* Are we called with an erroneous handle */
932 if(WndInsertAfter
== NULL
)
934 /* Link in a default position */
935 IntLinkHwnd(Wnd
, HWND_TOP
);
939 IntLinkWindow(Wnd
, WndInsertAfter
);
941 /* Fix the WS_EX_TOPMOST flag */
942 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
944 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
948 if(WndInsertAfter
->spwndNext
&&
949 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
951 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
955 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
959 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
963 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
966 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
967 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
969 //ERR("ProcessOwnerSwap Old out.\n");
970 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
976 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
979 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
981 //ERR("ProcessOwnerSwap New in.\n");
982 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
986 // FIXME: System Tray checks.
990 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
992 PWND Wnd
, WndOldOwner
, WndNewOwner
;
995 Wnd
= IntGetWindowObject(hWnd
);
999 WndOldOwner
= Wnd
->spwndOwner
;
1001 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1002 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1004 if (!WndNewOwner
&& hWndNewOwner
)
1006 EngSetLastError(ERROR_INVALID_PARAMETER
);
1011 /* if parent belongs to a different thread and the window isn't */
1012 /* top-level, attach the two threads */
1013 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1015 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1019 Wnd
->spwndOwner
= WndNewOwner
;
1023 Wnd
->spwndOwner
= NULL
;
1028 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1029 EngSetLastError(ERROR_INVALID_PARAMETER
);
1033 UserDereferenceObject(Wnd
);
1038 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1040 PWND WndOldParent
, pWndExam
;
1043 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1046 ASSERT(WndNewParent
);
1047 ASSERT_REFS_CO(Wnd
);
1048 ASSERT_REFS_CO(WndNewParent
);
1050 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1052 EngSetLastError(ERROR_ACCESS_DENIED
);
1056 /* Some applications try to set a child as a parent */
1057 if (IntIsChildWindow(Wnd
, WndNewParent
))
1059 TRACE("IntSetParent try to set a child as a parent.\n");
1060 EngSetLastError( ERROR_INVALID_PARAMETER
);
1064 pWndExam
= WndNewParent
; // Load parent Window to examine.
1065 // Now test for set parent to parent hit.
1068 if (Wnd
== pWndExam
)
1070 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1071 EngSetLastError(ERROR_INVALID_PARAMETER
);
1074 pWndExam
= pWndExam
->spwndParent
;
1078 * Windows hides the window first, then shows it again
1079 * including the WM_SHOWWINDOW messages and all
1081 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1083 /* Window must belong to current process */
1084 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1086 ERR("IntSetParent Window must belong to current process!\n");
1090 WndOldParent
= Wnd
->spwndParent
;
1092 if ( WndOldParent
&&
1093 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1094 pt
.x
= Wnd
->rcWindow
.right
;
1096 pt
.x
= Wnd
->rcWindow
.left
;
1097 pt
.y
= Wnd
->rcWindow
.top
;
1099 IntScreenToClient(WndOldParent
, &pt
);
1101 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1103 if (WndNewParent
!= WndOldParent
)
1105 /* Unlink the window from the siblings list */
1106 IntUnlinkWindow(Wnd
);
1107 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1109 /* Set the new parent */
1110 Wnd
->spwndParent
= WndNewParent
;
1112 if ( Wnd
->style
& WS_CHILD
&&
1114 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1116 ERR("SetParent Top Most from Pop up!\n");
1117 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1120 /* Link the window with its new siblings */
1122 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1123 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1127 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1128 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1130 Wnd
->style
|= WS_CLIPSIBLINGS
;
1131 DceResetActiveDCEs(Wnd
);
1134 /* if parent belongs to a different thread and the window isn't */
1135 /* top-level, attach the two threads */
1136 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1138 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1140 if (WndOldParent
&& (Wnd
->head
.pti
!= WndOldParent
->head
.pti
))
1142 //ERR("SetParent Old out.\n");
1143 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1146 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1148 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1150 //ERR("SetParent New in.\n");
1151 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1156 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1157 swFlags
|= SWP_NOACTIVATE
;
1159 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1161 * SetParent additionally needs to make hwnd the top window
1162 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1163 * WM_WINDOWPOSCHANGED notification messages.
1165 //ERR("IntSetParent SetWindowPos 1\n");
1166 co_WinPosSetWindowPos( Wnd
,
1167 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1168 pt
.x
, pt
.y
, 0, 0, swFlags
);
1169 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1170 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1172 return WndOldParent
;
1176 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1178 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1179 HWND hWndOldParent
= NULL
;
1180 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1182 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1184 EngSetLastError(ERROR_INVALID_PARAMETER
);
1188 if (hWndChild
== IntGetDesktopWindow())
1190 ERR("UserSetParent Access Denied!\n");
1191 EngSetLastError(ERROR_ACCESS_DENIED
);
1197 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1199 ERR("UserSetParent Bad New Parent!\n");
1205 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1211 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1213 ERR("UserSetParent Bad Child!\n");
1217 UserRefObjectCo(Wnd
, &Ref
);
1218 UserRefObjectCo(WndParent
, &ParentRef
);
1219 //ERR("Enter co_IntSetParent\n");
1220 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1221 //ERR("Leave co_IntSetParent\n");
1222 UserDerefObjectCo(WndParent
);
1223 UserDerefObjectCo(Wnd
);
1227 hWndOldParent
= WndOldParent
->head
.h
;
1228 UserDereferenceObject(WndOldParent
);
1231 return( hWndOldParent
);
1234 /* Unlink the window from siblings. children and parent are kept in place. */
1236 IntUnlinkWindow(PWND Wnd
)
1239 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1242 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1244 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1245 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1247 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1250 /* FUNCTIONS *****************************************************************/
1253 * As best as I can figure, this function is used by EnumWindows,
1254 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1256 * It's supposed to build a list of HWNDs to return to the caller.
1257 * We can figure out what kind of list by what parameters are
1265 NtUserBuildHwndList(
1278 return ERROR_INVALID_PARAMETER
;
1280 if (hwndParent
|| !dwThreadId
)
1283 PWND Parent
, Window
;
1287 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1289 return ERROR_INVALID_HANDLE
;
1294 Status
= IntValidateDesktopHandle(hDesktop
,
1298 if(!NT_SUCCESS(Status
))
1300 return ERROR_INVALID_HANDLE
;
1303 hwndParent
= Desktop
->DesktopWindow
;
1310 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1311 (Window
= Parent
->spwndChild
))
1313 BOOL bGoDown
= TRUE
;
1315 Status
= STATUS_SUCCESS
;
1320 if(dwCount
++ < *pBufSize
&& pWnd
)
1324 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1325 *pWnd
= Window
->head
.h
;
1328 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1330 Status
= _SEH2_GetExceptionCode();
1333 if(!NT_SUCCESS(Status
))
1335 SetLastNtError(Status
);
1339 if (Window
->spwndChild
&& bChildren
)
1341 Window
= Window
->spwndChild
;
1346 if (Window
->spwndNext
)
1348 Window
= Window
->spwndNext
;
1352 Window
= Window
->spwndParent
;
1353 if (Window
== Parent
)
1362 ObDereferenceObject(Desktop
);
1365 else // Build EnumThreadWindows list!
1368 PTHREADINFO W32Thread
;
1372 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1373 if (!NT_SUCCESS(Status
))
1375 ERR("Thread Id is not valid!\n");
1376 return ERROR_INVALID_PARAMETER
;
1378 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1380 ObDereferenceObject(Thread
);
1381 TRACE("Tried to enumerate windows of a non gui thread\n");
1382 return ERROR_INVALID_PARAMETER
;
1385 // Do not use Thread link list due to co_UserFreeWindow!!!
1386 // Current = W32Thread->WindowListHead.Flink;
1387 // Fixes Api:CreateWindowEx tests!!!
1388 List
= IntWinListChildren(UserGetDesktopWindow());
1392 for (i
= 0; List
[i
]; i
++)
1394 Window
= ValidateHwndNoErr(List
[i
]);
1395 if (Window
&& Window
->head
.pti
== W32Thread
)
1397 if (dwCount
< *pBufSize
&& pWnd
)
1401 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1402 *pWnd
= Window
->head
.h
;
1405 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1407 Status
= _SEH2_GetExceptionCode();
1410 if (!NT_SUCCESS(Status
))
1412 ERR("Failure to build window list!\n");
1413 SetLastNtError(Status
);
1420 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
1423 ObDereferenceObject(Thread
);
1426 *pBufSize
= dwCount
;
1427 return STATUS_SUCCESS
;
1430 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1432 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1433 !(pWindow
->ExStyle
& WS_EX_NOPARENTNOTIFY
))
1435 if (VerifyWnd(pWindow
->spwndParent
) && pWindow
->spwndParent
!= UserGetDesktopWindow())
1437 USER_REFERENCE_ENTRY Ref
;
1438 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1439 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1441 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1442 (LPARAM
)pWindow
->head
.h
);
1443 UserDerefObjectCo(pWindow
->spwndParent
);
1449 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1451 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1453 /* default positioning for overlapped windows */
1454 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1457 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1459 pMonitor
= UserGetPrimaryMonitor();
1461 /* Check if we don't have a monitor attached yet */
1462 if(pMonitor
== NULL
)
1470 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1472 if (IS_DEFAULT(Cs
->x
))
1474 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1476 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1478 Cs
->x
= ProcessParams
->StartingX
;
1479 Cs
->y
= ProcessParams
->StartingY
;
1483 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1484 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1485 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1486 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1488 /* reset counter and position */
1491 pMonitor
->cWndStack
= 0;
1493 pMonitor
->cWndStack
++;
1497 if (IS_DEFAULT(Cs
->cx
))
1499 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1501 Cs
->cx
= ProcessParams
->CountX
;
1502 Cs
->cy
= ProcessParams
->CountY
;
1506 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1507 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1510 /* neither x nor cx are default. Check the y values .
1511 * In the trace we see Outlook and Outlook Express using
1512 * cy set to CW_USEDEFAULT when opening the address book.
1514 else if (IS_DEFAULT(Cs
->cy
))
1516 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1517 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1522 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1523 if(IS_DEFAULT(Cs
->x
))
1528 if(IS_DEFAULT(Cs
->cx
))
1538 /* Allocates and initializes a window */
1539 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1540 PLARGE_STRING WindowName
,
1545 PDESKTOP pdeskCreated
)
1549 PTHREADINFO pti
= NULL
;
1551 BOOL bUnicodeWindow
;
1553 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1555 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1556 { // Need both here for wine win.c test_CreateWindow.
1557 //if (Cs->hwndParent && ParentWindow)
1558 if (ParentWindow
) // It breaks more tests..... WIP.
1560 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1561 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1562 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1563 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1567 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1569 * Dialog boxes and message boxes do not inherit layout, so you must
1570 * set the layout explicitly.
1572 if ( Class
->fnid
!= FNID_DIALOG
)
1574 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1576 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1582 /* Automatically add WS_EX_WINDOWEDGE */
1583 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1584 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1585 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1586 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1588 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1590 /* Is it a unicode window? */
1591 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1592 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1594 /* Allocate the new window */
1595 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1596 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1600 sizeof(WND
) + Class
->cbwndExtra
);
1607 TRACE("Created window object with handle %p\n", hWnd
);
1609 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1610 { /* HACK: Helper for win32csr/desktopbg.c */
1611 /* If there is no desktop window yet, we must be creating it */
1612 TRACE("CreateWindow setting desktop.\n");
1613 pdeskCreated
->DesktopWindow
= hWnd
;
1614 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1618 * Fill out the structure describing it.
1620 /* Remember, pWnd->head is setup in object.c ... */
1621 pWnd
->spwndParent
= ParentWindow
;
1622 pWnd
->spwndOwner
= OwnerWindow
;
1624 pWnd
->spwndLastActive
= pWnd
;
1625 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1627 pWnd
->hModule
= Cs
->hInstance
;
1628 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1629 pWnd
->ExStyle
= Cs
->dwExStyle
;
1630 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1631 pWnd
->pActCtx
= acbiBuffer
;
1632 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1633 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1635 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1637 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1638 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1641 pWnd
->head
.pti
->cWindows
++;
1643 if (Class
->spicn
&& !Class
->spicnSm
)
1645 HICON IconSmHandle
= NULL
;
1646 if((Class
->spicn
->CURSORF_flags
& (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1647 == (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1649 IconSmHandle
= co_IntCopyImage(
1650 UserHMGetHandle(Class
->spicn
),
1652 UserGetSystemMetrics( SM_CXSMICON
),
1653 UserGetSystemMetrics( SM_CYSMICON
),
1654 LR_COPYFROMRESOURCE
);
1658 /* Retry without copying from resource */
1659 IconSmHandle
= co_IntCopyImage(
1660 UserHMGetHandle(Class
->spicn
),
1662 UserGetSystemMetrics( SM_CXSMICON
),
1663 UserGetSystemMetrics( SM_CYSMICON
),
1669 Class
->spicnSm
= UserGetCurIconObject(IconSmHandle
);
1670 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1674 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1675 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1677 /* BugBoy Comments: Comment below say that System classes are always created
1678 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1679 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1681 No where can I see in code or through testing does the window change back
1682 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1683 see what problems this would cause. */
1685 // Set WndProc from Class.
1686 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1688 // GetWindowProc, test for non server side default classes and set WndProc.
1689 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1693 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1694 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1698 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1699 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1703 // If not an Unicode caller, set Ansi creator bit.
1704 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1706 // Clone Class Ansi/Unicode proc type.
1707 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1709 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1710 pWnd
->Unicode
= FALSE
;
1714 * It seems there can be both an Ansi creator and Unicode Class Window
1715 * WndProc, unless the following overriding conditions occur:
1717 if ( !bUnicodeWindow
&&
1718 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1719 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1720 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1721 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1722 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1723 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1724 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1725 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1726 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1727 { // Override Class and set the window Ansi WndProc.
1728 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1729 pWnd
->Unicode
= FALSE
;
1732 { // Set the window Unicode WndProc.
1733 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1734 pWnd
->Unicode
= TRUE
;
1738 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1739 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1740 Dont understand why it does this. */
1741 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1743 PCALLPROCDATA CallProc
;
1744 CallProc
= CreateCallProc(pWnd
->head
.rpdesk
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1748 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1749 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1753 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1757 InitializeListHead(&pWnd
->PropListHead
);
1758 pWnd
->PropListItems
= 0;
1760 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1762 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1763 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1764 if (pWnd
->strName
.Buffer
== NULL
)
1769 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1770 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1771 pWnd
->strName
.Length
= WindowName
->Length
;
1772 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1775 /* Correct the window style. */
1776 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1778 pWnd
->style
|= WS_CLIPSIBLINGS
;
1779 if (!(pWnd
->style
& WS_POPUP
))
1781 pWnd
->style
|= WS_CAPTION
;
1785 /* WS_EX_WINDOWEDGE depends on some other styles */
1786 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1787 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1788 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1790 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1791 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1792 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1795 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1797 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1798 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1800 /* Set the window menu */
1801 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1805 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1807 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1809 UNICODE_STRING MenuName
;
1812 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1814 MenuName
.Length
= 0;
1815 MenuName
.MaximumLength
= 0;
1816 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1820 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1822 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1823 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1827 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1830 if ( ParentWindow
&&
1831 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1832 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1834 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1836 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1838 EngSetLastError(ERROR_INVALID_PARAMETER
);
1841 if ( pWnd
->spwndOwner
&&
1842 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1844 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1846 if ( pWnd
->spwndOwner
&&
1847 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1848 pti
!= pWnd
->spwndOwner
->head
.pti
)
1850 //ERR("CreateWindow Owner in.\n");
1851 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1855 /* Insert the window into the thread's window list. */
1856 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1858 /* Handle "CS_CLASSDC", it is tested first. */
1859 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1860 { /* One DCE per class to have CLASS. */
1861 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1863 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1864 { /* Allocate a DCE for this window. */
1865 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1871 ERR("IntCreateWindow Allocation Error.\n");
1872 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1875 UserDereferenceObject(pWnd
);
1883 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1884 PUNICODE_STRING ClassName
,
1885 PLARGE_STRING WindowName
,
1889 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1890 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1891 PWINSTATION_OBJECT WinSta
;
1894 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1895 CBT_CREATEWNDW
* pCbtCreate
;
1897 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1899 DWORD dwShowMode
= SW_SHOW
;
1900 CREATESTRUCTW
*pCsw
= NULL
;
1901 PVOID pszClass
= NULL
, pszName
= NULL
;
1904 /* Get the current window station and reference it */
1905 pti
= GetW32ThreadInfo();
1906 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1908 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1909 return NULL
; // There is nothing to cleanup.
1911 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1912 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1917 /* Get the class and reference it */
1918 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
1921 ERR("Failed to find class %wZ\n", ClassName
);
1925 /* Now find the parent and the owner window */
1926 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
1929 if (Cs
->hwndParent
== HWND_MESSAGE
)
1931 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
1933 else if (Cs
->hwndParent
)
1935 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1936 hWndOwner
= Cs
->hwndParent
;
1938 hWndParent
= Cs
->hwndParent
;
1940 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1942 ERR("Cannot create a child window without a parrent!\n");
1943 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1944 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1947 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1948 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1950 /* FIXME: Is this correct? */
1952 OwnerWindow
= UserGetAncestor(OwnerWindow
, GA_ROOT
);
1954 /* Fix the position and the size of the window */
1957 UserRefObjectCo(ParentWindow
, &ParentRef
);
1958 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
1961 /* Allocate and initialize the new window */
1962 Window
= IntCreateWindow(Cs
,
1971 ERR("IntCreateWindow failed!\n");
1975 hWnd
= UserHMGetHandle(Window
);
1976 hwndInsertAfter
= HWND_TOP
;
1978 UserRefObjectCo(Window
, &Ref
);
1979 UserDereferenceObject(Window
);
1980 ObDereferenceObject(WinSta
);
1982 //// Check for a hook to eliminate overhead. ////
1983 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
1985 // Allocate the calling structures Justin Case this goes Global.
1986 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
1987 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
1988 if (!pCsw
|| !pCbtCreate
)
1990 ERR("UserHeapAlloc() failed!\n");
1994 /* Fill the new CREATESTRUCTW */
1995 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
1996 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
1998 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
1999 if (!IS_ATOM(ClassName
->Buffer
))
2001 if (Window
->state
& WNDS_ANSICREATOR
)
2003 ANSI_STRING AnsiString
;
2004 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2005 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2008 ERR("UserHeapAlloc() failed!\n");
2011 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2012 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2013 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2017 UNICODE_STRING UnicodeString
;
2018 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2019 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2022 ERR("UserHeapAlloc() failed!\n");
2025 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2026 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2027 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2029 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2031 if (WindowName
->Length
)
2033 UNICODE_STRING Name
;
2034 Name
.Buffer
= WindowName
->Buffer
;
2035 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2036 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2038 if (Window
->state
& WNDS_ANSICREATOR
)
2040 ANSI_STRING AnsiString
;
2041 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2042 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2045 ERR("UserHeapAlloc() failed!\n");
2048 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2049 AnsiString
.Buffer
= (PCHAR
)pszName
;
2050 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2054 UNICODE_STRING UnicodeString
;
2055 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2056 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2059 ERR("UserHeapAlloc() failed!\n");
2062 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2063 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2064 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2066 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2069 pCbtCreate
->lpcs
= pCsw
;
2070 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2072 //// Call the WH_CBT hook ////
2073 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2076 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2079 // Write back changes.
2084 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2087 /* NCCREATE and WM_NCCALCSIZE need the original values */
2088 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2089 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2091 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2093 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2095 Cs
->x
+= ParentWindow
->rcClient
.left
;
2096 Cs
->y
+= ParentWindow
->rcClient
.top
;
2100 /* Send the WM_GETMINMAXINFO message */
2104 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2106 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2107 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2108 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2109 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2110 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2113 Window
->rcWindow
.left
= Cs
->x
;
2114 Window
->rcWindow
.top
= Cs
->y
;
2115 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2116 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2118 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2120 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2121 RECTL_vOffsetRect(&Window->rcWindow,
2122 ParentWindow->rcClient.left,
2123 ParentWindow->rcClient.top);
2126 /* correct child window coordinates if mirroring on parent is enabled */
2127 if (ParentWindow
!= NULL
)
2129 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2130 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2132 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2133 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2137 Window
->rcClient
= Window
->rcWindow
;
2139 /* Link the window */
2140 if (NULL
!= ParentWindow
)
2142 /* Link the window into the siblings list */
2143 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2144 IntLinkHwnd(Window
, HWND_BOTTOM
);
2146 IntLinkHwnd(Window
, hwndInsertAfter
);
2149 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2151 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2152 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2155 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2157 if ( !IntIsTopLevelWindow(Window
) )
2159 if (pti
!= Window
->spwndParent
->head
.pti
)
2161 //ERR("CreateWindow Parent in.\n");
2162 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2167 /* Send the NCCREATE message */
2168 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2171 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2175 /* Send the WM_NCCALCSIZE message */
2178 MaxPos
.x
= Window
->rcWindow
.left
;
2179 MaxPos
.y
= Window
->rcWindow
.top
;
2181 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2182 //rc = Window->rcWindow;
2183 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2184 //Window->rcClient = rc;
2186 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2187 MaxPos
.y
- Window
->rcWindow
.top
);
2190 /* Send the WM_CREATE message. */
2191 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2192 if (Result
== (LRESULT
)-1)
2194 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2198 /* Send the EVENT_OBJECT_CREATE event */
2199 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2201 /* By setting the flag below it can be examined to determine if the window
2202 was created successfully and a valid pwnd was passed back to caller since
2203 from here the function has to succeed. */
2204 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2206 /* Send the WM_SIZE and WM_MOVE messages. */
2207 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2209 co_WinPosSendSizeMove(Window
);
2212 /* Show or maybe minimize or maximize the window. */
2214 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2215 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2218 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2220 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2221 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2222 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2223 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2224 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2227 /* Send the WM_PARENTNOTIFY message */
2228 IntSendParentNotify(Window
, WM_CREATE
);
2230 /* Notify the shell that a new window was created */
2231 if (Window
->spwndParent
== UserGetDesktopWindow() &&
2232 Window
->spwndOwner
== NULL
&&
2233 (Window
->style
& WS_VISIBLE
) &&
2234 (!(Window
->ExStyle
& WS_EX_TOOLWINDOW
) ||
2235 (Window
->ExStyle
& WS_EX_APPWINDOW
)))
2237 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2240 /* Initialize and show the window's scrollbars */
2241 if (Window
->style
& WS_VSCROLL
)
2243 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2245 if (Window
->style
& WS_HSCROLL
)
2247 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2250 /* Show the new window */
2251 if (Cs
->style
& WS_VISIBLE
)
2253 if (Window
->style
& WS_MAXIMIZE
)
2254 dwShowMode
= SW_SHOW
;
2255 else if (Window
->style
& WS_MINIMIZE
)
2256 dwShowMode
= SW_SHOWMINIMIZED
;
2258 co_WinPosShowWindow(Window
, dwShowMode
);
2260 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2262 ASSERT(ParentWindow
);
2265 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2266 /* ShowWindow won't activate child windows */
2267 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2271 if (Class
->atomClassName
== gaGuiConsoleWndClass
)
2273 /* Count only console windows manually */
2274 co_IntUserManualGuiCheck(TRUE
);
2277 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2283 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2284 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2286 co_UserDestroyWindow(Window
);
2288 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2291 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2292 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2293 if (pszName
) UserHeapFree(pszName
);
2294 if (pszClass
) UserHeapFree(pszClass
);
2298 UserDerefObjectCo(Window
);
2300 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2307 ProbeAndCaptureLargeString(
2308 OUT PLARGE_STRING plstrSafe
,
2309 IN PLARGE_STRING plstrUnsafe
)
2311 LARGE_STRING lstrTemp
;
2312 PVOID pvBuffer
= NULL
;
2316 /* Probe and copy the string */
2317 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2318 lstrTemp
= *plstrUnsafe
;
2320 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2323 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2327 if (lstrTemp
.Length
!= 0)
2329 /* Allocate a buffer from paged pool */
2330 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2333 return STATUS_NO_MEMORY
;
2338 /* Probe and copy the buffer */
2339 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2340 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2342 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2344 /* Cleanup and fail */
2345 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2346 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2351 /* Set the output string */
2352 plstrSafe
->Buffer
= pvBuffer
;
2353 plstrSafe
->Length
= lstrTemp
.Length
;
2354 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2356 return STATUS_SUCCESS
;
2360 * \todo Allow passing plstrClassName as ANSI.
2364 NtUserCreateWindowEx(
2366 PLARGE_STRING plstrClassName
,
2367 PLARGE_STRING plstrClsVersion
,
2368 PLARGE_STRING plstrWindowName
,
2376 HINSTANCE hInstance
,
2382 LARGE_STRING lstrWindowName
;
2383 LARGE_STRING lstrClassName
;
2384 UNICODE_STRING ustrClassName
;
2389 lstrWindowName
.Buffer
= NULL
;
2390 lstrClassName
.Buffer
= NULL
;
2392 ASSERT(plstrWindowName
);
2394 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2396 /* check hMenu is valid handle */
2397 if (hMenu
&& !UserGetMenuObject(hMenu
))
2399 ERR("NtUserCreateWindowEx: Got an invalid menu handle!\n");
2400 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
2405 /* Copy the window name to kernel mode */
2406 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2407 if (!NT_SUCCESS(Status
))
2409 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2410 SetLastNtError(Status
);
2414 plstrWindowName
= &lstrWindowName
;
2416 /* Check if the class is an atom */
2417 if (IS_ATOM(plstrClassName
))
2419 /* It is, pass the atom in the UNICODE_STRING */
2420 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2421 ustrClassName
.Length
= 0;
2422 ustrClassName
.MaximumLength
= 0;
2426 /* It's not, capture the class name */
2427 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2428 if (!NT_SUCCESS(Status
))
2430 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2431 /* Set last error, cleanup and return */
2432 SetLastNtError(Status
);
2436 /* We pass it on as a UNICODE_STRING */
2437 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2438 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2439 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2442 /* Fill the CREATESTRUCTW */
2443 /* we will keep here the original parameters */
2445 Cs
.lpCreateParams
= lpParam
;
2446 Cs
.hInstance
= hInstance
;
2448 Cs
.hwndParent
= hWndParent
;
2453 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2454 Cs
.lpszClass
= ustrClassName
.Buffer
;
2455 Cs
.dwExStyle
= dwExStyle
;
2457 UserEnterExclusive();
2459 /* Call the internal function */
2460 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClassName
, plstrWindowName
, acbiBuffer
);
2464 ERR("co_UserCreateWindowEx failed!\n");
2466 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2471 if (lstrWindowName
.Buffer
)
2473 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2475 if (lstrClassName
.Buffer
)
2477 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2484 BOOLEAN
co_UserDestroyWindow(PVOID Object
)
2490 PWND Window
= Object
;
2492 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2494 hWnd
= Window
->head
.h
;
2495 ti
= PsGetCurrentThreadWin32Thread();
2497 TRACE("co_UserDestroyWindow \n");
2499 /* Check for owner thread */
2500 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2502 /* Check if we are destroying the desktop window */
2503 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2505 EngSetLastError(ERROR_ACCESS_DENIED
);
2510 /* If window was created successfully and it is hooked */
2511 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2513 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2515 ERR("Destroy Window WH_CBT Call Hook return!\n");
2520 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2522 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2524 if (Window
->spwndOwner
)
2526 //ERR("DestroyWindow Owner out.\n");
2527 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2532 /* Inform the parent */
2533 if (Window
->style
& WS_CHILD
)
2535 IntSendParentNotify(Window
, WM_DESTROY
);
2538 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
2540 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
2543 /* Hide the window */
2544 if (Window
->style
& WS_VISIBLE
)
2546 if (Window
->style
& WS_CHILD
)
2548 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
2549 co_WinPosShowWindow(Window
, SW_HIDE
);
2553 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2557 // Adjust last active.
2558 if ((pwndTemp
= Window
->spwndOwner
))
2560 while (pwndTemp
->spwndOwner
)
2561 pwndTemp
= pwndTemp
->spwndOwner
;
2563 if (pwndTemp
->spwndLastActive
== Window
)
2564 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2567 if (Window
->spwndParent
&& IntIsWindow(UserHMGetHandle(Window
)))
2569 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2571 if (!IntIsTopLevelWindow(Window
))
2573 //ERR("DestroyWindow Parent out.\n");
2574 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2579 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2580 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2581 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2582 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2583 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2584 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2585 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2586 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2589 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2592 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2594 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2596 ERR("Destroying the ShellWindow!\n");
2597 ti
->pDeskInfo
->hShellWindow
= NULL
;
2601 IntEngWindowChanged(Window
, WOC_DELETE
);
2603 if (!IntIsWindow(UserHMGetHandle(Window
)))
2608 /* Recursively destroy owned windows */
2610 if (! (Window
->style
& WS_CHILD
))
2614 BOOL GotOne
= FALSE
;
2617 PWND Child
, Desktop
;
2619 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2620 UserGetWindowObject(IntGetDesktopWindow());
2621 Children
= IntWinListChildren(Desktop
);
2625 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2627 Child
= UserGetWindowObject(*ChildHandle
);
2630 if (Child
->spwndOwner
!= Window
)
2635 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2637 USER_REFERENCE_ENTRY ChildRef
;
2638 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2639 co_UserDestroyWindow(Child
);
2640 UserDerefObjectCo(Child
); // Temp HACK?
2646 if (Child
->spwndOwner
!= NULL
)
2648 Child
->spwndOwner
= NULL
;
2652 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2661 /* Generate mouse move message for the next window */
2662 msg
.message
= WM_MOUSEMOVE
;
2663 msg
.wParam
= UserGetMouseButtonsState();
2664 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2665 msg
.pt
= gpsi
->ptCursor
;
2666 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2668 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2670 /* Send destroy messages */
2672 IntSendDestroyMsg(UserHMGetHandle(Window
));
2674 if (!IntIsWindow(UserHMGetHandle(Window
)))
2679 /* Destroy the window storage */
2680 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2690 NtUserDestroyWindow(HWND Wnd
)
2693 DECLARE_RETURN(BOOLEAN
);
2695 USER_REFERENCE_ENTRY Ref
;
2697 TRACE("Enter NtUserDestroyWindow\n");
2698 UserEnterExclusive();
2700 if (!(Window
= UserGetWindowObject(Wnd
)))
2705 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2706 ret
= co_UserDestroyWindow(Window
);
2707 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2712 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2718 static HWND FASTCALL
2719 IntFindWindow(PWND Parent
,
2722 PUNICODE_STRING WindowName
)
2724 BOOL CheckWindowName
;
2727 UNICODE_STRING CurrentWindowName
;
2731 CheckWindowName
= WindowName
->Buffer
!= 0;
2733 if((List
= IntWinListChildren(Parent
)))
2738 /* skip handles before and including ChildAfter */
2739 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2743 /* search children */
2747 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2752 /* Do not send WM_GETTEXT messages in the kernel mode version!
2753 The user mode version however calls GetWindowText() which will
2754 send WM_GETTEXT messages to windows belonging to its processes */
2755 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2757 // FIXME: LARGE_STRING truncated
2758 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2759 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2760 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2761 if(!CheckWindowName
||
2762 (Child
->strName
.Length
< 0xFFFF &&
2763 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2765 Ret
= Child
->head
.h
;
2770 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2778 * Searches a window's children for a window with the specified
2781 * hwndParent = The window whose childs are to be searched.
2783 * HWND_MESSAGE = message-only windows
2785 * hwndChildAfter = Search starts after this child window.
2786 * NULL = start from beginning
2788 * ucClassName = Class name to search for
2789 * Reguired parameter.
2791 * ucWindowName = Window name
2792 * ->Buffer == NULL = don't care
2795 * The HWND of the window if it was found, otherwise NULL
2801 NtUserFindWindowEx(HWND hwndParent
,
2802 HWND hwndChildAfter
,
2803 PUNICODE_STRING ucClassName
,
2804 PUNICODE_STRING ucWindowName
,
2807 PWND Parent
, ChildAfter
;
2808 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2809 HWND Desktop
, Ret
= NULL
;
2810 BOOL DoMessageWnd
= FALSE
;
2811 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2812 DECLARE_RETURN(HWND
);
2814 TRACE("Enter NtUserFindWindowEx\n");
2817 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2821 if (ucClassName
!= NULL
)
2823 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2824 if (ClassName
.Length
!= 0)
2826 ProbeForRead(ClassName
.Buffer
,
2830 else if (!IS_ATOM(ClassName
.Buffer
))
2832 EngSetLastError(ERROR_INVALID_PARAMETER
);
2836 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2843 if (ucWindowName
!= NULL
)
2845 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2846 if (WindowName
.Length
!= 0)
2848 ProbeForRead(WindowName
.Buffer
,
2854 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2856 SetLastNtError(_SEH2_GetExceptionCode());
2857 _SEH2_YIELD(RETURN(NULL
));
2861 if (ucClassName
!= NULL
)
2863 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2864 !IS_ATOM(ClassName
.Buffer
))
2866 EngSetLastError(ERROR_INVALID_PARAMETER
);
2869 else if (ClassAtom
== (RTL_ATOM
)0)
2871 /* LastError code was set by IntGetAtomFromStringOrAtom */
2877 Desktop
= IntGetCurrentThreadDesktopWindow();
2879 if(hwndParent
== NULL
)
2881 hwndParent
= Desktop
;
2882 DoMessageWnd
= TRUE
;
2884 else if(hwndParent
== HWND_MESSAGE
)
2886 hwndParent
= IntGetMessageWindow();
2889 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2895 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2902 if(Parent
->head
.h
== Desktop
)
2905 PWND TopLevelWindow
;
2906 BOOLEAN CheckWindowName
;
2907 BOOLEAN WindowMatches
;
2908 BOOLEAN ClassMatches
;
2910 /* windows searches through all top-level windows if the parent is the desktop
2913 if((List
= IntWinListChildren(Parent
)))
2919 /* skip handles before and including ChildAfter */
2920 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2924 CheckWindowName
= WindowName
.Buffer
!= 0;
2926 /* search children */
2929 UNICODE_STRING ustr
;
2931 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2936 /* Do not send WM_GETTEXT messages in the kernel mode version!
2937 The user mode version however calls GetWindowText() which will
2938 send WM_GETTEXT messages to windows belonging to its processes */
2939 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2940 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
2941 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
2942 WindowMatches
= !CheckWindowName
||
2943 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2944 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
2945 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
2946 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
2948 if (WindowMatches
&& ClassMatches
)
2950 Ret
= TopLevelWindow
->head
.h
;
2954 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
2956 /* window returns the handle of the top-level window, in case it found
2958 Ret
= TopLevelWindow
->head
.h
;
2963 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2968 ERR("FindWindowEx: Not Desktop Parent!\n");
2969 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
2972 if (Ret
== NULL
&& DoMessageWnd
)
2976 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
2978 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
2982 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2984 SetLastNtError(_SEH2_GetExceptionCode());
2992 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3001 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3003 PWND WndAncestor
, Parent
;
3005 if (Wnd
->head
.h
== IntGetDesktopWindow())
3014 WndAncestor
= Wnd
->spwndParent
;
3025 if(!(Parent
= WndAncestor
->spwndParent
))
3029 if(IntIsDesktopWindow(Parent
))
3034 WndAncestor
= Parent
;
3045 Parent
= IntGetParent(WndAncestor
);
3052 WndAncestor
= Parent
;
3070 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3072 PWND Window
, Ancestor
;
3073 DECLARE_RETURN(HWND
);
3075 TRACE("Enter NtUserGetAncestor\n");
3076 UserEnterExclusive();
3078 if (!(Window
= UserGetWindowObject(hWnd
)))
3083 Ancestor
= UserGetAncestor(Window
, Type
);
3084 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3086 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3089 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3095 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3097 /* combo state struct */
3111 INT fixedOwnerDrawHeight
;
3112 INT droppedWidth
; /* last two are not used unless set */
3113 INT editHeight
; /* explicitly */
3115 } HEADCOMBO
,*LPHEADCOMBO
;
3117 // Window Extra data container.
3118 typedef struct _WND2CBOX
3122 } WND2CBOX
, *PWND2CBOX
;
3124 #define CBF_BUTTONDOWN 0x0002
3130 NtUserGetComboBoxInfo(
3136 BOOL NotSameppi
= FALSE
;
3138 DECLARE_RETURN(BOOL
);
3140 TRACE("Enter NtUserGetComboBoxInfo\n");
3143 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3149 ProbeForWrite(pcbi
, sizeof(COMBOBOXINFO
), 1);
3151 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3153 SetLastNtError(_SEH2_GetExceptionCode());
3154 _SEH2_YIELD(RETURN(FALSE
));
3158 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3160 EngSetLastError(ERROR_INVALID_PARAMETER
);
3164 // Pass the user pointer, it was already probed.
3165 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3167 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3170 ppi
= PsGetCurrentProcessWin32Process();
3171 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3174 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3179 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3180 pcbi
->rcItem
= lphc
->textRect
;
3181 pcbi
->rcButton
= lphc
->buttonRect
;
3182 pcbi
->stateButton
= 0;
3183 if (lphc
->wState
& CBF_BUTTONDOWN
)
3184 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3185 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3186 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3187 pcbi
->hwndCombo
= lphc
->self
;
3188 pcbi
->hwndItem
= lphc
->hWndEdit
;
3189 pcbi
->hwndList
= lphc
->hWndLBox
;
3191 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3194 SetLastNtError(_SEH2_GetExceptionCode());
3201 if (NotSameppi
) KeDetachProcess();
3202 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3208 //// ReactOS work around! Keep it the sames as in Listbox.c
3210 /* Listbox structure */
3213 HWND self
; /* Our own window handle */
3214 HWND owner
; /* Owner window to send notifications to */
3215 UINT style
; /* Window style */
3216 INT width
; /* Window width */
3217 INT height
; /* Window height */
3218 VOID
*items
; /* Array of items */
3219 INT nb_items
; /* Number of items */
3220 INT top_item
; /* Top visible item */
3221 INT selected_item
; /* Selected item */
3222 INT focus_item
; /* Item that has the focus */
3223 INT anchor_item
; /* Anchor item for extended selection */
3224 INT item_height
; /* Default item height */
3225 INT page_size
; /* Items per listbox page */
3226 INT column_width
; /* Column width for multi-column listboxes */
3229 // Window Extra data container.
3230 typedef struct _WND2LB
3240 NtUserGetListBoxInfo(
3245 BOOL NotSameppi
= FALSE
;
3247 DECLARE_RETURN(DWORD
);
3249 TRACE("Enter NtUserGetListBoxInfo\n");
3252 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3257 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3259 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3262 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3263 ppi
= PsGetCurrentProcessWin32Process();
3264 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3267 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3272 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3273 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3274 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3275 Ret
= descr
->page_size
* descr
->column_width
;
3277 Ret
= descr
->page_size
;
3279 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3282 SetLastNtError(_SEH2_GetExceptionCode());
3289 if (NotSameppi
) KeDetachProcess();
3290 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3298 * The NtUserSetParent function changes the parent window of the specified
3302 * The new parent window and the child window must belong to the same
3303 * application. If the window identified by the hWndChild parameter is
3304 * visible, the system performs the appropriate redrawing and repainting.
3305 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3306 * or WS_POPUP window styles of the window whose parent is being changed.
3313 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3315 DECLARE_RETURN(HWND
);
3317 TRACE("Enter NtUserSetParent\n");
3318 UserEnterExclusive();
3321 Check Parent first from user space, set it here.
3325 hWndNewParent
= IntGetDesktopWindow();
3327 else if (hWndNewParent
== HWND_MESSAGE
)
3329 hWndNewParent
= IntGetMessageWindow();
3332 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3335 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3341 * UserGetShellWindow
3343 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3348 HWND FASTCALL
UserGetShellWindow(VOID
)
3350 PWINSTATION_OBJECT WinStaObject
;
3353 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3359 if (!NT_SUCCESS(Status
))
3361 SetLastNtError(Status
);
3365 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3367 ObDereferenceObject(WinStaObject
);
3372 * NtUserSetShellWindowEx
3374 * This is undocumented function to set global shell window. The global
3375 * shell window has special handling of window position.
3381 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3383 PWINSTATION_OBJECT WinStaObject
;
3384 PWND WndShell
, WndListView
;
3385 DECLARE_RETURN(BOOL
);
3386 USER_REFERENCE_ENTRY Ref
;
3390 TRACE("Enter NtUserSetShellWindowEx\n");
3391 UserEnterExclusive();
3393 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3398 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3403 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3409 if (!NT_SUCCESS(Status
))
3411 SetLastNtError(Status
);
3416 * Test if we are permitted to change the shell window.
3418 if (WinStaObject
->ShellWindow
)
3420 ObDereferenceObject(WinStaObject
);
3425 * Move shell window into background.
3427 if (hwndListView
&& hwndListView
!= hwndShell
)
3430 * Disabled for now to get Explorer working.
3431 * -- Filip, 01/nov/2003
3434 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3437 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3439 ObDereferenceObject(WinStaObject
);
3444 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3446 ObDereferenceObject(WinStaObject
);
3450 UserRefObjectCo(WndShell
, &Ref
);
3451 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3452 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3454 WinStaObject
->ShellWindow
= hwndShell
;
3455 WinStaObject
->ShellListView
= hwndListView
;
3457 ti
= GetW32ThreadInfo();
3460 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3461 ti
->pDeskInfo
->spwndShell
= WndShell
;
3462 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3465 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3467 UserDerefObjectCo(WndShell
);
3469 ObDereferenceObject(WinStaObject
);
3473 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3478 // Fixes wine Win test_window_styles and todo tests...
3479 static BOOL FASTCALL
3480 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3482 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3484 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3491 co_IntSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
, BOOL bAlter
)
3493 PWND Window
, Parent
;
3494 PWINSTATION_OBJECT WindowStation
;
3498 if (!(Window
= UserGetWindowObject(hWnd
)))
3503 if ((INT
)Index
>= 0)
3505 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3507 EngSetLastError(ERROR_INVALID_INDEX
);
3511 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3513 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3515 OldValue = (LONG)IntSetWindowProc( Wnd,
3518 if (!OldValue) return 0;
3521 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3528 OldValue
= (LONG
) Window
->ExStyle
;
3529 Style
.styleOld
= OldValue
;
3530 Style
.styleNew
= NewValue
;
3532 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3535 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3537 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3540 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3541 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3543 /* WS_EX_WINDOWEDGE depends on some other styles */
3544 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3545 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3547 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3549 if (!(Window
->ExStyle
& WS_EX_LAYERED
))
3551 SetLayeredStatus(Window
, 0);
3554 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3556 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3560 OldValue
= (LONG
) Window
->style
;
3561 Style
.styleOld
= OldValue
;
3562 Style
.styleNew
= NewValue
;
3565 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3567 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3568 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3569 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3570 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3571 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3573 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3575 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3577 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3578 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3579 DceResetActiveDCEs( Window
);
3581 Window
->style
= (DWORD
)Style
.styleNew
;
3584 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3589 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3590 Window
->fnid
& FNID_FREED
)
3592 EngSetLastError(ERROR_ACCESS_DENIED
);
3595 OldValue
= (LONG
)IntSetWindowProc(Window
,
3602 OldValue
= (LONG
) Window
->hModule
;
3603 Window
->hModule
= (HINSTANCE
) NewValue
;
3606 case GWL_HWNDPARENT
:
3607 Parent
= Window
->spwndParent
;
3608 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3609 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3611 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3615 OldValue
= (LONG
) Window
->IDMenu
;
3616 Window
->IDMenu
= (UINT
) NewValue
;
3620 OldValue
= Window
->dwUserData
;
3621 Window
->dwUserData
= NewValue
;
3625 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3626 EngSetLastError(ERROR_INVALID_INDEX
);
3637 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3639 return co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3643 * NtUserSetWindowLong
3645 * The NtUserSetWindowLong function changes an attribute of the specified
3646 * window. The function also sets the 32-bit (long) value at the specified
3647 * offset into the extra window memory.
3654 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3658 UserEnterExclusive();
3660 if (hWnd
== IntGetDesktopWindow())
3662 EngSetLastError(STATUS_ACCESS_DENIED
);
3667 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3675 NtUserAlterWindowStyle(HWND hWnd
, DWORD Index
, LONG NewValue
)
3679 UserEnterExclusive();
3681 if (hWnd
== IntGetDesktopWindow())
3683 EngSetLastError(STATUS_ACCESS_DENIED
);
3688 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, FALSE
, TRUE
);
3697 * NtUserSetWindowWord
3699 * Legacy function similar to NtUserSetWindowLong.
3706 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3710 DECLARE_RETURN(WORD
);
3712 TRACE("Enter NtUserSetWindowWord\n");
3713 UserEnterExclusive();
3715 if (hWnd
== IntGetDesktopWindow())
3717 EngSetLastError(STATUS_ACCESS_DENIED
);
3721 if (!(Window
= UserGetWindowObject(hWnd
)))
3730 case GWL_HWNDPARENT
:
3731 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3735 EngSetLastError(ERROR_INVALID_INDEX
);
3740 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3742 EngSetLastError(ERROR_INVALID_PARAMETER
);
3746 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3747 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3752 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3758 QueryWindow based on KJK::Hyperion and James Tabor.
3760 0 = QWUniqueProcessId
3761 1 = QWUniqueThreadId
3764 4 = QWIsHung Implements IsHungAppWindow found
3767 9 = QWKillWindow When I called this with hWnd ==
3768 DesktopWindow, it shutdown the system
3775 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3777 /* Console Leader Process CID Window offsets */
3778 #define GWLP_CONSOLE_LEADER_PID 0
3779 #define GWLP_CONSOLE_LEADER_TID 4
3783 DECLARE_RETURN(UINT
);
3785 TRACE("Enter NtUserQueryWindow\n");
3788 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3795 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3797 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3798 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3800 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
3801 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
3805 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3810 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3812 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3813 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3815 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
3816 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
3820 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3825 case QUERY_WINDOW_ACTIVE
:
3826 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3829 case QUERY_WINDOW_FOCUS
:
3830 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3833 case QUERY_WINDOW_ISHUNG
:
3834 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
);
3837 case QUERY_WINDOW_REAL_ID
:
3838 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3841 case QUERY_WINDOW_FOREGROUND
:
3842 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3846 Result
= (DWORD
)NULL
;
3853 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
3862 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3864 UNICODE_STRING SafeMessageName
;
3867 DECLARE_RETURN(UINT
);
3869 TRACE("Enter NtUserRegisterWindowMessage\n");
3870 UserEnterExclusive();
3872 if(MessageNameUnsafe
== NULL
)
3874 EngSetLastError(ERROR_INVALID_PARAMETER
);
3878 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3879 if(!NT_SUCCESS(Status
))
3881 SetLastNtError(Status
);
3885 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3886 if (SafeMessageName
.Buffer
)
3887 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3891 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
3900 NtUserSetWindowFNID(HWND hWnd
,
3904 DECLARE_RETURN(BOOL
);
3906 TRACE("Enter NtUserSetWindowFNID\n");
3907 UserEnterExclusive();
3909 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3914 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3916 EngSetLastError(ERROR_ACCESS_DENIED
);
3920 // From user land we only set these.
3921 if (fnID
!= FNID_DESTROY
)
3923 /* HACK: The minimum should be FNID_BUTTON, but menu code relies on this */
3924 if (fnID
< FNID_FIRST
|| fnID
> FNID_GHOST
||
3927 EngSetLastError(ERROR_INVALID_PARAMETER
);
3936 TRACE("Leave NtUserSetWindowFNID\n");
3942 DefSetText(PWND Wnd
, PCWSTR WindowText
)
3944 UNICODE_STRING UnicodeString
;
3947 RtlInitUnicodeString(&UnicodeString
, WindowText
);
3949 if (UnicodeString
.Length
!= 0)
3951 if (Wnd
->strName
.MaximumLength
> 0 &&
3952 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
3954 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
3956 Wnd
->strName
.Length
= UnicodeString
.Length
;
3957 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
3958 RtlCopyMemory(Wnd
->strName
.Buffer
,
3959 UnicodeString
.Buffer
,
3960 UnicodeString
.Length
);
3965 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
3966 buf
= Wnd
->strName
.Buffer
;
3967 Wnd
->strName
.Buffer
= NULL
;
3970 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
3973 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
3974 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
3975 if (Wnd
->strName
.Buffer
!= NULL
)
3977 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
3978 RtlCopyMemory(Wnd
->strName
.Buffer
,
3979 UnicodeString
.Buffer
,
3980 UnicodeString
.Length
);
3981 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
3982 Wnd
->strName
.Length
= UnicodeString
.Length
;
3986 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
3993 Wnd
->strName
.Length
= 0;
3994 if (Wnd
->strName
.Buffer
!= NULL
)
3995 Wnd
->strName
.Buffer
[0] = L
'\0';
3998 // FIXME: HAX! Windows does not do this in here!
3999 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4000 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4001 /* Send shell notifications */
4002 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4004 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) UserHMGetHandle(Wnd
), FALSE
); // FIXME Flashing?
4009 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4016 * Undocumented function that is called from DefWindowProc to set
4023 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4026 LARGE_STRING SafeText
;
4027 UNICODE_STRING UnicodeString
;
4030 TRACE("Enter NtUserDefSetText\n");
4032 if (WindowText
!= NULL
)
4036 SafeText
= ProbeForReadLargeString(WindowText
);
4038 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4041 SetLastNtError(_SEH2_GetExceptionCode());
4051 UserEnterExclusive();
4053 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4059 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4060 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4061 // Now we know what the bAnsi is for.
4062 RtlInitUnicodeString(&UnicodeString
, NULL
);
4063 if (SafeText
.Buffer
)
4068 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4070 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4071 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4073 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4076 SetLastNtError(_SEH2_GetExceptionCode());
4079 if (!Ret
) goto Exit
;
4082 if (UnicodeString
.Length
!= 0)
4084 if (Wnd
->strName
.MaximumLength
> 0 &&
4085 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4087 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4089 Wnd
->strName
.Length
= UnicodeString
.Length
;
4090 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4091 RtlCopyMemory(Wnd
->strName
.Buffer
,
4092 UnicodeString
.Buffer
,
4093 UnicodeString
.Length
);
4098 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4099 buf
= Wnd
->strName
.Buffer
;
4100 Wnd
->strName
.Buffer
= NULL
;
4103 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4106 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4107 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4108 if (Wnd
->strName
.Buffer
!= NULL
)
4110 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4111 RtlCopyMemory(Wnd
->strName
.Buffer
,
4112 UnicodeString
.Buffer
,
4113 UnicodeString
.Length
);
4114 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4115 Wnd
->strName
.Length
= UnicodeString
.Length
;
4119 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4127 Wnd
->strName
.Length
= 0;
4128 if (Wnd
->strName
.Buffer
!= NULL
)
4129 Wnd
->strName
.Buffer
[0] = L
'\0';
4132 // FIXME: HAX! Windows does not do this in here!
4133 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4134 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4135 /* Send shell notifications */
4136 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4138 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4143 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4144 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4150 * NtUserInternalGetWindowText
4157 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4162 DECLARE_RETURN(INT
);
4164 TRACE("Enter NtUserInternalGetWindowText\n");
4167 if(lpString
&& (nMaxCount
<= 1))
4169 EngSetLastError(ERROR_INVALID_PARAMETER
);
4173 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4178 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4181 const WCHAR Terminator
= L
'\0';
4183 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4185 Copy
= min(nMaxCount
- 1, Result
);
4188 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4189 if(!NT_SUCCESS(Status
))
4191 SetLastNtError(Status
);
4197 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4198 if(!NT_SUCCESS(Status
))
4200 SetLastNtError(Status
);
4210 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4220 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4226 // ASSERT(OwnerWnd);
4228 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4229 win_array
= IntWinListChildren(OwnerWnd
);
4234 while (win_array
[count
])
4236 while (--count
>= 0)
4238 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4240 if (pWnd
->spwndOwner
!= OwnerWnd
)
4245 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4247 /* In Windows, ShowOwnedPopups(TRUE) generates
4248 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4249 * regardless of the state of the owner
4251 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4257 if (pWnd
->style
& WS_VISIBLE
)
4259 /* In Windows, ShowOwnedPopups(FALSE) generates
4260 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4261 * regardless of the state of the owner
4263 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4269 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4270 TRACE("Leave ShowOwnedPopups\n");