2.1.27.10 GetNBox


Description

This function opens a dialog from a tree constructed using a set of macros.

Syntax

int GetNBox(TreeNode& tr, PEVENT_GETN pfnEventEx, LPCSTR lpcszTitle = NULL, LPCSTR lpcszDescription = NULL, HWND hWndParent = NULL, bool bShowApplyButton = false, PAPPLY_FUNC pfnApply = NULL);
int GetNBox(TreeNode& tr, PEVENT_GETN pfnEvent, GetNBoxDisplayInfo* pInfo, HWND hWndParent = NULL);

Parameters

trNode
[modify] A TreeNode constructed by the GETN_BOX or GETN_TREE macro
pfnEventEx
[input] PEVENT_GETN type function pointer. See PEVENT_GETN for more details, or see function GetNBox_ex3 below for example.
lpcszTitle
[input] Dialog title
lpcszDescription
[input] A line of text above the editable list of parameters
hWndParent
[input] Parent window. If NULL, Origin main window will be used, also the location of the dialog will be reset to where it was brought up the time before.
If hWndParent is specified, the dialog will be open at its default location, so the event handler can move the dialog to a desired location.
bShowApplyButton
[input] true to show Apply button; false will not show.
pfnApply
[input] PAPPLY_FUNC type function pointer. If specified, an Apply button will show and call this handler when click button. Click PAPPLY_FUNC for more details.
tr
[modify] A TreeNode constructed by the GETN_BOX or GETN_TREE macro
pfnEvent
[input] PEVENT_GETN type function pointer. See PEVENT_GETN for more details
pInfo
[input] Set dialog title, customise OK/Cancel buttons etc. See function GetNBox_ex4 below for example.
class GetNBoxDisplayInfo
{
public:
	LPCSTR		lpcszTitle; // dialog title
	LPCSTR		lpcszDescription; // A line of text above the editable list of parameters
	bool		bAlwaysUpdateEditTree; // if true, tr is always be updated after dialog closes, no matter OK or Cancel button is clicked.

	bool		bShowApply; // true to show Apply button; false will not show.
	PAPPLY_FUNC	pfnApply; // PAPPLY_FUNC type function pointer. If specified, an Apply button will show and call this handler when click button. Click [[OriginC%3APAPPLY_FUNC|PAPPLY_FUNC]] for more details.
	LPCSTR		lpcszTextApply; // Apply button's text

	bool		bHideOK; // true to hide OK button
	LPCSTR		lpcszTextOK; // OK button's text

	bool		bHideCancel; // true to hide Cancel button
	LPCSTR		lpcszTextCancel; // Cancel button's text

	bool		bHideContextHelp; // true to hide the context help button on the upper-right corner of the dialog
};
hWndParent
[input] Parent window. If NULL, Origin main window will be used, also the location of the dialog will be reset to where it was brought up the time before.
If hWndParent is specified, the dialog will be open at its default location, so the event handler can move the dialog to a desired location.

Return

1 if user clicks OK, 0 if user clicks Cancel.

Examples

EX1

#include <Origin.h>
#include <GetNbox.h>

// this will bring up the simple form with dialog look
void GetNBox_ex1()
{
    double x0, x1;
    GETN_BOX(trTemp)
    GETN_NUM(xFrom, "X From", 1.3)
    GETN_NUM(xStep, "X Step", -0.5)
    if(GetNBox(trTemp, "Row# as X", "Please specify initial X value and increment"))
    {
        x0 = trTemp.xFrom.dVal;
        x1 = trTemp.xStep.dVal;
        printf("X from %f with increment %f\n", x0, x1);
    }
}

EX2

#include <Origin.h>
#include <GetNbox.h>

// the following example shows a tree that allow more info to be edited
static bool fit_expdecay_event(TreeNode& myTree, int nRow, int nType, Dialog& dlgGetNBox)    
{
    if(nRow < 0) // On dialog init, nothing to do
        return false;
    
    // only handle the button for file path for now
    if(TRGP_STR_BUTTON == nType)
    {
        string str = BrowseGetPath(GetAppPath() + "OriginC\\", "Browse");
        myTree.Path.strVal = str;
        return true;
    }
    return false;
}
void GetNBox_ex2()
{
    GETN_TREE(myTree)
    GETN_COMBO(numExp, "Number of Terms", 1, "1|2|3")
    
    GETN_BEGIN_BRANCH(DecayTime, "Decay Times")
        GETN_NUM(decayT1, "1st Decay Time (t1)", 0.0)
        GETN_NUM(decayT2, "2nd Decay Time (t2)", 0.0)
        GETN_NUM(decayT3, "3rd Decay Time (t3)", 0.0)
    GETN_END_BRANCH(DecayTime)
    
    GETN_CHECK(PartialRange, "Fit Partial Data", false)
    GETN_BUTTON(Path, "File path", "c:\\")
    
    GETN_COLOR(FitCurveColor, "Fit Curve color", 1)
    
    if(GetNBox(myTree, "Fit Exp Decay", "Fit Exponential Decay 1,2,3", NULL, fit_expdecay_event))
    {
        if(myTree.numExp.nVal > 1)
            out_str("Multiple exponential");
        if(myTree.DecayTime.decayT1.dVal <= 0)
            out_str("Invalid decay time specified");
    }
}

Ex3

#include <GetNbox.h>
 
void GetNBox_ex3()
{
    GETN_TREE(tr)
    GETN_CHECK(check, "Yes or No", 0) 
    GETN_STR(strval, "Please enter a text for label", "")
 
    if( GetNBox(tr, _event_func_ex, "Test Event Function", "Test...") ) 
    {
    	out_str("Done"); // if OK button clicked
    }
}
int _event_func_ex(TreeNode& tr, int nRow, int nEvent, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& getNContainer, string& strAux, string& strErrMsg)
{
    TreeNode trEdited; 
 
    // check nEvent
    switch(nEvent)
    {
    case GETNE_ON_INIT:
    	out_str("Dialog Init event.");
    	break;
 
    case GETNE_ON_OK:
    	out_str("Cliked OK button. ");
    	break; 
 
    case GETNE_ON_VALUE_CHANGE:    
    	trEdited = tree_get_node(tr, nRow);
    	if( trEdited )
    	    	printf("%s control changed.\n", trEdited.tagName);
    	break;
    }
 
    // shows how to disable OK button
    if( tr.check )
    {
    	// disable OK button if "Yes or No" checkbox is unchecked.
    	bool bEnable = ( 1 == tr.check.nVal ); 
    	O_SET_BIT(dwEnables, GETNGEVT_OK_ENABLE, bEnable);     	
    	if( !bEnable )
    		strErrMsg = "Error! Yes or No checkbox is unchecked";
    }
    return true;
}

Ex4

#include <GetNbox.h>

void GetNBox_ex4()
{
	GetNBoxDisplayInfo displayInfo;
	displayInfo.lpcszTitle = "Test GetNBoxDisplayInfo";
	displayInfo.bAlwaysUpdateEditTree	= true;
	displayInfo.lpcszTextOK		= "Close";
	displayInfo.bHideCancel		= true;
	displayInfo.bHideContextHelp= true;
	
    GETN_TREE(tr)
    GETN_CHECK(check, "Yes or No", 0) 
    GETN_STR(strval, "Please enter a text for label", "")
 
    GetNBox(tr, NULL, &displayInfo);
    out_tree(tr);
}

Remark

See Also

InputBox, GetN, PAPPLY_FUNC, PEVENT_FUNC, PEVENT_GETN

Header to Include

GetNbox.h

Reference