Здравствуйте собственно перехватываю вставку флешек
проблема вся в том что не приходит DBT_DEVTYP_DEVICEINTERFACE так как в ней содержится dbcc name
Буква вставленной флешки определяется
вот код
mainwindow.h
C++ (Qt)
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <Windows.h>
#include <Dbt.h>
#include <QMainWindow>
#include <QMessageBox>
#pragma comment(lib, "User32.lib")
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
bool msgp=false;
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
protected slots:
bool nativeEvent(const QByteArray &eventType, void *message, long *result);
public slots:
char FirstDriveFromMask(ULONG);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
mainwindow.cpp
C++ (Qt)
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
#include <hidclass.h>
#define HID_CLASSGUID {0x745a17a0,0x74d3, 0x11d0, 0xb6fe, 0x00a0c90f57da}
static const GUID GUID_DEVINTERFACE_LAUNCHPAD =
{ 0xfd96fadb, 0x9246, 0x4017, { 0x8d, 0x76, 0x3e, 0x30, 0x77, 0x80, 0xf6, 0xeb } };
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->centralWidget->hide();
// hide();
//ui->MainWindow.centralWidget->hide();
}
MainWindow::~MainWindow()
{
delete ui;
}
char MainWindow::FirstDriveFromMask( ULONG unitmask )
{
char i;
for (i = 0; i < 26; ++i)
{
if (unitmask & 0x1)
break;
unitmask = unitmask >> 1;
}
return( i + 'A' );
}
bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
MSG *msg = static_cast< MSG * > (message);
int msgType = msg->message;
if(msgType == WM_CREATE)
{
if(!msgp) //Only the first WM_PAINT
{
GUID InterfaceClassGuid = HID_CLASSGUID;
ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_LAUNCHPAD;
HWND hw = (HWND) this->effectiveWinId(); //Main window handle
HDEVNOTIFY hDevNotify = RegisterDeviceNotification(hw,&NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE);
msgp = true;
}
}
if (msgType== WM_DEVICECHANGE) // добавление или удаление нового устройства
{
// cout<<"USTROIASTVO="<<endl;
//PDEV_BROADCAST_HDR jj=(PDEV_BROADCAST_HDR)msg->lParam;
WPARAM kk=msg->wParam;
if (kk==DBT_DEVICEARRIVAL) // устройство было вставлено
{
PDEV_BROADCAST_HDR jj=(PDEV_BROADCAST_HDR)msg->lParam;
// PDEV_BROADCAST_DEVICEINTERFACE rrr=(PDEV_BROADCAST_DEVICEINTERFACE)msg->lParam;
// rrr->dbcc_name;
DWORD gt=jj->dbch_devicetype;
if (gt==DBT_DEVTYP_VOLUME)
{
int i=0;
QString as;
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)jj;
PDEV_BROADCAST_DEVICEINTERFACE devinfo=(PDEV_BROADCAST_DEVICEINTERFACE)jj;
wchar_t *gg=devinfo->dbcc_name;
while (NotificationFilter.dbcc_name[i]!=0)
//while (devinfo->dbcc_name[i]!=0)
{
wchar_t k=devinfo->dbcc_name[i];
as.append(k);
i++;
}
ULONG unitmask=lpdbv->dbcv_unitmask;
char t=FirstDriveFromMask(unitmask);
cout<<"BUKKKVAA="<<t<<endl;
cout<<"NAME="<<as.toStdString()<<endl;
}
if (gt==DBT_DEVTYP_DEVICEINTERFACE)
{
cout<<"voshel"<<endl;
}
}
if (kk==DBT_DEVICEREMOVECOMPLETE)
{
PDEV_BROADCAST_HDR jj=(PDEV_BROADCAST_HDR)msg->lParam;
DWORD gt=jj->dbch_devicetype;
if (gt==DBT_DEVTYP_VOLUME)
{
//cout<<"USTROIASTVO2="<<endl;
int i=0;
QString as;
PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)jj;
ULONG unitmask=lpdbv->dbcv_unitmask;
// lpdbv->
char t=FirstDriveFromMask(unitmask);
cout<<"BUKKKVAA="<<t<<endl;
cout<<"NAME="<<as.toStdString()<<endl;
}
}
}
return QMainWindow::nativeEvent(eventType,message,result);
//return false;
}
в чем может быть проблема
таким образом вот это условие не выполняется
C++ (Qt)
if (gt==DBT_DEVTYP_DEVICEINTERFACE)
{
cout<<"voshel"<<endl;
}