AnnCalibrateRuler example for Visual C++
// The following example calibrates a ruler object (hObject)
// so that it measures 10 inches with a DPI ratio of 1:1.
// Note that hObject must be of type ANNOBJECT_RULER.
// It then sets this calibration to ALL ruler objects
// (ANNOBJECT_RULER, ANNOBJECT_POLYRULER, ANNOBJECT_CROSSPRODUCT, ANNOBJECT_PROTRACTOR)
// in the container:
int CAnnCOMView::ExampleAnnCalibrateRuler()
{
int nRet = 0;
long lObjectType = 0;
double dDpiX = 0;
double dDpiY = 0;
long hObjectRuler =0;
nRet = m_pltAnn->AnnCreate(ANN_OBJECT_RULER, TRUE, TRUE);
hObjectRuler = m_pltAnn->GetAnnObject();
m_pltAnn->AnnDefine(hObjectRuler, 0, 0, ANN_DEFINE_BEGINSET);
m_pltAnn->AnnDefine(hObjectRuler, 100, 100, ANN_DEFINE_END);
nRet = m_pltAnn->AnnGetType(hObjectRuler);
if (nRet != 0)
return nRet;
lObjectType = m_pltAnn->AnnType;
if (lObjectType!= ANN_OBJECT_RULER)
{
MessageBox(TEXT("Error: AnnCalibrateRuler only works on ANN_OBJECT_RULER objects"), TEXT("Error"), MB_OK);
return 0;
}
nRet = m_pltAnn->AnnCalibrateRuler(hObjectRuler, 10, ANN_UNIT_INCHES, 1.0);
if (nRet != 0)
return nRet;
MessageBox(TEXT("Ruler has been calibrated to have a length of 10 inches. Now all existing and newly created ruler objects will be matched to this calibration."), TEXT("Error"), MB_OK);
dDpiX = m_pltAnn->AnnGetBitmapDpiX(hObjectRuler);
dDpiY = m_pltAnn->AnnGetBitmapDpiY(hObjectRuler);
//Match calibration to existing objects in container
m_pltAnn->AnnSetBitmapDpiX(hObjectRuler, (float)dDpiX, FALSE);
m_pltAnn->AnnSetBitmapDpiY(hObjectRuler, (float)dDpiY, FALSE);
//Set automation defaults so that all newly created objects have this calibration
m_pltAnn->AnnSetBitmapDpiX(m_pltAnn->AnnAutomation, (float)dDpiX, FALSE);
m_pltAnn->AnnSetBitmapDpiY(m_pltAnn->AnnAutomation, (float)dDpiY, FALSE);
return 0;
}