Para expertos en API...

03/01/2004 - 14:43 por Lorenzo Peretti | Informe spam
Hace unos meses que comencé a programar en Visual FoxPro 6.0, ya que antes
lo hacia en FoxPro 2.6 para D.O.S, y me encontré con un problema que no he
podido resolver:
Necesito copiar archivos mediante la Api de Windows mostrando la barra de
progreso y el cuadro de diálogo de confirmación. Luego de buscar en
internet encontré lo que buscaba, el único inconveniente es que el código
está escrito en Visual Basic y desconozco las equivalencias entre los dos
lenguajes . He comprobado que por sus trabajos expuestos en el Portal,
algunos colegas poseen un excelente conocimiento de cómo trabajar con las
Apis por eso les pido su ayuda. Abajo describo el código que encontré:

****Inicio
‘ Copiar un fichero utilizando el SHFileOperation de la API que hace
aparecer el cuadro de diálogo del Windows
‘ Declaraciones

Public Type SHFILEOPSTRUCT
hWnd As Long
wFunc As Long
pFrom As String
pTo As String
fFlags As Integer
fAnyOperationsAborted As Boolean
hNameMappings As Long
lpszProgressTitle As String
End Type

Public Declare Function SHFileOperation Lib "shell32.dll" Alias
"SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
Public Const FO_COPY = &H2
Public Const FOF_ALLOWUNDO = &H40

‘ Código

Public Sub CopyFileWindowsWay(SourceFile As String, DestinationFile As
String)
Dim lngReturn As Long
Dim typFileOperation As SHFILEOPSTRUCT

With typFileOperation
.hWnd = 0
.wFunc = FO_COPY
.pFrom = SourceFile & vbNullChar & vbNullChar 'source file
.pTo = DestinationFile & vbNullChar & vbNullChar 'destination file
.fFlags = FOF_ALLOWUNDO
End With
lngReturn = SHFileOperation(typFileOperation)
If lngReturn <> 0 Then 'Operation failed
MsgBox Err.LastDllError, vbCritical Or vbOKOnly
Else 'Aborted
If typFileOperation.fAnyOperationsAborted = True Then
MsgBox "Operation Failed", vbCritical Or vbOKOnly
End If
End If
End Sub
***** Fin

Supongo que dicha Api traducida a Visual FoxPro sería algo así:
DECLARE Integer SHFileOperation IN shell32.dll As SHFileOperationA ;
SHFILEOPSTRUCT @lpFileOp

Pero no tengo idea de cómo armar la cadena ‘lpFileOp’ usada como parametro.
Aca abajo tengo unas líneas de ayuda sobre las declaraciones de esta Api y
sus parámetros:

SHFileOperation
Performs a copy, move, rename, or delete operation on a file system
object.
WINSHELLAPI int WINAPI SHFileOperation(LPSHFILEOPSTRUCT lpFileOp)

Parameters
lpFileOp

Pointer to an SHFILEOPSTRUCT structure that contains information the
function needs to carry out the operation.

Return Values
Returns zero if successful or nonzero if an error occurs.


SHFILEOPSTRUCT
Contains information that the SHFileOperation function uses to perform
file operations.

typedef struct _SHFILEOPSTRUCT { // shfos
HWND hwnd;
UINT wFunc;
LPCSTR pFrom;
LPCSTR pTo;
FILEOP_FLAGS fFlags;
BOOL fAnyOperationsAborted;
LPVOID hNameMappings;
LPCSTR lpszProgressTitle;
} SHFILEOPSTRUCT, FAR *LPSHFILEOPSTRUCT;


Members
hwnd
Handle of the dialog box to use to display information about the status of
the operation.

wFunc
Operation to perform. This member can be one of the following values:
FO_COPY Copies the files specified by pFrom to the location specified by
pTo.
FO_DELETE Deletes the files specified by pFrom (pTo is ignored).
FO_MOVE Moves the files specified by pFrom to the location specified by
pTo.
FO_RENAME Renames the files specified by pFrom.

pFrom
Pointer to a buffer that specifies one or more source file names. Multiple
names must be null-separated. The list of names must be double
null-terminated.

pTo
Pointer to a buffer that contains the name of the destination file or
directory. The buffer can contain mutiple destination file names if the
fFlags member specifies FOF_MULTIDESTFILES. Multiple names must be
null-separated. The list of names must be double null-terminated.

fFlags
Flags that control the file operation. This member can be a combination of
the following values:
FOF_ALLOWUNDO Preserves undo information, if possible.
FOF_CONFIRMMOUSE Not implemented.
FOF_FILESONLY Performs the operation only on files if a wildcard
filename (*.*) is specified.
FOF_MULTIDESTFILES Indicates that the pTo member specifies multiple
destination files (one for each source file) rather than one directory
where all source files are to be deposited.
FOF_NOCONFIRMATION Responds with "yes to all" for any dialog box that is
displayed.
FOF_NOCONFIRMMKDIR Does not confirm the creation of a new directory if
the operation requires one to be created.
FOF_RENAMEONCOLLISION Gives the file being operated on a new name (such as
"Copy #1 of...") in a move, copy, or rename operation if a file of the
target name already exists.
FOF_SILENT Does not display a progress dialog box.
FOF_SIMPLEPROGRESS Displays a progress dialog box, but does not show the
filenames.
FOF_WANTMAPPINGHANDLE Fills in the hNameMappings member. The handle must
be freed by using the SHFreeNameMappings function.


