Skip to content

Commit e6c8905

Browse files
authored
Update FindOnPage.md
1 parent 52ba7d4 commit e6c8905

1 file changed

Lines changed: 58 additions & 85 deletions

File tree

FindOnPage.md

Lines changed: 58 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -115,46 +115,6 @@ async void ConfigureAndExecuteFindAsync(string searchTerm){
115115
}
116116
//! [ConfigureAndExecuteFind]
117117
```
118-
119-
120-
//! [GetMatchCount]
121-
bool AppWindow::GetMatchCount()
122-
{
123-
auto webView2staging11 = m_webView.try_query<ICoreWebView2Staging11>();
124-
CHECK_FEATURE_RETURN(webView2staging11);
125-
wil::com_ptr<ICoreWebView2StagingFind> webView2stagingfind;
126-
CHECK_FAILURE(webView2staging11->get_Find(&webView2stagingfind));
127-
LONG matchCount;
128-
CHECK_FAILURE(webView2stagingfind->get_MatchesCount(&matchCount));
129-
130-
// Update UI or handle matchCount as you wish
131-
// For example, you could show a message box
132-
std::wstring matchCountStr = L"Match Count: " + std::to_wstring(matchCount);
133-
MessageBox(m_mainWindow, matchCountStr.c_str(), L"Find Operation", MB_OK);
134-
135-
return true;
136-
}
137-
//! [GetMatchCount]
138-
139-
//! [GetActiveMatchIndex]
140-
bool AppWindow::GetActiveMatchIndex()
141-
{
142-
auto webView2staging11 = m_webView.try_query<ICoreWebView2Staging11>();
143-
CHECK_FEATURE_RETURN(webView2staging11);
144-
wil::com_ptr<ICoreWebView2StagingFind> webView2stagingfind;
145-
CHECK_FAILURE(webView2staging11->get_Find(&webView2stagingfind));
146-
LONG activeMatchIndex;
147-
CHECK_FAILURE(webView2stagingfind->get_ActiveMatchIndex(&activeMatchIndex));
148-
149-
// Update UI or handle activeMatchIndex as you wish
150-
// For example, you could show a message box
151-
std::wstring activeMatchIndexStr = L"Active Match Index: " + std::to_wstring(activeMatchIndex);
152-
MessageBox(m_mainWindow, activeMatchIndexStr.c_str(), L"Find Operation", MB_OK);
153-
154-
return true;
155-
}
156-
//! [GetActiveMatchIndex]
157-
```
158118

159119
### Retrieve the Number of Matches
160120

@@ -185,7 +145,6 @@ To retrieve the total number of matches found during a find operation within a W
185145
186146
```csharp
187147
//! [GetMatchCount]
188-
bool AppWindow::GetMatchCount()
189148
public async Task<int> GetMatchCountAsync()
190149
{
191150
var webViewFind = webView.CoreWebView2.FindController; // Assuming webView is your WebView2 control
@@ -195,30 +154,61 @@ To retrieve the total number of matches found during a find operation within a W
195154
}
196155
//! [GetMatchCount]
197156
```
198-
#### Handle Match Count Changes
157+
#### Handle Match Count Changes
199158

