?? webmonitordlg.cpp
字號:
// WebMonitorDlg.cpp : implementation file
//
#include "stdafx.h"
#include "WebMonitor.h"
#include "WebMonitorDlg.h"
#include "CRobot.h"
#include "CRobotInternet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWebMonitorDlg dialog
CWebMonitorDlg::CWebMonitorDlg(CWnd* pParent /*=NULL*/)
: CDialog(CWebMonitorDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CWebMonitorDlg)
m_status = _T("");
m_url1 = _T("");
m_url2 = _T("");
m_url3 = _T("");
m_url4 = _T("");
m_url5 = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CWebMonitorDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWebMonitorDlg)
DDX_Control(pDX, IDC_ICON5, m_icon5_ctl);
DDX_Control(pDX, IDC_ICON4, m_icon4_ctl);
DDX_Control(pDX, IDC_ICON3, m_icon3_ctl);
DDX_Control(pDX, IDC_ICON2, m_icon2_ctl);
DDX_Control(pDX, IDC_ICON1, m_icon1_ctl);
DDX_Text(pDX, IDC_STATUS, m_status);
DDX_Text(pDX, IDC_URL1, m_url1);
DDX_Text(pDX, IDC_URL2, m_url2);
DDX_Text(pDX, IDC_URL3, m_url3);
DDX_Text(pDX, IDC_URL4, m_url4);
DDX_Text(pDX, IDC_URL5, m_url5);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CWebMonitorDlg, CDialog)
//{{AFX_MSG_MAP(CWebMonitorDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWebMonitorDlg message handlers
BOOL CWebMonitorDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
bRunning = false;
return TRUE; // return TRUE unless you set the focus to a control
}
void CWebMonitorDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CWebMonitorDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
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;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CWebMonitorDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
// *********
// * *
// * log *
// * *
// *********
// Description: Outputs date, time, and message to fLog log file.
void CWebMonitorDlg::log(const CString& sMessage)
{
CTime tNow;
CString sNow;
tNow = CTime::GetCurrentTime();
sNow.Format("%02d/%02d/%04d %02d:%02d",
tNow.GetMonth(), tNow.GetDay(), tNow.GetYear(),
tNow.GetHour(), tNow.GetMinute());
fLog.WriteString(sNow + " " + sMessage + "\n");
}
void CWebMonitorDlg::OnOK()
{
bRunning = true;
UpdateData(true);
m_status = "Running";
GetDlgItem(IDOK)->EnableWindow(false);
UpdateData(false);
fLog.Open("WebMonitor.log",
CFile::modeCreate
| CFile::modeNoTruncate
| CFile::modeWrite);
fLog.SeekToEnd();
SetTimer(1, 1000, NULL);
}
void CWebMonitorDlg::OnTimer(UINT nIDEvent)
{
CRobotInternet internet;
CString sHTML;
int nResult;
CString sErrMsg;
KillTimer(1);
CWaitCursor wc;
m_status = "Checking sites...";
UpdateData(false);
log("Checking web sites");
if (m_url1!="")
{
m_icon1_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_CHECKING));
m_status = "Checking " + m_url1;
UpdateData(false);
m_icon1_ctl.UpdateWindow();
if (internet.httpGet(m_url1, sHTML, nResult, sErrMsg))
m_icon1_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_OK));
else
{
m_icon1_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_ERR));
log(" *** ERROR: Unable to access site " + m_url1);
log(" CRobotInternet error: " + sErrMsg);
} // End else
m_icon1_ctl.UpdateWindow();
} // End if
if (m_url2!="")
{
m_icon2_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_CHECKING));
m_status = "Checking " + m_url2;
UpdateData(false);
m_icon2_ctl.UpdateWindow();
if (internet.httpGet(m_url2, sHTML, nResult, sErrMsg))
m_icon2_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_OK));
else
{
m_icon2_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_ERR));
log(" *** ERROR: Unable to access site " + m_url2);
log(" CRobotInternet error: " + sErrMsg);
} // End else
m_icon2_ctl.UpdateWindow();
} // End if
if (m_url3!="")
{
m_icon3_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_CHECKING));
m_status = "Checking " + m_url3;
UpdateData(false);
m_icon3_ctl.UpdateWindow();
if (internet.httpGet(m_url3, sHTML, nResult, sErrMsg))
m_icon3_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_OK));
else
{
m_icon3_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_ERR));
log(" *** ERROR: Unable to access site " + m_url3);
log(" CRobotInternet error: " + sErrMsg);
} // End else
m_icon3_ctl.UpdateWindow();
} // End if
if (m_url4!="")
{
m_icon4_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_CHECKING));
m_status = "Checking " + m_url4;
UpdateData(false);
m_icon4_ctl.UpdateWindow();
if (internet.httpGet(m_url4, sHTML, nResult, sErrMsg))
m_icon4_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_OK));
else
{
m_icon4_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_ERR));
log(" *** ERROR: Unable to access site " + m_url4);
log(" CRobotInternet error: " + sErrMsg);
} // End else
m_icon4_ctl.UpdateWindow();
} // End if
if (m_url5!="")
{
m_icon5_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_CHECKING));
m_status = "Checking " + m_url5;
UpdateData(false);
m_icon5_ctl.UpdateWindow();
if (internet.httpGet(m_url5, sHTML, nResult, sErrMsg))
m_icon5_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_OK));
else
{
m_icon5_ctl.SetIcon(AfxGetApp()->LoadIcon(IDI_ERR));
log(" *** ERROR: Unable to access site " + m_url5);
log(" CRobotInternet error: " + sErrMsg);
} // End else
m_icon5_ctl.UpdateWindow();
} // End if
m_status = "Waiting...";
UpdateData(false);
SetTimer(1, 60*1000, NULL);
}
void CWebMonitorDlg::OnCancel()
{
if (bRunning)
{
fLog.Close();
bRunning = false;
GetDlgItem(IDOK)->EnableWindow(true);
} // End if
else
{
CDialog::OnCancel();
} // End else
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -