C#获取USB事件API实例分析
内容摘要
本文实例讲述了C#获取USB事件API。分享给大家供大家参考。具体如下:
const int WM_DEVICECHANGE = 0x2190;
const int DBT_DEVICEARRIVAL = 0x8000;
const int DBT_DEVICER
const int WM_DEVICECHANGE = 0x2190;
const int DBT_DEVICEARRIVAL = 0x8000;
const int DBT_DEVICER
文章正文
本文实例讲述了C#获取USB事件API。分享给大家供大家参考。具体如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 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); } |
希望本文所述对大家的C#程序设计有所帮助。
代码注释