diff --git a/dlls/user32/dialog.c b/dlls/user32/dialog.c index 0b33a579b5c..72e6eee02f1 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 631f3d3b2b5..8c9bd21482b 100644 --- a/dlls/user32/tests/dialog.c +++ b/dlls/user32/tests/dialog.c @@ -907,6 +907,56 @@ 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; +} + +static INT_PTR CALLBACK focusChildDlgWinProc (HWND hwnd, UINT uiMsg, WPARAM wParam, + LPARAM lParam) +{ + static HWND hChildDlg; + + 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 +1143,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)