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)

// 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
return HitArea;

Appreciate your comments...