Skip to content

Commit bcb312d

Browse files
authored
Update FindOnPage.md
1 parent bdcfbb5 commit bcb312d

1 file changed

Lines changed: 169 additions & 0 deletions

File tree

FindOnPage.md

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,31 @@ bool AppWindow::ConfigureAndExecuteFind(
4040
return ExecuteFindOperation(findConfiguration.get());
4141
}
4242
```
43+
```csharp
44+
bool AppWindow::ConfigureAndExecuteFind(
45+
const std::wstring& searchTerm,
46+
bool caseSensitive,
47+
bool highlightAllMatches,
48+
COREWEBVIEW2_FIND_DIRECTION direction)
49+
{
50+
// Query for the ICoreWebView2StagingEnvironment5 interface.
51+
auto webView2Environment5 = m_webViewEnvironment.try_query<ICoreWebView2StagingEnvironment5>();
52+
CHECK_FEATURE_RETURN(webView2Environment5);
53+
54+
// Create the find configuration.
55+
wil::com_ptr<ICoreWebView2StagingFindConfiguration> findConfiguration;
56+
CHECK_FAILURE(webView2Environment5->CreateFindConfiguration(&findConfiguration));
4357
58+
// Apply the find operation configurations.
59+
CHECK_FAILURE(findConfiguration->put_FindTerm(searchTerm.c_str()));
60+
CHECK_FAILURE(findConfiguration->put_IsCaseSensitive(caseSensitive));
61+
CHECK_FAILURE(findConfiguration->put_ShouldHighlightAllMatches(highlightAllMatches));
62+
CHECK_FAILURE(findConfiguration->put_FindDirection(direction));
63+
64+
// Proceed to execute the find operation with the configured settings.
65+
return ExecuteFindOperation(findConfiguration.get());
66+
}
67+
```
4468
### Start a Find Operation
4569

4670
```cpp
@@ -81,6 +105,46 @@ bool AppWindow::ExecuteFindOperation(ICoreWebView2StagingFindConfiguration* conf
81105
return SUCCEEDED(result);
82106
}
83107

108+
//! [StartFindOnPage]
109+
```
110+
```csharp
111+
//! [StartFindOnPage]
112+
bool AppWindow::ExecuteFindOperation(ICoreWebView2StagingFindConfiguration* configuration)
113+
{
114+
// Query for the ICoreWebView2Staging17 interface to access the Find feature.
115+
auto webView2staging17 = m_webView.try_query<ICoreWebView2Staging17>();
116+
CHECK_FEATURE_RETURN(webView2staging17);
117+
118+
// Get the Find interface.
119+
wil::com_ptr<ICoreWebView2StagingFind> webView2stagingfind;
120+
CHECK_FAILURE(webView2staging17->get_Find(&webView2stagingfind));
121+
122+
// Apply custom UI settings and highlight configurations.
123+
CHECK_FAILURE(webView2stagingfind->put_UseCustomUI(false)); // Assuming you want to use the default UI, adjust as necessary.
124+
CHECK_FAILURE(webView2stagingfind->put_ShouldHighlightAllMatches(true)); // This should match the passed parameter if dynamic.
125+
CHECK_FAILURE(webView2stagingfind->PassHighlightSettings());
126+
127+
// Start the find operation with the configured findConfiguration.
128+
HRESULT result = webView2stagingfind->StartFind(
129+
configuration,
130+
Callback<ICoreWebView2StagingFindOperationCompletedHandler>(
131+
[this](HRESULT result, LONG ActiveIdx, LONG MatchesCount) -> HRESULT
132+
{
133+
if (SUCCEEDED(result))
134+
{
135+
// Handle successful find operation
136+
// For example, updating UI elements to reflect the find results
137+
}
138+
else
139+
{
140+
// Handle errors appropriately
141+
}
142+
return S_OK;
143+
}).Get());
144+
145+
return SUCCEEDED(result);
146+
}
147+
84148
//! [StartFindOnPage]
85149
```
86150
### Stop an existing find operation
@@ -99,6 +163,19 @@ bool AppWindow::StopFind()
99163
}
100164
//! [StopFind]
101165
```
166+
```csharp
167+
//! [StopFind]
168+
bool AppWindow::StopFind()
169+
{
170+
auto webView2staging17 = m_webView.try_query<ICoreWebView2Staging17>();
171+
CHECK_FEATURE_RETURN(webView2staging17);
172+
wil::com_ptr<ICoreWebView2StagingFind> webView2stagingfind;
173+
CHECK_FAILURE(webView2staging17->get_Find(&webView2stagingfind));
174+
CHECK_FAILURE(webView2stagingfind->StopFind());
175+
return true;
176+
}
177+
//! [StopFind]
178+
```
102179

103180
### Retrieve the Number of Matches
104181

@@ -126,6 +203,26 @@ bool AppWindow::GetMatchCount()
126203
}
127204
//! [GetMatchCount]
128205
```
206+
```csharp
207+
//! [GetMatchCount]
208+
bool AppWindow::GetMatchCount()
209+
{
210+
auto webView2staging17 = m_webView.try_query<ICoreWebView2Staging17>();
211+
CHECK_FEATURE_RETURN(webView2staging17);
212+
wil::com_ptr<ICoreWebView2StagingFind> webView2stagingfind;
213+
CHECK_FAILURE(webView2staging17->get_Find(&webView2stagingfind));
214+
LONG matchCount;
215+
CHECK_FAILURE(webView2stagingfind->get_MatchesCount(&matchCount));
216+
217+
// Update UI or handle matchCount as you wish
218+
// For example, you could show a message box
219+
std::wstring matchCountStr = L"Match Count: " + std::to_wstring(matchCount);
220+
MessageBox(m_mainWindow, matchCountStr.c_str(), L"Find Operation", MB_OK);
221+
222+
return true;
223+
}
224+
//! [GetMatchCount]
225+
```
129226
#### Handle Match Count Changes
130227

131228
```cpp
@@ -135,6 +232,14 @@ void OnMatchCountChanged(LONG matchesCount)
135232
// Update UI elements or perform actions based on the new match count
136233
}
137234
```
235+
236+
```csharp
237+
void OnMatchCountChanged(LONG matchesCount)
238+
{
239+
// Handle match count changes
240+
// Update UI elements or perform actions based on the new match count
241+
}
242+
```
138243
### Retrieve the Index of the Active Match
139244

140245
#### Description
@@ -163,6 +268,28 @@ bool AppWindow::GetActiveMatchIndex()
163268
//! [GetActiveMatchIndex]
164269
```
165270

271+
```csharp
272+
//! [GetActiveMatchIndex]
273+
bool AppWindow::GetActiveMatchIndex()
274+
{
275+
auto webView2staging17 = m_webView.try_query<ICoreWebView2Staging17>();
276+
CHECK_FEATURE_RETURN(webView2staging17);
277+
wil::com_ptr<ICoreWebView2StagingFind> webView2stagingfind;
278+
CHECK_FAILURE(webView2staging17->get_Find(&webView2stagingfind));
279+
LONG activeMatchIndex;
280+
CHECK_FAILURE(webView2stagingfind->get_ActiveMatchIndex(&activeMatchIndex));
281+
282+
// Update UI or handle activeMatchIndex as you wish
283+
// For example, you could show a message box
284+
std::wstring activeMatchIndexStr =
285+
L"Active Match Index: " + std::to_wstring(activeMatchIndex);
286+
MessageBox(m_mainWindow, activeMatchIndexStr.c_str(), L"Find Operation", MB_OK);
287+
288+
return true;
289+
}
290+
//! [GetActiveMatchIndex]
291+
```
292+
166293
#### Handle Active Match Index Changes
167294
```cpp
168295
void OnActiveMatchIndexChanged(ICoreWebView2* sender, ICoreWebView2StagingFindActiveMatchIndexChangedEventArgs* args)
@@ -172,6 +299,14 @@ void OnActiveMatchIndexChanged(ICoreWebView2* sender, ICoreWebView2StagingFindAc
172299
}
173300
```
174301
302+
```csharp
303+
void OnActiveMatchIndexChanged(ICoreWebView2* sender, ICoreWebView2StagingFindActiveMatchIndexChangedEventArgs* args)
304+
{
305+
// Handle active match index changes
306+
// Update UI to reflect the change in the active match index
307+
}
308+
```
309+
175310
### Navigate to the Next Match
176311

177312
#### Description
@@ -196,6 +331,24 @@ bool AppWindow::FindNext()
196331
//! [FindNext]
197332
```
198333

334+
```csharp
335+
//! [FindNext]
336+
bool AppWindow::FindNext()
337+
{
338+
auto webView2staging17 = m_webView.try_query<ICoreWebView2Staging17>();
339+
CHECK_FEATURE_RETURN(webView2staging17);
340+
wil::com_ptr<ICoreWebView2StagingFind> webView2stagingfind;
341+
CHECK_FAILURE(webView2staging17->get_Find(&webView2stagingfind));
342+
343+
CHECK_FAILURE(webView2stagingfind->FindNext());
344+
CHECK_FAILURE(webView2stagingfind->remove_ActiveMatchIndexChanged(
345+
m_ActiveMatchIndexChangedEventToken));
346+
347+
return true;
348+
}
349+
//! [FindNext]
350+
```
351+
199352
### Navigate to the Previous Match
200353

201354
#### Description
@@ -218,6 +371,22 @@ bool AppWindow::FindPrevious()
218371
//! [FindPrevious]
219372
```
220373

374+
```csharp
375+
//! [FindPrevious]
376+
bool AppWindow::FindPrevious()
377+
{
378+
auto webView2staging17 = m_webView.try_query<ICoreWebView2Staging17>();
379+
CHECK_FEATURE_RETURN(webView2staging17);
380+
wil::com_ptr<ICoreWebView2StagingFind> webView2stagingfind;
381+
CHECK_FAILURE(webView2staging17->get_Find(&webView2stagingfind));
382+
383+
CHECK_FAILURE(webView2stagingfind->FindPrevious());
384+
385+
return true;
386+
}
387+
//! [FindPrevious]
388+
```
389+
221390
## API Details
222391
```csharp
223392

0 commit comments

Comments
 (0)