Skip to content

Commit 826bd41

Browse files
authored
[NTUSER][USER32] Initial support of WS_EX_NOACTIVATE flag (reactos#4731)
WS_EX_NOACTIVATE flag forbids the window to be activated. CORE-18417
1 parent bd027c9 commit 826bd41

File tree

5 files changed

+36
-20
lines changed

5 files changed

+36
-20
lines changed

win32ss/user/ntuser/focus.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ IsAllowedFGActive(PTHREADINFO pti, PWND Wnd)
734734
pti->rpdesk != gpdeskInputDesktop || // not current Desktop,
735735
pti->MessageQueue == gpqForeground || // if already the queue foreground,
736736
IsFGLocked() || // foreground is locked,
737-
Wnd->ExStyle & WS_EX_NOACTIVATE ) // or,,, does not become the foreground window when the user clicks it.
737+
(Wnd->ExStyle & WS_EX_NOACTIVATE)) // or, does not become the foreground window when the user clicks it.
738738
{
739739
return FALSE;
740740
}
@@ -1041,9 +1041,8 @@ co_IntSetActiveWindow(
10411041
ThreadQueue = pti->MessageQueue;
10421042
ASSERT(ThreadQueue != 0);
10431043

1044-
hWndPrev = ThreadQueue->spwndActive ? UserHMGetHandle(ThreadQueue->spwndActive) : NULL;
1045-
10461044
pWndChg = ThreadQueue->spwndActive; // Keep to notify of a preemptive switch.
1045+
hWndPrev = (pWndChg ? UserHMGetHandle(pWndChg) : NULL);
10471046

10481047
if ( !Wnd || Wnd == UserGetDesktopWindow() )
10491048
{
@@ -1055,6 +1054,9 @@ co_IntSetActiveWindow(
10551054
hWnd = UserHMGetHandle(Wnd);
10561055
//ERR("co_IntSetActiveWindow 2 hWnd 0x%p\n",hWnd);
10571056

1057+
if (Wnd->ExStyle & WS_EX_NOACTIVATE)
1058+
return TRUE;
1059+
10581060
/* check if the specified window can be set in the input data of a given queue */
10591061
if ( ThreadQueue != Wnd->head.pti->MessageQueue )
10601062
{
@@ -1248,9 +1250,12 @@ BOOL FASTCALL
12481250
co_IntMouseActivateWindow(PWND Wnd)
12491251
{
12501252
TRACE("Mouse Active\n");
1253+
if (Wnd && (Wnd->ExStyle & WS_EX_NOACTIVATE))
1254+
return TRUE;
12511255
return co_IntSetForegroundAndFocusWindow(Wnd, TRUE, TRUE);
12521256
}
12531257

1258+
/* Win: PWND xxxSetActiveWindow(Wnd) */
12541259
BOOL FASTCALL
12551260
UserSetActiveWindow( _In_opt_ PWND Wnd )
12561261
{
@@ -1660,8 +1665,9 @@ NtUserSetActiveWindow(HWND hWnd)
16601665
{
16611666
USER_REFERENCE_ENTRY Ref;
16621667
HWND hWndPrev;
1663-
PWND Window;
1668+
PWND Window, pwndPrev;
16641669
DECLARE_RETURN(HWND);
1670+
BOOL bActivated;
16651671

16661672
TRACE("Enter NtUserSetActiveWindow(%p)\n", hWnd);
16671673
UserEnterExclusive();
@@ -1679,11 +1685,14 @@ NtUserSetActiveWindow(HWND hWnd)
16791685
if (!Window ||
16801686
Window->head.pti->MessageQueue == gptiCurrent->MessageQueue)
16811687
{
1682-
hWndPrev = gptiCurrent->MessageQueue->spwndActive ? UserHMGetHandle(gptiCurrent->MessageQueue->spwndActive) : NULL;
1688+
pwndPrev = gptiCurrent->MessageQueue->spwndActive;
1689+
hWndPrev = (pwndPrev ? UserHMGetHandle(pwndPrev) : NULL);
16831690
if (Window) UserRefObjectCo(Window, &Ref);
1684-
UserSetActiveWindow(Window);
1691+
bActivated = UserSetActiveWindow(Window);
16851692
if (Window) UserDerefObjectCo(Window);
1686-
RETURN( hWndPrev ? (IntIsWindow(hWndPrev) ? hWndPrev : 0) : 0 );
1693+
if (!bActivated)
1694+
RETURN(NULL);
1695+
RETURN(hWndPrev ? hWndPrev : hWnd);
16871696
}
16881697
RETURN( NULL);
16891698

win32ss/user/ntuser/nonclient.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,12 +438,12 @@ DefWndDoSizeMove(PWND pwnd, WORD wParam)
438438
if (doSideSnap)
439439
{
440440
co_WinPosSetWindowPos(pwnd,
441-
0,
441+
NULL,
442442
snapRect.left,
443443
snapRect.top,
444444
snapRect.right - snapRect.left,
445445
snapRect.bottom - snapRect.top,
446-
0);
446+
SWP_NOACTIVATE);
447447
pwnd->InternalPos.NormalRect = origRect;
448448
}
449449
else
@@ -551,13 +551,13 @@ DefWndDoSizeMove(PWND pwnd, WORD wParam)
551551

552552
//// This causes the mdi child window to jump up when it is moved.
553553
//IntMapWindowPoints( 0, pWndParent, (POINT *)&rect, 2 );
554-
co_WinPosSetWindowPos( pwnd,
555-
0,
556-
newRect.left,
557-
newRect.top,
558-
newRect.right - newRect.left,
559-
newRect.bottom - newRect.top,
560-
( hittest == HTCAPTION ) ? SWP_NOSIZE : 0 );
554+
co_WinPosSetWindowPos(pwnd,
555+
NULL,
556+
newRect.left,
557+
newRect.top,
558+
newRect.right - newRect.left,
559+
newRect.bottom - newRect.top,
560+
SWP_NOACTIVATE | ((hittest == HTCAPTION) ? SWP_NOSIZE : 0));
561561

562562
hrgnNew = GreCreateRectRgnIndirect(&pwnd->rcWindow);
563563
if (pwnd->hrgnClip != NULL)
@@ -1532,7 +1532,8 @@ NC_HandleNCLButtonDown(PWND pWnd, WPARAM wParam, LPARAM lParam)
15321532
TopWnd = parent;
15331533
}
15341534

1535-
if ( co_IntSetForegroundWindowMouse(TopWnd) ||
1535+
if ( (pWnd && (pWnd->ExStyle & WS_EX_NOACTIVATE)) ||
1536+
co_IntSetForegroundWindowMouse(TopWnd) ||
15361537
//NtUserCallHwndLock(hTopWnd, HWNDLOCK_ROUTINE_SETFOREGROUNDWINDOWMOUSE) ||
15371538
UserGetActiveWindow() == UserHMGetHandle(TopWnd))
15381539
{
@@ -1689,6 +1690,7 @@ LRESULT NC_HandleNCRButtonDown( PWND pwnd, WPARAM wParam, LPARAM lParam )
16891690
if (UserHMGetHandle(pwnd) != IntGetCapture()) return 0;
16901691
}
16911692
IntReleaseCapture();
1693+
16921694
if (hittest == HTCAPTION || hittest == HTSYSMENU || hittest == HTHSCROLL || hittest == HTVSCROLL)
16931695
{
16941696
TRACE("Msg pt %x and Msg.lParam %x and lParam %x\n",MAKELONG(msg.pt.x,msg.pt.y),msg.lParam,lParam);

win32ss/user/ntuser/window.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2494,7 +2494,11 @@ co_UserCreateWindowEx(CREATESTRUCTW* Cs,
24942494

24952495
SwFlag = co_WinPosMinMaximize(Window, SwFlag, &NewPos);
24962496
SwFlag |= SWP_NOZORDER|SWP_FRAMECHANGED; /* Frame always gets changed */
2497-
if (!(style & WS_VISIBLE) || (style & WS_CHILD) || UserGetActiveWindow()) SwFlag |= SWP_NOACTIVATE;
2497+
if (!(style & WS_VISIBLE) || (style & WS_CHILD) || UserGetActiveWindow() ||
2498+
(Window->ExStyle & WS_EX_NOACTIVATE))
2499+
{
2500+
SwFlag |= SWP_NOACTIVATE;
2501+
}
24982502
co_WinPosSetWindowPos(Window, 0, NewPos.left, NewPos.top,
24992503
NewPos.right, NewPos.bottom, SwFlag);
25002504
}

win32ss/user/ntuser/winpos.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,7 @@ BOOL FASTCALL can_activate_window( PWND Wnd OPTIONAL)
379379
if (!(style & WS_VISIBLE)) return FALSE;
380380
if (style & WS_MINIMIZE) return FALSE;
381381
if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
382+
if (Wnd->ExStyle & WS_EX_NOACTIVATE) return FALSE;
382383
return TRUE;
383384
/* FIXME: This window could be disable because the child that closed
384385
was a popup. */

win32ss/user/user32/controls/appswitch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ BOOL IsAltTabWindow(HWND hwnd)
225225
if (!IsWindowVisible(hwnd))
226226
return FALSE;
227227

228-
// must not be WS_EX_TOOLWINDOW
228+
// must not be WS_EX_TOOLWINDOW nor WS_EX_NOACTIVATE
229229
ExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
230-
if (ExStyle & WS_EX_TOOLWINDOW)
230+
if (ExStyle & (WS_EX_TOOLWINDOW | WS_EX_NOACTIVATE))
231231
return FALSE;
232232

233233
// must be not empty rect

0 commit comments

Comments
 (0)