Method 1:
When a radio button is used in groups, you only need to ensure that the resource number is continuous when the control is added, and the group in the first radio button attribute is selected.
In this way, you can add member variables to this group of controls.
Example:
1. Create a dialog box-based application, add three radio buttons, and select the group in the first radio button attribute for a button. Then associate raido1 with an int variable (also grouping is required) m_nradio1. Open the constructor in the dialog box and you will find the following:
M_nradio1 =-1; m_nradio1 do not assign a value-1, indicating that none of them are selected. If you change-1 to 0, you will find that radio1 is selected by default. In this case, the value of m_nradio1 is 1, and the second is selected (the problem also exists here, which one is the first? Which is the second one ?). It is easy to get the status. After updatedata (true), you can determine the value of m_nradio1.
2. Add code to the Click Event of the button:
UpdateData(TRUE); if(m_radio==0) MessageBox("0"); if(m_radio==1) MessageBox("1"); if (m_radio==2) MessageBox("2"); UpdateData(false);
Note: Sometimes these radio files must be generated at the same time. If a new radio is added later, the group may be invalid. In this case, you need to delete all radio files and add them again.
Method 2:
1. Create a dialog box-based application, and add three radio buttons with the following IDs:
Idc_radio1, idc_radio2, idc_radio3
2. Control initialization:
Add the code to oninitdialog of the dialog box class:
Checkradiobutton (idc_radio1, // The first parameter is the ID idc_radio3 of the first radio button in the group, // The second parameter is the ID idc_radio3 of the last radio button in the group ); // The third parameter is the ID of the selected radio button in the group.
3. Add a button control and write the Click Event code for it:
int iRadioButton; iRadioButton=GetCheckedRadioButton(IDC_RADIO1,IDC_RADIO3); if(iRadioButton==IDC_RADIO1) MessageBox("Click Button1"); if(iRadioButton==IDC_RADIO2) MessageBox("Click Button2"); if(iRadioButton==IDC_RADIO3) MessageBox("Click Button3");
Reprinted from: http://libala0805.blog.163.com/blog/static/108826907201178114849799/