可视化复习资料.docx

上传人:b****7 文档编号:10470502 上传时间:2023-02-13 格式:DOCX 页数:24 大小:110.09KB
下载 相关 举报
可视化复习资料.docx_第1页
第1页 / 共24页
可视化复习资料.docx_第2页
第2页 / 共24页
可视化复习资料.docx_第3页
第3页 / 共24页
可视化复习资料.docx_第4页
第4页 / 共24页
可视化复习资料.docx_第5页
第5页 / 共24页
点击查看更多>>
下载资源
资源描述

可视化复习资料.docx

《可视化复习资料.docx》由会员分享,可在线阅读,更多相关《可视化复习资料.docx(24页珍藏版)》请在冰豆网上搜索。

可视化复习资料.docx

可视化复习资料

1、Windows程序必须至少有两个函数,一个的法定名称为WinMain的主程序,另一个为窗口函数

2、主程序如何结束

(1)关闭应用程序窗口;

(2)结束主程序的运行。

3、关闭程序的流程:

v4、句柄是Windows用来标识创建或使用应用程序的唯一的整数值。

v实例是Windows应用程序运行的副本。

5、WinMain函数的工作

①调用初始化函数,它注册窗口类、创建窗口以及执行任何其他必要的初始化工作;

②进入消息循环,以处理来自应用程序队列的消息;

③当消息循环检测到WM_QUIT消息时,终止应用程序。

6、显示和更新窗口

ShowWindow(hWnd,nCmdShow);

UpdateWindow(hWnd);

7、创建消息循环

{

MSGmsg;//消息

……

while(GetMessage(&msg,//消息结构

NULL,//接收消息句柄

0,//最低消息

0))//最高消息

{

TranslateMessage(&msg);//翻译消息

DispatchMessage(&msg);//传输消息

}

returnmsg.wParam;

}

8、定义菜单

先写菜单名,再写关键字MENU

9、描述菜单

(1)POPUP语句定义一个弹出式菜单

(2)MENUITEM语句定义菜单项、显示和标识符

10、通知程序重新绘图使用语句

InvalidateRect(hWnd,NULL,TRUE);

11、添加新功能

(1)修改头文件

(2)编制Wnd4Proc.cpp文件

(3)改编wnd4.cpp文件

12、Windows的对话框按照其与父窗口的关系可以分为两类:

modal和modeless对话框。

modeless对话框的特点是父窗口与对话框共同运行,model对话框是令其父窗口无效,直到对话框结束运行后,才将父窗口恢复为有效。

13、

14、classCMyWin:

publicCFrameWnd

{

public:

CMyWin(){}

protected:

afx_msgvoidOnPaint();

DECLARE_MESSAGE_MAP()//声明宏

};

BEGIN_MESSAGE_MAP(CMyWin,CFrameWnd)

ON_WM_PAINT()

END_MESSAGE_MAP()

voidCMyWin:

:

OnPaint()

{

CStringstr="Hello,MFC!

";//设置输出窗口的字符串内容

CRectrect(240,100,340,200);

CPaintDCdc(this);

dc.DrawText(str,&rect,DT_CENTER);

}

classCMyApp:

publicCWinApp

{

public:

BOOLInitInstance();

};

BOOLCMyApp:

:

InitInstance()

{

CMyWin*pFrame=newCMyWin;

pFrame->Create(0,_T("使用MFC的Win32Application"));

pFrame->ShowWindow

(1);//m_nCmdShow=1

pFrame->UpdateWindow();

this->m_pMainWnd=pFrame;

returnTRUE;

}

CMyApptheApp;//全局对象

15、基于对话框风格的设计实例

(1)界面设计

(2)设置成员变量

(3)增加消息处理函数

16、文档和视的关系:

17、函数作用:

通过CArchive类实现应用程序和文件的数据交换。

18、文档对象

OnNewDocument()函数、OnOpenDocument()函数默认调用DeleteContents()成员函数,以便清除当前文档对象中的所有数据

19、CFrameWnd类中重要的成员函数及其作用

