ashugarg00
asked on
Converting twips to client coordinates
I'm using a rich edit control which supports tables. I need to convert twips (which indicate the column width) into client coordinates. Any help?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot,
Malcolm
Malcolm
A twip is a 20th of a typographical point, which is 1/72 th of an inch.
The resolustion of an inch on screen can be found with GetDeviceCaps,
LOGPIXELSX and LOGPIXELSY.
So, a twip (height) is LOGPIXELSY/72/20.
This function could help you
#define TWIPS_PER_INCH 1440
int TwipsToPixels(CDC* pDC, int iNbTwips, BOOL bY)
{
int iNbPixels = 0;
if (pDC != NULL)
{
int iDeviceCaps;
if (bY == TRUE)
{
iDeviceCaps = pDC->GetDeviceCaps(LOGPIXE
}
else
{
iDeviceCaps = pDC->GetDeviceCaps(LOGPIXE
}
iNbPixels = MulDiv(iNbTwips, iDeviceCaps, TWIPS_PER_INCH);
}
return iNbPixels;
}