CWebView::FindBrowser Method  
 
HWND FindBrowser(
  HWND hWndParent,  
  LPCTSTR lpszSearch,  
  DWORD dwFlags,  
  LPDWORD lpdwThreadId  
);

The FindBrowser method locates the associated host or child window handle for a browser instance.

Parameters

hWndParent
Handle to the parent window. If this parameter is NULL, it will search all top-level windows. If this parameter is not NULL, it must be a valid window handle and the method will only match against a window which is a child window of the specified handle.
lpszSearch
An optional null-terminated string which specifies a URL. The function will only match those browser windows which have navigated to the specified URL. A simple case-insensitive substring search is performed, but will only match windows created by the current process. If this parameter is NULL or an empty string, the method will not match against any specific URL.
dwFlags
This parameter is reserved for future use and should always be zero. Future versions may expand this to support additional types of matching, such as document titles or more advanced search expressions.
lpdwThreadId
An optional parameter which is a pointer to an unsigned integer value that will contain the thread ID for the browser instance if a matching window is found. If no browser is found, this value will be set to zero. If this information is not required, this parameter can be NULL.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The FindBrowser method can be used to locate the window handle for an existing WebView2 instance that was created by the calling process. This is useful if the application needs to re-establish a reference to a previously created browser window, for example when handling messages or coordinating multiple windows.

If a parent window handle is specified, the method will restrict its search to that window and its children. This is the most efficient approach when the caller already knows the expected parent container. If the parameter is NULL, all top-level windows owned by the process are searched. An optional URL string can also be provided to limit results to windows whose current location contains the specified substring. The search is case-insensitive and only applies to windows created by the current process.

The method only returns a single matching window handle. If multiple instances could match the criteria, the particular instance returned is not guaranteed and the caller should design accordingly. When both the parent handle and search string are NULL, the method simply locates the first available WebView2 instance owned by the current thread.

If the optional lpdwThreadId parameter is supplied, it will receive the thread identifier that owns the WebView2 instance. This can be used when thread affinity is important, such as posting messages directly to the UI thread.

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
Unicode: Implemented as Unicode and ANSI versions

See Also