Owner Drawn Menu With Free Color '& Font | CodeGuru

Owner Drawn Menu With Free Color ‘& Font

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 […]

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

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);
}

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. © 2026 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.