From: Alistair Leslie-Hughes Subject: [PATCH v2] user32: Dont reset focus if current dialog is a child. Message-Id: Date: Fri, 14 Dec 2018 04:00:43 +0000 Regression of 44f89322ba8825a8e4851aaaf7de89910701ca75 The standard File Open Dialog, creates an empty WS_EX_CONTROLPARENT child dialog which shouldn't receive focus. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46215 Signed-off-by: Alistair Leslie-Hughes --- dlls/user32/dialog.c | 5 +++- dlls/user32/tests/dialog.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/dlls/user32/dialog.c b/dlls/user32/dialog.c index 0b33a57..72e6eee 100644 --- a/dlls/user32/dialog.c +++ b/dlls/user32/dialog.c @@ -692,7 +692,10 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate, SetFocus( focus ); } else - SetFocus( hwnd ); + { + if (!(template.style & WS_CHILD)) + SetFocus( hwnd ); + } } } diff --git a/dlls/user32/tests/dialog.c b/dlls/user32/tests/dialog.c index 631f3d3..ff6052f 100644 --- a/dlls/user32/tests/dialog.c +++ b/dlls/user32/tests/dialog.c @@ -907,6 +907,55 @@ static INT_PTR CALLBACK focusDlgWinProc (HWND hDlg, UINT uiMsg, WPARAM wParam, return FALSE; } +static INT_PTR CALLBACK EmptyProcUserTemplate(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch(uMsg) { + case WM_INITDIALOG: + return TRUE; + } + return FALSE; +} + +HWND hChildDlg = NULL; +static INT_PTR CALLBACK focusChildDlgWinProc (HWND hwnd, UINT uiMsg, WPARAM wParam, + LPARAM lParam) +{ + switch (uiMsg) + { + case WM_INITDIALOG: + { + RECT rectHwnd; + struct { + DLGTEMPLATE tmplate; + WORD menu,class,title; + } temp; + + SetFocus( GetDlgItem(hwnd, 200) ); + + GetClientRect(hwnd,&rectHwnd); + temp.tmplate.style = WS_CHILD | WS_CLIPSIBLINGS | WS_VISIBLE | DS_CONTROL | DS_3DLOOK; + temp.tmplate.dwExtendedStyle = 0; + temp.tmplate.cdit = 0; + temp.tmplate.x = 0; + temp.tmplate.y = 0; + temp.tmplate.cx = 0; + temp.tmplate.cy = 0; + temp.menu = temp.class = temp.title = 0; + + hChildDlg = CreateDialogIndirectParamA(g_hinst, &temp.tmplate, + hwnd, (DLGPROC)EmptyProcUserTemplate, 0); + ok(hChildDlg != 0, "Failed to create test dialog.\n"); + + return FALSE; + } + case WM_CLOSE: + DestroyWindow(hChildDlg); + return TRUE; + } + + return FALSE; +} + /* Helper for InitialFocusTest */ static const char * GetHwndString(HWND hw) { @@ -1093,6 +1142,29 @@ static void test_focus(void) DestroyWindow(hDlg); } + + /* Test 6: + * Select textbox's text on creation when WM_INITDIALOG creates a child dialog. */ + { + HWND hDlg; + HRSRC hResource; + HANDLE hTemplate; + DLGTEMPLATE* pTemplate; + HWND edit; + + hResource = FindResourceA(g_hinst,"FOCUS_TEST_DIALOG_3", (LPCSTR)RT_DIALOG); + hTemplate = LoadResource(g_hinst, hResource); + pTemplate = LockResource(hTemplate); + + hDlg = CreateDialogIndirectParamA(g_hinst, pTemplate, NULL, focusChildDlgWinProc, 0); + ok(hDlg != 0, "Failed to create test dialog.\n"); + edit = GetDlgItem(hDlg, 200); + + ok(GetFocus() == edit, "Focus not set to edit, focus=%p, dialog=%p, edit=%p\n", + GetFocus(), hDlg, edit); + + DestroyWindow(hDlg); + } } static void test_GetDlgItemText(void) -- 1.9.1