AIMCC C++/ATL Plugin Tutorial


Lesson 4 : Adding a Preferences Page

You may want to allow users to adjust settings for your plugin. AIMCC applications will display a "Settings" button for plugins when displaying the list of installed plugins, which plugins can use to pop up a preferences dialog box.

To receive notification of the Settings button being clicked, you must implement the IAccCommandTarget interface. Implementing IAccCommandTarget is done the same way that we implemented IAccPlugin in lesson 2. Right click on your plugin class and select Add -> Implement Interface. In the next dialog, select AccCoreLib again, and choose IAccCommandTarget as the interface to implement.

You will now have two new methods in your plugin class - Exec and QueryStatus. QueryStatus is used when AIMCC asks your plugin about the status of a command; you can return a true/false value in the last parameter to indicate whether the command should be enabled or disabled. Exec is used when AIMCC invokes a command on your plugin.

For our preference page, we will focus on the Exec implementation. When the Settings button is clicked, AIMCC will invoke the Exec method with the command AccCommandId_Preferences. We will look for that and display a dialog box when this occurs. (The implementation of the dialog box is left as an exercise to the reader.)

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
{
 . . .

    STDMETHOD(Exec)(int command, VARIANT users)
    {
        if (command == AccCommandId_Preferences)
            CAxDialogImpl<CMyPluginSettingsDlg>::Create(NULL);
        return S_OK;

    }
  
    STDMETHOD(QueryStatus)(int command, VARIANT users, VARIANT_BOOL* pEnabled)
    {
        *pEnabled = (command == AccCommandId_Preferences) ?
            VARIANT_TRUE : VARIANT_FALSE;
        return S_OK;
    }

 . . .

};

If you now rebuild your plugin, your dialog box will be displayed when the plugin's Settings button is clicked.

Next Lesson | Back to Table of Contents


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