add hg-helper tool, to find error message and advanced configurations
This commit is contained in:
parent
eb17ea2ff4
commit
cb16c2bc6e
BIN
docs/扫描仪配置属性.doc
BIN
docs/扫描仪配置属性.doc
Binary file not shown.
|
@ -0,0 +1,679 @@
|
||||||
|
// DlgIndicator.cpp: 实现文件
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "DlgBase.h"
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
// #pragma comment(linker,"\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
|
||||||
|
|
||||||
|
#pragma warning(disable: 4996)
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
|
||||||
|
static IMPLEMENT_OPTION_STRING_COMPARE(is_sane_opt);
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// dlg_base 对话框
|
||||||
|
extern HMODULE g_my_inst;
|
||||||
|
|
||||||
|
std::wstring dlg_base::prop_name = L"dlg_base_object_prop_name";
|
||||||
|
|
||||||
|
dlg_base::dlg_base(HWND parent, UINT idd) : parent_(parent), hwnd_(NULL), idd_(idd), ui_event_notify_(NULL), ui_notify_param_(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
dlg_base::~dlg_base()
|
||||||
|
{
|
||||||
|
if (IsWindow(hwnd_))
|
||||||
|
{
|
||||||
|
SetPropW(hwnd_, dlg_base::prop_name.c_str(), NULL);
|
||||||
|
//if (GetCurrentThreadId() == GetWindowThreadProcessId(hwnd_, NULL))
|
||||||
|
DestroyWindow(hwnd_);
|
||||||
|
}
|
||||||
|
EnableWindow(parent_, TRUE);
|
||||||
|
BringWindowToTop(parent_);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL CALLBACK dlg_base::dlg_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||||
|
{
|
||||||
|
if (msg == WM_INITDIALOG)
|
||||||
|
{
|
||||||
|
dlg_base* obj = (dlg_base*)lp;
|
||||||
|
|
||||||
|
SetPropW(hwnd, dlg_base::prop_name.c_str(), (HANDLE)obj);
|
||||||
|
obj->hwnd_ = hwnd;
|
||||||
|
}
|
||||||
|
else if (msg == WM_DESTROY)
|
||||||
|
{
|
||||||
|
dlg_base* obj = (dlg_base*)GetPropW(hwnd, dlg_base::prop_name.c_str());
|
||||||
|
SetPropW(hwnd, dlg_base::prop_name.c_str(), NULL);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
dlg_base *obj = (dlg_base*)GetPropW(hwnd, dlg_base::prop_name.c_str());
|
||||||
|
BOOL ret = FALSE;
|
||||||
|
|
||||||
|
if (obj)
|
||||||
|
{
|
||||||
|
ret = obj->handle_message(msg, wp, lp);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dlg_base::screen_2_client(HWND wnd, LPRECT r)
|
||||||
|
{
|
||||||
|
POINT pt = { r->left, r->top };
|
||||||
|
|
||||||
|
ScreenToClient(wnd, &pt);
|
||||||
|
OffsetRect(r, pt.x - r->left, pt.y - r->top);
|
||||||
|
}
|
||||||
|
void dlg_base::client_2_screen(HWND wnd, LPRECT r)
|
||||||
|
{
|
||||||
|
POINT pt = { r->left, r->top };
|
||||||
|
|
||||||
|
ClientToScreen(wnd, &pt);
|
||||||
|
OffsetRect(r, pt.x - r->left, pt.y - r->top);
|
||||||
|
}
|
||||||
|
bool dlg_base::get_max_size(SIZE& dst, const SIZE& src)
|
||||||
|
{
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
|
if (dst.cx < src.cx)
|
||||||
|
{
|
||||||
|
dst.cx = src.cx;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (dst.cy < src.cy)
|
||||||
|
{
|
||||||
|
dst.cy = src.cy;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
bool dlg_base::get_max_size(SIZE& dst, int cx, int cy)
|
||||||
|
{
|
||||||
|
bool changed = false;
|
||||||
|
|
||||||
|
if (dst.cx < cx)
|
||||||
|
{
|
||||||
|
dst.cx = cx;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
if (dst.cy < cy)
|
||||||
|
{
|
||||||
|
dst.cy = cy;
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
std::wstring dlg_base::get_wnd_text(HWND h)
|
||||||
|
{
|
||||||
|
int len = GetWindowTextLengthW(h);
|
||||||
|
wchar_t* buf = new wchar_t[len + 8];
|
||||||
|
std::wstring ret(L"");
|
||||||
|
|
||||||
|
memset(buf, 0, (len + 8) * 2);
|
||||||
|
GetWindowTextW(h, buf, len + 2);
|
||||||
|
ret = buf;
|
||||||
|
delete[] buf;
|
||||||
|
|
||||||
|
return std::move(ret);
|
||||||
|
}
|
||||||
|
std::wstring dlg_base::get_menu_text(HMENU menu, int ind)
|
||||||
|
{
|
||||||
|
MENUITEMINFOW mi = { 0 };
|
||||||
|
wchar_t text[128] = { 0 };
|
||||||
|
|
||||||
|
mi.cbSize = sizeof(mi);
|
||||||
|
mi.fMask = mi.fType = MIIM_STRING; // MFT_STRING;
|
||||||
|
mi.dwTypeData = text;
|
||||||
|
mi.cch = _countof(text) - 1;
|
||||||
|
GetMenuItemInfoW(menu, ind, MF_BYPOSITION, &mi);
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
void dlg_base::center_window(HWND wnd, HWND parent)
|
||||||
|
{
|
||||||
|
RECT rme = { 0 }, rp = { 0 };
|
||||||
|
int x = 0, y = 0;
|
||||||
|
|
||||||
|
GetWindowRect(wnd, &rme);
|
||||||
|
if (!IsWindow(parent))
|
||||||
|
parent = GetDesktopWindow();
|
||||||
|
GetWindowRect(parent, &rp);
|
||||||
|
x = rp.left + (RECT_W(rp) - RECT_W(rme)) / 2;
|
||||||
|
y = rp.top + (RECT_H(rp) - RECT_H(rme)) / 2;
|
||||||
|
OffsetRect(&rme, x - rme.left, y - rme.top);
|
||||||
|
MoveWindow(wnd, rme.left, rme.top, RECT_W(rme), RECT_H(rme), FALSE);
|
||||||
|
}
|
||||||
|
int dlg_base::get_combox_cur_sel(HWND wnd)
|
||||||
|
{
|
||||||
|
return SendMessageW(wnd, CB_GETCURSEL, 0, 0);
|
||||||
|
}
|
||||||
|
int dlg_base::get_button_check(HWND wnd)
|
||||||
|
{
|
||||||
|
return SendMessageW(wnd, BM_GETCHECK, 0, 0);
|
||||||
|
}
|
||||||
|
int dlg_base::list_insert_column(HWND list_wnd, const wchar_t* text, int cx, int ind)
|
||||||
|
{
|
||||||
|
LVCOLUMNW col = { 0 };
|
||||||
|
|
||||||
|
if (ind == -1)
|
||||||
|
ind = dlg_base::list_get_column_count(list_wnd);
|
||||||
|
col.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
|
||||||
|
col.pszText = (LPWSTR)text;
|
||||||
|
col.iSubItem = 0;
|
||||||
|
col.cx = cx;
|
||||||
|
|
||||||
|
return ListView_InsertColumn(list_wnd, ind, &col);
|
||||||
|
}
|
||||||
|
int dlg_base::list_insert_item(HWND list_wnd, const wchar_t* text, int ind)
|
||||||
|
{
|
||||||
|
LV_ITEMW item = { 0 };
|
||||||
|
|
||||||
|
if (ind == -1)
|
||||||
|
ind = dlg_base::list_get_item_count(list_wnd);
|
||||||
|
item.mask = LVIF_TEXT;
|
||||||
|
item.pszText = (PWSTR)text;
|
||||||
|
item.iItem = ind;
|
||||||
|
|
||||||
|
return ListView_InsertItem(list_wnd, &item);
|
||||||
|
}
|
||||||
|
int dlg_base::list_get_item_count(HWND list_wnd)
|
||||||
|
{
|
||||||
|
return ListView_GetItemCount(list_wnd);
|
||||||
|
}
|
||||||
|
int dlg_base::list_get_column_count(HWND list_wnd)
|
||||||
|
{
|
||||||
|
return ListView_GetItemCount((HWND)ListView_GetHeader(list_wnd));
|
||||||
|
}
|
||||||
|
std::wstring dlg_base::list_get_text(HWND list_wnd, int ind, int sub)
|
||||||
|
{
|
||||||
|
LV_ITEMW item = { 0 };
|
||||||
|
wchar_t text[128] = { 0 };
|
||||||
|
|
||||||
|
item.mask = LVIF_TEXT;
|
||||||
|
item.pszText = (PWSTR)text;
|
||||||
|
item.iItem = ind;
|
||||||
|
item.iSubItem = sub;
|
||||||
|
item.cchTextMax = _countof(text) - 1;
|
||||||
|
ListView_GetItem(list_wnd, &item);
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
void dlg_base::list_get_selected_items(HWND list_wnd, std::vector<int>& sels)
|
||||||
|
{
|
||||||
|
LV_ITEMW item = { 0 };
|
||||||
|
|
||||||
|
item.mask = LVIF_STATE;
|
||||||
|
for (int i = 0; i < dlg_base::list_get_item_count(list_wnd); ++i)
|
||||||
|
{
|
||||||
|
item.iItem = i;
|
||||||
|
item.stateMask = LVIS_SELECTED;
|
||||||
|
ListView_GetItem(list_wnd, &item);
|
||||||
|
if (item.state & LVIS_SELECTED)
|
||||||
|
sels.push_back(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int dlg_base::list_set_item_text(HWND list_wnd, int item, int sub_item, const wchar_t* text)
|
||||||
|
{
|
||||||
|
LV_ITEMW lvi = { 0 };
|
||||||
|
|
||||||
|
lvi.iItem = item;
|
||||||
|
lvi.iSubItem = sub_item;
|
||||||
|
lvi.pszText = (LPWSTR)text;
|
||||||
|
lvi.mask = LVIF_TEXT;
|
||||||
|
|
||||||
|
return ListView_SetItem(list_wnd, &lvi) ? 0 : 1;
|
||||||
|
}
|
||||||
|
int dlg_base::get_tab_count(HWND tab)
|
||||||
|
{
|
||||||
|
int count = -1;
|
||||||
|
|
||||||
|
if (IsWindow(tab))
|
||||||
|
count = TabCtrl_GetItemCount(tab);
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
int dlg_base::insert_page_to_tab(HWND tab, dlg_base* page, const wchar_t* title)
|
||||||
|
{
|
||||||
|
TC_ITEMW item = { 0 };
|
||||||
|
int ind = 0;
|
||||||
|
std::wstring t(title);
|
||||||
|
|
||||||
|
item.mask = TCIF_PARAM | TCIF_TEXT;
|
||||||
|
item.lParam = (LPARAM)page;
|
||||||
|
item.pszText = &t[0];
|
||||||
|
ind = TabCtrl_InsertItem(tab, dlg_base::get_tab_count(tab), &item);
|
||||||
|
|
||||||
|
return ind;
|
||||||
|
}
|
||||||
|
void* dlg_base::get_tab_item_data(HWND tab, int index)
|
||||||
|
{
|
||||||
|
TCITEMW item = { 0 };
|
||||||
|
|
||||||
|
item.mask = TCIF_PARAM;
|
||||||
|
TabCtrl_GetItem(tab, index, &item);
|
||||||
|
|
||||||
|
return (void*)item.lParam;
|
||||||
|
}
|
||||||
|
std::string dlg_base::u2m(const wchar_t* u, int page)
|
||||||
|
{
|
||||||
|
char* ansi = NULL;
|
||||||
|
int len = 0;
|
||||||
|
std::string mb("");
|
||||||
|
|
||||||
|
len = WideCharToMultiByte(page, 0, u, lstrlenW(u), NULL, 0, NULL, NULL);
|
||||||
|
ansi = new char[len + 2];
|
||||||
|
len = WideCharToMultiByte(page, 0, u, lstrlenW(u), ansi, len, NULL, NULL);
|
||||||
|
ansi[len--] = 0;
|
||||||
|
mb = ansi;
|
||||||
|
delete[] ansi;
|
||||||
|
|
||||||
|
return mb;
|
||||||
|
}
|
||||||
|
std::wstring dlg_base::m2u(const char* m, int page)
|
||||||
|
{
|
||||||
|
wchar_t* unic = NULL;
|
||||||
|
int len = 0;
|
||||||
|
std::wstring u(L"");
|
||||||
|
|
||||||
|
len = MultiByteToWideChar(page, 0, m, lstrlenA(m), NULL, 0);
|
||||||
|
unic = new wchar_t[len + 2];
|
||||||
|
len = MultiByteToWideChar(page, 0, m, lstrlenA(m), unic, len);
|
||||||
|
unic[len--] = 0;
|
||||||
|
u = unic;
|
||||||
|
delete[] unic;
|
||||||
|
|
||||||
|
return u;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL dlg_base::handle_message(UINT msg, WPARAM wp, LPARAM lp)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
void dlg_base::on_font_changed(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
void dlg_base::create(void)
|
||||||
|
{
|
||||||
|
// InitCommonControls();
|
||||||
|
hwnd_ = CreateDialogParamW(g_my_inst, MAKEINTRESOURCE(idd_), parent_, (DLGPROC)&dlg_base::dlg_proc, (LPARAM)this);
|
||||||
|
}
|
||||||
|
void dlg_base::notify_ui_event(int ev)
|
||||||
|
{
|
||||||
|
if (ui_event_notify_)
|
||||||
|
ui_event_notify_(ev, this, ui_notify_param_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void dlg_base::set_ui_event_notify(void(__stdcall* notify)(int, void*, void*), void* param)
|
||||||
|
{
|
||||||
|
ui_event_notify_ = notify;
|
||||||
|
ui_notify_param_ = param;
|
||||||
|
}
|
||||||
|
HWND dlg_base::hwnd(void)
|
||||||
|
{
|
||||||
|
return hwnd_;
|
||||||
|
}
|
||||||
|
void dlg_base::show(bool visible, bool hold)
|
||||||
|
{
|
||||||
|
UINT cmd = visible ? SW_SHOW : SW_HIDE;
|
||||||
|
DWORD style = GetWindowLong(hwnd_, GWL_STYLE);
|
||||||
|
|
||||||
|
if (!(style & WS_CHILD))
|
||||||
|
{
|
||||||
|
if (visible)
|
||||||
|
{
|
||||||
|
RECT r0 = { 0 }, rp = { 0 }, rme = { 0 };
|
||||||
|
POINT pt = { 0 };
|
||||||
|
HWND after = HWND_TOP;
|
||||||
|
|
||||||
|
if (IsWindow(parent_))
|
||||||
|
{
|
||||||
|
HMONITOR mon = MonitorFromWindow(parent_, MONITOR_DEFAULTTOPRIMARY);
|
||||||
|
MONITORINFO mi = { 0 };
|
||||||
|
|
||||||
|
mi.cbSize = sizeof(mi);
|
||||||
|
GetMonitorInfoW(mon, &mi);
|
||||||
|
r0 = mi.rcWork;
|
||||||
|
GetWindowRect(parent_, &rp);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
GetWindowRect(GetDesktopWindow(), &r0);
|
||||||
|
rp = r0;
|
||||||
|
after = HWND_TOPMOST;
|
||||||
|
}
|
||||||
|
GetWindowRect(hwnd_, &rme);
|
||||||
|
pt.x = rp.left + (RECT_W(rp) - RECT_W(rme)) / 2;
|
||||||
|
pt.y = rp.top + (RECT_H(rp) - RECT_H(rme)) / 2;
|
||||||
|
if (pt.x + RECT_W(rme) > r0.right)
|
||||||
|
pt.x = r0.right - RECT_W(rme);
|
||||||
|
if (pt.x < r0.left)
|
||||||
|
pt.x = r0.left;
|
||||||
|
if (pt.y + RECT_H(rme) > r0.bottom)
|
||||||
|
pt.y = r0.bottom - RECT_H(rme);
|
||||||
|
if (pt.y < r0.top)
|
||||||
|
pt.y = r0.top;
|
||||||
|
SetWindowPos(hwnd_, after, pt.x, pt.y, RECT_W(rme), RECT_H(rme), SWP_NOSIZE);
|
||||||
|
UpdateWindow(hwnd_);
|
||||||
|
}
|
||||||
|
EnableWindow(parent_, !visible);
|
||||||
|
}
|
||||||
|
ShowWindow(hwnd_, cmd);
|
||||||
|
|
||||||
|
if (hold)
|
||||||
|
{
|
||||||
|
MSG msg = { 0 };
|
||||||
|
BOOL ret = FALSE;
|
||||||
|
|
||||||
|
abandon_hold_ = false;
|
||||||
|
while ((ret = GetMessageW(&msg, NULL, 0, 0)))
|
||||||
|
{
|
||||||
|
if (ret == -1 || abandon_hold_)
|
||||||
|
break;
|
||||||
|
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
DispatchMessageW(&msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int dlg_base::do_modal(HWND parent)
|
||||||
|
{
|
||||||
|
BOOL enable_parent = FALSE,
|
||||||
|
got = TRUE;
|
||||||
|
MSG msg = { 0 };
|
||||||
|
|
||||||
|
modal_exit_ = 0;
|
||||||
|
if (IsWindow(parent) && parent != GetDesktopWindow())
|
||||||
|
{
|
||||||
|
EnableWindow(parent, FALSE);
|
||||||
|
enable_parent = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
dlg_base::center_window(hwnd(), parent);
|
||||||
|
ShowWindow(hwnd(), SW_SHOW);
|
||||||
|
while ((got = GetMessage(&msg, NULL, 0, 0)))
|
||||||
|
{
|
||||||
|
if ((DWORD)got == -1)
|
||||||
|
break;
|
||||||
|
|
||||||
|
//if (enable_parent && msg.hwnd == parent &&
|
||||||
|
// msg.message >= WM_MOUSEFIRST && msg.message <= WM_MOUSELAST &&
|
||||||
|
// msg.message >= WM_KEYFIRST && msg.message <= WM_KEYLAST)
|
||||||
|
// continue;
|
||||||
|
|
||||||
|
TranslateMessage(&msg);
|
||||||
|
DispatchMessage(&msg);
|
||||||
|
if (modal_exit_)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ShowWindow(hwnd(), SW_HIDE);
|
||||||
|
|
||||||
|
if (enable_parent)
|
||||||
|
{
|
||||||
|
EnableWindow(parent, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return modal_exit_;
|
||||||
|
}
|
||||||
|
void dlg_base::quit_modal(int non_zero_code)
|
||||||
|
{
|
||||||
|
// assert ( non_zero_code );
|
||||||
|
modal_exit_ = non_zero_code;
|
||||||
|
}
|
||||||
|
void dlg_base::enable(bool enable)
|
||||||
|
{
|
||||||
|
EnableWindow(hwnd_, enable);
|
||||||
|
}
|
||||||
|
void dlg_base::screen_2_client(LPRECT r)
|
||||||
|
{
|
||||||
|
POINT pt = { r->left, r->top };
|
||||||
|
|
||||||
|
ScreenToClient(hwnd_, &pt);
|
||||||
|
OffsetRect(r, pt.x - r->left, pt.y - r->top);
|
||||||
|
}
|
||||||
|
void dlg_base::client_2_screen(LPRECT r)
|
||||||
|
{
|
||||||
|
POINT pt = { r->left, r->top };
|
||||||
|
|
||||||
|
ClientToScreen(hwnd_, &pt);
|
||||||
|
OffsetRect(r, pt.x - r->left, pt.y - r->top);
|
||||||
|
}
|
||||||
|
HWND dlg_base::get_item(UINT id)
|
||||||
|
{
|
||||||
|
return GetDlgItem(hwnd_, id);
|
||||||
|
}
|
||||||
|
BOOL dlg_base::set_font(HFONT font)
|
||||||
|
{
|
||||||
|
BOOL ret = SendMessage(hwnd_, WM_SETFONT, (WPARAM)font, 1) == 0;
|
||||||
|
|
||||||
|
if (ret)
|
||||||
|
on_font_changed();
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
HFONT dlg_base::get_font(void)
|
||||||
|
{
|
||||||
|
return (HFONT)SendMessage(hwnd_, WM_GETFONT, 0, 0);
|
||||||
|
}
|
||||||
|
int dlg_base::get_string_width(const wchar_t* str, HWND wnd)
|
||||||
|
{
|
||||||
|
if (!wnd)
|
||||||
|
wnd = hwnd_;
|
||||||
|
|
||||||
|
HDC hdc = GetWindowDC(wnd);
|
||||||
|
SIZE size = { 0 };
|
||||||
|
|
||||||
|
GetTextExtentPointW(hdc, str, lstrlenW(str), &size);
|
||||||
|
ReleaseDC(wnd, hdc);
|
||||||
|
|
||||||
|
return size.cx;
|
||||||
|
}
|
||||||
|
bool dlg_base::get_item_rect(UINT id, LPRECT r, bool client)
|
||||||
|
{
|
||||||
|
if (client)
|
||||||
|
return GetClientRect(GetDlgItem(hwnd_, id), r) == TRUE;
|
||||||
|
else
|
||||||
|
return GetWindowRect(GetDlgItem(hwnd_, id), r) == TRUE;
|
||||||
|
}
|
||||||
|
std::wstring dlg_base::get_item_text(UINT id)
|
||||||
|
{
|
||||||
|
return std::move(dlg_base::get_wnd_text(get_item(id)));
|
||||||
|
}
|
||||||
|
int dlg_base::get_width_diff_as_text_length(UINT id)
|
||||||
|
{
|
||||||
|
RECT r = { 0 };
|
||||||
|
|
||||||
|
get_item_rect(id, &r);
|
||||||
|
|
||||||
|
return get_string_width(get_item_text(id).c_str()) - RECT_W(r);
|
||||||
|
}
|
||||||
|
void dlg_base::offset_item(HWND wnd, int dx, int dy)
|
||||||
|
{
|
||||||
|
RECT r = { 0 };
|
||||||
|
|
||||||
|
GetWindowRect(wnd, &r);
|
||||||
|
OffsetRect(&r, dx, dy);
|
||||||
|
screen_2_client(&r);
|
||||||
|
MoveWindow(wnd, r.left, r.top, RECT_W(r), RECT_H(r), FALSE);
|
||||||
|
}
|
||||||
|
void dlg_base::offset_item(UINT id, int dx, int dy)
|
||||||
|
{
|
||||||
|
offset_item(get_item(id), dx, dy);
|
||||||
|
}
|
||||||
|
void dlg_base::expand_item(UINT id, int dx, int dy)
|
||||||
|
{
|
||||||
|
RECT r = { 0 };
|
||||||
|
|
||||||
|
get_item_rect(id, &r, false);
|
||||||
|
r.right += dx;
|
||||||
|
r.bottom += dy;
|
||||||
|
screen_2_client(&r);
|
||||||
|
MoveWindow(get_item(id), r.left, r.top, RECT_W(r), RECT_H(r), FALSE);
|
||||||
|
}
|
||||||
|
bool dlg_base::set_item_text(UINT id, const wchar_t* text)
|
||||||
|
{
|
||||||
|
return SetWindowTextW(GetDlgItem(hwnd_, id), text) == TRUE;
|
||||||
|
}
|
||||||
|
int dlg_base::set_item_fit_to_text(UINT id)
|
||||||
|
{
|
||||||
|
HWND wnd = get_item(id);
|
||||||
|
std::wstring text(get_item_text(id));
|
||||||
|
RECT r = { 0 };
|
||||||
|
int w = get_string_width(text.c_str(), wnd);
|
||||||
|
|
||||||
|
get_item_rect(id, &r, false);
|
||||||
|
if (w > RECT_W(r) || w <= RECT_W(r) / 2)
|
||||||
|
{
|
||||||
|
if (w > RECT_W(r))
|
||||||
|
w -= RECT_W(r);
|
||||||
|
else
|
||||||
|
w -= RECT_W(r) / 2;
|
||||||
|
expand_item(id, w, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
w = 0;
|
||||||
|
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
void dlg_base::show_scroll_bar(int bar, bool show)
|
||||||
|
{
|
||||||
|
DWORD style = GetWindowLong(hwnd(), GWL_STYLE);
|
||||||
|
if (bar == SB_VERT || bar == SB_BOTH)
|
||||||
|
{
|
||||||
|
if (show)
|
||||||
|
style |= WS_VSCROLL;
|
||||||
|
else
|
||||||
|
style &= ~WS_VSCROLL;
|
||||||
|
SetWindowLong(hwnd(), GWL_STYLE, style);
|
||||||
|
}
|
||||||
|
else if (bar == SB_HORZ || bar == SB_BOTH)
|
||||||
|
{
|
||||||
|
if (show)
|
||||||
|
style |= WS_HSCROLL;
|
||||||
|
else
|
||||||
|
style &= ~WS_HSCROLL;
|
||||||
|
SetWindowLong(hwnd(), GWL_STYLE, style);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool dlg_base::track_mouse_hover(void)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
TRACKMOUSEEVENT tme = { 0 };
|
||||||
|
|
||||||
|
tme.cbSize = sizeof(tme);
|
||||||
|
tme.dwFlags = TME_HOVER;
|
||||||
|
tme.dwHoverTime = HOVER_DEFAULT;
|
||||||
|
tme.hwndTrack = hwnd_;
|
||||||
|
|
||||||
|
return TrackMouseEvent(&tme);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// tooltip_wnd
|
||||||
|
tooltip_wnd::tooltip_wnd() : hwnd_(NULL), parent_(NULL)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
tooltip_wnd::~tooltip_wnd()
|
||||||
|
{
|
||||||
|
DestroyWindow(hwnd_);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tooltip_wnd::create(HWND parent)
|
||||||
|
{
|
||||||
|
if (!IsWindow(hwnd_))
|
||||||
|
{
|
||||||
|
parent_ = parent;
|
||||||
|
hwnd_ = CreateWindowExW(NULL, TOOLTIPS_CLASSW, NULL,
|
||||||
|
WS_POPUP | TTS_ALWAYSTIP | TTS_BALLOON,
|
||||||
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||||
|
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||||
|
parent_, NULL,
|
||||||
|
GetModuleHandle(NULL), NULL);
|
||||||
|
SetWindowPos(hwnd_, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
return IsWindow(hwnd_);
|
||||||
|
}
|
||||||
|
void tooltip_wnd::enable(bool enabled)
|
||||||
|
{
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool tooltip_wnd::add_tool_tip_for_rect(const RECT& r, const wchar_t* tips)
|
||||||
|
{
|
||||||
|
TTTOOLINFOW toolInfo = { 0 };
|
||||||
|
|
||||||
|
toolInfo.cbSize = sizeof(toolInfo) - sizeof(toolInfo.lpReserved); // TOOLTIPS_CLASSW in old style, not with member 'lpReserved'
|
||||||
|
toolInfo.hwnd = parent_;
|
||||||
|
toolInfo.uFlags = TTF_SUBCLASS;
|
||||||
|
toolInfo.lpszText = (wchar_t*)(DWORD_PTR)tips; // LPSTR_TEXTCALLBACK - WM_NOTIFY.TTN_GETDISPINFO
|
||||||
|
toolInfo.hinst = GetModuleHandle(NULL);
|
||||||
|
memcpy(&toolInfo.rect, &r, sizeof(toolInfo.rect));
|
||||||
|
|
||||||
|
return SendMessageW(hwnd_, TTM_ADDTOOL, 0, (LPARAM)&toolInfo) == TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tooltip_wnd::add_tool_tip_for_ctrl(HWND ctrl, const wchar_t* tips)
|
||||||
|
{
|
||||||
|
TTTOOLINFOW toolInfo = { 0 };
|
||||||
|
|
||||||
|
toolInfo.cbSize = sizeof(toolInfo) - sizeof(toolInfo.lpReserved); // TOOLTIPS_CLASSW in old style, not with member 'lpReserved'
|
||||||
|
toolInfo.hwnd = parent_;
|
||||||
|
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
|
||||||
|
toolInfo.uId = (UINT_PTR)ctrl;
|
||||||
|
toolInfo.lpszText = (wchar_t*)(DWORD_PTR)tips; // LPSTR_TEXTCALLBACK - WM_NOTIFY.TTN_GETDISPINFO
|
||||||
|
toolInfo.hinst = GetModuleHandle(NULL);
|
||||||
|
|
||||||
|
return SendMessageW(hwnd_, TTM_ADDTOOL, 0, (LPARAM)&toolInfo) == TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool tooltip_wnd::remove_tool_tip_for_ctrl(HWND ctrl)
|
||||||
|
{
|
||||||
|
TTTOOLINFOW toolInfo = { 0 };
|
||||||
|
|
||||||
|
toolInfo.cbSize = sizeof(toolInfo) - sizeof(toolInfo.lpReserved); // TOOLTIPS_CLASSW in old style, not with member 'lpReserved'
|
||||||
|
toolInfo.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
|
||||||
|
toolInfo.hwnd = parent_;
|
||||||
|
toolInfo.uId = (UINT_PTR)ctrl;
|
||||||
|
|
||||||
|
return SendMessageW(hwnd_, TTM_DELTOOL, 0, (LPARAM)&toolInfo) == TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//
|
|
@ -0,0 +1,145 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <CommCtrl.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <sane/sane_ex.h>
|
||||||
|
#include <sane/sane_option_definitions.h>
|
||||||
|
|
||||||
|
// CDlgIndicator 对话框
|
||||||
|
#define FLOAT_FORMAT L"%.2f"
|
||||||
|
#define IS_STR_EQUAL(s1, s2) (wcscmp(s1, s2) == 0)
|
||||||
|
#define IS_EDIT(cls) IS_STR_EQUAL(cls, WC_EDITW)
|
||||||
|
#define IS_COMBOX(cls) IS_STR_EQUAL(cls, WC_COMBOBOXW)
|
||||||
|
#define IS_BUTTON(cls) IS_STR_EQUAL(cls, WC_BUTTONW)
|
||||||
|
#define IS_TRACKBAR(cls) IS_STR_EQUAL(cls, TRACKBAR_CLASSW)
|
||||||
|
#define IS_UPDOWN_ARROW(cls) IS_STR_EQUAL(cls, UPDOWN_CLASSW)
|
||||||
|
|
||||||
|
#define RECT_W(r) (r.right - r.left)
|
||||||
|
#define RECT_H(r) (r.bottom - r.top)
|
||||||
|
|
||||||
|
#define WM_SCAN_WORKING WM_USER + 301 // WPARAM: unused; LPARAM: unsed
|
||||||
|
#define WM_USB_PACKET_RECEIVED WM_USER + 302
|
||||||
|
#define WM_IMAGE_RECEIVED WM_USER + 303
|
||||||
|
#define WM_SCAN_FINISHED WM_USER + 304 // WPARAM: std::string* msg; LPARAM: boo err
|
||||||
|
#define WM_REFRESH_OPTION WM_USER + 311 // WPARAM: source option SN, LPARAM: unused now
|
||||||
|
#define WM_GET_CONFIG_OBJ WM_USER + 312 // WPARAM: bool*, [in]create new if NULL; [out]created, LPARAM: to receive the gb::sane_config_schm* object
|
||||||
|
|
||||||
|
|
||||||
|
class dlg_base
|
||||||
|
{
|
||||||
|
int modal_exit_; // set non-ZERO code to exit modal dialog
|
||||||
|
|
||||||
|
protected:
|
||||||
|
HWND hwnd_;
|
||||||
|
HWND parent_;
|
||||||
|
UINT idd_;
|
||||||
|
bool abandon_hold_;
|
||||||
|
void(__stdcall* ui_event_notify_)(int uev, void* sender, void* param);
|
||||||
|
void* ui_notify_param_;
|
||||||
|
static std::wstring prop_name;
|
||||||
|
static BOOL CALLBACK dlg_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);
|
||||||
|
|
||||||
|
virtual BOOL handle_message(UINT msg, WPARAM wp, LPARAM lp);
|
||||||
|
virtual void on_font_changed(void);
|
||||||
|
void create(void);
|
||||||
|
void notify_ui_event(int ev);
|
||||||
|
|
||||||
|
public:
|
||||||
|
dlg_base(HWND parent, UINT idd);
|
||||||
|
virtual ~dlg_base();
|
||||||
|
|
||||||
|
static void screen_2_client(HWND wnd, LPRECT r);
|
||||||
|
static void client_2_screen(HWND wnd, LPRECT r);
|
||||||
|
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);
|
||||||
|
static std::wstring get_wnd_text(HWND h);
|
||||||
|
static bool is_language_pack_default_code_page(void);
|
||||||
|
static std::wstring get_menu_text(HMENU menu, int ind);
|
||||||
|
static void center_window(HWND wnd, HWND parent);
|
||||||
|
static int get_combox_cur_sel(HWND wnd);
|
||||||
|
static int get_button_check(HWND wnd);
|
||||||
|
|
||||||
|
static int list_insert_column(HWND list_wnd, const wchar_t* text, int cx = 20, int ind = -1);
|
||||||
|
static int list_insert_item(HWND list_wnd, const wchar_t* text, int ind = -1);
|
||||||
|
static int list_get_item_count(HWND list_wnd);
|
||||||
|
static int list_get_column_count(HWND list_wnd);
|
||||||
|
static std::wstring list_get_text(HWND list_wnd, int ind, int sub = 0);
|
||||||
|
static void list_get_selected_items(HWND list_wnd, std::vector<int>& sels);
|
||||||
|
static int list_set_item_text(HWND list_wnd, int item, int sub_item, const wchar_t* text);
|
||||||
|
static int get_tab_count(HWND tab);
|
||||||
|
static int insert_page_to_tab(HWND tab, dlg_base* page, const wchar_t* title);
|
||||||
|
static void* get_tab_item_data(HWND tab, int index);
|
||||||
|
static std::string u2m(const wchar_t* u, int page);
|
||||||
|
static std::wstring m2u(const char* m, int page);
|
||||||
|
|
||||||
|
public:
|
||||||
|
void set_ui_event_notify(void(__stdcall* notify)(int, void*, void*), void* param);
|
||||||
|
HWND hwnd(void);
|
||||||
|
void show(bool visible, bool hold = false);
|
||||||
|
int do_modal(HWND parent);
|
||||||
|
void quit_modal(int non_zero_code);
|
||||||
|
void enable(bool enable);
|
||||||
|
void screen_2_client(LPRECT r);
|
||||||
|
void client_2_screen(LPRECT r);
|
||||||
|
HWND get_item(UINT id);
|
||||||
|
BOOL set_font(HFONT font);
|
||||||
|
HFONT get_font(void);
|
||||||
|
int get_string_width(const wchar_t* str, HWND wnd = NULL);
|
||||||
|
bool get_item_rect(UINT id, LPRECT r, bool client = true);
|
||||||
|
std::wstring get_item_text(UINT id);
|
||||||
|
int get_width_diff_as_text_length(UINT id); //
|
||||||
|
void offset_item(HWND wnd, int dx, int dy);
|
||||||
|
void offset_item(UINT id, int dx, int dy);
|
||||||
|
void expand_item(UINT id, int dx, int dy);
|
||||||
|
bool set_item_text(UINT id, const wchar_t* text);
|
||||||
|
int set_item_fit_to_text(UINT id); // return difference
|
||||||
|
void show_scroll_bar(int bar = SB_VERT, bool show = true);
|
||||||
|
bool track_mouse_hover(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
class tooltip_wnd
|
||||||
|
{
|
||||||
|
HWND hwnd_;
|
||||||
|
HWND parent_;
|
||||||
|
WNDPROC org_proc_;
|
||||||
|
|
||||||
|
typedef struct _tip_ele
|
||||||
|
{
|
||||||
|
HWND ctrl;
|
||||||
|
RECT rect;
|
||||||
|
std::wstring tips;
|
||||||
|
|
||||||
|
struct _tip_ele()
|
||||||
|
{
|
||||||
|
ctrl = NULL;
|
||||||
|
memset(&rect, 0, sizeof(rect));
|
||||||
|
tips = L"";
|
||||||
|
}
|
||||||
|
bool operator==(const HWND& wnd)
|
||||||
|
{
|
||||||
|
return ctrl == wnd;
|
||||||
|
}
|
||||||
|
bool operator==(const RECT& r)
|
||||||
|
{
|
||||||
|
return memcmp(&rect, &r, sizeof(r)) == 0;
|
||||||
|
}
|
||||||
|
}TIPELEM;
|
||||||
|
std::vector<TIPELEM> elements_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
tooltip_wnd();
|
||||||
|
~tooltip_wnd();
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool create(HWND parent);
|
||||||
|
void enable(bool enabled);
|
||||||
|
bool add_tool_tip_for_rect(const RECT& r, const wchar_t* tips);
|
||||||
|
bool add_tool_tip_for_ctrl(HWND ctrl, const wchar_t* tips);
|
||||||
|
bool remove_tool_tip_for_ctrl(HWND ctrl);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,106 @@
|
||||||
|
// DlgIndicator.cpp: 实现文件
|
||||||
|
//
|
||||||
|
#include "DlgMain.h"
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
// CDlgIndicator 对话框
|
||||||
|
#include "DlgPageAdvConfig.h"
|
||||||
|
#include "DlgPageErrMsg.h"
|
||||||
|
|
||||||
|
dlg_main::dlg_main(HWND parent) : dlg_base(parent, IDD_MAIN), tab_(NULL)
|
||||||
|
{
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
dlg_main::~dlg_main()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOL dlg_main::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;
|
||||||
|
case WM_NOTIFY:
|
||||||
|
ret = on_notify((int)wp, (LPNMHDR)lp);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ret = FALSE;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
void dlg_main::handle_command(WORD code, WORD id, HANDLE ctrl)
|
||||||
|
{
|
||||||
|
if (id == IDOK || id == IDCANCEL)
|
||||||
|
PostQuitMessage(0);
|
||||||
|
}
|
||||||
|
BOOL dlg_main::on_notify(int ctrl_id, LPNMHDR pnmh)
|
||||||
|
{
|
||||||
|
BOOL ret = TRUE;
|
||||||
|
|
||||||
|
if (pnmh->hwndFrom == tab_)
|
||||||
|
{
|
||||||
|
if (pnmh->code == TCN_SELCHANGING)
|
||||||
|
ret = FALSE;
|
||||||
|
else if (pnmh->code == TCN_SELCHANGE)
|
||||||
|
select_page(TabCtrl_GetCurSel(tab_));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dlg_main::add_page(const wchar_t* title, dlg_base* dlg)
|
||||||
|
{
|
||||||
|
HFONT font = (HFONT)SendMessage(get_item(IDOK), WM_GETFONT, 0, 0);
|
||||||
|
LOGFONTW lf = { 0 };
|
||||||
|
|
||||||
|
GetObjectW(font, sizeof(lf), &lf);
|
||||||
|
dlg->set_font(font);
|
||||||
|
|
||||||
|
return dlg_base::insert_page_to_tab(tab_, dlg, title);
|
||||||
|
}
|
||||||
|
dlg_base* dlg_main::select_page(int index)
|
||||||
|
{
|
||||||
|
dlg_base* ret = NULL, * cur = NULL;
|
||||||
|
|
||||||
|
for (int i = 0; cur = (dlg_base*)dlg_base::get_tab_item_data(tab_, i); ++i)
|
||||||
|
{
|
||||||
|
if (i == index)
|
||||||
|
{
|
||||||
|
ret = cur;
|
||||||
|
cur->show(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
cur->show(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dlg_main::on_init_dlg(void)
|
||||||
|
{
|
||||||
|
dlg_base* page = new dlg_err_msg(hwnd());
|
||||||
|
RECT r = { 0 };
|
||||||
|
|
||||||
|
SetWindowTextW(hwnd(), L"\u626B\u63CF\u4EEA\u9519\u8BEF\u4FE1\u606F\u53CA\u9AD8\u7EA7\u8C03\u8BD5\u914D\u7F6E");
|
||||||
|
get_item_rect(IDC_STATIC_PAGE, &r, false);
|
||||||
|
screen_2_client(&r);
|
||||||
|
tab_ = get_item(IDC_PAGES);
|
||||||
|
MoveWindow(page->hwnd(), r.left, r.top, RECT_W(r), RECT_H(r), TRUE);
|
||||||
|
add_page(L"\u9519\u8BEF\u4FE1\u606F", dynamic_cast<dlg_base*>(page));
|
||||||
|
|
||||||
|
page = new dlg_adv_cfg(hwnd());
|
||||||
|
MoveWindow(page->hwnd(), r.left, r.top, RECT_W(r), RECT_H(r), TRUE);
|
||||||
|
add_page(L"\u9AD8\u7EA7\u914D\u7F6E", dynamic_cast<dlg_base*>(page));
|
||||||
|
select_page(0);
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "DlgBase.h"
|
||||||
|
|
||||||
|
// CDlgIndicator 对话框
|
||||||
|
|
||||||
|
class dlg_main: public dlg_base
|
||||||
|
{
|
||||||
|
HWND tab_;
|
||||||
|
|
||||||
|
BOOL handle_message(UINT msg, WPARAM wp, LPARAM lp) override;
|
||||||
|
void handle_command(WORD code, WORD id, HANDLE ctrl);
|
||||||
|
BOOL on_notify(int ctrl_id, LPNMHDR pnmh);
|
||||||
|
|
||||||
|
int add_page(const wchar_t* title, dlg_base* dlg);
|
||||||
|
dlg_base* select_page(int index);
|
||||||
|
|
||||||
|
void on_init_dlg(void);
|
||||||
|
|
||||||
|
public:
|
||||||
|
dlg_main(HWND parent);
|
||||||
|
~dlg_main();
|
||||||
|
};
|
|
@ -0,0 +1,526 @@
|
||||||
|
// DlgIndicator.cpp: 实现文件
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "DlgPageAdvConfig.h"
|
||||||
|
#include "resource.h"
|
||||||
|
#include "ini_file.h"
|
||||||
|
|
||||||
|
#include <file/file_util.h>
|
||||||
|
#include <coding/coding.h>
|
||||||
|
|
||||||
|
#pragma warning(disable: 4996)
|
||||||
|
|
||||||
|
namespace config
|
||||||
|
{
|
||||||
|
INTER_MODULE_CALLBACK(got_str)
|
||||||
|
{
|
||||||
|
*(std::string*)param += std::string(data, len);
|
||||||
|
|
||||||
|
return inter_module_data::SET_RESULT_CONTINUE;
|
||||||
|
}
|
||||||
|
INTER_MODULE_CALLBACK(got_wstr)
|
||||||
|
{
|
||||||
|
*(std::wstring*)param += std::wstring((const wchar_t*)data, len / 2);
|
||||||
|
|
||||||
|
return inter_module_data::SET_RESULT_CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::wstring get_log_method(const wchar_t* cfg_file)
|
||||||
|
{
|
||||||
|
wchar_t buf[256] = { 0 };
|
||||||
|
|
||||||
|
GetPrivateProfileStringW(L"log", L"type", L"file", buf, _countof(buf) - 1, cfg_file);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
void set_log_method(const wchar_t* cfg_file, const wchar_t* val)
|
||||||
|
{
|
||||||
|
WritePrivateProfileStringW(L"log", L"type", val, cfg_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring get_log_level(const wchar_t* cfg_file)
|
||||||
|
{
|
||||||
|
wchar_t buf[256] = { 0 };
|
||||||
|
|
||||||
|
GetPrivateProfileStringW(L"log", L"level", L"all", buf, _countof(buf) - 1, cfg_file);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
void set_log_level(const wchar_t* cfg_file, const wchar_t* val)
|
||||||
|
{
|
||||||
|
WritePrivateProfileStringW(L"log", L"level", val, cfg_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring get_log_file(const wchar_t* cfg_file)
|
||||||
|
{
|
||||||
|
wchar_t buf[256] = { 0 };
|
||||||
|
|
||||||
|
GetPrivateProfileStringW(L"log", L"path", L"", buf, _countof(buf) - 1, cfg_file);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
void set_log_file(const wchar_t* cfg_file, const wchar_t* val)
|
||||||
|
{
|
||||||
|
WritePrivateProfileStringW(L"log", L"path", val, cfg_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_twain_log_level(const wchar_t* cfg_file)
|
||||||
|
{
|
||||||
|
return GetPrivateProfileIntW(L"log", L"twain-level", 1, cfg_file);
|
||||||
|
}
|
||||||
|
void set_twain_log_level(const wchar_t* cfg_file, int val)
|
||||||
|
{
|
||||||
|
WritePrivateProfileStringW(L"log", L"twain-level", std::to_wstring(val).c_str(), cfg_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get_twain_log_triples(const wchar_t* cfg_file)
|
||||||
|
{
|
||||||
|
return GetPrivateProfileIntW(L"twain-app", L"log-all-triple", 0, cfg_file) == 1;
|
||||||
|
}
|
||||||
|
void set_twain_log_triples(const wchar_t* cfg_file, bool val)
|
||||||
|
{
|
||||||
|
WritePrivateProfileStringW(L"twain-app", L"log-all-triple", std::to_wstring(val).c_str(), cfg_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_twain_notify_close_policy(const wchar_t* cfg_file)
|
||||||
|
{
|
||||||
|
return GetPrivateProfileIntW(L"twain-app", L"notify-close", 0, cfg_file);
|
||||||
|
}
|
||||||
|
void set_twain_notify_close_policy(const wchar_t* cfg_file, int val)
|
||||||
|
{
|
||||||
|
WritePrivateProfileStringW(L"twain-app", L"notify-close", std::to_wstring(val).c_str(), cfg_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get_dump_images(const wchar_t* cfg_file)
|
||||||
|
{
|
||||||
|
return GetPrivateProfileIntW(L"dump", L"dumpusb", 0, cfg_file) == 1;
|
||||||
|
}
|
||||||
|
void set_dump_images(const wchar_t* cfg_file, bool val)
|
||||||
|
{
|
||||||
|
WritePrivateProfileStringW(L"dump", L"dumpusb", std::to_wstring(val).c_str(), cfg_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring get_dump_img_path(const wchar_t* cfg_file)
|
||||||
|
{
|
||||||
|
wchar_t buf[256] = { 0 };
|
||||||
|
|
||||||
|
GetPrivateProfileStringW(L"dump", L"usb_path", L"", buf, _countof(buf) - 1, cfg_file);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
void set_dump_img_path(const wchar_t* cfg_file, const wchar_t* val)
|
||||||
|
{
|
||||||
|
WritePrivateProfileStringW(L"dump", L"usb_path", val, cfg_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::wstring get_tmp_img_path(const wchar_t* cfg_file)
|
||||||
|
{
|
||||||
|
wchar_t buf[256] = { 0 };
|
||||||
|
|
||||||
|
GetPrivateProfileStringW(L"paths", L"final_img", L"", buf, _countof(buf) - 1, cfg_file);
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
void set_tmp_img_path(const wchar_t* cfg_file, const wchar_t* val)
|
||||||
|
{
|
||||||
|
WritePrivateProfileStringW(L"paths", L"final_img", val, cfg_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get_opencv_adv(const wchar_t* cfg_file)
|
||||||
|
{
|
||||||
|
return GetPrivateProfileIntW(L"cpu", L"advanced", 1, cfg_file) == 1;
|
||||||
|
}
|
||||||
|
void set_opencv_adv(const wchar_t* cfg_file, bool val)
|
||||||
|
{
|
||||||
|
WritePrivateProfileStringW(L"cpu", L"advanced", std::to_wstring(val).c_str(), cfg_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_memory_max(const wchar_t* cfg_file)
|
||||||
|
{
|
||||||
|
return GetPrivateProfileIntW(L"mem", L"max_img", 1000, cfg_file);
|
||||||
|
}
|
||||||
|
void set_memory_max(const wchar_t* cfg_file, int val)
|
||||||
|
{
|
||||||
|
WritePrivateProfileStringW(L"mem", L"max_img", std::to_wstring(val).c_str(), cfg_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_notify_close_method(const wchar_t* cfg_file)
|
||||||
|
{
|
||||||
|
return GetPrivateProfileIntW(L"twain-app", L"notify-close", NOTIFY_AUTO, cfg_file);
|
||||||
|
}
|
||||||
|
void set_notify_close_method(const wchar_t* cfg_file, int val)
|
||||||
|
{
|
||||||
|
WritePrivateProfileStringW(L"twain-app", L"notify-close", std::to_wstring(val).c_str(), cfg_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_read_eof_processes(const wchar_t* cfg_file, std::vector<readeof>& procs)
|
||||||
|
{
|
||||||
|
simple_ini ini;
|
||||||
|
std::vector<KEYVAL> vals;
|
||||||
|
|
||||||
|
ini.load(dlg_base::u2m(cfg_file, CP_ACP).c_str());
|
||||||
|
ini.get("read_eof", vals);
|
||||||
|
for (auto& v : vals)
|
||||||
|
{
|
||||||
|
readeof eof;
|
||||||
|
eof.name = dlg_base::m2u(v.key.c_str(), CP_ACP);
|
||||||
|
eof.ret_eof = v.val == "1";
|
||||||
|
procs.push_back(eof);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void set_read_eof_processes(const wchar_t* cfg_file, const wchar_t* name, bool eof)
|
||||||
|
{
|
||||||
|
WritePrivateProfileStringW(L"read_eof", name, std::to_wstring(eof).c_str(), cfg_file);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dlg_adv_cfg::dlg_adv_cfg(HWND parent) : dlg_base(parent, IDD_ADV_CFG)
|
||||||
|
{
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
dlg_adv_cfg::~dlg_adv_cfg()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BOOL dlg_adv_cfg::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;
|
||||||
|
case WM_NOTIFY:
|
||||||
|
ret = on_notify((int)wp, (LPNMHDR)lp);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ret = FALSE;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
void dlg_adv_cfg::handle_command(WORD code, WORD id, HANDLE ctrl)
|
||||||
|
{
|
||||||
|
if (code == EN_KILLFOCUS)
|
||||||
|
{
|
||||||
|
on_lost_focus((HWND)ctrl);
|
||||||
|
}
|
||||||
|
else if (code == CBN_SELCHANGE)
|
||||||
|
{
|
||||||
|
on_combox_sel_changed((HWND)ctrl);
|
||||||
|
}
|
||||||
|
else if (code == BN_CLICKED)
|
||||||
|
{
|
||||||
|
on_button_clicked((HWND)ctrl, id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BOOL dlg_adv_cfg::on_notify(int ctrl_id, LPNMHDR pnmh)
|
||||||
|
{
|
||||||
|
BOOL ret = TRUE;
|
||||||
|
|
||||||
|
if (pnmh->hwndFrom == get_item(IDC_COMBO_METHOD))
|
||||||
|
{
|
||||||
|
if (pnmh->code == TCN_SELCHANGING)
|
||||||
|
ret = FALSE;
|
||||||
|
else if (pnmh->code == TCN_SELCHANGE)
|
||||||
|
EnableWindow(get_item(IDC_EDIT_LOG_FILE), dlg_base::get_combox_cur_sel(get_item(IDC_COMBO_METHOD)) == 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void dlg_adv_cfg::on_init_dlg(void)
|
||||||
|
{
|
||||||
|
std::wstring path(dlg_base::m2u(getenv("LOCALAPPDATA"), CP_ACP)),
|
||||||
|
cfg(path + L"\\config\\debug.cfg");
|
||||||
|
HWND lst = get_item(IDC_LIST1);
|
||||||
|
LVCOLUMNW col;
|
||||||
|
int ind = 0;
|
||||||
|
|
||||||
|
ListView_SetExtendedListViewStyle(lst, LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
|
||||||
|
col.mask = LVCF_TEXT | LVCF_WIDTH;
|
||||||
|
col.pszText = (wchar_t*)L"\u8FDB\u7A0B\u540D\u79F0";
|
||||||
|
col.cx = 100;
|
||||||
|
ListView_InsertColumn(lst, ind++, &col);
|
||||||
|
col.pszText = (wchar_t*)L"EOF";
|
||||||
|
col.cx = 40;
|
||||||
|
ListView_InsertColumn(lst, ind++, &col);
|
||||||
|
|
||||||
|
path += L"\\HuagoScan\\";
|
||||||
|
cfg = path + L"\\config\\debug.cfg";
|
||||||
|
SetDlgItemTextW(hwnd(), IDC_EDIT_CFG_PATH, cfg.c_str());
|
||||||
|
|
||||||
|
HWND oem = get_item(IDC_COMBO_OEM);
|
||||||
|
SendMessageW(oem, CB_ADDSTRING, 0, (LPARAM)L"HuagoScan");
|
||||||
|
SendMessageW(oem, CB_ADDSTRING, 0, (LPARAM)L"HanvonScan");
|
||||||
|
SendMessageW(oem, CB_ADDSTRING, 0, (LPARAM)L"LanxumScan");
|
||||||
|
SendMessageW(oem, CB_ADDSTRING, 0, (LPARAM)L"CumtennScan");
|
||||||
|
SendMessageW(oem, CB_ADDSTRING, 0, (LPARAM)L"MicrotekScan");
|
||||||
|
SendMessageW(oem, CB_ADDSTRING, 0, (LPARAM)L"UniScan");
|
||||||
|
SendMessageW(oem, CB_ADDSTRING, 0, (LPARAM)L"NeuScan");
|
||||||
|
SendMessageW(oem, CB_SETCURSEL, 0, 0);
|
||||||
|
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
void dlg_adv_cfg::on_lost_focus(HWND wnd)
|
||||||
|
{
|
||||||
|
// check if EDIT control ...
|
||||||
|
std::wstring cfg(get_item_text(IDC_EDIT_CFG_PATH));
|
||||||
|
|
||||||
|
if (wnd == get_item(IDC_EDIT_LOG_FILE))
|
||||||
|
{
|
||||||
|
std::wstring text(get_item_text(IDC_EDIT_LOG_FILE));
|
||||||
|
if (text.find(L"%") == std::wstring::npos)
|
||||||
|
{
|
||||||
|
config::set_log_file(cfg.c_str(), text.c_str());
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (wnd == get_item(IDC_EDIT_MEM_MAX))
|
||||||
|
{
|
||||||
|
std::wstring text(get_item_text(IDC_EDIT_MEM_MAX));
|
||||||
|
|
||||||
|
config::set_memory_max(cfg.c_str(), _wtoi(text.c_str()));
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
else if (wnd == get_item(IDC_EDIT_IMGS_PATH))
|
||||||
|
{
|
||||||
|
std::wstring text(get_item_text(IDC_EDIT_IMGS_PATH));
|
||||||
|
config::set_dump_img_path(cfg.c_str(), text.c_str());
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
else if (wnd == get_item(IDC_EDIT_IMG_PATH))
|
||||||
|
{
|
||||||
|
std::wstring text(get_item_text(IDC_EDIT_IMG_PATH));
|
||||||
|
config::set_tmp_img_path(cfg.c_str(), text.c_str());
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
else if (wnd == get_item(IDC_EDIT_TWAIN_LEVEL))
|
||||||
|
{
|
||||||
|
std::wstring text(get_item_text(IDC_EDIT_TWAIN_LEVEL));
|
||||||
|
config::set_twain_log_level(cfg.c_str(), _wtoi(text.c_str()));
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
else if (wnd == get_item(IDC_EDIT_EOF))
|
||||||
|
{
|
||||||
|
std::wstring text(get_item_text(IDC_EDIT_EOF)), first(L"[read_eof]\r\n");
|
||||||
|
size_t pos = text.find(first), cnt = 0;
|
||||||
|
if (pos != std::wstring::npos)
|
||||||
|
{
|
||||||
|
text.erase(0, pos + first.length());
|
||||||
|
while (text.length())
|
||||||
|
{
|
||||||
|
pos = text.find(L"\r\n");
|
||||||
|
if (pos == std::wstring::npos)
|
||||||
|
{
|
||||||
|
first = text;
|
||||||
|
text = L"";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
first = text.substr(0, pos);
|
||||||
|
text.erase(0, pos + 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
pos = first.find(L"=");
|
||||||
|
if (pos != std::wstring::npos)
|
||||||
|
{
|
||||||
|
config::set_read_eof_processes(cfg.c_str(), first.substr(0, pos).c_str(), first.substr(pos + 1) == L"1");
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (cnt)
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void dlg_adv_cfg::on_combox_sel_changed(HWND wnd)
|
||||||
|
{
|
||||||
|
std::wstring cfg(get_item_text(IDC_EDIT_CFG_PATH));
|
||||||
|
int sel = dlg_base::get_combox_cur_sel(wnd);
|
||||||
|
|
||||||
|
if (wnd == get_item(IDC_COMBO_METHOD))
|
||||||
|
{
|
||||||
|
const wchar_t* val[] = {L"none", L"console", L"file"};
|
||||||
|
config::set_log_method(cfg.c_str(), val[sel]);
|
||||||
|
init();
|
||||||
|
|
||||||
|
wnd = get_item(IDC_EDIT_LOG_FILE);
|
||||||
|
EnableWindow(wnd, sel == 2);
|
||||||
|
}
|
||||||
|
else if (wnd == get_item(IDC_COMBO_LEVEL))
|
||||||
|
{
|
||||||
|
const wchar_t* val[] = { L"all", L"debug", L"warning", L"fatal"};
|
||||||
|
config::set_log_level(cfg.c_str(), val[sel]);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
else if (wnd == get_item(IDC_COMBO_NOTIFY_CLOSE))
|
||||||
|
{
|
||||||
|
config::set_notify_close_method(cfg.c_str(), sel);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
else if (wnd == get_item(IDC_COMBO_OEM))
|
||||||
|
{
|
||||||
|
STR_PARENT_FOLDER(cfg);
|
||||||
|
STR_PARENT_FOLDER(cfg);
|
||||||
|
STR_PARENT_FOLDER(cfg);
|
||||||
|
cfg += L"\\" + get_item_text(IDC_COMBO_OEM) + L"\\config\\debug.cfg";
|
||||||
|
STR_SIMPLIFY_PATH(cfg);
|
||||||
|
SetDlgItemTextW(hwnd(), IDC_EDIT_CFG_PATH, cfg.c_str());
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void dlg_adv_cfg::on_button_clicked(HWND wnd, WORD id)
|
||||||
|
{
|
||||||
|
std::wstring cfg(get_item_text(IDC_EDIT_CFG_PATH));
|
||||||
|
int chk = dlg_base::get_button_check(wnd);
|
||||||
|
|
||||||
|
if (id == IDC_CHECK_OPENCV)
|
||||||
|
{
|
||||||
|
config::set_opencv_adv(cfg.c_str(), chk == BST_CHECKED);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
else if (id == IDC_CHECK_OUT_IMGS)
|
||||||
|
{
|
||||||
|
config::set_dump_images(cfg.c_str(), chk == BST_CHECKED);
|
||||||
|
init();
|
||||||
|
EnableWindow(get_item(IDC_EDIT_IMGS_PATH), chk == BST_CHECKED);
|
||||||
|
}
|
||||||
|
else if (id == IDC_CHECK_RECORD_MSGS)
|
||||||
|
{
|
||||||
|
config::set_twain_log_triples(cfg.c_str(), chk == BST_CHECKED);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dlg_adv_cfg::init(void)
|
||||||
|
{
|
||||||
|
std::wstring cfg(dlg_base::get_item_text(IDC_EDIT_CFG_PATH));
|
||||||
|
HWND ctrl = get_item(IDC_COMBO_METHOD);
|
||||||
|
|
||||||
|
load_from_file(cfg.c_str());
|
||||||
|
|
||||||
|
while (SendMessageW(ctrl, CB_DELETESTRING, 0, 0) != CB_ERR);
|
||||||
|
SendMessageW(ctrl, CB_ADDSTRING, 0, (LPARAM)L"\u4E0D\u8F93\u51FA\u65E5\u5FD7");
|
||||||
|
SendMessageW(ctrl, CB_ADDSTRING, 0, (LPARAM)L"\u8F93\u51FA\u5230\u63A7\u5236\u53F0");
|
||||||
|
SendMessageW(ctrl, CB_ADDSTRING, 0, (LPARAM)L"\u8F93\u51FA\u5230\u6587\u4EF6");
|
||||||
|
if (log_method_ == L"file")
|
||||||
|
SendMessageW(ctrl, CB_SETCURSEL, 2, 0);
|
||||||
|
else if (log_method_ == L"console")
|
||||||
|
SendMessageW(ctrl, CB_SETCURSEL, 1, 0);
|
||||||
|
else
|
||||||
|
SendMessageW(ctrl, CB_SETCURSEL, 0, 0);
|
||||||
|
|
||||||
|
ctrl = get_item(IDC_COMBO_LEVEL);
|
||||||
|
while (SendMessageW(ctrl, CB_DELETESTRING, 0, 0) != CB_ERR);
|
||||||
|
SendMessageW(ctrl, CB_ADDSTRING, 0, (LPARAM)L"\u6240\u6709\u65E5\u5FD7");
|
||||||
|
SendMessageW(ctrl, CB_ADDSTRING, 0, (LPARAM)L"\u8C03\u8BD5\u4FE1\u606F\u53CA\u4EE5\u4E0A");
|
||||||
|
SendMessageW(ctrl, CB_ADDSTRING, 0, (LPARAM)L"\u8B66\u544A\u4FE1\u606F\u53CA\u4EE5\u4E0A");
|
||||||
|
SendMessageW(ctrl, CB_ADDSTRING, 0, (LPARAM)L"\u81F4\u547D\u9519\u8BEF\u53CA\u4EE5\u4E0A");
|
||||||
|
if (log_method_ == L"fatal")
|
||||||
|
SendMessageW(ctrl, CB_SETCURSEL, 3, 0);
|
||||||
|
else if (log_method_ == L"warning")
|
||||||
|
SendMessageW(ctrl, CB_SETCURSEL, 2, 0);
|
||||||
|
else if (log_method_ == L"debug")
|
||||||
|
SendMessageW(ctrl, CB_SETCURSEL, 1, 0);
|
||||||
|
else
|
||||||
|
SendMessageW(ctrl, CB_SETCURSEL, 0, 0);
|
||||||
|
|
||||||
|
ctrl = get_item(IDC_COMBO_NOTIFY_CLOSE);
|
||||||
|
while (SendMessageW(ctrl, CB_DELETESTRING, 0, 0) != CB_ERR);
|
||||||
|
SendMessageW(ctrl, CB_ADDSTRING, 0, (LPARAM)L"\u81EA\u52A8\u6A21\u5F0F");
|
||||||
|
SendMessageW(ctrl, CB_ADDSTRING, 0, (LPARAM)L"\u76F4\u63A5\u8C03\u7528");
|
||||||
|
SendMessageW(ctrl, CB_ADDSTRING, 0, (LPARAM)L"eventProcess\u8C03\u7528");
|
||||||
|
if (notify_close_ < 0 || notify_close_ > NOTIFY_NONE)
|
||||||
|
notify_close_ = NOTIFY_AUTO;
|
||||||
|
SendMessageW(ctrl, CB_SETCURSEL, notify_close_, 0);
|
||||||
|
|
||||||
|
SetDlgItemInt(hwnd(), IDC_EDIT_TWAIN_LEVEL, twain_log_level_, FALSE);
|
||||||
|
SendMessage(get_item(IDC_CHECK_RECORD_MSGS), BM_SETCHECK, twain_log_all_triples_ ? (WPARAM)BST_CHECKED : (WPARAM)BST_UNCHECKED, 0);
|
||||||
|
|
||||||
|
SendMessage(get_item(IDC_CHECK_OUT_IMGS), BM_SETCHECK, dump_images_ ? (WPARAM)BST_CHECKED : (WPARAM)BST_UNCHECKED, 0);
|
||||||
|
EnableWindow(get_item(IDC_EDIT_IMGS_PATH), dump_images_);
|
||||||
|
|
||||||
|
SetDlgItemTextW(hwnd(), IDC_EDIT_LOG_FILE, log_file_.c_str());
|
||||||
|
SetDlgItemTextW(hwnd(), IDC_EDIT_IMG_PATH, tmp_img_path_.c_str());
|
||||||
|
SetDlgItemTextW(hwnd(), IDC_EDIT_IMGS_PATH, dump_img_path_.c_str());
|
||||||
|
|
||||||
|
HWND list_ = get_item(IDC_LIST1);
|
||||||
|
std::wstring eof(L"[read_eof]\r\n");
|
||||||
|
ListView_DeleteAllItems(list_);
|
||||||
|
for (auto& v : eof_procs_)
|
||||||
|
{
|
||||||
|
LVITEMW item = { 0 };
|
||||||
|
int ind = ListView_GetItemCount(list_);
|
||||||
|
|
||||||
|
item.mask = LVIF_TEXT;
|
||||||
|
item.iItem = ListView_GetItemCount(list_);
|
||||||
|
item.pszText = &v.name[0];
|
||||||
|
ind = ListView_InsertItem(list_, &item);
|
||||||
|
ListView_SetItemText(list_, ind, 1, v.ret_eof ? (wchar_t*)L"true" : (wchar_t*)L"false");
|
||||||
|
eof += v.name + L"=" + std::to_wstring(v.ret_eof) + L"\r\n";
|
||||||
|
}
|
||||||
|
SetDlgItemTextW(hwnd(), IDC_EDIT_EOF, eof.c_str());
|
||||||
|
|
||||||
|
SetDlgItemInt(hwnd(), IDC_EDIT_MEM_MAX, max_mem_, FALSE);
|
||||||
|
SendMessage(get_item(IDC_CHECK_OPENCV), BM_SETCHECK, enable_opencv_adv_ ? (WPARAM)BST_CHECKED : (WPARAM)BST_UNCHECKED, 0);
|
||||||
|
}
|
||||||
|
void dlg_adv_cfg::load_from_file(const wchar_t* file)
|
||||||
|
{
|
||||||
|
log_method_ = config::get_log_method(file);
|
||||||
|
log_level_ = config::get_log_level(file);
|
||||||
|
log_file_ = config::get_log_file(file);
|
||||||
|
if (log_file_.empty())
|
||||||
|
{
|
||||||
|
log_file_ = file;
|
||||||
|
STR_PARENT_FOLDER(log_file_);
|
||||||
|
STR_PARENT_FOLDER(log_file_);
|
||||||
|
log_file_ += L"\\log\\%APPNAME%.log";
|
||||||
|
}
|
||||||
|
twain_log_level_ = config::get_twain_log_level(file);
|
||||||
|
twain_log_all_triples_ = config::get_twain_log_triples(file);
|
||||||
|
notify_close_ = config::get_notify_close_method(file);
|
||||||
|
tmp_img_path_ = config::get_tmp_img_path(file);
|
||||||
|
if (tmp_img_path_.empty())
|
||||||
|
{
|
||||||
|
tmp_img_path_ = file;
|
||||||
|
STR_PARENT_FOLDER(tmp_img_path_);
|
||||||
|
STR_PARENT_FOLDER(tmp_img_path_);
|
||||||
|
tmp_img_path_ += L"\\imgs\\";
|
||||||
|
STR_SIMPLIFY_PATH(tmp_img_path_);
|
||||||
|
}
|
||||||
|
dump_images_ = config::get_dump_images(file);
|
||||||
|
dump_img_path_ = config::get_dump_img_path(file);
|
||||||
|
if (dump_img_path_.empty())
|
||||||
|
dump_img_path_ = tmp_img_path_;
|
||||||
|
|
||||||
|
max_mem_ = config::get_memory_max(file);
|
||||||
|
enable_opencv_adv_ = config::get_opencv_adv(file);
|
||||||
|
debug_cfg_path_ = file;
|
||||||
|
|
||||||
|
config::get_read_eof_processes(file, eof_procs_);
|
||||||
|
|
||||||
|
std::string raw("");
|
||||||
|
std::wstring unic(L"");
|
||||||
|
|
||||||
|
file_util::load_file(file, config::got_str, &raw);
|
||||||
|
coding_util::bom::to_unicode(raw.c_str(), raw.length(), config::got_wstr, &unic);
|
||||||
|
SetDlgItemTextW(hwnd(), IDC_EDIT_CONTENT, unic.c_str());
|
||||||
|
}
|
||||||
|
void dlg_adv_cfg::save_to_file(const wchar_t* file)
|
||||||
|
{
|
||||||
|
std::wstring cont(get_item_text(IDC_EDIT_CONTENT));
|
||||||
|
std::string bom(""), utf8("");
|
||||||
|
|
||||||
|
coding_util::unicode_2_utf8(cont.c_str(), config::got_str, &utf8);
|
||||||
|
coding_util::bom::from_utf8(utf8.c_str(), utf8.length(), config::got_str, &bom);
|
||||||
|
file_util::save_2_file(bom.c_str(), bom.length(), file);
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "DlgBase.h"
|
||||||
|
|
||||||
|
// CDlgIndicator 对话框
|
||||||
|
|
||||||
|
typedef struct _read_eof
|
||||||
|
{
|
||||||
|
bool ret_eof;
|
||||||
|
std::wstring name;
|
||||||
|
}readeof;
|
||||||
|
enum { NOTIFY_AUTO = 0, NOTIFY_ALWAYS, NOTIFY_NONE };
|
||||||
|
class dlg_adv_cfg : public dlg_base
|
||||||
|
{
|
||||||
|
std::wstring log_method_ = L"file";
|
||||||
|
std::wstring log_level_ = L"all";
|
||||||
|
std::wstring log_file_;
|
||||||
|
int twain_log_level_ = 1;
|
||||||
|
bool twain_log_all_triples_ = false;
|
||||||
|
std::wstring tmp_img_path_;
|
||||||
|
bool dump_images_;
|
||||||
|
std::wstring dump_img_path_;
|
||||||
|
std::vector<readeof> eof_procs_;
|
||||||
|
int max_mem_ = 1000;
|
||||||
|
|
||||||
|
int notify_close_ = 0;
|
||||||
|
bool enable_opencv_adv_ = true;
|
||||||
|
std::wstring debug_cfg_path_;
|
||||||
|
|
||||||
|
BOOL handle_message(UINT msg, WPARAM wp, LPARAM lp) override;
|
||||||
|
void handle_command(WORD code, WORD id, HANDLE ctrl);
|
||||||
|
BOOL on_notify(int ctrl_id, LPNMHDR pnmh);
|
||||||
|
|
||||||
|
void on_init_dlg(void);
|
||||||
|
void on_lost_focus(HWND wnd);
|
||||||
|
void on_combox_sel_changed(HWND wnd);
|
||||||
|
void on_button_clicked(HWND wnd, WORD id);
|
||||||
|
|
||||||
|
void init(void);
|
||||||
|
void load_from_file(const wchar_t* file);
|
||||||
|
void save_to_file(const wchar_t* file);
|
||||||
|
|
||||||
|
public:
|
||||||
|
dlg_adv_cfg(HWND parent);
|
||||||
|
~dlg_adv_cfg();
|
||||||
|
|
||||||
|
public:
|
||||||
|
};
|
|
@ -0,0 +1,146 @@
|
||||||
|
// DlgIndicator.cpp: 实现文件
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "DlgPageErrMsg.h"
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
#include <huagao/hgscanner_error.h>
|
||||||
|
|
||||||
|
dlg_err_msg::dlg_err_msg(HWND parent) : dlg_base(parent, IDD_ERR_MSG), list_(NULL)
|
||||||
|
{
|
||||||
|
create();
|
||||||
|
}
|
||||||
|
dlg_err_msg::~dlg_err_msg()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void dlg_err_msg::init_error_items(void)
|
||||||
|
{
|
||||||
|
LVITEMW item = { 0 };
|
||||||
|
int ind = ListView_GetItemCount(list_);
|
||||||
|
std::wstring text(L"");
|
||||||
|
wchar_t buf[80] = { 0 };
|
||||||
|
|
||||||
|
#define INSERT_ERROR_MSG(err) \
|
||||||
|
item.mask = LVIF_TEXT; \
|
||||||
|
item.iItem = ListView_GetItemCount(list_); \
|
||||||
|
text = std::to_wstring(item.iItem + 1); \
|
||||||
|
item.pszText = &text[0]; \
|
||||||
|
ind = ListView_InsertItem(list_, &item); \
|
||||||
|
swprintf_s(buf, _countof(buf) - 1, L"%05d - 0x%04X", SCANNER_ERR_##err, SCANNER_ERR_##err); \
|
||||||
|
ListView_SetItemText(list_, ind, 1, buf); \
|
||||||
|
text = dlg_base::m2u(STATU_DESC_SCANNER_ERR_##err, CP_UTF8); \
|
||||||
|
ListView_SetItemText(list_, ind, 2, &text[0]);
|
||||||
|
|
||||||
|
INSERT_ERROR_MSG(OK);
|
||||||
|
INSERT_ERROR_MSG(INVALID_PARAMETER);
|
||||||
|
INSERT_ERROR_MSG(USER_CANCELED);
|
||||||
|
INSERT_ERROR_MSG(INSUFFICIENT_MEMORY);
|
||||||
|
INSERT_ERROR_MSG(ACCESS_DENIED);
|
||||||
|
INSERT_ERROR_MSG(IO_PENDING);
|
||||||
|
INSERT_ERROR_MSG(NOT_EXACT);
|
||||||
|
INSERT_ERROR_MSG(CONFIGURATION_CHANGED);
|
||||||
|
INSERT_ERROR_MSG(NOT_OPEN);
|
||||||
|
INSERT_ERROR_MSG(NOT_START);
|
||||||
|
INSERT_ERROR_MSG(NOT_ANY_MORE);
|
||||||
|
INSERT_ERROR_MSG(NO_DATA);
|
||||||
|
INSERT_ERROR_MSG(HAS_DATA_YET);
|
||||||
|
INSERT_ERROR_MSG(OUT_OF_RANGE);
|
||||||
|
INSERT_ERROR_MSG(IO);
|
||||||
|
INSERT_ERROR_MSG(TIMEOUT);
|
||||||
|
INSERT_ERROR_MSG(OPEN_FILE_FAILED);
|
||||||
|
INSERT_ERROR_MSG(CREATE_FILE_FAILED);
|
||||||
|
INSERT_ERROR_MSG(WRITE_FILE_FAILED);
|
||||||
|
INSERT_ERROR_MSG(DATA_DAMAGED);
|
||||||
|
INSERT_ERROR_MSG(OPENED_BY_OTHER_PROCESS);
|
||||||
|
INSERT_ERROR_MSG(LANG_PAK_LOST);
|
||||||
|
INSERT_ERROR_MSG(RELOAD_IMAGE_PARAM);
|
||||||
|
INSERT_ERROR_MSG(RELOAD_OPT_PARAM);
|
||||||
|
INSERT_ERROR_MSG(USB_INIT_FAILED);
|
||||||
|
INSERT_ERROR_MSG(USB_REGISTER_PNP_FAILED);
|
||||||
|
INSERT_ERROR_MSG(USB_CLAIM_INTERFACE_FAILED);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_NOT_FOUND);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_NOT_SUPPORT);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_BUSY);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_SLEEPING);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_COUNT_MODE);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_STOPPED);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_COVER_OPENNED);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_NO_PAPER);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_FEEDING_PAPER);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_DOUBLE_FEEDING);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_PAPER_JAMMED);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_STAPLE_ON);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_PAPER_SKEW);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_SIZE_CHECK);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_DOGEAR);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_NO_IMAGE);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_SCANN_ERROR);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_PC_BUSY);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_ISLOCK);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_UPGRADE_SUCCESSFUL);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_UPGRADE_FAIL);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_AUTO_FAIL_OVER);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_AUTO_FAIL_INFO);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_DISTORTION);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_MAYBE_IS_HOLE);
|
||||||
|
INSERT_ERROR_MSG(DEVICE_DEVS_BOOTING);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL dlg_err_msg::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;
|
||||||
|
case WM_NOTIFY:
|
||||||
|
ret = on_notify((int)wp, (LPNMHDR)lp);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ret = FALSE;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
void dlg_err_msg::handle_command(WORD code, WORD id, HANDLE ctrl)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void dlg_err_msg::on_init_dlg(void)
|
||||||
|
{
|
||||||
|
LVCOLUMNW col;
|
||||||
|
int ind = 0;
|
||||||
|
|
||||||
|
list_ = get_item(IDC_LIST_ERR_CODE);
|
||||||
|
ListView_SetExtendedListViewStyle(list_, LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
|
||||||
|
col.mask = LVCF_TEXT | LVCF_WIDTH;
|
||||||
|
col.pszText = (wchar_t*)L"\u5E8F\u53F7";
|
||||||
|
col.cx = 40;
|
||||||
|
ListView_InsertColumn(list_, ind++, &col);
|
||||||
|
col.pszText = (wchar_t*)L"\u9519\u8BEF\u4EE3\u7801\uFF08\u5341/\u5341\u516D\u8FDB\u5236\uFF09";
|
||||||
|
col.cx = 150;
|
||||||
|
ListView_InsertColumn(list_, ind++, &col);
|
||||||
|
col.pszText = (wchar_t*)L"\u9519\u8BEF\u63CF\u8FF0";
|
||||||
|
col.cx = 319;
|
||||||
|
ListView_InsertColumn(list_, ind++, &col);
|
||||||
|
|
||||||
|
init_error_items();
|
||||||
|
}
|
||||||
|
BOOL dlg_err_msg::on_notify(int ctrl_id, LPNMHDR pnmh)
|
||||||
|
{
|
||||||
|
BOOL ret = TRUE;
|
||||||
|
|
||||||
|
if (pnmh->hwndFrom == list_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Windows.h>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "DlgBase.h"
|
||||||
|
|
||||||
|
// CDlgIndicator 对话框
|
||||||
|
|
||||||
|
class dlg_err_msg: public dlg_base
|
||||||
|
{
|
||||||
|
HWND list_;
|
||||||
|
|
||||||
|
void init_error_items(void);
|
||||||
|
BOOL handle_message(UINT msg, WPARAM wp, LPARAM lp) override;
|
||||||
|
void handle_command(WORD code, WORD id, HANDLE ctrl);
|
||||||
|
|
||||||
|
void on_init_dlg(void);
|
||||||
|
BOOL on_notify(int ctrl_id, LPNMHDR pnmh);
|
||||||
|
|
||||||
|
public:
|
||||||
|
dlg_err_msg(HWND parent);
|
||||||
|
~dlg_err_msg();
|
||||||
|
|
||||||
|
public:
|
||||||
|
};
|
|
@ -0,0 +1,15 @@
|
||||||
|
// header.h: 标准系统包含文件的包含文件,
|
||||||
|
// 或特定于项目的包含文件
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "targetver.h"
|
||||||
|
#define WIN32_LEAN_AND_MEAN // 从 Windows 头文件中排除极少使用的内容
|
||||||
|
// Windows 头文件
|
||||||
|
#include <windows.h>
|
||||||
|
// C 运行时头文件
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <memory.h>
|
||||||
|
#include <tchar.h>
|
Binary file not shown.
|
@ -0,0 +1,28 @@
|
||||||
|
// hg-helper.cpp : 定义应用程序的入口点。
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "framework.h"
|
||||||
|
#include "hg-helper.h"
|
||||||
|
#include "DlgMain.h"
|
||||||
|
|
||||||
|
HMODULE g_my_inst;
|
||||||
|
|
||||||
|
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||||
|
_In_opt_ HINSTANCE hPrevInstance,
|
||||||
|
_In_ LPWSTR lpCmdLine,
|
||||||
|
_In_ int nCmdShow)
|
||||||
|
{
|
||||||
|
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||||
|
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||||
|
|
||||||
|
// TODO: 在此处放置代码。
|
||||||
|
g_my_inst = hInstance;
|
||||||
|
{
|
||||||
|
dlg_main dlg(NULL);
|
||||||
|
|
||||||
|
dlg.do_modal(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "resource.h"
|
Binary file not shown.
After Width: | Height: | Size: 154 KiB |
Binary file not shown.
|
@ -0,0 +1,179 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup Label="ProjectConfigurations">
|
||||||
|
<ProjectConfiguration Include="Debug|Win32">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|Win32">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Win32</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Debug|x64">
|
||||||
|
<Configuration>Debug</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
<ProjectConfiguration Include="Release|x64">
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>x64</Platform>
|
||||||
|
</ProjectConfiguration>
|
||||||
|
</ItemGroup>
|
||||||
|
<PropertyGroup Label="Globals">
|
||||||
|
<VCProjectVersion>16.0</VCProjectVersion>
|
||||||
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
<ProjectGuid>{3178ddc5-6524-48f0-b5e3-dcc55965cd30}</ProjectGuid>
|
||||||
|
<RootNamespace>hghelper</RootNamespace>
|
||||||
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>true</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||||
|
<ConfigurationType>Application</ConfigurationType>
|
||||||
|
<UseDebugLibraries>false</UseDebugLibraries>
|
||||||
|
<PlatformToolset>v142</PlatformToolset>
|
||||||
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
|
<CharacterSet>Unicode</CharacterSet>
|
||||||
|
</PropertyGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
|
<ImportGroup Label="ExtensionSettings">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="Shared">
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
</ImportGroup>
|
||||||
|
<PropertyGroup Label="UserMacros" />
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
<OutDir>$(ProjectDir)..\..\solution\$(Configuration)\</OutDir>
|
||||||
|
<IntDir>$(OutDir)$(ProjectName)\</IntDir>
|
||||||
|
<IncludePath>$(ProjectDir)..\..\..\sdk\include\;$(ProjectDir)..\sdk\include\</IncludePath>
|
||||||
|
<LibraryPath>$(ProjectDir)..\sdk\lib\$(Configuration)\;$(LibraryPath)</LibraryPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
<OutDir>$(ProjectDir)..\..\solution\$(Configuration)\</OutDir>
|
||||||
|
<IntDir>$(OutDir)$(ProjectName)\</IntDir>
|
||||||
|
<IncludePath>$(ProjectDir)..\..\..\sdk\include\;$(ProjectDir)..\sdk\include\</IncludePath>
|
||||||
|
<LibraryPath>$(ProjectDir)..\sdk\lib\$(Configuration)\;$(LibraryPath)</LibraryPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<LinkIncremental>true</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<LinkIncremental>false</LinkIncremental>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
<ClCompile>
|
||||||
|
<WarningLevel>Level3</WarningLevel>
|
||||||
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
|
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||||
|
<SDLCheck>true</SDLCheck>
|
||||||
|
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
</ClCompile>
|
||||||
|
<Link>
|
||||||
|
<SubSystem>Windows</SubSystem>
|
||||||
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
</Link>
|
||||||
|
</ItemDefinitionGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="DlgBase.h" />
|
||||||
|
<ClInclude Include="DlgMain.h" />
|
||||||
|
<ClInclude Include="DlgPageAdvConfig.h" />
|
||||||
|
<ClInclude Include="DlgPageErrMsg.h" />
|
||||||
|
<ClInclude Include="framework.h" />
|
||||||
|
<ClInclude Include="hg-helper.h" />
|
||||||
|
<ClInclude Include="ini_file.h" />
|
||||||
|
<ClInclude Include="Resource.h" />
|
||||||
|
<ClInclude Include="targetver.h" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="DlgBase.cpp" />
|
||||||
|
<ClCompile Include="DlgMain.cpp" />
|
||||||
|
<ClCompile Include="DlgPageAdvConfig.cpp" />
|
||||||
|
<ClCompile Include="DlgPageErrMsg.cpp" />
|
||||||
|
<ClCompile Include="hg-helper.cpp" />
|
||||||
|
<ClCompile Include="ini_file.cpp" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ResourceCompile Include="hg-helper.rc" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Image Include="hg-helper.ico" />
|
||||||
|
<Image Include="small.ico" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
</ImportGroup>
|
||||||
|
</Project>
|
|
@ -0,0 +1,79 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<ItemGroup>
|
||||||
|
<Filter Include="源文件">
|
||||||
|
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||||
|
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="头文件">
|
||||||
|
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||||
|
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||||
|
</Filter>
|
||||||
|
<Filter Include="资源文件">
|
||||||
|
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||||
|
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||||
|
</Filter>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClInclude Include="framework.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="targetver.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="Resource.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="hg-helper.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="DlgBase.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="DlgMain.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="DlgPageAdvConfig.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="DlgPageErrMsg.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="ini_file.h">
|
||||||
|
<Filter>头文件</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ClCompile Include="hg-helper.cpp">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="DlgBase.cpp">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="DlgMain.cpp">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="DlgPageAdvConfig.cpp">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="DlgPageErrMsg.cpp">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="ini_file.cpp">
|
||||||
|
<Filter>源文件</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ResourceCompile Include="hg-helper.rc">
|
||||||
|
<Filter>资源文件</Filter>
|
||||||
|
</ResourceCompile>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Image Include="small.ico">
|
||||||
|
<Filter>资源文件</Filter>
|
||||||
|
</Image>
|
||||||
|
<Image Include="hg-helper.ico">
|
||||||
|
<Filter>资源文件</Filter>
|
||||||
|
</Image>
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
|
@ -0,0 +1,262 @@
|
||||||
|
|
||||||
|
#include "ini_file.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
#pragma warning(disable: 4996)
|
||||||
|
|
||||||
|
#if defined(WIN32) || defined(_WIN64)
|
||||||
|
#define bzero(b, s) memset(b, 0, s)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
simple_ini::simple_ini()
|
||||||
|
{}
|
||||||
|
simple_ini::~simple_ini()
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
std::string simple_ini::temporary_path(void)
|
||||||
|
{
|
||||||
|
#if defined(WIN32) || defined(_WIN64)
|
||||||
|
char path[MAX_PATH] = { 0 };
|
||||||
|
|
||||||
|
if (GetTempPathA(_countof(path) - 1, path))
|
||||||
|
{
|
||||||
|
if (path[lstrlenA(path) - 1] == '\\')
|
||||||
|
path[lstrlenA(path) - 1] = 0;
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
#else
|
||||||
|
return "/tmp";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
bool simple_ini::skip_empty(char*& ptr)
|
||||||
|
{
|
||||||
|
char* p = ptr;
|
||||||
|
while(*ptr == ' ' || *ptr == '\t' || *ptr == '\r' || *ptr == '\n')
|
||||||
|
ptr++;
|
||||||
|
|
||||||
|
return ptr > p;
|
||||||
|
}
|
||||||
|
void simple_ini::trime(char*& ptr)
|
||||||
|
{
|
||||||
|
skip_empty(ptr);
|
||||||
|
|
||||||
|
char* tail = ptr + strlen(ptr) - 1;
|
||||||
|
while (tail >= ptr)
|
||||||
|
{
|
||||||
|
if (*tail != ' ' && *tail != '\t' && *tail != '\r' && *tail != '\n')
|
||||||
|
break;
|
||||||
|
tail--;
|
||||||
|
}
|
||||||
|
tail[1] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int simple_ini::load(const char* local_file)
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
#if (defined(WIN32) || defined(_WIN64)) && !defined(UNIFY_OS)
|
||||||
|
file_ = local_file;
|
||||||
|
#else
|
||||||
|
values_.clear();
|
||||||
|
|
||||||
|
FILE* src = fopen(local_file, "rb");
|
||||||
|
if (src)
|
||||||
|
{
|
||||||
|
char line[256];
|
||||||
|
char* oper = NULL;
|
||||||
|
SECKEY sec;
|
||||||
|
|
||||||
|
bzero(line, sizeof(line));
|
||||||
|
while (fgets(line, sizeof(line) - 1, src))
|
||||||
|
{
|
||||||
|
oper = line;
|
||||||
|
simple_ini::skip_empty(oper);
|
||||||
|
if (strstr(oper, "//") == oper ||
|
||||||
|
strstr(oper, "#") == oper ||
|
||||||
|
*oper == 0)
|
||||||
|
{
|
||||||
|
bzero(line, sizeof(line));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (*oper == '[')
|
||||||
|
{
|
||||||
|
oper++;
|
||||||
|
if (strstr(oper, (char*)"]"))
|
||||||
|
strstr(oper, (char*)"]")[0] = 0;
|
||||||
|
if (sec.sec != oper)
|
||||||
|
{
|
||||||
|
if (sec.vals.size())
|
||||||
|
values_.push_back(sec);
|
||||||
|
sec.vals.clear();
|
||||||
|
|
||||||
|
sec.sec = oper;
|
||||||
|
std::vector<SECKEY>::iterator it = std::find(values_.begin(), values_.end(), oper);
|
||||||
|
if (it != values_.end())
|
||||||
|
{
|
||||||
|
sec = *it;
|
||||||
|
values_.erase(it);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
char* v = strstr(oper, "=");
|
||||||
|
if (v)
|
||||||
|
{
|
||||||
|
*v++ = 0;
|
||||||
|
trime(oper);
|
||||||
|
if (*oper)
|
||||||
|
{
|
||||||
|
trime(v);
|
||||||
|
|
||||||
|
KEYVAL kv;
|
||||||
|
kv.key = oper;
|
||||||
|
kv.val = v;
|
||||||
|
sec.vals.push_back(kv);
|
||||||
|
std::sort(sec.vals.begin(), sec.vals.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bzero(line, sizeof(line));
|
||||||
|
}
|
||||||
|
fclose(src);
|
||||||
|
if (sec.vals.size())
|
||||||
|
values_.push_back(sec);
|
||||||
|
std::sort(values_.begin(), values_.end());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ret = errno;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (!defined(WIN32) && !defined(_WIN64)) || defined(UNIFY_OS)
|
||||||
|
int simple_ini::save(const char* local_file)
|
||||||
|
{
|
||||||
|
FILE* dst = fopen(local_file, "wb");
|
||||||
|
if (dst)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < values_.size(); ++i)
|
||||||
|
{
|
||||||
|
std::string val(values_[i].sec);
|
||||||
|
|
||||||
|
val.insert(0, "[");
|
||||||
|
val += "]\r\n";
|
||||||
|
fwrite(val.c_str(), 1, val.length(), dst);
|
||||||
|
for (size_t j = 0; j < values_[i].vals.size(); ++j)
|
||||||
|
{
|
||||||
|
val = values_[i].vals[j].key + "=" + values_[i].vals[j].val + "\r\n";
|
||||||
|
fwrite(val.c_str(), 1, val.length(), dst);
|
||||||
|
}
|
||||||
|
val = "\r\n";
|
||||||
|
fwrite(val.c_str(), 1, val.length(), dst);
|
||||||
|
}
|
||||||
|
fclose(dst);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string simple_ini::get(const char* sec, const char* key, const char* default_val)
|
||||||
|
{
|
||||||
|
#if (defined(WIN32) || defined(_WIN64)) && !defined(UNIFY_OS)
|
||||||
|
char str[MAX_PATH] = { 0 };
|
||||||
|
GetPrivateProfileStringA(sec, key, default_val, str, _countof(str), file_.c_str());
|
||||||
|
|
||||||
|
return str;
|
||||||
|
#else
|
||||||
|
std::vector<SECKEY>::iterator it = std::find(values_.begin(), values_.end(), sec);
|
||||||
|
if (it == values_.end())
|
||||||
|
return default_val;
|
||||||
|
|
||||||
|
std::vector<KEYVAL>::iterator it1 = std::find(it->vals.begin(), it->vals.end(), key);
|
||||||
|
if (it1 == it->vals.end())
|
||||||
|
return default_val;
|
||||||
|
else
|
||||||
|
return it1->val;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
int simple_ini::get(const char* sec, std::vector<KEYVAL>& vals)
|
||||||
|
{
|
||||||
|
std::vector<SECKEY>::iterator it = std::find(values_.begin(), values_.end(), sec);
|
||||||
|
if (it == values_.end())
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
int cnt = 0;
|
||||||
|
for (auto& v : it->vals)
|
||||||
|
{
|
||||||
|
vals.push_back(v);
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cnt;
|
||||||
|
}
|
||||||
|
void simple_ini::set(const char* sec, const char* key, const char* val)
|
||||||
|
{
|
||||||
|
#if (defined(WIN32) || defined(_WIN64)) && !defined(UNIFY_OS)
|
||||||
|
WritePrivateProfileStringA(sec, key, val, file_.c_str());
|
||||||
|
#else
|
||||||
|
std::vector<SECKEY>::iterator it = std::find(values_.begin(), values_.end(), sec);
|
||||||
|
if (it == values_.end())
|
||||||
|
{
|
||||||
|
KEYVAL kv;
|
||||||
|
SECKEY sk;
|
||||||
|
|
||||||
|
kv.key = key;
|
||||||
|
kv.val = val;
|
||||||
|
sk.sec = sec;
|
||||||
|
sk.vals.push_back(kv);
|
||||||
|
values_.push_back(sk);
|
||||||
|
std::sort(values_.begin(), values_.end());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<KEYVAL>::iterator it1 = std::find(it->vals.begin(), it->vals.end(), key);
|
||||||
|
if (it1 == it->vals.end())
|
||||||
|
{
|
||||||
|
KEYVAL kv;
|
||||||
|
|
||||||
|
kv.key = key;
|
||||||
|
kv.val = val;
|
||||||
|
it->vals.push_back(kv);
|
||||||
|
std::sort(it->vals.begin(), it->vals.end());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
it1->val = val;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void simple_ini::remove(const char* sec, const char* key)
|
||||||
|
{
|
||||||
|
#if (defined(WIN32) || defined(_WIN64)) && !defined(UNIFY_OS)
|
||||||
|
#else
|
||||||
|
std::vector<SECKEY>::iterator it = std::find(values_.begin(), values_.end(), sec);
|
||||||
|
if (it == values_.end())
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::vector<KEYVAL>::iterator it1 = std::find(it->vals.begin(), it->vals.end(), key);
|
||||||
|
if (it1 != it->vals.end())
|
||||||
|
it->vals.erase(it1);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void simple_ini::remove(const char* sec)
|
||||||
|
{
|
||||||
|
#if (defined(WIN32) || defined(_WIN64)) && !defined(UNIFY_OS)
|
||||||
|
#else
|
||||||
|
std::vector<SECKEY>::iterator it = std::find(values_.begin(), values_.end(), sec);
|
||||||
|
if (it != values_.end())
|
||||||
|
values_.erase(it);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
void simple_ini::clear(void)
|
||||||
|
{
|
||||||
|
values_.clear();
|
||||||
|
}
|
|
@ -0,0 +1,73 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if defined(WIN32) || defined(_WIN64)
|
||||||
|
#include <Windows.h>
|
||||||
|
#else
|
||||||
|
#include <string.h>
|
||||||
|
#define stricmp strcasecmp
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
|
|
||||||
|
#define UNIFY_OS
|
||||||
|
|
||||||
|
typedef struct _key_val
|
||||||
|
{
|
||||||
|
std::string key;
|
||||||
|
std::string val;
|
||||||
|
|
||||||
|
bool operator==(const char* k)
|
||||||
|
{
|
||||||
|
return key == k;
|
||||||
|
}
|
||||||
|
bool operator<(const struct _key_val& r)
|
||||||
|
{
|
||||||
|
return key.compare(r.key) < 0;
|
||||||
|
}
|
||||||
|
}KEYVAL;
|
||||||
|
|
||||||
|
class simple_ini
|
||||||
|
{
|
||||||
|
typedef struct _sec_key
|
||||||
|
{
|
||||||
|
std::string sec;
|
||||||
|
std::vector<KEYVAL> vals;
|
||||||
|
bool operator==(const char* s)
|
||||||
|
{
|
||||||
|
return sec == s;
|
||||||
|
}
|
||||||
|
bool operator<(const struct _sec_key& r)
|
||||||
|
{
|
||||||
|
return sec.compare(r.sec) < 0;
|
||||||
|
}
|
||||||
|
}SECKEY;
|
||||||
|
std::vector<SECKEY> values_;
|
||||||
|
|
||||||
|
#if defined(WIN32) || defined(_WIN64)
|
||||||
|
std::string file_;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public:
|
||||||
|
simple_ini();
|
||||||
|
~simple_ini();
|
||||||
|
|
||||||
|
static std::string temporary_path(void);
|
||||||
|
static bool skip_empty(char*& ptr);
|
||||||
|
static void trime(char*& ptr);
|
||||||
|
|
||||||
|
public:
|
||||||
|
int load(const char* local_file);
|
||||||
|
#if (!defined(WIN32) && !defined(_WIN64)) || defined(UNIFY_OS)
|
||||||
|
int save(const char* local_file);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
std::string get(const char* sec, const char* key, const char* default_val = "");
|
||||||
|
int get(const char* sec, std::vector<KEYVAL>& vals); // return count ...
|
||||||
|
void set(const char* sec, const char* key, const char* val);
|
||||||
|
void remove(const char* sec, const char* key);
|
||||||
|
void remove(const char* sec);
|
||||||
|
void clear(void);
|
||||||
|
};
|
|
@ -0,0 +1,51 @@
|
||||||
|
//{{NO_DEPENDENCIES}}
|
||||||
|
// Microsoft Visual C++ 生成的包含文件。
|
||||||
|
// 供 hg-helper.rc 使用
|
||||||
|
//
|
||||||
|
#define IDC_MYICON 2
|
||||||
|
#define IDD_HGHELPER_DIALOG 102
|
||||||
|
#define IDS_APP_TITLE 103
|
||||||
|
#define IDD_ABOUTBOX 103
|
||||||
|
#define IDM_ABOUT 104
|
||||||
|
#define IDM_EXIT 105
|
||||||
|
#define IDI_HGHELPER 107
|
||||||
|
#define IDI_SMALL 108
|
||||||
|
#define IDC_HGHELPER 109
|
||||||
|
#define IDR_MAINFRAME 128
|
||||||
|
#define IDD_MAIN 129
|
||||||
|
#define IDD_ERR_MSG 141
|
||||||
|
#define IDD_ADV_CFG 142
|
||||||
|
#define IDC_PAGES 1000
|
||||||
|
#define IDC_STATIC_PAGE 1001
|
||||||
|
#define IDC_LIST_ERR_CODE 1002
|
||||||
|
#define IDC_EDIT_CONTENT 1003
|
||||||
|
#define IDC_COMBO_METHOD 1004
|
||||||
|
#define IDC_COMBO_LEVEL 1005
|
||||||
|
#define IDC_EDIT_LOG_FILE 1006
|
||||||
|
#define IDC_EDIT_TWAIN_LEVEL 1007
|
||||||
|
#define IDC_CHECK_RECORD_MSGS 1008
|
||||||
|
#define IDC_EDIT_IMG_PATH 1009
|
||||||
|
#define IDC_CHECK_OUT_IMGS 1010
|
||||||
|
#define IDC_EDIT_IMGS_PATH 1011
|
||||||
|
#define IDC_COMBO_NOTIFY_CLOSE 1012
|
||||||
|
#define IDC_CHECK_OPENCV 1013
|
||||||
|
#define IDC_EDIT_MEM_MAX 1014
|
||||||
|
#define IDC_EDIT_CFG_PATH 1015
|
||||||
|
#define IDC_BUTTON1 1016
|
||||||
|
#define IDC_LIST1 1017
|
||||||
|
#define IDC_COMBO_OEM 1018
|
||||||
|
#define IDC_EDIT_CONTENT2 1019
|
||||||
|
#define IDC_EDIT_EOF 1019
|
||||||
|
#define IDC_STATIC -1
|
||||||
|
|
||||||
|
// Next default values for new objects
|
||||||
|
//
|
||||||
|
#ifdef APSTUDIO_INVOKED
|
||||||
|
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||||
|
#define _APS_NO_MFC 1
|
||||||
|
#define _APS_NEXT_RESOURCE_VALUE 131
|
||||||
|
#define _APS_NEXT_COMMAND_VALUE 32771
|
||||||
|
#define _APS_NEXT_CONTROL_VALUE 1018
|
||||||
|
#define _APS_NEXT_SYMED_VALUE 110
|
||||||
|
#endif
|
||||||
|
#endif
|
Binary file not shown.
After Width: | Height: | Size: 45 KiB |
|
@ -0,0 +1,6 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
// // 包含 SDKDDKVer.h 可定义可用的最高版本的 Windows 平台。
|
||||||
|
// 如果希望为之前的 Windows 平台构建应用程序,在包含 SDKDDKVer.h 之前请先包含 WinSDKVer.h 并
|
||||||
|
// 将 _WIN32_WINNT 宏设置为想要支持的平台。
|
||||||
|
#include <SDKDDKVer.h>
|
Binary file not shown.
Loading…
Reference in New Issue