Virtual Developer Workshop: Containerized Development with Docker

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 08: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 enabled...so 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 08: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 08: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 07: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 08: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 08: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 08: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 08:00am

    Originally posted by: MB

    Please use CCoolMenuManager written by Paul DiLascia.


    • good!

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

      i like this oage

  • Required Dockable Menu with Icons

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

    Originally posted by: J. Karuna Sagar

    Required Dockable Menu with Icons

  • Check out the latest version!!

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

    Originally posted by: MB

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


  • 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