XLL+ Class Library (6.3)

ExUIPopup Sample

Demonstrates a popup editor within the Excel Formula Wizard

Overview

This project demonstrates how to show a popup editor for an argument in the Excel Formula Wizard. It contains a single worksheet function, SimulateLife.

A class CFileNamePopupProvider is defined, which is derived from CXlWizExUIPopupProviderBase, and implements the virtual function Edit.

CFileNamePopupProvider

CFileNamePopupProvider::Edit does the 3 steps required of an editor.

  1. Creates a dialog (in this case by initializing an OPENFILENAME structure) and initializes the values in the dialog (in this case, by setting the file name to be the value of strValue passed to Edit).
  2. Shows the dialog.
  3. If the user selects a file, sets strValue and returns true. The file name is surrounded by quotes, so that it is a legal Excel string value. If the user presses Cancel, then Edit returns false.

Note that CFileNamePopupProvider contains a data member, m_strTitle, which will be displayed in the title of the file dialog. This member can be set to be different for each of the arguments for which this editor is provided.

CopyC++
virtual bool Edit(CString& strValue, HWND hwndParent)
{
    // Setup a file dialog
    TCHAR achFileName[MAX_PATH + 1];
    OPENFILENAME ofn;
    // ... omitted for brevity 
 
    // Clean up strValue 
    // ... omitted for brevity 
 
    // Show file dialog
    BOOL ok = ::GetSaveFileName(&ofn);

    // Copy results to output 
    if (ok)
    {
        strValue = CString(_T("\"")) + achFileName + _T("\"");
        return true;
    }
    else 
        return false;
}

Registering the popup provider

To register the popup editor, an instance of CXlWizExUIArgumentPopupCreator is declared at global scope. The arguments to the constructor include (i) the name of the add-in function for which the editor is being registered, (ii) the index of the argument to which it applies and (iii) an instance of the popup provider, CFileNamePopupProvider.

Note that a specialized title is provided in the constructor of CFileNamePopupProvider, which applies only to the popup editor for this specific argument (DataFile in SimulateLife). In this case the title is "Select a data file".

Note that the developer is responsible for constructing the instance of CFileNamePopupProvider, but the framework is responsible for destroying it. For this reason, if a destructor is provided for a popup provider class, it must be declared as virtual.

Classes and functions used

CXlWizExUIPopupProviderBase | CXlWizExUIPopupProviderBase::Edit | CXlWizExUIArgumentPopupCreator | CXlWizExUIArgumentPopupCreator::CXlWizExUIArgumentPopupCreator

Sample project

Each sample project is located in a sub-directory of the Samples directory of the XLL+ installation. To use the sample project, open the solution file ExUIPopup.sln or the project file ExUIPopup.vcproj.

You can enable debugging under Excel by using the Setup Debugging command in the XLL+ ToolWindow.

When delivered, the help files are excluded from the build. You can enable the help build by selecting the files ExUIPopup.help.xml and ExUIPopup.chm in the Solution Explorer, and using the right-click menu to view Properties. Select the page "Configuration Properties/General" and set the "Excluded from build" property to "No". See Generating help in the User Guide for more information.

See Also

List of Sample Projects | Popup Editors (User Guide) | ExUIPopupMFC sample | ExUIPopupClr sample