@@ -34,31 +34,42 @@ where there may be custom cursors.
34
34
# Examples
35
35
36
36
``` 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
+ {
42
47
HCURSOR cursor;
43
48
UINT32 cursorId;
44
49
wil::com_ptr<ICoreWebView2CompositionController2> compositionController2 =
45
- sender .query<ICoreWebView2CompositionController2 >();
50
+ m_compositionController .query<ICoreWebView2CompositionController2>();
46
51
CHECK_FAILURE (compositionController2->get_SystemCursorId(&cursorId));
47
- if (cursorId != 0)
52
+ cursor = ::LoadCursor(nullptr, MAKEINTRESOURCE(cursorId));
53
+
54
+ if (cursor)
48
55
{
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;
60
58
}
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;
62
73
})
63
74
.Get(),
64
75
&m_cursorChangedToken));
0 commit comments