Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ChildWindowFromPoint

Posted on 1998-10-29
3
Medium Priority
?
708 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 400 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

824 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