Path: blob/master/samples/winrt_universal/PhoneTutorial/App.xaml.cpp
16354 views
//1// App.xaml.cpp2// Implementation of the App class.3//45#include "pch.h"6#include "MainPage.xaml.h"78using namespace PhoneTutorial;910using namespace Platform;11using namespace Windows::ApplicationModel;12using namespace Windows::ApplicationModel::Activation;13using namespace Windows::Foundation;14using namespace Windows::Foundation::Collections;15using namespace Windows::UI::Xaml;16using namespace Windows::UI::Xaml::Controls;17using namespace Windows::UI::Xaml::Controls::Primitives;18using namespace Windows::UI::Xaml::Data;19using namespace Windows::UI::Xaml::Input;20using namespace Windows::UI::Xaml::Interop;21using namespace Windows::UI::Xaml::Media;22using namespace Windows::UI::Xaml::Media::Animation;23using namespace Windows::UI::Xaml::Navigation;2425// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkID=3916412627/// <summary>28/// Initializes the singleton application object. This is the first line of authored code29/// executed, and as such is the logical equivalent of main() or WinMain().30/// </summary>31App::App()32{33InitializeComponent();34Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);35}3637/// <summary>38/// Invoked when the application is launched normally by the end user. Other entry points39/// will be used when the application is launched to open a specific file, to display40/// search results, and so forth.41/// </summary>42/// <param name="e">Details about the launch request and process.</param>43void App::OnLaunched(LaunchActivatedEventArgs^ e)44{45#if _DEBUG46if (IsDebuggerPresent())47{48DebugSettings->EnableFrameRateCounter = true;49}50#endif5152auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content);5354// Do not repeat app initialization when the Window already has content,55// just ensure that the window is active.56if (rootFrame == nullptr)57{58// Create a Frame to act as the navigation context and associate it with59// a SuspensionManager key60rootFrame = ref new Frame();6162// TODO: Change this value to a cache size that is appropriate for your application.63rootFrame->CacheSize = 1;6465if (e->PreviousExecutionState == ApplicationExecutionState::Terminated)66{67// TODO: Restore the saved session state only when appropriate, scheduling the68// final launch steps after the restore is complete.69}7071// Place the frame in the current Window72Window::Current->Content = rootFrame;73}7475if (rootFrame->Content == nullptr)76{77// Removes the turnstile navigation for startup.78if (rootFrame->ContentTransitions != nullptr)79{80_transitions = ref new TransitionCollection();81for (auto transition : rootFrame->ContentTransitions)82{83_transitions->Append(transition);84}85}8687rootFrame->ContentTransitions = nullptr;88_firstNavigatedToken = rootFrame->Navigated += ref new NavigatedEventHandler(this, &App::RootFrame_FirstNavigated);8990// When the navigation stack isn't restored navigate to the first page,91// configuring the new page by passing required information as a navigation92// parameter.93if (!rootFrame->Navigate(MainPage::typeid, e->Arguments))94{95throw ref new FailureException("Failed to create initial page");96}97}9899// Ensure the current window is active100Window::Current->Activate();101}102103/// <summary>104/// Restores the content transitions after the app has launched.105/// </summary>106void App::RootFrame_FirstNavigated(Object^ sender, NavigationEventArgs^ e)107{108auto rootFrame = safe_cast<Frame^>(sender);109110TransitionCollection^ newTransitions;111if (_transitions == nullptr)112{113newTransitions = ref new TransitionCollection();114newTransitions->Append(ref new NavigationThemeTransition());115}116else117{118newTransitions = _transitions;119}120121rootFrame->ContentTransitions = newTransitions;122rootFrame->Navigated -= _firstNavigatedToken;123}124125/// <summary>126/// Invoked when application execution is being suspended. Application state is saved127/// without knowing whether the application will be terminated or resumed with the contents128/// of memory still intact.129/// </summary>130void App::OnSuspending(Object^ sender, SuspendingEventArgs^ e)131{132(void) sender; // Unused parameter133(void) e; // Unused parameter134135// TODO: Save application state and stop any background activity136}137138