在Windows上的Qt中检测USB通知 [英] Detecting USB notification in Qt on windows
问题描述
在我的qt应用程序中,我想将一些应用程序输出数据保存到USB笔式驱动器中的文件中.我需要在我的qt应用程序中添加以下功能
- 检测到USB驱动器插入
- 我只有一个USB插槽.
- 插入后,我想知道其驱动器号和字母,然后将PC中特定位置的文件传输到该USB驱动器.
有人可以告诉我我用来获取上述所有功能的winapi .lib,.h和.dll文件吗?
如果有人可以提供一些代码片段,对我很有帮助.
处理 In my qt application I want to save some application output data to an file in my usb pen drive. I need to put following features in my qt application Can anybody tell me which winapi .lib , .h and .dll file i hav to use to get all the above functionalities ? If someone can provide some code snippets, it will very much helpful for me. Handle If wParam is If the structures Now check the
这篇关于在Windows上的Qt中检测USB通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! WM_DEVICECHANGE
-请参见
WM_DEVICECHANGE
- See http://lists.trolltech.com/qt-interest/2001-08/thread00698-0.html for how to handle windows messages in QT.DBT_DEVICEARRIVAL
then cast lParam to a DEV_BROADCAST_HDR *
dbch_devicetype
is DBT_DEVTYP_VOLUME
cast lParam again, this time to a DEV_BROADCAST_VOLUME *
dbcv_unitmask
bit field, iterate over bits 0..31 and check if the corresponding drive match your USB drive.if (wParam == DBT_DEVICEARRIVAL) {
if (((DEV_BROADCAST_HDR *) lParam)->dbch_devicetype == DBT_DEVTYP_VOLUME) {
DWORD Mask = ((DEV_BROADCAST_VOLUME *) lParam)->dbcv_unitmask;
for (int i = 0; i < 32; ++i) {
if (Mask & (1 << i)) {
char RootPath[4] = "A:\\";
RootPath[0] += i;
// Check if the root path in RootPath is your USB drive.
}
}
}
}