From abb32e9ed29e485e782a6b5e87aa0c80ced622aa Mon Sep 17 00:00:00 2001 From: ww-rm Date: Sun, 20 Apr 2025 16:13:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=80=E4=BA=9B=E5=A5=87?= =?UTF-8?q?=E6=80=AA=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpineViewer/Forms/WallpaperForm.cs | 52 ++++++++++++++++++------------ 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/SpineViewer/Forms/WallpaperForm.cs b/SpineViewer/Forms/WallpaperForm.cs index bb4bbb5..cdef080 100644 --- a/SpineViewer/Forms/WallpaperForm.cs +++ b/SpineViewer/Forms/WallpaperForm.cs @@ -23,25 +23,20 @@ namespace SpineViewer InitializeComponent(); } - //protected override CreateParams CreateParams - //{ - // get - // { - // var cp = base.CreateParams; - // cp.ExStyle = Win32.WS_EX_LAYERED; - // return cp; - // } - //} - - //protected override void OnHandleCreated(EventArgs e) - //{ - // base.OnHandleCreated(e); - // Win32.SetLayeredWindowAttributes(Handle, 0, 255, Win32.LWA_ALPHA); - // SetWallpaper(); - //} - - public void SetWallpaper() + protected override CreateParams CreateParams { + get + { + var cp = base.CreateParams; + cp.ExStyle = Win32.WS_EX_TOOLWINDOW | Win32.WS_EX_LAYERED; + return cp; + } + } + + protected override void OnLoad(EventArgs e) + { + base.OnLoad(e); + // 设置成嵌入桌面 var progman = Win32.FindWindow("Progman", null); if (progman != IntPtr.Zero) @@ -51,11 +46,28 @@ namespace SpineViewer var workerW = Win32.GetWorkerW(); if (workerW != IntPtr.Zero) { - Win32.SetWindowLong(Handle, Win32.GWL_EXSTYLE, Win32.GetWindowLong(Handle, Win32.GWL_EXSTYLE) | Win32.WS_EX_LAYERED); Win32.SetLayeredWindowAttributes(Handle, 0, 255, Win32.LWA_ALPHA); - Win32.SetParent(Handle, workerW); + Win32.SetParent(Handle, workerW); // 嵌入之前必须保证有 WS_EX_LAYERED 标志 } } } + + [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] + [Browsable(false)] + public byte LayeredWindowAlpha + { + get + { + uint crKey = 0; + byte bAlpha = 255; + uint dwFlags = Win32.LWA_ALPHA; + Win32.GetLayeredWindowAttributes(Handle, ref crKey, ref bAlpha, ref dwFlags); + return bAlpha; + } + set + { + Win32.SetLayeredWindowAttributes(Handle, 0, value, Win32.LWA_ALPHA); + } + } } }