Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no documented API for this. That's entirely by design: this setting is intended to be changed by the <em>user</em>, not by applications. And there's a built-in applet for the user to use to do this: the Personalize control panel.</p> <p>But like the code that you've got hints at, there is an <em>undocumented</em> API that you can use—<code>DwmSetColorizationParameters</code>. You just need to carefully test that your code works on all targeted operating systems and be aware that it is subject to break with any new versions of Windows and/or any updates to the current version of Windows.</p> <p>I know that it used to work in Windows 7, but I haven't tested it with all of the latest service packs and other updates, nor do I have any idea if it works in Windows 8. That's all up to you to test. Using undocumented APIs is a lot of work.</p> <p>You're lucky, though. <a href="http://theroadtodelphi.wordpress.com/2011/05/05/changing-the-glass-composition-color-dwm-using-delphi/" rel="nofollow noreferrer">Someone else</a> has already done the reverse engineering for you. (And probably other people, too, like the person who wrote the code you show in your question. It would be nice to give them credit. Maybe it was <a href="https://stackoverflow.com/a/1813169/366904">this guy</a>?)</p> <p>Here's how you use it:</p> <pre><code>using System; using System.Drawing; using System.Globalization; using System.Runtime.InteropServices; class DwmManager { private struct DWM_COLORIZATION_PARAMS { public uint clrColor; public uint clrAfterGlow; public uint nIntensity; public uint clrAfterGlowBalance; public uint clrBlurBalance; public uint clrGlassReflectionIntensity; public bool fOpaque; } [DllImport("dwmapi.dll", EntryPoint = "#127", PreserveSig = false)] private static extern void DwmGetColorizationParameters(out DWM_COLORIZATION_PARAMS parameters); [DllImport("dwmapi.dll", EntryPoint = "#131", PreserveSig = false)] private static extern void DwmSetColorizationParameters(ref DWM_COLORIZATION_PARAMS parameters, bool unknown); // Helper method to convert from a Win32 BGRA-format color to a .NET color. private static Color BgraToColor(uint color) { return Color.FromArgb(Int32.Parse(color.ToString("X"), NumberStyles.HexNumber)); } // Helper method to convert from a .NET color to a Win32 BGRA-format color. private static uint ColorToBgra(Color color) { return (uint)(color.B | (color.G &lt;&lt; 8) | (color.R &lt;&lt; 16) | (color.A &lt;&lt; 24)); } // Gets or sets the current color used for DWM glass, based on the user's color scheme. public static Color ColorizationColor { get { // Call the DwmGetColorizationParameters function to fill in our structure. DWM_COLORIZATION_PARAMS parameters; DwmGetColorizationParameters(out parameters); // Convert the colorization color to a .NET color and return it. return BgraToColor(parameters.clrColor); } set { // Retrieve the current colorization parameters, just like we did above. DWM_COLORIZATION_PARAMS parameters; DwmGetColorizationParameters(out parameters); // Then modify the colorization color. // Note that the other parameters are left untouched, so they will stay the same. // You can also modify these; that is left as an exercise. parameters.clrColor = ColorToBgra(value); // Call the DwmSetColorizationParameters to make the change take effect. DwmSetColorizationParameters(ref parameters, false); } } } </code></pre> <p>Once you've got that class added to your project, you interact with it through the <code>ColorizationColor</code> property. Like the comments say, the <code>DWM_COLORIZATION_PARAMS</code> structure gives you a <em>lot</em> more information. You could add properties to get/set each of these additional parameters, if you like. Although it'll take some experimentation to figure out exactly what they do.</p> <p>Note that you also need to check that DWM composition is supported and enabled by the host operating system <em>before</em> running any of these functions. (Otherwise, the <code>PreserveSig</code> attribute will ensure that an exception is thrown.) This is fairly obvious, but worth mentioning anyway. To do that, you will also need this function:</p> <pre><code>[DllImport("dwmapi.dll")] private static extern int DwmIsCompositionEnabled(ref bool pfEnabled); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload