ScanExeDlg.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // ScanExeDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "ScanExe.h"
  5. #include "ScanExeDlg.h"
  6. #include "afxdialogex.h"
  7. #include "ScanDll.h"
  8. #include "CommandLineInfoEx.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #endif
  12. // CScanExeDlg 对话框
  13. CScanExeDlg::CScanExeDlg(CWnd* pParent /*=NULL*/)
  14. : CDialogEx(CScanExeDlg::IDD, pParent)
  15. {
  16. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  17. }
  18. void CScanExeDlg::DoDataExchange(CDataExchange* pDX)
  19. {
  20. CDialogEx::DoDataExchange(pDX);
  21. }
  22. BEGIN_MESSAGE_MAP(CScanExeDlg, CDialogEx)
  23. ON_WM_PAINT()
  24. ON_WM_QUERYDRAGICON()
  25. END_MESSAGE_MAP()
  26. // CScanExeDlg 消息处理程序
  27. vector<string> splitEx(const string& src, string separate_character)
  28. {
  29. vector<string> strs;
  30. int separate_characterLen = separate_character.size();//分割字符串的长度,这样就可以支持如“,,”多字符串的分隔符
  31. int lastPosition = 0, index = -1;
  32. while (-1 != (index = src.find(separate_character, lastPosition)))
  33. {
  34. strs.push_back(src.substr(lastPosition, index - lastPosition));
  35. lastPosition = index + separate_characterLen;
  36. }
  37. string lastString = src.substr(lastPosition);//截取最后一个分隔符后的内容
  38. if (!lastString.empty())
  39. strs.push_back(lastString);//如果最后一个分隔符后还有内容就入队
  40. return strs;
  41. }
  42. HWND g_TargetWnd = NULL;
  43. HWND g_thisWnd = NULL;
  44. DWORD WINAPI KeepAliveThread(void* param)
  45. {
  46. HWND wnd = (HWND)param;
  47. char* pData = "scanexe_heart";
  48. while (true)
  49. {
  50. COPYDATASTRUCT cpd;
  51. cpd.dwData = strlen(pData) + sizeof(COPYDATASTRUCT);
  52. cpd.cbData = strlen(pData);
  53. cpd.lpData = (void*)pData;
  54. ::SendMessage(g_TargetWnd, WM_COPYDATA, (WPARAM)g_thisWnd, (LPARAM)&cpd);
  55. Sleep(10000);
  56. }
  57. }
  58. BOOL CScanExeDlg::OnInitDialog()
  59. {
  60. CDialogEx::OnInitDialog();
  61. // 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动
  62. // 执行此操作
  63. SetIcon(m_hIcon, TRUE); // 设置大图标
  64. SetIcon(m_hIcon, FALSE); // 设置小图标
  65. CCommandLineInfoEx cmdinfo;
  66. CCommandLineInfoEx::ParseCommandLine(cmdinfo);
  67. string strWindowHandle;
  68. //MessageBoxA("启动扫描程序");
  69. if (cmdinfo.GetWindowHandle(strWindowHandle))
  70. {
  71. HWND wnd = (HWND)strtol(strWindowHandle.c_str(), 0, 16);
  72. g_TargetWnd = wnd;
  73. g_thisWnd = m_hWnd;
  74. QueueUserWorkItem(KeepAliveThread, NULL, WT_EXECUTELONGFUNCTION);
  75. string strID;
  76. cmdinfo.GetBatchID(strID);
  77. int batch_id = atoi(strID.c_str());
  78. StartScan(wnd, batch_id);
  79. {
  80. char* pData = "scanexe_done";
  81. COPYDATASTRUCT cpd;
  82. cpd.dwData = strlen(pData) + sizeof(COPYDATASTRUCT);
  83. cpd.cbData = strlen(pData);
  84. cpd.lpData = (void*)pData;
  85. ::SendMessage(g_TargetWnd, WM_COPYDATA, (WPARAM)g_thisWnd, (LPARAM)&cpd);
  86. }
  87. }
  88. //TestDb();
  89. OnOK();
  90. // TODO: 在此添加额外的初始化代码
  91. return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
  92. }
  93. // 如果向对话框添加最小化按钮,则需要下面的代码
  94. // 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序,
  95. // 这将由框架自动完成。
  96. void CScanExeDlg::OnPaint()
  97. {
  98. if (IsIconic())
  99. {
  100. CPaintDC dc(this); // 用于绘制的设备上下文
  101. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  102. // 使图标在工作区矩形中居中
  103. int cxIcon = GetSystemMetrics(SM_CXICON);
  104. int cyIcon = GetSystemMetrics(SM_CYICON);
  105. CRect rect;
  106. GetClientRect(&rect);
  107. int x = (rect.Width() - cxIcon + 1) / 2;
  108. int y = (rect.Height() - cyIcon + 1) / 2;
  109. // 绘制图标
  110. dc.DrawIcon(x, y, m_hIcon);
  111. }
  112. else
  113. {
  114. CDialogEx::OnPaint();
  115. }
  116. }
  117. //当用户拖动最小化窗口时系统调用此函数取得光标
  118. //显示。
  119. HCURSOR CScanExeDlg::OnQueryDragIcon()
  120. {
  121. return static_cast<HCURSOR>(m_hIcon);
  122. }