• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1869
  • Last Modified:

Get Coordinates of a Window

HI,
My application's MDICHILD child window is too large. I have scrolled in the middle. Obviously, half of child window is above the visible screen and half is below the visible screen. How can I get the coordinates of the window part that is currently visible through the mdi window, if this also 0,0 (relative) how do I calculate the actual points relative to whole window.

Regards,
msjammu
0
msjammu
Asked:
msjammu
2 Solutions
 
AlexFMCommented:
Using function GetWindowRect you can get screen coordinates of any window.
To convert screen coordinates to client coordinates use ScreenToClient function.

I cannot follow your explanations about MDI windows, so I give a simple example of the dialog class which has child window m_child:

CRect rect;
m_child.GetWindowRect(&rect);    // rect contains screen coordinates of m_child

this->ScreenToClient(&rect);         // now rect contains coordinates of m_child relatively to this (dialog) client area

You can calculate coordinates of any window relatively to client area of any other window using this way.
0
 
raj3060Commented:
Jammu.
 you can use JavaScript for this purpose. There are several javascript codes out there to get the coordinate.
--Raj
0
 
msjammuAuthor Commented:
raj:
Javascript in VB?
0
 
Julian HansenCommented:
Are you asking what the co-ordinates are of the child window that are visible in the parenti.e.
     a+------------+b
       |                |
c+---A-------------B------+d
  |    |                |         |
  |    |                |         |
  |    |                |         |
  |    |                |         |
e+---H-------------I------+f
       |                |
     j +------------+ k

where cdef is the parent and abjk is the child are you asking about ABHI or abjk.

If abjk then AlexFM has the answer
If ABHI then you need to get the coordinates of the parent cdef and the coordinates of the child abjk and create a new rect ABHJ as c.top a.left f.bottom and k.right.

So ...

GetWindowsRect ( &parent )
GetWindowsRect ( &child )
RECT newRect ;
// You might need to do some checking to see if the width of the child is greater than the parent and choose the parent left and right or child left and right accordingly
newRect.top = parent.top
newrect.left = child.left
newrect.bottom = parent.bottom
newrect.right = child.right

ScreenToClient ( &newrect ) // To get the rect relative to the parent.

Not sure if this is what you were asking though
0
 
msjammuAuthor Commented:
Thanks for the nice diagram
Actually I want ABHI, so each time I resize the child programatically I want it to be placed at the same place where that was before resize. My requirement are due to the MDI scrollbar problem here:

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21118126.html

I am actually trying to figger out a solution for myself for the above problem. you may help !

Let me try your solution

msjammu
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now