转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 软件开发 >> Delphi程序 >> 正文
監視資源管理器的文件變化         ★★★★

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

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1511 更新时间:2009/4/23 18:25:46

我的主页:http://www.tommstudio.com/



unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, shlobj, activex, StdCtrls, FileCtrl,strUtils;

const
shcne_renameitem = $1;
shcne_create = $2;
shcne_delete = $4;
shcne_mkdir = $8;
shcne_rmdir = $10;
shcne_mediainserted = $20;
shcne_mediaremoved = $40;
shcne_driveremoved = $80;
shcne_driveadd = $100;
shcne_netshare = $200;
shcne_netunshare = $400;
shcne_attributes = $800;
shcne_updatedir = $1000;
shcne_updateitem = $2000;
shcne_serverdisconnect = $4000;
shcne_updateimage = $8000;
shcne_driveaddgui = $10000;
shcne_renamefolder = $20000;
shcne_freespace = $40000;
shcne_assocchanged = $8000000;
shcne_diskevents = $2381F;
shcne_globalevents = $C0581E0;
shcne_allevents = $7FFFFFFF;
shcne_interrupt = $80000000;

shcnf_idlist = 0; //  lpitemidlist
  shcnf_patha = $1; // path name
  shcnf_printera = $2; // printer friendly name
  shcnf_dword = $3; // dword
  shcnf_pathw = $5; // path name
  shcnf_printerw = $6; // printer friendly name
  shcnf_type = $FF;

shcnf_flush = $1000;

shcnf_flushnowait = $2000;
shcnf_path = shcnf_pathw;
shcnf_printer = shcnf_printerw;

wm_shnotify = $401;
noerror = 0;


type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
DirectoryListBox1: TDirectoryListBox;
DriveComboBox1: TDriveComboBox;
Label1: TLabel;
Button2: TButton;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
procedure wmshellreg(var message: tmessage); message wm_shnotify;

public
{ Public declarations }
end;

type pshnotifystruct = ^shnotifystruct;
shnotifystruct = record
dwitem1: pitemidlist;
dwitem2: pitemidlist;
end;

type pshfileinfobyte = ^shfileinfobyte;
_shfileinfobyte = record
hicon: integer;
iicon: 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 := ''''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
      

[1] [2]  下一页


没有相关教程
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · C语言系列  · VB.NET程序
    · JAVA开发  · Delphi程序
    · 脚本语言
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台