Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Open and Close a CD Tray a better way Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
20-Nov-03
Category
Multimedia
Language
Delphi 3.x
Views
155
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC