FileOperations

_Convert_Files, _MakeDirectory, _SendFile, AppendFile, Convert_Files, CopyFile, DeleteFile, DeleteFileQuery, EditFile, ExistFile, FindFiles, Get_Filename, Get_FileSize, Get_FileTitle, GetFreeDiskSpace, GetOpenSaveFileName, MakeDirectory, ReadFile, ReadFileEx, RenameFile, SaveImageTextInfo, SelectFile, SelectImage, TraceToLogFile, WriteFile

AppendFile

Description 

 AppendFile(
   char *DestFile,
   char *SourFile
);

This function appends the source file to the destination file.

Parameters

char *DestFile

Destination file.

char *SourFile

Pointer to a file name.

Return Values

The function returns TRUE, if the source file was appended, else returns FALSE.

See Also 
ExistFile, CopyFile, RenameFile, WriteFile, ReadFile

Convert_Files

Interactive command to this function: File > Import/Export > Convert Files

Description 

 Convert_Files(
   char *Dest_Directory,
   char *sour_dir,
   char *Sour_Filter,
   int  dest_fmt,
   int  dest_compr,
   int  sour_fmt,
   int  subdir,
   int  x_resize,
   int  y_resize,
   int  image_info
);

This function converts files from one directory to another. You can include subdirectories, change format and resize the images.

Parameters

char *Dest_Directory

This parameter describes path to the resulting files (destination directory).

char *sour_dir

Source directory.

char *Sour_Filter

Filename filter.

int dest_fmt

Destination file format.

0

keep source file format

1

lim

2

bmp

3

tif

4

jpg

5

jp2

6

gif

int dest_compr

Destination compression.

0

LIM format - lossless

1

LIM format - no compression

0

BMP format - no compression

0

TIF format - no compression

1

TIF format - LZW (key needed)

2

TIF format - CCIT (binary image only)

0-4

JPG format - level of compression

0-5

JP2 format - level of compression (0 = lossless)

0

GIF format - lossless (not binary image, key needed)

0

PNG format - no compression

0

ND2 format - lossless

0

AVI format - this parameter is ignored. Compression depends on the selected codec an its settings.

int sour_fmt

Source format filter.

0

all

1

tiff

2

jp2

3

lim

4

jpg

5

bmp

6

png

7

gif

8

psd

9

ndf

10

nef

11

LSM

int subdir

Include subdirectories.

int x_resize

New width.

-1

Original Width.

int y_resize

New height.

-1

Original Height.

-2

Keep Aspect.

int image_info

Defines new Image Info.

0

Use Image Info Defined in _Convert_Files.

1

Leave Image Info.

See Also 
_Convert_Files

CopyFile

Description 

 CopyFile(
   char *DestFile,
   char *SourFile
);

This function copies g source file to a destination file.

Parameters

char *DestFile

Destination file.

char *SourFile

Pointer to a file name.

Return Values

The function returns TRUE if copying was OK. Otherwise it returns FALSE or -1.

See Also 
ExistFile, RenameFile, ReadFile, AppendFile, WriteFile

DeleteFile

Description 

 DeleteFile(
    file_name
);

This function erases the file.

Parameters

file_name

Name of file that is to be erased.

Note

This function is typically called, when you invoke the _ImageOpen and press Delete button.

See Also 
DeleteFileQuery

DeleteFileQuery

Description 

 DeleteFileQuery(
    file_name
);

This function erases the file. This function is typically called, when you Delete item under commands button. Before deleting the file, MessageBox with a warning appears.

Parameters

file_name

Name of file that is to be erased.

See Also 
DeleteFile

EditFile

Description 

 EditFile(
   char *Filename
);

This function enables you to edit a filename. The Edit File dialog box appears.

Parameters

char *Filename

The path and the name of the file.

See Also 
EditMacro

ExistFile

Description 

int ExistFile(
   char *Filename
);

This function tries to find the specified file.

If the Filename parameter specifies a filename and extension only the function searches for a matching file in the following directories (in this order): 1 The directory containing the executable file for the current task. 2 The Windows directory, 3 The Windows system directory (the directory containing such system files as GDI.EXE). 4 The directories listed in the PATH environment variable.

Parameters

char *Filename

The path and the name of the file.

Return Values

int

The function returns TRUE (1) if the filename exist.

