sobota, 23 grudnia 2017

Status CD Drive (class C++ Builder)

#include <mmsystem.h>
#include <ExtCtrls.hpp>
#include <FileCtrl.hpp>

class state_CD
{
private:

MCI_OPEN_PARMS cd_Parameters;
MCI_STATUS_PARMS cd_State;

int sent_Value;
UnicodeString cD;
public:

state_CD()
{

 cD="CDAudio";
 cd_Parameters.dwCallback=0;
 cd_Parameters.lpstrDeviceType=cD.w_str();

}
int read_Value(UnicodeString type_CD)
{

 cd_Parameters.lpstrElementName=type_CD.w_str();
 mciSendCommand(0,MCI_OPEN,MCI_OPEN_ELEMENT | MCI_OPEN_TYPE,(long)&cd_Parameters);
 cd_State.dwItem=MCI_STATUS_MODE;
 mciSendCommand(cd_Parameters.wDeviceID,MCI_STATUS,MCI_WAIT | MCI_STATUS_ITEM,(long)&cd_State);
 sent_Value=cd_State.dwReturn;
 mciSendCommand(cd_Parameters.wDeviceID,MCI_CLOSE,MCI_NOTIFY,(long)&cd_Parameters);
 return sent_Value;

}
void write_ListBox(TDriveComboBox *tDCB,TListBox *tLB)
{
UnicodeString test_Value;
test_Value=UnicodeString(tDCB->Drive+":");
if(read_Value(test_Value)==526)
 tLB->Items->Add("Playing");
else if(read_Value(test_Value)==525)
 tLB->Items->Add("Pause");
else if(read_Value(test_Value)==530)
 tLB->Items->Add("No CD");
else if(read_Value(test_Value)==1242732)
 tLB->Items->Add("No CD Drive");
else if(read_Value(test_Value)==1242348)
 tLB->Items->Add("Symbol is not CD Drive");
else
 tLB->Items->Add("Default operation: "+IntToStr(read_Value((UnicodeString)tDCB->Drive+":")));

    }
};

And example: 

void __fastcall TForm1::Button1Click(TObject *Sender)
{
 state_CD test_CD;
 test_CD.write_ListBox(DriveComboBox1,ListBox1);

}

Brak komentarzy:

Prześlij komentarz