如何检测何时将设备添加到系统? [英] How to detect when a device is added to the system?

查看:65
本文介绍了如何检测何时将设备添加到系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有一段时间这个问题了,但是由于我现在必须解决它,因此我必须对其进行补救.我试图检测何时将设备连接到Windows 7中的系统,并且收到WM_DEVICECHANGE很好,但是wParam中的消息始终为DBT_DEVNODES_CHANGED.永远不要使用DBT_DEVICEARRIVAL或DBT_DEVICEREMOVECOMPLETE.到目前为止,我还没有运气好,所以我希望有人能在几个小时后找到东西之前将我指向正确的方向:) 谢谢你的时间.

I've had this problem for a while now but I have to remedy it as I must tackle it now. I'm trying to detect when a device is connected to the system in windows 7 and I receive the WM_DEVICECHANGE just fine, however the message in wParam is always DBT_DEVNODES_CHANGED. Never a DBT_DEVICEARRIVAL or DBT_DEVICEREMOVECOMPLETE. I have had no luck googling thus far so I'm hoping someone will point me in the right direction before I find something in a few hours time :) Thanks for ya time.

推荐答案

文档指出,默认情况下应接收DBT_DEVICEARRIVAL和DBT_DEVICEREMOVECOMPLETE事件.应用程序可以通过调用RegisterDeviceNotification函数来注册以接收更多详细事件.希望您注册应用后会收到所需的事件.请确保在关闭时调用UnregisterDeviceNotification.

The documentation states that the DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE events should be received by default. The application can register to receive more detailed events by calling the RegisterDeviceNotification function. Hopefully you will receive the events you need after registering your app. Be sure to call UnregisterDeviceNotification upon closedown.

RegisterDeviceNotification参考:

RegisterDeviceNotification reference:

http://msdn.microsoft .com/en-us/library/aa363431%28v = VS.85%29.aspx

P/调用签名:

http://pinvoke.net/default.aspx/user32.RegisterDeviceNotification

UnregisterDeviceNotification参考:

UnregisterDeviceNotification reference:

http://msdn.microsoft .com/en-us/library/aa363475%28v = VS.85%29.aspx

P/调用签名:

http://pinvoke.net/default.aspx/user32.UnregisterDeviceNotification

这篇关于如何检测何时将设备添加到系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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