dastucky

Custom BaseTools not appearing in Custom BaseMenu on Toolbar.

Discussion created by dastucky on Aug 29, 2012
Latest reply on Aug 30, 2012 by Neil

What do I need to do in order to view my custom tools on an ESRI menu (BaseMenu)? I have no problem adding custom tools to the ESRI toolbar but it doesn't work when I add the tools to a menu item that was added to the ESRI toolbar. I even have followed the ESRI documentation and it still doesn't work. It seems like something isn't getting registered correctly and someone suggested I use the ESRIRegAsm.exe file to do this but I don't understand why I would need to do this in the special case of a BaseMenu when it works fine with adding derived BaseTools and derived BaseCommands directly to the ESRI toolbar.

In this example I can see the ESRI tools added to the custom menu (in blue below) but the custom tools (in red below) don't appear. Can anybody help?

Thanks,

Dan

I'm using ArcGIS engine 10 with .NET 4.0 and Visual Studio 2010.

***************************Form***************************
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.SystemUI;

namespace ToobarTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
axToolbarControl1.AddItem(new ToobarTest.Menu(), 0, -1, false, 0, esriCommandStyles.esriCommandStyleIconAndText);
}
}
}





*******************Custom Menu****************************************
//Instantiates out of the box ESRI tools which works but does not instantiate the custom tool
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.CATIDs;
using ESRI.ArcGIS.ADF.BaseClasses;

namespace ToobarTest
{
/// <summary>
/// Summary description for Menu.
/// </summary>
[Guid("71986c34-2287-47e3-b9af-ef3721a50512")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("ToobarTest.Menu")]
public sealed class Menu : BaseMenu
{
#region COM Registration Function(s)
[ComRegisterFunction()]
[ComVisible(false)]
static void RegisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryRegistration(registerType);

//
// TODO: Add any COM registration code here
//
}

[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(Type registerType)
{
// Required for ArcGIS Component Category Registrar support
ArcGISCategoryUnregistration(registerType);

//
// TODO: Add any COM unregistration code here
//
}

#region ArcGIS Component Category Registrar generated code
/// <summary>
/// Required method for ArcGIS Component Category registration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryRegistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
ControlsMenus.Register(regKey);
}
/// <summary>
/// Required method for ArcGIS Component Category unregistration -
/// Do not modify the contents of this method with the code editor.
/// </summary>
private static void ArcGISCategoryUnregistration(Type registerType)
{
string regKey = string.Format("HKEY_CLASSES_ROOT\\CLSID\\{{{0}}}", registerType.GUID);
ControlsMenus.Unregister(regKey);
}

#endregion
#endregion

public Menu()
{
  // These work!!
AddItem("esriControls.ControlsMapZoomInFixedCommand"); // using ESRI PROGID reference.
BeginGroup(); //Separator
AddItem("{380FB31E-6C24-4F5C-B1DF-47F33586B885}"); //using GUID reference
AddItem(new Guid("B0675372-0271-4680-9A2C-269B3F0C01E8")); //using GUID reference
  // Trying to get Tool1 to appear on the menu like the items above.
// It doesn't work!!
// Either with calling with class type, using PROGID or the GUID of the class!!
// I can't figure it out. AddItem(new Tool1().GetType().GUID);
AddItem("{6acb6257-ddd5-4756-b228-a065fd71b0a1}");
AddItem("ToobarTest.Tool1"); }

public override string Caption{get{return "My C# Menu";}}
public override string Name{get{return "Menu";}
}
}
}


*******************Custom Tool (No implementation)******************************
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using ESRI.ArcGIS.ADF.BaseClasses;
using ESRI.ArcGIS.ADF.CATIDs;
using System.Windows.Forms;

namespace ToobarTest
{
/// <summary>
/// Summary description for Tool1.
/// </summary>
[Guid("6acb6257-ddd5-4756-b228-a065fd71b0a1")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("ToobarTest.Tool1")]
public sealed class Tool1 : BaseTool
{
public Tool1()
{
//
// TODO: Define values for the public properties
//
base.m_category = ""; //localizable text
base.m_caption = ""; //localizable text
base.m_message = ""; //localizable text
base.m_toolTip = ""; //localizable text
base.m_name = ""; //unique id, non-localizable (e.g. "MyCategory_MyTool")
try
{
//
// TODO: change resource name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
base.m_cursor = new System.Windows.Forms.Cursor(GetType(), GetType().Name + ".cur");
}
catch (Exception ex)
{
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
}
}

#region Overridden Class Methods

/// <summary>
/// Occurs when this tool is created
/// </summary>
/// <param name="hook">Instance of the application</param>
public override void OnCreate(object hook)
{
// TODO: Add Tool1.OnCreate implementation
}

/// <summary>
/// Occurs when this tool is clicked
/// </summary>
public override void OnClick()
{
// TODO: Add Tool1.OnClick implementation
}

public override void OnMouseDown(int Button, int Shift, int X, int Y)
{
// TODO: Add Tool1.OnMouseDown implementation
}

public override void OnMouseMove(int Button, int Shift, int X, int Y)
{
// TODO: Add Tool1.OnMouseMove implementation
}

public override void OnMouseUp(int Button, int Shift, int X, int Y)
{
// TODO: Add Tool1.OnMouseUp implementation
}
#endregion
}
}

Outcomes