Mountains_do 2022-09-24 21:22 采纳率: 66.7%
浏览 58
已结题

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

  • 写回答

2条回答 默认 最新

  • 快乐鹦鹉 2022-09-24 21:49
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(1条)

报告相同问题?

问题事件

  • 系统已结题 10月2日
  • 已采纳回答 9月24日
  • 赞助了问题酬金10元 9月24日
  • 创建了问题 9月24日

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看