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 owner drawn with the following statements:

CEZMenu ezmenu;
CMenu* pmenu;
//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
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

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.


Download demo project - 27 Kb
Download source - 4 Kb