一、顺序绑定

1.定义变量

    int m_nValue;

2.关联变量

    DDX_Radio(pDX, IDC_RADIO1, m_nValue);

void CTestRadioDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    DDX_Radio(pDX, IDC_RADIO1, m_nValue);
}

3.赋值

CTestRadioDlg::CTestRadioDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestRadioDlg::IDD, pParent)
    , m_nValue(0)

 

4.定义资源id

#define IDC_RADIO1                      1000
#define IDC_RADIO2                      1001

 5.在对话框资源中的位置


CONTROL "Radio1",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON | WS_GROUP ,43,37,38,10 CONTROL "Radio1",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON,45,62,38,10

以上完成,m_nValue==0时,上一个radio选中

二、但我想m_nValue==0下一个radio选中,该怎么办呢?

1.

#define IDC_RADIO2                      1000
#define IDC_RADIO1                      1001

2.

    CONTROL         "Radio1",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON | WS_GROUP,45,62,38,10
    CONTROL         "Radio1",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON ,43,37,38,10

完成。

三、你还可以这样做

    CONTROL         "Radio1",IDC_RADIO2,"Button",BS_AUTORADIOBUTTON | WS_GROUP ,45,62,38,10
    CONTROL         "Radio1",IDC_RADIO1,"Button",BS_AUTORADIOBUTTON,43,37,38,10

 

    DDX_Radio(pDX, IDC_RADIO2, m_nValue);