C#獲得USB事宜API實例剖析。本站提示廣大學習愛好者:(C#獲得USB事宜API實例剖析)文章只能為提供參考,不一定能成為您想要的結果。以下是C#獲得USB事宜API實例剖析正文
本文實例講述了C#獲得USB事宜API。分享給年夜家供年夜家參考。詳細以下:
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#法式設計有所贊助。