1 Attachment(s)
Classic VB: ConvertTwipsToPixels
This module is designed to assist with migration from Visual Basic 5/6 to the .NET Framework. It provides one function: ConvertTwipsToPixels.
I have used this module in Visual Basic 6 projects and have incorpoated it into an Excel 2003 spreadsheet as a function. If you have any questions, let me know.
VB Code:
Attribute VB_Name = "Conversions"
Option Explicit
Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
Const LogicalPixelsX = 88
Const LogicalPixelsY = 90
Const TwipsPerInch = 1440
'ConvertTwipsToPixels Function takes two arguments: the number of twips (lngTwips)
'and the direction to calculate against (boolean: True for Horizontal, False for Vertical)
'This function can be integrated into Visual Basic 5, Visual Basic 6, or VBA under
'Office 2000/XP/2003
Function ConvertTwipsToPixels(lngTwips As Long, bDirection As Boolean) As Long
Dim lngDC As Long
Dim lngPixelsPerInch As Long
lngDC = GetDC(0)
If (bDirection = True) Then
lngPixelsPerInch = GetDeviceCaps(lngDC, LogicalPixelsX)
Else
lngPixelsPerInch = GetDeviceCaps(lngDC, LogicalPixelsY)
End If
lngDC = ReleaseDC(0, lngDC)
ConvertTwipsToPixels = (lngTwips / TwipsPerInch) * lngPixelsPerInch
End Function