Results 1 to 5 of 5

Thread: convert units

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Posts
    8

    Post

    my program snaps to the sides of the screen (like winamp), and the user has the option of changing the # of twips that the screen snaps from (so if the window is closer than X twips, it snaps to the side). anyway, since most people aren't very familiar with twips, i was wondering how to convert twips to pixels, or possibly just use pixels as the default measurement. here is the code from my sub:

    'The Form is the form
    'Dist is the # of twips that it snaps from

    ReleaseCapture
    Call SendMessage(TheForm.hwnd, &HA1, 2, 0&)

    If TheForm.Left <= Dist Then TheForm.Left = 0
    If TheForm.Top <= Dist Then TheForm.Top = 0
    If TheForm.Left >= (Screen.Width - (TheForm.Width + Dist)) Then TheForm.Left = Screen.Width - TheForm.Width
    If TheForm.Top >= (Screen.Height - (TheForm.Height + Dist)) Then TheForm.Top = Screen.Height - TheForm.Height

    ------------------

    -cxs
    [email protected]

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Use the ScaleX/ScaleY Methods to Convert between Scale Modes, ie.

    lValueInPixels = ScaleX(lValueInTwips, vbTwips, vbPixels)

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Certified AllExperts Expert

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Posts
    8

    Post

    i still couldn't get it. i tried messing around with a few things, but it always ended up not snapping to the sides properly. here is my original sub:

    Sub MoveFormSnap(TheForm As Form, Dist As Single)

    ReleaseCapture
    Call SendMessage(TheForm.hwnd, &HA1, 2, 0&)

    If TheForm.Left <= Dist Then TheForm.Left = 0
    If TheForm.Top <= Dist Then TheForm.Top = 0
    If TheForm.Left >= (Screen.Width - (TheForm.Width + Dist)) Then TheForm.Left = Screen.Width - TheForm.Width
    If TheForm.Top >= (Screen.Height - (TheForm.Height + Dist)) Then TheForm.Top = Screen.Height - TheForm.Height

    End Sub

    [This message has been edited by cxs (edited 02-07-2000).]

  4. #4
    New Member
    Join Date
    Feb 2000
    Posts
    8

    Post

    Never posted here before, so please bear with me if I screw something up.

    Easiest way that I know of would be to let the user post in pixels and use Screen.TwipsPerPixelX and/or Screen.TwipsPerPixelY to make the conversion:

    User enters 5 pixels. 5 * Screen.TwipsPerPixelX would be your "dist". I'd guess both ...PixelX and ...PixelY are always the same, but I don't know.

    Hope this helps!

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Posts
    8

    Post

    i tested it with winamp using the same number of pixels and it worked perfectly....thanks a lot. here's the final sub, just in case you are interested.

    _______________

    Sub MoveFormSnap(TheForm As Form, NumOfPixels)

    Dim TwipsPerX

    TwipsPerX = Screen.TwipsPerPixelX
    NumOfPixels = NumOfPixels * TwipsPerX

    ReleaseCapture
    Call SendMessage(TheForm.hwnd, &HA1, 2, 0&)

    If TheForm.Left <= NumOfPixels Then TheForm.Left = 0
    If TheForm.Top <= NumOfPixels Then TheForm.Top = 0
    If TheForm.Left >= (Screen.Width - (TheForm.Width + NumOfPixels)) Then TheForm.Left = Screen.Width - TheForm.Width
    If TheForm.Top >= (Screen.Height - (TheForm.Height + NumOfPixels)) Then TheForm.Top = Screen.Height - TheForm.Height

    End Sub
    _______________



    ------------------

    -cxs
    [email protected]

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