当前位置: 首页 > 编程日记 > 正文

vs2008中,在OCX控件中应用doc/view基本步骤

1、利用向导创建一个MFC ActiveX Control控件CMyOCX;
2、在工程中加入ActivDoc头文件和执行文件;
class CActiveXDocTemplate : public CSingleDocTemplate
{
    enum { IDR_NOTUSED = 0x7FFF };

CWnd* m_pParentWnd;
    CFrameWnd* m_pFrameWnd;
    CString m_docFile;
 CView*  m_pView;

public:
    CActiveXDocTemplate(CRuntimeClass* pDocClass,
        CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass);

CFrameWnd* CreateDocViewFrame(CWnd* pParentWnd);
    void SaveDocumentFile();

virtual CFrameWnd* CreateNewFrame(CDocument* pDoc,
        CFrameWnd* pOther);
    virtual CDocument* OpenDocumentFile(
        LPCTSTR lpszPathName, BOOL bVerifyExists = TRUE);
};

/

class CActiveXDocControl : public COleControl
{
    enum { WM_IDLEUPDATECMDUI = 0x0363 };

static BOOL m_bDocInitialized;
    CActiveXDocTemplate* m_pDocTemplate;
    CFrameWnd* m_pFrameWnd;

DECLARE_DYNAMIC(CActiveXDocControl)

protected:
    void AddDocTemplate(CActiveXDocTemplate* pDocTemplate);
    CDocTemplate* GetDocTemplate() { return m_pDocTemplate; }

//{{AFX_MSG(CActiveXDocControl)
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg void OnSize(UINT nType, int cx, int cy);
    afx_msg void OnTimer(UINT nIDEvent);
    afx_msg void OnDestroy();
    //}}AFX_MSG
    //{{AFX_DISPATCH(CActiveXDocControl)
    //}}AFX_DISPATCH
    //{{AFX_EVENT(CActiveXDocControl)
    //}}AFX_EVENT

DECLARE_MESSAGE_MAP()
    DECLARE_DISPATCH_MAP()
    DECLARE_EVENT_MAP()

public:
 CFrameWnd* GetFrameWnd();
    CActiveXDocControl();
    virtual ~CActiveXDocControl();

enum {
    //{{AFX_DISP_ID(CActiveXDocControl)
    //}}AFX_DISP_ID
    };
};

///
// ActivDoc.cpp : implementation file
//

#include "stdafx.h"
#include "ActivDoc.h"

CActiveXDocTemplate::CActiveXDocTemplate(CRuntimeClass* pDocClass,
    CRuntimeClass* pFrameClass, CRuntimeClass* pViewClass)
        : CSingleDocTemplate(IDR_NOTUSED, pDocClass, pFrameClass,
            pViewClass)
{
    ASSERT(pFrameClass);
 m_pView = (CView*)pViewClass;
}

CFrameWnd* CActiveXDocTemplate::CreateDocViewFrame(CWnd* pParentWnd)
{
    ASSERT(pParentWnd && IsWindow(*pParentWnd));
    ASSERT_KINDOF(CActiveXDocControl, pParentWnd);
    m_pParentWnd = pParentWnd;
    m_pFrameWnd = NULL;

// OpenDocumentFile is a virtual method (implemented in
    // the CSingleDocTemplate base class) that creates
    // the document (either empty or loaded from the specified
    // file) and calls our CreateNewFrame function. Passing
    // NULL to the function creates a new document. Incidentally,
    // the view is created by the CFrameWnd's OnCreateClient()
    // method.

if (!OpenDocumentFile(NULL))
        return NULL;

// Since OpenDocumentFile sets m_pFrame, we can now use it.

ASSERT(m_pFrameWnd);
    ASSERT_KINDOF(CFrameWnd, m_pFrameWnd);
    m_pFrameWnd->ShowWindow(SW_SHOWNORMAL);
    return m_pFrameWnd;
}

