Einzelnen Beitrag anzeigen

TiGü

Registriert seit: 6. Apr 2011
Ort: Berlin
3.062 Beiträge
 
Delphi 10.4 Sydney
 
#10

AW: SHChangeNotifyRegister Event

  Alt 11. Mai 2017, 09:09
Ganz gute Infoquelle: https://www.codeproject.com/Articles...he-Recycle-Bin

Und hiermit funktioniert es.
Das heißt, dass der MessageHandler für WM_SHELLNOTIFY getriggert wird und der LPARAM sagt was passiert ist.
Musste natürlich noch auf NonVCL stricken...LOL!

Delphi-Quellcode:
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Classes,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,
  Winapi.ShlObj;

const
  SHCNF_ACCEPT_INTERRUPTS = $0001;
  SHCNF_ACCEPT_NON_INTERRUPTS = $0002;

  WM_SHELLNOTIFY = WM_USER + 5;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
  public
    procedure WMShellNotify(var Message: TMessage); message WM_SHELLNOTIFY;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  hr: HRESULT;
  hNotifyRBin: ULONG;
  pidlRecycleBin: PItemIDList;
  stPIDL: TSHChangeNotifyEntry;
  MainHandle: HWND;
begin
  MainHandle := Self.Handle;

  hr := SHGetSpecialFolderLocation(MainHandle, CSIDL_BITBUCKET, pidlRecycleBin);

  if Succeeded(hr) then
  begin
    stPIDL.pidl := pidlRecycleBin;
    stPIDL.fRecursive := True;

    hNotifyRBin := SHChangeNotifyRegister(
      MainHandle,
      SHCNF_ACCEPT_INTERRUPTS or SHCNF_ACCEPT_NON_INTERRUPTS,
      SHCNE_ALLEVENTS,
      WM_SHELLNOTIFY, // Message that would be sent by the Shell
      1, stPIDL);

    if 0 = hNotifyRBin then
    begin
      RaiseLastOSError(GetLastError, 'Change Register Failed for RecycleBin');
    end;
  end
  else
    RaiseLastOSError;
end;

procedure TForm1.WMShellNotify(var Message: TMessage);
begin
  case Message.LParam of
    SHCNE_RENAMEITEM, // 0x00000001L
    SHCNE_CREATE, // 0x00000002L
    SHCNE_DELETE, // 0x00000004L
    SHCNE_MKDIR, // 0x00000008L
    SHCNE_RMDIR, // 0x00000010L
    SHCNE_MEDIAINSERTED, // 0x00000020L
    SHCNE_MEDIAREMOVED, // 0x00000040L
    SHCNE_DRIVEREMOVED, // 0x00000080L
    SHCNE_DRIVEADD, // 0x00000100L
    SHCNE_NETSHARE, // 0x00000200L
    SHCNE_NETUNSHARE, // 0x00000400L
    SHCNE_ATTRIBUTES, // 0x00000800L
    SHCNE_UPDATEDIR, // 0x00001000L
    SHCNE_UPDATEITEM, // 0x00002000L
    SHCNE_SERVERDISCONNECT, // 0x00004000L
    SHCNE_UPDATEIMAGE, // 0x00008000L
    SHCNE_DRIVEADDGUI, // 0x00010000L
    SHCNE_RENAMEFOLDER, // 0x00020000L
    SHCNE_FREESPACE: // 0x00040000L
      begin
        ShowMessage(IntToStr(Message.LParam));
      end;
  end;
end;

end.
  Mit Zitat antworten Zitat