C++
  Home arrow C++ arrow Page 3 - 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 
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 2: Menus
By: Mitchell Harper
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 29
    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 - Adding a resource file to our project


    (Page 3 of 9 )

    It’s really simple to add a resource file to our project. Simply click on the file menu and choose the New… option. Click on the Files tab and choose the text file option. In the file name field, enter “menu.rc” and click on the OK button. If we wanted to use the built-in GUI editor to create menus using a point and click interface, we would choose the resource script option instead. But, because we chose the text file option, we will be able to build the resource file by hand, using plain text. This is the best way to learn how menus work and interact with our MFC app.

    Adding a new text-based resource file to our app

    Now, double-click on the menu.rc file under the FileView tab of the Workspace window. We’re ready to create our menu!

    Firstly, let’s describe the structure of a menu:

    [MenuName] MENU

    {

    POPUP “[Item Text]”

    {

    MENUITEM “[Item Text]”, [Item Id]

    MENUITEM" “[Item Text]”, [Item Id]

    }

    }


    MenuName is the name that we will use throughout our code to reference our menu. It should start with an alphabetical character and contain only alphanumeric characters, such as MyMenu, Menu3, Red99Menu, etc. Next to the menu name, we have the MENU keyword, which tells the resource compiler that we are creating a new menu.

    Next, between a set of braces, we have the POPUP keyword. This creates a new popup menu. Popup menus are the most common windows menu type, and the perfect example of a popup menu is the drop down menu that appears when you click on the “File” menu at the top of this browser window. The item text of the popup menu is enclosed in quotes and will be used to display the name of the popup menu on the menu bar. The “File” text shown in the menu at the top of this browser window is an example of a popup menus item text.

    Next, we have two menu items. They are prefixed with the MENUITEM keyword, followed by the actual text that will be displayed for that item. Lastly, the item id is either a textual/numerical value, which will be used to represent the menu throughout our code. Typically, we would #define a value for each items ID in another file and include this file into the resource script. More on this in a minute.

    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

    - 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 1 hosted by Hostway
    Stay green...Green IT