Прозрачная консоль C#

kick

Предвестник
Administrator
За веру и верность форуму
Отец-основатель
Сообщения
7 027
Розыгрыши
21
Решения
1
Репутация
5 854
Реакции
6 522
Баллы
2 688
Код:
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
 
namespace GlassExample
{
    class Program
    {
        [DllImport("user32.dll")]
        static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey,
           byte bAlpha, uint dwFlags);
 
        [DllImport("user32.dll")]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
 
        [DllImport("user32.dll", SetLastError = true)]
        private static extern System.UInt32 GetWindowLong(IntPtr hWnd, int nIndex);
 
        public const int GWL_EXSTYLE = -20;
        public const int WS_EX_LAYERED = 0x80000;
        public const int LWA_ALPHA = 0x2;
        public const int LWA_COLORKEY = 0x1;
 
        [StructLayout(LayoutKind.Sequential)]
        public struct DWM_BLURBEHIND
        {
            public DwmBlurBehindDwFlags dwFlags;
            public bool fEnable;
            public IntPtr hRgnBlur;
            public bool fTransitionOnMaximized;
        }
 
        [Flags()]
        public enum DwmBlurBehindDwFlags : uint
        {
            DWM_BB_ENABLE = 0x1,
            DWM_BB_BLURREGION = 0x2,
            DWM_BB_TRANSITIONONMAXIMIZED = 0x4
        }
 
        [DllImport("dwmapi.dll", PreserveSig = false)]
        public static extern void DwmEnableBlurBehindWindow(IntPtr hwnd, ref DWM_BLURBEHIND blurBehind);
 
        static void EnableBlurBehind()
        {
            IntPtr Handle = Process.GetCurrentProcess().MainWindowHandle;
            DWM_BLURBEHIND blur = new DWM_BLURBEHIND();
            blur.dwFlags = DwmBlurBehindDwFlags.DWM_BB_ENABLE;// +DwmBlurBehindDwFlags.DWM_BB_TRANSITIONONMAXIMIZED;
            blur.fEnable = true;
            //blur.hRgnBlur = 0;
            blur.fTransitionOnMaximized = true;// DwmBlurBehindDwFlags.DWM_BB_TRANSITIONONMAXIMIZED;
 
            DwmEnableBlurBehindWindow(Handle, ref blur);
        }
 
        static void MakeTransparent(byte pct)
        {
            IntPtr Handle = Process.GetCurrentProcess().MainWindowHandle;
            int newDwLong = ((int)GetWindowLong(Handle, GWL_EXSTYLE)) ^ WS_EX_LAYERED;
            SetWindowLong(Handle, GWL_EXSTYLE, newDwLong);
            SetLayeredWindowAttributes(Handle, 0, pct, LWA_ALPHA);
        }
 
        static void Main(string[] args)
        {
            EnableBlurBehind();
            MakeTransparent(170);  //0 to 255
 
            Console.WriteLine("Test");
 
            Console.ReadKey();
        }
    }
}
 

Назад
Сверху Снизу