多个光驱,如何控制其中一个的关或开。(100分)

  • 主题发起人 主题发起人 nzfboy
  • 开始时间 开始时间
N

nzfboy

Unregistered / Unconfirmed
GUEST, unregistred user!
我已经可以开了,但无法关闭。请大家看一下,我把开的代码拿出来。如下:<br>function EjectCD(Drive : char) : bool;<br>var<br>&nbsp; mp : TMediaPlayer;<br>begin<br>&nbsp; result := false;<br>&nbsp; Application.ProcessMessages;<br>&nbsp; //if not IsDriveCD(Drive) then exit;<br>&nbsp; mp := TMediaPlayer.Create(nil);<br>&nbsp; mp.Visible := false;<br>&nbsp; mp.Parent := Application.MainForm;<br>&nbsp; mp.Shareable := true;<br>&nbsp; mp.DeviceType := dtCDAudio;<br>&nbsp; mp.FileName := Drive + ':';<br>&nbsp; mp.Open;<br>&nbsp; Application.ProcessMessages;<br>&nbsp; mp.Eject;<br>&nbsp; Application.ProcessMessages;<br>&nbsp; mp.Close;<br>&nbsp; Application.ProcessMessages;<br>&nbsp; mp.free;<br>&nbsp; result := true;<br>end;<br>注意:use &nbsp;mplayer
 
单个的可以使用mciSendString控制开关。<br>多个的据说就得用mciSendCommand了。但是我没有实验过。
 
参考下面的代码把, <br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>with MediaPlayer1 do<br>if (MediaPlayer1.Mode = mpOpen) then<br>&nbsp; &nbsp;mciSendCommand(MediaPlayer1.DeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0)<br>else<br>&nbsp; &nbsp;mciSendCommand(MediaPlayer1.DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);<br>end;<br><br>-------------- <br> <br> void CDEject() <br>  { <br>  MCI_SET_PARMS mciset; <br>  mciSendCommand( wDevID, MCI_SET, <br>  MCI_SET_DOOR_OPEN | MCI_SET_OFF, <br>  ( DWORD )( LPSTR ) &amp;mciset ); <br>  } <br>   <br>  void CDBack() <br>  { <br>  MCI_SET_PARMS mciset; <br>  mciSendCommand( wDevID, MCI_SET, <br>  MCI_SET_DOOR_CLOSED | MCI_SET_ON, <br>  ( DWORD )( LPSTR ) &amp;mciset ); <br>  } <br>  上面两个函数可以实现光驱托盘的弹出和收回。但是在使用这 两个函数之前,必须得到CD-ROM的设备ID号,这可以通过下面函数 来实现: <br>  void GetAudioCDDevID() <br>  { <br>  MCI_OPEN_PARMS mciOpenParms; <br>  mciOpenParms.lpstrDeviceType = "cdaudio"; <br>  if( mciSendCommand( 0, MCI_OPEN, MCI_OPEN_TYPE, <br>  ( DWORD )( LPVOID ) &amp;mciOpenParms ) ) { <br>  wDevID = 0; <br>  return; <br>  } <br>  wDevID = mciOpenParms.wDeviceID; <br>  } <br>  这里,wDevID是CD-ROM的设备ID。在上面的例子里面它应该是 一个全局变量。需要注意的是,在程序运行结束的时候需要关闭该 设备以便其他程序能够接管它,具体实现是: <br>  BOOL CloseCDDevice() <br>  { <br>  DWORD dwRes; <br>  dwRes = mciSendCommand( wDevID, MCI_CLOSE, 0, 0 ); <br>  return ( !( ( BOOL ) dwRes) ); <br>  } <br>  在具体实现的时候,一般按照: <br>  GetAudioCDDevID(); <br>  CDEject(); // 或者CDBack(); <br>  CloseCDDevice(); <br>  的顺序来调用。 <br><br><br>  《电子与电脑》99年1期
 
uses mmSystem;<br>procedure CDRomOpen(bOpenDrive:boolean; cDrive:char); &nbsp;//uses mmSystem<br>var open:MCI_OPEN_PARMS;<br>&nbsp; &nbsp; status:MCI_STATUS_PARMS;<br>&nbsp; &nbsp; flags:dword;<br>&nbsp; &nbsp; szDriveName:array[0..3]of char;<br>begin<br>&nbsp; &nbsp; strcopy(szDriveName,'?:');<br>&nbsp; &nbsp; ZeroMemory(@open,sizeof(MCI_OPEN_PARMS));<br>&nbsp; &nbsp; open.lpstrDeviceType:=LPCSTR(MCI_DEVTYPE_CD_AUDIO);<br>&nbsp; &nbsp; szDriveName[0]:=cDrive;<br>&nbsp; &nbsp; open.lpstrElementName:=szDriveName;<br>&nbsp; &nbsp; flags:=MCI_OPEN_TYPE or MCI_OPEN_TYPE_ID or MCI_OPEN_ELEMENT or MCI_OPEN_SHAREABLE;<br>&nbsp; &nbsp; if mciSendCommand(0,MCI_OPEN,flags,LongWord(@open))=0 then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; status.dwItem:=MCI_STATUS_READY;<br>&nbsp; &nbsp; &nbsp; &nbsp; if (bOpenDrive) then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mciSendCommand(open.wDeviceID,MCI_SET,MCI_SET_DOOR_OPEN,0)<br>&nbsp; &nbsp; &nbsp; &nbsp; else <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mciSendCommand(open.wDeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; mciSendCommand(open.wDeviceID,MCI_CLOSE,MCI_WAIT,0);<br>&nbsp; &nbsp; &nbsp; end;<br>end;<br>procedure TForm1.BitBtn1Click(Sender: TObject);<br>begin<br>&nbsp; CDRomOpen(true,'I'); &nbsp;// open cd<br>end;<br><br>procedure TForm1.BitBtn2Click(Sender: TObject);<br>begin<br>&nbsp; CDRomOpen(false,'I'); // &nbsp;Close cd<br>end;
 
nzfsoft的经试验,确定可行。其它人的没成功。
 
多人接受答案了。
 
后退
顶部