Do not change focus if the being activated window is no more active

Dmitry Timoshkov dmitry at baikal.ru
Tue Nov 15 08:38:23 CST 2005


Hello,

one of the apps I'm working on suffers from the focus stealing bug:
an app's dialog has an edit control and in the subclassed edit proc
on WM_SETFOCUS the app does ShowWindow(SW_SHOW) on a WS_POPUP window.
Then the app plays with SetWindowPos to prevent deactivation of the main
dialog window. Running with spy++ under Windows shows that Windows doesn't
set the focus to the WS_POPUP window once it gets deactivated. This patch
does an attempt to replicate that behaviour.

Changelog:
    Dmitry Timoshkov <dmitry at codeweavers.com>
    Do not change focus if the being activated window is no more active.

--- cvs/hq/wine/dlls/user/focus.c	2005-07-22 13:12:04.000000000 +0900
+++ wine/dlls/user/focus.c	2005-11-15 22:18:23.000000000 +0800
@@ -161,9 +161,15 @@ static BOOL set_active_window( HWND hwnd
     /* now change focus if necessary */
     if (focus)
     {
-        HWND curfocus = GetFocus();
-        if (!curfocus || !hwnd || GetAncestor( curfocus, GA_ROOT ) != hwnd)
-            set_focus_window( hwnd );
+        GUITHREADINFO info;
+
+        GetGUIThreadInfo( GetCurrentThreadId(), &info );
+        /* Do not change focus if the window is no more active */
+        if (hwnd == info.hwndActive)
+        {
+            if (!info.hwndFocus || !hwnd || GetAncestor( info.hwndFocus, GA_ROOT ) != hwnd)
+                set_focus_window( hwnd );
+        }
     }
 
     return TRUE;






More information about the wine-patches mailing list