检测在Windows 7下连接或删除的外部显示器 [英] Detect external display being connected or removed under Windows 7

查看:177
本文介绍了检测在Windows 7下连接或删除的外部显示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

笔记本电脑是否检测到有一些事件或通知,每次外部液晶显示器插入或从运行Windows 7的笔记本电脑中拔下电源时,都可以接收或挂断?



这将把我的显示器切换到外部屏幕,然后使用某些类型的调整大小或重新定位,但这是由操作系统公开的,以便应用程序可以提供处理程序,附加脚本等。



如果没有,是否有可以不时轮询的注册表设置或API?



(我更喜欢编程C + Win32 API)



更新



Mike的答案在下面, WM_DEVICECHANGE 导致我 RegisterDeviceNotification() ,但是我至今仍在努力实现...



更新2



这个问题已经用不同的措辞问了几次,但是在我看来还没有完全回答: / p>


解决方案

您可以尝试 WM_DEVICECHANGE 。如果没有这样做,请运行你的窗口并附加Spy ++,它将记录它收到的所有窗口消息。然后将显示器插入并检查是否收到任何消息。



或者您可以轮询 GetSystemMetrics()与SM_CMONITORS。


Is there some event or notification I can receive or hook each time an external LCD monitor is plugged in or unplugged from a laptop running Windows 7?

The laptop detects this and switches my display to the external screen and back with certain kinds of resizing or repositioning but is this exposed by the operating system so that applications can provide a handler, attach a script, etc?

If not, is there a registry setting or API I could poll from time to time?

(I prefer programming C + Win32 API)

UPDATE

Mike's answer below, WM_DEVICECHANGE led me to RegisterDeviceNotification(), but I'm struggling to implement it so far...

UPDATE 2

This question has been asked with different wording a couple of times, but not fully answered yet in my opinion:

解决方案

You can try WM_DEVICECHANGE. If that doesn't do the trick, run your window and attach Spy++ to it which will log all the window messages it receives. Then plug your monitor in and check if you received any messages.

Alternatively you can poll GetSystemMetrics() with SM_CMONITORS.

这篇关于检测在Windows 7下连接或删除的外部显示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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