• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 343
  • Last Modified:

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?
0
ashugarg00
Asked:
ashugarg00
  • 2
1 Solution
 
rollocoolCommented:


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;
}
0
 
rollocoolCommented:

hi

The above function will return in screen coordinates. You will need to change it to client coordinates using the ScreenToClient API

rollocool
0
 
ashugarg00Author Commented:
Thanks a lot,
Malcolm
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now