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] |