MFC动态画圆
以下是我的代码voidCMyView::OnLButtonDown(UINTnFlags,CPointpoint){m_pointOri=point;CWnd::OnLB...
以下是我的代码
void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{m_pointOri = point;
CWnd::OnLButtonDown(nFlags, point);
}
void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{}
void CMyView::OnLButtonUp(UINT nFlags, CPoint point)
{CClientDC dc(this);
dc.SetViewportOrg(point);
dc.Ellipse(-(point.x - m_pointOri.x), -(point.x - m_pointOri.x), (point.x - m_pointOri.x),(point.x - m_pointOri.x));
CWnd::OnLButtonUp(nFlags, point);
}
现在能画出圆形,但是画的过程没有动态显示,请问onmousemove里怎么写 能实现跟随鼠标动态显示 展开
void CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{m_pointOri = point;
CWnd::OnLButtonDown(nFlags, point);
}
void CMyView::OnMouseMove(UINT nFlags, CPoint point)
{}
void CMyView::OnLButtonUp(UINT nFlags, CPoint point)
{CClientDC dc(this);
dc.SetViewportOrg(point);
dc.Ellipse(-(point.x - m_pointOri.x), -(point.x - m_pointOri.x), (point.x - m_pointOri.x),(point.x - m_pointOri.x));
CWnd::OnLButtonUp(nFlags, point);
}
现在能画出圆形,但是画的过程没有动态显示,请问onmousemove里怎么写 能实现跟随鼠标动态显示 展开
1个回答
展开全部
相关代码如下:
// 先在类中定义三个变量
bool m_painting; // 是否正在绘制
CPoint m_pointOri; // 中心点
float m_radius; // 半径
Cdemo98View::Cdemo98View()
{
m_painting = false;
m_radius = 0;
}
void Cdemo98View::OnDraw(CDC* pDC)
{
Cdemo98Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
pDC->Ellipse(m_pointOri.x - m_radius, m_pointOri.y - m_radius, m_pointOri.x + m_radius, m_pointOri.y + m_radius);
}
void Cdemo98View::OnLButtonDown(UINT nFlags, CPoint point)
{
m_pointOri = point;
m_radius = 0;
m_painting = true;
}
void Cdemo98View::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_painting) {
// 计算当前点距离中心点距离也就是半径
m_radius = sqrt(pow(float(point.x - m_pointOri.x), 2) + pow(float(point.y - m_pointOri.y), 2));
Invalidate();
}
}
void Cdemo98View::OnLButtonUp(UINT nFlags, CPoint point)
{
// 计算当前点距离中心点距离也就是半径
m_radius = sqrt(pow(float(point.x - m_pointOri.x), 2) + pow(float(point.y - m_pointOri.y), 2));
m_painting = false;
Invalidate();
}
运行结果:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询