|
提示:需要在重载WndProc函数,在消息中捕获处理。
protected override void WndProc(ref Message sysm) { const int WM_DEVICECHANGE = 0x219; const int DBT_DEVICEARRIVAL = 0x8000; try { if (sysm.Msg == WM_DEVICECHANGE) { if (sysm.WParam.ToInt32() == DBT_DEVICEARRIVAL) { string[] dirs = Environment.GetLogicalDrives(); //取得所有的盘符 foreach (string dir in dirs) { if (GetDriveType(dir) == 2 || GetDriveType(dir) == 3) //是移动硬盘 { try { MessageBox.Show("ok"); } catch { MessageBox.Show("error"); }
} }
}
}
} catch { } base.WndProc(ref sysm); } |