Page 1 of 1

How to get the coordinates of a child window?

Posted: Mon Feb 04, 2019 12:22 pm
by frose
Hi,

understanding that the method ::GetRect() always returns an oRect with the coordinates on the main window.

But how to get the coordinates of a child window (TMdiChild) relative to the parent window (TMdiFrame) when the user moved/sized it?

Is there a method or function which is doing this job or have I write one for my own :?:

Any suggestion for this 'HowTo' are welcome :) :idea:

Re: How to get the coordinates of a child window?

Posted: Tue Feb 05, 2019 8:16 am
by frose
The methods :GetCliRect() and :GetCliAreaRect() are doing exactly what I was looking for :!:

Here are some posts regarding these two methods:
http://forums.fivetechsupport.com/viewt ... ect#p41038:
Antonio wrotes:
The buttonbar and the messagebar are also controls, in the same way as SAYs, GETs, Buttons, etc.

You just need to use oBar:nHeight and oMsgBar:nHeight to calculate the right coordinates for the other controls

When you do oWnd:oClient = oControl the FWH calculates the remaining client area automatically
http://forums.fivetechsupport.com/viewt ... ect#p62355:
Can you be more specific about your problem. It seams to me now, you have the same problem I as have. My question is: do you create browse from RESOURCE (.RC or .DLL) or you put it on the dialog with @ y,x commands? It is important. If I don't use resources, I can fit browse without problem, but if I use resources, then there are problems, browse doesn't fit always in the dialog! The difference arise when I change the system settings related to the font sizes! (Setup-display-settings-font size).
Try: ...
http://forums.fivetechsupport.com/viewt ... =6&t=35139&:
lo que hace es centrar en la pantalla, no en la ventana contenedora.
A mi entender, creo que deberia de funcionar el evento Center() del ejemplo anterior, seria lo mas "correcto"


Y para centrarlo, de momento... lo hago "calculando" el ancho/alto...

Code: Select all

#include "FiveWin.ch"

function Main()

   local oWnd, oChild1
   Local nClientWidth

   DEFINE WINDOW oWnd FROM 1,0 TO 500,800 PIXEL
   nClientWidth := oWnd:GetCliAreaRect():nWidth

   DEFINE WINDOW oChild1 FROM 0, (nClientWidth-250)/2 TO 0, (nClientWidth/2)+125 PIXEL OF oWnd

   oChild1:nHeight := oWnd:GetCliAreaRect():nHeight
   oChild1:Show()

   ACTIVATE WINDOW oWnd 

Return nil
Conclusions:
:GetCliRect() - returns an oRect with the relative gross coordinates, mean including the menu (SM_CYMENU), button and message bar,...
:GetCliAreaRect() - returns an oRect with the relative net coordinates, mean excluding the menu, button and message bar,...

Both oRect excluded the window title (SM_CYCAPTION) and frame (SM_CYDLGFRAME, SM_CYDLGFRAME)

Any comments or corrections :?:

Re: How to get the coordinates of a child window?

Posted: Tue Feb 05, 2019 1:38 pm
by nageswaragunupudi
You are right.

Re: How to get the coordinates of a child window?

Posted: Wed Feb 06, 2019 6:51 am
by frose
but GetCliRect() and GetCliAreaRect() doesn't work as expected, nTop and nLeft are always 0 :o
I then tried GetCoors() and it works: 8)
Image

Re: How to get the coordinates of a child window?

Posted: Wed Feb 06, 2019 7:12 am
by nageswaragunupudi
but GetCliRect() and GetCliAreaRect() doesn't work as expected
They always start with 0,0. That is to be expected.

Re: How to get the coordinates of a child window?

Posted: Wed Feb 06, 2019 8:06 am
by frose
Ok, that is what I suspected, but I wasn't quite sure, if it is true, because it's not very clear explained here:
https://docs.microsoft.com/en-us/window ... clientrect
Retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0).
They should be say:
... the coordinates of the upper-left corner are ALWAYS (0,0).

Nevertheless, I have got want I want and can go further now 8)