关于对话框窗体拖动的问题
通常情况下是,按住鼠标不放,按住标题栏区域可拖动窗体,按住客户区不可以拖动窗体
通过添加如下代码,可以实现按住客户区可拖动的操作
LRESULT CTestMfcDlg::OnNcHitTest(CPoint point)
{
UINT nHitTest=CDialogEx::OnNcHitTest(point);
if(nHitTest==HTCLIENT)//如果是客户区
{
nHitTest=HTCAPTION; //则把它当成标题栏
}
return nHitTest;
}
通过如下代码,可改变标题栏高度
void CTestMfcDlg::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS* lpncsp)
{
int myCaptionHeight = 50; //标题栏高度
int myLeftBorderWeight =10;
int myRightBorderWeight =10;
int myBottomBorderWeight =10;
if (bCalcValidRects)
{
CRect& rc = (CRect&)lpncsp->rgrc[0];//get the client rectangle
rc.top += myCaptionHeight - GetSystemMetrics(SM_CYCAPTION) - GetSystemMetrics(SM_CYDLGFRAME);
rc.left += myLeftBorderWeight - GetSystemMetrics(SM_CYDLGFRAME);
rc.bottom -= myBottomBorderWeight - GetSystemMetrics(SM_CYDLGFRAME);
rc.right -= myRightBorderWeight - GetSystemMetrics(SM_CYDLGFRAME);
}
CDialogEx::OnNcCalcSize(bCalcValidRects,lpncsp);
}