Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to convert pixels to inches/cm?
Message
From
22/08/2006 18:35:57
Mike Sue-Ping
Cambridge, Ontario, Canada
 
 
To
22/08/2006 07:32:43
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01147454
Message ID:
01147738
Views:
29
>>Hi,
>>
>>I have a grid on a form. I'd like to be able to generate a report based on the information shown in the columns while preserving the grid column order and widths. I've created reports on the fly at runtime that work except for the fact that I cannot reliably determine what the column widths are (in inches) for the report.
>>
>>Does anyone know how I can convert the grid's column width from pixels to inches?
>>
>>TIA
>>
>>Mike
>
>Here is a sample:
>
>Declare Integer ReleaseDC In Win32Api;
>  INTEGER nwnd, Integer hdc
>Declare Integer GetDeviceCaps In Win32API;
>  INTEGER hdc, Integer nIndex
>Declare Integer GetWindowDC In Win32API;
>  INTEGER HWnd
>
>#Define WU_LOGPIXELSX  88
>lnDC = GetWindowDC(0)
>lnPixelsPerInch = GetDeviceCaps(lnDC, WU_LOGPIXELSX)
>lnDC = ReleaseDC(0, lnDC)
>
>lcFont = 'Arial' && _Screen.FontName
>lnFontSize = _Screen.FontSize
>lcStyle = ;
>  Iif(_Screen.FontBold,'B','')+;
>  Iif(_Screen.FontItalic,'I','')+;
>  Iif(_Screen.FontUnderline,'U','')
>lcStyle = Iif( Empty(m.lcStyle),'N',m.lcStyle)
>lcTextToMeasure = "Sample text"
>lnSizeInPixels = Txtwidth(m.lcTextToMeasure, m.lcFont, m.lnFontSize,m.lcStyle) * ;
>  fontmetric(6, m.lcFont, m.lnFontSize,m.lcStyle)
>lnSizeInTwips = ( m.lnSizeInPixels  / m.lnPixelsPerInch * 1440 )
>lnSizeInPoints = m.lnSizeInTwips / 20
>lnSizeInInches = m.lnSizeInTwips / 1440
>lnSizeInCm = m.lnSizeInTwips / 1440 * 2.54
>clear
>TEXT TO m.lcDisplay TEXTMERGE noshow
>Pixels per inch is: <<m.lnPixelsPerInch>>
>Font: <<m.lcFont>>, <<m.lnFontSize>>, <<m.lcStyle>>
>String "<<m.lcTextToMeasure>>" measures:
>In pixels:	<<m.lnSizeInPixels>>
>In Twips:	<<m.lnSizeInTwips>>
>In points:	<<m.lnSizeInPoints>>
>In Inches:	<<m.lnSizeInInches>>
>In centimeters:	<<m.lnSizeInCm>>
>endtext
>? m.lcDisplay
>* 1 Twip = 1/20 point, 567 twips 1 cm ~ 1440/2.54, 1 inch = 72pts = 1440 twips
>
Cetin

Thanks very much Cetin. That does exactly what I need. Now, how do I obtain same for the text height? I imagine I'd need a WU_LOGPIXELSY?

Mike
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform