Solved

Get Coordinates of a Window

Posted on 2004-09-11
5
1,847 Views
Last Modified: 2012-06-27
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
Comment
Question by:msjammu
5 Comments
 
LVL 48

Assisted Solution

by:AlexFM
AlexFM earned 250 total points
ID: 12033759
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
 
LVL 11

Expert Comment

by:raj3060
ID: 12035564
Jammu.
 you can use JavaScript for this purpose. There are several javascript codes out there to get the coordinate.
--Raj
0
 
LVL 6

Author Comment

by:msjammu
ID: 12037241
raj:
Javascript in VB?
0
 
LVL 56

Accepted Solution

by:
Julian Hansen earned 250 total points
ID: 12037773
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
 
LVL 6

Author Comment

by:msjammu
ID: 12037985
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

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question