Click here to Skip to main content
12,455,701 members (93,589 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VS2008 Visual-Studio MFC , +
I am creating MFC Dialog based application.
I have three radio buttons in a dialog using VS2008. I have tried the following code and it always returns 0 even though the first radio button is checked while I Have set Group(WS_Group) property true for all buttons. What am I doing wrong?

int CtrlID = GetCheckedRadioButton(IDC_RADIO_1, IDC_RADIO_3);
Posted 15-Jan-13 20:43pm
Updated 24-Jan-13 22:23pm
v5
Comments
SoMad 25-Jan-13 4:21am
   
As I recall, you should only set the Group property to true on the first button.

Soren Madsen
Jochen Arndt 25-Jan-13 4:23am
   
Is IDC_RADIO_1 smaller than IDC_RADIO_3? If not, the call will always return 0. Are the IDs in consecutive order? This is not really necessary but recommended.
Member 7909353 25-Jan-13 8:11am
   
I MAKE A CALL WRONGLY.
NOW MAKE THE BUTTONS ASSCENDING ORDER.
IT FINE.
H.Brydon 25-Jan-13 22:31pm
   
Not correct - the IDs do not need to be in consecutive order (although this is a good idea for maintenance purposes).

The controls need to be in consecutive tab order to work correctly.
Jochen Arndt 26-Jan-13 4:19am
   
What is not correct?
GetCheckedRadioButtons() uses a for loop. So the first ID must be the smallest one and the last the largest one. The tab order does not care for the function.
H.Brydon 26-Jan-13 14:07pm
   
[wait wait read all of it before replying]
Here are some IDs that are a mix of contiguous and non-contiguous (in resource.h or equiv):

#define IDC_RADIO_1 42
#define IDC_RADIO_22 74
#define IDC_RADIO_12 55
#define IDC_RADIO_23 56

Here are controls that are not in consecutive tab order (in app.rc or equiv):

IDD_Whatever...
BEGIN
CONTROL "ABC1",IDC_xx1,"Button",BS_AUTORADIOBUTTON | WS_GROUP,21,326,110,10
CONTROL "ABC2",IDC_xx2,"Button",BS_AUTORADIOBUTTON,21,340,110,10
CONTROL "ABC3",IDC_xxx3,"Button",BS_AUTORADIOBUTTON,21,355,110,10
CTEXT "Blah blah",IDC_POSNWONLOSTCHECK,148,342,85,8,SS_CENTERIMAGE
CONTROL "ABC4",IDC_xxx4,"Button",BS_AUTORADIOBUTTON,21,368,110,10
CONTROL "ABC5",IDC_xxx5,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,21,382,110,10
END

Controls ABC1/2/3 are in contiguous tab order. ABC4/5 are not (with 1/2/3). The ID values of IDC_xxx1/2/3/4/5 do not matter. The tab order does matter.

[update] Jochen Arndt I are both right, on 2 points. Jochen is correct that the IDs that need to be contiguous. My example above with IDC_RADIO_1 through IDC_RADIO_23 is how NOT to do it. If you use GetCheckedRadioButtons() the IDs need to be contiguous. To be properly recognized as a group, the controls need to be in contiguous tab order (as with ABC1/2/3 in my resource file example).

See http://support.microsoft.com/kb/138663 for more details on the ID problem.
Member 7909353 25-Jan-13 4:59am
   
Yes,Thank you!

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


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 25 Jan 2013
Copyright © CodeProject, 1999-2016
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