如何以编程方式退出或关闭 UWP C++ 应用程序?
How to exit or close an UWP C++ app programmatically?
我想在我的应用程序中添加 "Exit" 按钮。
如果我这样写:
void LibraryUWP::MainPage::ExitEvent(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Application::Exit;
}
我有一个错误:
1>...\mainpage.xaml.cpp(32): error C3867: 'Windows::UI::Xaml::Application::Exit': non-standard syntax; use '&' to create a pointer to member
如果我运行
void LibraryUWP::MainPage::ExitEvent(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Application::Exit();
}
我有:
1>...\mainpage.xaml.cpp(32): error C2352: 'Windows::UI::Xaml::Application::Exit': illegal call of non-static member function
如果我 运行 这个:
void LibraryUWP::MainPage::ExitEvent(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Application::Current::Exit();
}
我有一个错误:
1>...\mainpage.xaml.cpp(32): error C2039: 'Exit': is not a member of 'Windows::UI::Xaml::Application::Current'
1>...\mainpage.xaml.cpp(32): error C3861: 'Exit': identifier not found
我明白,第一个和第二个变体无法工作。但是第三个呢?或者别的什么?
MS Visual Studio 2015 更新 3。
对于 Windows 10.10240 平台
P.S。如果我 运行 没有最后一个护腕的第三个变体,我有同样的错误,这告诉我,我们没有这样的方法。
将您的代码更改为:
void MyApp::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Application::Current->Exit();
}
谢谢,
Stefan Wick - Windows 开发者平台
如果你的应用只有一个window,你可以这样退出应用:
void UWPcpp::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
ApplicationView::GetForCurrentView()->TryConsolidateAsync();
}
这会暂停您的应用程序而不是突然退出它,这也是您重新启动应用程序时它的大小和位置与之前相同的唯一方法。
我想在我的应用程序中添加 "Exit" 按钮。
如果我这样写:
void LibraryUWP::MainPage::ExitEvent(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Application::Exit;
}
我有一个错误:
1>...\mainpage.xaml.cpp(32): error C3867: 'Windows::UI::Xaml::Application::Exit': non-standard syntax; use '&' to create a pointer to member
如果我运行
void LibraryUWP::MainPage::ExitEvent(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Application::Exit();
}
我有:
1>...\mainpage.xaml.cpp(32): error C2352: 'Windows::UI::Xaml::Application::Exit': illegal call of non-static member function
如果我 运行 这个:
void LibraryUWP::MainPage::ExitEvent(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Application::Current::Exit();
}
我有一个错误:
1>...\mainpage.xaml.cpp(32): error C2039: 'Exit': is not a member of 'Windows::UI::Xaml::Application::Current'
1>...\mainpage.xaml.cpp(32): error C3861: 'Exit': identifier not found
我明白,第一个和第二个变体无法工作。但是第三个呢?或者别的什么?
MS Visual Studio 2015 更新 3。 对于 Windows 10.10240 平台
P.S。如果我 运行 没有最后一个护腕的第三个变体,我有同样的错误,这告诉我,我们没有这样的方法。
将您的代码更改为:
void MyApp::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
Application::Current->Exit();
}
谢谢,
Stefan Wick - Windows 开发者平台
如果你的应用只有一个window,你可以这样退出应用:
void UWPcpp::MainPage::Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
ApplicationView::GetForCurrentView()->TryConsolidateAsync();
}
这会暂停您的应用程序而不是突然退出它,这也是您重新启动应用程序时它的大小和位置与之前相同的唯一方法。