Solved

ChildWindowFromPoint

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
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.

821 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