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 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来