SetPixel( x, y, color )函数绘制彩色矩形

求解哪里出了问题


// MyFirstView.cpp : implementation of the CMyFirstView class
//

#include "stdafx.h"
#include "MyFirst.h"

#include "MyFirstDoc.h"
#include "MyFirstView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyFirstView

IMPLEMENT_DYNCREATE(CMyFirstView, CView)

BEGIN_MESSAGE_MAP(CMyFirstView, CView)
    //{{AFX_MSG_MAP(CMyFirstView)
        // NOTE - the ClassWizard will add and remove mapping macros here.
        //    DO NOT EDIT what you see in these blocks of generated code!
    //}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyFirstView construction/destruction

CMyFirstView::CMyFirstView()
{
    // TODO: add construction code here

}

CMyFirstView::~CMyFirstView()
{
}

BOOL CMyFirstView::PreCreateWindow(CREATESTRUCT& cs)
{
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs

    return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMyFirstView drawing

void CMyFirstView::OnDraw(CDC* pDC)
{
    CMyFirstDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
CWnd  *pDeskTop  =   GetDesktopWindow(  );
  CDC     *pDC    =  pDeskTop->GetWindowDC(  );
  for   (  int  x = 0;  x < 900;  x++ )
for  (  int  y = 0; y < 700;  y++ )
            pDC->SetPixel( x+0, y+0, x*y );
  pDeskTop->ReleaseDC( pDC );
 

}

/////////////////////////////////////////////////////////////////////////////
// CMyFirstView printing

BOOL CMyFirstView::OnPreparePrinting(CPrintInfo* pInfo)
{
    // default preparation
    return DoPreparePrinting(pInfo);
}

void CMyFirstView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: add extra initialization before printing
}

void CMyFirstView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
    // TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMyFirstView diagnostics

#ifdef _DEBUG
void CMyFirstView::AssertValid() const
{
    CView::AssertValid();
}

void CMyFirstView::Dump(CDumpContext& dc) const
{
    CView::Dump(dc);
}

CMyFirstDoc* CMyFirstView::GetDocument() // non-debug version is inline
{
    ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyFirstDoc)));
    return (CMyFirstDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyFirstView message handlers

OnDraw的参数名是pDC,你函数里又定义CDC *pDC,变量重名了
换个变量名就可以了。不要叫pDC

pDC->SetPixel( x+0, y+0, x*y ) 的第三个参数应该传一个颜色结构体