CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: MFC problems

  1. #1
    Join Date
    Jan 2010
    Posts
    9

    MFC problems

    Hi all..

    I'm working wid MFC on a dialog base program wid opencv,
    does anyone knows how to clear the radio button selection when i click on a button?

    another problem i'm facing is - hw do i prompt a error message when step one button is not press and user jump to e second step button instead


    thanks in advance for the help.

  2. #2
    Join Date
    Apr 2008
    Posts
    133

    Re: MFC problems

    In MFC, a radio button is a CButton so you can use CButton SetCheck with BST_UNCHECKED to uncheck it.
    For prompting the user you can use AfxMessageBox

  3. #3
    Join Date
    Feb 2010
    Posts
    30

    Re: MFC problems

    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

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: MFC problems

    +1 on the get a book on MFC recommendation.

    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.
    Attached Images Attached Images
    Attached Files Attached Files

  5. #5
    Join Date
    Jan 2010
    Posts
    9

    Re: MFC problems

    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??

  6. #6
    Join Date
    Apr 2008
    Posts
    133

    Re: MFC problems

    See if this helps..
    CWnd::CheckRadioButton

  7. #7
    Join Date
    Feb 2010
    Posts
    30

    Re: MFC problems

    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

  8. #8
    Join Date
    Jan 2010
    Posts
    9

    Re: MFC problems

    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.

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: MFC problems

    Quote Originally Posted by dception View Post
    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??
    Did you read my previous post? You know the one with the complete source code that included clearing radio buttons?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured