To move a captionless dialog.

Have you ever wondered how do people move dialogs by simply clicking anywhere inside the dialog and dragging them. Have you ever wondered how caption-less dialogs can be dragged around. If it is so then let me tell you that you can do the same with just few lines of code…

Here goes the code:

[sourcecode language=’cpp’]BEGIN_MESSAGE_MAP(CGuineaPigDlg, CDialog)
//{{AFX_MSG_MAP(CGuineaPigDlg)
ON_WM_NCHITTEST()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// First add above message entry
UINT CGuineaPigDlg::OnNcHitTest(CPoint point)
{
const UINT HitArea = CDialog::OnNcHitTest(point);
if( HitArea == HTCLIENT )
{
return HTCAPTION; // Fake caption drag effect
}
else
{
return HitArea;
}
}[/sourcecode]

Appreciate your comments...