Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio Buttons

Status
Not open for further replies.

nbgoku

Programmer
May 25, 2004
108
US
ok with check buttons, i understand how to create bool variables to contain the values as to whether or not the check buttons have been cheched or not, but with radio buttons, do i also define bool variables containing 1 or 0, how does it work with radio buttons
 
you can attach a single variable to your group of radio buttons. e.g.

int option;

This will result in option = 0 for the first check box in your radio control, 1 in second etc.......
 
not required. You may handle OnCommand or WM_COMMAND when some of box is set.

Ion Filipski
1c.bmp
 
shetlandbob i tryed what u said, but it doesnt seem to work for me, would u have an example i could follow by?
 
what i did was select 2 of the radio buttons, and then add a int variable from the Add Variable option, then i went into my program and tryed to fool around with the int variable, given it values 0 or 1, and doing UpdateData(0); b/c i want 1 of them to be preselected when the program starts (sort of like a default selection), but it didnt work
 
Did you set one of the radio button group variables to true? ( the first one in the tab order, thus all others in your tab order will be in that group of radio buttons until it finds another that has group set to TRUE)

Then when you add a variable you should get

Code:
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
  CDialog::DoDataExchange(pDX);
  [b]DDX_Radio(pDX, IDC_RADIO1, radio);[/b]
}

then in your OnInit

Code:
BOOL CMyDlg::OnInitDialog()
{
    CDialog::OnInitDialog();
    
    SetIcon(m_hIcon, TRUE);     // Set big icon
    SetIcon(m_hIcon, FALSE);    // Set small icon

    [b]radio = 0;
    UpdateData ( false );[/b]
    return TRUE;
}

Thus when you load up your dialog you will have the first one set to default (Set = 1 to get your second etc....)
 
how did u define radio, b/c when i run my program i get radio as an undeclared identifier, i think i missed a step or 2 in the beginning when declaring radio but dunno which steps
 
you can do handle each pressing of RadioButton. It sends to window a WM_COMMAND. You will handle

..... OnCommand(WPARAM wParam)
{
somevalue = wParam... this is the just choosen option
}
or
.....OnRadioButtonXXXX....()
{
somevalue = xxxx...
}

...... OnRadioButtonYYYY....()
{
somevalue = yyyy...
}

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top