Hack Forums
[.NET] C# Fade Console Window - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] C# Fade Console Window (/showthread.php?tid=5852269)



C# Fade Console Window - Crakxproo - Jun 21, 2018

Code
[DllImport("user32.dll")]
        static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

        [DllImport("user32.dll")]
        static extern bool SetLayeredWindowAttributes(IntPtr hWnd, uint crKey, byte bAlpha, uint dwFlags);

        [DllImport("user32.dll", SetLastError = true)]
        internal static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);

        [DllImport("kernel32.dll", SetLastError = true)]
        internal static extern IntPtr GetConsoleWindow();


        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;

        IntPtr MainHandle = Process.GetCurrentProcess().MainWindowHandle;
            Int32 Old = (int)GetWindowLong(MainHandle, GWL_EXSTYLE);
            Int32 AlsoOld = SetWindowLong(MainHandle, GWL_EXSTYLE, Old | WS_EX_LAYERED);
            bool result = SetLayeredWindowAttributes(MainHandle, 0, 255 / 2, LWA_ALPHA); // 50% opacity