📄 sys_utils.h
字号:
/*------------------------------------------------------------------------------*
* File Name: sys_utils.h *
* Creation: CPY 3/13/02 *
* Purpose: Basic and common utilities for general Origin C development. *
* Copyright (c) OriginLab Corp. 2002, 2003, 2004, 2005, 2006, 2007 *
* All Rights Reserved *
* *
* Modification Log: *
* EJP 07-10-2003 v7.0622 QA70-4745 SET_PAGE_IMPORT_INFO_ON_123_ASC_IMPORT *
*------------------------------------------------------------------------------*/
#ifndef _SYS_UTILS_H
#define _SYS_UTILS_H
// Included files
#include <stdio.h> // IO functions and string.h
#include <OC_const.h> // MAXFULLPATH
#include <math.h> // Mathematical functions
#include <utilities.h> // LT_ functions
#include <complex.h> // For implementing the Re, Im, and Conj functions
#include <mswin.h> // Windows API functions
#include <page.h> // GraphPage class
// Enumerated definitions
typedef enum { FDLOG_ORIGIN = 1, FDLOG_EXCEL, FDLOG_TEMPLATE, FDLOG_ASCII, FDLOG_LOTUS, FDLOG_IMPORT_EXCEL,
FDLOG_DBASE, FDLOG_DIF, ORIGIN_LABTECH, FDLOG_SOUND, FDLOG_MATHEMATICA, FDLOG_KALEIDAGRAPH,
FDLOG_IMAGE, FDLOG_CSV, FDLOG_PCLAMP, FDLOG_SCRIPT, FDLOG_NOTES, FDLOG_EDITOR, FDLOG_SIGMA_PLOT,
FDLOG_ODAQ, FDLOG_THERMO_GALACTIC_SPC, FDLOG_MINI_TAB,
FDLOG_FILTER_ASCII=10000, FDLOG_FILTER_BINARY, FDLOG_FILTER_USERDEFINED } FDLogUseGroup;
typedef enum { FDLOG_TYPE_SAVE_AS = 0, FDLOG_TYPE_OPEN_SINGLE, FDLOG_TYPE_OPEN_MULTISEL,
FDLOG_TYPE_MULTI_OPEN } FDLogDialogType;
// FDLog Multi-Selection/Multi-Open options
#define FDLOG_MULTI_OPEN_MULTI_SELECTION_ONLY -1
#define FDLOG_MULTI_OPEN_SHOW_COL_DESIG 1
#define FDLOG_MULTI_OPEN_SHOW_TEMPLATE 2
#define FDLOG_MULTI_OPEN_SHOW_FILE_SIZE 4
#define FDLOG_MULTI_OPEN_SHOW_MODIFY 8
// Function prototypes
/** >User Interface Controls
Open an FDLog Browse (OpenPath) dialog box.
Example:
string strPath;
strPath = BrowseGetPath(); // or
strPath = BrowseGetPath( "C:\\Program Files\\" ); // or
strPath = BrowseGetPath( GetAppPath() + "OriginC\\", "Browse" );
Parameters:
lpcszPath=Initial path when dialog opens, default NULL uses FDLog tracking
lpcszDialogName=Title of the dialog box, default NULL uses "Open"
Return:
Returns the path browsed to or an empty string if Cancel button in dialog
box is clicked.
*/
string BrowseGetPath( LPCSTR lpcszPath = NULL, LPCSTR lpcszDialogName = NULL );
/** >User Interface Controls
Open an FDLog Open dialog box passing the file types to list in an array
of strings.
Example:
string strPath;
StringArray saFiletypes;
saFiletypes.SetSize( 3 );
saFiletypes[0]="[Project (*.OPJ)] *.OPJ";
saFiletypes[1]="[Old version (*.ORG)] *.ORG";
saFiletypes[2]="[Worksheets (*.OGW)] *.OGW";
strPath = GetOpenBox( saFiletypes ); // or
//strPath = GetOpenBox( saFiletypes, "C:\\Program Files\\" ); // or
//strPath = GetOpenBox( saFiletypes, "C:\\Program Files\\", "Origin" ); // or
//strPath = GetOpenBox( saFiletypes, "C:\\Program Files\\", "Origin", "OpenOPJ" );
if( strPath.IsEmpty() )
out_str( "User has cancelled the Open dialog box." );
else
printf( "The file chosen is %s\n.", strPath );
Parameters:
saFiletypes=Vector containing file types to list in the dialog box, each element
of vector must follow syntax of LabTalk FDLog.TypeN$ object property
lpcszPath=Initial path when dialog opens, default NULL uses FDLog tracking
lpcszFileName=Initial filename when dialog opens, default NULL uses an empty string
lpcszDialogName=Title of the dialog box, default NULL uses "Open"
Return:
Returns the path and filename of a selecetd file or an empty string if Cancel button
in dialog box is clicked.
*/
string GetOpenBox( StringArray &saFiletypes, LPCSTR lpcszPath = NULL, LPCSTR lpcszFilename = NULL,
LPCSTR lpcszDialogName = NULL );
/** >User Interface Controls
An FDLog.UseGroup version of GetOpenBox that uses an enumerated FDLog.UseGroup
code to indicate the set of file types to list. See sys_utils.h or the Origin.ini
file for a list of the enumerated FDLOG.UseGroup codes.
Example:
string strPath;
strPath = GetOpenBox( FDLOG_ORIGIN ); // or
//strPath = GetOpenBox( FDLOG_EXCEL, "C:\\Program Files\\" ); // or
//strPath = GetOpenBox( FDLOG_ASCII, "C:\\Program Files\\", "Origin" ); // or
//strPath = GetOpenBox( FDLOG_SCRIPT, "C:\\Program Files\\", "Origin", "OpenOGS" );
if( strPath.IsEmpty() )
out_str( "User has cancelled the Open dialog box." );
else
printf( "The file chosen is %s\n.", strPath );
Parameters:
nFDLogUseGroup=A LabTalk FDLog.UseGroup code as enumerated in sys_utils.h and in
the Origin.ini file
lpcszPath=Initial path when dialog opens, default NULL uses FDLog tracking
lpcszFileName=Initial filename when dialog opens, default NULL uses an empty string
lpcszDialogName=Title of the dialog box, default NULL uses "Open"
Return:
Returns the path and filename of a selected file or an empty string if Cancel button
in dialog box is clicked.
*/
string GetOpenBox( FDLogUseGroup nFDLogUseGroup, LPCSTR lpcszPath = NULL, LPCSTR lpcszFilename = NULL,
LPCSTR lpcszDialogName = NULL );
/** >User Interface Controls
An easier to use version of GetOpenBox that works for a single file type.
Example:
string strPath;
strPath = GetOpenBox(); // or
//strPath = GetOpenBox( "[Old version (*.ORG)] *.ORG" ); // or
//strPath = GetOpenBox( "*.OPJ"); // or
//strPath = GetOpenBox( "*.ocw Workspace", GetAppPath() + "OriginC\\" ); // or
//strPath = GetOpenBox( "*.ocw Workspace", GetAppPath() + "OriginC\\", "Origin" ); // or
//strPath = GetOpenBox( "*.ocw Workspace", "C:\\Program Files\\", "Origin", "Open Workspace" );
if( strPath.IsEmpty() )
out_str( "User has cancelled the Open dialog box." );
else
printf( "The file chosen is %s\n.", strPath );
Parameters:
lpcszFileType="*.ext description", or "[decription (*.ext)] *.ext", or just "*.ext"
lpcszPath=Initial path when dialog opens, default NULL uses FDLog tracking
lpcszFileName=Initial filename when dialog opens, default NULL uses an empty string
lpcszDialogName=Title of the dialog box, default NULL uses "Open"
Return:
Returns the path and filename of a selecetd file or an empty string if Cancel button
in dialog box is clicked.
*/
string GetOpenBox( LPCSTR lpcszFileType = "*.* All Files", LPCSTR lpcszPath = NULL, LPCSTR lpcszFilename = NULL,
LPCSTR lpcszDialogName = NULL );
/** >User Interface Controls
Open an FDLog SaveAs dialog box passing the file types to list in an array
of strings.
Example:
string strPath;
StringArray saFiletypes;
saFiletypes.SetSize( 3 );
saFiletypes[0]="[Project (*.OPJ)] *.OPJ";
saFiletypes[1]="[Old version (*.ORG)] *.ORG";
saFiletypes[2]="[Worksheets (*.OGW)] *.OGW";
strPath = GetSaveAsBox( saFiletypes ); // or
//strPath = GetSaveAsBox( saFiletypes, "C:\\Program Files\\" ); // or
//strPath = GetSaveAsBox( saFiletypes, "C:\\Program Files\\", "Origin" ); // or
//strPath = GetSaveAsBox( saFiletypes, "C:\\Program Files\\", "Origin", "SaveAsOPJ" );
if( strPath.IsEmpty() )
out_str( "User has cancelled the SaveAs dialog box." );
else
printf( "The file chosen is %s\n.", strPath );
Parameters:
saFiletypes=Vector containing file types to list in the dialog box, each element
of vector must follow syntax of LabTalk FDLog.TypeN$ object property
lpcszPath=Initial path when dialog opens, default NULL uses FDLog tracking
lpcszFileName=Initial filename when dialog opens, default NULL uses an empty string
lpcszDialogName=Title of the dialog box, default NULL uses "SaveAs"
Return:
Returns the path and filename of a selecetd file or an empty string if Cancel button
in dialog box is clicked.
*/
string GetSaveAsBox( StringArray &saFiletypes, LPCSTR lpcszPath = NULL, LPCSTR lpcszFilename = NULL,
LPCSTR lpcszDialogName = NULL );
/** >User Interface Controls
An FDLog.UseGroup version of GetSaveAsBox that uses an enumerated FDLog.UseGroup
code to indicate the set of file types to list. See sys_utils.h or the Origin.ini
file for a list of the enumerated FDLOG.UseGroup codes.
Example:
string strPath;
strPath = GetSaveAsBox( FDLOG_ORIGIN ); // or
//strPath = GetSaveAsBox( FDLOG_EXCEL, "C:\\Program Files\\" ); // or
//strPath = GetSaveAsBox( FDLOG_ASCII, "C:\\Program Files\\", "Origin" ); // or
//strPath = GetSaveAsBox( FDLOG_SCRIPT, "C:\\Program Files\\", "Origin", "SaveAsOGS" );
if( strPath.IsEmpty() )
out_str( "User has cancelled the SaveAs dialog box." );
else
printf( "The file chosen is %s\n.", strPath );
Parameters:
nFDLogUseGroup=A LabTalk FDLog.UseGroup code as enumerated in sys_utils.h and in
the Origin.ini file
lpcszPath=Initial path when dialog opens, default NULL uses FDLog tracking
lpcszFileName=Initial filename when dialog opens, default NULL uses an empty string
lpcszDialogName=Title of the dialog box, default NULL uses "SaveAs"
Return:
Returns the path and filename of a selected file or an empty string if Cancel button
in dialog box is clicked.
*/
string GetSaveAsBox( FDLogUseGroup nFDLogUseGroup, LPCSTR lpcszPath = NULL, LPCSTR lpcszFilename = NULL,
LPCSTR lpcszDialogName = NULL );
/** >User Interface Controls
An easier to use version of GetSaveAsBox that works for a single file type.
Example:
string strPath;
strPath = GetSaveAsBox(); // or
//strPath = GetSaveAsBox( "[Old version (*.ORG)] *.ORG" ); // or
//strPath = GetSaveAsBox( "*.OPJ"); // or
//strPath = GetSaveAsBox( "*.ocw Workspace", GetAppPath() + "OriginC\\" ); // or
//strPath = GetSaveAsBox( "*.ocw Workspace", GetAppPath() + "OriginC\\", "Origin" ); // or
//strPath = GetSaveAsBox( "*.ocw Workspace", "C:\\Program Files\\", "Origin", "SaveAs Workspace" );
if( strPath.IsEmpty() )
out_str( "User has cancelled the SaveAs dialog box." );
else
printf( "The file chosen is %s\n.", strPath );
Parameters:
lpcszFileType="*.ext description", or "[decription (*.ext)] *.ext", or just "*.ext"
lpcszPath=Initial path when dialog opens, default NULL uses FDLog tracking
lpcszFileName=Initial filename when dialog opens, default NULL uses an empty string
lpcszDialogName=Title of the dialog box, default NULL uses "SaveAs"
Return:
Returns the path and filename of a selecetd file or an empty string if Cancel button
in dialog box is clicked.
*/
string GetSaveAsBox( LPCSTR lpcszFileType = "*.* All Files", LPCSTR lpcszPath = NULL, LPCSTR lpcszFilename = NULL,
LPCSTR lpcszDialogName = NULL );
/** >Mathematical
This function is essentially the same as the rnd() function
Parameters:
nSeed = (optional) pass any nonzero value to set the seed for random number generation, or 0
to use the current seed.
Returns:
A uniformly random number between 0. and 1.
Example:
// The example displays 10 random numbers between 0. and 1.
void run_rnd()
{
for (int ii = 0; ii < 10; ii++)
{
double rr = ran();
out_double("value = ", rr);
}
}
*/
double ran(int nSeed = 0);
/** >System
Get the text data copied onto the clipboard.
Example:
string strClipboardText;
BOOL bSuccess;
bSuccess = GetClipboardText( strClipboardText );
if( bSuccess )
out_str( strClipboardText );
else
out_str( "Error reading Clipboard or Clipboard is empty." );
Parameters:
strData = Output text copied from clipboard
Return:
Returns TRUE and a string containing text copied onto the clipboard
on success or returns FALSE and an empty string on failure or if
the Clipboard is empty.
*/
BOOL GetClipboardText( string& strData );
/** >File Management
This function constructs a temporary file name in the Windows Temp path
Example:
string strTempFile;
if(GetTempFileName(strTempFile,"ABC"))
{
printf("You can use this file name as temp file:%s\n", strTempFile);
}
Parameters:
strFile = a string to receive the temp file full path file name
lpcszPrefix = The function uses the first three characters of this string as the prefix of the file name.
If left as NULL, "OTF" will be used.
Return:
TRUE if success, FALSE if not able to fine a temp path.
*/
BOOL GetTempFileName(string &strFile, LPCSTR lpcszPrefix = NULL);
/** >File Management
Get the file modification date of a file from an input string containing
a path and filename.
Example:
string strFileDate, strDataFile = "C:\\Origin80\\Origin.ini";
strFileDate = GetFileModificationDate(strDataFile);
Parameters:
strPathAndFilename=Input string containing a path and filename with filetype extension
Return:
Returns a Windows like file modification date formatted for display.
*/
string GetFileModificationDate(LPCSTR lpcstrPathAndFilename, WORD wFormat=LDF_SHORT);
/** >File Management
List all files of a specified file type found in a folder
Example:
string strExePath = GetAppPath();
StringArray saResult;
FindFiles(saResult, strExePath, "otw");
Parameters:
saResult = the referrence of string array will receive the finding results
lpcszPath = the file path to search for files
lpcszExt = the file extension to search for
bCheckExist = true will check the given saReult to see if the file is already in that array
Return:
Returns TRUE for success, otherwise failure.
*/
BOOL FindFiles(StringArray& saResult, LPCSTR lpcszPath, LPCSTR lpcszExt, bool bCheckExist = false);
/** >File Management
Copy file and also set destination file's attribute
Example:
string strThemeFile = get_theme_file_name(nSelRow, flx);
string strPath = GetAppPath();
strPath += "Deleted";
if(CheckMakePath(strPath))
{
string strTemp = GetFileName(strThemeFile);
FileCopy(strThemeFile, strPath + "\\" + strTemp);
DeleteFile(strThemeFile);
load_themes_to_grid();
}
Parameters:
lpcszSrc = [in] Pointer to a null-terminated string that specifies the name of an existing file.
lpcszDest = [in] Pointer to a null-terminated string that specifies the name of the new file.
dwAttribute = the file attribute to set on the new file lpcszDest
bSetCurrentTime = set the destination file to the current time or not
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -