gpt4 book ai didi

c++ - 关闭显示器?

转载 作者:可可西里 更新时间:2023-11-01 14:02:38 25 4
gpt4 key购买 nike

我有 windows 10 64 位,我花了很多时间在屏幕后面编程。我需要不时休息一下,并通过使屏幕变黑来限制屏幕光线/辐射与我的头部碰撞, 就像关机一样。

我能做的就是掉到登录屏幕,但我需要看到它变黑才能松一口气!我真正希望实现的是一段时间不活动时出现的黑屏。我可以通过编程方式实现吗?

这是我到目前为止的代码:

#include <Windows.h>

#define KEY_DOWN(key) ((::GetAsyncKeyState(key) & 0x80000) ? 1 : 0)
#define KEY_UP(key) ((::GetAsyncKeyState(key) & 0x80000) ? 0 : 1)

int main(void)
{
// Hide the console window
HWND hWnd;
AllocConsole();
hWnd = FindWindowA("ConsoleWindowClass", NULL);
ShowWindow(hWnd, 0);

//Press ctrl + alt + 'L' to lock / Press ctrl + 'E' to terminate the program
while (1)
{
if (::GetAsyncKeyState('L') == -32767)
{
if (KEY_DOWN(VK_CONTROL) && KEY_DOWN(VK_MENU))
LockWorkStation();
}
if (::GetAsyncKeyState('E') == -32767)
{
if (KEY_DOWN(VK_CONTROL))
return 0;
}
}
return 0;
}

最佳答案

使用 WM_SYSCOMMAND 消息的 SC_MONITORPOWER 参数关闭监视器:

SendMessage(handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2);

第四个参数的参数 2 关闭监视器。

另见 https://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx

关于c++ - 关闭显示器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37148702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com