C++
  Home arrow C++ arrow Page 4 - Using MFC in C++ Part 4: Controls, DDX and...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
C++

Using MFC in C++ Part 4: Controls, DDX and DDV
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 38
    2001-12-17

    Table of Contents:
  • Using MFC in C++ Part 4: Controls, DDX and DDV
  • Controls explained
  • The push button control
  • The check box control
  • The radio button control
  • The list box control
  • The group box control
  • DDX and DDV explained
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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:

    AUTOCHECKBOX "Able to vote?", IDCB_CANVOTE, 20, 35, 50, 15, WS_VISIBLE | WS_CHILD | WS_TABSTOP

    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);

    pCheck->SetCheck(1);


    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.

    More C++ Articles
    More By Mitchell Harper


     

    C++ ARTICLES

    - Paths and Files
    - Directories in C++
    - Focusing on C++ Files
    - Const Correctness in C++
    - Manipulating Streams and Files with C++
    - Streams and Files
    - Multiplying Large Numbers with Karatsuba`s A...
    - Large Numbers
    - Dijkstra`s Shunting Algorithm with STL and C...
    - Brief Introduction to the STL Containers
    - The Standard Template Library
    - Templates in C++
    - C++ Programmer Alerts
    - C++ Programming Tips
    - First Steps in (C) Programming, conclusion






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT