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

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >



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:00am

    Originally 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?
    Please help me
    Thank you

    Reply
  • Problems with menues

    Posted by Legacy on 03/20/2002 12:00am

    Originally 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!

    Reply
  • Vc6.0 bugs fix. (Release version for the toolbar)

    Posted by Legacy on 07/09/2001 12:00am

    Originally posted by: taobell

    When you build release version for the toolbar.
    
    you may get four errors.
    undefined TB_SETINSERTMARKCOLOR
    undefined TB_GETINSERTMARKCOLOR
    undefined TVM_SETINSERTMARKCOLOR
    undefined TVM_GETINSERTMARKCOLOR

    Add follows to Afxcmn.inl(vc98\mfc\include)
    //======================
    #define TB_SETINSERTMARKCOLOR (WM_USER + 88)
    #define TB_GETINSERTMARKCOLOR (WM_USER + 89)
    #if (_WIN32_IE >= 0x0400)
    #define TVM_SETINSERTMARKCOLOR (TV_FIRST + 37)
    #define TreeView_SetInsertMarkColor(hwnd, clr) \
    (COLORREF)SNDMSG((hwnd), TVM_SETINSERTMARKCOLOR, 0, (LPARAM)clr)
    #define TVM_GETINSERTMARKCOLOR (TV_FIRST + 38)
    #define TreeView_GetInsertMarkColor(hwnd) \
    (COLORREF)SNDMSG((hwnd), TVM_GETINSERTMARKCOLOR, 0, 0)
    #endif // (_WIN32_IE >= 0x0400)
    //======================

    It is not a very clever method.but it works..;)

    Reply
  • Open problems

    Posted by Legacy on 03/28/2001 12:00am

    Originally posted by: Israel Rosas Hernandez

    I downloaded the Project but I can not open it. I have Visual C++ 6.0. Can you sende me a copy. I think that maybe the file is corrupted.
    
    

    Thanks

    Reply
  • Doesn't supply keyboard

    Posted by Legacy on 08/21/2000 12:00am

    Originally posted by: SnowFei

    This menu in Lib doesn't supply keyboard.
    1.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!

    Reply
  • Problem with *! menus

    Posted by Legacy on 05/10/2000 12:00am

    Originally posted by: hugh

    I have a number of 'top level' menus, ie menus that directly lauch a command, rather than a sub menu.
    It appears that these classes don't recognise this case. I cannot figure out how, or where to intercept it. Can anyone help please?

    Reply
  • rebuild in VC++6

    Posted by Legacy on 04/04/2000 12:00am

    Originally posted by: Frank

    I try to rebuild the dll in release version but i have some errors like this. 
    
    E:\Visual Studio\VC98\MFC\INCLUDE\afxcmn.inl(326) : error C2065: 'TVM_GETINSERTMARKCOLOR' : undeclared identifier

    The same problem appears when i want to rebuild the client project in release version

    Please, help me

    Frank

    Reply
  • loading icons from a resource ?

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

    Originally 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.

    Reply
  • Bugs with VC 6.0 (2)

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

    Originally 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.

    Reply
  • Adding menu sounds

    Posted by Legacy on 05/15/1999 12:00am

    Originally posted by: Andreas Roth

    Here's the sound support for the emnu system.
    
    Step 1: Add this three function to the ngenericpopup.cpp

    HKEY OpenRegKeyPath(HKEY hBegin,LPCTSTR lpszRegPath)
    {
    LPTSTR lpszName = new TCHAR [64];
    int begin = 0;
    HKEY hTemp;
    HKEY hKey;
    DWORD dw;
    hTemp = hBegin;
    for( int i = 0; i <= lstrlen(lpszRegPath); i++ )
    {
    if( lpszRegPath[i] == '\\' || i == lstrlen(lpszRegPath))
    {
    lstrcpyn(lpszName,&lpszRegPath[begin],i-begin+1);
    if( RegCreateKeyEx(hTemp,
    lpszName,
    0,
    REG_NONE,
    REG_OPTION_NON_VOLATILE,
    KEY_WRITE|KEY_READ,
    NULL,
    &hKey,
    &dw) == ERROR_SUCCESS )
    {
    RegCloseKey(hTemp);
    hTemp = hKey;
    }
    else
    {
    hKey = NULL;
    break;
    }
    begin = i + 1;
    }
    }
    delete lpszName;
    return hKey;
    }

    void CNGenericPopup::PlayPopupSound()
    {
    LPTSTR lpszSound = new TCHAR [MAX_PATH+1];
    DWORD cbSound = MAX_PATH+1;
    HKEY hKey;

    hKey = OpenRegKeyPath(HKEY_CURRENT_USER,
    _T("AppEvents\\Schemes\\Apps\\.Default\\MenuPopup\\.Current"));
    if( hKey != NULL &&
    RegQueryValueEx(hKey,NULL,NULL,NULL,(LPBYTE)lpszSound,&cbSound) == ERROR_SUCCESS)
    {
    PlaySound(lpszSound,NULL,SND_FILENAME);
    }
    delete lpszSound;
    }

    void CNGenericPopup::PlayMenuCmdSound()
    {
    LPTSTR lpszSound = new TCHAR [MAX_PATH+1];
    DWORD cbSound = MAX_PATH+1;
    HKEY hKey;

    hKey = OpenRegKeyPath(HKEY_CURRENT_USER,
    _T("AppEvents\\Schemes\\Apps\\.Default\\MenuCommand\\.Current"));
    if( hKey != NULL &&
    RegQueryValueEx(hKey,NULL,NULL,NULL,(LPBYTE)lpszSound,&cbSound) == ERROR_SUCCESS)
    {
    PlaySound(lpszSound,NULL,SND_FILENAME);
    }
    delete lpszSound;
    }

    Step 2: Add PlayPopupSound() at the end of ShowMenu(), add PalyMenuCmdSound() after PostMessage()

    Step 3: Insert the mmsystem.h header at the begining of ngenericpopup.cpp and add the winmm.lib to the library settings

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date