Fix for notepad and winecfg losing focus

Pavel Roskin proski at gnu.org
Wed Oct 1 15:35:42 CDT 2003


Hello!

Our notepad has a bug that causes it to lose focus on startup.  In order
to initialize the new document, WinMain() calls DIALOG_FileNew(), which
focuses the editor subwindow.  The problem is that it happens before
ShowWindow() is called on the main window.

As a result, focusing the subwindow causes "activation" of its parent
without actually showing it.  This leaves the code in dlls/user/focus.c in
the confused state.  When ShowWindow() is called, the window is not
brought to foreground because it's "already active".  Then
set_active_window() decides to draw the inactive caption because the
window is not in foreground.

Windows 2000 doesn't show this problem.  Notepad and winecfg are focused
properly on startup.

I think there are many solutions to this problem.  For example, the check
for visibility could be moved from SetActiveWindow() to the lower-level
set_active_window().

The attached patch is minimally intrusive.  This decreases its chances of
breaking anything, but it may not be the best radical solution.  If
SetFocus() finds an invisible window while looking for the ultimate
parent, it fails.  The same is already done for minimized and disabled
windows.

The patch has been successfully tested in the non-managed and desktop
modes.  The managed node is not affected because the captions are not
shown.  Cygwin setup (http:/www.cygwin.com/setup.exe) is also positively
affected.

===========================
--- dlls/user/focus.c
+++ dlls/user/focus.c
@@ -258,6 +258,7 @@ HWND WINAPI SetFocus( HWND hwnd )
             HWND parent;
             LONG style = GetWindowLongW( hwndTop, GWL_STYLE );
             if (style & (WS_MINIMIZE | WS_DISABLED)) return 0;
+            if (!(style & WS_VISIBLE)) return 0;
             parent = GetAncestor( hwndTop, GA_PARENT );
             if (!parent || parent == GetDesktopWindow()) break;
             hwndTop = parent;
===========================

-- 
Regards,
Pavel Roskin



More information about the wine-devel mailing list