CFrameWnd* CActiveXDocTemplate::CreateNewFrame(CDocument* pDoc,
        CFrameWnd* pOther)
{
    ASSERT(pOther == NULL);
    ASSERT(m_pFrameClass != NULL);
    if (pDoc != NULL)
        ASSERT_VALID(pDoc);

// Create a frame wired to the specified document

CCreateContext context;
    context.m_pCurrentFrame = pOther;
    context.m_pCurrentDoc = pDoc;
    context.m_pNewViewClass = m_pViewClass;
    context.m_pNewDocTemplate = this;

m_pFrameWnd = (CFrameWnd*)m_pFrameClass->CreateObject();
    if (m_pFrameWnd == NULL)
    {
        TRACE1("Warning: Dynamic create of frame %hs failed.\n",
            m_pFrameClass->m_lpszClassName);
        return NULL;
    }
    ASSERT_KINDOF(CFrameWnd, m_pFrameWnd);

if (context.m_pNewViewClass == NULL)
        TRACE0("Warning: creating frame with no default view.\n");

// The frame is created as a menu-less child of the
    // CActiveXDocControl in which it will reside.

ASSERT_KINDOF(CActiveXDocControl, m_pParentWnd);
    if (!m_pFrameWnd->Create(NULL, "", WS_CHILD|WS_VISIBLE,
        CFrameWnd::rectDefault, m_pParentWnd, NULL, 0, &context))
    {
        TRACE0("Warning: CDocTemplate couldn't create a frame.\n");
        return NULL;
    }

return m_pFrameWnd;
}

CDocument* CActiveXDocTemplate::OpenDocumentFile(
    LPCTSTR lpszPathName, BOOL bVerifyExists)
{
    SaveDocumentFile();
    m_docFile = lpszPathName;

if (bVerifyExists)
    {
        DWORD dwAttrib = GetFileAttributes(m_docFile);
        if (dwAttrib == 0xFFFFFFFF ||
            dwAttrib == FILE_ATTRIBUTE_DIRECTORY)
        {
            lpszPathName = NULL;
        }
    }

return CSingleDocTemplate::OpenDocumentFile(
        lpszPathName, TRUE);
}

void CActiveXDocTemplate::SaveDocumentFile()
{
    if (m_pOnlyDoc != NULL)
    {
        if (!m_docFile.IsEmpty())
            m_pOnlyDoc->OnSaveDocument(m_docFile);
        else
            m_pOnlyDoc->SetModifiedFlag(FALSE);
    }
}

/
// CActiveXDocControl

IMPLEMENT_DYNAMIC(CActiveXDocControl, COleControl)
BEGIN_MESSAGE_MAP(CActiveXDocControl, COleControl)
    //{{AFX_MSG_MAP(CActiveXDocControl)
    ON_WM_CREATE()
    ON_WM_SIZE()
    ON_WM_TIMER()
    ON_WM_DESTROY()
    //}}AFX_MSG_MAP
    ON_OLEVERB(AFX_IDS_VERB_PROPERTIES, OnProperties)
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CActiveXDocControl, COleControl)
    //{{AFX_DISPATCH_MAP(CActiveXDocControl)
    //}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
BEGIN_EVENT_MAP(CActiveXDocControl, COleControl)
    //{{AFX_EVENT_MAP(COleFrameCtrl)
    //}}AFX_EVENT_MAP
END_EVENT_MAP()

int CActiveXDocControl::m_bDocInitialized = FALSE;

CActiveXDocControl::CActiveXDocControl()
{
    m_pDocTemplate = NULL;
    m_pFrameWnd = NULL;

// Since we're in an OCX, CWinApp::InitApplication() is
    // not called by the framework. Unfortunately, that method
    // performs CDocManager initialization that is necessary
    // in order for our DocTemplate to clean up after itself.
    // We simulate the same initialization by calling the
    // following code the first time we create a control.

if (!m_bDocInitialized)
    {
        CDocManager docManager;
        docManager.AddDocTemplate(NULL);
        m_bDocInitialized = TRUE;
    }
}

CActiveXDocControl::~CActiveXDocControl()
{
    // Note that the frame, the document, and the view are
    // all deleted automatically by the framework!
   
    delete m_pDocTemplate;
}

void CActiveXDocControl::AddDocTemplate(CActiveXDocTemplate* pDocTemplate)
{
    // I've decided to call this function AddDocTemplate to
    // be consistent with naming of CWinApp::AddDocTemplate.
    // However, only one DocTemplate is allowed per control.
   
    ASSERT(pDocTemplate);
    ASSERT(m_pDocTemplate == NULL);
    m_pDocTemplate = pDocTemplate;
}

int CActiveXDocControl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (COleControl::OnCreate(lpCreateStruct) == -1)
        return -1;

// The CActiveXDocTemplate object will create the
    // document, the view, and the frame inside the
    // control. The reason we need a handle to the frame
    // is so that we can resize it when the control is
    // resized.
   
    ASSERT(m_pDocTemplate);    // Set in call to AddDocTemplate
    m_pFrameWnd = m_pDocTemplate->CreateDocViewFrame(this);
    ASSERT_KINDOF(CFrameWnd, m_pFrameWnd);

