Exemplo n.º 1
0
        private void OnDeviceAddRemove(object sender, DriveDetectorEventArgs e)
        {
            _disks = DiskInfo.GetDisks();

            ddlDevice.Items.Clear();

            foreach (var disk in _disks)
            {
                ddlDevice.Items.Add(disk);

                if (_selectedDisk != null && _selectedDisk.DiskNumber == disk.DiskNumber)
                {
                    ddlDevice.SelectedItem = disk;
                }
            }
        }
Exemplo n.º 2
0
        internal void WndProc(ref Message m)
        {
            if (m.Msg == NativeInterop.WM_DEVICECHANGE)
            {
                var wParam = m.WParam.ToInt32();

                switch (wParam)
                {
                case NativeInterop.DBT_DEVICEARRIVAL:
                case NativeInterop.DBT_DEVICEREMOVECOMPLETE:
                {
                    var devType = Marshal.ReadInt32(m.LParam, 4);

                    if (devType == NativeInterop.DBT_DEVTYP_VOLUME)
                    {
                        var vol         = (NativeInterop.DEV_BROADCAST_VOLUME)Marshal.PtrToStructure(m.LParam, typeof(NativeInterop.DEV_BROADCAST_VOLUME));
                        var driveLetter = DriveMaskToLetter(vol.dbcv_unitmask);
                        DriveDetectorEventHandler handler = null;

                        if (wParam == NativeInterop.DBT_DEVICEARRIVAL)
                        {
                            handler = DeviceArrived;
                        }
                        else
                        {
                            handler = DeviceRemoved;
                        }

                        if (handler != null)
                        {
                            var args = new DriveDetectorEventArgs($"{driveLetter}:\\");

                            handler(this, args);
                        }
                    }

                    break;
                }
                }
            }
        }