Link to home
Start Free TrialLog in
Avatar of ashugarg00
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?
Avatar of rollocool
rollocool



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(LOGPIXELSY)­;
    }
    else
    {
      iDeviceCaps = pDC->GetDeviceCaps(LOGPIXELSX)­;
    }


    iNbPixels = MulDiv(iNbTwips, iDeviceCaps, TWIPS_PER_INCH);
  }


  return iNbPixels;
}
ASKER CERTIFIED SOLUTION
Avatar of rollocool
rollocool

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ashugarg00

ASKER

Thanks a lot,
Malcolm