Article View: borland.public.cppbuilder.nativeapi
Article #16395Re: Eject CD
From: JD
Date: Wed, 14 May 2003 20:36
Date: Wed, 14 May 2003 20:36
113 lines
4209 bytes
4209 bytes
"Mirko Rajkovaca" <mirko796@ptt.yu> wrote:
>
>Which API function should I use to eject CD from CD-drive?(under win98,Me and XP)
This sample was posted by Rhys a while back. I haven't tested it (or even looked at it) but I assume that since he uses it it works. I included the entire post so that you can choose what's relivent for you.
~ JD
//-------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include <shellapi.h>
#include "Unit1.h"
//-------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
void EjectCD(void);
void CloseDrawer(void);
//--------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------
void __fastcall TForm1::SpeedButton3Click(TObject *Sender)
{
Close();
//CD->Eject();
EjectCD();
}
//--------------------------------------------------------------
void __fastcall TForm1::SpeedButton4Click(TObject *Sender)
{
if(DiskFree(0) < 10) SpeedButton1->Visible = false;
if(!FileExists("CV.hta"))
CloseDrawer();
if(FileExists("CV.hta"))
ShellExecute( NULL, "open", "CV.hta" , NULL, "", SW_SHOWNORMAL );
else
{
MessageDlg("Business card CD not in drive.", mtWarning ,
TMsgDlgButtons() << mbOK , 0 );
EjectCD();
}
}
//--------------------------------------------------------------
void __fastcall TForm1::SpeedButton1Click(TObject *Sender)
{
if(!FileExists("SageWorld Language Tutor.rtf"))
CloseDrawer();
if(FileExists("SageWorld Language Tutor.rtf"))
ShellExecute( NULL, "open", "SageWorld Language Tutor.rtf" , NULL, "",
SW_SHOWNORMAL );
else
{
MessageDlg("Business card CD not in drive.", mtWarning ,
TMsgDlgButtons() << mbOK , 0 );
EjectCD();
}
}
//--------------------------------------------------------------
void __fastcall TForm1::SpeedButton2Click(TObject *Sender)
{
if(!FileExists("Demo.exe"))
CloseDrawer();
if(FileExists("Demo.exe"))
ShellExecute( NULL, "open", "Demo.exe" , NULL, "", SW_SHOWNORMAL );
else
{
MessageDlg("Business card CD not in drive.", mtWarning ,
TMsgDlgButtons() << mbOK , 0 );
EjectCD();
}
}
//--------------------------------------------------------------
void EjectCD(void)
{
UINT wDeviceID;
MCI_OPEN_PARMS pciop;
MCI_SET_PARMS mciSetParms;
MCI_GENERIC_PARMS mcigp;
pciop.lpstrDeviceType = "cdaudio";
if (mciSendCommand(NULL, MCI_OPEN,
MCI_OPEN_TYPE, (DWORD)(LPVOID) &pciop))
{
return;
}
wDeviceID = pciop.wDeviceID;
mciSendCommand(wDeviceID, MCI_SET,MCI_SET_DOOR_OPEN, (DWORD)(LPVOID)
&mciSetParms);
mciSendCommand(wDeviceID, MCI_CLOSE,MCI_WAIT, (DWORD)(LPVOID) &mcigp);
}
//--------------------------------------------------------------
void CloseDrawer(void)
{
UINT wDeviceID;
MCI_OPEN_PARMS pciop;
MCI_SET_PARMS mciSetParms;
pciop.lpstrDeviceType = "cdaudio";
MCI_GENERIC_PARMS mcigp;
if (mciSendCommand(NULL, MCI_OPEN,
MCI_OPEN_TYPE, (DWORD)(LPVOID) &pciop))
{
return;
}
wDeviceID = pciop.wDeviceID;
mciSendCommand(wDeviceID, MCI_SET,MCI_SET_DOOR_CLOSED, (DWORD)(LPVOID)
&mciSetParms);
mciSendCommand(wDeviceID, MCI_CLOSE,MCI_WAIT, (DWORD)(LPVOID) &mcigp);
}
Technical Details
Message-ID:
<3ec2a8df@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailReferences:
<3ec2a399$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,ef9a257b22696451 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-05-14 13:41:00 PST From: "JD" <nospam@nospam.com> Sender: "JD" <nospam@nospam.com> Reply-To: "JD" <nospam@nospam.com> Subject: Re: Eject CD Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 172.128.244.93 172.128.244.93 References: <3ec2a399$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.65 Message-ID: <3ec2a8df@newsgroups.borland.com> Date: 14 May 2003 13:36:47 -0700 X-Trace: newsgroups.borland.com 1052944607 207.105.83.65 (14 May 2003 13:36:47 -0700) Lines: 114 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail