:Integer;
dwAttributes : Integer;
szDisplayName : array [0..259] of char;
szTypeName : array [0..79] of char;
end;
SHFileInfoByte=_SHFileInfoByte;
Type PIDLSTRUCT = ^IDLSTRUCT;
_IDLSTRUCT = record
pidl : PItemIDList;
bWatchSubFolders : Integer;
end;
IDLSTRUCT =_IDLSTRUCT;
function SHNotify_Register(hWnd : Integer) : Bool;
function SHNotify_UnRegister:Bool;
function SHEventName(strPath1,strPath2:string;lParam:Integer):string;
Function SHChangeNotifyDeregister(hNotify:integer):integer;stdcall;
external ''Shell32.dll'' index 4;
Function SHChangeNotifyRegister(hWnd,uFlags,dwEventID,uMSG,cItems:LongWord;
lpps:PIDLSTRUCT):integer;stdcall;external ''Shell32.dll'' index 2;
Function SHGetFileInfoPidl(pidl : PItemIDList;
dwFileAttributes : Integer;
psfib : PSHFILEINFOBYTE;
cbFileInfo : Integer;
uFlags : Integer):Integer;stdcall;
external ''Shell32.dll'' name ''SHGetFileInfoA'';
var
Form1: TForm1;
m_hSHNotify:Integer;
m_pidlDesktop : PItemIDList;
implementation
{$R *.DFM}
function SHEventName(strPath1,strPath2:string;lParam:Integer):string;
var
sEvent:String;
begin
case lParam of //根据参数设置提示消息
SHCNE_RENAMEITEM: sEvent := ''重命名文件''+strPath1+''为''+strpath2;
SHCNE_CREATE: sEvent := ''建立文件 文件名:''+strPath1;
SHCNE_DELETE: sEvent := ''删除文件 文件名:''+strPath1;
SHCNE_MKDIR: sEvent := ''新建目录 目录名:''+strPath1;
SHCNE_RMDIR: sEvent := ''删除目录 目录名:''+strPath1;
SHCNE_MEDIAINSERTED: sEvent := strPath1+''中插入可移动存储介质'';
SHCNE_MEDIAREMOVED: sEvent := strPath1+''中移去可移动存储介质''+strPath1+'' ''+strpath2;
SHCNE_DRIVEREMOVED: sEvent := ''移去驱动器''+strPath1;
SHCNE_DRIVEADD: sEvent := ''添加驱动器''+strPath1;
SHCNE_NETSHARE: sEvent := ''改变目录''+strPath1+''的共享属性'';
SHCNE_ATTRIBUTES: sEvent := ''改变文件目录属性 文件名''+strPath1;
SHCNE_UPDATEDIR: sEvent := ''更新目录''+strPath1;
SHCNE_UPDATEITEM: sEvent := ''更新文件 文件名:''+strPath1;
SHCNE_SERVERDISCONNECT: sEvent := ''断开与服务器的连接''+strPath1+'' ''+strpath2;
SHCNE_UPDATEIMAGE: sEvent := ''SHCNE_UPDATEIMAGE'';
SHCNE_DRIVEADDGUI: sEvent := ''SHCNE_DRIVEADDGUI'';
SHCNE_RENAMEFOLDER: sEvent := ''重命名文件夹''+strPath1+''为''+strpath2;
SHCNE_FREESPACE: sEvent := ''磁盘空间大小改变'';
SHCNE_ASSOCCHANGED: sEvent := ''改变文件关联'';
else
sEvent:=''未知操作''+IntToStr(lParam);
end;
Result:=sEvent;
end;
function SHNotify_Register(hWnd : Integer) : Bool;
var
ps:PIDLSTRUCT;
begin
{$R-}
Result:=False;
If m_hSHNotify = 0 then begin
//获取桌面文件夹的Pidl
if SHGetSpecialFolderLocation(0, CSIDL_DESKTOP,
m_pidlDesktop)<> NOERROR then
Form1.close;
if Boolean(m_pidlDesktop) then begin
ps.bWatchSubFolders := 1;
ps.pidl := m_pidlDesktop;
// 利用SHChangeNotifyRegister函数
注册系统消息处理
m_hSHNotify := SHChangeNotifyReg