Skip to content

Commit bf9a83f

Browse files
authored
Sample code update
1. fixed space 2. Fix name of variables 3. Added GetHICon check
1 parent 2a19f7c commit bf9a83f

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

specs/GetFavicon.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,34 @@ We propose a new Webview2 event which would allow developers to access the curre
77
# Examples
88
## Win32 C++ Registering a listener for favicon changes
99
```cpp
10-
CHECK_FAILURE(m_webView->add_FaviconChanged(
11-
Callback<ICoreWebView2FaviconChangedEventHandler>(
12-
[this](ICoreWebView2* sender, IUnknown* args) -> HRESULT {
13-
14-
wil::unique_cotaskmem_string url;
15-
CHECK_FAILURE(sender->get_FaviconUri(&url));
16-
wil::com_ptr<IStream> pStream = SHCreateMemStream(nullptr, 0);
17-
18-
sender->GetFavicon(
19-
COREWEBVIEW2_FAVICON_IMAGE_FORMAT_PNG,
20-
pStream,
21-
Callback<
22-
ICoreWebView2GetFaviconCompletedHandler>(
23-
[&pStream, this](HRESULT code) -> HRESULT {
24-
Gdiplus::Bitmap* pBitmap = new Gdiplus::Bitmap(pStream);
25-
HICON icon;
26-
pBitmap->GetHICON(&icon);
27-
SendMessage(
28-
m_appWindow->GetMainWindow(), WM_SETICON, ICON_SMALL,
29-
(LPARAM)icon);
30-
return S_OK;
31-
})
32-
.Get());
10+
CHECK_FAILURE(m_webView->add_FaviconChanged(
11+
Callback<ICoreWebView2FaviconChangedEventHandler>(
12+
[this](ICoreWebView2* sender, IUnknown* args) -> HRESULT {
13+
14+
wil::com_ptr<IStream> iconStream = SHCreateMemStream(nullptr, 0);
15+
16+
sender->GetFavicon(COREWEBVIEW2_FAVICON_IMAGE_FORMAT_PNG, iconStream.get(),
17+
Callback<ICoreWebView2ExperimentalGetFaviconCompletedHandler>(
18+
[iconStream, this](HRESULT error_code) -> HRESULT
19+
{
20+
if (error_code == S_OK)
21+
{
22+
Gdiplus::Bitmap* iconBitmap =
23+
new Gdiplus::Bitmap(iconStream.get());
24+
HICON icon;
25+
if (!iconBitmap->GetHICON(&icon))
26+
{
27+
SendMessage(
28+
m_appWindow->GetMainWindow(), WM_SETICON,
29+
ICON_SMALL, (LPARAM)icon);
30+
}
31+
}
3332

3433
return S_OK;
35-
})
36-
.Get(),
37-
&m_faviconChangedToken));
34+
}).Get());
35+
36+
return S_OK;
37+
}).Get(), &m_faviconChangedToken));
3838
```
3939
## .NET / WinRT Registering a listener for favicon changes
4040
```c#

0 commit comments

Comments
 (0)