0 out of 1 rated this helpful - Rate this topic

ChildWindowFromPoint function

Applies to: desktop apps only

Determines which, if any, of the child windows belonging to a parent window contains the specified point. The search is restricted to immediate child windows. Grandchildren, and deeper descendant windows are not searched.

To skip certain child windows, use the ChildWindowFromPointEx function.

Syntax

HWND WINAPI ChildWindowFromPoint(
  __in  HWND hWndParent,
  __in  POINT Point
);

Parameters

hWndParent [in]

Type: HWND

A handle to the parent window.

Point [in]

Type: POINT

A structure that defines the client coordinates, relative to hWndParent, of the point to be checked.

Return value

Type:

Type: HWND

The return value is a handle to the child window that contains the point, even if the child window is hidden or disabled. If the point lies outside the parent window, the return value is NULL. If the point is within the parent window but not within any child window, the return value is a handle to the parent window.

Remarks

The system maintains an internal list, containing the handles of the child windows associated with a parent window. The order of the handles in the list depends on the Z order of the child windows. If more than one child window contains the specified point, the system returns a handle to the first window in the list that contains the point.

ChildWindowFromPoint treats an HTTRANSPARENT area of a standard control the same as other parts of the control. In contrast, RealChildWindowFromPoint treats an HTTRANSPARENT area differently; it returns the child window behind a transparent area of a control. For example, if the point is in a transparent area of a groupbox, ChildWindowFromPoint returns the groupbox while RealChildWindowFromPoint returns the child window behind the groupbox. However, both APIs return a static field, even though it, too, returns HTTRANSPARENT.

Examples

For an example, see "Creating a Combo Box Toolbar" in Using Combo Boxes.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Reference
ChildWindowFromPointEx
RealChildWindowFromPoint
WindowFromPoint
Conceptual
Windows
Other Resources
POINT

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
They all don't work correctly
It does not matter if you use WindowFromPoint, ChildWindowFromPoint, ChildWindowFromPointEx or RealChildWindowFromPoint. None of these functions returns ALWAYS the windows under the given point. These functions work in some cases, but none of them works correctly ALWAYS. The one the works best to obtain the window at the given point is RealChildWindowFromPoint. But also this function fails if you have a Dialog in a TabControl like in Microsoft`s Html Help Workshop for example. In this case the funtion returns the Tab Control although the given point lies in the smaller Dialog (ListBox). So if you need a realiable function that works corretcly ALWAYS you will end up writing your own code. You have to test with a lot of applications to find out if your code realy works correctly in all cases. Don't forget to test also RTL scenarios! It is a shame that Microsoft is not able to give a function that works correctly.
Comparison of different *WindowFromPoint* methods
Raymond Chen discusses the different methods here:

http://blogs.msdn.com/b/oldnewthing/archive/2010/12/30/10110077.aspx

"WindowFromPoint, ChildWindowFromPoint, RealChildWindowFromPoint, when will it all end?"