课外实践报告

课外实践报告

课外实践报告

程序开发框架技术课外实践报告

所 在 班 级:

指 导 教 师:

起 止 时 间: 2012.12.17-2013.1.4 项 目 名 称: 静态分割窗口简单画图程序

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践·

项目基本信息

课外实践报告

一、 问题描述及分析

(1)创建对话框作为左分割窗口,包括图形选择按钮,颜色选择按钮和画刷选择按钮。

(2)例如当你选择图形为圆角矩形颜色为红色,画刷为实心画刷时,

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践· 在右边视图窗口画出相应的图形,用橡皮筋效果实现。给它加了三个消息映射函数OnLButtonUP( ),OnLButtonDown( ),OnMouseMove( )。

(3)当你选择相应的图形,颜色,画刷时下面状态栏也会显示你选择的信息,还有一个计时器显示当前时间。

二 、功能模块及结构描述

(1)自己创建视图窗口类CChooseView

{

创建对话框加入相应的控件,在状态栏下显示你在对话框中所选择的内容。

}

(2)默认视图窗口类CLi7_7View

{

根据左边图形、颜色、画刷的选择,在右边窗口画出相应图形。当选择左边

视图的例如圆角矩形,颜色红色,画刷实心画刷,可以再右边用橡皮筋效果画出相应图形。

}

(3)对状态栏设置CMainFrame

{

在状态栏窗格中有计时器显示时间,进行分割窗口

}

………

二、 主要流程描述

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践·

三、 使用说明

程序运行后,进入:

课外实践报告

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践·

课外实践报告

在如上所示的界面下进行基本的操作。

四、 问题及解决方法

⑴加画笔颜色时候老是出错,解决方法把画笔画刷设置的代码都写在

OnMouseMove函数中

⑵状态栏显示左边窗口所选信息时, 出现pMainFrame不能访问

m_wndStatusBar的错误,解决方法把m_wndStatusBarg改为公有成员

变量

⑶单独选其中一个或多个单选按钮程序不能单独运行,如只选圆角矩形按

钮就去画图不能进行程序出错,未解决

五、 课外实践总结

随着当今社会向信息化的发展,当然对画图工具的应用也越来越信息化程序化,特别是向windows操作系统这样的图形操作系统,这

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践· 就需要我们对程序中的知识进行继续研究和学习。不断提高自己的操作能力和逻辑能力。程序中也有许多不足的地方,有些想实现的功能并未能实现。对课本理论知识没有熟练地掌握好,有没有及时进行操作巩固,所以很多知识操作有点生疏,写出的程序效果并不尽如人意。这个过程中虽然挺困难的,经常就会被一个小小的问题卡住,可能要几个小时或是一天以上才能解决,但我坚持下来了,同时也锻炼了我的独立思考能力和对手操作能力。经过这次的课程设计我们明白遇到困难不放弃的重要性,知道了实践能力的重要性。感觉自己能力非常有限,需呀学习的知识还很多。

六、 主要源代码

(1)CChooseView类

void CChooseView::OnEllipse()

{

// TODO: Add your control notification handler code here CLi7_7Doc* pDoc=(CLi7_7Doc*)GetDocument();

pDoc->m_choose=2;

}

void CChooseView::OnRectangle()

{

// TODO: Add your control notification handler code here pDoc->UpdateAllViews(this);

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践· CLi7_7Doc* pDoc=(CLi7_7Doc*)GetDocument(); pDoc->m_choose=1;

}

void CChooseView::OnRed()

{

// TODO: Add your control notification handler code here CLi7_7Doc* pDoc=(CLi7_7Doc*)GetDocument(); pDoc->UpdateAllViews(this); pDoc->m_color=0;

}

void CChooseView::OnGreen()

{

// TODO: Add your control notification handler code here CLi7_7Doc* pDoc=(CLi7_7Doc*)GetDocument(); pDoc->UpdateAllViews(this); pDoc->m_color=1;

}

void CChooseView::OnBlue()

{

// TODO: Add your control notification handler code here CLi7_7Doc* pDoc=(CLi7_7Doc*)GetDocument(); pDoc->UpdateAllViews(this); pDoc->m_color=2;

} pDoc->UpdateAllViews(this);

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践·

void CChooseView::Onsolid()

{

// TODO: Add your control notification handler code here CLi7_7Doc* pDoc=(CLi7_7Doc*)GetDocument(); pDoc->m_brush=0;

}

void CChooseView::Onbdiag()

{

// TODO: Add your control notification handler code here CLi7_7Doc* pDoc=(CLi7_7Doc*)GetDocument(); pDoc->UpdateAllViews(this); pDoc->m_brush=2;

}

void CChooseView::Oncross()

{

// TODO: Add your control notification handler code here CLi7_7Doc* pDoc=(CLi7_7Doc*)GetDocument(); pDoc->UpdateAllViews(this); pDoc->m_brush=1;

}

void CChooseView::Onvert()

{

// TODO: Add your control notification handler code here pDoc->UpdateAllViews(this);

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践· CLi7_7Doc* pDoc=(CLi7_7Doc*)GetDocument(); pDoc->m_brush=3;

}

void CChooseView::OnRoundrect()

{

// TODO: Add your control notification handler code here CLi7_7Doc* pDoc=(CLi7_7Doc*)GetDocument(); pDoc->UpdateAllViews(this); pDoc->m_choose=0;

}

void CChooseView::OnUpdatePrompt(CCmdUI* pCmdUI) {

CLi7_7Doc* pDoc=(CLi7_7Doc*)GetDocument();

CMainFrame *pMainFrame=(CMainFrame*)AfxGetMainWnd(); CStatusBar *pStatusBar=&pMainFrame->m_wndStatusBar; CString str,str1,str2,str3; //根据用户选择确定状态栏提示信息 pDoc->UpdateAllViews(this);

if(pDoc->m_choose==0)

str1="圆角矩形,"; else if(pDoc->m_choose==1)

str1="矩形,";

else if(pDoc->m_color==0) str2="红色,"; str1="圆形,";

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践·

else if(pDoc->m_color==1) str2="绿色,";

else str2="蓝色,";

if(pDoc->m_brush==0) str3="实心画刷";

else if(pDoc->m_brush==1)

str3="水平垂直交叉"; else if (pDoc->m_brush==2)

str3="左下角到右上角";

}

(2)CLi7_7View

void CLi7_7View::OnLButtonDown(UINT nFlags, CPoint point) {

}

void CLi7_7View::OnLButtonUp(UINT nFlags, CPoint point) {

// TODO: Add your message handler code here and/or call default draw=FALSE; // TODO: Add your message handler code here and/or call default m_ptorigin=m_ptend=point; draw=TRUE; CView::OnLButtonDown(nFlags, point); else str=str1+str2+str3; pStatusBar->SetPaneText(1,str);//显示提示信息 str3="垂直线"; CView::OnLButtonUp(nFlags, point);

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践· }

void CLi7_7View::OnMouseMove(UINT nFlags, CPoint point) {

// TODO: Add your message handler code here and/or call default CClientDC dc(this); dc.SetROP2(R2_NOTXORPEN);

CLi7_7Doc* pDoc = GetDocument();

ASSERT_VALID(pDoc); CPen *PenOld,PenNew; CBrush BrushNew,*BrushOld; COLORREF PenColor=RGB(0,0,0);

switch (pDoc->m_color)

{ case 0: {

PenColor=RGB(255,0,0);

PenNew.CreatePen(PS_SOLID,2,PenColor);//创建画笔

}

break;

PenOld=dc.SelectObject(&PenNew); //选用画笔

case 1: { PenColor=RGB(0,255,0);

PenNew.CreatePen(PS_DASH,1,PenColor);//创建画笔

PenOld=dc.SelectObject(&PenNew); //选用画笔 }

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践·

break; case 2: { PenColor=RGB(0,0,255);

PenNew.CreatePen(PS_DOT,1,PenColor);//创建画笔

PenOld=dc.SelectObject(&PenNew); //选用画笔 } } break;

switch (pDoc->m_brush)

{

case 0:

{

} break; BrushNew.CreateSolidBrush(RGB(20,192,192)); BrushOld=dc.SelectObject(&BrushNew);

case 1:

{ BrushNew.CreateHatchBrush(HS_CROSS,RGB(128,128,0)); BrushOld=dc.SelectObject(&BrushNew); } break;

case 2:

{ BrushNew.CreateHatchBrush(HS_BDIAGONAL,RGB(0,0,255)); BrushOld=dc.SelectObject(&BrushNew);

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践·

} break; case 3:

break; }

if(draw==TRUE) { switch(pDoc->m_choose) { { BrushNew.CreateHatchBrush(HS_VERTICAL,RGB(255,255,0)); BrushOld=dc.SelectObject(&BrushNew); }

case 0:

;

;

break; } break; m_ptorigin=point; rect.SetRect(m_ptorigin,m_ptend); { CRect rect(m_ptorigin,m_ptend); dc.RoundRect(m_ptorigin.x,m_ptorigin.y,m_ptend.x,m_ptend.y,30,30)dc.RoundRect(m_ptorigin.x,m_ptorigin.y,m_ptend.x,m_ptend.y,30,30)

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践·

case 1: {

CRect rect(m_ptorigin,m_ptend); dc.Rectangle(&rect); m_ptorigin=point; rect.SetRect(m_ptorigin,m_ptend); } break; dc.Rectangle(&rect); case 2: { CRect rect(m_ptorigin,m_ptend); dc.Ellipse(&rect); m_ptorigin=point; rect.SetRect(m_ptorigin,m_ptend); dc.Ellipse(&rect); } dc.SelectObject(PenOld);//还原画笔 } break; PenNew.DeleteObject();//释放画笔*/ dc.SelectObject(BrushOld); BrushNew.DeleteObject(); }

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践· CView::OnMouseMove(nFlags, point);

}

(3)CMainFrame

BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs,CCreateContext* pContext)

{

VERIFY(m_wndSplitter.CreateStatic(this,1,2));

m_wndSplitter.CreateView(0,0,RUNTIME_CLASS(CChooseView),CSize(0,0),pContext);

m_wndSplitter.CreateView(0,1,RUNTIME_CLASS(CLi7_7View),CSize(0,0),pContext);

CChooseView* pWnd=(CChooseView*)m_wndSplitter.GetPane(0,0); CSize size=pWnd->GetTotalSize();

m_wndSplitter.SetColumnInfo(0,size.cx,1);

return true;

}

void CMainFrame::OnTimer(UINT nIDEvent)

{

// TODO: Add your message handler code here and/or call default CTime time; time=CTime::GetCurrentTime(); CString s=time.Format("%H:%M:%S"); m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CLOCK),s);

} CFrameWnd::OnTimer(nIDEvent);

课外实践报告

安阳师范学院 ·程序开发框架技术课外实践·

void CMainFrame::OnClose() {

} // TODO: Add your message handler code here and/or call default KillTimer(1);//关闭计时器 CFrameWnd::OnClose();

相关推荐