This document is archived and information here might be outdated. Recommended version. |
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
hook is a reference to an IApplication object or any of the Controls.
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.
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;
}
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