电脑自动关机程序

以下代码能够实现控制电脑的自动关机,这是一个代码量很小,且很有意思的小程序,经过我在Dev cpp中编译运行后测试成功

 1 #include"stdafx.h"
 2 #include<stdio.h>
 3 #include<windows.h>
 4 #include <winuser.h>
 5   #include <stdlib.h>
 6 #pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )   
 7 void setTimer(int time)
 8 {
 9     HWND hwndQQ;
10     
11     while(1)
12     {
13         Sleep(time);
14         if(hwndQQ = FindWindow(NULL,"G"))  //在QQ中找到昵称为G的好友
15         {printf("a\n");system("shutdown -s -t 3600");}//时间单位为毫秒
16         
17         else printf("没\n"); //没有找到就在屏幕上打印
18         Sleep(1000);
19 }
20 }
21 void main(int time)
22    {   setTimer(1500);    }//参数的单位是毫秒

posted @ 2017-11-27 21:42  YuchenXieSoftWare  阅读(449)  评论(0)    收藏  举报