光驱状态(50分)

  • 主题发起人 主题发起人 Briny
  • 开始时间 开始时间
B

Briny

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样判断光驱是弹出还是关上状态
 
我也想了很久。
 
我有段程序,帮你找找,您请少等。
 
可以利用MCI检查光驱状态。使用mciSendCommand或者mciSendString来检测。
program cdinout;

uses mmSystem;

var
MCIO : TMCI_Open_Parms;

MCIS : TMCI_Status_Parms;

begin

MCIO.lpstrDeviceType := PChar(MCI_DEVTYPE_CD_AUDIO);

if mciSendCommand(0, MCI_OPEN, MCI_OPEN_TYPE or MCI_OPEN_TYPE_ID or
MCI_OPEN_SHAREABLE, LongInt(@MCIO) )= 0 then

begin

MCIS.dwItem := MCI_STATUS_READY;

mciSendCommand(MCIO.wDeviceID, MCI_STATUS, MCI_STATUS_ITEM
or MCI_WAIT, LongInt(@MCIS));

if MCIS.dwReturn<> 0 then

mciSendCommand(MCIO.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0)
else

mciSendCommand(MCIO.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);

mciSendCommand(MCIO.wDeviceID, MCI_CLOSE, MCI_WAIT, 0);

end;


end.
 
不能判断的。
 
我也想知道
 

function IsAudioCD(Drive : char) : bool;
var
DrivePath : string;
MaximumComponentLength : DWORD;
FileSystemFlags : DWORD;
VolumeName : string;
begin

Result := false;
DrivePath := Drive + ':/';
if GetDriveType(PChar(DrivePath)) <> DRIVE_CDROM then
exit;
SetLength(VolumeName, 64);
GetVolumeInformation(PChar(DrivePath),
PChar(VolumeName),
Length(VolumeName),
nil,
MaximumComponentLength,
FileSystemFlags,
nil,
0);
if lStrCmp(PChar(VolumeName),'Audio CD') = 0 then
result := true;
end;


function PlayAudioCD(Drive : char) : bool;
var
mp : TMediaPlayer;
begin

result := false;
Application.ProcessMessages;
if not IsAudioCD(Drive) then
exit;
mp := TMediaPlayer.Create(nil);
mp.Visible := false;
mp.Parent := Application.MainForm;
mp.Shareable := true;
mp.DeviceType := dtCDAudio;
mp.FileName := Drive + ':';
mp.Shareable := true;
mp.Open;
Application.ProcessMessages;
mp.Play;
Application.ProcessMessages;
mp.Close;
Application.ProcessMessages;
mp.free;
result := true;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin

if not PlayAudioCD('D') then

ShowMessage('Not an Audio CD');
end;


 
接受答案了.
 
后退
顶部