|
@@ -14,6 +14,8 @@
|
|
|
#include "lib_common_depence.h"
|
|
|
#include <direct.h>
|
|
|
#include <io.h>
|
|
|
+#include "Buffers.h"
|
|
|
+#include "Config.h"
|
|
|
|
|
|
#if defined(GNUC)
|
|
|
#pragma GCC diagnostic push
|
|
@@ -164,7 +166,13 @@ HANDLE _threadScan = NULL;
|
|
|
DWORD WINAPI ScanThread(void *param)
|
|
|
{
|
|
|
CMFCApplication1Dlg* pWnd = (CMFCApplication1Dlg*)theApp.m_pMainWnd;
|
|
|
-
|
|
|
+ auto exitfun = [&]() {
|
|
|
+ //通知发送消息到窗口
|
|
|
+ CString strErrorMsg = L"";
|
|
|
+ strErrorMsg.Format(L"扫描线程退出!\r\n");
|
|
|
+ SendMessage(pWnd->m_hWnd, WM_SHOWSCANINFO, (WPARAM)strErrorMsg.GetBuffer(), 1);
|
|
|
+ strErrorMsg.ReleaseBuffer();
|
|
|
+ };
|
|
|
std::vector<std::string> imgPath; //图片本地路径(和上面url地址一一对应)
|
|
|
preinfo::templatesInfo temeplatInfo;
|
|
|
preinfo::SubjChiInfo sujChiInfo;
|
|
@@ -173,8 +181,14 @@ DWORD WINAPI ScanThread(void *param)
|
|
|
{
|
|
|
_mkdir(strTempDir.c_str());
|
|
|
}
|
|
|
- PareseModeJson(temeplatInfo);
|
|
|
- int nRet = api_processing_images("",
|
|
|
+ int nRet = PareseModeJson(temeplatInfo);
|
|
|
+ if (nRet)
|
|
|
+ {
|
|
|
+ pWnd->FormatScanMsg("模板解析识别");
|
|
|
+ exitfun();
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ nRet = api_processing_images("",
|
|
|
strTempDir.c_str(),
|
|
|
temeplatInfo,
|
|
|
sujChiInfo,
|
|
@@ -187,16 +201,9 @@ DWORD WINAPI ScanThread(void *param)
|
|
|
////启动算法扫描功能
|
|
|
if (nRet != RT_OK)
|
|
|
{
|
|
|
- // 扫描异常
|
|
|
- CString strErrorMsg = L"";
|
|
|
- strErrorMsg.Format(L"扫描失败,errorCode:%d!\r\n", nRet);
|
|
|
- SendMessage(pWnd->m_hWnd, WM_SHOWSCANINFO, (WPARAM)strErrorMsg.GetBuffer(), 1);
|
|
|
+ pWnd->FormatScanMsg("扫描失败,errorCode:%d", nRet);
|
|
|
}
|
|
|
- //通知发送消息到窗口
|
|
|
- CString strErrorMsg = L"";
|
|
|
- strErrorMsg.Format(L"扫描完成!\r\n");
|
|
|
- SendMessage(pWnd->m_hWnd, WM_SHOWSCANINFO, (WPARAM)strErrorMsg.GetBuffer(), 1);
|
|
|
- strErrorMsg.ReleaseBuffer();
|
|
|
+ exitfun();
|
|
|
return 0L;
|
|
|
}
|
|
|
CMFCApplication1Dlg::CMFCApplication1Dlg(CWnd* pParent /*=nullptr*/)
|
|
@@ -261,7 +268,13 @@ BOOL CMFCApplication1Dlg::OnInitDialog()
|
|
|
SetIcon(m_hIcon, TRUE); // 设置大图标
|
|
|
SetIcon(m_hIcon, FALSE); // 设置小图标
|
|
|
|
|
|
- // TODO: 在此添加额外的初始化代码
|
|
|
+ CConfig::Instance()->LoadFromINI();
|
|
|
+ GetDlgItem(IDC_EDIT_TXT)->SetWindowText(CConfig::Instance()->m_strTxt);
|
|
|
+ GetDlgItem(IDC_EDIT_PDF)->SetWindowText(CConfig::Instance()->m_strPdf);
|
|
|
+
|
|
|
+ GetDlgItem(IDC_EDIT_MODEPATH)->SetWindowText(CConfig::Instance()->m_strMode);
|
|
|
+ GetDlgItem(IDC_EDIT_IMGPATH)->SetWindowText(CConfig::Instance()->m_strImg);
|
|
|
+ GetDlgItem(IDC_EDIT_CUTPATH)->SetWindowText(CConfig::Instance()->m_strCut);
|
|
|
|
|
|
return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
|
|
|
}
|
|
@@ -403,6 +416,7 @@ void CMFCApplication1Dlg::OnBnClickedCancel()
|
|
|
{
|
|
|
SAFETY_EXIT_THREAD(_threadProcess, 100);
|
|
|
SAFETY_EXIT_THREAD(_threadScan, 100);
|
|
|
+ CConfig::Instance()->SaveSetting();
|
|
|
CDialogEx::OnCancel();
|
|
|
}
|
|
|
|
|
@@ -452,6 +466,7 @@ void CMFCApplication1Dlg::OnBnClickedBtnTxt()
|
|
|
return;
|
|
|
}
|
|
|
pEdit->SetWindowText(strText);
|
|
|
+ CConfig::Instance()->m_strTxt = strText;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -469,6 +484,7 @@ void CMFCApplication1Dlg::OnBnClickedBtnPdf()
|
|
|
return;
|
|
|
}
|
|
|
pEdit->SetWindowText(strText);
|
|
|
+ CConfig::Instance()->m_strPdf = strText;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -486,6 +502,7 @@ void CMFCApplication1Dlg::OnBnClickedBtnModepath()
|
|
|
return;
|
|
|
}
|
|
|
pEdit->SetWindowText(strText);
|
|
|
+ CConfig::Instance()->m_strMode = strText;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -503,6 +520,7 @@ void CMFCApplication1Dlg::OnBnClickedBtnImgpath()
|
|
|
return;
|
|
|
}
|
|
|
pEdit->SetWindowText(strText);
|
|
|
+ CConfig::Instance()->m_strImg = strText;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -520,6 +538,7 @@ void CMFCApplication1Dlg::OnBnClickedBtnCutpath()
|
|
|
return;
|
|
|
}
|
|
|
pEdit->SetWindowText(strText);
|
|
|
+ CConfig::Instance()->m_strCut = strText;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -550,3 +569,21 @@ void CMFCApplication1Dlg::OnBnClickedBtnScan()
|
|
|
SAFETY_EXIT_THREAD(_threadScan, 100);
|
|
|
_threadScan = CreateThread(NULL, 0, ScanThread, NULL, 0, NULL);
|
|
|
}
|
|
|
+
|
|
|
+void CMFCApplication1Dlg::FormatScanMsg(const char *szFmt, ...)
|
|
|
+{
|
|
|
+ if (!szFmt)
|
|
|
+ return;
|
|
|
+
|
|
|
+ va_list ap;
|
|
|
+ va_start(ap, szFmt);
|
|
|
+ size_t nLength = _vsnprintf(nullptr, 0, szFmt, ap) + 1;
|
|
|
+ CBuffers buffer;
|
|
|
+ char* szLogMsg = buffer.GetBuf(nLength);
|
|
|
+ _vsnprintf(szLogMsg, nLength, szFmt, ap);
|
|
|
+ va_end(ap);
|
|
|
+ CString strMsg;
|
|
|
+ // 扫描异常
|
|
|
+ strMsg.Format(L"%s!\r\n", GB2312ToTstring(szLogMsg).c_str());
|
|
|
+ SendMessage(WM_SHOWSCANINFO, (WPARAM)strMsg.GetBuffer(), 0);
|
|
|
+}
|