我想设置所有窗口的透明度。我有以下代码。

public partial class Form1 : Form
{
    [DllImport("user32.dll")]
    static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

    [DllImport("user32.dll")]
    static extern int GetWindowLong(IntPtr hWnd, int nIndex);

    [DllImport("user32.dll")]
    static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);

    public const int GWL_EXSTYLE = -20;
    public const int WS_EX_LAYERED = 0x80000;
    public const int LWA_ALPHA = 0x2;

    public Form1()
    {
        InitializeComponent();
        this.Load += new EventHandler(Form1_Load);
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        Process[] processlist = Process.GetProcesses();

        foreach (Process theprocess in processlist)
        {
            SetWindowLong(theprocess.Handle, GWL_EXSTYLE,
                GetWindowLong(theprocess.Handle, GWL_EXSTYLE) ^ WS_EX_LAYERED);
            SetLayeredWindowAttributes(theprocess.Handle, 0, 128, LWA_ALPHA);
        }

    }
}

当我执行代码没有反应。

什么错误??

有帮助吗?

解决方案

SetWindowLong需要一个窗口句柄(HWND),但你传递一个进程句柄来代替。 改变的所有实例

theprocess.Handle

theProcess.MainWindowHandle

改变在此之后,它的工作我测试了它在Windows XP计算机上。现在,我要必须修改代码来获取窗口恢复正常;)幸运的是,Visual Studio 2010的窗口并没有受到影响。

其他提示

您这部分代码:^ WS_EX_LAYERED翻转WS_EX_LAYERED位

我想你想:| WS_EX_LAYERED

你有没有尝试设置不透明度

this.Opacity = 0.50;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top