Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User/erlangl/packaged cpp app #224

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.2.32505.173
MinimumVisualStudioVersion = 10.0.40219.1
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "CppPackagedAppNotifications (Package)", "CppPackagedAppNotifications\CppPackagedAppNotifications (Package)\CppPackagedAppNotifications (Package).wapproj", "{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CppPackagedAppNotifications", "CppPackagedAppNotifications\CppPackagedAppNotifications\CppPackagedAppNotifications.vcxproj", "{8388B1E5-C891-4AF3-9380-4F89C7EB9690}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|arm64 = Debug|arm64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|arm64 = Release|arm64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Debug|arm64.ActiveCfg = Debug|arm64
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Debug|arm64.Build.0 = Debug|arm64
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Debug|arm64.Deploy.0 = Debug|arm64
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Debug|x64.ActiveCfg = Debug|x64
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Debug|x64.Build.0 = Debug|x64
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Debug|x64.Deploy.0 = Debug|x64
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Debug|x86.ActiveCfg = Debug|x86
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Debug|x86.Build.0 = Debug|x86
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Debug|x86.Deploy.0 = Debug|x86
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Release|arm64.ActiveCfg = Release|arm64
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Release|arm64.Build.0 = Release|arm64
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Release|arm64.Deploy.0 = Release|arm64
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Release|x64.ActiveCfg = Release|x64
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Release|x64.Build.0 = Release|x64
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Release|x64.Deploy.0 = Release|x64
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Release|x86.ActiveCfg = Release|x86
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Release|x86.Build.0 = Release|x86
{DD0A6C40-D9D2-419C-85E1-D491A835DBB4}.Release|x86.Deploy.0 = Release|x86
{8388B1E5-C891-4AF3-9380-4F89C7EB9690}.Debug|arm64.ActiveCfg = Debug|arm64
{8388B1E5-C891-4AF3-9380-4F89C7EB9690}.Debug|arm64.Build.0 = Debug|arm64
{8388B1E5-C891-4AF3-9380-4F89C7EB9690}.Debug|x64.ActiveCfg = Debug|x64
{8388B1E5-C891-4AF3-9380-4F89C7EB9690}.Debug|x64.Build.0 = Debug|x64
{8388B1E5-C891-4AF3-9380-4F89C7EB9690}.Debug|x86.ActiveCfg = Debug|Win32
{8388B1E5-C891-4AF3-9380-4F89C7EB9690}.Debug|x86.Build.0 = Debug|Win32
{8388B1E5-C891-4AF3-9380-4F89C7EB9690}.Release|arm64.ActiveCfg = Release|arm64
{8388B1E5-C891-4AF3-9380-4F89C7EB9690}.Release|arm64.Build.0 = Release|arm64
{8388B1E5-C891-4AF3-9380-4F89C7EB9690}.Release|x64.ActiveCfg = Release|x64
{8388B1E5-C891-4AF3-9380-4F89C7EB9690}.Release|x64.Build.0 = Release|x64
{8388B1E5-C891-4AF3-9380-4F89C7EB9690}.Release|x86.ActiveCfg = Release|Win32
{8388B1E5-C891-4AF3-9380-4F89C7EB9690}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D03F5394-3C2A-41D0-8FF2-E1797073B319}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '15.0'">
<VisualStudioVersion>15.0</VisualStudioVersion>
</PropertyGroup>
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x86">
<Configuration>Debug</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x86">
<Configuration>Release</Configuration>
<Platform>x86</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|arm64">
<Configuration>Debug</Configuration>
<Platform>arm64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|arm64">
<Configuration>Release</Configuration>
<Platform>arm64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup>
<WapProjPath Condition="'$(WapProjPath)'==''">$(MSBuildExtensionsPath)\Microsoft\DesktopBridge\</WapProjPath>
<DebuggerType>NativeOnly</DebuggerType>
<BackgroundTaskDebugEngines>NativeOnly</BackgroundTaskDebugEngines>
</PropertyGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.props" />
<PropertyGroup>
<ProjectGuid>dd0a6c40-d9d2-419c-85e1-d491a835dbb4</ProjectGuid>
<TargetPlatformVersion>10.0.22000.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<DefaultLanguage>en-US</DefaultLanguage>
<AppxPackageSigningEnabled>True</AppxPackageSigningEnabled>
<EntryPointProjectUniqueName>..\CppPackagedAppNotifications\CppPackagedAppNotifications.vcxproj</EntryPointProjectUniqueName>
<PackageCertificateThumbprint>ACA086B7A353F6C7E2CB72FEFC1DD02AD0048727</PackageCertificateThumbprint>
<PackageCertificateKeyFile>CppPackagedAppNotifications %28Package%29_TemporaryKey.pfx</PackageCertificateKeyFile>
</PropertyGroup>
<ItemGroup>
<AppxManifest Include="Package.appxmanifest">
<SubType>Designer</SubType>
</AppxManifest>
</ItemGroup>
<ItemGroup>
<Content Include="Images\Square44x44Logo.altform-lightunplated_targetsize-16.png" />
<Content Include="Images\Square44x44Logo.altform-lightunplated_targetsize-24.png" />
<Content Include="Images\Square44x44Logo.altform-lightunplated_targetsize-256.png" />
<Content Include="Images\Square44x44Logo.altform-lightunplated_targetsize-32.png" />
<Content Include="Images\Square44x44Logo.altform-lightunplated_targetsize-48.png" />
<Content Include="Images\Square44x44Logo.altform-unplated_targetsize-16.png" />
<Content Include="Images\Square44x44Logo.altform-unplated_targetsize-256.png" />
<Content Include="Images\Square44x44Logo.altform-unplated_targetsize-32.png" />
<Content Include="Images\Square44x44Logo.altform-unplated_targetsize-48.png" />
<Content Include="Images\Square44x44Logo.scale-100.png" />
<Content Include="Images\Square44x44Logo.scale-125.png" />
<Content Include="Images\Square44x44Logo.scale-150.png" />
<Content Include="Images\Square44x44Logo.scale-400.png" />
<Content Include="Images\Square44x44Logo.targetsize-16.png" />
<Content Include="Images\Square44x44Logo.targetsize-24.png" />
<Content Include="Images\Square44x44Logo.targetsize-256.png" />
<Content Include="Images\Square44x44Logo.targetsize-32.png" />
<Content Include="Images\Square44x44Logo.targetsize-48.png" />
<Content Include="Images\Wide310x150Logo.scale-400.png" />
<None Include="CppPackagedAppNotifications %28Package%29_TemporaryKey.pfx" />
<Content Include="Images\SplashScreen.scale-200.png" />
<Content Include="Images\LockScreenLogo.scale-200.png" />
<Content Include="Images\Square150x150Logo.scale-100.png" />
<Content Include="Images\Square150x150Logo.scale-125.png" />
<Content Include="Images\Square150x150Logo.scale-150.png" />
<Content Include="Images\Square150x150Logo.scale-200.png" />
<Content Include="Images\Square150x150Logo.scale-400.png" />
<Content Include="Images\Square44x44Logo.scale-200.png" />
<Content Include="Images\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Images\StoreLogo.png" />
<Content Include="Images\Wide310x150Logo.scale-100.png" />
<Content Include="Images\Wide310x150Logo.scale-125.png" />
<Content Include="Images\Wide310x150Logo.scale-150.png" />
<Content Include="Images\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CppPackagedAppNotifications\CppPackagedAppNotifications.vcxproj">
<SkipGetTargetFrameworkProperties>True</SkipGetTargetFrameworkProperties>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Windows.CppWinRT" Version="2.0.210922.5" />
<PackageReference Include="Microsoft.Windows.ImplementationLibrary" Version="1.0.220201.1" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.0-preview3" />
</ItemGroup>
<Import Project="$(WapProjPath)\Microsoft.DesktopBridge.targets" />
</Project>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>

<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
xmlns:com="http://schemas.microsoft.com/appx/manifest/com/windows10"
IgnorableNamespaces="uap rescap">

<Identity
Name="4e7bdd5e-c13e-405b-9f4e-6462002dda2e"
Publisher="CN=erlangl"
Version="1.0.0.0" />

<Properties>
<DisplayName>CppPackagedAppNotifications (Package)</DisplayName>
<PublisherDisplayName>erlangl</PublisherDisplayName>
<Logo>Images\StoreLogo.png</Logo>
</Properties>

<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
<TargetDeviceFamily Name="Windows.Desktop" MinVersion="10.0.17763.0" MaxVersionTested="10.0.19041.0" />
</Dependencies>

<Resources>
<Resource Language="x-generate"/>
</Resources>

<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$">
<uap:VisualElements
DisplayName="CppPackagedAppNotifications (Package)"
Description="CppPackagedAppNotifications (Package)"
BackgroundColor="transparent"
Square150x150Logo="Images\Square150x150Logo.png"
Square44x44Logo="Images\Square44x44Logo.png">
<uap:DefaultTile Wide310x150Logo="Images\Wide310x150Logo.png" />
<uap:SplashScreen Image="Images\SplashScreen.png" />
</uap:VisualElements>

<Extensions>
<!--Register the OM CLSID for Push Notifications-->
<com:Extension Category="windows.comServer">
<com:ComServer>
<com:ExeServer Executable="CppPackagedAppNotifications.exe" DisplayName="SampleBackgroundApp" Arguments="----WindowsAppRuntimePushServer:">
<com:Class Id="4e7bdd5e-c13e-405b-9f4e-6462002dda2e" DisplayName="Windows App SDK Push" />
</com:ExeServer>
</com:ComServer>
</com:Extension>

<!--Specify which CLSID to activate when a toast is clicked-->
<desktop:Extension Category="windows.toastNotificationActivation">
<desktop:ToastNotificationActivation ToastActivatorCLSID="4e1cdfbb-7bdc-48e3-8fb5-4451897781f9" />
</desktop:Extension>

<!--Register the COM CLSID for App Notifications-->
<com:Extension Category="windows.comServer">
<com:ComServer>
<com:ExeServer Executable="CppPackagedAppNotifications.exe" Arguments="----AppNotificationActivated:" DisplayName="Toast activator">
<com:Class Id="4e1cdfbb-7bdc-48e3-8fb5-4451897781f9" DisplayName="Toast activator"/>
</com:ExeServer>
</com:ComServer>
</com:Extension>
</Extensions>
</Application>
</Applications>

<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
</Package>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!-- Copyright (c) Microsoft Corporation.
Licensed under the MIT License. -->
<Application
x:Class="CppPackagedAppNotifications.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CppPackagedAppNotifications">
<Application.Resources>
<!-- Application-specific resources -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!--
Styles that define common aspects of the platform look and feel
Required by Visual Studio project and item templates
-->
<ResourceDictionary Source="ms-appx:///Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#include "pch.h"
#include "App.xaml.h"
#include "MainWindow.xaml.h"
#include "Notifications\NotificationManager.h"
#include <wil/result.h>
#include <Microsoft.UI.Xaml.Window.h>
#include <winrt/Microsoft.Windows.AppLifecycle.h>
#include <winrt/Microsoft.Windows.AppNotifications.h>

namespace winrt
{
using namespace Windows::Foundation;
using namespace Microsoft::UI::Xaml;
using namespace winrt::Microsoft::Windows::AppLifecycle;
using namespace winrt::Microsoft::Windows::AppNotifications;
}

// NotificationManager is responsible for registering and unregistering the Sample for App Notifications as well as
// dispatching actioned notifications to the appropriate scenario.
// Registration will happen when Init() is called and Unregistration will happen when this
// instance variable goes out of scope, i.e.: when the App is terminated.
static NotificationManager g_notificationManager;

namespace winrt::CppPackagedAppNotifications::implementation
{
static App* app{ nullptr };

App::App()
{
InitializeComponent();
app = this;

#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException([](winrt::IInspectable const&, winrt::UnhandledExceptionEventArgs const& e)
{
if (IsDebuggerPresent())
{
auto errorMessage = e.Message();
__debugbreak();
}
});
#endif
}

void App::ToForeground()
{
assert(app != nullptr);

HWND hwnd;
auto windowNative{ app->window.as<IWindowNative>() };
if (windowNative && SUCCEEDED(windowNative->get_WindowHandle(&hwnd)))
{
SwitchToThisWindow(hwnd, TRUE);
}
}

std::wstring App::GetFullPathToExe()
{
TCHAR buffer[MAX_PATH] = { 0 };
GetModuleFileName(NULL, buffer, MAX_PATH);
std::wstring::size_type pos = std::wstring(buffer).find_last_of(L"\\/");
return std::wstring(buffer).substr(0, pos);
}

std::wstring App::GetFullPathToAsset(std::wstring const& assetName)
{
return GetFullPathToExe() + L"\\Images\\" + assetName;
}

void App::OnLaunched(winrt::Microsoft::UI::Xaml::LaunchActivatedEventArgs const& /*args*/)
{
window = make<MainWindow>();

g_notificationManager.Init();

// NOTE: AppInstance is ambiguous between
// Microsoft.Windows.AppLifecycle.AppInstance and
// Windows.ApplicationModel.AppInstance
auto currentInstance{ winrt::AppInstance::GetCurrent() };
if (currentInstance)
{
// AppInstance.GetActivatedEventArgs will report the correct ActivationKind,
// even in WinUI's OnLaunched.
winrt::AppActivationArguments activationArgs{ currentInstance.GetActivatedEventArgs() };
if (activationArgs)
{
winrt::ExtendedActivationKind extendedKind{ activationArgs.Kind() };
if (extendedKind == winrt::Microsoft::Windows::AppLifecycle::ExtendedActivationKind::AppNotification)
{
winrt::AppNotificationActivatedEventArgs notificationActivatedEventArgs{ activationArgs.Data().as<winrt::AppNotificationActivatedEventArgs>() };
g_notificationManager.ProcessLaunchActivationArgs(notificationActivatedEventArgs);
}
}
}

window.Activate();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#pragma once
#include "App.xaml.g.h"
#include "pch.h"

namespace winrt::CppPackagedAppNotifications::implementation
{
struct App : AppT<App>
{
App();

static std::wstring GetFullPathToExe();
static std::wstring GetFullPathToAsset(std::wstring const& assetName);
static void ToForeground();

void OnLaunched(Microsoft::UI::Xaml::LaunchActivatedEventArgs const&);

private:
Microsoft::UI::Xaml::Window window{ nullptr };
};
}
Binary file not shown.
Loading