Draw text
MapControlEvents.cpp
// Copyright 2011 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 

  
#include "MapControlEvents.h"

void MapControlEvents::OnAfterDraw(VARIANT display, long viewDrawPhase)
{
  // If the foreground phase has drawn, viewDrawPhase will be 32
  if (viewDrawPhase == 32)
  {
    // If a line object for splining text exists
    if (g_ipPolyline)
    {
      // Need at least 2 points in the line
      long points;
      g_ipPointCollection->get_PointCount(&points);
      if (points > 1)
      {
        ILineSymbolPtr ipLineSymbol(CLSID_SimpleLineSymbol);
        IRgbColorPtr ipColor(CLSID_RgbColor);
        ipColor->put_Red(0);
        ipColor->put_Green(0);
        ipColor->put_Blue(0);
        ipLineSymbol->put_Color(ipColor);
        ipLineSymbol->put_Width(2);
        
        // Create text symbol
        ITextSymbolPtr ipTextSymbol(CLSID_TextSymbol);
        // FONT SYMBOL NOT HERE YET
        ipTextSymbol->put_Color(ipColor);

        // Create text path and spline the text
        ITextPathPtr ipTextPath(CLSID_BezierTextPath);
        ISimpleTextSymbolPtr ipSimpleTextSymbol = ipTextSymbol;
        ipSimpleTextSymbol->putref_TextPath(ipTextPath);
        ipSimpleTextSymbol->put_Size(16);

        // Draw the line object 
        IActiveViewPtr ipActive;
        g_ipMapControl->get_ActiveView(&ipActive);
        IScreenDisplayPtr ipScreen;
        ipActive->get_ScreenDisplay(&ipScreen);
        ipScreen->StartDrawing(0, esriNoScreenCache);
        ISymbolPtr ipSymbol = ipLineSymbol;
        ipScreen->SetSymbol(ipSymbol);
        ipScreen->DrawPolyline(g_ipPolyline);
        ipScreen->FinishDrawing();
        
        // Spline the user text around the line        
        ipScreen->StartDrawing(0, esriNoScreenCache);
        ipSymbol = ipSimpleTextSymbol;
        ipScreen->SetSymbol(ipSymbol);
        IGeometryPtr ipLineGeom = g_ipPolyline;
        char* towrite = XmTextFieldGetString(g_textBox);
        ipScreen->DrawText(ipLineGeom, CComBSTR(towrite));
      }
    }
  }
}

void MapControlEvents::OnAfterScreenDraw(long hdc)
{
}

void MapControlEvents::OnBeforeScreenDraw(long hdc)
{
}

void MapControlEvents::OnDoubleClick(long button, long shift, long x,
                                     long y, double mapX, double mapY)
{
}

void MapControlEvents::OnExtentUpdated(VARIANT displayTransformation,
                                       VARIANT_BOOL sizeChanged, 
                                       VARIANT newEnvelope)
{
}

void MapControlEvents::OnFullExtentUpdated(VARIANT displayTransformation,
                                           VARIANT newEnvelope)
{
}

void MapControlEvents::OnKeyDown(long keyCode, long shift)
{
}

void MapControlEvents::OnKeyUp(long keyCode, long shift)
{
}

void MapControlEvents::OnMapReplaced(VARIANT newMap)
{
}

void MapControlEvents::OnMouseDown(long button, long shift, long x, long y, 
                                   double mapX,double mapY)
{
  // If left hand mouse button, add a point
  if (button == 1)
  {
    // Create a point and grab hold of the IPoint interface
    IPointPtr ipPoint(CLSID_Point);
    ipPoint->put_X(mapX);
    ipPoint->put_Y(mapY);
      
    // If this is the first point of a new line, create the line
    if (!g_ipPolyline)
      g_ipPolyline = IPolylinePtr(CLSID_Polyline);

    g_ipPointCollection = g_ipPolyline;
    g_ipPointCollection->AddPoint(ipPoint);

    // Refresh the forground to remove any text annotation
    g_ipMapControl->Refresh(esriViewForeground);
  }
  else
  {
    // If right or middle button, zoom to user defined rectangle
    // Create an envelope and grab hold of IEnvelope interface
    IEnvelopePtr ipEnv = NULL;
    g_ipMapControl->TrackRectangle(&ipEnv);
    // If the user dragged a rectangle, set extent of map
    if (ipEnv)
      g_ipMapControl->put_Extent(ipEnv);
  }
}

void MapControlEvents::OnMouseMove(long button, long shift, long x, long y,
                                   double mapX, double mapY)
{
}

void MapControlEvents::OnMouseUp(long button, long shift, long x, long y,
                                 double mapX, double mapY)
{
}

void MapControlEvents::OnOleDrop(esriControlsDropAction dropAction, 
                                 VARIANT dataObjectHelper, long* effect, 
                                 long button, long shift, long x, long y)
{
}

void MapControlEvents::OnSelectionChanged()
{
}

void MapControlEvents::OnViewRefreshed(VARIANT ActiveView, long viewDrawPhase,
                                       VARIANT layerOrElement, 
                                       VARIANT envelope)
{
}