代码如下:<br>uses MMSYSTEM;<br>procedure CloseCD(Drive: Char);<br>Var<br> Res : MciError;<br> OpenParm: TMCI_Open_Parms;<br> Flags : DWord;<br> S : String;<br> DeviceID : Word;<br>begin<br> S:=Drive+':';<br> Flags:=mci_Open_Type or mci_Open_Element;<br> With OpenParm do begin<br> dwCallback := 0;<br> lpstrDeviceType := 'CDAudio';<br> lpstrElementName := PChar(S);<br> end;<br> Res := mciSendCommand(0, mci_Open, Flags, Longint(@OpenParm));<br> IF Res<>0 Then exit;<br> DeviceID:=OpenParm.wDeviceID;<br> try<br> Res:=mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);<br> IF Res=0 Then exit;<br> finally<br> mciSendCommand(DeviceID, mci_Close, Flags, Longint(@OpenParm));<br> end;<br>end;<br><br>procedure OpenCD(Drive: Char);<br>Var<br> Res : MciError;<br> OpenParm: TMCI_Open_Parms;<br> Flags : DWord;<br> S : String;<br> DeviceID : Word;<br>begin<br> S:=Drive+':';<br> Flags:=mci_Open_Type or mci_Open_Element;<br> With OpenParm do begin<br> dwCallback := 0;<br> lpstrDeviceType := 'CDAudio';<br> lpstrElementName := PChar(S);<br> end;<br> Res := mciSendCommand(0, mci_Open, Flags, Longint(@OpenParm));<br> IF Res<>0 Then exit;<br> DeviceID:=OpenParm.wDeviceID;<br> try<br> Res:=mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);<br> IF Res=0 Then exit;<br> finally<br> mciSendCommand(DeviceID, mci_Close, Flags, Longint(@OpenParm));<br> end;<br>end;<br>