问题描述
笔记本电脑是否检测到有一些事件或通知,每次外部液晶显示器插入或从运行Windows 7的笔记本电脑中拔下电源时,都可以接收或挂断?
这将把我的显示器切换到外部屏幕,然后使用某些类型的调整大小或重新定位,但这是由操作系统公开的,以便应用程序可以提供处理程序,附加脚本等。
如果没有,是否有可以不时轮询的注册表设置或API?
(我更喜欢编程C + Win32 API)
更新
Mike的答案在下面,导致我,但是我至今仍在努力实现...
更新2
这个问题已经用不同的措辞问了几次,但是在我看来还没有完全回答: / p>
您可以尝试。如果没有这样做,请运行你的窗口并附加Spy ++,它将记录它收到的所有窗口消息。然后将显示器插入并检查是否收到任何消息。
或者您可以轮询与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:
- How to detect hot plugging of monitor in a win32 application?
- Getting an event on monitor hotplug for windows
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下连接或删除的外部显示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!