3.Arcgis Engine(Extending Arcobjects)注册

本文主要介绍Base CommandBase MenuBase Toolbar之间的注册,注册层级应从大到小,从最外围到最里层的关系进行注册。

Base Toolbar

例子代码如下所示,是新建了一个Base Toolbar的组件,继承自BaseToolbar抽象类。

namespace COMUS
{
    /// <summary>
    /// Summary description for COMUSToolbar.
    /// </summary>
    [Guid("7176ffc4-d845-4d18-9a2a-46c614e88c80")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("COMUS.COMUSToolbar")]
    public sealed class COMUSToolbar : BaseToolbar
    {
        #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);
            MxCommandBars.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);
            MxCommandBars.Unregister(regKey);
        }

        #endregion
        #endregion

        public COMUSToolbar()
        {
            AddItem("{e7f6497a-79ca-4202-9a73-96212e114c9d}", 1);
            BeginGroup();
            AddItem("{566738fc-4636-465e-8f3c-64ae8b89e7e3}", 1);
        }

        public override string Caption
        {
            get {
                //TODO: Replace bar caption
                return "COMUS";
            }
        }
        public override string Name
        {
            get {
                //TODO: Replace bar ID
                return "COMUS";
            }
        }
    }
}

注册部分代码为

        public COMUSToolbar()
        {
            AddItem("{e7f6497a-79ca-4202-9a73-96212e114c9d}", 1);
            BeginGroup();
            AddItem("{566738fc-4636-465e-8f3c-64ae8b89e7e3}", 1);
        }

每一个AddItem("{e7f6497a-79ca-4202-9a73-96212e114c9d}", 1)就是一个Base Menu(中间的具体序列号下文将),BeginGroup()是分割线。

Base Menu

例子代码如下所示,是新建了一个Base Menu的组件,继承自BaseMenu抽象类。

    /// <summary>
    /// Summary description for ProjectOperate.
    /// </summary>
    [Guid("e7f6497a-79ca-4202-9a73-96212e114c9d")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("COMUS.ProjectOpertae.ProjectOperate")]
    public sealed class ProjectOperate : 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);
            MxCommandBars.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);
            MxCommandBars.Unregister(regKey);
        }

        #endregion
        #endregion


        public ProjectOperate()
        {
            AddItem("{1b513403-4ff4-4a39-a192-890cbb2a57f2}", 1);
            AddItem("{9989436e-da94-4c97-8bdf-9d13519eec8e}", 2);
            BeginGroup();
            AddItem("{ef2e3dee-a7e1-4ad5-b976-f4314424e5f6}", 3);
            AddItem("{b66b84f6-c6a3-4111-8103-c667a90f62a8}", 4);
        }
        

        public override string Caption
        {
            get {
                //TODO: Replace bar caption
                return "工程操作";
            }
        }
        public override string Name
        {
            get {
                //TODO: Replace bar ID
                return "工程操作";
            }
        }

        
    }

可以清楚的看到,该Base Menu的注册号码为[Guid("e7f6497a-79ca-4202-9a73-96212e114c9d")],上一节中的注册序列号就由此而来。

Base Command

例子代码如下所示,是新建了一个Base Command的组件,继承自BaseCommand抽象类。

    [Guid("ef2e3dee-a7e1-4ad5-b976-f4314424e5f6")]
    [ClassInterface(ClassInterfaceType.None)]
    [ProgId("COMUS.ProjectOpertae.ControlParamCmd")]
    public sealed class ControlParamCmd : 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);
            MxCommands.Register(regKey);
            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);
            MxCommands.Unregister(regKey);
            ControlsCommands.Unregister(regKey);
        }

        #endregion
        #endregion

        private IHookHelper m_hookHelper = null;
        public ControlParamCmd()
        {
            //
            // TODO: Define values for the public properties
            //
            base.m_category = "工程操作"; //localizable text
            base.m_caption = "控制性参数设置";  //localizable text 
            base.m_message = "为该COMUS工程设置控制性参数,需要模拟的源汇项及输出项选择!";  //localizable text
            base.m_toolTip = "控制性参数设置";  //localizable text
            base.m_name = "控制性参数设置";   //unique id, non-localizable (e.g. "MyCategory_MyCommand")
        }

        #region Overridden Class Methods
        public override bool Checked
        {
            get {
                return Variables.ControlParam_Checked;
            }
        }

        public override bool Enabled
        {
            get {
                return Variables.ControlParam_Enabled;
            }
        }



        /// <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;

            try {
                m_hookHelper = new HookHelperClass();
                m_hookHelper.Hook = hook;
                if (m_hookHelper.ActiveView == null)
                    m_hookHelper = null;
            }
            catch {
                m_hookHelper = null;
            }

            if (m_hookHelper == null)
                base.m_enabled = false;
            else
                base.m_enabled = true;
            // TODO:  Add other initialization code
        }

        /// <summary>
        /// Occurs when this command is clicked
        /// </summary>
        public override void OnClick()
        {
            ControlParam form = new ControlParam();
            form.ShowDialog();
        }

        #endregion
    }

可以清楚的看到,该Base Command的注册号码为[Guid("ef2e3dee-a7e1-4ad5-b976-f4314424e5f6")],上一节中Menu的注册序列号就由此而来,可以重写方法OnClick,在WPF开发中,可以通过每一个OnClick弹出一个Window页面,以此为基础进行WPF+AE插件式开发。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HydroCoder

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值