AIMCC Technote 13

Plugin Commands and Actions


Overview

This technote demonstrates how to implement Plugin Commands for your AIM Plugin. Specifically this technote will demonstrate what commands insert menus into specific areas of the client. This technote shows screen shots from the AIM 6.8 client.

Using the Open AIM SDK you can add menu items to the AIM 6.8 client via the IAccCommand interface.

In the following code samples, we will demonstrate how to implement this code in the following languages, C++, C#, VB.NET, and JavaScript. We also have sample plugins included showing this code in the Open AIM SDK. You can find the plugins in the "samples" folder.

The commands flags below describe specific areas of the client where your command will be added. Below this list are code samples for C++, C#, VB, and AIM Module (AMO) plugins. Note that all images come from AIM 6.8 and this technote has been written for developers looking to deploy plugins on AIM 6.8 and above.

C++ Actions Menu Example:

class ATL_NO_VTABLE CMyPlugin : 
    public IMyPlugin,
    public IAccPlugin,
    public IDispatchImpl,
    public IAccCommandTarget
{    
	  static const int kMyCommandId = 0; 
    // IAccPlugin Member, this is where we create the command
    // and add it to the menu
    STDMETHOD(Init)(IAccSession * session, IAccPluginInfo * pluginInfo)
    {
        // create an IAccCommand object and add the command with
        // the above integer of 0.
        
        CComPtr  spiLoadCommand;
        pluginInfo->AddCommand(kMyCommandId, &spiLoadCommand);
        
        // add text to display in the menu
        spiLoadCommand->put_Property(AccCommandProp_Text, CComVariant("My Actions Command"));
        
        // add the menu to the actions menu
        // if we wanted to add to a different 
        // menu then we specify a different flag from above
        spiLoadCommand->put_Property(AccCommandProp_Flags, CComVariant(AccCommandFlags_ActionsUi));
    }
    
    // this is an IAccCommandTarget function
    // your class will inherit from this interface
    // now lets get notified of when our plugin is selected
    STDMETHOD(Exec)(int command, VARIANT users)
    {
        if (command == kMyCommandId) 
        {
            // Add your code here
            // i.e. load a window
        }
        return S_OK;
    }
private:
    CComPtr m_spiSession;
};    

C# Example:

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

    public Class1()
    {
    }
		
    #region IAccPlugin Members

    // IAccPlugin Member, this is where we create the command
    // and add it to the menu
    public void Init(AccSession session, IAccPluginInfo pluginInfo)
    {
       m_session = session;
       // create an IAccCommand object and add the command with
       // the above integer of 0.
       IAccCommand command = pluginInfo.AddCommand(kCommandId);
       
       // add text to display in the menu
       command.set_Property(AccCommandProp.AccCommandProp_Text, "My Command");
       
       // add the menu to the actions menu
       // if we wanted to add to a different 
       // menu then we specify a different flag from above
       command.set_Property(AccCommandProp.AccCommandProp_Flags, AccCommandFlags.AccCommandFlags_ActionsUi);
    }

    #endregion

    #region IAccCommandTarget Members
    
    // this is an IAccCommandTarget function
    // your class will inherit from this interface
    // now lets get notified of when our plugin is selected
    public void Exec(int command, object users)
    {
      if (command == kCommandId)  
      {
          // Add your code here
          // i.e. load a window
      }
    }
}

VB.NET Example:

Public Class Class1
    Implements IAccPlugin
    Implements IAccCommandTarget

    Private s As AccSession
    Private kMyCommand As Integer = 0

    Public Sub Init(ByVal session As AccCoreLib.AccSession, ByVal pluginInfo As AccCoreLib.IAccPluginInfo) Implements AccCoreLib.IAccPlugin.Init
        s = session

        ' create an IAccCommand object and add the command with
        ' the above integer of 0.
        Dim command As IAccCommand = pluginInfo.AddCommand(kMyCommand)

        ' add text to display in the menu
        command.Property(AccCommandProp.AccCommandProp_Text) = "My Actions Command"

        ' add the menu to the actions menu
        ' if we wanted to add to a different 
        ' menu then we specify a different flag from above
        command.Property(AccCommandProp.AccCommandProp_Flags) = AccCommandFlags.AccCommandFlags_ActionsUi
    End Sub

    ' this is an IAccCommandTarget function
    ' your class will inherit from this interface
    ' now lets get notified of when our plugin is selected
    Public Sub Exec(ByVal command As Integer, ByVal names As Object) Implements AccCoreLib.IAccCommandTarget.Exec
        If command = kMyCommand Then
            ' Add your code here
            ' i.e. load a window
        End If
    End Sub
End Class          


rev. 2008/05/20