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
Jordan shoes mentioned Gene to come by the discredit, a division of Nike
Posted by TaddyGaffic on 04/24/2013 02:15pmWhere 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
ReplyAssertion Fail Bug
Posted by Legacy on 11/03/1998 12:00amOriginally posted by: Seung-Ik Lee
Reply