Added DWM window shadow

This commit is contained in:
Jaex 2022-07-22 10:39:25 +03:00
parent f293e037fb
commit ca90a55787

View file

@ -88,13 +88,18 @@ public int ImageOpacity
public bool KeepCenterLocation { get; set; } = true;
public bool HighQualityScale { get; set; } = true;
public int ScaleStep { get; set; } = 20;
public int ScaleStep { get; set; } = 10;
public int OpacityStep { get; set; } = 10;
public bool ShowShadow { get; set; } = true;
private bool isDWMEnabled;
private PinToScreenForm()
{
InitializeComponent();
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint, true);
isDWMEnabled = NativeMethods.IsDWMEnabled();
}
private PinToScreenForm(Image image) : this()
@ -163,6 +168,26 @@ private void AutoSizeForm()
NativeMethods.SetWindowPos(Handle, (IntPtr)SpecialWindowHandles.HWND_TOPMOST, newLocation.X, newLocation.Y, newSize.Width, newSize.Height, flags);
}
protected override void WndProc(ref Message m)
{
if (ShowShadow && m.Msg == (int)WindowsMessages.NCPAINT && isDWMEnabled)
{
NativeMethods.SetNCRenderingPolicy(Handle, DwmNCRenderingPolicy.Enabled);
MARGINS margins = new MARGINS()
{
bottomHeight = 1,
leftWidth = 1,
rightWidth = 1,
topHeight = 1
};
NativeMethods.DwmExtendFrameIntoClientArea(Handle, ref margins);
}
base.WndProc(ref m);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
//base.OnPaintBackground(e);