熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

C#獲取USB事件API

2022-06-13   來源: .NET編程 

  const int WM_DEVICECHANGE = x;
const int DBT_DEVICEARRIVAL = x;
const int DBT_DEVICEREMOVECOMPLETE = x;
protected override void WndProc(ref Message m)
{
try
{
//if (mMsg == WM_DEVICECHANGE)
//{
switch (mWParamToInt())
{
case DBT_DEVICEARRIVAL: // U盤插入
DriveInfo[] s = DriveInfoGetDrives();
foreach (DriveInfo drive in s)
{
if (driveDriveType == DriveTypeRemovable)
{
ConsoleWriteLine("USB插入");
break;
}
}
break;
case DBT_DEVICEREMOVECOMPLETE: //U盤卸載
//
ConsoleWriteLine("USB卸載");
break;
default:
break;
}
//}
}
catch (Exception ex)
{
MessageBoxShow(exMessage);
}
baseWndProc(ref m);
}


From:http://tw.wingwit.com/Article/program/net/201311/14053.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.