Guest User

TransparentTaskbar

a guest
Aug 3rd, 2016
1,210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. using System;
  2. using System.Runtime.InteropServices;
  3.  
  4. public class TransparentTaskbar {
  5.     static class Interop {
  6.         [DllImport("user32.dll", SetLastError = true)]
  7.         internal static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  8.        
  9.         [DllImport("user32.dll")]
  10.         internal static extern int SetWindowCompositionAttribute(IntPtr hwnd, ref WindowCompositionAttributeData data);
  11.  
  12.         [StructLayout(LayoutKind.Sequential)]
  13.         internal struct WindowCompositionAttributeData {
  14.             public WindowCompositionAttribute Attribute;
  15.             public IntPtr Data;
  16.             public int SizeOfData;
  17.         }
  18.  
  19.         [StructLayout(LayoutKind.Sequential)]
  20.         internal struct AccentPolicy {
  21.             public AccentState AccentState;
  22.             public AccentFlags AccentFlags;
  23.             public uint GradientColor;
  24.             public int AnimationId;
  25.         }
  26.  
  27.         [Flags]
  28.         internal enum AccentFlags {
  29.             // ...
  30.             DrawLeftBorder = 0x20,
  31.             DrawTopBorder = 0x40,
  32.             DrawRightBorder = 0x80,
  33.             DrawBottomBorder = 0x100,
  34.             DrawAllBorders = (DrawLeftBorder | DrawTopBorder | DrawRightBorder | DrawBottomBorder)
  35.             // ...
  36.         }
  37.  
  38.         internal enum WindowCompositionAttribute {
  39.             // ...
  40.             WCA_ACCENT_POLICY = 19
  41.             // ...
  42.         }
  43.  
  44.         internal enum AccentState {
  45.             ACCENT_DISABLED = 0,
  46.             ACCENT_ENABLE_GRADIENT = 1,
  47.             ACCENT_ENABLE_TRANSPARENTGRADIENT = 2,
  48.             ACCENT_ENABLE_BLURBEHIND = 3,
  49.             ACCENT_INVALID_STATE = 4
  50.         }
  51.     }
  52.  
  53.     public static void Main(string[] CommandLine) {
  54.         var accent = new Interop.AccentPolicy();
  55.         accent.AccentState = Interop.AccentState.ACCENT_ENABLE_BLURBEHIND;
  56.  
  57.         var accentPtr = Marshal.AllocHGlobal(Marshal.SizeOf(accent));
  58.         Marshal.StructureToPtr(accent, accentPtr, false);
  59.  
  60.         var data = new Interop.WindowCompositionAttributeData();
  61.         data.Attribute = Interop.WindowCompositionAttribute.WCA_ACCENT_POLICY;
  62.         data.SizeOfData = Marshal.SizeOf(accent);
  63.         data.Data = accentPtr;
  64.  
  65.         Interop.SetWindowCompositionAttribute(Interop.FindWindow("Shell_TrayWnd", null), ref data);
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment