Pergunta

Eu estou tentando set transparência de todas as janelas. Eu tenho seguinte código.

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

    }
}

nada acontece quando eu executar o código.

O que está errado ??

Foi útil?

Solução

SetWindowLong leva um identificador de janela (hWnd), mas você está passando um identificador de processo em seu lugar. Alterar todas as instâncias de

theprocess.Handle

para

theProcess.MainWindowHandle

Depois de mudar isso, ele trabalhou na máquina Windows XP Eu testei-o em. Agora eu vou ter que modificar o código para obter as janelas de volta ao normal;) Felizmente, a janela Visual Studio 2010 não foi afetado

.

Outras dicas

Esta parte do seu código: ^ WS_EX_LAYERED vira o WS_EX_LAYERED pouco,

Eu acho que você quer: | WS_EX_LAYERED

Você já tentou definir a opacidade ?

this.Opacity = 0.50;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top