Dragging a dialog by clicking anywhere on it

This is how you create a dialog that can be dragged by clicking anywhere
on it, ie. not just the caption bar.

void CNCHitDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
	CDialog::OnLButtonDown(nFlags, point);
	// fake windows into thinking your clicking on the caption, does not
	// maximize on double click
	PostMessage( WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM( point.x, point.y));
}

or

UINT CNCHitDlg::OnNcHitTest(CPoint point)
{
	UINT nHitTest = CDialog::OnNcHitTest( point );
	// also fake windows out, but this maximizes the window when you double
	// click on it. 
	return (nHitTest == HTCLIENT) ? HTCAPTION : nHitTest;
}

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read