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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to calculate twips to pixels

Usefull Functions & Procedures

How to calculate twips to pixels

by  Mike Gagnon  Posted    (Edited  )
Twips is a unit of measure sometimes used in calculating picture resolution.

Code:
#DEFINE TWIPS_IN_CM 567
#DEFINE HWND_DESKTOP 0
#DEFINE LOGPIXELSX 88
#DEFINE LOGPIXELSY 90

?TwipsToMM(5300)
?TwipsPerPixelX()
?TwipsPerPixelY()

FUNCTION TwipsToMM
 LPARAMETER tnTwips
 RETURN INT(((tnTwips + 0.0005) / TWIPS_IN_CM) * 10)
ENDFUNC

FUNCTION TwipsPerPixelX
 LOCAL lnDC, lnTwipsPerpixelX
 DECLARE LONG GetDC IN "user32" LONG hwnd
 DECLARE LONG ReleaseDC IN "user32" LONG hwnd, LONG hdc
 DECLARE LONG GetDeviceCaps IN "gdi32" LONG hdc, LONG nIndex
 lnDC = GetDC(HWND_DESKTOP)
 lnTwipsPerpixelX = 1440 / GetDeviceCaps(lnDC, LOGPIXELSX)
 ReleaseDC(HWND_DESKTOP, lnDC)
 RETURN lnTwipsPerpixelX
ENDFUNC

FUNCTION TwipsPerPixelY
 LOCAL lnDC
 DECLARE LONG GetDC IN "user32" LONG hwnd
 DECLARE LONG ReleaseDC IN "user32" LONG hwnd, LONG hdc
 DECLARE LONG GetDeviceCaps IN "gdi32" LONG hdc, LONG nIndex
 lnDC = GetDC(HWND_DESKTOP)
 lnTwipsInPixelY = 1440 / GetDeviceCaps(lnDC, LOGPIXELSY)
 ReleaseDC(HWND_DESKTOP, lnDC)
 RETURN lnTwipsInPixelY
ENDFUNC
Mike Gagnon
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top