EnableWindow

Ulrich Czekalla ulrich.czekalla at utoronto.ca
Wed Jun 2 14:14:27 CDT 2004


Here is an updated version with revised tests.

/Ulrich

On Fri, May 28, 2004 at 09:24:43PM -0400, Ulrich Czekalla wrote:
> Here is an updated patch with the test included in win.c.
> 
> /Ulrich
> 
> On Fri, May 28, 2004 at 05:00:42PM -0700, Alexandre Julliard wrote:
> > Ulrich Czekalla <ulrich.czekalla at utoronto.ca> writes:
> > 
> > > ChangeLog:
> > > 	Ulrich Czekalla <ulrich at codeweavers.com>
> > > 	EnableWindow should not remove the focus of child windows
> > 
> > Thanks for providing a test, but could you please merge it with the
> > existing win.c and/or msg.c tests?  We can't create a new file for
> > every API being tested.
> > 
> > -- 
> > Alexandre Julliard
> > julliard at winehq.org

> Index: dlls/user/tests/win.c
> ===================================================================
> RCS file: /home/wine/wine/dlls/user/tests/win.c,v
> retrieving revision 1.26
> diff -u -r1.26 win.c
> --- dlls/user/tests/win.c	24 May 2004 19:08:41 -0000	1.26
> +++ dlls/user/tests/win.c	29 May 2004 01:21:30 -0000
> @@ -49,6 +49,8 @@
>  static HWND hwndMain, hwndMain2;
>  static HHOOK hhook;
>  
> +static UINT enableWindowMsgIndex;
> +
>  /* check the values returned by the various parent/owner functions on a given window */
>  static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
>                             HWND gw_owner, HWND ga_root, HWND ga_root_owner )
> @@ -1644,6 +1646,83 @@
>      ok( GetActiveWindow() != hwnd2, "Window %p is still active\n", hwnd2 );
>  }
>  
> +static LRESULT WINAPI enable_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
> +{
> +    switch (msg)
> +    {
> +        case WM_CANCELMODE:
> +            ok (enableWindowMsgIndex++ == 1, "WM_CANCELMODE received out of sequence\n");
> +            break;
> +
> +        case WM_ENABLE:
> +            ok (enableWindowMsgIndex++ == 2, "WM_ENABLE received out of sequence\n");
> +            break;
> +
> +        default:
> +            break;
> +    }
> +
> +    return DefWindowProcA(hwnd, msg, wparam, lparam);
> +}
> +
> +static LRESULT WINAPI enable_window_child_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
> +{
> +    switch (msg)
> +    {
> +        case WM_SETFOCUS:
> +            ok (enableWindowMsgIndex++ == 0, "WM_SETFOCUS received out of sequence\n");
> +            break;
> +
> +        case WM_KILLFOCUS:
> +            ok (FALSE, "WM_KILLFOCUS received out of sequence\n");
> +            break;
> +
> +        default:
> +            break;
> +    }
> +
> +    return DefWindowProcA(hwnd, msg, wparam, lparam);
> +}
> +
> +static void test_EnableWindow()
> +{
> +    HWND hWndMain;
> +    HWND hWndChild;
> +    WNDCLASSA cls;
> +
> +    cls.style = 0;
> +    cls.lpfnWndProc = enable_window_procA;
> +    cls.cbClsExtra = 0;
> +    cls.cbWndExtra = 0;
> +    cls.hInstance = GetModuleHandleA(0);
> +    cls.hIcon = 0;
> +    cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
> +    cls.hbrBackground = GetStockObject(WHITE_BRUSH);
> +    cls.lpszMenuName = NULL;
> +    cls.lpszClassName = "EnableWindowClass";
> +    RegisterClassA(&cls);
> +
> +    cls.lpfnWndProc = enable_window_child_procA;
> +    cls.hbrBackground = GetStockObject(GRAY_BRUSH);
> +    cls.lpszClassName = "EnableWindowChildClass";
> +    RegisterClassA(&cls);
> +
> +    enableWindowMsgIndex = 0;
> +
> +    hWndMain = CreateWindowExA(0, "EnableWindowClass", "",  WS_VISIBLE | WS_POPUP | WS_CAPTION | WS_SYSMENU,
> +        0, 0, 100, 100, NULL, NULL, NULL, NULL);
> +    hWndChild = CreateWindowExA(0, "EnableWindowChildClass", "", WS_VISIBLE | WS_CHILD,
> +        20, 20, 60, 60, hWndMain, NULL, NULL, NULL);
> +
> +    assert( hWndMain );
> +    assert( hWndChild );
> +
> +    SetFocus(hWndChild);
> +    EnableWindow(hWndMain, FALSE);
> +
> +    ok (GetFocus() == hWndChild, "Window %p should have focus\n", hWndChild);
> +}
> +
>  START_TEST(win)
>  {
>      pGetAncestor = (void *)GetProcAddress( GetModuleHandleA("user32.dll"), "GetAncestor" );
> @@ -1695,4 +1774,6 @@
>      test_children_zorder(hwndMain);
>  
>      UnhookWindowsHookEx(hhook);
> +
> +    test_EnableWindow();
>  }
> Index: windows/win.c
> ===================================================================
> RCS file: /home/wine/wine/windows/win.c,v
> retrieving revision 1.242
> diff -u -r1.242 win.c
> --- windows/win.c	28 May 2004 19:35:37 -0000	1.242
> +++ windows/win.c	29 May 2004 01:21:31 -0000
> @@ -1759,7 +1759,7 @@
>          WIN_SetStyle( hwnd, style | WS_DISABLED );
>  
>          focus_wnd = GetFocus();
> -        if (hwnd == focus_wnd || IsChild(hwnd, focus_wnd))
> +        if (hwnd == focus_wnd)
>              SetFocus( 0 );  /* A disabled window can't have the focus */
>  
>          capture_wnd = GetCapture();

-------------- next part --------------
Index: windows/win.c
===================================================================
RCS file: /home/wine/wine/windows/win.c,v
retrieving revision 1.242
diff -u -r1.242 win.c
--- windows/win.c	28 May 2004 19:35:37 -0000	1.242
+++ windows/win.c	2 Jun 2004 19:08:18 -0000
@@ -1759,7 +1759,7 @@
         WIN_SetStyle( hwnd, style | WS_DISABLED );
 
         focus_wnd = GetFocus();
-        if (hwnd == focus_wnd || IsChild(hwnd, focus_wnd))
+        if (hwnd == focus_wnd)
             SetFocus( 0 );  /* A disabled window can't have the focus */
 
         capture_wnd = GetCapture();
Index: dlls/user/tests/win.c
===================================================================
RCS file: /home/wine/wine/dlls/user/tests/win.c,v
retrieving revision 1.27
diff -u -r1.27 win.c
--- dlls/user/tests/win.c	1 Jun 2004 19:46:23 -0000	1.27
+++ dlls/user/tests/win.c	2 Jun 2004 19:08:19 -0000
@@ -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 );
 }
 
Index: dlls/user/tests/msg.c
===================================================================
RCS file: /home/wine/wine/dlls/user/tests/msg.c,v
retrieving revision 1.21
diff -u -r1.21 msg.c
--- dlls/user/tests/msg.c	1 Jun 2004 19:39:26 -0000	1.21
+++ dlls/user/tests/msg.c	2 Jun 2004 19:08:19 -0000
@@ -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)


More information about the wine-patches mailing list