windows-nt/Source/XPSP1/NT/multimedia/media/sndrec32/o2base/himetric.cxx

91 lines
2.2 KiB
C++
Raw Normal View History

2020-09-26 03:20:57 -05:00
//+---------------------------------------------------------------------
//
// File: himetric.cxx
//
// Contents: Routines to convert Pixels to Himetric and vice versa
//
//----------------------------------------------------------------------
#include "headers.hxx"
#pragma hdrstop
#define HIMETRIC_PER_INCH 2540L
//+---------------------------------------------------------------
//
// Function: HimetricFromHPix
//
// Synopsis: Converts horizontal pixel units to himetric units.
//
//----------------------------------------------------------------
long
HimetricFromHPix(int iPix)
{
HDC hdc = GetDC(NULL);
if (!hdc)
return 0;
int iPPLI = GetDeviceCaps(hdc, LOGPIXELSX);
ReleaseDC(NULL, hdc);
return (HIMETRIC_PER_INCH * (long)iPix)/(long)iPPLI;
}
//+---------------------------------------------------------------
//
// Function: HimetricFromVPix
//
// Synopsis: Converts vertical pixel units to himetric units.
//
//----------------------------------------------------------------
long
HimetricFromVPix(int iPix)
{
HDC hdc = GetDC(NULL);
if (!hdc)
return 0;
int iPPLI = GetDeviceCaps(hdc, LOGPIXELSY);
ReleaseDC(NULL, hdc);
return (HIMETRIC_PER_INCH * (long)iPix)/(long)iPPLI;
}
//+---------------------------------------------------------------
//
// Function: HPixFromHimetric
//
// Synopsis: Converts himetric units to horizontal pixel units.
//
//----------------------------------------------------------------
int
HPixFromHimetric(long lHi)
{
HDC hdc = GetDC(NULL);
if (!hdc)
return 0;
int iPPLI = GetDeviceCaps(hdc, LOGPIXELSX);
ReleaseDC(NULL, hdc);
return (int)(( (iPPLI * lHi) + (HIMETRIC_PER_INCH / 2) )/HIMETRIC_PER_INCH);
}
//+---------------------------------------------------------------
//
// Function: VPixFromHimetric
//
// Synopsis: Converts himetric units to vertical pixel units.
//
//----------------------------------------------------------------
int
VPixFromHimetric(long lHi)
{
HDC hdc = GetDC(NULL);
if (!hdc)
return 0;
int iPPLI = GetDeviceCaps(hdc, LOGPIXELSY);
ReleaseDC(NULL, hdc);
return (int)(( (iPPLI * lHi) + (HIMETRIC_PER_INCH / 2) )/HIMETRIC_PER_INCH);
}