L_AnnSetUnit

#include "l_bitmap.h"

L_LTANN_API L_INT L_AnnSetUnit(hObject, uUnit, pUnitAbbrev, uPrecision, uFlags)

HANNOBJECT hObject;

/* handle to the annotation automation object */

L_UINT uUnit;

/* unit of measure */

L_TCHAR * pUnitAbbrev;

/* address of the character string containing the unit abbreviation string */

L_UINT uPrecision;

/* number of digits */

L_UINT uFlags;

/* flags that determine which objects to process */

Sets the unit of measurement for the rulers used by those objects that use rulers.

This function is available in the Document and Medical Imaging toolkits.

Parameter

Description

hObject

Handle to the annotation automation object.

uUnit

The unit of measure of the ruler. Possible values are:

 

Value

Meaning

 

ANNUNIT_INCH

[0x0000] inches

 

ANNUNIT_FEET

[0x0001] feet

 

ANNUNIT_YARDS

[0x0002] yards

 

ANNUNIT_MICROMETERS

[0x0003] micrometers

 

ANNUNIT_MILLIMETERS

[0x0004] millimeters

 

ANNUNIT_CENTIMETERS

[0x0005] centimeters

 

ANNUNIT_METERS

[0x0006] meters

 

ANNUNIT_TWIPS

[0x0007] twips

 

ANNUNIT_POINTS

[0x0008] points

 

ANNUNIT_PIXELS

[0x0009] pixels

 

ANNUNIT_SMART_METRIC

[0x0010] Smart Metric

 

ANNUNIT_SMART_ENGLISH

[0x0011] Smart English

pUnitAbbrev

Address of the character string containing the unit abbreviation string to be displayed after the distance. You can pass NULL to get the default abbreviations for the current unit of measurement.

uPrecision

Number of digits to be displayed after the decimal place. Valid values are 0 200.

uFlags

Flags that determine which objects to process. Possible values are:

 

Value

Meaning

 

0

Process only the specified object.

 

ANNFLAG_SELECTED

[0x0001] Process only objects that have the selected property set to TRUE. For getting and setting the selected property, use the L_AnnGetSelected and L_AnnSetSelected functions.

 

ANNFLAG_NOTTHIS

[0x0004] Process only one level of objects within the specified container, not the container itself. If there are containers within the container, they are modified, but the objects within them are not.

 

ANNFLAG_RECURSE

[0x0008] Process objects within a container, and within any subcontainers, down to any level.

 

ANNFLAG_NOTCONTAINER

[0x0002] (Used with ANNFLAG_RECURSE) Process objects within containers, not the containers themselves.

 

ANNFLAG_NOINVALIDATE

[0x0010] Do not invalidate the affected rectangle in the window. Use this to avoid generating unwanted paint messages.

 

ANNFLAG_CHECKMENU

[0x0020] Process objects only if the ANNAUTOTEXT_MENU_RULER menu item has been selected.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

The following annotation objects utilize one or more rulers as part of the annotation:

ANNOBJECT_RULER

ANNOBJECT_POLYRULER

ANNOBJECT_PROTRACTOR

ANNOBJECT_CROSSPRODUCT

In addition, the Automation object (ANNOBJECT_AUTOMATION) stores default unit settings along with the other object default settings.

The default unit of measure for ruler, polyruler, and crossproduct objects is smart English. With the smart units, the unit changes with the length. For example, if the length is 11 inches (assuming the default precision of 2 is being used), "11.00 in" displays whereas if the length is 15 inches, "1 ft 3.00 in" displays. Call the L_AnnSetUnit function to set the unit of measurement and its precision for the ruler. The precision indicates how many digits to display to the right of the decimal point in the length. Call the L_AnnGetUnit function to get the unit of measurement and its precision for the ruler. The L_AnnGetDistance2 function gets the length of each ruler that makes up an object, and the total length of all rulers.

This function applies to multiple and selected objects based on the value of the uFlags parameter.

Only Automation and Ruler objects are affected. Refer to Annotation Automation Object.

Required DLLs and Libraries

LTANN

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Windows 2000 / XP/Vista.

See Also

Functions:

L_AnnSetBitmapDpiX, L_AnnGetBitmapDpiX, L_AnnGetBitmapDpiY, L_AnnSetBitmapDpiY, L_AnnGetUnit, L_AnnGetUnitLen, L_AnnGetDistance, L_AnnSetGaugeLength, L_AnnGetGaugeLength, L_AnnGetTicMarkLength, L_AnnSetTicMarkLength, L_AnnGetDistance2, ANNSMARTDISTANCE, L_AnnCalibrateRuler, L_AnnCalibrateRulerSuccessive

