Author: Thanh Cong Le
Opening and Closing a CD Tray?
Answer:
1 uses
2 MMSystem;
3
4 // Open CD Tray
5
6 {Simple Way:}
7
8 mciSendstring('SET CDAUDIO DOOR OPEN WAIT', nil, 0, Self.Handle);
9
10 {More complex way:}
11
12 function OpenCD(Drive: Char): Boolean;
13 var
14 Res: MciError;
15 OpenParm: TMCI_Open_Parms;
16 Flags: DWORD;
17 S: string;
18 DeviceID: Word;
19 begin
20 Result := False;
21 S := Drive + ':';
22 Flags := MCI_OPEN_TYPE or MCI_OPEN_ELEMENT;
23 with OpenParm do
24 begin
25 dwCallback := 0;
26 lpstrDeviceType := 'CDAudio';
27 lpstrElementName := PChar(S);
28 end;
29 Res := mciSendCommand(0, MCI_OPEN, Flags, Longint(@OpenParm));
30 if Res <> 0 then
31 Exit;
32 DeviceID := OpenParm.wDeviceID;
33 try
34 Res := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
35 if Res = 0 then
36 Exit;
37 Result := True;
38 finally
39 mciSendCommand(DeviceID, MCI_CLOSE, Flags, Longint(@OpenParm));
40 end;
41 end;
42
43 //Close CD Tray
44
45 {Simple Way:}
46
47 mciSendstring('SET CDAUDIO DOOR CLOSED WAIT', nil, 0, Self.Handle);
48
49 {More complex way:}
50
51 function CloseCD(Drive: Char): Boolean;
52 var
53 Res: MciError;
54 OpenParm: TMCI_Open_Parms;
55 Flags: DWORD;
56 S: string;
57 DeviceID: Word;
58 begin
59 Result := False;
60 S := Drive + ':';
61 Flags := MCI_OPEN_TYPE or MCI_OPEN_ELEMENT;
62 with OpenParm do
63 begin
64 dwCallback := 0;
65 lpstrDeviceType := 'CDAudio';
66 lpstrElementName := PChar(S);
67 end;
68 Res := mciSendCommand(0, MCI_OPEN, Flags, Longint(@OpenParm));
69 if Res <> then
70 Exit;
71 DeviceID := OpenParm.wDeviceID;
72 try
73 Res := mciSendCommand(DeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
74 if Res = 0 then
75 Exit;
76 Result := True;
77 finally
78 mciSendCommand(DeviceID, MCI_CLOSE, Flags, Longint(@OpenParm));
79 end;
80 end;
|