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
