Click here to Skip to main content
15,894,539 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am going to develop mfc dialogue based application in which one scenario there is 3 radio buttons; whenever user click on the 3rd radio button, some controls on the dialog should be disable!!! How can I do that??
Posted

1 solution

Add BN_CLICKED handlers for all radio buttons to detect state changings. From within the handler, enable or disable dependant controls according to the button states. With your scenario, one function can handle it all:
// Handler function declared in header as 
//  afx_msg void OnBnClickedRadio();

ON_BN_CLICKED(IDC_RBTN_1, OnBnClickedRadio)
ON_BN_CLICKED(IDC_RBTN_2, OnBnClickedRadio)
ON_BN_CLICKED(IDC_RBTN_3, OnBnClickedRadio)

void CMyDialog::OnBnClickedRadio()
{
    // Enable controls if radio button 3 is not checked
    CButton *pRadio3 = (CButton*)GetDlgItem(IDC_RBTN_3);
    BOOL bEnable = (BST_CHECKED != pRadio3->GetCheck());
    // Access control by ID
    GetDlgItem(IDC_SOME_CONTROL)->EnableWindow(bEnable);
    // Access control by member var
    m_SomeOtherControl.EnableWindow(bEnable);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900