Solved

Get Coordinates of a Window

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

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
This is about my first experience with programming Arduino.
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

785 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