Solved

Convert Pixels to Twips

Posted on 2001-09-11
8
2,994 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

685 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