Home arrow C++ arrow Page 5 - Using MFC in C++ Part 4: Controls, DDX and DDV

Using MFC in C++ Part 4: Controls, DDX and DDV

In this article, Mitchell will describe how to add several controls to your dialog windows, including the edit box, group box, check box, list box and radio button. He will also describe what DDX and DDV functions are, and show you how to use them to automatically get and set the values of the controls on a dialog.

Author Info:
By: Mitchell Harper
Rating: 4 stars4 stars4 stars4 stars4 stars / 62
December 17, 2001
  1. · Using MFC in C++ Part 4: Controls, DDX and DDV
  2. · Controls explained
  3. · The push button control
  4. · The check box control
  5. · The radio button control
  6. · The list box control
  7. · The group box control
  8. · DDX and DDV explained
  9. · Conclusion

print this article

Using MFC in C++ Part 4: Controls, DDX and DDV - The radio button control
(Page 5 of 9 )

The radio button control is used to provide a user with a mutually exclusive set of options, which are accessible programmatically (just like the edit box and check box controls). We create radio buttons as part of our resource file. The syntax of our radio button is exactly the same as the CHECKBOX and AUTOCHECKBOX controls:

[AUTO]RADIOBUTTON [Caption], [Control Id], [X Pos], [Y Pos], [Width], [Height], [Style Options]

As with the CHECKBOX and AUTOCHECKBOX controls, we can prefix the definition with the ďAUTOĒ keyword, to let windows handle the changing of the options automatically. Radio buttons should be used when one and only one option in a group will be selected. You can retrieve the value of a radio button like this:

int radioState;

CButton* pRadio = (CButton*)GetDlgItem(IDRB_1);

radioState = pRadio->GetCheck();

Once again, the radio button control is part of the CButton class, and we cast it to a pointer-to-CButton using the GetDlgItem function. As with the check box control, the GetCheck returns 0 for off, or 1 for on.

The CTEXT control

Another very simple control is the CTEXT control. The CTEXT control acts like a label, and is primarily used for display purposes only. The CTEXT control has the following syntax:

CTEXT [Caption], [Control Id], [X Pos], [Y Pos], [Width], [Height], [Style Options]

We would add a label to a dialog boxes resource definition like this:

CTEXT "This is a label", IDCT_1, 10, 90, 60, 15, WS_VISIBLE | WS_CHILD | WS_TABSTOP

One of the more interesting and advanced control is the list box. Letís take a look at the list box now.
blog comments powered by Disqus

- Intel Threading Building Blocks
- Threading Building Blocks with C++
- Video Memory Programming in Text Mode
- More Tricks to Gain Speed in Programming Con...
- Easy and Efficient Programming for Contests
- Preparing For Programming Contests
- Programming Contests: Why Bother?
- Polymorphism in C++
- Overview of Virtual Functions
- Inheritance in C++
- Extending the Basic Streams in C++
- Using Stringstreams in C++
- Custom Stream Manipulation in C++
- General Stream Manipulation in C++
- Serialize Your Class into Streams in C++

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials