From 82cb2745fe2529795d780d433d0aa84f53e85aa2 Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Fri, 2 Jun 2023 14:34:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E7=AC=AC=E4=B8=80=E6=AC=A1?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E6=89=93=E5=BC=80ds=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E6=8F=90=E7=A4=BAmsgbox?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/twain_user/HGTwainImpl.cpp | 17 +++++++++++++---- modules/twain_user/app_cfg.cpp | 21 +++++++++++++++++++++ modules/twain_user/app_cfg.h | 2 ++ modules/twainui/twainui.cpp | 7 ++++++- 4 files changed, 42 insertions(+), 5 deletions(-) diff --git a/modules/twain_user/HGTwainImpl.cpp b/modules/twain_user/HGTwainImpl.cpp index aaddda09..17e7a5d2 100644 --- a/modules/twain_user/HGTwainImpl.cpp +++ b/modules/twain_user/HGTwainImpl.cpp @@ -166,7 +166,9 @@ HGResult HGTwainDSMImpl::OpenDS(HGUInt index, class HGTwainDSImpl** dsImpl) return ret; } - saveCfgValue("twain", "source", m_vds[index].ProductName); + saveCfgValue("twain", "showMsgBox", true); + std::string DSName = m_vds[index].ProductName; + saveCfgValue("twain", "source", DSName); m_listDSImpl.push_back(newDSImpl); *dsImpl = newDSImpl; return HGBASE_ERR_OK; @@ -184,6 +186,7 @@ HGResult HGTwainDSMImpl::OpenDefaultDS(class HGTwainDSImpl** dsImpl) return HGBASE_ERR_FAIL; } + saveCfgValue("twain", "showMsgBox", false); std::string sourceName = getCfgValue("twain", "source", std::string("")); int index = -1; @@ -209,7 +212,8 @@ HGResult HGTwainDSMImpl::OpenDefaultDS(class HGTwainDSImpl** dsImpl) return ret; } - saveCfgValue("twain", "source", m_vds[index].ProductName); + std::string DSName = m_vds[index].ProductName; + saveCfgValue("twain", "source", DSName); m_listDSImpl.push_back(newDSImpl); *dsImpl = newDSImpl; return HGBASE_ERR_OK; @@ -222,6 +226,8 @@ HGResult HGTwainDSMImpl::OpenSelectedDS(class HGTwainDSImpl** dsImpl) return HGBASE_ERR_INVALIDARG; } + saveCfgValue("twain", "showMsgBox", true); + TW_IDENTITY selectDS; if (TWRC_SUCCESS != m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_USERSELECT, &selectDS)) { @@ -236,7 +242,8 @@ HGResult HGTwainDSMImpl::OpenSelectedDS(class HGTwainDSImpl** dsImpl) return ret; } - saveCfgValue("twain", "source", selectDS.ProductName); + std::string DSName = selectDS.ProductName; + saveCfgValue("twain", "source", DSName); m_listDSImpl.push_back(newDSImpl); *dsImpl = newDSImpl; return HGBASE_ERR_OK; @@ -249,6 +256,7 @@ HGResult HGTwainDSMImpl::OpenSelectedDSEx(class HGTwainDSImpl** dsImpl) return HGBASE_ERR_INVALIDARG; } + saveCfgValue("twain", "showMsgBox", true); std::string sourceName = getCfgValue("twain", "source", std::string("")); TW_IDENTITY selectDS; @@ -271,7 +279,8 @@ HGResult HGTwainDSMImpl::OpenSelectedDSEx(class HGTwainDSImpl** dsImpl) return ret; } - saveCfgValue("twain", "source", selectDS.ProductName); + std::string DSName = selectDS.ProductName; + saveCfgValue("twain", "source", DSName); m_listDSImpl.push_back(newDSImpl); *dsImpl = newDSImpl; return HGBASE_ERR_OK; diff --git a/modules/twain_user/app_cfg.cpp b/modules/twain_user/app_cfg.cpp index 955e57eb..af1c1c12 100644 --- a/modules/twain_user/app_cfg.cpp +++ b/modules/twain_user/app_cfg.cpp @@ -16,6 +16,17 @@ std::string getCfgValue(const char *appName, const char *key, const std::string return StdStringToUtf8(value).c_str(); } +bool getCfgValue(const char *appName, const char *key, bool def) +{ + HGChar cfgPath[512]; + HGBase_GetConfigPath(cfgPath, 512); + strcat(cfgPath, "config.ini"); + + HGInt value = 0; + HGBase_GetProfileInt(cfgPath, appName, key, (HGInt)def, &value); + return (bool)value; +} + void saveCfgValue(const char *appName, const char *key, const std::string &value) { HGChar cfgPath[512]; @@ -25,3 +36,13 @@ void saveCfgValue(const char *appName, const char *key, const std::string &value HGBase_SetProfileString(cfgPath, appName, key, value.c_str()); } + +void saveCfgValue(const char *appName, const char *key, bool value) +{ + HGChar cfgPath[512]; + HGBase_GetConfigPath(cfgPath, 512); + HGBase_CreateDir(cfgPath); + strcat(cfgPath, "config.ini"); + + HGBase_SetProfileInt(cfgPath, appName, key, (HGInt)value); +} diff --git a/modules/twain_user/app_cfg.h b/modules/twain_user/app_cfg.h index 2736dc0a..96f8f248 100644 --- a/modules/twain_user/app_cfg.h +++ b/modules/twain_user/app_cfg.h @@ -4,6 +4,8 @@ #include std::string getCfgValue(const char *appName, const char *key, const std::string &def); +bool getCfgValue(const char *appName, const char *key, bool def); void saveCfgValue(const char *appName, const char *key, const std::string &value); +void saveCfgValue(const char *appName, const char *key, bool value); #endif /* __APP_CFG_H__ */ diff --git a/modules/twainui/twainui.cpp b/modules/twainui/twainui.cpp index 0fddbe78..dcf7b7cf 100644 --- a/modules/twainui/twainui.cpp +++ b/modules/twainui/twainui.cpp @@ -9,6 +9,7 @@ #include "device_menu.h" #include "base/HGBase.h" #include "Manager.h" +#include "app_cfg.h" #ifdef HG_CMP_MSC #include "qwinwidget.hpp" @@ -206,7 +207,11 @@ int show_messagebox_ui(HWND parent, int event, void *msg, int flag) g_manager = new Manager; } - return g_manager->showMessageBoxUi(nullptr == g_hThread, parent, event, msg, flag); + bool showMsgBox = getCfgValue("twain", "showMsgBox", false); + if (showMsgBox) + return g_manager->showMessageBoxUi(nullptr == g_hThread, parent, event, msg, flag); + + return 0; } int show_twain_srclist_ui(const TW_IDENTITY *vds, HGUInt count, const HGChar *defDsName, HGWindow parent, TW_IDENTITY *ds)