Results 1 to 4 of 4

Thread: Twips, pixels, and conversion between them

  1. #1

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Twips, pixels, and conversion between them

    I use the following code to move the mouse at one selected spot (20000, 20000) on the screen.

    Code:
    mouse_event MOUSEEVENTF_MOVE Or MOUSEEVENTF_ABSOLUTE, 20000, 20000, 0, 0
    If I click the mouse at THAT spot, the Form_MouseDown returns the following coords: x=351, y=237 (There are in PIXELS, I believe). (see EDIT)

    I want to know how I can convert 351,237 back to 20000, 20000.. I don't think that mouse_event coords (20000,20000) are in twips (351 * 15 != 20000, but 5265).

    I'm sure that's a quite easy one.. Thanks for helping me out.

    Edit: I started using the GetCursorPos API to get the X,Y coords in pixels - x=351,y=263 would be more like it. Extra pixels in the Y coord because the form_mousedown would calculate only the visible form, EXCLUDING the title bar. In my case, I need the title bar included... MOUSEEVENTF_MOVE with coords 1000 and 1000 will bring the mouse over the title bar, and that's something I may need to do.
    Last edited by Krass; Jul 2nd, 2007 at 04:27 PM.
    Chris

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Twips, pixels, and conversion between them

    TWIPS are 1440 to an inch.

    Screen.TwipsPerPixelX and .TwipsPerPixelY will give you values for translating between pixels (which are device specific) and TWIPS - which are a static value.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  3. #3

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Re: Twips, pixels, and conversion between them

    Using mouse_event coords VS pixels:

    5000, 5000 - 87, 65
    10000,10000 - 175,131
    20000,20000 - 351,263

    By trial an error, I noticed that I could take the X coord in pixel (87, 175 and 351) and multiply it by 57 to have the corresponding "mouse_event X coord".

    I can work with this from now on, but I just don't understand WHY "57".
    Chris

  4. #4
    coder. Lord Orwell's Avatar
    Join Date
    Feb 2001
    Location
    Elberfeld, IN
    Posts
    7,628

    Re: Twips, pixels, and conversion between them

    Read szlammy's post. He explained it CLEARLY. 1440 twips per inch. If you change your screen resolution, that number will no longer be valid.
    Twip = PixelNum& * screen.twipsperpixelx for horizontal and screen.twipsperpixely for vertical.
    If you are using API, you can get the client area of your window with
    Code:
    Private Declare Function GetClientRect Lib "user32" (ByVal hWnd As Long, ByRef lpRect As RECT) As Long
    where hwnd is the handle to your window
    and you can convert form pixel position to screen pixel position with this:
    Code:
    Public Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
    where as above hwnd is the handle to your form.
    Both RECT and POINTAPI are structures defined in the api text browser.
    My light show youtube page (it's made the news) www.youtube.com/@lightsofelberfeld
    Contact me on the socials www.facebook.com/lordorwell

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