Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
interface ICoreWebView2FindOptions
: public IUnknown
Interface defining the find options.
Summary
Members | Descriptions |
---|---|
get_FindTerm | Gets the FindTerm property. |
get_IsCaseSensitive | Gets the IsCaseSensitive property. |
get_ShouldHighlightAllMatches | Gets the ShouldHighlightAllMatches property. |
get_ShouldMatchWord | Gets the ShouldMatchWord property. |
get_SuppressDefaultFindDialog | Gets the SuppressDefaultFindDialog property. |
put_FindTerm | Gets or sets the word or phrase to be searched in the current page. |
put_IsCaseSensitive | Determines if the find session is case sensitive. |
put_ShouldHighlightAllMatches | Gets or sets the state of whether all matches are highlighted. |
put_ShouldMatchWord | Similar to case sensitivity, word matching also can vary by locale, which may be influenced by both the browser's UI locale and the document's language settings. |
put_SuppressDefaultFindDialog | Sets this property to hide the default Find UI. |
This interface provides the necessary methods and properties to configure a find session.
Applies to
Product | Introduced |
---|---|
WebView2 Win32 | N/A |
WebView2 Win32 Prerelease | 1.0.3415 |
Members
get_FindTerm
Gets the FindTerm
property.
public HRESULT get_FindTerm(LPWSTR * value)
The caller must free the returned string with CoTaskMemFree
. See API Conventions.
get_IsCaseSensitive
Gets the IsCaseSensitive
property.
public HRESULT get_IsCaseSensitive(BOOL * value)
get_ShouldHighlightAllMatches
Gets the ShouldHighlightAllMatches
property.
public HRESULT get_ShouldHighlightAllMatches(BOOL * value)
get_ShouldMatchWord
Gets the ShouldMatchWord
property.
public HRESULT get_ShouldMatchWord(BOOL * value)
get_SuppressDefaultFindDialog
Gets the SuppressDefaultFindDialog
property.
public HRESULT get_SuppressDefaultFindDialog(BOOL * value)
put_FindTerm
Gets or sets the word or phrase to be searched in the current page.
public HRESULT put_FindTerm(LPCWSTR value)
You can set FindTerm
to any text you want to find on the page. This will take effect the next time you call the Start()
method.
bool AppWindow::FindTerm()
{
auto webView2_28 = m_webView.try_query<ICoreWebView2_28>();
CHECK_FEATURE_RETURN(webView2_28);
wil::com_ptr<ICoreWebView2Find> webView2find;
CHECK_FAILURE(webView2_28->get_Find(&webView2find));
TextInputDialog dialog(
GetMainWindow(), L"Find on Page Term", L"Find on Page Term:", L"Enter Find Term");
auto m_env15 = m_webViewEnvironment.try_query<ICoreWebView2Environment15>();
CHECK_FEATURE_RETURN(m_env15);
CHECK_FAILURE(webView2find->Stop());
if (!findOptions)
{
findOptions = SetDefaultFindOptions();
}
CHECK_FAILURE(findOptions->put_FindTerm(dialog.input.c_str()));
CHECK_FAILURE(webView2find->Start(
findOptions.get(), Callback<ICoreWebView2FindStartCompletedHandler>(
[this](HRESULT result) -> HRESULT { return S_OK; })
.Get()));
return true;
}
put_IsCaseSensitive
Determines if the find session is case sensitive.
public HRESULT put_IsCaseSensitive(BOOL value)
Returns TRUE if the find is case sensitive, FALSE otherwise. When toggling case sensitivity, the behavior can vary by locale, which may be influenced by both the browser's UI locale and the document's language settings. The browser's UI locale typically provides a default handling approach, while the document's language settings (e.g., specified using the HTML lang attribute) can override these defaults to apply locale-specific rules. This dual consideration ensures that text is processed in a manner consistent with user expectations and the linguistic context of the content.
bool AppWindow::IsCaseSensitive()
{
auto webView2_28 = m_webView.try_query<ICoreWebView2_28>();
CHECK_FEATURE_RETURN(webView2_28);
wil::com_ptr<ICoreWebView2Find> webView2find;
CHECK_FAILURE(webView2_28->get_Find(&webView2find));
auto m_env15 = m_webViewEnvironment.try_query<ICoreWebView2Environment15>();
CHECK_FEATURE_RETURN(m_env15);
CHECK_FAILURE(webView2find->Stop());
if (!findOptions)
{
findOptions = SetDefaultFindOptions();
}
BOOL caseSensitive;
findOptions->get_IsCaseSensitive(&caseSensitive);
CHECK_FAILURE(findOptions->put_IsCaseSensitive(!caseSensitive));
CHECK_FAILURE(webView2find->Start(
findOptions.get(), Callback<ICoreWebView2FindStartCompletedHandler>(
[this](HRESULT result) -> HRESULT { return S_OK; })
.Get()));
return true;
}
put_ShouldHighlightAllMatches
Gets or sets the state of whether all matches are highlighted.
public HRESULT put_ShouldHighlightAllMatches(BOOL value)
Returns TRUE if all matches are highlighted, FALSE otherwise. Note: Changes to this property take effect only when Start, FindNext, or FindPrevious is called. Preferences for the session cannot be updated unless another call to the Start function on the server-side is made. Therefore, changes will not take effect until one of these functions is called.
bool AppWindow::ShouldHighlightAllMatches()
{
auto webView2_28 = m_webView.try_query<ICoreWebView2_28>();
CHECK_FEATURE_RETURN(webView2_28);
wil::com_ptr<ICoreWebView2Find> webView2find;
CHECK_FAILURE(webView2_28->get_Find(&webView2find));
auto m_env15 = m_webViewEnvironment.try_query<ICoreWebView2Environment15>();
CHECK_FEATURE_RETURN(m_env15);
CHECK_FAILURE(webView2find->Stop());
if (!findOptions)
{
findOptions = SetDefaultFindOptions();
}
BOOL shouldHighlightAllMatches;
CHECK_FAILURE(findOptions->get_ShouldHighlightAllMatches(&shouldHighlightAllMatches));
CHECK_FAILURE(findOptions->put_ShouldHighlightAllMatches(!shouldHighlightAllMatches));
CHECK_FAILURE(webView2find->Start(
findOptions.get(), Callback<ICoreWebView2FindStartCompletedHandler>(
[this](HRESULT result) -> HRESULT { return S_OK; })
.Get()));
return true;
}
put_ShouldMatchWord
Similar to case sensitivity, word matching also can vary by locale, which may be influenced by both the browser's UI locale and the document's language settings.
public HRESULT put_ShouldMatchWord(BOOL value)
The browser's UI locale typically provides a default handling approach, while the document's language settings (e.g., specified using the HTML lang attribute) can override these defaults to apply locale-specific rules. This dual consideration ensures that text is processed in a manner consistent with user expectations and the linguistic context of the content. ShouldMatchWord determines if only whole words should be matched during the find session. Returns TRUE if only whole words should be matched, FALSE otherwise.
bool AppWindow::ShouldMatchWord()
{
auto webView2_28 = m_webView.try_query<ICoreWebView2_28>();
CHECK_FEATURE_RETURN(webView2_28);
wil::com_ptr<ICoreWebView2Find> webView2find;
CHECK_FAILURE(webView2_28->get_Find(&webView2find));
auto m_env15 = m_webViewEnvironment.try_query<ICoreWebView2Environment15>();
CHECK_FEATURE_RETURN(m_env15);
CHECK_FAILURE(webView2find->Stop());
if (!findOptions)
{
findOptions = SetDefaultFindOptions();
}
BOOL shouldMatchWord;
findOptions->get_ShouldMatchWord(&shouldMatchWord);
CHECK_FAILURE(findOptions->put_ShouldMatchWord(!shouldMatchWord));
CHECK_FAILURE(webView2find->Start(
findOptions.get(), Callback<ICoreWebView2FindStartCompletedHandler>(
[this](HRESULT result) -> HRESULT { return S_OK; })
.Get()));
return true;
}
put_SuppressDefaultFindDialog
Sets this property to hide the default Find UI.
public HRESULT put_SuppressDefaultFindDialog(BOOL value)
You can use this to hide the default UI so that you can show your own custom UI or programmatically interact with the Find API while showing no Find UI. Returns TRUE if hiding the default Find UI and FALSE if using showing the default Find UI. Note: Changes to this property take effect only when Start, FindNext, or FindPrevious is called. Preferences for the session cannot be updated unless another call to the Start function on the server-side is made. Therefore, changes will not take effect until one of these functions is called.
bool AppWindow::SuppressDefaultFindDialog()
{
auto webView2_28 = m_webView.try_query<ICoreWebView2_28>();
CHECK_FEATURE_RETURN(webView2_28);
wil::com_ptr<ICoreWebView2Find> webView2find;
CHECK_FAILURE(webView2_28->get_Find(&webView2find));
auto m_env15 = m_webViewEnvironment.try_query<ICoreWebView2Environment15>();
CHECK_FEATURE_RETURN(m_env15);
CHECK_FAILURE(webView2find->Stop());
if (!findOptions)
{
findOptions = SetDefaultFindOptions();
}
BOOL suppressDefaultDialog;
findOptions->get_SuppressDefaultFindDialog(&suppressDefaultDialog);
CHECK_FAILURE(findOptions->put_SuppressDefaultFindDialog(!suppressDefaultDialog));
CHECK_FAILURE(webView2find->Stop());
CHECK_FAILURE(webView2find->Start(
findOptions.get(), Callback<ICoreWebView2FindStartCompletedHandler>(
[this](HRESULT result) -> HRESULT { return S_OK; })
.Get()));
return true;
}