WEB开发网
开发学院WEB开发ASP.NET C#获取USB事件API 阅读

C#获取USB事件API

 2012-12-10 14:33:51 来源:WEB开发网   
核心提示: const int WM_DEVICECHANGE = 0x2190;const int DBT_DEVICEARRIVAL = 0x8000;const int DBT_DEVICEREMOVECOMPLETE = 0x8004;protected override void WndProc(ref Messa

  const int WM_DEVICECHANGE = 0x2190;
const int DBT_DEVICEARRIVAL = 0x8000;
const int DBT_DEVICEREMOVECOMPLETE = 0x8004;
protected override void WndProc(ref Message m)
{
try
{
//if (m.Msg == WM_DEVICECHANGE)
//{
switch (m.WParam.ToInt32())
{
case DBT_DEVICEARRIVAL: // U盘插入
DriveInfo[] s = DriveInfo.GetDrives();
foreach (DriveInfo drive in s)
{
if (drive.DriveType == DriveType.Removable)
{
Console.WriteLine("USB插入");
break;
}
}
break;
case DBT_DEVICEREMOVECOMPLETE: //U盘卸载
//
Console.WriteLine("USB卸载");
break;
default:
break;
}
//}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
base.WndProc(ref m);
}

Tags:获取 USB 事件

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接