Path: blob/master/samples/winrt/ImageManipulations/App.xaml.cpp
16337 views
//*********************************************************1//2// Copyright (c) Microsoft. All rights reserved.3// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF4// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY5// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR6// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.7//8//*********************************************************910//11// App.xaml.cpp12// Implementation of the App.xaml class.13//1415#include "pch.h"16#include "MainPage.xaml.h"17#include "AdvancedCapture.xaml.h"18#include "Common\SuspensionManager.h"1920using namespace SDKSample;21using namespace SDKSample::Common;22using namespace SDKSample::MediaCapture;2324using namespace Concurrency;25using namespace Platform;26using namespace Windows::ApplicationModel;27using namespace Windows::ApplicationModel::Activation;28using namespace Windows::Foundation;29using namespace Windows::Foundation::Collections;30using namespace Windows::UI::Core;31using namespace Windows::UI::Xaml;32using namespace Windows::UI::Xaml::Controls;33using namespace Windows::UI::Xaml::Controls::Primitives;34using namespace Windows::UI::Xaml::Data;35using namespace Windows::UI::Xaml::Input;36using namespace Windows::UI::Xaml::Interop;37using namespace Windows::UI::Xaml::Media;38using namespace Windows::UI::Xaml::Navigation;3940/// <summary>41/// Initializes the singleton application object. This is the first line of authored code42/// executed, and as such is the logical equivalent of main() or WinMain().43/// </summary>44App::App()45{46InitializeComponent();47this->Suspending += ref new SuspendingEventHandler(this, &SDKSample::App::OnSuspending);48}4950/// <summary>51/// Invoked when the application is launched normally by the end user. Other entry points will52/// be used when the application is launched to open a specific file, to display search results,53/// and so forth.54/// </summary>55/// <param name="pArgs">Details about the launch request and process.</param>56void App::OnLaunched(LaunchActivatedEventArgs^ pArgs)57{58this->LaunchArgs = pArgs;5960// Do not repeat app initialization when already running, just ensure that61// the window is active62if (pArgs->PreviousExecutionState == ApplicationExecutionState::Running)63{64Window::Current->Activate();65return;66}6768// Create a Frame to act as the navigation context and associate it with69// a SuspensionManager key70auto rootFrame = ref new Frame();71SuspensionManager::RegisterFrame(rootFrame, "AppFrame");7273auto prerequisite = task<void>([](){});74if (pArgs->PreviousExecutionState == ApplicationExecutionState::Terminated)75{76// Restore the saved session state only when appropriate, scheduling the77// final launch steps after the restore is complete78prerequisite = SuspensionManager::RestoreAsync();79}80prerequisite.then([=]()81{82// When the navigation stack isn't restored navigate to the first page,83// configuring the new page by passing required information as a navigation84// parameter85if (rootFrame->Content == nullptr)86{87if (!rootFrame->Navigate(TypeName(MainPage::typeid)))88{89throw ref new FailureException("Failed to create initial page");90}91}9293// Place the frame in the current Window and ensure that it is active94Window::Current->Content = rootFrame;95Window::Current->Activate();96}, task_continuation_context::use_current());97}9899/// <summary>100/// Invoked when application execution is being suspended. Application state is saved101/// without knowing whether the application will be terminated or resumed with the contents102/// of memory still intact.103/// </summary>104/// <param name="sender">The source of the suspend request.</param>105/// <param name="e">Details about the suspend request.</param>106void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)107{108(void) sender; // Unused parameter109110auto deferral = e->SuspendingOperation->GetDeferral();111SuspensionManager::SaveAsync().then([=]()112{113deferral->Complete();114});115}116117118