Home > MFC, Windows API > To move a captionless dialog.

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:

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;
   }
}
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: