📄 zhengyappwizardview.cpp
字号:
// ZhengyAppWizardView.cpp : implementation of the CZhengyAppWizardView class
//
#include "stdafx.h"
#include "ZhengyAppWizard.h"
#include "ZhengyAppWizardDoc.h"
#include "ZhengyAppWizardView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CZhengyAppWizardView
IMPLEMENT_DYNCREATE(CZhengyAppWizardView, CView)
BEGIN_MESSAGE_MAP(CZhengyAppWizardView, CView)
//{{AFX_MSG_MAP(CZhengyAppWizardView)
ON_COMMAND(ID_MENUITEM32771, OnShowData)
ON_COMMAND(ID_MENUITEM_zhexiantu, OnShow_zhexiantu)
ON_COMMAND(ID_MENUITEM_zhuzhuangtux, OnShow_zhuzhuangtux)
ON_COMMAND(ID_MENUITEM_zhuzhuangtuy, OnShow_zhuzhuangtuy)
//}}AFX_MSG_MAP
// Standard printing commands
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()
/////////////////////////////////////////////////////////////////////////////
// CZhengyAppWizardView construction/destruction
CZhengyAppWizardView::CZhengyAppWizardView()
{
// TODO: add construction code here
}
CZhengyAppWizardView::~CZhengyAppWizardView()
{
}
BOOL CZhengyAppWizardView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CZhengyAppWizardView drawing
void CZhengyAppWizardView::OnDraw(CDC* pDC)
{
int zy_ShowData=1;//显示数据
int zy_Show_zhexiantu=2;//显示折线图
int zy_Show_zhuzhuangtux=3;//显示柱状图在X轴
int zy_Show_zhuzhuangtuy=4;//显示柱壮图在Y轴
CZhengyAppWizardDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int* zy_Data=pDoc->GetFirstData();//从DOC类获取数据
int zy_temp=pDoc->GetTemp();//获取临时变量
RECT zy_rect;//存储获取的窗口矩形
pDC->SetMapMode(MM_ANISOTROPIC);//设置映射模式
GetClientRect(&zy_rect);
int WndHeight=zy_rect.bottom-zy_rect.top;//客户区域的高度
int WndWidth=zy_rect.right-zy_rect.left;//客户区域的宽度
//显示生成的数据
if(zy_temp==zy_ShowData)//是否是显示数据由菜单项的单击事件设置 也可方便调试
{
TEXTMETRIC tm;
SIZE size;
char zy_DataCh[3]="";
pDC->GetTextMetrics(&tm);//获取字符信息
int zy_x=tm.tmAveCharWidth;
int zy_y=tm.tmHeight+tm.tmExternalLeading;
int zy_x0=zy_x;
for(int count=0;count<90;count++)
{
int i=count/30+1;//数组位置确定
int j=count%30+1;
if(count%30==0)
zy_x0=zy_x;//换行
itoa(zy_Data[count],zy_DataCh,10);
pDC->TextOut(zy_x0,zy_y*i,zy_DataCh);
size=pDC->GetTextExtent(zy_DataCh,strlen(zy_DataCh));//获取字符串信息
zy_x0=zy_x0+size.cx+tm.tmAveCharWidth; //输出位置
}
}
if(zy_temp==zy_Show_zhexiantu)
{
CPen zy_pen1(PS_SOLID,1,RGB(0,0,0));
int zy_show_width=WndWidth-200;//坐标系显示的宽度
int zy_show_height=WndHeight-100;//坐标系显示的高度
int zy_AveWidth=zy_show_width/30;
int zy_AveHeight=zy_show_height/20;
//描绘坐标系
CPen* zy_OldPen1=pDC->SelectObject(&zy_pen1);
pDC->MoveTo(zy_show_width+120,zy_show_height+50);
pDC->LineTo(100,zy_show_height+50);//横向长度(长20)
pDC->LineTo(100,30);//纵高度(高20)
pDC->LineTo(95,35);
pDC->MoveTo(100,30);
pDC->LineTo(105,35);
pDC->MoveTo(zy_show_width+120,zy_show_height+50);
pDC->LineTo(zy_show_width+115,zy_show_height+45);
pDC->MoveTo(zy_show_width+120,zy_show_height+50);
pDC->LineTo(zy_show_width+115,zy_show_height+55);
pDC->TextOut(zy_show_width+120,zy_show_height+50,"X");
pDC->TextOut(85,25,"Y");
for(int zy_i=0;zy_i<=30;zy_i++)//横坐标刻度
{
char zy_str[3]="";
itoa(zy_i,zy_str,10);
pDC->MoveTo(100+zy_i*zy_AveWidth,zy_show_height+50);
pDC->LineTo(100+zy_i*zy_AveWidth,zy_show_height+53);
pDC->TextOut(97+zy_i*zy_AveWidth,zy_show_height+55,zy_str);
}
for( zy_i=1;zy_i<=20;zy_i++)//纵坐标刻度
{
char zy_str[3]="";
itoa(zy_i*10,zy_str,10);
pDC->MoveTo(100,zy_show_height+50-zy_AveHeight*zy_i);
pDC->LineTo(97,zy_show_height+50-zy_AveHeight*zy_i);
pDC->TextOut(70,zy_show_height+42-zy_AveHeight*zy_i,zy_str);
}
pDC->SelectObject(zy_OldPen1);
//描绘折线图
for(zy_i=0;zy_i<3;zy_i++)
{
CPen zy_Pen;
LOGBRUSH zy_logBrush;
zy_logBrush.lbStyle=BS_SOLID;
if(zy_i==0)
zy_logBrush.lbColor=RGB(255,0,0);//三种染色
if(zy_i==1)
zy_logBrush.lbColor=RGB(0,255,0);
if(zy_i==2)
zy_logBrush.lbColor=RGB(0,0,255);
zy_Pen.CreatePen(PS_SOLID, 1, &zy_logBrush);//设置画笔
CPen* zy_OldPen=pDC->SelectObject(&zy_Pen);
int zy_temp1=zy_Data[0+zy_i*30]/10*zy_AveHeight;//单位长度
int zy_temp2=zy_Data[0+zy_i*30]%10*0.1*zy_AveHeight;
pDC->MoveTo(100+zy_AveWidth,zy_show_height+50-zy_temp1-zy_temp2);//每组的第1个点
for(int zy_j=1;zy_j<30;zy_j++)
{
zy_temp1=zy_Data[zy_j+zy_i*30]/10*zy_AveHeight;//帮助确定长度
zy_temp2=zy_Data[zy_j+zy_i*30]%10*0.1*zy_AveHeight;
pDC->LineTo(100+zy_AveWidth*(zy_j+1),zy_show_height+50-zy_temp1-zy_temp2);
}
pDC->SelectObject(zy_OldPen);//还原画笔
}
}
//柱状图
if(zy_temp==zy_Show_zhuzhuangtux)
{
CPen zy_pen1(PS_SOLID,1,RGB(0,0,0));
int zy_show_width=WndWidth-200;//坐标系显示的宽度
int zy_show_height=WndHeight-100;//坐标系显示的高度
int zy_AveWidth=zy_show_width/30;
int zy_AveHeight=zy_show_height/20;
//描绘坐标系
CPen* zy_OldPen1=pDC->SelectObject(&zy_pen1);
pDC->MoveTo(zy_show_width+120,zy_show_height+50);
pDC->LineTo(100,zy_show_height+50);//横向长度(长20)
pDC->LineTo(100,30);//纵高度(高20)
pDC->LineTo(95,35);
pDC->MoveTo(100,30);
pDC->LineTo(105,35);
pDC->MoveTo(zy_show_width+120,zy_show_height+50);
pDC->LineTo(zy_show_width+115,zy_show_height+45);
pDC->MoveTo(zy_show_width+120,zy_show_height+50);
pDC->LineTo(zy_show_width+115,zy_show_height+55);
pDC->TextOut(zy_show_width+120,zy_show_height+50,"X");
pDC->TextOut(85,25,"Y");
for(int zy_i=0;zy_i<=30;zy_i++)//画刻度 标号
{
char zy_str[3]="";
itoa(zy_i,zy_str,10);
pDC->MoveTo(100+zy_i*zy_AveWidth,zy_show_height+50);
pDC->LineTo(100+zy_i*zy_AveWidth,zy_show_height+53);
pDC->TextOut(97+zy_i*zy_AveWidth,zy_show_height+55,zy_str);
}
for( zy_i=1;zy_i<=20;zy_i++)//画刻度 标号
{
char zy_str[3]="";
itoa(zy_i*10,zy_str,10);
pDC->MoveTo(100,zy_show_height+50-zy_AveHeight*zy_i);
pDC->LineTo(97,zy_show_height+50-zy_AveHeight*zy_i);
pDC->TextOut(70,zy_show_height+42-zy_AveHeight*zy_i,zy_str);
}
pDC->SelectObject(zy_OldPen1);
//画柱状图
for(zy_i=0;zy_i<3;zy_i++)
{
CPen zy_Pen;
LOGBRUSH zy_logBrush;
CBrush zy_Brush;
zy_logBrush.lbStyle=BS_SOLID;
if(zy_i==0)
{
zy_Brush.CreateSolidBrush(RGB(255,0,0));
zy_logBrush.lbColor=RGB(255,0,0);
}
if(zy_i==1)
{
zy_logBrush.lbColor=RGB(0,255,0);
zy_Brush.CreateSolidBrush(RGB(0,255,0));
}
if(zy_i==2)
{
zy_Brush.CreateSolidBrush(RGB(0,0,255));
zy_logBrush.lbColor=RGB(0,0,255);
}
zy_Pen.CreatePen(PS_SOLID,1,&zy_logBrush);//创建画刷
CPen* zy_OldPen=pDC->SelectObject(&zy_Pen);
CBrush* zy_OldBrush=pDC->SelectObject(&zy_Brush);
for(int zy_j=0;zy_j<30;zy_j++)
{
int zy_temp1=zy_Data[zy_j+zy_i*30]/10*zy_AveHeight;
int zy_temp2=zy_Data[zy_j+zy_i*30]%10*0.1*zy_AveHeight;
int zy_RectWidth=zy_AveWidth/3;
int zy_Recttop=zy_show_height+50-zy_temp1-zy_temp2;//矩形的上下左右
int zy_Rectleft=100+zy_j*zy_AveWidth+zy_i*zy_RectWidth;
int zy_Rectright=100+zy_j*zy_AveWidth+(zy_i+1)*zy_RectWidth;
int zy_Rectbottom=zy_show_height+50;
pDC->Rectangle(zy_Rectleft,zy_Recttop,zy_Rectright,zy_Rectbottom);
}
pDC->SelectObject(zy_OldPen);
pDC->SelectObject(zy_OldBrush);
}
}
//柱状图Y
if(zy_temp==zy_Show_zhuzhuangtuy)
{
CPen zy_pen1(PS_SOLID,1,RGB(0,0,0));
int zy_show_width=WndWidth-200;//坐标系显示的宽度
int zy_show_height=WndHeight-100;//坐标系显示的高度
int zy_AveWidth=zy_show_width/20;//横向的平均宽度,单位长度
int zy_AveHeight=zy_show_height/30;//纵向的平均长度,单位长度
//画坐标系
CPen* zy_OldPen1=pDC->SelectObject(&zy_pen1);
pDC->MoveTo(zy_show_width+120,zy_show_height+50);
pDC->LineTo(100,zy_show_height+50);
pDC->LineTo(100,30);
pDC->LineTo(95,35);
pDC->MoveTo(100,30);
pDC->LineTo(105,35);
pDC->MoveTo(zy_show_width+120,zy_show_height+50);
pDC->LineTo(zy_show_width+115,zy_show_height+45);
pDC->MoveTo(zy_show_width+120,zy_show_height+50);
pDC->LineTo(zy_show_width+115,zy_show_height+55);
pDC->TextOut(zy_show_width+120,zy_show_height+50,"X");
pDC->TextOut(85,25,"Y");
for(int zy_i=0;zy_i<=20;zy_i++)//横向显示刻度
{
char zy_str[3]="";
itoa(zy_i*10,zy_str,10);
pDC->MoveTo(100+zy_i*zy_AveWidth,zy_show_height+50);
pDC->LineTo(100+zy_i*zy_AveWidth,zy_show_height+53);
pDC->TextOut(97+zy_i*zy_AveWidth,zy_show_height+55,zy_str);
}
for( zy_i=0;zy_i<=30;zy_i++)//纵向显示刻度
{
char zy_str[3]="";
itoa(zy_i,zy_str,10);
pDC->MoveTo(100,48+zy_AveHeight*zy_i);
pDC->LineTo(97,48+zy_AveHeight*zy_i);
pDC->TextOut(70,35+zy_AveHeight*zy_i,zy_str);
}
pDC->SelectObject(zy_OldPen1);
//绘图(小矩形显示)
for(zy_i=0;zy_i<3;zy_i++)
{
CPen zy_Pen;
LOGBRUSH zy_logBrush;
CBrush zy_Brush;
zy_logBrush.lbStyle=BS_SOLID;
if(zy_i==0)//染色
{
zy_Brush.CreateSolidBrush(RGB(255,0,0));
zy_logBrush.lbColor=RGB(255,0,0);
}
if(zy_i==1)
{
zy_logBrush.lbColor=RGB(0,255,0);
zy_Brush.CreateSolidBrush(RGB(0,255,0));
}
if(zy_i==2)
{
zy_Brush.CreateSolidBrush(RGB(0,0,255));
zy_logBrush.lbColor=RGB(0,0,255);
}
zy_Pen.CreatePen(PS_SOLID,1,&zy_logBrush);
CPen* zy_OldPen=pDC->SelectObject(&zy_Pen);
CBrush* zy_OldBrush=pDC->SelectObject(&zy_Brush);
for(int zy_j=0;zy_j<30;zy_j++)
{
int zy_temp1=zy_Data[zy_j+zy_i*30]/10*zy_AveWidth;
int zy_temp2=zy_Data[zy_j+zy_i*30]%10*0.1*zy_AveWidth;
int zy_Rectheigh=zy_AveHeight/3;
int zy_Recttop=48+zy_i*zy_Rectheigh+zy_j*zy_AveHeight;//矩形的左上和右下坐标
int zy_Rectleft=100;
int zy_Rectright=100+zy_temp1+zy_temp2;
int zy_Rectbottom=zy_Recttop+zy_Rectheigh;
pDC->Rectangle(zy_Rectleft,zy_Recttop,zy_Rectright,zy_Rectbottom);
}
pDC->SelectObject(zy_OldPen);
pDC->SelectObject(zy_OldBrush);
}
}
}
/////////////////////////////////////////////////////////////////////////////
// CZhengyAppWizardView printing
BOOL CZhengyAppWizardView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CZhengyAppWizardView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CZhengyAppWizardView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CZhengyAppWizardView diagnostics
#ifdef _DEBUG
void CZhengyAppWizardView::AssertValid() const
{
CView::AssertValid();
}
void CZhengyAppWizardView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CZhengyAppWizardDoc* CZhengyAppWizardView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CZhengyAppWizardDoc)));
return (CZhengyAppWizardDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CZhengyAppWizardView message handlers
//DEL void CZhengyAppWizardView::OnFileNew()
//DEL {
//DEL }
void CZhengyAppWizardView::OnShowData()
{
// TODO: Add your command handler code here
CZhengyAppWizardDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int zy_ShowData=1;
pDoc->SetTemp(zy_ShowData);
Invalidate(true);
}
void CZhengyAppWizardView::OnShow_zhexiantu()
{
// TODO: Add your command handler code here
CZhengyAppWizardDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int zy_Show_zhexiantu=2;
pDoc->SetTemp(zy_Show_zhexiantu);
Invalidate(true);
}
void CZhengyAppWizardView::OnShow_zhuzhuangtux()
{
// TODO: Add your command handler code here
CZhengyAppWizardDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int zy_Show_zhuzhuangtux=3;
pDoc->SetTemp(zy_Show_zhuzhuangtux);
Invalidate(true);
}
void CZhengyAppWizardView::OnShow_zhuzhuangtuy()
{
// TODO: Add your command handler code here
CZhengyAppWizardDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
int zy_Show_zhuzhuangtuy=4;
pDoc->SetTemp(zy_Show_zhuzhuangtuy);
Invalidate(true);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -