📄 shutdowndlg.cpp
字号:
// ShutDownDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ShutDown.h"
#include "ShutDownDlg.h"
#include "Shortcut.h"
#include "PwdDlg.h"
#include "KeyDlg.h"
#include "IdleUI.h"
#include "Input.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 HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
//}}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)
ON_WM_CTLCOLOR()
ON_WM_LBUTTONUP()
ON_WM_SETCURSOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
HBRUSH CAboutDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_STATIC)
{
CString ss;
pWnd->GetWindowText(ss);
if(memcmp(ss,"chf@371.net",11) == 0)
{
pDC->SetTextColor(RGB(0,0,238));
}
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CAboutDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
CRect rcStatic;
CPoint ptCursor;
CWnd *pStatic=GetDlgItem(IDC_STATIC_MAIL);
pStatic->GetWindowRect(rcStatic);
GetCursorPos(&ptCursor);
if(rcStatic.PtInRect(ptCursor))
{
ShellExecute(m_hWnd,NULL,"mailto:chf@371.net",NULL,NULL,SW_SHOWMAXIMIZED);
}
CDialog::OnLButtonUp(nFlags, point);
}
BOOL CAboutDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
CRect rcStatic;
CPoint ptCursor;
CWnd *pStatic=GetDlgItem(IDC_STATIC_MAIL);
pStatic->GetWindowRect(rcStatic);
GetCursorPos(&ptCursor);
if(rcStatic.PtInRect(ptCursor))
{
//change cursor to hand
HCURSOR hHandCursor = AfxGetApp()->LoadCursor(IDC_HAND);
if(hHandCursor)
SetCursor(hHandCursor);
return TRUE;
}
return CDialog::OnSetCursor(pWnd, nHitTest, message);
}
/////////////////////////////////////////////////////////////////////////////
// CShutDownDlg dialog
CShutDownDlg::CShutDownDlg(CWnd* pParent /*=NULL*/)
: CDialog(CShutDownDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CShutDownDlg)
m_sNowTime = _T("");
m_Time1 = CTime(2000,8,13,11,59,0);
m_Time2 = CTime(2000,8,13,17,59,0);
m_Time3 = CTime(2000,8,13,21,59,0);
m_UserTime1 = CTime(2000,8,13,0,0,0);
m_UserTime2 = CTime(2000,8,13,1,0,0);
m_Check1 = TRUE;
m_Check2 = TRUE;
m_Check3 = TRUE;
m_Check4 = FALSE;
m_Check5 = FALSE;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
m_Cdrom = FALSE;
}
void CShutDownDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CShutDownDlg)
DDX_Control(pDX, IDC_DATETIMEPICKER5, m_UserTimer2);
DDX_Control(pDX, IDC_DATETIMEPICKER4, m_UserTimer1);
DDX_Control(pDX, IDC_DATETIMEPICKER3, m_Timer3);
DDX_Control(pDX, IDC_DATETIMEPICKER2, m_Timer2);
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_Timer1);
DDX_Text(pDX, IDC_STATIC_NOW, m_sNowTime);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_Time1);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER2, m_Time2);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER3, m_Time3);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER4, m_UserTime1);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER5, m_UserTime2);
DDX_Check(pDX, IDC_CHECK1, m_Check1);
DDX_Check(pDX, IDC_CHECK2, m_Check2);
DDX_Check(pDX, IDC_CHECK3, m_Check3);
DDX_Check(pDX, IDC_CHECK4, m_Check4);
DDX_Check(pDX, IDC_CHECK5, m_Check5);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CShutDownDlg, CDialog)
//{{AFX_MSG_MAP(CShutDownDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
ON_WM_CTLCOLOR()
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER1, OnDatetimechangeDatetimepicker1)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER2, OnDatetimechangeDatetimepicker2)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER3, OnDatetimechangeDatetimepicker3)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER4, OnDatetimechangeDatetimepicker4)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER5, OnDatetimechangeDatetimepicker5)
ON_BN_CLICKED(IDC_BUTTON_SHUTDOWN, OnButtonShutdown)
ON_BN_CLICKED(IDC_BUTTON_HIDE, OnButtonHide)
ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
ON_BN_CLICKED(IDC_CHECK3, OnCheck3)
ON_BN_CLICKED(IDC_CHECK4, OnCheck4)
ON_BN_CLICKED(IDC_CHECK5, OnCheck5)
ON_COMMAND(ID_MENU_ABORT, OnMenuAbort)
ON_COMMAND(ID_MENU_MAIN, OnMenuMain)
ON_COMMAND(ID_MENU_NOWSHUT, OnMenuNowshut)
ON_COMMAND(ID_MENU_EXIT, OnMenuExit)
ON_COMMAND(ID_MENU_SHORTCUT, OnMenuShortcut)
ON_COMMAND(ID_MENU_OUT, OnMenuOut)
ON_COMMAND(ID_MENU_CLOSE, OnMenuClose)
ON_COMMAND(ID_MENU_SYSTEM, OnMenuSystem)
ON_COMMAND(ID_MENU_PASSWORD, OnMenuPassword)
ON_COMMAND(ID_MENU_IDLEMIN, OnMenuIdlemin)
ON_COMMAND(ID_MENU_REBOOT, OnMenuReboot)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShutDownDlg message handlers
BOOL CShutDownDlg::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
CString str1,str2,str3,pwd;
UINT ctl1,ctl2,ctl3;
time_t t1,t2,t3;
str1 = AfxGetApp()->GetProfileString("ShutDown","time1");
str2 = AfxGetApp()->GetProfileString("ShutDown","time2");
str3 = AfxGetApp()->GetProfileString("ShutDown","time3");
pwd = AfxGetApp()->GetProfileString("ShutDown","pwd");
t1 = (time_t) atol(str1);
t2 = (time_t) atol(str2);
t3 = (time_t) atol(str3);
ctl1 = AfxGetApp()->GetProfileInt("ShutDown","timer1",1);
ctl2 = AfxGetApp()->GetProfileInt("ShutDown","timer2",1);
ctl3 = AfxGetApp()->GetProfileInt("ShutDown","timer3",1);
m_IdleMin = AfxGetApp()->GetProfileInt("ShutDown","idlemin",0);
m_Check1 = ctl1;
m_Check2 = ctl2;
m_Check3 = ctl3;
if(str1.IsEmpty())
{
t1 = m_Time1.GetTime();
t2 = m_Time2.GetTime();
t3 = m_Time3.GetTime();
str1.Format("%ld",t1);
str2.Format("%ld",t2);
str3.Format("%ld",t3);
AfxGetApp()->WriteProfileString("ShutDown","time1",str1);
AfxGetApp()->WriteProfileString("ShutDown","time2",str2);
AfxGetApp()->WriteProfileString("ShutDown","time3",str3);
AfxGetApp()->WriteProfileInt("ShutDown","timer1",1);
AfxGetApp()->WriteProfileInt("ShutDown","timer2",1);
AfxGetApp()->WriteProfileInt("ShutDown","timer3",1);
AfxGetApp()->WriteProfileInt("ShutDown","idlemin",0);
m_Check1 = 0;
m_Check2 = 0;
m_Check3 = 0;
m_IdleMin= 0;
}
if(pwd.IsEmpty())
{
pwd = _T("12345678");
CShutDownApp *myapp = (CShutDownApp *)AfxGetApp();
myapp->strCheck = myapp->KeyChanged(pwd);
AfxGetApp()->WriteProfileString("ShutDown","pwd",myapp->strCheck);
}
m_Time1 = CTime(t1);
m_Time2 = CTime(t2);
m_Time3 = CTime(t3);
SetTimer(0,1000,NULL);
m_Timer1.EnableWindow(m_Check1);
m_Timer2.EnableWindow(m_Check2);
m_Timer3.EnableWindow(m_Check3);
m_UserTimer1.EnableWindow(m_Check4);
m_UserTimer2.EnableWindow(m_Check5);
m_Cdrom = GetCdrom();
if(!IdleUIInit())
{
AfxMessageBox(IDS_INIT_IDLE_ERROR, MB_ICONWARNING);
m_IdleOK = FALSE;
}
m_IdleOK = TRUE;
return TRUE; // return TRUE unless you set the focus to a control
}
void CShutDownDlg::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 CShutDownDlg::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 CShutDownDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CShutDownDlg::OnOK()
{
NOTIFYICONDATA nid;
nid.cbSize = sizeof(nid);
nid.uID = 10;
nid.hWnd = m_hWnd;
Shell_NotifyIcon(NIM_DELETE, &nid);
KillTimer(0);
if(m_IdleOK)
IdleUITerm();
CDialog::OnOK();
}
HBRUSH CShutDownDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor == CTLCOLOR_STATIC)
{
CString ss;
pWnd->GetWindowText(ss);
if(memcmp(ss,"现在时间",8) != 0 &&
memcmp(ss,"预定时间",8) != 0 &&
memcmp(ss,"自定义时间",10) != 0 &&
memcmp(ss,"条件设置",8) !=0 )
{
pDC->SetTextColor(RGB(0,0,238));
}
else
{
pDC->SetTextColor(RGB(250,0,238));
}
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CShutDownDlg::OnTimer(UINT nIDEvent)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -