Another similar way is to test the return of DefWindowProc in WM_NCHITTEST
int nRet = DefWindowProc(hWnd, WM_NCHITTEST, 0, lParam);
switch (nRet)
{
case HTLEFT:
case HTTOP:
case HTBOTTOM:
case HTRIGHT:
case HTBOTTOMLEFT:
case HTBOTTOMRIGHT:
case HTTOPLEFT:
case HTTOPRIGHT:
{
handled = true;
return new IntPtr(HTNOWHERE);
}
}
with :
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int DefWindowProc(IntPtr hWnd, int msg, int wParam, IntPtr lParam);