R
rlaemmler
Hi,
Programmatically I try to initialize the column width from a pixel
value I have. I found a conversion function but doesn't function quite
accurate. In below code, GetScreenXPI returns 96 on my computer. My
default width is 8.43 char (64 pixel). PioxToCharX in this case would
return 8 char for 64 pixels. What am I missing? Any help would be
appreciated.
Reto
www.xcellery.com
' Conversion code
'*********************
Public Const TWIPS_PER_INCH = 1440 ' number TWIP units per
inch
Public Const TWIPS_PER_CHAR_X = 120 ' number TWIP units per
logical character
Public Function PixToCharX(ByVal pixels As Long) As Long
PixToCharX = ((pixels / GetScreenXDPI) * TWIPS_PER_INCH) /
TWIPS_PER_CHAR_X
End Function
Function GetScreenXDPI() As Long
Dim hdc As Long
hdc = CreateICA("DISPLAY", vbNullString, vbNullString, 0)
If (hdc <> 0) Then
GetScreenXDPI = GetDeviceCaps(hdc, 88) 'screen res x
DeleteDC (hdc)
End If
End Function
Programmatically I try to initialize the column width from a pixel
value I have. I found a conversion function but doesn't function quite
accurate. In below code, GetScreenXPI returns 96 on my computer. My
default width is 8.43 char (64 pixel). PioxToCharX in this case would
return 8 char for 64 pixels. What am I missing? Any help would be
appreciated.
Reto
www.xcellery.com
' Conversion code
'*********************
Public Const TWIPS_PER_INCH = 1440 ' number TWIP units per
inch
Public Const TWIPS_PER_CHAR_X = 120 ' number TWIP units per
logical character
Public Function PixToCharX(ByVal pixels As Long) As Long
PixToCharX = ((pixels / GetScreenXDPI) * TWIPS_PER_INCH) /
TWIPS_PER_CHAR_X
End Function
Function GetScreenXDPI() As Long
Dim hdc As Long
hdc = CreateICA("DISPLAY", vbNullString, vbNullString, 0)
If (hdc <> 0) Then
GetScreenXDPI = GetDeviceCaps(hdc, 88) 'screen res x
DeleteDC (hdc)
End If
End Function