Owner Drawn Menu With Free Color '& Font

defaul1.gif.gif (4096 bytes)

Download Source Code and Example 35K

CFreeMenu:This class is a owner drawn menu, You will be able to:
1. Set the menu position
2. Set the menu background color
3. Set the menu bar's edge color
4. Set the menu text color
5. Set the menu text font
6. Set the first level menu as horizontal or vertical
7.Develop the class to implement menuitem with icon,and cool background menubar (as wood, metal ,or other picture etc.)

In order to use it,you need add the file freemenu.cpp ,freemenu.h,menuitemwnd.cpp and menuitemwnd.h to your project.If you don't change any of the code,you can get the 1-6 function.To redraw the CFreeMenu's method DrawMenu you can develop it.

In the beginning of  .H file add those code:

            #include "freemenu.h"

In the containing class add those code:

             CFreeMenu *m_Menu;

In the .CPP file of the class where you want use the menu add those code:

1. In initialization part(as CDialog class' OnInitDialog method,the CFreeMenu need a parent window) add those code:

    m_menu = new CFreeMenu(IDR_MENU1,     //The menu ID

                        CPoint(10,10),this,         //The Menu position and it's parent window
                        RGB(192,192,192),        //The Color of the menu bar's background
                        RGB(255,225,255),        //The Color of the menu bar's left and up edge
                        RGB(128,128,128),        //The Color of the menu bar's right and down edge
                        RGB(0,0,0),&font,0);     //The Color and font of the menu text, when the

                                                            // last parameter is 0 the first level of the menu if

                                                            // horizontal,1 meant vertical

2.Where you need the menu you add those code:

3.In your class derive the WindowProc method to call the function:

void CTestdiDlg::OnMenuitem32782()
    AfxMessageBox("Test menu");   

LRESULT CTestdiDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
    return CDialog::WindowProc(message, wParam, lParam);

Download demo project 35K

Last updated: 26 June 1998


  • how to add shortcut to free menu

    Posted by Sanjeev_Kumar_Magoo on 03/18/2004 01:21am

    how to add shortcut to free menu

  • VC++, can I change font for caption of the menu

    Posted by Legacy on 10/16/2003 12:00am

    Originally posted by: Bao Chau

    How I change the font of the menu caption in VC++? But not use class, only simple application.

    Please give me the sample code.

  • have a memery leak!

    Posted by Legacy on 07/15/2003 12:00am

    Originally posted by: Lism

    have a memery leak!

  • Good work, but ...

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

    Originally posted by: Zoran Basaric

    1. When I put control on dialog, and when I click on the menu, submenu is under the control. Only when mouse is over submenu item, submenu is visible.
    2. When submenu shows and when I click beside the submenu, it is still visible. It remains visible until I click on its subitem.

    Can someone help?

    Thanks in advance,
    Zoran Basaric

    • Help on Closing this menu

      Posted by danandu on 02/27/2009 06:20am

      Hi, I was using FreeMenu from the article in CG written by ShiGui Lu "Owner drawn menu with free color and font" Drawback: it doesnt close the opened menus and sub menus when clicked outside the menu (since standard menus do so). So i started altering my code as like this: void CTestdiDlg::OnLButtonDown(UINT nFlags, CPoint point) { int iMenuNo = -1; if(m_menu->m_selected != -1) { iMenuNo = m_menu->m_selected; switch(iMenuNo) { case 0: case 2: m_menu->SubMenu[m_menu->m_selected]->ClearParent(); break; case 1: m_menu->SubMenu[m_menu->m_selected]->SubMenu[3]->ClearParent(); break; } m_menu->DrawMenu(); } CDialog::OnLButtonDown(nFlags, point); } But Still i am hardcoding the menu numbers (observe that i have used 3) How to generalize my code Or how to alter authors code to suit my reqmt.

  • Great!

    Posted by Legacy on 11/18/2001 12:00am

    Originally posted by: Nathan Moinvaziri

    I like the brevity of this example the best.

  • Need some help.

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

    Originally posted by: Neha

    It is really a nice thing.But i want to implement this for my main menu.Which i am loading through the following stmt.

    pDocTemplate = new CSingleDocTemplate(
    RUNTIME_CLASS(CMainFrame), // main SDI frame window);

    After some stmts i have the following stmts:

    m_menu = new CFreeMenu(IDR_MAINFRAME,CPoint(0,0),m_pMainWnd,RGB(0,192,192),RGB(0,225,255),
    RGB(0,128,128), RGB(255,255,255),&font,1);

    Now my freemenu will be overlapped with my toolbar.
    So How do i replace the main menu by freemenu.
    Looking forward for reply.

  • use with message

    Posted by Legacy on 10/06/2000 12:00am

    Originally posted by: David

    pretty cool menu, except it can't be use with a message map. I made a small change in the CFreeMenu::WindowProc() function in side case statment case WM_LBUTTONDOWN:

    I modified the PostMessage() function to send out a WM_COMMAND message when the menu item was pressed. By doing so, I can use messge mapping in my host class that employ the CFreeMenu class, and I no longer need to override my host class' WindowProc() virtual function.

    m_ParentWnd->PostMessage(WM_COMMAND, MAKEWPARAM(m_Menu->GetMenuItemID(selected),0), 0);
    m_selected = -1;
    m_goby = -1;

  • Wow...Amazing

    Posted by Legacy on 02/28/2000 12:00am

    Originally posted by: BostonGuy

    Aami sojje Korti Pachchi na... aami more jabo....

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

Top White Papers and Webcasts

  • Companies undertaking an IT project need to find the right balance between cost and functionality. It's important to start by determining whether to build a solution from scratch, buy an out-of-the-box solution, or a combination of both. In reality, most projects will require some system tailoring to meet business requirements. Decision-makers must understand how much software development is enough and craft a detailed implementation plan to ensure the project's success. This white paper examines the different …

  • On-demand Event Event Date: February 12, 2015 The evolution of systems engineering with the SysML modeling language has resulted in improved requirements specification, better architectural definition, and better hand-off to downstream engineering. Agile methods have proven successful in the software domain, but how can these methods be applied to systems engineering? Check out this webcast and join Bruce Powel Douglass, author of Real-Time Agility, as he discusses how agile methods have had a tremendous …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date