Windows 进入睡眠模式时的通知 [英] Notification when Windows enters in sleep mode

查看:53
本文介绍了Windows 进入睡眠模式时的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法可以知道 Windows 何时进入睡眠模式/是否处于睡眠模式?

Is there any way to find out when Windows will enter sleep mode/is in sleep mode?

推荐答案

如果您使用的是托管代码,那么这会在 SystemEvents.PowerModeChanged 事件中公开.

If you're using managed code then this is exposed in the SystemEvents.PowerModeChanged event.

SystemEvents.PowerModeChanged += OnPowerModeChanged;

private void OnPowerModeChanged(object sender, PowerModeChangedEventArgs e) {
  if (e.Mode == PowerModes.Suspend) {
    // Going to sleep
  }
}

如果您使用本机代码,那么您希望在 WindowProc 处理程序中监听 WM_POWERBROADCAST 消息.

If you're using native code then you want to listen for the WM_POWERBROADCAST message in your WindowProc handler.

LRESULT WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
  if (WM_POWERBROADCAST == message && PBT_APMSUSPEND == wParam) {
    // Going to sleep
  }
}

这篇关于Windows 进入睡眠模式时的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