简体   繁体   English

如何在Windows 7中检查PC监视器是否已打开或关闭任何工具或事件查看器

[英]How to check PC monitor is turned on or off any tool or event viewer in windows 7

我需要检查在Win7 OS中我的电脑显示器是打开还是关闭

MSDN power management documentation explains that you can get notifications when the monitor is turned on or off. MSDN电源管理文档说明,当显示器打开或关闭时,您可以获得通知。 Basically, you register for the power broadcast messages, and then you'll get a WM_POWERBROADCAST message whenever there's a change. 基本上,您注册的是超级广播消息,然后每当有更改时,您都会收到WM_POWERBROADCAST消息。 There are several different GUIDs for monitoring the display state, depending on which version of Windows you use. 有几种不同的GUID用于监视显示状态,具体取决于您使用的Windows版本。

At the beginning of your program (after creating your main windows), you do something like: 在程序开始时(在创建主窗口之后),您将执行以下操作:

HPOWERNOTIFY hPower =
  RegisterPowerSettingNotification(hwndMain, GUID_SESSION_DISPLAY_STATUS, 0);

(There are other choices for the GUID depending on which version of Windows you're targeting.) (根据要定位的Windows版本, GUID还有其他选择 。)

Then in your main window procedure: 然后在您的主窗口过程中:

case WM_POWERBROADCAST:
  if (wParam == PBT_POWERSETTINGCHANGE) {
    const POWERBROADCAST_SETTING *pSetting =
      reinterpret_cast<const POWERBROADCAST_SETTING*>(lParam);
    if (pSetting->PowerSetting == GUID_SESSION_DISPLAY_STATUS) {
      assert(pSetting->DataLength >= sizeof(DWORD));
      DWORD data = *reinterpret_cast<const DWORD*>(&pSetting->Data);
      switch (data) {
        case 0: /* monitor is off */ break;
        case 1: /* monitor is on */ break;
        case 2: /* monitor is dimmed */ break;
        default:  /* ???? */ break;
      }
    }
  }
  break;

If at any point you no longer care about the power notifications, you can unregister: 如果您在任何时候都不再关心电源通知,则可以注销:

UnregsisterPowerSettingNotification(hPower);
hPower = NULL;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在C++查看windows通知是否开启或关闭? - How to check in C++ whether windows notifications are turned on or off? 如何检查Windows 10 Universal App中的wifi是否已打开/关闭? - How to check if wifi is turned on/off in Windows 10 Universal App? 有没有办法检测 Windows 中的监视器状态(打开或关闭)? - Is there any way to detect the monitor state in Windows (on or off)? 有什么方法可以检查哪个显示器是主要显示器,然后在Windows命令行中基于该显示器执行命令? - Is there any way to check which monitor is the primary display, then execute a command based off of that in windows command line? 如何通过 windows API 关闭电脑? - How to turn off pc via windows API? 如何为Windows事件查看器创建CRITICAL事件? - How to create CRITICAL events for Windows Event Viewer? 在 Windows 中监视网络连接的工具 - Tool to monitor network connectivity in Windows 如何检查Windows设备是手机还是平板电脑/电脑? - How to check if Windows device is phone or tablet/pc? Windows CLI工具监视信号量? - Windows cli tool to monitor semaphores? 一旦关闭电源设置,如何唤醒我的Windows显示器? - How do I wake up my Windows monitors once turned off by power settings?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM