Skip to content

Commit 703302a

Browse files
authored
Application recovery and restart samples (#265)
* Scenarios 1 + 2 * Scenario 3 * add cpp sample * cpp samples * update readme * move to cswin32 for pinvoke * Update WinAppSDK and CsWin32 versions * Update remaining nuget packages
1 parent 449ee88 commit 703302a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+2834
-0
lines changed

Samples/AppLifecycle/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ All the constraints for packaged apps also apply to WinUI apps (because they are
7272
- Unpackaged apps: Fully usable.
7373
- Packaged apps: Fully usable.
7474

75+
### Application Recovery and Restart APIs
76+
77+
- Unpackaged apps: Fully usable.
78+
- Packaged apps: Fully usable.
79+
7580
## Related Links
7681

7782
- [Windows App SDK](https://docs.microsoft.com/windows/apps/windows-app-sdk/)
@@ -82,6 +87,8 @@ All the constraints for packaged apps also apply to WinUI apps (because they are
8287

8388
- [Power/state notifications](https://docs.microsoft.com/en-us/windows/apps/windows-app-sdk/applifecycle/applifecycle-power)
8489

90+
- [Application Recovery and Restart](https://learn.microsoft.com/en-us/windows/win32/api/_recovery/)
91+
8592

8693

8794

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!-- Copyright (c) Microsoft Corporation.
2+
Licensed under the MIT License. -->
3+
<Application
4+
x:Class="cpp_winui_packaged.App"
5+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
6+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
7+
xmlns:local="using:cpp_winui_packaged">
8+
9+
<Application.Resources>
10+
<!-- Application-specific resources -->
11+
<ResourceDictionary>
12+
<ResourceDictionary.MergedDictionaries>
13+
<!--
14+
Styles that define common aspects of the platform look and feel
15+
Required by Visual Studio project and item templates
16+
-->
17+
<ResourceDictionary Source="ms-appx:///Styles.xaml"/>
18+
</ResourceDictionary.MergedDictionaries>
19+
</ResourceDictionary>
20+
</Application.Resources>
21+
</Application>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
#include "pch.h"
5+
6+
#include "App.xaml.h"
7+
#include "MainWindow.xaml.h"
8+
9+
namespace winrt
10+
{
11+
using namespace Windows::Foundation;
12+
using namespace Microsoft::UI::Xaml;
13+
}
14+
15+
namespace winrt::cpp_winui_packaged::implementation
16+
{
17+
App::App()
18+
{
19+
InitializeComponent();
20+
21+
#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
22+
UnhandledException([](winrt::IInspectable const&, winrt::UnhandledExceptionEventArgs const& e)
23+
{
24+
if (IsDebuggerPresent())
25+
{
26+
auto errorMessage = e.Message();
27+
__debugbreak();
28+
}
29+
});
30+
#endif
31+
}
32+
33+
void App::OnLaunched(winrt::LaunchActivatedEventArgs const&)
34+
{
35+
window = winrt::make<MainWindow>();
36+
window.Activate();
37+
window.Title(L"Application Recovery and Restart");
38+
}
39+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
#pragma once
5+
#include "App.xaml.g.h"
6+
#include "pch.h"
7+
8+
namespace winrt::cpp_winui_packaged::implementation
9+
{
10+
struct App : AppT<App>
11+
{
12+
App();
13+
14+
void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&);
15+
16+
private:
17+
Microsoft::UI::Xaml::Window window{ nullptr };
18+
};
19+
}
76.3 KB
Loading
10.6 KB
Loading
2.73 KB
Loading
10.9 KB
Loading
3.06 KB
Loading

0 commit comments

Comments
 (0)