DevStudio style Dockable Menu Bar (does not require MSIE)

This article was contributed by MB.

Environment: VC5/6 win95/98

I'm looking for Visual C++ 5.0 style menu bar, but most of products require MSIE4 or a new comctrl32.dll(don't encourage me do update) . So I've made a class called CMenuBar which don't use any common controls.

To use CMenuBar in a MFC application, you have to perform the following steps.

1. #include "MenuBar.h" in either StdAfx.h or MainFrm.h

2. Add CMenuBar m_wndMenuBar; to CMainFrame class

3. Add a following code to CMainFrame::OnCreate

    if (!m_wndMenuBar.CreateEx(this, WS_CHILD | WS_VISIBLE | CBRS_TOP
        TRACE0("Failed to create menubar\n");
        return -1;      // failed to create
4. Add a following code to CMainFrame::OnCreate after CStatusBar::Create and before CToolBar::EnableDocking and any other CMainFrame::EnableDocking.
5. Overide PreTranslateMessage in CMainFrame with a following code
    BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
        if (m_wndMenuBar.TranslateFrameMessage(pMsg))
            return TRUE;

        return CFrameWnd::PreTranslateMessage(pMsg);
Update History :
July 01, 1999
    First submitted to CodeGuru.
July 11, 1999
    Posted on CodeGuru site.
    Fatal hanged up problem fixed.
        (I guess CMenuBar::SizeMenuBar had entered endless loop).
    Support a MDI application.
    Crash in debug mode fixed by Mark Gentry.Thanks!
    Gripper graphics changed a little.
    Rewrite most of codes.
    Use the latest CSubclassWnd.
October 06, 1999 version 2.08
    Cope with MFC6.(gripper graphics is changed.)
    Cope with CReBar easily.
    Insist own dock line by CMenuBar::EnableDockingEx.
November 13, 1999 version 2.10
    CMenuDockBar fixed
December 02, 1999 version 2.12
    Support OLE menu

Known Problems :
    Can't determine a direction of popupmenu as MSIE5 can't.
        (please check out _ComputeMenuTrackPoint)
    OLE menu support is not enough, but I can't add 5000 lines for perfect support.

Special Thanks to :
    Paul DiLascia an MSJ columnist
    This article is based on his *PixieLib*.


Download demo project - 58 Kb
Download source - 26 Kb


  • How to enable menu Items...

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

    Originally posted by: sumit kapoor

    I'm using this menu bar in another frame window(not CMainFrame)..
    Then I get to know that Menus are visible but they r not not getting any Message from user...
    Anybody please tell me..How to enable menu & Run function according to menu Item seleted by user...

    I'm using
    CFrameWnd1 as CFrameWnd
    CScrollView as View to map Msg.

    I'm not getting its repond...
    Plz tell me How can I use this....
    Thanks ..Bye

  • Excellent Job! Well done!

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

    Originally posted by: Jon

    Excellent job man. I just have to say something about the rude people on here. This man took many hours to write code to help others and all some people do is complain. IF YOU DONT LIKE IT, DONT USE IT, or better yet WRITE YOUR OWN and show us how much better you are.

    Now that thats out of my system, I just wanted to let you guys know that im working on a bit of a framework, similar to CockJockey, and will be posting it soon...

  • How to access the Menu Items

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

    Originally posted by: Rahul

    I am using CMenuBar, but didnt figure out how to get hold of a menu item and modify the state of the menu item(ex: enable, disable)

    Can anyone help, greatly appreciate



  • Can't add MenuBar to Dialog?

    Posted by Legacy on 06/11/2001 12:00am

    Originally posted by: Liu guoping

    dear friend:
    I want to add a menubar to my dialog so i can modify the positon of the menubar.I build the sample project sucessly.
    But I can't execute my exe file(dialog),even under debug mode.
    .But how it can worked under doc/view mode ,and why not under dialog mode???????????????????
    and When i trace into the program,I found the code like that in function
    'BOOL CMenuBar::LoadMenuBar(UINT nIDResource)':
    if (m_pDockSite->GetMenu()) {
    PostMessage(MB_SET_MENU_NULL, (WPARAM)m_pDockSite->GetSafeHwnd());

    I found the variaty 'm_pDockSite' is never declared

  • When display settings change, the menu crashes

    Posted by Legacy on 02/14/2001 12:00am

    Originally posted by: Sjoerd van Leent

    When I change the settings, the menu crashes, try it out yourself.

  • How to use with CReBar

    Posted by Legacy on 01/07/2001 12:00am

    Originally posted by: g_ch

    when i use it with the CReBar ,and want to add background bitmap . I found that it was not transparent . how to do?

  • Compatible with VC6 Rebar

    Posted by Legacy on 02/28/2000 12:00am

    Originally posted by: Frank Xu

    did anyone improve this menu control to let it work in

  • menu with icon

    Posted by Legacy on 12/29/1999 12:00am

    Originally posted by: MB

    Please use CCoolMenuManager written by Paul DiLascia.

    • good!

      Posted by bright_shark on 02/16/2008 12:49am

      i like this oage

  • Required Dockable Menu with Icons

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

    Originally posted by: J. Karuna Sagar

    Required Dockable Menu with Icons

  • Check out the latest version!!

    Posted by Legacy on 10/15/1999 12:00am

    Originally posted by: MB

    Codeguru in trouble?
    Anyway, you can get latest version of this article.

  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Moving from an on-premises environment to Office 365 does not remove the need to plan for disruptions or reduce the business risk requirements for protecting email services. If anything, some risks increase with a move to the cloud. Read how to ease the transition every business faces if considering or already migrating to cloud email. This white paper discusses: Setting expectations when migrating to Office 365 Understanding the implications of relying solely on Exchange Online security Necessary archiving …

  • Enterprises are increasingly looking to platform as a service (PaaS) to lower their costs and speed their time to market for new applications. Developing, deploying, and managing applications in the cloud eliminates the time and expense of managing a physical infrastructure to support them. PaaS offerings must deliver additional long-term benefits, such as a lower total cost of ownership (TCO), rapid scalability, and ease of integration, all while providing robust security and availability. This report …

Most Popular Programming Stories

More for Developers

RSS Feeds

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