Advertisement
Jong

SetConsoleAlpha

Feb 16th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1.         static void SetConsoleAlpha(byte alpha)
  2.         {
  3.             IntPtr hwnd = GetConsoleWindow();
  4.             SetWindowLong(hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED);
  5.             SetLayeredWindowAttributes(hwnd, 0, alpha, LWA_ALPHA);
  6.         }
  7.  
  8.         [DllImport("kernel32.dll")]
  9.         static extern IntPtr GetConsoleWindow();
  10.  
  11.         [DllImport("user32.dll")]
  12.         static extern int SetWindowLong(IntPtr hwnd, int nIndex, long dwNewLong);
  13.  
  14.         [DllImport("user32.dll")]
  15.         static extern int GetWindowLong(IntPtr hwnd, int nIndex);
  16.  
  17.         [DllImport("user32.dll")]
  18.         static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
  19.  
  20.         const int GWL_EXSTYLE = -20;
  21.         const int WS_EX_LAYERED = 0x80000;
  22.         const int LWA_ALPHA = 0x2;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement