书上的一个C++程序编译没错误,但得不到正确结果!!请各位大侠帮忙啊,讲详细点,本人还是个菜鸟
// Example1View.cpp : implementation of the CExample1View class//每隔500ms生成一个随机大小,随机位置,随机颜色的实心圆,并显示在屏幕上。。
#include "stdafx.h"
#include "Example1.h"
#include "Example1Doc.h"
#include "Example1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CExample1View
IMPLEMENT_DYNCREATE(CExample1View, CView)
BEGIN_MESSAGE_MAP(CExample1View, CView)
//{{AFX_MSG_MAP(CExample1View)
ON_WM_TIMER()
ON_COMMAND(IDM_START, OnStart)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CExample1View construction/destruction
CExample1View::CExample1View()
{
// TODO: add construction code here
}
CExample1View::~CExample1View()
{
}
BOOL CExample1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CExample1View drawing
void CExample1View::OnDraw(CDC* pDC)
{
CExample1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CExample1View printing
BOOL CExample1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CExample1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CExample1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CExample1View diagnostics
#ifdef _DEBUG
void CExample1View::AssertValid() const
{
CView::AssertValid();
}
void CExample1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CExample1Doc* CExample1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CExample1Doc)));
return (CExample1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CExample1View message handlers
void CExample1View::OnTimer(UINT nIDEvent)
{
CDC*pDC=this->GetDC(); //pDC->SetPixel(rand()%800,rand()%600,RGB(rand()%256,rand()%256));
for(int i=0;i<100;i++){
int x=rand()%1024;
int y=rand()%768;
int r=rand()%100;
CBrush brush;
brush.CreateSolidBrush(RGB(rand()%256,rand()%256,rand()%256));
pDC->SelectObject(&brush);
pDC->Ellipse(x,y,x+r,y+r);
//pDC->Recrangle(x,y,x+r,y+r);
}// TODO: Add your message handler code here and/or call default
CView::OnTimer(nIDEvent);
}
void CExample1View::OnStart()
{
this->SetTimer(1,500,NULL); // TODO: Add your command handler code here
}