Create(),为该CFrameWnd对象创建框架窗口

LoadFrame(),动态创建框架对象

20、文档模板

CDocTemplate∷CDocTemplate()

21、

(1).命令消息(WM_COMMAND)

一般性映射规则是:

ON_COMMAND(ID,MemberFxn)

(2).标准Windows的WM_类消息对应规则

WM_PAINT

(3).控件产生的(Notification)消息

ON_BN_CLICKED(ID,MemeberFxn)

22、三角形

//shiyan13_2View.cpp:

implementationoftheCShiyan13_2Viewclass

//

#include"stdafx.h"

#include"shiyan13_2.h"

#include"math.h"

#include"shiyan13_2Doc.h"

#include"shiyan13_2View.h"

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

//CShiyan13_2View

IMPLEMENT_DYNCREATE(CShiyan13_2View,CFormView)

BEGIN_MESSAGE_MAP(CShiyan13_2View,CFormView)

//{{AFX_MSG_MAP(CShiyan13_2View)

ON_BN_CLICKED(ID_RESET,OnReset)

ON_BN_CLICKED(IDBtnCal,OnBtnCal)

//}}AFX_MSG_MAP

//Standardprintingcommands

ON_COMMAND(ID_FILE_PRINT,CFormView:

:

OnFilePrint)

ON_COMMAND(ID_FILE_PRINT_DIRECT,CFormView:

:

OnFilePrint)

ON_COMMAND(ID_FILE_PRINT_PREVIEW,CFormView:

:

OnFilePrintPreview)

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

//CShiyan13_2Viewconstruction/destruction

CShiyan13_2View:

:

CShiyan13_2View()

:

CFormView(CShiyan13_2View:

:

IDD)

{

//{{AFX_DATA_INIT(CShiyan13_2View)

m_dAx=0.0;

m_dAy=0.0;

m_dBx=0.0;

m_dBy=0.0;

m_dCx=0.0;

m_dCy=0.0;

m_dAB=0.0;

m_dAC=0.0;

m_dBC=0.0;

//}}AFX_DATA_INIT

//TODO:

addconstructioncodehere

}

CShiyan13_2View:

:

~CShiyan13_2View()

{

}

voidCShiyan13_2View:

:

DoDataExchange(CDataExchange*pDX)

{

CFormView:

:

DoDataExchange(pDX);

//{{AFX_DATA_MAP(CShiyan13_2View)

DDX_Control(pDX,IDC_EDIT10,m_Display);

DDX_Text(pDX,IDC_EDIT1,m_dAx);

DDX_Text(pDX,IDC_EDIT2,m_dAy);

DDX_Text(pDX,IDC_EDIT3,m_dBx);

DDX_Text(pDX,IDC_EDIT4,m_dBy);

DDX_Text(pDX,IDC_EDIT5,m_dCx);

DDX_Text(pDX,IDC_EDIT6,m_dCy);

DDX_Text(pDX,IDC_EDIT7,m_dAB);

DDX_Text(pDX,IDC_EDIT8,m_dAC);

DDX_Text(pDX,IDC_EDIT9,m_dBC);

//}}AFX_DATA_MAP

}

BOOLCShiyan13_2View:

:

PreCreateWindow(CREATESTRUCT&cs)

{

//TODO:

ModifytheWindowclassorstylesherebymodifying

//theCREATESTRUCTcs

returnCFormView:

:

PreCreateWindow(cs);

}

voidCShiyan13_2View:

:

OnInitialUpdate()

{

CFormView:

:

OnInitialUpdate();

GetParentFrame()->RecalcLayout();

ResizeParentToFit();

m_dAx=GetDocument()->m_dAx;

m_dAy=GetDocument()->m_dAy;

m_dBx=GetDocument()->m_dBx;

m_dBy=GetDocument()->m_dBy;

m_dCx=GetDocument()->m_dCx;

m_dCy=GetDocument()->m_dCy;

m_dAB=GetDocument()->m_dAB;

m_dAC=GetDocument()->m_dAC;

m_dBC=GetDocument()->m_dBC;

UpdateData(false);//通知View

}

