1. Computing

Programmatically Empty Windows Recycle Bin from Delphi

From , former About.com Guide

Put a Button on Form1 and replace Unit1 code the following code:
 unit Unit1;
 
 interface
 
 uses
    Windows, Messages, SysUtils, Classes, Graphics, ShellApi,Controls, Forms,Dialogs,StdCtrls, ExtCtrls;
 type
    TForm1 = class(TForm)
      Button1: TButton;
      procedure Button1Click(Sender: TObject) ;
    end;
 
   var Form1: TForm1;
 
   function SHEmptyRecycleBin(Wnd:HWnd; LPCTSTR:PChar; DWORD:Word):Integer; stdcall;
 
   const
   SHERB_NOCONFIRMATION = $00000001;
   SHERB_NOPROGRESSUI = $00000002;
   SHERB_NOSOUND = $00000004;
 
   implementation {$R *.DFM}
 
   function SHEmptyRecycleBin; external 'SHELL32.DLL' name 'SHEmptyRecycleBinA';
 
   procedure TForm1.Button1Click(Sender: TObject) ;
   begin
    SHEmptyRecycleBin(self.handle,'', SHERB_NOCONFIRMATION) ;
   end;
 end.
 
Delphi tips navigator:
» ]Handle Event: CD in/out
« Programmatically Exit From Windows

©2013 About.com. All rights reserved.