Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC VC++
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 10-Jan-13 21:17pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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);
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 386
1 Marcin Kozub 225
2 Sergey Alexandrovich Kryukov 215
3 /\jmot 189
4 Praneet Nadkar 173
0 OriginalGriff 8,289
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,624
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 11 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100