vc++ 画圆&画直线
求一程序,仅需实现鼠标拖动画圆和画直线即可。程序和源代码都要。注:是基于vc的,不是turbec下的;根据答案的质量会考虑追加分数...
求一程序,仅需实现鼠标拖动画圆和画直线即可。程序和源代码都要。
注:是基于vc 的,不是turbe c下的;根据答案的质量会考虑追加分数 展开
注:是基于vc 的,不是turbe c下的;根据答案的质量会考虑追加分数 展开
3个回答
2013-07-13
展开全部
我是在visual studio 2008下面的。
文件--新建---项目---MFC--MFC应用程序---自已起个名字--确定---单文档--其它都默认就行了。
主要代码如下
void CMyDrawView::OnLine()
{
isLine = TRUE;
isELLI = FALSE;
}
void CMyDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_startPoint = point;
isDraw = TRUE;
CView::OnLButtonDown(nFlags, point);
}
void CMyDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
isDraw = FALSE;
CView::OnLButtonUp(nFlags, point);
}
void CMyDrawView::OnEllieps()
{
isELLI = TRUE;
isLine = FALSE;
}
void CMyDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
if (isDraw)
{
CClientDC dc(this);
if (isLine)
{
dc.SetROP2(R2_NOTXORPEN);
dc.MoveTo(m_startPoint);
dc.LineTo(point);
}
if (isELLI)
{
dc.Ellipse(m_startPoint.x,m_startPoint.y,point.x,point.y);
}
}
CView::OnMouseMove(nFlags, point);
}
文件--新建---项目---MFC--MFC应用程序---自已起个名字--确定---单文档--其它都默认就行了。
主要代码如下
void CMyDrawView::OnLine()
{
isLine = TRUE;
isELLI = FALSE;
}
void CMyDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_startPoint = point;
isDraw = TRUE;
CView::OnLButtonDown(nFlags, point);
}
void CMyDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
isDraw = FALSE;
CView::OnLButtonUp(nFlags, point);
}
void CMyDrawView::OnEllieps()
{
isELLI = TRUE;
isLine = FALSE;
}
void CMyDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
if (isDraw)
{
CClientDC dc(this);
if (isLine)
{
dc.SetROP2(R2_NOTXORPEN);
dc.MoveTo(m_startPoint);
dc.LineTo(point);
}
if (isELLI)
{
dc.Ellipse(m_startPoint.x,m_startPoint.y,point.x,point.y);
}
}
CView::OnMouseMove(nFlags, point);
}
2013-07-13
展开全部
void CMessageView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
StartPoint=point; //鼠标左键定义了,画线的起始位置。StartPoint应先定义为CPoint, 在构造函数进行初始化=-1;
CView::OnLButtonDown(nFlags, point);
}
void CMessageView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
if (StartPoint.x != -1)
{
dc.MoveTo(StartPoint.x,StartPoint.y); //移动到给定的开始点
dc.LineTo(point); //绘制一条直线
StartPoint = point;
}
CView::OnMouseMove(nFlags, point);
}
void CMessageView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
StartPoint=-1;
CView::OnLButtonUp(nFlags, point);
}
void CMessageView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
dc.Ellipse(100,100,200,200); //右键画圆
CView::OnRButtonDown(nFlags, point);
}
{
// TODO: Add your message handler code here and/or call default
StartPoint=point; //鼠标左键定义了,画线的起始位置。StartPoint应先定义为CPoint, 在构造函数进行初始化=-1;
CView::OnLButtonDown(nFlags, point);
}
void CMessageView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
if (StartPoint.x != -1)
{
dc.MoveTo(StartPoint.x,StartPoint.y); //移动到给定的开始点
dc.LineTo(point); //绘制一条直线
StartPoint = point;
}
CView::OnMouseMove(nFlags, point);
}
void CMessageView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
StartPoint=-1;
CView::OnLButtonUp(nFlags, point);
}
void CMessageView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
dc.Ellipse(100,100,200,200); //右键画圆
CView::OnRButtonDown(nFlags, point);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-13
展开全部
发到邮箱里了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |