单文档视图结构的ActiveX控件.docVIP

  • 5
  • 0
  • 约1.15万字
  • 约 11页
  • 2016-09-11 发布于河南
  • 举报
单文档视图结构的ActiveX控件

单文档/视图结构的ActiveX控件 单文档/视图模式是MFC编程里比较强大的一种编程模式,如果ActiveX控件能够用这种模式的话,将可以做出非常强大的Web在线应用。 下面我们就介绍一种把单文档/视图模式的程序改造成ActiveX控件的方法。 做起来很难,但是完成了会很有成就感,本方法来源于15Seconds。 在VC6.0和VC.Net下都已证明可行。我用这个方法做了一个Web上的在线服装设计软件,Client端支持NT4.0,客户公司有上千台NT4.0。据美国同事说在投标中击败了Altium公司(电路设计软件Protel的开发商)的方案,哈。 需要要两个文件: 1.ActivDoc.cpp //?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); } CFrameWnd*?CActiveXDocTemplate::CreateDocViewFrame(CWnd*?pParentWnd) { ????CWaitCursor?cursor; ?TRY ?{ ?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?CFrameWnds?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; ?} ?CATCH_ALL(e) ?{ ??AfxMessageBox(Read?storyboard?error.please?retry!); ??//THROW_LAST(); ?} ?END_CATCH_ALL ?return?NULL; } 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_pCurrentDo

文档评论(0)

1亿VIP精品文档

相关文档