值不在dwmapi.dll的预期范围内

时间:2016-06-29 00:30:52

标签: c#

"价值不会随预期范围而下降"使用航空玻璃运行程序时出现错误。我正在使用dwmapi.dll。这是代码:

ON Aero.cs

[StructLayout(LayoutKind.Sequential)]
    public struct Margins
    {
        public int Left;
        public int Right;
        public int Top;
        public int Bottom;
    }

    [DllImport("dwmapi.dll", PreserveSig = false)]
    public static extern void DwmExtendFrameIntoClientArea(IntPtr hwnd, ref Margins margins);

    [DllImport("dwmapi.dll", PreserveSig = false)]
    public static extern bool DwmIsCompositionEnabled();

ON AddStudent.cs

    private const int PaddingCounter = 0;
    private Aero.Margins _newMargins;

    private void SetGlassArea()
    {
        if (Aero.DwmIsCompositionEnabled())
        {
            _newMargins.Top = Padding.Top;
            _newMargins.Bottom = Padding.Bottom;
            _newMargins.Left = Padding.Left;
            _newMargins.Right = Padding.Right;
            Aero.DwmExtendFrameIntoClientArea(this.Handle, ref _newMargins);
        }
    }

    protected override void OnPaintBackground(PaintEventArgs e)
    {
        base.OnPaint(e);
        if (Aero.DwmIsCompositionEnabled())
        {
            e.Graphics.Clear(Color.Black);
            Rectangle clientArea = new Rectangle(_newMargins.Left, _newMargins.Top, this.ClientRectangle.Width - _newMargins.Left -_newMargins.Right,
                this.ClientRectangle.Height - _newMargins.Top - _newMargins.Bottom);
            Brush b = new SolidBrush(this.BackColor);
            e.Graphics.FillRectangle(b, clientArea);
        }
    }

    public void ApplyGlassSurface()
    {
        this.Padding = new Padding(PaddingCounter);
        SetGlassArea();
        Invalidate();
    }

    private void AddStudent_Load(object sender, EventArgs e)
    {
        ApplyGlassSurface();
        webcam = new FilterInfoCollection(FilterCategory.VideoInputDevice);
        foreach (FilterInfo videoCaptureDevice in webcam)
        {
            comboBoxEx1.Items.Add(videoCaptureDevice.Name);
        }
        comboBoxEx1.SelectedIndex = 0;
    }

错误指向:

Aero.DwmExtendFrameIntoClientArea(this.Handle, ref _newMargins);

你能告诉我它有什么问题吗?我知道它应该有效,因为我看过一个视频,它对他有用。谢谢!

1 个答案:

答案 0 :(得分:0)

可能会更改DwmExtendFrameIntoClientArea PreserveSig to true

将边距更改为:

[StructLayout(LayoutKind.Sequential)]
public struct Margins
{
    public int leftWidth;
    public int rightWidth;
    public int topHeight;
    public int bottomHeight;
}