I'm trying to put a custom command into the Help menu on startup if it isn't already there. This is my code to do so:

private void OnCreate()
    // other stuff in OnCreate()...
    // registering my method for the right event
    m_appStatusEvents = m_application as IApplicationStatusEvents_Event;
    m_appStatusEvents.Initialized += new IApplicationStatusEvents_InitializedEventHandler(AddCmd);

private void AddCmd()
    UID myCmdId = new UIDClass();
    myCmdId.Value = myCmdIdValue;  // myCmdIdValue is my command's UID

    ICommandBars commandBars = m_application.Document.CommandBars;

    UID helpMenuId = new UIDClass();
    helpMenuId.Value = helpMenuIdValue; // helpMenuIdValue is esriArcMapUI.MxHelpMenu
    ICommandBar helpMenu = null;
    helpMenu = (ICommandBar)commandBars.Find(helpMenuId, false, false);
    // here, helpMenu.Count is 3
    if (helpMenu != null)
        ICommandItem myCmd = helpMenu.Find(myCmdId, false);
        if (myCmd == null)
            Object index = Type.Missing;
            helpMenu.Add(myCmdId, ref index);
            // here helpMenu.Count is 4, so my command was added

I think it's pretty straight forward: I'm looking for the Help menu and add my command if it isn't already there. In the debugger, I can see that an item is added to the Help menu, as its Count goes from 3 to 4.

Problem is: The command doesn't show up. I can add it manually, so I know it's loaded and correct, it just doesn't show up when I try to add it automatically.

Edit: I just tried to refresh the Help menu with (helpMenu as ICommandItem).Refresh() but that didn't help either.

Edit2: I just added this to debug:

for (int i = 0; i < helpMenu.Count; i++)

And it shows

  • &ArcGIS Desktop-Help

  • &ArcGIS Resource Center

  • &About ArcMap...

  • myCommand Caption

So it's definitely there, it just won't show!

  • What exactly is your helpMenuIdValue value? Are you using the GUID {119591D1-0255-11D2-8D20-080009EE4E51} to get a handle on the Help Menu? – Hornbydd Nov 6 '13 at 14:57
  • I tried both {119591D1-0255-11D2-8D20-080009EE4E51} and esriArcMapUI.MxHelpMenu - both times the command gets added but both times it wont show up in the menu. – germi Nov 6 '13 at 15:01
  • Try casting helpMenu to ICommandItem and call Refresh() after adding command. Also myCmd.Refresh() just to be sure. – Kirk Kuykendall Nov 6 '13 at 16:11
  • As written in my first edit: casting to ICommandItem and calling Refresh has no effect on the menu. I now tried it with myCommand, too. No effect. – germi Nov 7 '13 at 7:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.