用C++编一个画图程序,求源程序(只要求能够画直线和圆)
呵呵,谢谢你们啦~~但是我要的是整个程序的源代码~~希望有的就分享下下啦~~如果可行,我可以再加10分的~~谢谢...
呵呵,谢谢你们啦~~但是我要的是整个程序的源代码~~希望有的就分享下下啦~~如果可行,我可以再加10分的~~谢谢
展开
3个回答
展开全部
============================================================
//在构造函数里添加以下两句:
//加载十字光标
m_hCrossCur = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
//加载箭头光标
m_hArrowCur = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
============================================================
============================================================
//以下是画直线的代码:
void CMyProject4View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bLButtonDown = TRUE; //鼠标左键按下
m_ptStart = point; //直线的起点
m_ptEnd = point; //直线的临时端点
SetCapture();
SetCursor(m_hCrossCur);//设置鼠标捕捉
CView::OnLButtonDown(nFlags, point);
}
void CMyProject4View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bLButtonDown)
{
m_bLButtonDown = FALSE; //鼠标左键释放
ReleaseCapture(); //释放鼠标捕捉
CClientDC dc(this);//创建客户区设备环境
dc.MoveTo(m_ptStart);
dc.LineTo(point);
SetCursor(m_hArrowCur);
CView::OnLButtonUp(nFlags, point);
}
}
void CMyProject4View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bLButtonDown)
{
CClientDC dc(this);
dc.SetROP2(R2_NOT);
dc.MoveTo(m_ptStart); //擦除从起点到上个鼠标移动点间的直线
dc.LineTo(m_ptEnd);
dc.MoveTo(m_ptStart); //绘制从起点到当前点间的直线
dc.LineTo(point);
m_ptEnd = point; //保存当前鼠标位置
}
CView::OnMouseMove(nFlags, point);
}
============================================================
============================================================
以下是画圆的代码:
void CMyProject4View::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rcClient;
GetClientRect (&rcClient);
int cx=rcClient.Width() /2;
int cy=rcClient.Height() /2;
CRect rc(cx-45,cy-45,cx+45,cy+45);
CBrush brush(RGB(0,250,250));
CBrush *poldbrush=dc.SelectObject(&brush);
dc.Ellipse(rc);
}
// Do not call CView::OnPaint() for painting messages
}
============================================================
============================================================
代码过多,只截取部分程序,希望对你有点帮助!
运行平台:Microsoft Visual C++ 6.0
操作系统:Microsoft Windows XP
============================================================
//在构造函数里添加以下两句:
//加载十字光标
m_hCrossCur = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
//加载箭头光标
m_hArrowCur = AfxGetApp()->LoadStandardCursor(IDC_ARROW);
============================================================
============================================================
//以下是画直线的代码:
void CMyProject4View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_bLButtonDown = TRUE; //鼠标左键按下
m_ptStart = point; //直线的起点
m_ptEnd = point; //直线的临时端点
SetCapture();
SetCursor(m_hCrossCur);//设置鼠标捕捉
CView::OnLButtonDown(nFlags, point);
}
void CMyProject4View::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bLButtonDown)
{
m_bLButtonDown = FALSE; //鼠标左键释放
ReleaseCapture(); //释放鼠标捕捉
CClientDC dc(this);//创建客户区设备环境
dc.MoveTo(m_ptStart);
dc.LineTo(point);
SetCursor(m_hArrowCur);
CView::OnLButtonUp(nFlags, point);
}
}
void CMyProject4View::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_bLButtonDown)
{
CClientDC dc(this);
dc.SetROP2(R2_NOT);
dc.MoveTo(m_ptStart); //擦除从起点到上个鼠标移动点间的直线
dc.LineTo(m_ptEnd);
dc.MoveTo(m_ptStart); //绘制从起点到当前点间的直线
dc.LineTo(point);
m_ptEnd = point; //保存当前鼠标位置
}
CView::OnMouseMove(nFlags, point);
}
============================================================
============================================================
以下是画圆的代码:
void CMyProject4View::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rcClient;
GetClientRect (&rcClient);
int cx=rcClient.Width() /2;
int cy=rcClient.Height() /2;
CRect rc(cx-45,cy-45,cx+45,cy+45);
CBrush brush(RGB(0,250,250));
CBrush *poldbrush=dc.SelectObject(&brush);
dc.Ellipse(rc);
}
// Do not call CView::OnPaint() for painting messages
}
============================================================
============================================================
代码过多,只截取部分程序,希望对你有点帮助!
运行平台:Microsoft Visual C++ 6.0
操作系统:Microsoft Windows XP
============================================================
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询