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