我正在尝试设置所有窗口的透明度。我有以下代码。
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
to
theProcess.MainWindowHandle
更改后,它可以在我测试的 Windows XP 机器上运行。现在我必须修改代码才能使窗口恢复正常;)幸运的是,Visual Studio 2010 窗口不受影响。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)