200-
```cpp
201-
void OnMatchCountChanged(LONG matchesCount)
159+
```cpp
160+
// Register MatchCountChanged event handler
161+
m_webView->add_MatchCountChanged(
162+
Callback<ICoreWebView2FindMatchCountChangedEventHandler>(
163+
[this](LONG matchCount) -> HRESULT
164+
{
165+
// Update custom UI
166+
wprintf(L"Match Count Changed: %ld\n", matchCount);
167+
return S_OK;
168+
}).Get(),
169+
&m_matchCountChangedToken);
170+
```
171+
172+
```csharp
173+
void MatchCountChangedSample()
174+
{
175+
_webview.MatchCountChanged += (object sender, CoreWebView2MatchCountChangedEventArgs args) =>
202176
{
203-
// Handle match count changes
204-
// Update UI elements or perform actions based on the new match count
205-
}
206-
```
207-
208-
```csharp
209-
private void OnMatchCountChanged(object sender, EventArgs e)
177+
// Update Custom UI
178+
};
179+
}
180+
```
181+
#### Handle Match Index Changes
182+
183+
```cpp
184+
// Register ActiveMatchIndexChanged event handler
185+
m_webView->add_ActiveMatchIndexChanged(
186+
Callback<ICoreWebView2FindActiveMatchIndexChangedEventHandler>(
187+
[this](LONG activeMatchIndex) -> HRESULT
188+
{
189+
// Update custom UI
190+
wprintf(L"Active Match Index Changed: %ld\n", activeMatchIndex);
191+
return S_OK;
192+
}).Get(),
193+
&m_activeMatchIndexChangedToken);
194+
```
195+
196+
```csharp
197+
void ActiveMatchIndexChangedSample()
198+
{
199+
_webview.MatchCountChanged += (object sender, CoreWebView2ActiveMatchIndexChangedEventArgs args) =>
210200
{
211-
// Assuming EventArgs or a derived type carries the new match count
212-
MessageBox.Show($"Match count changed. New count: {e.MatchCount}", "Find Operation");
213-
}
214-
```
215-
### Retrieve the Index of the Active Match
201+
// Update Custom UI
202+
};
203+
}
204+
```
205+
### Retrieve the Index of the Active Match
216206

217-
#### Description
218-
Developers can retrieve the index of the currently active match within a WebView2 control using the `GetActiveMatchIndex` method.
207+
#### Description
208+
Developers can retrieve the index of the currently active match within a WebView2 control using the `GetActiveMatchIndex` method.
219209

220210

221-
```cpp
211+
```cpp
222212
//! [GetActiveMatchIndex]
223213
bool AppWindow::GetActiveMatchIndex()
224214
{
@@ -238,36 +228,19 @@ To retrieve the total number of matches found during a find operation within a W
238228
return true;
239229
}
240230
//! [GetActiveMatchIndex]
241-
```
242-
243-
```csharp
244-
//! [GetActiveMatchIndex]
245-
public async Task<int> GetActiveMatchIndexAsync()
246-
{
247-
var webViewFind = webView.CoreWebView2.FindController; // Assuming webView is your WebView2 control
248-
var activeMatchIndex = await webViewFind.GetActiveMatchIndexAsync();
249-
MessageBox.Show($"Active Match Index: {activeMatchIndex}", "Find Operation", MessageBoxButton.OK);
250-
return activeMatchIndex;
251-
}
252-
253-
//! [GetActiveMatchIndex]
254-
```
255-
256-
#### Handle Active Match Index Changes
257-
```cpp
258-
void OnActiveMatchIndexChanged(ICoreWebView2* sender, ICoreWebView2FindActiveMatchIndexChangedEventArgs* args)
259-
{
260-
// Handle active match index changes
261-
// Update UI to reflect the change in the active match index
262-
}
263231
```
264-
232+
265233
```csharp
266-
private void OnActiveMatchIndexChanged(object sender, EventArgs e)
234+
//! [GetActiveMatchIndex]
235+
public async Task<int> GetActiveMatchIndexAsync()
267236
{
268-
// Assuming EventArgs or a derived type carries the new active match index
269-
MessageBox.Show($"Active match index changed. New index: {e.ActiveMatchIndex}", "Find Operation");
237+
var webViewFind = webView.CoreWebView2.FindController; // Assuming webView is your WebView2 control
238+
var activeMatchIndex = await webViewFind.GetActiveMatchIndexAsync();
239+
MessageBox.Show($"Active Match Index: {activeMatchIndex}", "Find Operation", MessageBoxButton.OK);
240+
return activeMatchIndex;
270241
}
242+
243+
//! [GetActiveMatchIndex]
271244
```
272245

273246

0 commit comments

Comments
 (0)