// ExistFile example - shows how to use different functions for File handling.
dword     key,keys[1]; 
char      buf[1024], buffer[10000];
char      press_enter[256];
char      *str;
strcpy(press_enter, "\tPress Enter to Continue.");
keys[0] = VK_RETURN;
SetCommandText("Working...");
Int_CreateTextWindow("API Example - ReadFile, CopyFile, WriteFile, SelectFile, RenameFile, AppendFile functions.",
0,RGB(0,0,128),RGB_WHITE,100);
Wait(3);
// Testing existance of C:\CONFIG.SYS
if(ExistFile("c:/config.sys") == FALSE)
   {
   strcpy(buf, "ExistFile function... File c:\config.sys doesn't exist.");
   strcat(buf, press_enter);
   Int_CreateTextWindow(buf,5,RGB(0,0,128),RGB_WHITE,90);
   key=0; while(!key) key=Int_GetEvents(keys,1);
   goto end;
   }
strcpy(buf, "ExistFile function... File c:\config.sys exists.");
strcat(buf, press_enter);
Int_CreateTextWindow(buf,5,RGB(0,0,128),RGB_WHITE,90);
key=0; while(!key) key=Int_GetEvents(keys,1);
// Copying C:\CONFIG.SYS to C:\CONFIG.DEL
if(CopyFile("c:/config.del", "c:/config.sys") != TRUE)
   {
   strcpy(buf, "CopyFile function... File c:\config.sys cannot be copied to c:\config.del");
   strcat(buf, press_enter);
   Int_CreateTextWindow(buf,5,RGB(0,0,128),RGB_WHITE,90);
   key=0; while(!key) key=Int_GetEvents(keys,1);
   goto end;
   }
strcpy(buf, "CopyFile function... File c:\config.sys was succesfully copied to c:\config.del");
strcat(buf, press_enter);
Int_CreateTextWindow(buf,5,RGB(0,0,128),RGB_WHITE,90);
key=0; while(!key) key=Int_GetEvents(keys,1);
// Renaming C:\CONFIG.DEL to C:\CONFIG.DUM, deleting if destination already exists
if(ExistFile("c:/config.dum")) DeleteFile("c:\config.dum");
RenameFile("c:/config.dum", "c:/config.del");
strcpy(buf, "RenameFile function... File c:\config.del was succesfully renamed to config.dum");
strcat(buf, press_enter);
Int_CreateTextWindow(buf,5,RGB(0,0,128),RGB_WHITE,90);
key=0; while(!key) key=Int_GetEvents(keys,1);
// Reading C:\CONFIG.DUM
ReadFile("c:/config.dum", buffer, 10000);
str = strchr(buffer, VK_RETURN);
if(str) *str=0;
sprintf(buf,"First line of config.dum:\t%s","buffer");
Int_CreateTextWindow(buf,5,RGB(0,0,128),RGB_WHITE,90);
key=0; while(!key) key=Int_GetEvents(keys,1);
// Overwriting C:\CONFIG.DUM with text "First Line."
WriteFile("c:/config.dum", "First Line. ", 12);
Int_CreateTextWindow("First line of CONFIG.DUM is overwritten with text 'First Line.",5,RGB(0,0,128),RGB_WHITE,90);
key=0; while(!key) key=Int_GetEvents(keys,1);
// Appending to C:\CONFIG.DUM the file C:\AUTOEXEC.BAT."
AppendFile("c:/config.dum", "c:/autoexec.bat");
Int_CreateTextWindow("AUTOEXEC.BAT is appended to CONFIG.DUM.\tPress Enter to Continue. ",5,RGB(0,0,128),RGB_WHITE,90);
key=0; while(!key) key=Int_GetEvents(keys,1);
Int_CreateTextWindow("Viewing C:\CONFIG.DUM",0,RGB(0,0,128),RGB_WHITE,100);
EditFile("c:/config.dum");
DeleteFile("c:/config.dum");
Int_CreateTextWindow("CONFIG.DUM was deleted just now.\tPress Enter to Continue. ",5,RGB(0,0,128),RGB_WHITE,90);
key=0; while(!key) key=Int_GetEvents(keys,1);
end:
Int_CloseTextWindow();

See Also 
CopyFile, RenameFile, ReadFile, AppendFile, WriteFile

FindFiles

Description 

 FindFiles(
   char *Buffer,
   int  Count,
   char *Filename,
   int  onlyDir
);

This function fills the buffer with the specified files. Macro is responsible to allocate the buffer. Each filename has a constant width in the buffer - MAX_FILE_NAME. The filename parameter may use wildcards (* and ?).

Parameters

char *Buffer

Address of the buffer.

int Count

Number of iterations.

char *Filename

The path and the name of the file(s). Wildcards can be used

int onlyDir

If specified, only directory selection will be enabled.

0

Select a file.

1

Select a directory

Return Values

The function fills buffer with the specified files.

