• Welcome to PlanetSquires Forums.
 

AfxGetWindowLocation

Started by Paul Squires, June 20, 2018, 11:09:36 AM

Previous topic - Next topic

Paul Squires

Hi Jose, curious as to why you decided to use pointers for the incoming nLeft and nTop parameters rather than using ByRef which would be more "BASIC-like"?


' ========================================================================================
' Gets the location of the top left corner of the window, in pixels.
' The location is relative to the upper-left corner of the client area in the parent window.
' ========================================================================================
PRIVATE SUB AfxGetWindowLocation (BYVAL hwnd AS HWND, BYVAL nLeft AS LONG PTR, BYVAL nTop AS LONG PTR)
   DIM rc AS RECT
   ' // Get the dimensions of the window
   GetWindowRect(hwnd, @rc)
   ' // Convert the coordinates to be relative to the parent
   MapWindowPoints(HWND_DESKTOP, GetParent(hwnd), CAST(POINT PTR, @rc), 2)
   ' // Return the left and top values
   *nLeft = rc.Left
   *nTop = rc.Top
END SUB
' ========================================================================================
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

Probably it was one of the first that I wrote and I was still trying to follow the syntax used by the FB includes. I can change it if you want.

Paul Squires

I'd vote for changing it because it seems out of place with the rest of your wrappers.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

Changed to:


' ========================================================================================
' Gets the location of the top left corner of the window, in pixels.
' The location is relative to the upper-left corner of the client area in the parent window.
' ========================================================================================
PRIVATE SUB AfxGetWindowLocation (BYVAL hwnd AS HWND, BYREF nLeft AS LONG, BYREF nTop AS LONG)
   DIM rc AS RECT
   ' // Get the dimensions of the window
   GetWindowRect(hwnd, @rc)
   ' // Convert the coordinates to be relative to the parent
   MapWindowPoints(HWND_DESKTOP, GetParent(hwnd), CAST(POINT PTR, @rc), 2)
   ' // Return the left and top values
   nLeft = rc.Left
   nTop = rc.Top
END SUB
' ========================================================================================