Home arrow C++ arrow Page 4 - 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 check box control
(Page 4 of 9 )

As with the EDITTEXT control, we create both the check box control within our resource file. Updating our example resource file, we would add a check box, like this:


This would add a check box to our dialog box. Its caption would be set to ďAble to vote?Ē. MFC provides two types of check boxes: The CHECKBOX, and the AUTOCHECKBOX control. In our example above, I have used the AUTOCHECKBOX control, simply because if we chose the CHECKBOX control, we would have to handle the checking and un-checking of the box manually, which is just a pain.

The syntax of the CHECKBOX control is shown below:

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

The caption of the check box is the text that will be displayed next to the check box. The control id is a numerical id, which is #defined within another header file. In our example, we have used IDCB_CANVOTE. I have prefixed the check box controls id with IDCB, which is representational for ďCheck Box IdentificationĒ. You can, however name your controls idís whatever you like.

Itís really simple to get and set the value of a check box control. As you can probably guess, a check box is either on or off, 1 or 0. We retrieve the value of our check box control like this:

int checkState;

CButton* pCheck = (CButton*)GetDlgItem(IDCB_CANVOTE);

checkState = pCheck->GetCheck();

As with the EDITTEXT control, we retrieve a reference to the control via its id. The check box control is a member of the CButton class, so we cast it as such. The GetCheck method of the CButton class returns the current value of our check box: 0 for not checked, or 1 for checked.

To set the value of our check box control, we can use the SetCheck method, like this:

CButton* pCheck = (CButton*)GetDlgItem(IDCB_CANVOTE);


Thatís pretty much all you need to create and use a check box control because they are so simple. Letís now look at the radio button control.
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-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials