@@ -4,9 +4,9 @@ When an app is using composition hosting to host WebView, the current cursor
44image cannot be determined easily by the hosting application. For example, if
55the cursor over the WebView is also over a textbox inside of the WebView, the
66cursor should usually be IDC_IBEAM. And by default, the cursor is IDC_ARROW.
7- Currently, we return the what the cursor should be as an HCURSOR object (After
8- calling LoadCursor on those IDC values). The hosting application can then use
9- the HCURSOR object to change the current cursor to the correct image.
7+ Currently, the ` ICoreWebView2CompositionController.Cursor ` property returns what
8+ the cursor should be as an HCURSOR object, which the hosting application can
9+ then use the to change the current cursor to the correct image.
1010
1111However, Office already has a well established way of using cursors internally
1212by using IDC_ * values and there is no easy way to convert the HCURSOR object we
@@ -35,25 +35,28 @@ where there may be custom cursors.
3535
3636``` cpp
3737CHECK_FAILURE (m_compositionController->add_CursorChanged(
38- Callback<ICoreWebView2ExperimentalCursorChangedEventHandler >(
39- [ this] (ICoreWebView2ExperimentalCompositionController * sender, IUnknown* args)
38+ Callback<ICoreWebView2CursorChangedEventHandler >(
39+ [ this] (ICoreWebView2CompositionController * sender, IUnknown* args)
4040 -> HRESULT {
4141 HRESULT hr = S_OK;
4242 HCURSOR cursor;
4343 UINT32 cursorId;
44- wil::com_ptr<ICoreWebView2ExperimentalCompositionController2 > compositionController2 =
45- m_controller .query<ICoreWebView2ExperimentalCompositionController2 >();
44+ wil::com_ptr<ICoreWebView2CompositionController2 > compositionController2 =
45+ sender .query<ICoreWebView2CompositionController2 >();
4646 CHECK_FAILURE(compositionController2->get_SystemCursorId(&cursorId));
47- cursor = ::LoadCursor(nullptr, MAKEINTRESOURCE(cursorId));
48- if (cursor == nullptr)
47+ if (cursorId != 0)
4948 {
50- hr = HRESULT_FROM_WIN32(GetLastError());
51- }
52-
53- if (SUCCEEDED(hr))
54- {
55- SetClassLongPtr(
56- m_appWindow->GetMainWindow() /* HWND */, GCLP_HCURSOR, (LONG_PTR)cursor);
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+ }
5760 }
5861 return hr;
5962 })
@@ -82,10 +85,13 @@ interface ICoreWebView2CompositionController2 : ICoreWebView2CompositionControll
8285 /// Otherwise, if custom CSS cursors are being used, this will return 0.
8386 /// To actually use systemCursorId in LoadCursor or LoadImage,
8487 /// MAKEINTRESOURCE must be called on it first.
88+ /// If possible, use the Cursor property rather than the SystemCursorId
89+ /// property because the Cursor property can express custom CSS cursors.
8590 ///
8691 /// \snippet ViewComponent.cpp SystemCursorId
8792 [ propget] HRESULT SystemCursorId([ out, retval] UINT32* systemCursorId);
8893}
94+ ```
8995
9096``` c#
9197namespace Microsoft .Web .WebView2 .Core
@@ -110,9 +116,12 @@ namespace Microsoft.Web.WebView2.Core
110116 // Otherwise, if custom CSS cursors are being used, this will return 0.
111117 // To create a Cursor object, create an IntPtr from the returned uint to
112118 // pass into the constructor
119+ // If possible, use the Cursor property rather than the SystemCursorId
120+ // property because the Cursor property can express custom CSS cursors.
113121 public Uint32 SystemCursorId { get ; }
114122 }
115123}
124+ ```
116125
117126# Appendix
118127
0 commit comments