// By default, we'll create the control with a border,
    // since it looks better for frames containing a toolbar.

SetBorderStyle(TRUE);
    SetTimer(WM_IDLEUPDATECMDUI, 300, NULL);
    return 0;
}

void CActiveXDocControl::OnSize(UINT nType, int cx, int cy)
{
    COleControl::OnSize(nType, cx, cy);

// The CFrameWnd should always fill up the entire client
    // area of the control.

if (m_pFrameWnd != NULL)
    {
        ASSERT(IsWindow(*m_pFrameWnd));
        CRect area;
        GetClientRect(area);
        m_pFrameWnd->MoveWindow(area.left, area.top, area.right,
            area.bottom);
    }
}

void CActiveXDocControl::OnTimer(UINT nIDEvent)
{
    // Since we're in an OCX, we don't control the message loop,
    // so CWinThread::OnIdle is never called. That means we have
    // to periodically pump the ON_UPDATE_COMMAND_UI messages
    // by hand.
   
    SendMessageToDescendants(WM_IDLEUPDATECMDUI, TRUE);
    COleControl::OnTimer(nIDEvent);
}


void CActiveXDocControl::OnDestroy()
{
    AfxGetApp()->m_pMainWnd = NULL;
    m_pDocTemplate->SaveDocumentFile();
    COleControl::OnDestroy();
}

CFrameWnd* CActiveXDocControl::GetFrameWnd()
{
 return m_pFrameWnd;
}

3、在CMyOCX头文件中包含#include "ActivDoc.h";
4、将CMyOCX头文件和执行文件中的COleControl全部用CActiveXDocControl替换;
5、添加CMyView、CMyDocument、CMyFrame三个类,它们分别继承于CView、CDocument、CFrameWnd,在它们的头文件中分别将它们
的构造函数和析构函数有protected该成public;
6、在CMyOCX执行文件中包含#include "MyDocument.h"  #include "MyView.h"   #include "MyFrame.h";
7、在CMyOCX执行文件中的构造函数中添加语句:
 AddDocTemplate(new CActiveXDocTemplate(
  RUNTIME_CLASS(CMyDocument),
  RUNTIME_CLASS(CMyFrame),
  RUNTIME_CLASS(CMyView)));
基本模型形成,然后就可以按照自己的需要向里面添加东西了。

相关文章:

常见存储过程分页PK赛——简单测试分析常见存储过程分页速度

数据的分页是我们再熟悉不过的功能了,各种各样的分页方式层出不穷。今天我把一些常见的存储过程分页列出来,再简单地测一下性能,算是对知识的总结,也是对您好想法的抛钻引玉。废话不多说,开始吧~~ 1.首先建立一张测试表…

YOLOv3模型剪枝,瘦身80%,提速100%,精度基本不变

作者 | CV君转载自我爱计算机视觉(ID: aicvml)如果要在实际应用中部署目标检测,你会想到哪项算法?在52CV目标检测交流群里,被提及最多的,恐怕就是YOLOv3了。虽然新出的一些算法号称“完胜”“吊打”某某某算…

Ubuntu开发用新机安装流程

1.SSH安装 Ubuntu缺省已安装客户端,此处安装服务端 sudo apt-get install openssh-server 确认sshserver是否启动 netstat -tlp | grep ssh 或 ps -e | grep ssh 未启动,选择启动 sudo /etc/init.d/ssh start 2.问题解决:ACPI Error:Method p…

人工智能六十年技术简史

出品 | AI科技大本营(ID:rgznai100)作者:李理,环信人工智能研发中心vp,十多年自然语言处理和人工智能研发经验。主持研发过多款智能硬件的问答和对话系统,负责环信中文语义分析开放平台和环信智能机器人的设…

【Android游戏开发二十五】在Android上的使用《贝赛尔曲线》!

首先对于《赛贝尔曲线》不是很了解的童鞋,请自觉白度百科、google等等... 为了方便偷懒的童鞋,这里给个《贝赛尔曲线》百科地址,以及一段话简述《贝赛尔曲线》: 《贝赛尔曲线》白度百科快速地址:http://baike.baidu.co…

Spring Boot 工程集成全局唯一ID生成器 Vesta

2019独角兽企业重金招聘Python工程师标准>>> 本文内容脑图如下: 文章共 760字,阅读大约需要 2分钟 ! 概 述 在前一篇文章 《Spring Boot工程集成全局唯一ID生成器 UidGenerator》 中给大家推荐了一款由百度开发的基于 Snowflake算…

