在双光驱的情况下,如何得知道当前弹出/关闭的是哪个光驱?(50分)

  • 主题发起人 主题发起人 Vision
  • 开始时间 开始时间
V

Vision

Unregistered / Unconfirmed
GUEST, unregistred user!
在双光驱的情况下,如何得知道当前弹出/关闭的是哪个光驱?
 
看这段代码,可以弹出不同的光驱。
uses mmSysTem;

procedure CDRomOpen(bOpenDrive: Boolean; cDrive: Char);
var
o: MCI_OPEN_PARMS;
status: MCI_STATUS_PARMS;
flags: DWord;
szDriveName: array[0..3] of Char;
begin
szDriveName := '?:';
ZeroMemory(@o, SizeOf(MCI_OPEN_PARMS));
szDriveName[0] := cDrive;

o.lpstrDeviceType := PChar(MCI_DEVTYPE_CD_AUDIO);
o.lpstrElementName := szDriveName;
flags := MCI_OPEN_TYPE or MCI_OPEN_TYPE_ID or MCI_OPEN_ELEMENT or MCI_OPEN_SHAREABLE;
if mciSendCommand(0, MCI_OPEN, flags, Cardinal(@o)) = 0 then
begin
status.dwItem := MCI_STATUS_READY;

if bOpenDrive then
mciSendCommand(o.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0)
else
mciSendCommand(o.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);

mciSendCommand(o.wDeviceID, MCI_CLOSE, MCI_WAIT, 0);
end;
end;
 
这是不跟判断当前是那个盘符是一样的吗?
 
嘿嘿,我想知道的是在程序里如何知道哪个光驱的门被弹出来了,而不是如何控制它
unit MainUnit;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;
...
const
...
type
TMainForm = class(TForm)
...
private
procedure WMDeviceChange(var Msg:TMessage);message WM_DEVICECHANGE;
public
{ Public declarations }
end;

var
MainForm: TMainForm;
implementation
...
procedure TMainForm.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_QUERYCHANGECONFIG :;
DBT_CONFIGCHANGED :;
DBT_CONFIGCHANGECANCELED :;
DBT_DEVICEARRIVAL :
DBT_DEVICEQUERYREMOVE :;
DBT_DEVICEQUERYREMOVEFAILED :;
DBT_DEVICEREMOVEPENDING :;
DBT_DEVICEREMOVECOMPLETE :
DBT_DEVICETYPESPECIFIC :;
DBT_USERDEFINED :;
end;
..在此可以知道光盘是否有更换过,但如何通消息知道是哪个光驱被换过?.
Msg.WParam
msg.LParam
msg.Result
msg.WParamLo
msg.WParamHi
msg.LParamLo
msg.LParamHi
msg.ResultLo
msg.ResultHi
里都有些什么东东??
 
这个问题都放了这么久了,没人愿意指教吗?
 
刚才的一部分测试数据,没有实质性结果,但是是一部分,可供参考

type
PDEV_BROADCAST_HDR = ^TDEV_BROADCAST_HDR;
TDEV_BROADCAST_HDR = record
dbch_size: ULONG;
dbch_devicetype: ULONG;
dbch_reserved: ULONG;
end;

var
a: PDEV_BROADCAST_HDR;

a := PDEV_BROADCAST_HDR(Msg.LParam);
ListBox1.Items.Add(InttoStr(a.dbch_size));
ListBox1.Items.Add(InttoStr(a.dbch_devicetype));
ListBox1.Items.Add(InttoStr(a.dbch_reserved));
 
to: yzhshi

试试
 
后退
顶部