this one uses the same variable names for the Message-Struct like described in the
API-Reference:
procedure TForm1.WMDEVICECHANGE(var Msg: TMsg);
var
MsgType: String;
Filter: PDevBroadcastVolume;
lpdb: PDEVBROADCASTHDR;
Volume: String;
begin
lpdb := PDEVBROADCASTHDR(Msg.lParam);
if assigned(lpdb) then
begin
case lpdb^.dbch_devicetype of
DBT_DEVTYP_OEM: MsgType := 'OEM- or IHV-defined';
DBT_DEVTYP_DEVNODE: MsgType := 'Devnode number';
DBT_DEVTYP_VOLUME: MsgType := 'Logical volume';
DBT_DEVTYP_PORT: MsgType := 'Port (serial or parallel';
DBT_DEVTYP_NET: MsgType := 'Network resource';
DBT_DEVTYP_DEVICEINTERFACE: MsgType := 'DEVTYP_DEVICEINTERFACE';
DBT_DEVTYP_HANDLE: MsgType := 'DEVTYP_HANDLE';
DBT_DEVNODES_CHANGED: MsgType := 'DBT_DEVNODES_CHANGED';
else MsgType := 'Unkown DeviceType' + IntToStr(lpdb^.dbch_devicetype);
end;
end;
Memo1.Lines.Add(MsgType);
case Msg.wParam of
DBT_DEVICEARRIVAL: MsgType := 'DBT_DEVICEARRIVAL';
DBT_DEVICEQUERYREMOVE: MsgType := 'DBT_DEVICEQUERYREMOVE';
DBT_DEVICEQUERYREMOVEFAILED: MsgType := 'DBT_DEVICEQUERYREMOVEFAILED';
DBT_DEVICEREMOVEPENDING: MsgType := 'DBT_DEVICEREMOVEPENDING';
DBT_DEVICEREMOVECOMPLETE: MsgType := 'DBT_DEVICEREMOVECOMPLETE';
DBT_DEVICETYPESPECIFIC: MsgType := 'DBT_DEVICETYPESPECIFIC';
DBT_CONFIGCHANGED: MsgType := 'DBT_CONFIGCHANGED';
else MsgType := 'Unknown event ' + IntToHex(Msg.wParam, 0);
end;
Memo1.Lines.Add('Msg: ' + IntToStr(Msg.message));
Memo1.Lines.Add('Event: ' + IntToStr(Msg.wParam));
Memo1.Lines.Add('Result: ' + IntToStr(Msg.lParam));
if Msg.lParam > 0 then
begin
Filter:= @Msg.lParam;
Volume:= DetermineVolume(Filter^.dbcv_unitmask);
MsgType := MsgType + ' ' + Volume +
' '+ IntToSTr(Filter^.dbcv_flags);
Memo1.Lines.Add(MsgType);
end;
if Msg.wParam = DBT_DEVICEARRIVAL then
begin
//do something
end;
end;