-
Notifications
You must be signed in to change notification settings - Fork 364
/
DeviceHtoplug_Old.h
40 lines (35 loc) · 1.11 KB
/
DeviceHtoplug_Old.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#pragma once
#include <QObject>
#include <QHash>
#include <QUuid>
#include <QAbstractNativeEventFilter>
#include <Windows.h>
/**
* @brief 设备插拔事件监听
* @author 龚建波
* @date 2022-12-24
* @details
* 设备类文档,可以在设备管理器找自己的设备guid
* https://learn.microsoft.com/zh-cn/windows-hardware/drivers/install/overview-of-device-setup-classes
*/
class DeviceHotplug_Old : public QObject, public QAbstractNativeEventFilter
{
Q_OBJECT
public:
explicit DeviceHotplug_Old(QObject *parent = nullptr);
~DeviceHotplug_Old();
// 注册设备guid关联窗口id,RegisterDeviceNotification
// 暂未考虑注册失败的处理
// 暂未考虑重复注册
void installFilter(HANDLE winId, const QVector<QUuid> &uuids);
// UnregisterDeviceNotification
void uninstallFilter();
// QAbstractNativeEventFilter回调
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
signals:
void deviceAdded();
void deviceRemoved();
private:
// 设备通知句柄和uuid
QHash<QUuid, HDEVNOTIFY> devNotifys;
};