Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
3.40/5 (2 votes)
See more:
Hy what does equal this code in win32 project :

C#
if(radioButton1.Checked == True)
   MessageBox.Show("Hello");
Posted

C++
if ( Button_GetCheck(hwndRadioButton1) == BST_CHECKED)
{
  MessageBox(NULL, _T("Hello"), _T("Info"), MB_OK);
}


See Button_GetCheck macro[^], MessageBox function[^] at MSDN.
 
Share this answer
 
Comments
Mohibur Rashid 16-Sep-12 10:12am    
+5
CPallini 16-Sep-12 10:32am    
Thank you.
For MFC:
C++
CButton * btn = (CButton *)GetDlgItem(IDC_MY_RADIO);
if( btn != NULL )
    if( btn->GetCheck() == BST_CHECKED )
        AfxMessageBox( "Hello" );
 
Share this answer
 
Comments
Chuck O'Toole 16-Sep-12 22:24pm    
I don't have VS installed on this PC at the moment so I can't check but I'm pretty sure that GetDlgItem() returns a CWnd * not a CButton *. Since CButton is derived from CWnd, you are "Upcasting" an object and you can't be sure that "GetCheck()" will work. If it does work, it's by accident and not design.
skydger 17-Sep-12 4:23am    
I agree that this is not a good design of application, the DDX_Control and other things are better but also takes a time for additional code. If there is a need to use temporary variable whithout member object, GetDlgItem(...) is the way to do so.
Chuck O'Toole 17-Sep-12 13:20pm    
My issue is *not* with GetDlgItem(), I use it all the time. My issue is that you cast the return (CWnd *) to a CButton * which is NOT the correct thing to do. CButton is *derived* from CWnd, not the other way round. You are improperly UPCASTING to a higher object and none of the Vtable or member variables that are unique to CButton will be there. The only right way to do this is to subclass the control into a variable using DDX. Showing this incorrect technique to an obvious newbie isn't helping him at all.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900