Visual Studio/Office 97 style Flat Toolbar and Dockable Menu bar
Download source files
and Sample project (287 Kb). This is a menu/toolbar/dockbar combination which is as close to the VC5/Office style as I could get.
This code consists of 9 classes:
CNGenericDockBar
The standard CDockBar overlaps the toolbars by a couple of pixels, which is undesirable if you want a '3d' look as we do. This is just a simple hack to remove the overlap on our toolbars.
CNGenericMenu
This is the draggable menu. It creates a toolbar with text items only and TBSTYLE_DROPDOWN style. It attempts to emulate the operation of a VC/Office menu as accurately as possible. When a button is clicked, the menu creates a window of type CNGenericPopup, which draws the menu. A single menu is created by the frame window class.
CNGenericPopup
This draws a standard popup menu, but passes keypresses (left/right arrow mainly) to the owner toolbar. At present it doesn't put the icons on the left as in VC5, but this should be trivial to implement. It uses a standard CMenu object, walks each menu item and draws it. A current limitation of this implementation is that it doesn't support submenus.
CNGenericToolBar
This is based on the code by Roger Onslow, with modifications to allow displaying of text on the buttons, and accelerator keys. This works as a drop in replacement for CToolBar. Functions:
BOOL CreateEx(CWnd* pParentWnd, DWORD dwExStyle = TBSTYLE_FLAT | TBSTYLE_TRANSPARENT, DWORD dwStyle = WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_SIZE_DYNAMIC, UINT nID = AFX_IDW_TOOLBAR, LPCTSTR szTitle = NULL)
Extended create function.
BOOL SetVisualState(BOOL bButtons, BOOL bText)
Calling CNGenericToolBar::SetVisualState() allows you to set how toolbars are shown (with/without bitmaps or text). It is usual to do this on your CMainFrame::OnCreate.
BOOL GetVisualState(BOOL bText) Return visibility of text or bitmaps on toolbars. BOOL GenericToolBarModifyStyle(DWORD dwRemove, DWORD dwAdd) Adds/removes extended toolbar styles NGTB_NO_SYSMENU (Override system menu on undocked toolbars) DWORD GetGenericToolBarStyle() Returns current extended toolbar style
CNMDIClient
A quick hack to handle the change of menu when a document is opened/closed. If anyone has a better way to do this I'd be glad to hear it!
CNMDIGenericMenu
Subclass of CNGenericMenu with an added function to subclass the MDIClient for MDI apps.
CNMDIMenuFrameWnd
Overrides necessary parts of CMDIFrameWnd, to allow proper hotkey operation of the menu/toolbar and to replace the CDockBar for the frame. Fairly trivial to use - just derive your CMainFrame from this & the menus work automatically.
CNMiniDockFrameWnd
Implements extended style NTGB_NOSYSMENU in toolbar styles (see CNGenericToolBar)
CNSDIMenuFrameWnd
Overrides necessary parts of CFrameWnd, to allow proper hotkey operation of the menu/toolbar and to replace the CDockBar for the frame.
Usage:
Requirements:
VC++5 with service pack 3.
commctrl.dll 4.71 or above.
Simple usage:
Create an MDI or SDI app. Add the following to the end of your stdafx.h
#define AUTO_SUBCLASS #include "NGToolbar.h"
Complex(!) usage:
Derive your main frame from CNMDIFrameWnd or CNSDIFrameWnd Use CNGenericToolBar instead of CToolBar You can set the text that appears on the toolbar buttons by putting a third 'line' in its associated text (eg. xxx\nyyyy\nzzz). To set the startup state of a toolbar call CNGenericToolBar::SetVisualState.
Rebuilding NGTLB10x.DLL:
Requirements:
VC++5 with service pack 3.
commctrl.dll 4.71 or above.
Up to date commctrl.h
Build will create NGTLB10R.DLL for release and NGTLB10D.DLL for debug. Library inclusion is automatic (see NGToolbar.h)
Note: Compilation requires an up to date commctrl.h from Microsoft. There is one at http://premium.microsoft.com/msdn/library/sdkdoc/c622_7nzn.htm.
Updated 5 May 1998.

Comments
menu _ save _ open
Posted by Legacy on 11/05/2003 12:00amOriginally posted by: Hanhlona
assume i create a project in SDI, when i run my program, how can i save the data that the user input in it and how can i open the file i saved?
ReplyPlease help me
Thank you
Problems with menues
Posted by Legacy on 03/20/2002 12:00amOriginally posted by: Frog
Is there a fix for the problems with vertikal docked menues? If the menu is vertikal docked the menue items get lost, because they were placed like horizontal docked. And there is a second problem. The menue bar has a close SysIcon in the caption bar. If you close the menue you will never get it!
ReplyVc6.0 bugs fix. (Release version for the toolbar)
Posted by Legacy on 07/09/2001 12:00amOriginally posted by: taobell
ReplyOpen problems
Posted by Legacy on 03/28/2001 12:00amOriginally posted by: Israel Rosas Hernandez
ReplyDoesn't supply keyboard
Posted by Legacy on 08/21/2000 12:00amOriginally posted by: SnowFei
This menu in Lib doesn't supply keyboard.
Reply1.when u push the ALT key down and up,the menu doesn't emboss.
2.when u push the ALT_F key down and up,u can't cancel the drop menu with ESC key,ALT key and mouse event.
3.this time u cann't select the other submenu and the NUM,CAP,SCR in statubar don't work,too.
Sorry, i am not good at English.
i hope you can know my means!
thanks!
Problem with *! menus
Posted by Legacy on 05/10/2000 12:00amOriginally posted by: hugh
I have a number of 'top level' menus, ie menus that directly lauch a command, rather than a sub menu.
ReplyIt appears that these classes don't recognise this case. I cannot figure out how, or where to intercept it. Can anyone help please?
rebuild in VC++6
Posted by Legacy on 04/04/2000 12:00amOriginally posted by: Frank
Replyloading icons from a resource ?
Posted by Legacy on 08/30/1999 12:00amOriginally posted by: rinix
Very nice work !
and I'll use the auto-subclassing feature for my future custom controls
Just one question :
How to load the icons from a resource (from the toolbar resource or a resource-only dll with icons or a bitmap) ?
Thanks.
ReplyBugs with VC 6.0 (2)
Posted by Legacy on 07/28/1999 12:00amOriginally posted by: Viktor
I've got similar problems trying to work with Your sample projects in VC 6.0. It's really good idea to make samples easier (more understandable I mean).
Thank You.
ReplyAdding menu sounds
Posted by Legacy on 05/15/1999 12:00amOriginally posted by: Andreas Roth
ReplyLoading, Please Wait ...