| 1 |
/*** |
| 2 |
* Copyright (C) Microsoft. All rights reserved. |
| 3 |
* Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. |
| 4 |
****/ |
| 5 |
|
| 6 |
#include "pch.h" |
| 7 |
|
| 8 |
#include "MainPage.xaml.h" |
| 9 |
|
| 10 |
using namespace WindowsLiveAuth; |
| 11 |
|
| 12 |
using namespace Platform; |
| 13 |
using namespace Windows::ApplicationModel; |
| 14 |
using namespace Windows::ApplicationModel::Activation; |
| 15 |
using namespace Windows::Foundation; |
| 16 |
using namespace Windows::Foundation::Collections; |
| 17 |
using namespace Windows::UI::Xaml; |
| 18 |
using namespace Windows::UI::Xaml::Controls; |
| 19 |
using namespace Windows::UI::Xaml::Controls::Primitives; |
| 20 |
using namespace Windows::UI::Xaml::Data; |
| 21 |
using namespace Windows::UI::Xaml::Input; |
| 22 |
using namespace Windows::UI::Xaml::Interop; |
| 23 |
using namespace Windows::UI::Xaml::Media; |
| 24 |
using namespace Windows::UI::Xaml::Navigation; |
| 25 |
|
| 26 |
// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=234227 |
| 27 |
|
| 28 |
/// <summary> |
| 29 |
/// Initializes the singleton application object. This is the first line of authored code |
| 30 |
/// executed, and as such is the logical equivalent of main() or WinMain(). |
| 31 |
/// </summary> |
| 32 |
App::App() |
| 33 |
{ |
| 34 |
InitializeComponent(); |
| 35 |
Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending); |
| 36 |
} |
| 37 |
|
| 38 |
/// <summary> |
| 39 |
/// Invoked when the application is launched normally by the end user. Other entry points |
| 40 |
/// will be used when the application is launched to open a specific file, to display |
| 41 |
/// search results, and so forth. |
| 42 |
/// </summary> |
| 43 |
/// <param name="args">Details about the launch request and process.</param> |
| 44 |
void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs ^ args) |
| 45 |
{ |
| 46 |
auto rootFrame = dynamic_cast<Frame ^>(Window::Current->Content); |
| 47 |
|
| 48 |
// Do not repeat app initialization when the Window already has content, |
| 49 |
// just ensure that the window is active |
| 50 |
if (rootFrame == nullptr) |
| 51 |
{ |
| 52 |
// Create a Frame to act as the navigation context and associate it with |
| 53 |
// a SuspensionManager key |
| 54 |
rootFrame = ref new Frame(); |
| 55 |
|
| 56 |
if (args->PreviousExecutionState == ApplicationExecutionState::Terminated) |
| 57 |
{ |
| 58 |
// TODO: Restore the saved session state only when appropriate, scheduling the |
| 59 |
// final launch steps after the restore is complete |
| 60 |
} |
| 61 |
|
| 62 |
if (rootFrame->Content == nullptr) |
| 63 |
{ |
| 64 |
// When the navigation stack isn't restored navigate to the first page, |
| 65 |
// configuring the new page by passing required information as a navigation |
| 66 |
// parameter |
| 67 |
if (!rootFrame->Navigate(TypeName(MainPage::typeid), args->Arguments)) |
| 68 |
{ |
| 69 |
throw ref new FailureException("Failed to create initial page"); |
| 70 |
} |
| 71 |
} |
| 72 |
// Place the frame in the current Window |
| 73 |
Window::Current->Content = rootFrame; |
| 74 |
// Ensure the current window is active |
| 75 |
Window::Current->Activate(); |
| 76 |
} |
| 77 |
else |
| 78 |
{ |
| 79 |
if (rootFrame->Content == nullptr) |
| 80 |
{ |
| 81 |
// When the navigation stack isn't restored navigate to the first page, |
| 82 |
// configuring the new page by passing required information as a navigation |
| 83 |
// parameter |
| 84 |
if (!rootFrame->Navigate(TypeName(MainPage::typeid), args->Arguments)) |
| 85 |
{ |
| 86 |
throw ref new FailureException("Failed to create initial page"); |
| 87 |
} |
| 88 |
} |
| 89 |
// Ensure the current window is active |
| 90 |
Window::Current->Activate(); |
| 91 |
} |
| 92 |
} |
| 93 |
|
| 94 |
/// <summary> |
| 95 |
/// Invoked when application execution is being suspended. Application state is saved |
| 96 |
/// without knowing whether the application will be terminated or resumed with the contents |
| 97 |
/// of memory still intact. |
| 98 |
/// </summary> |
| 99 |
/// <param name="sender">The source of the suspend request.</param> |
| 100 |
/// <param name="e">Details about the suspend request.</param> |
| 101 |
void App::OnSuspending(Object ^ sender, SuspendingEventArgs ^ e) |
| 102 |
{ |
| 103 |
(void)sender; // Unused parameter |
| 104 |
(void)e; // Unused parameter |
| 105 |
|
| 106 |
// TODO: Save application state and stop any background activity |
| 107 |
} |