Results 1 to 1 of 1

Thread: Classic VB: ConvertTwipsToPixels

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2004
    Location
    Oklahoma City, OK
    Posts
    36

    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:
    1. Attribute VB_Name = "Conversions"
    2. Option Explicit
    3.  
    4. Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    5. Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
    6. Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, ByVal nIndex As Long) As Long
    7.  
    8. Const LogicalPixelsX = 88
    9. Const LogicalPixelsY = 90
    10. Const TwipsPerInch = 1440
    11.  
    12. 'ConvertTwipsToPixels Function takes two arguments: the number of twips (lngTwips)
    13. 'and the direction to calculate against (boolean: True for Horizontal, False for Vertical)
    14. 'This function can be integrated into Visual Basic 5, Visual Basic 6, or VBA under
    15. 'Office 2000/XP/2003
    16.  
    17. Function ConvertTwipsToPixels(lngTwips As Long, bDirection As Boolean) As Long
    18.     Dim lngDC As Long
    19.     Dim lngPixelsPerInch As Long
    20.  
    21.     lngDC = GetDC(0)
    22.  
    23.     If (bDirection = True) Then
    24.         lngPixelsPerInch = GetDeviceCaps(lngDC, LogicalPixelsX)
    25.     Else
    26.         lngPixelsPerInch = GetDeviceCaps(lngDC, LogicalPixelsY)
    27.     End If
    28.  
    29.     lngDC = ReleaseDC(0, lngDC)
    30.     ConvertTwipsToPixels = (lngTwips / TwipsPerInch) * lngPixelsPerInch
    31. End Function
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width