PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: CWindow and AfxGetWindowLocation  (Read 103 times)

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8747
  • Windows 10
    • PlanetSquires Software
CWindow and AfxGetWindowLocation
« 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?
 
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

  • Administrator
  • Guru Member
  • *****
  • Posts: 8747
  • Windows 10
    • PlanetSquires Software
Re: CWindow and AfxGetWindowLocation
« Reply #1 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.
Logged
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Josť Roca

  • Moderator
  • Guru Member
  • *****
  • Posts: 3164
Re: CWindow and AfxGetWindowLocation
« Reply #2 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
' =====================================================================================