AIMCC C# Plugin Tutorial


Lesson 5 : Adding Commands to the Actions Menu

In the last lesson we saw how to handle the "Settings" command via IAccCommandTarget. Plugins can also register commands of their own, which show up in AIMCC applications. AIM Triton will display such commands in its "Actions" menu button on the Buddy List Window. 

To do this, we add the following red lines of code.

. . .   

    public
class Class1 : IAccPlugin, IAccCommandTarget
   
{
        const int kCommandId = 0;


. . .

To add a command, we will make some calls on the IAccPluginInfo interface given to us in the Init call. Here we will add a command called "My Command"; we will assign this command an (arbitrary) id of 0.

     public void Init(AccSession session, IAccPluginInfo pluginInfo)
     {
         m_session = session;
         m_session.OnStateChange += new DAccEvents_OnStateChangeEventHandler(m_session_OnStateChange);
         IAccCommand command = pluginInfo.AddCommand(kCommandId);
         command.set_Property(AccCommandProp.AccCommandProp_Text, "My Command");

     }

Next we have to add the command to the Exec and QueryStatus methods, so we can act properly depending whether we receive AccCommandId_Preferences or the new custom command, kCommandId.

. . .

    public void
Exec(int command, object users)
    {
        if (command == kCommandId) 
            MessageBox.Show("Hi I am a command");
        else if (command == (int)AccCommandId.AccCommandId_Preferences)
        {

           Form test = new Form();
           test.Text = "My Plugin Settings";
           test.Show();
        }

    }

   
public bool QueryStatus(int command, object users)
    {
        if (command == (int)AccCommandId.AccCommandId_Preferences || 
            command == kCommandId)

            return true;
        else
            return false;
}
. . .

If you now rebuild your plugin, "My Command" should now show up in your AIMCC application.

Next Lesson | Back to Table of Contents


Questions? Visit http://developer.aim.com/
Last updated: 03/17/2007