3个回答
展开全部
1.分析Windows自带的画板程序,确定“简单绘图软件”需要实现的功能,并且确立“简单绘图软件”的大致框架模型;
2.按照MFC的提示向导,建立一个基于单文档的应用程序;
3.设计程序界面以及添加代码:首先建立一个“绘图”菜单,并建立“点”、“直线”、“矩形”、“椭圆”等选项的枣祥下拉菜单。在View类中添加UINT型m_nDrawType用来记录绘画的类型,然后分别对“点”、“直线”、“矩形”、“椭圆”等选项建立common映射消息,分别为m_nDrawType赋值。之后在View类中添加OnLButtonDown和OnLButtonUp函数,分别记录起始点和终止点,并在OnLButtonUp中添加绘制图形需要用的函数。第二步,建立“设置”—>“线型设置”、“颜色设置”菜单。设计“设置”对话框,并添加相关语句让“示例”得以实现。然后添加“线型设置”、“颜色设置”的common映射消息。第三步,创建独立的工具栏。首先设计工具栏的外观,并更改它们的ID号与相关功能菜单的ID相同。最后仿照系统自动生成的工具栏进行独立工具栏的显示和功能设置,并同时增加穗岩察一个独立工具栏的隐藏与显示功能。
4.编译猜茄调试程序。
5.美化界面:添加程序的启动画面,设置停留的时间为3000豪秒,然后更改程序的图标。
//保存”绘图”菜单的选择项
void CGraphicView::OnDot()
{
// TODO: Add your command handler code here
m_nDrawType=1;
}
void CGraphicView::OnLine()
{
// TODO: Add your command handler code here
m_nDrawType=2;
}
void CGraphicView::OnRectangle()
{
// TODO: Add your command handler code here
m_nDrawType=3;
}
void CGraphicView::OnEllipse()
{
// TODO: Add your command handler code here
m_nDrawType=4;
}
//获取并保存鼠标按下时的坐标
void CGraphicView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptOrigin=point;
CView::OnLButtonDown(nFlags, point);
}
//获取鼠标松开时的坐标,绘制相对应的图形
void CGraphicView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CPen pen(m_nLineStyle,m_nLineWidth,m_clr);
dc.SelectObject(&pen);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)); //使图形之间不互相重叠
dc.SelectObject(pBrush);
switch(m_nDrawType)
{
case 1: //画点
dc.SetPixel(point,m_clr);
break;
case 2: //画直线
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
break;
case 3: //画矩形
dc.Rectangle(CRect(m_ptOrigin,point));
break;
case 4: //画椭圆
dc.Ellipse(CRect(m_ptOrigin,point));
break;
}
CView::OnLButtonUp(nFlags, point);
}
//”设置”对话框的显示以及相关数据的保存
void CGraphicView::OnSetting()
{
// TODO: Add your command handler code here
CSettingDlg dlg;
dlg.m_nLineWidth=m_nLineWidth;
dlg.m_nLineStyle=m_nLineStyle;
dlg.m_clr=m_clr;
if(dlg.DoModal()==IDOK)
{
m_nLineWidth=dlg.m_nLineWidth;
m_nLineStyle=dlg.m_nLineStyle;
}
}
//”颜色”对话框的显示以及所选颜色的保存
void CGraphicView::OnColor()
{
// TODO: Add your command handler code here
CColorDialog dlg;
dlg.m_cc.Flags|=CC_RGBINIT;
dlg.m_cc.rgbResult=m_clr;
if(dlg.DoModal()==IDOK)
{
m_clr=dlg.m_cc.rgbResult;
}
}
//制作”设置”对话框上的”示例”的显示
void CSettingDlg::OnChangeLineWidth()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
Invalidate(); //使无效
}
void CSettingDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
Invalidate(); //使无效
}
void CSettingDlg::OnRadio2()
{
// TODO: Add your control notification handler code here
Invalidate(); //使无效
}
void CSettingDlg::OnRadio3()
{
// TODO: Add your control notification handler code here
Invalidate(); //使无效
}
void CSettingDlg::OnRadio4()
{
// TODO: Add your control notification handler code here
Invalidate(); //使无效
}
void CSettingDlg::OnRadio5()
{
// TODO: Add your control notification handler code here
Invalidate(); //使无效
}
//绘制改变的示例图形
void CSettingDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
UpdateData();
CPen pen(m_nLineStyle,m_nLineWidth,m_clr);
dc.SelectObject(&pen);
CRect rect;
GetDlgItem(IDC_SAMPLE)->GetWindowRect(&rect);
ScreenToClient(rect); //使原点移动到对话框的原点位置
//使示例图形居中显示
dc.MoveTo(rect.left+20,rect.top+rect.Height()/2);
dc.LineTo(rect.right-20,rect.top+rect.Height()/2);
// Do not call CDialog::OnPaint() for painting messages
}
2.按照MFC的提示向导,建立一个基于单文档的应用程序;
3.设计程序界面以及添加代码:首先建立一个“绘图”菜单,并建立“点”、“直线”、“矩形”、“椭圆”等选项的枣祥下拉菜单。在View类中添加UINT型m_nDrawType用来记录绘画的类型,然后分别对“点”、“直线”、“矩形”、“椭圆”等选项建立common映射消息,分别为m_nDrawType赋值。之后在View类中添加OnLButtonDown和OnLButtonUp函数,分别记录起始点和终止点,并在OnLButtonUp中添加绘制图形需要用的函数。第二步,建立“设置”—>“线型设置”、“颜色设置”菜单。设计“设置”对话框,并添加相关语句让“示例”得以实现。然后添加“线型设置”、“颜色设置”的common映射消息。第三步,创建独立的工具栏。首先设计工具栏的外观,并更改它们的ID号与相关功能菜单的ID相同。最后仿照系统自动生成的工具栏进行独立工具栏的显示和功能设置,并同时增加穗岩察一个独立工具栏的隐藏与显示功能。
4.编译猜茄调试程序。
5.美化界面:添加程序的启动画面,设置停留的时间为3000豪秒,然后更改程序的图标。
//保存”绘图”菜单的选择项
void CGraphicView::OnDot()
{
// TODO: Add your command handler code here
m_nDrawType=1;
}
void CGraphicView::OnLine()
{
// TODO: Add your command handler code here
m_nDrawType=2;
}
void CGraphicView::OnRectangle()
{
// TODO: Add your command handler code here
m_nDrawType=3;
}
void CGraphicView::OnEllipse()
{
// TODO: Add your command handler code here
m_nDrawType=4;
}
//获取并保存鼠标按下时的坐标
void CGraphicView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptOrigin=point;
CView::OnLButtonDown(nFlags, point);
}
//获取鼠标松开时的坐标,绘制相对应的图形
void CGraphicView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CPen pen(m_nLineStyle,m_nLineWidth,m_clr);
dc.SelectObject(&pen);
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH)); //使图形之间不互相重叠
dc.SelectObject(pBrush);
switch(m_nDrawType)
{
case 1: //画点
dc.SetPixel(point,m_clr);
break;
case 2: //画直线
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
break;
case 3: //画矩形
dc.Rectangle(CRect(m_ptOrigin,point));
break;
case 4: //画椭圆
dc.Ellipse(CRect(m_ptOrigin,point));
break;
}
CView::OnLButtonUp(nFlags, point);
}
//”设置”对话框的显示以及相关数据的保存
void CGraphicView::OnSetting()
{
// TODO: Add your command handler code here
CSettingDlg dlg;
dlg.m_nLineWidth=m_nLineWidth;
dlg.m_nLineStyle=m_nLineStyle;
dlg.m_clr=m_clr;
if(dlg.DoModal()==IDOK)
{
m_nLineWidth=dlg.m_nLineWidth;
m_nLineStyle=dlg.m_nLineStyle;
}
}
//”颜色”对话框的显示以及所选颜色的保存
void CGraphicView::OnColor()
{
// TODO: Add your command handler code here
CColorDialog dlg;
dlg.m_cc.Flags|=CC_RGBINIT;
dlg.m_cc.rgbResult=m_clr;
if(dlg.DoModal()==IDOK)
{
m_clr=dlg.m_cc.rgbResult;
}
}
//制作”设置”对话框上的”示例”的显示
void CSettingDlg::OnChangeLineWidth()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
Invalidate(); //使无效
}
void CSettingDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
Invalidate(); //使无效
}
void CSettingDlg::OnRadio2()
{
// TODO: Add your control notification handler code here
Invalidate(); //使无效
}
void CSettingDlg::OnRadio3()
{
// TODO: Add your control notification handler code here
Invalidate(); //使无效
}
void CSettingDlg::OnRadio4()
{
// TODO: Add your control notification handler code here
Invalidate(); //使无效
}
void CSettingDlg::OnRadio5()
{
// TODO: Add your control notification handler code here
Invalidate(); //使无效
}
//绘制改变的示例图形
void CSettingDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
UpdateData();
CPen pen(m_nLineStyle,m_nLineWidth,m_clr);
dc.SelectObject(&pen);
CRect rect;
GetDlgItem(IDC_SAMPLE)->GetWindowRect(&rect);
ScreenToClient(rect); //使原点移动到对话框的原点位置
//使示例图形居中显示
dc.MoveTo(rect.left+20,rect.top+rect.Height()/2);
dc.LineTo(rect.right-20,rect.top+rect.Height()/2);
// Do not call CDialog::OnPaint() for painting messages
}
展开全部
服了,问得简略,乎察袭答得详尽岁兄。
如果所有得代码都是没氏别人帮你做好,提高太慢了
读三个程序不如动手写一个程序
如果所有得代码都是没氏别人帮你做好,提高太慢了
读三个程序不如动手写一个程序
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
在View类中添加OnLButtonDown和OnLButtonUp函数大简
相应代码如下,LButtonDown中每一个/* */实现一种功能,是我以前照书上的写的,绝对能运行 你自己试下
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptOrigin=point;
CView::OnLButtonDown(nFlags, point);
}
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/*
HDC hdc;
hdc=::GetDC(m_hWnd);
MoveToEx(hdc,m_ptOrigin.x,m_ptOrigin.y,NULL);
LineTo(hdc,point.x,point.y);
::ReleaseDC(m_hWnd,hdc);*/
/*
CDC *pDC=GetDC();
pDC->MoveTo(m_ptOrigin);
pDC->LineTo(point);
ReleaseDC(pDC);*/
/*
CClientDC dc(this);//view Ïà¹Ø
//CClientDC dc(GetParent());//mainFrameÏà¹Ø
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);*/
/*
//模谈CWindowDC dc(this);
//CWindowDC dc(GetParent());//·ÃÎÊ´°¿Ú °üÀ¨±êÌâÀ¸
CWindowDC dc(GetDesktopWindow());//·ÃÎÊÕû¸öÆÁÄ»
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);*/
/*
CPen pen(PS_DASH,1,RGB(0,0,255));//DASH pen
CClientDC dc(this);
CPen *pOldPen=dc.SelectObject(&pen);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
dc.SelectObject(pOldPen);*/
/*
CBrush brush(RGB(0,0,255));//画刷
CClientDC dc(this);
dc.FillRect(CRect(m_ptOrigin,point),&brush);*/
/*
CBitmap bitmap; //位图画刷
bitmap.LoadBitmap(IDB_BITMAP1);
CBrush brush(&bitmap);
CClientDC dc(this);
dc.FillRect(CRect(m_ptOrigin,point),&brush);*/
CClientDC dc(this);
//旦仿碰dc.Rectangle(CRect(m_ptOrigin,point));//矩形
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
CBrush *pOldBrush=dc.SelectObject(pBrush);
dc.Rectangle(CRect(m_ptOrigin,point));
dc.SelectObject(pOldBrush);
CView::OnLButtonUp(nFlags, point);//透明矩形
}
相应代码如下,LButtonDown中每一个/* */实现一种功能,是我以前照书上的写的,绝对能运行 你自己试下
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_ptOrigin=point;
CView::OnLButtonDown(nFlags, point);
}
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
/*
HDC hdc;
hdc=::GetDC(m_hWnd);
MoveToEx(hdc,m_ptOrigin.x,m_ptOrigin.y,NULL);
LineTo(hdc,point.x,point.y);
::ReleaseDC(m_hWnd,hdc);*/
/*
CDC *pDC=GetDC();
pDC->MoveTo(m_ptOrigin);
pDC->LineTo(point);
ReleaseDC(pDC);*/
/*
CClientDC dc(this);//view Ïà¹Ø
//CClientDC dc(GetParent());//mainFrameÏà¹Ø
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);*/
/*
//模谈CWindowDC dc(this);
//CWindowDC dc(GetParent());//·ÃÎÊ´°¿Ú °üÀ¨±êÌâÀ¸
CWindowDC dc(GetDesktopWindow());//·ÃÎÊÕû¸öÆÁÄ»
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);*/
/*
CPen pen(PS_DASH,1,RGB(0,0,255));//DASH pen
CClientDC dc(this);
CPen *pOldPen=dc.SelectObject(&pen);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
dc.SelectObject(pOldPen);*/
/*
CBrush brush(RGB(0,0,255));//画刷
CClientDC dc(this);
dc.FillRect(CRect(m_ptOrigin,point),&brush);*/
/*
CBitmap bitmap; //位图画刷
bitmap.LoadBitmap(IDB_BITMAP1);
CBrush brush(&bitmap);
CClientDC dc(this);
dc.FillRect(CRect(m_ptOrigin,point),&brush);*/
CClientDC dc(this);
//旦仿碰dc.Rectangle(CRect(m_ptOrigin,point));//矩形
CBrush *pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
CBrush *pOldBrush=dc.SelectObject(pBrush);
dc.Rectangle(CRect(m_ptOrigin,point));
dc.SelectObject(pOldBrush);
CView::OnLButtonUp(nFlags, point);//透明矩形
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询