C++
  Home arrow C++ arrow Page 7 - 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 - Adding the OnItem functions


    (Page 7 of 9 )

    Our CMainWin class declaration now has three function declarations: OnItem1, OnItem2 and OnItem3. These functions need to be defined in menu.cpp. Add the following code just before the “CApp App;” line in menu.cpp:

    afx_msg void CMainWin::OnItem1()

    {

    MessageBox("This is the first menu item", NULL, MB_OK | MB_ICONINFORMATION);

    }

    afx_msg void CMainWin::OnItem2()

    {

    MessageBox("This is the second menu item", NULL, MB_OK | MB_ICONINFORMATION);

    }

    afx_msg void CMainWin::OnItem3()

    {

    MessageBox("This is the third menu item", NULL, MB_OK | MB_ICONINFORMATION);

    }


    These are three similar functions, which display a message box when each menu item is clicked on. The MessageBox() function is a member of the CMainWin() class and takes three parameters:

    lpszText: The text to display in the message box

    lpszCaption: The text to display as the title of the message box

    nType: The icon of the message box, as well as the combination of buttons which will be displayed on the message box. These are integer values that can be ored together and are defined in afxwin.h (and its other included header files). Our message box uses MB_OK (for an OK button) and MB_ICONINFORMATION (to display an information icon). Other values include: MB_ICONSTOP, MB_ICONEXCLAMATION, MB_ABORTRETRYCANCEL and MB_YESNO). Style id’s are mutually exclusive meaning that two MB_ICON… values can’t be ored together, for example.

    Finally, compile and run your new menu app. It should work as expected, displaying a message box whenever a menu item is clicked on:

    The message box appears when a menu item is clicked

    Now that we can create a menu, lets talk about accelerator keys and hot keys.

    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 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek