Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How many Twips are there in a Pixel?

Status
Not open for further replies.

sparafucile17

Programmer
Apr 5, 2002
40
US
Does anyone know how to calculate the number of twips per pixel? I am trying to determine how many lines of text will fit into my Rich Edit box. I can physically count that there are 23 lines at *MY* default windows font, but what I want to do is to figure out how to calculate this. So this is what I have so far:

CRichEditCtrl m_LogCtrl;
CHARFORMAT f;
RECT LogRect;

m_LogCtrl.GetDefaultCharFormat(f);
m_LogCtrl.GetRect(&LogRect);

LinesInLog = (LogRect.bottom - LogRect.top) / (f.yHeight);

The problem comes in when I try to determione the height of the font in pixels... The variable f.yHeight is returned in twips. But I can't for the life of me figure out how to get that into pixels.

Any suggestions and/or other alternatives for finding the max number of lines of text in a Rich Edit box?



Thanks,
Jeff Tackett
Sofware Engineer
Visteon Corp.
 
use GetDeviceCaps( hdcfromyoureditbox, LOGPIXELSY ) to get the number of pixels per inch of your screen. Then one twip is 1/20 of a point, or 1/1440 of an inch.

Vincent
 
Thanks, that helps out. But one thing... How do you get the HDC to your edit box? I looked around in MSDN and didn't find much.

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top