CWebView::GetChildWindow Method  
 
HWND GetChildWindow();

The GetChildWindow method returns the handle of the internal browser child window.

Parameters

None.

Return Value

If the method succeeds, the return value is a window handle. If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

The value returned by this function is the handle to an internal child window used by the WebView control. Applications should treat this handle as an implementation detail and avoid sending messages or altering window styles directly. The control manages this child window and relies on its state for proper operation. Interfering with the child window (for example, by subclassing it, changing its parent, or destroying it) can cause undefined behavior and application instability.

This method is primarily provided to support advanced scenarios where access to the native window handle is unavoidable, such as integrating with APIs that require a child window handle. In most cases, developers should use the higher-level functions in the CWebView class instead of interacting with the child window directly.

GetChildWindow searches the immediate child windows of the specified WebView host to locate the internal browser window. The function uses the window class name to identify the browser window, which is an implementation detail of the WebView2 runtime and may change between versions. If multiple Chromium-based windows are children of the same host, the method may not be able to distinguish between them and could return an incorrect handle. Applications should not attempt to locate the browser window independently by its class name.

The returned window handle is not guaranteed to remain valid for the lifetime of the WebView control. The WebView2 runtime may recreate its internal windows, particularly when the browser process is restarted. Applications should avoid storing the returned handle for extended periods and should call GetChildWindow again when the handle is needed.

If you want to get the handle to the window hosting the browser control, use the GetSafeHwnd method.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtmv12.lib

See Also