Skip to content

Commit a74ffa9

Browse files
authored
Created a flow for using custom dialog and default dialog within startfind
1 parent b3b07ae commit a74ffa9

1 file changed

Lines changed: 82 additions & 14 deletions

File tree

FindOnPage.md

Lines changed: 82 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ This method allows setting the search term and find parameters via the
1919
webview environment. Starting another with the same configuration will adjust
2020
the active match index based on the selected Find Direction.
2121
#### Create/Specify a Find Configuration
22+
2223
```cpp
2324

24-
//! [ConfigureAndExecuteFind]
25-
bool AppWindow::ConfigureAndExecuteFind(const std::wstring& searchTerm)
25+
//! [InitializeFindConfiguration]
26+
wil::com_ptr<ICoreWebView2FindConfiguration> AppWindow::InitializeFindConfiguration(const std::wstring& searchTerm)
2627
{
2728
// Query for the ICoreWebView2Environment5 interface.
2829
auto webView2Environment5 = m_webViewEnvironment.try_query<ICoreWebView2Environment5>();
@@ -44,35 +45,102 @@ bool AppWindow::ConfigureAndExecuteFind(const std::wstring& searchTerm)
4445
wil::com_ptr<ICoreWebView2Find> webView2Find;
4546
CHECK_FAILURE(webView2_17->get_Find(&webView2find));
4647

47-
// Determine if custom UI will be usedsettings and highlight configurations.
48+
return findConfiguration;
49+
}
50+
//! [InitializeFindConfiguration]
51+
```
52+
53+
```cpp
54+
//! [ExecuteFindWithDefaultUI]
55+
bool AppWindow::ConfigureAndExecuteFind(const std::wstring& searchTerm)
56+
{
57+
auto findConfiguration = InitializeFindConfiguration(searchTerm);
58+
if (!findConfiguration)
59+
{
60+
return false;
61+
}
62+
// Query for the ICoreWebView2_17 interface to access the Find feature.
63+
auto webView2_17 = m_webView.try_query<ICoreWebView2_17>();
64+
CHECK_FEATURE_RETURN(webView2_17);
65+
66+
// Get the Find interface.
67+
wil::com_ptr<ICoreWebView2Find> webView2Find;
68+
CHECK_FAILURE(webView2_17->get_Find(&webView2Find));
4869
4970
// Assuming you want to use the default UI, adjust as necessary.
50-
CHECK_FAILURE(webView2find->put_UseCustomUI(false));
71+
CHECK_FAILURE(webView2Find->put_UseCustomUI(false));
72+
CHECK_FAILURE(webView2Find->put_ShouldHighlightAllMatches(true));
73+
74+
// Start the find operation with a callback for completion.
75+
CHECK_FAILURE(webView2Find->StartFind(
76+
findConfiguration.get(),
77+
Callback<ICoreWebView2FindOperationCompletedHandler>(
78+
[this](HRESULT result, BOOL status) -> HRESULT
79+
{
80+
if (SUCCEEDED(result))
81+
{
82+
// Optionally update UI elements here upon successful find operation.
83+
}
84+
else
85+
{
86+
// Handle errors.
87+
}
88+
return S_OK;
89+
}).Get()));
90+
91+
// End user interaction is handled via UI.
92+
return true;
93+
}
94+
//! [ExecuteFindWithDefaultUI]
95+
```
96+
97+
```cpp
98+
//! [ExecuteFindWithCustomUI]
99+
bool AppWindow::ExecuteFindWithCustomUI(const std::wstring& searchTerm)
100+
{
101+
auto findConfiguration = InitializeFindConfiguration(searchTerm);
102+
if (!findConfiguration)
103+
{
104+
return false;
105+
}
106+
// Query for the ICoreWebView2_17 interface to access the Find feature.
107+
auto webView2_17 = m_webView.try_query<ICoreWebView2_17>();
108+
CHECK_FEATURE_RETURN(webView2_17);
109+
110+
// Get the Find interface.
111+
wil::com_ptr<ICoreWebView2Find> webView2Find;
112+
CHECK_FAILURE(webView2_17->get_Find(&webView2Find));
113+
114+
// Opt for using a custom UI for the find operation.
115+
CHECK_FAILURE(webView2find->put_UseCustomUI(true));
51116
CHECK_FAILURE(webView2find->put_ShouldHighlightAllMatches(true));
52117

53-
// Start the find operation
118+
// Start the find operation with callback for completion.
54119
CHECK_FAILURE(webView2find->StartFind(
55120
findConfiguration.get(),
56121
Callback<ICoreWebView2FindOperationCompletedHandler>(
57122
[this](HRESULT result, BOOL status) -> HRESULT
58123
{
59-
if (SUCCEEDED(result))
124+
if (SUCCEEDED(result) && status)
60125
{
61-
// For example, you could update UI elements here
126+
// Optionally update UI elements here upon successful find operation.
62127
}
63128
else
64129
{
65-
// Handle errors
130+
// Handle errors or unsuccessful search.
66131
}
67132
return S_OK;
68-
})
69-
.Get()));
70-
// End user will now be able to interact with default Find UX
71-
// using the built in navigation buttons and Find filters to
72-
// customize their search.
133+
}).Get()));
134+
135+
// Note: In this example, navigation through find results (FindNext/FindPrevious)
136+
// and stopping the find operation (StopFind) are assumed to be handled by
137+
// custom UI elements and user interaction, not directly in code here.
138+
// User could then connect functions such as FindNext, FindPrevious, and StopFind
139+
// to corresponding custom UI elements.
140+
73141
return true;
74142
}
75-
//! [ConfigureAndExecuteFind]
143+
//! [ExecuteFindWithCustomUI]
76144
```
77145
```csharp
78146
//! [ConfigureAndExecuteFind]

0 commit comments

Comments
 (0)