EnableWindow should not remove the focus of child windows.
diff --git a/dlls/user/tests/msg.c b/dlls/user/tests/msg.c
index 7e053fd..63114b6 100644
--- a/dlls/user/tests/msg.c
+++ b/dlls/user/tests/msg.c
@@ -599,6 +599,13 @@
{ 0 }
};
+static const struct message WmEnableWindowSeq[] =
+{
+ { WM_CANCELMODE, sent },
+ { WM_ENABLE, sent },
+ { 0 }
+};
+
static int after_end_dialog;
static int sequence_cnt, sequence_size;
static struct message* sequence;
@@ -910,6 +917,24 @@
ok_sequence(WmDrawMenuBarSeq, "DrawMenuBar");
DestroyWindow(hwnd);
+ flush_sequence();
+
+ /* Message sequence for EnableWindow */
+ hparent = CreateWindowExA(0, "TestWindowClass", "Test parent", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+ 100, 100, 200, 200, 0, 0, 0, NULL);
+ ok (hparent != 0, "Failed to create parent window\n");
+ hchild = CreateWindowExA(0, "TestWindowClass", "Test child", WS_CHILDWINDOW | WS_VISIBLE,
+ 0, 0, 10, 10, hparent, 0, 0, NULL);
+ ok (hchild != 0, "Failed to create child window\n");
+
+ SetFocus(hchild);
+ flush_sequence();
+
+ EnableWindow(hparent, FALSE);
+ ok_sequence(WmEnableWindowSeq, "EnableWindow");
+
+ DestroyWindow(hparent);
+ flush_sequence();
}
static LRESULT WINAPI MsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
diff --git a/dlls/user/tests/win.c b/dlls/user/tests/win.c
index b969e47..5161b72 100644
--- a/dlls/user/tests/win.c
+++ b/dlls/user/tests/win.c
@@ -1626,6 +1626,14 @@
ShowWindow(child, SW_HIDE);
ok( GetFocus() == hwnd, "Focus should still be on parent %p, not %p\n", hwnd, GetFocus() );
+ ShowWindow(hwnd, SW_SHOW);
+ ShowWindow(child, SW_SHOW);
+ SetFocus(child);
+ ok( GetFocus() == child, "Focus should be on child %p\n", child );
+ EnableWindow(hwnd, FALSE);
+ ok( GetFocus() == child, "Focus should still be on child %p\n", child );
+ EnableWindow(hwnd, TRUE);
+
DestroyWindow( child );
}
diff --git a/windows/win.c b/windows/win.c
index 52259d9..a73fbf0 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -1752,14 +1752,13 @@
}
else if (!enable && !retvalue)
{
- HWND focus_wnd, capture_wnd;
+ HWND capture_wnd;
SendMessageA( hwnd, WM_CANCELMODE, 0, 0);
WIN_SetStyle( hwnd, style | WS_DISABLED );
- focus_wnd = GetFocus();
- if (hwnd == focus_wnd || IsChild(hwnd, focus_wnd))
+ if (hwnd == GetFocus())
SetFocus( 0 ); /* A disabled window can't have the focus */
capture_wnd = GetCapture();