PlanetSquires Forums

Support Forums => WinFBX - Windows Framework for FreeBASIC => Topic started by: Paul Squires on March 13, 2019, 09:12:23 AM

Title: CWindow and AfxGetWindowLocation
Post by: Paul Squires on March 13, 2019, 09:12:23 AM
Hi Jose,

Just curious... should there be a "Left", "Top", properties for the CWindow class? We have properties like Height, Width, ClientWidth, ClientHeight, but nothing related to location of the window or child control? I have been using AfxGetWindowLocation but, as you know, that returns the raw pixel location not adjusted for the DPI setting. For consistency, should you add such properties to retrieve location of the form and/or child controls? Obviously I can build it into my winformsx classes but it makes more sense to have it in the CWindow base class?
 
Title: Re: CWindow and AfxGetWindowLocation
Post by: Paul Squires on March 13, 2019, 10:10:48 AM
...and I have already had to make changes to the visual designer WinFormsX code generation to modify the pixels returned by properties such as left, top, width, height to ensure that the value returned has been adjusted to account for the dpi resolution.
Title: Re: CWindow and AfxGetWindowLocation
Post by: Josť Roca on March 13, 2019, 12:08:33 PM
Done. The new methods are called SxreenX and ScrenY.

Code: [Select]
' =====================================================================================
' Returns the x-coordinate of the window relative to the screen.
' =====================================================================================
PRIVATE PROPERTY CWindow.ScreenX () AS LONG
   DIM rc AS RECT
   ' // Get the dimensions of the window
   .GetWindowRect(m_hwnd, @rc)
   ' // Convert the coordinates to be relative to the parent
   .MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), CAST(POINT PTR, @rc), 2)
   ' // Divide by m_rx to make the result High DPI aware
   PROPERTY = rc.Left / m_rx
END PROPERTY
' =====================================================================================

' =====================================================================================
' Returns the y-coordinate of the window relative to the screen.
' =====================================================================================
PRIVATE PROPERTY CWindow.ScreenY () AS LONG
   DIM rc AS RECT
   ' // Get the dimensions of the window
   .GetWindowRect(m_hwnd, @rc)
   ' // Convert the coordinates to be relative to the parent
   .MapWindowPoints(HWND_DESKTOP, GetParent(m_hwnd), CAST(POINT PTR, @rc), 2)
   ' // Divide by m_ry to make the result High DPI aware
   PROPERTY = rc.Top / m_ry
END PROPERTY
' =====================================================================================