【C++程序】[新手向]自动定时关机+限定时间内无法开机工程

整理代码片时找到了几个月以前写的完整工程,贴出来以供参考。
代码如下:

#include 
#include 
#include 
#include 
#include 
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" ) 
using namespace std; 

void CALLBACK TimerProc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
{
    system("erase /q C:\\time.txt");
    system("time /t >> c:\\time.txt");
    char timenow[5];
    ifstream infile;  
    infile.open("c://time.txt");
    if(infile.is_open())           
    {  
        for(int i = 0;infile.good() && !infile.eof();i++)  
        {  
            infile >> timenow[i];                   
        }  
        infile.close();  
    } //将文件中的系统时间写入数组
    char* address[4];
    address[0] = &timenow[0];
    address[1] = &timenow[1];
    address[2] = &timenow[3];
    address[3] = &timenow[4]; //获取小时、分钟对应地址
    int hour = atoi(address[0]);
    int min = atoi(address[2]); //获取数字类型的小时、分钟
    if((hour>=24 || hour<07) && (min>=0 && min<=60)) //检测系统时间是否在对应时间内
    {

        system("shutdown -s");
    }
}

int main()
{
    system("erase /q C:\\time.txt");
    system("time /t >> c:\\time.txt");
    char timenow[5];
    ifstream infile;  
    infile.open("c://time.txt");  
    if(infile.is_open())         
    {  
        for(int i = 0;infile.good() && !infile.eof();i++)  
        {  
            infile >> timenow[i];                   
        }  
        infile.close();  
    } //将文件中的系统时间写入数组
    char* address[4];
    address[0] = &timenow[0];
    address[1] = &timenow[1];
    address[2] = &timenow[3];
    address[3] = &timenow[4]; //获取小时、分钟对应地址
    int hour = atoi(address[0]);
    int min = atoi(address[2]); //获取数字类型的小时、分钟
    if((hour>=24 || hour<07) && (min>=0 && min<=60)) //检测系统时间是否在对应时间内
    {

        system("shutdown -s");
    }
    SetTimer(0,0,60000,&TimerProc);
    MSG   msg;   
    while(GetMessage(&msg,NULL,0,0))   
    {   
        if(msg.message==WM_TIMER)   
        {   
            DispatchMessage(&msg);   
        }   
    }
    return 0;
}

你可能感兴趣的:(【C++程序】,C++,自动定时关机,关机)