问题描述
如果Windows 电源管理"已关闭显示,我如何以编程方式检查 Windows 7 和 XP?(如果能收到活动就更好了.)
How can I programmatically check in Windows 7 and XP if 'windows power management' has turned off the display? (If I can receive an event, that would be even better.)
推荐答案
我认为 XP 无法做到.在 Windows 7 中有各种与电源管理相关的好东西.Windows API 代码包 是一组易于从 C# 或 VB 调用的托管包装器并且映射 Windows 范式(例如事件接收器、Windows消息和函数指针)转换为 .NET(如委托和事件).从代码包附带的电源管理演示中,这里有一些您可能会喜欢的代码:
I don't think it can be done for XP. In Windows 7 there are all kinds of goodies related to power management. The Windows API Code Pack is a set of managed wrappers that are simple to call from C# or VB and that map Windows paradigms (like event sinks, Windowsmessages and function pointers) into .NET ones (like delegates and events.) From the Power Management Demo that comes with the code pack, here is some code you might like:
using Microsoft.WindowsAPICodePack.ApplicationServices;
// . . .
PowerManager.IsMonitorOnChanged += new EventHandler(MonitorOnChanged);
// . . .
void MonitorOnChanged(object sender, EventArgs e)
{
settings.MonitorOn = PowerManager.IsMonitorOn;
AddEventMessage(string.Format("Monitor status changed (new status: {0})", PowerManager.IsMonitorOn ? "On" : "Off"));
}
Windows API 代码包链接:Windows API 代码包:它在哪里?
Links to Windows API Code Pack: Windows API Code Pack: Where is it?
如果你想像这篇文章中提到的那样使用它,请检查这个:https://stackoverflow.com/a/27709672/846232
If you want use it just like is mentioned in this post check this: https://stackoverflow.com/a/27709672/846232
这篇关于检查显示是否被 Windows 电源管理关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!