ArcObjects Library Reference (SystemUI)  

ICommand.OnCreate Method

Occurs when this command is created.

[Visual Basic .NET]
Public Sub OnCreate ( _
    ByVal Hook As Object _
)
[C#]
public void OnCreate (
    object Hook
);
[C++]
HRESULT OnCreate(
  IDispatch* Hook
);
[C++]

Parameters

Hook [in]   Hook is a parameter of type IDispatch*

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Description

hook is a reference to an IApplication object or any of the Controls.

Remarks

The OnCreate method gives the command a hook into the application.

When implementing ICommand to create a custom command, use the OnCreate method to get a hook to the application.

When you implement ICommand to create a custom command, you will find that your class constructor and destructor are called more than once per session. Commands are constructed once initially to get information about them, like the name, bitmap, etc and then they are destroyed. When the final, complete construction takes place, the OnCreate method gets called. OnCreate gets called only once, so you can rely on it to perform initialization of member variables. You can check for initialized member variables in the class destructor to find out if OnCreate has been called previously.

[C#]

The following code obtains a hook to the application.

 private IApplication m_app;
 public void OnCreate(object hook)
 {
     // The hook argument is a pointer to Application object.
     m_app = hook as IApplication;
 }


 

[Visual Basic .NET]

The following code obtains a hook to the application.

Private m_app As IApplication
Public Sub OnCreate(ByVal hook As Object) Implements ESRI.ArcGIS.SystemUI.ICommand.OnCreate 
     ' The hook argument is a pointer to Application object.
     m_app = CType(hook, IApplication)
End Sub

See Also

ICommand Interface | IApplication Interface