控制光驱开、关 (15分)

  • 主题发起人 主题发起人 toli
  • 开始时间 开始时间
T

toli

Unregistered / Unconfirmed
GUEST, unregistred user!
如果机器上有二个或两个以上的光驱,如何能能命令控制其中任意一个?
mciSendString('Set cdaudiodo
or open wait', nil, 0, handle);

mciSendString('Set cdaudiodo
or closed wait', nil, 0, handle);

只能控制第一个光驱。
 
mcisendcommand(deviceid,mci_set,mci_set_door_open,0);
查查相关的命令吧
 
uses mmsystem

mcisendstring('set CDAudiodo
or open wait',nil,0,handle);//开光驱

mcisendstring('set CDAudiodo
or closed wait',nil,0,handle);//关光驱

 
同意vine的意见,在写代码前一定要在use里加上MMSystem
 
mcisendcommand(deviceid,mci_set,mci_set_door_open,0);
相关的命令在哪里?
 
function GetDevice : word;
var
OpenParms : TMCI_Open_Parms;
MyErrorString : array[0..MAXERRORLENGTH - 1] of Char;
fErrCode:longint;
FFlags:dword;
ss: string;
begin

Result:=0;
FFlags := mci_notify or MCI_OPEN_ELEMENT or MCI_OPEN_SHAREABLE;
OpenParms.dwCallback := 0;
ss := DriverPath+'/track 1.cda';//DriverPath 你想控制的光驱的盘符,如I:
OpenParms.lpstrElementName := PChar(ss);
fErrCode := mciSendCommand(0, mci_open, FFlags, Longint(@OpenParms));
if FErrCode = 0 then
{device successfully opened}
begin

Result := OpenParms.wDeviceID;
end
else

begin

MciGetErrorString(FErrCode,MyErrorString,MAXERRORLENGTH - 1);
Showmessage(MyErrorString);
end;

end;


function OpenDoor(Open: Boolean): boolean;
var
SetParms: TMCI_Set_Parms;
GenParm: TMCI_Generic_Parms;
fErrCode:longint;
FFlags:dword;
did:dword;
MyErrorString : array[0..MAXERRORLENGTH - 1] of Char;
begin

if Open then

FFlags := mci_notify or mci_set_door_open
else

FFlags := mci_notify or mci_set_door_Closed;
do
orOpen := Open;
SetParms.dwCallback := 0;
did:=GetDevice;
fErrCode := mciSendCommand(did, mci_Set, FFlags, Longint(@SetParms));
if fErrCode=0 then

result:=true
else

result:=false;
FFlags := 0;
GenParm.dwCallback := 0;
fErrCode := mciSendCommand( did, mci_Close, FFlags, Longint(@GenParm));
if FErrCode <> 0 then
{device successfully opened}
begin

MciGetErrorString(FErrCode,MyErrorString,MAXERRORLENGTH - 1);
Showmessage(MyErrorString);
end;

end;
 
var
Form1: TForm1;
t:boolean;
implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin

if t then

begin

t:=false;
mcisendstring('set cdaudiodo
or open',nil,0,handle);
end
else

begin

t:=true;
mcisendstring('set cdaudiodo
or closed',nil,0,handle);
end;

end;


 
多人接受答案了。
 

Similar threads

后退
顶部