Since calling ReleaseCapture() inside WM_NCLBUTTONDOWN did not work, try explicitly forwarding the message to DefWindowProc after processing WM_NCLBUTTONDOWN. This ensures the system’s default behavior is not interfered with.
Modify your WM_NCLBUTTONDOWN handler to explicitly release capture.