若想改变原点,可采用CDC类的成员函数SetViewportOrg (int x, int y);
例如:设窗口中心点为坐标原点
CDC* pDC = GetDC()
CRect rect
GetClientRect(&rect)
pDC->SetViewportOrg(rect.right/2, rect.bottom/2)
若还想改变 X , Y 方向,比如常用的笛卡尔坐标系,即 X 轴右为正,Y 轴上为正,
可用函数SetMapMode( ****),参数自己可去查MSDN,根据自己需要设置。
基于对话框的MFC,在主对话框类中,OnPaint函数中,增加如下代码:if( m_beginPoint != CPoint( 0, 0 ) &&m_endPoint != CPoint( 0, 0 ) )
{
CClientDC hdc(this)//获得设备环境
hdc.MoveTo( m_beginPoint )
hdc.LineTo( m_endPoint )
}
然后创建一个OnLButtonDown函数,内容如下:
void CTestPaintDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if( !m_bState )//第一个点
{
m_beginPoint = point
}
else
{
m_endPoint = point
Invalidate( false )
}
m_bState = !m_bState
CDialog::OnLButtonDown(nFlags, point)
}
只是一个简单示例,可以参考一下。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)