Cc get USB event API

From , 4 Years ago, written in C#, viewed 56 times.
URL https://pastebin.vip/view/767b2cc8
  1. const int WM_DEVICECHANGE = 0x2190;
  2.         const int DBT_DEVICEARRIVAL = 0x8000;
  3.         const int DBT_DEVICEREMOVECOMPLETE = 0x8004;
  4.         protected override void WndProc(ref Message m)
  5.         {
  6.             try
  7.             {
  8.                 //if (m.Msg == WM_DEVICECHANGE)
  9.                 //{
  10.                     switch (m.WParam.ToInt32())
  11.                     {
  12.                         case DBT_DEVICEARRIVAL:     // U盘插入
  13.                             DriveInfo[] s = DriveInfo.GetDrives();
  14.                             foreach (DriveInfo drive in s)
  15.                             {
  16.                                 if (drive.DriveType == DriveType.Removable)
  17.                                 {
  18.                                     Console.WriteLine("USB插入");
  19.                                     break;
  20.                                 }
  21.                             }
  22.                             break;
  23.                         case DBT_DEVICEREMOVECOMPLETE: //U盘卸载
  24.                             //
  25.                             Console.WriteLine("USB卸载");
  26.                             break;
  27.                         default:
  28.                             break;
  29.                     }
  30.                 //}
  31.             }
  32.             catch (Exception ex)
  33.             {
  34.                 MessageBox.Show(ex.Message);
  35.             }
  36.             base.WndProc(ref m);
  37.         }
  38.  
  39. //csharp/5886

Reply to "Cc get USB event API"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website