1、代码如下:

// 吹彩色泡泡Doc.h : interface of the CMyDoc class
//
/#if !defined(AFX_DOC_H__559CF0A7_41F7_48A5_A356_774764C0E60F__INCLUDED_)
#define AFX_DOC_H__559CF0A7_41F7_48A5_A356_774764C0E60F__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000#define MAX_BUBBLE 250 //设置吹泡泡的上限class CMyDoc : public CDocument
{
protected: // create from serialization onlyCMyDoc();DECLARE_DYNCREATE(CMyDoc)// Attributes
public:CRect m_rectBubble[MAX_BUBBLE];int x[MAX_BUBBLE],y[MAX_BUBBLE],X[MAX_BUBBLE],Y[MAX_BUBBLE] ;int a[MAX_BUBBLE],b[MAX_BUBBLE],c[MAX_BUBBLE];int m_nBubbleCount;
// Operations
public:// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CMyDoc)public:virtual BOOL OnNewDocument();virtual void Serialize(CArchive& ar);//}}AFX_VIRTUAL// Implementation
public:virtual ~CMyDoc();
#ifdef _DEBUGvirtual void AssertValid() const;virtual void Dump(CDumpContext& dc) const;
#endifprotected:// Generated message map functions
protected://{{AFX_MSG(CMyDoc)// NOTE - the ClassWizard will add and remove member functions here.//    DO NOT EDIT what you see in these blocks of generated code !//}}AFX_MSGDECLARE_MESSAGE_MAP()
};///{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_DOC_H__559CF0A7_41F7_48A5_A356_774764C0E60F__INCLUDED_)
// 吹彩色泡泡View.h : interface of the CMyView class
//
/#if !defined(AFX_VIEW_H__50144892_DB2F_46D1_A755_F4A47754BBA2__INCLUDED_)
#define AFX_VIEW_H__50144892_DB2F_46D1_A755_F4A47754BBA2__INCLUDED_#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000class CMyView : public CView
{
protected: // create from serialization onlyCMyView();DECLARE_DYNCREATE(CMyView)// Attributes
public:CMyDoc* GetDocument();// Operations
public:// Overrides// ClassWizard generated virtual function overrides//{{AFX_VIRTUAL(CMyView)public:virtual void OnDraw(CDC* pDC);  // overridden to draw this viewvirtual BOOL PreCreateWindow(CREATESTRUCT& cs);protected:virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);//}}AFX_VIRTUAL// Implementation
public:virtual ~CMyView();
#ifdef _DEBUGvirtual void AssertValid() const;virtual void Dump(CDumpContext& dc) const;
#endifprotected:// Generated message map functions
protected://{{AFX_MSG(CMyView)afx_msg void OnLButtonDown(UINT nFlags, CPoint point);afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);afx_msg void OnTimer(UINT nIDEvent);afx_msg void OnPaint();//}}AFX_MSGDECLARE_MESSAGE_MAP()
};#ifndef _DEBUG  // debug version in 吹彩色泡泡View.cpp
inline CMyDoc* CMyView::GetDocument(){ return (CMyDoc*)m_pDocument; }
#endif///{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.#endif // !defined(AFX_VIEW_H__50144892_DB2F_46D1_A755_F4A47754BBA2__INCLUDED_)
// 吹彩色泡泡Doc.cpp : implementation of the CMyDoc class
//#include "stdafx.h"
#include "吹彩色泡泡.h"#include "吹彩色泡泡Doc.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/
// CMyDocIMPLEMENT_DYNCREATE(CMyDoc, CDocument)BEGIN_MESSAGE_MAP(CMyDoc, CDocument)//{{AFX_MSG_MAP(CMyDoc)// 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
END_MESSAGE_MAP()/
// CMyDoc construction/destructionCMyDoc::CMyDoc()
{// TODO: add one-time construction code here}CMyDoc::~CMyDoc()
{
}BOOL CMyDoc::OnNewDocument()
{if (!CDocument::OnNewDocument())return FALSE;// TODO: add reinitialization code here// (SDI documents will reuse this document)m_nBubbleCount=0;return TRUE;
}/
// CMyDoc serializationvoid CMyDoc::Serialize(CArchive& ar)
{if (ar.IsStoring()){// TODO: add storing code here}else{// TODO: add loading code here}
}/
// CMyDoc diagnostics#ifdef _DEBUG
void CMyDoc::AssertValid() const
{CDocument::AssertValid();
}void CMyDoc::Dump(CDumpContext& dc) const
{CDocument::Dump(dc);
}
#endif //_DEBUG/
// CMyDoc commands
// 吹彩色泡泡View.cpp : implementation of the CMyView class
//
#include<afxwin.h>#include "stdafx.h"
#include "吹彩色泡泡.h"#include "吹彩色泡泡Doc.h"
#include "吹彩色泡泡View.h"#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif/
// CMyViewIMPLEMENT_DYNCREATE(CMyView, CView)BEGIN_MESSAGE_MAP(CMyView, CView)//{{AFX_MSG_MAP(CMyView)ON_WM_LBUTTONDOWN()ON_WM_LBUTTONDBLCLK()ON_WM_RBUTTONDBLCLK()ON_WM_TIMER()ON_WM_PAINT()//}}AFX_MSG_MAP// Standard printing commandsON_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()/
// CMyView construction/destructionCMyView::CMyView()
{// TODO: add construction code here}CMyView::~CMyView()
{
}BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{// TODO: Modify the Window class or styles here by modifying//  the CREATESTRUCT csreturn CView::PreCreateWindow(cs);
}/
// CMyView drawingvoid CMyView::OnDraw(CDC* pDC)
{CMyDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);// TODO: add draw code for native data herefor(int i=0;i<pDoc->m_nBubbleCount;i++)         pDC->Ellipse(pDoc->m_rectBubble[i]);}/
// CMyView printingBOOL CMyView::OnPreparePrinting(CPrintInfo* pInfo)
{// default preparationreturn DoPreparePrinting(pInfo);
}void CMyView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{// TODO: add extra initialization before printing
}void CMyView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{// TODO: add cleanup after printing
}/
// CMyView diagnostics#ifdef _DEBUG
void CMyView::AssertValid() const
{CView::AssertValid();
}void CMyView::Dump(CDumpContext& dc) const
{CView::Dump(dc);
}CMyDoc* CMyView::GetDocument() // non-debug version is inline
{ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG/
// CMyView message handlersvoid CMyView::OnLButtonDown(UINT nFlags, CPoint point)
{// TODO: Add your message handler code here and/or call defaultCMyDoc* pDoc = GetDocument();ASSERT_VALID(pDoc);
if(pDoc->m_nBubbleCount<MAX_BUBBLE){int r=rand()%50+10;int j;j=pDoc->m_nBubbleCount;pDoc->a[j]=rand()%255,pDoc->b[j]=rand()%255,pDoc->c[j]=rand()%255;pDoc->x[j]=point.x-r;pDoc->y[j]=point.y-r;pDoc->X[j]=point.x+r;pDoc->Y[j]=point.y+r;CRect rect(point.x-r,point.y-r,point.x+r,point.y+r);pDoc->m_rectBubble[pDoc->m_nBubbleCount]=rect;pDoc->m_nBubbleCount++;pDoc->SetModifiedFlag();InvalidateRect(rect,FALSE);}CView::OnLButtonDown(nFlags, point);
}void CMyView::OnLButtonDblClk(UINT nFlags, CPoint point)
{// TODO: Add your message handler code here and/or call defaultSetTimer(1,200,NULL);CView::OnLButtonDblClk(nFlags, point);
}void CMyView::OnRButtonDblClk(UINT nFlags, CPoint point)
{// TODO: Add your message handler code here and/or call defaultKillTimer(1);CView::OnRButtonDblClk(nFlags, point);
}void CMyView::OnTimer(UINT nIDEvent)
{// TODO: Add your message handler code here and/or call defaultInvalidate();CView::OnTimer(nIDEvent);
}void CMyView::OnPaint()
{CMyDoc*pDoc=GetDocument();ASSERT_VALID(pDoc);
CPaintDC dc(this); // device context for paintingfor(int i=0;i<pDoc->m_nBubbleCount;i++){CBrush  brushNew;CPen  penNew;       brushNew.CreateSolidBrush(RGB(pDoc->a[i],pDoc->b[i],pDoc->c[i]));penNew.CreatePen(PS_SOLID,1,RGB(255,0,0));dc.SelectObject(&brushNew);  dc.SelectObject(&penNew);dc.Ellipse(pDoc->x[i],pDoc->y[i],pDoc->X[i],pDoc->Y[i]);pDoc->y[i]=pDoc->y[i]-15-(pDoc->X[i]-pDoc->x[i])/5,pDoc->Y[i]=pDoc->Y[i]-15-(pDoc->X[i]-pDoc->x[i])/5;RECT r;GetClientRect(&r);if(pDoc->Y[i]<0){pDoc->y[i]=r.bottom,pDoc->Y[i]=r.bottom-pDoc->X[i]+pDoc->x[i];}}    // TODO: Add your message handler code here// Do not call CView::OnPaint() for painting messages
}

2、运行效果如下:

左键单击画圆,左键双击画动圆,右键双击定圆。

MFC基于单文档制作吹彩色泡泡程序相关推荐

  1. MFC基于单文档实现绘图功能(线段,矩形,椭圆,圆,铅笔,橡皮),保姆式教程

    MFC基于单文档实现绘图功能(线段,矩形,椭圆,圆,铅笔,橡皮),保姆式教程 需要手写的代码都在图片下面,实际内容不多------嘻嘻. 1.打开VS–新建项目–选择mfc应用程序 2.选择单文档,m ...

  2. 基于单文档的MFC程序

    单文档 XXXX = CMy02_MFCTest class XXXXApp : public CWinAppEx 应用程序类//程序入口地址 CMainFrame:CFrameWnd : 框架类 X ...

  3. Windows编程与MFC # 4 单文档应用程序(1)

    整理自VC++程序设计课程课件 使用VC++的应用程序向导MFC AppWizard可以开发: Single document(单文档) Multiple document(多文档) Dialog b ...

  4. MFC 基于多文档的打印和打印预览功能的实现

    一.基础知识 1 网上有很多的关于打印的程序,一定要看清楚,是基于对话框dialog的打印功能,还是基于文档的打印功能. 如果分不清基于对话框和文档的区别,建议新建一个单文档.多文档和对话框的工程,看 ...

  5. MFC基于多文档框架(对话框内嵌office控件(word文档))

    office系列以简便.功能强大的特色发展为当今世界上范围最广.用户最多的办公软件,同时也深受码农的喜欢-.   MFC项目中嵌入office系列软件也是随处可见的,最早接触内嵌office软件是在几 ...

  6. MFC创建单文档工程(左上角名称前的mfc图标修改为其他需求图标)

    资源视图--VT_Ards.rc--右键选择添加资源,选择menu,然后导入 (提前最好把ico图标放到工程文件下的res文件夹下) 图标属性ID为:IDR_MAINFRAME

  7. MFC中 单文档程序 删除工具栏

    方法一 .在创建工程的过程中可通过Docking toolbar 选择不生成工具栏. 方法二 .已经生成工具栏以后可以使用 ShowControlBar(&m_wndToolBar,FALSE ...

  8. MFC应用程序类型:单文档、多文档与基于对话框

    单文档:记事本类程序的标准模式,有菜单栏.工具栏等,只能进行一份文档的操作,即不能同时在同一个应用程序中打开两个文件 多文档:WORD类或浏览器程序的标准模式,可多个窗口显示不同的信息,进行不同的任务 ...

  9. 基于MFC单文档的画图程序(小项目)

    基于MFC单文档的画图程序 前言 学习了一年多的MFC和Qt,对其基本用法已经熟练掌握,迫不及待的想实战一波,但是心急吃不了热豆腐,我还是踏踏实实的找一些既能复习以前知识的单子又不消耗我太多时间(最近 ...

最新文章

  1. 45度地图之整体旋转
  2. 一个文件,内含一千万行字符串,每个字符串在1K以内,要求找出所有相反的串对
  3. Tableau安装教程
  4. mschart控件使用详解
  5. php 滑块验证,实现一个滑块验证功能
  6. 神经网络激活函数的作用是什么?
  7. 生产者消费者的几种写法
  8. 【蓝牙开发】低功耗蓝牙ATT/GATT/Profile/Service/Characteristic规格解读
  9. ETA4322耐压30V,线性充1000mA,充电电流可调,双灯指示
  10. 大神李沐被曝离职!投身大模型创业,GitHub项目已开
  11. shui-执行多个window.onload
  12. python编译型语言和解释型语言
  13. 用JavaScript移动对象
  14. 回顾Vue2---②
  15. 阿里云云栖社区合作指南
  16. java 骰子游戏_java 骰子游戏
  17. Altair Activate 2021.1 x64
  18. Google Drive文件下载
  19. MySQL sql语句获取当前日期|时间|时间戳
  20. CentOS6.9安装反射内存卡出现的错误和问题

热门文章

  1. 拒绝暴力调参!推荐一个模型Debug神器!
  2. 最新进展 | 深度学习在天气预测中的应用
  3. 斯坦福大学NLP公开课CS224n上映啦!华人助教陪你追剧
  4. Android官方开发文档Training系列课程中文版:OpenGL绘图之环境配置
  5. leetcode--动态规划(Easy)
  6. 18-Gm-TransH:Group-Constrained Embedding of Multi-fold Relations in Knowledge Bases,嵌入,transH,n-ary
  7. 人工智能领域开展标准化研究
  8. 对于使用progisp软件进行ISP编程时进入不了编程模式的解决方法
  9. #leetcode刷题之路35-搜索插入位置
  10. Mysql Explain的简单使用