IntPtr pWnd = Win32.FindWindow("Progman", "Program Manager");
Win32.SetParent(this.Handle, pWnd);嵌入桌面之后,设置透明
Win32.SetWindowLong(this.Handle, Win32.GWL_EXSTYLE, Win32.GetWindowLong(this.Handle, Win32.GWL_EXSTYLE) |Win32.WS_EX_LAYERED); Win32.SetLayeredWindowAttributes(this.Handle, 0x003F85CD, 100), Win32.LWA_ALPHA);SetLayeredWindowAttributes返回false失败。请问如何解决。
Win32.SetParent(this.Handle, pWnd);嵌入桌面之后,设置透明
Win32.SetWindowLong(this.Handle, Win32.GWL_EXSTYLE, Win32.GetWindowLong(this.Handle, Win32.GWL_EXSTYLE) |Win32.WS_EX_LAYERED); Win32.SetLayeredWindowAttributes(this.Handle, 0x003F85CD, 100), Win32.LWA_ALPHA);SetLayeredWindowAttributes返回false失败。请问如何解决。
但是我也不清楚为什么。下面的代码实现的效果应该是你要的,
我刚才新建一个Form,测试了一下,没有问题,你核对一下!
private const uint WS_EX_LAYERED = 0x80000;
private const int WS_EX_TRANSPARENT = 0x20;
private const int GWL_STYLE = (-16);
private const int GWL_EXSTYLE = (-20);
private const int LWA_ALPHA = 0x2;
[DllImport("user32", EntryPoint = "SetWindowLong")]
private static extern uint SetWindowLong(
IntPtr hwnd,
int nIndex,
uint dwNewLong
);
[DllImport("user32", EntryPoint = "GetWindowLong")]
private static extern uint GetWindowLong(
IntPtr hwnd,
int nIndex
);
[DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]
private static extern int SetLayeredWindowAttributes(
IntPtr hwnd,
int crKey,
int bAlpha,
int dwFlags
);
/// <summary>
/// 设置窗体具有鼠标穿透效果
/// </summary>
public void SetPenetrate()
{
this.TopMost = true;
GetWindowLong(this.Handle, GWL_EXSTYLE);
SetWindowLong(this.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED);
SetLayeredWindowAttributes(this.Handle, 0, 100, LWA_ALPHA);
}
谢谢你!
嵌入桌面很多问题的
可以试试:
SetWindowPos+HWND_BOTTOM把桌面设置为最低层
然后屏幕最Win+D之类的操作