/////////////////////////////////////////////////////////////////////////////

//CShiyan13_2Viewprinting

BOOLCShiyan13_2View:

:

OnPreparePrinting(CPrintInfo*pInfo)

{

//defaultpreparation

returnDoPreparePrinting(pInfo);

}

voidCShiyan13_2View:

:

OnBeginPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)

{

//TODO:

addextrainitializationbeforeprinting

}

voidCShiyan13_2View:

:

OnEndPrinting(CDC*/*pDC*/,CPrintInfo*/*pInfo*/)

{

//TODO:

addcleanupafterprinting

}

voidCShiyan13_2View:

:

OnPrint(CDC*pDC,CPrintInfo*/*pInfo*/)

{

//TODO:

addcustomizedprintingcodehere

}

/////////////////////////////////////////////////////////////////////////////

//CShiyan13_2Viewdiagnostics

#ifdef_DEBUG

voidCShiyan13_2View:

:

AssertValid()const

{

CFormView:

:

AssertValid();

}

voidCShiyan13_2View:

:

Dump(CDumpContext&dc)const

{

CFormView:

:

Dump(dc);

}

CShiyan13_2Doc*CShiyan13_2View:

:

GetDocument()//non-debugversionisinline

{

ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CShiyan13_2Doc)));

return(CShiyan13_2Doc*)m_pDocument;

}

#endif//_DEBUG

/////////////////////////////////////////////////////////////////////////////

//CShiyan13_2Viewmessagehandlers

voidCShiyan13_2View:

:

OnReset()

{

//TODO:

Addyourcontrolnotificationhandlercodehere

m_dAx=0.0;m_dAy=0.0;

m_dBx=0.0;m_dBy=0.0;

m_dCx=0.0;

m_dCy=0.0;m_dAB=0.0;

m_dAC=0.0;m_dBC=0.0;

UpdateData(false);//更新各编辑控件

CRectrect;

m_Display.GetClientRect(&rect);

m_Display.InvalidateRect(&rect);

//清除绘图客户区矩形

}

voidCShiyan13_2View:

:

OnCancel()

{

//TODO:

Addyourcontrolnotificationhandlercodehere

PostQuitMessage(0);

}

voidCShiyan13_2View:

:

OnBtnCal()

{

//TODO:

Addyourcontrolnotificationhandlercodehere

//TODO:

Addyourcontrolnotificationhandlercodehere

//计算边长

UpdateData(true);

m_dAB=sqrt((m_dAx-m_dBx)*(m_dAx-m_dBx)+

(m_dAy-m_dBy)*(m_dAy-m_dBy));

m_dAC=sqrt((m_dAx-m_dCx)*(m_dAx-m_dCx)+

(m_dAy-m_dCy)*(m_dAy-m_dCy));

m_dBC=sqrt((m_dCx-m_dBx)*(m_dCx-m_dBx)+

(m_dCy-m_dBy)*(m_dCy-m_dBy));

UpdateData(false);//显示边长

//准备将数据送往文档

UpdateData();//数据从控制框向文档变量传输有效

CShiyan13_2Doc*pDoc=GetDocument();//指向文档

//的指针

if(m_dAx!

=pDoc->m_dAx)pDoc->m_dAx=m_dAx;

//将值传给文档的相应变量

if(m_dAy!

=pDoc->m_dAy)pDoc->m_dAy=m_dAy;

if(m_dBx!

=pDoc->m_dBx)pDoc->m_dBx=m_dBx;

if(m_dBy!

=pDoc->m_dBy)pDoc->m_dBy=m_dBy;

if(m_dCx!

=pDoc->m_dCx)pDoc->m_dCx=m_dCx;

if(m_dCy!

=pDoc->m_dCy)pDoc->m_dCy=m_dCy;

if(m_dAB!

=pDoc->m_dAB)pDoc->m_dAB=m_dAB;

if(m_dAC!

=pDoc->m_dAC)pDoc->m_dAC=m_dAC;

if(m_dBC!

=pDoc->m_dBC)pDoc->m_dBC=m_dBC;

//准备画图

CDC*pdc;CRectrect;

pdc=m_Display.GetDC();

m_Display.GetClientRect(&rect);

InvalidateRect(&rect,true);

m_Length=rect.Width();

m_Width=rect.Height();

pdc->MoveTo(int(m_dAx/200*m_Length),

int(m_dAy/200*m_Width));

pdc->LineTo(int(m_dBx/200*m_Length),

int(m_dBy/200*m_Width));

pdc->LineTo(int(m_dCx/200*m_Length),

int(m_dCy/200*m_Width));

pdc->LineTo(int(m_dAx/200*m_Length),

int(m_dAy/200*m_Width));

//标注顶点

pdc->TextOut(int(m_dAx/200*m_Length),

int(m_dAy/200*m_Width),"A");

pdc->TextOut(int(m_dBx/200*m_Length),

int(m_dBy/200*m_Width),"B");

pdc->TextOut(int(m_dCx/200*m_Length),

int(m_dCy/200*m_Width),"C");

}

