Como abrir o drive do CD/DVD?
É necessário estar declarado MMSystem na seção uses,
em versões unicode declare Winapi.MMSystem.
Com esta função é possível escolher o drive de CD/DVD a ser aberto.
Abaixo segue o código fonte da função:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| function OpenCD(Drive: Char): Boolean;
var
Res: MciError;
OpenParm: TMCI_Open_Parms;
Flags: DWORD;
S: string;
DeviceID: Word;
begin
Result := False;
S := Drive + ':';
Flags := MCI_OPEN_TYPE or MCI_OPEN_ELEMENT;
with OpenParm do
begin
dwCallback := 0;
lpstrDeviceType := 'CDAudio';
lpstrElementName := PChar(S);
end;
Res := mciSendCommand(0, MCI_OPEN, Flags, Longint(@OpenParm));
if Res <> 0 then
Exit;
DeviceID := OpenParm.wDeviceID;
try
Res := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
if Res = 0 then
Exit;
Result := True;
finally
mciSendCommand(DeviceID, MCI_CLOSE, Flags, Longint(@OpenParm));
end;
end; |
function OpenCD(Drive: Char): Boolean;
var
Res: MciError;
OpenParm: TMCI_Open_Parms;
Flags: DWORD;
S: string;
DeviceID: Word;
begin
Result := False;
S := Drive + ':';
Flags := MCI_OPEN_TYPE or MCI_OPEN_ELEMENT;
with OpenParm do
begin
dwCallback := 0;
lpstrDeviceType := 'CDAudio';
lpstrElementName := PChar(S);
end;
Res := mciSendCommand(0, MCI_OPEN, Flags, Longint(@OpenParm));
if Res <> 0 then
Exit;
DeviceID := OpenParm.wDeviceID;
try
Res := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
if Res = 0 then
Exit;
Result := True;
finally
mciSendCommand(DeviceID, MCI_CLOSE, Flags, Longint(@OpenParm));
end;
end;
Exemplo de uso:
1
2
3
4
5
| procedure TForm1.Button1Click(Sender: TObject);
begin
// Abrindo o drive de DVD
OpenCD('G');
end; |
procedure TForm1.Button1Click(Sender: TObject);
begin
// Abrindo o drive de DVD
OpenCD('G');
end;
Testado com o Delphi XE 7 no Windows 8.1.
Veja nesta dica como fechar o drive.
http://showdelphi.com.br/dica-como-fechar-o-drive-do-cd-dvd-delphi/
-
InfusTec
-
2.005 views
- 0 comentários
- 21 de abril de 2015
Está gostando do conteúdo? Considere pagar um cafezinho para nossa equipe!
Posts Relacionados - Continue Aprendendo