Code: Select all
#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