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