?
Solved

knowing if CD is inside the tray

Posted on 2002-03-05
15
Medium Priority
?
273 Views
Last Modified: 2012-05-04
How will i know if there is a CD inside the cdtray?
0
Comment
Question by:ryan_sabarre
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
  • +5
15 Comments
 

Author Comment

by:ryan_sabarre
ID: 6843096
help me please
0
 

Author Comment

by:ryan_sabarre
ID: 6843197
points was already increased, anybody can help me please
0
 

Expert Comment

by:ePing
ID: 6843223
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure WMDEVICECHANGE(var msg: TMessage); message WM_DEVICECHANGE;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.WMDEVICECHANGE(var msg:tmessage);
const
  DBT_DEVICEARRIVAL = $8000;
  DBT_DEVICEMOVECOMPLETE = $8004;
var
  TempStr: string;
begin
  inherited;
  case msg.WParam of
    DBT_DEVICEARRIVAL :tempstr:='Insert CD';
    DBT_DEVICEMOVECOMPLETE :tempstr:='Popup CD';
  end;
  ShowMessage(TempStr);
end;


ePing :o)

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ryan_sabarre
ID: 6843256
sorry your source code does not do anything
it doest work

please stick to my question please
0
 

Author Comment

by:ryan_sabarre
ID: 6843261
there are 2 cd rom drives in my computer
drive f and drive G

so how can i identify both drive if there is a CD existing inside?
0
 

Accepted Solution

by:
d32coder earned 150 total points
ID: 6843297
A low tech solution.  
It will not work on blank or Audio CDs.

if DirectoryExists('F:\')
  then Showmessage('CD Found in Drive F.');

Don
0
 

Expert Comment

by:pin_plunder
ID: 6843356
 var
    DrivePath: array [0..3] of char = 'A:\';

  function IsDiskIn(drive: char): boolean;
  var
    d1, d2, d3, d4: longword;
  begin
    DrivePath[0] := drive;
    Result := GetDiskFreeSpace(DrivePath, d1, d2, d3, d4);
  end;

this may be another solution without getting those blue error messages.
0
 
LVL 34

Expert Comment

by:Slick812
ID: 6843547
var
FatType: array [0..MAX_PATH] of Char;
MaxLen1,fSysFlags: DWORD;
ErrorMode: Integer;
Drive: String;

begin
FatType[0] := #0;
Drive := 'F:\';
ErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);
if not GetVolumeInformation(PChar(Drive), nil, 0,nil, MaxLen1, fSysFlags,FatType,DWORD(sizeof(FatType))) then
  begin
  ShowMessage('No CD in drive');
  end else
  ShowMessage('CD is in there');
SetErrorMode(ErrorMode);
end;

- - - - - - - - - - -  - - - - - -
GetVolumeInformation returns False if there is no volume to get info for
0
 

Author Comment

by:ryan_sabarre
ID: 6843616
hey "d32code" is your code safe?
i already try it with windows 2000 its ok
but in other Operating system i dont know
like WindowsXP/NT/Windows 98

anybody can say something with his code?
0
 

Expert Comment

by:pin_plunder
ID: 6846181
with d32code code you get a blue error screen when there's a blank or audio cd.
sorry d32code but let me say that's not too elegant.

paul.
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6846419
{ ... }
type
  TForm1 = class(TForm)
  private
    { private declarations }
    procedure WMDeviceChange(var Msg: TMessage); message WM_DeviceChange;
  public
    { public declarations }
  end;


procedure TForm1.WMDeviceChange(var Msg: TMessage);
const
  DBT_QUERYCHANGECONFIG = $0017;
  DBT_CONFIGCHANGED = $0018;
  DBT_CONFIGCHANGECANCELED = $0019;
  DBT_DEVICEARRIVAL = $8000;
  DBT_DEVICEQUERYREMOVE = $8001;
  DBT_DEVICEQUERYREMOVEFAILED = $8002;
  DBT_DEVICEREMOVEPENDING = $8003;
  DBT_DEVICEREMOVECOMPLETE = $8004;
  DBT_DEVICETYPESPECIFIC = $8005;
  DBT_USERDEFINED = $FFFF;
var
  tmpStr : String;
begin
  inherited
  case Msg.wParam of
    DBT_DEVICEARRIVAL:
      tmpStr := 'CD inserted in drive';
    DBT_DEVICEREMOVECOMPLETE:
      tmpSTr := 'CD removed from drive';
  end;
  ShowMessage(tmpStr);
end;
0
 
LVL 34

Expert Comment

by:Slick812
ID: 6851809
if you are still looking, here's a couple of web pages at Borland Community

Is disk in drive?
http://community.borland.com/article/0,1410,18004,00.html
(I still like the GetVolumeInformation way better, since it does all types of CD's)

Is CD a Audio CD?
http://community.borland.com/article/0,1410,17756,00.html
0
 
LVL 3

Expert Comment

by:lopem
ID: 6853725
listening...
0
 
LVL 3

Expert Comment

by:SteveWaite
ID: 6866371
have you tried:

Path := 'D:\'; // your cd etc.
if DirectoryExists(Path) then ..

You may need to repeat after a time because the cd may have just been inserted and Explorer hasn't picked it up yet.

Regards,
Steve
0
 

Author Comment

by:ryan_sabarre
ID: 6878815
Thank you for your idea
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month10 days, 23 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question