Enable button in MFC dialog
3 answers
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 to share