Csharp/C#教程:我不能通过c#中的句柄设置窗口的透明度?分享


我不能通过c#中的句柄设置窗口的透明度?

我试图设置所有窗口的透明度。 我有以下代码。

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机器上工作。 现在我将不得不修改代码以使窗口恢复正常;)幸运的是,Visual Studio 2010窗口不受影响。

这部分代码: ^ WS_EX_LAYERED翻转WS_EX_LAYERED位,

我想你想要: | WS_EX_LAYERED | WS_EX_LAYERED

你试过设置不透明度吗?

上述就是C#学习教程:我不能通过c#中的句柄设置窗口的透明度?分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 this.Opacity = 0.50; 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1030427.html

(0)
上一篇 2022年1月13日
下一篇 2022年1月13日

精彩推荐