Skip to content

Commit

Permalink
Add SystemBackdrop API for GetStoreAppInstaller
Browse files Browse the repository at this point in the history
Add SystemBackdrop API for GetStoreAppInstaller
  • Loading branch information
Gaoyifei1011 committed Oct 2, 2024
1 parent cdfa008 commit a3fb81d
Show file tree
Hide file tree
Showing 47 changed files with 6,266 additions and 24 deletions.
3 changes: 2 additions & 1 deletion Description/README_EN-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ All the content of the program has been developed
> * [Microsoft.Windows.SDK.BuildTools](https://aka.ms/WinSDKProjectURL) 
> * [Microsoft.WindowsAppSDK](https://github.com/microsoft/windowsappsdk) 
> * [Microsoft.WindowsPackageManager.ComInterop](https://github.com/microsoft/winget-cli) 
> * [Mile.Xaml](https://github.com/ProjectMile/Mile.Xaml) 
[Code referenced or used during the learning process](https://github.com/Gaoyifei1011/GetStoreApp/blob/main/Description/StudyReferenceCode.md) 
[Auxiliary Tools](https://github.com/Gaoyifei1011/GetStoreApp/blob/main/Description/AuxiliaryTools.md) 

Expand Down
3 changes: 2 additions & 1 deletion Description/README_ZH-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@
> * [Microsoft.Windows.SDK.BuildTools](https://aka.ms/WinSDKProjectURL) 
> * [Microsoft.WindowsAppSDK](https://github.com/microsoft/windowsappsdk) 
> * [Microsoft.WindowsPackageManager.ComInterop](https://github.com/microsoft/winget-cli) 
> * [Mile.Xaml](https://github.com/ProjectMile/Mile.Xaml) 
[学习过程中参考或使用的代码](https://github.com/Gaoyifei1011/GetStoreApp/blob/main/Description/StudyReferenceCode.md) 
[辅助工具](https://github.com/Gaoyifei1011/GetStoreApp/blob/main/Description/AuxiliaryTools.md) 

Expand Down
2 changes: 1 addition & 1 deletion GetStoreApp/GetStoreApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@

<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.2839-prerelease" />
<PackageReference Include="Microsoft.Windows.CsWinRT" Version="2.1.3" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240829007" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240923002" />

<Page Update="Styles\WinUI\AppBarButton.xaml" XamlRuntime="$(DefaultXamlRuntime)" />
<Page Update="Styles\WinUI\HyperlinkButton.xaml" XamlRuntime="$(DefaultXamlRuntime)" />
Expand Down
Binary file modified GetStoreApp/GetStoreApp.res
Binary file not shown.
6 changes: 3 additions & 3 deletions GetStoreApp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
[assembly: AssemblyCompany("高怡飞")]
[assembly: AssemblyCopyright("Copyright ©2022-2024 高怡飞, All Rights Reserved.")]
[assembly: AssemblyDescription("获取商店应用")]
[assembly: AssemblyFileVersion("5.0.929.0")]
[assembly: AssemblyInformationalVersion("5.0.929.0")]
[assembly: AssemblyFileVersion("5.0.1001.0")]
[assembly: AssemblyInformationalVersion("5.0.1001.0")]
[assembly: AssemblyProduct("获取商店应用")]
[assembly: AssemblyTitle("获取商店应用")]
[assembly: AssemblyVersion("5.0.929.0")]
[assembly: AssemblyVersion("5.0.1001.0")]

// 应用程序默认区域性的资源控制器设置
[assembly: NeutralResourcesLanguage("en-us")]
Expand Down
1 change: 1 addition & 0 deletions GetStoreApp/Views/Pages/AboutPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public bool IsChecking
new DictionaryEntry("Microsoft.Windows.SDK.BuildTools","https://aka.ms/WinSDKProjectURL"),
new DictionaryEntry("Microsoft.WindowsAppSDK","https://github.com/microsoft/windowsappsdk"),
new DictionaryEntry("Microsoft.WindowsPackageManager.ComInterop", "https://github.com/microsoft/winget-cli"),
new DictionaryEntry("Mile.Xaml", "https://github.com/ProjectMile/Mile.Xaml"),
];

//项目感谢者信息
Expand Down
2 changes: 1 addition & 1 deletion GetStoreApp/WindowsAPI/PInvoke/Kernel32/Kernel32Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static partial class Kernel32Library
/// <returns>如果该函数成功,则返回值为非零值。如果函数失败,则返回值为零。 要获得更多的错误信息,请调用 GetLastError。</returns>
[LibraryImport(Kernel32, EntryPoint = "ReadConsoleW", SetLastError = false), PreserveSig]
[return: MarshalAs(UnmanagedType.Bool)]
public static partial bool ReadConsole(IntPtr hConsoleInput, [Out] byte[] lpBuffer, int nNumberOfCharsToRead, out int lpNumberOfCharsRead, IntPtr pInputControl);
public static partial bool ReadConsole(IntPtr hConsoleInput, [Out, MarshalAs(UnmanagedType.LPArray)] byte[] lpBuffer, int nNumberOfCharsToRead, out int lpNumberOfCharsRead, IntPtr pInputControl);

/// <summary>
/// 设置由 WriteFile 或 WriteConsole 函数写入控制台屏幕缓冲区或由 ReadFile 或 ReadConsole 函数回显的字符的属性。 此函数会影响函数调用后写入的文本。
Expand Down
2 changes: 1 addition & 1 deletion GetStoreApp/WindowsAPI/PInvoke/User32/User32Library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static partial class User32Library
/// 如果 <param name="phicon"> 参数为 NULL 且此函数成功,则返回值为文件中的图标数。 如果函数失败,则返回值为 0。 如果 <param name="phicon"> 参数不是 NULL 且函数成功,则返回值是提取的图标数。 否则,如果未找到文件,则返回值0xFFFFFFFF。
/// </returns>
[LibraryImport(User32, EntryPoint = "PrivateExtractIconsW", SetLastError = false, StringMarshalling = StringMarshalling.Utf16), PreserveSig]
public static partial int PrivateExtractIcons([MarshalAs(UnmanagedType.LPWStr)] string lpszFile, int nIconIndex, int cxIcon, int cyIcon, [Out] IntPtr[] phicon, [Out] int[] piconid, int nIcons, int flags);
public static partial int PrivateExtractIcons([MarshalAs(UnmanagedType.LPWStr)] string lpszFile, int nIconIndex, int cxIcon, int cyIcon, [Out, MarshalAs(UnmanagedType.LPArray)] IntPtr[] phicon, [Out, MarshalAs(UnmanagedType.LPArray)] int[] piconid, int nIcons, int flags);

/// <summary>
/// 将指定的消息发送到窗口或窗口。 SendMessage 函数调用指定窗口的窗口过程,在窗口过程处理消息之前不会返回。
Expand Down
Binary file modified GetStoreAppInstaller/GetStoreAppInstaller.res
Binary file not shown.
34 changes: 34 additions & 0 deletions GetStoreAppInstaller/Helpers/Backdrop/BackdropHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Windows.System;
using Windows.UI.Composition.Desktop;
using Windows.UI.Xaml;
using WindowsTools.WindowsAPI.ComTypes;

namespace GetStoreAppInstaller.Helpers.Backdrop
{
/// <summary>
/// 背景色辅助类
/// </summary>
public static class BackdropHelper
{
/// <summary>
/// 初始化 DesktopWindowTarget(表示作为合成目标的窗口)
/// </summary>
public static DesktopWindowTarget InitializeDesktopWindowTarget(IntPtr handle, bool isTopMost)
{
if (handle == nint.Zero)
{
throw new NullReferenceException("窗口句柄无效");
}

IntPtr desktopWindowTargetPtr = IntPtr.Zero;
if (DispatcherQueue.GetForCurrentThread() is not null)
{
ICompositorDesktopInterop interop = Window.Current.Compositor as object as ICompositorDesktopInterop;
interop.CreateDesktopWindowTarget(handle, isTopMost, out desktopWindowTargetPtr);
}

return desktopWindowTargetPtr != IntPtr.Zero ? DesktopWindowTarget.FromAbi(desktopWindowTargetPtr) : null;
}
}
}
6 changes: 3 additions & 3 deletions GetStoreAppInstaller/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
[assembly: AssemblyCompany("高怡飞")]
[assembly: AssemblyCopyright("Copyright ©2022-2024 高怡飞, All Rights Reserved.")]
[assembly: AssemblyDescription("获取商店应用 应用安装器")]
[assembly: AssemblyFileVersion("5.0.929.0")]
[assembly: AssemblyInformationalVersion("5.0.929.0")]
[assembly: AssemblyFileVersion("5.0.1001.0")]
[assembly: AssemblyInformationalVersion("5.0.1001.0")]
[assembly: AssemblyProduct("获取商店应用 应用安装器")]
[assembly: AssemblyTitle("获取商店应用 应用安装器")]
[assembly: AssemblyVersion("5.0.929.0")]
[assembly: AssemblyVersion("5.0.1001.0")]

// 应用程序默认区域性的资源控制器设置
[assembly: NeutralResourcesLanguage("en-us")]
Expand Down
96 changes: 96 additions & 0 deletions GetStoreAppInstaller/UI/Backdrop/BlendEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using GetStoreAppInstaller.WindowsAPI.ComTypes;
using System;
using System.Runtime.InteropServices;
using Windows.Foundation;
using Windows.Graphics.Effects;

namespace GetStoreAppInstaller.UI.Backdrop
{
[Guid("81C5B77B-13F8-4CDD-AD20-C890547AC65D")]
public sealed partial class BlendEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop
{
private readonly IPropertyValueStatics propertyValue = PropertyValue.As<IPropertyValueStatics>();

public BlendEffectMode Mode { get; set; } = BlendEffectMode.Multiply;

public string Name { get; set; } = string.Empty;

public IGraphicsEffectSource Background { get; set; }

public IGraphicsEffectSource Foreground { get; set; }

public int GetEffectId(out Guid id)
{
id = typeof(BlendEffect).GUID;
return 0;
}

public int GetNamedPropertyMapping(IntPtr name, out uint index, out GRAPHICS_EFFECT_PROPERTY_MAPPING mapping)
{
switch (Marshal.PtrToStringUni(name))
{
case nameof(Mode):
{
index = 0;
mapping = GRAPHICS_EFFECT_PROPERTY_MAPPING.GRAPHICS_EFFECT_PROPERTY_MAPPING_DIRECT;
break;
}
default:
{
index = 0xFF;
mapping = (GRAPHICS_EFFECT_PROPERTY_MAPPING)0xFF;
break;
}
}

return 0;
}

public int GetProperty(uint index, out IntPtr source)
{
if (index is 0)
{
propertyValue.CreateUInt32((uint)Mode, out IntPtr ptr);
if (ptr != IntPtr.Zero)
{
source = ptr;
return 0;
}
}

source = IntPtr.Zero;
return -2147483637;
}

public int GetPropertyCount(out uint count)
{
count = 1;
return 0;
}

public int GetSource(uint index, out IGraphicsEffectSource source)
{
if (index is 0)
{
source = Background;
return 0;
}
else if (index is 1)
{
source = Foreground;
return 0;
}
else
{
source = null;
return 2147483637;
}
}

public int GetSourceCount(out uint count)
{
count = 2;
return 0;
}
}
}
32 changes: 32 additions & 0 deletions GetStoreAppInstaller/UI/Backdrop/BlendEffectMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
namespace GetStoreAppInstaller.UI.Backdrop
{
public enum BlendEffectMode
{
Multiply = 0,
Screen = 1,
Darken = 2,
Lighten = 3,
Dissolve = 4,
ColorBurn = 5,
LinearBurn = 6,
DarkerColor = 7,
LighterColor = 8,
ColorDodge = 9,
LinearDodge = 10,
Overlay = 11,
SoftLight = 12,
HardLight = 13,
VividLight = 14,
LinearLight = 15,
PinLight = 16,
HardMix = 17,
Difference = 18,
Exclusion = 19,
Hue = 20,
Saturation = 21,
Color = 22,
Luminosity = 23,
Subtract = 24,
Division = 25
}
}
108 changes: 108 additions & 0 deletions GetStoreAppInstaller/UI/Backdrop/BorderEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using GetStoreAppInstaller.WindowsAPI.ComTypes;
using System;
using System.Runtime.InteropServices;
using Windows.Foundation;
using Windows.Graphics.Effects;

namespace GetStoreAppInstaller.UI.Backdrop
{
[Guid("2A2D49C0-4ACF-43C7-8C6A-7C4A27874D27")]
public sealed partial class BorderEffect : IGraphicsEffect, IGraphicsEffectSource, IGraphicsEffectD2D1Interop
{
private readonly IPropertyValueStatics propertyValue = PropertyValue.As<IPropertyValueStatics>();

public string Name { get; set; } = string.Empty;

public CanvasEdgeBehavior ExtendX { get; set; } = CanvasEdgeBehavior.Clamp;

public CanvasEdgeBehavior ExtendY { get; set; } = CanvasEdgeBehavior.Clamp;

public IGraphicsEffectSource Source { get; set; }

public int GetEffectId(out Guid id)
{
id = typeof(BorderEffect).GUID;
return 0;
}

public int GetNamedPropertyMapping(IntPtr name, out uint index, out GRAPHICS_EFFECT_PROPERTY_MAPPING mapping)
{
switch (Marshal.PtrToStringUni(name))
{
case nameof(ExtendX):
{
index = 0;
mapping = GRAPHICS_EFFECT_PROPERTY_MAPPING.GRAPHICS_EFFECT_PROPERTY_MAPPING_DIRECT;
break;
}
case nameof(ExtendY):
{
index = 1;
mapping = GRAPHICS_EFFECT_PROPERTY_MAPPING.GRAPHICS_EFFECT_PROPERTY_MAPPING_DIRECT;
break;
}
default:
{
index = 0xFF;
mapping = (GRAPHICS_EFFECT_PROPERTY_MAPPING)0xFF;
break;
}
}

return 0;
}

public int GetProperty(uint index, out IntPtr source)
{
if (index is 0)
{
propertyValue.CreateUInt32((uint)ExtendX, out IntPtr ptr);

if (ptr != IntPtr.Zero)
{
source = ptr;
return 0;
}
}
else if (index is 1)
{
propertyValue.CreateUInt32((uint)ExtendY, out IntPtr ptr);

if (ptr != IntPtr.Zero)
{
source = ptr;
return 0;
}
}

source = IntPtr.Zero;
return -2147483637;
}

public int GetPropertyCount(out uint count)
{
count = 2;
return 0;
}

public int GetSource(uint index, out IGraphicsEffectSource source)
{
if (index is 0)
{
source = Source;
return 0;
}
else
{
source = null;
return 2147483637;
}
}

public int GetSourceCount(out uint count)
{
count = 1;
return 0;
}
}
}
19 changes: 19 additions & 0 deletions GetStoreAppInstaller/UI/Backdrop/CanvasComposite.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace GetStoreAppInstaller.UI.Backdrop
{
public enum CanvasComposite
{
SourceOver = 0,
DestinationOver = 1,
SourceIn = 2,
DestinationIn = 3,
SourceOut = 4,
DestinationOut = 5,
SourceAtop = 6,
DestinationAtop = 7,
Xor = 8,
Add = 9,
Copy = 10,
BoundedCopy = 11,
MaskInvert = 12
}
}
9 changes: 9 additions & 0 deletions GetStoreAppInstaller/UI/Backdrop/CanvasEdgeBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GetStoreAppInstaller.UI.Backdrop
{
public enum CanvasEdgeBehavior
{
Clamp = 0,
Wrap = 1,
Mirror = 2
}
}
Loading

0 comments on commit a3fb81d

Please sign in to comment.