visited 13 states (5.77%)
Create your own visited map of The World or Triposo world travel guide for Android
2012-12-27
2012-12-25
2012-12-23
2012-12-20
2012-12-17
2012-12-13
2012-12-11
2012-12-07
2012-12-03
2012-12-01
2012-11-28
2012-11-26
2012-11-23
2012-11-20
USB設備插拔消息
.h 內
private
:
// User declarations
void
__fastcall WndProc(TMessage &Msg);
.c內
#include "Dbt.h"
//---------------------------------------------------------------------------
// 重载窗体WndProc函数
void
__fastcall TForm1::WndProc(TMessage &Msg)
{
if
(Msg.Msg == WM_DEVICECHANGE)
{
int
nDevType;
PDEV_BROADCAST_HDR dbh;
if
(Msg.WParam == DBT_DEVICEARRIVAL || Msg.WParam == DBT_DEVICEREMOVECOMPLETE)
{
dbh = PDEV_BROADCAST_HDR(Msg.LParam);
if
(dbh->dbch_devicetype == DBT_DEVTYP_VOLUME)
{
if
(Msg.WParam == DBT_DEVICEARRIVAL)
{
ShowMessage(
"USB connect"
);
}
else
{
ShowMessage(
"USB remove"
);
}
}
}
}
TForm::WndProc(Msg);
}
1、可根據dbch_devicetype(DBT_DEVTYP_DEVICEINTERFACE和DBT_DEVTYP_VOLUME),分別得到PID/VID/SN和盤符號。
2、當USB設備不是存儲設備時,只出發一次WM_DEVICECHANGE,devicetype是DBT_DEVTYP_DEVICEINTERFACE
3、當USB設備是存儲設備時,會觸發兩次WM_DEVICECHANGE,一次是DBT_DEVTYP_DEVICEINTERFACE、一次是DBT_DEVTYP_VOLUME
4、插入時,先DBT_DEVTYP_DEVICEINTERFACE後DBT_DEVTYP_VOLUME
5、拔出時,先DBT_DEVTYP_VOLUME後DBT_DEVTYP_DEVICEINTERFACE
6、即使是存儲設備,有時也不會觸發DBT_DEVTYP_VOLUME,這個問題還沒搞清楚。
訂閱:
文章 (Atom)