本文主要介绍Base Command
、Base Menu
、Base 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插件式开发。