ryan_sabarre
asked on
knowing if CD is inside the tray
How will i know if there is a CD inside the cdtray?
ASKER
points was already increased, anybody can help me please
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
private
{ Private declarations }
procedure WMDEVICECHANGE(var msg: TMessage); message WM_DEVICECHANGE;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.WMDEVICECHANGE(var msg:tmessage);
const
DBT_DEVICEARRIVAL = $8000;
DBT_DEVICEMOVECOMPLETE = $8004;
var
TempStr: string;
begin
inherited;
case msg.WParam of
DBT_DEVICEARRIVAL :tempstr:='Insert CD';
DBT_DEVICEMOVECOMPLETE :tempstr:='Popup CD';
end;
ShowMessage(TempStr);
end;
ePing :o)
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
private
{ Private declarations }
procedure WMDEVICECHANGE(var msg: TMessage); message WM_DEVICECHANGE;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.WMDEVICECHANGE(var msg:tmessage);
const
DBT_DEVICEARRIVAL = $8000;
DBT_DEVICEMOVECOMPLETE = $8004;
var
TempStr: string;
begin
inherited;
case msg.WParam of
DBT_DEVICEARRIVAL :tempstr:='Insert CD';
DBT_DEVICEMOVECOMPLETE :tempstr:='Popup CD';
end;
ShowMessage(TempStr);
end;
ePing :o)
ASKER
sorry your source code does not do anything
it doest work
please stick to my question please
it doest work
please stick to my question please
ASKER
there are 2 cd rom drives in my computer
drive f and drive G
so how can i identify both drive if there is a CD existing inside?
drive f and drive G
so how can i identify both drive if there is a CD existing inside?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
var
DrivePath: array [0..3] of char = 'A:\';
function IsDiskIn(drive: char): boolean;
var
d1, d2, d3, d4: longword;
begin
DrivePath[0] := drive;
Result := GetDiskFreeSpace(DrivePath , d1, d2, d3, d4);
end;
this may be another solution without getting those blue error messages.
DrivePath: array [0..3] of char = 'A:\';
function IsDiskIn(drive: char): boolean;
var
d1, d2, d3, d4: longword;
begin
DrivePath[0] := drive;
Result := GetDiskFreeSpace(DrivePath
end;
this may be another solution without getting those blue error messages.
var
FatType: array [0..MAX_PATH] of Char;
MaxLen1,fSysFlags: DWORD;
ErrorMode: Integer;
Drive: String;
begin
FatType[0] := #0;
Drive := 'F:\';
ErrorMode := SetErrorMode(SEM_FAILCRITI CALERRORS) ;
if not GetVolumeInformation(PChar (Drive), nil, 0,nil, MaxLen1, fSysFlags,FatType,DWORD(si zeof(FatTy pe))) then
begin
ShowMessage('No CD in drive');
end else
ShowMessage('CD is in there');
SetErrorMode(ErrorMode);
end;
- - - - - - - - - - - - - - - - -
GetVolumeInformation returns False if there is no volume to get info for
FatType: array [0..MAX_PATH] of Char;
MaxLen1,fSysFlags: DWORD;
ErrorMode: Integer;
Drive: String;
begin
FatType[0] := #0;
Drive := 'F:\';
ErrorMode := SetErrorMode(SEM_FAILCRITI
if not GetVolumeInformation(PChar
begin
ShowMessage('No CD in drive');
end else
ShowMessage('CD is in there');
SetErrorMode(ErrorMode);
end;
- - - - - - - - - - - - - - - - -
GetVolumeInformation returns False if there is no volume to get info for
ASKER
hey "d32code" is your code safe?
i already try it with windows 2000 its ok
but in other Operating system i dont know
like WindowsXP/NT/Windows 98
anybody can say something with his code?
i already try it with windows 2000 its ok
but in other Operating system i dont know
like WindowsXP/NT/Windows 98
anybody can say something with his code?
with d32code code you get a blue error screen when there's a blank or audio cd.
sorry d32code but let me say that's not too elegant.
paul.
sorry d32code but let me say that's not too elegant.
paul.
{ ... }
type
TForm1 = class(TForm)
private
{ private declarations }
procedure WMDeviceChange(var Msg: TMessage); message WM_DeviceChange;
public
{ public declarations }
end;
procedure TForm1.WMDeviceChange(var Msg: TMessage);
const
DBT_QUERYCHANGECONFIG = $0017;
DBT_CONFIGCHANGED = $0018;
DBT_CONFIGCHANGECANCELED = $0019;
DBT_DEVICEARRIVAL = $8000;
DBT_DEVICEQUERYREMOVE = $8001;
DBT_DEVICEQUERYREMOVEFAILE D = $8002;
DBT_DEVICEREMOVEPENDING = $8003;
DBT_DEVICEREMOVECOMPLETE = $8004;
DBT_DEVICETYPESPECIFIC = $8005;
DBT_USERDEFINED = $FFFF;
var
tmpStr : String;
begin
inherited
case Msg.wParam of
DBT_DEVICEARRIVAL:
tmpStr := 'CD inserted in drive';
DBT_DEVICEREMOVECOMPLETE:
tmpSTr := 'CD removed from drive';
end;
ShowMessage(tmpStr);
end;
type
TForm1 = class(TForm)
private
{ private declarations }
procedure WMDeviceChange(var Msg: TMessage); message WM_DeviceChange;
public
{ public declarations }
end;
procedure TForm1.WMDeviceChange(var Msg: TMessage);
const
DBT_QUERYCHANGECONFIG = $0017;
DBT_CONFIGCHANGED = $0018;
DBT_CONFIGCHANGECANCELED = $0019;
DBT_DEVICEARRIVAL = $8000;
DBT_DEVICEQUERYREMOVE = $8001;
DBT_DEVICEQUERYREMOVEFAILE
DBT_DEVICEREMOVEPENDING = $8003;
DBT_DEVICEREMOVECOMPLETE = $8004;
DBT_DEVICETYPESPECIFIC = $8005;
DBT_USERDEFINED = $FFFF;
var
tmpStr : String;
begin
inherited
case Msg.wParam of
DBT_DEVICEARRIVAL:
tmpStr := 'CD inserted in drive';
DBT_DEVICEREMOVECOMPLETE:
tmpSTr := 'CD removed from drive';
end;
ShowMessage(tmpStr);
end;
if you are still looking, here's a couple of web pages at Borland Community
Is disk in drive?
http://community.borland.com/article/0,1410,18004,00.html
(I still like the GetVolumeInformation way better, since it does all types of CD's)
Is CD a Audio CD?
http://community.borland.com/article/0,1410,17756,00.html
Is disk in drive?
http://community.borland.com/article/0,1410,18004,00.html
(I still like the GetVolumeInformation way better, since it does all types of CD's)
Is CD a Audio CD?
http://community.borland.com/article/0,1410,17756,00.html
listening...
have you tried:
Path := 'D:\'; // your cd etc.
if DirectoryExists(Path) then ..
You may need to repeat after a time because the cd may have just been inserted and Explorer hasn't picked it up yet.
Regards,
Steve
Path := 'D:\'; // your cd etc.
if DirectoryExists(Path) then ..
You may need to repeat after a time because the cd may have just been inserted and Explorer hasn't picked it up yet.
Regards,
Steve
ASKER
Thank you for your idea
ASKER