FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Selecci贸n de m煤ltiples archivos
Posts: 1279
Joined: Mon Feb 06, 2006 04:28 PM
Selecci贸n de m煤ltiples archivos
Posted: Thu Nov 29, 2007 09:36 AM

Hay alguna forma de seleccionar los archivos con cGetFile32 u otra funci贸n de forma "multiselect", es decir usando may煤scula o Ctrl poder seleccionar varios archivos a la vez?

Gracias desde ya.

Saludos/Regards,

Jos茅 Murugosa

"Los errores en programaci贸n, siempre est谩n entre la silla, el teclado y la IA!!"
Posts: 1144
Joined: Mon Feb 05, 2007 07:15 PM
Selecci贸n de m煤ltiples archivos
Posted: Thu Nov 29, 2007 07:00 PM

Jose aca esta un pedazo de codigo,,,

include "Fivewin.ch"

define OFN_HIDEREADONLY 0x4

define OFN_ALLOWMULTISELECT 0x200

define OFN_EXPLORER 0x80000

FUNCTION _multiSelFile()

LOCAL cFile := CGETFILE( "*.*", "Test", , , , , NOR( OFN_ALLOWMULTISELECT, OFN_EXPLORER, OFN_HIDEREADONLY ) )

LOCAL aFile := {}

LOCAL cPath

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 )

RETURN NIL

Cesar Cortes Cruz

SysCtrl Software

Mexico



' Sin +- FWH es mejor "
Posts: 1144
Joined: Mon Feb 05, 2007 07:15 PM
Selecci贸n de m煤ltiples archivos
Posted: Thu Nov 29, 2007 07:02 PM

JOSE

ACA EL COMPLEMENTO,

SACADO DEL FORO EN INGLES

YA LO HE PROBADO FUNCIONA DE PERLAS

SALUDOS..

pragma BEGINDUMP

include <Windows.h>

include <CommDlg.h>

include <ClipApi.h>

include <HbApi.h>

static far WORD wIndex;
static far char Title[] = "Select the file";

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 ) );
_bcopy( 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 ) );
_bcopy( 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 ) );
_bcopy( pFile, hb_parc( 8 ), wLen );
}
else
{
wLen = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 1 ) );
_bcopy( 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 ) );
_bcopy( 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;

_bset( ( 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 "
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Selecci贸n de m煤ltiples archivos
Posted: Thu Nov 29, 2007 10:21 PM
Jose,

I enhanced this version sometime ago, so you can hide the placesbar on the left side of the dialog. See 9th parameter.

Hope it helps.

#pragma BEGINDUMP

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

static far WORD wIndex;
static far char Title[] = "Select the file";
static char szDirName[ MAX_PATH ];

HB_FUNC( CGETFILE )          // ( cFileMask, cTitle, nDefaultMask, ;
                             // cInitDir, lSave, lLongNames, nFlags, ;
                             // cIniFile, lHidePlacesBar  )  --> 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 );
   BOOL bHideBar = IF( PCOUNT() > 8 && ISLOGICAL( 9 ), hb_parl( 9 ), FALSE );   // SH, Sept. 2007

   char cFullName[64][1024];
   char cCurDir[512];
   char cFileName[512];
   int iPosition = 0;
   int iNumSelected = 0;
   int n;
   char buffer[65536];
   DWORD dwErr;

   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 ) );
      _bcopy( 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 ) );
      _bcopy( 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 ) );
      _bcopy( pFile, hb_parc( 8 ), wLen );
   }
   else
   {
      wLen = ( WORD ) min( ( unsigned long ) 127, hb_parclen( 1 ) );
      _bcopy( 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 ) );
   _bcopy( 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;

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

   ofn.lStructSize     = sizeof( OPENFILENAME );
   ofn.hwndOwner       = GetActiveWindow();
   ofn.lpstrFilter     = pFilter;
   ofn.lpstrFile       = buffer; //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;

   if( bHideBar )
      ofn.FlagsEx = OFN_EX_NOPLACESBAR;  // SH Sept. 2007

   wIndex = 0;
   buffer[0] = 0 ;

   if( bSave )
   {
      if( GetSaveFileName( &ofn ) )
         hb_retc( pFile );
      else
         hb_retc( "" );
   }
   else
   {
      if( GetOpenFileName( &ofn ) )
         if ( dwFlags & OFN_ALLOWMULTISELECT )
            //hb_retclen( pFile, 32768 );
           {
             wsprintf(cCurDir,"%s\\",&buffer[iPosition]);
             iPosition=iPosition+strlen(cCurDir);//+1;

             do
             {
                iNumSelected++;
                wsprintf(cFileName,"%s",&buffer[iPosition]);
                iPosition=iPosition+strlen(cFileName)+1;
                wsprintf(cFullName[iNumSelected],"%s\%s",cCurDir,cFileName);
             }
             while(  (strlen(cFileName)!=0) && ( iNumSelected <= 63 ) );

             if(iNumSelected > 1)
             {
                hb_reta( iNumSelected - 1 );

                for (n = 1; n < iNumSelected; n++)
                {
                   hb_storc( cFullName[n], -1, n );
                }
             }
             else
             {
                hb_retc( &buffer[0] );
             }
           }
         else
            hb_retc( &buffer[0] ); //( pFile );
      else
        {
         dwErr = CommDlgExtendedError();         // get error code
         hb_retni( dwErr );
        }
   }

   //wIndex = ( WORD ) ofn.nFilterIndex;

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

#pragma ENDDUMP
kind regards

Stefan
Posts: 1279
Joined: Mon Feb 06, 2006 04:28 PM
Selecci贸n de m煤ltiples archivos
Posted: Fri Nov 30, 2007 12:44 AM

Queridos amigos del Foro, Gracias por compartir su conocimiento conmigo ayud谩ndome en la tarea de desarrollo.

Es una dicha contar con colegas que con tan buena y desinteresada disposici贸n nos ayudan en la tarea diaria.

MUCHAS GRACIAS !!!! :D

Pondr茅 en pr谩ctica sus recomendaciones y aportes.

Saludos/Regards,

Jos茅 Murugosa

"Los errores en programaci贸n, siempre est谩n entre la silla, el teclado y la IA!!"

Continue the discussion