Selección múltiple de archivos

Selección múltiple de archivos

Postby quique » Wed Mar 13, 2013 10:44 pm

¿Es posible con cGetFile32() o cualquier otra función permitir una selección múltiple de archivos?
Saludos
Quique
User avatar
quique
 
Posts: 408
Joined: Sun Aug 13, 2006 5:38 am

Re: Selección múltiple de archivos

Postby sysctrl2 » Thu Mar 14, 2013 1:39 am

Quique, aqui una funcion y el modo de uso:

mi correo es: ccc_3_ccc@hotmail.com, SysCtrlSoftware@gmail.com

saludos..

Code: Select all  Expand view
aFiles := selectfiles()
for i := 1 to len( aFiles )
     ? aFiles[ i ]
next
 



Code: Select all  Expand view
* -------------------------------------------------------------
* funciona cGetFile Modificada para seleccionar varios archivos
* -------------------------------------------------------------

FUNCTION SelectFiles()
    LOCAL cCurDir := CurDrive() + ":\" + CurDir() //willy
    LOCAL cFile := CGETFILE( "
*.xml", "Selecciona uno o varios archivos ...", , , , , NOR( OFN_ALLOWMULTISELECT, OFN_EXPLORER, OFN_HIDEREADONLY ) )

    LOCAL aFile := {}

    LOCAL cPath
    local cFile1 := cFile

    IF !EMPTY( cFile )
        cPath = LEFT( cFile, AT( CHR( 0 ), cFile ) - 1 )

        IF RIGHT( cPath, 1 ) != "
\"; cPath += "\"; ENDIF

        WHILE .T.
            cFile = SUBSTR( cFile, AT( CHR( 0 ), cFile ) + 1 )
            IF LEFT( cFile, 1 ) = CHR( 0 ); EXIT; ENDIF
            AADD( aFile, cPath + LEFT( cFile, AT( CHR( 0 ), cFile ) - 1 ) )
        ENDDO

        IF LEN( aFile ) = 1
            aFile[ 1 ] = LEFT( aFile[ 1 ], LEN( aFile[ 1 ] ) - 1 )
        ENDIF
    ENDIF


    && WQOUT( aFile ) && muestra un arreglo en un dialogo.

    DirChange( cCurDir )     //wiliam morales

    * Si solo selecciona un elemento.
    if len( aFile ) = 0 .and. !empty( cFile1 )
       aadd( aFile, cFile1  )
    endif

RETURN ( aFile )


#pragma BEGINDUMP

#include <Windows.h>
#include <CommDlg.h>
#include <ClipApi.h>
#include <HbApi.h>

static far WORD wIndex;
static far char Title[] = "
Selecciona uno o varios archivos";


HB_FUNC( CGETFILE )          // ( cFileMask, cTitle, nDefaultMask, ;
                             // cInitDir, lSave, lLongNames, nFlags, ;
                             // cIniFile )  --> cFileName
{
   OPENFILENAME ofn;
   LPSTR pFile, pFilter, pDir, pTitle;
   WORD w = 0, wLen;
   BYTE bIndex = ( BYTE ) hb_parni( 3 );
   BOOL bSave = IF( PCOUNT() > 4 && ISLOGICAL( 5 ), hb_parl( 5 ), FALSE );
   BOOL bLongNames = hb_parl( 6 );
   DWORD dwFlags = IF( PCOUNT() > 6 && ISNUM( 7 ), hb_parnl( 7 ), 2060 );

   if( PCOUNT() < 1 )
   {
      hb_retc( "
" );
       return;
   }

   // alloc for title

   pTitle = ( LPSTR ) hb_xgrab( 128 );

   if ( PCOUNT() > 1 && ISCHAR( 2 ) )
   {
      wLen   = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 2 ) );
      memcpy( pTitle, hb_parc( 2 ), wLen );
      * ( pTitle + wLen ) = 0;

   }
   else
   {
      pTitle  = Title;
   }

   // alloc for initial dir

   pDir = ( LPSTR ) hb_xgrab( 128 );

   if ( PCOUNT() > 3 && ISCHAR( 4 ) )
   {
      wLen  = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 4 ) );
      memcpy( pDir, hb_parc( 4 ), wLen );
      * ( pDir + wLen ) = 0;
   }
   else
   {
      * ( pDir ) = 0;
   }

   // alloc for file

   if ( dwFlags & OFN_ALLOWMULTISELECT )
      pFile = ( LPSTR ) hb_xgrab( 32768 );
   else
      pFile = ( LPSTR ) hb_xgrab( 128 );

   if ( PCOUNT() > 7 && ISCHAR( 8 ) )
   {
      wLen = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 8 ) );
      memcpy( pFile, hb_parc( 8 ), wLen );
   }
   else
   {
      wLen = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 1 ) );
      memcpy( pFile, hb_parc( 1 ), wLen );
   }
   * ( pFile + wLen ) = 0;

   // alloc for mask

   pFilter = ( LPSTR ) hb_xgrab( 400 );
   wLen    = ( WORD ) min( ( unsigned long ) 398, hb_parclen( 1 ) );
   memcpy( pFilter, hb_parc( 1 ), wLen );
   * ( pFilter + wLen ) = 0;

   while( * ( pFilter + w ) )
   {
      if( * ( pFilter + w ) == '|' )
      {
         * ( pFilter + w ) = 0;
         if ( PCOUNT() < 8 )
            * (pFile) = 0;
      }
      w++;
   }

   * ( pFilter + wLen  ) = 0;
   * ( pFilter + wLen + 1 ) = 0;

   memset( ( char * ) &ofn, 0, sizeof( OPENFILENAME ) );

   ofn.lStructSize     = sizeof( OPENFILENAME );
   ofn.hwndOwner       = GetActiveWindow();
   ofn.lpstrFilter     = pFilter;
   ofn.lpstrFile       = pFile;
   ofn.lpstrInitialDir = pDir;
   ofn.lpstrTitle      = pTitle;
   ofn.lpstrCustomFilter = 0; // NIL;
   ofn.nFilterIndex    = bIndex ? bIndex: 1;
   ofn.nMaxFile        = dwFlags & OFN_ALLOWMULTISELECT ? 32768 : 128;
   ofn.lpstrFileTitle  = 0; // NIL;
   ofn.Flags           = OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR |
                        IF( bSave, OFN_HIDEREADONLY, 0 ) |
                        IF( bLongNames, OFN_LONGNAMES, 0 );

   if( dwFlags )
      ofn.Flags = dwFlags;

   wIndex = 0;

   if( bSave )
   {
      if( GetSaveFileName( &ofn ) )
         hb_retc( pFile );
      else
         hb_retc( "
" );
   }
   else
   {
      if( GetOpenFileName( &ofn ) )
         if ( dwFlags & OFN_ALLOWMULTISELECT )
            hb_retclen( pFile, 32768 );
         else
            hb_retc( pFile );
      else
         hb_retc( "
" );
   }

   wIndex = ( WORD ) ofn.nFilterIndex;

   hb_xfree( pFilter );
   hb_xfree( pFile );
   hb_xfree( pDir );
   hb_xfree( pTitle );
}

#pragma ENDDUMP
Cesar Cortes Cruz
SysCtrl Software
Mexico

' Sin +- FWH es mejor "
User avatar
sysctrl2
 
Posts: 955
Joined: Mon Feb 05, 2007 7:15 pm

Re: Selección múltiple de archivos

Postby quique » Thu Mar 14, 2013 3:34 am

Supongo que debido a mi gran ignorancia de C no me funcionó :(

Lo que hice fue copiar el código que pusiste tal cual al final de uno de los prg, de hecho, fue en el prg principal, y me marcó todos estos errores:


Error E2238 d:\lenguaje\harbour\include\clipdefs.h 84: Multiple declaration for
'WORD'
+ Full parser context
+ ..\\fuentes\\main.prg, line 381: #include \lenguaje\fwh\include\ClipApi.h
+ \lenguaje\fwh\include\ClipApi.h, line 22: #include \lenguaje\fwh\include\fwH
arb.h
+ \lenguaje\fwh\include\fwHarb.h, line 20: #include d:\lenguaje\harbour\includ
e\extend.h
+ d:\lenguaje\harbour\include\extend.h, line 65: #include d:\lenguaje\harbour\
include\extend.api
+ d:\lenguaje\harbour\include\extend.api, line 58: #include d:\lenguaje\harbou
r\include\clipdefs.h
Error E2344 \lenguaje\bcc55\Include\windef.h 145: Earlier declaration of 'WORD'
+ Full parser context
+ ..\\fuentes\\main.prg, line 381: #include \lenguaje\fwh\include\ClipApi.h
+ \lenguaje\fwh\include\ClipApi.h, line 22: #include \lenguaje\fwh\include\fwH
arb.h
+ \lenguaje\fwh\include\fwHarb.h, line 20: #include d:\lenguaje\harbour\includ
e\extend.h
+ d:\lenguaje\harbour\include\extend.h, line 65: #include d:\lenguaje\harbour\
include\extend.api
+ d:\lenguaje\harbour\include\extend.api, line 58: #include d:\lenguaje\harbou
r\include\clipdefs.h
Error E2238 d:\lenguaje\harbour\include\clipdefs.h 86: Multiple declaration for
'PWORD'
+ Full parser context
+ ..\\fuentes\\main.prg, line 381: #include \lenguaje\fwh\include\ClipApi.h
+ \lenguaje\fwh\include\ClipApi.h, line 22: #include \lenguaje\fwh\include\fwH
arb.h
+ \lenguaje\fwh\include\fwHarb.h, line 20: #include d:\lenguaje\harbour\includ
e\extend.h
+ d:\lenguaje\harbour\include\extend.h, line 65: #include d:\lenguaje\harbour\
include\extend.api
+ d:\lenguaje\harbour\include\extend.api, line 58: #include d:\lenguaje\harbou
r\include\clipdefs.h
Error E2344 \lenguaje\bcc55\Include\windef.h 154: Earlier declaration of 'PWORD'

+ Full parser context
+ ..\\fuentes\\main.prg, line 381: #include \lenguaje\fwh\include\ClipApi.h
+ \lenguaje\fwh\include\ClipApi.h, line 22: #include \lenguaje\fwh\include\fwH
arb.h
+ \lenguaje\fwh\include\fwHarb.h, line 20: #include d:\lenguaje\harbour\includ
e\extend.h
+ d:\lenguaje\harbour\include\extend.h, line 65: #include d:\lenguaje\harbour\
include\extend.api
+ d:\lenguaje\harbour\include\extend.api, line 58: #include d:\lenguaje\harbou
r\include\clipdefs.h
Error E2238 d:\lenguaje\harbour\include\clipdefs.h 106: Multiple declaration for
'BOOL'
+ Full parser context
+ ..\\fuentes\\main.prg, line 381: #include \lenguaje\fwh\include\ClipApi.h
+ \lenguaje\fwh\include\ClipApi.h, line 22: #include \lenguaje\fwh\include\fwH
arb.h
+ \lenguaje\fwh\include\fwHarb.h, line 20: #include d:\lenguaje\harbour\includ
e\extend.h
+ d:\lenguaje\harbour\include\extend.h, line 65: #include d:\lenguaje\harbour\
include\extend.api
+ d:\lenguaje\harbour\include\extend.api, line 58: #include d:\lenguaje\harbou
r\include\clipdefs.h
Error E2344 \lenguaje\bcc55\Include\windef.h 143: Earlier declaration of 'BOOL'
+ Full parser context
+ ..\\fuentes\\main.prg, line 381: #include \lenguaje\fwh\include\ClipApi.h
+ \lenguaje\fwh\include\ClipApi.h, line 22: #include \lenguaje\fwh\include\fwH
arb.h
+ \lenguaje\fwh\include\fwHarb.h, line 20: #include d:\lenguaje\harbour\includ
e\extend.h
+ d:\lenguaje\harbour\include\extend.h, line 65: #include d:\lenguaje\harbour\
include\extend.api
+ d:\lenguaje\harbour\include\extend.api, line 58: #include d:\lenguaje\harbou
r\include\clipdefs.h
Error E2238 d:\lenguaje\harbour\include\clipdefs.h 109: Multiple declaration for
'PBOOL'
+ Full parser context
+ ..\\fuentes\\main.prg, line 381: #include \lenguaje\fwh\include\ClipApi.h
+ \lenguaje\fwh\include\ClipApi.h, line 22: #include \lenguaje\fwh\include\fwH
arb.h
+ \lenguaje\fwh\include\fwHarb.h, line 20: #include d:\lenguaje\harbour\includ
e\extend.h
+ d:\lenguaje\harbour\include\extend.h, line 65: #include d:\lenguaje\harbour\
include\extend.api
+ d:\lenguaje\harbour\include\extend.api, line 58: #include d:\lenguaje\harbou
r\include\clipdefs.h
Error E2344 \lenguaje\bcc55\Include\windef.h 148: Earlier declaration of 'PBOOL'

+ Full parser context
+ ..\\fuentes\\main.prg, line 381: #include \lenguaje\fwh\include\ClipApi.h
+ \lenguaje\fwh\include\ClipApi.h, line 22: #include \lenguaje\fwh\include\fwH
arb.h
+ \lenguaje\fwh\include\fwHarb.h, line 20: #include d:\lenguaje\harbour\includ
e\extend.h
+ d:\lenguaje\harbour\include\extend.h, line 65: #include d:\lenguaje\harbour\
include\extend.api
+ d:\lenguaje\harbour\include\extend.api, line 58: #include d:\lenguaje\harbou
r\include\clipdefs.h
Error E2238 d:\lenguaje\harbour\include\clipdefs.h 118: Multiple declaration for
'HANDLE'
+ Full parser context
+ ..\\fuentes\\main.prg, line 381: #include \lenguaje\fwh\include\ClipApi.h
+ \lenguaje\fwh\include\ClipApi.h, line 22: #include \lenguaje\fwh\include\fwH
arb.h
+ \lenguaje\fwh\include\fwHarb.h, line 20: #include d:\lenguaje\harbour\includ
e\extend.h
+ d:\lenguaje\harbour\include\extend.h, line 65: #include d:\lenguaje\harbour\
include\extend.api
+ d:\lenguaje\harbour\include\extend.api, line 58: #include d:\lenguaje\harbou
r\include\clipdefs.h
Error E2344 \lenguaje\bcc55\Include\winnt.h 283: Earlier declaration of 'HANDLE'

+ Full parser context
+ ..\\fuentes\\main.prg, line 381: #include \lenguaje\fwh\include\ClipApi.h
+ \lenguaje\fwh\include\ClipApi.h, line 22: #include \lenguaje\fwh\include\fwH
arb.h
+ \lenguaje\fwh\include\fwHarb.h, line 20: #include d:\lenguaje\harbour\includ
e\extend.h
+ d:\lenguaje\harbour\include\extend.h, line 65: #include d:\lenguaje\harbour\
include\extend.api
+ d:\lenguaje\harbour\include\extend.api, line 58: #include d:\lenguaje\harbou
r\include\clipdefs.h
Error E2293 ..\\fuentes\\main.prg 384: ) expected
Warning W8019 ..\\fuentes\\main.prg 394: Code has no effect in function HB_FUN_C
GETFILE
Error E2379 ..\\fuentes\\main.prg 394: Statement missing ; in function HB_FUN_CG
ETFILE
Error E2140 ..\\fuentes\\main.prg 395: Declaration is not allowed here in functi
on HB_FUN_CGETFILE
Error E2140 ..\\fuentes\\main.prg 396: Declaration is not allowed here in functi
on HB_FUN_CGETFILE
Error E2140 ..\\fuentes\\main.prg 397: Declaration is not allowed here in functi
on HB_FUN_CGETFILE
Error E2140 ..\\fuentes\\main.prg 398: Declaration is not allowed here in functi
on HB_FUN_CGETFILE
Error E2451 ..\\fuentes\\main.prg 412: Undefined symbol 'wLen' in function HB_FU
N_CGETFILE
Error E2314 ..\\fuentes\\main.prg 412: Call of nonfunction in function HB_FUN_CG
ETFILE
Error E2314 ..\\fuentes\\main.prg 428: Call of nonfunction in function HB_FUN_CG
ETFILE
Error E2314 ..\\fuentes\\main.prg 446: Call of nonfunction in function HB_FUN_CG
ETFILE
Error E2314 ..\\fuentes\\main.prg 451: Call of nonfunction in function HB_FUN_CG
ETFILE
Error E2314 ..\\fuentes\\main.prg 459: Call of nonfunction in function HB_FUN_CG
ETFILE
Error E2451 ..\\fuentes\\main.prg 463: Undefined symbol 'w' in function HB_FUN_C
GETFILE
Error E2451 ..\\fuentes\\main.prg 496: Undefined symbol 'wIndex' in function HB_
FUN_CGETFILE
Error E2379 ..\\fuentes\\main.prg 516: Statement missing ; in function HB_FUN_CG
ETFILE
Error E2228 ..\\fuentes\\main.prg 516: Too many error or warning messages in fun
ction HB_FUN_CGETFILE
*** 26 errors in Compile ***
hbmk2: Error: Running C/C++ compiler. 1
bcc32.exe -c -q -CP437 -d -O2 -OS -Ov -Oc -Oi -6 -tW -tWM -w -Q -w-sig- -n..\.h
bmk\win\bcc -I\lenguaje\bcc55\Include -Id:\lenguaje\harbour\include -I\lenguaje\
fwh\include -I\lenguaje\harbour\contrib\xhb -I\quiquesoft\lib ..\.hbmk\win\bcc\m
ain.c


Se me hizo fácil quitar la lína

#include <ClipApi.h>

y el resultado fue el siguiente

..\fuentes\main.prg(57) Warning W0001 Ambiguous reference 'OFN_ALLOWMULTISELECT
'
..\fuentes\main.prg(57) Warning W0001 Ambiguous reference 'OFN_EXPLORER'
..\fuentes\main.prg(57) Warning W0001 Ambiguous reference 'OFN_HIDEREADONLY'
..\fuentes\main.prg(341) Warning W0001 Ambiguous reference 'OFN_ALLOWMULTISELEC
T'
..\fuentes\main.prg(341) Warning W0001 Ambiguous reference 'OFN_EXPLORER'
..\fuentes\main.prg(341) Warning W0001 Ambiguous reference 'OFN_HIDEREADONLY'
Lines 5364, Functions/Procedures 14
Generating C source output to '..\.hbmk\win\bcc\main.c'... Done.
hbmk2: Compiling...
..\.hbmk\win\bcc\main.c:
Warning W8065 ..\\fuentes\\main.prg 396: Call to function 'PCOUNT' with no proto
type in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 396: Call to function 'ISLOGICAL' with no pr
ototype in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 396: Call to function 'IF' with no prototype
in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 398: Call to function 'PCOUNT' with no proto
type in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 398: Call to function 'ISNUM' with no protot
ype in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 398: Call to function 'IF' with no prototype
in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 400: Call to function 'PCOUNT' with no proto
type in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 410: Call to function 'PCOUNT' with no proto
type in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 410: Call to function 'ISCHAR' with no proto
type in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 426: Call to function 'PCOUNT' with no proto
type in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 426: Call to function 'ISCHAR' with no proto
type in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 444: Call to function 'PCOUNT' with no proto
type in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 444: Call to function 'ISCHAR' with no proto
type in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 468: Call to function 'PCOUNT' with no proto
type in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 490: Call to function 'IF' with no prototype
in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 491: Call to function 'IF' with no prototype
in function HB_FUN_CGETFILE
hbmk2: Linking... ..\qs-ide.exe
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external '_ISLOGICAL' referenced from D:\QUIQUESOFT\IDE\.HBMK\
WIN\BCC\MAIN.OBJ
Error: Unresolved external '_ISNUM' referenced from D:\QUIQUESOFT\IDE\.HBMK\WIN\
BCC\MAIN.OBJ
Error: Unresolved external '_ISCHAR' referenced from D:\QUIQUESOFT\IDE\.HBMK\WIN
\BCC\MAIN.OBJ
Error: Unresolved external '_PCOUNT' referenced from D:\QUIQUESOFT\IDE\.HBMK\WIN
\BCC\MAIN.OBJ
Error: Unresolved external '_IF' referenced from D:\QUIQUESOFT\IDE\.HBMK\WIN\BCC
\MAIN.OBJ
Error: Unresolved external '_HB_FUN_CURDRIVE' referenced from D:\QUIQUESOFT\IDE\
.HBMK\WIN\BCC\MAIN.OBJ


Pero al menos pasó la compilación, falló porque faltan funciones ¿esas donde las consigo? si es que es correcto que solo quite la línea que quité
Saludos
Quique
User avatar
quique
 
Posts: 408
Joined: Sun Aug 13, 2006 5:38 am

Re: Selección múltiple de archivos

Postby Antonio Linares » Thu Mar 14, 2013 6:24 am

Quique,

Renombra las funciones que comienzan por IS... a HB_IS...

Renombra PCOUNT a hb_pcount()
regards, saludos

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

Re: Selección múltiple de archivos

Postby quique » Thu Mar 14, 2013 2:10 pm

Gracias Antonio, ya mejoró, quedó el fuente así:

Code: Select all  Expand view

* -------------------------------------------------------------
* funciona cGetFile Modificada para seleccionar varios archivos
* -------------------------------------------------------------

FUNCTION SelectFiles()
    LOCAL cCurDir := CurDrive() + ":\" + CurDir() //willy
    LOCAL cFile := CGETFILE( "
*.xml", "Selecciona uno o varios archivos ...", , , , , NOR( OFN_ALLOWMULTISELECT, OFN_EXPLORER, OFN_HIDEREADONLY ) )

    LOCAL aFile := {}

    LOCAL cPath
    local cFile1 := cFile

    IF !EMPTY( cFile )
        cPath = LEFT( cFile, AT( CHR( 0 ), cFile ) - 1 )

        IF RIGHT( cPath, 1 ) != "
\"; cPath += "\"; ENDIF

        WHILE .T.
            cFile = SUBSTR( cFile, AT( CHR( 0 ), cFile ) + 1 )
            IF LEFT( cFile, 1 ) = CHR( 0 ); EXIT; ENDIF
            AADD( aFile, cPath + LEFT( cFile, AT( CHR( 0 ), cFile ) - 1 ) )
        ENDDO

        IF LEN( aFile ) = 1
            aFile[ 1 ] = LEFT( aFile[ 1 ], LEN( aFile[ 1 ] ) - 1 )
        ENDIF
    ENDIF


    && WQOUT( aFile ) && muestra un arreglo en un dialogo.

    DirChange( cCurDir )     //wiliam morales

    * Si solo selecciona un elemento.
    if len( aFile ) = 0 .and. !empty( cFile1 )
       aadd( aFile, cFile1  )
    endif

RETURN ( aFile )


#pragma BEGINDUMP

#include <Windows.h>
#include <CommDlg.h>
//#include <ClipApi.h>
#include <HbApi.h>

static far WORD wIndex;
static far char Title[] = "
Selecciona uno o varios archivos";


HB_FUNC( CGETFILE )          // ( cFileMask, cTitle, nDefaultMask, ;
                             // cInitDir, lSave, lLongNames, nFlags, ;
                             // cIniFile )  --> cFileName
{
   OPENFILENAME ofn;
   LPSTR pFile, pFilter, pDir, pTitle;
   WORD w = 0, wLen;
   BYTE bIndex = ( BYTE ) hb_parni( 3 );
   BOOL bSave = IF( hb_pcount() > 4 && HB_ISLOGICAL( 5 ), hb_parl( 5 ), FALSE );
   BOOL bLongNames = hb_parl( 6 );
   DWORD dwFlags = IF( hb_pcount() > 6 && HB_ISNUM( 7 ), hb_parnl( 7 ), 2060 );

   if( hb_pcount() < 1 )
   {
      hb_retc( "
" );
       return;
   }

   // alloc for title

   pTitle = ( LPSTR ) hb_xgrab( 128 );

   if ( hb_pcount() > 1 && HB_ISCHAR( 2 ) )
   {
      wLen   = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 2 ) );
      memcpy( pTitle, hb_parc( 2 ), wLen );
      * ( pTitle + wLen ) = 0;

   }
   else
   {
      pTitle  = Title;
   }

   // alloc for initial dir

   pDir = ( LPSTR ) hb_xgrab( 128 );

   if ( hb_pcount() > 3 && HB_ISCHAR( 4 ) )
   {
      wLen  = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 4 ) );
      memcpy( pDir, hb_parc( 4 ), wLen );
      * ( pDir + wLen ) = 0;
   }
   else
   {
      * ( pDir ) = 0;
   }

   // alloc for file

   if ( dwFlags & OFN_ALLOWMULTISELECT )
      pFile = ( LPSTR ) hb_xgrab( 32768 );
   else
      pFile = ( LPSTR ) hb_xgrab( 128 );

   if ( hb_pcount() > 7 && HB_ISCHAR( 8 ) )
   {
      wLen = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 8 ) );
      memcpy( pFile, hb_parc( 8 ), wLen );
   }
   else
   {
      wLen = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 1 ) );
      memcpy( pFile, hb_parc( 1 ), wLen );
   }
   * ( pFile + wLen ) = 0;

   // alloc for mask

   pFilter = ( LPSTR ) hb_xgrab( 400 );
   wLen    = ( WORD ) min( ( unsigned long ) 398, hb_parclen( 1 ) );
   memcpy( pFilter, hb_parc( 1 ), wLen );
   * ( pFilter + wLen ) = 0;

   while( * ( pFilter + w ) )
   {
      if( * ( pFilter + w ) == '|' )
      {
         * ( pFilter + w ) = 0;
         if ( hb_pcount() < 8 )
            * (pFile) = 0;
      }
      w++;
   }

   * ( pFilter + wLen  ) = 0;
   * ( pFilter + wLen + 1 ) = 0;

   memset( ( char * ) &ofn, 0, sizeof( OPENFILENAME ) );

   ofn.lStructSize     = sizeof( OPENFILENAME );
   ofn.hwndOwner       = GetActiveWindow();
   ofn.lpstrFilter     = pFilter;
   ofn.lpstrFile       = pFile;
   ofn.lpstrInitialDir = pDir;
   ofn.lpstrTitle      = pTitle;
   ofn.lpstrCustomFilter = 0; // NIL;
   ofn.nFilterIndex    = bIndex ? bIndex: 1;
   ofn.nMaxFile        = dwFlags & OFN_ALLOWMULTISELECT ? 32768 : 128;
   ofn.lpstrFileTitle  = 0; // NIL;
   ofn.Flags           = OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR |
                        IF( bSave, OFN_HIDEREADONLY, 0 ) |
                        IF( bLongNames, OFN_LONGNAMES, 0 );

   if( dwFlags )
      ofn.Flags = dwFlags;

   wIndex = 0;

   if( bSave )
   {
      if( GetSaveFileName( &ofn ) )
         hb_retc( pFile );
      else
         hb_retc( "
" );
   }
   else
   {
      if( GetOpenFileName( &ofn ) )
         if ( dwFlags & OFN_ALLOWMULTISELECT )
            hb_retclen( pFile, 32768 );
         else
            hb_retc( pFile );
      else
         hb_retc( "
" );
   }

   wIndex = ( WORD ) ofn.nFilterIndex;

   hb_xfree( pFilter );
   hb_xfree( pFile );
   hb_xfree( pDir );
   hb_xfree( pTitle );
}

#pragma ENDDUMP



Pero marca estos errores

Warning W8065 ..\\fuentes\\main.prg 427: Call to function 'HB_ISLOGICAL' with no
prototype in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 427: Call to function 'IF' with no prototype
in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 429: Call to function 'IF' with no prototype
in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 521: Call to function 'IF' with no prototype
in function HB_FUN_CGETFILE
Warning W8065 ..\\fuentes\\main.prg 522: Call to function 'IF' with no prototype
in function HB_FUN_CGETFILE
hbmk2: Linking... ..\qs-ide.exe
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
Error: Unresolved external '_HB_ISLOGICAL' referenced from D:\QUIQUESOFT\IDE\.HB
MK\WIN\BCC\MAIN.OBJ
Error: Unresolved external '_IF' referenced from D:\QUIQUESOFT\IDE\.HBMK\WIN\BCC
\MAIN.OBJ
Error: Unresolved external '_HB_FUN_CURDRIVE' referenced from D:\QUIQUESOFT\IDE\
.HBMK\WIN\BCC\MAIN.OBJ


¿Puedes ayudarme por favor?
Saludos
Quique
User avatar
quique
 
Posts: 408
Joined: Sun Aug 13, 2006 5:38 am

Re: Selección múltiple de archivos

Postby sysctrl2 » Thu Mar 14, 2013 8:45 pm

Peron Quique,
se me olvido decirte que la funcion es para xhb.

usas harbour?

saludos-
Cesar Cortes Cruz
SysCtrl Software
Mexico

' Sin +- FWH es mejor "
User avatar
sysctrl2
 
Posts: 955
Joined: Mon Feb 05, 2007 7:15 pm

Re: Selección múltiple de archivos

Postby quique » Thu Mar 14, 2013 8:51 pm

Para el programa en el que lo necesito sí, de hecho, es un programa que originalmente estaba en xHarbour y ahora está en harbour.
Saludos
Quique
User avatar
quique
 
Posts: 408
Joined: Sun Aug 13, 2006 5:38 am

Re: Selección múltiple de archivos

Postby nnicanor » Fri Mar 15, 2013 2:06 am

Haciendo algunos ajustes para poder compilar con Harbour y xHarbour el codigo final funcional queda asi:

Code: Select all  Expand view


#include "fivewin.ch"

#define OFN_HIDEREADONLY 0x4
#define OFN_ALLOWMULTISELECT 0x200
#define OFN_EXPLORER 0x80000


* -------------------------------------------------------------
* funciona cGetFile Modificada para seleccionar varios archivos
* -------------------------------------------------------------

FUNCTION SelectFiles()
    LOCAL cCurDir := CurDrive() + ":\" + CurDir() //willy
    LOCAL cFile := CGETFILE( "
*.xml", "Selecciona uno o varios archivos ...", , , , , NOR( OFN_ALLOWMULTISELECT, OFN_EXPLORER, OFN_HIDEREADONLY ) )

    LOCAL aFile := {}

    LOCAL cPath
    local cFile1 := cFile

    IF !EMPTY( cFile )
        cPath = LEFT( cFile, AT( CHR( 0 ), cFile ) - 1 )

        IF RIGHT( cPath, 1 ) != "
\"; cPath += "\"; ENDIF

        WHILE .T.
            cFile = SUBSTR( cFile, AT( CHR( 0 ), cFile ) + 1 )
            IF LEFT( cFile, 1 ) = CHR( 0 ); EXIT; ENDIF
            AADD( aFile, cPath + LEFT( cFile, AT( CHR( 0 ), cFile ) - 1 ) )
        ENDDO

        IF LEN( aFile ) = 1
            aFile[ 1 ] = LEFT( aFile[ 1 ], LEN( aFile[ 1 ] ) - 1 )
        ENDIF
    ENDIF


    && WQOUT( aFile ) && muestra un arreglo en un dialogo.

    DirChange( cCurDir )     //wiliam morales

    * Si solo selecciona un elemento.
    if len( aFile ) = 0 .and. !empty( cFile1 )
       aadd( aFile, cFile1  )
    endif

RETURN ( aFile )


#pragma BEGINDUMP

#include <Windows.h>
#include <CommDlg.h>
//#include <ClipApi.h>
#include <HbApi.h>

static far WORD wIndex;
static far char Title[] = "
Selecciona uno o varios archivos";


HB_FUNC( CGETFILE )          // ( cFileMask, cTitle, nDefaultMask, ;
                             // cInitDir, lSave, lLongNames, nFlags, ;
                             // cIniFile )  --> cFileName
{
   OPENFILENAME ofn;
   LPSTR pFile, pFilter, pDir, pTitle;
   WORD w = 0, wLen;
   BYTE bIndex = ( BYTE ) hb_parni( 3 );
#ifndef __XHARBOUR__  
   BOOL bSave = hb_pcount() > 4 && HB_ISLOG( 5 ) ? hb_parl( 5 ) : FALSE  ;
#else
   BOOL bSave = hb_pcount() > 4 && ISLOG( 5 ) ? hb_parl( 5 ) : FALSE  ;
#endif
   BOOL bLongNames = hb_parl( 6 );
#ifndef __XHARBOUR__  
   DWORD dwFlags =  hb_pcount() > 6 && HB_ISNUM( 7 ) ?  hb_parnl( 7 ) : 2060 ;
#else
   DWORD dwFlags =  hb_pcount() > 6 && ISNUM( 7 ) ?  hb_parnl( 7 ) : 2060 ;
#endif
   if( hb_pcount() < 1 )
   {
      hb_retc( "
" );
       return;
   }

   // alloc for title

   pTitle = ( LPSTR ) hb_xgrab( 128 );
#ifndef __XHARBOUR__
   if ( hb_pcount() > 1 && HB_ISCHAR( 2 ) )
#else
   if ( hb_pcount() > 1 && ISCHAR( 2 ) )
#endif  
   {
      wLen   = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 2 ) );
      memcpy( pTitle, hb_parc( 2 ), wLen );
      * ( pTitle + wLen ) = 0;

   }
   else
   {
      pTitle  = Title;
   }

   // alloc for initial dir

   pDir = ( LPSTR ) hb_xgrab( 128 );

   if ( hb_pcount() > 3 && HB_ISCHAR( 4 ) )
   {
      wLen  = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 4 ) );
      memcpy( pDir, hb_parc( 4 ), wLen );
      * ( pDir + wLen ) = 0;
   }
   else
   {
      * ( pDir ) = 0;
   }

   // alloc for file

   if ( dwFlags & OFN_ALLOWMULTISELECT )
      pFile = ( LPSTR ) hb_xgrab( 32768 );
   else
      pFile = ( LPSTR ) hb_xgrab( 128 );

   if ( hb_pcount() > 7 && HB_ISCHAR( 8 ) )
   {
      wLen = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 8 ) );
      memcpy( pFile, hb_parc( 8 ), wLen );
   }
   else
   {
      wLen = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 1 ) );
      memcpy( pFile, hb_parc( 1 ), wLen );
   }
   * ( pFile + wLen ) = 0;

   // alloc for mask

   pFilter = ( LPSTR ) hb_xgrab( 400 );
   wLen    = ( WORD ) min( ( unsigned long ) 398, hb_parclen( 1 ) );
   memcpy( pFilter, hb_parc( 1 ), wLen );
   * ( pFilter + wLen ) = 0;

   while( * ( pFilter + w ) )
   {
      if( * ( pFilter + w ) == '|' )
      {
         * ( pFilter + w ) = 0;
         if ( hb_pcount() < 8 )
            * (pFile) = 0;
      }
      w++;
   }

   * ( pFilter + wLen  ) = 0;
   * ( pFilter + wLen + 1 ) = 0;

   memset( ( char * ) &ofn, 0, sizeof( OPENFILENAME ) );

   ofn.lStructSize     = sizeof( OPENFILENAME );
   ofn.hwndOwner       = GetActiveWindow();
   ofn.lpstrFilter     = pFilter;
   ofn.lpstrFile       = pFile;
   ofn.lpstrInitialDir = pDir;
   ofn.lpstrTitle      = pTitle;
   ofn.lpstrCustomFilter = 0; // NIL;
   ofn.nFilterIndex    = bIndex ? bIndex: 1;
   ofn.nMaxFile        = dwFlags & OFN_ALLOWMULTISELECT ? 32768 : 128;
   ofn.lpstrFileTitle  = 0; // NIL;
   ofn.Flags           = OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR |
                         bSave ?  OFN_HIDEREADONLY : 0  |
                         bLongNames ? OFN_LONGNAMES : 0 ;

   if( dwFlags )
      ofn.Flags = dwFlags;

   wIndex = 0;

   if( bSave )
   {
      if( GetSaveFileName( &ofn ) )
         hb_retc( pFile );
      else
         hb_retc( "
" );
   }
   else
   {
      if( GetOpenFileName( &ofn ) )
         if ( dwFlags & OFN_ALLOWMULTISELECT )
            hb_retclen( pFile, 32768 );
         else
            hb_retc( pFile );
      else
         hb_retc( "
" );
   }

   wIndex = ( WORD ) ofn.nFilterIndex;

   hb_xfree( pFilter );
   hb_xfree( pFile );
   hb_xfree( pDir );
   hb_xfree( pTitle );
}

#pragma ENDDUMP




Slds
Nicanor Martinez M.
Auditoria y Sistemas Ltda.
MicroExpress Ltda.
FW + FWH + XHARBOUR + HARBOUR + PELLES C + XDEVSTUDIO + XEDIT + BCC + VC_X86 + VCC_X64 + MINGW + R&R Reports + FastReport + Tdolphin + ADO + MYSQL + MARIADB + ORACLE
nnicanor@yahoo.com
nnicanor
 
Posts: 295
Joined: Fri Apr 23, 2010 4:30 am
Location: Colombia

Re: Selección múltiple de archivos

Postby quique » Fri Mar 15, 2013 5:32 am

Con unas ligeras modificaciones en la función SelectFiles() para poder adaptarlo a mi programa, ya quedó listo y trabajando :)

