English

How To: Add the MO2 legend control to a VC++ project

Summary

This document steps through the procedures and code required to add and initialize the legend control (MO2Legend.ocx) in a Visual C++ project.

Procedure

  1. Add the legend control (MO2Legend.OCX) to the project. Do not generate the COleFont class wrapper as this is already added with the MO2 control.

  2. Add a legend control to your form.

    Warning:
    If you are not using the MapHelper files, skip to Step 6.

  3. Make sure the MapHelper.h and MapHelper.cpp files are included in the project workspace.
    These are found under:
    "..ESRI\MapObjects2\Samples\MFC\Common"

  4. Edit stdafx.h and add, at the end:

    Code:
    #include "MapHelper.h"

  5. Intialize your legend

    Code:
    LPDISPATCH pDisp =::GetIDispatch(m_map);
    m_legend.setMapSource(&pDisp);
    pDisp->Release();


    Warning:
    Skip to Step 7.

  6. Intialize your legend (no MapHelper files):

    Code:
    LPDISPATCH pDisp = 0;
    LPUNKNOWN pUnknown = m_map.GetControlUnknown();
    if (pUnknown)
    pUnknown->QueryInterface(IID_IDispatch, (void**)&pDisp);
    m_legend.setMapSource(&pDisp);
    pDisp->Release();

  7. Set some properties of the legend control:

    Code:
    //set font properties:
    short idx = 0;
    m_legend.SetActive(&idx, TRUE);
    COleFont fnt(m_legend.GetFont());
    fnt.SetName(_T("Times"));
    m_legend.SetRefFont(fnt);

    m_legend.SetBackColor(moOrange);

  8. Load the Legend

    Code:
    BOOL bLoad = TRUE;
    m_legend.LoadLegend(&bLoad);