windows下C++编程,程序如何知道当前电脑是否插入了U盘?

chen327684096 2013-03-02 07:32:12
当打开程序后,如果插入了U盘,程序自动在桌面上创建一个快捷方式,应该怎么做?
需要看哪方面的资料?
...全文
440 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2013-03-07
  • 打赏
  • 举报
回复
CWnd::OnDeviceChange
afx_msg BOOL OnDeviceChange( UINT nEventType, DWORD dwData );

Parameters

nEventType

An event type. See the Remarks section for a description of the available values

dwData

The address of a structure that contains event-specific data. Its meaning depends on the given event.

Remarks

The framework calls this member function to notify an application or device driver of a change to the hardware configuration of a device or the computer.

For devices that offer software-controllable features, such as ejection and locking, the operating system typically sends a DBT_DEVICEREMOVEPENDING message to let applications and device drivers end their use of the device gracefully. 

If the operating system forcefully removes of a device, it may not send a DBT_DEVICEQUERYREMOVE message before doing so.

The nEvent parameter can be one of these values: 

DBT_DEVICEARRIVAL   A device has been inserted and is now available. 


DBT_DEVICEQUERYREMOVE   Permission to remove a device is requested. Any application can deny this request and cancel the removal.


DBT_DEVICEQUERYREMOVEFAILED   Request to remove a device has been canceled.


DBT_DEVICEREMOVEPENDING   Device is about to be removed. Cannot be denied.


DBT_DEVICEREMOVECOMPLETE   Device has been removed.


DBT_DEVICETYPESPECIFIC   Device-specific event.


DBT_CONFIGCHANGED   Current configuration has changed.


DBT_DEVNODES_CHANGED   Device node has changed. 
Note   This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.

CWnd Overview |  Class Members |  Hierarchy Chart

See Also   WM_DEVICECHANGE
lm_whales 2013-03-07
  • 打赏
  • 举报
回复
监控相应的设备类,注册下一个消息就可以了
chen327684096 2013-03-02
  • 打赏
  • 举报
回复
引用 2 楼 vuqrzk5w 的回复:
想深一点,如楼上据说,监听USB端口。 想浅一点实现,就在运行时看电脑有多少个盘符,定时检测,如果有多出来的,看看容量、特征,猜是不是U盘。
有没什么资料或者书籍有介绍这方面的编程?思路有了但不知道如何下手
chen327684096 2013-03-02
  • 打赏
  • 举报
回复
引用 1 楼 sun734274006 的回复:
你是说的360的那种吧,我觉得需要监听usb端口
对的,类似360那种,监听USB端口需要一直监听吗?
vuqrzk5w 2013-03-02
  • 打赏
  • 举报
回复
想深一点,如楼上据说,监听USB端口。 想浅一点实现,就在运行时看电脑有多少个盘符,定时检测,如果有多出来的,看看容量、特征,猜是不是U盘。
find_ 2013-03-02
  • 打赏
  • 举报
回复
你是说的360的那种吧,我觉得需要监听usb端口

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