FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour cGetFile() and Multiple file selection
Posts: 392
Joined: Tue Mar 10, 2009 11:54 AM
Re: cGetFile() and Multiple file selection
Posted: Thu Apr 30, 2009 11:38 AM
Anser,

the parameter <nDefaultMask>

is an optional numeric value in case that you want to start the DialogBox with a certain file type selected (if you are using the multiple file types format). To request lately what was the file type selected, you may use the function nGetFileFilter().
Windows 11 Pro 22H2 22621.1848

Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384

Harbour 3.2.0dev (r2008190002)

FWH 23.10 x86
Posts: 824
Joined: Thu Oct 13, 2005 07:39 AM
Re: cGetFile() and Multiple file selection
Posted: Thu Apr 30, 2009 08:06 PM
Anser,
if you wan only jpg files to be listet,you can do it this way:

Code (fw): Select all Collapse
cGetFileX ("Pictures|*.jpg" ,"Select pictures", , "C:\", lSave, .T., nFlag,"*.*",.t. )
kind regards

Stefan
Posts: 654
Joined: Mon May 29, 2006 03:14 PM
Re: cGetFile() and Multiple file selection
Posted: Mon Apr 04, 2016 09:46 PM
Compilando el ejemplo con BCC7 y FWH1602 me da estos errores:

Code (fw): Select all Collapse
Error E2209 cGetFileMultiple.prg 64: Unable to open include file 'ClipApi.h'
Warning W8065 cGetFileMultiple.prg 80: Call to function 'PCOUNT' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 80: Call to function 'ISLOGICAL' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 80: Call to function 'IF' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 82: Call to function 'PCOUNT' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 82: Call to function 'IF' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 83: Call to function 'PCOUNT' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 83: Call to function 'ISLOGICAL' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 83: Call to function 'IF' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 94: Call to function 'PCOUNT' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 103: Call to function 'PCOUNT' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 106: Call to function '_bcopy' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 117: Call to function 'PCOUNT' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 120: Call to function '_bcopy' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 134: Call to function 'PCOUNT' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 137: Call to function '_bcopy' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 142: Call to function '_bcopy' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 149: Call to function '_bcopy' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 157: Call to function 'PCOUNT' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 166: Call to function '_bset' with no prototype in function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 179: Call to function 'IF' with no prototypein function HB_FUN_CGETFILEX
Warning W8065 cGetFileMultiple.prg 180: Call to function 'IF' with no prototypein function HB_FUN_CGETFILEX

Alguna idea.
Gracias.
Mi abuelo dec铆a: Los aviones vuelan porque Dios quiere, y los helic贸pteros ni Dios sabe porque vuelan.

FWH 16.02, xHarbour 1.2.3, Harbour 3.2.0, WorkShop 4.5, AJ Make 0.30, Borlan BCC 7.00, VisualStudio 2013
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cGetFile() and Multiple file selection
Posted: Tue Apr 05, 2016 08:33 AM

Cambia clipapi.h por hbapi.h

Copia aqui el c贸digo y lo reviso

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: cGetFile() and Multiple file selection
Posted: Tue Apr 05, 2016 10:46 AM
There is already a ready made function in FWH since long
Code (fw): Select all Collapse
aGetFiles( cMask, cTitle, nDefaultMask, cInitDir ) --> aFiles

It is much simpler to use this function than re-inventing the wheel.
Regards



G. N. Rao.

Hyderabad, India
Posts: 654
Joined: Mon May 29, 2006 03:14 PM
Re: cGetFile() and Multiple file selection
Posted: Tue Apr 05, 2016 06:46 PM
Antonio Linares wrote:Cambia clipapi.h por hbapi.h
Me da los mismos errores excepto el de ClipApi.h.

Antonio Linares wrote:Copia aqui el c贸digo y lo reviso
Es el c贸digo del segundo mensaje de este tema (p谩g. 1) viewtopic.php?f=3&t=15004#p77571
Mi abuelo dec铆a: Los aviones vuelan porque Dios quiere, y los helic贸pteros ni Dios sabe porque vuelan.

FWH 16.02, xHarbour 1.2.3, Harbour 3.2.0, WorkShop 4.5, AJ Make 0.30, Borlan BCC 7.00, VisualStudio 2013
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: cGetFile() and Multiple file selection
Posted: Tue Apr 05, 2016 07:03 PM
Quitados los warnings pero aun asi da error en tiempo de ejecuci贸n:

Code (fw): Select all Collapse
#define OFN_READONLY                 0x00000001
#define OFN_OVERWRITEPROMPT          0x00000002
#define OFN_HIDEREADONLY             0x00000004
#define OFN_NOCHANGEDIR              0x00000008
#define OFN_SHOWHELP                 0x00000010
#define OFN_ENABLEHOOK               0x00000020
#define OFN_ENABLETEMPLATE           0x00000040
#define OFN_ENABLETEMPLATEHANDLE     0x00000080
#define OFN_NOVALIDATE               0x00000100
#define OFN_ALLOWMULTHB_ISELECT         0x00000200
#define OFN_EXTENSIONDIFFERENT       0x00000400
#define OFN_PATHMUSTEXHB_IST            0x00000800
#define OFN_FILEMUSTEXHB_IST            0x00001000
#define OFN_CREATEPROMPT             0x00002000
#define OFN_SHAREAWARE               0x00004000
#define OFN_NOREADONLYRETURN         0x00008000
#define OFN_NOTESTFILECREATE         0x00010000
#define OFN_NONETWORKBUTTON          0x00020000
#define OFN_NOLONGNAMES              0x00040000     // force no long names for 4.x modules
#define OFN_EXPLORER                 0x00080000     // new look commdlg
#define OFN_NODEREFERENCELINKS       0x00100000
#define OFN_LONGNAMES                0x00200000     // force long names for 3.x modules
#define OFN_ENABLEINCLUDENOTIFY      0x00400000     // send include message to callback
#define OFN_ENABLESIZING             0x00800000
#define OFN_DONTADDTORECENT          0x02000000
#define OFN_FORCESHOWHIDDEN          0x10000000    // Show All files including System and hidden files
#define  OFN_EX_NOPLACESBAR         0x00000001  // show the left bar, called "placesbar"



FUNCTION SelectFiles ()

local cFile, i
LOCAL nFlag := nOR( OFN_ALLOWMULTHB_ISELECT, OFN_HIDEREADONLY, OFN_EXPLORER )
LOCAL lSave := .f.
LOCAL cPath
LOCAL aFiles := {}

cFile := cGetFileX ("All | *.*" ,"Select the files to backup", "*.*", "C:\", lSave, .T., nFlag,"*.*",.t. )

if EMPTY( cFile ) .or. Valtype (cFile) = "N" // Errorcode
  MsgAlert ("Common Dialogbox Error: "+ Str (cFile,6))
endif

IF Valtype(cFile) = "A"
  FOR i := 1 TO Len (cFile)
    cFile[i] := IIF (SubStr (cFile[i],4,1)=="\",cFileDISc (cFile[i])+"\"+cFileName (cFile[i]),cFile[i])
    AAdd (aFiles, cFile[i])
  NEXT
ELSE
   AAdd (aFiles, cFile)
ENDIF

RETURN (aFiles)

//------------------------------------------------------------------//
#pragma BEGINDUMP

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

#define IF(x,y,z) ((x)?(y):(z))

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

HB_FUNC( CGETFILEX )          // ( 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( hb_pcount() > 4 && HB_ISLOG( 5 ), hb_parl( 5 ), FALSE );
   BOOL bLongNames = hb_parl( 6 );
   DWORD dwFlags = IF( hb_pcount() > 6 && HB_ISNUM( 7 ), hb_parnl( 7 ), 2060 );
   BOOL bHideBar = IF( hb_pcount() > 8 && HB_ISLOG( 9 ), hb_parl( 9 ), FALSE );

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

   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       = 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;

   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_storvc( 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: cGetFile() and Multiple file selection
Posted: Tue Apr 05, 2016 08:20 PM
Code (fw): Select all Collapse
#include 'fivewin.ch'

#define OFN_PATHMUSTEXIST            0x00000800
#define OFN_NOCHANGEDIR              0x00000008
#define OFN_ALLOWMULTISELECT         0x00000200
#define OFN_EXPLORER                 0x00080000     // new look commdlg
#define OFN_LONGNAMES                0x00200000     // force long names for 3.x modules
#define OFN_ENABLESIZING             0x00800000
#define OFN_HIDEREADONLY             0x00000004     // Oculta a caixa de sele莽茫o Somente leitura.
#define OFN_NONETWORKBUTTON          0x20000        // Desabilita o bot茫o [ REDE ] da Dlg

function aGetFiles( cMask, cTitle, nDefaultMask, cInitDir )

   local cSelect, nAt, aFiles := {}
   /*
   local nFlags   := nOr( OFN_PATHMUSTEXIST , OFN_NOCHANGEDIR , ;
                     OFN_ALLOWMULTISELECT , OFN_EXPLORER , ;
                     OFN_LONGNAMES, OFN_ALLOWMULTISELECT )
   */
   local nFlags   := nOr( OFN_PATHMUSTEXIST, OFN_NOCHANGEDIR, OFN_ALLOWMULTISELECT, ;
                          OFN_LONGNAMES, OFN_NONETWORKBUTTON )

   SKINBUTTONS()

   //cSelect  := cGetFile( cMask, cTitle, nDefaultMask, cInitDir, .f., .t., nFlags )
   cSelect := cGetFile( "Bitmap (*.bmp)| *.bmp|"+      ;
                        "DIB   (*.dib)| *.dib|" +      ;
                        "PCX   (*.pcx)| *.pcx|" +      ;
                        "JPEG  (*.jpg)| *.jpg|" +      ;
                        "GIF   (*.gif)| *.gif|" +      ;
                        "TARGA (*.tga)| *.tga|" +      ;
                        "RLE   (*.rle)| *.rle|" +      ;
                        "Todos os Arquivos (*.*)|*.*|" ;
                        ,"Selecione a Foto Desejada",1,,.F.,, nFlags )

   cSelect  := Left( cSelect, At( Chr( 0 ) + Chr( 0 ), cSelect ) - 1 )

   if ! Empty( cSelect )
      cSelect  := StrTran( cSelect, Chr( 0 ), "," )
      aFiles  := hb_aTokens( cSelect, "," )
      if Len( aFiles ) > 1
         for nAt := 2 TO Len( aFiles )
            aFiles[ nAt ] := aFiles[ 1 ] + "\" + aFiles[ nAt ]
         next nAt
         ADel( aFiles, 1 )
         ASize( aFiles, Len( aFiles ) - 1 )
      endif
   endif

return aFiles


Jo茫o Santos - S茫o Paulo - Brasil - Phone: +55(11)95150-7341

Continue the discussion