📄 tishidlg.cpp
字号:
// TiShiDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MyClock.h"
#include "TiShiDlg.h"
// CTiShiDlg dialog
IMPLEMENT_DYNAMIC(CTiShiDlg, CDialog)
CTiShiDlg::CTiShiDlg(CWnd* pParent /*=NULL*/)
: CDialog(CTiShiDlg::IDD, pParent)
{
i=30;
}
CTiShiDlg::~CTiShiDlg()
{
}
void CTiShiDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_STATIC1, m_static);
}
BEGIN_MESSAGE_MAP(CTiShiDlg, CDialog)
ON_WM_TIMER()
ON_BN_CLICKED(IDOK, &CTiShiDlg::OnBnClickedOk)
END_MESSAGE_MAP()
// CTiShiDlg message handlers
BOOL CTiShiDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CFont font;
font.CreateFont(
24, // nHeight
24, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("宋体")); // lpszFacename
// Do something with the font just created...
m_static.SetFont(&font);
m_static.SetDlgItemInt(IDC_STATIC1,i);
// Done with the font. Delete the font object.
font.DeleteObject();
this->SetDlgItemInt(IDC_STATIC1,i);
SetTimer(1,1000,NULL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CTiShiDlg::OnTimer(UINT_PTR nIDEvent)
{
// TODO: Add your message handler code here and/or call default
i--;
CFont font;
font.CreateFont(
24, // nHeight
24, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("宋体")); // lpszFacename
// Do something with the font just created...
m_static.SetFont(&font);
m_static.SetDlgItemInt(IDC_STATIC1,i);
// Done with the font. Delete the font object.
font.DeleteObject();
if(i==0)
{
this->CloseComputer();
this->KillTimer(1);
}
this->SetDlgItemInt(IDC_STATIC1,i);
CDialog::OnTimer(nIDEvent);
}
void CTiShiDlg::CloseComputer()
{
HANDLE hToken; // handle to process token
TOKEN_PRIVILEGES tkp; // pointer to token structure
BOOL fResult; // system shutdown flag
// Get the current process token handle so we can get shutdown
// privilege.
if (!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
CString str;
str="OpenProcessToken failed.";
MessageBox(str);
}
// Get the LUID for shutdown privilege.
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
&tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1; // one privilege to set
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
// Get shutdown privilege for this process.
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
(PTOKEN_PRIVILEGES) NULL, 0);
// Cannot test the return value of AdjustTokenPrivileges.
if (GetLastError() != ERROR_SUCCESS)
{
CString str1;
str1="AdjustTokenPrivileges enable failed.";
MessageBox(str1);
}
// Display the shutdown dialog box and start the time-out countdown.
fResult = InitiateSystemShutdown(NULL, NULL ,0,FALSE, FALSE); // reboot after shutdown
if (!fResult)
{
CString str1;
str1="InitiateSystemShutdown failed.";
MessageBox(str1);
}
}
void CTiShiDlg::OnBnClickedOk()
{
// TODO: Add your control notification handler code here
this->CloseComputer();
OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -