Generalnie chodzi o napędy podłączane pod USB.
Mam problem z przechwytywaniem Autouruchamiania (żeby rozpoznać moment podłączenia napędu i ominąć Autouruchamianie), kiedy program jest w tray'u. Kiedy forma jest otwarta - działa bez zarzutu. Jak jest w tray'u, to nie reaguje - domyślam się, że nie odbiera wtedy komunikatu... Jaka na to jest rada? I przy okazji - czy po podłączeniu nowego urządzenia (np. pendrive USB) rozsyłany jest komunikat jak została mu przydzielona litera dysku? Teraz po prostu skanuję napędy (GetDriveType), ale muszę porównywać stan "przed" i "po", żeby wykryć zmiany.
Do rozpoznawania autoruchamiania używam takiego kodu:
w definicji klasy formy, w sekcji public:
public
MsgID_QueryCancelAutoPlay : Word;
procedure WndProc( var Msg : TMessage ); override;
end;
W zdarzeniu FormCreate:
MsgID_QueryCancelAutoPlay := RegisterWindowMessage('QueryCancelAutoPlay');
i sama procedurka WndProc:
procedure TfrmMain.WndProc( var Msg : TMessage );
begin
if (Msg.Msg = WM_DEVICECHANGE) then
begin
case (Msg.WParam) of
DBT_DEVICEARRIVAL:
begin
StatusBar1.SimpleText := 'Connected';
end;
DBT_DEVICEREMOVECOMPLETE:
begin
StatusBar1.SimpleText := 'Disconnected';
end;
end;
end else
if (Msg.Msg = MsgID_QueryCancelAutoPlay) then
begin
Msg.Result := 1; // 1=stop AutoPlay, 0 conitnue Autoplay
end else
inherited WndProc(Msg);
end
Jacek