【お知らせ】この部分は英語原文のみでの提供となります。何卒ご了承ください。
2.1.27.16 InputBox
Contents
Description
Opens a simple input box for entering a number (double)
Opens a simple input box for entering a string.
Syntax
double InputBox( double dDefault, LPCSTR lpcszMsg = NULL )
string InputBox( LPCSTR lpcszMsg, LPCSTR lpcszDeault = NULL, DWORD dwOption = 0 )
Parameters
- dDefault
- [input] default value, must be supplied, to be shown when dialog is open
- lpcszMsg
- [input] Pointer to a string containing a message used to prompt the user.
- lpcszMsg
- [input] Pointer to a string containing a message used to prompt the user.
- lpcszDeault
- [input] optional pointer to a string with default value, if NULL, then edit box will be empty
- dwOption
- [input] The lowest 4 bits (0-15) is used to indicate multiline edit box. 0 or 1 will use single line, otherwise the number of lines
Return
the value entered by the user, or NANUM if use cancel, or if user types in none-numeric
the string which has been input
Examples
EX1
void test_input(double dd = 12.3) { double vv = dd; double v2 = InputBox(vv); if(is_missing_value(v2)) out_str("User cancelled or invalid"); else { Worksheet wks = Project.ActiveLayer(); wks.SetCell(0 ,1, vv); wks.SetCell(1, 1, v2); } }
EX2
// use inside GetNBox event #include <GetNBox.h> void test_number(double dd = 12.45) { double v1 = rnd(); v1 *= dd; GETN_TREE(tr) GETN_NUM(v1, "Number", v1) GETN_READ_ONLY GETN_BUTTON_GROUP(bb, "Button", 0, "Get Value...") GETN_OPTION_EVENT_EX(test_getval_event) if( GetNBox( tr, "Title Test", "Test Get Value", NULL, NULL, GetWindow() )) out_tree( tr ); } bool test_getval_event(TreeNode& trGUI, int nRow, int nCol, TreeNode& trNode, DWORD dwCntrl, int nType, WndContainer& theDlg) { if(ONODETYPE_PUSHBUTTON_GROUP != nType || (GETNEVENT_ON_INIT & dwCntrl)) return false; double dd = InputBox(trGUI.v1.dVal, "Please Type Some Value"); if(!is_missing_value(dd)) { trGUI.v1.dVal = dd; return true; } else return false; }
EX3
// This is a self contained sample program for the function InputBox, // To run the program, enter the following command in the Script window: // InputBox_ex1 // When you enter "12.34 56" in the input box, the following // meassage will be printed: // Entered string: "12.34 56" // Obtained numbers: v1=12.340000, v2=56.000000 // If you click the Cancel button, the follwoing message will // be printed: // Cancel button was clicked. // void InputBox_ex1() { string strInput; float v1,v2; try { strInput = InputBox("Enter two numbers\nseparated by spaces:") } catch(int nErr) { printf("Cancel button was clicked.\n"); return ; } sscanf(strInput,"%f %f",&v1,&v2); printf(" Entered string: \"%s\"\n Obtained numbers: v1=%f, v2=%f\n", strInput,v1,v2); }
EX4
// This example shows how to edit multiline string with InputBox void InputBox_ex2() { string str = "line1\r\nline2"; float v1,v2; try { str = InputBox("multi-line edit:", str, 4); } catch(int nErr) { printf("Cancel button was clicked.\n"); return ; } printf("You have entered:\n%s\n", str); }
Remark
Open a simple input box for entering a numeric, it will return NANUM when user cancel or input is not numeric value. To tell cancel from invalid input, user can use GetNBox to handle details.
Open a simple input box for entering a string. Need to use the try-and-catch structure to detect the Cancel button clicked, or else will throw runtime error exception when user cancel.
See Also
Header to Include
origin.h