A Cool Looking Menu For Easier Navigation

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 32x32 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



Comments

  • GOOD ONE..IT WORKS IF THE CONTEXTMENU.CPP AND .H ARE ADDED TO PROJECT

    Posted by Legacy on 09/11/2003 12:00am

    Originally posted by: SIBILSALIM

    hI FRIENDS

    THE LINKING ERROR CAN BE ELIMINTAED BY ADDING THE TWO FILE CONTEXTMENU.CPP AND .H TO PROJECT..
    ITS EASY ..LOAD THE PROJECT FROM DSW...AND U GET A LINK ERROR WHEN U TRY TO RUN IT..TAKE PROJECT FORM MENU
    SELECT ADD TO PROJECT..ADD FILES..SELECT THE TWO FILES...
    NOW RUN IT..IT WORKS...HAVE A GOOD TIME..
    DO FEEL FREE TO MAIL ME AT SIBILSALIM@OPERAMAIL.COM
    BYE

    Reply
  • link problems: read this

    Posted by Legacy on 08/02/2002 12:00am

    Originally posted by: Daniel L

    If you can't link the demo application, add the ContentMenu.h and .cpp files to the project. Btw, nice menu.

    Reply
  • A Cool Looking Menu For Easier Navigation

    Posted by Legacy on 01/22/2002 12:00am

    Originally posted by: OMAR VARGAS

    I CANT FIND THE FILE RESOURCE.H
    !HELP ME

    Reply
  • RE:article contributed by Shekar Narayanan,A Cool Looking Menu For Easier Navigation

    Posted by Legacy on 10/29/2001 12:00am

    Originally posted by: KC

    HELP!!!!
    When i downloaded the source code,unziped amd run in VC++,
    there was an error: fatal error C1083: Cannot open include file: 'stdafx.h': No such file or directory
    Error executing cl.exe.
    Help me please..and whats the difference between the source code and the Demo?
    because when i unzipped the demo file,the folder contains the display icon but the source dosen't...
    HElp PLEASE!!!
    If possible email me to help me solve!

    Reply
  • link error

    Posted by Legacy on 01/04/2001 12:00am

    Originally posted by: moon jung il

    ON compile time I get errors
    
    

    Linking...
    MainFrm.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CContentMenu::~CContentMenu(void)" (??1CContentMenu@@UAE@XZ)
    MainFrm.obj : error LNK2001: unresolved external symbol "public: __thiscall CContentMenu::CContentMenu(void)" (??0CContentMenu@@QAE@XZ)
    Debug/LookMaSDI.exe : fatal error LNK1120: 2 unresolved externals
    Error executing link.exe.

    LookMaSDI.exe - 3 error(s), 0 warning(s)

    please help me

    Reply
  • Problems making it work

    Posted by Legacy on 11/01/2000 12:00am

    Originally posted by: Neo

    ON compile time I get errors
    
    

    Linking...
    MainFrm.obj : error LNK2001: unresolved external symbol "public: virtual __thiscall CContentMenu::~CContentMenu(void)" (??1CContentMenu@@UAE@XZ)
    MainFrm.obj : error LNK2001: unresolved external symbol "public: __thiscall CContentMenu::CContentMenu(void)" (??0CContentMenu@@QAE@XZ)
    Debug/LookMaSDI.exe : fatal error LNK1120: 2 unresolved externals
    Error executing link.exe.

    LookMaSDI.exe - 3 error(s), 0 warning(s)

    Reply
  • newbie question

    Posted by Legacy on 03/07/2000 12:00am

    Originally posted by: Blind

    I know this is an idiotic question but how can I call up
    the dialog and/or change view using these cool looking buttons...??? Please help!!!

    Reply
  • Make it Resizeabe Easily!

    Posted by Legacy on 07/26/1999 12:00am

    Originally posted by: Viktor

    What about resizeable menu based on Your ownerdrawn listbox? You can implement it simply with a help of a class found at

    /docking/docking_window2.shtml

    It'll be cooler!

    Reply
  • real cool menu! but...

    Posted by Legacy on 06/14/1999 12:00am

    Originally posted by: tonio

    How can I destroy and restore the ContentMenu before and after the Print Preview. Is there a way?
    TIA.

    Reply
  • Can't run in vc4

    Posted by Legacy on 12/21/1998 12:00am

    Originally posted by: dharry

    Tried to use your app in vc4 but could not get it to run.

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • IBM Worklight is a mobile application development platform that lets you extend your business to mobile devices. It is designed to provide an open, comprehensive platform to build, run and manage HTML5, hybrid and native mobile apps.

  • In support of their business continuity and disaster recovery plans, many midsized companies endeavor to avoid putting all their eggs in one basket. Understanding the critical role of last-mile connectivity and always available Internet access for their enterprises, savvy firms utilize redundant connections from multiple service providers. Despite the good intentions, their Internet connectivity risk may still be in a single basket. That is because internet service providers (ISPs) and competitive local …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds