2014-06-08 48 views
0

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

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); 
     } 
    } 
} 

回答

2

我想你需要按位或者是单管|以及改变返回类型为GetWindowLongint。请参阅pinvoke.net