Inserting submenus in an existing SDI menu

In the SDI app I am working on, I needed to be able to insert a new submenu in the apps main menu based on the currently selected object. (My app uses the nested splitter code found elsewhere on CodeGuru to provide multiple views into a selected sound on an advanced MIDI soundcard). I found no information on how to do it, so after a bit of trial and error I came up with the technique shown in the following code. Please note that this code is NOT directly reusable; but it should give you an idea of what needs to be done. The submenus are all contained in a separate menubar, IDR_OBJECT_MENUS; everything else should be clear to the experienced MFC user :')
// Add a an additional popup menu to the main menu which is 
// specific to the currently selected object type. If pViewClass is NULL,
// no menu is added.
void CMainFrame::AddViewMenu(CRuntimeClass* pViewClass)
{
	const int INSERT_POSITION = 3;
	const int DEFAULT_MENU_COUNT = 6; // INCOMPLETE - change when test menu is
	removed!
		enum { PROGRAM_MENU, LAYER_MENU, KEYMAP_MENU, SAMPLE_MENU };
	
	CMenu* pMenu = GetMenu();
	ASSERT(pMenu->GetMenuItemCount() == DEFAULT_MENU_COUNT
		|| pMenu->GetMenuItemCount() == DEFAULT_MENU_COUNT + 1);
	
	// If there is already an extra menu present, remove it
	if (pMenu->GetMenuItemCount() == DEFAULT_MENU_COUNT + 1)
		pMenu->RemoveMenu(INSERT_POSITION, MF_BYPOSITION);
	
	// Now based on the specific view type, add the appropriate menu
	int iMenuToAdd = -1;
	if (pViewClass == RUNTIME_CLASS(CProgramView))
		iMenuToAdd = PROGRAM_MENU;
	else if (pViewClass == RUNTIME_CLASS(CLayerView))
		iMenuToAdd = LAYER_MENU;
	else if (pViewClass != NULL)
		ASSERT(FALSE); // INCOMPLETE - other types!
	
	if (iMenuToAdd != -1)
	{
		// get the menu to add
		CMenu objectMenu;
		objectMenu.LoadMenu(IDR_OBJECT_MENUS);
		CMenu* pPopupMenu = objectMenu.GetSubMenu(iMenuToAdd);
		ASSERT(pPopupMenu != NULL);
		
		// get its string - *^&) Windows can't figure it out for itself
		CString strMenuItem;
		objectMenu.GetMenuString(iMenuToAdd, strMenuItem, MF_BYPOSITION);
		
		// Add it
		VERIFY(pMenu->InsertMenu(INSERT_POSITION, MF_BYPOSITION | MF_POPUP, 
			(UINT)pPopupMenu->GetSafeHmenu(), strMenuItem));
		
		// remove from the other menu!
		objectMenu.RemoveMenu(iMenuToAdd, MF_BYPOSITION);
	}
	
	DrawMenuBar();
}



Comments

  • monster beats hovedtelefoner fremragende kvalitet, der oversteg

    Posted by bxflqv223 on 07/17/2013 04:01am

    Medmindre selvfølgelig, at du hellere træt, du aldrig kommer i seng, headsets i tillæg til et program, ferie kontorstol, nikkende, venter på dine vegne. Uanset om du er under metroen, workout, til hjemmet, hvor du arbejder af anden vej, for eksempel, giver næsten de fleste mennesker et headset hver eneste dag. Men når du burde “dele” enhver sang alle lytte, vil du have en persons Beats det alle. [url=http://beatsbydrdredanmark.webstarts.com/]beats by dre danmark[/url] Enhver Beats altid går, som vil komme op med en god måde undersøgelse. Det kunne gives, at disse headsets ikke kan være grundlæggende for dig, hvis du virkelig nyde populær musik, især dem, hvad personen virkelig nyde måde i processen. Det er udskiftelige pandebånd, bemærkelsesværdige gode, vil sammen med fuldstændig struktur bidrage til at gøre entusiaster sammen med fashionistas identisk tegn op, der vil disse smukke ørepropper. For virkelig at drage fordel af en persons sang alle nødt til at bruge en top-end sortiment af headset og også kombinere med bare Ogre Tilskyndelse tilfældigvis at være uden tvivl det faktum, at. Vedrørende afslapning, er de fleste en af de bedste, og giver en overordentlig fast golf greb om en persons trommehinder. Så igen, tæt forbundet med ville betyde disse ferie trygt og sikkert for din venture.. [urlhttp://beatsbydredanmark.webspawner.com/]Beats by Dre[/url] Beats hovedtelefoner har stor detalje, opløsning og billeddannelse. Når du vender kontakten til basforstærkning de er omtrent lige så god på den lave ende som enhver sammenligneligt prissat hovedtelefoner vi har hørt. Når du lytter til kvindelige vokal mere end guitar med støjreducerende på, hovedtelefonerne lyder stadig fuld og tilfredsstillende.Hvis han ikke havde travlt nok hjælpe Intel ud, musik kunstner og producer nu hjælpe miljøet ved at samarbejde med Coca-Cola og Beats med lanceringen af EKOCYCLE. Denne stand-alone initiativ er dedikeret til at fremme genbrug gennem produkter fremstillet i en del af genbrugsmateriale. Dybest set ønsker dig til at tænke genbrug er lige så cool som en iført et par beats hovedtelefoner, eller drikke en dåse cola.

    Reply
  • Du indser theMonster hovedtelefoner utvivlsomt har en betydelig beskyttelse

    Posted by wanzixiao on 06/04/2013 07:23am

    [url=http://www.beatsbydrdredanmark.moonfruit.com/]beats by dre tilbud[/url] i hvert fald set er en god musik altid være påkrævet, og hovedtelefonerne som Dre beats forbedrer sådan musik, så du har lyst til himlen. I denne artikel vil vi diskutere, hvor langt disse bemærkelsesværdige hovedtelefoner (Dre beats hovedtelefoner) er i stand til, og hvordan strålende det kan støtte dig til at få essensen af musikken. For din korte viden – Monster har formået at kombinere stil med funktionalitet i Dr. Dre udvalg af hovedtelefoner understøtter disse ikke blot at se godt, men også at gøre lydkvaliteten endnu bedre. Hvis du kigger ind i dens specifikationer så du kan indse det, at de beats fra Dre hovedtelefoner lyd er altid velafbalanceret med en varm mellemtone og dunkende bas. [url=http://www.beatsbydrdredanmark.blinkweb.com/]monster beats danmark[/url] Beats By Dr. Dre Beats Wireless har annonceret et trådløst Bluetooth-headset. Dette er udformningen af den populære Solo HD og kan let kobles med en smartphone eller tablet. Den nye model er også udstyret med ControlTalk, med en mikrofon i øret og alle nødvendige kontroller. Beats By Dr. Dre introducerer Beats trådløse Bluetooth hovedtelefoner Beats By Dr. Dre Beats introducerer den trådløse Bluetooth-hovedtelefoner lytteren fuld musikalsk frihed. [url=http://www.beatsbydrdredanmark.weebly.com/]Beats by dre danmark[/url] BIII booo din troede involverer let jazz, med essentials involverer normal, god ole ‘, sammen med digitalkameraer sange for dig at lave en ny specifikt eksklusiv lyd. BIII øjeblikket omdefinerer private musik ekspertise til at gøre dine musikernes øretelefoner. Enhver observere, hver eneste nuance, kan optaget med aldrig-hørt-før realistisk look, plus iøjnefaldende design og stil trådløse høretelefoner bestemt ved en ny trompet mundstykke har som en installation vidnesbyrd om den mestre kunsten. Disse former for sædvanligvis er ikke kun de bedste ørepuder vedrørende jazz. Uanset hvad nogen hører, vil BIII sikkert vokset til betragtes som en af dine nuværende all-time musikalske teknologi højder.

    Reply
  • Quieres obtener el mejor resultado Hairstyler, mejores maneras de aprender a usar mini styler ghd

    Posted by hanmeihm on 05/30/2013 05:49pm

    [url=http://www.planchasghdbaratasonline.com/]ghd España[/url] Trenzas Enderezadoras es una tcnica eficaz, su cabello totalmente desordenado, por supuesto, a cambio, manipulados, aunque es recomendable para hacer frente a. Planchas ghd rosa por lo general se encuentran entre la plancha de pelo ms fino que hay, Eso tiene un patrn elegante y con estilo, adems de tecnolgica excesiva know-how, que puede ser resuelta en cualquier caso, un poco ms debido a esto en comparacin con los destinados a planchas pelo ghd. [url=http://www.planchasghdbaratasonline.com/]ghd España[/url] El principal culpable de la destruccin de pelo es el uso excesivo del estilo planchas ghd. Cuando se utiliza demasiadas herramientas y productos para peinar, que han perdido su forma natural y rebote. Una cosa que a menudo le ayudar a mantener su definicin es simplemente cortar y simplificar la rutina de modelado. [url=http://www.ghd-baratas.manifo.com/]Ghd Baratas[/url] GHDs hierros han estado en GHD el mercado m¢s de unos pocos aos, as como haber visto diferentes movimientos, junto con los desarrollos electrnicos. Aunque se ha hecho beneficios, seoras continuamente actualizados los dueos de oferta de equipos para peinar el cabello para lograr la apariencia ideal. Ciertamente, no es raro que todas las mujeres que han adquirido varios nombres comerciales relacionados con alisadores, junto con la adicin de los clubes rizos ao tras ao.

    Reply
  • You pine pro some tomato basil and mozzarella. In behalf of indoor from, these slippers are as well-lighted and manueverable as sneakers.

    Posted by Soaceddew on 04/20/2013 04:25am

    Has just released respective different color Free Inneva Woven shoes, Nike recently with another direction to lure shoes with different styling to all [url=http://markwarren.org.uk/goodbuy.cfm]nike free run uk[/url] eyes. This brings important issue Unfastened Inneva Woven is a White Call of works in the series, represents shoes Italian made the assurance. Latest Free Inneva Woven clouded and bawdy are on tap in two color schemes, to hand-knit Woven vamp in extension to infiltrated Italy's [url=http://markwarren.org.uk/property-waet.cfm]air max 90 uk[/url] finest crafts, meanwhile gives athletes close to the foot of relieve, the most superior possibility a affairs is the goal of Unused 5 configuration, barefoot feel it will allure cannot be ignored. Nike Sovereign Inneva Woven SP Pale-complexioned Id Pack on Parade 16 at outlets around the [url=http://markwarren.org.uk/property-waet.cfm]air max 90[/url] brand on the shelves, and on trade in restricted bearing, interested friends should produce results clinch notice to Nike announced the news.

    Reply
  • Don't get messages when adding a submenu from a DLL to the main menu!

    Posted by Legacy on 01/04/2002 12:00am

    Originally posted by: Juergen Suetterlin

    Hy folks,
    I'm trying to modify my main menu out of a dynamically loaded (runtime) DLL.

    My application uses loadlibrary() to load my DLL and can open it. The I call an exported function inside the DLL which adds a submenu to the main menu (procedure found also at codeguru). But when I select the added submenu all sub entries are grayed and the debuggers says this: "Warning: no message line prompt for ID 0x8015." but in the resource the item was alligned to an ID and the ID was alligned to a funciton.

    Can anyone help me?

    J�rgen

    Reply
  • Works fine now thnaks to Julien Roger's fix !!!

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

    Originally posted by: Alf

    In fact it works without it on Win 95 / 98 / NT systems,
    but crashes on Win 2000 / XP systems. With the "fix" it
    works now fine !

    Reply
  • Disable a sub menu at runtime

    Posted by Legacy on 01/10/2001 12:00am

    Originally posted by: Usha

    I want to disable a sub menu at Runtime. Can u help me with that

    Thanks
    usha

    Reply
  • problem with Win95

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

    Originally posted by: latha

    This code works fine with NT but gives an assertion failure when i try to access the sub menu in Win95. Please let me know a solution for the same.

    Reply
  • ON_UPDATE_COMMAND_UI does not work on the inserted menu

    Posted by Legacy on 03/24/1999 12:00am

    Originally posted by: David Geldreich

    If you try to associate an ON_UPDATE_COMMAND_UI on one of the command included in the inserted menu command routing will work but in ON_UPDATE_COMMAND_UI, pCmdUI->Enable(FALSE) will not work.

    It is because things like pCmdUI->m_pMenu->EnableMenuItem(pCmdUI->m_nID, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND); will return -1.

    One solution is to keep a pointer to the inserted menu and do ourself, change pCmdUI->m_pMenu before calling CCmdUI functions.

    Reply
  • This doesn't work

    Posted by Legacy on 12/25/1998 12:00am

    Originally posted by: Vasu Y

    This piece of code doesn't work for me.
    It is adding the new Pop-up menu to the Main menu, but if you click on the newly added pop-up menu, it is giving a Debug-Assertion Failure.

    Can somebody help me out.
    The following is the piece of code.

    CMenu* pMainMenu = pMainFrame->GetMenu();
    short iMenuToAdd;
    iMenuToAdd = 0;
    CMenu objectMenu;
    objectMenu.LoadMenu(IDR_MENU2);
    CMenu* pPopupMenu = objectMenu.GetSubMenu(iMenuToAdd);
    ASSERT(pPopupMenu != NULL);
    short count = 0;
    count = pPopupMenu->GetMenuItemCount();
    // get its string - *^&) Windows can't figure it out for itself
    CString strMenuItem;
    objectMenu.GetMenuString(iMenuToAdd, strMenuItem, MF_BYPOSITION);

    VERIFY(pMainMenu->AppendMenu( MF_POPUP,
    (UINT)pPopupMenu->Detach(), strMenuItem));

    Reply
  • Loading, Please Wait ...

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

Top White Papers and Webcasts

  • Live Event Date: August 20, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT When you look at natural user interfaces as a developer, it isn't just fun and games. There are some very serious, real-world usage models of how things can help make the world a better place – things like Intel® RealSense™ technology. Check out this upcoming eSeminar and join the panel of experts, both from inside and outside of Intel, as they discuss how natural user interfaces will likely be getting adopted in a wide variety …

  • In this on-demand webcast, Oracle ACE and Toad Product Architect Bert Scalzo discusses 10 powerful and hidden features in Toad® that help increase your productivity and DB performance. Watch this webcast today.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds