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

 
Download Source Code and Example 200KB


This article is based on Visual Studio/Office 97 style Flat Toolbar and Dockable Menu bar from Tony Hoyle .

Like many people, I wanted to give to my applications the fancy look from Visual Studio/Office 97. As a frequent visitor of CodeGuru, I saw and tried the miscellanous sources related to that subject.

What I liked in Tony's code is its shortness, but for myself his code have two major problems:

  • Sub-menus couldn't be shown
  • All the menu navigation has to be simulated.

Basically, what's happening in Tony's code:

In your FrameWnd you call the CNGenericMenu::SetMenu function to load the menu. Then, when the user click/Shortcut a menu, a Notify Reflect on the CNGenericMenu::OnShowMenu is triggered, this function then call the CNGenericMenu::ShowDropDown.

This last function, extract a sub-menu from the menu title, and sends it to CNGenericPopup::ShowMenu. This function in turn, is responsible for creating a window in which the menu will be drawn/emulated.

In fact, what must be done there is to change the place where the menu has to be painted, and if possible to use a standard behaviour.

For our help, the CMenu class has a TrackPopupMenu function. This function is used normally to show a contextual popup-menu when the user is using the Right click on any object. For our help, there are no differences between the normal and contextual menus. So what has only to be done there, is to call it with the hMenu given by CNGenericMenu::ShowDropDown.

After all this, the ShowMenu function becomes:


BOOL CNGenericPopup::ShowMenu(BOOL bFromKey, int x, int y, CWnd* pParent, HMENU hMenu)
{
	ASSERT(hMenu);

	HideMenu();
	m_pMenu->m_hMenu=hMenu;
	m_pParent=pParent;

	if ((FALSE == m_bIsAttached) && (TRUE == m_cSubMenu.Attach (m_pMenu->m_hMenu)))
	{
		m_cSubMenu.TrackPopupMenu (TPM_LEFTALIGN , x , y , m_pParent , NULL);
		m_pParent->SendMessage(WM_ENTERMENULOOP,FALSE);
		m_bIsAttached = TRUE;
	}

	if(bFromKey)
	{
		m_pParent->SendMessage (WM_MENUSELECT , 0 , (LPARAM)hMenu);
	}

	return TRUE;
}

Then we arrived on an other problem: when the user, goes from one menu to an other, we have to close the opened menu before creating the new one. To do it, the CMenu is no help for us. We have to use directly the different menu events.

If you use the Spy++ from the Developper Studio, you'll see that the WM_EXITMENULOOP event is sent to close the currently opened menu; so that's exactly what we are going to do. The only thing that we must take care on is to Detach the hMenu, prior to sending the WM_EXITMENULOOP event.

So the HideMenu function becomes:


BOOL CNGenericPopup::HideMenu()
{
if (m_bIsAttached == TRUE)
{
m_cSubMenu.Detach ();
m_pParent->SendMessage(WM_EXITMENULOOP,(WPARAM)FALSE,0);
m_bIsAttached = FALSE;
}
return TRUE;
}

Finally, the last problem that subsists is when we click on the header of a menu to show the menu, then click on it again to close it. To have the correct behaviour, we must change slitly the CNGenericMenu::ShowDropDown function, and in it to force the close of the submenu by calling explicitely the HideMenu function. On the same occasion, we can suppress the ON_DISMISS event which now isn't used any more.

By doing things that way, we are now able to use all the different classes that you can find on this site to enhance the display of your menus and sub-menus, and have a good lightweight framework to base your work on.

Last updated: 03 June 1998



Comments

  • the cheapest clarisonic pro with fuselage dismiss purchasing in the ebay

    Posted by iouwanzi on 06/06/2013 10:31pm

    [url=http://www.miaclarisonicaustralia.org/]clarisonic australia[/url] Il existe plusieurs variétés d’instruments conformément à la l’extérieur de votre cuir chevelu. Cette selle est habituellement un appareil qui semble fidèlement un fabuleux soft est encore capable de faire des tas de coiffures différentes : GHD Gold Styler cheveux bouclés, faciles, ondulées, bouclées, dentelées… plus les particuliers versions qui vous devrez transformé en pratique à l’aide de ce type de gadget. [url=http://www.miaclarisonicaustralia.org/clarisonic-classic]clarisonic classic[/url] Il existe plusieurs variétés d’instruments conformément à la l’extérieur de votre cuir chevelu. Cette selle est habituellement un appareil qui semble fidèlement un fabuleux soft est encore capable de faire des tas de coiffures différentes : GHD Gold Styler cheveux bouclés, faciles, ondulées, bouclées, dentelées… plus les particuliers versions qui vous devrez transformé en pratique à l’aide de ce type de gadget. [url=http://www.miaclarisonicaustralia.org/]clarisonic australia[/url] our bikini fluo avec des chandails effet de perspective au crochet, plus la féminité très sexy se tailler grosses boucles, mais pas simple. Sexy niveau populaire, tant de belles femmes a eu à envier. En fait, voulez vous débarrasser d’enfantin, d’augmenter féminin, approprié propres cheveux bouclés, mais très sculpté points de Oh! Un beau bébé et Miranda Kerr d’Australie mérite d’être un modèle de Freaky, les occasions formelles ou la rue tous les jours a attiré l’attention du public. Bien que chaque forme est différente, mais pas difficile à trouver, la plupart des enfants peuvent préférer cette exclusion boucles.

    Reply
  • Jordan shoes mentioned Gene to come by the discredit, a division of Nike

    Posted by TaddyGaffic on 04/24/2013 02:15pm

    Where did that get us? A bunch of banks writing loans that they didnt care if poeple would be able to pay for because they were conforming [url=http://markwarren.org.uk/goodbuy.cfm]nike free uk[/url] loans and Fannie and Freddie would back them. And their $150+ billion losses show that they are just as unable to predict or control the market as the rest of us. It won't work because it doesn't reward investors for taking the risks involved. In order to set a good example of following your dreams, you may wish to consider strictly limiting, or eliminating TV from your life. When people are involved in pursuing their dreams they often find that they do not have the time to watch TV. TV just gets in the way of pursuing other dreams.. Take a limousine ride with Aerosmith on one of the fastest rollercoaster you have to face. Live shows throughout the day from Beauty and the Beast [url=http://fossilsdirect.co.uk/glossarey.cfm]nike huarache[/url] will bring memories flooding back for young and old. You can get closer to the action and feel that he wanted to be in the spotlight. Other technology advancements are the midsole. It has a compression molded EVA for lasting impact protection. A Vibrakill shock-absorber in the heel provides a lot of [url=http://fossilsdirect.co.uk/glossarey.cfm]nike huarache[/url] comfort, and the Exact Pro technology combines a pebax plate and a Dynamic camflex in the forefoot for improved energy return on every step. Meindl Borneo Lady Pro - This shoe is just one of my wifes most popular hiking boots. It is appropriate for lengthy outdoor hikes and you can actually do a tiny stretch of hill hiking whilst sporting them. This product also includes memory foam

    Reply
  • Assertion Fail Bug

    Posted by Legacy on 11/03/1998 12:00am

    Originally posted by: Seung-Ik Lee

    when I compiled the source files in ...src/ directory to build the library, An assertion fail occurred.
    
    

    I worked around this by modifying just one line in the sizecbar.cpp
    file.

    in the member function "Create"

    BOOL CSizingControlBar::Create(CWnd* pParentWnd, CSize sizeDefault, UINT nID, DWORD dwStyle)
    {
    ASSERT_VALID(pParentWnd); // must have a parent
    ASSERT (!((dwStyle & CBRS_SIZE_FIXED) && (dwStyle & CBRS_SIZE_DYNAMIC)));

    // save the style

    //m_dwStyle = dwStyle; <-- original
    m_dwStyle = CBRS_ALL; <-- modified line

    ......

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

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds