I wanted to add a nice shadow to my borderless form, and the best way I found for this with minimal performance loss is to use DwmExtendFrameIntoClientArea . However, it seems that this forces Windows to draw the classic title bar above the window, but it does not work (i.e., Glitch is just graphic).

This is the code I'm 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 tried to set ALLOW_NCPAINTto 1, and even tried to return 0 when the window receives WM_NCPAINTwithout a call DefWndProc, but that didn't matter.
Is there any way to solve this strange problem when using DwmExtendFrameIntoClientArea?