同步OPT界面;范围值支持跟随其它属性
This commit is contained in:
parent
101239518e
commit
ed13494e28
|
@ -49,7 +49,7 @@
|
|||
"desc": "选择色彩模式",
|
||||
"type": "string",
|
||||
"fix-id": 34819,
|
||||
"size": 54,
|
||||
"size": 24,
|
||||
"cur": "24位彩色",
|
||||
"default": "24位彩色",
|
||||
"range": ["24位彩色", "256级灰度", "黑白", "颜色自动识别"],
|
||||
|
@ -159,7 +159,7 @@
|
|||
"desc": "选择锐化效果或模糊效果",
|
||||
"type": "string",
|
||||
"fix-id": 34825,
|
||||
"size": 48,
|
||||
"size": 20,
|
||||
"cur": "无",
|
||||
"default": "无",
|
||||
"range": ["无", "锐化", "进一步锐化", "模糊", "进一步模糊"],
|
||||
|
@ -237,10 +237,10 @@
|
|||
"desc": "设置出图大小",
|
||||
"type": "string",
|
||||
"fix-id": 34831,
|
||||
"size": 96,
|
||||
"size": 44,
|
||||
"cur": "匹配原始尺寸",
|
||||
"default": "匹配原始尺寸",
|
||||
"range": ["A3", "8开", "A4", "A4横向", "16开", "16开横向", "A5", "A5横向", "A6", "A6横向", "B4", "B5", "B5横向", "B6", "B6横向", "Letter", "Letter横向", "Double Letter", "LEGAL", "匹配原始尺寸", {
|
||||
"range": ["A3", "8开", "A4", "16开", "A5", "A6", "B4", "B5", "B6", "Letter", "Double Letter", "LEGAL", "匹配原始尺寸", {
|
||||
"resolution<500": "最大扫描尺寸自动裁切"
|
||||
}, {
|
||||
"resolution<500": "最大扫描尺寸"
|
||||
|
@ -248,6 +248,20 @@
|
|||
"resolution<500": "三联试卷"
|
||||
}]
|
||||
},
|
||||
"lateral": {
|
||||
"cat": "base",
|
||||
"group": "base",
|
||||
"title": "横向",
|
||||
"desc": "横向放置纸张",
|
||||
"type": "bool",
|
||||
"fix-id": 34924,
|
||||
"affect": 6,
|
||||
"visible": 0,
|
||||
"size": 4,
|
||||
"cur": false,
|
||||
"default": false,
|
||||
"depend": "paper==A4 || paper==16开 || paper==A5 || paper==A6 || paper==B5 || paper==B6 || paper==Letter"
|
||||
},
|
||||
"is-custom-area": {
|
||||
"cat": "base",
|
||||
"group": "base",
|
||||
|
@ -342,7 +356,7 @@
|
|||
"size": 4,
|
||||
"cur": false,
|
||||
"default": false,
|
||||
"depend": "paper==A3||paper==A4||paper==A4横向||paper==A5||paper==A5横向||paper==A6||paper==A6横向||paper==B4||paper==B5||paper==B5横向||paper==B6||paper==B6横向||paper==Double Letter||paper==LEGAL||paper==Letter||paper==Letter横向"
|
||||
"depend": "paper==A3||paper==A4||paper==A5||paper==A6||paper==B4||paper==B5||paper==B6||paper==Double Letter||paper==LEGAL||paper==Letter"
|
||||
},
|
||||
"page": {
|
||||
"cat": "base",
|
||||
|
@ -351,10 +365,10 @@
|
|||
"desc": "设置页面扫描方式",
|
||||
"type": "string",
|
||||
"fix-id": 34838,
|
||||
"size": 78,
|
||||
"size": 12,
|
||||
"cur": "双面",
|
||||
"default": "双面",
|
||||
"range": ["单面", "双面", "跳过空白页(通用)", "跳过空白页(发票纸)", "对折"]
|
||||
"range": ["正面", "背面", "双面", "对折"]
|
||||
},
|
||||
"discardblank": {
|
||||
"cat": "base",
|
||||
|
@ -382,7 +396,7 @@
|
|||
"max": 100,
|
||||
"step": 1
|
||||
},
|
||||
"depend": "page==跳过空白页(发票纸)||page==跳过空白页(通用)||discardblank==true"
|
||||
"depend": "discardblank==true"
|
||||
},
|
||||
"fold-type": {
|
||||
"cat": "base",
|
||||
|
@ -391,7 +405,7 @@
|
|||
"desc": "",
|
||||
"type": "string",
|
||||
"fix-id": 34887,
|
||||
"size": 42,
|
||||
"size": 16,
|
||||
"cur": "左右对折",
|
||||
"default": "左右对折",
|
||||
"range": ["左右对折", "上下对折", "自动对折"],
|
||||
|
@ -423,7 +437,7 @@
|
|||
"desc": "选择扫描仪的画质模式",
|
||||
"type": "string",
|
||||
"fix-id": 34841,
|
||||
"size": 42,
|
||||
"size": 16,
|
||||
"cur": "画质优先",
|
||||
"default": "画质优先",
|
||||
"range": ["速度优先", "画质优先"],
|
||||
|
@ -439,7 +453,7 @@
|
|||
"size": 4,
|
||||
"cur": false,
|
||||
"default": false,
|
||||
"depend": "page!=单面"
|
||||
"depend": "page==双面"
|
||||
},
|
||||
"is-custom-gamma": {
|
||||
"cat": "base",
|
||||
|
@ -536,7 +550,7 @@
|
|||
"size": 4,
|
||||
"cur": false,
|
||||
"default": false,
|
||||
"depend": "page!=对折&&page!=跳过空白页(发票纸)&&page!=跳过空白页(通用)"
|
||||
"depend": "page!=对折"
|
||||
},
|
||||
"is-erase-black-frame": {
|
||||
"cat": "base",
|
||||
|
@ -556,7 +570,7 @@
|
|||
"desc": "选择背景填充方式",
|
||||
"type": "string",
|
||||
"fix-id": 34854,
|
||||
"size": 42,
|
||||
"size": 16,
|
||||
"cur": "凸多边形",
|
||||
"default": "凸多边形",
|
||||
"range": ["凸多边形", "凹多边形"],
|
||||
|
@ -655,7 +669,7 @@
|
|||
"desc": "选择防止渗透的等级",
|
||||
"type": "string",
|
||||
"fix-id": 34856,
|
||||
"size": 30,
|
||||
"size": 12,
|
||||
"cur": "较弱",
|
||||
"default": "较弱",
|
||||
"range": ["弱", "较弱", "一般", "较强", "强"],
|
||||
|
@ -791,7 +805,7 @@
|
|||
"desc": "设置结束待纸扫描的时间",
|
||||
"type": "string",
|
||||
"fix-id": 34920,
|
||||
"size": 42,
|
||||
"size": 16,
|
||||
"cur": "60s",
|
||||
"default": "60s",
|
||||
"range": ["15s", "30s", "60s", "2min", "4min", "8min"],
|
||||
|
@ -804,7 +818,7 @@
|
|||
"desc": "选择指定数量扫描或连续扫描",
|
||||
"type": "string",
|
||||
"fix-id": 34862,
|
||||
"size": 54,
|
||||
"size": 24,
|
||||
"cur": "连续扫描",
|
||||
"default": "连续扫描",
|
||||
"range": ["连续扫描", "扫描指定张数"],
|
||||
|
@ -829,7 +843,7 @@
|
|||
"desc": "设置图像的方向",
|
||||
"type": "string",
|
||||
"fix-id": 34864,
|
||||
"size": 72,
|
||||
"size": 32,
|
||||
"cur": "0°",
|
||||
"default": "0°",
|
||||
"range": ["0°", "90°", "180°", "-90°", "自动文本方向识别°"]
|
||||
|
@ -844,7 +858,7 @@
|
|||
"size": 4,
|
||||
"cur": false,
|
||||
"default": false,
|
||||
"depend": "page!=单面&&page!=对折&&direction!=自动文本方向识别°"
|
||||
"depend": "page!=对折&&direction!=自动文本方向识别°"
|
||||
},
|
||||
"is-ultrosonic": {
|
||||
"cat": "base",
|
||||
|
@ -864,7 +878,7 @@
|
|||
"desc": "检测到双张进纸后的处理方式",
|
||||
"type": "string",
|
||||
"fix-id": 34872,
|
||||
"size": 72,
|
||||
"size": 32,
|
||||
"cur": "丢弃图像并停止扫描",
|
||||
"default": "丢弃图像并停止扫描",
|
||||
"range": ["丢弃图像并停止扫描", "上传图像并停止扫描"],
|
||||
|
@ -972,7 +986,7 @@
|
|||
"desc": "设置扫描仪的分纸力度",
|
||||
"type": "string",
|
||||
"fix-id": 34874,
|
||||
"size": 30,
|
||||
"size": 12,
|
||||
"cur": "一般",
|
||||
"default": "一般",
|
||||
"range": ["弱", "一般", "强"],
|
||||
|
@ -985,7 +999,7 @@
|
|||
"desc": "设置扫描仪的休眠时间",
|
||||
"type": "string",
|
||||
"fix-id": 34875,
|
||||
"size": 36,
|
||||
"size": 16,
|
||||
"cur": "不休眠",
|
||||
"default": "不休眠",
|
||||
"range": ["不休眠", "五分钟", "十分钟", "半小时", "一小时", "两小时", "四小时"]
|
||||
|
|
|
@ -2735,8 +2735,10 @@ void CDlgOptJson::OnBnClickedButtonSet()
|
|||
dlg.vals_.push_back(cv);
|
||||
}
|
||||
|
||||
len += 4;
|
||||
len *= 3;
|
||||
len += 7;
|
||||
len /= 4;
|
||||
len *= 4;
|
||||
SetDlgItemInt(IDC_EDIT_SIZE, len);
|
||||
}
|
||||
}
|
||||
|
@ -2863,12 +2865,15 @@ void CDlgOptJson::OnBnClickedButtonSet()
|
|||
}
|
||||
else
|
||||
{
|
||||
opt.size = 0;
|
||||
for (auto& v : dlg.init_)
|
||||
{
|
||||
CONDVAL cv;
|
||||
cv.cond = local_trans::u2a(v.cond.c_str(), CP_UTF8);
|
||||
cv.val = std::string((const char*)v.val.c_str(), v.val.length() * 2 + 2);
|
||||
opt.def_val.push_back(cv);
|
||||
if (opt.size < v.val.length())
|
||||
opt.size = v.val.length();
|
||||
}
|
||||
|
||||
opt.range.clear();
|
||||
|
@ -2879,7 +2884,14 @@ void CDlgOptJson::OnBnClickedButtonSet()
|
|||
cv.val = std::string((const char*)v.val.c_str(), v.val.length() * 2 + 2);
|
||||
cv.cond = local_trans::u2a(v.cond.c_str(), CP_UTF8);
|
||||
opt.range.push_back(cv);
|
||||
if (opt.size < v.val.length())
|
||||
opt.size = v.val.length();
|
||||
}
|
||||
|
||||
opt.size *= 3;
|
||||
opt.size += 7;
|
||||
opt.size /= 4;
|
||||
opt.size *= 4;
|
||||
}
|
||||
|
||||
// add or insert ...
|
||||
|
@ -3609,7 +3621,7 @@ void CDlgOptJson::OnBnClickedButtonShowui()
|
|||
|
||||
test_sane_ui::init_api(&api);
|
||||
{
|
||||
dlg_setting dlg(::GetParent(m_hWnd), &api, (SANE_Handle)&sane, false, L"Test");
|
||||
dlg_setting dlg(::GetParent(m_hWnd), &api, (SANE_Handle)&sane, false, L"Test", true);
|
||||
|
||||
dlg.do_modal(::GetParent(m_hWnd));
|
||||
}
|
||||
|
|
|
@ -77,49 +77,129 @@ static IMPLEMENT_OPTION_STRING_COMPARE(is_sane_opt);
|
|||
static HMODULE g_my_inst = NULL;
|
||||
|
||||
std::wstring dlg_base::prop_name = L"dlg_base_object_prop_name";
|
||||
volatile bool dlg_base::msg_thread_exited_ = true;
|
||||
|
||||
dlg_base::dlg_base(HWND parent, UINT idd) : parent_(parent), hwnd_(NULL), idd_(idd), ui_event_notify_(NULL), ui_notify_param_(NULL)
|
||||
, msg_thread_id_(0), destroyed_(false), child_(false), del_at_destroy_(false)
|
||||
{
|
||||
}
|
||||
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_);
|
||||
//if (IsWindow(hwnd_))
|
||||
//{
|
||||
// //SetPropW(hwnd_, dlg_base::prop_name.c_str(), NULL);
|
||||
// //if (GetCurrentThreadId() == GetWindowThreadProcessId(hwnd_, NULL))
|
||||
// // DestroyWindow(hwnd_);
|
||||
// //show(false);
|
||||
// //PostMessage(hwnd_, WM_DESTROY, 0, 0);
|
||||
//}
|
||||
|
||||
//if (!child_)
|
||||
//{
|
||||
// EnableWindow(parent_, TRUE);
|
||||
// BringWindowToTop(parent_);
|
||||
//}
|
||||
|
||||
//if (msg_thread_.get())
|
||||
//{
|
||||
// PostThreadMessageW(msg_thread_id_, WM_QUIT_MSG_THREAD, 0, 0);
|
||||
// if (msg_thread_->joinable())
|
||||
// msg_thread_->join();
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// destroyed_ = false;
|
||||
// //PostMessageW(hwnd(), WM_DESTROY, 0, 0);
|
||||
// //while (!destroyed_)
|
||||
// //{
|
||||
// // MSG msg = { 0 };
|
||||
// // PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE);
|
||||
// //}
|
||||
//}
|
||||
}
|
||||
|
||||
BOOL CALLBACK dlg_base::dlg_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
|
||||
{
|
||||
// https://learn.microsoft.com/zh-cn/windows/win32/api/winuser/nc-winuser-dlgproc:
|
||||
// 尽管对话框过程类似于窗口过程,但它不得调用 DefWindowProc 函数来处理不需要的消息
|
||||
dlg_base* obj = (dlg_base*)GetPropW(hwnd, dlg_base::prop_name.c_str());
|
||||
BOOL ret = FALSE;
|
||||
|
||||
if (msg == WM_INITDIALOG)
|
||||
{
|
||||
dlg_base* obj = (dlg_base*)lp;
|
||||
obj = (dlg_base*)lp;
|
||||
|
||||
SetPropW(hwnd, dlg_base::prop_name.c_str(), (HANDLE)obj);
|
||||
obj->hwnd_ = hwnd;
|
||||
obj->child_ = (GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD) == WS_CHILD;
|
||||
}
|
||||
else if (msg == WM_DESTROY)
|
||||
else if (msg == WM_NCDESTROY)
|
||||
{
|
||||
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);
|
||||
if (msg == WM_INITDIALOG)
|
||||
obj->ready_ = true;
|
||||
else if (msg == WM_CLOSE)
|
||||
{
|
||||
DestroyWindow(hwnd);
|
||||
ret = TRUE;
|
||||
}
|
||||
else if (msg == WM_NCDESTROY)
|
||||
{
|
||||
if (!obj->child_)
|
||||
{
|
||||
EnableWindow(obj->parent_, TRUE);
|
||||
BringWindowToTop(obj->parent_);
|
||||
}
|
||||
obj->destroyed_ = true;
|
||||
if(obj->del_at_destroy_)
|
||||
delete obj;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
DWORD WINAPI dlg_base::start_thread(LPVOID lp)
|
||||
{
|
||||
dlg_base::msg_thread_exited_ = false;
|
||||
((dlg_base*)lp)->thread_pump_message();
|
||||
dlg_base::msg_thread_exited_ = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dlg_base::thread_pump_message(void)
|
||||
{
|
||||
msg_thread_id_ = GetCurrentThreadId();
|
||||
hwnd_ = CreateDialogParamW(g_my_inst, MAKEINTRESOURCE(idd_), parent_, (DLGPROC)&dlg_base::dlg_proc, (LPARAM)this);
|
||||
if (IsWindow(hwnd_))
|
||||
{
|
||||
MSG msg = { 0 };
|
||||
BOOL ret = TRUE;
|
||||
HWND hwnd = hwnd_;
|
||||
while ((ret = GetMessageW(&msg, NULL, 0, 0)))
|
||||
{
|
||||
|
||||
if (ret == -1 || msg.message == WM_QUIT_MSG_THREAD)
|
||||
break;
|
||||
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessageW(&msg);
|
||||
//if (msg.message == WM_DESTROY)
|
||||
//{
|
||||
// if (msg.hwnd == hwnd)
|
||||
// break;
|
||||
//}
|
||||
}
|
||||
DestroyWindow(hwnd);
|
||||
//if (del_at_destroy_)
|
||||
// delete this;
|
||||
}
|
||||
}
|
||||
|
||||
void dlg_base::screen_2_client(HWND wnd, LPRECT r)
|
||||
{
|
||||
|
@ -240,6 +320,10 @@ void dlg_base::center_window(HWND wnd, HWND parent, int ensure)
|
|||
|
||||
MoveWindow(wnd, rme.left, rme.top, RECT_W(rme), RECT_H(rme), FALSE);
|
||||
}
|
||||
bool dlg_base::is_message_thread_exited(void)
|
||||
{
|
||||
return dlg_base::msg_thread_exited_;
|
||||
}
|
||||
int dlg_base::list_insert_column(HWND list_wnd, const wchar_t* text, int cx, int ind)
|
||||
{
|
||||
LVCOLUMNW col = { 0 };
|
||||
|
@ -321,17 +405,64 @@ void dlg_base::on_font_changed(void)
|
|||
{
|
||||
|
||||
}
|
||||
void dlg_base::create(void)
|
||||
void dlg_base::create(bool sole_thread)
|
||||
{
|
||||
// InitCommonControls();
|
||||
hwnd_ = CreateDialogParamW(g_my_inst, MAKEINTRESOURCE(idd_), parent_, (DLGPROC)&dlg_base::dlg_proc, (LPARAM)this);
|
||||
if (sole_thread)
|
||||
{
|
||||
HANDLE h = CreateThread(NULL, 0, &dlg_base::start_thread, this, 0, &msg_thread_id_);
|
||||
if (h)
|
||||
{
|
||||
CloseHandle(h);
|
||||
while (!IsWindow(hwnd_))
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
}
|
||||
else
|
||||
hwnd_ = CreateDialogParamW(g_my_inst, MAKEINTRESOURCE(idd_), parent_, (DLGPROC)&dlg_base::dlg_proc, (LPARAM)this);
|
||||
}
|
||||
namespace notify
|
||||
{
|
||||
typedef struct _notify_param
|
||||
{
|
||||
void(__stdcall* ui_event_notify)(int uev, void* sender, void* param);
|
||||
void* param;
|
||||
int ev;
|
||||
void* sender;
|
||||
}NOTIFYPARAM, *LPNOTIFYPARAM;
|
||||
static DWORD WINAPI thread_notify(LPVOID lp)
|
||||
{
|
||||
LPNOTIFYPARAM param = (LPNOTIFYPARAM)lp;
|
||||
|
||||
if(param->ui_event_notify)
|
||||
param->ui_event_notify(param->ev, param->sender, param->param);
|
||||
delete param;
|
||||
|
||||
return 0;
|
||||
}
|
||||
static void notify(void(__stdcall* f)(int, void*, void*), int ev, void* sender, void* param)
|
||||
{
|
||||
LPNOTIFYPARAM p = new NOTIFYPARAM;
|
||||
HANDLE h = NULL;
|
||||
|
||||
p->ui_event_notify = f;
|
||||
p->sender = sender;
|
||||
p->ev = ev;
|
||||
p->param = param;
|
||||
|
||||
h = CreateThread(NULL, 0, thread_notify, p, 0, NULL);
|
||||
if (h)
|
||||
CloseHandle(h);
|
||||
else
|
||||
delete p;
|
||||
}
|
||||
}
|
||||
void dlg_base::notify_ui_event(int ev)
|
||||
{
|
||||
if (ui_event_notify_)
|
||||
if (ev == SANE_EVENT_UI_SCAN_COMMAND && ui_event_notify_)
|
||||
ui_event_notify_(ev, this, ui_notify_param_);
|
||||
else
|
||||
::PostMessage(hwnd(), WM_QUIT, 0, 0); // EndDialog(hwnd(), ev);
|
||||
notify::notify(ui_event_notify_, ev, this, ui_notify_param_);
|
||||
}
|
||||
|
||||
void dlg_base::set_ui_event_notify(void(__stdcall* notify)(int, void*, void*), void* param)
|
||||
|
@ -345,6 +476,12 @@ HWND dlg_base::hwnd(void)
|
|||
}
|
||||
void dlg_base::show(bool visible, bool hold)
|
||||
{
|
||||
while (!ready_)
|
||||
{
|
||||
MSG msg = { 0 };
|
||||
PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE);
|
||||
}
|
||||
|
||||
UINT cmd = visible ? SW_SHOW : SW_HIDE;
|
||||
DWORD style = GetWindowLong(hwnd_, GWL_STYLE);
|
||||
|
||||
|
@ -385,6 +522,7 @@ void dlg_base::show(bool visible, bool hold)
|
|||
pt.y = r0.top;
|
||||
SetWindowPos(hwnd_, after, pt.x, pt.y, RECT_W(rme), RECT_H(rme), SWP_NOSIZE);
|
||||
UpdateWindow(hwnd_);
|
||||
center_window(hwnd_, parent_);
|
||||
}
|
||||
EnableWindow(parent_, !visible);
|
||||
}
|
||||
|
@ -409,7 +547,8 @@ void dlg_base::show(bool visible, bool hold)
|
|||
int dlg_base::do_modal(HWND parent)
|
||||
{
|
||||
BOOL enable_parent = FALSE,
|
||||
got = TRUE;
|
||||
got = TRUE,
|
||||
wait_destory = FALSE;
|
||||
MSG msg = { 0 };
|
||||
|
||||
modal_exit_ = 0;
|
||||
|
@ -434,13 +573,21 @@ int dlg_base::do_modal(HWND parent)
|
|||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
if (modal_exit_)
|
||||
break;
|
||||
}
|
||||
ShowWindow(hwnd(), SW_HIDE);
|
||||
{
|
||||
if (destroyed_)
|
||||
break;
|
||||
else if (!wait_destory)
|
||||
{
|
||||
wait_destory = true;
|
||||
ShowWindow(hwnd(), SW_HIDE);
|
||||
|
||||
if (enable_parent)
|
||||
{
|
||||
EnableWindow(parent, TRUE);
|
||||
if (enable_parent)
|
||||
{
|
||||
EnableWindow(parent, TRUE);
|
||||
}
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return modal_exit_;
|
||||
|
@ -450,6 +597,13 @@ void dlg_base::quit_modal(int non_zero_code)
|
|||
// assert ( non_zero_code );
|
||||
modal_exit_ = non_zero_code;
|
||||
}
|
||||
void dlg_base::close(void)
|
||||
{
|
||||
if(msg_thread_id_) // 独立的消息循环,则退出
|
||||
PostMessageW(hwnd_, WM_QUIT, 0, 0);
|
||||
else // 共用父窗口消息循环,则关闭窗口。关闭窗口消息由自己处理,不提交到默认过程
|
||||
PostMessageW(hwnd_, WM_CLOSE, 0, 0);
|
||||
}
|
||||
void dlg_base::enable(bool enable)
|
||||
{
|
||||
EnableWindow(hwnd_, enable);
|
||||
|
@ -696,6 +850,8 @@ dlg_page::dlg_page(HWND parent, const wchar_t* name
|
|||
, id_custom_gamma_(-1), id_paper_(-1), paper_(L"A4"), id_dpi_(-1), dpi_(200), vsb_pos_(0), hsb_pos_(0)
|
||||
, vsb_(false), hsb_(false)
|
||||
{
|
||||
del_at_destroy_ = true;
|
||||
|
||||
size_.cx = size_.cy = 0;
|
||||
pos_.x = 12;
|
||||
pos_.y = 15;
|
||||
|
@ -704,8 +860,6 @@ dlg_page::dlg_page(HWND parent, const wchar_t* name
|
|||
}
|
||||
dlg_page::~dlg_page()
|
||||
{
|
||||
for (auto& v : ctrls_)
|
||||
DestroyWindow(v);
|
||||
}
|
||||
|
||||
BOOL dlg_page::handle_message(UINT msg, WPARAM wp, LPARAM lp)
|
||||
|
@ -735,6 +889,10 @@ BOOL dlg_page::handle_message(UINT msg, WPARAM wp, LPARAM lp)
|
|||
track_mouse_hover();
|
||||
on_mouse_hover(LOWORD(lp), HIWORD(lp), wp);
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
for (auto& v : ctrls_)
|
||||
DestroyWindow(v);
|
||||
break;
|
||||
default:
|
||||
ret = FALSE;
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <vector>
|
||||
#include <sane/sane_ex.h>
|
||||
#include <sane/sane_option_definitions.h>
|
||||
#include <thread>
|
||||
|
||||
// CDlgIndicator 对话框
|
||||
#define FLOAT_FORMAT L"%.2f"
|
||||
|
@ -20,6 +21,7 @@
|
|||
#define RECT_W(r) (r.right - r.left)
|
||||
#define RECT_H(r) (r.bottom - r.top)
|
||||
|
||||
#define WM_QUIT_MSG_THREAD WM_USER + 300
|
||||
#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
|
||||
|
@ -40,12 +42,23 @@ namespace local_trans
|
|||
class dlg_base
|
||||
{
|
||||
int modal_exit_; // set non-ZERO code to exit modal dialog
|
||||
DWORD msg_thread_id_;
|
||||
volatile bool destroyed_;
|
||||
bool child_;
|
||||
|
||||
static volatile bool msg_thread_exited_;
|
||||
|
||||
static DWORD WINAPI start_thread(LPVOID lp);
|
||||
void thread_pump_message(void);
|
||||
|
||||
protected:
|
||||
HWND hwnd_;
|
||||
HWND parent_;
|
||||
UINT idd_;
|
||||
bool abandon_hold_;
|
||||
bool del_at_destroy_; // 是否在窗口销毁时,自动释放对象
|
||||
volatile bool ready_ = false;
|
||||
|
||||
void(__stdcall* ui_event_notify_)(int uev, void* sender, void* param);
|
||||
void* ui_notify_param_;
|
||||
static std::wstring prop_name;
|
||||
|
@ -53,7 +66,7 @@ protected:
|
|||
|
||||
virtual BOOL handle_message(UINT msg, WPARAM wp, LPARAM lp);
|
||||
virtual void on_font_changed(void);
|
||||
void create(void);
|
||||
void create(bool sole_thread = false);
|
||||
void notify_ui_event(int ev);
|
||||
|
||||
public:
|
||||
|
@ -77,6 +90,7 @@ public:
|
|||
ENSURE_VISIBLE_BOTTOM
|
||||
};
|
||||
static void center_window(HWND wnd, HWND parent, int ensure = ENSURE_VISIBLE_NONE);
|
||||
static bool is_message_thread_exited(void);
|
||||
|
||||
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);
|
||||
|
@ -90,8 +104,9 @@ 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);
|
||||
int do_modal(HWND parent); // 该函数调用之后,自动销毁窗口。如果要反复使用,需要调整窗口创建时机,放到该函数入口处。(FIXED ME ...)
|
||||
void quit_modal(int non_zero_code);
|
||||
void close(void);
|
||||
void enable(bool enable);
|
||||
void screen_2_client(LPRECT r);
|
||||
void client_2_screen(LPRECT r);
|
||||
|
|
|
@ -14,13 +14,13 @@
|
|||
static IMPLEMENT_OPTION_STRING_COMPARE(cmp_sane_opt);
|
||||
|
||||
|
||||
dlg_setting::dlg_setting(HWND parent, LPSANEAPI api, SANE_Handle dev, bool with_scan, const wchar_t* name) : dlg_base(parent, IDD_SETTING)
|
||||
dlg_setting::dlg_setting(HWND parent, LPSANEAPI api, SANE_Handle dev, bool with_scan, const wchar_t* name, bool sole_thread) : dlg_base(parent, IDD_SETTING)
|
||||
, sane_api_(*api), sane_dev_(dev), with_scan_(with_scan)
|
||||
, papers_(0), images_(0), err_(false), tab_(NULL), twain_set_(nullptr)
|
||||
, schm_from_empty_(false)
|
||||
, schm_from_empty_(false), name_(name ? name : L"")
|
||||
{
|
||||
|
||||
create();
|
||||
create(sole_thread);
|
||||
}
|
||||
dlg_setting::~dlg_setting()
|
||||
{
|
||||
|
@ -64,6 +64,22 @@ BOOL dlg_setting::handle_message(UINT msg, WPARAM wp, LPARAM lp)
|
|||
*(void**)lp = nullptr;
|
||||
}
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
if (IsWindow(tab_))
|
||||
{
|
||||
for (int i = 0; i < get_tab_count(); ++i)
|
||||
{
|
||||
TCITEMW item = { 0 };
|
||||
|
||||
item.mask = TCIF_PARAM;
|
||||
TabCtrl_GetItem(tab_, i, &item);
|
||||
if (item.lParam)
|
||||
DestroyWindow(((dlg_page*)item.lParam)->hwnd());
|
||||
}
|
||||
DestroyWindow(tab_);
|
||||
}
|
||||
DestroyMenu(cfg_menu_);
|
||||
break;
|
||||
default:
|
||||
ret = FALSE;
|
||||
break;
|
||||
|
@ -78,17 +94,20 @@ void dlg_setting::handle_command(WORD code, WORD id, HANDLE ctrl)
|
|||
// menu command ...
|
||||
if (id == IDCANCEL)
|
||||
{
|
||||
//quit_modal(id);
|
||||
notify_over();
|
||||
}
|
||||
}
|
||||
else if (id == IDOK)
|
||||
{
|
||||
//quit_modal(id);
|
||||
notify_over();
|
||||
}
|
||||
}
|
||||
void dlg_setting::notify_over(void)
|
||||
{
|
||||
notify_ui_event(SANE_EVENT_UI_CLOSE_SETTING);
|
||||
//notify_ui_event(SANE_EVENT_UI_CLOSE_SETTING);
|
||||
quit_modal(IDOK);
|
||||
}
|
||||
void dlg_setting::on_init_dialog(void)
|
||||
{
|
||||
|
|
|
@ -28,6 +28,7 @@ class dlg_setting : public dlg_base
|
|||
std::wstring cfg_file_;
|
||||
bool *twain_set_;
|
||||
bool schm_from_empty_;
|
||||
std::wstring name_;
|
||||
|
||||
HMENU cfg_menu_;
|
||||
|
||||
|
@ -51,7 +52,7 @@ class dlg_setting : public dlg_base
|
|||
void save_changes_to_cur_scheme(int reason);
|
||||
|
||||
public:
|
||||
dlg_setting(HWND parent, LPSANEAPI api, SANE_Handle dev, bool with_scan, const wchar_t* name);
|
||||
dlg_setting(HWND parent, LPSANEAPI api, SANE_Handle dev, bool with_scan, const wchar_t* name, bool sole_thread);
|
||||
~dlg_setting();
|
||||
|
||||
public:
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue