mfc绘图时wingdi.cpp的ASSERT(m_hObject == NULL);句出错。。求解释原因和这个wingdi是甚么
//工程名是T
// TView.h : CTView 类的接口
//
#pragma once
class CTView : public CView
{
protected: // 仅从序列化创建
CTView();
DECLARE_DYNCREATE(CTView)
// 特性
public:
CTDoc* GetDocument() const;
CPoint cursor;
CPoint points[4];
CPen pen;
int color;
// 操作
public:
void setcolor();
// 重写
public:
virtual void OnDraw(CDC* pDC); // 重写以绘制该视图
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
// 实现
public:
virtual ~CTView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// 生成的消息映射函数
protected:
afx_msg void OnFilePrintPreview();
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
DECLARE_MESSAGE_MAP()
public:
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
};
#ifndef _DEBUG // TView.cpp 中的调试版本
inline CTDoc* CTView::GetDocument() const
{ return reinterpret_cast<CTDoc*>(m_pDocument); }
#endif
// TView.cpp : CTView 类的实现
//
#include "stdafx.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义,并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "T.h"
#endif
#include "TDoc.h"
#include "TView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CTView
IMPLEMENT_DYNCREATE(CTView, CView)
BEGIN_MESSAGE_MAP(CTView, CView)
// 标准打印命令
ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CTView::OnFilePrintPreview)
ON_WM_CONTEXTMENU()
ON_WM_RBUTTONUP()
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
// CTView 构造/析构
CTView::CTView()
{
// TODO: 在此处添加构造代码
points[0].x =150;points[0].y =150;
points[3].x =550;points[3].y =150;
}
CTView::~CTView()
{
}
BOOL CTView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: 在此处通过修改
// CREATESTRUCT cs 来修改窗口类或样式
return CView::PreCreateWindow(cs);
}
// CTView 绘制
void CTView::OnDraw(CDC* pDC)
{
CTDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (!pDoc)
return;
// TODO: 在此处为本机数据添加绘制代码
pDC ->SelectObject (pen);
pDC->PolyBezier (points ,4);
}
// CTView 打印
void CTView::OnFilePrintPreview()
{
#ifndef SHARED_HANDLERS
AFXPrintPreview(this);
#endif
}
BOOL CTView::OnPreparePrinting(CPrintInfo* pInfo)
{
// 默认准备
return DoPreparePrinting(pInfo);
}
void CTView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加额外的打印前进行的初始化过程
}
void CTView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: 添加打印后进行的清理过程
}
void CTView::OnRButtonUp(UINT /* nFlags */, CPoint point)
{
ClientToScreen(&point);
OnContextMenu(this, point);
}
void CTView::OnContextMenu(CWnd* /* pWnd */, CPoint point)
{
#ifndef SHARED_HANDLERS
theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);
#endif
}
// CTView 诊断
#ifdef _DEBUG
void CTView::AssertValid() const
{
CView::AssertValid();
}
void CTView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CTDoc* CTView::GetDocument() const // 非调试版本是内联的
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTDoc)));
return (CTDoc*)m_pDocument;
}
#endif //_DEBUG
void CTView ::setcolor ()
{
int red,green,blue;
blue =abs ( cursor.y - 150);
if (blue>255)blue =255;
if(cursor .x ==350){green =1;red =1;};
if(cursor .x <350)
{
red =350 - cursor .x;
green=1;
}
else
{
green =cursor .x - 350;
red =1;
};
if(red>225)red=225;
if(green>255)green=255;
color =RGB(red,green,blue);
}
// CTView 消息处理程序
void CTView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
cursor =point ;
setcolor() ;
pen.CreatePen (PS_SOLID ,5,color);
points [1].x =cursor .x -50;points[1].y =cursor .y;
points [2].x =cursor .x +50;points[2].y =cursor .y;
Invalidate() ;
CView::OnMouseMove(nFlags, point);
}