//FindFiles example - searches your hard disk C for LIM images and outputs list of images to the file RESULT1.TXT.
char      destfile[256];
char      directory[256];
char      buf[256],filenames[28800], buffer[28800];
char      newline[5];
char      *filename;
int       numfiles,qw;
dword     i, count;
Int_CreateTextWindow("API Example - FindFiles function.", 0,RGB(0,0,128),RGB_WHITE,100);
SetCommandText("Working...");
strcpy(destfile,"results1.txt");
qw = Int_Question("Searching hard disk C for LIM images","Do you want to continue?","&Yes","&No","","",1,0);
newline[0]=13;
newline[1]=10;
newline[2]=0;
if(qw == 1)
   {
   strcpy(buf,"Wait a moment, please...\tSearching hard disk C for LIM images");
   Int_CreateTextWindow(buf,0,RGB(0,0,128),RGB_WHITE,100);
   numfiles = FindFiles(filenames, 28800, "c:\*.lim", 1);
   strcpy(buf,"List of files will be stored in RESULTS1.TXT on selected directory.");
   Int_CreateTextWindow(buf,0,RGB(0,0,128),RGB_WHITE,100);
   SelectFile(directory,"Text files|*.txt|",1);
   if(numfiles != 0)  
  {
  *buffer = 0;
  for(i=0; i<numfiles; i=i+1)
 {
 filename = filenames+(i*MAX_FILE_NAME);
 strcat(filename, newline);
 strcat(buffer, filename);
 }
  sprintf(buf,"%s\%s","directory,destfile");
  count = strlen(buffer);
  WriteFile(buf,buffer,count);
  EditFile(buf);
  }
   else
  {
  Int_Question("Example","No files were found!","OK", NULL, NULL,NULL, 1, 0);
  }
   }
Int_CloseTextWindow();
GetFreeDiskSpace

Description 

double GetFreeDiskSpace(
   char *Directory
);

This function retrieves free space left on the disk specified.

Parameters

char *Directory

Directory path.

Return Values

double

Free disk space in Megabytes.

GetOpenSaveFileName

Description 

 GetOpenSaveFileName(
   int  OpenFile_bOpen,
   char *OpenFile_StartDir,
   char *OpenFile_Filter,
   char *OpenFile_Title,
   char *OpenFile_EndDir,
   int  OpenFile_EndDirLen,
   char *OpenFile_FileName,
   int  OpenFile_FileLen
);

This function allows the user to select file in open or save dialog box.

Parameters

int OpenFile_bOpen

Specifies if the dialog is for open or save.

0

Dialog is for save.

1

Dialog is for open.

char *OpenFile_StartDir

Specifies the startup directory for the dialog. String should be zero terminated.

char *OpenFile_Filter

Specifies file type filter. String should be zero terminated.

char *OpenFile_Title

Specifies title of the dialog. String should be zero terminated.

char *OpenFile_EndDir

This buffer is filled with the selected directory. It should be long enough to hold the selected directory name.

int OpenFile_EndDirLen

Length of OpenFile_EndDir buffer.

char *OpenFile_FileName

This buffer is filled with the selected filename. It should be long enough to hold selected filename.

int OpenFile_FileLen

Length of OpenFile_FileLen buffer.

Get_FileSize

Description 

 Get_FileSize(
   char *Filename,
   int *LpSize
);

This function retrieves the size of the file identified by the filename parameter.

Parameters

char *Filename

The path and the name of the file.

int *LpSize

0

Success.

-9

Error.

Get_FileTitle

Description 

 Get_FileTitle(
   char *Title,
   char *Filename
);

This function retrieves the title of the file identified by the filename parameter.

Parameters

char *Title

Title name.

char *Filename

The path and the name of the file.

Get_Filename

Description 

int Get_Filename(
   int  what,
   char *Filename
);

Retrieves various information - like filename or path to the data filename specified by the what parameter.

Parameters

int what

Type of the file.

0, FILE_OBJECTDATA

Object data filename.

1, FILE_FIELDDATA

Field data filename.

2, FILE_LENGTHDATA

Length data filename.

3, FILE_ANGLEDATA

Angle data filename.

4, FILE_MACRO

Name of the currently selected macro.

5, FILE_IMAGE

Full path to the currently opened image.

6, FILE_SEQIMAGE

Last opened image in the sequence.

7, FILE_CONFIG

Configuration (*.ini) file.

8, FILE_EXECUTABLE

Executable filename of running program.

9, FILE_WINDIR

Windows directory.

char *Filename

The path and the name of the file (output value).

Return Values

int

This function returns the filename of the file specified by the what parameter.

See Also 
Get_Info, Get_FileTitle

MakeDirectory

Description 

 MakeDirectory(
   char *Directory
);

This function creates a directory.

Parameters

char *Directory

Directory path.

See Also 
SetDrive, SetRelativePath

ReadFile

Description 

 ReadFile(
   char *DestFile,
   char *Buffer,
   int  Count
);

This function reads data to the specified buffer. Count parameter specifies the number of bytes to be read from the file.

Parameters

char *DestFile

Destination file.

char *Buffer

Address of the buffer.

int Count

Number of iterations.

Return Values

The function returns TRUE, if the data were successfully loaded, else returns FALSE.

See Also 
ExistFile, RenameFile, CopyFile, AppendFile, WriteFile

ReadFileEx

Description 

 ReadFileEx(
   char *DestFile,
   char *Buffer,
   int  Count,
   int  ReadFileFlag
);

This function reads data to the specified buffer. Count parameter specifies the number of bytes to be read from the file.

Parameters

char *DestFile

Destination file.

char *Buffer

Address of the buffer.

int Count

Number of iterations.

int ReadFileFlag

If this flag is 1, the function fills the buffer with UNICODE version of file data. Switching the flag to 0 cause simple copy of file data into the buffer.

Return Values

The function returns TRUE, if the data were successfully loaded, else returns FALSE.

See Also 
ReadFile, ExistFile, RenameFile, CopyFile, AppendFile, WriteFile

RenameFile

Description 

int RenameFile(
   char *DestFile,
   char *SourFile
);

This function renames the file or directory specified by sourfile parameter to the name given by the destfile. The sourfile name must be the path of an existing file or directory. The new name must not be the name of an existing file or directory.

Parameters

char *DestFile

Destination file.

char *SourFile

Pointer to a file name.

Return Values

int

Return value informs whether renaming was successful or not.

1

Renaming was successful

-1

Renaming failed

See Also 
ExistFile, CopyFile, AppendFile, WriteFile

SaveImageTextInfo

Description 

 SaveImageTextInfo(
   char *Filename
);

This function saves the current document info into a text file.

Parameters

char *Filename

Full path to the destination txt file. E.g. C:\export\file1.txt

SelectFile

Description 

int SelectFile(
   char *dir,
   char  ext,
   int  onlyDir
);

This function opens a dialog window and waits for the user to select a file or directory.

Parameters

char *dir

Fill in full path to a directory which will be open in the dialog window.

char ext

File extension filter for the dialog window. See example for correct syntax.

int onlyDir

If specified, only directory selection will be enabled.

0

Select a file.

1

Select a directory

Return Values

int

TRUE (1)

The user have selected valid file/directory.

FALSE (0)

The user have canceled the dialog window.

-1

User have inserted invalid file/directory name.

char filepath[260];
int returned;
strcpy(filepath, "c:\");
returned = SelectFile(filepath, "Text files (*.txt;*.doc)|*.txt;*.doc|", 0);
if (returned==TRUE)
   WaitText(0, filepath);
else
   WaitText(0, "The user selected nothing");

See Also 
FindFiles, CopyFile, ReadFile, WriteFile, AppendFile, RenameFile

SelectImage

Description 

 SelectImage(
   char  Directory
);

This function displays the Browse dialog box to enable an image selection.

Parameters

char Directory

Directory name with the path.

TraceToLogFile

Description 

 TraceToLogFile(
   char *Buffer
);

This function writes a string (Buffer) to the application log file. The lxapp.log file is stored in the Application Data directory. (via Documents and Settings\All Users\Application Data\Laboratory Imaging\Platform)

Parameters

char *Buffer

Address of the buffer.

WriteFile

Description 

 WriteFile(
   char *DestFile,
   char *Buffer,
   int  Count
);

This function writes data from buffer to the specified file. Count parameter specifies the number of bytes to be written to the file.

Parameters

char *DestFile

Destination file.

char *Buffer

Address of the buffer.

int Count

Number of iterations.

Return Values

The function returns TRUE, if the data were successfully written, else returns FALSE.

See Also 
ExistFile, RenameFile, ReadFile, AppendFile, CopyFile

_Convert_Files

This function runs the File > Import/Export > Convert Files command.

Description 

 _Convert_Files();

This function converts files from one directory to another. It displays the Conversion of Files dialog box.

See Also 
Convert_Files

_MakeDirectory

Description 

 _MakeDirectory();

This function displays the Make Directory dialog box.

_SendFile

Description 

 _SendFile();

This function sends a file to the mail recipient. First it shows the dialog for selecting the file with information about its size. Then it displays dialog for an empty message with previously selected file as an attachment. This dialog comes from the default e-mail client program and keeps its default settings.

See Also 
_SendMail, SendMail