Skip to content

Commit 0275700

Browse files
authored
Update SystemCursorId.md
1 parent 0ad0113 commit 0275700

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

specs/SystemCursorId.md

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,42 @@ where there may be custom cursors.
3434
# Examples
3535

3636
```cpp
37-
CHECK_FAILURE(m_compositionController->add_CursorChanged(
38-
Callback<ICoreWebView2CursorChangedEventHandler>(
39-
[this](ICoreWebView2CompositionController* sender, IUnknown* args)
40-
-> HRESULT {
41-
HRESULT hr = S_OK;
37+
// Handler for WM_SETCURSOR window message.
38+
bool OnSetCursor()
39+
{
40+
POINT point;
41+
if (m_compositionController && GetCursorPos(&point))
42+
{
43+
// Calculate if the point lies in the WebView visual for composition hosting
44+
// as it may not cover the whole HWND it's under.
45+
if (PtInRect(&m_webViewBounds, point))
46+
{
4247
HCURSOR cursor;
4348
UINT32 cursorId;
4449
wil::com_ptr<ICoreWebView2CompositionController2> compositionController2 =
45-
sender.query<ICoreWebView2CompositionController2>();
50+
m_compositionController.query<ICoreWebView2CompositionController2>();
4651
CHECK_FAILURE(compositionController2->get_SystemCursorId(&cursorId));
47-
if (cursorId != 0)
52+
cursor = ::LoadCursor(nullptr, MAKEINTRESOURCE(cursorId));
53+
54+
if (cursor)
4855
{
49-
cursor = ::LoadCursor(nullptr, MAKEINTRESOURCE(cursorId));
50-
if (cursor == nullptr)
51-
{
52-
hr = HRESULT_FROM_WIN32(GetLastError());
53-
}
54-
55-
if (SUCCEEDED(hr))
56-
{
57-
SetClassLongPtr(
58-
m_appWindow->GetMainWindow() /* HWND */, GCLP_HCURSOR, (LONG_PTR)cursor);
59-
}
56+
::SetCursor(cursor);
57+
return true;
6058
}
61-
return hr;
59+
}
60+
}
61+
return false;
62+
}
63+
64+
CHECK_FAILURE(m_compositionController->add_CursorChanged(
65+
Callback<ICoreWebView2CursorChangedEventHandler>(
66+
[this](ICoreWebView2CompositionController* sender, IUnknown* args)
67+
-> HRESULT {
68+
// No need to do hit testing here as the WM_SETCURSOR handler will have
69+
// to calculate if the point is within the WebView anyways.
70+
SendMessage(m_appWindow->GetMainWindow(), WM_SETCURSOR,
71+
(WPARAM)m_appWindow->GetMainWindow(), MAKELPARAM(HTCLIENT, WM_MOUSEMOVE));
72+
return S_OK;
6273
})
6374
.Get(),
6475
&m_cursorChangedToken));

0 commit comments

Comments
 (0)