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
        | CBRS_GRIPPER | CBRS_SIZE_DYNAMIC | CBRS_RAISEDBORDER) ||
        !m_wndMenuBar.LoadMenuBar(IDR_MAINFRAME))
    {
        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.
    m_wndMenuBar.EnableDockingEx(CBRS_ALIGN_ANY);
    EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndMenuBar);
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*.

Downloads

Download demo project - 58 Kb
Download source - 26 Kb


Comments

  • How to enable menu Items...

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

    Originally posted by: sumit kapoor

    Hi,
    
    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.
    NO DOC IS USED HERE MY ME.

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

    Reply
  • 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...

    Reply
  • 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

    Thanks,

    Rahul

    Reply
  • 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)':
    ASSERT_VALID(m_pDockSite);
    if (m_pDockSite->GetMenu()) {
    PostMessage(MB_SET_MENU_NULL, (WPARAM)m_pDockSite->GetSafeHwnd());
    }

    I found the variaty 'm_pDockSite' is never declared

    Reply
  • 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.

    Reply
  • 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?

    Reply
  • 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
    Rebar?

    Reply
  • menu with icon

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

    Originally posted by: MB

    Please use CCoolMenuManager written by Paul DiLascia.

    http://hp.vector.co.jp/authors/VA016589/english/mbfc/top.html

    • good!

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

      i like this oage

      Reply
    Reply
  • 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

    Reply
  • 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.

    http://hp.vector.co.jp/authors/VA016589/library/dockmenubar_codeguru.html

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • This paper introduces IBM Java on the IBM PowerLinux 7R2 server and describes IBM's implementation of the Java platform, which includes IBM's Java Virtual Machine and development toolkit.

  • Agile methodologies give development and test teams the ability to build software at a faster rate than ever before. Combining DevOps with hybrid cloud architectures give teams not just the principles, but also the technology necessary to achieve their goals. By combining hybrid cloud and DevOps: IT departments maintain control, visibility, and security Dev/test teams remain agile and collaborative Organizational barriers are broken down Innovation and automation can thrive Download this white paper to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds