[英]Turn off the monitor?
我有64位的Windows 10,我花了很多時間在屏幕后面編程。我需要不時休息一下,並通過使屏幕變黑來限制屏幕光線/輻射與我的頭部碰撞,就好像關掉。
我能做的就是掉到登錄界面,但我需要看到黑色才能放心! 我真正希望實現的是你在不活動時獲得的黑屏。可以通過編程方式進行嗎?
這是我到目前為止的代碼:
#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;
}
使用SC_MONITORPOWER
參數為WM_SYSCOMMAND
消息關閉顯示器:
SendMessage(handle, WM_SYSCOMMAND, SC_MONITORPOWER, 2);
第四個參數的參數2
關閉顯示器。
另請參見https://msdn.microsoft.com/en-us/library/windows/desktop/ms646360(v=vs.85).aspx
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.