码迷,mamicode.com
首页 > 其他好文 > 详细

MFC入门教程之控件(7)设备自动检测ondevicechange的添加和使用

时间:2014-07-10 21:49:41      阅读:338      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   使用   

MFC入门学习(1)了解MFC

 

源文档<http://blog.csdn.net/codectq/article/details/19131227>

 

MFC入门学习之控件(2)创建一个对话框窗口并在运行时显示

 

源文档<http://blog.csdn.net/codectq/article/details/19131289>

 

MFC入门学习之控件(3)标签控件Tab Control的添加和使用

 

源文档<http://blog.csdn.net/codectq/article/details/19131553>

 

MFC入门学习之控件(4)标签控件List Control的添加和使用(上)

 

源文档<http://blog.csdn.net/codectq/article/details/19176595>

 

MFC入门学习之控件(5)标签控件List Control的添加和使用(中)

 

源文档<http://blog.csdn.net/codectq/article/details/19204165>

 

MFC入门学习之控件(6)标签控件List Control的添加和使用(下)

 

源文档<http://blog.csdn.net/codectq/article/details/23550465


在对话框初始化过程中将设备通知消息注册到winproc中

//Register to receive notification when a USB device is plugged in.

broadcastInterface.dbcc_size =sizeof(DEV_BROADCAST_DEVICEINTERFACE);

broadcastInterface.dbcc_devicetype =DBT_DEVTYP_DEVICEINTERFACE;

 

memcpy( &(broadcastInterface.dbcc_classguid),

&(GUID_CLASS_USB_DEVICE),

sizeof(struct _GUID));

 

gNotifyDevHandle = RegisterDeviceNotification(hwnd,

&broadcastInterface,

DEVICE_NOTIFY_WINDOW_HANDLE);

 

// Now register for Hub notifications.

memcpy( &(broadcastInterface.dbcc_classguid),

&(GUID_CLASS_USBHUB),

sizeof(struct _GUID));

 

gNotifyHubHandle = RegisterDeviceNotification(hwnd,

&broadcastInterface,

DEVICE_NOTIFY_WINDOW_HANDLE);

 

 编写设备状态变化时的状态解析函数:

 

OnDeviceChange(UINTnEventType, DWORD dwData)

{

PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)dwData;

char cDrive;

TRACE("OnDeviceChange: %u\n",nEventType);

switch(nEventType)

{

case DBT_DEVICEARRIVAL:

TRACE("OnDeviceChange: DBT_DEVICEARRIVAL\n");

if(DBT_DEVTYP_VOLUME == lpdb->dbch_devicetype)

{

 

 

 

 

//Logical volume has been inserted and becomes available

PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;

if(0 == lpdbv->dbcv_flags)

{

cDrive = FirstDriveFromMask(lpdbv->dbcv_unitmask);

RemovableDiskArrival(cDrive);

}

}

break;

case DBT_DEVICEQUERYREMOVE:

break;

case DBT_DEVICEQUERYREMOVEFAILED:

break;

case DBT_DEVICEREMOVEPENDING:

break;

case DBT_DEVICEREMOVECOMPLETE:

TRACE("OnDeviceChange:DBT_DEVICEREMOVECOMPLETE\n");

if(DBT_DEVTYP_VOLUME == lpdb->dbch_devicetype)

{

//Logical volume has been physically removed

PDEV_BROADCAST_VOLUME lpdbv = (PDEV_BROADCAST_VOLUME)lpdb;

if(0 == lpdbv->dbcv_flags)

{

 

 

 

 

 

TRACE("OnDeviceChange: DBT_DEVICEREMOVECOMPLETERefreshTree\n");

cDrive = FirstDriveFromMask(lpdbv->dbcv_unitmask);

RemovableDiskRemove(cDrive);

 

 

 

 

}

}

 

break;

case DBT_DEVICETYPESPECIFIC:

break;

case DBT_CONFIGCHANGED:

break;

case DBT_DEVNODES_CHANGED:

break;

}

 

return TRUE;

}

 

 将消息添加到消息map表中

BEGIN_MESSAGE_MAP(CAutoDownDlg,CDialog)

ON_WM_DEVICECHANGE()

END_MESSAGE_MAP()

MFC入门教程之控件(7)设备自动检测ondevicechange的添加和使用,布布扣,bubuko.com

MFC入门教程之控件(7)设备自动检测ondevicechange的添加和使用

标签:des   style   blog   http   color   使用   

原文地址:http://blog.csdn.net/codectq/article/details/37597281

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!