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 UserDeleteObject(UserHMGetHandle(Window
), TYPE_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
);
678 // Same as User32:IntGetWndProc.
681 IntGetWindowProc(PWND pWnd
,
686 WNDPROC gcpd
, Ret
= 0;
688 ASSERT(UserIsEnteredExclusive() == TRUE
);
692 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
694 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
696 if (GETPFNSERVER(i
) == pWnd
->lpfnWndProc
)
699 Ret
= GETPFNCLIENTA(i
);
701 Ret
= GETPFNCLIENTW(i
);
707 if (Class
->fnid
== FNID_EDIT
)
708 Ret
= pWnd
->lpfnWndProc
;
711 Ret
= pWnd
->lpfnWndProc
;
713 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
717 if (GETPFNCLIENTW(Class
->fnid
) == pWnd
->lpfnWndProc
)
718 Ret
= GETPFNCLIENTA(Class
->fnid
);
722 if (GETPFNCLIENTA(Class
->fnid
) == pWnd
->lpfnWndProc
)
723 Ret
= GETPFNCLIENTW(Class
->fnid
);
726 if ( Ret
!= pWnd
->lpfnWndProc
)
729 if ( Ansi
== !!(pWnd
->state
& WNDS_ANSIWINDOWPROC
) )
732 gcpd
= (WNDPROC
)UserGetCPD(
734 (Ansi
? UserGetCPDA2U
: UserGetCPDU2A
)|UserGetCPDWindow
,
737 return (gcpd
? gcpd
: Ret
);
741 IntSetWindowProc(PWND pWnd
,
746 PCALLPROCDATA CallProc
;
748 WNDPROC Ret
, chWndProc
= NULL
;
750 // Retrieve previous window proc.
751 Ret
= IntGetWindowProc(pWnd
, Ansi
);
755 if (IsCallProcHandle(NewWndProc
))
757 CallProc
= UserGetObject(gHandleTable
, NewWndProc
, TYPE_CALLPROC
);
759 { // Reset new WndProc.
760 NewWndProc
= CallProc
->pfnClientPrevious
;
761 // Reset Ansi from CallProc handle. This is expected with wine "deftest".
762 Ansi
= !!(CallProc
->wType
& UserGetCPDU2A
);
765 // Switch from Client Side call to Server Side call if match. Ref: "deftest".
766 for ( i
= FNID_FIRST
; i
<= FNID_SWITCH
; i
++)
768 if (GETPFNCLIENTW(i
) == NewWndProc
)
770 chWndProc
= GETPFNSERVER(i
);
773 if (GETPFNCLIENTA(i
) == NewWndProc
)
775 chWndProc
= GETPFNSERVER(i
);
779 // If match, set/reset to Server Side and clear ansi.
782 pWnd
->lpfnWndProc
= chWndProc
;
783 pWnd
->Unicode
= TRUE
;
784 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
785 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
789 pWnd
->Unicode
= !Ansi
;
790 // Handle the state change in here.
792 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
794 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
796 if (pWnd
->state
& WNDS_SERVERSIDEWINDOWPROC
)
797 pWnd
->state
&= ~WNDS_SERVERSIDEWINDOWPROC
;
799 if (!NewWndProc
) NewWndProc
= pWnd
->lpfnWndProc
;
801 if (Class
->fnid
<= FNID_GHOST
&& Class
->fnid
>= FNID_BUTTON
)
805 if (GETPFNCLIENTW(Class
->fnid
) == NewWndProc
)
806 chWndProc
= GETPFNCLIENTA(Class
->fnid
);
810 if (GETPFNCLIENTA(Class
->fnid
) == NewWndProc
)
811 chWndProc
= GETPFNCLIENTW(Class
->fnid
);
814 // Now set the new window proc.
815 pWnd
->lpfnWndProc
= (chWndProc
? chWndProc
: NewWndProc
);
821 /* INTERNAL ******************************************************************/
824 // This fixes a check for children messages that need paint while searching the parents messages!
825 // Fixes wine msg:test_paint_messages:WmParentErasePaint ..
828 IntIsChildWindow(PWND Parent
, PWND BaseWindow
)
830 PWND Window
= BaseWindow
;
833 if ( Window
== NULL
|| (Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
836 Window
= Window
->spwndParent
;
838 while(Parent
!= Window
);
844 Link the window into siblings list
845 children and parent are kept in place.
850 PWND WndInsertAfter
/* set to NULL if top sibling */
853 if ((Wnd
->spwndPrev
= WndInsertAfter
))
855 /* link after WndInsertAfter */
856 if ((Wnd
->spwndNext
= WndInsertAfter
->spwndNext
))
857 Wnd
->spwndNext
->spwndPrev
= Wnd
;
859 Wnd
->spwndPrev
->spwndNext
= Wnd
;
864 if ((Wnd
->spwndNext
= Wnd
->spwndParent
->spwndChild
))
865 Wnd
->spwndNext
->spwndPrev
= Wnd
;
867 Wnd
->spwndParent
->spwndChild
= Wnd
;
872 Note: Wnd->spwndParent can be null if it is the desktop.
874 VOID FASTCALL
IntLinkHwnd(PWND Wnd
, HWND hWndPrev
)
876 if (hWndPrev
== HWND_NOTOPMOST
)
878 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
879 (Wnd
->ExStyle2
& WS_EX2_LINKED
)) return; /* nothing to do */
880 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
881 hWndPrev
= HWND_TOP
; /* fallback to the HWND_TOP case */
884 IntUnlinkWindow(Wnd
); /* unlink it from the previous location */
886 if (hWndPrev
== HWND_BOTTOM
)
888 /* Link in the bottom of the list */
891 WndInsertAfter
= Wnd
->spwndParent
->spwndChild
;
892 while( WndInsertAfter
&& WndInsertAfter
->spwndNext
)
893 WndInsertAfter
= WndInsertAfter
->spwndNext
;
895 IntLinkWindow(Wnd
, WndInsertAfter
);
896 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
898 else if (hWndPrev
== HWND_TOPMOST
)
900 /* Link in the top of the list */
901 IntLinkWindow(Wnd
, NULL
);
903 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
905 else if (hWndPrev
== HWND_TOP
)
907 /* Link it after the last topmost window */
908 PWND WndInsertBefore
;
910 WndInsertBefore
= Wnd
->spwndParent
->spwndChild
;
912 if (!(Wnd
->ExStyle
& WS_EX_TOPMOST
)) /* put it above the first non-topmost window */
914 while (WndInsertBefore
!= NULL
&& WndInsertBefore
->spwndNext
!= NULL
)
916 if (!(WndInsertBefore
->ExStyle
& WS_EX_TOPMOST
)) break;
917 if (WndInsertBefore
== Wnd
->spwndOwner
) /* keep it above owner */
919 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
922 WndInsertBefore
= WndInsertBefore
->spwndNext
;
926 IntLinkWindow(Wnd
, WndInsertBefore
? WndInsertBefore
->spwndPrev
: NULL
);
930 /* Link it after hWndPrev */
933 WndInsertAfter
= UserGetWindowObject(hWndPrev
);
934 /* Are we called with an erroneous handle */
935 if(WndInsertAfter
== NULL
)
937 /* Link in a default position */
938 IntLinkHwnd(Wnd
, HWND_TOP
);
942 IntLinkWindow(Wnd
, WndInsertAfter
);
944 /* Fix the WS_EX_TOPMOST flag */
945 if (!(WndInsertAfter
->ExStyle
& WS_EX_TOPMOST
))
947 Wnd
->ExStyle
&= ~WS_EX_TOPMOST
;
951 if(WndInsertAfter
->spwndNext
&&
952 WndInsertAfter
->spwndNext
->ExStyle
& WS_EX_TOPMOST
)
954 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
958 Wnd
->ExStyle2
|= WS_EX2_LINKED
;
962 IntProcessOwnerSwap(PWND Wnd
, PWND WndNewOwner
, PWND WndOldOwner
)
966 if (Wnd
->head
.pti
!= WndOldOwner
->head
.pti
)
969 Wnd
->head
.pti
== WndNewOwner
->head
.pti
||
970 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
972 //ERR("ProcessOwnerSwap Old out.\n");
973 UserAttachThreadInput(Wnd
->head
.pti
, WndOldOwner
->head
.pti
, FALSE
);
979 if (Wnd
->head
.pti
!= WndNewOwner
->head
.pti
)
982 WndOldOwner
->head
.pti
!= WndNewOwner
->head
.pti
)
984 //ERR("ProcessOwnerSwap New in.\n");
985 UserAttachThreadInput(Wnd
->head
.pti
, WndNewOwner
->head
.pti
, TRUE
);
989 // FIXME: System Tray checks.
993 IntSetOwner(HWND hWnd
, HWND hWndNewOwner
)
995 PWND Wnd
, WndOldOwner
, WndNewOwner
;
998 Wnd
= IntGetWindowObject(hWnd
);
1002 WndOldOwner
= Wnd
->spwndOwner
;
1004 ret
= WndOldOwner
? UserHMGetHandle(WndOldOwner
) : 0;
1005 WndNewOwner
= UserGetWindowObject(hWndNewOwner
);
1007 if (!WndNewOwner
&& hWndNewOwner
)
1009 EngSetLastError(ERROR_INVALID_PARAMETER
);
1014 /* if parent belongs to a different thread and the window isn't */
1015 /* top-level, attach the two threads */
1016 IntProcessOwnerSwap(Wnd
, WndNewOwner
, WndOldOwner
);
1018 if (IntValidateOwnerDepth(Wnd
, WndNewOwner
))
1022 Wnd
->spwndOwner
= WndNewOwner
;
1026 Wnd
->spwndOwner
= NULL
;
1031 IntProcessOwnerSwap(Wnd
, WndOldOwner
, WndNewOwner
);
1032 EngSetLastError(ERROR_INVALID_PARAMETER
);
1036 UserDereferenceObject(Wnd
);
1041 co_IntSetParent(PWND Wnd
, PWND WndNewParent
)
1043 PWND WndOldParent
, pWndExam
;
1046 int swFlags
= SWP_NOSIZE
|SWP_NOZORDER
;
1049 ASSERT(WndNewParent
);
1050 ASSERT_REFS_CO(Wnd
);
1051 ASSERT_REFS_CO(WndNewParent
);
1053 if (Wnd
== Wnd
->head
.rpdesk
->spwndMessage
)
1055 EngSetLastError(ERROR_ACCESS_DENIED
);
1059 /* Some applications try to set a child as a parent */
1060 if (IntIsChildWindow(Wnd
, WndNewParent
))
1062 TRACE("IntSetParent try to set a child as a parent.\n");
1063 EngSetLastError( ERROR_INVALID_PARAMETER
);
1067 pWndExam
= WndNewParent
; // Load parent Window to examine.
1068 // Now test for set parent to parent hit.
1071 if (Wnd
== pWndExam
)
1073 TRACE("IntSetParent Failed Test for set parent to parent!\n");
1074 EngSetLastError(ERROR_INVALID_PARAMETER
);
1077 pWndExam
= pWndExam
->spwndParent
;
1081 * Windows hides the window first, then shows it again
1082 * including the WM_SHOWWINDOW messages and all
1084 WasVisible
= co_WinPosShowWindow(Wnd
, SW_HIDE
);
1086 /* Window must belong to current process */
1087 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
1089 ERR("IntSetParent Window must belong to current process!\n");
1093 WndOldParent
= Wnd
->spwndParent
;
1095 if ( WndOldParent
&&
1096 WndOldParent
->ExStyle
& WS_EX_LAYOUTRTL
)
1097 pt
.x
= Wnd
->rcWindow
.right
;
1099 pt
.x
= Wnd
->rcWindow
.left
;
1100 pt
.y
= Wnd
->rcWindow
.top
;
1102 IntScreenToClient(WndOldParent
, &pt
);
1104 if (WndOldParent
) UserReferenceObject(WndOldParent
); /* Caller must deref */
1106 if (WndNewParent
!= WndOldParent
)
1108 /* Unlink the window from the siblings list */
1109 IntUnlinkWindow(Wnd
);
1110 Wnd
->ExStyle2
&= ~WS_EX2_LINKED
;
1112 /* Set the new parent */
1113 Wnd
->spwndParent
= WndNewParent
;
1115 if ( Wnd
->style
& WS_CHILD
&&
1117 Wnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1119 ERR("SetParent Top Most from Pop up!\n");
1120 Wnd
->ExStyle
|= WS_EX_TOPMOST
;
1123 /* Link the window with its new siblings */
1125 ((0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) &&
1126 WndNewParent
== UserGetDesktopWindow() ) ? HWND_TOP
: HWND_TOPMOST
) );
1130 if ( WndNewParent
== co_GetDesktopWindow(Wnd
) &&
1131 !(Wnd
->style
& WS_CLIPSIBLINGS
) )
1133 Wnd
->style
|= WS_CLIPSIBLINGS
;
1134 DceResetActiveDCEs(Wnd
);
1137 /* if parent belongs to a different thread and the window isn't */
1138 /* top-level, attach the two threads */
1139 if ((Wnd
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1141 if ( Wnd
->spwndParent
!= co_GetDesktopWindow(Wnd
))
1143 if (WndOldParent
&& (Wnd
->head
.pti
!= WndOldParent
->head
.pti
))
1145 //ERR("SetParent Old out.\n");
1146 UserAttachThreadInput(Wnd
->head
.pti
, WndOldParent
->head
.pti
, FALSE
);
1149 if ( WndNewParent
!= co_GetDesktopWindow(Wnd
))
1151 if (Wnd
->head
.pti
!= WndNewParent
->head
.pti
)
1153 //ERR("SetParent New in.\n");
1154 UserAttachThreadInput(Wnd
->head
.pti
, WndNewParent
->head
.pti
, TRUE
);
1159 if (WndOldParent
== UserGetMessageWindow() || WndNewParent
== UserGetMessageWindow())
1160 swFlags
|= SWP_NOACTIVATE
;
1162 IntNotifyWinEvent(EVENT_OBJECT_PARENTCHANGE
, Wnd
,OBJID_WINDOW
, CHILDID_SELF
, WEF_SETBYWNDPTI
);
1164 * SetParent additionally needs to make hwnd the top window
1165 * in the z-order and send the expected WM_WINDOWPOSCHANGING and
1166 * WM_WINDOWPOSCHANGED notification messages.
1168 //ERR("IntSetParent SetWindowPos 1\n");
1169 co_WinPosSetWindowPos( Wnd
,
1170 (0 == (Wnd
->ExStyle
& WS_EX_TOPMOST
) ? HWND_TOP
: HWND_TOPMOST
),
1171 pt
.x
, pt
.y
, 0, 0, swFlags
);
1172 //ERR("IntSetParent SetWindowPos 2 X %d Y %d\n",pt.x, pt.y);
1173 if (WasVisible
) co_WinPosShowWindow(Wnd
, SW_SHOWNORMAL
);
1175 return WndOldParent
;
1179 co_UserSetParent(HWND hWndChild
, HWND hWndNewParent
)
1181 PWND Wnd
= NULL
, WndParent
= NULL
, WndOldParent
;
1182 HWND hWndOldParent
= NULL
;
1183 USER_REFERENCE_ENTRY Ref
, ParentRef
;
1185 if (IntIsBroadcastHwnd(hWndChild
) || IntIsBroadcastHwnd(hWndNewParent
))
1187 EngSetLastError(ERROR_INVALID_PARAMETER
);
1191 if (hWndChild
== IntGetDesktopWindow())
1193 ERR("UserSetParent Access Denied!\n");
1194 EngSetLastError(ERROR_ACCESS_DENIED
);
1200 if (!(WndParent
= UserGetWindowObject(hWndNewParent
)))
1202 ERR("UserSetParent Bad New Parent!\n");
1208 if (!(WndParent
= UserGetWindowObject(IntGetDesktopWindow())))
1214 if (!(Wnd
= UserGetWindowObject(hWndChild
)))
1216 ERR("UserSetParent Bad Child!\n");
1220 UserRefObjectCo(Wnd
, &Ref
);
1221 UserRefObjectCo(WndParent
, &ParentRef
);
1222 //ERR("Enter co_IntSetParent\n");
1223 WndOldParent
= co_IntSetParent(Wnd
, WndParent
);
1224 //ERR("Leave co_IntSetParent\n");
1225 UserDerefObjectCo(WndParent
);
1226 UserDerefObjectCo(Wnd
);
1230 hWndOldParent
= WndOldParent
->head
.h
;
1231 UserDereferenceObject(WndOldParent
);
1234 return( hWndOldParent
);
1237 /* Unlink the window from siblings. children and parent are kept in place. */
1239 IntUnlinkWindow(PWND Wnd
)
1242 Wnd
->spwndNext
->spwndPrev
= Wnd
->spwndPrev
;
1245 Wnd
->spwndPrev
->spwndNext
= Wnd
->spwndNext
;
1247 if (Wnd
->spwndParent
&& Wnd
->spwndParent
->spwndChild
== Wnd
)
1248 Wnd
->spwndParent
->spwndChild
= Wnd
->spwndNext
;
1250 Wnd
->spwndPrev
= Wnd
->spwndNext
= NULL
;
1253 /* FUNCTIONS *****************************************************************/
1256 * As best as I can figure, this function is used by EnumWindows,
1257 * EnumChildWindows, EnumDesktopWindows, & EnumThreadWindows.
1259 * It's supposed to build a list of HWNDs to return to the caller.
1260 * We can figure out what kind of list by what parameters are
1268 NtUserBuildHwndList(
1281 return ERROR_INVALID_PARAMETER
;
1283 if (hwndParent
|| !dwThreadId
)
1286 PWND Parent
, Window
;
1290 if(hDesktop
== NULL
&& !(Desktop
= IntGetActiveDesktop()))
1292 return ERROR_INVALID_HANDLE
;
1297 Status
= IntValidateDesktopHandle(hDesktop
,
1301 if(!NT_SUCCESS(Status
))
1303 return ERROR_INVALID_HANDLE
;
1306 hwndParent
= Desktop
->DesktopWindow
;
1313 if((Parent
= UserGetWindowObject(hwndParent
)) &&
1314 (Window
= Parent
->spwndChild
))
1316 BOOL bGoDown
= TRUE
;
1318 Status
= STATUS_SUCCESS
;
1323 if(dwCount
++ < *pBufSize
&& pWnd
)
1327 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1328 *pWnd
= Window
->head
.h
;
1331 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1333 Status
= _SEH2_GetExceptionCode();
1336 if(!NT_SUCCESS(Status
))
1338 SetLastNtError(Status
);
1342 if (Window
->spwndChild
&& bChildren
)
1344 Window
= Window
->spwndChild
;
1349 if (Window
->spwndNext
)
1351 Window
= Window
->spwndNext
;
1355 Window
= Window
->spwndParent
;
1356 if (Window
== Parent
)
1365 ObDereferenceObject(Desktop
);
1368 else // Build EnumThreadWindows list!
1371 PTHREADINFO W32Thread
;
1375 Status
= PsLookupThreadByThreadId((HANDLE
)dwThreadId
, &Thread
);
1376 if (!NT_SUCCESS(Status
))
1378 ERR("Thread Id is not valid!\n");
1379 return ERROR_INVALID_PARAMETER
;
1381 if (!(W32Thread
= (PTHREADINFO
)Thread
->Tcb
.Win32Thread
))
1383 ObDereferenceObject(Thread
);
1384 TRACE("Tried to enumerate windows of a non gui thread\n");
1385 return ERROR_INVALID_PARAMETER
;
1388 // Do not use Thread link list due to co_UserFreeWindow!!!
1389 // Current = W32Thread->WindowListHead.Flink;
1390 // Fixes Api:CreateWindowEx tests!!!
1391 List
= IntWinListChildren(UserGetDesktopWindow());
1395 for (i
= 0; List
[i
]; i
++)
1397 Window
= ValidateHwndNoErr(List
[i
]);
1398 if (Window
&& Window
->head
.pti
== W32Thread
)
1400 if (dwCount
< *pBufSize
&& pWnd
)
1404 ProbeForWrite(pWnd
, sizeof(HWND
), 1);
1405 *pWnd
= Window
->head
.h
;
1408 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1410 Status
= _SEH2_GetExceptionCode();
1413 if (!NT_SUCCESS(Status
))
1415 ERR("Failure to build window list!\n");
1416 SetLastNtError(Status
);
1423 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
1426 ObDereferenceObject(Thread
);
1429 *pBufSize
= dwCount
;
1430 return STATUS_SUCCESS
;
1433 static void IntSendParentNotify( PWND pWindow
, UINT msg
)
1435 if ( (pWindow
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
1436 !(pWindow
->ExStyle
& WS_EX_NOPARENTNOTIFY
))
1438 if (VerifyWnd(pWindow
->spwndParent
) && pWindow
->spwndParent
!= UserGetDesktopWindow())
1440 USER_REFERENCE_ENTRY Ref
;
1441 UserRefObjectCo(pWindow
->spwndParent
, &Ref
);
1442 co_IntSendMessage( pWindow
->spwndParent
->head
.h
,
1444 MAKEWPARAM( msg
, pWindow
->IDMenu
),
1445 (LPARAM
)pWindow
->head
.h
);
1446 UserDerefObjectCo(pWindow
->spwndParent
);
1452 IntFixWindowCoordinates(CREATESTRUCTW
* Cs
, PWND ParentWindow
, DWORD
* dwShowMode
)
1454 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1456 /* default positioning for overlapped windows */
1457 if(!(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
1460 PRTL_USER_PROCESS_PARAMETERS ProcessParams
;
1462 pMonitor
= UserGetPrimaryMonitor();
1464 /* Check if we don't have a monitor attached yet */
1465 if(pMonitor
== NULL
)
1473 ProcessParams
= PsGetCurrentProcess()->Peb
->ProcessParameters
;
1475 if (IS_DEFAULT(Cs
->x
))
1477 if (!IS_DEFAULT(Cs
->y
)) *dwShowMode
= Cs
->y
;
1479 if(ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1481 Cs
->x
= ProcessParams
->StartingX
;
1482 Cs
->y
= ProcessParams
->StartingY
;
1486 Cs
->x
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CXSIZE
) + UserGetSystemMetrics(SM_CXFRAME
));
1487 Cs
->y
= pMonitor
->cWndStack
* (UserGetSystemMetrics(SM_CYSIZE
) + UserGetSystemMetrics(SM_CYFRAME
));
1488 if (Cs
->x
> ((pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) / 4) ||
1489 Cs
->y
> ((pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) / 4))
1491 /* reset counter and position */
1494 pMonitor
->cWndStack
= 0;
1496 pMonitor
->cWndStack
++;
1500 if (IS_DEFAULT(Cs
->cx
))
1502 if (ProcessParams
->WindowFlags
& STARTF_USEPOSITION
)
1504 Cs
->cx
= ProcessParams
->CountX
;
1505 Cs
->cy
= ProcessParams
->CountY
;
1509 Cs
->cx
= (pMonitor
->rcWork
.right
- pMonitor
->rcWork
.left
) * 3 / 4;
1510 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1513 /* neither x nor cx are default. Check the y values .
1514 * In the trace we see Outlook and Outlook Express using
1515 * cy set to CW_USEDEFAULT when opening the address book.
1517 else if (IS_DEFAULT(Cs
->cy
))
1519 TRACE("Strange use of CW_USEDEFAULT in nHeight\n");
1520 Cs
->cy
= (pMonitor
->rcWork
.bottom
- pMonitor
->rcWork
.top
) * 3 / 4;
1525 /* if CW_USEDEFAULT is set for non-overlapped windows, both values are set to zero */
1526 if(IS_DEFAULT(Cs
->x
))
1531 if(IS_DEFAULT(Cs
->cx
))
1541 /* Allocates and initializes a window */
1542 PWND FASTCALL
IntCreateWindow(CREATESTRUCTW
* Cs
,
1543 PLARGE_STRING WindowName
,
1548 PDESKTOP pdeskCreated
)
1552 PTHREADINFO pti
= NULL
;
1554 BOOL bUnicodeWindow
;
1556 pti
= pdeskCreated
? gptiDesktopThread
: GetW32ThreadInfo();
1558 if (!(Cs
->dwExStyle
& WS_EX_LAYOUTRTL
))
1559 { // Need both here for wine win.c test_CreateWindow.
1560 //if (Cs->hwndParent && ParentWindow)
1561 if (ParentWindow
) // It breaks more tests..... WIP.
1563 if ( (Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
&&
1564 ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
&&
1565 !(ParentWindow
->ExStyle
& WS_EX_NOINHERITLAYOUT
) )
1566 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1570 * Note from MSDN <http://msdn.microsoft.com/en-us/library/aa913269.aspx>:
1572 * Dialog boxes and message boxes do not inherit layout, so you must
1573 * set the layout explicitly.
1575 if ( Class
->fnid
!= FNID_DIALOG
)
1577 if (pti
->ppi
->dwLayout
& LAYOUT_RTL
)
1579 Cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1585 /* Automatically add WS_EX_WINDOWEDGE */
1586 if ((Cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1587 ((!(Cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1588 (Cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1589 Cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1591 Cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1593 /* Is it a unicode window? */
1594 bUnicodeWindow
=!(Cs
->dwExStyle
& WS_EX_SETANSICREATOR
);
1595 Cs
->dwExStyle
&= ~WS_EX_SETANSICREATOR
;
1597 /* Allocate the new window */
1598 pWnd
= (PWND
) UserCreateObject( gHandleTable
,
1599 pdeskCreated
? pdeskCreated
: pti
->rpdesk
,
1603 sizeof(WND
) + Class
->cbwndExtra
);
1610 TRACE("Created window object with handle %p\n", hWnd
);
1612 if (pdeskCreated
&& pdeskCreated
->DesktopWindow
== NULL
)
1613 { /* HACK: Helper for win32csr/desktopbg.c */
1614 /* If there is no desktop window yet, we must be creating it */
1615 TRACE("CreateWindow setting desktop.\n");
1616 pdeskCreated
->DesktopWindow
= hWnd
;
1617 pdeskCreated
->pDeskInfo
->spwnd
= pWnd
;
1621 * Fill out the structure describing it.
1623 /* Remember, pWnd->head is setup in object.c ... */
1624 pWnd
->spwndParent
= ParentWindow
;
1625 pWnd
->spwndOwner
= OwnerWindow
;
1627 pWnd
->spwndLastActive
= pWnd
;
1628 pWnd
->state2
|= WNDS2_WIN40COMPAT
; // FIXME!!!
1630 pWnd
->hModule
= Cs
->hInstance
;
1631 pWnd
->style
= Cs
->style
& ~WS_VISIBLE
;
1632 pWnd
->ExStyle
= Cs
->dwExStyle
;
1633 pWnd
->cbwndExtra
= pWnd
->pcls
->cbwndExtra
;
1634 pWnd
->pActCtx
= acbiBuffer
;
1635 pWnd
->InternalPos
.MaxPos
.x
= pWnd
->InternalPos
.MaxPos
.y
= -1;
1636 pWnd
->InternalPos
.IconPos
.x
= pWnd
->InternalPos
.IconPos
.y
= -1;
1638 if (pWnd
->spwndParent
!= NULL
&& Cs
->hwndParent
!= 0)
1640 pWnd
->HideFocus
= pWnd
->spwndParent
->HideFocus
;
1641 pWnd
->HideAccel
= pWnd
->spwndParent
->HideAccel
;
1644 pWnd
->head
.pti
->cWindows
++;
1646 if (Class
->spicn
&& !Class
->spicnSm
)
1648 HICON IconSmHandle
= NULL
;
1649 if((Class
->spicn
->CURSORF_flags
& (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1650 == (CURSORF_LRSHARED
| CURSORF_FROMRESOURCE
))
1652 IconSmHandle
= co_IntCopyImage(
1653 UserHMGetHandle(Class
->spicn
),
1655 UserGetSystemMetrics( SM_CXSMICON
),
1656 UserGetSystemMetrics( SM_CYSMICON
),
1657 LR_COPYFROMRESOURCE
);
1661 /* Retry without copying from resource */
1662 IconSmHandle
= co_IntCopyImage(
1663 UserHMGetHandle(Class
->spicn
),
1665 UserGetSystemMetrics( SM_CXSMICON
),
1666 UserGetSystemMetrics( SM_CYSMICON
),
1672 Class
->spicnSm
= UserGetCurIconObject(IconSmHandle
);
1673 Class
->CSF_flags
|= CSF_CACHEDSMICON
;
1677 if (pWnd
->pcls
->CSF_flags
& CSF_SERVERSIDEPROC
)
1678 pWnd
->state
|= WNDS_SERVERSIDEWINDOWPROC
;
1680 /* BugBoy Comments: Comment below say that System classes are always created
1681 as UNICODE. In windows, creating a window with the ANSI version of CreateWindow
1682 sets the window to ansi as verified by testing with IsUnicodeWindow API.
1684 No where can I see in code or through testing does the window change back
1685 to ANSI after being created as UNICODE in ROS. I didnt do more testing to
1686 see what problems this would cause. */
1688 // Set WndProc from Class.
1689 pWnd
->lpfnWndProc
= pWnd
->pcls
->lpfnWndProc
;
1691 // GetWindowProc, test for non server side default classes and set WndProc.
1692 if ( pWnd
->pcls
->fnid
<= FNID_GHOST
&& pWnd
->pcls
->fnid
>= FNID_BUTTON
)
1696 if (GETPFNCLIENTA(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1697 pWnd
->lpfnWndProc
= GETPFNCLIENTW(pWnd
->pcls
->fnid
);
1701 if (GETPFNCLIENTW(pWnd
->pcls
->fnid
) == pWnd
->lpfnWndProc
)
1702 pWnd
->lpfnWndProc
= GETPFNCLIENTA(pWnd
->pcls
->fnid
);
1706 // If not an Unicode caller, set Ansi creator bit.
1707 if (!bUnicodeWindow
) pWnd
->state
|= WNDS_ANSICREATOR
;
1709 // Clone Class Ansi/Unicode proc type.
1710 if (pWnd
->pcls
->CSF_flags
& CSF_ANSIPROC
)
1712 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1713 pWnd
->Unicode
= FALSE
;
1717 * It seems there can be both an Ansi creator and Unicode Class Window
1718 * WndProc, unless the following overriding conditions occur:
1720 if ( !bUnicodeWindow
&&
1721 ( Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_BUTTON
] ||
1722 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOBOX
] ||
1723 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_COMBOLBOX
] ||
1724 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_DIALOG
] ||
1725 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
] ||
1726 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_IME
] ||
1727 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_LISTBOX
] ||
1728 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_MDICLIENT
] ||
1729 Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_STATIC
] ) )
1730 { // Override Class and set the window Ansi WndProc.
1731 pWnd
->state
|= WNDS_ANSIWINDOWPROC
;
1732 pWnd
->Unicode
= FALSE
;
1735 { // Set the window Unicode WndProc.
1736 pWnd
->state
&= ~WNDS_ANSIWINDOWPROC
;
1737 pWnd
->Unicode
= TRUE
;
1741 /* BugBoy Comments: if the window being created is a edit control, ATOM 0xCxxx,
1742 then my testing shows that windows (2k and XP) creates a CallProc for it immediately
1743 Dont understand why it does this. */
1744 if (Class
->atomClassName
== gpsi
->atomSysClass
[ICLS_EDIT
])
1746 PCALLPROCDATA CallProc
;
1747 CallProc
= CreateCallProc(pWnd
->head
.rpdesk
, pWnd
->lpfnWndProc
, pWnd
->Unicode
, pWnd
->head
.pti
->ppi
);
1751 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
1752 ERR("Warning: Unable to create CallProc for edit control. Control may not operate correctly! hwnd %p\n", hWnd
);
1756 UserAddCallProcToClass(pWnd
->pcls
, CallProc
);
1760 InitializeListHead(&pWnd
->PropListHead
);
1761 pWnd
->PropListItems
= 0;
1763 if ( WindowName
->Buffer
!= NULL
&& WindowName
->Length
> 0 )
1765 pWnd
->strName
.Buffer
= DesktopHeapAlloc(pWnd
->head
.rpdesk
,
1766 WindowName
->Length
+ sizeof(UNICODE_NULL
));
1767 if (pWnd
->strName
.Buffer
== NULL
)
1772 RtlCopyMemory(pWnd
->strName
.Buffer
, WindowName
->Buffer
, WindowName
->Length
);
1773 pWnd
->strName
.Buffer
[WindowName
->Length
/ sizeof(WCHAR
)] = L
'\0';
1774 pWnd
->strName
.Length
= WindowName
->Length
;
1775 pWnd
->strName
.MaximumLength
= WindowName
->Length
+ sizeof(UNICODE_NULL
);
1778 /* Correct the window style. */
1779 if ((pWnd
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1781 pWnd
->style
|= WS_CLIPSIBLINGS
;
1782 if (!(pWnd
->style
& WS_POPUP
))
1784 pWnd
->style
|= WS_CAPTION
;
1788 /* WS_EX_WINDOWEDGE depends on some other styles */
1789 if (pWnd
->ExStyle
& WS_EX_DLGMODALFRAME
)
1790 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1791 else if (pWnd
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))
1793 if (!((pWnd
->ExStyle
& WS_EX_STATICEDGE
) &&
1794 (pWnd
->style
& (WS_CHILD
| WS_POPUP
))))
1795 pWnd
->ExStyle
|= WS_EX_WINDOWEDGE
;
1798 pWnd
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
1800 if (!(pWnd
->style
& (WS_CHILD
| WS_POPUP
)))
1801 pWnd
->state
|= WNDS_SENDSIZEMOVEMSGS
;
1803 /* Set the window menu */
1804 if ((Cs
->style
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1808 IntSetMenu(pWnd
, Cs
->hMenu
, &MenuChanged
);
1810 else if (pWnd
->pcls
->lpszMenuName
) // Take it from the parent.
1812 UNICODE_STRING MenuName
;
1815 if (IS_INTRESOURCE(pWnd
->pcls
->lpszMenuName
))
1817 MenuName
.Length
= 0;
1818 MenuName
.MaximumLength
= 0;
1819 MenuName
.Buffer
= pWnd
->pcls
->lpszMenuName
;
1823 RtlInitUnicodeString( &MenuName
, pWnd
->pcls
->lpszMenuName
);
1825 hMenu
= co_IntCallLoadMenu( pWnd
->pcls
->hModule
, &MenuName
);
1826 if (hMenu
) IntSetMenu(pWnd
, hMenu
, &MenuChanged
);
1830 pWnd
->IDMenu
= (UINT
) Cs
->hMenu
;
1833 if ( ParentWindow
&&
1834 ParentWindow
!= ParentWindow
->head
.rpdesk
->spwndMessage
&&
1835 ParentWindow
!= ParentWindow
->head
.rpdesk
->pDeskInfo
->spwnd
)
1837 PWND Owner
= IntGetNonChildAncestor(ParentWindow
);
1839 if (!IntValidateOwnerDepth(pWnd
, Owner
))
1841 EngSetLastError(ERROR_INVALID_PARAMETER
);
1844 if ( pWnd
->spwndOwner
&&
1845 pWnd
->spwndOwner
->ExStyle
& WS_EX_TOPMOST
)
1847 pWnd
->ExStyle
|= WS_EX_TOPMOST
;
1849 if ( pWnd
->spwndOwner
&&
1850 Class
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
] &&
1851 pti
!= pWnd
->spwndOwner
->head
.pti
)
1853 //ERR("CreateWindow Owner in.\n");
1854 UserAttachThreadInput(pti
, pWnd
->spwndOwner
->head
.pti
, TRUE
);
1858 /* Insert the window into the thread's window list. */
1859 InsertTailList (&pti
->WindowListHead
, &pWnd
->ThreadListEntry
);
1861 /* Handle "CS_CLASSDC", it is tested first. */
1862 if ( (pWnd
->pcls
->style
& CS_CLASSDC
) && !(pWnd
->pcls
->pdce
) )
1863 { /* One DCE per class to have CLASS. */
1864 pWnd
->pcls
->pdce
= DceAllocDCE( pWnd
, DCE_CLASS_DC
);
1866 else if ( pWnd
->pcls
->style
& CS_OWNDC
)
1867 { /* Allocate a DCE for this window. */
1868 DceAllocDCE(pWnd
, DCE_WINDOW_DC
);
1874 ERR("IntCreateWindow Allocation Error.\n");
1875 SetLastNtError(STATUS_INSUFFICIENT_RESOURCES
);
1878 UserDereferenceObject(pWnd
);
1886 co_UserCreateWindowEx(CREATESTRUCTW
* Cs
,
1887 PUNICODE_STRING ClassName
,
1888 PLARGE_STRING WindowName
,
1892 PWND Window
= NULL
, ParentWindow
= NULL
, OwnerWindow
;
1893 HWND hWnd
, hWndParent
, hWndOwner
, hwndInsertAfter
;
1894 PWINSTATION_OBJECT WinSta
;
1897 POINT MaxSize
, MaxPos
, MinTrack
, MaxTrack
;
1898 CBT_CREATEWNDW
* pCbtCreate
;
1900 USER_REFERENCE_ENTRY ParentRef
, Ref
;
1902 DWORD dwShowMode
= SW_SHOW
;
1903 CREATESTRUCTW
*pCsw
= NULL
;
1904 PVOID pszClass
= NULL
, pszName
= NULL
;
1907 /* Get the current window station and reference it */
1908 pti
= GetW32ThreadInfo();
1909 if (pti
== NULL
|| pti
->rpdesk
== NULL
)
1911 ERR("Thread is not attached to a desktop! Cannot create window!\n");
1912 return NULL
; // There is nothing to cleanup.
1914 WinSta
= pti
->rpdesk
->rpwinstaParent
;
1915 ObReferenceObjectByPointer(WinSta
, KernelMode
, ExWindowStationObjectType
, 0);
1920 /* Get the class and reference it */
1921 Class
= IntGetAndReferenceClass(ClassName
, Cs
->hInstance
, FALSE
);
1924 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
1925 ERR("Failed to find class %wZ\n", ClassName
);
1929 /* Now find the parent and the owner window */
1930 hWndParent
= pti
->rpdesk
->pDeskInfo
->spwnd
->head
.h
;
1933 if (Cs
->hwndParent
== HWND_MESSAGE
)
1935 Cs
->hwndParent
= hWndParent
= pti
->rpdesk
->spwndMessage
->head
.h
;
1937 else if (Cs
->hwndParent
)
1939 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1940 hWndOwner
= Cs
->hwndParent
;
1942 hWndParent
= Cs
->hwndParent
;
1944 else if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1946 ERR("Cannot create a child window without a parrent!\n");
1947 EngSetLastError(ERROR_TLW_WITH_WSCHILD
);
1948 goto cleanup
; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1951 ParentWindow
= hWndParent
? UserGetWindowObject(hWndParent
): NULL
;
1952 OwnerWindow
= hWndOwner
? UserGetWindowObject(hWndOwner
): NULL
;
1954 if (hWndParent
&& !ParentWindow
)
1956 ERR("Got invalid parent window handle\n");
1962 if (IntIsDesktopWindow(OwnerWindow
)) OwnerWindow
= NULL
;
1963 else if (ParentWindow
&& !IntIsDesktopWindow(ParentWindow
))
1965 ERR("an owned window must be created as top-level\n");
1966 EngSetLastError( STATUS_ACCESS_DENIED
);
1969 else /* owner must be a top-level window */
1971 while ((OwnerWindow
->style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
&& !IntIsDesktopWindow(OwnerWindow
->spwndParent
))
1972 OwnerWindow
= OwnerWindow
->spwndParent
;
1976 /* Fix the position and the size of the window */
1979 UserRefObjectCo(ParentWindow
, &ParentRef
);
1980 IntFixWindowCoordinates(Cs
, ParentWindow
, &dwShowMode
);
1983 /* Allocate and initialize the new window */
1984 Window
= IntCreateWindow(Cs
,
1993 ERR("IntCreateWindow failed!\n");
1997 hWnd
= UserHMGetHandle(Window
);
1998 hwndInsertAfter
= HWND_TOP
;
2000 UserRefObjectCo(Window
, &Ref
);
2001 UserDereferenceObject(Window
);
2002 ObDereferenceObject(WinSta
);
2004 //// Check for a hook to eliminate overhead. ////
2005 if ( ISITHOOKED(WH_CBT
) || (pti
->rpdesk
->pDeskInfo
->fsHooks
& HOOKID_TO_FLAG(WH_CBT
)) )
2007 // Allocate the calling structures Justin Case this goes Global.
2008 pCsw
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CREATESTRUCTW
), TAG_HOOK
);
2009 pCbtCreate
= ExAllocatePoolWithTag(NonPagedPool
, sizeof(CBT_CREATEWNDW
), TAG_HOOK
);
2010 if (!pCsw
|| !pCbtCreate
)
2012 ERR("UserHeapAlloc() failed!\n");
2016 /* Fill the new CREATESTRUCTW */
2017 RtlCopyMemory(pCsw
, Cs
, sizeof(CREATESTRUCTW
));
2018 pCsw
->style
= Window
->style
; /* HCBT_CREATEWND needs the real window style */
2020 // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
2021 if (!IS_ATOM(ClassName
->Buffer
))
2023 if (Window
->state
& WNDS_ANSICREATOR
)
2025 ANSI_STRING AnsiString
;
2026 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(ClassName
)+sizeof(CHAR
);
2027 pszClass
= UserHeapAlloc(AnsiString
.MaximumLength
);
2030 ERR("UserHeapAlloc() failed!\n");
2033 RtlZeroMemory(pszClass
, AnsiString
.MaximumLength
);
2034 AnsiString
.Buffer
= (PCHAR
)pszClass
;
2035 RtlUnicodeStringToAnsiString(&AnsiString
, ClassName
, FALSE
);
2039 UNICODE_STRING UnicodeString
;
2040 UnicodeString
.MaximumLength
= ClassName
->Length
+ sizeof(UNICODE_NULL
);
2041 pszClass
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2044 ERR("UserHeapAlloc() failed!\n");
2047 RtlZeroMemory(pszClass
, UnicodeString
.MaximumLength
);
2048 UnicodeString
.Buffer
= (PWSTR
)pszClass
;
2049 RtlCopyUnicodeString(&UnicodeString
, ClassName
);
2051 pCsw
->lpszClass
= UserHeapAddressToUser(pszClass
);
2053 if (WindowName
->Length
)
2055 UNICODE_STRING Name
;
2056 Name
.Buffer
= WindowName
->Buffer
;
2057 Name
.Length
= (USHORT
)min(WindowName
->Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2058 Name
.MaximumLength
= (USHORT
)min(WindowName
->MaximumLength
, MAXUSHORT
);
2060 if (Window
->state
& WNDS_ANSICREATOR
)
2062 ANSI_STRING AnsiString
;
2063 AnsiString
.MaximumLength
= (USHORT
)RtlUnicodeStringToAnsiSize(&Name
) + sizeof(CHAR
);
2064 pszName
= UserHeapAlloc(AnsiString
.MaximumLength
);
2067 ERR("UserHeapAlloc() failed!\n");
2070 RtlZeroMemory(pszName
, AnsiString
.MaximumLength
);
2071 AnsiString
.Buffer
= (PCHAR
)pszName
;
2072 RtlUnicodeStringToAnsiString(&AnsiString
, &Name
, FALSE
);
2076 UNICODE_STRING UnicodeString
;
2077 UnicodeString
.MaximumLength
= Name
.Length
+ sizeof(UNICODE_NULL
);
2078 pszName
= UserHeapAlloc(UnicodeString
.MaximumLength
);
2081 ERR("UserHeapAlloc() failed!\n");
2084 RtlZeroMemory(pszName
, UnicodeString
.MaximumLength
);
2085 UnicodeString
.Buffer
= (PWSTR
)pszName
;
2086 RtlCopyUnicodeString(&UnicodeString
, &Name
);
2088 pCsw
->lpszName
= UserHeapAddressToUser(pszName
);
2091 pCbtCreate
->lpcs
= pCsw
;
2092 pCbtCreate
->hwndInsertAfter
= hwndInsertAfter
;
2094 //// Call the WH_CBT hook ////
2095 Result
= co_HOOK_CallHooks(WH_CBT
, HCBT_CREATEWND
, (WPARAM
) hWnd
, (LPARAM
) pCbtCreate
);
2098 ERR("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result
);
2101 // Write back changes.
2106 hwndInsertAfter
= pCbtCreate
->hwndInsertAfter
;
2109 /* NCCREATE and WM_NCCALCSIZE need the original values */
2110 Cs
->lpszName
= (LPCWSTR
) WindowName
;
2111 Cs
->lpszClass
= (LPCWSTR
) ClassName
;
2113 if ((Cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
2115 if (ParentWindow
!= co_GetDesktopWindow(Window
))
2117 Cs
->x
+= ParentWindow
->rcClient
.left
;
2118 Cs
->y
+= ParentWindow
->rcClient
.top
;
2122 /* Send the WM_GETMINMAXINFO message */
2126 if ((Cs
->style
& WS_THICKFRAME
) || !(Cs
->style
& (WS_POPUP
| WS_CHILD
)))
2128 co_WinPosGetMinMaxInfo(Window
, &MaxSize
, &MaxPos
, &MinTrack
, &MaxTrack
);
2129 if (Size
.cx
> MaxTrack
.x
) Size
.cx
= MaxTrack
.x
;
2130 if (Size
.cy
> MaxTrack
.y
) Size
.cy
= MaxTrack
.y
;
2131 if (Size
.cx
< MinTrack
.x
) Size
.cx
= MinTrack
.x
;
2132 if (Size
.cy
< MinTrack
.y
) Size
.cy
= MinTrack
.y
;
2135 Window
->rcWindow
.left
= Cs
->x
;
2136 Window
->rcWindow
.top
= Cs
->y
;
2137 Window
->rcWindow
.right
= Cs
->x
+ Size
.cx
;
2138 Window
->rcWindow
.bottom
= Cs
->y
+ Size
.cy
;
2140 if (0 != (Window->style & WS_CHILD) && ParentWindow)
2142 ERR("co_UserCreateWindowEx(): Offset rcWindow\n");
2143 RECTL_vOffsetRect(&Window->rcWindow,
2144 ParentWindow->rcClient.left,
2145 ParentWindow->rcClient.top);
2148 /* correct child window coordinates if mirroring on parent is enabled */
2149 if (ParentWindow
!= NULL
)
2151 if ( ((Cs
->style
& WS_CHILD
) == WS_CHILD
) &&
2152 ((ParentWindow
->ExStyle
& WS_EX_LAYOUTRTL
) == WS_EX_LAYOUTRTL
))
2154 Window
->rcWindow
.right
= ParentWindow
->rcClient
.right
- (Window
->rcWindow
.left
- ParentWindow
->rcClient
.left
);
2155 Window
->rcWindow
.left
= Window
->rcWindow
.right
- Size
.cx
;
2159 Window
->rcClient
= Window
->rcWindow
;
2161 /* Link the window */
2162 if (NULL
!= ParentWindow
)
2164 /* Link the window into the siblings list */
2165 if ((Cs
->style
& (WS_CHILD
|WS_MAXIMIZE
)) == WS_CHILD
)
2166 IntLinkHwnd(Window
, HWND_BOTTOM
);
2168 IntLinkHwnd(Window
, hwndInsertAfter
);
2171 if (!(Window
->state2
& WNDS2_WIN31COMPAT
))
2173 if (Class
->style
& CS_PARENTDC
&& !(ParentWindow
->style
& WS_CLIPCHILDREN
))
2174 Window
->style
&= ~(WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
);
2177 if ((Window
->style
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2179 if ( !IntIsTopLevelWindow(Window
) )
2181 if (pti
!= Window
->spwndParent
->head
.pti
)
2183 //ERR("CreateWindow Parent in.\n");
2184 UserAttachThreadInput(pti
, Window
->spwndParent
->head
.pti
, TRUE
);
2189 /* Send the NCCREATE message */
2190 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_NCCREATE
, 0, (LPARAM
) Cs
);
2193 ERR("co_UserCreateWindowEx(): NCCREATE message failed\n");
2197 /* Send the WM_NCCALCSIZE message */
2200 MaxPos
.x
= Window
->rcWindow
.left
;
2201 MaxPos
.y
= Window
->rcWindow
.top
;
2203 Result
= co_WinPosGetNonClientSize(Window
, &Window
->rcWindow
, &Window
->rcClient
);
2204 //rc = Window->rcWindow;
2205 //Result = co_IntSendMessageNoWait(Window->head.h, WM_NCCALCSIZE, FALSE, (LPARAM)&rc);
2206 //Window->rcClient = rc;
2208 RECTL_vOffsetRect(&Window
->rcWindow
, MaxPos
.x
- Window
->rcWindow
.left
,
2209 MaxPos
.y
- Window
->rcWindow
.top
);
2212 /* Send the WM_CREATE message. */
2213 Result
= co_IntSendMessage(UserHMGetHandle(Window
), WM_CREATE
, 0, (LPARAM
) Cs
);
2214 if (Result
== (LRESULT
)-1)
2216 ERR("co_UserCreateWindowEx(): WM_CREATE message failed\n");
2220 /* Send the EVENT_OBJECT_CREATE event */
2221 IntNotifyWinEvent(EVENT_OBJECT_CREATE
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2223 /* By setting the flag below it can be examined to determine if the window
2224 was created successfully and a valid pwnd was passed back to caller since
2225 from here the function has to succeed. */
2226 Window
->state2
|= WNDS2_WMCREATEMSGPROCESSED
;
2228 /* Send the WM_SIZE and WM_MOVE messages. */
2229 if (!(Window
->state
& WNDS_SENDSIZEMOVEMSGS
))
2231 co_WinPosSendSizeMove(Window
);
2234 /* Show or maybe minimize or maximize the window. */
2236 style
= IntSetStyle( Window
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
2237 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
2240 UINT SwFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
2242 SwFlag
= co_WinPosMinMaximize(Window
, SwFlag
, &NewPos
);
2243 SwFlag
|= SWP_NOZORDER
|SWP_FRAMECHANGED
; /* Frame always gets changed */
2244 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || UserGetActiveWindow()) SwFlag
|= SWP_NOACTIVATE
;
2245 co_WinPosSetWindowPos(Window
, 0, NewPos
.left
, NewPos
.top
,
2246 NewPos
.right
, NewPos
.bottom
, SwFlag
);
2249 /* Send the WM_PARENTNOTIFY message */
2250 IntSendParentNotify(Window
, WM_CREATE
);
2252 /* Notify the shell that a new window was created */
2253 if (Window
->spwndParent
== UserGetDesktopWindow() &&
2254 Window
->spwndOwner
== NULL
&&
2255 (Window
->style
& WS_VISIBLE
) &&
2256 (!(Window
->ExStyle
& WS_EX_TOOLWINDOW
) ||
2257 (Window
->ExStyle
& WS_EX_APPWINDOW
)))
2259 co_IntShellHookNotify(HSHELL_WINDOWCREATED
, (WPARAM
)hWnd
, 0);
2262 /* Initialize and show the window's scrollbars */
2263 if (Window
->style
& WS_VSCROLL
)
2265 co_UserShowScrollBar(Window
, SB_VERT
, FALSE
, TRUE
);
2267 if (Window
->style
& WS_HSCROLL
)
2269 co_UserShowScrollBar(Window
, SB_HORZ
, TRUE
, FALSE
);
2272 /* Show the new window */
2273 if (Cs
->style
& WS_VISIBLE
)
2275 if (Window
->style
& WS_MAXIMIZE
)
2276 dwShowMode
= SW_SHOW
;
2277 else if (Window
->style
& WS_MINIMIZE
)
2278 dwShowMode
= SW_SHOWMINIMIZED
;
2280 co_WinPosShowWindow(Window
, dwShowMode
);
2282 if (Window
->ExStyle
& WS_EX_MDICHILD
)
2284 ASSERT(ParentWindow
);
2287 co_IntSendMessage(UserHMGetHandle(ParentWindow
), WM_MDIREFRESHMENU
, 0, 0);
2288 /* ShowWindow won't activate child windows */
2289 co_WinPosSetWindowPos(Window
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
2293 if (Class
->atomClassName
== gaGuiConsoleWndClass
)
2295 /* Count only console windows manually */
2296 co_IntUserManualGuiCheck(TRUE
);
2299 TRACE("co_UserCreateWindowEx(): Created window %p\n", hWnd
);
2305 TRACE("co_UserCreateWindowEx(): Error Created window!\n");
2306 /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
2308 co_UserDestroyWindow(Window
);
2310 IntDereferenceClass(Class
, pti
->pDeskInfo
, pti
->ppi
);
2313 if (pCsw
) ExFreePoolWithTag(pCsw
, TAG_HOOK
);
2314 if (pCbtCreate
) ExFreePoolWithTag(pCbtCreate
, TAG_HOOK
);
2315 if (pszName
) UserHeapFree(pszName
);
2316 if (pszClass
) UserHeapFree(pszClass
);
2320 UserDerefObjectCo(Window
);
2322 if (ParentWindow
) UserDerefObjectCo(ParentWindow
);
2329 ProbeAndCaptureLargeString(
2330 OUT PLARGE_STRING plstrSafe
,
2331 IN PLARGE_STRING plstrUnsafe
)
2333 LARGE_STRING lstrTemp
;
2334 PVOID pvBuffer
= NULL
;
2338 /* Probe and copy the string */
2339 ProbeForRead(plstrUnsafe
, sizeof(LARGE_STRING
), sizeof(ULONG
));
2340 lstrTemp
= *plstrUnsafe
;
2342 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2345 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2349 if (lstrTemp
.Length
!= 0)
2351 /* Allocate a buffer from paged pool */
2352 pvBuffer
= ExAllocatePoolWithTag(PagedPool
, lstrTemp
.Length
, TAG_STRING
);
2355 return STATUS_NO_MEMORY
;
2360 /* Probe and copy the buffer */
2361 ProbeForRead(lstrTemp
.Buffer
, lstrTemp
.Length
, sizeof(WCHAR
));
2362 RtlCopyMemory(pvBuffer
, lstrTemp
.Buffer
, lstrTemp
.Length
);
2364 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2366 /* Cleanup and fail */
2367 ExFreePoolWithTag(pvBuffer
, TAG_STRING
);
2368 _SEH2_YIELD(return _SEH2_GetExceptionCode();)
2373 /* Set the output string */
2374 plstrSafe
->Buffer
= pvBuffer
;
2375 plstrSafe
->Length
= lstrTemp
.Length
;
2376 plstrSafe
->MaximumLength
= lstrTemp
.Length
;
2378 return STATUS_SUCCESS
;
2382 * \todo Allow passing plstrClassName as ANSI.
2386 NtUserCreateWindowEx(
2388 PLARGE_STRING plstrClassName
,
2389 PLARGE_STRING plstrClsVersion
,
2390 PLARGE_STRING plstrWindowName
,
2398 HINSTANCE hInstance
,
2404 LARGE_STRING lstrWindowName
;
2405 LARGE_STRING lstrClassName
;
2406 LARGE_STRING lstrClsVersion
;
2407 UNICODE_STRING ustrClassName
;
2408 UNICODE_STRING ustrClsVersion
;
2413 lstrWindowName
.Buffer
= NULL
;
2414 lstrClassName
.Buffer
= NULL
;
2415 lstrClsVersion
.Buffer
= NULL
;
2417 ASSERT(plstrWindowName
);
2419 if ( (dwStyle
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2421 /* check hMenu is valid handle */
2422 if (hMenu
&& !UserGetMenuObject(hMenu
))
2424 ERR("NtUserCreateWindowEx: Got an invalid menu handle!\n");
2425 EngSetLastError(ERROR_INVALID_MENU_HANDLE
);
2430 /* Copy the window name to kernel mode */
2431 Status
= ProbeAndCaptureLargeString(&lstrWindowName
, plstrWindowName
);
2432 if (!NT_SUCCESS(Status
))
2434 ERR("NtUserCreateWindowEx: failed to capture plstrWindowName\n");
2435 SetLastNtError(Status
);
2439 plstrWindowName
= &lstrWindowName
;
2441 /* Check if the class is an atom */
2442 if (IS_ATOM(plstrClassName
))
2444 /* It is, pass the atom in the UNICODE_STRING */
2445 ustrClassName
.Buffer
= (PVOID
)plstrClassName
;
2446 ustrClassName
.Length
= 0;
2447 ustrClassName
.MaximumLength
= 0;
2451 /* It's not, capture the class name */
2452 Status
= ProbeAndCaptureLargeString(&lstrClassName
, plstrClassName
);
2453 if (!NT_SUCCESS(Status
))
2455 ERR("NtUserCreateWindowEx: failed to capture plstrClassName\n");
2456 /* Set last error, cleanup and return */
2457 SetLastNtError(Status
);
2461 /* We pass it on as a UNICODE_STRING */
2462 ustrClassName
.Buffer
= lstrClassName
.Buffer
;
2463 ustrClassName
.Length
= (USHORT
)min(lstrClassName
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2464 ustrClassName
.MaximumLength
= (USHORT
)min(lstrClassName
.MaximumLength
, MAXUSHORT
);
2467 /* Check if the class version is an atom */
2468 if (IS_ATOM(plstrClsVersion
))
2470 /* It is, pass the atom in the UNICODE_STRING */
2471 ustrClsVersion
.Buffer
= (PVOID
)plstrClsVersion
;
2472 ustrClsVersion
.Length
= 0;
2473 ustrClsVersion
.MaximumLength
= 0;
2477 /* It's not, capture the class name */
2478 Status
= ProbeAndCaptureLargeString(&lstrClsVersion
, plstrClsVersion
);
2479 if (!NT_SUCCESS(Status
))
2481 ERR("NtUserCreateWindowEx: failed to capture plstrClsVersion\n");
2482 /* Set last error, cleanup and return */
2483 SetLastNtError(Status
);
2487 /* We pass it on as a UNICODE_STRING */
2488 ustrClsVersion
.Buffer
= lstrClsVersion
.Buffer
;
2489 ustrClsVersion
.Length
= (USHORT
)min(lstrClsVersion
.Length
, MAXUSHORT
); // FIXME: LARGE_STRING truncated
2490 ustrClsVersion
.MaximumLength
= (USHORT
)min(lstrClsVersion
.MaximumLength
, MAXUSHORT
);
2493 /* Fill the CREATESTRUCTW */
2494 /* we will keep here the original parameters */
2496 Cs
.lpCreateParams
= lpParam
;
2497 Cs
.hInstance
= hInstance
;
2499 Cs
.hwndParent
= hWndParent
;
2504 Cs
.lpszName
= (LPCWSTR
) plstrWindowName
->Buffer
;
2505 Cs
.lpszClass
= ustrClassName
.Buffer
;
2506 Cs
.dwExStyle
= dwExStyle
;
2508 UserEnterExclusive();
2510 /* Call the internal function */
2511 pwnd
= co_UserCreateWindowEx(&Cs
, &ustrClsVersion
, plstrWindowName
, acbiBuffer
);
2515 ERR("co_UserCreateWindowEx failed!\n");
2517 hwnd
= pwnd
? UserHMGetHandle(pwnd
) : NULL
;
2522 if (lstrWindowName
.Buffer
)
2524 ExFreePoolWithTag(lstrWindowName
.Buffer
, TAG_STRING
);
2526 if (lstrClassName
.Buffer
)
2528 ExFreePoolWithTag(lstrClassName
.Buffer
, TAG_STRING
);
2530 if (lstrClsVersion
.Buffer
)
2532 ExFreePoolWithTag(lstrClsVersion
.Buffer
, TAG_STRING
);
2539 BOOLEAN
co_UserDestroyWindow(PVOID Object
)
2545 PWND Window
= Object
;
2547 ASSERT_REFS_CO(Window
); // FIXME: Temp HACK?
2549 hWnd
= Window
->head
.h
;
2550 ti
= PsGetCurrentThreadWin32Thread();
2552 TRACE("co_UserDestroyWindow \n");
2554 /* Check for owner thread */
2555 if ( Window
->head
.pti
!= PsGetCurrentThreadWin32Thread())
2557 /* Check if we are destroying the desktop window */
2558 if (! ((Window
->head
.rpdesk
->dwDTFlags
& DF_DESTROYED
) && Window
== Window
->head
.rpdesk
->pDeskInfo
->spwnd
))
2560 EngSetLastError(ERROR_ACCESS_DENIED
);
2565 /* If window was created successfully and it is hooked */
2566 if ((Window
->state2
& WNDS2_WMCREATEMSGPROCESSED
))
2568 if (co_HOOK_CallHooks(WH_CBT
, HCBT_DESTROYWND
, (WPARAM
) hWnd
, 0))
2570 ERR("Destroy Window WH_CBT Call Hook return!\n");
2575 if (Window
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_IME
])
2577 if ((Window
->style
& (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2579 if (Window
->spwndOwner
)
2581 //ERR("DestroyWindow Owner out.\n");
2582 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndOwner
->head
.pti
, FALSE
);
2587 /* Inform the parent */
2588 if (Window
->style
& WS_CHILD
)
2590 IntSendParentNotify(Window
, WM_DESTROY
);
2593 if (!Window
->spwndOwner
&& !IntGetParent(Window
))
2595 co_IntShellHookNotify(HSHELL_WINDOWDESTROYED
, (WPARAM
) hWnd
, 0);
2598 /* Hide the window */
2599 if (Window
->style
& WS_VISIBLE
)
2601 if (Window
->style
& WS_CHILD
)
2603 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
2604 co_WinPosShowWindow(Window
, SW_HIDE
);
2608 co_WinPosSetWindowPos(Window
, 0, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_HIDEWINDOW
);
2612 // Adjust last active.
2613 if ((pwndTemp
= Window
->spwndOwner
))
2615 while (pwndTemp
->spwndOwner
)
2616 pwndTemp
= pwndTemp
->spwndOwner
;
2618 if (pwndTemp
->spwndLastActive
== Window
)
2619 pwndTemp
->spwndLastActive
= Window
->spwndOwner
;
2622 if (Window
->spwndParent
&& IntIsWindow(UserHMGetHandle(Window
)))
2624 if ((Window
->style
& (WS_POPUP
| WS_CHILD
)) == WS_CHILD
)
2626 if (!IntIsTopLevelWindow(Window
))
2628 //ERR("DestroyWindow Parent out.\n");
2629 UserAttachThreadInput(Window
->head
.pti
, Window
->spwndParent
->head
.pti
, FALSE
);
2634 if (Window
->head
.pti
->MessageQueue
->spwndActive
== Window
)
2635 Window
->head
.pti
->MessageQueue
->spwndActive
= NULL
;
2636 if (Window
->head
.pti
->MessageQueue
->spwndFocus
== Window
)
2637 Window
->head
.pti
->MessageQueue
->spwndFocus
= NULL
;
2638 if (Window
->head
.pti
->MessageQueue
->spwndActivePrev
== Window
)
2639 Window
->head
.pti
->MessageQueue
->spwndActivePrev
= NULL
;
2640 if (Window
->head
.pti
->MessageQueue
->spwndCapture
== Window
)
2641 Window
->head
.pti
->MessageQueue
->spwndCapture
= NULL
;
2644 * Check if this window is the Shell's Desktop Window. If so set hShellWindow to NULL
2647 if ((ti
!= NULL
) && (ti
->pDeskInfo
!= NULL
))
2649 if (ti
->pDeskInfo
->hShellWindow
== hWnd
)
2651 ERR("Destroying the ShellWindow!\n");
2652 ti
->pDeskInfo
->hShellWindow
= NULL
;
2656 IntEngWindowChanged(Window
, WOC_DELETE
);
2658 if (!IntIsWindow(UserHMGetHandle(Window
)))
2663 /* Recursively destroy owned windows */
2665 if (! (Window
->style
& WS_CHILD
))
2669 BOOL GotOne
= FALSE
;
2672 PWND Child
, Desktop
;
2674 Desktop
= IntIsDesktopWindow(Window
) ? Window
:
2675 UserGetWindowObject(IntGetDesktopWindow());
2676 Children
= IntWinListChildren(Desktop
);
2680 for (ChildHandle
= Children
; *ChildHandle
; ++ChildHandle
)
2682 Child
= UserGetWindowObject(*ChildHandle
);
2685 if (Child
->spwndOwner
!= Window
)
2690 if (IntWndBelongsToThread(Child
, PsGetCurrentThreadWin32Thread()))
2692 USER_REFERENCE_ENTRY ChildRef
;
2693 UserRefObjectCo(Child
, &ChildRef
); // Temp HACK?
2694 co_UserDestroyWindow(Child
);
2695 UserDerefObjectCo(Child
); // Temp HACK?
2701 if (Child
->spwndOwner
!= NULL
)
2703 Child
->spwndOwner
= NULL
;
2707 ExFreePoolWithTag(Children
, USERTAG_WINDOWLIST
);
2716 /* Generate mouse move message for the next window */
2717 msg
.message
= WM_MOUSEMOVE
;
2718 msg
.wParam
= UserGetMouseButtonsState();
2719 msg
.lParam
= MAKELPARAM(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
2720 msg
.pt
= gpsi
->ptCursor
;
2721 co_MsqInsertMouseMessage(&msg
, 0, 0, TRUE
);
2723 IntNotifyWinEvent(EVENT_OBJECT_DESTROY
, Window
, OBJID_WINDOW
, CHILDID_SELF
, 0);
2725 /* Send destroy messages */
2726 IntSendDestroyMsg(UserHMGetHandle(Window
));
2728 if (!IntIsWindow(UserHMGetHandle(Window
)))
2733 /* Destroy the window storage */
2734 co_UserFreeWindow(Window
, PsGetCurrentProcessWin32Process(), PsGetCurrentThreadWin32Thread(), TRUE
);
2744 NtUserDestroyWindow(HWND Wnd
)
2747 DECLARE_RETURN(BOOLEAN
);
2749 USER_REFERENCE_ENTRY Ref
;
2751 TRACE("Enter NtUserDestroyWindow\n");
2752 UserEnterExclusive();
2754 if (!(Window
= UserGetWindowObject(Wnd
)))
2759 UserRefObjectCo(Window
, &Ref
); // FIXME: Dunno if win should be reffed during destroy...
2760 ret
= co_UserDestroyWindow(Window
);
2761 UserDerefObjectCo(Window
); // FIXME: Dunno if win should be reffed during destroy...
2766 TRACE("Leave NtUserDestroyWindow, ret=%u\n", _ret_
);
2772 static HWND FASTCALL
2773 IntFindWindow(PWND Parent
,
2776 PUNICODE_STRING WindowName
)
2778 BOOL CheckWindowName
;
2781 UNICODE_STRING CurrentWindowName
;
2785 CheckWindowName
= WindowName
->Buffer
!= 0;
2787 if((List
= IntWinListChildren(Parent
)))
2792 /* skip handles before and including ChildAfter */
2793 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2797 /* search children */
2801 if(!(Child
= UserGetWindowObject(*(phWnd
++))))
2806 /* Do not send WM_GETTEXT messages in the kernel mode version!
2807 The user mode version however calls GetWindowText() which will
2808 send WM_GETTEXT messages to windows belonging to its processes */
2809 if (!ClassAtom
|| Child
->pcls
->atomClassName
== ClassAtom
)
2811 // FIXME: LARGE_STRING truncated
2812 CurrentWindowName
.Buffer
= Child
->strName
.Buffer
;
2813 CurrentWindowName
.Length
= (USHORT
)min(Child
->strName
.Length
, MAXUSHORT
);
2814 CurrentWindowName
.MaximumLength
= (USHORT
)min(Child
->strName
.MaximumLength
, MAXUSHORT
);
2815 if(!CheckWindowName
||
2816 (Child
->strName
.Length
< 0xFFFF &&
2817 !RtlCompareUnicodeString(WindowName
, &CurrentWindowName
, TRUE
)))
2819 Ret
= Child
->head
.h
;
2824 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
2832 * Searches a window's children for a window with the specified
2835 * hwndParent = The window whose childs are to be searched.
2837 * HWND_MESSAGE = message-only windows
2839 * hwndChildAfter = Search starts after this child window.
2840 * NULL = start from beginning
2842 * ucClassName = Class name to search for
2843 * Reguired parameter.
2845 * ucWindowName = Window name
2846 * ->Buffer == NULL = don't care
2849 * The HWND of the window if it was found, otherwise NULL
2855 NtUserFindWindowEx(HWND hwndParent
,
2856 HWND hwndChildAfter
,
2857 PUNICODE_STRING ucClassName
,
2858 PUNICODE_STRING ucWindowName
,
2861 PWND Parent
, ChildAfter
;
2862 UNICODE_STRING ClassName
= {0}, WindowName
= {0};
2863 HWND Desktop
, Ret
= NULL
;
2864 BOOL DoMessageWnd
= FALSE
;
2865 RTL_ATOM ClassAtom
= (RTL_ATOM
)0;
2866 DECLARE_RETURN(HWND
);
2868 TRACE("Enter NtUserFindWindowEx\n");
2871 if (ucClassName
!= NULL
|| ucWindowName
!= NULL
)
2875 if (ucClassName
!= NULL
)
2877 ClassName
= ProbeForReadUnicodeString(ucClassName
);
2878 if (ClassName
.Length
!= 0)
2880 ProbeForRead(ClassName
.Buffer
,
2884 else if (!IS_ATOM(ClassName
.Buffer
))
2886 EngSetLastError(ERROR_INVALID_PARAMETER
);
2890 if (!IntGetAtomFromStringOrAtom(&ClassName
,
2893 EngSetLastError(ERROR_CANNOT_FIND_WND_CLASS
);
2898 if (ucWindowName
!= NULL
)
2900 WindowName
= ProbeForReadUnicodeString(ucWindowName
);
2901 if (WindowName
.Length
!= 0)
2903 ProbeForRead(WindowName
.Buffer
,
2909 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2911 SetLastNtError(_SEH2_GetExceptionCode());
2912 _SEH2_YIELD(RETURN(NULL
));
2916 if (ucClassName
!= NULL
)
2918 if (ClassName
.Length
== 0 && ClassName
.Buffer
!= NULL
&&
2919 !IS_ATOM(ClassName
.Buffer
))
2921 EngSetLastError(ERROR_INVALID_PARAMETER
);
2924 else if (ClassAtom
== (RTL_ATOM
)0)
2926 /* LastError code was set by IntGetAtomFromStringOrAtom */
2932 Desktop
= IntGetCurrentThreadDesktopWindow();
2934 if(hwndParent
== NULL
)
2936 hwndParent
= Desktop
;
2937 DoMessageWnd
= TRUE
;
2939 else if(hwndParent
== HWND_MESSAGE
)
2941 hwndParent
= IntGetMessageWindow();
2944 if(!(Parent
= UserGetWindowObject(hwndParent
)))
2950 if(hwndChildAfter
&& !(ChildAfter
= UserGetWindowObject(hwndChildAfter
)))
2957 if(Parent
->head
.h
== Desktop
)
2960 PWND TopLevelWindow
;
2961 BOOLEAN CheckWindowName
;
2962 BOOLEAN WindowMatches
;
2963 BOOLEAN ClassMatches
;
2965 /* windows searches through all top-level windows if the parent is the desktop
2968 if((List
= IntWinListChildren(Parent
)))
2974 /* skip handles before and including ChildAfter */
2975 while(*phWnd
&& (*(phWnd
++) != ChildAfter
->head
.h
))
2979 CheckWindowName
= WindowName
.Buffer
!= 0;
2981 /* search children */
2984 UNICODE_STRING ustr
;
2986 if(!(TopLevelWindow
= UserGetWindowObject(*(phWnd
++))))
2991 /* Do not send WM_GETTEXT messages in the kernel mode version!
2992 The user mode version however calls GetWindowText() which will
2993 send WM_GETTEXT messages to windows belonging to its processes */
2994 ustr
.Buffer
= TopLevelWindow
->strName
.Buffer
;
2995 ustr
.Length
= (USHORT
)min(TopLevelWindow
->strName
.Length
, MAXUSHORT
); // FIXME:LARGE_STRING truncated
2996 ustr
.MaximumLength
= (USHORT
)min(TopLevelWindow
->strName
.MaximumLength
, MAXUSHORT
);
2997 WindowMatches
= !CheckWindowName
||
2998 (TopLevelWindow
->strName
.Length
< 0xFFFF &&
2999 !RtlCompareUnicodeString(&WindowName
, &ustr
, TRUE
));
3000 ClassMatches
= (ClassAtom
== (RTL_ATOM
)0) ||
3001 ClassAtom
== TopLevelWindow
->pcls
->atomClassName
;
3003 if (WindowMatches
&& ClassMatches
)
3005 Ret
= TopLevelWindow
->head
.h
;
3009 if (IntFindWindow(TopLevelWindow
, NULL
, ClassAtom
, &WindowName
))
3011 /* window returns the handle of the top-level window, in case it found
3013 Ret
= TopLevelWindow
->head
.h
;
3018 ExFreePoolWithTag(List
, USERTAG_WINDOWLIST
);
3023 ERR("FindWindowEx: Not Desktop Parent!\n");
3024 Ret
= IntFindWindow(Parent
, ChildAfter
, ClassAtom
, &WindowName
);
3027 if (Ret
== NULL
&& DoMessageWnd
)
3031 if((MsgWindows
= UserGetWindowObject(IntGetMessageWindow())))
3033 Ret
= IntFindWindow(MsgWindows
, ChildAfter
, ClassAtom
, &WindowName
);
3037 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3039 SetLastNtError(_SEH2_GetExceptionCode());
3047 TRACE("Leave NtUserFindWindowEx, ret %p\n", _ret_
);
3056 PWND FASTCALL
UserGetAncestor(PWND Wnd
, UINT Type
)
3058 PWND WndAncestor
, Parent
;
3060 if (Wnd
->head
.h
== IntGetDesktopWindow())
3069 WndAncestor
= Wnd
->spwndParent
;
3080 if(!(Parent
= WndAncestor
->spwndParent
))
3084 if(IntIsDesktopWindow(Parent
))
3089 WndAncestor
= Parent
;
3100 Parent
= IntGetParent(WndAncestor
);
3107 WndAncestor
= Parent
;
3125 NtUserGetAncestor(HWND hWnd
, UINT Type
)
3127 PWND Window
, Ancestor
;
3128 DECLARE_RETURN(HWND
);
3130 TRACE("Enter NtUserGetAncestor\n");
3131 UserEnterExclusive();
3133 if (!(Window
= UserGetWindowObject(hWnd
)))
3138 Ancestor
= UserGetAncestor(Window
, Type
);
3139 /* faxme: can UserGetAncestor ever return NULL for a valid window? */
3141 RETURN(Ancestor
? Ancestor
->head
.h
: NULL
);
3144 TRACE("Leave NtUserGetAncestor, ret=%p\n", _ret_
);
3150 //// ReactOS work around! Keep it the sames as in Combo.c and Controls.h
3152 /* combo state struct */
3166 INT fixedOwnerDrawHeight
;
3167 INT droppedWidth
; /* last two are not used unless set */
3168 INT editHeight
; /* explicitly */
3170 } HEADCOMBO
,*LPHEADCOMBO
;
3172 // Window Extra data container.
3173 typedef struct _WND2CBOX
3177 } WND2CBOX
, *PWND2CBOX
;
3179 #define CBF_BUTTONDOWN 0x0002
3185 NtUserGetComboBoxInfo(
3191 BOOL NotSameppi
= FALSE
;
3193 DECLARE_RETURN(BOOL
);
3195 TRACE("Enter NtUserGetComboBoxInfo\n");
3198 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3204 ProbeForWrite(pcbi
, sizeof(COMBOBOXINFO
), 1);
3206 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3208 SetLastNtError(_SEH2_GetExceptionCode());
3209 _SEH2_YIELD(RETURN(FALSE
));
3213 if (pcbi
->cbSize
< sizeof(COMBOBOXINFO
))
3215 EngSetLastError(ERROR_INVALID_PARAMETER
);
3219 // Pass the user pointer, it was already probed.
3220 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_COMBOBOX
]) && Wnd
->fnid
!= FNID_COMBOBOX
)
3222 RETURN( (BOOL
) co_IntSendMessage( Wnd
->head
.h
, CB_GETCOMBOBOXINFO
, 0, (LPARAM
)pcbi
));
3225 ppi
= PsGetCurrentProcessWin32Process();
3226 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3229 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3234 LPHEADCOMBO lphc
= ((PWND2CBOX
)Wnd
)->pCBox
;
3235 pcbi
->rcItem
= lphc
->textRect
;
3236 pcbi
->rcButton
= lphc
->buttonRect
;
3237 pcbi
->stateButton
= 0;
3238 if (lphc
->wState
& CBF_BUTTONDOWN
)
3239 pcbi
->stateButton
|= STATE_SYSTEM_PRESSED
;
3240 if (RECTL_bIsEmptyRect(&lphc
->buttonRect
))
3241 pcbi
->stateButton
|= STATE_SYSTEM_INVISIBLE
;
3242 pcbi
->hwndCombo
= lphc
->self
;
3243 pcbi
->hwndItem
= lphc
->hWndEdit
;
3244 pcbi
->hwndList
= lphc
->hWndLBox
;
3246 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3249 SetLastNtError(_SEH2_GetExceptionCode());
3256 if (NotSameppi
) KeDetachProcess();
3257 TRACE("Leave NtUserGetComboBoxInfo, ret=%i\n",_ret_
);
3263 //// ReactOS work around! Keep it the sames as in Listbox.c
3265 /* Listbox structure */
3268 HWND self
; /* Our own window handle */
3269 HWND owner
; /* Owner window to send notifications to */
3270 UINT style
; /* Window style */
3271 INT width
; /* Window width */
3272 INT height
; /* Window height */
3273 VOID
*items
; /* Array of items */
3274 INT nb_items
; /* Number of items */
3275 INT top_item
; /* Top visible item */
3276 INT selected_item
; /* Selected item */
3277 INT focus_item
; /* Item that has the focus */
3278 INT anchor_item
; /* Anchor item for extended selection */
3279 INT item_height
; /* Default item height */
3280 INT page_size
; /* Items per listbox page */
3281 INT column_width
; /* Column width for multi-column listboxes */
3284 // Window Extra data container.
3285 typedef struct _WND2LB
3295 NtUserGetListBoxInfo(
3300 BOOL NotSameppi
= FALSE
;
3302 DECLARE_RETURN(DWORD
);
3304 TRACE("Enter NtUserGetListBoxInfo\n");
3307 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3312 if ((Wnd
->pcls
->atomClassName
!= gpsi
->atomSysClass
[ICLS_LISTBOX
]) && Wnd
->fnid
!= FNID_LISTBOX
)
3314 RETURN( (DWORD
) co_IntSendMessage( Wnd
->head
.h
, LB_GETLISTBOXINFO
, 0, 0 ));
3317 // wine lisbox:test_GetListBoxInfo lb_getlistboxinfo = 0, should not send a message!
3318 ppi
= PsGetCurrentProcessWin32Process();
3319 NotSameppi
= ppi
!= Wnd
->head
.pti
->ppi
;
3322 KeAttachProcess(&Wnd
->head
.pti
->ppi
->peProcess
->Pcb
);
3327 LB_DESCR
*descr
= ((PWND2LB
)Wnd
)->pLBiv
;
3328 // See Controls ListBox.c:LB_GETLISTBOXINFO must match...
3329 if (descr
->style
& LBS_MULTICOLUMN
) //// ReactOS
3330 Ret
= descr
->page_size
* descr
->column_width
;
3332 Ret
= descr
->page_size
;
3334 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
3337 SetLastNtError(_SEH2_GetExceptionCode());
3344 if (NotSameppi
) KeDetachProcess();
3345 TRACE("Leave NtUserGetListBoxInfo, ret=%lu\n", _ret_
);
3353 * The NtUserSetParent function changes the parent window of the specified
3357 * The new parent window and the child window must belong to the same
3358 * application. If the window identified by the hWndChild parameter is
3359 * visible, the system performs the appropriate redrawing and repainting.
3360 * For compatibility reasons, NtUserSetParent does not modify the WS_CHILD
3361 * or WS_POPUP window styles of the window whose parent is being changed.
3368 NtUserSetParent(HWND hWndChild
, HWND hWndNewParent
)
3370 DECLARE_RETURN(HWND
);
3372 TRACE("Enter NtUserSetParent\n");
3373 UserEnterExclusive();
3376 Check Parent first from user space, set it here.
3380 hWndNewParent
= IntGetDesktopWindow();
3382 else if (hWndNewParent
== HWND_MESSAGE
)
3384 hWndNewParent
= IntGetMessageWindow();
3387 RETURN( co_UserSetParent(hWndChild
, hWndNewParent
));
3390 TRACE("Leave NtUserSetParent, ret=%p\n", _ret_
);
3396 * UserGetShellWindow
3398 * Returns a handle to shell window that was set by NtUserSetShellWindowEx.
3403 HWND FASTCALL
UserGetShellWindow(VOID
)
3405 PWINSTATION_OBJECT WinStaObject
;
3408 NTSTATUS Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3414 if (!NT_SUCCESS(Status
))
3416 SetLastNtError(Status
);
3420 Ret
= (HWND
)WinStaObject
->ShellWindow
;
3422 ObDereferenceObject(WinStaObject
);
3427 * NtUserSetShellWindowEx
3429 * This is undocumented function to set global shell window. The global
3430 * shell window has special handling of window position.
3436 NtUserSetShellWindowEx(HWND hwndShell
, HWND hwndListView
)
3438 PWINSTATION_OBJECT WinStaObject
;
3439 PWND WndShell
, WndListView
;
3440 DECLARE_RETURN(BOOL
);
3441 USER_REFERENCE_ENTRY Ref
;
3445 TRACE("Enter NtUserSetShellWindowEx\n");
3446 UserEnterExclusive();
3448 if (!(WndShell
= UserGetWindowObject(hwndShell
)))
3453 if(!(WndListView
= UserGetWindowObject(hwndListView
)))
3458 Status
= IntValidateWindowStationHandle(PsGetCurrentProcess()->Win32WindowStation
,
3464 if (!NT_SUCCESS(Status
))
3466 SetLastNtError(Status
);
3471 * Test if we are permitted to change the shell window.
3473 if (WinStaObject
->ShellWindow
)
3475 ObDereferenceObject(WinStaObject
);
3480 * Move shell window into background.
3482 if (hwndListView
&& hwndListView
!= hwndShell
)
3485 * Disabled for now to get Explorer working.
3486 * -- Filip, 01/nov/2003
3489 co_WinPosSetWindowPos(WndListView
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3492 if (WndListView
->ExStyle
& WS_EX_TOPMOST
)
3494 ObDereferenceObject(WinStaObject
);
3499 if (WndShell
->ExStyle
& WS_EX_TOPMOST
)
3501 ObDereferenceObject(WinStaObject
);
3505 UserRefObjectCo(WndShell
, &Ref
);
3506 WndShell
->state2
|= WNDS2_BOTTOMMOST
;
3507 co_WinPosSetWindowPos(WndShell
, HWND_BOTTOM
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
|SWP_NOACTIVATE
);
3509 WinStaObject
->ShellWindow
= hwndShell
;
3510 WinStaObject
->ShellListView
= hwndListView
;
3512 ti
= GetW32ThreadInfo();
3515 ti
->pDeskInfo
->hShellWindow
= hwndShell
;
3516 ti
->pDeskInfo
->spwndShell
= WndShell
;
3517 ti
->pDeskInfo
->spwndBkGnd
= WndListView
;
3518 ti
->pDeskInfo
->ppiShellProcess
= ti
->ppi
;
3521 UserRegisterHotKey(WndShell
, SC_TASKLIST
, MOD_CONTROL
, VK_ESCAPE
);
3523 UserDerefObjectCo(WndShell
);
3525 ObDereferenceObject(WinStaObject
);
3529 TRACE("Leave NtUserSetShellWindowEx, ret=%i\n",_ret_
);
3534 // Fixes wine Win test_window_styles and todo tests...
3535 static BOOL FASTCALL
3536 IntCheckFrameEdge(ULONG Style
, ULONG ExStyle
)
3538 if (ExStyle
& WS_EX_DLGMODALFRAME
)
3540 else if (!(ExStyle
& WS_EX_STATICEDGE
) && (Style
& (WS_DLGFRAME
| WS_THICKFRAME
)))
3547 co_IntSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
, BOOL bAlter
)
3549 PWND Window
, Parent
;
3550 PWINSTATION_OBJECT WindowStation
;
3554 if (!(Window
= UserGetWindowObject(hWnd
)))
3559 if ((INT
)Index
>= 0)
3561 if ((Index
+ sizeof(LONG
)) > Window
->cbwndExtra
)
3563 EngSetLastError(ERROR_INVALID_INDEX
);
3567 OldValue
= *((LONG
*)((PCHAR
)(Window
+ 1) + Index
));
3569 if ( Index == DWLP_DLGPROC && Wnd->state & WNDS_DIALOGWINDOW)
3571 OldValue = (LONG)IntSetWindowProc( Wnd,
3574 if (!OldValue) return 0;
3577 *((LONG
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3584 OldValue
= (LONG
) Window
->ExStyle
;
3585 Style
.styleOld
= OldValue
;
3586 Style
.styleNew
= NewValue
;
3588 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3591 * Remove extended window style bit WS_EX_TOPMOST for shell windows.
3593 WindowStation
= Window
->head
.pti
->rpdesk
->rpwinstaParent
;
3596 if (hWnd
== WindowStation
->ShellWindow
|| hWnd
== WindowStation
->ShellListView
)
3597 Style
.styleNew
&= ~WS_EX_TOPMOST
;
3599 /* WS_EX_WINDOWEDGE depends on some other styles */
3600 if (IntCheckFrameEdge(Window
->style
, NewValue
))
3601 Style
.styleNew
|= WS_EX_WINDOWEDGE
;
3603 Style
.styleNew
&= ~WS_EX_WINDOWEDGE
;
3605 if (!(Window
->ExStyle
& WS_EX_LAYERED
))
3607 SetLayeredStatus(Window
, 0);
3610 Window
->ExStyle
= (DWORD
)Style
.styleNew
;
3612 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_EXSTYLE
, (LPARAM
) &Style
);
3616 OldValue
= (LONG
) Window
->style
;
3617 Style
.styleOld
= OldValue
;
3618 Style
.styleNew
= NewValue
;
3621 co_IntSendMessage(hWnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
) &Style
);
3623 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
3624 if (Window
->spwndParent
== UserGetDesktopWindow()) Style
.styleNew
|= WS_CLIPSIBLINGS
;
3625 /* WS_MINIMIZE can't be reset */
3626 if (OldValue
& WS_MINIMIZE
) Style
.styleNew
|= WS_MINIMIZE
;
3627 /* Fixes wine FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change WS_EX_WINDOWEDGE too */
3628 if (IntCheckFrameEdge(NewValue
, Window
->ExStyle
))
3629 Window
->ExStyle
|= WS_EX_WINDOWEDGE
;
3631 Window
->ExStyle
&= ~WS_EX_WINDOWEDGE
;
3633 if ((OldValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3635 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
3637 //// From child to non-child it should be null already.
3638 ERR("IDMenu going null! %d\n",Window
->IDMenu
);
3639 Window
->IDMenu
= 0; // Window->spmenu = 0;
3644 if ((NewValue
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
3646 PMENU pMenu
= UserGetMenuObject(UlongToHandle(Window
->IDMenu
));
3647 Window
->state
&= ~WNDS_HASMENU
;
3650 ERR("IDMenu released 0x%p\n",pMenu
);
3651 // ROS may not hold a lock after setting menu to window. But it should!
3652 //IntReleaseMenuObject(pMenu);
3657 if ((Style
.styleOld
^ Style
.styleNew
) & WS_VISIBLE
)
3659 if (Style
.styleOld
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
--;
3660 if (Style
.styleNew
& WS_VISIBLE
) Window
->head
.pti
->cVisWindows
++;
3661 DceResetActiveDCEs( Window
);
3663 Window
->style
= (DWORD
)Style
.styleNew
;
3666 co_IntSendMessage(hWnd
, WM_STYLECHANGED
, GWL_STYLE
, (LPARAM
) &Style
);
3671 if ( Window
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process() ||
3672 Window
->fnid
& FNID_FREED
)
3674 EngSetLastError(ERROR_ACCESS_DENIED
);
3677 OldValue
= (LONG
)IntSetWindowProc(Window
,
3684 OldValue
= (LONG
) Window
->hModule
;
3685 Window
->hModule
= (HINSTANCE
) NewValue
;
3688 case GWL_HWNDPARENT
:
3689 Parent
= Window
->spwndParent
;
3690 if (Parent
&& (Parent
->head
.h
== IntGetDesktopWindow()))
3691 OldValue
= (LONG
) IntSetOwner(Window
->head
.h
, (HWND
) NewValue
);
3693 OldValue
= (LONG
) co_UserSetParent(Window
->head
.h
, (HWND
) NewValue
);
3697 OldValue
= (LONG
) Window
->IDMenu
;
3698 Window
->IDMenu
= (UINT
) NewValue
;
3702 OldValue
= Window
->dwUserData
;
3703 Window
->dwUserData
= NewValue
;
3707 ERR("NtUserSetWindowLong(): Unsupported index %lu\n", Index
);
3708 EngSetLastError(ERROR_INVALID_INDEX
);
3719 co_UserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3721 return co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3725 * NtUserSetWindowLong
3727 * The NtUserSetWindowLong function changes an attribute of the specified
3728 * window. The function also sets the 32-bit (long) value at the specified
3729 * offset into the extra window memory.
3736 NtUserSetWindowLong(HWND hWnd
, DWORD Index
, LONG NewValue
, BOOL Ansi
)
3740 UserEnterExclusive();
3742 if (hWnd
== IntGetDesktopWindow())
3744 EngSetLastError(STATUS_ACCESS_DENIED
);
3749 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, Ansi
, FALSE
);
3757 NtUserAlterWindowStyle(HWND hWnd
, DWORD Index
, LONG NewValue
)
3761 UserEnterExclusive();
3763 if (hWnd
== IntGetDesktopWindow())
3765 EngSetLastError(STATUS_ACCESS_DENIED
);
3770 ret
= co_IntSetWindowLong(hWnd
, Index
, NewValue
, FALSE
, TRUE
);
3779 * NtUserSetWindowWord
3781 * Legacy function similar to NtUserSetWindowLong.
3788 NtUserSetWindowWord(HWND hWnd
, INT Index
, WORD NewValue
)
3792 DECLARE_RETURN(WORD
);
3794 TRACE("Enter NtUserSetWindowWord\n");
3795 UserEnterExclusive();
3797 if (hWnd
== IntGetDesktopWindow())
3799 EngSetLastError(STATUS_ACCESS_DENIED
);
3803 if (!(Window
= UserGetWindowObject(hWnd
)))
3812 case GWL_HWNDPARENT
:
3813 RETURN( (WORD
)co_UserSetWindowLong(UserHMGetHandle(Window
), Index
, (UINT
)NewValue
, TRUE
));
3817 EngSetLastError(ERROR_INVALID_INDEX
);
3822 if ((ULONG
)Index
> (Window
->cbwndExtra
- sizeof(WORD
)))
3824 EngSetLastError(ERROR_INVALID_PARAMETER
);
3828 OldValue
= *((WORD
*)((PCHAR
)(Window
+ 1) + Index
));
3829 *((WORD
*)((PCHAR
)(Window
+ 1) + Index
)) = NewValue
;
3834 TRACE("Leave NtUserSetWindowWord, ret=%u\n", _ret_
);
3840 QueryWindow based on KJK::Hyperion and James Tabor.
3842 0 = QWUniqueProcessId
3843 1 = QWUniqueThreadId
3846 4 = QWIsHung Implements IsHungAppWindow found
3849 9 = QWKillWindow When I called this with hWnd ==
3850 DesktopWindow, it shutdown the system
3857 NtUserQueryWindow(HWND hWnd
, DWORD Index
)
3859 /* Console Leader Process CID Window offsets */
3860 #define GWLP_CONSOLE_LEADER_PID 0
3861 #define GWLP_CONSOLE_LEADER_TID 4
3865 DECLARE_RETURN(UINT
);
3867 TRACE("Enter NtUserQueryWindow\n");
3870 if (!(pWnd
= UserGetWindowObject(hWnd
)))
3877 case QUERY_WINDOW_UNIQUE_PROCESS_ID
:
3879 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3880 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3882 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_PID)
3883 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_PID
)));
3887 Result
= (DWORD
)IntGetWndProcessId(pWnd
);
3892 case QUERY_WINDOW_UNIQUE_THREAD_ID
:
3894 if ( (pWnd
->head
.pti
->TIF_flags
& TIF_CSRSSTHREAD
) &&
3895 (pWnd
->pcls
->atomClassName
== gaGuiConsoleWndClass
) )
3897 // IntGetWindowLong(offset == GWLP_CONSOLE_LEADER_TID)
3898 Result
= (DWORD
)(*((LONG_PTR
*)((PCHAR
)(pWnd
+ 1) + GWLP_CONSOLE_LEADER_TID
)));
3902 Result
= (DWORD
)IntGetWndThreadId(pWnd
);
3907 case QUERY_WINDOW_ACTIVE
:
3908 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndActive
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndActive
) : 0);
3911 case QUERY_WINDOW_FOCUS
:
3912 Result
= (DWORD
)(pWnd
->head
.pti
->MessageQueue
->spwndFocus
? UserHMGetHandle(pWnd
->head
.pti
->MessageQueue
->spwndFocus
) : 0);
3915 case QUERY_WINDOW_ISHUNG
:
3916 Result
= (DWORD
)MsqIsHung(pWnd
->head
.pti
);
3919 case QUERY_WINDOW_REAL_ID
:
3920 Result
= (DWORD
)pWnd
->head
.pti
->pEThread
->Cid
.UniqueProcess
;
3923 case QUERY_WINDOW_FOREGROUND
:
3924 Result
= (pWnd
->head
.pti
->MessageQueue
== gpqForeground
);
3928 Result
= (DWORD
)NULL
;
3935 TRACE("Leave NtUserQueryWindow, ret=%u\n", _ret_
);
3944 NtUserRegisterWindowMessage(PUNICODE_STRING MessageNameUnsafe
)
3946 UNICODE_STRING SafeMessageName
;
3949 DECLARE_RETURN(UINT
);
3951 TRACE("Enter NtUserRegisterWindowMessage\n");
3952 UserEnterExclusive();
3954 if(MessageNameUnsafe
== NULL
)
3956 EngSetLastError(ERROR_INVALID_PARAMETER
);
3960 Status
= IntSafeCopyUnicodeStringTerminateNULL(&SafeMessageName
, MessageNameUnsafe
);
3961 if(!NT_SUCCESS(Status
))
3963 SetLastNtError(Status
);
3967 Ret
= (UINT
)IntAddAtom(SafeMessageName
.Buffer
);
3968 if (SafeMessageName
.Buffer
)
3969 ExFreePoolWithTag(SafeMessageName
.Buffer
, TAG_STRING
);
3973 TRACE("Leave NtUserRegisterWindowMessage, ret=%u\n", _ret_
);
3982 NtUserSetWindowFNID(HWND hWnd
,
3986 DECLARE_RETURN(BOOL
);
3988 TRACE("Enter NtUserSetWindowFNID\n");
3989 UserEnterExclusive();
3991 if (!(Wnd
= UserGetWindowObject(hWnd
)))
3996 if (Wnd
->head
.pti
->ppi
!= PsGetCurrentProcessWin32Process())
3998 EngSetLastError(ERROR_ACCESS_DENIED
);
4002 // From user land we only set these.
4003 if (fnID
!= FNID_DESTROY
)
4005 /* HACK: The minimum should be FNID_BUTTON, but menu code relies on this */
4006 if (fnID
< FNID_FIRST
|| fnID
> FNID_GHOST
||
4009 EngSetLastError(ERROR_INVALID_PARAMETER
);
4018 TRACE("Leave NtUserSetWindowFNID\n");
4024 DefSetText(PWND Wnd
, PCWSTR WindowText
)
4026 UNICODE_STRING UnicodeString
;
4029 RtlInitUnicodeString(&UnicodeString
, WindowText
);
4031 if (UnicodeString
.Length
!= 0)
4033 if (Wnd
->strName
.MaximumLength
> 0 &&
4034 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4036 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4038 Wnd
->strName
.Length
= UnicodeString
.Length
;
4039 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4040 RtlCopyMemory(Wnd
->strName
.Buffer
,
4041 UnicodeString
.Buffer
,
4042 UnicodeString
.Length
);
4047 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4048 buf
= Wnd
->strName
.Buffer
;
4049 Wnd
->strName
.Buffer
= NULL
;
4052 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4055 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4056 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4057 if (Wnd
->strName
.Buffer
!= NULL
)
4059 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4060 RtlCopyMemory(Wnd
->strName
.Buffer
,
4061 UnicodeString
.Buffer
,
4062 UnicodeString
.Length
);
4063 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4064 Wnd
->strName
.Length
= UnicodeString
.Length
;
4068 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4075 Wnd
->strName
.Length
= 0;
4076 if (Wnd
->strName
.Buffer
!= NULL
)
4077 Wnd
->strName
.Buffer
[0] = L
'\0';
4080 // FIXME: HAX! Windows does not do this in here!
4081 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4082 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4083 /* Send shell notifications */
4084 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4086 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) UserHMGetHandle(Wnd
), FALSE
); // FIXME Flashing?
4091 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4098 * Undocumented function that is called from DefWindowProc to set
4105 NtUserDefSetText(HWND hWnd
, PLARGE_STRING WindowText
)
4108 LARGE_STRING SafeText
;
4109 UNICODE_STRING UnicodeString
;
4112 TRACE("Enter NtUserDefSetText\n");
4114 if (WindowText
!= NULL
)
4118 SafeText
= ProbeForReadLargeString(WindowText
);
4120 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4123 SetLastNtError(_SEH2_GetExceptionCode());
4133 UserEnterExclusive();
4135 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4141 // ReactOS uses Unicode and not mixed. Up/Down converting will take time.
4142 // Brought to you by: The Wine Project! Dysfunctional Thought Processes!
4143 // Now we know what the bAnsi is for.
4144 RtlInitUnicodeString(&UnicodeString
, NULL
);
4145 if (SafeText
.Buffer
)
4150 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(CHAR
));
4152 ProbeForRead(SafeText
.Buffer
, SafeText
.Length
, sizeof(WCHAR
));
4153 Ret
= RtlLargeStringToUnicodeString(&UnicodeString
, &SafeText
);
4155 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
4158 SetLastNtError(_SEH2_GetExceptionCode());
4161 if (!Ret
) goto Exit
;
4164 if (UnicodeString
.Length
!= 0)
4166 if (Wnd
->strName
.MaximumLength
> 0 &&
4167 UnicodeString
.Length
<= Wnd
->strName
.MaximumLength
- sizeof(UNICODE_NULL
))
4169 ASSERT(Wnd
->strName
.Buffer
!= NULL
);
4171 Wnd
->strName
.Length
= UnicodeString
.Length
;
4172 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4173 RtlCopyMemory(Wnd
->strName
.Buffer
,
4174 UnicodeString
.Buffer
,
4175 UnicodeString
.Length
);
4180 Wnd
->strName
.MaximumLength
= Wnd
->strName
.Length
= 0;
4181 buf
= Wnd
->strName
.Buffer
;
4182 Wnd
->strName
.Buffer
= NULL
;
4185 DesktopHeapFree(Wnd
->head
.rpdesk
, buf
);
4188 Wnd
->strName
.Buffer
= DesktopHeapAlloc(Wnd
->head
.rpdesk
,
4189 UnicodeString
.Length
+ sizeof(UNICODE_NULL
));
4190 if (Wnd
->strName
.Buffer
!= NULL
)
4192 Wnd
->strName
.Buffer
[UnicodeString
.Length
/ sizeof(WCHAR
)] = L
'\0';
4193 RtlCopyMemory(Wnd
->strName
.Buffer
,
4194 UnicodeString
.Buffer
,
4195 UnicodeString
.Length
);
4196 Wnd
->strName
.MaximumLength
= UnicodeString
.Length
+ sizeof(UNICODE_NULL
);
4197 Wnd
->strName
.Length
= UnicodeString
.Length
;
4201 EngSetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4209 Wnd
->strName
.Length
= 0;
4210 if (Wnd
->strName
.Buffer
!= NULL
)
4211 Wnd
->strName
.Buffer
[0] = L
'\0';
4214 // FIXME: HAX! Windows does not do this in here!
4215 // In User32, these are called after: NotifyWinEvent EVENT_OBJECT_NAMECHANGE than
4216 // RepaintButton, StaticRepaint, NtUserCallHwndLock HWNDLOCK_ROUTINE_REDRAWFRAMEANDHOOK, etc.
4217 /* Send shell notifications */
4218 if (!Wnd
->spwndOwner
&& !IntGetParent(Wnd
))
4220 co_IntShellHookNotify(HSHELL_REDRAW
, (WPARAM
) hWnd
, FALSE
); // FIXME Flashing?
4225 if (UnicodeString
.Buffer
) RtlFreeUnicodeString(&UnicodeString
);
4226 TRACE("Leave NtUserDefSetText, ret=%i\n", Ret
);
4232 * NtUserInternalGetWindowText
4239 NtUserInternalGetWindowText(HWND hWnd
, LPWSTR lpString
, INT nMaxCount
)
4244 DECLARE_RETURN(INT
);
4246 TRACE("Enter NtUserInternalGetWindowText\n");
4249 if(lpString
&& (nMaxCount
<= 1))
4251 EngSetLastError(ERROR_INVALID_PARAMETER
);
4255 if(!(Wnd
= UserGetWindowObject(hWnd
)))
4260 Result
= Wnd
->strName
.Length
/ sizeof(WCHAR
);
4263 const WCHAR Terminator
= L
'\0';
4265 WCHAR
*Buffer
= (WCHAR
*)lpString
;
4267 Copy
= min(nMaxCount
- 1, Result
);
4270 Status
= MmCopyToCaller(Buffer
, Wnd
->strName
.Buffer
, Copy
* sizeof(WCHAR
));
4271 if(!NT_SUCCESS(Status
))
4273 SetLastNtError(Status
);
4279 Status
= MmCopyToCaller(Buffer
, &Terminator
, sizeof(WCHAR
));
4280 if(!NT_SUCCESS(Status
))
4282 SetLastNtError(Status
);
4292 TRACE("Leave NtUserInternalGetWindowText, ret=%i\n",_ret_
);
4302 IntShowOwnedPopups(PWND OwnerWnd
, BOOL fShow
)
4308 // ASSERT(OwnerWnd);
4310 TRACE("Enter ShowOwnedPopups Show: %s\n", (fShow
? "TRUE" : "FALSE"));
4311 win_array
= IntWinListChildren(OwnerWnd
);
4316 while (win_array
[count
])
4318 while (--count
>= 0)
4320 if (!(pWnd
= ValidateHwndNoErr( win_array
[count
] )))
4322 if (pWnd
->spwndOwner
!= OwnerWnd
)
4327 if (pWnd
->state
& WNDS_HIDDENPOPUP
)
4329 /* In Windows, ShowOwnedPopups(TRUE) generates
4330 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
4331 * regardless of the state of the owner
4333 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
4339 if (pWnd
->style
& WS_VISIBLE
)
4341 /* In Windows, ShowOwnedPopups(FALSE) generates
4342 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
4343 * regardless of the state of the owner
4345 co_IntSendMessage(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
4351 ExFreePoolWithTag(win_array
, USERTAG_WINDOWLIST
);
4352 TRACE("Leave ShowOwnedPopups\n");