我正在寻找一种方法来检查C#中的监视器状态(.net framework 4.5,win8.1)。
(我知道无法检查,用户手动关闭显示器,我不想要这个。我想检查系统(屏幕保护程序)关闭它,或者不... ...
我找到了一些关于SystemEvents.PowerModeChanged的信息,但它只是关于睡眠。
答案 0 :(得分:1)
您可以通过调用SystemParametersInfo函数并传递SPI_GETSCREENSAVERRUNNING
操作来确定屏幕保护程序是否正在运行。
您需要该功能的托管原型:
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SystemParametersInfo(
SPI uiAction, uint uiParam, ref T pvParam, SPIF fWinIni); // T = any type
const int SpiGetScreenSaverRunning = 0x0072;
并称之为:
bool screenSaverRunning;
if (!SystemParametersInfo(SpiGetScreenSaverRunning, 0, ref screenSaverRunning, 0))
{
// some error occurred
}
// screenSaverRunning will be true if the screen saver is running