How to get the coordinates of a child window?

How to get the coordinates of a child window?

Postby frose » Mon Feb 04, 2019 12:22 pm

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:
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

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

Postby frose » Tue Feb 05, 2019 8:16 am

The methods :GetCliRect() and :GetCliAreaRect() are doing exactly what I was looking for :!:

Here are some posts regarding these two methods:
viewtopic.php?f=3&t=8733&p=41038&hilit=GetCliRect#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


viewtopic.php?f=17&t=12423&p=62355&hilit=GetCliRect#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: ...


viewtopic.php?f=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  Expand view
#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 :?:
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

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

Postby nageswaragunupudi » Tue Feb 05, 2019 1:38 pm

You are right.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10316
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby frose » Wed Feb 06, 2019 6:51 am

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
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg

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

Postby nageswaragunupudi » Wed Feb 06, 2019 7:12 am

but GetCliRect() and GetCliAreaRect() doesn't work as expected

They always start with 0,0. That is to be expected.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10316
Joined: Sun Nov 19, 2006 5:22 am
Location: India

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

Postby frose » Wed Feb 06, 2019 8:06 am

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/windows/desktop/api/winuser/nf-winuser-getclientrect
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)
Windows 11 Pro 22H2 22621.1848
Microsoft (R) Windows (R) Resource Compiler Version 10.0.10011.16384
Harbour 3.2.0dev (r2008190002)
FWH 23.10 x86
User avatar
frose
 
Posts: 392
Joined: Tue Mar 10, 2009 11:54 am
Location: Germany, Rietberg


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 66 guests