vs2008中,创建基于对话框的mfc动态库步骤

1、利用MFC Dll向导初始生成一个mfc dll(默认设置); 2、添加一个对话框资源; 3、向工程中添加一个.h、.cpp文件,作为外部的接口; 4、.h头文件的格式仿照于基于控制台的dll的头文件格式; 5、.h头文件中包括资源文件头文…

poj3468 A Simple Problem with Integers

http://acm.hust.edu.cn:8080/judge/problem/viewProblem.action?id14607 题意:题目给你n个数,m个操作,接下来一行给你这n个数,接下的几行给出m个操作,Q a b 表示查询区间[a,b]里的数和和。U a b c 表示把区间[a,b]里的数都加上c…

【Luogu】P1613 跑路

【Luogu】P1613 跑路 一、题目 题目描述 小A的工作不仅繁琐,更有苛刻的规定,要求小A每天早上在6:00之前到达公司,否则这个月工资清零。可是小A偏偏又有赖床的坏毛病。于是为了保住自己的工资,小A买了一个十分牛B的空间…

matlab图形用户界面设计简介

1、File->New->GUI->Create New GUI->Blank GUI->OK即可打开图形用户界面开发环境。 在里面可以拖放需要的控件,包括pushbutton、slider、radiobutton、togglebutton、checkbox、listbox、popupmenu、edit text、static text、table、axes、panel、…

旷视发布《人工智能应用准则》,倡导AI技术健康可持续发展

2019年7月8日,旷视宣布推出基于企业自身管理标准的《人工智能应用准则》(以下简称《准则》),旨在从人工智能企业自身的角度,规范、引导人工智能技术正确运用和健康发展,并确保其安全可控可靠,促…

Java知识积累——String引用的判断问题

