Enable button in MFC dialog

I have two buttons:
Radio button: "Hex"
and button: "A"
I want to enable "A" anytime the "Hex" button is checked (state "A" is "disabled" when it is created) as I can I do it? Thanks everyone.The Calculator MFC Application

+3


source to share


3 answers


You need to use CButton EnableWindow function .



buttonA.EnableWindow( TRUE );

      

+3


source


You must use the ON_UPDATE_COMMAND_UI mechanism to enable / disable "A" or any other button in your dialog. It is not available by default for the dialog 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 the same states, so you can 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...
        }
}

      

+1


source


NameOfYourButton.EnableWindow( TRUE );

      

0


source







All Articles