BrainDump
  Home arrow BrainDump arrow Page 3 - The Resource View of the MFC
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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? 
BRAINDUMP

The Resource View of the MFC
By: Gabor Bernat
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2008-03-26

    Table of Contents:
  • The Resource View of the MFC
  • Menu Editing
  • Dialog Boxes
  • Toolbar, Hot-Keys and Icons
  • Epilogue

  • 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


    The Resource View of the MFC - Dialog Boxes


    (Page 3 of 5 )

    Dialog boxes are mostly used to interact with the user; they are called Dialog Boxes for this very reason. Initially, their purpose was to assure communication with the client/user. Of course, they can also stand by themselves as a true application, but that is a little more complicated and exceeds the goal of this series. Also, a Dialog box is modular by default; in plain English, it means that while you have a dialog box opened, you cannot switch to any other window in the application.

    Sometimes you will need to switch between a dialog box and another client window; this can be realized by implementing a non-modular dialog box. I won't cover this part because this article is intended as an introduction, but don't hesitate to explore this more deeply should you find it intriguing. Google is your friend, don't forget that!

    Our goal is to create a dialog box that will get a text from the user and draw that text in the client area. Then, as an extra, we say that a blue background can be used. Also, we shall encapsulate this in the Enter Data... menu. You have already made up a Dialog box if you open the Dialog part of the resource tree. This represents the Dialog box that appears when you push down the About key in the menu. But don't rush ahead. We'll start with the creation process. Follow the path: Resource View -> Right Click on the Tree view -> Add Resource... -> Dialog -> New. If you've done it correctly, you should have something like this:



    Now we can start customizing some part of it. In the Property page, you'll find a multitude of ways you can change the style of the Dialog box. We won't mess with that part yet, so you can comprehend the essence of the remaining part.

    First of all, just make sure that the Toolbox is present in your Visual Studio. If the answer is affirmative, then we'll add an Edit Control, a Check Box, and a Static text. You shouldn't have a problem with this part because it is a simple and straightforward process. Just select the proper option from the Toolbox and drag it into the box. Follow this process via some resizing until you get something like what's in the attached screen shot below.




    Change the captions for the Static text and the check box as I did in the above image. Finally, we can include the dialog box into our project by right clicking on the Dialog box and choosing "Add a box." Enter a class name for the Dialog box and press Finish. The code is generated and we can start with the needed modifications. The name I have chosen is CTutorial. Also notice that we have this Dialog ID assigned: IDD_DIALOG1.



    We assign a variable to the data entered in the CEdit control. Simply right click on the control in the resource view and select Add variable. Make sure you select the options as shown in the picture below. The image is pretty self-explanatory, so I won't discuss it in detail. Repeat the procedure for the check box - you add an m_checkbox bool variable.



    As this is done, we can integrate our creation into the application. Go to the place where you added the OnDataoptionsEnterdata on the previous page and add the following line to the corresponding CPP:

    #include "Tutorial.h"

    This simple step creates our customized Dialog Box when we press the Enter Data... menu and proceed to add the following code at the end:


    void CMFC_exampleView::OnDataoptionsEnterdata()

    {

    CTutorial dialog;

     

    dialog.m_data = CString("Enter data");

    dialog.m_checkbox = _useBlue;


    INT_PTR result = dialog.DoModal();

    if( result == IDOK)

    {

    this->_print = dialog.m_data;

    this->_useBlue = dialog.m_checkbox;

    this->Invalidate();

    }


    }


    We declared a CString type _print variable in the CMFC_exampleView that stores the value we got from the Dialog box. For some on-screen result, add the following code in the OnDraw:


    if(_useBlue)

    {

    pDC->SetBkColor(RGB(0,0,255));

    }

    pDC->TextOutW(0,20,_print);


    Yes, we are done for now. You can start the application and see the results for yourself. I hope you enjoy it. The following page will finish up the resources.

    More BrainDump Articles
    More By Gabor Bernat


       · Welcome my friend and thanks for reading my article. As previously mentioned I...
     

    BRAINDUMP ARTICLES

    - Introduction to Office Live Workspace
    - Using MS Excel for One-way Analysis of Varia...
    - Comparing Data Sets Using Statistical Analys...
    - Import Blogger Posts into WordPress Using Wi...
    - Download WordPress from an FTP Server and Ru...
    - Install and Run WordPress in XAMPP Local Host
    - What Windows 7 Brings to the Table
    - Virtualization and Sandbox Detection
    - Advanced Firebug Techniques in Windows XP Ho...
    - Editing CSS with Firebug in Windows XP Home
    - Using Firebug in Windows XP Home
    - Migrating to Exchange Server 2007
    - Using System Restore on a Non-Bootable PC
    - Finding Logged on Users and More Scripting S...
    - Developing Macro Commands in MS Excel





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek