//Q: http://forums.arcgis.com/threads/33463-Modify-(add)-to-MAIN-Toolbar-with-Addinx-files public class TestAddToMainMenu : ESRI.ArcGIS.Desktop.AddIns.Extension { public TestAddToMainMenu() { } protected override void OnStartup() { WireEvents(); } protected override void OnShutdown() { } private void WireEvents() { ArcMap.Events.OpenDocument += new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_OpenDocumentEventHandler(Events_OpenDocument); ArcMap.Events.NewDocument += new ESRI.ArcGIS.ArcMapUI.IDocumentEvents_NewDocumentEventHandler(Events_NewDocument); IApplicationStatusEvents_Event appStatusEvents = ArcMap.Application.Document.Parent as IApplicationStatusEvents_Event; appStatusEvents.Initialized += new IApplicationStatusEvents_InitializedEventHandler(Events_Initialized); } void Events_Initialized() { // Need this to load menu when no document loaded at startup LoadCustomMainMenu(); } void Events_OpenDocument() { LoadCustomMainMenu(); } void Events_NewDocument() { LoadCustomMainMenu(); } private void LoadCustomMainMenu() { ICommandBar mainMenuBar = GetMainMenuBar(); UID uid = new UIDClass(); // make sure we got the main menu bar if (mainMenuBar == null) return; // check if our custom menu is already there string menuID = "REPLACE WITH MENU ADDIN ID"; // ID of Add-In Root Menu ICommandBar myMenu = mainMenuBar.Find(menuID, false) as ICommandBar; if (myMenu == null) { // Add Menu, if needed uid.Value = menuID; Object indexObj = Type.Missing; // adds menu at far right myMenu = mainMenuBar.Add(uid, ref indexObj) as ICommandBar; } // add further items (this can be buttons AND tools *evil grin*) uid.Value = "REPLACE WITH BUTTON ADDIN ID"; myMenu.Add(uid); uid.Value = "REPLACE WITH TOOL ADDIN ID"; myMenu.Add(uid); //[...] just add any further item, you need ((ICommandItem)mainMenuBar).Refresh(); } private ICommandBar GetMainMenuBar() { try { //Grab the root menu bar UID uid = new UIDClass(); uid.Value = "{1E739F59-E45F-11D1-9496-080009EEBECB}"; // Main menubar ICommandBars cmdBars = ArcMap.Application.Document.CommandBars; //ICommandItem commandItem = cmdBars.Find(uid, false, false); //???? return cmdBars.Find(uid, false, false) as ICommandBar; } catch { return null; } }
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.