I wanted to add a nice shadow to my borderless form, and the best way I found to do it with minimal performance loss is to use DwmExtendFrameIntoClientArea. However, this seems to be causing Windows to draw a classic title bar over the window, but it is non-functional (ie. the glitch is merely graphical).
This is the code I am using:
int v = (int) DWMNCRENDERINGPOLICY.DWMNCRP_ENABLED;
NativeApi.DwmSetWindowAttribute(Handle, DwmWindowAttribute.NCRENDERING_POLICY, ref v, sizeof(int));
int enable = 0;
NativeApi.DwmSetWindowAttribute(Handle, DwmWindowAttribute.ALLOW_NCPAINT, ref enable, sizeof(int));
MARGINS margins = new MARGINS() {
leftWidth = 0,
topHeight = 0,
rightWidth = 0,
bottomHeight = 1
};
NativeApi.DwmExtendFrameIntoClientArea(Handle, ref margins);
I have tried setting ALLOW_NCPAINT to 1, and I even tried returning 0 when the window receives WM_NCPAINT without calling DefWndProc, but it made no difference.
Is there a way to resolve this weird issue while still using DwmExtendFrameIntoClientArea?

Big thanks to @Erik Philips, I have finally resolved the issue by following this answer's advice. The issue was in
CreateParams:The
|had to be removed fromcp.Style:This solved the issue, as apparently WinForms adds
WS_BORDERby default to the class style, even ifFormBorderStyleis later set toNone.