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


Comments

  • Memory Leak..!!!

    Posted by Legacy on 03/20/2001 12:00am

    Originally posted by: Dillip


    There is Memory leak in the programe ...!


    Reply
  • Memory Leak..!!!

    Posted by Legacy on 03/20/2001 12:00am

    Originally posted by: Dillip


    There is Memory leak in the programe ...!


    Reply
  • Bug fix memory leaks

    Posted by Legacy on 11/16/1999 12:00am

    Originally posted by: Gilestiel

    Add a member in CEZMenu :

    CPtrArray m_arrData ;

    When you create a CEZMenuDataItem ( new CEZMenuData ) , add the new item in m_parrData :

    m_parrData.Add( lpez ) ;

    And write the correct destructor of CEZMenu ;

    CEZMenu::~CEZMenu()
    {
    while( m_parrData.GetSize() != 0 )
    {
    delete (CEZMenuItemData*) m_parrData.GetAt(0) ;
    m_parrData.RemoveAt(0) ;
    }

    DestroyMenu();
    CMenu::~CMenu();
    }

    Gilestiel.

    Reply
  • Submenu needed for real application

    Posted by Legacy on 09/16/1999 12:00am

    Originally posted by: bob

    i try to modify your code to implement submenu.
    however, no progress till now.
    Could think about it for a while.

    Reply
  • On Integration with Frame Windows

    Posted by Legacy on 07/28/1999 12:00am

    Originally posted by: Viktor

    Your menu likes cool. All the more it has the ability to contain non-standard elements like progress indicator from the sample code distributed. But the main idea is to integrate ownerdrawn menus into existing Windows GUI system with minimum changes to client classes. As I can expect Your menu can represent only popups or some other kind of menus being created explicitly, but not a menu within the main frame window of an application for instance. Unfortunately we cannot integrate such a menu into the frame without any support from it, a user should add some stuff into the frame class manually or derive it from one obtained from the developer. There are samples of both paradigms on CodeGuru.

    And next, I don't know how it can (or cannot) work with submenus. It's important for the most real applications.

    Thank You.

    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.

  • On-demand Event Event Date: October 23, 2014 Despite the current "virtualize everything" mentality, there are advantages to utilizing physical hardware for certain tasks. This is especially true for backups. In many cases, it is clearly in an organization's best interest to make use of physical, purpose-built backup appliances rather than relying on virtual backup software (VBA - Virtual Backup Appliances). Join us for this webcast to learn why physical appliances are preferable to virtual backup appliances, …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds