C++
  Home arrow C++ arrow Page 4 - 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 - A sample menu


    (Page 4 of 9 )

    To put all of our theory into practice, lets create a menu. Double click on menu.rc and enter the following code:

    #include <afxres.h>

    #include "ids.h"

    MyMenu MENU

    {

    POPUP "Popup"

    {

    MENUITEM "Item One", IDM_1

    MENUITEM "Item Two", IDM_2

    MENUITEM SEPARATOR

    MENUITEM "Item Three", IDM_3

    }

    }


    You’ll notice that we are #including two files: afxres.h, which is an MFC header file that contains several menu constants and macros. Secondly, ids.h, which will containe the definitions of our menu items id values. Notice how our menu items have id’s IDM_1, IDM_2 and IDM_3? We define these in ids.h. Create a new C++ header file (File -> New… C++ Header File) named ids.h. Into ids.h, enter the following code:

    #define IDM_1 101

    #define IDM_2 102

    #define IDM_3 103


    This simply creates three id variables with numeric values 101, 102 and 103 respectively. They are prefixed with IDM, which is representational for Identification Menu. We prefix all of our menu id’s with IDM.

    Simply compiling and running the app will not add the menu to our program. To add it, we will need to modify the CMainWin() constructor.

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