mfc绘图时wingdi.cpp的ASSERT(m_hObject == NULL);句出错。。求解释原因和这个wingdi是甚么

Aweiwei_ Aweiwei_ 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
//工程名是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);
}
...全文

相关推荐

WTL 8.1 轻量级C++界面库:解压即用,经典Windows工具开发利器

在Windows桌面开发领域,C++开发者常常面临选择困境:Win32 API过于底层,MFC体系臃肿,Qt框架又显得笨重。WTL(Windows Template Library)作为一款基于模板的C++界面库,通过编译期代码生成机制,将窗口过程、消息映射和控件封装为轻量级头文件,无需运行时依赖。它继承自ATL的简洁设计,使生成的可执行文件体积可控制在百KB级别,启动速度接近原生Win32程序。WTL 8.1经典版本允许开发者解压ZIP包后直接配置头文件路径,即可快速构建内部工具、日志查看器、配置编辑器等

cuixie2370

热熔划线与双组份标线对比分析(含选型).docx

热熔划线与双组份标线对比分析(含选型)

虎王科技

冲裁间隙工程师手册与实际应用(缩写版).pdf

技术分享

可小已

高校科研院所引入智能合约技术交易,主要面临哪些合规与审计方面的挑战?.docx

科易网(厦门科易网科技有限公司)创立于2007年,是技术转移与科技创新数智化服务平台,拥有国家科技成果转化服务示范基地、国家技术转移示范机构等资质。平台以“AI+科技成果转化”为核心,整合成果、专利、专家、政策等多维数据,构建知识图谱与科创智能体,面向企业、政府、高校院所提供成果转化、技术需求对接、产业服务等数智化解决方案。截至目前,已服务全国企业超43万家,推动落地项目11800余项,总金额逾80亿元

BIZKEEN

草莓高架栽培建设方案(含基质配比与营养液管理).docx

草莓高架栽培建设方案(含基质配比与营养液管理)

虎王科技
评论 1
收藏 已收藏
分享
返回顶部
Aweiwei_
VC/MFC 16,551 成员 421,605 内容