MFC Learning Radio---MFC radio button Group use example

Source: Internet
Author: User

First we have to complete a function, in a new user to add the scene, through the radio button to determine whether the user chooses the administrator or the ordinary user.

To use the functionality of the radio group first we must make the following settings:

1, 2 Radio The ID number of the button is different, but their tab order must be arranged in order, these can be found in the Resource.h file.

such as: Radio1 id:idc_radio_admin

Radio2 Id:idc_radio_user

In the Resource.h file we may see:

#define IDC_RADIO_ADMIN 1001

#define IDC_RADIO_USER 1002

2, set the first radio button property within the group is true, then Radio1 and Radio2 become a group, if there are Radio3 and Radio4, if the Radio3 group is set to True, Then Radio3 and Radio4 become a group.

Well, the settings need to be done well, then, how to apply it?

In order to capture the user's event on this radio button group, we need to add a message (manually added) to the class associated with the group.

Before adding a message, we can add an enumeration variable to the associated dialog class in order to differentiate between which button the user chooses.

Public

enum {Admin, User} m_nusertype;

Now we're going to add message processing

1, in the class header file added: afx_msg void Onbnclickedradio (UINT idctl);

2. Add between Begin_message_map and End_message_map ()
On_control_range (bn_clicked, Idc_radio_admin, Idc_radio_user, Onbnclickedradio)

ON_CONTROL_RANGE This macro requires 4 parameters:

1. Type of event: Click event here

2. Button group's first button (identity start)

3. The last button of the button group (logo end)

4. Function of Event response

3. Add this function to the implementation file (CPP) of the class

void Cdlgxxx::onbnclickedradio (UINT idctl)
{
if (Idctl = = idc_radio_admin)
M_nusertype = Admin;
if (Idctl = = Idc_radio_user)
M_nusertype = User;
}

Here we are set to complete.

http://blog.csdn.net/lwwworkspace/article/details/6054354

MFC Learning Radio---MFC radio button Group use example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.