C++
  Home arrow C++ arrow Page 3 - Using MFC in C++ Part 3: Dialog Boxes
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  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
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 3: Dialog Boxes
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 33
    2001-12-08

    Table of Contents:
  • Using MFC in C++ Part 3: Dialog Boxes
  • Creating a modal dialog box
  • Creating a modal dialog box (contd.)
  • Encapsulating our dialog resource
  • Creating a modeless dialog box
  • The OnInitDialog() function
  • 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 3: Dialog Boxes - Creating a modal dialog box (contd.)


    (Page 3 of 7 )

    Because our dialog box is a resource, we will add it to the bottom of our mydialog.rc file, as shown below:

    TestDialog DIALOG 0, 0, 300, 200

    CAPTION "My Test Dialog Box"

    STYLE DS_MODALFRAME | WS_VISIBLE | WS_CAPTION | WS_SYSMENU

    {

    // Controls for the dialog will go here

    }


    We have just created a new dialog resource. Our new dialog resource has three components, as described below:

    TestDialog DIALOG 0, 0, 300, 200

    This is the declaration of our dialog resource. It contains six properties:

    [DialogId], DIALOG, [xPos], [yPos], [width], [height]

    DialogId: The id that we will use to reference our dialog box. Can be either a string of text, or a #defined ID. We have used TestDialog, which is interpreted by C++ a string of text, because we haven’t #defined an ID named TestDialog.

    DIALOG: The dialog keyword tells the C++ resource compiler that we are creating a new dialog box. If we wanted to create a dialog box with extended styles, we would use DIALOGEX instead.

    xPos: The x-coordinate from which our dialog box will be positioned when it is loaded. This co-ordinate is relative to the parent window of the dialog box (if any).

    yPos: The y-coordinate from which our dialog box will be positioned when it is loaded. This co-ordinate is relative to the parent window of the dialog box (if any).

    width: The width of the dialog resource, in logical units (pixels).

    height: The height of the dialog resource in logical units (pixels).

    CAPTION "My Test Dialog Box"

    This line simply sets the window caption of our dialog resource.

    STYLE DS_MODALFRAME | WS_VISIBLE | WS_CAPTION | WS_SYSMENU

    The third line of our dialog resource defines how it will look. Firstly, we have the keyword STYLE. STYLE is suffixed with four different MFC defined style macros:
    1. DS_MODALFRAME: Our dialog box can be modal
    2. WS_VISIBLE: Our dialog resource will be visible when it is loaded
    3. WS_CHILD: Our dialog box can have a parent window
    4. WS_SYSMENU: Our dialog box will have a system menu. A system menu simply means that when the icon in the title bar of the dialog resource is clicked, several menu items such as Restore, Minimize and Close will be displayed.
    {

    // Controls on the dialog will go here

    }


    Lastly, we have the “contents” of our dialog resource. As you can see, ours is empty. We will place resources for radio buttons, edit boxes, check boxes, etc in our dialogs contents soon. Instead of using opening and closing braces, we could use BEGIN and END respectively, however, I think that braces make our resource file easier to read.

    We have just created our dialog resource. To actually make our dialog resource visible through our application, we have to encapsulate it within a class. We will do that now.

    More C++ Articles
    More By Mitchell Harper


     

    C++ ARTICLES

    - 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
    - First Steps in (C) Programming, continued
    - First Steps in (C) Programming, introduction
    - C++ Preprocessor: Always Assert Your Code Is...
    - C++ Preprocessor: The Code in the Middle
    - Programming in C
    - Temporary Variables: Runtime rvalue Detection







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