devc++实现windowsshutdown图形化界⾯(源代码如下)
#include
#include
charstr[];
charcmd[];
//charhour[10],minute[10];
intnum;
intnum_text_hour,num_text_minute;
//charnum_str[];
LRESULTCALLBACKWndProc(HWND,UINT,WPARAM,LPARAM);
intWINAPIWinMain(HINSTANCEhInstance,HINSTANCEhPrevInstance,LPSTRlpCmdLine,intnCmdShow)
{
HWNDhWnd;
MSGMsg;
WNDCLASSWndClass;
=CS_HREDRAW|CS_VREDRAW;
dProc=WndProc;
xtra=0;
xtra=0;
nce=hInstance;
=LoadIcon(NULL,IDI_APPLICATION);
r=LoadCursor(NULL,IDC_ARROW);
kground=(HBRUSH)GetStockObject(WHITE_BRUSH);
nuName=NULL;
assName="HelloWin";//窗⼝类名
//注册窗⼝
if(!RegisterClass(&WndClass))
{
MessageBox(NULL,"窗⼝注册失败!","HelloWin",0);
return0;
}
//创建窗⼝
hWnd=CreateWindow("HelloWin","定时关机--junmuzi",WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
//显⽰窗⼝
ShowWindow(hWnd,nCmdShow);
//更新窗⼝
UpdateWindow(hWnd);
//进⼊消息循环:当从应⽤程序消息队列中捡取的消息是WM_QUIT时,则推出循环
while(GetMessage(&Msg,NULL,0,0))
{
TranslateMessage(&Msg);//转换键盘消息
DispatchMessage(&Msg);//分发消息
}
;
}
LRESULTCALLBACKWndProc(HWNDhWnd,UINTmessage,WPARAMwParam,LPARAMlParam)
{
HDChDC;
PAINTSTRUCTPs;
charstrEdit_hour[10],strEdit_minute[10];
staticHWNDhWndButton_ok,hWndButton_cancel,hWndEdit_hour,hWndEdit_minute;
switch(message)
{
caWM_CREATE:
hWndEdit_hour=
CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,10,60,100,25,hWnd,NULL,NULL,NULL);
hWndEdit_minute=
CreateWindow("edit",NULL,WS_CHILD|WS_VISIBLE|WS_BORDER,180,60,100,25,hWnd,NULL,NULL,NULL);
hWndButton_ok=CreateWindow("button","确定",WS_CHILD|WS_VISIBLE|WS_BORDER,340,60,100,25,
hWnd,NULL,NULL,NULL);
hWndButton_cancel=CreateWindow("button","取消定时关机",WS_CHILD|WS_VISIBLE|WS_BORDER,460,60,100,
25,hWnd,NULL,NULL,NULL);
return0;
caWM_COMMAND:
if(((HWND)lParam==hWndButton_ok)&&(HIWORD(wParam)==BN_CLICKED))
//按下按键hWndButton_ok
{
num_text_hour=GetWindowText(hWndEdit_hour,strEdit_hour,10);//获取编辑框控件hour的内容
//sprintf(str,"Theresultis:%s",strEdit_hour);
//sprintf(hour,"%s",strEdit_hour);
if(num_text_hour==0)
{
MessageBox(NULL,"⼩时不能为空!","错误信息:",MB_OK);
}
num_text_minute=GetWindowText(hWndEdit_minute,strEdit_minute,10);//获取编辑框控件minute的内容
if(num_text_minute==0)
{
MessageBox(NULL,"分钟不能为空!","错误信息:",MB_OK);
}
if(!((atoi(strEdit_hour)>=0)&&(atoi(strEdit_minute)>=0)&&(atoi(strEdit_minute)<=60)))
{
MessageBox(NULL,"⾮法输⼊(输⼊的⼩时必须⼤于等于0,输⼊的分钟必须⼤于等于0,且⼩于等于60)","错误信息:",
MB_OK);
}
if((num_text_hour!=0)&&(num_text_minute!=0)&&(atoi(strEdit_hour)>=0)&&(atoi(strEdit_minute)>=0)
&&(atoi(strEdit_minute)<=60))
{
num=atoi(strEdit_hour)*3600+atoi(strEdit_minute)*60;//把⼩时和分钟数转化为多少秒
//itoa(num,num_str,10);
//sprintf(str,"Theresultis:%s",strEdit_minute);
//sprintf(minute,"%s",strEdit_minute);
//strcat(cmd,str_);
//sprintf(cmd,"shutdown-s-t%s%s%d",strEdit_hour,strEdit_minute,num);
sprintf(cmd,"shutdown-s-t%d",num);//定时关机命令
sprintf(str,"电脑会在%s⼩时%s分钟后关机",strEdit_hour,strEdit_minute);
system(cmd);//shutdownthecomputer.
InvalidateRect(hWnd,NULL,TRUE);
}
}
if(((HWND)lParam==hWndButton_cancel)&&(HIWORD(wParam)==BN_CLICKED))
//按下按键hWndButton_cancel
{
sprintf(cmd,"shutdown-a");//取消定时关机
sprintf(str,"电脑定时关机被取消");
system(cmd);//cancel”shutdownthecomputer“.
InvalidateRect(hWnd,NULL,TRUE);
}
caWM_PAINT://设计编辑框
hDC=BeginPaint(hWnd,&Ps);
TextOut(hDC,10,10,"请输⼊你要设置的多长时间后关机(⼩时和分钟数):",48);
TextOut(hDC,120,60,"⼩时",4);
TextOut(hDC,290,60,"分钟",4);
//TextOut(hDC,10,90,str,strlen(str));
TextOut(hDC,10,90,str,strlen(str));
EndPaint(hWnd,&Ps);
return0;
caWM_DESTROY:
PostQuitMessage(0);
return0;
}
returnDefWindowProc(hWnd,message,wParam,lParam);
}
本文发布于:2023-03-06 05:37:03,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/1678052224153968.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:取消定时关机.doc
本文 PDF 下载地址:取消定时关机.pdf
留言与评论(共有 0 条评论) |