Question

Je suis en train de mettre la transparence de toutes les fenêtres. Je code suivant.

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

    }
}

rien ne se passe quand j'exécute le code.

Qu'est-ce qui ne va pas ??

Était-ce utile?

La solution

SetWindowLong prend une poignée de fenêtre (hWnd), mais vous passez une poignée de processus à la place. Remplacez toutes les instances de

theprocess.Handle

à

theProcess.MainWindowHandle

Après avoir changé cela, il a travaillé sur la machine Windows XP je l'ai testé sur. Maintenant, je vais devoir modifier le code pour obtenir les fenêtres à la normale;) Heureusement, la fenêtre Visual Studio 2010 n'a pas été affectée

.

Autres conseils

Cette partie de votre code: ^ WS_EX_LAYERED retourne le bit WS_EX_LAYERED,

Je pense que vous voulez: | WS_EX_LAYERED

Avez-vous essayé d'installer le Opacité ?

this.Opacity = 0.50;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top