资源简介

1.使用nativeEvent事件获取相关信息 2.界面是一个QDialog,设备vid pid 序列号已提取好,将显示在上面 3.附带源码,同时静态编译的了一个应用程序,可直接运行 4.测试环境为qt5.3.2+vs2013 5.给需要的人作参考,更多功能请自行拓展,不喜勿下哦!

资源截图

代码片段和文件信息

#include “dialog.h“
#include “ui_dialog.h“

#include 
#include 
#include 

Dialog::Dialog(QWidget *parent) :
    QDialog(parent)
    ui(new Ui::Dialog)
{
    registerDevice();
    ui->setupUi(this);

    setWindowtitle(QStringLiteral(“优盘探测工具v1.0 (By-Mr.Luo)“));
    setWindowFlags(Qt::WindowCloseButtonHint | Qt::WindowMinimizeButtonHint);
    setFixedSize(350 210);
    ui->lineEditPid->setReadOnly(true);
    ui->lineEditProduct->setReadOnly(true);
    ui->lineEditSerialNum->setReadOnly(true);
    ui->lineEditVendorID->setReadOnly(true);
    ui->lineEditVid->setReadOnly(true);
    ui->lineEditProductVersion->setReadOnly(true);
    ui->label_6->setAlignment(Qt::AlignRight);

    QPalette pa;
    pa.setColor(QPalette::WindowTextQt::red);
    ui->label_6->setPalette(pa);
}

Dialog::~Dialog()
{
    delete ui;
}

void Dialog::registerDevice()
{
    const GUID GUID_DEVINTERFACE_LIST[] = {
        { 0xA5DCBF10 0x6530 0x11D2 { 0x90 0x1F 0x00 0xC0 0x4F 0xB9 0x51 0xED } }
        { 0x53f56307 0xb6bf 0x11d0 { 0x94 0xf2 0x00 0xa0 0xc9 0x1e 0xfb 0x8b } }};

    HDEVNOTIFY hDevNotify;
    DEV_BROADCAST_DEVICEINTERFACE NotifacationFiler;
    ZeroMemory(&NotifacationFilersizeof(DEV_BROADCAST_DEVICEINTERFACE));
    NotifacationFiler.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
    NotifacationFiler.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;

    for(int i=0;i    {
        NotifacationFiler.dbcc_classguid = GUID_DEVINTERFACE_LIST[i];//GetCurrentUSBGUID();//m_usb->GetDriverGUID();

        hDevNotify = RegisterDeviceNotification((HANDLE)this->winId()&NotifacationFilerDEVICE_NOTIFY_WINDOW_HANDLE);
        if(!hDevNotify)
        {
            qDebug() << QStringLiteral(“注册失败!“) <        }
    }
}

bool Dialog::nativeEvent(const QByteArray &eventType void *message long *result)
{
    Q_UNUSED(eventType);
    Q_UNUSED(result);
    MSG* msg = reinterpret_cast(message);
    int msgType = msg->message;
    if(msgType==WM_DEVICECHANGE)
    {
        PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)msg->lParam;
        switch (msg->wParam) {
        case DBT_DEVICEARRIVAL:
            if(lpdb->dbch_devicetype == DBT_DEVTYP_VOLUME)
            {
                PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;
                if(lpdbv->dbcv_flags ==0) //优盘
                {
                    QString USBDisk = QString(this->FirstDriveFromMask(lpdbv ->dbcv_unitmask));
                    qDebug() << QString(QStringLiteral(“已检测到USB设备插入--盘符:<%1>“)).arg(USBDisk);
                    ui->label_6->setText(QString(QStringLiteral(“已检测到USB设备插入--盘符:<%1>“)).arg(USBDisk));
                }
                if(lpdbv->dbcv_flags == DBTF_MEDIA) { //光盘
                    qDebug() << “CD_Arrived“;
                }
            }
            if(lpdb->dbch_devicetype = DBT_DEVTYP_

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5987  2018-01-31 13:46  USBWatchTest\dialog.cpp

     文件        536  2016-04-22 17:11  USBWatchTest\dialog.h

     文件       4386  2016-04-22 16:55  USBWatchTest\dialog.ui

     文件        175  2016-04-22 00:30  USBWatchTest\main.cpp

     文件        373  2016-04-22 00:30  USBWatchTest\USBWatchTest.pro

     目录          0  2018-01-31 13:56  USBWatchTest

     文件    9756672  2018-01-31 13:53  USBWatchTest.exe

----------- ---------  ---------- -----  ----

              9768129                    7


评论

共有 条评论