2.2.1 Mapping Mode Conversions

The OLE libraries express rectangles and other dimensional quantities in HIMETRIC units (MM_HIMETRIC). This mapping mode includes any rectangles provided in the SetDocDimensions callback function or OleGetBounds function or in any metafile that the server application copies to the clipboard.

If your application uses another mapping mode, you must create conversion functions to and from the mapping mode you normally use. For example, if your application normally would use the MM_TWIPS mapping mode, you would need to convert from TWIPS to HIMETRIC when transferring data to OLE, and convert back from HIMETRIC to TWIPS when receiving OLE data.

Note Neither the width nor height of an OLE object should exceed 32,767 HIMETRIC units.

2.2.1.1 Sample Code for Converting Mapping Modes

The following code example shows how to convert to and from HIMETRIC units:

#define HIMETRIC_PER_INCH 2540

/* DeviceToHiMetric

* Converts a point from device units to HiMetric units. */

void DeviceToHiMetric (HWND hwnd, LPPOINT lppt)

{

lppt->x = MulDiv (lppt->x, HIMETRIC_PER_INCH, giXppli);

lppt->y = MulDiv (lppt->y, HIMETRIC_PER_INCH, giYppli);

}

\* HiMetricToDevice

* Converts a point from HiMetric units to device units. */

void HiMetricToDevice(HWND hwnd, LPPOINT lppt)

{

lppt->x=MulDiv(giXppli, lppt->x, HIMETRIC_PER_INCH);

lppt->y=MulDiv(giYppli, lppt->y, HIMETRIC_PER_INCH);

}