Screensize in points

Discussion in 'AutoCAD' started by Allen Johnson, Mar 3, 2005.

  1. I would like to keep my form centered vertically on the screen when it gets
    resized.
    VB provides the Screen.Height function but VBA apparently doesn't.
    I can use the GetSystemMetrics(SM_CYSCREEN) to get the screen height in
    pixels but VBA sizes appear to be in points.

    Is there a conversion factor for points to pixels?

    So far, I've stretched the window to its maximum height and read that value
    to set the maximum height, but that's sort of a dirty hack.

    Any ideas?

    Private Sub UserForm_Resize()

    'Guess of the screen height by stretching the window as large as
    'it could go yielded 777 - would be better to use the GetSystemMetrics
    'but I don't know the conversion from points to pixels.

    hgt = Me.Height
    scrnhgt = 777 ' GetSystemMetrics(SM_CYSCREEN)

    Me.top = (scrnhgt - hgt) / 2

    End Sub
     
    Allen Johnson, Mar 3, 2005
    #1
  2. Allen Johnson

    Jackrabbit Guest

    Check your monitor settings. Mine is set to:

    1280 x 1024 @ 96 pixels per inch.

    1024 pixels / 96 pixels per inch = 10.667 inches

    There are 72 points per inch so: 10.667 * 72 = 768 points
     
    Jackrabbit, Mar 4, 2005
    #2
  3. Allen Johnson

    fantum Guest

    scrnhgt = GetSystemMetrics(SM_CYSCREEN) / GetDeviceCaps(GetDC(HWND_DESKTOP), LOGPIXELSY) * 72
     
    fantum, Mar 4, 2005
    #3
  4. Thanks!

    FYI, this is what I used, insce GetDesktopWindow returns the handle...

    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 Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetDesktopWindow Lib "user32.dll" () As Long

    Const SM_CXSCREEN = 0 'X Size of screen
    Const SM_CYSCREEN = 1 'Y Size of Screen
    Const LOGPIXELSX = 88 ' logical pixels per inch X axis
    Const LOGPIXELSY = 90 ' logical pixels per inch Y axis



    scrnhgt = GetSystemMetrics(SM_CYSCREEN) /
    GetDeviceCaps(GetDC(GetDesktopWindow), LOGPIXELSY) * 72
     
    Allen Johnson, Mar 4, 2005
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.