#region Overriden Class Methods /// <summary> /// Occurs when this command is created /// </summary> /// <param name="hook">Instance of the application</param> public override void OnCreate(object hook) { m_application = hook as IApplication; } /// <summary> /// Occurs when this command is clicked /// </summary> public override void OnClick() { JITExtension1.SetEnabled(m_application, !JITExtension1.GetEnabled()); } public override bool Checked { get { return JITExtension1.GetEnabled(); } } #endregion
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Framework; using ESRI.ArcGIS.ADF.CATIDs; namespace Forums { [Guid("7c6aee7a-5e63-497d-a897-551ab8f6f761")] [ClassInterface(ClassInterfaceType.None)] [ProgId("Forums.JITExtension1")] public class JITExtension1 : IExtension { #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); MxExtensionJIT.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); MxExtensionJIT.Unregister(regKey); } #endregion #endregion private IApplication m_application; private bool m_Enabled; private static JITExtension1 m_instance; public bool Enabled { get { return m_Enabled; } set { m_Enabled = value; } } public static bool GetEnabled() { if(m_instance == null) return false; else return m_instance.Enabled; } public static void SetEnabled(IApplication app, bool enabled) { if (m_instance == null) { UID uid = new UIDClass(); uid.Value = "{7c6aee7a-5e63-497d-a897-551ab8f6f761}"; // this will cause instantiation (and Startup will get called) JITExtension1 ext = app.FindExtensionByCLSID(uid) as JITExtension1; ext.Enabled = enabled; } else m_instance.Enabled = enabled; } #region IExtension Members /// <summary> /// Name of extension. Do not exceed 31 characters /// </summary> public string Name { get { //TODO: Modify string to uniquely identify extension return "JITExtension1"; } } public void Shutdown() { //TODO: Clean up resources m_application = null; m_instance = null; } public void Startup(ref object initializationData) { m_instance = this; m_application = initializationData as IApplication; } #endregion } }