fAnyOperationsAborted
Value that receives TRUE if the user aborted any file operations before
they were completed or FALSE otherwise.

hNameMappings
Handle of a filename mapping object that contains an array of
SHNAMEMAPPING structures. Each structure contains the old and new path
names for each file that was moved, copied, or renamed. This member is
used only if fFlags includes FOF_WANTMAPPINGHANDLE.

lpszProgressTitle
Pointer to a string to use as the title for a progress dialog box. This
member is used only if fFlags includes FOF_SIMPLEPROGRESS.

Remarks
If pFrom or pTo are unqualified names, the current directories are taken
from the global current drive and directory settings as managed by the
GetCurrentDirectory and SetCurrentDirectory functions.

See Also
GetCurrentDirectory, SetCurrentDirectory, SHFileOperation,
SHFreeNameMappings, SHNAMEMAPPING

Espero no haberles quitado su tiempo con esta consulta y le quedo
agradecido por su ayuda si fuera posible, además podrían exponer esta Api
para todos los integrantes del Portal, seguramente alguien más podría
necesitarla.

Lorenzo Peretti
e-mail: [link]fabianp117@hotmail.com[/link]

P.D: Feliz Año Nuevo a todos, Gracias.


PortalFox :: Nada corre como un zorro
http://www.portalfox.com

PortalFox - NNTP Forum Gateway
 

Leer las respuestas

#1 David Amador \(Davphantom\)
03/01/2004 - 21:48 | Informe spam
Se me olvidaba . no soy experto ...

David Amador Tapia
WebMaster de La Web de Davphantom
www.davphantom.net
Cartagena. Colombia
Tel. (5) 6581523 - 6621502 - Cel 310-6581865


"David Amador (Davphantom)" escribió en
el mensaje news:uRT%
Puedes hacerlo con Shell asi ...

oSh = CREATEOBJECT("Shell.Application")
oSh.NameSpace("C:\CarpetaOrigen").MoveHere("C:\CarpetaDestino")

David Amador Tapia
WebMaster de La Web de Davphantom
www.davphantom.net
Cartagena. Colombia
Tel. (5) 6581523 - 6621502 - Cel 310-6581865


"Lorenzo Peretti" escribió en el mensaje
news:e6jAJ%
> Hace unos meses que comencé a programar en Visual FoxPro 6.0, ya que


antes
> lo hacia en FoxPro 2.6 para D.O.S, y me encontré con un problema que no


he
> podido resolver:
> Necesito copiar archivos mediante la Api de Windows mostrando la barra


de
> progreso y el cuadro de diálogo de confirmación. Luego de buscar en
> internet encontré lo que buscaba, el único inconveniente es que el


código
> está escrito en Visual Basic y desconozco las equivalencias entre los


dos
> lenguajes . He comprobado que por sus trabajos expuestos en el Portal,
> algunos colegas poseen un excelente conocimiento de cómo trabajar con


las
> Apis por eso les pido su ayuda. Abajo describo el código que encontré:
>
> ****Inicio
> ' Copiar un fichero utilizando el SHFileOperation de la API que hace
> aparecer el cuadro de diálogo del Windows
> ' Declaraciones
>
> Public Type SHFILEOPSTRUCT
> hWnd As Long
> wFunc As Long
> pFrom As String
> pTo As String
> fFlags As Integer
> fAnyOperationsAborted As Boolean
> hNameMappings As Long
> lpszProgressTitle As String
> End Type
>
> Public Declare Function SHFileOperation Lib "shell32.dll" Alias
> "SHFileOperationA" (lpFileOp As SHFILEOPSTRUCT) As Long
> Public Const FO_COPY = &H2
> Public Const FOF_ALLOWUNDO = &H40
>
> ' Código
>
> Public Sub CopyFileWindowsWay(SourceFile As String, DestinationFile As
> String)
> Dim lngReturn As Long
> Dim typFileOperation As SHFILEOPSTRUCT
>
> With typFileOperation
> .hWnd = 0
> .wFunc = FO_COPY
> .pFrom = SourceFile & vbNullChar & vbNullChar 'source file
> .pTo = DestinationFile & vbNullChar & vbNullChar 'destination


