MFCApplication1Dlg.cpp 5.4 KB

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