下面这个函数可以显示是否就绪。(From Borland)function DiskInDrive(Drive: Char): Boolean;
var ErrorMode: word;
begin
{ make it upper case }
if Drive in ['a'..'z'] then Dec(Drive, $20);
{ make sure it's a letter }
if not (Drive in ['A'..'Z']) then
raise EConvertError.Create('Not a valid drive ID');
{ turn off critical errors }
ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
try
{ drive 1 = a, 2 = b, 3 = c, etc. }
if DiskSize(Ord(Drive) - $40) = -1 then
Result := False
else
Result := True;
finally
{ restore old error mode }
SetErrorMode(ErrorMode);
end;
end;
var ErrorMode: word;
begin
{ make it upper case }
if Drive in ['a'..'z'] then Dec(Drive, $20);
{ make sure it's a letter }
if not (Drive in ['A'..'Z']) then
raise EConvertError.Create('Not a valid drive ID');
{ turn off critical errors }
ErrorMode := SetErrorMode(SEM_FailCriticalErrors);
try
{ drive 1 = a, 2 = b, 3 = c, etc. }
if DiskSize(Ord(Drive) - $40) = -1 then
Result := False
else
Result := True;
finally
{ restore old error mode }
SetErrorMode(ErrorMode);
end;
end;
begin
if Msg.wParam = DBT_DEVICEREMOVEPENDING then
// user has started to eject CD
// Tell Windows it's OK.
Msg.Result := True;
end; (*See also:
DBT_DEVICEARRIVAL
DBT_DEVICEREMOVECOMPLETE Where is DBT_DEVICEREMOVEPENDING defined? -- I can't find any hint
of this (except in the help files.....)
Sorry, seems that there isn't any declaration in Delphi. dbt_
constants are declared in dbt.h, in Delphi it would be: 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;
*)
MCI_SET_DOOR_OPEN
相信你能看出那一个是开那一个是关吧?
对暴雪:
程序怎么能收到wm_devicechange这个消息?
对飞鹰:
我看不出来,哪个是开,哪个是关啊?
对暴雪:
程序怎么能收到wm_devicechange这个消息?
对飞鹰:
我看不出来,哪个是开,哪个是关啊?
sendmessage(application.Handle,MCI_SET_DOOR_OPEN,0,0);
sendmessage(application.Handle,MCI_SET_DOOR_OPEN,0,0);
这好像是在控制光曲,而不是得到状态吧……
程序怎么能收到wm_devicechange这个消息?
shellapi单元里有两个消息函数,分别是打开,关闭cd们的,我不告诉你是什么函数
因为有些问题自己动手解决效果最好
往你明白
我说了。
以下是我的一个小程序
可以开关光驱的。但是,我见到一个程序,是console形式的。
肯定是对光驱门的开关情况作了判断,
怎么判断,如果用汇编,我有用dos的,但没有win32下的汇编资料。
所以才向你们求教的!
蚂蚁真可爱的啊!以后得多多求救向你了。。
以下是我的小程序,用delphi6编绎后只有10.5K的。如果用delphi5.0,可能约18K以后吧!program MyApp;uses Windows,
Messages,
mmsystem,shellapi;
// {$r eject.res} //编绎图标资源可执行文件大了2.5Kvar
MSG: TMsg;
W : hWnd;
b:bool;
pt:tpoint;
pm:hmenu;
WC : TWndClass;
IconData : TNotifyIconData;
procedure change; //开关光驱的动作
begin
if b=true then
begin
mcisendstring('set cdaudio door open wait',nil,0,0); //左键出光
b:=false; //false 表示关!
end
else
begin
mcisendstring('set cdaudio door closed',0,0,0);//右键进驱
b:=true;
end;
end;
function AppWindowProc( wx:HWND; uMsg:UINT;
wParam1:WPARAM; lParam:LPARAM):LRESULT; stdcall; // 回调函数
begin
Result := 0;
case uMsg of
// wm_devicechange:messagebox(0,'设备己经改变','警告',mb_iconinformation);
WM_DESTROY: PostQuitMessage(0);
wm_command:case loword(wparam1) of
1:change;
2:messagebox(wx,'本软件版权归陈振剑所有!','警告',mb_ok);
3:messagebox(wx,'用鼠标来操纵光驱','听着',mb_ok);
4:postquitmessage(0);
end;
2222: case lparam of
wm_lbuttondown: change;
wm_rbuttondown:begin
getcursorpos(pt);
pm:=createpopupmenu;
appendmenu(pm,0,1,'开关');
appendmenu(pm,0,2,'关于');
appendmenu(pm,0,3,'提示');
appendmenu(pm,0,4,'退出');
trackpopupmenu(pm,
tpm_centeralign
,pt.X,pt.Y,0,wx,nil);
destroymenu(pm);
end;
wm_mbuttondown:// MCI_SET_DOOR_CLOSED;
begin end;
end; end; //与uMSG case相对应
Result := DefWindowProc(wx, uMsg, wParam1, lParam);
end;Procedure CreateWindow;
Begin
With WC do
Begin
lpfnWndProc := @appwindowProc;
lpszClassName := 'MyClass';
end;
RegisterClass(WC);
W := Windows.CreateWindow(wc.lpszclassname,
'MyWindow',
ws_OverlappedWindow,
100,100,300,300,0,0,hInstance,nil);
End;
Procedure AddTrayIcon;
Begin
With IconData do
Begin
cbSize := SizeOf(IconData);
Wnd := w;
uID := 2;
uFlags := nif_Icon Or nif_Message Or nif_Tip;
uCallBackMessage := 2222;
// hIcon :=loadicon(hinstance,'bird'); //使用鸟图标,文件大了2.5K
hicon:=loadicon(0, IDI_APPLICATION);
sztip:='左键单击弹出或收入光驱';
End;
Shell_NotifyIcon(nim_Add,@IconData);
End;begin // 程序从这里开始执行
if findwindow(nil,'mywindow')<>0 then //加上防止重复运行的语句将增加0.5K
begin messagebox(0,'本软件己运行','喂!',mb_ok);exit;end;
b:=true;//true代表关!
CreateWindow;
AddTrayIcon;
While GetMessage(Msg,0,0,0) do //消息循环
Begin
TranslateMessage(Msg);
DispatchMessage(Msg);
End;
Shell_NotifyIcon(nim_delete,@IconData); //删除图标
end.
SHChangeNotifyRegister注册接受该消息,包含了光驱打开关闭消息的。
mcisendstring('set cdaudio door open wait',nil,0,handle);
mcisendstring('set cdaudio door closed wait',nil,0,handle);
不过这只是控制cd-rom打开和关闭
mcisendstring('set cdaudio door open wait',nil,0,handle);
mcisendstring('set cdaudio door closed wait',nil,0,handle);
上面这位兄弟说得对。
至于检验嘛,你可以用:
mcisendstring('set cdaudio door closed wait',nil,0,handle);
就可以使光驱关闭。执行了以上语句就可以认为光驱关闭了