Registriert seit: 30. Sep 2006
Ort: Gundelfingen
1.109 Beiträge
Delphi 2007 Professional
|
Re: USB Laufwerk erkennen
25. Apr 2008, 17:05
Delphi-Quellcode:
interface
type
TFenster = class(TForm) // deine Form halt...
// bla
procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
// bla
end;
implementation
procedure TFenster.WMDeviceChange(var Msg: TMessage);
type PDevBroadcastHdr = ^TDevBroadcastHdr;
TDevBroadcastHdr = packed record
dbcd_size, dbcd_devicetype, dbcd_reserved: DWORD; end;
type PDevBroadcastVolume = ^TDevBroadcastVolume;
TDevBroadcastVolume = packed record
dbcv_size, dbcv_devicetype, dbcv_reserved, dbcv_unitmask: DWORD;
dbcv_flags: Word; end;
function GetDrive(pDBVol: PDevBroadcastVolume): string;
var i: Byte; Maske: DWORD;
begin
if (pDBVol^.dbcv_flags and $0001) = $0001 then
begin
Maske := pDBVol^.dbcv_unitmask;
for i := 0 to 25 do
begin
if (Maske and 1) = 1 then
Result := Char(i + Ord('A')) + ': ';
Maske := Maske shr 1;
end;
end;
end;
var Drive: String;
begin
case Msg.wParam of
$8000:
if PDevBroadcastHdr(Msg.lParam)^.dbcd_devicetype = $0002 then
Pan('Datenträger in Laufwerk '+GetDrive(PDevBroadcastVolume(Msg.lParam))+'eingelegt');
$8004:
if PDevBroadcastHdr(Msg.lParam)^.dbcd_devicetype = $0002 then
begin
Drive := GetDrive(PDevBroadcastVolume(Msg.lParam));
Pan('Datenträger aus Laufwerk '+Drive+'entfernt');
if not(Drive = '') and (Drive[1] = ExtractFilePath(ParamStr(0))[1]) then Close;
end;
end;
end;
vllt noch nach den entstrechenden Units suchen und einbinden...
Dominik Wer anderen eine Grube gräbt, hat ein Gruben-Grab-Gerät!
|