// TODO: remove this code when final selection model code is written m_pSelection = NULL; // initialize selection
//Active documents should always be activated COleDocument* pDoc = (COleDocument*) GetDocument(); if (pDoc != NULL) { // activate the first one POSITION posItem = pDoc->GetStartPosition(); if (posItem != NULL) { CDocItem* pItem = pDoc->GetNextItem(posItem);
// only if it's an Active document COleDocObjectItem *pDocObjectItem = DYNAMIC_DOWNCAST(COleDocObjectItem, pItem);
void CBbView::OnInitialUpdate()
{
CView::OnInitialUpdate();
// TODO: remove this code when final selection model code is written
m_pSelection = NULL; // initialize selection
//Active documents should always be activated
COleDocument* pDoc = (COleDocument*) GetDocument();
if (pDoc != NULL)
{
// activate the first one
POSITION posItem = pDoc->GetStartPosition();
if (posItem != NULL)
{
CDocItem* pItem = pDoc->GetNextItem(posItem);
// only if it's an Active document
COleDocObjectItem *pDocObjectItem =
DYNAMIC_DOWNCAST(COleDocObjectItem, pItem);
if (pDocObjectItem != NULL)
{
pDocObjectItem->DoVerb(OLEIVERB_SHOW, this);
}
}
}
}
可以写出通过文件对话框载入 Word 文档的函数
void CBbView::OnOpenFile()
{
CFileDialog dlgFile(TRUE, NULL, NULL, OFN_HIDEREADONLY, _T("Word Documents(*.doc)|*.doc||"));
if(dlgFile.DoModal()!=IDOK)
return;
BeginWaitCursor();
CBbCntrItem* pItem = NULL;
CLSID clsidWord= {0xBB2E617C, 0x0920, 0x11D1, {0x9A, 0x0B, 0x00, 0xC0, 0x4F, 0xC2, 0xD6, 0xC1} };
TRY
{
CBbDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pItem = new CBbCntrItem(pDoc);
ASSERT_VALID(pItem);
pItem->CreateFromFile(dlgFile.GetPathName(), clsidWord );
pItem->DoVerb(OLEIVERB_SHOW, this);
m_pSelection = pItem; // set selection to last inserted item
pDoc->UpdateAllViews(NULL);
}
CATCH(CException, e)
{
if (pItem != NULL)
{
ASSERT_VALID(pItem);
pItem->Delete();
}
AfxMessageBox(IDP_FAILED_TO_CREATE);
}
END_CATCH
EndWaitCursor();
}
但是发现大小不适合。。请问怎么改啊