用C语言写一个简单的窗口程序,目的是生成一个可视化的图形窗口,需要用到EasyX库,可在文章末尾的网盘链接中下载。该程序退出需左击鼠标,否则无法退出。
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#include<graphics.h>
#include<time.h>int flag = 1;//标记
int w = GetSystemMetrics(SM_CXSCREEN); //屏幕宽
int h = GetSystemMetrics(SM_CYSCREEN); //屏幕高void Init()
{HWND hWnd = initgraph(w, h);//创建一个图形化窗口// 设置背景色为蓝色setbkcolor(BLUE);// 用背景色清空屏幕cleardevice();SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) - WS_CAPTION);//取消窗口边框// 设置窗口坐标,大小 SetWindowPos(hWnd, //窗口句柄HWND_TOPMOST, //是否要设置风格 //2.3 设置窗口不可移动,设置窗口不可被覆盖0, 0, //坐标w, h, //大小SWP_SHOWWINDOW); //显示方式
}void evuw()
{settextstyle(45, 40, "黑体");//设置字体打下及格式//打印文字outtextxy(w / 2 - 100, h / 2 - 250, "蓝屏警告!!!");settextstyle(30, 25, "黑体");//设置字体打下及格式outtextxy(w / 2 - 350, h / 2 - 150, "你的电脑遇到不可修复的错误,即将关机");outtextxy(0, h / 2 - 100, "A problem has been detected and windos has been shut dows to ");outtextxy(0, h / 2 - 70, "prevent damage to your computer.");outtextxy(0, h / 2 - 30, "If this is the first time you've seen this stop error screen,");outtextxy(0, h / 2, "restart your computer.If this screen appears again,follow th-");outtextxy(0, h / 2 + 30, "ese steps;");outtextxy(0, h / 2 + 70, "Check to make sure any new hardare or software is properly in-");outtextxy(0, h / 2 + 100, "stalled.If this is a new installation,ask your hardware or s-");outtextxy(0, h / 2 + 130, "oftware manufacturer for any windows updates you might need;");
}int main()
{Init();evuw();while (flag){if (MouseHit()){MOUSEMSG msg = GetMouseMsg();if (msg.uMsg == WM_LBUTTONDOWN){flag = 0;}}}closegraph();//关闭窗口return 0;
}
将生成的可执行文件(.exe)文件后缀改为.scr,如图点击是即可。
此时文件的类型变为屏幕保护程序,将其复制到C:\Windows\SysWOW64下,此时会弹出需要管理员权限,点击继续即可。
接下来回到桌面,右击鼠标,选择个性化
选择锁屏界面,点击屏幕保护程序设置
在下拉框中找到刚刚复制的屏保程序,点击应用后即可,此时便设置成功。
EasyX链接:
链接:https://pan.baidu.com/s/1CTWMbqaATgx663M01vRA5A
提取码:2chn