there are books out there that shows you how to code with MFC that shows how to in 24 hrs 'yeah right , in 24 hrs?' anyways, it shows you the basics from windows and document architecture,buttons menus, toolbars, etc. It is a valuable resource, from there its all fun
What most developers don't realize is to how to properly use the DDX control/variable mechanism in MFC. Instead they needlessly pepper their code with GetDlgItem calls and create unnecessary logic to determine radio button state when all of this is built into MFC via the DDX mechanism.
If you leverage the DDX mechanism, you can determine which radio button is selected by looking at the zero-based index of a single integer variable rather than looking at the state of each radio button to determine the selected one.
To make this work, you set the Group property on the first Radio button in the group to 'True'.
Then you right click on the first radio button and choose "add variable". When the "Add variable" dialog appears, change the "Category" to "Value", set the "Variable type:" to "int", and enter a variable name.
This will create an integer variable and the value of this variable will tell you which of the radio buttons has been selected (or you would like to select). If the value is set to -1, then none of the radio buttons is selected (or cleared).
A couple of important points:
1) For the DDX variable mechanism to work, each of the radio buttons must be in consecutive tab order. The first button (i.e with the attached integer variable and group style set to true) must be have the lowest tab order index
2) The group property delineates "groups" of radio buttons and determines the range of what the integer variable attached to the first radio button covers. For example, if I have 5 radio buttons on a dialog - all of which are in consecutive tab order.
If I set the group style to true on the first radio button and create an DDX integer variable to this button, then all 5 radio buttons will be included in the range of indexes that the variable includes (i.e index range is 0 - 4). If I want to separate the last two buttons into a different group, then I need to set the group style on the 4th button and create another DDX integer variable for the 4th button - this variable will handle the states for the 4th and 5th button.
A word about UpdateData( ) and UpdateData( FALSE ). In general, this method causes the DDX mechanism to take the value of a DDX variable and send it to or retrieve it from the control it's attached to.
In the case of the radio buttons, we determine which button is checked by calling UpdateData( ) and then looking at the appropriate member variable. To clear radio button state, set the member variable to -1 and then call UpdateData( FALSE ).
All of this is actually take far less time to implement than it does to explain. It probably took me about 5 minutes to create the attached sample application. It probably took me 10 minutes to try to explain it.
Guys, i have around 8 radio buttons in my program.
is there a command line which i can clear all radio button selection when i press on a button?
i believe not, how is the program supposed to know what buttons to uncheck etc... in side the so called reset/uncheckall button get the handles to each control and uncheck the controls
I've done my clear radio selection problem. thanks guys
Just 1 more problem.
say if i have 3 groups of buttons
can i disable group "b and c" buttons until any of the group a button is press?
im doing in mfc.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.