Click here to Skip to main content
12,950,090 members (72,711 online)
Rate this:
Please Sign up or sign in to vote.
See more:
what does equal this code in win32 project :

if(radioButton1.Checked == True)
Posted 15-Sep-12 20:29pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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

See Button_GetCheck macro[^], MessageBox function[^] at MSDN.
Mohibur Rashid 16-Sep-12 10:12am
CPallini 16-Sep-12 10:32am
Thank you.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

For MFC:
CButton * btn = (CButton *)GetDlgItem(IDC_MY_RADIO);
if( btn != NULL )
    if( btn->GetCheck() == BST_CHECKED )
        AfxMessageBox( "Hello" );
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)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,749
CHill60 3,380
Maciej Los 2,953
Jochen Arndt 1,935
ppolymorphe 1,820

Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 16 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100