Programming with Binary Switch Controls

Use SetCtrlAttribute and GetCtrlAttribute with the ATTR_ON_VALUE and ATTR_OFF_VALUE attributes to set and get the values corresponding to the on and off states of the binary switch.

Use SetCtrlVal to set the state of a binary switch by passing the value which corresponds to the desired state.

Use GetCtrlVal to obtain the value corresponding to the current state of a binary switch.

A binary switch control has a data type associated with it, so you must be careful to match the value you pass to SetCtrlVal, as well as the value you use to set ATTR_ON_VALUE and ATTR_OFF_VALUE, with the data type of the control. The pointer you pass to GetCtrlAttribute and to GetCtrlVal must also be compatible with the current data type of the control.

If the data type of the binary switch is VAL_STRING, then use GetCtrlAttribute with the ATTR_ON_VALUE_LENGTH and ATTR_OFF_VALUE_LENGTH attributes to determine the size of the buffer needed to get the value strings. Keep in mind that GetCtrlAttribute and GetCtrlVal append a NULL byte to the end of the text string, so you must make the buffer 1 byte larger than the value obtained using ATTR_ON_VALUE_LENGTH or ATTR_OFF_VALUE_LENGTH.