Returns the reference to an IApplication object.

Namespace:  ESRI.ArcGIS.Desktop.AddIns

Assembly:  ESRI.ArcGIS.Desktop.Addins (in ESRI.ArcGIS.Desktop.Addins.dll) Version: 10.0.0.0 (10.0.0.0)

Syntax

C#
protected Object Hook { get; }
Visual Basic (Declaration)
Protected ReadOnly Property Hook As Object
Visual C++
protected:
property Object^ Hook {
	Object^ get ();
}

Field Value

The hook.

Remarks

Use this property to get a hook to the application when necessary. However, the easiest way to get a reference to the application is through the application class which is automatically generated inside the Config.Designer.cs (Config.Designer.vb in VB.Net) file by the add-in templates. These application classes expose several static members for accessing commonly used types. For example, inside of an ArcMap add-in, instead of casting a Hook parameter to IApplication, simply call ArcMap.Application, and calling ArcMap.Document gets a reference to IMxDocument.

Examples

The code below shows the implementation of a simple combo box.
CopyC#
public class Combo1 : ESRI.ArcGIS.Desktop.AddIns.ComboBox
{
  public Combo1()
  {
    //Add two items to the combo box.
    Point o1 = new Point();
    o1.PutCoords(0, 0);
    int c1 = this.Add("Item1", o1);

    Point o2 = new Point();
    o2.PutCoords(1, 1);
    int c2 = this.Add("Item2", o2);

    //Add the application's caption.
    ESRI.ArcGIS.Framework.IApplication app = this.Hook as ESRI.ArcGIS.Framework.IApplication;
    this.Add(app.Caption);

    //Add one item then remove
    int c3 = this.Add("Item3");
    this.Remove(c3);

    //Select the second item.
    this.Select(c2);
  }

  protected override void OnSelChange(int cookie)
  {
    if (cookie == -1)
      return;

    //Get the associated object.
    Point tag = this.GetItem(cookie).Tag as Point;
    if (tag != null)
    {
      System.Windows.Forms.MessageBox.Show(tag.X + ", " + tag.Y);
    }
  }

  protected override void OnEnter()
  {
    //Loop through the item collection.
    foreach (ESRI.ArcGIS.Desktop.AddIns.ComboBox.Item item in this.items)
    {
      if (this.Value == item.Caption)
        return;
    }
    this.Add(this.Value);
  }

  protected override void OnEditChange(string editString)
  {
    if (string.Compare(editString, "ABC", true) == 0)
    {
      System.Windows.Forms.MessageBox.Show("editString is " + this.Value);
    }
  }

  protected override void OnFocus(bool set)
  {
    if (set)
      System.Diagnostics.Debug.WriteLine("Get focus.");

    if (!set)
      System.Diagnostics.Debug.WriteLine("Lose focus.");
  }

  protected override void OnUpdate()
  {
    this.Enabled = ArcMap.Application != null;
  }
}
CopyVB.NET
Public Class Combo1
  Inherits ESRI.ArcGIS.Desktop.AddIns.ComboBox
  Public Sub New()
    'Add two items to the combo box. 
    Dim o1 As New Point()
    o1.PutCoords(0, 0)
    Dim c1 As Integer = Me.Add("Item1", o1)

    Dim o2 As New Point()
    o2.PutCoords(1, 1)
    Dim c2 As Integer = Me.Add("Item2", o2)

    'Add the application's caption. 
    Dim app As ESRI.ArcGIS.Framework.IApplication = TryCast(Me.Hook, ESRI.ArcGIS.Framework.IApplication)
    Me.Add(app.Caption)

    'Add one item then remove 
    Dim c3 As Integer = Me.Add("Item3")
    Me.Remove(c3)

    'Select the second item. 
    Me.[Select](c2)
  End Sub

  Protected Overloads Overrides Sub OnSelChange(ByVal cookie As Integer)
    If cookie = -1 Then
      Exit Sub
    End If

    'Get the associated object. 
    Dim tag As Point = TryCast(Me.GetItem(cookie).Tag, Point)
    If tag IsNot Nothing Then
      System.Windows.Forms.MessageBox.Show((tag.X & ", ") + tag.Y)
    End If
  End Sub

  Protected Overloads Overrides Sub OnEnter()
    'Loop through the item collection. 
    For Each item As ESRI.ArcGIS.Desktop.AddIns.ComboBox.Item In Me.items
      If Me.Value = item.Caption Then
        Exit Sub
      End If
    Next
    Me.Add(Me.Value)
  End Sub

  Protected Overloads Overrides Sub OnEditChange(ByVal editString As String)
    If String.Compare(editString, "ABC", True) = 0 Then
      System.Windows.Forms.MessageBox.Show("editString is " & Me.Value)
    End If
  End Sub

  Protected Overloads Overrides Sub OnFocus(ByVal [set] As Boolean)
    If [set] Then
      System.Diagnostics.Debug.WriteLine("Get focus.")
    End If

    If Not [set] Then
      System.Diagnostics.Debug.WriteLine("Lose focus.")
    End If
  End Sub

  Protected Overloads Overrides Sub OnUpdate()
    Me.Enabled = ArcMap.Application IsNot Nothing
  End Sub
End Class

See Also