Visual Studio/Office 97 style Flat Toolbar and Dockable Menu bar | CodeGuru

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. […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 22, 1998
3 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

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.

Advertisement

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.

Advertisement

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.

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.