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

  • Live Event Date: December 11, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT Market pressures to move more quickly and develop innovative applications are forcing organizations to rethink how they develop and release applications. The combination of public clouds and physical back-end infrastructures are a means to get applications out faster. However, these hybrid solutions complicate DevOps adoption, with application delivery pipelines that span across complex hybrid cloud and non-cloud environments. Check out this …

  • CentreCorp is a fully integrated and diversified property management and real estate service company, specializing in the "shopping center" segment, and is one of the premier retail service providers in North America. Company executives travel a great deal, carrying a number of traveling laptops with critical current business data, and no easy way to back up to the network outside the office. Read this case study to learn how CentreCorp implemented a suite of business continuity services that included …

Most Popular Programming Stories

More for Developers

RSS Feeds