手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>delphi>列表

監視資源管理器的文件變化

来源:互联网 作者:西部数码 时间:2008-04-09
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!

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 := ''''rename'''' 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
new(ps);
try
ps.bwatchsubfolders := 1;
ps.pidl := m_pidldesktop;

// 利用shchangenotifyregister函数注册系统消息处理
m_hshnotify := shchangenotifyregister(hwnd, (shcnf_type or shcnf_idlist),
(shcne_allevents or shcne_interrupt),
wm_shnotify, 1, ps);
result := boolean(m_hshnotify);
finally
FreeMem(ps);
end;
end
else
// 如果出现错误就使用 cotaskmemfree函数来释放句柄
cotaskmemfree(m_pidldesktop);
end;
{$R }
end;

function shnotify_unregister: bool;
begin
result := false;
if boolean(m_hshnotify) then
//取消系统消息监视,同时释放桌面的pidl
if boolean(shchangenotifyderegister(m_hshnotify)) then begin
{$R-}
m_hshnotify := 0;
cotaskmemfree(m_pidldesktop);

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!