Topics:

Annotation Functions: Working with the Toolbar

 

Implementing Annotations

 

Automated User Interface for Annotations

 

Annotation Objects - Default Values

 

Annotation Objects - Automated Features

 

Implementing an Automated Annotation Program

 

Implementing a Non-automated Annotation Program

 

Altering Annotation Object Settings

 

Using Rulers in Annotation Objects

 

Annotation Features

 

Calibrating Annotation Ruler Objects

Example

TCHAR * GetUnitString(L_UINT uUnit)
{
   TCHAR *pszUnit = TEXT("");
   switch(uUnit)
   { 
   case ANNUNIT_INCHES:
      pszUnit = TEXT("ANNUNIT_INCHES");
      break;
   case ANNUNIT_FEET:
      pszUnit = TEXT("ANNUNIT_FEET");
      break;
   case ANNUNIT_YARDS:
      pszUnit = TEXT("ANNUNIT_YARDS");
      break;
   case ANNUNIT_MICROMETERS:
      pszUnit = TEXT("ANNUNIT_MICROMETERS");
      break;
   case ANNUNIT_MILLIMETERS:
      pszUnit = TEXT("ANNUNIT_MILLIMETERS");
      break;
   case ANNUNIT_CENTIMETERS:
      pszUnit = TEXT("ANNUNIT_CENTIMETERS");
      break;
   case ANNUNIT_METERS:
      pszUnit = TEXT("ANNUNIT_METERS");
      break;
   case ANNUNIT_TWIPS:
      pszUnit = TEXT("ANNUNIT_TWIPS");
      break;
   case ANNUNIT_POINTS:
      pszUnit = TEXT("ANNUNIT_POINTS");
      break;
   case ANNUNIT_PIXELS:
      pszUnit = TEXT("ANNUNIT_PIXELS");
      break;
   case ANNUNIT_SMART_METRIC:
      pszUnit = TEXT("ANNUNIT_SMART_METRIC");
      break;
   case ANNUNIT_SMART_ENGLISH:
      pszUnit = TEXT("ANNUNIT_SMART_ENGLISH");
      break;

   }
   return pszUnit;
}

 L_INT AnnSetUnitExample(HANNOBJECT hAnnObject)
{
   L_INT nRet;
   /* get the current measurement unit settings and display them */
   /* if unit is not inches, make it so */

   L_SIZE_T zLen;
   L_UINT   uType = 0;
   L_UINT   uUnit;
   HGLOBAL  hUnitAbbrev;
   L_TCHAR* pUnitAbbrev=NULL;
   L_UINT   uPrecision;
   L_TCHAR  buf[180];
   L_TCHAR  dis[180];
   L_TCHAR  format[180];
   L_DOUBLE dDistance;
   L_DOUBLE dDistance2;

   /* first, get unit abbreviation string len */
   nRet = L_AnnGetUnit(hAnnObject, NULL, NULL, &zLen, NULL);
   if(nRet != SUCCESS)
      return nRet;

   /* allocate enough memory for the abbreviation string */
   hUnitAbbrev = GlobalAlloc(GMEM_MOVEABLE, zLen * sizeof (L_TCHAR));
   pUnitAbbrev = (L_TCHAR*)GlobalLock(hUnitAbbrev);

   /* get the settings */
   nRet = L_AnnGetUnit(hAnnObject, &uUnit, pUnitAbbrev, &zLen, &uPrecision);
   if(nRet != SUCCESS)
      return nRet;

   /* and, get the distance */
   nRet = L_AnnGetDistance(hAnnObject, &dDistance, &dDistance2);
   if(nRet != SUCCESS)
      return nRet;

   /* display current settings & distance in current unit of measurement */
   L_AnnGetType(hAnnObject, &uType);
   _stprintf_s(buf, TEXT("Object Type: %d\nUnit: %s\nAbbrev: %s\nPrecision: %d\n"),
      uType, GetUnitString(uUnit), pUnitAbbrev, uPrecision);
   _stprintf_s(format, TEXT("Distance: %%.%df\n"),uPrecision);
   _stprintf_s(dis, format, dDistance);
   lstrcat(buf, dis);

   MessageBox(NULL, buf, TEXT("Units"), MB_OK);

   /* if unit is not inches, make it so */
   if(uUnit != ANNUNIT_INCHES)
   {
      nRet = L_AnnSetUnit(hAnnObject, ANNUNIT_INCHES, TEXT("in"), 2, 0);
      if(nRet != SUCCESS)
         return nRet;
   }

   GlobalUnlock(hUnitAbbrev);
   GlobalFree(hUnitAbbrev);
   return SUCCESS;
}