定时关机源代码
iec 2002-02-27 02:35:45 给你个源代码,麻烦帮我解决一下我提出的DOS问题
BCB5.0
ptime.cpp:
void __fastcall TForm1::Timer1Timer(TObject *Sender)
{
int str;
AnsiString iYear,iMonth,iDay,iHour,iMinute,iSecond;
iHour=Now().FormatString("hh");//取小时
iMinute=Now().FormatString("nn");//取分钟
iSecond=Now().FormatString("ss");//取秒
str=StrToInt(iHour);
if(str>=22)//假如晚上10点关机,也可以用API函数定时到开机以后一段时间后关机。
{
ExitWindowsEx(EWX_SHUTDOWN,0);
Application->Terminate() ;
}
}
//---------------------------------------------------------------------------
//以下是防止修改用户修改系统时间
void __fastcall TForm1::Timer2Timer(TObject *Sender)
{
HWND hCurWindow; // 窗口句柄
char WinText[255];
// 获取第一个窗口的句柄
hCurWindow = GetWindow(Handle, GW_HWNDFIRST);
while( hCurWindow!=0 )
{
// 获取窗口的名称
if( GetWindowText(hCurWindow, WinText, 255)>0 )
{
if(StrPas(WinText)=="日期/时间 属性")
{
ExitWindowsEx(EWX_SHUTDOWN,0);
Application->Terminate() ;
}
}
// 获取下一个窗口的句柄
hCurWindow = GetWindow(hCurWindow, GW_HWNDNEXT);
}
}
//---------------------------------------------------------------------------
//禁止用户关机
void __fastcall TForm1::WMQueryEndSession(TWMQueryEndSession &Message)
{
Message.Result = 0;
//ShowMessage("你不能关闭系统");
MessageBox("","你不能关闭系统" ,"警告!",MB_OKCANCEL );
//TODO: Add your source code here
}
-----------------------------------------------
别忘了自定义消息,拦截关机消息
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_QUERYENDSESSION,TWMQueryEndSession,WMQueryEndSession)
END_MESSAGE_MAP(TForm)
};
//---------------------------------------------------------------------------