Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am developing in c# using ArcGIS Engine 10. I created a BaseCommand class ZoomCommandTest using BaseCommand template in Visual Studio 2010 using .Net Framework 3.5

Following is the ZoomCommandTest class -

/// <summary>
/// Summary description for ZoomCommandTest.
/// </summary>
[Guid("166e3282-95e4-475a-b301-505a88a0a4bb")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("Exercise7B.ZoomCommandTest")]
public sealed class ZoomCommandTest : BaseCommand
{
    #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);
        ControlsCommands.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);
        ControlsCommands.Unregister(regKey);

    }

    #endregion
    #endregion

    private IHookHelper m_hookHelper;

    public ZoomCommandTest()
    {
        //
        // TODO: Define values for the public properties
        //

        base.m_category = "Map Navigation"; //localizable text
        base.m_caption = "Zoom Command Test";  //localizable text
        base.m_message = "Zooms to the extent of Layer currently selected in the TOC";  //localizable text 
        base.m_toolTip = "Zoom Command Test";  //localizable text 
        base.m_name = "MapNavigation_ZoomCommandTest";   //unique id, non-localizable (e.g. "MyCategory_MyCommand")

        try
        {
            //
            // TODO: change bitmap name if necessary
            //
            string bitmapResourceName = GetType().Name + ".bmp";
            base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
        }
        catch (Exception ex)
        {
            System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
        }
    }

    #region Overridden Class Methods

    /// <summary>
    /// Occurs when this command is created
    /// </summary>
    /// <param name="hook">Instance of the application</param>
    public override void OnCreate(object hook)
    {
        if (hook == null)
            return;

        if (m_hookHelper == null)
            m_hookHelper = new HookHelperClass();

        m_hookHelper.Hook = hook;

        // TODO:  Add other initialization code
    }

    /// <summary>
    /// Occurs when this command is clicked
    /// </summary>
    public override void OnClick()
    {
        // TODO: Add ZoomCommandTest.OnClick implementation
        MessageBox.Show("Zoom Command");
    }

    #endregion

Now, in my MapControl application, I configured the customize dialog box like this -

private void ConfigureCustomizeDialogBox()
    {
        m_customizeDlg = new CustomizeDialogClass();
        m_customizeDlg.ShowAddFromFile = true;
        m_customizeDlg.DialogTitle = "Customize Toolbar Items";
        m_customizeDlg.SetDoubleClickDestination(toolBarCtrl);

        // Sink Events
        ICustomizeDialogEvents_Event custDlgEvents = (ICustomizeDialogEvents_Event)m_customizeDlg;
        custDlgEvents.OnStartDialog += new ICustomizeDialogEvents_OnStartDialogEventHandler(custDlgEvents_OnStartDialog);
        custDlgEvents.OnCloseDialog += new ICustomizeDialogEvents_OnCloseDialogEventHandler(custDlgEvents_OnCloseDialog);
    }

Events -

void custDlgEvents_OnCloseDialog()
    {
        toolBarCtrl.Customize = false;
        button1.Enabled = true;
    }

    void custDlgEvents_OnStartDialog()
    {
        toolBarCtrl.Customize = true;
        button1.Enabled = false;

        //ZoomToLayer tool = new ZoomToLayer();            
        //toolBarCtrl.AddItem(tool, 0, -1, true, 0, esriCommandStyles.esriCommandStyleIconAndText);
    }

On toolbar double click, I popup the customize tool bar like this-

m_customizeDlg.StartDialog(toolBarCtrl.hWnd);

But my BaseCommand class ZoomCommandTest never show up in the Map Navigation Category. Am i doing something wrong in here...??

Hope description is clear enough...

Thanks,

share|improve this question
    
Put a breakpoint at the beginning of the constructor. Does it get hit? –  Petr Krebs Jul 10 '12 at 8:33
    
Nope, i tried but the constructor never gets called up... –  Prateek Singh Jul 10 '12 at 8:34
    
Then probably the command is not registered correctly. Do you run ESRIRegAsm.exe and register the command with Engine? I suggest you call it within project's post-build event, which will make your debugging easier. –  Petr Krebs Jul 10 '12 at 8:36
    
Thanks for the pointers... Let me try registering using ESRIRegAsm.exe –  Prateek Singh Jul 10 '12 at 8:42
1  
See help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/… which explains how are components registered from version 10.0 up. –  Petr Krebs Jul 10 '12 at 8:50
show 1 more comment

1 Answer 1

First of all make sure that you ran the visual studio as administrator.

share|improve this answer
    
Yes, My Visual Studio is set to Run as Administrator always..;) –  Prateek Singh Jul 10 '12 at 8:35
    
your code looks right. but try this, right click on the tool bar, go to customize, select the Commands tab, from the left list (Categories list) select "Map Navigation". hope this will help you. –  RASHOMON Jul 10 '12 at 8:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.