Common functions:
(Cbutton *) getdlgitem (idc_radio1)-> setcheck (true); // select
(Cbutton *) getdlgitem (idc_radio1)-> setcheck (false); // do not select
(Cbutton *) getdlgitem (idc_radio1)-> getcheck (); if 1 is returned, the value 0 indicates that the value is not selected.
Multiple groups are used in the same way as a group. You only need to know which group is used. Add radio3 and radio4 to the dialog box. Very simple
Single, sort the order of these radio buttons first (this must be done. For example, if one of your controls has radio1, Radio2, and radio3
Their tab order is set to 1, 2, 3, and the group attribute of radio1 is set to true. In this way, when radio1 is selected, it is associated with it.
The variable is 0. When Radio2 is selected, the associated variable is 1, and so on), that is, the taborder of them.
On the Resource Panel of the dialog box, press Ctrl + D and click one by one in the desired order. Assume that radio1,
Radio2, radio3, and radio4 are respectively 1, 2, 3, and 4. Radio1 and radio3 both select the group attribute. Therefore, 1 and 2 are a group and 3
4 is another group, because the grouping principle is to select the group attribute from the beginning until the next group attribute is selected.
CTRL + D again to make radio1, Radio2, radio3, and radio4 respectively 1, 3, 2, and 4. Then radio1 and radio3 are a group.
If m_nradio1 = 1, radio3 is selected instead of Radio2. Use them separately after grouping.
Well, it's very easy to add mouse-click events for them.
Use of the radio button
Keywords: radio button control usage
1. Group Single-choice buttons:
Set attributes for the first single-choice button in each group: group, tabstop, and auto. Set attributes for other buttons: tabstop and auto. For example:
Radio1, Radio2, and radio3 are a group, and radio4 and radio5 are a group.
Set radio1 attributes: group, tabstop, auto
Set the Radio2 attribute: tabstop, auto
Set the radio3 attribute: tabstop, auto
Set radio4 attributes: group, tabstop, and auto
Set the radio5 attribute: tabstop, auto
2. Use classwizard to define variables for single-choice controls. Each group can only define one variable. For example, m_radio1 and m_radio4.
3. Use classwizard to generate the click message function of each radio button and add the following content:
Void cweditview: onradio1 ()
{
M_radio1 = 0; // The first radio button is selected.
}
Void cweditview: onradio2 ()
{
M_radio1 = 1; // The second radio button is selected.
}
Void cweditview: onradio3 ()
{
M_radio1 = 2; // The third radio button is selected.
}
Void cweditview: onradio4 ()
{
M_radio4 = 0; // The fourth radio button is selected.
}
Void cweditview: onradio5 ()
{
M_radio4 = 1; // The fifth radio button is selected.
}
// Use the radio button
Method 1:
After adding a control to the project, you can directly write the required code in the Click Event of the control.
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, idc_radio3, idc_radio3); // The first parameter is the first radio button of the group.
ID
// The second parameter is the ID 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 ");
Other Instructions:
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 attribute of the first radio button is
The Group 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 one button
Select the group in the first radio button attribute
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 );