我正在尝试检测何时将HDMI线缆插入(或移除)运行Windows 7或更高版本的笔记本电脑或台式机。
我从WinAPI调用RegisterDeviceNotification
并设置以下内容:
DEV_BROADCAST_DEVICEINTERFACE filter;
memset(&filter, 0, sizeof(filter));
filter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
filter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
filter.dbcc_classguid = GUID_DEVINTERFACE_MONITOR; //Detect new monitor/tv..
hNotify = RegisterDeviceNotification(window, &filter, DEVICE_NOTIFY_WINDOW_HANDLE);
有效。我收到如下通知:
case WM_DEVICECHANGE:
{
DEV_BROADCAST_DEVICEINTERFACE* info = (DEV_BROADCAST_DEVICEINTERFACE*) lParam;
switch(wParam)
{
case DBT_DEVICEARRIVAL:
MessageBox(NULL, info->dbcc_name, "Attached", 0);
break;
case DBT_DEVICEREMOVECOMPLETE:
MessageBox(NULL, info->dbcc_name, "Detached", 0);
break;
default:
break;
}
}
break;
这很好用。它打印:
\\?\DISPLAY#SNY9C01#4&323d76f&0&UID50725632#{e6f07b5f-ee97-4a90-b076-33f57bf4eaa7}
但是,我无法确定它是HDMI端口还是其他端口。我所知道的是它的显示器已插入某个地方"。知道如何确定事件来自哪个端口?
有什么想法吗?