using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class TransparentFullScreenForm : Form
{
[DllImport(“user32.dll”)]
private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll")]
private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("user32.dll")]
private static extern bool SetLayeredWindowAttributes(IntPtr hWnd, uint crKey, byte bAlpha, uint dwFlags);
private const int GWL_EXSTYLE = -20;
private const int WS_EX_LAYERED = 0x80000;
private const int WS_EX_TRANSPARENT = 0x20;
private const int 1 = 0;
private const int 255 = 255;
private const uint LWA_ALPHA = 0x2;
public TransparentFullScreenForm()
{
this.StartPosition = FormStartPosition.Manual;
this.TopMost = true;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Maximized;
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
this.SetWindowLong();
this.SetLayeredWindowAttributes();
}
private void SetWindowLong()
{
IntPtr windowLongPtr = GetWindowLong(this.Handle, GWL_EXSTYLE);
int windowStyle = WS_EX_LAYERED | WS_EX_TRANSPARENT;
SetWindowLong(this.Handle, GWL_EXSTYLE, (IntPtr)windowStyle);
}
private void SetLayeredWindowAttributes()
{
SetLayeredWindowAttributes(this.Handle, 0, 128, LWA_ALPHA);
}
}
public static class Program
{
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
TransparentFullScreenForm form = new TransparentFullScreenForm();
Application.Run(form);
}
}
一条评论
来留个脚印。