23、直方图

//PlotView.cpp:

implementationoftheCPlotViewclass

//

#include"stdafx.h"

#include"Plot.h"

#include"PlotDoc.h"

#include"PlotView.h"

#ifdef_DEBUG

#definenewDEBUG_NEW

#undefTHIS_FILE

staticcharTHIS_FILE[]=__FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

//CPlotView

IMPLEMENT_DYNCREATE(CPlotView,CView)

BEGIN_MESSAGE_MAP(CPlotView,CView)

//{{AFX_MSG_MAP(CPlotView)

//NOTE-theClassWizardwilladdandremovemappingmacroshere.

//DONOTEDITwhatyouseeintheseblocksofgeneratedcode!

//}}AFX_MSG_MAP

//Standardprintingcommands

ON_COMMAND(ID_FILE_PRINT,CView:

:

OnFilePrint)

ON_COMMAND(ID_FILE_PRINT_DIRECT,CView:

:

OnFilePrint)

ON_COMMAND(ID_FILE_PRINT_PREVIEW,CView:

:

OnFilePrintPreview)

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

//CPlotViewconstruction/destruction

CPlotView:

:

CPlotView()

{

//TODO:

addconstructioncodehere

}

CPlotView:

:

~CPlotView()

{

}

BOOLCPlotView:

:

PreCreateWindow(CREATESTRUCT&cs)

{

//TODO:

ModifytheWindowclassorstylesherebymodifying

//theCREATESTRUCTcs

returnCView:

:

PreCreateWindow(cs);

}

/////////////////////////////////////////////////////////////////////////////

//CPlotViewdrawing

voidCPlotView:

:

OnDraw(CDC*pDC)

{

CPlotDoc*pDoc=GetDocument();

ASSERT_VALID(pDoc);

//TODO:

adddrawcodefornativedatahere

//坐标系

pDC->SetMapMode(MM_ISOTROPIC);

pDC->SetViewportOrg(50,250);//设置原点位置

pDC->MoveTo(0,0);//抬笔移到圆点

pDC->LineTo(1100,0);//画水平线

pDC->MoveTo(0,0);//返回原点

pDC->LineTo(0,600);//画垂直线

CBrushbrush;//创建画刷

brush.CreateSolidBrush(RGB(250,0,0));//设置红色

pDC->SelectObject(brush);//选择画刷

intch='A';//第一销售点标记

for(inti=1;i<6;i++,ch++)//画直方图并写字

{

pDC->Rectangle(200*i,0,200*i+40,pDoc->m_num[i-1]);

pDC->TextOut(200*i+10,-10,ch);

}

}

/////////////////////////////////////////////////////////////////////////////

//CPlotViewprinting

BOOLCPlotView:

:

OnPreparePrinting(CPrintInfo*pInfo)

{

//defaultpreparation

returnDoPreparePrinting(pInfo);

}

voidCPlotView:

:

OnBeginPrinting(CDC*/

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 笔试

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1