C++
  Home arrow C++ arrow Page 5 - Using MFC in C++ Part 2: Menus
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 
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 2: Menus
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 31
    2001-11-29

    Table of Contents:
  • Using MFC in C++ Part 2: Menus
  • The resource file
  • Adding a resource file to our project
  • A sample menu
  • Loading the menu
  • Linking up our new menus
  • Adding the OnItem functions
  • Adding accelerator keys
  • 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 2: Menus - Loading the menu


    (Page 5 of 9 )

    To load the menu, we need to double-click on menu.cpp and change the constructor of the derived CMainWin class, as shown below:

    CMainWin::CMainWin()

    {

    Create(NULL, "My Test Menu Application", WS_OVERLAPPEDWINDOW,

    rectDefault, NULL, "MyMenu");

    }


    We are adding changing the parameters passed to the Create() function, which creates an instance of our main window. The new parameters are:

    WS_OVERLAPPEDWINDOW: The style of our window. Other styles include WS_VSCROLL, WS_HSCROLL and WS_EX_TOOLWINDOW. The styles can be Ored together to use more than one, i.e.: WS_OVERLAPPEDWINDOW | WS_VSCROLL for a normal window with a vertical scroll bar.

    rectDefault: This is a RECT structure which contains the location of where our window will be loaded when it is create: a top, left, right and bottom co-ordinate. To set the location of the window manually, create a new MFC RECT object above the create() line, like this:

    RECT r;

    r.top = r.left = 100;

    r.bottom = r.right = 300;


    Next, change the rectDefault parameter to match your newly created RECT object, r.

    “MyMenu”: This is the name of our menu, enclosed by quotes. This will load our menu and display it as part of our apps main window. Compile and run your app (Cntl+F5). It should now have a menu, like this:

    Our new menu and its disabled menu items

    Notice how our menu options can’t be selected as yet? This is because they don’t contain any code to link them to a specific function when they are clicked on. Let’s add that code now.

    More C++ Articles
    More By Mitchell Harper


       · I have one small question,can u tell me how to provide this key board short...
     

    C++ ARTICLES

    - 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++
    - Advanced File Handling with Streams in C++
    - File Handling and Streams in C++
    - The STL String Class







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