110,555
社区成员
发帖
与我相关
我的任务
分享
public const int WM_DEVICECHANGE = 0x219;
public const int DBT_DEVICEARRIAL = 0x8000;
public const int DBT_DEVICEREMOVECOMPLETE = 0x8004;
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_DEVICECHANGE)
{
switch (m.WParam.ToInt32())
{
case DBT_DEVICEARRIAL:
{
DriveInfo[] dis = DriveInfo.GetDrives();
foreach (DriveInfo di in dis)
{
if (di.DriveType == DriveType.Removable)
{
listBox1.Items.Add("U盘已经插入,盘符为:" + di.Name);
break;
}
}
break;
}
case DBT_DEVICEREMOVECOMPLETE:
{
listBox1.Items.Add("U盘已经移除");
break;
}
}
}
base.WndProc(ref m);
}