看如下程序 1 public static void main(String[] args) {2 String a new String("abc");3 String b new String("abc");4 System.out.println(a b); 5 6 String c "abc";7 String d "abc";8 …

windows7下vs2008常见错误解决方法汇总

1、fatal error LNK1000:Internal error during IncrBuildImage 解决方法:选中对应工程-->点击右键,选择Properties-->Configuration Properties-->Linker-->General-->选中Enable Incremental Linking:改为No(/INCREMENTAL:NO),原始选项…

5G对AIoT的作用并无夸大,最大价值在于融合

采访嘉宾 | 崔宝秋、高恩重整理 | 夕颜出品 | AI科技大本营(ID:rgznai100)近年来,AIoT 的概念非常火爆,有不少企业将 AIoT 提升到公司的战略发展高度,然而实际上,走进普通人日常生活并真正实用的 AIoT 产品…

[USACO07JAN]平衡的阵容Balanced Lineup BZOJ 1699

题目背景 题目描述&#xff1a; 每天,农夫 John 的N(1 < N < 50,000)头牛总是按同一序列排队. 有一天, John 决定让一些牛们玩一场飞盘比赛. 他准备找一群在对列中为置连续的牛来进行比赛. 但是为了避免水平悬殊,牛的身高不应该相差太大. John 准备了Q (1 < Q < 18…

深度学习目标检测法进化史,看这一篇就够了

作者 | 黄浴&#xff0c;奇点汽车美研中心首席科学家兼总裁来源 | 转载自知乎专栏自动驾驶的挑战和发展本文将介绍自动驾驶中的深度学习目标检测的基本概念和方法&#xff0c;并对几个主要 Anchor free 方法进行了比较&#xff0c;希望对读者有所帮助&#xff0c;以下为正文&am…

Bridge Pattern

2019独角兽企业重金招聘Python工程师标准>>> http://www.cnblogs.com/hegezhou_hot/archive/2010/12/10/1902185.html 桥接模式的主要目的是将一个对象的变化因素抽象出来&#xff0c;不是通过类继承的方式来满足这个因素的变化&#xff0c;而是通过对象组合的方式来…

matlab神经网络工具箱函数汇总

转自&#xff1a;http://hi.baidu.com/lingyin55/blog/item/7a968ead11fe180c4b36d61e.html 1. 网络创建函数 newp 创建感知器网络 newlind 设计一线性层 newlin 创建一线性层 newff 创建一前馈BP网络 newcf 创建一多层前馈BP网络 newfftd 创建一前馈输入延迟BP网…

[每日短篇] 17 - 正确使用随机数 Random

2019独角兽企业重金招聘Python工程师标准>>> 随机数在系统开发中几乎是不可避免的一个需求&#xff0c;在大多数面试宝典一定会告诉你所谓的随机数其实是“伪”随机数&#xff0c;除此之外也就没有什么别的了。实际上这条知识本身已经是非常落后了&#xff0c;更不用…

LoadRunner的参数化功能分享

LoadRunner的参数化功能分享http://automationqa.com/forum.php?modviewthread&tid1598&fromuid2

MFC菜单的使用

1、 创建弹出菜单&#xff1a; (1)、利用向导&#xff0c;创建一个基于单文档的应用程序&#xff1b; (2)、在资源视图中选中”menu”&#xff0c;鼠标右键插入一新菜单IDR_POPMENU&#xff1b; (3)、在IDR_POPMENU菜单中添加”弹出菜单”选项&#xff0c;在”弹出菜单”下…

超阿里、大华,澎思科技行人再识别(ReID)技术刷新三大数据集记录

整理 | Jane出品 | AI科技大本营&#xff08;ID&#xff1a;rgznai100&#xff09;【导读】不久前&#xff0c;江苏省某市公安通过 AI 技术分析监控摄像头中的信息&#xff0c;抓获了一个偷盗电动车的嫌疑人员。监控摄像头在现场拍到的是嫌疑人背对摄像头的情况&#xff0c;未有…

[转] vuewebpack多页面配置

前言 最近由于项目需求&#xff0c;选择使用vue框架&#xff0c;webpack打包直接使用的vue-cli&#xff0c;因为需要多页面而vue-cli只有单页面&#xff0c;所以就决定修改vue-cli的配置文件来满足开发需求。 html-webpack-plugin 实现需求需要用到这个插件&#xff0c; 具体信…

微信扫描二维码登入实现,网页端

2019独角兽企业重金招聘Python工程师标准>>> 服务器端要做得事很多&#xff0c;虽然逻辑不是很复杂&#xff0c;但是我们必须要分析清楚我们要做哪些事&#xff0c;请看下图&#xff1a; 通过这张图&#xff0c;我们看出&#xff0c;服务器端的接口一共有6个&#…

微软洪小文:AI将成为人类未来最好的左脑

演讲嘉宾 | 洪小文整理 | 夕颜出品 | AI科技大本营&#xff08;ID:rgznai100&#xff09;导读&#xff1a;2019 年 6 月 14 日&#xff0c;由清华大学五道口金融学院、清华大学国家金融研究院、清华大学研究生会联合主办的“未来已来—全球领袖论天下”系列讲座再次开讲。应清华…

计算机视觉相关网站

转自&#xff1a;http://blog.sciencenet.cn/home.php?modspace&uid454498&doblog&id377338 1、OpenCV中文网站 http://www.opencv.org.cn/index.php/%E9%A6%96%E9%A1%B5 2、Advanced Digital Imaging Solutions Laboratory (ADISL) Image Apprentice is a C/C ba…

预告 · Flutter Live 2018 全球同步直播

Flutter Live 2018 是 Google 在伦敦线下举办&#xff0c;并面向全球线上直播的一次 Flutter 庆祝活动。在 2018 年已经过去的这段时间里&#xff0c;Flutter 有着非常大的进展&#xff1a; 2 月底在世界移动大会 (MWC) 上宣布了第一个 Beta 版发布;5 月的 Google I/O 大会上发…

context-param与init-param的区别与作用

<context-param>与<init-param>的区别与作用 spring2009-11-04 16:49阅读39 评论0字号&#xff1a;大 中 小<context-param>的作用:web.xml的配置中<context-param>配置作用1. 启动一个WEB项目的时候,容器(如:Tomcat)会去读它的配置文件web.xml.读两个…

C#中object的使用

转自&#xff1a;http://www.hackvip.com/article/sort0129/sort0143/Hackvip_233655.html C#中system.object的函数方法功能介绍 在C#中&#xff0c;Object类型是所有类型的根&#xff0c;大家平常开发中都要跟它打交道&#xff0c;但不见得对它里面的每个方法都知根知底&am…

百炼智百炼智能获5000万元Pre-A轮融资,深耕智能获客赛道

出品 | AI科技大本营&#xff08;ID:rgznai100&#xff09;2019年7月9日&#xff0c;百炼智能正式宣布完成5000万元Pre-A轮融资。该轮融资由东方嘉富领投&#xff0c;上市公司任子行、元投资本和酷我音乐创始人雷鸣等投资者跟投。百炼智能利用自有核心自然语言处理、图像识别和…