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
, TRUE
);
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
);
398 * Look whether the focus is within the tree of windows
399 * we will be destroying.
402 if ( ti
->MessageQueue
->spwndActive
== Window
|| // Fixes CORE-106 RegSvr32 exit and return focus to CMD.
403 (ti
->MessageQueue
->spwndActive
== NULL
&& ti
->MessageQueue
== IntGetFocusMessageQueue()) )
405 co_WinPosActivateOtherWindow(Window
);
408 /* Fixes CMD properties closing and returning focus to CMD */
409 if (ti
->MessageQueue
->spwndFocus
== Window
)
411 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
413 co_UserSetFocus(Window
->spwndParent
);
417 co_UserSetFocus(NULL
);
421 if (ti
->MessageQueue
->CaretInfo
.hWnd
== UserHMGetHandle(Window
))
423 co_IntDestroyCaret(ti
);
427 /* If the window being destroyed is the current clipboard owner... */
428 if (ti
->ppi
->prpwinsta
!= NULL
&& Window
== ti
->ppi
->prpwinsta
->spwndClipOwner
)
430 /* ... make it release the clipboard */
431 UserClipboardRelease(Window
);
434 /* Send the WM_DESTROY to the window */
435 co_IntSendMessage(hWnd
, WM_DESTROY
, 0, 0);
438 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
439 * make sure that the window still exists when we come back.
441 if (IntIsWindow(hWnd
))
446 if (!(pWndArray
= IntWinListChildren( Window
))) return;
448 for (i
= 0; pWndArray
[i
]; i
++)
450 if (IntIsWindow( pWndArray
[i
] )) IntSendDestroyMsg( pWndArray
[i
] );
452 ExFreePoolWithTag(pWndArray
, USERTAG_WINDOWLIST
);
456 TRACE("destroyed itself while in WM_DESTROY!\n");
461 UserFreeWindowInfo(PTHREADINFO ti
, PWND Wnd
)
463 PCLIENTINFO ClientInfo
= GetWin32ClientInfo();
467 if (ClientInfo
->CallbackWnd
.pWnd
== DesktopHeapAddressToUser(Wnd
))
469 ClientInfo
->CallbackWnd
.hWnd
= NULL
;
470 ClientInfo
->CallbackWnd
.pWnd
= NULL
;
473 if (Wnd
->strName
.Buffer
!= NULL
)
475 Wnd
->strName
.Length
= 0;
476 Wnd
->strName
.MaximumLength
= 0;
477 DesktopHeapFree(Wnd
->head
.rpdesk
,
478 Wnd
->strName
.Buffer
);
479 Wnd
->strName
.Buffer
= NULL
;
482 // DesktopHeapFree(Wnd->head.rpdesk, Wnd);
483 // WindowObject->hWnd = NULL;
486 /***********************************************************************
489 * Destroy storage associated to a window. "Internals" p.358
491 * This is the "functional" DestroyWindows function i.e. all stuff
492 * done in CreateWindow is undone here and not in DestroyWindow :-P
494 LRESULT
co_UserFreeWindow(PWND Window
,
495 PPROCESSINFO ProcessData
,
496 PTHREADINFO ThreadData
,
497 BOOLEAN SendMessages
)
503 BOOLEAN BelongsToThreadData
;
507 if(Window
->state2
& WNDS2_INDESTROY
)
509 TRACE("Tried to call co_UserFreeWindow() twice\n");
512 Window
->state2
|= WNDS2_INDESTROY
;
513 Window
->style
&= ~WS_VISIBLE
;
514 Window
->head
.pti
->cVisWindows
--;
517 /* remove the window already at this point from the thread window list so we
518 don't get into trouble when destroying the thread windows while we're still
519 in co_UserFreeWindow() */
520 RemoveEntryList(&Window
->ThreadListEntry
);
522 BelongsToThreadData
= IntWndBelongsToThread(Window
, ThreadData
);
524 IntDeRegisterShellHookWindow(UserHMGetHandle(Window
));
526 /* free child windows */
527 Children
= IntWinListChildren(Window
);
530 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
532 if ((Child
= IntGetWindowObject(*ChildHandle
)))
534 if (!IntWndBelongsToThread(Child
, ThreadData
))
536 /* send WM_DESTROY messages to windows not belonging to the same thread */
537 co_IntSendMessage( UserHMGetHandle(Child
), WM_ASYNC_DESTROYWINDOW
, 0, 0 );
540 co_UserFreeWindow(Child
, ProcessData
, ThreadData
, SendMessages
);
542 UserDereferenceObject(Child
);
545 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
551 * Clear the update region to make sure no WM_PAINT messages will be
552 * generated for this window while processing the WM_NCDESTROY.
554 co_UserRedrawWindow(Window
, NULL
, 0,
555 RDW_VALIDATE
| RDW_NOFRAME
| RDW_NOERASE
|
556 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
557 if (BelongsToThreadData
)
558 co_IntSendMessage(UserHMGetHandle(Window
), WM_NCDESTROY
, 0, 0);
561 UserClipboardFreeWindow(Window
);
563 DestroyTimersForWindow(ThreadData
, Window
);
565 /* Unregister hot keys */
566 UnregisterWindowHotKeys(Window
);
568 /* flush the message queue */
569 MsqRemoveWindowMessagesFromQueue(Window
);
571 /* from now on no messages can be sent to this window anymore */
572 Window
->state
|= WNDS_DESTROYED
;
573 Window
->fnid
|= FNID_FREED
;
575 /* don't remove the WINDOWSTATUS_DESTROYING bit */
577 /* reset shell window handles */
578 if (ThreadData
->rpdesk
)
580 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
)
581 ThreadData
->rpdesk
->rpwinstaParent
->ShellWindow
= NULL
;
583 if (Window
->head
.h
== ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
)
584 ThreadData
->rpdesk
->rpwinstaParent
->ShellListView
= NULL
;
587 /* Fixes dialog test_focus breakage due to r66237. */
588 if (ThreadData
->MessageQueue
->spwndFocus
== Window
)
589 ThreadData
->MessageQueue
->spwndFocus
= NULL
;
591 if (ThreadData
->MessageQueue
->spwndActive
== Window
)
592 ThreadData
->MessageQueue
->spwndActive
= NULL
;
594 if (ThreadData
->MessageQueue
->spwndCapture
== Window
)
599 //// Now kill those remaining "PAINTING BUG: Thread marked as containing dirty windows" spam!!!
600 if ( Window
->hrgnUpdate
!= NULL
|| Window
->state
& WNDS_INTERNALPAINT
)
602 MsqDecPaintCountQueue(Window
->head
.pti
);
603 if (Window
->hrgnUpdate
> HRGN_WINDOW
&& GreIsHandleValid(Window
->hrgnUpdate
))
605 GreDeleteObject(Window
->hrgnUpdate
);
607 Window
->hrgnUpdate
= NULL
;
608 Window
->state
&= ~WNDS_INTERNALPAINT
;
611 if (Window
->state
& (WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
))
613 Window
->state
&= ~(WNDS_SENDERASEBACKGROUND
|WNDS_SENDNCPAINT
);
616 if ( ((Window
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
) &&
618 (Menu
= UserGetMenuObject((HMENU
)Window
->IDMenu
)))
620 TRACE("UFW: IDMenu %p\n",Window
->IDMenu
);
621 IntDestroyMenuObject(Menu
, TRUE
);
625 if (Window
->SystemMenu
626 && (Menu
= UserGetMenuObject(Window
->SystemMenu
)))
628 IntDestroyMenuObject(Menu
, TRUE
);
629 Window
->SystemMenu
= (HMENU
)0;
632 DceFreeWindowDCE(Window
); /* Always do this to catch orphaned DCs */
634 IntUnlinkWindow(Window
);
636 if (Window
->PropListItems
)
638 UserRemoveWindowProps(Window
);
639 TRACE("Window->PropListItems %lu\n",Window
->PropListItems
);
640 ASSERT(Window
->PropListItems
==0);
643 UserReferenceObject(Window
);
644 UserMarkObjectDestroy(Window
);
646 IntDestroyScrollBars(Window
);
648 if (Window
->pcls
->atomClassName
== gaGuiConsoleWndClass
)
650 /* Count only console windows manually */
651 co_IntUserManualGuiCheck(FALSE
);
654 /* dereference the class */
655 NT_ASSERT(Window
->head
.pti
!= NULL
);
656 IntDereferenceClass(Window
->pcls
,
657 Window
->head
.pti
->pDeskInfo
,
658 Window
->head
.pti
->ppi
);
661 if (Window
->hrgnClip
)
663 IntGdiSetRegionOwner(Window
->hrgnClip
, GDI_OBJ_HMGR_POWNED
);
664 GreDeleteObject(Window
->hrgnClip
);
665 Window
->hrgnClip
= NULL
;
667 Window
->head
.pti
->cWindows
--;
669 // ASSERT(Window != NULL);
670 UserFreeWindowInfo(Window
->head
.pti
, Window
);
672 UserDereferenceObject(Window
);
673 UserDeleteObject(UserHMGetHandle(Window
), TYPE_WINDOW
);
679 // Same as User32:IntGetWndProc.
682 IntGetWindowProc(PWND pWnd
,
687 WNDPROC gcpd
, Ret
= 0;
689 ASSERT(UserIsEnteredExclusive() == TRUE
);
693 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
695 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
697 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
700 Ret
= GETPFNCLIENTA(i
);
702 Ret
= GETPFNCLIENTW(i
);
708 if (Class
->fnid
== FNID_EDIT
)
709 Ret
= pWnd
->lpfnWndProc
;
712 Ret
= pWnd
->lpfnWndProc
;
714 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
718 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
719 Ret
= GETPFNCLIENTA(Class
->fnid
);
723 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
724 Ret
= GETPFNCLIENTW(Class
->fnid
);
727 if ( Ret
!= pWnd
->lpfnWndProc
)
730 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
733 gcpd
= (WNDPROC
)UserGetCPD(
735 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
738 return (gcpd
? gcpd
: Ret
);
742 IntSetWindowProc(PWND pWnd
,
747 PCALLPROCDATA CallProc
;
749 WNDPROC Ret
, chWndProc
= NULL
;
751 // Retrieve previous window proc.
752 Ret
= IntGetWindowProc(pWnd
, Ansi
);
756 if (IsCallProcHandle(NewWndProc
))
758 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
760 { // Reset new WndProc.
761 NewWndProc
= CallProc
->pfnClientPrevious
;
762 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
763 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
766 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
767 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
769 if (GETPFNCLIENTW(i
) == NewWndProc
)
771 chWndProc
= GETPFNSERVER(i
);
774 if (GETPFNCLIENTA(i
) == NewWndProc
)
776 chWndProc
= GETPFNSERVER(i
);
780 // If match, set/reset to Server Side and clear ansi.
783 pWnd
->lpfnWndProc
= chWndProc
;
784 pWnd
->Unicode
= TRUE
;
785 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
786 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
790 pWnd
->Unicode
= !Ansi
;
791 // Handle the state change in here.
793 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
795 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
797 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
798 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
800 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
802 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
806 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
807 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
811 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
812 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
815 // Now set the new window proc.
816 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
822 /* INTERNAL ******************************************************************/
825 // This fixes a check for children messages that need paint while searching the parents messages!
826 // Fixes wine msg:test_paint_messages:WmParentErasePaint ..
829 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
831 PWND Window
= BaseWindow
;
834 if ( Window
== NULL
|| (Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
837 Window
= Window
->spwndParent
;
839 while(Parent
!= Window
);
845 Link the window into siblings list
846 children and parent are kept in place.
851 PWND WndInsertAfter
/* set to NULL if top sibling */
854 if ((Wnd
->spwndPrev
= WndInsertAfter
))
856 /* link after WndInsertAfter */
857 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
858 Wnd
->spwndNext
->spwndPrev
= Wnd
;
860 Wnd
->spwndPrev
->spwndNext
= Wnd
;
865 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
866 Wnd
->spwndNext
->spwndPrev
= Wnd
;
868 Wnd
->spwndParent
->spwndChild
= Wnd
;
873 Note: Wnd->spwndParent can be null if it is the desktop.
875 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
877 if (hWndPrev
== HWND_NOTOPMOST
)
879 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
880 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
881 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
882 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
885 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
887 if (hWndPrev
== HWND_BOTTOM
)
889 /* Link in the bottom of the list */
892 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
893 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
894 WndInsertAfter
= WndInsertAfter
->spwndNext
;
896 IntLinkWindow(Wnd
, WndInsertAfter
);
897 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
899 else if (hWndPrev
== HWND_TOPMOST
)
901 /* Link in the top of the list */
902 IntLinkWindow(Wnd
, NULL
);
904 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
906 else if (hWndPrev
== HWND_TOP
)
908 /* Link it after the last topmost window */
909 PWND WndInsertBefore
;
911 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
913 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
915 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
917 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
918 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
920 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
923 WndInsertBefore
= WndInsertBefore
->spwndNext
;
927 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
931 /* Link it after hWndPrev */
934 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
935 /* Are we called with an erroneous handle */
936 if(WndInsertAfter
== NULL
)
938 /* Link in a default position */
939 IntLinkHwnd(Wnd
, HWND_TOP
);
943 IntLinkWindow(Wnd
, WndInsertAfter
);
945 /* Fix the WS_EX_TOPMOST flag */
946 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
948 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
952 if(WndInsertAfter
->spwndNext
&&
953 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
955 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
959 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
963 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
967 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
970 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
971 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
973 //ERR("ProcessOwnerSwap Old out.\n");
974 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
980 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
983 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
985 //ERR("ProcessOwnerSwap New in.\n");
986 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
990 // FIXME: System Tray checks.
994 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
996 PWND Wnd
, WndOldOwner
, WndNewOwner
;
999 Wnd
= IntGetWindowObject(hWnd
);
1003 WndOldOwner
= Wnd
->spwndOwner
;
1005 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1006 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1008 if (!WndNewOwner
&& hWndNewOwner
)
1010 EngSetLastError(ERROR_INVALID_PARAMETER
);
1015 /* if parent belongs to a different thread and the window isn't */
1016 /* top-level, attach the two threads */
1017 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1019 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1023 Wnd
->spwndOwner
= WndNewOwner
;
1027 Wnd
->spwndOwner
= NULL
;
1032 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1033 EngSetLastError(ERROR_INVALID_PARAMETER
);
1037 UserDereferenceObject(Wnd
);
1042 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1044 PWND WndOldParent
, pWndExam
;
1047 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1050 ASSERT(WndNewParent
);
1051 ASSERT_REFS_CO(Wnd
);
1052 ASSERT_REFS_CO(WndNewParent
);
1054 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1056 EngSetLastError(ERROR_ACCESS_DENIED
);
1060 /* Some applications try to set a child as a parent */
1061 if (IntIsChildWindow(Wnd
, WndNewParent
))
1063 TRACE("IntSetParent try to set a child as a parent.\n");
1064 EngSetLastError( ERROR_INVALID_PARAMETER
);
1068 pWndExam
= WndNewParent
; // Load parent Window to examine.
1069 // Now test for set parent to parent hit.
1072 if (Wnd
== pWndExam
)
1074 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1075 EngSetLastError(ERROR_INVALID_PARAMETER
);
1078 pWndExam
= pWndExam
->spwndParent
;
1082 * Windows hides the window first, then shows it again
1083 * including the WM_SHOWWINDOW messages and all
1085 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1087 /* Window must belong to current process */
1088 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1090 ERR("IntSetParent Window must belong to current process!\n");
1094 WndOldParent
= Wnd
->spwndParent
;
1096 if ( WndOldParent
&&
1097 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1098 pt
.x
= Wnd
->rcWindow
.right
;
1100 pt
.x
= Wnd
->rcWindow
.left
;
1101 pt
.y
= Wnd
->rcWindow
.top
;
1103 IntScreenToClient(WndOldParent
, &pt
);
1105 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1107 if (WndNewParent
!= WndOldParent
)
1109 /* Unlink the window from the siblings list */
1110 IntUnlinkWindow(Wnd
);
1111 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1113 /* Set the new parent */
1114 Wnd
->spwndParent
= WndNewParent
;
1116 if ( Wnd
->style
& WS_CHILD
&&
1118 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1120 ERR("SetParent Top Most from Pop up!\n");
1121 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1124 /* Link the window with its new siblings */
1126 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1127 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1131 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1132 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1134 Wnd
->style
|= WS_CLIPSIBLINGS
;
1135 DceResetActiveDCEs(Wnd
);
1138 /* if parent belongs to a different thread and the window isn't */
1139 /* top-level, attach the two threads */
1140 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1142 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1144 if (WndOldParent
&& (Wnd
->head
.pti
!= WndOldParent
->head
.pti
))
1146 //ERR("SetParent Old out.\n");
1147 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1150 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1152 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1154 //ERR("SetParent New in.\n");
1155 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1160 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1161 swFlags
|= SWP_NOACTIVATE
;
1163 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1165 * SetParent additionally needs to make hwnd the top window
1166 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1167 * WM_WINDOWPOSCHANGED notification messages.
1169 //ERR("IntSetParent SetWindowPos 1\n");
1170 co_WinPosSetWindowPos( Wnd
,
1171 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1172 pt
.x
, pt
.y
, 0, 0, swFlags
);
1173 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1174 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1176 return WndOldParent
;
1180 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1182 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1183 HWND hWndOldParent
= NULL
;
1184 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1186 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1188 EngSetLastError(ERROR_INVALID_PARAMETER
);
1192 if (hWndChild
== IntGetDesktopWindow())
1194 ERR("UserSetParent Access Denied!\n");
1195 EngSetLastError(ERROR_ACCESS_DENIED
);
1201 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1203 ERR("UserSetParent Bad New Parent!\n");
1209 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1215 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1217 ERR("UserSetParent Bad Child!\n");
1221 UserRefObjectCo(Wnd
, &Ref
);
1222 UserRefObjectCo(WndParent
, &ParentRef
);
1223 //ERR("Enter co_IntSetParent\n");
1224 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1225 //ERR("Leave co_IntSetParent\n");
1226 UserDerefObjectCo(WndParent
);
1227 UserDerefObjectCo(Wnd
);
1231 hWndOldParent
= WndOldParent
->head
.h
;
1232 UserDereferenceObject(WndOldParent
);
1235 return( hWndOldParent
);
1238 /* Unlink the window from siblings. children and parent are kept in place. */
1240 IntUnlinkWindow(PWND Wnd
)
1243 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1246 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1248 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1249 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1251 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1254 /* FUNCTIONS *****************************************************************/
1257 * As best as I can figure, this function is used by EnumWindows,
1258 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1260 * It's supposed to build a list of HWNDs to return to the caller.
1261 * We can figure out what kind of list by what parameters are
1269 NtUserBuildHwndList(
1282 return ERROR_INVALID_PARAMETER
;
1284 if (hwndParent
|| !dwThreadId
)
1287 PWND Parent
, Window
;
1291 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1293 return ERROR_INVALID_HANDLE
;
1298 Status
= IntValidateDesktopHandle(hDesktop
,
1302 if(!NT_SUCCESS(Status
))
1304 return ERROR_INVALID_HANDLE
;
1307 hwndParent
= Desktop
->DesktopWindow
;
1314 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1315 (Window
= Parent
->spwndChild
))
1317 BOOL bGoDown
= TRUE
;
1319 Status
= STATUS_SUCCESS
;
1324 if(dwCount
++ < *pBufSize
&& pWnd
)
1328 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1329 *pWnd
= Window
->head
.h
;
1332 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1334 Status
= _SEH2_GetExceptionCode();
1337 if(!NT_SUCCESS(Status
))
1339 SetLastNtError(Status
);
1343 if (Window
->spwndChild
&& bChildren
)
1345 Window
= Window
->spwndChild
;
1350 if (Window
->spwndNext
)
1352 Window
= Window
->spwndNext
;
1356 Window
= Window
->spwndParent
;
1357 if (Window
== Parent
)
1366 ObDereferenceObject(Desktop
);
1369 else // Build EnumThreadWindows list!
1372 PTHREADINFO W32Thread
;
1376 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1377 if (!NT_SUCCESS(Status
))
1379 ERR("Thread Id is not valid!\n");
1380 return ERROR_INVALID_PARAMETER
;
1382 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1384 ObDereferenceObject(Thread
);
1385 TRACE("Tried to enumerate windows of a non gui thread\n");
1386 return ERROR_INVALID_PARAMETER
;
1389 // Do not use Thread link list due to co_UserFreeWindow!!!
1390 // Current = W32Thread->WindowListHead.Flink;
1391 // Fixes Api:CreateWindowEx tests!!!
1392 List
= IntWinListChildren(UserGetDesktopWindow());
1396 for (i
= 0; List
[i
]; i
++)
1398 Window
= ValidateHwndNoErr(List
[i
]);
1399 if (Window
&& Window
->head
.pti
== W32Thread
)
1401 if (dwCount
< *pBufSize
&& pWnd
)
1405 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1406 *pWnd
= Window
->head
.h
;
1409 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1411 Status
= _SEH2_GetExceptionCode();
1414 if (!NT_SUCCESS(Status
))
1416 ERR("Failure to build window list!\n");
1417 SetLastNtError(Status
);
1424 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
1427 ObDereferenceObject(Thread
);
1430 *pBufSize
= dwCount
;
1431 return STATUS_SUCCESS
;
1434 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1436 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1437 !(pWindow
->ExStyle
& WS_EX_NOPARENTNOTIFY
))
1439 if (VerifyWnd(pWindow
->spwndParent
) && pWindow
->spwndParent
!= UserGetDesktopWindow())
1441 USER_REFERENCE_ENTRY Ref
;
1442 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1443 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1445 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1446 (LPARAM
)pWindow
->head
.h
);
1447 UserDerefObjectCo(pWindow
->spwndParent
);
1453 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1455 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1457 /* default positioning for overlapped windows */
1458 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1461 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1463 pMonitor
= UserGetPrimaryMonitor();
1465 /* Check if we don't have a monitor attached yet */
1466 if(pMonitor
== NULL
)
1474 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1476 if (IS_DEFAULT(Cs
->x
))
1478 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1480 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1482 Cs
->x
= ProcessParams
->StartingX
;
1483 Cs
->y
= ProcessParams
->StartingY
;
1487 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1488 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1489 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1490 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1492 /* reset counter and position */
1495 pMonitor
->cWndStack
= 0;
1497 pMonitor
->cWndStack
++;
1501 if (IS_DEFAULT(Cs
->cx
))
1503 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1505 Cs
->cx
= ProcessParams
->CountX
;
1506 Cs
->cy
= ProcessParams
->CountY
;
1510 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1511 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1514 /* neither x nor cx are default. Check the y values .
1515 * In the trace we see Outlook and Outlook Express using
1516 * cy set to CW_USEDEFAULT when opening the address book.
1518 else if (IS_DEFAULT(Cs
->cy
))
1520 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1521 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1526 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1527 if(IS_DEFAULT(Cs
->x
))
1532 if(IS_DEFAULT(Cs
->cx
))
1542 /* Allocates and initializes a window */
1543 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1544 PLARGE_STRING WindowName
,
1549 PDESKTOP pdeskCreated
)
1553 PTHREADINFO pti
= NULL
;
1555 BOOL bUnicodeWindow
;
1557 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1559 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1560 { // Need both here for wine win.c test_CreateWindow.
1561 //if (Cs->hwndParent && ParentWindow)
1562 if (ParentWindow
) // It breaks more tests..... WIP.
1564 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1565 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1566 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1567 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1571 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1573 * Dialog boxes and message boxes do not inherit layout, so you must
1574 * set the layout explicitly.
1576 if ( Class
->fnid
!= FNID_DIALOG
)
1578 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1580 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1586 /* Automatically add WS_EX_WINDOWEDGE */
1587 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1588 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1589 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1590 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1592 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1594 /* Is it a unicode window? */
1595 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1596 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1598 /* Allocate the new window */
1599 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1600 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1604 sizeof(WND
) + Class
->cbwndExtra
);
1611 TRACE("Created window object with handle %p\n", hWnd
);
1613 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1614 { /* HACK: Helper for win32csr/desktopbg.c */
1615 /* If there is no desktop window yet, we must be creating it */
1616 TRACE("CreateWindow setting desktop.\n");
1617 pdeskCreated
->DesktopWindow
= hWnd
;
1618 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1622 * Fill out the structure describing it.
1624 /* Remember, pWnd->head is setup in object.c ... */
1625 pWnd
->spwndParent
= ParentWindow
;
1626 pWnd
->spwndOwner
= OwnerWindow
;
1628 pWnd
->spwndLastActive
= pWnd
;
1629 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1631 pWnd
->hModule
= Cs
->hInstance
;
1632 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1633 pWnd
->ExStyle
= Cs
->dwExStyle
;
1634 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1635 pWnd
->pActCtx
= acbiBuffer
;
1636 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1637 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1639 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1641 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1642 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1645 pWnd
->head
.pti
->cWindows
++;
1647 if (Class
->spicn
&& !Class
->spicnSm
)
1649 HICON IconSmHandle
= NULL
;
1650 if((Class
->spicn
->CURSORF_flags
& (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1651 == (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1653 IconSmHandle
= co_IntCopyImage(
1654 UserHMGetHandle(Class
->spicn
),
1656 UserGetSystemMetrics( SM_CXSMICON
),
1657 UserGetSystemMetrics( SM_CYSMICON
),
1658 LR_COPYFROMRESOURCE
);
1662 /* Retry without copying from resource */
1663 IconSmHandle
= co_IntCopyImage(
1664 UserHMGetHandle(Class
->spicn
),
1666 UserGetSystemMetrics( SM_CXSMICON
),
1667 UserGetSystemMetrics( SM_CYSMICON
),
1673 Class
->spicnSm
= UserGetCurIconObject(IconSmHandle
);
1674 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1678 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1679 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1681 /* BugBoy Comments: Comment below say that System classes are always created
1682 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1683 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1685 No where can I see in code or through testing does the window change back
1686 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1687 see what problems this would cause. */
1689 // Set WndProc from Class.
1690 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1692 // GetWindowProc, test for non server side default classes and set WndProc.
1693 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1697 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1698 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1702 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1703 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1707 // If not an Unicode caller, set Ansi creator bit.
1708 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1710 // Clone Class Ansi/Unicode proc type.
1711 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1713 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1714 pWnd
->Unicode
= FALSE
;
1718 * It seems there can be both an Ansi creator and Unicode Class Window
1719 * WndProc, unless the following overriding conditions occur:
1721 if ( !bUnicodeWindow
&&
1722 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1723 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1724 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1725 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1726 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1727 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1728 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1729 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1730 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1731 { // Override Class and set the window Ansi WndProc.
1732 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1733 pWnd
->Unicode
= FALSE
;
1736 { // Set the window Unicode WndProc.
1737 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1738 pWnd
->Unicode
= TRUE
;
1742 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1743 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1744 Dont understand why it does this. */
1745 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1747 PCALLPROCDATA CallProc
;
1748 CallProc
= CreateCallProc(pWnd
->head
.rpdesk
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1752 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1753 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1757 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1761 InitializeListHead(&pWnd
->PropListHead
);
1762 pWnd
->PropListItems
= 0;
1764 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1766 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1767 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1768 if (pWnd
->strName
.Buffer
== NULL
)
1773 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1774 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1775 pWnd
->strName
.Length
= WindowName
->Length
;
1776 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1779 /* Correct the window style. */
1780 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1782 pWnd
->style
|= WS_CLIPSIBLINGS
;
1783 if (!(pWnd
->style
& WS_POPUP
))
1785 pWnd
->style
|= WS_CAPTION
;
1789 /* WS_EX_WINDOWEDGE depends on some other styles */
1790 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1791 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1792 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1794 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1795 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1796 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1799 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1801 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1802 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1804 /* Set the window menu */
1805 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1809 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1811 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1813 UNICODE_STRING MenuName
;
1816 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1818 MenuName
.Length
= 0;
1819 MenuName
.MaximumLength
= 0;
1820 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1824 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1826 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1827 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1831 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1834 if ( ParentWindow
&&
1835 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1836 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1838 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1840 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1842 EngSetLastError(ERROR_INVALID_PARAMETER
);
1845 if ( pWnd
->spwndOwner
&&
1846 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1848 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1850 if ( pWnd
->spwndOwner
&&
1851 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1852 pti
!= pWnd
->spwndOwner
->head
.pti
)
1854 //ERR("CreateWindow Owner in.\n");
1855 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1859 /* Insert the window into the thread's window list. */
1860 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1862 /* Handle "CS_CLASSDC", it is tested first. */
1863 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1864 { /* One DCE per class to have CLASS. */
1865 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1867 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1868 { /* Allocate a DCE for this window. */
1869 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1875 ERR("IntCreateWindow Allocation Error.\n");
1876 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1879 UserDereferenceObject(pWnd
);
1887 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1888 PUNICODE_STRING ClassName
,
1889 PLARGE_STRING WindowName
,
1893 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1894 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1895 PWINSTATION_OBJECT WinSta
;
1898 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1899 CBT_CREATEWNDW
* pCbtCreate
;
1901 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1903 DWORD dwShowMode
= SW_SHOW
;
1904 CREATESTRUCTW
*pCsw
= NULL
;
1905 PVOID pszClass
= NULL
, pszName
= NULL
;
1908 /* Get the current window station and reference it */
1909 pti
= GetW32ThreadInfo();
1910 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1912 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1913 return NULL
; // There is nothing to cleanup.
1915 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1916 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1921 /* Get the class and reference it */
1922 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
1925 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
1926 ERR("Failed to find class %wZ\n", ClassName
);
1930 /* Now find the parent and the owner window */
1931 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
1934 if (Cs
->hwndParent
== HWND_MESSAGE
)
1936 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
1938 else if (Cs
->hwndParent
)
1940 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1941 hWndOwner
= Cs
->hwndParent
;
1943 hWndParent
= Cs
->hwndParent
;
1945 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1947 ERR("Cannot create a child window without a parrent!\n");
1948 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1949 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1952 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1953 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1955 if (hWndParent
&& !ParentWindow
)
1957 ERR("Got invalid parent window handle\n");
1963 if (IntIsDesktopWindow(OwnerWindow
)) OwnerWindow
= NULL
;
1964 else if (ParentWindow
&& !IntIsDesktopWindow(ParentWindow
))
1966 ERR("an owned window must be created as top-level\n");
1967 EngSetLastError( STATUS_ACCESS_DENIED
);
1970 else /* owner must be a top-level window */
1972 while ((OwnerWindow
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
&& !IntIsDesktopWindow(OwnerWindow
->spwndParent
))
1973 OwnerWindow
= OwnerWindow
->spwndParent
;
1977 /* Fix the position and the size of the window */
1980 UserRefObjectCo(ParentWindow
, &ParentRef
);
1981 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
1984 /* Allocate and initialize the new window */
1985 Window
= IntCreateWindow(Cs
,
1994 ERR("IntCreateWindow failed!\n");
1998 hWnd
= UserHMGetHandle(Window
);
1999 hwndInsertAfter
= HWND_TOP
;
2001 UserRefObjectCo(Window
, &Ref
);
2002 UserDereferenceObject(Window
);
2003 ObDereferenceObject(WinSta
);
2005 //// Check for a hook to eliminate overhead. ////
2006 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2008 // Allocate the calling structures Justin Case this goes Global.
2009 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2010 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2011 if (!pCsw
|| !pCbtCreate
)
2013 ERR("UserHeapAlloc() failed!\n");
2017 /* Fill the new CREATESTRUCTW */
2018 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2019 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2021 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2022 if (!IS_ATOM(ClassName
->Buffer
))
2024 if (Window
->state
& WNDS_ANSICREATOR
)
2026 ANSI_STRING AnsiString
;
2027 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2028 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2031 ERR("UserHeapAlloc() failed!\n");
2034 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2035 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2036 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2040 UNICODE_STRING UnicodeString
;
2041 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2042 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2045 ERR("UserHeapAlloc() failed!\n");
2048 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2049 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2050 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2052 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2054 if (WindowName
->Length
)
2056 UNICODE_STRING Name
;
2057 Name
.Buffer
= WindowName
->Buffer
;
2058 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2059 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2061 if (Window
->state
& WNDS_ANSICREATOR
)
2063 ANSI_STRING AnsiString
;
2064 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2065 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2068 ERR("UserHeapAlloc() failed!\n");
2071 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2072 AnsiString
.Buffer
= (PCHAR
)pszName
;
2073 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2077 UNICODE_STRING UnicodeString
;
2078 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2079 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2082 ERR("UserHeapAlloc() failed!\n");
2085 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2086 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2087 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2089 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2092 pCbtCreate
->lpcs
= pCsw
;
2093 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2095 //// Call the WH_CBT hook ////
2096 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2099 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2102 // Write back changes.
2107 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2110 /* NCCREATE and WM_NCCALCSIZE need the original values */
2111 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2112 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2114 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2116 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2118 Cs
->x
+= ParentWindow
->rcClient
.left
;
2119 Cs
->y
+= ParentWindow
->rcClient
.top
;
2123 /* Send the WM_GETMINMAXINFO message */
2127 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2129 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2130 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2131 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2132 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2133 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2136 Window
->rcWindow
.left
= Cs
->x
;
2137 Window
->rcWindow
.top
= Cs
->y
;
2138 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2139 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2141 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2143 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2144 RECTL_vOffsetRect(&Window->rcWindow,
2145 ParentWindow->rcClient.left,
2146 ParentWindow->rcClient.top);
2149 /* correct child window coordinates if mirroring on parent is enabled */
2150 if (ParentWindow
!= NULL
)
2152 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2153 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2155 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2156 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2160 Window
->rcClient
= Window
->rcWindow
;
2162 /* Link the window */
2163 if (NULL
!= ParentWindow
)
2165 /* Link the window into the siblings list */
2166 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2167 IntLinkHwnd(Window
, HWND_BOTTOM
);
2169 IntLinkHwnd(Window
, hwndInsertAfter
);
2172 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2174 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2175 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2178 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2180 if ( !IntIsTopLevelWindow(Window
) )
2182 if (pti
!= Window
->spwndParent
->head
.pti
)
2184 //ERR("CreateWindow Parent in.\n");
2185 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2190 /* Send the NCCREATE message */
2191 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2194 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2198 /* Send the WM_NCCALCSIZE message */
2201 MaxPos
.x
= Window
->rcWindow
.left
;
2202 MaxPos
.y
= Window
->rcWindow
.top
;
2204 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2205 //rc = Window->rcWindow;
2206 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2207 //Window->rcClient = rc;
2209 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2210 MaxPos
.y
- Window
->rcWindow
.top
);
2213 /* Send the WM_CREATE message. */
2214 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2215 if (Result
== (LRESULT
)-1)
2217 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2221 /* Send the EVENT_OBJECT_CREATE event */
2222 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2224 /* By setting the flag below it can be examined to determine if the window
2225 was created successfully and a valid pwnd was passed back to caller since
2226 from here the function has to succeed. */
2227 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2229 /* Send the WM_SIZE and WM_MOVE messages. */
2230 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2232 co_WinPosSendSizeMove(Window
);
2235 /* Show or maybe minimize or maximize the window. */
2237 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2238 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2241 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2243 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2244 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2245 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2246 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2247 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2250 /* Send the WM_PARENTNOTIFY message */
2251 IntSendParentNotify(Window
, WM_CREATE
);
2253 /* Notify the shell that a new window was created */
2254 if (Window
->spwndParent
== UserGetDesktopWindow() &&
2255 Window
->spwndOwner
== NULL
&&
2256 (Window
->style
& WS_VISIBLE
) &&
2257 (!(Window
->ExStyle
& WS_EX_TOOLWINDOW
) ||
2258 (Window
->ExStyle
& WS_EX_APPWINDOW
)))
2260 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2263 /* Initialize and show the window's scrollbars */
2264 if (Window
->style
& WS_VSCROLL
)
2266 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2268 if (Window
->style
& WS_HSCROLL
)
2270 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2273 /* Show the new window */
2274 if (Cs
->style
& WS_VISIBLE
)
2276 if (Window
->style
& WS_MAXIMIZE
)
2277 dwShowMode
= SW_SHOW
;
2278 else if (Window
->style
& WS_MINIMIZE
)
2279 dwShowMode
= SW_SHOWMINIMIZED
;
2281 co_WinPosShowWindow(Window
, dwShowMode
);
2283 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2285 ASSERT(ParentWindow
);
2288 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2289 /* ShowWindow won't activate child windows */
2290 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2294 if (Class
->atomClassName
== gaGuiConsoleWndClass
)
2296 /* Count only console windows manually */
2297 co_IntUserManualGuiCheck(TRUE
);
2300 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2306 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2307 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2309 co_UserDestroyWindow(Window
);
2311 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2314 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2315 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2316 if (pszName
) UserHeapFree(pszName
);
2317 if (pszClass
) UserHeapFree(pszClass
);
2321 UserDerefObjectCo(Window
);
2323 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2330 ProbeAndCaptureLargeString(
2331 OUT PLARGE_STRING plstrSafe
,
2332 IN PLARGE_STRING plstrUnsafe
)
2334 LARGE_STRING lstrTemp
;
2335 PVOID pvBuffer
= NULL
;
2339 /* Probe and copy the string */
2340 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2341 lstrTemp
= *plstrUnsafe
;
2343 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2346 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2350 if (lstrTemp
.Length
!= 0)
2352 /* Allocate a buffer from paged pool */
2353 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2356 return STATUS_NO_MEMORY
;
2361 /* Probe and copy the buffer */
2362 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2363 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2365 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2367 /* Cleanup and fail */
2368 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2369 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2374 /* Set the output string */
2375 plstrSafe
->Buffer
= pvBuffer
;
2376 plstrSafe
->Length
= lstrTemp
.Length
;
2377 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2379 return STATUS_SUCCESS
;
2383 * \todo Allow passing plstrClassName as ANSI.
2387 NtUserCreateWindowEx(
2389 PLARGE_STRING plstrClassName
,
2390 PLARGE_STRING plstrClsVersion
,
2391 PLARGE_STRING plstrWindowName
,
2399 HINSTANCE hInstance
,
2405 LARGE_STRING lstrWindowName
;
2406 LARGE_STRING lstrClassName
;
2407 LARGE_STRING lstrClsVersion
;
2408 UNICODE_STRING ustrClassName
;
2409 UNICODE_STRING ustrClsVersion
;
2414 lstrWindowName
.Buffer
= NULL
;
2415 lstrClassName
.Buffer
= NULL
;
2416 lstrClsVersion
.Buffer
= NULL
;
2418 ASSERT(plstrWindowName
);
2420 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2422 /* check hMenu is valid handle */
2423 if (hMenu
&& !UserGetMenuObject(hMenu
))
2425 ERR("NtUserCreateWindowEx: Got an invalid menu handle!\n");
2426 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
2431 /* Copy the window name to kernel mode */
2432 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2433 if (!NT_SUCCESS(Status
))
2435 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2436 SetLastNtError(Status
);
2440 plstrWindowName
= &lstrWindowName
;
2442 /* Check if the class is an atom */
2443 if (IS_ATOM(plstrClassName
))
2445 /* It is, pass the atom in the UNICODE_STRING */
2446 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2447 ustrClassName
.Length
= 0;
2448 ustrClassName
.MaximumLength
= 0;
2452 /* It's not, capture the class name */
2453 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2454 if (!NT_SUCCESS(Status
))
2456 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2457 /* Set last error, cleanup and return */
2458 SetLastNtError(Status
);
2462 /* We pass it on as a UNICODE_STRING */
2463 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2464 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2465 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2468 /* Check if the class version is an atom */
2469 if (IS_ATOM(plstrClsVersion
))
2471 /* It is, pass the atom in the UNICODE_STRING */
2472 ustrClsVersion
.Buffer
= (PVOID
)plstrClsVersion
;
2473 ustrClsVersion
.Length
= 0;
2474 ustrClsVersion
.MaximumLength
= 0;
2478 /* It's not, capture the class name */
2479 Status
= ProbeAndCaptureLargeString(&lstrClsVersion
, plstrClsVersion
);
2480 if (!NT_SUCCESS(Status
))
2482 ERR("NtUserCreateWindowEx: failed to capture plstrClsVersion\n");
2483 /* Set last error, cleanup and return */
2484 SetLastNtError(Status
);
2488 /* We pass it on as a UNICODE_STRING */
2489 ustrClsVersion
.Buffer
= lstrClsVersion
.Buffer
;
2490 ustrClsVersion
.Length
= (USHORT
)min(lstrClsVersion
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2491 ustrClsVersion
.MaximumLength
= (USHORT
)min(lstrClsVersion
.MaximumLength
, MAXUSHORT
);
2494 /* Fill the CREATESTRUCTW */
2495 /* we will keep here the original parameters */
2497 Cs
.lpCreateParams
= lpParam
;
2498 Cs
.hInstance
= hInstance
;
2500 Cs
.hwndParent
= hWndParent
;
2505 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2506 Cs
.lpszClass
= ustrClassName
.Buffer
;
2507 Cs
.dwExStyle
= dwExStyle
;
2509 UserEnterExclusive();
2511 /* Call the internal function */
2512 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClsVersion
, plstrWindowName
, acbiBuffer
);
2516 ERR("co_UserCreateWindowEx failed!\n");
2518 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2523 if (lstrWindowName
.Buffer
)
2525 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2527 if (lstrClassName
.Buffer
)
2529 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2531 if (lstrClsVersion
.Buffer
)
2533 ExFreePoolWithTag(lstrClsVersion
.Buffer
, TAG_STRING
);
2540 BOOLEAN
co_UserDestroyWindow(PVOID Object
)
2546 PWND Window
= Object
;
2548 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2550 hWnd
= Window
->head
.h
;
2551 ti
= PsGetCurrentThreadWin32Thread();
2553 TRACE("co_UserDestroyWindow \n");
2555 /* Check for owner thread */
2556 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2558 /* Check if we are destroying the desktop window */
2559 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2561 EngSetLastError(ERROR_ACCESS_DENIED
);
2566 /* If window was created successfully and it is hooked */
2567 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2569 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2571 ERR("Destroy Window WH_CBT Call Hook return!\n");
2576 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2578 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2580 if (Window
->spwndOwner
)
2582 //ERR("DestroyWindow Owner out.\n");
2583 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2588 /* Inform the parent */
2589 if (Window
->style
& WS_CHILD
)
2591 IntSendParentNotify(Window
, WM_DESTROY
);
2594 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
2596 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
2599 /* Hide the window */
2600 if (Window
->style
& WS_VISIBLE
)
2602 if (Window
->style
& WS_CHILD
)
2604 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
2605 co_WinPosShowWindow(Window
, SW_HIDE
);
2609 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2613 // Adjust last active.
2614 if ((pwndTemp
= Window
->spwndOwner
))
2616 while (pwndTemp
->spwndOwner
)
2617 pwndTemp
= pwndTemp
->spwndOwner
;
2619 if (pwndTemp
->spwndLastActive
== Window
)
2620 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2623 if (Window
->spwndParent
&& IntIsWindow(UserHMGetHandle(Window
)))
2625 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2627 if (!IntIsTopLevelWindow(Window
))
2629 //ERR("DestroyWindow Parent out.\n");
2630 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2635 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2636 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2637 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2638 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2639 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2640 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2641 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2642 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2645 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2648 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2650 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2652 ERR("Destroying the ShellWindow!\n");
2653 ti
->pDeskInfo
->hShellWindow
= NULL
;
2657 IntEngWindowChanged(Window
, WOC_DELETE
);
2659 if (!IntIsWindow(UserHMGetHandle(Window
)))
2664 /* Recursively destroy owned windows */
2666 if (! (Window
->style
& WS_CHILD
))
2670 BOOL GotOne
= FALSE
;
2673 PWND Child
, Desktop
;
2675 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2676 UserGetWindowObject(IntGetDesktopWindow());
2677 Children
= IntWinListChildren(Desktop
);
2681 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2683 Child
= UserGetWindowObject(*ChildHandle
);
2686 if (Child
->spwndOwner
!= Window
)
2691 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2693 USER_REFERENCE_ENTRY ChildRef
;
2694 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2695 co_UserDestroyWindow(Child
);
2696 UserDerefObjectCo(Child
); // Temp HACK?
2702 if (Child
->spwndOwner
!= NULL
)
2704 Child
->spwndOwner
= NULL
;
2708 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2717 /* Generate mouse move message for the next window */
2718 msg
.message
= WM_MOUSEMOVE
;
2719 msg
.wParam
= UserGetMouseButtonsState();
2720 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2721 msg
.pt
= gpsi
->ptCursor
;
2722 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2724 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2726 /* Send destroy messages */
2727 IntSendDestroyMsg(UserHMGetHandle(Window
));
2729 if (!IntIsWindow(UserHMGetHandle(Window
)))
2734 /* Destroy the window storage */
2735 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2745 NtUserDestroyWindow(HWND Wnd
)
2748 DECLARE_RETURN(BOOLEAN
);
2750 USER_REFERENCE_ENTRY Ref
;
2752 TRACE("Enter NtUserDestroyWindow\n");
2753 UserEnterExclusive();
2755 if (!(Window
= UserGetWindowObject(Wnd
)))
2760 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2761 ret
= co_UserDestroyWindow(Window
);
2762 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2767 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2773 static HWND FASTCALL
2774 IntFindWindow(PWND Parent
,
2777 PUNICODE_STRING WindowName
)
2779 BOOL CheckWindowName
;
2782 UNICODE_STRING CurrentWindowName
;
2786 CheckWindowName
= WindowName
->Buffer
!= 0;
2788 if((List
= IntWinListChildren(Parent
)))
2793 /* skip handles before and including ChildAfter */
2794 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2798 /* search children */
2802 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2807 /* Do not send WM_GETTEXT messages in the kernel mode version!
2808 The user mode version however calls GetWindowText() which will
2809 send WM_GETTEXT messages to windows belonging to its processes */
2810 if (!ClassAtom
|| Child
->pcls
->atomNVClassName
== ClassAtom
)
2812 // FIXME: LARGE_STRING truncated
2813 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2814 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2815 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2816 if(!CheckWindowName
||
2817 (Child
->strName
.Length
< 0xFFFF &&
2818 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2820 Ret
= Child
->head
.h
;
2825 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2833 * Searches a window's children for a window with the specified
2836 * hwndParent = The window whose childs are to be searched.
2838 * HWND_MESSAGE = message-only windows
2840 * hwndChildAfter = Search starts after this child window.
2841 * NULL = start from beginning
2843 * ucClassName = Class name to search for
2844 * Reguired parameter.
2846 * ucWindowName = Window name
2847 * ->Buffer == NULL = don't care
2850 * The HWND of the window if it was found, otherwise NULL
2856 NtUserFindWindowEx(HWND hwndParent
,
2857 HWND hwndChildAfter
,
2858 PUNICODE_STRING ucClassName
,
2859 PUNICODE_STRING ucWindowName
,
2862 PWND Parent
, ChildAfter
;
2863 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2864 HWND Desktop
, Ret
= NULL
;
2865 BOOL DoMessageWnd
= FALSE
;
2866 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2867 DECLARE_RETURN(HWND
);
2869 TRACE("Enter NtUserFindWindowEx\n");
2872 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2876 if (ucClassName
!= NULL
)
2878 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2879 if (ClassName
.Length
!= 0)
2881 ProbeForRead(ClassName
.Buffer
,
2885 else if (!IS_ATOM(ClassName
.Buffer
))
2887 EngSetLastError(ERROR_INVALID_PARAMETER
);
2891 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2894 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
2899 if (ucWindowName
!= NULL
)
2901 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2902 if (WindowName
.Length
!= 0)
2904 ProbeForRead(WindowName
.Buffer
,
2910 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2912 SetLastNtError(_SEH2_GetExceptionCode());
2913 _SEH2_YIELD(RETURN(NULL
));
2917 if (ucClassName
!= NULL
)
2919 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2920 !IS_ATOM(ClassName
.Buffer
))
2922 EngSetLastError(ERROR_INVALID_PARAMETER
);
2925 else if (ClassAtom
== (RTL_ATOM
)0)
2927 /* LastError code was set by IntGetAtomFromStringOrAtom */
2933 Desktop
= IntGetCurrentThreadDesktopWindow();
2935 if(hwndParent
== NULL
)
2937 hwndParent
= Desktop
;
2938 DoMessageWnd
= TRUE
;
2940 else if(hwndParent
== HWND_MESSAGE
)
2942 hwndParent
= IntGetMessageWindow();
2945 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2951 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2958 if(Parent
->head
.h
== Desktop
)
2961 PWND TopLevelWindow
;
2962 BOOLEAN CheckWindowName
;
2963 BOOLEAN WindowMatches
;
2964 BOOLEAN ClassMatches
;
2966 /* windows searches through all top-level windows if the parent is the desktop
2969 if((List
= IntWinListChildren(Parent
)))
2975 /* skip handles before and including ChildAfter */
2976 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2980 CheckWindowName
= WindowName
.Buffer
!= 0;
2982 /* search children */
2985 UNICODE_STRING ustr
;
2987 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2992 /* Do not send WM_GETTEXT messages in the kernel mode version!
2993 The user mode version however calls GetWindowText() which will
2994 send WM_GETTEXT messages to windows belonging to its processes */
2995 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2996 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
2997 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
2998 WindowMatches
= !CheckWindowName
||
2999 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
3000 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
3001 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
3002 ClassAtom
== TopLevelWindow
->pcls
->atomNVClassName
;
3004 if (WindowMatches
&& ClassMatches
)
3006 Ret
= TopLevelWindow
->head
.h
;
3010 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3012 /* window returns the handle of the top-level window, in case it found
3014 Ret
= TopLevelWindow
->head
.h
;
3019 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3024 TRACE("FindWindowEx: Not Desktop Parent!\n");
3025 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3028 if (Ret
== NULL
&& DoMessageWnd
)
3032 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3034 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3038 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3040 SetLastNtError(_SEH2_GetExceptionCode());
3048 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3057 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3059 PWND WndAncestor
, Parent
;
3061 if (Wnd
->head
.h
== IntGetDesktopWindow())
3070 WndAncestor
= Wnd
->spwndParent
;
3081 if(!(Parent
= WndAncestor
->spwndParent
))
3085 if(IntIsDesktopWindow(Parent
))
3090 WndAncestor
= Parent
;
3101 Parent
= IntGetParent(WndAncestor
);
3108 WndAncestor
= Parent
;
3126 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3128 PWND Window
, Ancestor
;
3129 DECLARE_RETURN(HWND
);
3131 TRACE("Enter NtUserGetAncestor\n");
3132 UserEnterExclusive();
3134 if (!(Window
= UserGetWindowObject(hWnd
)))
3139 Ancestor
= UserGetAncestor(Window
, Type
);
3140 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3142 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3145 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3151 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3153 /* combo state struct */
3167 INT fixedOwnerDrawHeight
;
3168 INT droppedWidth
; /* last two are not used unless set */
3169 INT editHeight
; /* explicitly */
3171 } HEADCOMBO
,*LPHEADCOMBO
;
3173 // Window Extra data container.
3174 typedef struct _WND2CBOX
3178 } WND2CBOX
, *PWND2CBOX
;
3180 #define CBF_BUTTONDOWN 0x0002
3186 NtUserGetComboBoxInfo(
3192 BOOL NotSameppi
= FALSE
;
3194 DECLARE_RETURN(BOOL
);
3196 TRACE("Enter NtUserGetComboBoxInfo\n");
3199 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3205 ProbeForWrite(pcbi
, sizeof(COMBOBOXINFO
), 1);
3207 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3209 SetLastNtError(_SEH2_GetExceptionCode());
3210 _SEH2_YIELD(RETURN(FALSE
));
3214 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3216 EngSetLastError(ERROR_INVALID_PARAMETER
);
3220 // Pass the user pointer, it was already probed.
3221 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3223 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3226 ppi
= PsGetCurrentProcessWin32Process();
3227 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3230 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3235 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3236 pcbi
->rcItem
= lphc
->textRect
;
3237 pcbi
->rcButton
= lphc
->buttonRect
;
3238 pcbi
->stateButton
= 0;
3239 if (lphc
->wState
& CBF_BUTTONDOWN
)
3240 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3241 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3242 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3243 pcbi
->hwndCombo
= lphc
->self
;
3244 pcbi
->hwndItem
= lphc
->hWndEdit
;
3245 pcbi
->hwndList
= lphc
->hWndLBox
;
3247 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3250 SetLastNtError(_SEH2_GetExceptionCode());
3257 if (NotSameppi
) KeDetachProcess();
3258 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3264 //// ReactOS work around! Keep it the sames as in Listbox.c
3266 /* Listbox structure */
3269 HWND self
; /* Our own window handle */
3270 HWND owner
; /* Owner window to send notifications to */
3271 UINT style
; /* Window style */
3272 INT width
; /* Window width */
3273 INT height
; /* Window height */
3274 VOID
*items
; /* Array of items */
3275 INT nb_items
; /* Number of items */
3276 INT top_item
; /* Top visible item */
3277 INT selected_item
; /* Selected item */
3278 INT focus_item
; /* Item that has the focus */
3279 INT anchor_item
; /* Anchor item for extended selection */
3280 INT item_height
; /* Default item height */
3281 INT page_size
; /* Items per listbox page */
3282 INT column_width
; /* Column width for multi-column listboxes */
3285 // Window Extra data container.
3286 typedef struct _WND2LB
3296 NtUserGetListBoxInfo(
3301 BOOL NotSameppi
= FALSE
;
3303 DECLARE_RETURN(DWORD
);
3305 TRACE("Enter NtUserGetListBoxInfo\n");
3308 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3313 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3315 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3318 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3319 ppi
= PsGetCurrentProcessWin32Process();
3320 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3323 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3328 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3329 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3330 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3331 Ret
= descr
->page_size
* descr
->column_width
;
3333 Ret
= descr
->page_size
;
3335 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3338 SetLastNtError(_SEH2_GetExceptionCode());
3345 if (NotSameppi
) KeDetachProcess();
3346 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3354 * The NtUserSetParent function changes the parent window of the specified
3358 * The new parent window and the child window must belong to the same
3359 * application. If the window identified by the hWndChild parameter is
3360 * visible, the system performs the appropriate redrawing and repainting.
3361 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3362 * or WS_POPUP window styles of the window whose parent is being changed.
3369 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3371 DECLARE_RETURN(HWND
);
3373 TRACE("Enter NtUserSetParent\n");
3374 UserEnterExclusive();
3377 Check Parent first from user space, set it here.
3381 hWndNewParent
= IntGetDesktopWindow();
3383 else if (hWndNewParent
== HWND_MESSAGE
)
3385 hWndNewParent
= IntGetMessageWindow();
3388 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3391 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3397 * UserGetShellWindow
3399 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3404 HWND FASTCALL
UserGetShellWindow(VOID
)
3406 PWINSTATION_OBJECT WinStaObject
;
3409 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3415 if (!NT_SUCCESS(Status
))
3417 SetLastNtError(Status
);
3421 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3423 ObDereferenceObject(WinStaObject
);
3428 * NtUserSetShellWindowEx
3430 * This is undocumented function to set global shell window. The global
3431 * shell window has special handling of window position.
3437 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3439 PWINSTATION_OBJECT WinStaObject
;
3440 PWND WndShell
, WndListView
;
3441 DECLARE_RETURN(BOOL
);
3442 USER_REFERENCE_ENTRY Ref
;
3446 TRACE("Enter NtUserSetShellWindowEx\n");
3447 UserEnterExclusive();
3449 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3454 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3459 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3465 if (!NT_SUCCESS(Status
))
3467 SetLastNtError(Status
);
3472 * Test if we are permitted to change the shell window.
3474 if (WinStaObject
->ShellWindow
)
3476 ObDereferenceObject(WinStaObject
);
3481 * Move shell window into background.
3483 if (hwndListView
&& hwndListView
!= hwndShell
)
3486 * Disabled for now to get Explorer working.
3487 * -- Filip, 01/nov/2003
3490 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3493 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3495 ObDereferenceObject(WinStaObject
);
3500 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3502 ObDereferenceObject(WinStaObject
);
3506 UserRefObjectCo(WndShell
, &Ref
);
3507 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3508 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3510 WinStaObject
->ShellWindow
= hwndShell
;
3511 WinStaObject
->ShellListView
= hwndListView
;
3513 ti
= GetW32ThreadInfo();
3516 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3517 ti
->pDeskInfo
->spwndShell
= WndShell
;
3518 ti
->pDeskInfo
->spwndBkGnd
= WndListView
;
3519 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3522 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3524 UserDerefObjectCo(WndShell
);
3526 ObDereferenceObject(WinStaObject
);
3530 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3535 // Fixes wine Win test_window_styles and todo tests...
3536 static BOOL FASTCALL
3537 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3539 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3541 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3548 co_IntSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
, BOOL bAlter
)
3550 PWND Window
, Parent
;
3551 PWINSTATION_OBJECT WindowStation
;
3555 if (!(Window
= UserGetWindowObject(hWnd
)))
3560 if ((INT
)Index
>= 0)
3562 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3564 EngSetLastError(ERROR_INVALID_INDEX
);
3568 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3570 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3572 OldValue = (LONG)IntSetWindowProc( Wnd,
3575 if (!OldValue) return 0;
3578 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3585 OldValue
= (LONG
) Window
->ExStyle
;
3586 Style
.styleOld
= OldValue
;
3587 Style
.styleNew
= NewValue
;
3589 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3592 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3594 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3597 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3598 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3600 /* WS_EX_WINDOWEDGE depends on some other styles */
3601 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3602 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3604 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3606 if (!(Window
->ExStyle
& WS_EX_LAYERED
))
3608 SetLayeredStatus(Window
, 0);
3611 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3613 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3617 OldValue
= (LONG
) Window
->style
;
3618 Style
.styleOld
= OldValue
;
3619 Style
.styleNew
= NewValue
;
3622 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3624 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3625 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3626 /* WS_MINIMIZE can't be reset */
3627 if (OldValue
& WS_MINIMIZE
) Style
.styleNew
|= WS_MINIMIZE
;
3628 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3629 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3630 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3632 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3634 if ((OldValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3636 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
3638 //// From child to non-child it should be null already.
3639 ERR("IDMenu going null! %d\n",Window
->IDMenu
);
3640 Window
->IDMenu
= 0; // Window->spmenu = 0;
3645 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3647 PMENU pMenu
= UserGetMenuObject(UlongToHandle(Window
->IDMenu
));
3648 Window
->state
&= ~WNDS_HASMENU
;
3651 ERR("IDMenu released 0x%p\n",pMenu
);
3652 // ROS may not hold a lock after setting menu to window. But it should!
3653 //IntReleaseMenuObject(pMenu);
3658 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3660 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3661 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3662 DceResetActiveDCEs( Window
);
3664 Window
->style
= (DWORD
)Style
.styleNew
;
3667 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3672 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3673 Window
->fnid
& FNID_FREED
)
3675 EngSetLastError(ERROR_ACCESS_DENIED
);
3678 OldValue
= (LONG
)IntSetWindowProc(Window
,
3685 OldValue
= (LONG
) Window
->hModule
;
3686 Window
->hModule
= (HINSTANCE
) NewValue
;
3689 case GWL_HWNDPARENT
:
3690 Parent
= Window
->spwndParent
;
3691 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3692 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3694 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3698 OldValue
= (LONG
) Window
->IDMenu
;
3699 Window
->IDMenu
= (UINT
) NewValue
;
3703 OldValue
= Window
->dwUserData
;
3704 Window
->dwUserData
= NewValue
;
3708 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3709 EngSetLastError(ERROR_INVALID_INDEX
);
3720 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3722 return co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3726 * NtUserSetWindowLong
3728 * The NtUserSetWindowLong function changes an attribute of the specified
3729 * window. The function also sets the 32-bit (long) value at the specified
3730 * offset into the extra window memory.
3737 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3741 UserEnterExclusive();
3743 if (hWnd
== IntGetDesktopWindow())
3745 EngSetLastError(STATUS_ACCESS_DENIED
);
3750 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3758 NtUserAlterWindowStyle(HWND hWnd
, DWORD Index
, LONG NewValue
)
3762 UserEnterExclusive();
3764 if (hWnd
== IntGetDesktopWindow())
3766 EngSetLastError(STATUS_ACCESS_DENIED
);
3771 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, FALSE
, TRUE
);
3780 * NtUserSetWindowWord
3782 * Legacy function similar to NtUserSetWindowLong.
3789 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3793 DECLARE_RETURN(WORD
);
3795 TRACE("Enter NtUserSetWindowWord\n");
3796 UserEnterExclusive();
3798 if (hWnd
== IntGetDesktopWindow())
3800 EngSetLastError(STATUS_ACCESS_DENIED
);
3804 if (!(Window
= UserGetWindowObject(hWnd
)))
3813 case GWL_HWNDPARENT
:
3814 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3818 EngSetLastError(ERROR_INVALID_INDEX
);
3823 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3825 EngSetLastError(ERROR_INVALID_PARAMETER
);
3829 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3830 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3835 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3841 QueryWindow based on KJK::Hyperion and James Tabor.
3843 0 = QWUniqueProcessId
3844 1 = QWUniqueThreadId
3847 4 = QWIsHung Implements IsHungAppWindow found
3850 9 = QWKillWindow When I called this with hWnd ==
3851 DesktopWindow, it shutdown the system
3858 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3860 /* Console Leader Process CID Window offsets */
3861 #define GWLP_CONSOLE_LEADER_PID 0
3862 #define GWLP_CONSOLE_LEADER_TID 4
3866 DECLARE_RETURN(UINT
);
3868 TRACE("Enter NtUserQueryWindow\n");
3871 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3878 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3880 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3881 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3883 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
3884 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
3888 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3893 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3895 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3896 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3898 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
3899 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
3903 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3908 case QUERY_WINDOW_ACTIVE
:
3909 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3912 case QUERY_WINDOW_FOCUS
:
3913 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3916 case QUERY_WINDOW_ISHUNG
:
3917 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
);
3920 case QUERY_WINDOW_REAL_ID
:
3921 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3924 case QUERY_WINDOW_FOREGROUND
:
3925 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3929 Result
= (DWORD
)NULL
;
3936 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
3945 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3947 UNICODE_STRING SafeMessageName
;
3950 DECLARE_RETURN(UINT
);
3952 TRACE("Enter NtUserRegisterWindowMessage\n");
3953 UserEnterExclusive();
3955 if(MessageNameUnsafe
== NULL
)
3957 EngSetLastError(ERROR_INVALID_PARAMETER
);
3961 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3962 if(!NT_SUCCESS(Status
))
3964 SetLastNtError(Status
);
3968 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3969 if (SafeMessageName
.Buffer
)
3970 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3974 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
3983 NtUserSetWindowFNID(HWND hWnd
,
3987 DECLARE_RETURN(BOOL
);
3989 TRACE("Enter NtUserSetWindowFNID\n");
3990 UserEnterExclusive();
3992 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3997 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3999 EngSetLastError(ERROR_ACCESS_DENIED
);
4003 // From user land we only set these.
4004 if (fnID
!= FNID_DESTROY
)
4006 /* HACK: The minimum should be FNID_BUTTON, but menu code relies on this */
4007 if (fnID
< FNID_FIRST
|| fnID
> FNID_GHOST
||
4010 EngSetLastError(ERROR_INVALID_PARAMETER
);
4019 TRACE("Leave NtUserSetWindowFNID\n");
4025 DefSetText(PWND Wnd
, PCWSTR WindowText
)
4027 UNICODE_STRING UnicodeString
;
4030 RtlInitUnicodeString(&UnicodeString
, WindowText
);
4032 if (UnicodeString
.Length
!= 0)
4034 if (Wnd
->strName
.MaximumLength
> 0 &&
4035 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4037 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4039 Wnd
->strName
.Length
= UnicodeString
.Length
;
4040 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4041 RtlCopyMemory(Wnd
->strName
.Buffer
,
4042 UnicodeString
.Buffer
,
4043 UnicodeString
.Length
);
4048 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4049 buf
= Wnd
->strName
.Buffer
;
4050 Wnd
->strName
.Buffer
= NULL
;
4053 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4056 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4057 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4058 if (Wnd
->strName
.Buffer
!= NULL
)
4060 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4061 RtlCopyMemory(Wnd
->strName
.Buffer
,
4062 UnicodeString
.Buffer
,
4063 UnicodeString
.Length
);
4064 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4065 Wnd
->strName
.Length
= UnicodeString
.Length
;
4069 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4076 Wnd
->strName
.Length
= 0;
4077 if (Wnd
->strName
.Buffer
!= NULL
)
4078 Wnd
->strName
.Buffer
[0] = L
'\0';
4081 // FIXME: HAX! Windows does not do this in here!
4082 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4083 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4084 /* Send shell notifications */
4085 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4087 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) UserHMGetHandle(Wnd
), FALSE
); // FIXME Flashing?
4092 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4099 * Undocumented function that is called from DefWindowProc to set
4106 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4109 LARGE_STRING SafeText
;
4110 UNICODE_STRING UnicodeString
;
4113 TRACE("Enter NtUserDefSetText\n");
4115 if (WindowText
!= NULL
)
4119 SafeText
= ProbeForReadLargeString(WindowText
);
4121 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4124 SetLastNtError(_SEH2_GetExceptionCode());
4134 UserEnterExclusive();
4136 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4142 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4143 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4144 // Now we know what the bAnsi is for.
4145 RtlInitUnicodeString(&UnicodeString
, NULL
);
4146 if (SafeText
.Buffer
)
4151 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4153 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4154 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4156 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4159 SetLastNtError(_SEH2_GetExceptionCode());
4162 if (!Ret
) goto Exit
;
4165 if (UnicodeString
.Length
!= 0)
4167 if (Wnd
->strName
.MaximumLength
> 0 &&
4168 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4170 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4172 Wnd
->strName
.Length
= UnicodeString
.Length
;
4173 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4174 RtlCopyMemory(Wnd
->strName
.Buffer
,
4175 UnicodeString
.Buffer
,
4176 UnicodeString
.Length
);
4181 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4182 buf
= Wnd
->strName
.Buffer
;
4183 Wnd
->strName
.Buffer
= NULL
;
4186 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4189 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4190 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4191 if (Wnd
->strName
.Buffer
!= NULL
)
4193 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4194 RtlCopyMemory(Wnd
->strName
.Buffer
,
4195 UnicodeString
.Buffer
,
4196 UnicodeString
.Length
);
4197 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4198 Wnd
->strName
.Length
= UnicodeString
.Length
;
4202 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4210 Wnd
->strName
.Length
= 0;
4211 if (Wnd
->strName
.Buffer
!= NULL
)
4212 Wnd
->strName
.Buffer
[0] = L
'\0';
4215 // FIXME: HAX! Windows does not do this in here!
4216 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4217 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4218 /* Send shell notifications */
4219 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4221 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4226 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4227 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4233 * NtUserInternalGetWindowText
4240 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4245 DECLARE_RETURN(INT
);
4247 TRACE("Enter NtUserInternalGetWindowText\n");
4250 if(lpString
&& (nMaxCount
<= 1))
4252 EngSetLastError(ERROR_INVALID_PARAMETER
);
4256 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4261 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4264 const WCHAR Terminator
= L
'\0';
4266 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4268 Copy
= min(nMaxCount
- 1, Result
);
4271 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4272 if(!NT_SUCCESS(Status
))
4274 SetLastNtError(Status
);
4280 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4281 if(!NT_SUCCESS(Status
))
4283 SetLastNtError(Status
);
4293 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4303 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4309 // ASSERT(OwnerWnd);
4311 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4312 win_array
= IntWinListChildren(OwnerWnd
);
4317 while (win_array
[count
])
4319 while (--count
>= 0)
4321 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4323 if (pWnd
->spwndOwner
!= OwnerWnd
)
4328 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4330 /* In Windows, ShowOwnedPopups(TRUE) generates
4331 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4332 * regardless of the state of the owner
4334 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4340 if (pWnd
->style
& WS_VISIBLE
)
4342 /* In Windows, ShowOwnedPopups(FALSE) generates
4343 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4344 * regardless of the state of the owner
4346 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4352 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4353 TRACE("Leave ShowOwnedPopups\n");