I have a dialog box with a check-box and a button. I want to make the button ena开发者_如何学JAVAbled/disabled depending on the state of the check-box. I have tried achieving this using ON_UPDATE_COMMAND_UI:
...
DDX_Check(pDX, IDC_CHECK1, bFlag);
...
ON_UPDATE_COMMAND_UI(IDC_BUTTON1, OnUpdateButton1)
...
void ColorDialog::OnUpdateButton1(CCmdUI* pCmdUI)
{
pCmdUI->Enable(bFlag);
}
But nothing happens. Checking/unchecking the check-box does nothing to the button.
What am I doing wrong here?ON_UPDATE_COMMAND_UI is relevant only for menu items amd toolbar buttons. You have to add ON_BN_CLICKED to your message map.
Add an eventhandler for checkbox-click, where you call
UpdateData(TRUE);
pButton->EnableWindow(bFlag);
This should do the trick.
精彩评论