ArcObjects Library Reference

Display Extension State on Status Bar Snippet

Display the state of the specified ArcGIS extension on the status bar when a CLSID or ProgID is supplied.

[C#]

///<summary>Display the state of the specified ArcGIS extension on the status bar when a CLSID or ProgID is supplied.</summary>
///  
///<param name="application">An IApplication interface.</param>
///<param name="extensionName">A System.String that is the CLSID or ProgID for the ArcGIS extension to be returned. Example: "{3C5059FE-9F15-401A-94ED-EED914D73E3E}" or "esriSpatialAnalystUI.SAExtension"</param>
///   
///<remarks>A listing of available ArcGIS extensions CLSID and ProgID values can be found at: http://edndoc.esri.com/arcobjects/9.1/default.asp?URL=/arcobjects/9.1/ArcGISDevHelp/TechnicalDocuments/Guids/ESRIExtIds.htm</remarks>
public void DisplayExtensionStateOnStatusBar(ESRI.ArcGIS.Framework.IApplication application, System.String extensionName)
{
  ESRI.ArcGIS.esriSystem.UID uid = new ESRI.ArcGIS.esriSystem.UIDClass();
  uid.Value = extensionName; // example: "esriPublisherUI.Publisher" 
  ESRI.ArcGIS.esriSystem.esriExtensionState extensionState = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESUnavailable;
  ESRI.ArcGIS.esriSystem.IExtensionManager extensionManager = application as ESRI.ArcGIS.esriSystem.IExtensionManager; // dynamic cast
  ESRI.ArcGIS.esriSystem.IExtension extension = extensionManager.FindExtension(uid);

  if (extension != null)
  {
    if (extension is ESRI.ArcGIS.esriSystem.IExtensionConfig)
    {
      ESRI.ArcGIS.esriSystem.IExtensionConfig extensionConfig = (ESRI.ArcGIS.esriSystem.IExtensionConfig)extension; // explicit cast
      extensionState = extensionConfig.State;
    }
    else
      extensionState = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESEnabled;
  }
  else
  {
    ESRI.ArcGIS.esriSystem.IJITExtensionManager jitExtensionManager = application as ESRI.ArcGIS.esriSystem.IJITExtensionManager; // dynamic cast
    if (jitExtensionManager.IsLoaded(uid))
    {
      ESRI.ArcGIS.esriSystem.IExtension jitExtension = application.FindExtensionByCLSID(uid);
      if (jitExtension is ESRI.ArcGIS.esriSystem.IExtensionConfig)
      {
        ESRI.ArcGIS.esriSystem.IExtensionConfig jitExtensionConfig = (ESRI.ArcGIS.esriSystem.IExtensionConfig)jitExtension; // explicit cast
        extensionState = jitExtensionConfig.State;
      }
      else
      {
        extensionState = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESEnabled;
      }
    }
    else
    {
      for (int i = 0; i < jitExtensionManager.JITExtensionCount; i++)
      {
        if (jitExtensionManager.get_JITExtensionCLSID(i).Compare(uid))
        {
          if (jitExtensionManager.IsExtensionEnabled(uid))
          {
            extensionState = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESEnabled;
          }
          else
          {
            extensionState = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESDisabled;
          }
          break;
        }
      }
    }
  }

  if (extensionState == ESRI.ArcGIS.esriSystem.esriExtensionState.esriESEnabled)
  {
    application.StatusBar.set_Message(0, "Extension is enabled");
  }
  else if (extensionState == ESRI.ArcGIS.esriSystem.esriExtensionState.esriESDisabled)
  {
    application.StatusBar.set_Message(0, "Extension is disabled");
  }
  else if (extensionState == ESRI.ArcGIS.esriSystem.esriExtensionState.esriESUnavailable)
  {
    application.StatusBar.set_Message(0, "Extension is unavailable");
  }
  else
  {
    application.StatusBar.set_Message(0, "Extension state is unknown.");
  }
}
[Visual Basic .NET]

'''<summary>Display the state of the specified ArcGIS extension on the status bar when a CLSID or ProgID is supplied.</summary>
'''  
'''<param name="application">An IApplication interface.</param>
'''<param name="extensionName">A System.String that is the CLSID or ProgID for the ArcGIS extension to be returned. Example: "{3C5059FE-9F15-401A-94ED-EED914D73E3E}" or "esriSpatialAnalystUI.SAExtension"</param>
'''   
'''<remarks>A listing of available ArcGIS extensions CLSID and ProgID values can be found at: http://edndoc.esri.com/arcobjects/9.1/default.asp?URL=/arcobjects/9.1/ArcGISDevHelp/TechnicalDocuments/Guids/ESRIExtIds.htm</remarks>
Public Sub DisplayExtensionStateOnStatusBar(ByVal application As ESRI.ArcGIS.Framework.IApplication, ByVal extensionName As System.String)

  Dim uid As ESRI.ArcGIS.esriSystem.UID = New ESRI.ArcGIS.esriSystem.UIDClass ' example: "esriPublisherUI.Publisher"
  UID.Value = extensionName

  Dim extensionState As ESRI.ArcGIS.esriSystem.esriExtensionState = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESUnavailable
  Dim extensionManager As ESRI.ArcGIS.esriSystem.IExtensionManager = CType(application, ESRI.ArcGIS.esriSystem.IExtensionManager) ' Explicit Cast
  Dim extension As ESRI.ArcGIS.esriSystem.IExtension = extensionManager.FindExtension(UID)

  If Not (extension Is Nothing) Then
    If TypeOf extension Is ESRI.ArcGIS.esriSystem.IExtensionConfig Then
      Dim extensionConfig As ESRI.ArcGIS.esriSystem.IExtensionConfig = CType(extension, ESRI.ArcGIS.esriSystem.IExtensionConfig) ' Explicit Cast
      extensionState = extensionConfig.State
    Else
      extensionState = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESEnabled
    End If
  Else
    Dim jitExtensionManager As ESRI.ArcGIS.esriSystem.IJITExtensionManager = CType(application, ESRI.ArcGIS.esriSystem.IJITExtensionManager) ' Explicit Cast
    If jitExtensionManager.IsLoaded(UID) Then
      Dim jitExtension As ESRI.ArcGIS.esriSystem.IExtension = application.FindExtensionByCLSID(UID)
      If TypeOf jitExtension Is ESRI.ArcGIS.esriSystem.IExtensionConfig Then
        Dim jitExtensionConfig As ESRI.ArcGIS.esriSystem.IExtensionConfig = CType(jitExtension, ESRI.ArcGIS.esriSystem.IExtensionConfig) ' Explicit Cast
        extensionState = jitExtensionConfig.State
      Else
        extensionState = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESEnabled
      End If
    Else
      Dim i As Integer = 0
      For i = 0 To jitExtensionManager.JITExtensionCount - 1
        If jitExtensionManager.JITExtensionCLSID(i).Compare(UID) Then
          If jitExtensionManager.IsExtensionEnabled(UID) Then
            extensionState = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESEnabled
          Else
            extensionState = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESDisabled
          End If
        End If
      Next i
    End If
  End If
  If extensionState = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESEnabled Then
    application.StatusBar.Message(0) = "Extension is enabled"
  Else
    If extensionState = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESDisabled Then
      application.StatusBar.Message(0) = "Extension is disabled"
    Else
      If extensionState = ESRI.ArcGIS.esriSystem.esriExtensionState.esriESUnavailable Then
        application.StatusBar.Message(0) = "Extension is unavailable"
      Else
        application.StatusBar.Message(0) = "Extension state is unknown"
      End If
    End If
  End If

End Sub


Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Framework
  • ESRI.ArcGIS.System