Sintaxis SHFile

Sintaxis SHFile

Postby jicorral » Mon Aug 11, 2008 4:09 pm

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.
User avatar
jicorral
 
Posts: 47
Joined: Thu Jul 10, 2008 7:33 am

Postby Antonio Linares » Tue Aug 12, 2008 12:02 am

http://msdn.microsoft.com/en-us/library/bb762164(VS.85).aspx

http://msdn.microsoft.com/en-us/library/bb759795(VS.85).aspx

La estructura SHFILEOPSTRUCT tienes que rellenarla adecuadamente. Aqui tienes un ejemplo en VB que facilmente puedes adaptar a FiveWin:
Code: Select all  Expand view
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);
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41291
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby jicorral » Tue Aug 12, 2008 9:41 am

He visto este ejemplo (samples\dlgfile.prg):

Code: Select all  Expand view
#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 )
//----------------------------------------------------------------------------/


pero aqui no pasa flags y lo he intentado pero no se en que posicion pasarlos y siempre me pide confirmacion.

Code: Select all  Expand view
SHFile( GetActiveWindow(), FO_DELETE, cFich + Chr( 0 ) , nAnd( FOF_ALLOWUNDO, FOF_NOCONFIRMATION ))


Tambien he intentado lo que me dices:

Code: Select all  Expand view
#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


pero en ejecucion me de un error al añadir el primer miembro de la estructura:

Code: Select all  Expand view
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.......................


Total, que no le encuentro solucion. A ver si ve alguien algo porque no se porque el error.
User avatar
jicorral
 
Posts: 47
Joined: Thu Jul 10, 2008 7:33 am

Postby Antonio Linares » Tue Aug 12, 2008 10:11 am

Jose Luis,

Estas usando FWH 32 bits ?

Lo más sencillo es crear la función en C directamente, pero necesitas usar FWH.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41291
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby jicorral » Tue Aug 12, 2008 11:20 am

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.


Si, estoy usando FWH de 32 bits.

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  Expand view
SHFile( GetActiveWindow(), FO_DELETE, cFich + Chr( 0 ) , nAnd( FOF_ALLOWUNDO, FOF_NOCONFIRMATION )


Esto me lo acepta pero me saca el dialogo pidiendo confirmacion.

¿Como lo ves tu?

Ah, soy Jorge Ignacio :D
User avatar
jicorral
 
Posts: 47
Joined: Thu Jul 10, 2008 7:33 am

Postby Antonio Linares » Tue Aug 12, 2008 5:50 pm

Jorge Ignacio,

Aqui tienes un ejemplo completo funcionando:

test.prg
Code: Select all  Expand view
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41291
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby jicorral » Wed Aug 13, 2008 10:31 am

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:

Code: Select all  Expand view
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 **


El fichero ocidl.h no lo tengo en todo el disco.
User avatar
jicorral
 
Posts: 47
Joined: Thu Jul 10, 2008 7:33 am

Postby Antonio Linares » Wed Aug 13, 2008 2:58 pm

Aqui tienes el fichero que te falta:

http://rapidshare.com/files/137047804/ocidl.h.html
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41291
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby jicorral » Thu Aug 14, 2008 4:09 pm

Ahora me compila pero no hay forma; no aparece en la papelera, lo borra sin mas. Ni caso al ALLOWUNDO.

He intentado mover el fichero a la papelera directamente, pero no me deja. En fin, que ya no se por donde tirar.
User avatar
jicorral
 
Posts: 47
Joined: Thu Jul 10, 2008 7:33 am

Postby Antonio Linares » Fri Aug 15, 2008 6:09 pm

Aqui está funcionando bien y lo envia a la papelera.

Si quieres te envio el EXE para que lo pruebes
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41291
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby jicorral » Tue Aug 19, 2008 8:55 pm

Antonio Linares wrote:Aqui está funcionando bien y lo envia a la papelera.

Si quieres te envio el EXE para que lo pruebes


No es que lo dude pero es que me tiene loco porque asi deberia ser. Si, por favor, mandame el exe y yo te mando el mio y probamos.
User avatar
jicorral
 
Posts: 47
Joined: Thu Jul 10, 2008 7:33 am

Postby Antonio Linares » Wed Aug 20, 2008 6:57 am

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41291
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby jicorral » Wed Sep 03, 2008 8:36 am

Tampoco con tu exe me lo manda a la papelera. Yo borro archivos desde el explorador de windows y lo hace sin problema. No se que es lo que pasa.
User avatar
jicorral
 
Posts: 47
Joined: Thu Jul 10, 2008 7:33 am

Postby Antonio Linares » Fri Sep 05, 2008 8:22 am

Aqui funciona correctamente, probado con Vista.
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 41291
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain


Return to FiveWin para CA-Clipper

Who is online

Users browsing this forum: No registered users and 2 guests