FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Error set the cgetfile function: resoved !!!
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Error set the cgetfile function: resoved !!!
Posted: Fri Jun 19, 2015 08:24 AM
I made :
Code (fw): Select all Collapse
 local gcFile := cGetFile( "Immagini (*.gif , *.jpg , *.jpeg, *. png , *.bmp)| *.gif , *.jpg , *.jpeg, *. png , *.bmp|" + ;
                              "Documenti Pdf (*.pdf)|*.pdf |"  +;
                              "Documenti OpenOffice (*.odt,*.ods,*.odp, *.sxw, *.sxc,*. sxi )|*.odt,*.ods,*.odp, *.sxw, *.sxc,*. sxi|"+   ;
                              "Documenti Ms Office ( *.doc,*.xls,*.ppt,*.docx,*.xlsx,*.pptx)|*.doc, *.xls, *.ppt, *.docx,*.xlsx,*.pptx|"+ ;
                              "Tutti i file (*.*)| *.*"             ;
                             ,"Per favore seleziona un file", 4 )


it run but if I select Ms Office documents it not show this type of document on the folder I select why ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Error set the cgetfile function
Posted: Fri Jun 19, 2015 08:49 AM
Silvio,

Where have you seen that you can select multiple types at types separating the types with "," ?

Here you have a working example:

Code (fw): Select all Collapse
cGetFile( FWString( "Program file" ) + ;
                                  " (*.prg) |*.prg|" + ;
                                  FWString( "Header file" ) + ;
                                  " (*.ch) |*.ch|" + ;
                                  FWString( "Resource file" ) + ;
                                  " (*.rc) |*.rc|" + ;
                                  FWString( "Open any file" ) + ;
                                  " (*.*) |*.*|",;
                                  FWString( "Select a file to open" ) )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Error set the cgetfile function
Posted: Fri Jun 19, 2015 09:57 AM
Antonio Linares wrote:Silvio,

Where have you seen that you can select multiple types at types separating the types with "," ?



Antonio,

I saw it on a delphi application


I wish create on fwh this



how I must create it ?





for cgettfile multiple I have a Stephan Haupt function
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_ALLOWMULTISELECT         0x00000200
#define OFN_EXTENSIONDIFFERENT       0x00000400
#define OFN_PATHMUSTEXIST            0x00000800
#define OFN_FILEMUSTEXIST            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_ALLOWMULTISELECT, 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 <ClipApi.h>
#include <HbApi.h>
//#include <shlobj.h>

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( 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 );

   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;

   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
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: Error set the cgetfile function
Posted: Fri Jun 19, 2015 10:53 AM
On OPENFILENAME you can separate the filters by a semicolon ";"
This code works:
Code (fw): Select all Collapse
local gcFile := cGetFile( "Immagini (*.gif , *.jpg , *.jpeg, *. png , *.bmp)|*.gif;*.jpg;*.jpeg;*.png;*.bmp|" + ;
                              "Documenti Pdf (*.pdf)|*.pdf|"  +;
                              "Documenti OpenOffice (*.odt,*.ods,*.odp, *.sxw, *.sxc,*. sxi )|*.odt;*.ods;*.odp;*.sxw;*.sxc;*.sxi|"+   ;
                              "Documenti Ms Office ( *.doc,*.xls,*.ppt,*.docx,*.xlsx,*.pptx)|*.doc;*.xls;*.ppt;*.docx;*.xlsx;*.pptx|"+ ;
                              "Tutti i file (*.*)|*.*";
                             ,"Per favore seleziona un file", 4 )

I removed spaces in filters list and substituted all comma with semicolon.
Regards,
Antonino
Posts: 9020
Joined: Thu Oct 06, 2005 08:17 PM
Re: Error set the cgetfile function
Posted: Fri Jun 19, 2015 10:57 AM
Silvio,

this is working fine here:

Code (fw): Select all Collapse
cFile = CGETFILE( "Image files|*.bmp;*.gif;*.ico;*.jpg;*.png;*.tif", "Open an image file", , CURDRIVE() + "\" + cPath )


EMG
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Error set the cgetfile function
Posted: Fri Jun 19, 2015 01:28 PM

Enrico I need to open :
Image -> bmp, jpg, jpeg png gif
msoffice document doc xls ppt docx pptx xlsx
openoffice document .odt,.ods,.odp, .sxw, .sxc,. sxi

I need it for a Optical Archive of School

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Error set the cgetfile function
Posted: Fri Jun 19, 2015 01:39 PM
resolved !!!!!!!!!!!!!!

local gcFile := CGETFILE( "Immagini(*.bmp,*.gif,*.jpg,*.png,*.tif)|*.bmp;*.gif;*.jpg;*.png;*.tif|"+;
"Documenti Pdf(*.pdf)|*.pdf| "+ ;
"Documenti MsOffice( *.doc,*.xls,*.ppt,*.docx,*.xlsx,*.pptx)|*.doc;*.xls;*.ppt;*.docx;*.xlsx;*.pptx |"+ ;
"Documenti OpenOffice (*.odt,*.ods,*.odp, *.sxw, *.sxc,*. sxi )|*.odt;*.ods;*.odp;*.sxw;*.sxc;*. sxi|"+ ;
"Tutti i file (*.*)| *.*", ;
"Per favore seleziona un file", , CURDRIVE() + "\" + cPath )
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Error set the cgetfile function: resoved !!!
Posted: Fri Jun 19, 2015 04:43 PM

very good, thanks! :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Re: Error set the cgetfile function
Posted: Fri Jun 19, 2015 08:30 PM
Silvio.Falconi wrote:resolved !!!!!!!!!!!!!!

local gcFile := CGETFILE( "Immagini(*.bmp,*.gif,*.jpg,*.png,*.tif)|*.bmp;*.gif;*.jpg;*.png;*.tif|"+;
"Documenti Pdf(*.pdf)|*.pdf| "+ ;
"Documenti MsOffice( *.doc,*.xls,*.ppt,*.docx,*.xlsx,*.pptx)|*.doc;*.xls;*.ppt;*.docx;*.xlsx;*.pptx |"+ ;
"Documenti OpenOffice (*.odt,*.ods,*.odp, *.sxw, *.sxc,*. sxi )|*.odt;*.ods;*.odp;*.sxw;*.sxc;*. sxi|"+ ;
"Tutti i file (*.*)| *.*", ;
"Per favore seleziona un file", , CURDRIVE() + "\" + cPath )


Gracias por el aporte, me vino como anillo al dedo, casualidad que estaba trabajando en un sistema y necesite algo como eso y me ayudo bastante, saludos... :-)
Dios no está muerto...



Gracias a mi Dios ante todo!
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: Error set the cgetfile function: resoved !!!
Posted: Sat Jun 20, 2015 07:01 AM

With it I can select only one file one step ....

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Error set the cgetfile function: resoved !!!
Posted: Sun Jun 21, 2015 01:57 AM

To select more files at a time, use aGetFiles(....) with the same syntax.

Regards



G. N. Rao.

Hyderabad, India

Continue the discussion