Select more files

Select more files

Postby MarcoBoschi » Fri Oct 30, 2009 8:13 am

Dear friends,
is there a function that return an array of selected files?
something like aFile := cGeMoretFile() ?

Thanks in advance
User avatar
MarcoBoschi
 
Posts: 1015
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Select more files

Postby Enrico Maria Giordano » Fri Oct 30, 2009 8:25 am

This is a working sample (warning: it may have some limits):

Code: Select all  Expand view
#include "Fivewin.ch"


FUNCTION MAIN()

    LOCAL aFiles := CGETFILEEX( "Tutti i file (*.*)|*.*", "Copia da", , CURDRIVE() + ":\" + CURDIR() )

    IF VALTYPE( aFiles ) = "
C"
        ? aFiles
    ELSE
        ? LEN( aFiles )
        WQOUT( aFiles )
    ENDIF

    RETURN NIL


#pragma BEGINDUMP
#include "
windows.h"
#include "
hbapi.h"
#include <shlobj.h>

//static far char IniDir[] = "
.\\";
static char szDirName[ MAX_PATH ];
void cdecl _bcopy( void *, void *, unsigned int );
static far char Title[] = "
Select the file";

HB_FUNC ( CGETFILEEX )    
{
   OPENFILENAME ofn;
   char buffer[65536];
   char cFullName[64][1024];
   char cCurDir[512];
   char cFileName[512];
   int iPosition = 0;
   int iNumSelected = 0;
   int n;
   LPSTR  pFile,pFilter,pTitle,pDir;
   WORD w = 0, wLen;
   int flags =  OFN_ALLOWMULTISELECT | OFN_EXPLORER ; //OFN_FILEMUSTEXIST  |

   buffer[0] = 0 ;

   pTitle = ( LPSTR ) hb_xgrab( 128 );

   if ( hb_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;
   }

   pDir = ( LPSTR ) hb_xgrab( 128 );

   if ( hb_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;
   }

   pFile = ( LPSTR ) hb_xgrab( 255 );

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

   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 ( hb_pcount() < 8 )
            * (pFile) = 0;
      }
      w++;
   }

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


   memset( (void*) &ofn, 0, sizeof( OPENFILENAME ) );
   ofn.lStructSize = sizeof(ofn);
   ofn.hwndOwner = GetActiveWindow();
   ofn.lpstrFilter = pFilter;
   ofn.nFilterIndex = 1;
   ofn.lpstrFile = buffer;
   ofn.nMaxFile = sizeof(buffer);
   ofn.lpstrInitialDir = hb_parc(3);
   ofn.lpstrTitle = pTitle;
   ofn.nMaxFileTitle = 512;
   ofn.Flags = flags;

   if( GetOpenFileName( &ofn ) )
   {
      if(ofn.nFileExtension!=0)
      {
         hb_retc( ofn.lpstrFile );
      }
      else
      {
         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( "
" );
   }
}

INT CALLBACK BrowseCallbackProc(HWND hwnd,
                                UINT uMsg,
                                LPARAM lp,
                                LPARAM pData)
{
   switch(uMsg)
   {
   case BFFM_INITIALIZED:
      if (szDirName)
      {
         // WParam is TRUE since you are passing a path.
         // It would be FALSE if you were passing a pidl.
         SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szDirName);
      }
      break;
   }
   return 0;
}

#pragma ENDDUMP


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Select more files

Postby MarcoBoschi » Fri Oct 30, 2009 8:42 am

Enrico,
Thanks
When I compile I have this

xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6569)
Copyright 1999-2009, http://www.xharbour.org http://www.harbour-project.org/
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
morefiles.c:
Warning W8057 morefiles.prg 175: Parameter 'lp' is never used in function BrowseCallbackProc
Warning W8057 morefiles.prg 175: Parameter 'pData' is never used in function BrowseCallbackProc
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
User avatar
MarcoBoschi
 
Posts: 1015
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Select more files

Postby Enrico Maria Giordano » Fri Oct 30, 2009 8:53 am

You can safely ignore those warnings.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Select more files

Postby lailton.webmaster » Fri Oct 30, 2009 8:56 am

I use this and work very fine to me.

