Вот что есть, может как то и поможет...
| Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private procedure WMDeviceChange(var Msg: TMessage); message WM_DeviceChange; public { Public declarations } end;
const DBT_DeviceArrival = $8000; DBT_DeviceRemoveComplete = $8004;
type PDevBroadcastVolume = ^TDevBroadcastVolume; //Если честно не помню точно, но помоему эта структура описана не полностью... TDevBroadcastVolume = packed record dbcv_size: DWORD; dbcv_devicetype: DWORD; dbcv_reserved: DWORD; dbcv_unitmask: DWORD; dbcv_flags: Word; end; function GetDrive(pDBVol: PDevBroadcastVolume): string;
var Form1: TForm1;
implementation
{$R *.dfm}
function GetDrive(pDBVol: PDevBroadcastVolume): string; //Получаем букву драйва из структуры PDevBroadcastVolume var i: Byte; Maske: DWORD; 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;
procedure TForm1.WMDeviceChange(var Msg: TMessage); //собственно ловим инсерт/еджект драйвов var Drive: string; begin Application.ProcessMessages; if Msg.wParam = DBT_DeviceArrival then begin //если засунули Drive := GetDrive(PDevBroadcastVolume(Msg.lParam)); ShowMessage(Drive); end else if Msg.wParam = DBT_DeviceRemoveComplete then begin //если выдернули Drive := GetDrive(PDevBroadcastVolume(Msg.lParam)); ShowMessage(Drive); end; end;
end.
|
|