Solved

ChildWindowFromPoint

Posted on 1998-10-29
3
686 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
paragon account problem 9 96
Pressing cancel button with C# UI Automation 3 40
centeredAverage challenge 8 122
tripleUp challenge 7 66
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 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

14 Experts available now in Live!

Get 1:1 Help Now