值不在dwmapi.dll的预期范围内
本文关键字:范围内 dll dwmapi | 更新日期: 2023-09-27 17:53:04
"值不落在预期范围内"错误出现时,我运行我的程序与航空玻璃。我正在使用dwmapi.dll。这是代码:
在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();
在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);
你能告诉我有什么问题吗?我知道这应该管用,因为我看过一段视频,对他很有效。谢谢!
可能改变DwmExtendFrameIntoClientArea PreserveSig to true
。
并将外边距改为:
[StructLayout(LayoutKind.Sequential)]
public struct Margins
{
public int leftWidth;
public int rightWidth;
public int topHeight;
public int bottomHeight;
}