dialogs and DDX_Radio()

This is a discussion on dialogs and DDX_Radio() within the Windows Programming forums, part of the Platform Specific Boards category; I need help getting from a radio button to a cstring. I need to find out the sex of the ...

  1. #1
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537

    dialogs and DDX_Radio()

    I need help getting from a radio button to a cstring. I need to find out the sex of the user but am not sure how to use the DDX_Radio function to find out which button is checked. Here is what I have so far but it crashes at run time when I try to open the dialogbox.
    Code:
    void NewCompetitorDlg::DoDataExchange( CDataExchange* pDX )
    {
    	CDialog :: DoDataExchange( pDX );
    
    	DDX_Text( pDX, IDC_EDIT_FIRST, newCompetitor->m_firstname );
    	DDV_MaxChars( pDX, newCompetitor->m_firstname, 20 );
    
    	DDX_Text( pDX, IDC_EDIT_LAST, newCompetitor->m_lastname );
    	DDV_MaxChars( pDX, newCompetitor->m_lastname, 40 );
    
    	DDX_Text( pDX, IDC_EDIT_SCHOOL, newCompetitor->m_school );
    	DDV_MaxChars( pDX, newCompetitor->m_school, 40 );
    
    	DDX_Radio( pDX, IDC_MALE, newCompetitor->m_sex );
    	DDX_Radio( pDX, IDC_FEMALE, newCompetitor->m_sex );
    }
    In case it isnt clear I have a compeitior object which contains a CString which needs to contain the competitors gender.

    tia
    Couldn't think of anything interesting, cool or funny - sorry.

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Add the radio button to the class member variable. Call GetCheck() to determine the status of the button.

    Kuphryn

  3. #3
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    ok I've sorted that now, I used the aptly named function IsDlgButtonChecked(...)

    The problem now is that I need to ensure that at least 1 radio button is checked. The best way for me to do this would be to displaya messagebox when the user hits ok, but I dont know where to put the code for that. That way a number of different things could be checked, like other buttons and stuff. This is the code that calls the dialog box:

    Code:
    bool TkdWin::addCompetitor( )
    {
    	Competitor empty;
    	NewCompetitorDlg dlg( empty );
    
    	if( IDOK == dlg.DoModal( ) )
    	{
    		//add a new record!
    		MessageBox( empty.m_sex );
    	}
    
    	return true;
    }
    So where do I put the messageboxes so that when ok is clicked the dialog does not actually dissapear but tells the user to complete the dialog?
    Couldn't think of anything interesting, cool or funny - sorry.

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    One solution is an event handler. Add an event handler for the radio buttons. When there is a change, traverse through them and determine their status. If none of the radio buttons is checked, then prompt the user.

    Kuphryn

  5. #5
    Seeking motivation... endo's Avatar
    Join Date
    May 2002
    Posts
    537
    Isn't there a simpler way? All I want is to check that 1 of 2 bools has been set to true, and other similar things with other buttons. I was hoping I could just check the variables and prompt the user to finish off the input before the dialog closes?

    Btw, I've made this dialog with the visual editor so what is the easiest way to access the different components, like radio buttons?
    Couldn't think of anything interesting, cool or funny - sorry.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21