修改ComboBox有前导子串时,设置选择项不匹配的问题

This commit is contained in:
gb 2022-08-02 11:16:08 +08:00
parent d8f5e635fa
commit eb7b79621c
2 changed files with 20 additions and 1 deletions

View File

@ -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))
{

View File

@ -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);