Kirk,Thanks for the reply. You are correct, as far as I can tel, IApplicationStatus.Initialized is indeed false in the startup method. How do I correct this?I am using the AcmeExt (Applying user interface customizations at startup) ESRI example along with the default code that comes with the ApplicationExtension template and I must admit I don't understand some of it but figured if it is in their example, I should not mess with it.Last night as a test, I installed the ESRI example, put message boxes in the same locations as in my code and when I started ArcMap, I got the same result, message box displaying in the disabled code eventhough I had not yet turned on the extension. I'm beginning to think that the problem might be with the example.Anyhow, below is my entire extension as it currently stands. Can you please take a look at it and see if you can tell what the problem is and how I can fix it? I will look at JIT extension and see if that might work better for me. Hopefully I can find some examples of those.Thanks a lot!Carlosnamespace RegGSS
{
[Guid("21fee823-6e9a-43af-a452-f5c8678b6e99")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("RegGSS.Extension")]
public class Extension : IExtension, IExtensionConfig, IPersistVariant
{
private IApplication m_application;
private IMxDocument m_mxDocument;
private esriExtensionState m_enableState;
private IApplicationStatus m_appStatus;
private IApplicationStatusEvents_Event m_mapStatusEvents;
private IActiveViewEvents_Event m_mapEvents;
#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 "RegGSS Extension";
}
}
public void Shutdown()
{
//TODO: Clean up resources
m_application = null;
//m_docEvents = null;
}
public void Startup(ref object initializationData)
{
m_application = initializationData as IApplication;
if (m_application == null)
return;
//TODO: Add code to initialize the extension
m_appStatus = m_application as IApplicationStatus;
}
#endregion
#region IExtensionConfig Members
public string Description
{
get
{
//TODO: Replace description (use \r\n for line break)
return "RegGSS 9.3\r\n" +
"Copyright © SFWMD 2010\r\n\r\n" +
"Environmental Resource Regulation\r\n" +
"Regulatory Support - GIS Section";
}
}
/// <summary>
/// Friendly name shown in the Extension dialog
/// </summary>
public string ProductName
{
get
{
//TODO: Replace
return "RegGSS";
}
}
public esriExtensionState State
{
get
{
return m_enableState;
}
set
{
if (m_enableState != 0 && value == m_enableState)
return;
//Check if ok to enable or disable extension
esriExtensionState requestState = value;
if (requestState == esriExtensionState.esriESEnabled)
{
//Cannot enable if it's already in unavailable state
if (m_enableState == esriExtensionState.esriESUnavailable)
{
throw new COMException("Cannot enable extension");
}
//Determine if state can be changed
esriExtensionState checkState = StateCheck(true);
m_enableState = checkState;
MessageBox.Show("Enabled");
CheckToolbarValidity();
SetupEvents();
}
else if (requestState == 0 || requestState == esriExtensionState.esriESDisabled)
{
//Determine if state can be changed
esriExtensionState checkState = StateCheck(false);
if (checkState != m_enableState)
m_enableState = checkState;
MessageBox.Show("Disabled");
UnloadCustomizations();
//Remove event
m_mapEvents.ItemAdded -= new IActiveViewEvents_ItemAddedEventHandler(OnItemAdded);
}
}
}
#endregion
/// <summary>
/// Determine extension state
/// </summary>
/// <param name="requestEnable">true if to enable; false to disable</param>
private esriExtensionState StateCheck(bool requestEnable)
{
//TODO: Replace with advanced extension state checking if needed
//Turn on or off extension directly
if (requestEnable)
return esriExtensionState.esriESEnabled;
else
return esriExtensionState.esriESDisabled;
}
#region IPersistVariant Members
public UID ID
{
get
{
UID typeID = new UIDClass();
typeID.Value = GetType().GUID.ToString("B");
return typeID;
}
}
public void Load(IVariantStream Stream)
{
//TODO: Load persisted data from document stream
Marshal.ReleaseComObject(Stream);
}
public void Save(IVariantStream Stream)
{
//TODO: Save extension related data to document stream
Marshal.ReleaseComObject(Stream);
}
#endregion
private void SetupEvents()
{
// Make sure we're dealing with ArcMap
if (m_application.Document.Parent is IMxApplication)
{
m_mxDocument = m_application.Document as IMxDocument;
m_mapEvents = m_mxDocument.FocusMap as IActiveViewEvents_Event;
m_mapEvents.ItemAdded += new IActiveViewEvents_ItemAddedEventHandler(OnItemAdded);
m_mapStatusEvents = m_application.Document.Parent as IApplicationStatusEvents_Event;
m_mapStatusEvents.Initialized += new IApplicationStatusEvents_InitializedEventHandler(OnInitialized);
}
}
// Called when the framework is fully initialized
// After this event fires, it is safe to make UI customizations
void OnInitialized()
{
CheckToolbarValidity();
MessageBox.Show("Initialized");
}
void OnItemAdded(object Item)
{
MessageBox.Show("Item Added");
IFeatureLayer pFeatureLayer;
if (Item is IFeatureLayer)
{
pFeatureLayer = Item as IFeatureLayer;
MessageBox.Show("Layer name: " + pFeatureLayer.Name);
}
}
private void CheckToolbarValidity()
{
// Wait for framework to initialize before making ui customizations
// Check framework initialization flag
if (!m_appStatus.Initialized)
return;
// Make sure the extension is enabled
if (m_enableState != esriExtensionState.esriESEnabled)
return;
// Perform the customization
LoadCustomizations();
}
private void LoadCustomizations()
{
}
private void UnloadCustomizations()
{
}
}
}