Solved

Convert Pixels to Twips

Posted on 2001-09-11
8
2,898 Views
Last Modified: 2007-12-19
I am trying to convert pixels to twips.  I know about TwipsPerPixelX, but it only seems to work with Screen.TwipsPerPixelX.  Is there a built in function that does this or does someone have a conversion formula?
0
Comment
Question by:joesmow
8 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 6475388
Hi joesmow,

From the Access Developers Handbook

===================================
http://www.mcwtech.com
Stop by http://www.developershandbook.com   
if you have any of the Developer's Handbooks
co-authored by MCW Technologies folks.
Updates, info, and registration available.

===================================

Private Declare Function GetDC _
 Lib "user32" _
 (ByVal hWnd As Long) As Long

Private Declare Function ReleaseDC _
 Lib "user32" _
 (ByVal hWnd As Long, ByVal hdc As Long) As Long

Private Declare Function GetSystemMetrics _
 Lib "user32" _
 (ByVal nIndex As Long) As Long
 
Private Declare Function GetDeviceCaps _
 Lib "gdi32" _
 (ByVal hdc As Long, ByVal nIndex As Long) As Long

Private Type POINTAPI
    x As Long
    y As Long
End Type

' These give the size of the whole screen.
Public Const SM_CXSCREEN = 0
Public Const SM_CYSCREEN = 1

' These give the usable size of the screen.
Private Const SM_CXFULLSCREEN = 16
Private Const SM_CYFULLSCREEN = 17

Private Const LOGPIXELSX = 88        '  Logical pixels/inch in X
Private Const LOGPIXELSY = 90        '  Logical pixels/inch in Y
Private Const adhcTwipsPerInch = 1440

Private mptCurrentDPI As POINTAPI
Private mptTwipsPerPixel As POINTAPI
Private mptCurrentScreen As POINTAPI

Public Sub GetScreenInfo()
    ' Get the information context you need to find
    ' the screen info.
    ' This procedure fills in the module variables:
    ' mptCurrentScreen
    ' mptCurrentDPI
    ' mptTwipsPerPixel
   
    ' From Access 2000 Developer's Handbook, Volume I
    ' by Getz, Litwin, and Gilbert (Sybex)
    ' Copyright 1999.  All rights reserved.
   
    Const HWND_DESKTOP = 0
    Dim lngDC As Long
   
    lngDC = GetDC(HWND_DESKTOP)

    ' If the call to GetDC didn't fail (and it had
    ' better not, or things are really busted),
    ' then get the info.
   
    If lngDC <> 0 Then
        ' Find the number of pixels in both directions on the
        ' screen, (640x480, 800x600, 1024x768, 1280x1024?).
        mptCurrentScreen.x = GetSystemMetrics(SM_CXSCREEN)
        mptCurrentScreen.y = GetSystemMetrics(SM_CYSCREEN)
       
        ' Get the pixels/inch ratio, as well.
        mptCurrentDPI.x = GetDeviceCaps(lngDC, LOGPIXELSX)
        mptCurrentDPI.y = GetDeviceCaps(lngDC, LOGPIXELSY)
       
        mptTwipsPerPixel.x = adhcTwipsPerInch / mptCurrentDPI.x
        mptTwipsPerPixel.y = adhcTwipsPerInch / mptCurrentDPI.y

        ' Release the information context.
        Call ReleaseDC(HWND_DESKTOP, lngDC)
    End If
End Sub

HTH:O)Bruintje
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6475472
ypu could use multiply pixel per twips:

pixel * 15 = twips
0
 
LVL 4

Expert Comment

by:Jeremy_D
ID: 6476225
joesmow: What exactly is the problem in using the TwipsPerPixel properties of the Screen object?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 4

Accepted Solution

by:
Jeremy_D earned 50 total points
ID: 6476226
bruintje: that seems like an incredible elaborate way to do this:

TwipsX = PixelsX * Screen.TwipsPerPixelX
TwipsY = PixelsY * Screen.TwipsPerPixelY


0
 
LVL 4

Expert Comment

by:Jeremy_D
ID: 6476231
Richie: Assuming 15 twips per pixel will bring you into problems. This value is not the same for all display devices. I seem to remember that for instance the on-board graphics of the Intel 810 chipset motherboards work with 14 twips per pixel. Might have been another graphics device, but you get my drift, 15 is not a fixed number.
0
 

Expert Comment

by:IBRown
ID: 6476237
Richie: There are only 15 twips per pixel when working on the screen in 'small fonts'. Change to 'large fonts' and the value is something like 12.

Joesmow: There is a Printer.TwipsPerPixelX and Printer.TwipsPerPixelY. What is the problem you are having? What is it that you are trying to do?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6476477
Yep, i know. Just a cheap comment ;)
0
 

Author Comment

by:joesmow
ID: 6477256
Thanks.  I just misunderstood how Screen.TwipsPerPixelX works.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question