Una de cGetFile()

Una de cGetFile()

Postby Yannis » Fri Oct 07, 2005 5:23 pm

Hola a todos !
Tengo un problema con cGetFile()
En modo seleccionar UN solo archivo, todo funciona .
En modo multiseleccion , me deja seleccionar mas archivos, pero me devuelve SOLO la ruta donde estan los archivos !

FWH 2.5 + xHarbour + Borland + Windows XP pro
Esta es la funcion que uso :

Code: Select all  Expand view
// Function YGetFile
Function YGetFile(cFileName)
   local cFile,  cFileMask, cTitle
   Local nDefaultMask, cInitDir, nFlags,  cIniFile, lSave
   Local lLongNames
   MemVar oApp

   cTitle       := "Select file"
   cFileMask    := "Jpeg   (*.jpg) |*.jpg|" + ;
                   "Bitmap (*.bmp) |*.bmp|" + ;
                   "Tiff   (*.tif)  |*.tif|" + ;
                   "Gif    (*.gif)  |*.gif|"

   cTitle       := "Select a photo"
   nDefaultMask := 1
   cInitDir     := ".\"
   nFlags       := OFN_ALLOWMULTISELECT + OFN_EXPLORER   // 512 + 524288
   cIniFile     := ""
   cFileName    := ""
   lSave        := .f.
   lLongNames   := .t.

   cFile        := Space(32000)

   //cGetFile( <cFileMask>, <cTitle>, [<nDefaultMask>], [<cInitialDirectory>], [lSave], [lLongNames], [nFlags] )  --> <cFileName>
   cFile := cGetFile(cFileMask,;
                     cTitle,;
                     nDefaultMask,;
                     cInitDir,;
                     lSave,;
                     lLongNames,;
                     nFlags)

   ? cfile

   If Empty(cFile)
      cFile := cFileName
   Endif
Return cFile



Alguien tiene una solucion ?
De antemano muchas gracias por su ajuda :-)
Un saludo
Last edited by Yannis on Fri Oct 21, 2005 5:03 pm, edited 2 times in total.
User avatar
Yannis
 
Posts: 13
Joined: Fri Oct 07, 2005 2:41 pm
Location: Greece

cGetFile multiple

Postby Paco Garcia » Sat Oct 08, 2005 9:20 am

Hola, pues algo asi me paso a mi. Copiando de aqui y de allí conseguí sacar esta función que creo que funciona.

Si alguien la quiere mejorar pues... la compartiremos todos.

Un saludo

Paco García

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

User avatar
Paco Garcia
 
Posts: 172
Joined: Fri Oct 07, 2005 12:00 pm

Postby Guest » Sat Oct 08, 2005 10:14 am

Hola Paco !
Ya me hice unas pruebas.
Funciona muy bien ! :-)
Excellente la solucion la de revolver un array de archivos !

Un problemita :
Cuando la seleccion es de UN solo archivo, devuelve un array con las letras del nombre del archivo.
Nada para preocuparse. Hago un check para ver si los elementos del array
tienen un solo caratter.

Ya me salvaste el dia :D :D
Muchas gracias por tu tiempo y por este aporte..
Un saludo
Yannis Yannas
http://www.trinityvision.gr
Guest
 

Se puede arreglar la clase Original ;-)

Postby jesus » Thu Oct 20, 2005 5:03 pm

Ya que hay un parche que funciona, mas o menos... Necesita que se le pasen ciertos parametros para que sea igual que la clase original.

Antonio !
¿ por que no se puede arreglar la clase original ?
Necesito la multiple selección, pero tambien la normal y que le pueda pasar los flags...

Un saludo
Dpto.Desarrollos eTi
Jesús Díez González
Villajoyosa (Alicante)
User avatar
jesus
 
Posts: 21
Joined: Fri Oct 07, 2005 5:13 am
Location: Villajoyosa-Alicante(España)


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 27 guests