لا يمكنني تعيين شفافية من النافذة عن طريق مقبضها في C #؟

StackOverflow https://stackoverflow.com/questions/1270316

  •  13-09-2019
  •  | 
  •  

سؤال

أحاول ضبط شفافية جميع النوافذ. لدي ما بعد التعليمات البرمجية.

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 الذي اختبرته عليه. الآن سأضطر إلى تعديل التعليمات البرمجية للحصول على Windows مرة أخرى؛) لحسن الحظ، كانت نافذة Visual Studio 2010 غير متأثرة.

نصائح أخرى

هذا الجزء من التعليمات البرمجية الخاصة بك: ^ WS_EX_LAYERED تقلب قليلا WS_EX_LAYERED،

أعتقد أنك تريد: | WS_EX_LAYERED

هل حاولت الإعداد العتامة?

this.Opacity = 0.50;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top