Kbase 21421: Use Win32 API SHFileOperationA to Send Files to Recycle Bin
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  18/10/2005 |
|
Status: Unverified
GOAL:
How to use the SHFileOperationA 32-Bit Windows API function call to send file(s) to the Recycle Bin from a 4GL program.
FACT(s) (Environment):
Windows 32 Intel
FIX:
This example demonstrates the SHFileOperationA functionality:
/* Recycle.p */
DEFINE VARIABLE mStruct AS MEMPTR NO-UNDO. /* SHFileOpStruct */
DEFINE VARIABLE mStrFrom AS MEMPTR NO-UNDO. /* pFrom */
DEFINE VARIABLE iReturn AS INTEGER NO-UNDO.
DEFINE VARIABLE iCount AS INTEGER NO-UNDO.
DEFINE VARIABLE iLength AS INTEGER NO-UNDO.
DEFINE VARIABLE cFilename AS CHARACTER NO-UNDO.
cFilename = 'c:\temp\runtimeParam.zip,' +
'c:\temp\runtimeExample.p,' +
'c:\temp\reports.prl,' +
'c:\temp\sports.lg'.
/* Initialize 'pFrom' structure */
SET-SIZE(mStrFrom) = LENGTH(cFilename) + (4 * NUM-ENTRIES(cFilename)).
/* Initialize SHFileOpStruct structure */
SET-SIZE(mStruct) = 28 + LENGTH(cFilename) + 5.
/* Place the filename(s) as a NULL separated list into the 'pFrom'
structure */
DO iCount = 1 TO NUM-ENTRIES(cFilename):
PUT-STRING(mStrFrom,
(IF iCount = 1 THEN 1 ELSE iLength + 1)) =
ENTRY(iCount,cFilename).
IF NUM-ENTRIES(cFilename) >= (iCount + 1) THEN DO:
PUT-BYTE(mStrFrom,25) = 0. /* If there are more entries in the
list, separate them with a NULL
character (zero 0) */
iLength = iLength + 1. /* Add the length of the NULL to the
length */
END.
iLength = iLength + LENGTH(ENTRY(iCount,cFilename)).
END.
/* Build the SHFileOpStruct structure */
PUT-LONG(mStruct,1) = CURRENT-WINDOW:HWND. /*HWND - controlling win*/
PUT-LONG(mStruct,5) = 3. /* Function */
PUT-LONG(mStruct,9) = GET-POINTER-VALUE(mStrFrom). /*Filelist structure - From
*/
PUT-LONG(mStruct,13) = 0. /* Filelist structure - To (move/copy ops)*/
PUT-LONG(mStruct,17) = 64. /* Flags (64 for move to recycle bin)*/
PUT-LONG(mStruct,21) = 0. /* Any Operations Aborted - Not Used here*/
PUT-LONG(mStruct,25) = 0. /* Name Mappings - Not used here */
PUT-LONG(mStruct,29) = 0. /* Title structure for Progress indicator*/
RUN SHFileOperationA ( INPUT mStruct,
OUTPUT iReturn ).
/* Reset memory for all pointers to zero */
SET-SIZE(mStruct) = 0.
SET-SIZE(mStrFrom) = 0.
/* External Procedure definition */
PROCEDURE SHFileOperationA EXTERNAL "shell32.dll":
DEFINE INPUT PARAMETER mStruct AS MEMPTR.
DEFINE RETURN PARAMETER iReturn AS LONG.
END PROCEDURE.
/* End Program - Recycle.p */
Below is the map of the SHFileOpStruct structure.
typedef struct _SHFILEOPSTRUCT{ */
HWND hwnd; */
UINT wFunc; */
LPCTSTR pFrom; */
LPCTSTR pTo; */
FILEOP_FLAGS fFlags; */
BOOL fAnyOperationsAborted; */
LPVOID hNameMappings; */
LPCTSTR lpszProgressTitle; */
} SHFILEOPSTRUCT, *LPSHFILEOPSTRUCT; */