打印本文 打印本文 关闭窗口 关闭窗口
監視資源管理器的文件變化
作者:武汉SEO闵涛  文章来源:敏韬网  点击数1956  更新时间:2009/4/23 18:25:46  文章录入:mintao  责任编辑:mintao
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);
      result := true;
      {$R-}
    end;
  end;
  
  procedure tform1.wmshellreg(var message: tmessage); //系统消息处理函数
var
  strpath1, strpath2: string;
  charpath: array[0..259] of char;
  pidlitem: pshnotifystruct;
  vPath,vFile:string;
  begin
    pidlitem := pshnotifystruct(message.wparam);
    //  获得系统消息相关得路径
  shgetpathfromidlist(pidlitem.dwitem1, charpath);
    strpath1 := charpath;
    shgetpathfromidlist(pidlitem.dwitem2, charpath);
    strpath2 := charpath;
    vPath:=ExtractFilePath(strPath1);
    vFile:=ExtractFileName(strPath1);
    if (message.lparam=shcne_create) and (vPath=(Label1.Caption+''''\'''')) then
    begin
      // memo1.lines.add(sheventname(strpath1, strpath2, message.lparam) + chr(13) + chr(10));
    if not AnsiContainsText(Memo1.Lines.Text,vFile) then
      memo1.lines.add(vFile);
    end;
  end;
  
  
  procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
  begin
    //在程序退出的同时删除监视
  if boolean(m_pidldesktop) then
    shnotify_unregister;
    
  end;
  
  procedure TForm1.Button1Click(Sender: TObject);
  begin
    Memo1.Clear;
    m_hshnotify := 0;
    if shnotify_register(form1.handle) then begin //注册shell监视
    showmessage(''''shell监视程序成功注册'''');
      button1.enabled := false;
    end
    else
    showmessage(''''shell监视程序注册失败'''');
    
  end;
  
  procedure TForm1.Button2Click(Sender: TObject);
  var
  i:integer;
  begin
    i:=Memo1.Lines.IndexOf(Memo1.SelText);
    Memo1.Lines.Delete(i);
  end;
  
end.



上一页  [1] [2] 

打印本文 打印本文 关闭窗口 关闭窗口