C# 透明控制台DllImport

C# 透明控制台DllImport,c#,dllimport,C#,Dllimport,我希望控制台透明,但我有一个编译错误: Transparency.cs(39,48):错误CS0019:运算符“^”不能应用于“System.IntPtr”和“int”类型的操作数 using System; using System.Runtime.InteropServices; namespace Transparency { class Program { [DllImport("user32.dll")] static extern i

我希望控制台透明,但我有一个编译错误: Transparency.cs(39,48):错误CS0019:运算符“^”不能应用于“System.IntPtr”和“int”类型的操作数

using System;
using System.Runtime.InteropServices;

namespace Transparency
{
    class Program
    {
        [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(); 

        static void Main(string[] args)
        {
            int GWL_EXSTYLE = -20;
            int WS_EX_LAYERED = 0x80000;
            uint LWA_ALPHA = 0x2;
            //int LWA_COLORKEY = 0x1;

            // Obtain our handle (hWnd)
            IntPtr Handle = GetConsoleWindow();
            SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) ^ WS_EX_LAYERED);
            // Opacity = 0.5 = (255/2)
            SetLayeredWindowAttributes(Handle, 0, 128, LWA_ALPHA);
        }
    }
}

我认为您需要按位or,即单管道
,以及将
GetWindowLong
的返回类型更改为
int
。看