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:
        m_menu->DrawMenu();

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)
{
    if(message==ID_MENUITEM32782)
    {
        OnMenuitem32782();
    }
   
    return CDialog::WindowProc(message, wParam, lParam);
}

Download demo project 35K

Last updated: 26 June 1998



Comments

  • 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

    Reply
  • 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.

    Reply
  • have a memery leak!

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

    Originally posted by: Lism

    have a memery leak!

    Reply
  • 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.

      Reply
    Reply
  • Great!

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

    Originally posted by: Nathan Moinvaziri

    I like the brevity of this example the best.

    Reply
  • 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(
    IDR_MAINFRAME,
    RUNTIME_CLASS(CADoc),
    RUNTIME_CLASS(CMainFrame), // main SDI frame window);
    AddDocTemplate(pDocTemplate);

    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);
    if(m_menu)
    {
    m_menu->DrawMenu();
    }

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

    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.

    if(!m_Menu->GetSubMenu(selected))
    {
    m_ParentWnd->PostMessage(WM_COMMAND, MAKEWPARAM(m_Menu->GetMenuItemID(selected),0), 0);
    m_selfWnd->BringWindowToTop();
    ClearParent();
    m_selected = -1;
    m_goby = -1;
    }


    Reply
  • Wow...Amazing

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

    Originally posted by: BostonGuy

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

    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.

  • New IT trends to support worker mobility — such as VDI and BYOD — are quickly gaining interest and adoption. But just as with any new trend, there are concerns and pitfalls to avoid.  Download this paper to learn the most important considerations to keep in mind for your VDI project.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds