Virtual Developer Workshop: Containerized Development with Docker


Here are just some of the cool features of this menu class.
  • Vertical bitmap can be shown to the left side of menu items of popup menu, just like Windows start menu.
  • Child controls can be placed on the menu window.

Usage Instructions:

In order to use CBmpMenu class, user needs to use the standard functions implemented by CMenu for showing a popup menu. User creates an instance of CBmpMenu instead of CMenu and then uses LoadMenu or CreatePopupMenu followed by TrackPopupMenu.

User needs to provide handle of vertical bitmap in the constructor.

CBmpMenu(int nBitmapW=0, 
 BOOL bShowBmp4SubMenu=FALSE, 
 HBITMAP hBitmap=0, 
 BOOL StretchBmp=TRUE);
Explanation of arguments
  • nBitmapW - Width of the blank space to be shown to the left side of menu items in a popup menu.
  • bShowBmp4SubMenu - If TRUE, then blank space is shown for all submenus of a popup menu. If FALSE, then blank space is shown only for main menu.
  • hBitmap - If a valid handle is passed then this bitmap is drawn on the blank space
  • bStretchBmp - If TRUE, then bitmap is drawn using StretchBlt. If False, then the blank space is filled with pattern brush created from the bitmap.

If user wants to place any child controls on the menu window, he needs to do the processing in WM_ENTERMENULOOP handler.

The parameters for WM_ENTERMENULOOP has been changed by CbmpMenu class.


// handle of menu which is entering the modal loop
wParam = (HMENU)hMenu;  

//handle of menu window(menu window is of type CBmpMenu)
lParam = (HEND)hWindow; 

Using hWindow as parent window, any child controls can be created and placed on the menu window.


Download demo project - 40 Kb
Download source - 14 Kb


  • Dynamic creation of menus

    Posted by Legacy on 01/14/2004 08:00am

    Originally posted by: Priyanka

    I need the method to create menus dynamically.

  • ex(Popup)Menu

    Posted by Legacy on 06/12/2002 07:00am

    Originally posted by: Mike Philips

    Grest work.

    Here's a link to a smart menu control:



  • 32x32 pixels icons?

    Posted by Legacy on 03/31/2002 08:00am

    Originally posted by: MAV

    How to use this class for displaying 32x32 icons ?

  • Problems under XP

    Posted by Legacy on 02/11/2002 08:00am

    Originally posted by: Jase Jennings

    Under XP, separators are drawn in a gray text, although the background for the menu is white - so this menu looks plain old ugly on XP. If i find the solution, i'll post it here. In the meantime, i could use a little help :)

  • Popup Menu is not Displaying

    Posted by Legacy on 01/03/2002 08:00am

    Originally posted by: Mahesh

    when i tried using the pop up menu,the menu items are not displaying properly. I created a menu in the resouce editor and used the LoadMenu method..

    so can anyone help me to solve the problem.
    Thanks & Regards

  • bug report(new)

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

    Originally posted by: xiaolei zhuansun

    I found a new bug while I use the cool control:

    I popup a menu with 30 items(or 40, 50, any number that the height of the menu > deskRect/2), then I click on the middle of the screen, I found that the menu can't popup.

    here is my solution:
    1) insert new function:
    BOOL CXXXMenu::PositionSubMenu(CPoint pt, CRect menuRect, BOOL bRight)
    CRect deskRect;
    int nLeft = bRight ? pt.x : pt.x - menuRect.Width();
    if(deskRect.Height() < menuRect.Height())
    MoveWindow(nLeft, 0, menuRect.Width(), deskRect.Height());
    return TRUE;
    if(deskRect.Height()/2 < pt.y)
    MoveWindow(nLeft, 0, menuRect.Width(), menuRect.Height());
    MoveWindow(nLeft, deskRect.bottom - menuRect.Height(), menuRect.Width(), menuRect.Height());
    return TRUE;
    2) chage the function "PositionMenuWindow(...)", to
    void CXXXMenu::PositionMenuWindow(CPoint pt, CRect* pItemRect, CRect menuRect)
    CRect deskRect;
    if(PositionSubMenu(...) == FALSE)
    if(PositionSubMenu(...) == FALSE)
    if(PositionSubMenu(...) == FALSE)
    if(PositionSubMenu(CPoint(pItemRect->left, pItemRect->bottom), menuRect, FALSE, FALSE) == FALSE)
    BOOL bRight = (pItemRect->right + menuRect.Width() > deskRect.right) ? FALSE : TRUE;
    int nLeft = bRight ? pItemRect->right : pItemRect->left;
    PositionSubMenu(CPoint(nLeft, pItemRect->bottom), menuRect, bRight);

    But unfortunately, this is only partial solution, if the menu have so many items, the height of menu will larger then the deskRect.Height(). with this solution, it can only display part of the memu item.
    Is there any easy way to implement the feature like CMenu---there are two spin on the top and bottom of the menu window?

  • How can I use this class with Pointers?

    Posted by Legacy on 11/06/2000 08:00am

    Originally posted by: Stephan Schumann

    Because of the multiple inheritance there are to defined new operators (Both in CObject) is there a solution for this problem

  • I fixed a bug to be happen from clicking the area of outside.

    Posted by Legacy on 08/11/2000 07:00am

    Originally posted by: Cho, SungHee

    I faced two major bugs using CBMPMenu.

    One was a bug in case of clicking seperator,

    Other was a bug in case of clicking the area of outside.

    I want to help men undergo bug2 with my poor codes.

    At First, Declare a boolean variable in CBMPMenu.h

    Add "bool m_bEndModalLoop;" in Class CBMPMenu.

    and then,

    Add 2 member functions in CBMPMenu.h & CBMPMenu.cpp

    Add "int RunModalLoop(DWORD dwFlags=0);" in Class CBMPMenu

    and add "void EndModalLoop(int);" in Class CBMPMenu

    Real source code follows as below.

    int CGradientMenu::RunModalLoop(DWORD dwFlags) {
    MSG msg;
    m_bEndModalLoop = false;
    while (m_bEndModalLoop==false) {
    while ( PeekMessage (&msg, 0, 0, 0, PM_REMOVE) ) {
    TranslateMessage (&msg) ;
    DispatchMessage (&msg) ;
    return 0;

    void CGradientMenu::EndModalLoop(int nResult) {
    m_bEndModalLoop = true;
    ::ShowWindow(m_hWnd, SW_HIDE);

    That's all. be helpful to others.

    and Thanks to Coral.

  • Support default menu item

    Posted by Legacy on 04/22/2000 07:00am

    Originally posted by: Lior

    add after comment line "draw text" the following:
    //draw the text
    if (menuInfo.fState & MFS_DEFAULT ) {
    LOGFONT logfont;
    CFont font;
    logfont.lfWeight = FW_BOLD;
    } // end changes
    dc.DrawText(menuInfo.dwTypeData, rcItem, DT_LEFT|DT_VCENTER);

  • Bug

    Posted by Legacy on 03/20/2000 08:00am

    Originally posted by: SeungKoo

    After menu is shown, I clicked the area not in dialgo box.
    But the menu was not destroyed and debug error dialog appeared.

    How can I fix this problem?

  • Loading, Please Wait ...

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date