Solved

ChildWindowFromPoint

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

932 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

16 Experts available now in Live!

Get 1:1 Help Now