This example demonstrates how to construct controls in an X-Function GetN dialog by TreeNode variable. This mechanism is used to avoid adding controls by multiple variables. This is an example X-Function dialog:
if ( strcmp("GUI", lpcszVarName) == 0 ) // check variable by name { // ID should be unique int nBranchID = 0x0001; int nUserID = GET_USER_DATAID(0); //NodeID to enable Theme support GETN_USE(tr) //use this node as current node //begin of sub branch GETN_BEGIN_BRANCH(UserInfo, "User Information") GETN_ID(nBranchID++) // string edit box GETN_STR(UserName, "Name", "Unknown") GETN_ID(nUserID++) // pass word edit box GETN_PASSWORD(Password, "Password", "") GETN_ID(nUserID++) GETN_END_BRANCH(UserInfo) //end of sub branch //begin of sub branch GETN_BEGIN_BRANCH(Detail, "Details") GETN_ID(nBranchID++) // editable drop-down list GETN_STRLIST(Language, "Language", "English", "|English|German") GETN_ID(nUserID++) // radio buttons GETN_BEGIN_BRANCH(lGender, "Gender") GETN_ID(nBranchID++) GETN_RADIO_INDEX(Gender, 0, "Male|Female") GETN_ID(nUserID++) // the format of radio buttons GETN_OPTION_DISPLAY_FORMAT(DISPLAY_EDITOR_LEFT) GETN_END_BRANCH(lGender) //numeric edit box, age must be Integer, so use format "%d" GETN_NUM(Age, "Age", 18) GETN_OPTION_NUM_FORMAT("%d") GETN_ID(nUserID++) //check box with event handling function GETN_CHECK(iEmail, "Have Email", 0) GETN_ID(nUserID++)//check box GETN_OPTION_EVENT(_show_email) //event of iEmail checkbox // string edit box GETN_STR(Email, "Email", "") GETN_ID(nUserID++) GETN_END_BRANCH(Detail) //end of sub branch }
static bool _show_email(TreeNode& tr, int nRow, int nType, Dialog& Dlg) { TreeNode trDetail = tr.GUI.Detail; if ( !trDetail ) return false; int nShow = trDetail.iEmail.nVal; //if check, show, else hide. trDetail.Email.Show = (nShow == 1); return true; } static bool _check_email(LPCSTR lpcszEmail) { string strEmail(lpcszEmail); if ( strEmail.Count('@') != 1 ) return false; //should contains '@' and only one. int nSep = strEmail.Find('@'); string strLeft = strEmail.Left(nSep); string strRight = strEmail.Right(strEmail.GetLength() - nSep - 1); if ( strLeft.GetLength() == 0 ) return false; if ( strRight.GetLength() == 0 ) return false; LPCSTR lpcszInvalid = "~!#$%^&*()+ -=|\\/><,`"; if ( strEmail.FindOneOf(lpcszInvalid) >= 0 ) return false; return true; }
if ( strcmp(lpcszNodeName, "Email") == 0 ) { string strVal = trGetN.GUI.Detail.Email.strVal; if ( !_check_email(strVal) ) { strErrMsg = "Invalid Email Address! Please correct it"; //disable OK button, should not continue when there is error. bOKEnable = false; } }
out_tree(GUI);