Public partial class form1: Form
{
Public const int wm_devicechange = 0x219;
Public const int dbt_devicearrival = 0x8000;
Public const int dbt_configchangecanceled = 0x0019;
Public const int dbt_configchanged = 0x0018;
Public const int dbt_customevent = 0x8006;
Public const int dbt_devicequeryremove = 0x8001;
Public const int dbt_devicequeryremovefailed = 0x8002;
Public const int dbt_deviceremovecomplete = 0x8004;
Public const int dbt_deviceremovepending = 0x8003;
Public const int dbt_devicetypespecific = 0x8005;
Public const int dbt_devnodes_changed = 0x0007;
Public const int dbt_querychangeconfig = 0x0017;
Public const int dbt_userdefined = 0 xFFFF;
Public form1 ()
{
Initializecomponent ();
}
Protected override void wndproc (ref message m)
{
If (M. MSG = wm_devicechange)
{
Stringbuilder STR = new stringbuilder ();
Switch (M. wparam. toint32 ())
{
Case dbt_devnodes_changed:
Driveinfo [] drivers = driveinfo. getdrives ();
Foreach (driveinfo info in drivers)
{
If (info. drivetype = drivetype. removable)
{
Str. append ("drive letter:" + info. Name );
}
}
MessageBox. Show (Str. tostring ());
Break;
}
}
Base. wndproc (ref m );
}
}