fun.prg
Code: Select all  Expand view
#pragma BEGINDUMP
#include "windows.h"
#include "hbapi.h"
#include <shlobj.h>

static far char IniDir[] = ".\\";
static char szDirName[ MAX_PATH ];
void cdecl _bcopy( void *, void *, unsigned int );
static far char Title[] = "Select the file";

HB_FUNC ( CGETFILEX )  
{
   OPENFILENAME ofn;
   char buffer[65536];
   char cFullName[64][1024];
   char cCurDir[512];
   char cFileName[512];
   int iPosition = 0;
   int iNumSelected = 0;
   int n;
   LPSTR  pFile,pFilter,pTitle,pDir;
   WORD w = 0, wLen;
   int flags =  OFN_ALLOWMULTISELECT | OFN_EXPLORER ; //OFN_FILEMUSTEXIST  |

   buffer[0] = 0 ;

   pTitle = ( LPSTR ) hb_xgrab( 128 );

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

   }
   else
   {
      pTitle  = Title;
   }

   pDir = ( LPSTR ) hb_xgrab( 128 );

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

   pFile = ( LPSTR ) hb_xgrab( 255 );

   if ( hb_pcount() > 7 && ISCHAR( 8 ) )
   {
      wLen = min( ( unsigned long ) 254, hb_parclen( 8 ) );
      _bcopy( pFile, hb_parc( 8 ), wLen );
   }
   else
   {
      wLen = min( ( unsigned long ) 254, hb_parclen( 1 ) );
      _bcopy( pFile, hb_parc( 1 ), wLen );
   }
   * ( pFile + wLen ) = 0;

   pFilter = ( LPSTR ) hb_xgrab( 400 );
   wLen    = 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 ( hb_pcount() < 8 )
            * (pFile) = 0;
      }
      w++;
   }

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


   memset( (void*) &ofn, 0, sizeof( OPENFILENAME ) );
   ofn.lStructSize = sizeof(ofn);
   ofn.hwndOwner = GetActiveWindow();
   ofn.lpstrFilter = pFilter;
   ofn.nFilterIndex = 1;
   ofn.lpstrFile = buffer;
   ofn.nMaxFile = sizeof(buffer);
   ofn.lpstrInitialDir = hb_parc(3);
   ofn.lpstrTitle = pTitle;
   ofn.nMaxFileTitle = 512;
   ofn.Flags = flags;

   if( GetOpenFileName( &ofn ) )
   {
      if(ofn.nFileExtension!=0)
      {
         hb_retc( ofn.lpstrFile );
      }
      else
      {
         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( "" );
   }
}

INT CALLBACK BrowseCallbackProc(HWND hwnd,
                                UINT uMsg,
                                LPARAM lp,
                                LPARAM pData)
{
   switch(uMsg)
   {
   case BFFM_INITIALIZED:
      if (szDirName)
      {
         // WParam is TRUE since you are passing a path.
         // It would be FALSE if you were passing a pidl.
         SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szDirName);
      }
      break;
   }
   return 0;
}

#pragma ENDDUMP
 


To use:

cFile:= cGetFileX( "HTML (*.htm)| *.htm|PHP (*.php)| *.php|CSS (*.css)| *.css|Todos (*.*)| *.*|", "Selecione um Arquivo", 1 )


:D
lailton.webmaster
 
Posts: 603
Joined: Sun May 04, 2008 8:44 pm

Re: Select more files

Postby anserkk » Fri Oct 30, 2009 9:16 am

Why don't we have this Multiple File Selection function included in the FWH build itself.

Regards
Anser
User avatar
anserkk
 
Posts: 1329
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Re: Select more files

Postby MarcoBoschi » Fri Oct 30, 2009 9:34 am

I agree
Thanks to all
Marco
User avatar
MarcoBoschi
 
Posts: 1015
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Select more files

Postby MarcoBoschi » Fri Oct 30, 2009 9:48 am

new error:
I copy your sample into a program and compile....
This is complier response.

xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6569)
Copyright 1999-2009, http://www.xharbour.org http://www.harbour-project.org/
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
crypt2.c:
Error E2356 crypt2.prg 371: Type mismatch in redeclaration of '_bcopy'
Error E2344 c:\fwh\include\fwHarb.h 21: Earlier declaration of '_bcopy'
Warning W8057 crypt2.prg 521: Parameter 'lp' is never used in function BrowseCallbackProc
Warning W8057 crypt2.prg 521: Parameter 'pData' is never used in function BrowseCallbackProc
*** 2 errors in Compile ***



369 //static far char IniDir[] = ".\\";
370 static char szDirName[ MAX_PATH ];
371 void cdecl _bcopy( void *, void *, unsigned int );
372 static far char Title[] = "Select the file";
User avatar
MarcoBoschi
 
Posts: 1015
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Select more files

Postby Enrico Maria Giordano » Fri Oct 30, 2009 10:11 am

Why are you including fwharb.h?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Select more files

Postby MarcoBoschi » Fri Oct 30, 2009 10:35 am

I ....don't know
Sorry
User avatar
MarcoBoschi
 
Posts: 1015
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Select more files

Postby MarcoBoschi » Fri Oct 30, 2009 10:40 am

Enrico,
I found this

...
SETFTIME( hFile, cTime, cDate )
...


#pragma BEGINDUMP

#include <windows.h>
#include <hbapi.h>
#include <clipapi.h>


static WORD CharsToWord( LPSTR pChars )
{
WORD w = 0;

if( pChars[ 0 ] != '0' )
w = ( WORD ) ( ( pChars[ 0 ] - '0' ) * 10 );

if( pChars[ 1 ] != '0' )
w += ( WORD ) ( ( pChars[ 1 ] - '0' ) );

return w;
}


static WORD CharsToLong( LPSTR pChars )
{
LONG l = 0;

if( pChars[ 0 ] != '0' )
{
l = ( ( pChars[ 0 ] - '0' ) * 100 );
l *= 10; // Borland C++ bug
}

if( pChars[ 1 ] != '0' )
l += ( ( pChars[ 1 ] - '0' ) * 100 );

if( pChars[ 2 ] != '0' )
l += ( ( pChars[ 2 ] - '0' ) * 10 );

if( pChars[ 3 ] != '0' )
l += ( pChars[ 3 ] - '0' );

return ( WORD ) l;
}


HB_FUNC( SETFTIME ) // ( nFileHandle, cTime, dDate ) --> lSuccess
{
void * wHandle = ( void * ) hb_parnl( 1 );
SYSTEMTIME st;
FILETIME ft;
LPSTR pTime = hb_parc( 2 );
LPSTR pDate = IF( ISDATE( 3 ), hb_pards( 3 ), hb_parc( 3 ) );

_bset( ( char * ) &st, 0, sizeof( st ) );

if( pDate )
{
st.wDay = CharsToWord( pDate + 6 );
st.wMonth = CharsToWord( pDate + 4 );
st.wYear = CharsToLong( pDate );
}
if( pTime )
{
st.wHour = CharsToWord( pTime );
st.wMinute = CharsToWord( pTime + 3 );
st.wSecond = CharsToWord( pTime + 6 );
st.wMilliseconds = 0;
}

SystemTimeToFileTime( &st, &ft );
hb_retl( SetFileTime( wHandle, &ft, &ft, &ft ) );
}

#pragma ENDDUMP
User avatar
MarcoBoschi
 
Posts: 1015
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Select more files

Postby Enrico Maria Giordano » Fri Oct 30, 2009 11:30 am

SETFTIME() has nothing to do with CGETFILEEX(), or am I missing something?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Select more files

Postby MarcoBoschi » Fri Oct 30, 2009 1:42 pm

Roger!
I need function CGETFILEEX in a program where there is SETFTIME( hFile, cTime, cDate ) too!
Thanks
User avatar
MarcoBoschi
 
Posts: 1015
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy

Re: Select more files

Postby Enrico Maria Giordano » Fri Oct 30, 2009 5:35 pm

Ok, but there's not #include fwharb.h in SETFTIME(). Or am I missing it?

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8315
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Select more files

Postby MarcoBoschi » Tue Nov 03, 2009 8:24 am

Enrico,
case solved
Thank You very much.

Marco
User avatar
MarcoBoschi
 
Posts: 1015
Joined: Thu Nov 17, 2005 11:08 am
Location: Padova - Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 91 guests