Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

ChildWindowFromPoint

Posted on 1998-10-29
3
693 Views
Last Modified: 2013-11-20
I am using GetCursorPos(LPPOINT lpPoint) to get the position of the cursor.  Then I use ChildWindowFromPoint using the MainFrame.  For example

CMainFrame *pMainFrame = (CMainFrame *)AfxGetMainWnd();
CWnd *childWnd = pMainFrame->ChildWindowFromPoint(point);
if (childWnd )
   ...

The problem is that childWnd is not return NULL when point is not within a child window.  What's the problem?

How can I get the window under the mouse?


0
Comment
Question by:solomon021499
3 Comments
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1324009
If it's not within any child window, it will return the handle of the parent, so:
if (childWnd->m_hWnd!=parentWnd->m_hWnd) //Returned handle
0
 

Author Comment

by:solomon021499
ID: 1324010
It's a good answer except that it does not work.  I get the same child window pointer whether I clicked in the main frame or the child frame, and it's not the main frame pointer.

I don't know why?
0
 
LVL 2

Accepted Solution

by:
prasanth earned 200 total points
ID: 1324011
Here's the problem. GetCursorPos returns screen coordinates but ChildWindowFromPoint takes client coordinates.

So convert point from screen to client coordinates by calling
pMainFrame->ScreenToClient(&point);
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Title # Comments Views Activity
repeatEnd java challenge 42 85
Generic progress indicator 6 117
conditional code and condition difference 9 84
tripleUp challenge 7 86
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

808 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