win32api之窗体穿透

/// <summary>
/// 窗体效果.
/// </summary>
/// <author>YangSen</author>
public class WindowEffect
{
    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 = 0;

    /// <summary>
    /// 鼠标穿透.
    /// </summary>
    /// <param name="hWnd">The h WND.</param>
    /// <author>YangSen</author>
    public static void Penetrate(IntPtr hWnd)
    {
        Methods.GetWindowLong(hWnd, GWL_EXSTYLE);
        Methods.SetWindowLong(hWnd, GWL_EXSTYLE, WS_EX_TRANSPARENT | WS_EX_LAYERED);
        Methods.SetLayeredWindowAttributes(hWnd, 0, 100, LWA_ALPHA);
    }
}
[DllImport("user32", EntryPoint = "GetWindowLong")]
public static extern uint GetWindowLong(IntPtr hwnd, int nIndex);

[DllImport("user32", EntryPoint = "SetLayeredWindowAttributes")]
public static extern int SetLayeredWindowAttributes(IntPtr hwnd, int crKey, int bAlpha, int dwFlags);

可以做窗体穿透,也可以做控件穿透,开发气泡就可以使用。

猜你喜欢

转载自blog.csdn.net/yangsen600/article/details/56280051