不显示指示框的错误信息提示

This commit is contained in:
13038267101 2023-05-04 10:36:55 +08:00
parent 8a70b2f6ed
commit ee54680fdc
1 changed files with 69 additions and 37 deletions

View File

@ -345,6 +345,7 @@ namespace callback
int (*apply_current_config)(const char* dev_name, SANE_Handle device, LPSANEAPI api) = NULL; // 应用设备的当前配置 int (*apply_current_config)(const char* dev_name, SANE_Handle device, LPSANEAPI api) = NULL; // 应用设备的当前配置
int (*show_setting_ui)(SANE_Handle device, HWND parent, LPSANEAPI api, const char* devname, bool with_scan) = NULL; int (*show_setting_ui)(SANE_Handle device, HWND parent, LPSANEAPI api, const char* devname, bool with_scan) = NULL;
int (*show_progress_ui)(HWND parent, std::function<void(ui_result)> callback, std::function<void(int/*event*/, void*/*msg*/, int/*flag*/)>* notify) = NULL; int (*show_progress_ui)(HWND parent, std::function<void(ui_result)> callback, std::function<void(int/*event*/, void*/*msg*/, int/*flag*/)>* notify) = NULL;
int (*show_messagebox_ui)(HWND parent, int/*event*/, void*/*msg*/, int/*flag*/) = NULL;
//std::function<void(ui_result)> ui_result_callback; //std::function<void(ui_result)> ui_result_callback;
std::function<void(int/*event*/, void*/*msg*/, int/*flag*/)> notify; std::function<void(int/*event*/, void*/*msg*/, int/*flag*/)> notify;
@ -376,6 +377,7 @@ namespace callback
GET_API(apply_current_config); GET_API(apply_current_config);
GET_API(show_setting_ui); GET_API(show_setting_ui);
GET_API(show_progress_ui); GET_API(show_progress_ui);
GET_API(show_messagebox_ui);
} }
} }
} }
@ -877,12 +879,20 @@ int scanner::open(void)
} }
else else
{ {
std::wstring msg(local_trans::a2u(hg_scanner_err_description(ret), CP_UTF8)); if (callback::show_messagebox_ui)
HWND parent = callback::find_main_wnd(); {
callback::show_messagebox_ui(app_wnd_, ret, (void*)hg_scanner_err_description(ret), 0);
}
else
{
std::wstring msg(local_trans::a2u(hg_scanner_err_description(ret), CP_UTF8));
if (!IsWindow(parent)) //if (indicator_.get())
callback::bring_message_box_topmost(local_trans::lang_trans_between_hz936(CONST_STRING_OPEN_FAILED).c_str()); // indicator_->show(false);
MessageBoxW(parent, msg.c_str(), local_trans::lang_trans_between_hz936(CONST_STRING_OPEN_FAILED).c_str(), MB_OK | MB_ICONERROR); if (!IsWindow(app_wnd_))
callback::bring_message_box_topmost(local_trans::lang_trans_between_hz936(CONST_STRING_START_FAILED).c_str());
MessageBoxW(app_wnd_, msg.c_str(), local_trans::lang_trans_between_hz936(CONST_STRING_START_FAILED).c_str(), MB_OK | MB_ICONERROR);
}
} }
return ret; return ret;
@ -2425,13 +2435,30 @@ COM_API_IMPLEMENT(scanner, int, start(void))
//} //}
else else
{ {
std::wstring msg(local_trans::a2u(hg_scanner_err_description(ret), CP_UTF8)); if (callback::show_progress_ui && is_bIndicator)
{
int ev = ret;
//if (indicator_.get()) ui_notify(ev, (void *)hg_scanner_err_description(ret), 0);
// indicator_->show(false); }
if (!IsWindow(app_wnd_)) else
callback::bring_message_box_topmost(local_trans::lang_trans_between_hz936(CONST_STRING_START_FAILED).c_str()); {
MessageBoxW(app_wnd_, msg.c_str(), local_trans::lang_trans_between_hz936(CONST_STRING_START_FAILED).c_str(), MB_OK | MB_ICONERROR);
if (callback::show_messagebox_ui)
{
callback::show_messagebox_ui(app_wnd_, ret, (void*)hg_scanner_err_description(ret), 0);
}
else
{
std::wstring msg(local_trans::a2u(hg_scanner_err_description(ret), CP_UTF8));
//if (indicator_.get())
// indicator_->show(false);
if (!IsWindow(app_wnd_))
callback::bring_message_box_topmost(local_trans::lang_trans_between_hz936(CONST_STRING_START_FAILED).c_str());
MessageBoxW(app_wnd_, msg.c_str(), local_trans::lang_trans_between_hz936(CONST_STRING_START_FAILED).c_str(), MB_OK | MB_ICONERROR);
}
}
} }
prev_start_result_ = ret; prev_start_result_ = ret;
is_scanning_ = ret == SANE_STATUS_GOOD; is_scanning_ = ret == SANE_STATUS_GOOD;
@ -2997,33 +3024,34 @@ COM_API_IMPLEMENT(scanner, bool, ui_show_setting(HWND parent, bool with_scan, bo
COM_API_IMPLEMENT(scanner, bool, ui_show_progress(HWND parent, bool bIndicator)) COM_API_IMPLEMENT(scanner, bool, ui_show_progress(HWND parent, bool bIndicator))
{ {
is_bIndicator = bIndicator; is_bIndicator = bIndicator;
auto ui_process = [this](ui_result res)
{
int uev = SANE_EVENT_SCAN_FINISHED;
switch (res)
{
case UI_RESULT_FAILED:
break;
case UI_RESULT_OK:
break;
case UI_RESULT_CLOSE_NORMAL:
uev = SANE_EVENT_UI_CLOSE_NORMAL;
on_ui_event(uev, (void*)uev);
break;
case UI_RESULT_CLOSE_CANCEL:
uev = SANE_EVENT_UI_CLOSE_CANCEL;
on_ui_event(uev, (void*)uev);
break;
case UI_RESULT_START_SCAN:
break;
default:
break;
}
};
if (callback::show_progress_ui && bIndicator) if (callback::show_progress_ui && bIndicator)
{ {
auto ui_process = [this](ui_result res)
{
int uev = SANE_EVENT_SCAN_FINISHED;
switch (res)
{
case UI_RESULT_FAILED:
break;
case UI_RESULT_OK:
break;
case UI_RESULT_CLOSE_NORMAL:
uev = SANE_EVENT_UI_CLOSE_NORMAL;
on_ui_event(uev, (void*)uev);
break;
case UI_RESULT_CLOSE_CANCEL:
uev = SANE_EVENT_UI_CLOSE_CANCEL;
on_ui_event(uev, (void*)uev);
break;
case UI_RESULT_START_SCAN:
break;
default:
break;
}
};
callback::show_progress_ui(parent, ui_process,&ui_notify); callback::show_progress_ui(parent, ui_process,&ui_notify);
} }
@ -3126,7 +3154,11 @@ int scanner::handle_device_event(int ev_code, void* data, unsigned int* len)
ui_notify(ev_code, data, 0); ui_notify(ev_code, data, 0);
else else
{ {
//if (*len) if (callback::show_messagebox_ui && *len)
{
callback::show_messagebox_ui(app_wnd_, ev_code, (void*)data, 0);
}
else if (*len) //错误弹出
{ {
std::wstring msg(local_trans::a2u((char*)data, CP_UTF8)); std::wstring msg(local_trans::a2u((char*)data, CP_UTF8));
if(!IsWindow(app_wnd_)) if(!IsWindow(app_wnd_))