I have two buttons:
I want to enable "A" anytime users "Hex" button is checked (the state of "A" is "Disabled" when it is created), how can I do that? Thank everyone.
You need to use CButton
's EnableWindow
function.
buttonA.EnableWindow( TRUE );
If you do not have the CButton
object, you can access the button by calling GetDlgItem
with its ID:
GetDlgItem( IDC_BUTTON_A )->EnableWindow( TRUE );
You should use ON_UPDATE_COMMAND_UI
mechanism to enable/disable the 'A' or any other button in your dialog. By default it is not available for dialog based application but you can easily enable them by following this article.
The code in your update function will look something like this:
void CCalculatorDlg::OnUpdateButtonA(CCmdUI* pCmdUI)
{
if( m_ctrlBtnHex.GetCheck() == BST_CHECKED )
{
pCmdUI->Enable( TRUE );
}
else
{
pCmdUI->Enable( FALSE );
}
}
In your case since A, B, C, D, E, F will essentially have same states so you can instead do this:
void CCalculatorDlg::OnUpdateButtonA(CCmdUI* pCmdUI)
{
if( m_ctrlBtnHex.GetCheck() == BST_CHECKED) )
{
m_ctrlBtnA.EnableWindow( TRUE );
m_ctrlBtnB.EnableWindow( TRUE );
m_ctrlBtnC.EnableWindow( TRUE );
// so on...
}
else
{
m_ctrlBtnA.EnableWindow( FALSE );
m_ctrlBtnB.EnableWindow( FALSE );
m_ctrlBtnC.EnableWindow( FALSE );
// so on...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With