123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- // HJHomeworkDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "HJHomework.h"
- #include "HJHomeworkDlg.h"
- #include "afxdialogex.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // CHJHomeworkDlg 对话框
- #define WM_TO_TRAY_MSG (WM_USER + 2)
- CHJHomeworkDlg::CHJHomeworkDlg(CWnd* pParent /*=NULL*/)
- : CDialogEx(CHJHomeworkDlg::IDD, pParent)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- m_hFontMessage = CreateFont(-12, 0, 0, 0, FW_THIN,
- 0, 0, 0, DEFAULT_CHARSET, OUT_CHARACTER_PRECIS,
- CLIP_CHARACTER_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH |
- FF_DONTCARE, L"微软雅黑");
- m_bMonitor = FALSE;
- }
- void CHJHomeworkDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialogEx::DoDataExchange(pDX);
- }
- BEGIN_MESSAGE_MAP(CHJHomeworkDlg, CDialogEx)
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_WM_CLOSE()
- ON_WM_COPYDATA()
- END_MESSAGE_MAP()
- BOOL CHJHomeworkDlg::OnInitDialog()
- {
- CDialogEx::OnInitDialog();
- m_unZipManager.SetMainHwnd(GetSafeHwnd(), PirntLog);
- SetIcon(m_hIcon, TRUE);
- SetIcon(m_hIcon, FALSE);
- m_combo_folder.Create(this, IDC_COMBO_FOLDER, CPoint(20, 20), CSize(310, 36), L"请选择图片目录", NULL, COMBOBOX_FOLDER);
- m_combo_folder.ShowWindow(SW_SHOW);
- m_btn_monitor.Create(this, IDC_BUTTON_MONITOR, CPoint(350, 20), CSize(115, 36), BUTTON_TYPE_TEXT, L"开始监控");
- m_btn_monitor.ShowWindow(SW_SHOW);
- m_btn_hide.Create(this, IDC_BUTTON_HIDE, CPoint(474, 20), CSize(65, 36), BUTTON_TYPE_TEXT, L"隐藏", RGB(0x99, 0x99, 0x99));
- m_btn_monitor.ShowWindow(SW_SHOW);
- m_edit_message.Create(WS_CHILD | ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL | WS_VISIBLE | WS_BORDER, CRect(20, 70, 538, 330), this, 5003);
- m_edit_message.SetFont(CFont::FromHandle(m_hFontMessage));
- m_edit_message.SetReadOnly(TRUE);
- m_edit_message.HideCaret();
- m_edit_message.SetBackgroundColor(FALSE, RGB(234, 234, 234));
- RegisterNotify();
- //m_edit_message.SetWindowText(m_strInfo.c_str());
- InitSharePath();
- for (int i = 0; i < __argc; i++)
- {
- CString pszParam = __targv[i];
- if (pszParam.Find(L"autoMonitor")>-1)
- {
- OnMonitor();
- }
- }
- return TRUE;
- }
- BOOL CHJHomeworkDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct)
- {
- if (pCopyDataStruct && pCopyDataStruct->lpData && pCopyDataStruct->cbData > 0)
- {
- if (m_unZipManager.OnCopyData(pWnd, pCopyDataStruct))
- {
- return true;
- }
- }
- return true;
- }
- void CHJHomeworkDlg::PirntLog(const wchar_t* pszLog)
- {
- CTime tm = CTime::GetCurrentTime();
- CString strTime = tm.Format(L"%Y-%m-%d %H:%M:%S");
- TCHAR szText[1024] = { 0 };
- _stprintf(szText, L"%s %s\r", strTime, pszLog);
- CHJHomeworkDlg* dlg = (CHJHomeworkDlg*)theApp.m_pMainWnd;
- dlg->m_edit_message.SetSel(-1, -1);
- dlg->m_edit_message.ReplaceSel(szText); //追加显示的内容
- }
- void CHJHomeworkDlg::InitSharePath()
- {
- WCHAR share_path[MAX_PATH] = { 0 };
- GetPrivateProfileString(_T("USER"), _T("share_path"), _T(""), share_path, MAX_PATH, m_unZipManager.m_strConfigPath.c_str());
- m_combo_folder.SetWindowText(share_path);
- }
- void CHJHomeworkDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(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 CHJHomeworkDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- void CHJHomeworkDlg::OnMonitor()
- {
- CString strPath;
- m_combo_folder.GetWindowText(strPath);
- if (strPath.GetLength() == 0)
- {
- MessageBox(L"未选择共享文件夹", L"提示", MB_OK);
- return;
- }
- if (!PathIsDirectory(strPath))
- {
- MessageBox(L"共享文件夹不存在", L"提示", MB_OK);
- return;
- }
- if (m_unZipManager.m_strConfigPath != (wstring)strPath)
- {
- WritePrivateProfileString(_T("USER"), _T("share_path"), strPath, m_unZipManager.m_strConfigPath.c_str());
- }
-
- if (!m_bMonitor)
- {
- m_btn_monitor.SetWindowText(L"停止监控");
- m_bMonitor = TRUE;
- m_unZipManager.OnTaskStart();
- PirntLog(L"解压程序启动成功");
- }
- else
- {
- std::wstring strMessage = L"确定要停止监控吗?";
- if (IDOK == MessageBox(strMessage.c_str(), L"提示", MB_OKCANCEL))
- {
- m_btn_monitor.SetWindowText(L"开始监控");
- m_bMonitor = FALSE;
- PirntLog(L"停止监控");
- m_unZipManager.OnClose();
- }
- }
- }
- void CHJHomeworkDlg::OnClose()
- {
- std::wstring strMessage = L"确定要退出吗?";
- if (IDOK == MessageBox(strMessage.c_str(), L"提示", MB_OKCANCEL))
- {
- m_unZipManager.OnClose();
- ::Shell_NotifyIcon(NIM_DELETE, &m_notifyIcon);
- CDialogEx::OnOK();
- }
- }
- void CHJHomeworkDlg::OnHide()
- {
- this->ShowWindow(SW_HIDE);
- }
- void CHJHomeworkDlg::RegisterNotify()
- {
- m_notifyIcon.cbSize = sizeof NOTIFYICONDATA;
- m_notifyIcon.hWnd = this->m_hWnd;
- m_notifyIcon.uID = IDR_MAINFRAME;
- m_notifyIcon.hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_MAINFRAME));
- _tcscpy(m_notifyIcon.szTip, L"初中作业监控程序");
- m_notifyIcon.uCallbackMessage = WM_TO_TRAY_MSG;
- m_notifyIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP; //OK,下面就是托盘产生了.
- Shell_NotifyIcon(NIM_ADD, &m_notifyIcon);
- }
- LRESULT CHJHomeworkDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- // TODO: 在此添加专用代码和/或调用基类
- switch (message) //判断消息类型
- {
- case WM_BUTTON_CLICKED: // 读卷界面的按钮单击
- {
- if (wParam == IDC_BUTTON_MONITOR)
- {
- OnMonitor();
- }
- else if (wParam == IDC_BUTTON_HIDE)
- {
- OnHide();
- }
- }
- break;
- case WM_TO_TRAY_MSG:
- //如果是用户定义的消息
- if (lParam == WM_LBUTTONUP)
- {
- //鼠标双击时主窗口出现
- if (this->IsWindowVisible()) //判断窗口当前状态
- {
- this->ShowWindow(SW_HIDE); //隐藏窗口
- }
- else
- {
- this->ShowWindow(SW_SHOW); //显示窗口
- }
- }
- break;
- }
- return CDialogEx::WindowProc(message, wParam, lParam);
- }
|