CButton - States
-
I would like to highlight the state of the button when pressed; i.e. show its 'ON' then reset its state when pressed again - 'OFF'. The following code does not quiet do what I require and I have looked at the methods and not found anything that would do.
void CTabOne::OnBnClickedRelayButton() { // Maintain the button state along with the bool variable if(m_bRelayState) { m_cRelayButton.SetState(FALSE); m_cRelayButton.SetWindowTextA("OFF"); m_bRelayState = false; } else { m_cRelayButton.SetState(TRUE); m_cRelayButton.SetWindowTextA("ON"); m_bRelayState = true; } }
Any suggestions please. Andy. -
I would like to highlight the state of the button when pressed; i.e. show its 'ON' then reset its state when pressed again - 'OFF'. The following code does not quiet do what I require and I have looked at the methods and not found anything that would do.
void CTabOne::OnBnClickedRelayButton() { // Maintain the button state along with the bool variable if(m_bRelayState) { m_cRelayButton.SetState(FALSE); m_cRelayButton.SetWindowTextA("OFF"); m_bRelayState = false; } else { m_cRelayButton.SetState(TRUE); m_cRelayButton.SetWindowTextA("ON"); m_bRelayState = true; } }
Any suggestions please. Andy.you should use either a Radio button or a checkbox button with the pushbutton style.
TOXCCT >>> GEII power
[VisualCalc 3.0 updated ][Flags Beginner's Guide new! ]
-
I would like to highlight the state of the button when pressed; i.e. show its 'ON' then reset its state when pressed again - 'OFF'. The following code does not quiet do what I require and I have looked at the methods and not found anything that would do.
void CTabOne::OnBnClickedRelayButton() { // Maintain the button state along with the bool variable if(m_bRelayState) { m_cRelayButton.SetState(FALSE); m_cRelayButton.SetWindowTextA("OFF"); m_bRelayState = false; } else { m_cRelayButton.SetState(TRUE); m_cRelayButton.SetWindowTextA("ON"); m_bRelayState = true; } }
Any suggestions please. Andy.you can write this in your void CTabOne::OnBnClickedRelayButton() function
CString text; m_cRelayButton.GetWindowText(text); if(text == "OFF") { m_cRelayButton.SetState(TRUE); m_cRelayButton.SetWindowText(_T("ON")); } if(text == "ON") { mm_cRelayButton.SetState(FALSE); m_cRelayButton.SetWindowText(_T("OFF")); }
i think this should do hope that it would help a.hemdan -
I would like to highlight the state of the button when pressed; i.e. show its 'ON' then reset its state when pressed again - 'OFF'. The following code does not quiet do what I require and I have looked at the methods and not found anything that would do.
void CTabOne::OnBnClickedRelayButton() { // Maintain the button state along with the bool variable if(m_bRelayState) { m_cRelayButton.SetState(FALSE); m_cRelayButton.SetWindowTextA("OFF"); m_bRelayState = false; } else { m_cRelayButton.SetState(TRUE); m_cRelayButton.SetWindowTextA("ON"); m_bRelayState = true; } }
Any suggestions please. Andy.If you have a button I sugget use of a checkbox.
WhiteSky