Solved

Convert Pixels to Twips

Posted on 2001-09-11
8
2,634 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now