Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,

I'm trying to detect the PeekAtDeskTop is enabled/disabled.

What I have tried:

C#
public enum WindowsPeekAtDesktop
{
        Enabled = 1,
        Disabled = 0,
}

[DllImport("dwmapi.dll", PreserveSig = false)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DwmIsCompositionEnabled();

public static WindowsPeekAtDesktop IsPeekAtDesktop()
{
            // Tried using RegistryKey
            //RegistryKey AeroPeek = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\DWM", true);
            //var abc = AeroPeek.GetValue("EnableAeroPeek");
            //var aa = DwmWindowAttribute.DWMWA_EXCLUDED_FROM_PEEK;


            if (Environment.OSVersion.Version.Major >= 6 && DwmIsCompositionEnabled())
                return WindowsPeekAtDesktop.Enabled;
            
            return WindowsPeekAtDesktop.Disabled;
}


If I enabled/disabled peekatdesktop the DwmIsCompositionEnabled() and RegistryKey is always returning true.

Can anyone please help me. How to detect PeekAtDesktop is enabled/disabled.

Thanks in advance
Posted
Updated 1-Jan-20 0:59am
Comments
[no name] 1-Jan-20 9:37am    
Check this for the correct signature: pinvoke.net: dwmiscompositionenabled (dwmapi)[^]

1 solution

Your code is not correct, the function requires an out parameter (see pinvoke.net: dwmiscompositionenabled (dwmapi)[^] ) that gets the setting. If the function succeeds, whichever value is set, it will always return true. See DwmIsCompositionEnabled function (dwmapi.h) - Win32 apps | Microsoft Docs[^] for full details.

[edit]
Added P/Invoke signature thanks to 0X01AA
[/edit]
 
Share this answer
 
v2
Comments
[no name] 1-Jan-20 9:58am    
This sould help for the signature: https://www.pinvoke.net/default.aspx/dwmapi.dwmiscompositionenabled
Richard MacCutchan 1-Jan-20 10:04am    
Thanks, added to Solution with acknowledgement.
abdul subhan mohammed 2-Jan-20 1:03am    
//Peek at desktop
        [DllImport("dwmapi.dll")]
        public static extern int DwmIsCompositionEnabled(out bool enabled);

        public static bool AeroEnabled()
        {
            if (Environment.OSVersion.Version.Major < 6)
                return false;

            bool result;
            DwmIsCompositionEnabled(out result);

            return result;
        }

        public static WindowsPeekAtDesktop IsPeekAtDesktop()
        {            
            return AeroEnabled() ? WindowsPeekAtDesktop.Enable : WindowsPeekAtDesktop.Disable;
        }

I tried the above code but still always its return true eventhough the PeekAtDesktop is disabled.

Please help me.
Richard MacCutchan 2-Jan-20 3:51am    
As stated in the documentation:
Quote: Note As of Windows 8, DWM composition is always enabled.
abdul subhan mohammed 7-Jan-20 2:15am    
I tried to win 10 as well, but still, the result always returning true.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900