Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Controlling CNiButton thru its Value

I have some buttons that I have added to a dialog box using the controls pallette. The tool tip text show these a CWButtons. Is this normal? Next using the class wizard I created member variables for the controls, these are of type CNiButton. I am using these buttons to control some hardware. I would like to use the ValueChanged message map to send commands to the hardware. Then check the status of the hardware and set the data members value depending on the outcome. I am having some difficulty setting the value data member in the OnValueChanged callback function for the control. It seems to be jumping out of the handler as soon as the CNiButton.Value is changed and immediately reentering it with the new value.
0 Kudos
Message 1 of 2
(3,016 Views)
The reason that you see a tooltip that says CWButton is because CNiButton is a C++ interface on top of an ActiveX control called CWButton, and the dialog editor is hosting the control as an ActiveX control.

The reason for the behavior that you're seeing with the ValueChanged event is that the ValueChanged event fires both when you change the value interactively and when you change the value programmatically. The first time through your event handler is a result of an interactive change, but then you change the value in your event handler, which results in the event firing again, hence the appearance that it's jumping out of the handler and reentering the handler.

You could work around this by having a boolean member variable in your class that tracks w
hether you've entered the event handler and then check this flag in the event handler to prevent executing the code again when you set the Value property. For example, assuming you have a boolean member variable called m_inHandler whose value is set to false in the constructor:

void CCppButtonTestDlg::OnValueChanged(BOOL Value)
{
if (!m_inHandler)
{
m_inHandler = true;

// Make changes to Value property here ...

m_inHandler = false;
}
}

- Elton
0 Kudos
Message 2 of 2
(3,016 Views)