<i id='aFO3l'><tr id='aFO3l'><dt id='aFO3l'><q id='aFO3l'><span id='aFO3l'><b id='aFO3l'><form id='aFO3l'><ins id='aFO3l'></ins><ul id='aFO3l'></ul><sub id='aFO3l'></sub></form><legend id='aFO3l'></legend><bdo id='aFO3l'><pre id='aFO3l'><center id='aFO3l'></center></pre></bdo></b><th id='aFO3l'></th></span></q></dt></tr></i><div id='aFO3l'><tfoot id='aFO3l'></tfoot><dl id='aFO3l'><fieldset id='aFO3l'></fieldset></dl></div>

      <small id='aFO3l'></small><noframes id='aFO3l'>

    1. <legend id='aFO3l'><style id='aFO3l'><dir id='aFO3l'><q id='aFO3l'></q></dir></style></legend>
      <tfoot id='aFO3l'></tfoot>

        <bdo id='aFO3l'></bdo><ul id='aFO3l'></ul>
    2. C# 控制台获取 Windows 10 强调色

      C# console get Windows 10 Accent Color(C# 控制台获取 Windows 10 强调色)
        <tbody id='SPb02'></tbody>
        <bdo id='SPb02'></bdo><ul id='SPb02'></ul>
        <tfoot id='SPb02'></tfoot>

        <legend id='SPb02'><style id='SPb02'><dir id='SPb02'><q id='SPb02'></q></dir></style></legend>
          <i id='SPb02'><tr id='SPb02'><dt id='SPb02'><q id='SPb02'><span id='SPb02'><b id='SPb02'><form id='SPb02'><ins id='SPb02'></ins><ul id='SPb02'></ul><sub id='SPb02'></sub></form><legend id='SPb02'></legend><bdo id='SPb02'><pre id='SPb02'><center id='SPb02'></center></pre></bdo></b><th id='SPb02'></th></span></q></dt></tr></i><div id='SPb02'><tfoot id='SPb02'></tfoot><dl id='SPb02'><fieldset id='SPb02'></fieldset></dl></div>

          <small id='SPb02'></small><noframes id='SPb02'>

              • 本文介绍了C# 控制台获取 Windows 10 强调色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                .Net Core 2.X 中有没有办法在控制台应用程序中读取选定的 Windows 10 强调色.

                Is there a way in .Net Core 2.X to read the Selected Windows 10 Accent Color in a Console Application.

                我发现的大多数解决方案都是 UWP 或 WPF 应用程序.

                Most of the solution I found are UWP or WPF apps.

                也告诉你我的意思是哪种颜色,这是它的图片:

                Too show you which color I mean, here is a picture of it:

                推荐答案

                HKEY_CURRENT_USERSoftwareMicrosoftWindowsDWM - 存储所有装饰颜色.因此,如果应用程序以 HKEY_CURRENT_USER 权限启动,您可以读取或更改AccentColor"属性(和目录中的其他人)或自行更改十六进制表示法的颜色代码.

                HKEY_CURRENT_USERSoftwareMicrosoftWindowsDWM - Stores all decoration colors. So if app launched with rights to HKEY_CURRENT_USER you can read or change "AccentColor" property (and others in directory) or change the color code in hexadecimal notation on your own.

                要访问 Windows 注册表,您需要安装软件包:https://www.nuget.org/packages/Microsoft.Windows.Compatibility/

                To get access to windows registry you need to install package: https://www.nuget.org/packages/Microsoft.Windows.Compatibility/

                这里关于包裹的信息:https://docs.microsoft.com/en-us/dotnet/core/porting/windows-compat-pack/

                颜色值以 ABGR 顺序存储为注册表 DWORD(32 位整数)值(相对于 ARGBRGBA 顺序).

                The color values are stored as Registry DWORD (32-bit integer) values in ABGR order (as opposed to ARGB or RGBA order).

                using Microsoft.Win32;
                
                public static ( Byte r, Byte g, Byte b, Byte a ) GetAccentColor()
                {
                    const String DWM_KEY = @"SoftwareMicrosoftWindowsDWM";
                    using( RegistryKey dwmKey = Registry.CurrentUser.OpenSubKey( DWM_KEY, RegistryKeyPermissionCheck.ReadSubTree ) )
                    {
                        const String KEY_EX_MSG = "The "HKCU\" + DWM_KEY + "" registry key does not exist.";
                        if( dwmKey is null ) throw new InvalidOperationException( KEY_EX_MSG );
                
                        Object accentColorObj = dwmKey.GetValue( "AccentColor" );
                        if( accentColorObj is Int32 accentColorDword )
                        {
                            return ParseDWordColor( accentColorDword );
                        }
                        else
                        {
                            const String VALUE_EX_MSG = "The "HKCU\" + DWM_KEY + "\AccentColor" registry key value could not be parsed as an ABGR color.";
                            throw new InvalidOperationException( VALUE_EX_MSG );
                        }
                    }
                
                }
                
                private static ( Byte r, Byte g, Byte b, Byte a ) ParseDWordColor( Int32 color )
                {
                    Byte
                        a = ( color >> 24 ) & 0xFF,
                        b = ( color >> 16 ) & 0xFF,
                        g = ( color >>  8 ) & 0xFF,
                        r = ( color >>  0 ) & 0xFF;
                
                    return ( r, g, b, a );
                }
                
                

                这篇关于C# 控制台获取 Windows 10 强调色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)

                  <tbody id='VN7H3'></tbody>

                <small id='VN7H3'></small><noframes id='VN7H3'>

                • <tfoot id='VN7H3'></tfoot>

                          <bdo id='VN7H3'></bdo><ul id='VN7H3'></ul>

                          <legend id='VN7H3'><style id='VN7H3'><dir id='VN7H3'><q id='VN7H3'></q></dir></style></legend>
                          <i id='VN7H3'><tr id='VN7H3'><dt id='VN7H3'><q id='VN7H3'><span id='VN7H3'><b id='VN7H3'><form id='VN7H3'><ins id='VN7H3'></ins><ul id='VN7H3'></ul><sub id='VN7H3'></sub></form><legend id='VN7H3'></legend><bdo id='VN7H3'><pre id='VN7H3'><center id='VN7H3'></center></pre></bdo></b><th id='VN7H3'></th></span></q></dt></tr></i><div id='VN7H3'><tfoot id='VN7H3'></tfoot><dl id='VN7H3'><fieldset id='VN7H3'></fieldset></dl></div>