C++
  Home arrow C++ arrow Page 2 - 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 - The resource file


    (Page 2 of 9 )

    In C++, objects such as buttons, dialog boxes, menus, list boxes and radio buttons are created as part of a resource file. A resource file contains a resource script, which is compiled at run-time by a resource compiler. The resource compiler is typically bundled with the C++ IDE. In this article, I will be using Microsoft Visual C++ 6 and its built in resource compiler to discuss menus.

    You should be familiar with a menu. A menu is simply a column of buttons that can be activated by clicking on them. When they are clicked on, a popup menu may be displayed showing further options. These options can also be popup menus in themselves, and can contain a further set of options, etc.

    To demonstrate how we will incorporate a menu into our C++ project via a resource file, open Microsoft Visual C++ 6 and create a new empty Win32 project as described in article 1. Name the project “MenuApp”.

    Right click on the “MenuApp classes” node under the ClassView tab, and add a new class. Name the new class “menu”, as shown below:

    Our new class, containing menu.cpp and menu.h

    Click on the FileView tab and expand all of the nodes. Double click on menu.h and then menu.cpp and delete all of the code in the right hand window. To re-create our basic application skeleton, enter the following code into menu.h:

    class CMainWin : public CFrameWnd

    {

    public:

    CMainWin();

    DECLARE_MESSAGE_MAP()

    };

    class CApp : public CWinApp

    {

    public:

    BOOL InitInstance();

    };


    Next, double-click on menu.cpp and enter the following code:

    #include <afxwin.h>

    #include "menu.h"

    CMainWin::CMainWin()

    {

    Create(NULL, "My Test Menu Application");

    }

    BOOL CApp::InitInstance()

    {

    m_pMainWnd = new CMainWin;

    m_pMainWnd->ShowWindow(m_nCmdShow);

    m_pMainWnd->UpdateWindow();

    return TRUE;

    }

    BEGIN_MESSAGE_MAP(CMainWin, CFrameWnd)

    END_MESSAGE_MAP()

    CApp App;


    I wont describe the code above because it was covered in part one of this series.

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