【问题标题】:How Do I Correctly Hide Mouse Cursor On App Start?如何在应用启动时正确隐藏鼠标光标?
【发布时间】:2021-10-19 05:20:52
【问题描述】:

我想在我的 DX12 UWP C++/CX 应用程序中隐藏鼠标光标:

CoreWindow::GetForCurrentThread()->PointerCursor = nullptr;

这会在我使用触摸板/鼠标移动光标后隐藏光标。在此之前它不会隐藏光标。之后我还尝试了其他设置光标位置的建议:

CoreWindow::GetForCurrentThread()->PointerPosition = Point(0, 0);

这没有效果。

我看过的所有地方都说将指针设置为 null 可以解决问题,但事实并非如此。我错过了什么?这感觉像是一个错误。

提前致谢。

编辑:

尝试了以下方法: SetWindow OnActivated Run

编辑 2:

auto applicationView = Windows::UI::ViewManagement::ApplicationView::GetForCurrentView();
while (!applicationView->TryEnterFullScreenMode()) {
    Sleep(10);
}

auto coreWindow = CoreWindow::GetForCurrentThread();
coreWindow->PointerPosition = Point(coreWindow->Bounds.Width / 2, coreWindow->Bounds.Height / 2);
coreWindow->PointerCursor = nullptr;

uiThreadDispatcher->RunAsync(Windows::UI::Core::CoreDispatcherPriority::Normal, ref new Windows::UI::Core::DispatchedHandler([]() {
    auto coreWindow = CoreWindow::GetForCurrentThread();
    coreWindow->PointerPosition = Point(coreWindow->Bounds.Width / 2, coreWindow->Bounds.Height / 2);
    coreWindow->PointerCursor = nullptr;
}));

已经发生了,光标在应用启动时偶尔消失,但这是不可重复的。无论何时何地调用这些方法,唯一保证让光标消失的方法是当我用鼠标或触摸板移动光标时。

【问题讨论】:

    标签: uwp c++-cx directx-12


    【解决方案1】:

    这会在我使用触摸板/鼠标移动光标后隐藏它。

    设置当前PointerCursor为null只隐藏当前核心窗口的光标,不会隐藏整个系统的PointerCursor,在这种情况下,你可以全屏启动应用程序,光标会自动隐藏。您可以尝试在核心窗口中心设置PointerPosition,然后将PointerCursor 设置为null,这样可以确保光标在窗口中。请注意上面的方法需要在ui线程中调用。

    【讨论】:

    • 感谢您的回复!抱歉耽搁了,正好在放假。我使用 TryEnterFullScreenMode 方法,指针仍然存在。我还尝试使用 CoreWindow::GetForCurrentThread()->Dispatcher 将 pointerCursor 设置为 null。在使用鼠标或触摸板之前,这再次不起作用。
    • 您是否尝试过根据上述setps设置PointerPosition?
    • 我已经用代码更新了原始问题,展示了我在做什么。谢谢!
    • 请将 PointerCursor 设置为 null 然后将 PointerPosition 移动到窗口的中心
    • 仍然不起作用...它只是偶尔隐藏它。无论我是从 VS 开始还是从 UWP App 本身开始,唯一可靠的方法就是移动鼠标...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-01
    • 2011-05-24
    • 2022-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    相关资源
    最近更新 更多