怎么获得设备改变的消息(高手请进)

李V四 2003-04-08 04:47:09
在msdn上有以下方法:
我的问题是怎么获得class的GUID??
Registering for Device Notification
Applications can use the RegisterDeviceNotification function to register to receive notification messages from the system. The following example function demonstrates how to register for notification of events for the device interfaces which are members of the interface class whose GUID is passed to the function.

BOOL DoRegisterDeviceInterface(
GUID InterfaceClassGuid,
HDEVNOTIFY *hDevNotify
)
/*
Routine Description:
Registers for notification of changes in the device interfaces for
the specified interface class GUID.

Parameters:
InterfaceClassGuid - The interface class GUID for the device
interfaces.

hDevNotify - Receives the device notification handle. On failure,
this value is NULL.

Return Value:
If the function succeeds, the return value is TRUE.

If the function fails, the return value is FALSE.
*/
{
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
DWORD Err;

ZeroMemory( ¬ificationFilter, sizeof(NotificationFilter) );
NotificationFilter.dbcc_size =
sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
NotificationFilter.dbcc_classguid = InterfaceClassGuid;

*hDevNotify = RegisterDeviceNotification( hWnd,
¬ificationFilter,
DEVICE_NOTIFY_WINDOW_HANDLE
);

if(!*hDevNotify)
{
Err = GetLastError();
printf( "RegisterDeviceNotification failed: %lx.\n", Err);
return FALSE;
}

return TRUE;
}


Then, in your main window procedure, check for messages announcing that a device has been attached, is about to be removed, or has been removed, as follows:

MyWindowProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
switch (nMsg)
{
case WM_DEVICECHANGE:
{
switch (wParam)
{
case DBT_DEVICEARRIVAL:
// Handle device arrival
break;

case DBT_DEVICEQUERYREMOVE:
// Handle device removal request
break;

case DBT_DEVICEREMOVECOMPLETE:
// Handle device removal
break;
}
}
.
.
.
}
}

...全文
89 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
李V四 2003-04-08
  • 打赏
  • 举报
回复
up

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