Edit

Share via


Pixel/HIMETRIC Conversion Global Functions

These functions provide support for converting to and from pixel and HIMETRIC units.

Important

The functions listed in the following table cannot be used in applications that execute in the Windows Runtime.

Name Description
AtlHiMetricToPixel Converts HIMETRIC units (each unit is 0.01 millimeter) to pixels.
AtlPixelToHiMetric Converts pixels to HIMETRIC units (each unit is 0.01 millimeter).

AtlHiMetricToPixel

Converts an object's size in HIMETRIC units (each unit is 0.01 millimeter) to a size in pixels on the screen device.

extern void AtlHiMetricToPixel(
    const SIZEL* lpSizeInHiMetric,
    LPSIZEL lpSizeInPix);

Parameters

lpSizeInHiMetric
[in] Pointer to the size of the object in HIMETRIC units.

lpSizeInPix
[out] Pointer to where the object's size in pixels is to be returned.

Example

// m_sizeExtent is a member of CComControlBase that holds the 
// control's extents in HIMETRIC units.
// Use AtlHiMetricToPixel to find the extent of the control in pixels.
AtlHiMetricToPixel(&m_sizeExtent, &sz);
ATLTRACE("Width = %d, Height = %d\n", sz.cx, sz.cy);

Requirements

Header: atlwin.h

AtlPixelToHiMetric

Converts an object's size in pixels on the screen device to a size in HIMETRIC units (each unit is 0.01 millimeter).

extern void AtlPixelToHiMetric(
    const SIZEL* lpSizeInPix,
    LPSIZEL lpSizeInHiMetric);

Parameters

lpSizeInPix
[in] Pointer to the object's size in pixels.

lpSizeInHiMetric
[out] Pointer to where the object's size in HIMETRIC units is to be returned.

Example

// Initialize our control's default size to 100 by 25 pixels
CMyControl::CMyControl()
{
    // width = 100 pixels, height = 25 pixels
    SIZE sz = { 100, 25 };
    // convert pixels to himetric
    AtlPixelToHiMetric(&sz, &m_sizeExtent);
    // store natural extent
    m_sizeNatural = m_sizeExtent;
}

Requirements

Header: atlwin.h

See also

Functions