{oapdf_gg}
Office software is closely linked to the PDF,the PDF is also must have to control!      Set home Page  Add to Favorites  
You are here:Home > OA info > WORD info and download
WORD info and download
MFC application in dynamic embedded Word document
Finishing by: Date:2009-08-01 10:01:04 Popularity: Tags:
open and display word documents
  
Category in the main framework ID_FILE_OPEN add menu command response function in order to open Word documents to dynamically provide their support. The following code in the Word document file to be the full path will WM_COMMAND message by sending the document to create a new view:

// Open file dialog box displayed
CFileDialog fileDlg(TRUE, "*.doc", "*.doc", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Word猟周(*.doc)|*.doc||", NULL);
if (fileDlg.DoModal() == IDOK)
{
 // Get file path
 m_sPath = fileDlg.GetPathName();
 // New Document
 PostMessage(WM_COMMAND, ID_FILE_NEW, 0);
}

  
View class in the initialization function update OnInitialUpdate () in the completion of the dynamics of embedded Word:


CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->GetMainWnd();
if (pFrame->m_sPath.Right(3) != "DOC" && pFrame->m_sPath.Right(3) != "doc")
 return;
m_sPath = pFrame->m_sPath;
EmbedAutomateWord();
if (m_pSelection != NULL)
{
 CRect rect;
 GetClientRect(&rect);
 CDC* pDC = GetDC();
 m_pSelection->Draw(pDC,rect);
 ReleaseDC(pDC);
}
m_pSelection = NULL;

  
Which, EmbedAutomateWord () function will be responsible for the procedures will be embedded in Word. Its concrete realization of the process is as follows:


BeginWaitCursor();
CEmbed_WordCntrItem* pItem = NULL;
TRY
{
 CEmbed_WordDoc* pDoc = GetDocument();
 ASSERT_VALID(pDoc);
 pItem = new CEmbed_WordCntrItem(pDoc);
 ASSERT_VALID(pItem);
 CLSID clsid;
 if (FAILED(::CLSIDFromProgID(L"Word.document", &clsid)))
  AfxThrowMemoryException();
 if (!pItem->CreateFromFile(m_sPath, clsid))
  AfxThrowMemoryException();
 pItem->DoVerb(OLEIVERB_SHOW, this);
 m_pSelection = pItem;
 pDoc->UpdateAllViews(NULL);
 LPDISPATCH lpDisp;
 lpDisp = pItem->GetIDispatch();
}
CATCH(CException, e)
{
 if (pItem != NULL)
 
 AfxMessageBox(IDP_FAILED_TO_CREATE);
}
END_CATCH
EndWaitCursor();

  If you have looked carefully at the code, you will find it with AppWizard automatically generated OnInsertObject () function has a surprising degree of similarity, in fact, the above code is only OnInsertObject () of a special case: OnInsertObject () allows the user from the available OLE Object list, select the one inserted into the application. Because of this we need to do is to automate Word, so the act of derivation. Here through the use of CreateFromFile () method to open m_sPath designated by the Word document, and DoVerb () method implementation of the verb to complete the document OLEIVERB_SHOW show action. In order to embed the work area occupying the entire client area, the need to embed documents, customer size changes and update the view after the call Draw () method to re-draw.
there isArticle InformationsComment Information
Category column

Site Help | Site Map | Feedback |
OAPDF.COM Copyright 2009 V1.1