Solved

Get Coordinates of a Window

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
find a node in VST 2 47
triangle challenge 4 79
firstChar challenge 13 86
Adding Namespace to the second node of the xml 16 35
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
A short article about a problem I had getting the GPS LocationListener working.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now