覆盖 Windows 10 通用应用程序 UWP 上的关闭框

2022-01-15 00:00:00 windows-10 c++ uwp universal

我试图通过单击应用程序窗口上的关闭框来防止应用程序被关闭.例如,有一个带有未保存更改的文本编辑器,在按下关闭框时,我首先会显示您要在退出前保存更改吗?"

I'm trying to prevent the app from being closed by clicking the Close box on the App Window. For example, having a text editor with unsaved changes, upon pressing Close Box, I would first display, "Do you want to save changes before exiting?"

如何检测想要关闭的应用并防止这种情况发生?

How can I detect app wanting to close and prevent that from happening?

我正在使用 C++,这需要用于 Windows 10 通用应用程序 UWP.我已经知道如何为 Win32 做到这一点.

I'm using C++, and this needs to be for Windows 10 Universal Apps UWP. I already know how to do this for Win32.

推荐答案

评论正确.常规的商店应用目前无法做到这一点.

The comments are correct. There is currently no way for a regular Store app to do this.

但是,在 Creators Update(和相应的 SDK)中,我们包含了一个预览 API,您现在可以查看该功能:

However, with the Creators Update (and corresponding SDK) we have included a preview API that you can now check out for this functionality:

Windows.UI.Core.Preview.SystemNavigationManagerPreview 类提供了一个应用可以标记为已处理的 CloseRequested 事件.为了使活动正常运行,应用程序需要声明受限的confirmAppClose"功能:https://docs.microsoft.com/en-us/windows/uwp/packaging/app-capability-declarations

The Windows.UI.Core.Preview.SystemNavigationManagerPreview class provides a CloseRequested event that an app can mark as handled. For the event to work the app will need to declare the restricted 'confirmAppClose' capability per: https://docs.microsoft.com/en-us/windows/uwp/packaging/app-capability-declarations

请让我们知道您的反馈.

Please let us know your feedback.

谢谢,Stefan Wick - Windows 开发者平台

Thanks, Stefan Wick - Windows Developer Platform

相关文章