MFCApplication1Dlg.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. 
  2. // MFCApplication1Dlg.cpp: 实现文件
  3. //
  4. #include "pch.h"
  5. #include "framework.h"
  6. #include "MFCApplication1.h"
  7. #include "MFCApplication1Dlg.h"
  8. #include "afxdialogex.h"
  9. #include "CvxText.h"
  10. #include "BaseUtility.h"
  11. #include "libpdf.h"
  12. #if defined(GNUC)
  13. #pragma GCC diagnostic push
  14. #pragma GCC diagnostic ignored “-Wdeprecated-declarations”
  15. #elif defined(_MSC_VER)
  16. #pragma warning(disable : 4996)
  17. #endif
  18. #include <json/json.h>
  19. #ifdef _DEBUG
  20. #pragma comment(lib, "libpdfd.lib")
  21. #else
  22. #pragma comment(lib, "libpdf.lib")
  23. #endif
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #endif
  27. #define SAFETY_CLOSE_HANDLE( handle ) \
  28. if( NULL != handle ) \
  29. { \
  30. CloseHandle( handle ); \
  31. handle = NULL; \
  32. }
  33. #define SAFETY_EXIT_THREAD( hThread, Timeout ) \
  34. if( NULL != hThread ) \
  35. { \
  36. if( WaitForSingleObject( hThread, Timeout ) == WAIT_TIMEOUT ) \
  37. TerminateThread( hThread, -1 ); \
  38. CloseHandle( hThread ); \
  39. hThread = NULL; \
  40. }
  41. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  42. class CAboutDlg : public CDialogEx
  43. {
  44. public:
  45. CAboutDlg();
  46. // 对话框数据
  47. #ifdef AFX_DESIGN_TIME
  48. enum { IDD = IDD_ABOUTBOX };
  49. #endif
  50. protected:
  51. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  52. // 实现
  53. protected:
  54. DECLARE_MESSAGE_MAP()
  55. };
  56. CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
  57. {
  58. }
  59. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CDialogEx::DoDataExchange(pDX);
  62. }
  63. BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
  64. END_MESSAGE_MAP()
  65. // CMFCApplication1Dlg 对话框
  66. HANDLE _threadProcess = NULL;
  67. DWORD WINAPI ProcessThread(void *param)
  68. {
  69. CMFCApplication1Dlg* pWnd = (CMFCApplication1Dlg*)theApp.m_pMainWnd;
  70. //1.读txt列表
  71. //2.生成图像及图像对应的模板json
  72. Json::Value jsonArray(Json::arrayValue);
  73. Json::Value item;
  74. item["status"] = "1";
  75. item["url"] = "1";
  76. jsonArray.append(item);
  77. Json::Value itemRoot;
  78. itemRoot["status"] = 1;
  79. itemRoot["url"] = "1";
  80. Json::FastWriter writer;
  81. std::string strJson = writer.write(itemRoot);
  82. Json::Features features;
  83. Json::Reader re(features);
  84. Json::Value root;
  85. re.parse(strJson, root);
  86. if (root["status"].isInt() && root["status"].asInt() == 1)
  87. {
  88. string strUrl = root["url"].asString();
  89. }
  90. //3.图像合并成pdf
  91. //通知发送消息到窗口
  92. CString strErrorMsg = L"";
  93. strErrorMsg.Format(L"PDF生成完成!\r\n");
  94. SendMessage(pWnd->m_hWnd, WM_SHOWINFO, (WPARAM)strErrorMsg.GetBuffer(), 1);
  95. strErrorMsg.ReleaseBuffer();
  96. return 0L;
  97. }
  98. CMFCApplication1Dlg::CMFCApplication1Dlg(CWnd* pParent /*=nullptr*/)
  99. : CDialogEx(IDD_MFCAPPLICATION1_DIALOG, pParent)
  100. , m_strMsg(_T(""))
  101. {
  102. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  103. }
  104. void CMFCApplication1Dlg::DoDataExchange(CDataExchange* pDX)
  105. {
  106. CDialogEx::DoDataExchange(pDX);
  107. DDX_Text(pDX, IDC_EDIT_MSG, m_strMsg);
  108. }
  109. BEGIN_MESSAGE_MAP(CMFCApplication1Dlg, CDialogEx)
  110. ON_WM_SYSCOMMAND()
  111. ON_WM_PAINT()
  112. ON_WM_QUERYDRAGICON()
  113. ON_BN_CLICKED(IDOK, &CMFCApplication1Dlg::OnBnClickedOk)
  114. ON_MESSAGE(WM_SHOWINFO, OnShowInfo)
  115. ON_BN_CLICKED(IDCANCEL, &CMFCApplication1Dlg::OnBnClickedCancel)
  116. END_MESSAGE_MAP()
  117. // CMFCApplication1Dlg 消息处理程序
  118. BOOL CMFCApplication1Dlg::OnInitDialog()
  119. {
  120. CDialogEx::OnInitDialog();
  121. // 将“关于...”菜单项添加到系统菜单中。
  122. // IDM_ABOUTBOX 必须在系统命令范围内。
  123. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  124. ASSERT(IDM_ABOUTBOX < 0xF000);
  125. CMenu* pSysMenu = GetSystemMenu(FALSE);
  126. if (pSysMenu != nullptr)
  127. {
  128. BOOL bNameValid;
  129. CString strAboutMenu;
  130. bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
  131. ASSERT(bNameValid);
  132. if (!strAboutMenu.IsEmpty())
  133. {
  134. pSysMenu->AppendMenu(MF_SEPARATOR);
  135. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  136. }
  137. }
  138. // 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动
  139. // 执行此操作
  140. SetIcon(m_hIcon, TRUE); // 设置大图标
  141. SetIcon(m_hIcon, FALSE); // 设置小图标
  142. // TODO: 在此添加额外的初始化代码
  143. return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
  144. }
  145. void CMFCApplication1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
  146. {
  147. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  148. {
  149. CAboutDlg dlgAbout;
  150. dlgAbout.DoModal();
  151. }
  152. else
  153. {
  154. CDialogEx::OnSysCommand(nID, lParam);
  155. }
  156. }
  157. // 如果向对话框添加最小化按钮,则需要下面的代码
  158. // 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序,
  159. // 这将由框架自动完成。
  160. void CMFCApplication1Dlg::OnPaint()
  161. {
  162. if (IsIconic())
  163. {
  164. CPaintDC dc(this); // 用于绘制的设备上下文
  165. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  166. // 使图标在工作区矩形中居中
  167. int cxIcon = GetSystemMetrics(SM_CXICON);
  168. int cyIcon = GetSystemMetrics(SM_CYICON);
  169. CRect rect;
  170. GetClientRect(&rect);
  171. int x = (rect.Width() - cxIcon + 1) / 2;
  172. int y = (rect.Height() - cyIcon + 1) / 2;
  173. // 绘制图标
  174. dc.DrawIcon(x, y, m_hIcon);
  175. }
  176. else
  177. {
  178. CDialogEx::OnPaint();
  179. }
  180. }
  181. //当用户拖动最小化窗口时系统调用此函数取得光标
  182. //显示。
  183. HCURSOR CMFCApplication1Dlg::OnQueryDragIcon()
  184. {
  185. return static_cast<HCURSOR>(m_hIcon);
  186. }
  187. void CMFCApplication1Dlg::OnBnClickedOk()
  188. {
  189. GetDlgItem(IDOK)->EnableWindow(FALSE);
  190. SAFETY_EXIT_THREAD(_threadProcess, 100);
  191. _threadProcess = CreateThread(NULL, 0, ProcessThread, NULL, 0, NULL);
  192. std::vector<string> vecLines;
  193. for (size_t i = 0; i < 100; i++)
  194. {
  195. vecLines.push_back(ConvertGB2312toUTF8("寿1111111112222333"));
  196. }
  197. dataCollectionPaper(1,1000, 10, 100, false, vecLines);
  198. //CDialogEx::OnOK();
  199. }
  200. void CMFCApplication1Dlg::UpdateMsg(CString strMsg)
  201. {
  202. m_strMsg += strMsg;
  203. UpdateData(FALSE);
  204. }
  205. LRESULT CMFCApplication1Dlg::OnShowInfo(WPARAM wParam, LPARAM lParam)
  206. {
  207. char* p = (char*)wParam;
  208. CString str;
  209. str.Format(_T("%s"), p);
  210. m_strMsg += str;
  211. UpdateData(FALSE);
  212. if (lParam == 1)
  213. {
  214. GetDlgItem(IDOK)->EnableWindow(TRUE);
  215. }
  216. return 0;
  217. }
  218. void CMFCApplication1Dlg::OnBnClickedCancel()
  219. {
  220. SAFETY_EXIT_THREAD(_threadProcess, 100);
  221. CDialogEx::OnCancel();
  222. }