还剩24页未读,继续阅读
本资源只提供10页预览,全部文档请下载后查看!喜欢就下载吧,查找使用更方便
文本内容:
result!=miniumenum l,num2;CDC*pDC二GetDC;CString strl;str.Format_T%d,resultl;pDC-TextOut200,15O,strl;菜单项
2.
1.
2.1在菜单中添加一个选项文件也编辑更视图9显示谙在此处健人
2.
1.
2.2为菜单项添加一个事件处理函数以弹出对话框在view头文件中添加一个变量MyDialog dig;在事件处理函数中添加代码void CEx21View::OnDialog//TODO:在此添加命令处理程序代码dlg.DoModal;结
2.
1.
2.
32.
1.
3.1UpdateDatatrue;为传值函数,将输入的文本赋予变量
2.
1.
3.2CDC*pDC=GetDC;获取view类的OnDraw函数功能
2.
1.
3.3变量result,resultl为int型,应该用CString strl;str.Format_T%d,result1;语句转化成CString型
2.
1.
3.4pDC-TextOut200,l5O,str1;一次只能输出一个值,分2个按钮输出结果
2.
1.
3.5dlg.DoModal;语句触发对话框实验三编写一个单文档应用程序在主菜单中增加【曲线】、【线宽】和【颜色】
3.1Ex5个菜单项,【曲线】菜单中包含【正弦】和【余弦】两个菜单项;【线宽】菜单中3包含【线宽】和【线宽】两个菜单项;【颜色】菜单中包含【红色】和【蓝色】23两个菜单项为该应用程序创建一个新工具栏和一个快捷菜单,工具栏包含个按4钮,分别与菜单项【线宽】、【线宽】、【红色】和【蓝色】相对应,快捷菜23单上有【正弦】、【余弦】、【线宽】、【线宽】、【红色】和【蓝色】个菜236单项在状态栏中增加一个窗格,用来显示曲线的类型、线宽以及颜色的提示信实验步骤
3.2321制作菜单项,快捷菜单项,按钮项将对应选项ID分别设为正弦ID.S1NE余弦ID_COSINE线宽2ID_DRAW_LINE2线宽3ID_DRAW_LINE3红色ID_SETLINE_RED蓝色ID_S ETLINE_B LUE
3.
2.2为菜单项添加click事件在view类的头文件中添加变量public:int OperationType;//曲线类型int LineType;〃线宽int ColorType;//颜色void CEx5View::0nSine//TODO:在此添加命令处理程序代码OperationType=l;OnDrawNULL;this-Invalidatetrue;void CEx5View::OnCosine{//TODO:在此添加命令处理程序代码OperationType=2;OnDrawNULL;this-Invalidatetrue;void CEx5View::OnDrawLine2//TODO:在此添加命令处理程序代码LineType=5;OnDrawNULL;this-Invalidatetrue;void CEx5View::OnDrawLine3//TODO:在此添加命令处理程序代码LineType=16;OnDrawNULL;this-Invalidatetrue;void CEx5View::OnSetlineRed//TODO:在此添加命令处理程序代码ColorType=2;OnDrawNULL;this-Invalidatetrue;void CEx5View::OnSetlineBlue//TODO:在此添加命令处理程序代码ColorType=3;OnDrawNULL;this-Invalidatetrue;为快捷菜单添加代码在mainframe的头文件中添加public:CToolBar m_wndMYToolBar;在mainframe.cpp中的OnCreate函数中添加if!m_wndMYToolBar.CreateExthis,TBSTYLE.FLAT,WS.CHILD|WS_VISIBLE|CBRS_TOP|CBRS_GRIPPER|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC||!m_wndToolBar.LoadToolBarIDR_TOOLBARlTRACE未能创建工具栏\n”;return-1;//未能创建//TODO:如果不需要可停靠工具栏,则删除这三行m_wndMYToolBar.EnabIeDockingCBRS_ALIGN_ANY;EnableDockingCBRS_ALIGN_ANY;DockControlBarm_wndMYToolBar;在mainframe类中重写函数OnContextMenuvoid CMainFrame::OnContextMenuCWnd*pWnd,CPoint point//TODO:在此处添加消息处理程序代码CMenu menu;ifmenu.LoadMenuIDR_POPUP_MENU CMenu*pPopup=menu.GetSubMenu0;pPopup-TrackPopupMenuTPM_LEFTALIGN|TPM_RIGHTBUTTON,point.x,point.y,this;
3.
2.3添加画法代码在view类的OnDraw函数中添加void CEx5View::OnDrawCDC*pDC CEx5Doc*pDoc二GetDocument;ASSERT_VALIDpDoc;if!pDoc return;CClientDC pcthis;pc.SetMapModeMM_TEXT;pc.SetWindowOrgCPoint-300,-300;pc.MoveTo0,0;pc.LineTo420,0;pc.MoveTo0,0;pc.LineTo0,-220;//pc-TextOut50,10,1,r,;CStringArray s;s.SetSize8,-l;s
[0]=,r,;s[l]=,2,;s
[2]=3,;s
[3]=,4;s
[4]=,5;s
[5]=6,,;s
[6]=7,;s
[7]=,8;fbrint i=l;i=8;i++{pc.MoveToi*50,-l0;pc.LineToi*50,+10;pc.TextOuti*50,10,s[i-l];int x,y,j;float a;pc.MoveTo0,0;CPen Pen;switch ColorTypecase2:Pen.CreatePenPS_SOLID,LineType,RGB255,0,0;break;case3:Pen.CreatePenPS_SOLID,LineType,RGB0,0,255;break;CPen*OldPen=pc.SelectObjectPen;switchOperationType forj=0;j=400;j++x二j;a=j;y=-50*sina/50;pc.LineTox,y;}break;forj=0;j=400;j++x二j;a=j;y=-50*cosa/50;pc.LineTox,y;}break;pc.SelectObjectOldPen;//TODO:在此处为本机数据添加绘制代码状态栏在mainframe的头文件中添加public:CStatusBar m_wndStatusBar;在mainframe中的数组static UINTindicators!]=ID_SEPARATOR,//状态行指示器IDJNDICATOR_CAPS,IDJNDICATOR_NUM,IDJNDICATOR_SCRL,;中添加3个ID:ID_LINE_TYPE;ID_LINE_COLOR;ID_LINE_SYM;在mainframe的OnCreate函数中添加m_wndStatusBar.SetPaneInfo1,ID_LINE_TYPE,SBPS_POPOUT,50;m_wndStatusBar.SetPaneInfo2,ID_LINE_COLOR,SBPS_POPOUT,50;m_wndStatusBar.SetPaneInfo2,ID_LINE_SYM,SBPS_POPOUT,50;实验四自定义一个学生信息类,包括学生姓名,电话,地址,学号使用链表模板存
4.1贮班级学生信息,使用显示,要求有数据导航功能(参考.附件)Cformview1,
4.L1制作一个对话框
4.
1.
1.1在view类中添加对话框相应控件的变量CString StuName;int StuGrade;CString StuAddress;int StuNumber;
4.
1.
1.2插入3个函数以获取、删除和插入对话框输入的信息void CEx41View::GetInfoPOSITION position{ifposition{Student*student=m_pList-GetAtposition;StuName=student-StuName;StuGrade=student-StuGrade;StuAddress=student-StuAddress;StuNumber=student-StuNumber;}else{Getlnfo;UpdateDatafalse;void CEx41View::GetInfo{StuName=MH;StuGrade=O;StuAddress=,1H;StuNumber=O;UpdateDatafalse;CDialog*this-GotoDlgCtrlGetDlgItemIDC_STU_NAME;void CEx41View::InsertstudentPOSITION position{ifUpdateDatatrue{Student*student=new Student;student-StuName=StuName;student-StuGrade=StuGrade;student-StuAddress=StuAddress;student-StuNumber=StuNumber;m_position=m_pList-InsertAfterm_position,student;
4.
1.
1.3添加消息处理函数DoDataExchange^OnlnitialUpdate和OnUpdatevoid CEx41View::DoDataExchangeCDataExchange*pDX//TODO:在此添加专用代码和/或调用基类CFormView::DoDataExchangepDX;DDX_TextpDX,IDC_STU_NAME,StuName;DDV_MaxCharspDX,StuName,30;DDX_TextpDX,IDC_STU_GRADE,StuGrade;DDV_MinMaxIntpDX,StuGrade,0,100;DDX_TextpDX,IDC_STU_ADRESS,StuAddress;DDV_MaxCharspDX,StuAddress,50;DDX_TextpDX,IDC_STU_NUMBER,StuNumber;DDV_MinMaxIntpDX,StuNumber,0,999999;void CEx41View::OnInitialUpdate//TODO:在此添加专用代码和/或调用基类m_pList=GetDocument-GetList;CFormView::OnInitialUpdate;void CEx41View::OnUpdateCView*pSender,LPARAM IHint,CObject*pHint//TODO:在此添加专用代码和/或调用基类m_position=m_pList-GetHeadPosition;
4.
1.
1.4为控件clear添加事件处理函数void CEx41View::OnBnClickedStuClear//TODO:在此添加控件通知处理程序代码Getlnfo;制作一个菜单项学生信息话在此处键入insertdeleteFirstPrevi ousNextLast话在此处键入为菜单项添加消息处理函数Command型void CEx41View::OnStuInsert//TODO:在此添加命令处理程序代码TRACEEntering CEx41View::OnStuInsert\n;InsertStudentm_position;GetDocument-SetModifiedFlag;GetDocument-UpdateAllViewsthis;void CEx41View::OnStuDelete//TODO:在此添加命令处理程序代码POSITION pos;i fpos=m_position!=NULL{m_pList-GetNextpos;if==NULL{pospos=m_pList-GetHeadPosition;ifpos==m_position{pos=NULL;Getlnfopos;Student*stu=m_pList-GetAtDisposition;m_pList-RemoveAtm_position;delete stu;m_position=pos;GetDocument-SetModifiedFlag;GetDocument-UpdateAllViewsthis;void CEx41View::OnStuFirst//TODO:在此添加命令处理程序代码if!m_pList-IsEmpty{m_position=m_pList-GetHeadPosition;Getlnfom_position;void CEx41View::OnStuPrevious//TODO:在此添加命令处理程序代码POSITION pos;ifpos=m_position!=NULL{m_pList-GetPrevpos;ifpos{Getlnfopos;m_position=pos;void CEx41View::OnStuNext//TODO:在此添加命令处理程序代码POSITION pos;ifpos=m_position!=NULL{m_pList-GetNextpos;ifpos{Getlnfopos;m_position=pos;实验一
1.1显示一首诗在view类的ondraw函数中添加代码如下void CExl1View::OnDrawCDC*pDC CExlI Doc*pDoc二GetDocumentO;ASSERT_VALIDpDoc;if!pDoc return;//TODO:在此处为本机数据添加绘制代码CString s
[4];s
[0]=人生得意须尽欢,莫使金樽空对,月s[l]二两岸青山相对出,孤帆一片日边来s
[2]=孤帆远影碧空尽,惟见长江天际流”;s
[3]=飞流直下三千尺,疑是银河落九天”;forint i=0;i4;i++pDC-TextOutl00,100+20*i,s[i];
1.2画一个坐标系,画函数y=sinx,x£-2i,2»的图像在view类的ondraw函数中添加代码如下void CEx12View::OnDrawCDC5fs pDC CExl2Doc*pDoc=GetDocument;ASSERT_VALIDpDoc;if!pDoc return;//TODO:在此处为本机数据添加绘制代码pDC-SetMapModeMM_TEXT;pDC-SetWindowOrgCPoint-370,-250;pDC-MoveTo0,0;pDC-LineTo420,0;pDC-MoveTo0,0;pDC-LineTo0,-220;pDC-MoveTo0,0;pDC-LineTo-420,0;pDC-MoveTo0,0;pDC-LineTo0,220;void CEx41View::OnStuLast//TODO:在此添加命令处理程序代码if!m_pList-IsEmpty{m_position=m_pList-GetTailPosition;Getlnfom_position;Update型void CEx41View::OnUpdateStuFirstCCmdUI*pCmdUI//TODO:在此添加命令更新用户界面处理程序代码POSITION pos;pos=m_pList-GetHeadPosition;pCmdUI-Enablem_position!=NULLpos!=m_position;void CEx41View::OnUpdateStuLastCCmdUI*pCmdUI//TODO:在此添加命令更新用户界面处理程序代码POSITION pos;pos=m_pList-GetTailPosition;pCmdUI-Enablem_position!=NULLpos!=m_position;void CEx41View::OnUpdateStuDeleteCCmdUI*pCmdUI//TODO:在此添加命令更新用户界面处理程序代码pCmdUI-Enablem_position!=NULL;对附件加以修改,增加对颜色,笔宽的处理(参考附件
4.23)2做以下修改:
4.
2.1在view类中加入2个变量protected:CStroke*m_pStrokeCur;//the stroke in progressCPoint m_ptPrev;//the lastmouse ptin thestrokeinprogress
4.
2.2加入3个消息处理函数void CScribbleView::OnLButtonDownUINT,CPoint point//Pressing the mouse buttonin theview windowstarts anew strokem_pStrokeCur=GetDocument-NewStroke;//Add firstpoint tothe new strokem_pStrokeCur-m_pointArray.Addpoint;SetCapture;//Capture the mouse untilbutton up.m_ptPrev=point;//Serves as the MoveToanchor pointfor the//LineTo thenext point,asthe user dragsthe//mouse.return;void CScribbleView::OnLButtonUpUINT,CPoint point//Mouse buttonup is interesting in the Scribble application//only ifthe useris currentlydrawing anew strokeby dragging//the capturedmouse.if GetCapture!=thisreturn;//If this window viewdidnt capturethemouse,//then theuser isntdrawing in thiswindow.CScribbleDoc*pDoc二GetDocument;CClientDC dcthis;CPen*pOldPen二dc.SelectObjectpDoc-GetCurrentPen;dc.MoveTom_ptPrev;dc.LineTopoint;dc.SelectObjectpOldPen;m_pStrokeCur-m_pointArray.Addpoint;ReleaseCapture;//Release themouse captureestablished at//the beginningof themouse drag.return;void CScribbleView::OnMouseMoveUINT,CPoint point//Mouse movementisinterestingin theScribbleapplication//only iftheuseris currentlydrawing anewstrokeby dragging//the capturedmouse.if GetC叩ture!=this return;//If thiswindow viewdidnt capturethemouse,//then theuser isntdrawinginthiswindow.CClientDC dcthis;m_pStrokeCur-m_pointArray.Addpoint;//Draw aline fromthe previousdetected pointinthemouse//drag tothe currentpoint.CPen*pOldPen=dc.SelectObjectGetDocument-GetCurrentPen;dc.MoveTom_ptPrev;dc.LineTopoint;dc.SelectObjectpOldPen;m_ptPrev=point;return;
4.
2.3在OnDraw函数中加入代码void CScribbleView::OnDrawCDC*pDC{CScribbleDoc*pDoc=GetDocument;ASSERT_VALIDpDoc;//The viewdelegates thedrawing ofindividual strokesto//CStroke::DrawStroke.CTypedPtrListCObList,CStroke*strokeList=pDoc-m_strokeList;POSITION pos=strokeList.GetHeadPosition;while pos!=NULL CStroke*pStroke=strokeList.GetNextpos;pStroke-DrawStrokepDC;实验五
5.1实验内容1使用单文档应用研究程序及分裂视图方法,左窗格使用CformView,添加两个列表框,一个设定颜色红、绿、兰;一个设定sin、cos;右窗格使用Cview,画一个坐标系,显示正余弦图像2参考msdn示例之mdi;在多文档应用程序框架下使用菜单分别打开两个不同的文档一个文档及相关视图用来进行诗行显示;另一个实现正、余弦曲线显示.诗行显示,正、余弦曲线显示由菜单控制
5.2制作过程521建立一个工程Curve并在原工程中选择添力口一>现有项一>CurveView.h/CurveView.cpp在MainFrm.cpp中添加#include CurveView.h在CurveView.cpp中添加#include nstdafx.hinclude”Ex
5.h”#include Ex5View.h#include MainFrm.h#include nEx5Doc.hn#include nmath.hn4£CurveView.hl1tl#pragma once上方添加include nEx5Doc.h
5.
2.
1.1CurveView.cpp
5.
2.
1.
1.1在Curve类中添加2个变量public:intm_string;int color;在视图类的头文件中加上#include math.h
5.
2.L
1.2在OnDraw函数中添加画sin和cos曲线的代码void CCurve::OnDrawCDC*pDCCEx5Doc*pDoc=GetDocument;ASSERT_VALIDpDoc;if!pDocreturn;//TODO:在此处为本机数据添加绘制代码〃画出坐标系CRect rectClient;GetClientRectrectClient;pDC-SetMapMode MM.ANISOTROPIC;pDC-SetWindowExt1000,1000;pDC-SetViewportExt rectClient.right,-rectClient.bottom;pDC-SetViewportOrg rectClient.right/2,rectClient.bottom/2;//pDC-Ellipse-500,500,500,-500;pDC-MoveTo-500,0;pDC-LineTo500,0;pDC-MoveTo500,0;pDC-LineTo490,10;pDC-MoveTo500,0;pDC-LineTo490,-10;pDC-MoveTo0,-500;pDC-LineTo0,500;pDC-MoveTo0,500;pDC-LineTo-10,490;pDC-MoveTo0,500;pDC-LineTo10,490;forint i=-4;iv=4;i++CString str;str.Format_T%d,i;pDC-MoveToi*100,-5;pDC-LineToi*100,+5;pDC-TextOutW i*100,-5,str;forint i=-l;i=l;i++continue;CString str;str.Format_T%dn,i;pDC-MoveTo-5,i*100;pDC-LineTo+5,i*100;pDC-TextOutW+5,i*lOO,str;m_string=pDoc-m_string;color=pDoc-color;CPen pen;〃选择颜色switchcolor{case0:pen.CreatePenPS_SOLID,3,RGB255,0,0;break;pen.CreatePenPS_SOLID,3,RGB0,0,255;break;pen.CreatePenPS_SOLID,3,RGB0,255,0;break;CPen*oldPen=pDC-SelectObjectpen;〃选择线形switchm_string{case0:pDC-MoveTo-400,int100*sinfloat-4;forint i=-400;i=400;i++float ix,iy;int y;ix=floati/100;iy=sinix;y=int100*iy;pDC-LineTo i,y;break;case1:pDC-MoveTo-400,int100*cosfloat-4;forint i=-400;i=400;i++float ix,iy;int y;ix=floati/100;iy=cosix;y=int100*iy;pDC-LineTo i,y;break;pDC-SelectObjectoldPen;在MainFrame类中重写函数OnCreateClient,在头文件中加入public:CSplitterWnd m_wndSplitter;在M ainFrame.cpp中加入头文件#include nCurveView.hinclude HEx5View.hn并添加代码BOOL CMainFrame::OnCreateClientLPCREATESTRUCT/*lpcs*/,CCreateContext*pContext/*return m_wndSplitter.Createthis,2,2,//TODO:调整行数和列数CSize10,10,//TODO:调整最小窗格大小pContext;*/VERIFYm_wndSplitter.CreateStaticthis,l,2;VERIFYm_wndSplitter.CreateView0,0,RUNTIME_CLASSCEx5View,CSizel00,100,pContext;VERIFYm_wndSplitter.CreateViewO,l,RUNTIME_CLASSCCurveView,CSizel00,100,pContext;returntrue;
5.
2.3制作一个对话框设置Vertical ScrolTrueButtonl设置3个控件ID依次为IDC.LIST1IDC.LIST2IDC_BUTTON1为3个控件添加Ex5View的事件处理函数:void CEx5View::OnBnClickedButton1//TODO:在此添加控件通知处理程序代码CWnd*pwnd;pwnd=GetDIgItem IDC_STATIC;CDC*pDC=pwnd-GetDC;pDC-Ellipse0,0,100,100;void CEx5View::OnLbnSelchangeList1{//TODO:在此添加控件通知处理程序代码CEx5Doc*pDoc=GetDocument;ASSERT_VALIDpDoc;if!pDocreturn;CListBox*pCtrl=CListBox*GetDlgItem IDC_LIST1;m_string=pCtrl-GetCurSel;pDoc-m_string=m_string;pDoc-Update AllViews NULL;void CEx5View::OnLbnSelchangeList2//TODO:在此添加控件通知处理程序代码CEx5Doc*pDoc二GetDocument;ASSERT_VALIDpDoc;if!pDocreturn;CListBox*pCtrl=CListBox*GetDlgItem IDC.LIST2;col or=pC tri-GetC urSel;pDoc-color=color;pDoc-UpdateAHViews NULL;重写函数OnlrdtialUpdatevoid CEx5View::OnInitialUpdateCFormView::OnInitialUpdate;GetParentFrame-RecalcLayout;ResizeParentToFit;CListBox*ptrl=CListBox*GetDlgItemIDC_LISTl;ptrl-AddString_THsinx;ptrl-AddString_Tcosx;ptrl-SetCurSelO;CListBox*ptrl2=CListBox*GetDlgItemIDC_LIST2;pE2・AddString_T“红;ptrl2-AddString_T“绿;ptrl2-AddString_T^n;ptrl2-SetCurSel0;//pDC-TextOut50,10,uln;CStringArray p;p.SetSize8,-l;p
[0]=-l”;p[lH-2M2]=-3;p
[3]=“4;p
[4]=”S;p
[5]=”-6;p
[6]=”-7;p
[7]=-8”;forint i=l;i=8;i++{pDC-MoveToi*-50,-l0;pDC-LineToi*-50,+10;pDC-TextOuti*-50,10,p[i-l];CStringArray s;s.SetSize8,-l;s|0]=nr,;s[l]=,2,,;s
[2]=n3,;s|31=,,4,;s
[4]=5*;s[5|=6,;s
[6]=n7;s|7|=,,8n;forint i=l;i=8;i++{pDC-MoveToi*50,-l0;pDC-LineToi*50,+10;pDC-TextOuti*50,l0,s[i・1];int x,y,j;float a;pDC-MoveTo0,0;forj=0;j=315;j++{x=j;a二j;y=-50*sina/50;pDC-LineTox,y;}pDC-MoveTo0,0;forj=0;j=-315;j-{x=j;a=j;y=-50*sina/50;pDC-LineTox,y;}
1.3显示资源中的一幅位图131在资源视图中找到Bitmap右键添加一个位图ID_BITMAP1并添加函数132在view类的属性找到消息WM ERASEBKGNDOnEraseBkgn V
1.
3.2在函数OnEraseBkgnd中添加代码如下BOOL CEx13View::OnEraseBkgndCDC*pDC//TODO:在此添加消息处理程序代码和/或调用默认值CBitmap bitmap;bitmap.LoadBitmapIDB_BITM AP1;BITMAP bmp;bitmap.GetBitmapbmp;CDC dcCompatible;dcCompatible.CreateCompatibleDCpDC;dcCompatible.SelectObjectbitmap;CRect rect0,0,500,500;GetClientRectrect;pDC-BitBlt0,0,rect.Width,rect.Height,dcCompatible,0,0,SRCCOPY;〃原位图pDC-StretchBltO,O,rect.Width,rect.Height,dcCompatible,〃可对位图进行伸缩0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY;〃可对位图进行伸缩return TRUE;return CView::OnEraseBkgndpDC;
1.4GDI绘图之鼠标绘图.141画笔
1.
5.L1在view类中添加变量CString m_ptPrev;WM LBUTTONDOWH
1.
6.
1.2在view类中添加消息响应函数OnLB uttonDownvoid CExl41View::OnLButtonDownUINT nFlags,CPoint point//TODO:Add yourmessage handlercode hereand/or calldefaultSetCapture;m_ptPrev=point;CView::OnLButtonDownnFlags,point;
1.
7.
1.3在view类中添加消息响应函数OnLButtonUpvoid CEx141View::OnLButtonUpUINT nFlags,CPoint point//TODO:Add yourmessage handlercode hereand/or calldefault ifGetCapture!=thisreturn;CClientDC dcthis;dc.MoveTom_ptPrev;dc.LineTopoint;ReleaseCapture;CView::OnLButtonUpnFlags,point;
1.
8.
1.4在view类中添加消息响应函数OnMouseMovevoid CEx141View::OnMouseMoveUINT nFlags,CPoint point//TODO:Add yourmessage handlercode hereand/or calldefault ifGetCapture!=th isreturn;CClientDC dcthis;dc.MoveTom_ptPrev;dc.LineTopoint;m_ptPrev=point;CView::OnMouseMovenFlags,point;}142绘制直线在view类中添加变量CPoint m_bMouseDown;CPoint m_ptStart;CPoint m_ptOld;CPoint m_hCross;CPoint m_hArrow;CPoint nFlags;CPoint point;void CEx142View::OnLBu11onDown UINTnFlags,CPoint point//TODO:Add yourmessage handlercode hereand/or calldefault//TODO:Add yourmessage handlercode hereand/or calldefault m_bMouseDown=true;m_ptStart=point;m ptOld=point;SetCapture;CRect rect;GetClientRect ferect;ClientToScreen rect;ClipCursorrect;SetCursor m_hCross;〃设置鼠标形状为十字形CView::OnLButtonDownnFlags,point;void CExl42View::OnLButtonlJpUINT nFlags,CPoint point//TODO:Add yourmessage handlercode hereand/or calldefault ifm bMouseDown{mbMouseDown=false;ReleaseCapture;ClipCursor NULL;CClientDC dethis;de.SetROP2R2_NOT;de.MoveTo m_ptStart;〃这两行代码擦除从起点鼠标按下点到de.LineTo m_pt01d;〃上次鼠标移动到的位置之间的临时线de.SetROP2R2_COPYPEN;de.MoveTo m_ptStart;〃这两行代码从起点到鼠标当前位置画线de.LineTo point;//CExl42Doc*pDoc=GetDocument;〃得到文档类指针pDoc-m line=new CLinem_ptStart,point;〃创建CLine对象pDoc-m LineList.AddTailpDoc-m line;〃将pLine加入到链表中pDoc-SetModifiedFlagO;//Markthe document as having been modified,for//purposes ofconfirming FileClose.//pDoc-UpdateAHViews this,OL,pLine;SetCursor m_hArrow;〃设置鼠标形状为标准箭头形CView::OnLButtonUpnFlags,point;画矩形voidCEx143View::OnLBu11onDown UINTnFlags,CPointpoint//TODO:在此添加消息处理程序代码和/或调用默认值mbMouseDown=true;m_ptStart=point;m_pt01d=point;SetCapture;CRect rect;GetClientRectrect;ClientToScreen rect;ClipCursor ferect;//SetCursor mhCross;CVicw::OnLButtonDownnFlags,point;void CExl43View::OnLButtonUpUINT nFlags,CPoint point//TODO:在此添加消息处理程序代码和/或调用默认值ifm bMouseDown{mbMouseDown=false;ReleaseCapture;ClipCursor NULL;CClientDC dethis;de.SetROP2R2_N0T;//de.MoveTo m_ptStart;〃这两行代码擦除从起点鼠标按下点到//de.LineTo m_pt01d;de.Rectangle m_ptStart.x,m ptStart.y,m ptOld.x,m ptOld.y;〃上次鼠标移动到的位置之间的临时线de.SetR0P2R2_COPYPEN;//de.MoveTo m_ptStart;〃这两行代码从起点到鼠标当前位置画线//de.LineTo point;//de.Rectangle m_ptStart.x,m ptStart.y,point,x,point,y;//CExl42Doc*pDoc=GetDocument;〃得到文档类指针//pDoc-m_line=new CLinem_ptStart,point;〃创建CLine对象//pDoc-m LineList.AddTailpDoc-m line;〃将pLine加入到链表中//pDoc-SetModifiedFlagO;//Mark thedocumentashavingbeenmodified,for//purposes ofconfirming FileClose.//pDoc-UpdateAHViews this,OL,pLine;//SetCursor m_hArrow;〃设置鼠标形状为标准箭头形CView::OnLButtonUpnFlags,point;void CExl43View::On\louseMove UINTnFlags,CPoint point//TODO:在此添加消息处理程序代码和/或调用默认值if mbMouseDownCClientDC dethis;de.SetR0P2R2_N0T;〃绘制模式//de.MoveTo m_ptStart;〃这两行代码擦除从起点鼠标按下点到//dc.LineTo m_pt01d;〃上次鼠标移动到的位置之间的临时线de.Rectangle m_ptStart.x,m_ptStart.y,m_pt01d.x,m_pt01d.y;de.MoveTo m_ptStart;〃这两行代码从起点到鼠标当前位置画线//de.LineTo point;//de.Rectangle m_ptStart,x,m ptStart.y,point,x,point,y;m_pt01d-point;〃鼠标当前位置在下一次鼠标移动事件看来就是〃旧位置〃CView::OnMouseMovenFlags,point;实验二求两正整数的最大公约数和最小公倍速数,用一个函数求最大公约
2.1数,另一个函数求最小公倍数要求两正整数从对话框输入将最大公约数和最小公倍数在函数中输出ondraw制作一个对话框,并添加一个对话框类MyDialog
1.
1.
1.1Edit Control空间添加2个变量;int numl;int num
22.
1.
1.3在view类中添加2个变量int result;int result1;
2.
1.
1.4在MyDialog类中添加2个函数,用以求出最大公约数和最小公倍数int MyDialog::maxiumeint a,int bintmax=0;forint i=l;iabb:a;i++ifa%i==Ob%i==Omax=i;return max;int MyDialog::miniumeint c,int dintmin=O;forint i=O;i=c;i++forint j=1;j=d;j++ifc*j==d*imin二c*j;break;ifmin!=Obreak;return min;为最大公约数工具添加一个事件处理函数
2.
1.
1.5buttonlvoid MyDialog::OnBnClickedButton1//TODO:在此添加控件通知处理程序代码UpdateDatatrue;result=maxiumenuml,num2;CDC*pDC=GetDC;CString str;str.Format_T%d,result;pDC-TextOutl00,100,str;为最小公倍数工具添加一个事件处理函数
2.
1.
1.6button2void MyDialog::OnBnClickedButton2//TODO:在此添加控件通知处理程序代码UpdateDatatrue;。