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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

radio button member function access

Status
Not open for further replies.

reneb

Programmer
Aug 8, 2000
43
US
I am placing a radio button in a dialogue box using the resource editor. I want to check its status when the dialogue box closes. There is method called CButton::GetCheck which returns the status of the radio button, but I can't access it because I don't have an object name to use for the call. I can't do radiobuton.GetCheck(); because all I know about my radio button is its ID. How can I access the GetCheck method? Please help. Thanks in advance.
 
All you have to do is say<br>your dialogname like this :<br>Cdialog1::GetCheck();<br>or CDialog1.GetCheck();<br><br>I cant remember precisely !<br>I hope it helps!<br>&nbsp;<br>
 
> when the dialogue box closes

That statement is ambigious. If you mean inside the dialog in the WM_CLOSE handler you would do something like this:

// WM_CLOSE message handler
void MainDlg::OnClose()
{
int iVal = -1;
CButton* pBtn = dynamic_cast<CButton*>(GetDlgItem(IDC_BGREY));
if ( pBtn)
iVal = pBtn->GetCheck();

TRACE(&quot;Radio.getCheck returned: %d\r\n&quot;, iVal);
CDialog::OnClose();
}


If you mean from the caller code that created the dialog you would do something like this:

// public member function
int MainDlg::getRadioCheck(UINT id)
{
int nret = -1; // failed to find control 'id'
CButton* pBtn = dynamic_cast<CButton*>(GetDlgItem(id));
if ( pBtn)
nret = pBtn->GetCheck();

return nret;
}

// now in the callers code
void MyFrame::showTestDlg(){

MainDlg dlg;
if ( IDOK == dlg.DoModal()){
TRACE(&quot;MainDlg.radioValue is %d\r\n&quot;,
dlg.getRadioCheck( IDC_BGREY));
}
}

Hope this helps
-pete
 
void CBUTONDlg::OnButton1()
{
int i;

i = GetCheckedRadioButton(IDC_RADIO1, IDC_RADIO3);

switch(i)
{
case IDC_RADIO1:
strcpy(str1 , &quot;Radio1&quot;);
break;
case IDC_RADIO2:
strcpy(str1 , &quot;Radio2&quot;);
break;
case IDC_RADIO3:
strcpy(str1 , &quot;Radio3&quot;);
break;
default:
strcpy(str1 , &quot;(Seçili öge yok) Nothing Selected!&quot;);
break;
}
AfxMessageBox (str1);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top