ADD: Exit from drive if it removed

This commit is contained in:
Alexander Koblov 2013-12-28 17:08:04 +00:00
commit 261feaf52f
2 changed files with 39 additions and 3 deletions

View file

@ -5197,6 +5197,14 @@ end;
procedure TfrmMain.OnDriveWatcherEvent(EventType: TDriveWatcherEvent; const ADrive: PDrive);
begin
UpdateDiskCount;
if (EventType = dweDriveRemoved) and Assigned(ADrive) then
begin
if IsInPath(ADrive^.Path, ActiveFrame.CurrentPath, True, True) then
ActiveFrame.CurrentPath:= gpExePath
else if IsInPath(ADrive^.Path, NotActiveFrame.CurrentPath, True, True) then
NotActiveFrame.CurrentPath:= gpExePath;
end;
end;
procedure TfrmMain.AppActivate(Sender: TObject);

View file

@ -146,15 +146,43 @@ end;
{$IFDEF MSWINDOWS}
function MyWndProc(hWnd: HWND; uiMsg: UINT; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
var
ADrive: PDrive = nil;
ADrive: TDrive;
lpdb: PDEV_BROADCAST_HDR absolute lParam;
lpdbv: PDEV_BROADCAST_VOLUME absolute lpdb;
function GetDrivePath(UnitMask: ULONG): String;
var
DriveNum: Byte;
begin
for DriveNum:= 0 to 25 do
begin
if ((UnitMask shr DriveNum) and $01) <> 0 then
Exit(AnsiChar(DriveNum + Ord('a')) + ':\');
end;
end;
begin
case uiMsg of
WM_DEVICECHANGE:
case wParam of
DBT_DEVICEARRIVAL:
DoDriveAdded(ADrive);
begin
if (lpdb^.dbch_devicetype <> DBT_DEVTYP_VOLUME) then
DoDriveAdded(nil)
else begin
ADrive.Path:= GetDrivePath(lpdbv^.dbcv_unitmask);
DoDriveAdded(@ADrive);
end;
end;
DBT_DEVICEREMOVECOMPLETE:
DoDriveRemoved(ADrive);
begin
if (lpdb^.dbch_devicetype <> DBT_DEVTYP_VOLUME) then
DoDriveRemoved(nil)
else begin
ADrive.Path:= GetDrivePath(lpdbv^.dbcv_unitmask);
DoDriveRemoved(@ADrive);
end;
end;
end;
end; // case
Result := CallWindowProc(OldWProc, hWnd, uiMsg, wParam, lParam);