* * *

Author Topic: How To Form OnNotifyEvent TMessage Parse For Change Directory and Files  (Read 530 times)

samurat2000

  • Newbie
  • Posts: 2
procedure TForm1.OnNotifyEvent(var AMessage: TMessage);
begin
   ....
   ....
end;

In above code, how to TMessage parse to detail change directory and files.

ASerge

  • Sr. Member
  • ****
  • Posts: 280
You mean cross-platform behavior like Windows.FindFirstChangeNotification?

samurat2000

  • Newbie
  • Posts: 2
http://stackoverflow.com/questions/31168116/how-to-get-notified-when-disk-free-space-changes

In this link code below.

Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7.   Dialogs, ShlObj, ActiveX;
  8.  
  9. const
  10.  
  11.   SHCNRF_INTERRUPTLEVEL     = $0001;
  12.   SHCNRF_SHELLLEVEL         = $0002;
  13.   SHCNRF_RECURSIVEINTERRUPT = $1000;
  14.   SHCNRF_NEWDELIVERY        = $8000;
  15.  
  16. type
  17.   TSHChangeNotifyEntry = record
  18.     pidl: PItemIdList;
  19.     fRecursive: BOOL;
  20.   end;
  21.  
  22.   TForm1 = class(TForm)
  23.     procedure FormCreate(Sender: TObject);
  24.     procedure FormDestroy(Sender: TObject);
  25.   private
  26.     procedure OnNotifyEvent(var AMessage:TMessage); message WM_USER;
  27.   end;
  28.  
  29. var
  30.   Form1: TForm1;
  31.   Hand: THandle;
  32.  
  33. function SHChangeNotifyRegister(OwnerHwnd:HWND; fSources:Integer; fEvents:DWord; wMsg:UINT;
  34.          cEntries:Integer; var pshcne:TSHChangeNotifyEntry):ULONG; stdcall; external 'shell32.dll';
  35.  
  36. function SHChangeNotifyDeregister(ulID:ULONG):BOOL; stdcall; external 'shell32.dll';
  37.  
  38. implementation
  39.  
  40. {$R *.dfm}
  41.  
  42. procedure TForm1.FormCreate(Sender: TObject);
  43. var Desktop:IShellFolder;
  44.     pidl:PItemIdList;
  45.     Path:String;
  46.     Eaten,attr,Events,Sources:DWord;
  47.     cnPIDL:TSHChangeNotifyEntry;
  48. begin
  49.  if Succeeded(SHGetDesktopFolder(Desktop)) then begin
  50.   Path:='D:\Test';
  51.   if Succeeded(Desktop.ParseDisplayName(0, nil, PWideChar(Path), Eaten, pidl, attr)) then begin
  52.    Caption:=Path;
  53.    cnPIDL.pidl:=pidl;
  54.    cnPIDL.fRecursive:=true;
  55.    Sources:=SHCNRF_INTERRUPTLEVEL or SHCNRF_SHELLLEVEL or SHCNRF_NEWDELIVERY or SHCNRF_RECURSIVEINTERRUPT;
  56.    Events:=SHCNE_FREESPACE;
  57.    Hand:=SHChangeNotifyRegister(Handle, Sources, Events, WM_USER, 1, cnPIDL);;
  58.    CoTaskMemFree(pidl);
  59.   end;
  60.  end;
  61. end;
  62.  
  63. procedure TForm1.FormDestroy(Sender: TObject);
  64. begin
  65.  SHChangeNotifyDeregister(Hand);
  66. end;
  67.  
  68. procedure TForm1.OnNotifyEvent(var AMessage: TMessage);
  69. begin
  70.  if AMessage.Msg = WM_USER then Caption:=Caption+' x';
  71. end;
  72.  
  73. end.
  74.  

This procedure;

procedure TForm1.OnNotifyEvent(var AMessage: TMessage);
begin
 if AMessage.Msg = WM_USER then Caption:=Caption+' x';
end;

How to AMessage parse for change detail (folder change detail, file change detil ? which file (full path) and which change?

ASerge

  • Sr. Member
  • ****
  • Posts: 280
See Processing non-user messages in your window in http://wiki.lazarus.freepascal.org/Win32/64_Interface

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus