Create C# class with Visual Studio
- Open your project in Visual Studio
- Select your project and click on
- Add -> New Item...
- Select Visual C# Items -> Class
- Rename your class here with EwUsersCommandX
Click OK.
Create a new Command
For create a new command derive your EwUsersCommandX class with the EwCommandX interface.
public class EwUsersCommandX : EwCommandX
{
After that you must override 4 functions.
The Second step is to:
- give a unique name of the command.
- give a description of the command.
- give a flag instruction (see help for more information).
{
return "HelloWorld";
}
public string getDescription(out
EwErrorCode errorCode)
{
return "An Hello World Message";
}
{
return (
int) (EwCommandType.kCommandSession |
EwCommandType.kCommandNoUndoMarker);
}
EwErrorCode
All errors codes for this API.
Definition: EnumDefinition.idl:24
EwCommandType
Flag type for custom commands created by users.
Definition: EwEnumeration.idl:727
The next step is to code the goal of your command.
public EwErrorCode execute(EwCommandContextX commandContextX)
{
if (mEwApplicationX == null)
return ewErrorCode;
EwDialogTaskX ewDialogTask = mEwApplicationX.getEwDialogTask(out ewErrorCode);
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewDialogTask ==
null))
return ewErrorCode;
ewDialogTask.setContent("Hello World.");
ewDialogTask.addButton("Ok", 1);
ewDialogTask.show(out ewErrorCode);
return ewErrorCode;
}
Here is a C# example of implementation:
using System.Runtime.InteropServices;
using EwAPI;
namespace UsersCommand
{
[ComVisible(true)]
public class EwUsersCommandX : EwCommandX
{
{
return "HelloWorld";
}
public string getDescription(out
EwErrorCode errorCode)
{
return "An Hello World Message";
}
{
return (
int) (EwCommandType.kCommandSession |
EwCommandType.kCommandNoUndoMarker);
}
public EwErrorCode execute(EwCommandContextX commandContextX)
{
if (mEwApplicationX == null)
return ewErrorCode;
EwDialogTaskX ewDialogTask = mEwApplicationX.
getEwDialogTask(out ewErrorCode);
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewDialogTask ==
null))
return ewErrorCode;
ewDialogTask.addButton("Ok", 1);
ewDialogTask.show(out ewErrorCode);
return ewErrorCode;
}
public void test()
{
}
}
}
Use this interface to manage the application.
Definition: EwAPI.idl:694
IEwDialogTaskX getEwDialogTask(EwErrorCode *errorCode)
To get the task dialog wrapper.
EwErrorCode runCommand(BSTR strCommand)
Run a command.
void setContent(BSTR strContent)
Set the content.
How to use a new Command
Now it's time to add the new command to
public void addCommand()
{
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewCommandManager ==
null))
return;
EwUsersCommandX ewCommand = new EwUsersCommandX();
ewErrorCode = ewCommandManager.
addCommand(ewCommand);
}
IEwCommandManagerX getEwCommandManager(EwErrorCode *errorCode)
Get the IEwCommandManagerX command manager interface.
Use this manager to add or remove custom commands.
Definition: EwApplicationObjects.idl:856
EwErrorCode addCommand(IEwCommandX *iCommand)
Add an object derived from IEwCommandX.
And to test it.
To knowing the list of parameters of the last command
public void getParameterList()
{
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewCommandManager ==
null))
return;
int iSize = vArray.Length;
for(int i = 0; i < iSize; i++)
{
string strParam = vArray[i];
}
}
VARIANT getParameterList(EwErrorCode *errorCode)
Return the list of parameters of the last command executed.
And to remove the command
public void removeCommand()
{
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewCommandManager ==
null))
return;
}
EwErrorCode removeCommand(BSTR strCommandName)
Remove a command.
Here is a C# example of use:
using System;
using System.Runtime.InteropServices;
using EwAPI;
namespace UsersCommand
{
public class EwUserCommandManagerX
{
public void addCommand()
{
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewCommandManager ==
null))
return;
EwUsersCommandX ewCommand = new EwUsersCommandX();
ewErrorCode = ewCommandManager.
addCommand(ewCommand);
}
public void removeCommand()
{
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewCommandManager ==
null))
return;
}
public void getParameterList()
{
if ((ewErrorCode !=
EwErrorCode.EW_NO_ERROR) || (ewCommandManager ==
null))
return;
int iSize = vArray.Length;
for(int i = 0; i < iSize; i++)
{
string strParam = vArray[i];
}
}
}
}
- Note
- mEwApplicationX: application object previously created.