Detects insertion or removal of removable drives. Use it in 1 or 2 steps: 1) Create instance of this class in your project and add handlers for the DeviceArrived, DeviceRemoved and QueryRemove events. AND (if you do not want drive detector to creaate a hidden form)) 2) Override WndProc in your form and call DriveDetector's WndProc from there. If you do not want to do step 2, just use the DriveDetector constructor without arguments and it will create its own invisible form to receive messages from Windows.
Inheritance: IDisposable
 /// <summary>
 /// Set up the hidden form.
 /// </summary>
 /// <param name="detector">DriveDetector object which will receive notification about USB drives, see WndProc</param>
 public RemovableDetectorForm(RemovableDriveDetector detector)
 {
     mDetector            = detector;
     this.MinimizeBox     = false;
     this.MaximizeBox     = false;
     this.ShowInTaskbar   = false;
     this.ShowIcon        = false;
     this.FormBorderStyle = FormBorderStyle.None;
     this.Load           += new System.EventHandler(this.Load_Form);
     this.Activated      += new EventHandler(this.Form_Activated);
 }
Exemple #2
0
 protected virtual void ApplicationInitialize()
 {
     if (this.IsStandalone)
     {
     #if SAFE_ANYWHERE_WITHUK
         mRemovableDriveDetector = new RemovableDriveDetector();
         mRemovableDriveDetector.DeviceRemoved += new RemovableDriveDetectorEventHandler(RemovableDriveDetector_DeviceRemoved);
     #else
         this.ClearUselessFiles();
     #endif
     }
 }
 /// <summary>
 /// Set up the hidden form. 
 /// </summary>
 /// <param name="detector">DriveDetector object which will receive notification about USB drives, see WndProc</param>
 public RemovableDetectorForm(RemovableDriveDetector detector)
 {
     mDetector = detector;
     this.MinimizeBox = false;
     this.MaximizeBox = false;
     this.ShowInTaskbar = false;
     this.ShowIcon = false;
     this.FormBorderStyle = FormBorderStyle.None;
     this.Load += new System.EventHandler(this.Load_Form);
     this.Activated += new EventHandler(this.Form_Activated);
 }