Solo dos detalles que vale la pena comentar, porque sin ellos no me funcionó:

1. Cambié la función CurDrive() por hb_CurDrive()

2. Modifiqué la línea aadd( aFile, cFile1 ) por aadd( aFile, left( cFile1, at( chr( 0 ), cFile1 ) - 1 ) ), porque si no, tenía problemas cuando solo seleccionaban un archivo.

Muchas gracias, esto ahorrara mucho trabajo, ya me toco meter uno por uno mas de 70 archivos.
Saludos
Quique
User avatar
quique
 
Posts: 408
Joined: Sun Aug 13, 2006 5:38 am

Re: Selección múltiple de archivos

Postby FiveWiDi » Sat Mar 16, 2013 10:16 pm

Hola a todos,

Y para hacerla más genérica, no sería mejor dejarla así:

Code: Select all  Expand view
FUNCTION SelectFiles( cDirSelect, cMascara )
    LOCAL cCurDir := HB_CurDrive() + ":\" + CurDir() //willy
    /* LOCAL cFile := CGETFILE( "
*.xml", "Selecciona uno o varios archivos ...", , , , , NOR( OFN_ALLOWMULTISELECT, OFN_EXPLORER, OFN_HIDEREADONLY ) )*/
    LOCAL cFile := CGETFILE( cMascara, "
Selecciona uno o varios archivos ...", "*.*", cDirSelect, , , NOR( OFN_ALLOWMULTISELECT, OFN_EXPLORER, OFN_HIDEREADONLY ) )

...

Un Saludo
Carlos G.

FiveWin 24.02 + Harbour 3.2.0dev (r2403071241), BCC 7.7 Windows 10
FiveWiDi
 
Posts: 1063
Joined: Mon Oct 10, 2005 2:38 pm

Re: Selección múltiple de archivos

Postby nnicanor » Sat Mar 16, 2013 11:04 pm

Bueno señores, quedo mas que genial ...

Slds
Nicanor Martinez M.
Auditoria y Sistemas Ltda.
MicroExpress Ltda.
FW + FWH + XHARBOUR + HARBOUR + PELLES C + XDEVSTUDIO + XEDIT + BCC + VC_X86 + VCC_X64 + MINGW + R&R Reports + FastReport + Tdolphin + ADO + MYSQL + MARIADB + ORACLE
nnicanor@yahoo.com
nnicanor
 
Posts: 295
Joined: Fri Apr 23, 2010 4:30 am
Location: Colombia


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 7 guests