[|]光盘的弹入弹出会触发什么消息?

DEnzllWang 2003-10-10 09:41:02
是不是WM_DEVICECHANGE, 我用这个消息好像没有用.

...全文
86 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
pankun 2003-10-11
  • 打赏
  • 举报
回复
http://www.comprg.com.cn/wz048.htm
ly_liuyang 2003-10-11
  • 打赏
  • 举报
回复
就是那个

procedure TCDEvents.WndProc(var Msg: TMessage);
begin
if (Msg.Msg = WM_DEVICECHANGE) then begin
if FEnabled and (fNotifyMode = nmEvent) then
try
WMDeviceChange(TWMDeviceChange(Msg));
except
Application.HandleException(Self);
end
end
else
Msg.Result := DefWindowProc(FWindowHandle, Msg.Msg, Msg.wParam, Msg.lParam);
end;

function TCDEvents.GetFirstDriveLetter(unitmask : longint):char;
var DriveLetter : shortint;
begin
DriveLetter := Ord('A');
while (unitmask and 1)=0 do begin
unitmask := unitmask shr 1;
inc(DriveLetter);
end;
Result := Char(DriveLetter);
end;

procedure TCDEvents.WMDeviceChange(var Msg : TWMDeviceChange);
var lpdb : PDEV_BROADCAST_HDR;
lpdbv : PDEV_BROADCAST_VOLUME;
begin
(* received a wm_devicechange message *)
lpdb := PDEV_BROADCAST_HDR(Msg.dwData);
(* look at the event send together with the wm_devicechange message *)
case Msg.Event of
DBT_DEVICEARRIVAL : begin
if lpdb^.dbch_devicetype = DBT_DEVTYP_VOLUME then begin
lpdbv := PDEV_BROADCAST_VOLUME(Msg.dwData);
if (lpdbv^.dbcv_flags and DBTF_MEDIA) = 1 then
if Assigned(fAfterArrival) then
fAfterArrival(Self,
GetFirstDriveLetter(lpdbv^.dbcv_unitmask));
end;
end;
DBT_DEVICEREMOVECOMPLETE : begin
if lpdb^.dbch_devicetype = DBT_DEVTYP_VOLUME then begin
lpdbv := PDEV_BROADCAST_VOLUME(Msg.dwData);
if (lpdbv^.dbcv_flags and DBTF_MEDIA) = 1 then
if Assigned(fAfterRemove) then
fAfterRemove(Self,
GetFirstDriveLetter(lpdbv^.dbcv_unitmask));
end;
end;
end;
end;

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