Solved

Convert Pixels to Twips

Posted on 2001-09-11
8
3,344 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…
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…
Suggested Courses
Course of the Month7 days, 15 hours left to enroll

617 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