🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #9715

Re: CD Tray

#9715
From: JD
Date: Fri, 18 Jun 2004 23:22
43 lines
2193 bytes
"Simon Macneall" <macneall@iinet-dot-net-dot-au> wrote:
> [...] If it is closed with no disk in, the FileExists will
> fail and you will try to close the door, which would be
> wrong.

No, it would be a step in a chain of events.

Instead of looking for a particular file, look for any file.
If that fails, close the door and look again. If it fails again
the drive is empty so open the door.

But there is a better way. You can actually detect the draw
state by using the MediaPlayer:

    if( MediaPlayer->Mode = mpOpen )

Another way is to override the form's WndProc method and listen for the WM_DEVICECHANGE message:

//--- in the form's header
    protected: // User declarations
        virtual void __fastcall WndProc(TMessage &Message);

//--- in the cpp file
    void __fastcall TForm1::WndProc(TMessage &Message)
    {
        if( Message.Msg == WM_DEVICECHANGE )
          {
              if( Message.wParam == DBT_DEVICEREMOVEPENDING )
                {
                    // user has started to eject CD
                }
              else if( Message.wParam == DBT_DEVICEREMOVECOMPLETE )
                {
                    // the draw has been closed
                }
          }
        TForm::WndProc(Message);
    }

Also have a look at DBT_DEVICEARRIVAL.

~ JD
Technical Details
Message-ID: <40d37932$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!colt.net!peernews3.colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <opr9pzs4ic2nqexn@lightyear> <40d15a23$1@newsgroups.borland.com> <opr9ric4112nqexn@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.146.77.122     
References: <opr9pzs4ic2nqexn@lightyear> <40d15a23$1@newsgroups.borland.com> <opr9ric4112nqexn@lightyear>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <40d37932$1@newsgroups.borland.com>
Date: 18 Jun 2004 16:22:26 -0700
X-Trace: newsgroups.borland.com 1087600946 207.105.83.66 (18 Jun 2004 16:22:26 -0700)
Lines: 44
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed.icl.net!colt.net!peernews3.colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail