【问题标题】:Transparent console DllImport透明控制台 DllImport
【发布时间】:2014-06-08 20:39:42
【问题描述】:

我希望控制台透明,但出现编译错误: 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);
        }
    }
}

【问题讨论】:

    标签: c# dllimport


    【解决方案1】:

    我认为您需要按位或哪个是单管道 | 以及将 GetWindowLong 的返回类型更改为 int。见pinvoke.net

    【讨论】:

      猜你喜欢
      • 2012-03-28
      • 2011-12-14
      • 2011-01-25
      • 1970-01-01
      • 2017-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      相关资源
      最近更新 更多