Andrew Nguyen : user32: Ensure that WM_INITDIALOG passes the first tabstop control handle to the dialog procedure .

Alexandre Julliard julliard at winehq.org
Tue Feb 23 11:17:24 CST 2010


Module: wine
Branch: master
Commit: 0b2301286796df64959d910b4afb3609b6da3e41
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=0b2301286796df64959d910b4afb3609b6da3e41

Author: Andrew Nguyen <arethusa26 at gmail.com>
Date:   Tue Feb 23 01:16:18 2010 -0600

user32: Ensure that WM_INITDIALOG passes the first tabstop control handle to the dialog procedure.

---

 dlls/user32/dialog.c       |    9 ++++++---
 dlls/user32/tests/dialog.c |   18 ++++++++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/dlls/user32/dialog.c b/dlls/user32/dialog.c
index c7c9409..325d6e2 100644
--- a/dlls/user32/dialog.c
+++ b/dlls/user32/dialog.c
@@ -690,11 +690,14 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
 
         if (dlgProc)
         {
-            if (SendMessageW( hwnd, WM_INITDIALOG, (WPARAM)dlgInfo->hwndFocus, param ) &&
+            HWND focus = GetNextDlgTabItem( hwnd, 0, FALSE );
+            if (SendMessageW( hwnd, WM_INITDIALOG, (WPARAM)focus, param ) &&
                 ((~template.style & DS_CONTROL) || (template.style & WS_VISIBLE)))
             {
-                /* By returning TRUE, app has requested a default focus assignment */
-                dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE);
+                /* By returning TRUE, app has requested a default focus assignment.
+                 * WM_INITDIALOG may have changed the tab order, so find the first
+                 * tabstop control again. */
+                dlgInfo->hwndFocus = GetNextDlgTabItem( hwnd, 0, FALSE );
                 if( dlgInfo->hwndFocus )
                     SetFocus( dlgInfo->hwndFocus );
             }
diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c
index 204d854..c423f0b 100644
--- a/dlls/user32/tests/dialog.c
+++ b/dlls/user32/tests/dialog.c
@@ -926,6 +926,21 @@ static INT_PTR CALLBACK DestroyOnCloseDlgWinProc (HWND hDlg, UINT uiMsg,
     return FALSE;
 }
 
+static INT_PTR CALLBACK TestInitDialogHandleProc (HWND hDlg, UINT uiMsg,
+        WPARAM wParam, LPARAM lParam)
+{
+    if (uiMsg == WM_INITDIALOG)
+    {
+        HWND expected = GetNextDlgTabItem(hDlg, NULL, FALSE);
+        ok(expected == (HWND)wParam,
+           "Expected wParam to be the handle to the first tabstop control (%p), got %p\n",
+           expected, (HWND)wParam);
+
+        EndDialog(hDlg, LOWORD(SendMessage(hDlg, DM_GETDEFID, 0, 0)));
+        return TRUE;
+    }
+    return FALSE;
+}
 
 static INT_PTR CALLBACK TestDefButtonDlgProc (HWND hDlg, UINT uiMsg,
                                               WPARAM wParam, LPARAM lParam)
@@ -978,6 +993,9 @@ static void test_DialogBoxParamA(void)
        broken(GetLastError() == 0xdeadbeef),
        "got %d, expected ERROR_INVALID_WINDOW_HANDLE\n", GetLastError());
 
+    ret = DialogBoxParamA(GetModuleHandle(NULL), "TEST_EMPTY_DIALOG", 0, TestInitDialogHandleProc, 0);
+    ok(ret == IDOK, "Expected IDOK\n");
+
     ret = DialogBoxParamA(GetModuleHandle(NULL), "TEST_EMPTY_DIALOG", 0, TestDefButtonDlgProc, 0);
     ok(ret == IDOK, "Expected IDOK\n");
 }




More information about the wine-cvs mailing list