如何检测计算机中刚插入的移动硬盘和U盘。(100分)

  • 主题发起人 主题发起人 wv990
  • 开始时间 开始时间
W

wv990

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,最好能提供代码示例一下。
 
去WWW.2CCC.COM 下一个闪盘小偷”DELPHI版"就知道了,就是捕获特殊的系统消息
 
其实不难
只要定义一个数据结构
调用一个函数
再定义一个消息处理过程就可以了
 
给段别人的代码给你
unit usb;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure WMDeviceChange(var Message: TMessage);
message WM_DEVICECHANGE;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
const DBT_DEVICEARRIVAL = $8000;
const DBT_DEVICEQUERYREMOVE = $8001;
const DBT_DEVICEQUERYREMOVEFAILED = $8002;
const DBT_DEVICEREMOVEPENDING = $8003;
const DBT_DEVICEREMOVECOMPLETE = $8004;
const DBT_DEVICETYPESPECIFIC = $8005;
const DBT_CONFIGCHANGED = $0018;

procedure TForm1.WMDeviceChange(var Message: TMessage);
var
s : string;
begin
{Do Something here}
case Message.WParam of
DBT_DEVICEARRIVAL :
s := 'A device has been inserted and is now available';
DBT_DEVICEQUERYREMOVE:
begin
s := 'Permission to remove a device is requested';
ShowMessage(s); {True grants premission}
Message.Result := integer(true);
exit;
end;
DBT_DEVICEQUERYREMOVEFAILED :
s := 'Request to remove a device has been canceled';
DBT_DEVICEREMOVEPENDING :
s := 'Device is about to be removed';
DBT_DEVICEREMOVECOMPLETE :
s := 'Device has been removed';
DBT_DEVICETYPESPECIFIC :
s := 'Device-specific event';
DBT_CONFIGCHANGED :
s:= 'Current configuration has changed'
else s := 'Unknown Device Message';
end;
ShowMessage(s);
inherited;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(inttostr(GetTickCount));
end;
论坛上很多人讨论过了,可以自己看看
 
闪盘小偷 用于U盘好像是可以得,不过移动硬盘不行
 
接受答案了.
 
后退
顶部