Pregunta

Estoy tratando de establecer la transparencia de todas las ventanas. He siguiente 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);
        }

    }
}

No ocurre nada cuando ejecutar el código.

Lo que está mal ??

¿Fue útil?

Solución

SetWindowLong toma un identificador de ventana (hWnd), pero estás pasando un identificador de proceso en su lugar. Cambiar todas las instancias de

theprocess.Handle

a

theProcess.MainWindowHandle

Después de cambiar eso, se trabajó en la máquina Windows XP he comprobado en. Ahora voy a tener que modificar el código para obtener las ventanas de volver a la normalidad;) Afortunadamente, la ventana de Visual Studio 2010 no se vio afectada

.

Otros consejos

Esta parte de su código: ^ WS_EX_LAYERED voltea el bit WS_EX_LAYERED,

Creo que desee: | WS_EX_LAYERED

¿Usted ha intentado establecer la opacidad

this.Opacity = 0.50;
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top