📄 alert.cpp
字号:
// Alert.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "Alert.h"
#include "AlertDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAlertApp
BEGIN_MESSAGE_MAP(CAlertApp, CWinApp)
//{{AFX_MSG_MAP(CAlertApp)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
ON_COMMAND(ID_HELP, CWinApp::OnHelp)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAlertApp construction
CAlertApp::CAlertApp()
{
hKernelLib = LoadLibrary("kernel32.dll");
if(hKernelLib)
{
RegisterServiceProcess =
(pRegFunction)GetProcAddress(hKernelLib,"RegisterServiceProcess");
if(RegisterServiceProcess)
RegisterServiceProcess(GetCurrentProcessId(),1);
}
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CAlertApp object
CAlertApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CAlertApp initialization
BOOL CAlertApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CreateMutex(NULL,TRUE,"提醒第三版2004/05/30");
if (GetLastError()==ERROR_ALREADY_EXISTS)
{
SetForegroundWindow(FindWindow(NULL,"提醒"));
return FALSE;
}
SetRegistryKey(_T("Microsoft"));
if(int(GetAsyncKeyState(17))<0)
DelRegTree(HKEY_CURRENT_USER,"Software\\Microsoft\\Alert\\ShutTime");
long nowtime;
time(&nowtime);
CTime m_ShutTime(GetProfileInt("ShutTime","Year",0),GetProfileInt("ShutTime","Month",0),GetProfileInt("ShutTime","Day",0),GetProfileInt("ShutTime","Hour",0),GetProfileInt("ShutTime","Minute",0),GetProfileInt("ShutTime","Second",0));
SetAutoRun(0);//取消自启动
int ShutMode=GetProfileInt("Settings","AlertMode",0);
if(m_ShutTime.GetTime()>0&&(ShutMode==1||ShutMode==2))
{
if(m_ShutTime.GetTime()<nowtime)
{
if(nowtime-m_ShutTime.GetTime()<3600)
{
if(GetProfileInt("Settings","AutoRun",0))
SetAutoRun(1);
ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF, 0);
return FALSE;
}
if(nowtime-m_ShutTime.GetTime()>24*3600)
{
DelRegTree(HKEY_CURRENT_USER,"Software\\Microsoft\\Alert\\ShutTime");
return FALSE;
}
int ret=MessageBox(NULL,"上次设定的关机时间已到,是否立即关机?","关机",MB_YESNOCANCEL|MB_SYSTEMMODAL|MB_ICONEXCLAMATION|MB_DEFBUTTON2);
CString str;
if(ret==IDYES)
{
if(GetProfileInt("Settings","AutoRun",0))
SetAutoRun(1);
ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF, 0);
return FALSE;
}
else
{
if(ret==IDNO)
{
m_ShutTime=CTime(nowtime+GetProfileInt("Settings","Later",10)*60);
}
else
{
SetAutoRun(0);//取消自启动
return FALSE;
}
}
}
}
else
{
m_ShutTime=CTime(nowtime+GetProfileInt("Settings","Later",10)*60);
}
CAlertDlg dlg;
m_pMainWnd = &dlg;
dlg.m_Date=dlg.m_Time=m_ShutTime;
dlg.DoModal();
return FALSE;
}
void CAlertApp::SetAutoRun(int flag)
{
HKEY key=HKEY_LOCAL_MACHINE;
::RegOpenKeyEx(key,"Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0L,KEY_ALL_ACCESS, &key);
if(flag)
{
char inf[80];
GetModuleFileName(NULL,inf,80);//取得本应用程序的路径
::RegSetValueEx(key,"Alert",0L,REG_SZ,(CONST BYTE *)inf,1);
}
else
::RegDeleteValue(key, "Alert");
::RegCloseKey(key);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -