Форум: "Система";
Текущий архив: 2002.09.16;
Скачать: [xml.tar.bz2];
ВнизCd-rom Найти похожие ветки
← →
Чайник2 (2002-07-05 08:58) [0]Здравствуйте, а как узнать, что у меня есть сидюк и что он открыт?
← →
tamerlan311 (2002-07-05 11:45) [1]как отккыть или закрыть знаю :
mciSendString("Set cdaudio door closed wait", nil, 0, handle);
//закрыть
mciSendString("Set cdaudio door open wait", nil, 0, handle);
//открыть
а как узнать открыт он или закрыт , незнаю (сам ищу!)
← →
Севостьянов Игорь (2002-07-05 12:51) [2]Есть только понятие есть ли CD в CD-ROM
Понятие открыт он или нет не существует
(разве только на уровне железа)
Можно попробовать его закрыть или открыть и смотреть на
результат, если ошибка, то статус обратный
Что-то вроде
uses MMSystem...
...
function CheckCD(DiskNum: Integer): Integer;
const
cddbUnknown = 1;
cddbOK = 0;
cddbDriveInUse = -1;
cddbUnableToOpen = -2;
cddbMSFFormatUnavailable = -3;
cddbNoDiscInDrive = -4;
cddbNoTracks = -5;
cddbUnableToGetTracks = -6;
var
j: Integer;
lP : tMCI_OPEN_Parms;
lSP : tMCI_STATUS_Parms;
DevID : Integer;
lErr : mciError;
lIP : tMCI_INFO_Parms;
begin
Result := cddbUnknown;
// try to open
lP.lpstrDeviceType := pChar(MCI_DEVTYPE_CD_AUDIO + DiskNum shl 16);
lErr := mciSendCommand(MCI_DEVTYPE_CD_AUDIO, MCI_OPEN, MCI_WAIT + MCI_OPEN_TYPE + MCI_OPEN_TYPE_ID, Integer(@lP));
DevID := lP.wDeviceID;
if (lErr = 0) then
try
// check if CD inserted
lSP.dwItem := MCI_STATUS_MEDIA_PRESENT;
lErr := mciSendCommand(DevID, MCI_STATUS, MCI_WAIT + MCI_STATUS_ITEM, Integer(@lSP));
if (lErr = 0) and (lSP.dwReturn <> 0) then Result := cddbOK;
finally
mciSendCommand(DevID, MCI_CLOSE, MCI_WAIT, 0);
end
else
if (lErr = MCIERR_MUST_USE_SHAREABLE) then Result := cddbDriveInUse
else Result := cddbUnableToOpen;
end;
← →
LENIN INC (2002-07-05 12:55) [3]Проверить, открыт ли CD-привод можно и так:
uses
mmsystem;
procedure TForm1.Button1Click(Sender: TObject);
var
s: array[0..64] of Char;
error: Cardinal;
Text: array[0..255] of Char;
begin
error := mciSendstring("open cdaudio alias geraet", nil, 0, Handle);
if error <> 0 then
begin
mciGetErrorstring(error, @Text, 255);
ShowMessage(Text);
mciSendstring("close geraet", nil, 0, Handle);
Exit;
end;
error := mciSendstring("status geraet mode", @s, SizeOf(s), Handle);
if error <> 0 then
begin
mciGetErrorstring(error, @Text, 255);
ShowMessage(Text);
mciSendstring("close geraet", nil, 0, Handle);
Exit;
end;
mciSendstring("close geraet", nil, 0, Handle);
ShowMessage("Message: " + s);
end;
← →
Севостьянов Игорь (2002-07-05 15:47) [4]Брехня у меня Win2000 постоянно пишет, что он открыт независимо от состояния CD-ROM
Ну, а наличие CD в CD-ROM работает вот тут я уже не из глоловы брал, а проверил
unit Main;
interface
uses
Windows, SysUtils, Classes, Controls, Forms,
MMSystem, StdCtrls, MCI;
type
TfrmMain = class(TForm)
btnCheckCDROM: TButton;
procedure btnCheckCDROMClick(Sender: TObject);
end;
var
frmMain: TfrmMain;
implementation
{$R *.DFM}
procedure TfrmMain.btnCheckCDROMClick(Sender: TObject);
var
Result :Integer;
Error :mciError;
begin
Result := CheckCD(dtCDAudio, Error);
if Result = 0 then MessageBox(0, "В CD-ROM есть CD", "Сообщение", MB_OK)
else
begin
MessageBox(0, "В CD-ROM нет CD", "Сообщение", MB_OK);
if Error <> ERROR_SUCCESS then
MessageBox(0, GetErrorMgs(Error), PChar("Ошибка #"+IntTostr(Error)), MB_OK);
end;
end;
end.
продолжение следует...
← →
Севостьянов Игорь (2002-07-05 15:49) [5]
unit MCI;
interface
uses MMSystem;
type
TMPDeviceTypes = (dtAutoSelect, dtAVIVideo, dtCDAudio, dtDAT,
dtDigitalVideo, dtMMMovie, dtOther, dtOverlay,
dtScanner, dtSequencer, dtVCR, dtVideodisc, dtWaveAudio);
const
MCIERR_NONE_ERROR = 0;
cddbOK = 0;
cddbDriveInUse = -1;
cddbUnableToOpen = -2;
cddbMSFFormatUnavailable = -3;
cddbNoDiscInDrive = -4;
cddbNoTracks = -5;
cddbUnableToGetTracks = -6;
DeviceName: array[TMPDeviceTypes] of PChar =
("", "AVIVideo", "CDAudio", "DAT",
"DigitalVideo", "MMMovie", "Other",
"Overlay", "Scanner", "Sequencer",
"VCR", "Videodisc", "WaveAudio");
function CheckCD(MPDeviceType: TMPDeviceTypes; var Error: mciError): Integer;
function GetErrorMgs(Error: Integer): PChar;
implementation
function GetErrorMgs(Error: Integer): PChar;
begin
case Error of
MCIERR_NONE_ERROR : Result := "MCIERR_NONE_ERROR";
MCIERR_INVALID_DEVICE_ID : Result := "MCIERR_INVALID_DEVICE_ID";
MCIERR_UNRECOGNIZED_KEYWORD : Result := "MCIERR_UNRECOGNIZED_KEYWORD";
MCIERR_UNRECOGNIZED_COMMAND : Result := "MCIERR_UNRECOGNIZED_COMMAND";
MCIERR_HARDWARE : Result := "MCIERR_HARDWARE";
MCIERR_INVALID_DEVICE_NAME : Result := "MCIERR_INVALID_DEVICE_NAME";
MCIERR_OUT_OF_MEMORY : Result := "MCIERR_OUT_OF_MEMORY";
MCIERR_DEVICE_OPEN : Result := "MCIERR_DEVICE_OPEN";
MCIERR_CANNOT_LOAD_DRIVER : Result := "MCIERR_CANNOT_LOAD_DRIVER";
MCIERR_MISSING_COMMAND_STRING : Result := "MCIERR_MISSING_COMMAND_STRING";
MCIERR_PARAM_OVERFLOW : Result := "MCIERR_PARAM_OVERFLOW";
MCIERR_MISSING_STRING_ARGUMENT : Result := "MCIERR_MISSING_STRING_ARGUMENT";
MCIERR_BAD_INTEGER : Result := "MCIERR_BAD_INTEGER";
MCIERR_PARSER_INTERNAL : Result := "MCIERR_PARSER_INTERNAL";
MCIERR_DRIVER_INTERNAL : Result := "MCIERR_DRIVER_INTERNAL";
MCIERR_MISSING_PARAMETER : Result := "MCIERR_MISSING_PARAMETER";
MCIERR_UNSUPPORTED_FUNCTION : Result := "MCIERR_UNSUPPORTED_FUNCTION";
MCIERR_FILE_NOT_FOUND : Result := "MCIERR_FILE_NOT_FOUND";
MCIERR_DEVICE_NOT_READY : Result := "MCIERR_DEVICE_NOT_READY";
MCIERR_INTERNAL : Result := "MCIERR_INTERNAL";
MCIERR_DRIVER : Result := "MCIERR_DRIVER";
MCIERR_CANNOT_USE_ALL : Result := "MCIERR_CANNOT_USE_ALL";
MCIERR_MULTIPLE : Result := "MCIERR_MULTIPLE";
MCIERR_EXTENSION_NOT_FOUND : Result := "MCIERR_EXTENSION_NOT_FOUND";
MCIERR_OUTOFRANGE : Result := "MCIERR_OUTOFRANGE";
MCIERR_FLAGS_NOT_COMPATIBLE : Result := "MCIERR_FLAGS_NOT_COMPATIBLE";
MCIERR_FILE_NOT_SAVED : Result := "MCIERR_FILE_NOT_SAVED";
MCIERR_DEVICE_TYPE_REQUIRED : Result := "MCIERR_DEVICE_TYPE_REQUIRED";
MCIERR_DEVICE_LOCKED : Result := "MCIERR_DEVICE_LOCKED";
MCIERR_DUPLICATE_ALIAS : Result := "MCIERR_DUPLICATE_ALIAS";
MCIERR_BAD_CONSTANT : Result := "MCIERR_BAD_CONSTANT";
MCIERR_MUST_USE_SHAREABLE : Result := "MCIERR_MUST_USE_SHAREABLE";
MCIERR_MISSING_DEVICE_NAME : Result := "MCIERR_MISSING_DEVICE_NAME";
MCIERR_BAD_TIME_FORMAT : Result := "MCIERR_BAD_TIME_FORMAT";
MCIERR_NO_CLOSING_QUOTE : Result := "MCIERR_NO_CLOSING_QUOTE";
MCIERR_DUPLICATE_FLAGS : Result := "MCIERR_DUPLICATE_FLAGS";
MCIERR_INVALID_FILE : Result := "MCIERR_INVALID_FILE";
MCIERR_NULL_PARAMETER_BLOCK : Result := "MCIERR_NULL_PARAMETER_BLOCK";
MCIERR_UNNAMED_RESOURCE : Result := "MCIERR_UNNAMED_RESOURCE";
MCIERR_NEW_REQUIRES_ALIAS : Result := "MCIERR_NEW_REQUIRES_ALIAS";
MCIERR_NOTIFY_ON_AUTO_OPEN : Result := "MCIERR_NOTIFY_ON_AUTO_OPEN";
MCIERR_NO_ELEMENT_ALLOWED : Result := "MCIERR_NO_ELEMENT_ALLOWED";
MCIERR_NONAPPLICABLE_FUNCTION : Result := "MCIERR_NONAPPLICABLE_FUNCTION";
MCIERR_ILLEGAL_FOR_AUTO_OPEN : Result := "MCIERR_ILLEGAL_FOR_AUTO_OPEN";
MCIERR_FILENAME_REQUIRED : Result := "MCIERR_FILENAME_REQUIRED";
MCIERR_EXTRA_CHARACTERS : Result := "MCIERR_EXTRA_CHARACTERS";
MCIERR_DEVICE_NOT_INSTALLED : Result := "MCIERR_DEVICE_NOT_INSTALLED";
MCIERR_GET_CD : Result := "MCIERR_GET_CD";
MCIERR_SET_CD : Result := "MCIERR_SET_CD";
MCIERR_SET_DRIVE : Result := "MCIERR_SET_DRIVE";
MCIERR_DEVICE_LENGTH : Result := "MCIERR_DEVICE_LENGTH";
MCIERR_DEVICE_ORD_LENGTH : Result := "MCIERR_DEVICE_ORD_LENGTH";
MCIERR_NO_INTEGER : Result := "MCIERR_NO_INTEGER";
продолжение следует...
← →
Севостьянов Игорь (2002-07-05 15:50) [6]
MCIERR_WAVE_OUTPUTSINUSE : Result := "MCIERR_WAVE_OUTPUTSINUSE";
MCIERR_WAVE_SETOUTPUTINUSE : Result := "MCIERR_WAVE_SETOUTPUTINUSE";
MCIERR_WAVE_INPUTSINUSE : Result := "MCIERR_WAVE_INPUTSINUSE";
MCIERR_WAVE_SETINPUTINUSE : Result := "MCIERR_WAVE_SETINPUTINUSE";
MCIERR_WAVE_OUTPUTUNSPECIFIED : Result := "MCIERR_WAVE_OUTPUTUNSPECIFIED";
MCIERR_WAVE_INPUTUNSPECIFIED : Result := "MCIERR_WAVE_INPUTUNSPECIFIED";
MCIERR_WAVE_OUTPUTSUNSUITABLE : Result := "MCIERR_WAVE_OUTPUTSUNSUITABLE";
MCIERR_WAVE_SETOUTPUTUNSUITABLE : Result := "MCIERR_WAVE_SETOUTPUTUNSUITABLE";
MCIERR_WAVE_INPUTSUNSUITABLE : Result := "MCIERR_WAVE_INPUTSUNSUITABLE";
MCIERR_WAVE_SETINPUTUNSUITABLE : Result := "MCIERR_WAVE_SETINPUTUNSUITABLE";
MCIERR_SEQ_DIV_INCOMPATIBLE : Result := "MCIERR_SEQ_DIV_INCOMPATIBLE";
MCIERR_SEQ_PORT_INUSE : Result := "MCIERR_SEQ_PORT_INUSE";
MCIERR_SEQ_PORT_NONEXISTENT : Result := "MCIERR_SEQ_PORT_NONEXISTENT";
MCIERR_SEQ_PORT_MAPNODEVICE : Result := "MCIERR_SEQ_PORT_MAPNODEVICE";
MCIERR_SEQ_PORT_MISCERROR : Result := "MCIERR_SEQ_PORT_MISCERROR";
MCIERR_SEQ_TIMER : Result := "MCIERR_SEQ_TIMER";
MCIERR_SEQ_PORTUNSPECIFIED : Result := "MCIERR_SEQ_PORTUNSPECIFIED";
MCIERR_SEQ_NOMIDIPRESENT : Result := "MCIERR_SEQ_NOMIDIPRESENT";
MCIERR_NO_WINDOW : Result := "MCIERR_NO_WINDOW";
MCIERR_CREATEWINDOW : Result := "MCIERR_CREATEWINDOW";
MCIERR_FILE_READ : Result := "MCIERR_FILE_READ";
MCIERR_FILE_WRITE : Result := "MCIERR_FILE_WRITE";
MCIERR_NO_IDENTITY : Result := "MCIERR_NO_IDENTITY";
else Result := "UNKNOWN CUSTOM ERROR";
end;
end;
function CheckCD(MPDeviceType: TMPDeviceTypes; var Error: mciError): Integer;
var
MCIOpen :TMCI_OPEN_PARMS;
MCIStatus :TMCI_STATUS_PARMS;
DevID :Integer;
begin
//MCIOpen.lpstrDeviceType := pChar(MCI_DEVTYPE_CD_AUDIO + DiskNum shl 16);
//MCIOpen.lpstrElementName := "";
MCIOpen.lpstrDeviceType := DeviceName[MPDeviceType];
Error := mciSendCommand(MCI_DEVTYPE_CD_AUDIO,
MCI_OPEN, MCI_WAIT + MCI_OPEN_TYPE{ + MCI_OPEN_TYPE_ID},
Integer(@MCIOpen));
DevID := MCIOpen.wDeviceID;
if (Error = 0) then
try
MCIStatus.dwItem := MCI_STATUS_MEDIA_PRESENT;
Error := mciSendCommand(DevID, MCI_STATUS, MCI_WAIT + MCI_STATUS_ITEM, Integer(@MCIStatus));
if (Error = 0) and (MCIStatus.dwReturn <> 0) then Result := cddbOK
else Result := cddbNoDiscInDrive;
finally
mciSendCommand(DevID, MCI_CLOSE, MCI_WAIT, 0);
end
else
if (Error = MCIERR_MUST_USE_SHAREABLE) then Result := cddbDriveInUse
else Result := cddbUnableToOpen;
end;
end.
продолжение следует...
← →
Севостьянов Игорь (2002-07-05 15:52) [7]
program CheckCD;
uses
Forms,
Main in "Main.pas" {frmMain},
MCI in "MCI.pas";
{$R *.RES}
begin
Application.Initialize;
Application.CreateForm(TfrmMain, frmMain);
Application.Run;
end.
Теперь вроде все
Страницы: 1 вся ветка
Форум: "Система";
Текущий архив: 2002.09.16;
Скачать: [xml.tar.bz2];
Память: 0.48 MB
Время: 0.006 c