mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using System.Text;
|
|
using System.Windows.Media;
|
|
using Microsoft.Win32;
|
|
|
|
namespace Flow.Launcher.Helper;
|
|
|
|
public static class WallpaperPathRetrieval
|
|
{
|
|
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
|
private static extern Int32 SystemParametersInfo(UInt32 action,
|
|
Int32 uParam, StringBuilder vParam, UInt32 winIni);
|
|
private static readonly UInt32 SPI_GETDESKWALLPAPER = 0x73;
|
|
private static int MAX_PATH = 260;
|
|
|
|
public static string GetWallpaperPath()
|
|
{
|
|
var wallpaper = new StringBuilder(MAX_PATH);
|
|
SystemParametersInfo(SPI_GETDESKWALLPAPER, MAX_PATH, wallpaper, 0);
|
|
|
|
var str = wallpaper.ToString();
|
|
if (string.IsNullOrEmpty(str))
|
|
return null;
|
|
|
|
return str;
|
|
}
|
|
|
|
public static Color GetWallpaperColor()
|
|
{
|
|
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Colors", true);
|
|
var result = key?.GetValue("Background", null);
|
|
if (result is string strResult)
|
|
{
|
|
try
|
|
{
|
|
var parts = strResult.Trim().Split(new[] {' '}, 3).Select(byte.Parse).ToList();
|
|
return Color.FromRgb(parts[0], parts[1], parts[2]);
|
|
}
|
|
catch
|
|
{
|
|
}
|
|
}
|
|
return Colors.Transparent;
|
|
}
|
|
}
|