From: Suresh Murty Subject: Comdlg32: Select initial text in edit control (try 2) Message-Id: Date: Fri, 13 Jul 2012 01:12:05 -0500 Sends a EM_SETSEL message after the initial text has been set. This fixes bug #24492. http://bugs.winehq.org/show_bug.cgi?id=24492 Sends a EM_SETSEL message after the initial text has been set.

This fixes bug #24492. http://bugs.winehq.org/show_bug.cgi?id=24492
From e0afd1b52483db732a3fee27b2c4be80b105eca8 Mon Sep 17 00:00:00 2001 From: Suresh Murty Date: Fri, 13 Jul 2012 00:53:34 -0500 Subject: Comdlg32: Select initial text in edit control (try 2). This is a fix for bug #24492 --- dlls/comdlg32/filedlg.c | 2 + dlls/comdlg32/tests/filedlg.c | 82 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 0 deletions(-) diff --git a/dlls/comdlg32/filedlg.c b/dlls/comdlg32/filedlg.c index 3e7ee4f..1a50cc5 100644 --- a/dlls/comdlg32/filedlg.c +++ b/dlls/comdlg32/filedlg.c @@ -1537,9 +1537,11 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) debugstr_w(fodInfos->filename), debugstr_w(fodInfos->initdir)); } SetDlgItemTextW(hwnd, IDC_FILENAME, fodInfos->filename); + SendMessageW(fodInfos->DlgInfos.hwndFileName, EM_SETSEL, 0, -1); } else { SetDlgItemTextW(hwnd, IDC_FILENAME, fodInfos->filename); + SendMessageW(fodInfos->DlgInfos.hwndFileName, EM_SETSEL, 0, -1); } } diff --git a/dlls/comdlg32/tests/filedlg.c b/dlls/comdlg32/tests/filedlg.c index c9bf52a..01066ab 100644 --- a/dlls/comdlg32/tests/filedlg.c +++ b/dlls/comdlg32/tests/filedlg.c @@ -1238,6 +1238,87 @@ static void test_null_filename(void) ok(ofnW.nFileExtension == 0, "ofnW.nFileExtension is 0x%x, should be 0\n", ofnW.nFileExtension); } +static BOOL WINAPI test_select_enum(HWND hwnd, LPARAM lParam) +{ + /* Find the textbox and check that it contains and selects the string "test"*/ + + CHAR className[20], filename[MAX_PATH] = {0}; + DWORD StartPos = 0xdeadbeef, EndPos = 0xdeadbeef; + INT ret; + HWND parent; + + parent = GetParent(hwnd); + + if(GetClassNameA(hwnd, className, sizeof(className)) > 0 && !strcmp("Edit",className)){ + + ret = GetWindowText(hwnd, filename, MAX_PATH); + ok(ret == 4, "Failed to read the filename, expected 4, got %d\n", ret); + + SendMessageA(hwnd, WM_GETTEXT, MAX_PATH, (LPARAM)filename); + ok(!strcmp("test",filename), "Expected: test, Found: %s\n", filename); + + SendMessageA(hwnd, EM_GETSEL, (WPARAM)&StartPos, (LPARAM)&EndPos); + ok(StartPos == 0, "The start position must be 0, but it was %u\n", StartPos); + ok(EndPos == 4, "The end position must be 4, but it was %u\n", EndPos); + + return FALSE; /*break window enumeration*/ + } + + return TRUE; +} + +static UINT_PTR WINAPI test_select_wndproc(HWND dlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + HWND parent = GetParent(dlg); + + if( msg == WM_TIMER) { + if(!wParam) { + EnumChildWindows( parent, test_select_enum, 0); + PostMessage( parent, WM_COMMAND, IDOK, 0); + } + else { + /* the dialog did not close automatically */ + KillTimer( dlg, 0); + PostMessage( parent, WM_COMMAND, IDCANCEL, 0); + } + } + if( msg == WM_NOTIFY) { + SetTimer( dlg, 0, 100, 0); + SetTimer( dlg, 1, 1000, 0); + } + return FALSE; +} + +/* Test for bug 24492*/ +static void test_select_filename(void) +{ + OPENFILENAMEA ofn = {0}; + BOOL result; + DWORD ret; + CHAR filename [MAX_PATH] = {"test"}; + + ofn.lStructSize = sizeof(OPENFILENAMEA); + ofn.hInstance = GetModuleHandleA(NULL); + ofn.lpstrFilter="Text Files\0*.txt\0All\0*\0\0"; + ofn.lpstrFile = filename; + ofn.nMaxFile = MAX_PATH; + ofn.lpstrFileTitle = NULL; + ofn.lpstrCustomFilter = NULL; + ofn.nFilterIndex = 1; + ofn.lpstrTitle = NULL; + ofn.Flags = OFN_EXPLORER|OFN_ENABLEHOOK; + ofn.lpstrDefExt = NULL; + ofn.lpfnHook = test_select_wndproc; + ofn.nFileOffset = 0xdead; + ofn.nFileExtension = 0xbeef; + + result = GetSaveFileNameA(&ofn); + ok(result, "Expected TRUE: GetLastError returned %#x\n", GetLastError()); + + ret = CommDlgExtendedError(); + ok(!ret, "CommDlgExtendedError returned %#x\n", ret); +} + START_TEST(filedlg) { test_DialogCancel(); @@ -1251,4 +1332,5 @@ START_TEST(filedlg) if( resizesupported) test_resizable2(); test_extension(); test_null_filename(); + test_select_filename(); } -- 1.7.0.4