Cool Popup Menu

Features

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.


WM_ENTERMENULOOP:

// 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.

Downloads

Download demo project - 40 Kb
Download source - 14 Kb


Comments

  • Dynamic creation of menus

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

    Originally posted by: Priyanka

    Hi,
    I need the method to create menus dynamically.
    thankyou,
    bye
    priyanka

    Reply
  • ex(Popup)Menu

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

    Originally posted by: Mike Philips

    Grest work.
    
    

    Here's a link to a smart menu control:

    http://www.exontrol.com/sg.jsp?content=products/exmenu

    Regards,
    Mike

    Reply
  • 32x32 pixels icons?

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

    Originally posted by: MAV

    How to use this class for displaying 32x32 icons ?
    Thanks

    Reply
  • Problems under XP

    Posted by Legacy on 02/11/2002 12: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 :)

    Reply
  • Popup Menu is not Displaying

    Posted by Legacy on 01/03/2002 12: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
    Mahesh

    Reply
  • bug report(new)

    Posted by Legacy on 12/03/2001 12: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;
    GetDesktopWindow()->GetWindowRect(&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());
    else
    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(pItemRect)
    {
    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?

    Reply
  • How can I use this class with Pointers?

    Posted by Legacy on 11/06/2000 12: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

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

    Posted by Legacy on 08/11/2000 12: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.


    Reply
  • Support default menu item

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

    Originally posted by: Lior

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

    Reply
  • Bug

    Posted by Legacy on 03/20/2000 12: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?

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: November 13, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT APIs can be a great source of competitive advantage. The practice of exposing backend services as APIs has become pervasive, however their use varies widely across companies and industries. Some companies leverage APIs to create internal, operational and development efficiencies, while others use them to drive ancillary revenue channels. Many companies successfully support both public and private programs from the same API by varying levels …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds