PutFile() with 5th parameter

Beware : This article posted on  February 2, 2013 and than with HMG 3.1.3 release on 23 May 2013 added 5th and 6th parameters to that function by our genius Dr. Soto …

Look at changelog of HMG.

 

PutFile() is a HMG function that :

Opens ‘Save As’ System Dialog And Returns The Saved File name

Syntax:

PutFile ( acFilter , cTitle , cIniFolder , lNoChangeDir ) –> cSavedFileName

Although its name is “Put”, this function doesn’t “put” anything to anywhere; that is don’t write anything to disk. It only return a file name ( or empty string if user not selected / typed anything). File that name returned by PutFile() may exist or not. This is only difference between PutFile() and GetFile(); the second return only name of an existing file.

Therefore PutFile() function doesn’t check overwrite status. This is totally responsibility of programmer and if not care, PutFile() become a dangerous tool. The “Default File Name” and network environments will increase the risk. Of course no problem for intentionally overwrite.

As a result, PutFile() open a “Save As…” dialog box and returns a file name to save, selected / typed by user.

As above syntax indicated, this function has four parameters.

Whereas sometime required a bit more info : default file name.

When program suggest a default file name, in addition to select / type a new file name, user may feel more comfortable by only confirm (verbatim or after typing something) suggested file name.

This is a bit modified version of PutFile() (with a small test program); since accept default file name as 5th parameter, name is PutFile5P()

Note : This work is superseded by adding two parameters to official PutFile() function at HMG 3.1.4 2013/06/16.

Happy HMG’ing 😀

PutFile5P

~~~~~~~~~~~~~~~~

/*

  HMG Common Dialog Functions 
  PutFile5P() Test prg.

*/
#include "hmg.ch"
PROCEDURE Main()
  LOCAL nTask
  DEFINE WINDOW Win_1 ;
     AT 0,0 ;
     WIDTH 400 ;
     HEIGHT 400 ;
     TITLE 'PutFile with Default File Name' ;
     MAIN
     DEFINE MAIN MENU
        POPUP 'Common &Dialog Functions'
           ITEM 'PutFile5P()'ACTION MsgInfo( Putfile5P( ;                       
                { {'Text Files','*.txt'} },; // 1° acFilter ;
                   'Save Text',;             // 2° cTitle 
                   'C:\',;                   // 3° cIniFolder 
                   ,;                        // 4° lNoChangeDir 
                  "New_Text.TXT" ) )         // 5° cDefaultFileName
       END POPUP
    END MENU
  END WINDOW
  ACTIVATE WINDOW Win_1
RETURN // TestPF5P.PRG
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*-----------------------------------------------------------------------------*
FUNCTION Putfile5P ( aFilter, title, cIniFolder, nochangedir, cDeFilName )
*-----------------------------------------------------------------------------*
   LOCAL c:='' , n

   IF aFilter == Nil
      aFilter := {}
   EndIf

   IF HB_ISNIL( cDeFilName )
      cDeFilName := ''
   ENDIF 

   FOR n := 1 TO Len ( aFilter )
       c += aFilter [n] [1] + chr(0) + aFilter [n] [2] + chr(0)
   NEXT

RETURN C_PutFile5P ( c, title, cIniFolder, nochangedir, cDeFilName )
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#pragma BEGINDUMP
#define HB_OS_WIN_USED
#define _WIN32_WINNT 0x0400
#include <windows.h>
#include "hbapi.h"
#include "hbapiitm.h"

HB_FUNC ( C_PUTFILE5P )
{

 OPENFILENAME ofn;

 char buffer[512];

 int flags = OFN_FILEMUSTEXIST | OFN_EXPLORER ;

 if ( hb_parl(4) )
 {
 flags = flags | OFN_NOCHANGEDIR ;
 }

 if( strlen( hb_parc( 5 ) ) != 0 )
 strcpy( buffer, hb_parc( 5 ) );
 else
 strcpy( buffer, "" );

 memset( (void*) &ofn, 0, sizeof( OPENFILENAME ) );
 ofn.lStructSize = sizeof(ofn);
 ofn.hwndOwner = GetActiveWindow() ;
 ofn.lpstrFilter = hb_parc(1) ;
 ofn.lpstrFile = buffer;
 ofn.nMaxFile = 512;
 ofn.lpstrInitialDir = hb_parc(3);
 ofn.lpstrTitle = hb_parc(2) ;
 ofn.Flags = flags;

 if( GetSaveFileName( &ofn ) )
 {
 hb_retc( ofn.lpstrFile );
 }
 else
 {
 hb_retc( "" );
 }
}
#pragma ENDDUMP

HMG Samples

About HMG Samples

Language Related

 Arrays

Array Arithmetic

Load / Save ANY array

Conversion

DOS -> Windows Character Conversion

National Issues

National Alternate Collating Sequence

National Change Case

 Windows

Tracking Mouse

Controls

Browse

Quick Search    

Combo box

Dynamic ComboBox

Edit Box

Word wrap in EditBox

 Grid

Get Data Into Grid via IDE

Text Box

Auto fill in text box

Search in and Fill Box (SFilBox) 

Tree

Tree Menu

Two Methods for Tree

Functions

 Drives, Directories and Files

Drives and Directories

Directory List

Fill Directory List

PutFile() with default file name

Messages

HMG Message Functions

Message for multiple values

Message Extended

Where Is It ?

Improvements in Message functions

Miscellaneous

Is application running ?

Get Process ID

Simple Error Handling

Funny

Cuckoo Clock

Untouchable window

Warn Lazy User

Pegs Game

Drawing

Play Draw

Draw Border

Printing

 Text Mode

Using printer under Windows 

Obsolete ways

Send to File

Print File

GUI Mode

HMG Print

 HMG Print ( Mini Print ) for beginners in 10 easy steps

Print a plain text file by HMG Print – 1

HMG Report

HMG HPDF

HMG_HPDF — Bill

Unicode

HMG Unicode

Utilities

Color Codes

DB Validate 

Hex View

Mini Agenda

DBA : Data Base Assistant

Low-Level DBU

x-Base Modul List

Mini Search Machine (2014)