3.12.4.2 How to Disable OK Button

Version Info

Minimum Origin Version Required: Origin 8 SR0

Description

Following code show how to construct a simple dialog using Origin C GETN macros. The functions in the dialog included:

  1. Attach a checkbox named Auto with a numeric edit box.
  2. How to show error message and disable OK button.

Getn disable ok button.jpg

The dialog will show error message if uncheck Auto checkbox and input 0 to control.

Example

#include <GetNbox.h>

void GetN_Disable_OK_ex()
{
	GETN_TREE(tr)
    GETN_BEGIN_BRANCH(Table, _L("Output")) GETN_OPTION_BRANCH(GETNBRANCH_OPEN) 
        GETN_NUM(start, "Start Time", 1) GETN_ADD_AUTO(1)
        GETN_NUM(stop, "Stop Time", 100) GETN_ADD_AUTO(1)
    GETN_END_BRANCH(Table)
    
    if( GetNBox(tr, _event_func) ) // if clicked OK button
    {
    	out_tree(tr);
    }
}

int _event_func(TreeNode& tr, int nRow, int nEvent, DWORD& dwEnables, LPCSTR lpcszNodeName, WndContainer& getNContainer, string& strAux, string& strErrMsg)
{	
	TreeNode trStart = tr.Table.start;
	TreeNode trStop = tr.Table.stop;
	if( !trStart || !trStop )
		return 0;	
		
	if( nEvent > 0 )// nEvent > 0 on change from individul control from nRow with cntrl Type in nEvent
	{
		if( 0 == lstrcmp(lpcszNodeName, "start") )		
			tree_check_replace_auto(trStart, 1);
		if( 0 == lstrcmp(lpcszNodeName, "stop") )
			tree_check_replace_auto(trStop, 100);
	}
	else 
	{
		bool bOKEnable = trStart.dVal < trStop.dVal && 0 != trStart.dVal && 0 != trStop.dVal;
		O_SET_BIT(dwEnables, GETNGEVT_OK_ENABLE, bOKEnable);
		if( !bOKEnable )
			strErrMsg = "Please input valid number for start and stop control.";
	}
	return 0;
}