如何以编程方式退出或关闭 UWP C++应用?
How to exit or close an UWP C++ app programmatically?
我想在我的应用程序中添加"退出"按钮。
如果我写这样的东西:
void LibraryUWP::MainPage::ExitEvent(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Application::Exit;
}
我有一个错误:
1>...\mainpage.xaml.cpp(32): 错误 C3867: 'Windows::UI::Xaml::Application::Exit':非标准语法;使用"&"创建指向成员的指针
如果我跑
void LibraryUWP::MainPage::ExitEvent(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Application::Exit();
}
我有:
1>...\mainpage.xaml.cpp(32):错误 C2352:"Windows::UI::Xaml::应用程序::退出":非法调用非静态成员函数
如果我运行这个:
void LibraryUWP::MainPage::ExitEvent(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Application::Current::Exit();
}
我有一个错误:
1>...\mainpage.xaml.cpp(32):错误 C2039:"退出":不是"Windows::UI::Xaml::应用程序::当前">
的成员1>...\mainpage.xaml.cpp(32):错误 C3861:"退出":找不到标识符
我知道,第一个和第二个变体不起作用。但是第三个呢?还是别的什么?
MS Visual Studio 2015 Update 3. 对于 Windows 10.10240 平台
附言如果我在没有最后一个护腕的情况下运行第三个变体,我有同样的错误,告诉我,我们没有这样的方法。
将代码更改为以下内容:
void MyApp::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Application::Current->Exit();
}
谢谢
Stefan Wick - Windows Developer Platform
如果您的应用只有一个窗口,您可以像这样退出应用:
void UWPcpp::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
ApplicationView::GetForCurrentView()->TryConsolidateAsync();
}
这会暂停您的应用程序,而不是突然退出它,这也是重新启动应用程序时的唯一方法,它将具有与以前相同的大小和位置。
相关文章:
- 将图像添加到资源文件夹UWP C++
- 如何使用 OpenCV 解码在两个 UWP 应用之间发送的图像字节?
- 尝试从C++访问 UWP 的电子邮件邮件类会导致"REGDB_E_CLASSNOTREG类未注册"错误
- 将 dll 文件注入 UWP
- 如何在 Win32 C++控制台应用程序中调用 UWP 类库
- 确定C++应用程序是否作为具有旧版支持的 UWP 应用运行
- UWP 应用未通过认证过程
- 使用 c++/WinRT Direct3D UWP Game DR 模板 Direct X11 的错误消息
- CMake 在为 UWP 生成时无法获取 VCTargetsPath 的值
- C++ with XAML and UWP
- 我可以用C++/WinRT编写一个DLL,供windows桌面应用程序(而不是UWP)或Unity插件使用吗
- 背景任务UWP C++只触发一次
- 如何创建一个windows visual Studio C++/CX NOT UWP
- UWP 在 InitializeComponent() [C++] 时崩溃
- Visual Studio 中从 .Net 到 UWP C++的 SerialPort 类等效于什么?
- 如何从 c++ winrt UWP 应用中的代码将文本添加到富文本块
- 如何在 UWP C++/CX 中对象的成员函数中使用 std::thread
- C++/CX 如何从 IRandomAccessStream^ 转换为字节并返回.(UWP)
- 在 UWP 视觉工作室项目中包括外部文件夹
- UWP:在树节点中将文本设置为粗体