📄 tuxing.cpp
字号:
// Tuxing.cpp : implementation file
//
#include "stdafx.h"
#include "Ex07b.h"
#include "Tuxing.h"
#include "Ex07bDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// Tuxing
IMPLEMENT_DYNCREATE(Tuxing, CScrollView)
Tuxing::Tuxing()
{
}
Tuxing::~Tuxing()
{
}
BEGIN_MESSAGE_MAP(Tuxing, CScrollView)
//{{AFX_MSG_MAP(Tuxing)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint) //Attention here!!!!
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint) //Attention here!!!!
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview) //Attention here!!!!
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// Tuxing drawing
void Tuxing::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx =80;
sizeTotal.cy = 10;
SetScrollSizes(MM_TEXT, sizeTotal);
}
void Tuxing::OnDraw(CDC* pDC)
{
CEx07bDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
char str[64];
int top=50;
int b=350;
int w=50;
int left=50;
int i=0;
float tt=0;
POSITION pos=pDoc->m_dataList.GetHeadPosition();
while (pos!=NULL)
{
CStudent *pStudent=pDoc->m_dataList.GetAt(pos);
RECT Rect3;
Rect3.left=left+i*w;
Rect3.top=b-(pStudent->m_lAge*(b-top)/100);
Rect3.right=Rect3.left+w;
Rect3.bottom=b;
CBrush Brush3(RGB((50+i*210),((i-1)*310),(150+i*125)));
CBrush *pOldBrush=pDC->SelectObject(&Brush3);
pDC->FillRect(&Rect3,&Brush3);
pDC->SelectObject(pOldBrush);
//写坐标下的项目
pDC->SetTextColor(RGB((50+i*210),((i-1)*310),(150+i*125)));
pDC->TextOut(left+i*w,b+10,pStudent->m_sName);
//写方框图上的频率
sprintf(str,"%6.0f",pStudent->m_nCode);
pDC->TextOut(left+i*w,Rect3.top-20,str);
//画累计百分比的线
CPen Pen2;
Pen2.CreatePen(PS_DOT,1,RGB(0,128,128));
CPen* poldPen=pDC->SelectObject(&Pen2);
pDC->SelectObject(&Pen2);
if (i==0)
pDC->MoveTo(left,b);//-(pStudent->m_lScore*(b-top)/100));
else
pDC->MoveTo(left+i*w,tt);
pDC->LineTo(left+(i+1)*w,b-(pStudent->m_lScore*(b-top)/100));
tt=b-(pStudent->m_lScore*(b-top)/100);
//写线上的累计百分比
// if (i!=0)
// {
sprintf(str,"%6.2f",pStudent->m_lScore);
pDC->TextOut(left+(i+1)*w,b-(pStudent->m_lScore*(b-top)/100),str);
pDC->TextOut(left+(i+1)*w+40,b-(pStudent->m_lScore*(b-top)/100),"%");
// }
pStudent=pDoc->m_dataList.GetNext(pos);
i++;
pDC->SelectObject(poldPen);
}
CPen Pen3;
Pen3.CreatePen(PS_DASH,1,RGB(0,255,0));
CPen* poldPen=pDC->SelectObject(&Pen3);
pDC->SelectObject(&Pen3);
pDC->MoveTo(left,b-(80*(b-top)/100));
pDC->LineTo(left+i*w,b-(80*(b-top)/100));
CPen Pen4;
Pen4.CreatePen(PS_DASH,1,RGB(0,255,255));
pDC->SelectObject(&Pen4);
pDC->MoveTo(left,b-(90*(b-top)/100));
pDC->LineTo(left+i*w,b-(90*(b-top)/100));
CPen Pen;
Pen.CreatePen(PS_SOLID,2,RGB(255,128,128));
pDC->SelectObject(&Pen);
pDC->BeginPath();
pDC->MoveTo(left,top);
pDC->LineTo((left+i*w),top);
pDC->LineTo((left+i*w),b);
pDC->LineTo(left,b);
pDC->CloseFigure();
pDC->EndPath();
pDC->StrokePath();
pDC->SelectObject(poldPen);
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx =i*w+100;
sizeTotal.cy = 480;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// Tuxing diagnostics
#ifdef _DEBUG
void Tuxing::AssertValid() const
{
CScrollView::AssertValid();
}
void Tuxing::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// Tuxing message handlers
void Tuxing::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
// TODO: Add your specialized code here and/or call the base class
Invalidate(true);
}
#ifdef _DEBUG
CEx07bDoc *Tuxing::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx07bDoc)));
return (CEx07bDoc*)m_pDocument;
}
#endif
void Tuxing::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
CScrollView::OnBeginPrinting(pDC, pInfo);
}
void Tuxing::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
CScrollView::OnEndPrinting(pDC, pInfo);
}
void Tuxing::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
CScrollView::OnPrepareDC(pDC, pInfo);
pDC->SetMapMode(MM_ANISOTROPIC);
//转换坐标映射方式
CSize size = CSize(800, 580);
pDC->SetWindowExt(size);
//确定窗口大小
//得到实际设备每逻辑英寸的像素数量
int xLogPixPerInch=pDC->GetDeviceCaps(LOGPIXELSX);
int yLogPixPerInch = pDC->GetDeviceCaps(LOGPIXELSY);
//得到设备坐标和逻辑坐标的比例
long xExt = (long)size.cx * xLogPixPerInch/96 ;
long yExt = (long)size.cy * yLogPixPerInch/96 ;
pDC->SetViewportExt((int)xExt, (int)yExt);
//确定视口大小
}
BOOL Tuxing::OnPreparePrinting(CPrintInfo* pInfo)
{
// TODO: call DoPreparePrinting to invoke the Print dialog box
// return CScrollView::OnPreparePrinting(pInfo);
BOOL b=CView::DoPreparePrinting(pInfo);
return b;
}
void Tuxing::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
CScrollView::OnPrint(pDC, pInfo);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -