Delphi捕获U盘插入或者拔出


本文整理自网络,侵删。

 Delphi捕获U盘插入或者拔出
在USB端口被热插后,系统会向所有程序发布WM_DEVICECHANGE消息,所以只要捕获此消息即可实现对U盘的监视。
1、新建工程;
2、在form1上放一个Label;
3、定义一个私有过程 procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;

引用
unit   Unit1;
  
interface
  
uses
      Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,
      Dialogs,   AppEvnts,   ExtCtrls,   StdCtrls;
  
type
      TForm1   =   class(TForm)
          Label1:   TLabel;
      private
          {   Private   declarations   }
          procedure   WMDeviceChange(var   Msg:   TMessage);   message   WM_DEVICECHANGE;
      public
          {   Public   declarations   }
      end;
  
var
      Form1:   TForm1;
  
implementation
  
{$R   *.dfm}
  
procedure   TForm1.WMDeviceChange   (var   Msg:   TMessage);
var
      myMsg   :   String;
begin
      Case   Msg.WParam   of
      32768:
          begin
              myMsg   :='U盘插入';
              Label1.Caption:=myMsg
          end;
      32772:
          begin
              myMsg   :='U盘拔出';
              Label1.Caption:=myMsg;
          end;
      end;
end;
  
end.

相关阅读 >>

Delphi 将鼠标锁定在一定范围

Delphi双击tmemo选择光标所在行

Delphi 自我复制源码

Delphi 62 进制的简单实现

Delphi 62进制转10进制

Delphi getwindowhandle

Delphi中获取guid的函数

Delphi listview的用法

Delphi 读取文件的md5值

Delphi xe5 重启 关闭 windows 8

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...

    正在狠努力加载,请稍候...