FrontPage > Microsoft.NET > C#.NET > USBメモリ認識チェック
「System.Windows.Forms.Form」などWindows部品の親にあたる
「System.Windows.Forms.Control」の「WndProc」をオーバーライドします。
「Message.Msg」が「WM_WM_DEVICECHANGE」かチェック。
「Message.WParam」が「 DBT_DEVICEARRIVAL、DBT_DEVICEREMOVECOMPLETE」かチェック。
// 「Windows メッセージを処理」をオーバライド protected override void WndProc(ref Message m) { // WM_DEVICECHANGE : 0x219 if (m.Msg == 0x219) { // DBT_DEVICEARRIVAL : 0x8000 if (m.WParam.ToInt64() == 0x8000) { // USB等デバイス認識 // DBT_DEVICEREMOVECOMPLETE : 0x8004 } else if (m.WParam.ToInt64() == 0x8004) { // USB等デバイス削除 } } base.WndProc(ref m); }