In the last lesson we saw how to handle the "Settings" command via IAccCommandTarget. Plugins can also register additional 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 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.
We also 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. We will have our plugin make a beep when the Exec method is called with our new command (not very exciting, but makes for a simple example).
To do this, we add the following red lines of code.
class ATL_NO_VTABLE CMyPlugin :
public IMyPlugin,
public
IAccPlugin,
public
IDispEventImpl<1,
CMyPlugin, &__uuidof(DAccEvents),
&LIBID_AccCoreLib, /* wMajor = */ 1,
/* wMinor = */ 0>,
public
IAccCommandTarget
{
const int kMyCommandId = 0;
. . .
STDMETHOD(Init)(IAccSession * piAccSession, IAccPluginInfo*
piPluginInfo)
{
m_spiSession =
piAccSession;
CComPtr <IAccCommand> spiLoadCommand;
piPluginInfo->AddCommand(kMyCommandId,
&spiLoadCommand);
spiLoadCommand->put_Property(AccCommandProp_Text,
CComVariant("My Command"));
return
DispEventAdvise(m_spiSession);
}
. . .
STDMETHOD(Exec)(int command, VARIANT users)
{
if (command == kMyCommandId)
MessageBeep(MB_ICONASTERISK);
else if (command == AccCommandId_Preferences)
CAxDialogImpl<CMyPluginSettingsDlg>::Create(NULL);
return
S_OK;
}
STDMETHOD(QueryStatus)(int command, VARIANT users,
VARIANT_BOOL* pEnabled)
{
*pEnabled = (command ==
AccCommandId_Preferences
||
command == kMyCommandId)
?
VARIANT_TRUE : VARIANT_FALSE;
return S_OK;
}
. . .
};
If you now rebuild the 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