DwmManager.cs :  » GUI » LongBar » Slate » DWM » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » GUI » LongBar 
LongBar » Slate » DWM » DwmManager.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using System.Drawing;

namespace Slate.DWM{
    public class DwmManager
    {
        [DllImport("dwmapi.dll")]
        private static extern int DwmEnableBlurBehindWindow(IntPtr hWnd, ref BB_Struct BlurBehind);
        [DllImport("dwmapi.dll")]
        private static extern void DwmIscompositionEnabled(ref bool result);
        [DllImport("dwmapi.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern void DwmGetColorizationColor(out int color, out bool opaque);

        [DllImport("dwmapi.dll", PreserveSig = false)]
        public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);

        private struct BB_Struct //Blur Behind Structure
        {
            public BB_Flags flags;
            public bool enable;
            public IntPtr region;
            public bool transitionOnMaximized;
        }

        private enum BB_Flags : byte //Blur Behind Flags
        {
            DWM_BB_ENABLE = 1,
            DWM_BB_BLURREGION = 2,
            DWM_BB_TRANSITIONONMAXIMIZED = 4,
        };

        public static bool IsGlassAvailable() //Check if it is not a Windows Vista or it is a Windows Vista Home Basic
        {
            if (Environment.OSVersion.Version.Major < 6 || Environment.OSVersion.Version.Build < 5600 || !File.Exists(Environment.SystemDirectory + @"\dwmapi.dll"))
                return false;
            else
                return true;
        }

        public static bool EnableGlass(ref IntPtr handle, IntPtr rgn) //Try to enable Aero Glass. If success return true
        {
            Region region = new Region();
            region.MakeInfinite();
            BB_Struct bb = new BB_Struct();
            bb.enable = true;
            bb.flags = BB_Flags.DWM_BB_ENABLE | BB_Flags.DWM_BB_BLURREGION;
            if (region != null)
                bb.region = rgn;
            else
                bb.region = IntPtr.Zero; //Region.GetHrgn(Graphics)
            if (DwmEnableBlurBehindWindow(handle, ref bb) != 0)
                return false;
            else
                return true;
        }

        public static bool DisableGlass(ref IntPtr handle) //Try to disable Aero Glass. If success return true
        {
            Region region = new Region();
            Graphics graphics = Graphics.FromHwnd(handle);
            BB_Struct bb = new BB_Struct();
            bb.enable = false;
            bb.flags = BB_Flags.DWM_BB_ENABLE | BB_Flags.DWM_BB_BLURREGION;
            bb.region = IntPtr.Zero;
            if (DwmEnableBlurBehindWindow(handle, ref bb) != 0)
                return false;
            else
                return true;
        }

        private const int ExcludedFromPeek = 12;
        private const int Flip3D = 8;

        public enum Flip3DPolicy
        {
            Default = 0,
            ExcludeBelow,
            ExcludeAbove
        }

        public static void RemoveFromAeroPeek(IntPtr hwnd)
        {
            if (IsGlassAvailable())
            {
                int attrValue = 1; // True
                DwmSetWindowAttribute(hwnd, 12, ref attrValue, sizeof(int));
            }
        }

        public static void RemoveFromFlip3D(IntPtr hwnd)
        {
            if (IsGlassAvailable())
            {
                int attrValue = (int)Flip3DPolicy.ExcludeBelow; // True
                DwmSetWindowAttribute(hwnd, Flip3D, ref attrValue, sizeof(int));
            }
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.