Article View: borland.public.cppbuilder.nativeapi
Article #9693Re: CD Tray
From: JD
Date: Thu, 17 Jun 2004 08:45
Date: Thu, 17 Jun 2004 08:45
129 lines
4201 bytes
4201 bytes
"Simon Macneall" <macneall@iinet-dot-net-dot-au> wrote:
> [...] Anyone have any suggestions?
This is a post cut-n-pasted as it:
This is a simple CD door opening and closing program (with a few extras
built in). I think it'll do all that you need. just modify it a bit.
--
Yours,
Rhys
//--------------------------------------------------------------------------
-
#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:
<40d15a23$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!solnet.ch!solnet.ch!irazu.switch.ch!switch.ch!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<opr9pzs4ic2nqexn@lightyear>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,d2e307fb824306b9 X-Google-Attributes: gid10cc67,public From: "JD" <nospam@nospam.com> Sender: "JD" <nospam@nospam.com> Reply-To: "JD" <nospam@nospam.com> Subject: Re: CD Tray Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 172.132.4.55 References: <opr9pzs4ic2nqexn@lightyear> NNTP-Posting-Host: 207.105.83.66 Message-ID: <40d15a23$1@newsgroups.borland.com> Date: 17 Jun 2004 01:45:23 -0700 X-Trace: newsgroups.borland.com 1087461923 207.105.83.66 (17 Jun 2004 01:45:23 -0700) Lines: 130 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!solnet.ch!solnet.ch!irazu.switch.ch!switch.ch!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail