Solved

Get Coordinates of a Window

Posted on 2004-09-11
5
1,846 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 55

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
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 …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

765 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