控制多个关驱中一个,烦请把VC码转为delphi码!!(50分)

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

nzfboy

Unregistered / Unconfirmed
GUEST, unregistred user!
控制多个关驱中一个
例如使用MCI命令控制多个光驱的弹出关闭:(Visual C++)
// 例子:弹出光驱F CDRomOpen(TRUE,'F')
// 关闭光驱F CDRomOpen(FALSE,'F')
void CDRomOpen(BOOL bOpenDrive,TCHAR cDrive)
{
MCI_OPEN_PARMS open;
MCI_STATUS_PARMS status;
DWORD flags;
TCHAR szDriveName[4];
strcpy(szDriveName,"?:");
::ZeroMemory(&open,sizeof(MCI_OPEN_PARMS));
open.lpstrDeviceType=(LPCSTR)MCI_DEVTYPE_CD_AUDIO;
szDriveName[0]=cDrive;
open.lpstrElementName=szDriveName;
flags=MCI_OPEN_TYPE¦MCI_OPEN_TYPE_ID¦MCI_OPEN_ELEMENT¦MCI_OPEN_SHAREABLE;
if(!mciSendCommand(0,MCI_OPEN,flags,(unsigned long)&open)){
status.dwItem=MCI_STATUS_READY;
if(bOpenDrive)
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);
}
}
 
试试吧.

uses mmSystem;
procedure CDRomOpen(bOpenDrive: Boolean; cDrive: Char);
var
; o ; ; ; ; ; : MCI_OPEN_PARMS;
; status ; ; ;: MCI_STATUS_PARMS status;
; flags ; ; ; : DWord;
; szDriveName : array[0..3] of Char;
begin
; szDriveName := '?:';
; ZeroMemory(@o, SizeOf(MCI_OPEN_PARMS));
; szDriveName[0] := cDrive;

; o.lpstrDeviceType :=PChar(MCI_DEVTYPE_CD_AUDIO);
; o.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,Cardinal(@o)) = 0 then
; ; begin
; ; status.dwItem:=MCI_STATUS_READY;

; ; if bOpenDrive then
; ; ; mciSendCommand(o.wDeviceID,MCI_SET,MCI_SET_DOOR_OPEN,0)
; ; else
; ; ; mciSendCommand(o.wDeviceID,MCI_SET,MCI_SET_DOOR_CLOSED,0);

; ; mciSendCommand(o.wDeviceID,MCI_CLOSE,MCI_WAIT,0);
; ; end;
end;
 
以上VC转换为DELPHI后的代码:
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;
 
如何检查是否是CD-ROM
有几个
 
后退
顶部