在c#中带有分层窗口的启动画面

时间:2013-03-01 11:42:17

标签: c# splash-screen layered-windows

在多层窗口中我点击工作但我仍然看到窗口背景图片后面的灰色如何删除?我查看了堆栈溢出和codeproject,但我找不到解决方案。

这是我的代码:

private Margins marg;
    internal struct Margins 
    {
        public int Left, Right, Top, Bottom;
    }

    public enum GWL
    {
        ExStyle = -20
    }

    public enum WS_EX
    {
        Transparent = 0x20,
        Layered = 0x80000
    }

    public enum LWA
    {
        ColorKey = 0x1,
        Alpha = 0x2
    }

    const Int32 HTCAPTION = 0x02;
    const Int32 WM_NCHITTEST = 0x84;
    const byte AC_SRC_OVER = 0x00;
    const byte AC_SRC_ALPHA = 0x01;

    [DllImport("user32.dll", SetLastError = true)]

    private static extern UInt32 GetWindowLong(IntPtr hWnd, int nIndex);

    [DllImport("user32.dll")]

    static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool SetLayeredWindowAttributes(IntPtr hwnd, int crKey, byte bAlpha, LWA dwFlags);

    [DllImport("dwmapi.dll")]
    static extern void DwmExtendFrameIntoClientArea(IntPtr hWnd, ref Margins pMargins);

    public Form1() {
        InitializeComponent();

        //BackColor = Color.Aqua;
        //TransparencyKey = Color.Aqua;

        StartPosition = FormStartPosition.CenterScreen;
        BackgroundImage = new Bitmap(mypicture);
        BackgroundImageLayout = ImageLayout.Stretch;
        this.Size = mypicture.Size;
        this.FormBorderStyle = FormBorderStyle.None;

        TopMost = true;
        Visible = true;

        int initialsytle = (int) GetWindowLong(this.Handle,-20);
        initialsytle = initialsytle |0x80000 | 0x20;
        IntPtr pointer = (IntPtr) initialsytle;
        SetWindowLong(this.Handle, -20, pointer);
        SetLayeredWindowAttributes(this.Handle, 0, 128, LWA.ColorKey);



    }

    protected override void OnPaint(PaintEventArgs e) {
        base.OnPaint(e);

        marg.Left = 0;
        marg.Top = 0;
        marg.Right = this.Width;
        marg.Bottom = this.Height;

        DwmExtendFrameIntoClientArea(this.Handle, ref marg);

    }
}

0 个答案:

没有答案
相关问题