UINT CNCMsgDlg::OnNcHitTest(CPoint point) { UINT nTest; RECT rect; GetWindowRect(&rect); //如果鼠标指针处于窗体边界5像素以内,可以拖动改变窗体大小。 //如果鼠标指针处于窗体上部20像素以内,可以像标题栏那样移动窗体。 if(point.x >= rect.left && point.x < rect.left + 4) //鼠标X坐标在窗体左边界 { if(point.y >= rect.top && point.y <= rect.top + 4) nTest = HTTOPLEFT; //鼠标在窗体左上角 else if(point.y >= rect.bottom-4 && point.y <= rect.bottom) nTest = HTBOTTOMLEFT; //鼠标在窗体左下角 else nTest = HTLEFT; //鼠标在窗体左边界其它位置 } else if(point.x <= rect.right && point.x >= rect.right - 4) //鼠标X坐标在窗体右边界 { if(point.y >= rect.top && point.y <= rect.top + 4) nTest = HTTOPRIGHT; //鼠标在窗体右上角 else if(point.y >= rect.bottom-4 && point.y <= rect.bottom) nTest = HTBOTTOMRIGHT; //鼠标在窗体右下角 else nTest = HTRIGHT; //鼠标在窗体右边界其它位置 } else if(point.y >= rect.top && point.y <= rect.top + 4) { nTest = HTTOP; //鼠标在窗体上边界 } else if(point.y >= rect.bottom - 4 && point.y < rect.bottom) { nTest = HTBOTTOM; //鼠标 } else if(point.y < rect.top + 20) { nTest = HTCAPTION; //鼠标处于“标题栏” } else { nTest = HTCLIENT; //默认情况,无特殊处理 } return nTest; }