CWindow and AfxGetWindowLocation

Started by Paul Squires, March 13, 2019, 09:42:23 AM

Previous topic - Next topic

Paul Squires

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?
Paul Squires
PlanetSquires Software

Paul Squires

...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.
Paul Squires
PlanetSquires Software

José Roca

Done. The new methods are called SxreenX and ScrenY.


' =====================================================================================
' 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
' =====================================================================================