Sintaxis SHFile
Sintaxis SHFile
Estoy buscando documentacion sobre la funcion SHFile() y no encuentro mas que un ejemplo incompleto ¿Me puede alguien decir la sintaxis de la funcion? Quiero borrar un fichero y que lo envie a la papelera sin pedir confirmacion.
Gracias.
Gracias.
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
http://msdn.microsoft.com/en-us/library ... S.85).aspx
http://msdn.microsoft.com/en-us/library ... S.85).aspx
La estructura SHFILEOPSTRUCT tienes que rellenarla adecuadamente. Aqui tienes un ejemplo en VB que facilmente puedes adaptar a FiveWin:
http://msdn.microsoft.com/en-us/library ... S.85).aspx
La estructura SHFILEOPSTRUCT tienes que rellenarla adecuadamente. Aqui tienes un ejemplo en VB que facilmente puedes adaptar a FiveWin:
Code: Select all
static extern int SHFileOperation(ref SHFILEOPSTRUCT FileOp);
const int FO_DELETE = 3;
const int FOF_ALLOWUNDO = 0x40;
const int FOF_NOCONFIRMATION = 0x10; //No prompt dialogs
SHFILEOPSTRUCT shf = new SHFILEOPSTRUCT();
shf.wFunc = FO_DELETE;
shf.fFlags = FOF_ALLOWUNDO | FOF_NOCONFIRMATION;
shf.pFrom = "Filename.Extension";
SHFileOperation(ref shf);
He visto este ejemplo (samples\dlgfile.prg):
pero aqui no pasa flags y lo he intentado pero no se en que posicion pasarlos y siempre me pide confirmacion.
Tambien he intentado lo que me dices:
pero en ejecucion me de un error al añadir el primer miembro de la estructura:
Total, que no le encuentro solucion. A ver si ve alguien algo porque no se porque el error.
Code: Select all
#include "FiveWin.ch"
#define FO_MOVE 0x0001
#define FO_COPY 0x0002
#define FO_DELETE 0x0003
#define FO_RENAME 0x0004
#define FOF_MULTIDESTFILES 0x0001
#define FOF_CONFIRMMOUSE 0x0002
#define FOF_SILENT 0x0004 // don't create progress/report
#define FOF_RENAMEONCOLLISION 0x0008
#define FOF_NOCONFIRMATION 0x0010 // Don't prompt the user.
#define FOF_WANTMAPPINGHANDLE 0x0020 // Fill in SHFILEOPSTRUCT.hNameMappings
// Must be freed using SHFreeNameMappings
#define FOF_ALLOWUNDO 0x0040
#define FOF_FILESONLY 0x0080 // on *.*, do only files
#define FOF_SIMPLEPROGRESS 0x0100 // means don't show names of files
#define FOF_NOCONFIRMMKDIR 0x0200 // don't confirm making any needed dirs
#define FOF_NOERRORUI 0x0400 // don't put up error UI
#define FOF_NOCOPYSECURITYATTRIBS 0x0800 // dont copy NT file Security Attributes
#define FOF_NORECURSION 0x1000 // don't recurse into directories.
static oDlg
//----------------------------------------------------------------------------//
function Main()
DEFINE DIALOG oDlg TITLE "System Files management Dialogs"
@ 0.5, 1 BUTTON "&Copy" ACTION CopyFile( "dlgfile.exe", "c:\dlgfile.exe" ) ;
SIZE 30, 12
@ 1.5, 1 BUTTON "&Delete" ACTION DeleteFile( "c:\dlgfile.exe" ) ;
SIZE 30, 12
@ 2.5, 1 BUTTON "&Move" ACTION MoveFile( "dlgfile.exe", "c:\dlgfile.exe" ) ;
SIZE 30, 12
ACTIVATE DIALOG oDlg CENTERED
return nil
//----------------------------------------------------------------------------//
function CopyFile( cSource, cDestination )
return SHFile( oDlg:hWnd, FO_COPY, cSource + Chr( 0 ), cDestination )
//----------------------------------------------------------------------------//
function DeleteFile( cFileName )
return SHFile( oDlg:hWnd, FO_DELETE, cFileName + Chr( 0 ) )
//----------------------------------------------------------------------------//
function MoveFile( cSource, cDestination )
return SHFile( oDlg:hWnd, FO_MOVE, cSource + Chr( 0 ), cDestination )
//----------------------------------------------------------------------------/
Code: Select all
SHFile( GetActiveWindow(), FO_DELETE, cFich + Chr( 0 ) , nAnd( FOF_ALLOWUNDO, FOF_NOCONFIRMATION ))
Code: Select all
#include "FiveWin.ch"
#include "Fileio.ch"
#include "struct.ch"
#define FO_MOVE 0x0001
#define FO_COPY 0x0002
#define FO_DELETE 0x0003
#define FO_RENAME 0x0004
#define FOF_MULTIDESTFILES 0x0001
#define FOF_CONFIRMMOUSE 0x0002
#define FOF_SILENT 0x0004
#define FOF_RENAMEONCOLLISION 0x0008
#define FOF_NOCONFIRMATION 0x0010
#define FOF_WANTMAPPINGHANDLE 0x0020
#define FOF_ALLOWUNDO 0x0040
#define FOF_FILESONLY 0x0080
#define FOF_SIMPLEPROGRESS 0x0100
#define FOF_NOCONFIRMMKDIR 0x0200
#define FOF_NOERRORUI 0x0400
#define FOF_NOCOPYSECURITYATTRIBS 0x0800
#define FOF_NORECURSION 0x1000
function APapelera(cFich)
local oShFileOps
local nError
STRUCT oShFileOps
MEMBER hwnd AS LONG
MEMBER wFunc AS LONG
MEMBER pFrom AS STRING
MEMBER pTo AS STRING
MEMBER fFlags AS _INT
MEMBER fAnyOperationsAborted AS LONG
MEMBER hNameMappings AS LONG
MEMBER lpszProgressTitle AS STRING
ENDSTRUCT
oShFileOps:wFunc = FO_DELETE
oShFileOps:pFrom = cFich
oShFileOps:fFlags = nAnd( FOF_ALLOWUNDO, FOF_NOCONFIRMATION )
nError := ShFileOper(@oShFileOps)
return nError
DLL32 FUNCTION SHFileOper;
( @lpFileOp AS LPSTR ) ; // SHFILEOPSTRUCT
AS LONG PASCAL;
FROM "SHFileOperationA" LIB "SHELL32
Code: Select all
Application
===========
Path and name: D:\CHOCO\CHoCo.Exe (32 bits)
Size: 523,264 bytes
Time from start: 0 hours 0 mins 0 secs
Error occurred at: 12/08/2008, 11:23:13
Error description: Error BASE/1106 Argument error: REPLICATE
Args:
[ 1] = C
[ 2] = U
Stack Calls
===========
Called from: => REPLICATE(0)
Called from: TStruct.PRG => TSTRUCT:ADDMEMBER(0)
Called from: UTILS.PRG => APAPELERA(173)
Called from: CHOCO.PRG => MAIN(127)
System.......................
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Si, estoy usando FWH de 32 bits.Antonio Linares wrote:Jose Luis,
Estas usando FWH 32 bits ?
Lo más sencillo es crear la función en C directamente, pero necesitas usar FWH.
No he escrito nunca una funcion en C para usarla desde FWH pero lopuedo mirar. Lo que me resulta mas raro es que no me deje ni definir la estructura. Y tambien me da pena no poder usar algo que ya esta escrito. Si supiese como esta escrita SHFile o supiese la sintaxis, imagino que serviria.
Code: Select all
SHFile( GetActiveWindow(), FO_DELETE, cFich + Chr( 0 ) , nAnd( FOF_ALLOWUNDO, FOF_NOCONFIRMATION )
¿Como lo ves tu?
Ah, soy Jorge Ignacio
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Jorge Ignacio,
Aqui tienes un ejemplo completo funcionando:
test.prg
Aqui tienes un ejemplo completo funcionando:
test.prg
Code: Select all
#include "FiveWin.ch"
#define FO_DELETE 3
#define FOF_ALLOWUNDO 0x40
#define FOF_NOCONFIRMATION 0x10
function Main()
local nResultado := ShFile( GetActiveWindow(), FO_DELETE, "test.map" + Chr( 0 ), nil,;
nOr( FOF_ALLOWUNDO, FOF_NOCONFIRMATION ) )
MsgInfo( nResultado )
return nil
#pragma BEGINDUMP
#include <hbapi.h>
#include <Windows.h>
#include <ShellApi.h>
#include <ShlObj.h>
HB_FUNC( SHFILE )
{
SHFILEOPSTRUCT sh;
memset( ( char * ) &sh, 0, sizeof( sh ) );
sh.hwnd = ( HWND ) hb_parnl( 1 );
sh.wFunc = ( UINT ) hb_parnl( 2 );
sh.pFrom = ( LPSTR ) hb_parc( 3 );
sh.pTo = ( LPSTR ) hb_parc( 4 );
sh.fFlags = ( FILEOP_FLAGS ) hb_parnl( 5 );
hb_retnl( SHFileOperation( &sh ) );
}
#pragma ENDDUMP
Esta visto que lo de esta funcion no es lo mio.
Algo tenemos distinto en el entorno. Me da errores de compilacion porque le faltan cabeceras:
El fichero ocidl.h no lo tengo en todo el disco.
Algo tenemos distinto en el entorno. Me da errores de compilacion porque le faltan cabeceras:
Code: Select all
Borland C++ 5.5 for Win32 Copyright (c) 1993, 2000 Borland
d:\pruebas\shfile\shfile.c:
Error E2209 C:\bcc55\include\exdisp.h 239: Unable to open include file 'ocidl.h'
Error E2209 C:\bcc55\include\docobj.h 86: Unable to open include file 'ocidl.h'
Error E2303 C:\bcc55\include\exdisp.h 2135: Type name expected
Error E2303 C:\bcc55\include\exdisp.h 2490: Type name expected
Error E2209 C:\bcc55\include\shldisp.h 284: Unable to open include file 'ocidl.h'
*** 5 errors in Compile **
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
- Antonio Linares
- Site Admin
- Posts: 37481
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact: