SHARE
Facebook X Pinterest WhatsApp

EZMenu-Self Drawing Menu

Environment: VC6 SP2,98 With this self drawing menu, replicating the Windows start menu is a snap. It can draw True color icons, a bitmap menu title and progress bars. The usage is similar to (if not simpler than MFC’s CMenu class). If there is a pop up menu named IDR_MYPOPUP, the items can be made […]

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

Environment: VC6 SP2,98

With this self drawing menu, replicating the Windows start
menu is a snap. It can draw True color icons, a bitmap menu title
and progress bars. The usage is similar to (if not simpler than MFC’s
CMenu class). If there is a pop up menu named IDR_MYPOPUP, the
items can be made owner drawn with the following statements:

CEZMenu ezmenu;
CMenu* pmenu;
pmenu->LoadMenu(IDR_MYPOPUP);
ezmenu.Attach(pmenu->GetSubMenu(0)->GetSafeHmenu());
//for all items->call ezmenu.InsertOwnerDrawnMenu.

Various functions available for inserting menu items
are,

void
InsertOwnerDrawnMenuItem
(
UINT nID/*The Id of the menu item*/
,LPEZMENUITEMDATA lpez/*Data->Explained below*/
,int nPos=0/*Insert Where?*/
);

void AppendOwnerDrawnItem(UINT nID,LPEZMENUITEMDATA lpez);


void ModifyOwnerDrawnMenuItem(int nPos,UINT nID,int nTotalCheck,LPEZMENUITEMDATA
lpez);//Doubtful->suggestions welcome

Menu Item Data->The properties of the menu item
are received by a class called CEZMenuItemData whose members are
self explainatory.

class
CEZMenuItemData
{
public:
CEZMenuItemData();
HICON hItemIconLarge;//Large Icon Handle
HICON hItemIconSmall;//Small Icon Handle
CString strItemText;//Menu string
BOOL bChecked;//Is item checked?
BOOL bSeperator;.
//Why do you need an Owner drawn menu to draw a **seperator**?
BOOL bProgress;//Progressbar needed?
int nProgress; //if bProgress what is the percentage?
};
//Useful typedef
typedef CEZMenuItemData* LPEZMENUITEMDATA;

If a bitmap is needed, then there is a hitch. The number of
items that would lay beside the bitmap should be specified as
well as the size of the bitmap.

void
SetTotalItems(int nItems);//necessary.
void SetMenuBitmap(HBITMAP hBitmap);
void SetBitmapDimension(CSize sz);
void SetExtensionColor(COLORREF clrExtend);
//if bitmap is shorter than menu height a rectangle whose width
is same as that of the bitmap
//and whose height compensates for a shor bitmap is painted in
clrExtend

It is fairly simple to modify the code to paint gradient rect
by getting two colors from the user.In case a progressbar is
needed the percentage unfilled part should be specified. I’ve done
this because more often than not, we only have the unfilled
percent rather than the filled ones.

Though the code works fine and I did not encounter any
problems with it, there is a major bug which to my surprise does’nt
show at all. I have not deleted objects and didn’t free resource
handles (I was unable to do it). I would like Codeguru regulars
to clarify this point.

I think the demo project and comments in the code would do the
rest of the explaination.

Downloads

Download demo project – 27 Kb
Download source – 4 Kb

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.