UINT CSampleDialog::OnNcHitTest (Cpoint point )
{
UINT nHitTest = CDialog::OnNcHitTest (point );
return (nHitTest == HTCLIENT)? HTCAPTION : nHitTest;
}
上述技术有两点不利之处,
其一是在窗口的客户区域双击时,窗口将极大;
其二, 它不适合包含几个视窗的主框窗口。
还有一种方法,当用户按下鼠标左键使主框窗口认为鼠标在其窗口标题上,使用ClassWizard在视窗中处理WM_LBUTTODOWN信息并向主框窗口发送一个WM_NCLBUTTONDOWN信息和一个单击测试HTCAPTION。
void CSampleView::OnLButtonDown (UINT nFlags, Cpoint point)
{
CSampleView::OnLButtonDown(nFlags, point);
//Fool frame window into thinking somene clicked on its caption bar .
GetParentFrame( )->PostMessage (WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM (poitn .x , point .y) );
}
该技术也适用于对话框和基于对话框的应用程序,只是不必调用CWnd: :GetParentFrame 。
void CSampleDialog::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDown(nFlags, point);
PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x, point.y));
}

