解决新版twain 设置界面点击取消不能扫描不能使用点击设置,不显示进度指示器崩溃

This commit is contained in:
13038267101 2023-05-03 17:09:05 +08:00
parent 3728253810
commit 8a70b2f6ed
7 changed files with 52 additions and 35 deletions

View File

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommand>C:\Program Files\HuaGoScan\HuaGoScan.exe</LocalDebuggerCommand>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

View File

@ -282,7 +282,7 @@ struct __declspec(novtable) ISaneInvoker : public IRef
// ui ...
COM_API_DECLARE(bool, ui_show_main(HWND parent));
COM_API_DECLARE(bool, ui_show_setting(HWND parent, bool with_scan, bool indicator = true));
COM_API_DECLARE(bool, ui_show_progress(HWND parent));
COM_API_DECLARE(bool, ui_show_progress(HWND parent, bool bIndicator));
COM_API_DECLARE(void, ui_hide(void));
COM_API_DECLARE(bool, ui_is_ok(void));

View File

@ -386,7 +386,7 @@ scanner::scanner(SCANNERID id) : handle_(NULL), id_(id), ex_id_(EXTENSION_ID_BAS
, dpi_(200), tmp_path_(L""), img_ind_(0)
, scanner_name_(L""), cfg_(NULL), is_ui_wait_img_(false), is_scanning_(false)
, scanner_ev_handler_(NULL), evh_param_(NULL), app_wnd_(NULL), user_cancel_(false)
, max_img_mem_(1 * 1024), twain_set_(false), ev_cnt_(0)
, max_img_mem_(1 * 1024), twain_set_(false), ev_cnt_(0), is_bIndicator(false)
{
sane_api_.sane_cancel_api = inner_sane_cancel;
sane_api_.sane_close_api = inner_sane_close;
@ -2410,8 +2410,8 @@ COM_API_IMPLEMENT(scanner, int, start(void))
if (ret == SANE_STATUS_GOOD)
{
if (indicator_.get() && !IsWindowVisible(indicator_->hwnd()))
indicator_->show(true);
/*if (indicator_.get() && !IsWindowVisible(indicator_->hwnd()))
indicator_->show(true);*/
unsigned int l = sizeof(img_fmt_);
SANE_CompressionType cmprsn = img_fmt_.compress.compression;
@ -2427,8 +2427,8 @@ COM_API_IMPLEMENT(scanner, int, start(void))
{
std::wstring msg(local_trans::a2u(hg_scanner_err_description(ret), CP_UTF8));
if (indicator_.get())
indicator_->show(false);
//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);
@ -2959,6 +2959,11 @@ COM_API_IMPLEMENT(scanner, bool, ui_show_setting(HWND parent, bool with_scan, bo
//start();
on_ui_event(SANE_EVENT_UI_SCAN_COMMAND, NULL);
}
else if (res == UI_RESULT_CLOSE_CANCEL)
{
int ev = SANE_EVENT_UI_CLOSE_CANCEL;
on_ui_event(ev, (void*)ev);
}
//on_ui_event(ev, NULL);
}
else if (cfg_)
@ -2989,9 +2994,10 @@ COM_API_IMPLEMENT(scanner, bool, ui_show_setting(HWND parent, bool with_scan, bo
return true;
}
COM_API_IMPLEMENT(scanner, bool, ui_show_progress(HWND parent))
COM_API_IMPLEMENT(scanner, bool, ui_show_progress(HWND parent, bool bIndicator))
{
if (callback::show_progress_ui)
is_bIndicator = bIndicator;
if (callback::show_progress_ui && bIndicator)
{
auto ui_process = [this](ui_result res)
{
@ -3023,14 +3029,14 @@ COM_API_IMPLEMENT(scanner, bool, ui_show_progress(HWND parent))
}
else
{
if (setting_.get() && IsWindowVisible(setting_->hwnd()))
/*if (setting_.get() && IsWindowVisible(setting_->hwnd()))
parent = setting_->hwnd();
else if (!IsWindow(parent))
parent = callback::find_main_wnd();
indicator_.reset(new dlg_indicator(parent));
indicator_->set_ui_event_notify(&scanner::ui_callback, this);
indicator_->show(true);
indicator_->show(true);*/
}
return true;
@ -3054,12 +3060,16 @@ int scanner::handle_device_event(int ev_code, void* data, unsigned int* len)
{
if (ev_code == SANE_EVENT_WORKING)
{
if (indicator_.get())
indicator_->notify_working();
else
//if (indicator_.get())
// indicator_->notify_working();
//else on_ui_event(ev_code, (void*)ev_code);
if (callback::show_progress_ui && is_bIndicator)
ui_notify(ev_code, data, 0);
//else
on_ui_event(ev_code, (void*)ev_code);
ui_notify(ev_code, data, 0);
log_info(L"Scanning ...\r\n", 0);
}
@ -3093,8 +3103,8 @@ int scanner::handle_device_event(int ev_code, void* data, unsigned int* len)
{
img->release();
}
if (indicator_.get())
indicator_->notify_data_arrived(true);
//if (indicator_.get())
// indicator_->notify_data_arrived(true);
{
wchar_t msg[128] = { 0 };
@ -3104,21 +3114,19 @@ int scanner::handle_device_event(int ev_code, void* data, unsigned int* len)
}
else if (ev_code == SANE_EVENT_USB_DATA_RECEIVED)
{
if (indicator_.get())
indicator_->notify_data_arrived(false);
//if (indicator_.get())
// indicator_->notify_data_arrived(false);
}
else if (ev_code == SANE_EVENT_SCAN_FINISHED)
{
err_ = *len;
if (indicator_.get())
indicator_->notify_scan_over((char*)data, *len != SCANNER_ERR_OK);
else if (callback::show_progress_ui)
{
//if (indicator_.get())
// indicator_->notify_scan_over((char*)data, *len != SCANNER_ERR_OK);
if (callback::show_progress_ui && is_bIndicator)
ui_notify(ev_code, data, 0);
}
else
{
if (*len)
//if (*len)
{
std::wstring msg(local_trans::a2u((char*)data, CP_UTF8));
if(!IsWindow(app_wnd_))

View File

@ -38,6 +38,7 @@ class scanner : public ISaneInvoker, virtual public refer
int ex_id_;
int prev_start_result_;
int dpi_;
bool is_bIndicator;
unsigned int img_ind_;
std::wstring scanner_name_;
std::wstring tmp_path_;
@ -315,7 +316,7 @@ public:
// ui ...
COM_API_OVERRIDE(bool, ui_show_main(HWND parent));
COM_API_OVERRIDE(bool, ui_show_setting(HWND parent, bool with_scan, bool indicator = true));
COM_API_OVERRIDE(bool, ui_show_progress(HWND parent));
COM_API_OVERRIDE(bool, ui_show_progress(HWND parent, bool bIndicator));
COM_API_OVERRIDE(void, ui_hide(void));
COM_API_OVERRIDE(bool, ui_is_ok(void));

View File

@ -78,11 +78,11 @@
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\OEM\huagao\</OutDir>
<IntDir>$(SolutionDir)..\..\tmp\$(PlatformTarget)\huagao\$(Configuration)\$(ProjectName)\</IntDir>
<LibraryPath>$(LibraryPath)</LibraryPath>
<TargetName>huagaotwain400.ds</TargetName>
<TargetName>huagaotwain200.ds</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LibraryPath>$(LibraryPath)</LibraryPath>
<TargetName>huagaotwain400.ds</TargetName>
<TargetName>huagaotwain200.ds</TargetName>
<LinkIncremental>true</LinkIncremental>
<IncludePath>$(SolutionDir)..\..\sdk\include\;$(SolutionDir)..\..\sdk\include\twain\;$(IncludePath)</IncludePath>
<OutDir>$(SolutionDir)..\..\release\win\$(PlatformTarget)\OEM\huagao\</OutDir>
@ -126,9 +126,9 @@
<Command>copy "$(TargetPath)" C:\Windows\twain_32\HuagoTwain\$(TargetName) /y
move /Y "$(TargetPath)" "$(OutputPath)$(TargetName)"
mkdir "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
move /Y "$(OutputPath)$(TargetName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
move /Y "$(OutputPath)$(TargetName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
move /Y "$(OutputPath)$(TargetName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"</Command>
copy /Y "$(OutputPath)$(TargetName).lib" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
copy /Y "$(OutputPath)$(TargetName).exp" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"
copy /Y "$(OutputPath)$(TargetName).pdb" "$(ProjectDir)..\..\sdk\lib\win\$(PlatformTarget)\OEM\huagao"</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">

View File

@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommand>D:\work\code\twain-samples-master\TWAIN-Samples\Twain_App_sample01\visual_studio_mfc\Release\TWAIN_App_mfc32.exe</LocalDebuggerCommand>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
<LocalDebuggerWorkingDirectory>C:\Windows\twain_32\HuaGoTwain</LocalDebuggerWorkingDirectory>
</PropertyGroup>
</Project>

View File

@ -1173,8 +1173,9 @@ Result huagao_ds::userInterfaceEnable(const Identity&, UserInterface& ui)
{
if (!ui.showUi())
{
if (m_bIndicator && !scanner_->ui_show_progress((HWND)ui.parent().raw()))
return seqError();
scanner_->ui_show_progress((HWND)ui.parent().raw(), m_bIndicator);
//if (m_bIndicator && !)
// return seqError();
xfer_ready_failed_ = false;
scanner_->twain_set_transfer((twain_xfer)m_capXferMech);
@ -3467,7 +3468,7 @@ int huagao_ds::handle_scanner_event(int ev, bool from_event_proc)
break;
case SANE_EVENT_UI_SCAN_COMMAND:
if (m_bIndicator)
scanner_->ui_show_progress(NULL);
scanner_->ui_show_progress(NULL, m_bIndicator);
else
scanner_->ui_hide();
scanner_status_ = SCANNER_STATUS_SCAN_1;