unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,ShellAPI;
type
TForm1 = class(TForm)
Button1: TButton;
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;
i: char;
Begin
Case Msg.WParam Of
32768: Begin
ShowMessage('U盘插入');
For i := 'D' To 'Z' Do
If GetDriveType(PChar(i + ':"')) = DRIVE_REMOVABLE Then Begin
ShellExecute(Handle, 'open', 'Explorer.exe', PChar(i + ':"'), Nil, SW_SHOWNORMAL);
End;
End;
32772: Begin
ShowMessage('U盘退出')
End;
End;
End;
end.
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交