Announcement

Collapse
No announcement yet.

Dialog Pixels To Units

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dialog Pixels To Units

    When I use the following code:
    Code:
    Dim X As Long, Y As Long
      Dialog Pixels hDlg, GetSystemMetrics(% SM_CXSCREEN)  ,GetSystemMetrics(%SM_CYSCREEN) To Units x, y
      Control Add Label, hDlg, -1, "Test!", X\2-20, Y\2-10, 40, 20
    The label should be positioned on the screen center, but it isn't. The horizontal (x)position is OK, but the vertical (y) position is well below the screen center on a fullscreen dialog window. The getsystemmetrics call returns the right value's (1024 * 768 in my case) Is there some error in the pixels-to-units conversion?



    -------------
    Kind regards,
    Peter.
    Regards,
    Peter

  • #2
    Peter;

    The coordinates used for creating controls are "Client" coordinates, not "Screen" coordinates.

    To make a label centered in your Dialog, requires knowing the width and height of the client area (inside of Dialog, excluding the Caption Bar, menu and Borders) and then calculating where to center it.

    You seem to be using "Screen" coordinates, based on centering to the screen.



    ------------------
    Chris Boss
    Computer Workshop
    Developer of "EZGUI"
    http://cwsof.com
    http://twitter.com/EZGUIProGuy

    Comment


    • #3
      also, when centering a control or a dialog relative to the screen, you should also take into account how big the task bar is - if the task bar is large or on an "unusual" position, your app may end up overlapping it which can produce interesting results! you should calculate the centre based on the available desktop area, rather than the screen area.

      the systemparametersinfo() api with the %spi_getworkarea flag will give you the true desktop size.

      also see http://www.powerbasic.com/support/pb...ead.php?t=1855

      ------------------
      lance
      powerbasic support
      mailto:[email protected][email protected]</a>
      Lance
      mailto:[email protected]

      Comment

      Working...
      X