Parsi Coders
سورس کد خالی کردن سطل زباله (دلفی) - نسخه قابل چاپ

+- Parsi Coders (http://parsicoders.com)
+-- انجمن: Software Development Programming (http://parsicoders.com/forumdisplay.php?fid=37)
+--- انجمن: Pascal/Delphi (http://parsicoders.com/forumdisplay.php?fid=45)
+---- انجمن: Delphi (http://parsicoders.com/forumdisplay.php?fid=69)
+---- موضوع: سورس کد خالی کردن سطل زباله (دلفی) (/showthread.php?tid=2156)



سورس کد خالی کردن سطل زباله (دلفی) - Amin_Mansouri - 04-22-2012

کد:
function EmptyRecycleBin: Boolean;
const
  // Flags passed to SHEmptyRecycleBin
  SHERB_NOCONFIRMATION = $00000001;
  SHERB_NOPROGRESSUI = $00000002;
  SHERB_NOSOUND = $00000004;
  // DLL containing function
  cDLLName = 'Shell32.dll';
  // Function name
  cFnName = 'SHEmptyRecycleBinA';
type
  // Prototype of API function
  TSHEmptyRecycleBin = function(
    Wnd: Windows.HWND;
    pszRootPath: PChar;
    dwFlags: Windows.DWORD
  ): HRESULT; stdcall;
var
  SHEmptyRecycleBin: TSHEmptyRecycleBin;  // API function address
  DLLHandle: Windows.THandle;             // Handle of required DLL
begin
  // Assume failure
  Result := False;
  // Load required DLL
  DLLHandle := Windows.LoadLibrary(cDLLName);
  if DLLHandle <> 0 then
  begin
    try
      // Get reference of API function from DLL
      @SHEmptyRecycleBin := Windows.GetProcAddress(DLLHandle, cFnName);
      if Assigned(@SHEmptyRecycleBin) then
      begin
        // Try to empty recycle bin
        Result := Windows.Succeeded(
          SHEmptyRecycleBin(
            0,
            nil,
            SHERB_NOCONFIRMATION or SHERB_NOSOUND or SHERB_NOPROGRESSUI
          )
        );
      end;
    finally
      Windows.FreeLibrary(DLLHandle);
    end;
  end;
end;