(7)为了使嵌入的工作区占满整个客户区可以通过修改OnDraw函数来实现:
- void CEmbed_WordView:nDraw(CDC* pDC)
- {
- CEmbed_WordDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if (m_pSelection == NULL)
- {
- POSITION pos = pDoc->GetStartPosition();
- m_pSelection = (CEmbed_WordCntrItem*)pDoc->GetNextClientItem(pos);
- }
- if (m_pSelection != NULL)
- {
- CRect rect;
- GetClientRect(&m_pSelection->rect);
- m_pSelection->OnGetItemPosition(rect);
- m_pSelection->Draw(pDC,rect);
- }
- }
二:
在VC中调用WORD(显示,修改,存盘,运行宏)
(1)使用AppWizard创建一个新的MFC AppWizard(EXE)工程,命名为"office"
(2)选择单文档视图(SDI)结构,在第3步中需要选中Container,以提供容器支持,并且选中active document container 其它都为默认
(3)在View菜单中,选ClassWizard,选Automation选项卡,选Add Class,选择From a TypeLibrary, 在Office目录中选中Microsoft Word 97/2000 类型库Word8.olb或Word9.olb,选中application,document,_document。单击ok
(4)给COfficeCntrItem添加一Public方法。LPDISPATCH GetIDispatch()
其源码如下:
- ASSERT_VALID(this); ASSERT(m_lpObject != NULL);
- LPUNKNOWN lpUnk = m_lpObject; Run();
- LPOLELINK lpOleLink = NULL; if (m_lpObject->QueryInterface(IID_IOleLink, (LPVOID FAR*)&lpOleLink) == NOERROR)
- { ASSERT(lpOleLink != NULL);
- lpUnk = NULL; if (lpOleLink->GetBoundSource(&lpUnk) != NOERROR)
- { TRACE0("Warning: Link is not connected!\n");