diff --git a/sane/DlgPage.cpp b/sane/DlgPage.cpp index 55c3f0d..d293ad5 100644 --- a/sane/DlgPage.cpp +++ b/sane/DlgPage.cpp @@ -102,6 +102,24 @@ bool dlg_base::get_max_size(SIZE& dst, int cx, int cy) return changed; } +int dlg_base::select_combo_text(HWND combo, const wchar_t* text) +{ + int ind = SendMessageW(combo, CB_SELECTSTRING, -1, (LPARAM)text), + ret = ind; + + while (ind >= 0) + { + wchar_t buf[256] = { 0 }; + GetWindowTextW(combo, buf, _countof(buf) - 1); + if (wcsicmp(buf, text) == 0) + break; + + ret = ind; + ind = SendMessageW(combo, CB_SELECTSTRING, ret, (LPARAM)text); + } + + return ret; +} BOOL dlg_base::handle_message(UINT msg, WPARAM wp, LPARAM lp) { @@ -821,7 +839,7 @@ void dlg_page::set_ctrl_value(HWND ctrl, SANE_Value_Type type, void* val, bool o if (IS_EDIT(cls)) SetWindowTextW(ctrl, text.c_str()); else - SendMessageW(ctrl, CB_SELECTSTRING, 0, (LPARAM)text.c_str()); + dlg_base::select_combo_text(ctrl, text.c_str()); } else if (IS_UPDOWN_ARROW(cls)) { diff --git a/sane/DlgPage.h b/sane/DlgPage.h index d7a769b..35511bf 100644 --- a/sane/DlgPage.h +++ b/sane/DlgPage.h @@ -43,6 +43,7 @@ public: static bool get_max_size(SIZE& dst, const SIZE& src); // return whether changed dst static bool get_max_size(SIZE& dst, int cx, int cy); // return whether changed dst + static int select_combo_text(HWND combo, const wchar_t* text); public: void set_ui_event_notify(void(__stdcall* notify)(int, void*, void*), void* param);