OSDN Git Service

#xxxxx FDKのコミット漏れ対応(CWindowsTheme.cs) 。ダークテーマ対応のための下回りだが不完全。
authoryyagi <yyagi.dtxmania@gmail.com>
Wed, 30 Oct 2019 13:52:32 +0000 (22:52 +0900)
committeryyagi <yyagi.dtxmania@gmail.com>
Wed, 30 Oct 2019 13:52:32 +0000 (22:52 +0900)
#xxxxx COS.cs: Windows10のビルド情報を補足。また、OSのビルド番号の確認機能をpublic化。
#xxxxx NVorbisのビルド時警告を抑制。csprojの<NoWarn>は最初の<PropertyGroup>に置かないと機能しないらしい。

FDK/コード/00.共通/COS.cs
FDK/コード/00.共通/CWindowsTheme.cs [new file with mode: 0644]
NVorbis/NVorbis.csproj

index 0a2b5d7..acaee25 100644 (file)
@@ -124,18 +124,18 @@ namespace FDK
                }
                public enum WIN10BUILD : int
                {
-                       TH1 = 10240,
-                       TH2 = 10586,
-                       RS1 = 14393,
-                       RS2 = 15063,
-                       RS3 = 16299,
-                       RS4 = 17134,
-            RS5 = 17763,
-            _19H1 = 18362,
+                       TH1 = 10240,    // 1507: 
+                       TH2 = 10586,    // 1511: November Update
+                       RS1 = 14393,    // 1607: Anniversary Update
+                       RS2 = 15063,    // 1703: Creators Update
+                       RS3 = 16299,    // 1709: Fall Creators Update
+                       RS4 = 17134,    // 1803: April 2018 Update
+            RS5 = 17763,       // 1809: October 2018 Update
+            _19H1 = 18362,     // 1903: May 2019 Update
                        UNKNOWN  = -1,
                        NOTWIN10 = 0
                }
-               private static WIN10BUILD GetWin10BuildNumber()
+               public static WIN10BUILD GetWin10BuildNumber()
                {
                        WIN10BUILD ret = WIN10BUILD.UNKNOWN;
 
diff --git a/FDK/コード/00.共通/CWindowsTheme.cs b/FDK/コード/00.共通/CWindowsTheme.cs
new file mode 100644 (file)
index 0000000..d0f1866
--- /dev/null
@@ -0,0 +1,153 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Runtime.InteropServices;
+using System.Diagnostics;
+using System.Drawing;
+using Microsoft.Win32;
+
+namespace FDK
+{
+       /// <summary>
+       /// Dark theme suuport class
+       /// </summary>
+       /// <remarks>
+       /// http://grabacr.net/archives/6671
+       /// </remarks>
+       public class CWindowsTheme
+    {
+               protected internal static class SafeNativeMethod
+               {
+                       [DllImport("Dwmapi.dll")]
+                       public static extern void DwmGetColorizationColor([Out] out int pcrColorization, [Out] out bool pfOpaqueBlend);
+               }
+
+               /// <summary>
+               /// Get Current Accent Color
+               /// </summary>
+               /// <returns>Accent Color (ARGB)</returns>
+               public Color AccentColor
+               {
+                       get
+                       {
+                               SafeNativeMethod.DwmGetColorizationColor(out int pcrColorization, out bool pfOpaqueBlend);
+                               Trace.TraceInformation($"AccentColor: Color={pcrColorization.ToString("X4")}, Opaque={pfOpaqueBlend}");
+                               return GetColorFromInt(pcrColorization);
+                       }
+               }
+               public Color GetColorFromInt(int color)
+               {
+                       return Color.FromArgb((byte)(color >> 24), (byte)(color >> 16), (byte)(color >> 8), (byte)color);
+               }
+
+
+               /// <summary>
+               /// Get Current Fontcolor.
+               /// </summary>
+               /// <remarks>
+               /// It should be depends on the AccentColor. Need Improvement.
+               /// </remarks>
+               public Color FontColor
+               {
+                       get
+                       {
+                               // it should be depends on the AccentColor. Need Improvement.
+                               if (AppMode == EAppMode.Dark)
+                               {
+                                       return Color.White;
+                               }
+                               else
+                               {
+                                       return Color.Black;
+                               }
+                       }
+               }
+               /// <summary>
+               /// Get Current Backgroundcolor.
+               /// </summary>
+               /// <remarks>
+               /// It should be depends on the AccentColor. Need Improvement.
+               /// </remarks>
+               public Color BackgroundColor
+               {
+                       get
+                       {
+                               // it should be depends on the AccentColor. Need Improvement.
+                               if (AppMode == EAppMode.Dark)
+                               {
+                                       return Color.Black;
+                               }
+                               else
+                               {
+                                       return Color.White;
+                               }
+                       }
+               }
+
+               public enum EAppMode:int
+               {
+                       NotSupported = -1,
+                       Dark  = 0,
+                       Light = 1
+               }
+
+               /// <summary>
+               /// Get Current App Theme (Dark/Light) from registry
+               /// </summary>
+               public EAppMode AppMode
+               {
+                       get
+                       {
+                               #region [If OS doesn't support Dark Theme, return "Not Supported"]
+                               if (!COS.bIsWin10OrLater())
+                               {
+                                       return EAppMode.NotSupported;
+                               }
+                               if (COS.GetWin10BuildNumber() < COS.WIN10BUILD.RS1)
+                               {
+                                       return EAppMode.NotSupported;
+                               }
+                               #endregion
+
+                               #region [Get app theme value from registry]
+                               string rKeyName = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize";
+                               string rGetValueName = "AppsUseLightTheme";
+                               int AppsUseLightTheme = (int)EAppMode.Light;
+                               try
+                               {
+                                       RegistryKey rKey = Registry.CurrentUser.OpenSubKey(rKeyName);
+                                       AppsUseLightTheme = (int)rKey.GetValue(rGetValueName);
+                                       rKey.Close();
+
+                                       Trace.TraceInformation($"Current App Theme = {AppsUseLightTheme}");
+                               }
+                               catch (NullReferenceException)
+                               {
+                                       Trace.TraceWarning($"Warning: No registry key {rKeyName} in {rGetValueName}. Light Theme is assumed.");
+                                       // AppsUseLightTheme = (int)EAppMode.Light;
+                               }
+                               #endregion
+
+                               return (EAppMode)AppsUseLightTheme;
+                       }
+                       //HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize
+                       //AppsUseLightTheme
+               }
+#if false
+if (msg == (int)WindowsMessages.WM_SETTINGCHANGE)
+{
+    var systemParmeter = Marshal.PtrToStringAuto(lParam);
+    if (systemParmeter == "ImmersiveColorSet")
+    {
+        // 再度レジストリから Dark/Light をとってくるとか
+        handled = true;
+    }
+}
+#endif
+
+       }
+
+}
index 32a49a4..c0b87fa 100644 (file)
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
 
   <PropertyGroup>
     <TargetFrameworks>netstandard2.0;net35</TargetFrameworks>
     <RepositoryType>git</RepositoryType>
     <GenerateDocumentationFile>true</GenerateDocumentationFile>
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
+    <NoWarn>1701,1702,1591</NoWarn>
+  </PropertyGroup>
+
+  <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
   </PropertyGroup>
 
 </Project>