// ScanExeDlg.cpp : 实现文件 // #include "stdafx.h" #include "ScanExe.h" #include "ScanExeDlg.h" #include "afxdialogex.h" #include "ScanDll.h" #include "CommandLineInfoEx.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CScanExeDlg 对话框 CScanExeDlg::CScanExeDlg(CWnd* pParent /*=NULL*/) : CDialogEx(CScanExeDlg::IDD, pParent) { m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CScanExeDlg::DoDataExchange(CDataExchange* pDX) { CDialogEx::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CScanExeDlg, CDialogEx) ON_WM_PAINT() ON_WM_QUERYDRAGICON() END_MESSAGE_MAP() // CScanExeDlg 消息处理程序 vector splitEx(const string& src, string separate_character) { vector strs; int separate_characterLen = separate_character.size();//分割字符串的长度,这样就可以支持如“,,”多字符串的分隔符 int lastPosition = 0, index = -1; while (-1 != (index = src.find(separate_character, lastPosition))) { strs.push_back(src.substr(lastPosition, index - lastPosition)); lastPosition = index + separate_characterLen; } string lastString = src.substr(lastPosition);//截取最后一个分隔符后的内容 if (!lastString.empty()) strs.push_back(lastString);//如果最后一个分隔符后还有内容就入队 return strs; } HWND g_TargetWnd = NULL; HWND g_thisWnd = NULL; DWORD WINAPI KeepAliveThread(void* param) { HWND wnd = (HWND)param; char* pData = "scanexe_heart"; while (true) { COPYDATASTRUCT cpd; cpd.dwData = strlen(pData) + sizeof(COPYDATASTRUCT); cpd.cbData = strlen(pData); cpd.lpData = (void*)pData; ::SendMessage(g_TargetWnd, WM_COPYDATA, (WPARAM)g_thisWnd, (LPARAM)&cpd); Sleep(10000); } } BOOL CScanExeDlg::OnInitDialog() { CDialogEx::OnInitDialog(); // 设置此对话框的图标。 当应用程序主窗口不是对话框时,框架将自动 // 执行此操作 SetIcon(m_hIcon, TRUE); // 设置大图标 SetIcon(m_hIcon, FALSE); // 设置小图标 CCommandLineInfoEx cmdinfo; CCommandLineInfoEx::ParseCommandLine(cmdinfo); string strWindowHandle; //MessageBoxA("启动扫描程序"); if (cmdinfo.GetWindowHandle(strWindowHandle)) { HWND wnd = (HWND)strtol(strWindowHandle.c_str(), 0, 16); g_TargetWnd = wnd; g_thisWnd = m_hWnd; QueueUserWorkItem(KeepAliveThread, NULL, WT_EXECUTELONGFUNCTION); string strID; cmdinfo.GetBatchID(strID); int batch_id = atoi(strID.c_str()); StartScan(wnd, batch_id); { char* pData = "scanexe_done"; COPYDATASTRUCT cpd; cpd.dwData = strlen(pData) + sizeof(COPYDATASTRUCT); cpd.cbData = strlen(pData); cpd.lpData = (void*)pData; ::SendMessage(g_TargetWnd, WM_COPYDATA, (WPARAM)g_thisWnd, (LPARAM)&cpd); } } //TestDb(); OnOK(); // TODO: 在此添加额外的初始化代码 return TRUE; // 除非将焦点设置到控件,否则返回 TRUE } // 如果向对话框添加最小化按钮,则需要下面的代码 // 来绘制该图标。 对于使用文档/视图模型的 MFC 应用程序, // 这将由框架自动完成。 void CScanExeDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // 用于绘制的设备上下文 SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0); // 使图标在工作区矩形中居中 int cxIcon = GetSystemMetrics(SM_CXICON); int cyIcon = GetSystemMetrics(SM_CYICON); CRect rect; GetClientRect(&rect); int x = (rect.Width() - cxIcon + 1) / 2; int y = (rect.Height() - cyIcon + 1) / 2; // 绘制图标 dc.DrawIcon(x, y, m_hIcon); } else { CDialogEx::OnPaint(); } } //当用户拖动最小化窗口时系统调用此函数取得光标 //显示。 HCURSOR CScanExeDlg::OnQueryDragIcon() { return static_cast(m_hIcon); }