Author Topic: Manipulating Recycle Bin  (Read 3435 times)

0 Members and 1 Guest are viewing this topic.

Offline Patrice Terrier

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2399
  • Gender: Male
    • www.zapsolution.com
Manipulating Recycle Bin
« on: November 24, 2008, 03:19:46 PM »
While working on OTB i needed to detect the RecycleBin status as to display the good icon (full or empty).

Hence a few functions to help RecycleBin manipulating.

Code: [Select]
%SHERB_NOCONFIRMATION    = &H00000001???
%SHERB_NOPROGRESSUI      = &H00000002???
%SHERB_NOSOUND           = &H00000004???

TYPE SHQUERYRBINFO
   cbSize      AS DWORD   ' DWORD   cbSize
   i64Size     AS QUAD    ' __int64 i64Size
   i64NumItems AS QUAD    ' __int64 i64NumItems
END TYPE

DECLARE FUNCTION SHQueryRecycleBin LIB "SHELL32.DLL" ALIAS "SHQueryRecycleBinA" ( _
   BYREF ASCIIZ _                             ' [in] LPCSTR pszRootPath
 , BYREF SHQUERYRBINFO _                      ' [in] LPSHQUERYRBINFO pSHQueryRBInfo
 ) AS LONG                                    ' HRESULT

DECLARE FUNCTION SHEmptyRecycleBin LIB "SHELL32.DLL" ALIAS "SHEmptyRecycleBinA" ( _
   BYVAL DWORD _                              ' [in] HWND hwnd
 , BYREF ASCIIZ _                             ' [in] LPCSTR pszRootPath
 , BYVAL DWORD _                              ' [in] DWORD dwFlags
 ) AS LONG                                    ' HRESULT

DECLARE FUNCTION SHUpdateRecycleBinIcon LIB "SHELL32.DLL" ALIAS "SHUpdateRecycleBinIcon" () AS LONG

FUNCTION GetRecycleBinCount() AS QUAD

   DIM SHQBI AS SHQUERYRBINFO

   SHQBI.cbSize = SIZEOF(SHQUERYRBINFO)
   CALL SHQueryRecycleBin("", SHQBI)

   FUNCTION = SHQBI.i64NumItems
   
END FUNCTION

FUNCTION PBMAIN
    LOCAL nCount AS LONG
    nCount = GetRecycleBinCount()
    MSGBOX str$(nCount)
   
    IF nCount THEN
       CALL SHEmptyRecycleBin(0, "", %SHERB_NOCONFIRMATION OR %SHERB_NOPROGRESSUI OR %SHERB_NOSOUND)
       CALL SHUpdateRecycleBinIcon()
    END IF
END FUNCTION
Patrice Terrier
GDImage (advanced graphic addon)
http://www.zapsolution.com