1

多層ウィンドウでクリックスルーが機能していますが、ウィンドウの背景画像の後ろに灰色が表示されますが、それを削除するにはどうすればよいですか?スタックオーバーフローと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);

    }
}
4

0 に答える 0