diff options
| author | Luke <[email protected]> | 2017-11-28 00:22:11 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-11-28 00:22:11 -0800 |
| commit | 79bbbca2f6e37d94fbbbd60d12c5c1e7dde650da (patch) | |
| tree | 793ff943b8b641f95d05401156badd42da4a0f12 /general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp | |
| parent | ed1df9a8b80b154b71b79635e40af75f4f19001c (diff) | |
| parent | 2817004092cee784d4aaf36c045fdb5b0bc09f7e (diff) | |
Merge pull request #1 from Microsoft/master
Updating Local
Diffstat (limited to 'general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp')
6 files changed, 514 insertions, 0 deletions
diff --git a/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/App.xaml.cpp b/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/App.xaml.cpp new file mode 100644 index 00000000..1abebcb3 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/App.xaml.cpp @@ -0,0 +1,134 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#include "pch.h" +#include "MainPage.xaml.h" + +using namespace SDKTemplate; + +using namespace Platform; +using namespace Windows::ApplicationModel; +using namespace Windows::ApplicationModel::Activation; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +using namespace Windows::UI::Xaml::Controls::Primitives; +using namespace Windows::UI::Xaml::Data; +using namespace Windows::UI::Xaml::Input; +using namespace Windows::UI::Xaml::Interop; +using namespace Windows::UI::Xaml::Media; +using namespace Windows::UI::Xaml::Navigation; + +// The Blank Application template is documented at http://go.microsoft.com/fwlink/?LinkId=402347&clcid=0x409 + +// These placeholder functions are used if the sample does not +// implement the corresponding methods. This allows us to simulate +// C# partial methods in C++. + +static void Partial_Construct() { } + +/// <summary> +/// Initializes the singleton application object. This is the first line of authored code +/// executed, and as such is the logical equivalent of main() or WinMain(). +/// </summary> +App::App() +{ + InitializeComponent(); + Partial_Construct(); + Suspending += ref new Windows::UI::Xaml::SuspendingEventHandler(this, &SDKTemplate::App::OnSuspending); +} + +/// <summary> +/// Invoked when the application is launched normally by the end user. Other entry points +/// will be used such as when the application is launched to open a specific file. +/// </summary> +/// <param name="e">Details about the launch request and process.</param> +void App::OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) +{ +#if _DEBUG + // Show graphics profiling information while debugging. + if (IsDebuggerPresent()) + { + // Display the current frame rate counters + DebugSettings->EnableFrameRateCounter = false; + } +#endif + + auto rootFrame = dynamic_cast<Frame^>(Window::Current->Content); + + // Do not repeat app initialization when the Window already has content, + // just ensure that the window is active + if (rootFrame == nullptr) + { + // Create a Frame to act as the navigation context and associate it with + // a SuspensionManager key + rootFrame = ref new Frame(); + + // Set the default language + rootFrame->Language = Windows::Globalization::ApplicationLanguages::Languages->GetAt(0); + + rootFrame->NavigationFailed += ref new Windows::UI::Xaml::Navigation::NavigationFailedEventHandler(this, &App::OnNavigationFailed); + + if (e->PreviousExecutionState == ApplicationExecutionState::Terminated) + { + // TODO: Restore the saved session state only when appropriate, scheduling the + // final launch steps after the restore is complete + } + + if (rootFrame->Content == nullptr) + { + // When the navigation stack isn't restored navigate to the first page, + // configuring the new page by passing required information as a navigation + // parameter + rootFrame->Navigate(TypeName(MainPage::typeid), e->Arguments); + } + // Place the frame in the current Window + Window::Current->Content = rootFrame; + // Ensure the current window is active + Window::Current->Activate(); + } + else + { + if (rootFrame->Content == nullptr) + { + // When the navigation stack isn't restored navigate to the first page, + // configuring the new page by passing required information as a navigation + // parameter + rootFrame->Navigate(TypeName(MainPage::typeid), e->Arguments); + } + // Ensure the current window is active + Window::Current->Activate(); + } +} + +/// <summary> +/// Invoked when application execution is being suspended. Application state is saved +/// without knowing whether the application will be terminated or resumed with the contents +/// of memory still intact. +/// </summary> +/// <param name="sender">The source of the suspend request.</param> +/// <param name="e">Details about the suspend request.</param> +void App::OnSuspending(Object^ /* sender */, SuspendingEventArgs^ /* e */) +{ + //TODO: Save application state and stop any background activity +} + + +/// <summary> +/// Invoked when Navigation to a certain page fails +/// </summary> +/// <param name="sender">The Frame which failed navigation</param> +/// <param name="e">Details about the navigation failure</param> +void App::OnNavigationFailed(Platform::Object ^sender, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^e) +{ + throw ref new FailureException("Failed to load Page " + e->SourcePageType.Name); +}
\ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/App.xaml.h b/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/App.xaml.h new file mode 100644 index 00000000..e7bd715a --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/App.xaml.h @@ -0,0 +1,33 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#pragma once + +#include "App.g.h" + +namespace SDKTemplate +{ + /// <summary> + /// Provides application-specific behavior to supplement the default Application class. + /// </summary> + ref class App sealed + { + protected: + virtual void OnLaunched(Windows::ApplicationModel::Activation::LaunchActivatedEventArgs^ e) override; + + internal: + App(); + + private: + void OnSuspending(Platform::Object^ sender, Windows::ApplicationModel::SuspendingEventArgs^ e); + void OnNavigationFailed(Platform::Object ^sender, Windows::UI::Xaml::Navigation::NavigationFailedEventArgs ^e); + }; +} diff --git a/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/DeviceHelpers.h b/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/DeviceHelpers.h new file mode 100644 index 00000000..c2fa82b2 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/DeviceHelpers.h @@ -0,0 +1,67 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#pragma once + +namespace SDKTemplate +{ + namespace DeviceHelpers + { + // We use a DeviceWatcher instead of DeviceInformation.FindAllAsync because + // the DeviceWatcher will let us see the devices as they are discovered, + // whereas FindAllAsync returns results only after discovery is complete. + // + // The convertAsync functional is passed a device ID (Platform::String^) and returns a + // Concurrency::task<Something^>. + template<typename Converter> + auto GetFirstDeviceAsync(Platform::String^ selector, Converter convertAsync) + -> decltype(convertAsync(nullptr)) + { + using T = typename decltype(convertAsync(nullptr))::result_type; + Concurrency::task_completion_event<T> completionEvent; + auto pendingTasks = std::make_shared<std::vector<Concurrency::task<void>>>(); + Windows::Devices::Enumeration::DeviceWatcher^ watcher = Windows::Devices::Enumeration::DeviceInformation::CreateWatcher(selector); + + watcher->Added += ref new Windows::Foundation::TypedEventHandler<Windows::Devices::Enumeration::DeviceWatcher^, Windows::Devices::Enumeration::DeviceInformation^>( + [completionEvent, pendingTasks, convertAsync](Windows::Devices::Enumeration::DeviceWatcher^ sender, Windows::Devices::Enumeration::DeviceInformation^ device) + { + auto task = convertAsync(device->Id).then([completionEvent](T t) + { + if (t != nullptr) + { + completionEvent.set(t); + } + }); + pendingTasks->push_back(task); + }); + + watcher->EnumerationCompleted += ref new Windows::Foundation::TypedEventHandler<Windows::Devices::Enumeration::DeviceWatcher^, Platform::Object^>( + [completionEvent, pendingTasks](Windows::Devices::Enumeration::DeviceWatcher^ sender, Platform::Object^ args) + { + // Wait for completion of all the tasks we created in our "Added" event handler. + Concurrency::when_all(pendingTasks->begin(), pendingTasks->end()).then([completionEvent]() + { + // This sets the result to "nullptr" if no task was able to produce a device. + completionEvent.set(nullptr); + }); + }); + + watcher->Start(); + + // Wait for enumeration to complete or for a device to be found, whichever comes first. + return Concurrency::create_task(completionEvent).then([watcher](T result) + { + watcher->Stop(); + return result; + }); + } + } +} diff --git a/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/MainPage.xaml b/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/MainPage.xaml new file mode 100644 index 00000000..5179f520 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/MainPage.xaml @@ -0,0 +1,80 @@ +<!-- +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* +--> + +<Page + x:Class="SDKTemplate.MainPage" + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="using:SDKTemplate" + xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + mc:Ignorable="d"> + + <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> + <Grid.RowDefinitions> + <RowDefinition Height="Auto"/> + <RowDefinition Height="*"/> + </Grid.RowDefinitions> + <SplitView x:Name="Splitter" IsPaneOpen="True" Grid.Row="1" DisplayMode="Inline"> + <SplitView.Pane> + <RelativePanel Margin="10,0,0,0"> + <TextBlock x:Name="SampleTitle" Text="Sample Title Here" Style="{StaticResource SampleHeaderTextStyle}" TextWrapping="Wrap" Margin="0,10,0,0"/> + <ListBox x:Name="ScenarioControl" SelectionChanged="ScenarioControl_SelectionChanged" + SelectionMode="Single" HorizontalAlignment="Left" Background="Transparent" BorderThickness="0" + VerticalAlignment="Top" RelativePanel.Below="SampleTitle" Margin="0,10,0,0" RelativePanel.Above="FooterPanel"> + <ListBox.ItemTemplate> + <DataTemplate> + <TextBlock Text="{Binding Converter={StaticResource ScenarioConverter}}"/> + </DataTemplate> + </ListBox.ItemTemplate> + </ListBox> + <StackPanel x:Name="FooterPanel" Orientation="Vertical" RelativePanel.AlignBottomWithPanel="True"> + <Image Source="Assets/microsoft-sdk.png" AutomationProperties.Name="Microsoft Logo" Stretch="None" HorizontalAlignment="Left" Margin="10,0,0,0"/> + <TextBlock x:Name="Copyright" Text="© Microsoft Corporation. All rights reserved." Style="{StaticResource CopyrightTextStyle}" + RelativePanel.Above="LinksPanel" Margin="10,10,0,0" + TextWrapping="Wrap"/> + <StackPanel x:Name="LinksPanel" Orientation="Horizontal" Margin="10,10,0,10"> + <HyperlinkButton Content="Trademarks" Tag="http://go.microsoft.com/fwlink/?LinkID=623755" + Click="Footer_Click" FontSize="12" Style="{StaticResource HyperlinkStyle}" /> + <TextBlock Text="|" Style="{StaticResource SeparatorStyle}" VerticalAlignment="Center" /> + <HyperlinkButton x:Name="PrivacyLink" Content="Privacy" Tag="http://privacy.microsoft.com" Click="Footer_Click" FontSize="12" Style="{StaticResource HyperlinkStyle}"/> + </StackPanel> + </StackPanel> + </RelativePanel> + </SplitView.Pane> + <RelativePanel> + <Frame x:Name="ScenarioFrame" Margin="0,5,0,0" RelativePanel.AlignTopWithPanel="True" RelativePanel.Above="StatusPanel" RelativePanel.AlignRightWithPanel="True" RelativePanel.AlignLeftWithPanel="True"/> + <StackPanel x:Name="StatusPanel" Orientation="Vertical" RelativePanel.AlignBottomWithPanel="True" RelativePanel.AlignRightWithPanel="True" RelativePanel.AlignLeftWithPanel="True"> + <TextBlock x:Name="StatusLabel" Margin="0,0,0,10" TextWrapping="Wrap" Text="Status:" /> + <Border x:Name="StatusBorder" Margin="0,0,0,0" Visibility="Visible" > + <ScrollViewer VerticalScrollMode="Auto" VerticalScrollBarVisibility="Auto" MaxHeight="200"> + <TextBlock x:Name="StatusBlock" FontWeight="Bold" + MaxWidth="{Binding ElementName=Splitter, Path=ActualWidth}" Margin="10,10,10,20" TextWrapping="Wrap" /> + </ScrollViewer> + </Border> + </StackPanel> + </RelativePanel> + </SplitView> + <StackPanel x:Name="HeaderPanel" Orientation="Horizontal"> + <Border Background="{ThemeResource SystemControlBackgroundChromeMediumBrush}" Grid.Row="0"> + <ToggleButton Style="{StaticResource SymbolButton}" Click="Button_Click" VerticalAlignment="Top" Foreground="{ThemeResource ApplicationForegroundThemeBrush}"> + <ToggleButton.Content> + <FontIcon x:Name="Hamburger" FontFamily="Segoe MDL2 Assets" Glyph="" Margin="0,10,0,0"/> + </ToggleButton.Content> + </ToggleButton> + </Border> + <Image x:Name="WindowsLogo" Stretch="None" Source="Assets/windows-sdk.png" Margin="0,15,0,0" /> + <TextBlock x:Name="Header" Text="Universal Windows Platform sample" Style="{StaticResource TagLineTextStyle}" Margin="0,15,0,0" /> + </StackPanel> + </Grid> +</Page> diff --git a/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/MainPage.xaml.cpp b/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/MainPage.xaml.cpp new file mode 100644 index 00000000..24c12f68 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/MainPage.xaml.cpp @@ -0,0 +1,154 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#include "pch.h" +#include "MainPage.xaml.h" + +using namespace SDKTemplate; +using namespace Platform; +using namespace Windows::Foundation; +using namespace Windows::Foundation::Collections; +using namespace Windows::UI::Core; +using namespace Windows::UI::Xaml; +using namespace Windows::UI::Xaml::Controls; +using namespace Windows::UI::Xaml::Controls::Primitives; +using namespace Windows::UI::Xaml::Data; +using namespace Windows::UI::Xaml::Input; +using namespace Windows::UI::Xaml::Media; +using namespace Windows::UI::Xaml::Navigation; +using namespace Windows::UI::Xaml::Interop; + +// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 + +MainPage^ MainPage::Current = nullptr; + +MainPage::MainPage() +{ + InitializeComponent(); + SampleTitle->Text = FEATURE_NAME; + + // This is a static public property that allows downstream pages to get a handle to the MainPage instance + // in order to call methods that are in this class. + MainPage::Current = this; +} + +void MainPage::OnNavigatedTo(NavigationEventArgs^ e) +{ + // Populate the ListBox with the scenarios as defined in SampleConfiguration.cpp. + auto itemCollection = ref new Platform::Collections::Vector<Object^>(); + int i = 1; + for (auto const& s : MainPage::Current->scenarios) + { + // Create a textBlock to hold the content and apply the ListItemTextStyle from Styles.xaml + TextBlock^ textBlock = ref new TextBlock(); + ListBoxItem^ item = ref new ListBoxItem(); + auto style = App::Current->Resources->Lookup("ListItemTextStyle"); + + textBlock->Text = (i++).ToString() + ") " + s.Title; + textBlock->Style = safe_cast<Windows::UI::Xaml::Style ^>(style); + + item->Name = s.ClassName; + item->Content = textBlock; + itemCollection->Append(item); + } + + // Set the newly created itemCollection as the ListBox ItemSource. + ScenarioControl->ItemsSource = itemCollection; + int startingScenarioIndex; + + if (Window::Current->Bounds.Width < 640) + { + startingScenarioIndex = -1; + } + else + { + startingScenarioIndex = 0; + } + + ScenarioControl->SelectedIndex = startingScenarioIndex; + ScenarioControl->ScrollIntoView(ScenarioControl->SelectedItem); +} + + +void MainPage::ScenarioControl_SelectionChanged(Object^ sender, SelectionChangedEventArgs^ e) +{ + ListBox^ scenarioListBox = safe_cast<ListBox^>(sender); //as ListBox; + ListBoxItem^ item = dynamic_cast<ListBoxItem^>(scenarioListBox->SelectedItem); + if (item != nullptr) + { + // Clear the status block when changing scenarios + NotifyUser("", NotifyType::StatusMessage); + + // Navigate to the selected scenario. + TypeName scenarioType = { item->Name, TypeKind::Custom }; + ScenarioFrame->Navigate(scenarioType, this); + + if (Window::Current->Bounds.Width < 640) + { + Splitter->IsPaneOpen = false; + } + } +} + +void MainPage::NotifyUser(String^ strMessage, NotifyType type) +{ + if (Dispatcher->HasThreadAccess) + { + UpdateStatus(strMessage, type); + } + else + { + Dispatcher->RunAsync(CoreDispatcherPriority::Normal, ref new DispatchedHandler([strMessage, type, this]() + { + UpdateStatus(strMessage, type); + })); + } +} + +void MainPage::UpdateStatus(String^ strMessage, NotifyType type) +{ + switch (type) + { + case NotifyType::StatusMessage: + StatusBorder->Background = ref new SolidColorBrush(Windows::UI::Colors::Green); + break; + case NotifyType::ErrorMessage: + StatusBorder->Background = ref new SolidColorBrush(Windows::UI::Colors::Red); + break; + default: + break; + } + + StatusBlock->Text = strMessage; + + // Collapse the StatusBlock if it has no text to conserve real estate. + if (StatusBlock->Text != "") + { + StatusBorder->Visibility = Windows::UI::Xaml::Visibility::Visible; + StatusPanel->Visibility = Windows::UI::Xaml::Visibility::Visible; + } + else + { + StatusBorder->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + StatusPanel->Visibility = Windows::UI::Xaml::Visibility::Collapsed; + } +} + +void MainPage::Footer_Click(Object^ sender, RoutedEventArgs^ e) +{ + auto uri = ref new Uri((String^)((HyperlinkButton^)sender)->Tag); + Windows::System::Launcher::LaunchUriAsync(uri); +} + +void MainPage::Button_Click(Object^ sender, RoutedEventArgs^ e) +{ + Splitter->IsPaneOpen = !Splitter->IsPaneOpen; +}
\ No newline at end of file diff --git a/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/MainPage.xaml.h b/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/MainPage.xaml.h new file mode 100644 index 00000000..e87e24f0 --- /dev/null +++ b/general/WinHEC 2017 Lab/Toaster Support App/SharedContent/cpp/MainPage.xaml.h @@ -0,0 +1,46 @@ +//********************************************************* +// +// Copyright (c) Microsoft. All rights reserved. +// This code is licensed under the MIT License (MIT). +// THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY +// IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR +// PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT. +// +//********************************************************* + +#pragma once + +#include "MainPage.g.h" +#include "SampleConfiguration.h" + +namespace SDKTemplate +{ + public enum class NotifyType + { + StatusMessage, + ErrorMessage + }; + + /// <summary> + /// An empty page that can be used on its own or navigated to within a Frame. + /// </summary> + public ref class MainPage sealed + { + public: + MainPage(); + + protected: + virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override; + + private: + void ScenarioControl_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e); + void Footer_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void Button_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e); + void UpdateStatus(Platform::String^ strMessage, NotifyType type); + + internal: + static MainPage^ Current; + void NotifyUser(Platform::String^ strMessage, NotifyType type); + }; +} |
