我正在使用 Visual Studio、C# 和 .NET Framework。
我已按照本教程进行操作:https://www.youtube.com/watch?v=oKQlPE57gYg 至 4:20,但经过测试后我收到此错误消息,但我不知道如何修复它:
这是我的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Energy_Organizer
{
public partial class Form1 : Form
{
private bool drag;
private int mouseX;
private int mouseY;
private const int WM_NCHITTEST = 0x84;
private const int HTCLIENT = 0x1;
private const int HTCAPTION = 0x2;
private bool m_aeroEnabled;
private const int CS_DROPSHADOW = 0x00020000;
private const int WM_NCPAINT = 0x0085;
private const int WM_ACTIVEAPP = 0x001C;
[System.Runtime.InteropServices.DllImport("dwmapi.dll")]
public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
[System.Runtime.InteropServices.DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
[System.Runtime.InteropServices.DllImport("dwampi.dll")]
public static extern int DwmIsCompoisionEnabled(ref int pfEnabled);
[System.Runtime.InteropServices.DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
private static extern IntPtr CreateRoundRectRgn
(
int nLeftRect,
int nTopRect,
int nRightRect,
int nBottomRect,
int nWidthEllipse,
int nHeightEllipse
);
public struct MARGINS
{
public int leftWidth;
public int rightWidth;
public int topHeight;
public int bottomHeight;
}
protected override CreateParams CreateParams
{
get
{
m_aeroEnabled = CheckAeroEnabled();
CreateParams cp = base.CreateParams;
if (!m_aeroEnabled)
cp.ClassStyle |= CS_DROPSHADOW; return cp;
}
}
private bool CheckAeroEnabled()
{
if (Environment.OSVersion.Version.Major >= 6)
{
int enabled = 0; DwmIsCompoisionEnabled(ref enabled);
return (enabled == 1) ? true : false;
}
return false;
}
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_NCPAINT:
if (m_aeroEnabled)
{
var v = 2;
DwmSetWindowAttribute(this.Handle, 2, ref v, 4);
MARGINS margins = new MARGINS()
{
bottomHeight = 1,
leftWidth = 0,
rightWidth = 0,
topHeight = 0
}; DwmExtendFrameIntoClientArea(this.Handle, ref margins);
}
break;
default: break;
}
base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST && (int)m.Result == HTCLIENT)
m.Result = (IntPtr)HTCAPTION;
}
public Form1()
{
InitializeComponent();
}
}
}
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Forms;
namespace Energy_Organizer
{
internal class Gradient_Sidebar_Panel : System.Windows.Forms.Panel
{
public Color gradientTop {get; set;}
public Color gradientBottom {get; set;}
protected override void OnPaint(PaintEventArgs e)
{
LinearGradientBrush linear = new LinearGradientBrush(this.ClientRectangle, this.gradientTop, this.gradientBottom, 90F);
Graphics graphics = e.Graphics;
graphics.FillRectangle(linear, this.ClientRectangle);
base.OnPaint(e);
}
}
}
我已经尝试过 Visual Studio 的基本提示,但没有任何效果。
我希望有人能帮助我:) 谢谢
我将上述解决方案总结为一个答案。
看起来像一个错字:
您写了
dwampi.dll
,正确的是dwmapi.dll
。
google 对
DwmIsCompoisionEnabled
函数一无所知,但它知道 DwmIsCompositionEnabled
(learn.microsoft.com/en-us/windows/win32/api/dwmapi/…) 函数。