【VC开源代码栏目提醒】:网学会员鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“CDraw_7View.cpp”一文,供大家参考学习
// CDraw_7View.cpp : implementation of the CCDraw_7View class
//
#include "stdafx.h"
#include "CDraw_7.h"
#include "CDraw_7Doc.h"
#include "CDraw_7View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCDraw_7View
IMPLEMENT_DYNCREATE(CCDraw_7View, CView)
BEGIN_MESSAGE_MAP(CCDraw_7View, CView)
//{{AFX_MSG_MAP(CCDraw_7View)
ON_WM_PAINT()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CCDraw_7View construction/destruction
CCDraw_7View::CCDraw_7View()
{
// TODO: add construction code here
}
CCDraw_7View::~CCDraw_7View()
{
}
BOOL CCDraw_7View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCDraw_7View drawing
void CCDraw_7View::OnDraw(CDC* pDC)
{
CCDraw_7Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCDraw_7View printing
BOOL CCDraw_7View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCDraw_7View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCDraw_7View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCDraw_7View diagnostics
#ifdef _DEBUG
void CCDraw_7View::AssertValid() const
{
CView::AssertValid();
}
void CCDraw_7View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCDraw_7Doc* CCDraw_7View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCDraw_7Doc)));
return (CCDraw_7Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCDraw_7View message handlers
void CCDraw_7View::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect rc;
int i,j;
this->GetWindowRect(rc);//获得窗口的大小
int y=rc.Height()/5; //直线的纵坐标
CPen pen,*oldpen;
oldpen=dc.SelectObject(&pen);
dc.MoveTo(0,y); //转移当前位置
dc.LineTo(0,y); //画直线
for(i=1;i<255;i++)
{
pen.DeleteObject();
pen.CreatePen(PS_SOLID,2,RGB(255,i,0));
//创建一个画笔,逐渐改变颜色
dc.SelectObject(&pen);
dc.LineTo(i,y);
}
dc.MoveTo(0,y*2);
dc.LineTo(0,y*2);
for(j=1;j<255;j++)
{
pen.DeleteObject();
pen.CreatePen(PS_SOLID,2,RGB(0,255,j));
dc.SelectObject(&pen);
dc.LineTo(j,y*2);
}
// Do not call CView::OnPaint() for painting messages
}
上一篇:
CDraw_7Doc.cpp
下一篇:
如何当一个轻松的班主任