hier ein sourcecode für laufwerkserkennung beim entfernen/anschliessen
Delphi-Quellcode:
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;
MFG
[edit=Luckie]Delphi-Tags gesetzt. Mfg, Luckie[/edit]