code_twain/sane/DlgInput.cpp

109 lines
2.4 KiB
C++
Raw Normal View History

// DlgIndicator.cpp: 实现文件
//
#include "DlgInput.h"
#include "resource.h"
#include "scanned_img.h" // for local_trans
#include "mem_dc.h"
#include "gb_json.h"
// CDlgIndicator 对话框
dlg_input::dlg_input(HWND parent, const wchar_t* init_val) : dlg_base(parent, IDD_INPUT), val_(init_val ? init_val : L"")
{
create();
std::wstring title(local_trans::lang_trans_between_hz936(CONST_STRING_INPUT_VAL));
SetWindowTextW(hwnd(), title.c_str());
title = local_trans::lang_trans_between_hz936(CONST_STRING_CANCEL);
set_item_text(IDCANCEL, title.c_str());
title = local_trans::lang_trans_between_hz936(CONST_STRING_OK);
set_item_text(IDOK, title.c_str());
}
dlg_input::~dlg_input()
{
}
BOOL dlg_input::handle_message(UINT msg, WPARAM wp, LPARAM lp)
{
wchar_t text[40] = { 0 };
BOOL ret = TRUE;
switch (msg)
{
case WM_INITDIALOG:
on_init_dlg();
UpdateWindow(hwnd());
break;
case WM_COMMAND:
handle_command(HIWORD(wp), LOWORD(wp), (HWND)lp);
break;
default:
ret = FALSE;
}
return ret;
}
void dlg_input::handle_command(WORD code, WORD id, HANDLE ctrl)
{
wchar_t cls[128] = { 0 };
GetClassNameW((HWND)ctrl, cls, _countof(cls) - 1);
if (IS_BUTTON(cls))
{
if (code == BN_CLICKED)
{
if (id == IDOK || id == IDCANCEL)
{
if (id == IDOK)
{
std::wstring input(dlg_base::get_item_text(IDC_EDIT1));
if (input.empty())
{
MessageBoxW(hwnd(), local_trans::lang_trans_between_hz936(CONST_STRING_RE_INPUT).c_str(), local_trans::lang_trans_between_hz936(CONST_STRING_NO_INPUT).c_str(), MB_OK | MB_ICONSTOP);
SetFocus(get_item(IDC_EDIT1));
return;
}
for (auto& v : no_repeats_)
{
if (v == input)
{
input += L" " + local_trans::lang_trans_between_hz936(CONST_STRING_ALREADY_EXISTS);
::MessageBoxW(hwnd(), input.c_str(), local_trans::lang_trans_between_hz936(CONST_STRING_RE_INPUT).c_str(), MB_OK | MB_ICONINFORMATION);
SetFocus(get_item(IDC_EDIT1));
return;
}
}
val_ = std::move(input);
}
quit_modal(id);
}
}
}
else if (IS_EDIT(cls))
{
//if (code == EN_SETFOCUS)
// label_edit_ = (HWND)ctrl;
}
}
void dlg_input::on_init_dlg(void)
{
dlg_base::set_item_text(IDC_EDIT1, val_.c_str());
}
void dlg_input::set_no_repeats(const std::vector<std::wstring>& vals)
{
no_repeats_ = vals;
}
std::wstring dlg_input::get_value(void)
{
return val_;
}