To determine which drives are available, their drive letters, and what kind of device they represent: DWORD <strong>GetLogicalDrives</strong>()
DWORD <strong>GetLogicalDriveStrings</strong>( DWORD nBufferLength, LPTSTR lpBuffer )
UINT <strong>GetDriveType</strong>( LPCTSTR lpRootPathName )
(Yes, the above is in C. Specify the Windows unit in your using clause to use them. Delphi will correct you about the types of the arguments as you type --chances are that the strings will be var parameters.) Either use the IDE help or Google MSDN for more information on each function.
To catch drive change notifications you need to subclass your main window. There are several ways to do this, but the simplest is just to override WndProc in one of your toplevel forms (probably the main form):
unit Unit1;
interface
uses ...
type
TForm1 = class(TForm)
...
protected
procedure WndProc( var message: TMessage ); override;
end;
implementation
procedure TForm1.WndProc( var message: TMessage );
begin
if message.msg = WM_DEVICECHANGE
then case message.wParam of
DBT_DEVICEARRIVAL: { A new drive is available };
DBT_DEVICEQUERYREMOVE: { The user pressed the eject button. Allow? };
DBT_DEVICEREMOVEPENDING: { The device is about to eject whether you like it or not. Clean up. };
DBT_DEVICEREMOVECOMPLETE: { The device is no longer available. };
end;
inherited
end;
ThelParam contains a pointer to a DEV_BROADCAST_HDR record identifying the type of device. You'll have to query the system again to determine which device actually changed.
Google "msdn" and any of the above message constants for more information.
Hope this helps.
[EDIT] You know what, I just checked this and it's not quite right... Check again tomorrow evening and I'll have it working for you... :$ :)
Duoas
Postaholic
2,043 posts since Oct 2007
Reputation Points: 1,140
Solved Threads: 229