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);

可以做窗體穿透,也可以做控件穿透,開發氣泡就可以使用。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章