Page 2 of 3

Re: Help with PutFile()

Posted: Tue May 21, 2013 10:58 pm
by Pablo César
esgici wrote:PS: To Rathi : Will be possible a little modification in f.PutFile() ( h_dialogs.prg ) and f.C_PutFile() ( in c_dialogs.c ) in the next release ?
This is very usefull, because according File Type selected by user, can be defined which kind of file can be used for EXPORT proposes.

Re: Help with PutFile()

Posted: Tue May 21, 2013 11:12 pm
by esgici
Pablo César wrote:
esgici wrote:PS: To Rathi : Will be possible a little modification in f.PutFile() ( h_dialogs.prg ) and f.C_PutFile() ( in c_dialogs.c ) in the next release ?
This is very usefull, because according File Type selected by user, can be defined which kind of file can be used for EXPORT proposes.
Hola amigo Pablo :)

Thanks to remind :)

This was not only a wish, it was implemented too ;)

So, (if you like) you can use it without waiting included in legal HMG distribution by admin.

Happy HMG'ing :D

Re: Help with PutFile()

Posted: Tue May 21, 2013 11:18 pm
by Pablo César
esgici wrote:So, (if you like) you can use it without waiting included in legal HMG distribution by admin.
Yeah, thanks for your tip. But it would be a common benefits to all when it will be in the next releases and Mr. Rathinagiri has already agreed with this implementation.

Image

Re: Help with PutFile()

Posted: Tue May 21, 2013 11:24 pm
by esgici
Pablo César wrote:Yeah, thanks for your tip. But it would be a common benefits to all when it will be in the next releases and Mr. Rathinagiri has already agreed with this implementation.
Thanks, you are right; probably Mr. Diamond was forgot it :(

TIA :D

Help with PutFile()

Posted: Tue May 21, 2013 11:31 pm
by Pablo César
esgici wrote:Thanks, you are right; probably Mr. Diamond was forgot it
Yes, I guess so... for also this question I make an update reminder in Pendings for NEXT release ( REMINDER ).

There is another question, very important now with UNICODE mode enhancements in this last HMG version, which it will demand some modification (like as C HMG_ functions) in your code of PutFile5P.prg

Re: Help with PutFile()

Posted: Tue May 21, 2013 11:37 pm
by esgici
Pablo César wrote:...There is another question, very important now with UNICODE mode enhancements in this last HMG version, which it will demand some modification (like as C HMG_ functions) in your code of PutFile5P.prg
Which modification(s) may be required, would you specify please :?

Help with PutFile()

Posted: Wed May 22, 2013 12:11 am
by Pablo César
esgici wrote:Which modification(s) may be required, would you specify please :?
Before answer this your question, let me put clear something I noted recentely.

You Esgici are indicating a 5th parameter for default indicated file at InputFile dialog. In other words and sample:
Screen75.PNG
Screen75.PNG (4.45 KiB) Viewed 3834 times
By picture you can see where affects:
InputFileDialog2.jpg
InputFileDialog2.jpg (40.2 KiB) Viewed 3834 times
But I as thinking in another parameter which allows to know the number option of array passed as at first parameter:
Screen76.PNG
Screen76.PNG (5.26 KiB) Viewed 3834 times
Image
Note first parameter is an array with two elements (two types of files: TXT & PRG) and by this extra parameter, we supose to take which one have been choosen by user (as above image showing).

One good example is C:\MiniGUI\SAMPLES\Applications\DBFview\source\DBFview.prg (see below part of it):

Code: Select all

Static Procedure ExportData()
Local cExt, cSaveFile, nIndex := 1, cAlias, nRecno

IF !Empty(nFocus)
	cSaveFile := PutFile( { {"DBF files (*.dbf)", "*.dbf"}, {"Text files (*.txt)", "*.txt"}, ;
		{"Data files (*.dat)", "*.dat"}, {"Excel files (*.xls)", "*.xls"}, ;
		{"Clipper, Foxpro files (*.prg)", "*.prg"}, {"All files (*.*)", "*.*"} }, , , , @nIndex )

	IF !Empty( cSaveFile )
		IF nIndex == 2
			cExt := "txt"
		ELSEIF nIndex == 3
			cExt := "dat"
		ELSEIF nIndex == 4
			cExt := "xls"
		ELSEIF nIndex == 5
			cExt := "prg"
		ELSE
			cExt := "dbf"
		ENDIF
So we're talking about different goals, here. Probably need the 6th parameter to attend both... ;)

Help with PutFile()

Posted: Wed May 22, 2013 12:33 am
by Pablo César
esgici wrote:Which modification(s) may be required, would you specify please :?
For example, replacing hb_parc by HMG_parc. And add after line #pragma begindump this:

#define COMPILE_HMG_UNICODE
#include "HMG_UNICODE.h"

Mr. Rathinagiri, what do you think about 5th and 6th extra parameters in InputFile source code ? Both ideas are usefull... :P

Help with PutFile()

Posted: Wed May 22, 2013 11:47 am
by Pablo César
I've tried to compose right code, but there some errors in C code. Here are for both codes proposed:
c_dialogs.c

Code: Select all

HB_FUNC( C_PUTFILENEW )
{
	OPENFILENAME ofn;
	TCHAR buffer[512];
	char cExt[ 4 ];
	int flags = OFN_FILEMUSTEXIST | OFN_EXPLORER ;
	
	if ( hb_parl(4) )
	{
		flags = flags | OFN_NOCHANGEDIR ;
	}
	
	if( strlen( HMG_parc( 5 ) ) != 0 )
      strcpy( buffer, HMG_parc( 5 ) );
    else
      strcpy( buffer, "" );
	  
	if( strlen( HMG_parc( 6 ) ) != 0 )
       strcpy( cExt, HMG_parc( 6 ) );
    else
       strcpy( cExt, "" );
 
	//******************************************************************************************************//   
	// ofn.lpstrFilter = A buffer containing pairs of null-terminated filter strings. 
	//                   The last string in the buffer must be terminated by two NULL characters.
	// The following code converts a ANSI (CHAR) filter string into a UNICODE (UNSIGNED INT) filter string
   
    #define _MAX_FILTER 32*1024
    INT i, j=0, cont=0;
    CHAR *p = (CHAR*) hb_parc(1);
    TCHAR Filter [_MAX_FILTER];
    memset((void*) &Filter, 0, sizeof(Filter));
    
    for (i=0; *p != '\0'; i++)
    {  cont = cont + strlen(p) + 1;
       if (cont < _MAX_FILTER)
       {   lstrcpy (&Filter[j],HMG_CHAR_TO_WCHAR(p));
           /*
              TCHAR Text [100];
              wsprintf(Text,_TEXT("%d  %d  %s"),i,cont,&Filter[j]);
              MessageBox (NULL, Text, _TEXT("DEBUG"), MB_OK);   
           */
           j = j + lstrlen (HMG_CHAR_TO_WCHAR(p)) + 1;
           p = p + strlen(p) + 1;
       }
       else
          break;
    }
	//**********************************************************************//   

	memset ((void*)&buffer, 0, sizeof(buffer));
	memset( (void*) &ofn, 0, sizeof( OPENFILENAME ) );
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.hwndOwner = GetActiveWindow() ;
	// ofn.lpstrFilter = (LPCTSTR) hb_parc(1);
	ofn.lpstrFilter = (LPCTSTR) &Filter;
	ofn.lpstrFile = (LPTSTR) &buffer;
	ofn.nMaxFile = 512;
	ofn.lpstrInitialDir = (LPCTSTR) HMG_parc(3);
	ofn.lpstrTitle = (LPCTSTR) HMG_parc(2);
	ofn.Flags = flags;
	ofn.lpstrDefExt = cExt;
	
	if( GetSaveFileName( &ofn ) )
	{
		HMG_retc(ofn.lpstrFile);
	}
	else
	{
		hb_retc( "" );
	}
}
h_dialogs.prg

Code: Select all

*-----------------------------------------------------------------------------*
Function PutfileNew ( aFilter, title, cIniFolder, nochangedir, cDeFilName, cFileName )
*-----------------------------------------------------------------------------*
Local c:='' , n

DEFAULT cFileName := ""
DEFAULT cDeFilName := ""
DEFAULT aFilter:={}
DEFAULT title := ""
DEFAULT cIniFolder := ""
 
For n := 1 TO HMG_LEN ( aFilter )
	c += aFilter [n] [1] + CHR(0) + aFilter [n] [2] + CHR(0)
Next
c :=  c + CHR(0)
Return C_PutFileNew ( c, title, cIniFolder, nochangedir, cDeFilName, cFileName )
Please Dr. Soto, would help us in this ? My C knowledges are not so good than yours. ;)

Re: Help with PutFile()

Posted: Wed May 22, 2013 3:35 pm
by esgici
Hi Pablo

Good suggestions, I agree with you, these enhancements will be good and useful.

By the way,
probably Mr. Diamond was forgot it
... or he didn't like it :(

TIA :D