我要打开光驱!!!(100分)

  • 主题发起人 主题发起人 安伟
  • 开始时间 开始时间

安伟

Unregistered / Unconfirmed
GUEST, unregistred user!
我想打开我指定的光驱!
而不是系统默认的第一个光驱!比方 我有两个光驱我要打开第二个!

请那位高手指点!!! 谢谢!
 

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

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

注意:use mplayer
 
uses mmSystem;
procedure CDRomOpen(bOpenDrive:boolean;
cDrive:char);
//uses mmSystem
var open:MCI_OPEN_PARMS;
status:MCI_STATUS_PARMS;
flags:dword;
szDriveName:array[0..3]of char;
begin

strcopy(szDriveName,'?:');
ZeroMemory(@open,sizeof(MCI_OPEN_PARMS));
open.lpstrDeviceType:=LPCSTR(MCI_DEVTYPE_CD_AUDIO);
szDriveName[0]:=cDrive;
open.lpstrElementName:=szDriveName;
flags:=MCI_OPEN_TYPE or MCI_OPEN_TYPE_ID or MCI_OPEN_ELEMENT or MCI_OPEN_SHAREABLE;
if mciSendCommand(0,MCI_OPEN,flags,LongWord(@open))=0 then

begin

status.dwItem:=MCI_STATUS_READY;
if (bOpenDrive) then

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

mciSendCommand(open.wDeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0);
mciSendCommand(open.wDeviceID,MCI_CLOSE,MCI_WAIT,0);
end;

end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin

CDRomOpen(true,'I');
// open cd
end;


procedure TForm1.BitBtn2Click(Sender: TObject);
begin

CDRomOpen(false,'I');
// Close cd
end;
 
怎么样,发银子吧
 
首先要用这个单元 mmSystem;
procedure CDRomOpen(bOpenDrive:boolean;
cDrive:char);

var open:MCI_OPEN_PARMS;
status:MCI_STATUS_PARMS;
flags:dword;
szDriveName:array[0..3]of char;
begin

strcopy(szDriveName,'?:');
ZeroMemory(@open,sizeof(MCI_OPEN_PARMS));
open.lpstrDeviceType:=LPCSTR(MCI_DEVTYPE_CD_AUDIO);
szDriveName[0]:=cDrive;
open.lpstrElementName:=szDriveName;
flags:=MCI_OPEN_TYPE or MCI_OPEN_TYPE_ID or MCI_OPEN_ELEMENT or MCI_OPEN_SHAREABLE;
if mciSendCommand(0,MCI_OPEN,flags,LongWord(@open))=0 then

begin

status.dwItem:=MCI_STATUS_READY;
if (bOpenDrive) then

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

mciSendCommand(open.wDeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0);
mciSendCommand(open.wDeviceID,MCI_CLOSE,MCI_WAIT,0);
end;

end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin

CDRomOpen(true,'I');
// open cd
end;


procedure TForm1.BitBtn2Click(Sender: TObject);
begin

CDRomOpen(false,'I');
// Close cd
end;

 
Procedure CloseDoor(Driveletter:Char);
Var
Alias : String;
begin

Alias:='Drive'+DriveLetter;
mciSendString(pChar('Open '+DriveLetter+': Alias ' +Alias+' Type CDAudio'), nil, 0, 0);
mciSendString(pChar('Set '+Alias+'do
or Closed'), nil, 0, 0);
mciSendString(pChar('Close '+DriveLetter+': Alias ' +Alias+' Type CDAudio'), nil, 0, 0);
end;

Procedure OpenDoor(Driveletter:Char);
Var
Alias : String;
begin

Alias:='Drive'+DriveLetter;
mciSendString(pChar('Open '+DriveLetter+': Alias ' +Alias+' Type CDAudio'), nil, 0, 0);
mciSendString(pChar('Set '+Alias+'do
or Open'), nil, 0, 0);
mciSendString(pChar('Close '+DriveLetter+': Alias ' +Alias+' Type CDAudio'), nil, 0, 0);
end;



例如 OpenDoor(Edit1.Text[1]);
 
加上
uses
mmsystem;
 
多人接受答案了。
 
后退
顶部