应用程序可以使用RegisterDeviceNotification功能进行注册,以接收来自系统的通知消息。 This example显示如何注册设备接口的事件通知,这些接口是GUID传递给函数的接口类的成员。
在此示例中,我应该使用哪个代码片段来处理USB设备插入消息?
答案 0 :(得分:2)
搜索 DBT_DEVICEARRIVAL:这是处理USB设备插入消息的地方。
case WM_DEVICECHANGE:
{
//
// This is the actual message from the interface via Windows messaging.
// This code includes some additional decoding for this particular device type
// and some common validation checks.
//
// Note that not all devices utilize these optional parameters in the same
// way. Refer to the extended information for your particular device type
// specified by your GUID.
//
PDEV_BROADCAST_DEVICEINTERFACE b = (PDEV_BROADCAST_DEVICEINTERFACE) lParam;
TCHAR strBuff[256];
// Output some messages to the window.
switch (wParam)
{
case DBT_DEVICEARRIVAL:
msgCount++;
StringCchPrintf(
strBuff, 256,
TEXT("Message %d: DBT_DEVICEARRIVAL\n"), msgCount);
break;