1. Home
  2. Computing & Technology
  3. Delphi Programming

Programmatically Empty Windows Recycle Bin from Delphi

By Zarko Gajic, About.com

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
Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2001 Delphi Tips
  7. Programmatically Empty Windows Recycle Bin from Delphi

©2009 About.com, a part of The New York Times Company.

All rights reserved.