如题!

解决方案 »

  1.   

    http://www.google.cn/search?hl=zh-CN&newwindow=1&rlz=1C1GGLS_zh-CNCN292&q=u盘+拔插+消息+WM_DEVICECHANGE&btnG=Google+搜索&meta=&aq=f&oq=
      

  2.   

    unit Unit1;interfaceuses
       Windows,   Messages,   SysUtils,   Variants,   Classes,   Graphics,   Controls,   Forms,   
          Dialogs,   AppEvnts,   ExtCtrls,   StdCtrls;   
        
    type
      TForm1 = class(TForm)
        Label1: TLabel;
      private
         procedure   WMDeviceChange(var   Msg:   TMessage);   message   WM_DEVICECHANGE;    { Private declarations }
      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.
    在USB端口被热插后,系统会向所有程序发布WM_DEVICECHANGE消息,所以只要捕获此消息即可实现对U盘的监视。
      1、新建工程;   
      2、在form1上放一个Label;   
      3、定义一个私有过程 procedure   WMDeviceChange(var   Msg:   TMessage);   message   WM_DEVICECHANGE;