调用头文件
#include <Windows.h>
#include <Dbt.h>
函数声明
/**
Description:
动态获取设备信息
@param 无
@return 无
/
bool nativeEvent(const QByteArray& eventType, void message, long* result);
函数体
bool MainWindowView::nativeEvent(const QByteArray& eventType, void* message, long* result)
{
MSG* msg = reinterpret_cast<MSG*>(message);
int msgType = msg->message;
if (WM_DEVICECHANGE == msgType)
{
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)msg->lParam;
switch (msg->wParam)
{
case 0x7:
printf(“11111111111111\n”);
break;
default:
break;
}
return true;
}
return false;//默认返回值
}