从CoreIndependentInputSource更改指针光标的问题 [英] Problems with changing pointer cursor from CoreIndependentInputSource

查看:107
本文介绍了从CoreIndependentInputSource更改指针光标的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我在DirectX应用程序中实现用户指针操作时遇到问题.

在示例应用输入中,事件以这种方式处理

Hi all!

I faced a problem with implementing user pointer actions in my DirectX application.

In sample app input events are processed  in this way

	auto workItemHandler = ref new WorkItemHandler([this] (IAsyncAction ^)
	{
		// The CoreIndependentInputSource will raise pointer events for the specified device types on whichever thread it's created on.
		m_coreInput = swapChainPanel->CreateCoreIndependentInputSource(
			Windows::UI::Core::CoreInputDeviceTypes::Mouse |
			Windows::UI::Core::CoreInputDeviceTypes::Touch |
			Windows::UI::Core::CoreInputDeviceTypes::Pen
			);

		// Register for pointer events, which will be raised on the background thread.
		m_coreInput->PointerPressed += ref new TypedEventHandler<Object^, PointerEventArgs^>(this, &DirectXPage::OnPointerPressed);
		m_coreInput->PointerMoved += ref new TypedEventHandler<Object^, PointerEventArgs^>(this, &DirectXPage::OnPointerMoved);
		m_coreInput->PointerReleased += ref new TypedEventHandler<Object^, PointerEventArgs^>(this, &DirectXPage::OnPointerReleased);

		// Begin processing input messages as they're delivered.
		m_coreInput->Dispatcher->ProcessEvents(CoreProcessEventsOption::ProcessUntilQuit);
	});

然后 workItemHandler 在高优先级的后台线程上运行,并且所有事件,例如指针按下 PointerMoved 在触发时将在同一线程中处理.现在,我需要更改指针光标,例如在我的 PointerPressed 事件处理程序.因此,我以这种方式修改了标准的样本项目:

Then workItemHandler runs on a high priority background thread, and all events, such PointerPressed and PointerMoved will process in the same thread if they fire. Now, i need to change pointer cursor, for example in my PointerPressed event handler. So i modified standart sample project in this way:

void DirectXPage::OnPointerPressed(Object^ sender, PointerEventArgs^ e)
{
        //change pointer cursor on press
	this->m_coreInput->PointerCursor = ref new Windows::UI::Core::CoreCursor(Windows::UI::Core::CoreCursorType::Hand, 1u);
	m_main->StartTracking();
}

综上所述,此代码以一种奇怪的方式工作.此刻,当我按下鼠标按钮时,它什么也没有改变.但是在此之后,如果我将鼠标移到任何XAML元素上,则再次在我的swapChain cursorType上将更改为CoreCursorType :: Hand.
从coreInput调度程序或从UI线程在CoreWindow中设置新的游标会获得相同的结果.

如果有人告诉我我做错了,我将不胜感激.
您可以通过在VisualStudio中创建新的DirectX11和XAML通用应用程序并更改DirectXPage :: OnPointerPressed;来尝试此代码.

To sum up, this code works in a strange way. In the moment, when i press my mouse button, it changes nothing. But after this, if i move mouse over any XAML element, then again over my swapChain cursorType will change to CoreCursorType::Hand.
Setting new cursor from coreInput dispatcher, or in CoreWindow from UI thread gain same results.

I will be grateful, if someone tells to me, what i'm doing wrong.
You can try this code by creating new DirectX11 and XAML universal app in your VisualStudio and changing DirectXPage::OnPointerPressed;

推荐答案

您好

Hello Скляров Вячеслав

似乎DirectX有一个专门的论坛来解决此问题.也许将您的案子转移到更好的地方. https://social.msdn.microsoft.com/Forums/vstudio/zh-CN/home?forum=vsga 而我会为您完成此操作.

It seems DirectX has a specific forum for this issue. Maybe move your case to there is better. https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vsga And I will do this for you.

我们可以知道您如何编写OnPointerMoved事件处理程序吗?

Can we know how you write your OnPointerMoved event handler?

>>此刻,当我按下鼠标按钮时,它什么都没有改变.

>>In the moment, when i press my mouse button, it changes nothing.

您在哪里按下鼠标?您页面上的任何地方?

Where did you pressed your mouse? Any place on your page?

最诚挚的问候,

巴里


这篇关于从CoreIndependentInputSource更改指针光标的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