file
> .fFlags = FOF_ALLOWUNDO
> End With
> lngReturn = SHFileOperation(typFileOperation)
> If lngReturn <> 0 Then 'Operation failed
> MsgBox Err.LastDllError, vbCritical Or vbOKOnly
> Else 'Aborted
> If typFileOperation.fAnyOperationsAborted = True Then
> MsgBox "Operation Failed", vbCritical Or vbOKOnly
> End If
> End If
> End Sub
> ***** Fin
>
> Supongo que dicha Api traducida a Visual FoxPro sería algo así:
> DECLARE Integer SHFileOperation IN shell32.dll As SHFileOperationA ;
> SHFILEOPSTRUCT @lpFileOp
>
> Pero no tengo idea de cómo armar la cadena 'lpFileOp' usada como
parametro.
> Aca abajo tengo unas líneas de ayuda sobre las declaraciones de esta Api


y
> sus parámetros:
>
> SHFileOperation
> Performs a copy, move, rename, or delete operation on a file system
> object.
> WINSHELLAPI int WINAPI SHFileOperation(LPSHFILEOPSTRUCT lpFileOp)
>
> Parameters
> lpFileOp
>
> Pointer to an SHFILEOPSTRUCT structure that contains information the
> function needs to carry out the operation.
>
> Return Values
> Returns zero if successful or nonzero if an error occurs.
>
>
> SHFILEOPSTRUCT
> Contains information that the SHFileOperation function uses to perform
> file operations.
>
> typedef struct _SHFILEOPSTRUCT { // shfos
> HWND hwnd;
> UINT wFunc;
> LPCSTR pFrom;
> LPCSTR pTo;
> FILEOP_FLAGS fFlags;
> BOOL fAnyOperationsAborted;
> LPVOID hNameMappings;
> LPCSTR lpszProgressTitle;
> } SHFILEOPSTRUCT, FAR *LPSHFILEOPSTRUCT;
>
>
> Members
> hwnd
> Handle of the dialog box to use to display information about the status


of
> the operation.
>
> wFunc
> Operation to perform. This member can be one of the following values:
> FO_COPY Copies the files specified by pFrom to the location specified by
> pTo.
> FO_DELETE Deletes the files specified by pFrom (pTo is ignored).
> FO_MOVE Moves the files specified by pFrom to the location specified by
> pTo.
> FO_RENAME Renames the files specified by pFrom.
>
> pFrom
> Pointer to a buffer that specifies one or more source file names.


Multiple
> names must be null-separated. The list of names must be double
> null-terminated.
>
> pTo
> Pointer to a buffer that contains the name of the destination file or
> directory. The buffer can contain mutiple destination file names if the
> fFlags member specifies FOF_MULTIDESTFILES. Multiple names must be
> null-separated. The list of names must be double null-terminated.
>
> fFlags
> Flags that control the file operation. This member can be a combination


of
> the following values:
> FOF_ALLOWUNDO Preserves undo information, if possible.
> FOF_CONFIRMMOUSE Not implemented.
> FOF_FILESONLY Performs the operation only on files if a wildcard
> filename (*.*) is specified.
> FOF_MULTIDESTFILES Indicates that the pTo member specifies multiple
> destination files (one for each source file) rather than one directory
> where all source files are to be deposited.
> FOF_NOCONFIRMATION Responds with "yes to all" for any dialog box that is
> displayed.
> FOF_NOCONFIRMMKDIR Does not confirm the creation of a new directory if
> the operation requires one to be created.
> FOF_RENAMEONCOLLISION Gives the file being operated on a new name (such


as
> "Copy #1 of...") in a move, copy, or rename operation if a file of the
> target name already exists.
> FOF_SILENT Does not display a progress dialog box.
> FOF_SIMPLEPROGRESS Displays a progress dialog box, but does not show the
> filenames.
> FOF_WANTMAPPINGHANDLE Fills in the hNameMappings member. The handle must
> be freed by using the SHFreeNameMappings function.
>
>
> fAnyOperationsAborted
> Value that receives TRUE if the user aborted any file operations before
> they were completed or FALSE otherwise.
>
> hNameMappings
> Handle of a filename mapping object that contains an array of
> SHNAMEMAPPING structures. Each structure contains the old and new path
> names for each file that was moved, copied, or renamed. This member is
> used only if fFlags includes FOF_WANTMAPPINGHANDLE.
>
> lpszProgressTitle
> Pointer to a string to use as the title for a progress dialog box. This
> member is used only if fFlags includes FOF_SIMPLEPROGRESS.
>
> Remarks
> If pFrom or pTo are unqualified names, the current directories are taken
> from the global current drive and directory settings as managed by the
> GetCurrentDirectory and SetCurrentDirectory functions.
>
> See Also
> GetCurrentDirectory, SetCurrentDirectory, SHFileOperation,
> SHFreeNameMappings, SHNAMEMAPPING
>
> Espero no haberles quitado su tiempo con esta consulta y le quedo
> agradecido por su ayuda si fuera posible, además podrían exponer esta


Api
> para todos los integrantes del Portal, seguramente alguien más podría
> necesitarla.
>
> Lorenzo Peretti
> e-mail: [link][/link]
>
> P.D: Feliz Año Nuevo a todos, Gracias.
>
>
> PortalFox :: Nada corre como un zorro
> http://www.portalfox.com
>
> PortalFox - NNTP Forum Gateway


Preguntas similares