请写一段在windows电脑上保持屏幕活动状态的程序
时间: 2023-03-31 22:01:25 浏览: 76
以下是一段在 Windows 电脑上保持屏幕活动状态的程序:
#include <Windows.h>
int main()
{
// 获取屏幕大小
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
// 创建一个矩形,覆盖整个屏幕
RECT rect;
rect.left = ;
rect.top = ;
rect.right = screenWidth;
rect.bottom = screenHeight;
// 创建一个全屏的窗口
HWND hWnd = CreateWindowEx(
WS_EX_TOPMOST, // 窗口样式
L"STATIC", // 窗口类名
NULL, // 窗口标题
WS_VISIBLE | WS_POPUP, // 窗口属性
rect.left, rect.top, // 窗口位置
rect.right - rect.left, rect.bottom - rect.top, // 窗口大小
NULL, // 父窗口句柄
NULL, // 菜单句柄
NULL, // 实例句柄
NULL // 创建参数
);
// 将窗口置于顶层
SetWindowPos(hWnd, HWND_TOPMOST, , , , , SWP_NOMOVE | SWP_NOSIZE);
// 消息循环,保持窗口活动状态
MSG msg;
while (GetMessage(&msg, NULL, , ))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return ;
}