📄 prodview.cpp
字号:
// prodView.cpp : implementation of the CProdView class
//
#include "stdafx.h"
#include "prod.h"
#include "fstream"
#include "prodDoc.h"
#include "prodView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CProdView
IMPLEMENT_DYNCREATE(CProdView, CView)
BEGIN_MESSAGE_MAP(CProdView, CView)
//{{AFX_MSG_MAP(CProdView)
ON_COMMAND(ID_MENUITEM32771, OnMenuitem32771)
ON_COMMAND(ID_MENUITEM32772, OnMenuitem32772)
ON_COMMAND(ID_MENUITEM32773, OnMenuitem32773)
ON_COMMAND(ID_MENUITEM32774, OnMenuitem32774)
ON_COMMAND(ID_MENUITEM32775, OnMenuitem32775)
ON_COMMAND(ID_MENUITEM32776, OnMenuitem32776)
ON_COMMAND(ID_MENUITEM32777, OnMenuitem32777)
ON_COMMAND(ID_MENUITEM32778, OnMenuitem32778)
ON_WM_RBUTTONDOWN()
ON_WM_LBUTTONDOWN()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CProdView construction/destruction
CProdView::CProdView()
{
// TODO: add construction code here
////////////////////////////////////////////////////////////从文件data.txt中读数据,判断数据的个数
CStdioFile file;
CString temp;
file.Open ("data.txt",CFile::modeReadWrite );
int i=0;
while(i>=0)
{
if(file.ReadString (temp)==true)
i++;
else
break;
}
file.Close();
num=i;
///////////////////////////////////////
data=new int[num];
str=new CString[num];
colorr=new COLORREF[num];
p1=new CString[i];
max=270;
for(i=0;i<num;i++)
{
data[i]=0;
str[i]="";
colorr[i]=RGB(100+20*i,30*i,255-30*i);
}
///////////////////////////////////////////////从data.txt中读取数据
file.Open ("data.txt",CFile::modeReadWrite );
for(int j=0;j<i;j++)
{
file.ReadString (p1[j]);
data[j]=atoi(p1[j]);
if(data[j]>max)
max=data[j];
}
file.Close();
}
CProdView::~CProdView()
{
}
BOOL CProdView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CProdView drawing
void CProdView::OnDraw(CDC* pDC)
{
CProdDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//////////////////////////////////////////////////////////////画产量坐标轴
CBrush brush,*brushold=0;
CMainFrame* pMain=(CMainFrame*)(AfxGetApp()->m_pMainWnd);
brush.CreateSolidBrush(pMain->color);
brushold=pDC->SelectObject(&brush);
for(int i=0;i<6;i++)
{
if(i%2==0)
pDC->Rectangle(100,312-i/2*90,102,400-i/2*90);
else
pDC->Rectangle(100,310-i/2*90,108,312-i/2*90);
}
pDC->Rectangle(100,80,102,130);
pDC->Rectangle(100,398,90*num+100,400);
POINT pt1[3]={{101,75},{104,80},{98,80}};
POINT pt2[3]={{90*num+105,399},{90*num+100,402},{90*num+100,396}};
pDC->Polygon(pt1,3);
pDC->Polygon(pt2,3);
pDC->SelectObject (brushold);
brush.DeleteObject ();
pDC->TextOut(110,75,"产量");
CString temp;
int t1=max,t2=1;
while(t1/10!=0)
{
t1=t1/10;
t2++;
}
for(int j=1;j<=3;j++)
{
temp.Format ("%d",max*j/3);
pDC->TextOut(100-t2*9,312-90*(j-1),temp);
}
if(num>4)
for(int n=0;n<num;n++)
{
temp.Format ("%d",n+1);
pDC->TextOut (135+80*n,410,"第"+temp+"个月");
}
else
for(int n=0;n<num;n++)
{
temp.Format ("%d",n+1);
pDC->TextOut (140+80*n,410,"第"+temp+"季度");
}
/////////////////////////////////////////////////////////////////////显示柱子的大小
for(int m=0;m<num;m++)
if(max<=270)
pDC->TextOut (120+80*m,370-max,str[m]);
else
pDC->TextOut (120+80*m,60,str[m]);
/////////////////////////////////////////////////////////////////////画矩形柱子和改变矩形柱子颜色
for(int k=0;k<num;k++)
{
brush.CreateSolidBrush (colorr[k]);
brushold=pDC->SelectObject (&brush);
pDC->Rectangle(150+80*k,400-270*data[k]/max,180+80*k,400);
pDC->TextOut(150+80*k,380-270*data[k]/max,p1[k]);
pDC->SelectObject (brushold);
brush.DeleteObject ();
}
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CProdView printing
BOOL CProdView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CProdView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CProdView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CProdView diagnostics
#ifdef _DEBUG
void CProdView::AssertValid() const
{
CView::AssertValid();
}
void CProdView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CProdDoc* CProdView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CProdDoc)));
return (CProdDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CProdView message handlers
void CProdView::OnMenuitem32771()
{
// TODO: Add your command handler code here
for(int k=0;k<num;k++)
{
if(pt.x >150+k*80&&pt.x<180+k*80)
{
if(pt.y >400-270*data[k]/max&&pt.y<400)
{
colorr[k]=RGB(255,0,0);
}
}
}
Invalidate();
}
void CProdView::OnMenuitem32772()
{
// TODO: Add your command handler code here
for(int k=0;k<num;k++)
{
if(pt.x >150+k*80&&pt.x<180+k*80)
{
if(pt.y >400-270*data[k]/max&&pt.y<400)
{
colorr[k]=RGB(0,255,0);
}
}
}
Invalidate();
}
void CProdView::OnMenuitem32773()
{
// TODO: Add your command handler code here
for(int k=0;k<num;k++)
{
if(pt.x >150+k*80&&pt.x<180+k*80)
{
if(pt.y >400-270*data[k]/max&&pt.y<400)
{
colorr[k]=RGB(0,0,255);
}
}
}
Invalidate();
}
void CProdView::OnMenuitem32774()
{
// TODO: Add your command handler code here
for(int k=0;k<num;k++)
{
if(pt.x >150+k*80&&pt.x<180+k*80)
{
if(pt.y >400-270*data[k]/max&&pt.y<400)
{
colorr[k]=RGB(255,255,0);
}
}
}
Invalidate();
}
void CProdView::OnMenuitem32775()
{
// TODO: Add your command handler code here
for(int k=0;k<num;k++)
{
if(pt.x >150+k*80&&pt.x<180+k*80)
{
if(pt.y >400-270*data[k]/max&&pt.y<400)
{
colorr[k]=RGB(0,255,255);
}
}
}
Invalidate();
}
void CProdView::OnMenuitem32776()
{
// TODO: Add your command handler code here
for(int k=0;k<num;k++)
{
if(pt.x >150+k*80&&pt.x<180+k*80)
{
if(pt.y >400-270*data[k]/max&&pt.y<400)
{
colorr[k]=RGB(192,192,192);
}
}
}
Invalidate();
}
void CProdView::OnMenuitem32777()
{
// TODO: Add your command handler code here
for(int k=0;k<num;k++)
{
if(pt.x >150+k*80&&pt.x<180+k*80)
{
if(pt.y >400-270*data[k]/max&&pt.y<400)
{
colorr[k]=RGB(0,0,0);
}
}
}
Invalidate();
}
void CProdView::OnMenuitem32778()
{
// TODO: Add your command handler code here
for(int k=0;k<num;k++)
{
if(pt.x >150+k*80&&pt.x<180+k*80)
{
if(pt.y >400-270*data[k]/max&&pt.y<400)
{
colorr[k]=RGB(255,255,255);
}
}
}
Invalidate();
}
void CProdView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
///////////////
pt=point;
CView::OnRButtonDown(nFlags, point);
}
void CProdView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CString temp;
bool BOOL=false;
for(int i=0;i<num;i++)
str[i]="";
if(num>4)
for(int n=0;n<num;n++)
{
if(point.x >150+n*80&&point.x<180+n*80)
{
if(point.y >400-data[n]&&point.y<400)
{
temp.Format ("%d",n+1);
str[n]="第"+temp+"个月"+"产量为"+p1[n];
BOOL=true;
}
}
}
else
for(int n=0;n<num;n++)
{
if(point.x >150+n*80&&point.x<180+n*80)
{
if(point.y >400-data[n]&&point.y<400)
{
temp.Format ("%d",n+1);
str[n]="第"+temp+"个季度"+"产量为"+p1[n];
BOOL=true;
}
}
}
Invalidate();
CView::OnLButtonDown(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -