SHARE
Facebook X Pinterest WhatsApp

A Cool Looking Menu For Easier Navigation

Download Source Code and Demo Features: Unlimited entries Displays 32X32 Icons with text Text wraps to multiple line Button pops up when the mouse is on the image Owner Drawn and easily customize the source! Can be used in SDI or MDI Usage Instructions: Open the project in which you want to add this feature. […]

Written By
thumbnail
CodeGuru Staff
CodeGuru Staff
Aug 6, 1998
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Sample image of the ContentMenu

Download Source Code and Demo

Features:

  • Unlimited entries
  • Displays 32X32 Icons with text
  • Text wraps to multiple line
  • Button pops up when the mouse is on the image
  • Owner Drawn and easily customize the source!
  • Can be used in SDI or MDI

Usage Instructions:

Open the project in which you want to add this feature. From the Project menu, select Add To Project and then Components &
Controls. From Developer Studio Components, select Dialog Bar component and click insert. When prompted, change the name of
the dialog bar to ContentMenu and the member variable to m_wndContentMenu.

Also change the default docking side to left and click OK and close all the Component Gallery windows.

Now, open the CG_IDD_CONTENTMENU from the dialog resource and replace the default TODO… static control with a new List
Box (it is a list box and NOT list control). Change the default ID from IDC_LIST1 to IDC_LIST_CONTENTS in the property window.
Also change the following style:

  • Owner Draw – Variable
  • No Sort
  • Optionally – change the extended style to Modal Frame

With the dialog bar open in the resource editor, bring up the Class Wizard by pressing Ctrl-W. You will be given the option of
creating a new class or select an existing class. Click Select an existing class and press OK. When prompted, select
CMainFrame from the list and click OK and close all the open windows.

  1. Add the provided ContentMenu.cpp to the project and include the ContentMenu.h in the mainfrm.h.
  2. Create a variable for the class CContentMenu in the CMainFrame object in mainfrm.h

        CContentMenu m_ContentMenu;
    

  3. In the OnCreate function of CMainFrame, add the following code

        m_ContentMenu.SubclassDlgItem (IDC_LIST_CONTENTS, &m_wndContentBar);
        m_ContentMenu.SetItems(ContentInfo, sizeof(ContentInfo) / sizeof(CONTENT_ITEMS));
    

    ContentInfo is a regular C structure defined in the mainfrm.cpp which holds the information about the items to be displayed. It is
    created as

        // Menu Information for the Content Bar
        static CONTENT_ITEMS ContentInfo[] =
        {
            {IDI_COMPOSE,  "Main View"},
            {IDI_FINISHED, "Another View"},
            {IDI_FILED,    "Another View"},
            {IDI_CALENDAR, "Another View"},
        };
    

    where IDI_… are the 32×32 icons.

Now, you should be able to compile and see how it works. To get the selection from the CMainFrame object, you have to add the
code to handle the ON_LBN_SELCHANGE message. Normally, you would do this by using the Class Wizard, but in this case, you
have to do it manually:

  1. Add the following prototype in the mainfrm.h

        afx_msg void OnSelchangeListContents();
    

  2. Add the following in mainfrm.cpp

        ON_LBN_SELCHANGE(IDC_LIST_CONTENTS, OnSelchangeListContents)
    

    before the line

        END_MESSAGE_MAP()
    

  3. Add the following function also in mainfrm.cpp

        void CMainFrame::OnSelchangeListContents()
        {
            switch (m_ContentMenu.GetCurSel())
            {
            case 0:
                AfxMessageBox(“You have selected First Item”);
                break;

            case 1:
                AfxMessageBox(“You have selected Second Item”);
                break;

            case 2:
                AfxMessageBox(“You have selected Third Item”);
                break;

            case 3:
                AfxMessageBox(“You have selected Fourth Item”);
                break;
            }
        }


NOTE: THIS SOURCE CODE IS PROVIDED AS IS AND I WILL NOT BE RESPONSIBLE FOR ANY DELAYS
OR DAMAGES CAUSED BY USING IT. USE AT OWN RISK.

Last updated: 10 May 1998

Recommended for you...

Video Game Careers Overview
CodeGuru Staff
Sep 18, 2022
Dealing with non-CLS Exceptions in .NET
Hannes DuPreez
Aug 5, 2022
Online Courses to Learn Video Game Development
Ronnie Payne
Jul 8, 2022
Best Online Courses to Learn C++
CodeGuru Staff
Jun 25, 2022
CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.