Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to convert pixels to inches/cm?
Message
From
22/08/2006 07:32:43
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
21/08/2006 20:04:22
Mike Sue-Ping
Cambridge, Ontario, Canada
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:
01147513
Views:
16
This message has been marked as the solution to the initial question of the thread.
>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
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform