I have a simple problem that is driving me slightly nuts. I have a dialog-based MFC app which has 3 radio buttons on it, each with a click handler doing different things.
The third button activates a separate modal dialog, which has an OnCancel
handler. The OnCancel
handler calls CheckRadioButton
on the parent dialog, to try to set the check to the first button in the group (thus indicating that the Modal dialog is no longer up). This does indeed set the check correctly, but for some reason it also generates a call to the third radio button click handler, and so the modal dialog reappears. This happens repeatedly (about 7 times), until eventually the repetitive calls stop, the modal dialog disappears, and all is apparently normmal.
This first became apparent in a large desktop app that I am adding features to, but it also occurs in a simple minimal dialog-based app, which I put together to test things.
I've tried this all sorts of ways, including using CButton::SetCheck
, and also having a control variable and using UpdateData(FALSE)
. All generate the same problem.
I'm probably doing something daft, but I can't see what it is!! I'm using Visual Studio 2013. Any help greatly appreciated.
// in parent dialog
void Ctest_radioDlg::OnBnClickedRadio3()
{
TRACE(_T("Clicked 3"));
CTestDlg testDlg;
testDlg.m_pParent = this;
testDlg.DoModal();
}
// in modal dialog
void CTestDlg::OnCancel()
{
m_pParent->CheckRadioButton(IDC_RADIO1, IDC_RADIO3, IDC_RADIO1);
CDialogEx::OnCancel();
}
OnBnClickedRadio3
to callif (IDCANCEL==testDlg.DoModal()) CheckRadioButton(...)
This wayCTestDlg
is removed as suspect. You should perhaps show the message map, otherwise there shouldn't be any problem from what is shown here. – Barmak Shemirani