windows 监听 U盘插入事件 用c++ 怎么写?

guyunchuxiu1993 2014-09-12 10:16:46
我知道 windows 提供了一个 message ,可是不知道怎么调用,请教各位?就是只要我的程序在运行,你插入了优盘 ,程序就能反应过来
...全文
701 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Saleayas 2014-09-19
  • 打赏
  • 举报
回复
					_hWnd_ = ::CreateWindowExW(0L, MESSAGE_WINDOW_CLASS_NAME, L"", 0, 0, 0, 1, 1, HWND_MESSAGE, NULL, _class._hModule, &_cd);
赵4老师 2014-09-19
  • 打赏
  • 举报
回复
SW_HIDE
xiaohuh421 2014-09-18
  • 打赏
  • 举报
回复
因为这个消息只发给窗口, 你不创建一个窗口你就收不到, 玩不了了
guyunchuxiu1993 2014-09-18
  • 打赏
  • 举报
回复
引用 7 楼 Saleayas 的回复:
不是让你创建一个向你看到的窗口, 创建一个消息窗口。
哦??还有看不见的窗口??求大侠指教,小弟感激不尽
赵4老师 2014-09-17
  • 打赏
  • 举报
回复
WM_DEVICECHANGE The WM_DEVICECHANGE device message notifies an application or device driver of a change to the hardware configuration of a device or the computer. Event = (UINT) wParam; dwData = (DWORD) lParam; Parameters Event Event type. This parameter can be one of the following values: Value Meaning DBT_CONFIGCHANGECANCELED A request to change the current configuration (dock or undock) has been canceled. DBT_CONFIGCHANGED The current configuration has changed, due to a dock or undock. DBT_DEVICEARRIVAL A device has been inserted and is now available. DBT_DEVICEQUERYREMOVE Permission is requested to remove a device. Any application can deny this request and cancel the removal. DBT_DEVICEQUERYREMOVEFAILED A request to remove a device has been canceled. DBT_DEVICEREMOVECOMPLETE A device has been removed. DBT_DEVICEREMOVEPENDING A device is about to be removed. Cannot be denied. DBT_DEVICETYPESPECIFIC A device-specific event has occurred. DBT_QUERYCHANGECONFIG Permission is requested to change the current configuration (dock or undock). DBT_USERDEFINED The meaning of this message is user-defined. dwData Address of a structure that contains event-specific data. Its meaning depends on the given event. Return Values Return TRUE to grant a requested action. Return BROADCAST_QUERY_DENY to deny a requested action. Remarks For devices that offer software-controllable features, such as ejection and locking, the system typically sends a DBT_DEVICEREMOVEPENDING message to let applications and device drivers end their use of the device gracefully. If the system forcibly removes a device, it may not send a DBT_DEVICEQUERYREMOVE message before doing so. DBT_CONFIGCHANGECANCELED, DBT_CONFIGCHANGED, DBT_DEVICEARRIVAL, DBT_DEVICEQUERYREMOVE, DBT_DEVICEQUERYREMOVEFAILED, DBT_DEVICEREMOVECOMPLETE, DBT_DEVICEREMOVEPENDING, DBT_DEVICETYPESPECIFIC, DBT_QUERYCHANGECONFIG, DBT_USERDEFINED QuickInfo Windows NT: Requires version 4.0 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in winuser.h. See Also System Messages Overview, System Message Messages
xiaohuh421 2014-09-17
  • 打赏
  • 举报
回复
既然定义的消息, 那么就需要窗口接收. 所以你的程序只需要创建一个窗口. 然后在窗口的消息处理函数处理WM_DEVICECHANGE消息即可.
xydp1987108 2014-09-17
  • 打赏
  • 举报
回复
在devicechange消息中处理
赵4老师 2014-09-17
  • 打赏
  • 举报
回复
参考Microsoft SDK\samples\multimedia\directshow\capture\dvapp\dvapp.cpp
sp_daiyq 2014-09-17
  • 打赏
  • 举报
回复
响应WM_DEVICECHANGE消息 在OnDeviceChange函数中判断
Saleayas 2014-09-17
  • 打赏
  • 举报
回复
不是让你创建一个向你看到的窗口, 创建一个消息窗口。
guyunchuxiu1993 2014-09-17
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
WM_DEVICECHANGE The WM_DEVICECHANGE device message notifies an application or device driver of a change to the hardware configuration of a device or the computer. Event = (UINT) wParam; dwData = (DWORD) lParam; Parameters Event Event type. This parameter can be one of the following values: Value Meaning DBT_CONFIGCHANGECANCELED A request to change the current configuration (dock or undock) has been canceled. DBT_CONFIGCHANGED The current configuration has changed, due to a dock or undock. DBT_DEVICEARRIVAL A device has been inserted and is now available. DBT_DEVICEQUERYREMOVE Permission is requested to remove a device. Any application can deny this request and cancel the removal. DBT_DEVICEQUERYREMOVEFAILED A request to remove a device has been canceled. DBT_DEVICEREMOVECOMPLETE A device has been removed. DBT_DEVICEREMOVEPENDING A device is about to be removed. Cannot be denied. DBT_DEVICETYPESPECIFIC A device-specific event has occurred. DBT_QUERYCHANGECONFIG Permission is requested to change the current configuration (dock or undock). DBT_USERDEFINED The meaning of this message is user-defined. dwData Address of a structure that contains event-specific data. Its meaning depends on the given event. Return Values Return TRUE to grant a requested action. Return BROADCAST_QUERY_DENY to deny a requested action. Remarks For devices that offer software-controllable features, such as ejection and locking, the system typically sends a DBT_DEVICEREMOVEPENDING message to let applications and device drivers end their use of the device gracefully. If the system forcibly removes a device, it may not send a DBT_DEVICEQUERYREMOVE message before doing so. DBT_CONFIGCHANGECANCELED, DBT_CONFIGCHANGED, DBT_DEVICEARRIVAL, DBT_DEVICEQUERYREMOVE, DBT_DEVICEQUERYREMOVEFAILED, DBT_DEVICEREMOVECOMPLETE, DBT_DEVICEREMOVEPENDING, DBT_DEVICETYPESPECIFIC, DBT_QUERYCHANGECONFIG, DBT_USERDEFINED QuickInfo Windows NT: Requires version 4.0 or later. Windows: Requires Windows 95 or later. Windows CE: Unsupported. Header: Declared in winuser.h. See Also System Messages Overview, System Message Messages
不带这么玩的,我知道MSDN
guyunchuxiu1993 2014-09-17
  • 打赏
  • 举报
回复
引用 3 楼 xiaohuh421 的回复:
既然定义的消息, 那么就需要窗口接收. 所以你的程序只需要创建一个窗口. 然后在窗口的消息处理函数处理WM_DEVICECHANGE消息即可.
我不用窗口,只是想返回一个值给主程序
guyunchuxiu1993 2014-09-16
  • 打赏
  • 举报
回复
不要沉,大神指教啊

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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