1.18.1.2 GetN DialogGetN Simple Dialog
Simple Dialog
There is an easy way to create a simple dialog using GetN macros and GetNBox function.
The dialog looks below:
Run the following function to open the upper dialog:
#include <GetNbox.h>
void simple_dialog()
{
GETN_BOX(trRoot) // define a Tree variable named "trRoot"
// data range control
GETN_INTERACTIVE(Input, "Input data", "[Book1]Sheet1!A")
// radio button
GETN_RADIO_INDEX_EX(Operator, "Operator", 0, "Add|Subtract")
// list box
GETN_LIST(type, "Operand", 0, "Constant|Reference Data")
// string edit box
GETN_STR(Constant, "Constant", "10")
// choose a data range for reference data
GETN_INTERACTIVE(Reference, "Reference Data", "[Book1]Sheet1!B")
// choose a column for output data
GETN_INTERACTIVE(Output, "Output data", "[Book1]Sheet1!C")
// bring up dialog
GetNBox(trRoot );
}
Controls
The following table lists the commonly used controls. For more controls and style setup, please refer to Origin C Reference: Macros: GetN.
Event Handler
In the above dialog box, you can add an event function like below function node_event to dynamicly show/hide a control, or reconstruct a combo list and so on.
Change the line in the above example function from
GetNBox(trRoot);
to
GetNBox(trRoot, node_event);
Add an event fucntion as below:
int node_event(TreeNode& trRoot, int nRow, int nEvent, DWORD& dwEnables,
LPCSTR lpcszNodeName, WndContainer& getNContainer, string& strAux,
string& strErrMsg)
{
if( 0 == lstrcmp(lpcszNodeName, "type") || GETNE_ON_VALUE_CHANGE == nEvent
|| GETNE_ON_INIT == nEvent )
{
trRoot.Constant.Show = (0 == trRoot.type.nVal); // show Constant
trRoot.Reference.Show = (1 == trRoot.type.nVal); // show reference
}
return 0;
}
Apply Button
The default GetN Dialog has OK and Cancel buttons; the Apply button is optional. When the Apply button is displayed, and the user clicks this button, you may want to call the related event function to do something.
The following is an example showing how to display the Apply button on a GetN dialog, and call the event function _apply_event when the Apply button is clicked.
#include <GetNbox.h>
void GETN_Apply_ex1()
{
GETN_TREE(tr)
GETN_COLOR(LineColor, "Color", 3)
// the option to set color list to contain custom panel
GETN_COLOR_CHOICE_OPTIONS(COLORLIST_CUSTOM | COLORLIST_SINGLE)
bool bShowApply = true;
if(GetNBox(tr, NULL, "Example", NULL, GetWindow(), bShowApply,
_apply_event))
{
out_str("Click OK");
}
}
// The interface of apply button event function need to according to
// PAPPLY_FUNC typedef.
bool _apply_event(TreeNode& tr)
{
int nIndex = tr.LineColor.nVal;
UINT cr = color_index_to_rgb(nIndex);
printf("Red = %d, Green = %d, Blue = %d\n", GetRValue(cr),
GetGValue(cr), GetBValue(cr));
return true;
}
| By default, the Apply button in a GetN dialog will become inactive after first click and won't be active again unless a change is made to the GetN dialog. If you want to keep the Apply button always active, set system variable @EAB = 0.
|
|