📄 dlg_utils.c
字号:
/*------------------------------------------------------------------------------*
* File Name: Dlg_Utils.c *
* Creation: GJL 10/15/2002 *
* Purpose: Origin C file containing Dialog Builder Utilities *
* Copyright (c) OriginLab Corp. 2002-2007 *
* All Rights Reserved *
*------------------------------------------------------------------------------*/
////////////////////////////////////////////////////////////////////////////////////
// Included header files
//////////////////////////////////////////////////////////////////////////////////
//
#include <Origin.h>
//#include <common.h> // Basic data types
//#include <sys_utils.h> // basic routines implemeted through Origin C, see sys_utils.c
//#include <mswin.h> // WIN API functions
#include <Dialog.h> // Dialog class
#include <Tree.h> // Tree class
#include "Wks_Utils.h" // Wks_Utils function prototypes and non-localized constants
#include "App_Utils.h" // App_Utils function prototypes and non-localized constants
#include "Dlg_Utils.h" // Dlg_Utils function prototypes and non-localized constants
/**
Get the current worksheet/workbook sheet selection as a list of non-contiguous
ranges and populate the specified Dialog Builder list box with the list. The list
box name and property must be specified but the function enumerates as needed. This
function can be used with Dialog Builder list boxes, comboxes, and list controls.
Example:
string strMsg;
// Populate Data Range list box, type out error if problem
if( PopulateListBoxWithNonContiguousSelection( "StatisticsOn!Tab.Operation.DataLBX" ) )
{
strMsg = SO_WKS_DATA_SEL_ERROR_MSG; // Output error message and return
strMsg.Write( WRITE_MESSAGE_BOX );
return FALSE;
}
Parameters:
strListBoxName=Input name of Dialog Builder list box, combox, or list control
strPropertyName=Input name of Dialog Builder property to set like ".V" or .V2_, default is ".V"
bAppend=Input option to append new selected ranges in list box (TRUE) or to reset list box and
populate starting in first row (default FALSE)
bSelectAll=Input option to select entire worksheet/workbook sheet if there is no selection (TRUE)
or to return a no selection warning code if there is no selection (default FALSE)
Return:
Returns DLG_UTILS_NO_ERROR on success and a DLG_UTILS warning or error code on failure.
*/
int PopulateListBoxWithNonContiguousSelection(LPCSTR lpcstrListBoxName, LPCSTR lpcstrPropertyName, BOOL bAppend,
BOOL bSelectAll ) // lpcstrPropertyName = NULL, bAppend = FALSE, bSelectAll = FALSE
{
string strPropertyName = (lpcstrPropertyName ? lpcstrPropertyName : ".V");
string strCommand, strSelectedRange;
int ii, iRet, iNumRanges;
double dNumItems;
iRet = wuGetNonContiguousWksSelection( strSelectedRange, iNumRanges ); // Get current selection range
if( iRet ) // If no selection or bad selection...
{
if( bSelectAll && ( iRet == WKS_UTILS_NO_SEL_WARNING ) ) // If bSelectAll is TRUE and no selection...
iRet = wuGetNonContiguousWksSelection( strSelectedRange, iNumRanges, TRUE ); // Get entire worksheet/workbook as selected data
if( iRet ) // Now if no selection or bad selection...
return iRet; // Return warning or error code
else
MessageBeep( MB_OK ); // Else just beep to warn about selecting all
}
// *** The remaing code will be replaced using Dialog object once fully supported ***
if( !bAppend ) // If user does not want to append...
{
strCommand.Format( "%s.Reset()", lpcstrListBoxName ); // Build command to reset list box
LT_execute( strCommand ); // Execute command to reset list box
}
strCommand.Format( "dNumItems=%s.NumItems", lpcstrListBoxName ); // Build command to get number of items in list box
LT_execute( strCommand ); // Execute command to get number of items in list box
LT_get_var( "dNumItems", &dNumItems ); // Get number of items from LabTalk variable
LT_execute( "delete -v dNumItems" ); // Delete LabTalk variable
for( ii = 0; ii < iNumRanges; ii++ ) // For each selected range
{
strCommand.Format( "%s%s%d$=%s", lpcstrListBoxName, strPropertyName, nint(dNumItems) + ii + 1, strSelectedRange.GetToken( ii, ',' ) );
LT_execute( strCommand );
}
return DLG_UTILS_NO_ERROR;
}
/**
Get the current worksheet/workbook sheet selection range and populate the specified
Dialog Builder edit box with it. The selection range must be contiguous and the edit
box name must be specified as an argument.
Example:
string strMsg;
// Populate Weighting edit box, type out error if problem
if( PopulateEditBoxWithContiguousSelection( "StatisticsOn!Tab.Operation.WeightingEBX" ) )
{
strMsg = SO_WKS_WEIGHT_SEL_ERROR_MSG; // Output error message and return
strMsg.Write( WRITE_MESSAGE_BOX );
return FALSE;
}
Parameters:
strEditBoxName=Input name of Dialog Builder edit box
bSelectAll=Input option to select entire worksheet/workbook sheet if there is no selection (TRUE)
or to return a no selection warning code if there is no selection (default FALSE)
Return:
Returns DLG_UTILS_NO_ERROR on success and a DLG_UTILS warning or error code on failure.
*/
int PopulateEditBoxWithContiguousSelection(LPCSTR lpcstrEditBoxName, BOOL bSelectAll) // bSelectAll = FALSE
{
string strCommand, strSelectedRange;
int iRet;
iRet = wuGetContiguousWksSelection( strSelectedRange ); // Get current selection range
if( iRet ) // If no selection or bad selection...
{
if( bSelectAll && ( iRet == WKS_UTILS_NO_SEL_WARNING ) ) // If bSelectAll is TRUE and no selection...
iRet = wuGetContiguousWksSelection( strSelectedRange, TRUE ); // Get entire worksheet/workbook as selected data
if( iRet ) // Now if no selection or bad selection...
return iRet; // Return warning or error code
else
MessageBeep( MB_OK ); // Else just beep to warn about selecting all
}
strCommand.Format( "%s.V1$=%s", lpcstrEditBoxName, strSelectedRange ); // Assign selected range to edit box
LT_execute( strCommand );
return DLG_UTILS_NO_ERROR;
}
/**
Search a windows folder adding any files that match a specified file filter to a Dialog Builder
list box. Options specify whether or not subfolders are to be recursively searched and whether
or not the files are to be appended to or are to replace existing files in the list box. The list
box name and property must be specified but the function enumerates as needed. This function can
be used with Dialog Builder list boxes, comboxes, and list controls.
Example:
string strPath = GetAppPath() + "Filters\";
PopulateListBoxWithFilenames( "AIW!Page.Source.Filters", ".V", FALSE, strPath, "*.oaf", 3 );
Parameters:
strListBoxName=Input name of Dialog Builder list box, combox, or list control
strPropertyName=Input name of Dialog Builder property to set like ".V" or .V2_, default is ".V"
bAppend=Input option to append new selected ranges in list box (TRUE) or to reset list box and
populate starting in first row (default FALSE)
strPath=Input path to start searching, default "" is path to Origin ini file
strFileFilter=Input file filter which may include DOS wild card characters, default is "*.*"
bRecursive=Input option to recursively search subfolders, default is FALSE
wDisplayOptions=Input bitwise flag specifying display options, default value DLG_UTILS_FILE_WITH_PATH
displays path, filename and filetype, DLG_UTILS_FILE_NO_PATH displays filename and filetype without
path, DLG_UTILS_FILE_NO_EXT displays path and filename with out filetype extension, and
DLG_UTILS_FILE_NO_PATH | DLG_UTILS_FILE_NO_EXT displays file name without path or filetype extension
Return:
Returns DLG_UTILS_NO_ERROR on success and a DLG_UTILS warning or error code on failure.
*/
int PopulateListBoxWithFilenames(
LPCSTR lpcstrListBoxName,
LPCSTR lpcstrPropertyName,
BOOL bAppend,
LPCSTR lpcstrPath,
LPCSTR lpcstrFileFilter,
BOOL bRecursive,
UINT wDisplayOptions)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -