Home arrow C++ arrow Page 4 - Using MFC in C++ Part 2: Menus
C++

Using MFC in C++ Part 2: Menus


In part one of this series, Mitch described how to create a simple MFC based application skeleton. In this article, he builds on part one, and adds a menu to the applications main window. He also talks about accelerator keys.

Author Info:
By: Mitchell Harper
Rating: 4 stars4 stars4 stars4 stars4 stars / 47
November 29, 2001
TABLE OF CONTENTS:
  1. · Using MFC in C++ Part 2: Menus
  2. · The resource file
  3. · Adding a resource file to our project
  4. · A sample menu
  5. · Loading the menu
  6. · Linking up our new menus
  7. · Adding the OnItem functions
  8. · Adding accelerator keys
  9. · Conclusion

print this article
SEARCH DEVARTICLES

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.
blog comments powered by Disqus
C++ ARTICLES

- Intel Threading Building Blocks
- Threading Building Blocks with C++
- Video Memory Programming in Text Mode
- 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++

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials