简体   繁体   English

如何获取 WinUI 3 桌面应用程序的屏幕边界?

[英]How to get screen bounds for WinUI 3 Desktop application?

I need to achieve below requirements in WinUI 3 Desktop applications.我需要在 WinUI 3 桌面应用程序中实现以下要求。

  1. How to get screen bounds?如何获得屏幕边界?
  2. How to change windows cursor type in runtime?如何在运行时更改 windows cursor 类型?

I already did this in WinUI UWP applications.我已经在 WinUI UWP 应用程序中这样做了。

For Screen bounds,对于屏幕边界,

var visibleBounds = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().VisibleBounds;
var scaleFactor = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
Size screenSize = new Size((visibleBounds.Width * scaleFactor), (visibleBounds.Height * scaleFactor));

For Cursor:对于 Cursor:

Window.Current.CoreWindow.PointerCursor = new CoreCursor(CoreCursorType.SizeNorthwestSoutheast, 0);

Anyone please suggest how to achieve same requirement in WinUI Desktop applications?任何人请建议如何在 WinUI 桌面应用程序中实现相同的要求?

I've added the following to App.xaml.cs:我在 App.xaml.cs 中添加了以下内容:

private static MainWindow m_window;

public static MainWindow MainWindow { get { return m_window; } }

protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs e)
{  
   m_window = new MainWindow();        
      
   m_window.Activate();
}      

And when I need bounds anywhere, I can use MainWindow.Bounds .当我在任何地方需要边界时,我可以使用MainWindow.Bounds

Regarding cursor, you need ProtectedCursor关于 cursor,你需要ProtectedCursor

this.ProtectedCursor = InputSystemCursor.Create(InputSystemCursorShape.Arrow);

Only thing it is protected, so you need to use it from right class.只有它受到保护,所以您需要从正确的 class 使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# WinUI 3 桌面应用程序。 如何设置相关面板或页面的背景图片 - C# WinUI 3 desktop application. How to set background image of relative panel or page 如何在托管环境中部署 WinUI 3 桌面应用程序? 有人成功过吗? - How do I deploy a WinUI 3 desktop application in a managed environment? Has anyone done it successfully? 如何从桌面颤振应用程序中删除标题栏? 始终让应用程序处于全屏模式 - How to remove the title bar from the desktop flutter application? always leave the application in full screen mode 如何在UWP中记录桌面屏幕 - How to record Desktop screen in UWP 如何使用Twitterizer for Desktop Application获取六位数的密码 - How to get six digit pin number using Twitterizer for Desktop Application 桌面应用程序如何从网站获取信息? - How does a desktop application get information back from a website? 如何更改桌面屏幕分辨率 - how to change desktop screen resolution 我想制作一个桌面应用程序来查看 Omegle 用户出现在我的屏幕上的位置怎么办? - I want to make a desktop application to see the location of Omegle user's appearing on my screen how to do? UWP/WinUI 桌面应用程序访问 Azure Key Vault 机密 - UWP/WinUI desktop app access to Azure Key Vault secrets 如何获取桌面位置? - How to get Desktop location?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM