DevStudio style Dockable Menu Bar (does not require MSIE)
Posted
by MB MB
on December 29th, 1999
This article was contributed by MB.
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 KbDownload source - 26 Kb
Comments
How to enable menu Items...
Posted by Legacy on 12/06/2003 12:00amOriginally posted by: sumit kapoor
Excellent Job! Well done!
Posted by Legacy on 03/14/2002 12:00amOriginally 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...
ReplyHow to access the Menu Items
Posted by Legacy on 03/13/2002 12:00amOriginally 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
ReplyCan't add MenuBar to Dialog?
Posted by Legacy on 06/11/2001 12:00amOriginally 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
ReplyWhen display settings change, the menu crashes
Posted by Legacy on 02/14/2001 12:00amOriginally posted by: Sjoerd van Leent
When I change the settings, the menu crashes, try it out yourself.
ReplyHow to use with CReBar
Posted by Legacy on 01/07/2001 12:00amOriginally 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?
ReplyCompatible with VC6 Rebar
Posted by Legacy on 02/28/2000 12:00amOriginally posted by: Frank Xu
did anyone improve this menu control to let it work in
ReplyRebar?
menu with icon
Posted by Legacy on 12/29/1999 12:00amOriginally 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:49ami like this oage
ReplyRequired Dockable Menu with Icons
Posted by Legacy on 12/28/1999 12:00amOriginally posted by: J. Karuna Sagar
Required Dockable Menu with Icons
ReplyCheck out the latest version!!
Posted by Legacy on 10/15/1999 12:00amOriginally 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
Loading, Please Wait ...