如何用程序实现“打开”光盘(30分)

  • 主题发起人 主题发起人 chenglc
  • 开始时间 开始时间
C

chenglc

Unregistered / Unconfirmed
GUEST, unregistred user!
请各位大虾帮忙解决。
 
是打开光驱还是打开光盘上的文件
 
好象是打开光驱!!
 
http://lysoft.lz169.com/kingron/__17.html
 
library ctlcdrom;<br><br>uses<br> &nbsp;Windows, MMSystem;<br><br>{$R *.res}<br><br>type<br> &nbsp;TCDRomOperate = (cdOpen, cdClose);<br> &nbsp;TCDStatus &nbsp; &nbsp; = (csOpen, csClosed);<br><br>function OperateCDROM(DriveLetter: Char; Operate: TCDRomOperate): Boolean;<br>var<br> &nbsp;OpenParm: TMCI_OPEN_Parms;<br> &nbsp;Flags: DWORD;<br> &nbsp;Drive: string;<br> &nbsp;DeviceID: Word;<br> &nbsp;Err: Cardinal;<br>begin<br> &nbsp;Drive := DriveLetter + ':';<br> &nbsp;Flags := mci_Open_Type or mci_Open_Element;<br> &nbsp;with OpenParm do<br> &nbsp;begin<br> &nbsp; &nbsp;dwCallBack := 0;<br> &nbsp; &nbsp;lpstrDeviceType := 'CDAudio';<br> &nbsp; &nbsp;lpstrElementName := PChar(Drive);<br> &nbsp;end;<br> &nbsp;Result := mciSendCommand(0, mci_Open, Flags, Longint(@OpenParm)) = 0;<br> &nbsp;if Result then<br> &nbsp;begin<br> &nbsp; &nbsp;DeviceID := OpenParm.wDeviceID;<br> &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp;case Operate of<br> &nbsp; &nbsp; &nbsp; &nbsp;cdOpen :<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0) = 0;<br> &nbsp; &nbsp; &nbsp; &nbsp;cdClose:<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0) = 0;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp;mciSendCommand(DeviceID, mci_Close, Flags, Longint(@OpenParm));<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br>end;<br><br>function OpenCDROM(Drive: Char): Boolean; stdcall; // 打开CDROM<br>begin<br> &nbsp;Result := OperateCDROM(Drive, cdOpen);<br>end;<br><br>function CloseCDROM(Drive: Char): Boolean; stdcall; // 关闭CDROM<br>begin<br> &nbsp;Result := OperateCDROM(Drive, cdClose);<br>end;<br><br>exports //dll文件导出的函数列表<br> &nbsp;OpenCDROM,<br> &nbsp;CloseCDROM;<br><br>begin<br>end.
 
to zqw0117:<br> 要打开和关闭光驱,似乎不用这么麻烦吧,用以下两条语句就能搞定了吧:<br>uses mmsystem<br>mciSendString('Set cdaudio door open wait',nil,0,handle);<br>mciSendString('Set cdaudio door closed wait',nil,0,handle);
 
同意楼上,这种mci代码十多年前用VB3写过,网上很多例子的。
 
我的代码可以分别打开一个电脑上的多个CDRom,直接用mciSendString则如果电脑上同时安装了2个以上的CDRom,将会出现一打开就同时打开的现象.
 
后退
顶部