{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:
Save Word document

  Although the environment has been embedded into the Word application, Word document has been opened and displayed, but if you use the wizard to generate the "Save" function to save the current open Word documents can only save an empty document. This is because the current procedures embedded in Word interface after the "file" menu is a package container program, and the Word in the absence of associated documents can not be implemented before the preservation of function. In its response function in order to add the following code to complete the preservation of the document:
// Open file dialog box displayed
CFileDialog fileDlg(FALSE, "*.doc", "*.doc", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, "Word猟周(*.doc)|*.doc||", NULL);
if (fileDlg.DoModal() != IDOK)
 return;
CString sPath = fileDlg.GetPathName();
char cPath[256];
memset(cPath, 0, sizeof(cPath));
memcpy(cPath, sPath, sPath.GetLength());
WCHAR wPath[256];
memset(wPath, 0, sizeof(wPath));
MultiByteToWideChar(CP_ACP, MB_COMPOSITE, cPath, sPath.GetLength(), wPath, sizeof(wPath));
IDispatch *pOle = m_pSelection->GetIDispatch();
if (!pOle )
 return; // No ole document
IPersistFile *pPFile = NULL;
pOle->QueryInterface(IID_IPersistFile, (void**)&pPFile);
if (!pPFile)
{
 // IPersistFile interface does not support
 if (pOle)
  pOle->Release();
 if (pPFile)
  pPFile->Release();
}
else
pPFile->Save(wPath, FALSE);

  The core idea of this code is through the use of IPersistFile interface Save () method to preserve the current document. Since the method of the first parameter is a variable LPOLESTR to see the definition of the macro can be aware of the variables is a point to wide-character buffer pointer from CFileDialog Class Member Functions GetPathName () the return path CString type can not directly use the document to be through MultiByteToWideChar () function will convert the content type to a WCHAR array. Its first parameter specified by CP_ACP package to use ANSI encoding, the second parameter set to indicate MB_COMPOSITE have been using composite characters. Behind the four variables were the source buffer's address, size and purpose of the address and the size of the buffer zone.
  Summary
  
Compiler implementation of the procedure, when the program will open the Word document automation services dynamic start Word, then the mouse will be in a wait state, when the mouse back to normal mode, Word has been embedded into the process, the toolbars and menus are added to many Word tools and menus, can they improve on the Word document to provide support and services. This procedure in the Windows 2000 Professional by Microsoft Visual C + + 6.0 compiler through. Program need to have Microsoft Word 97 or Word 2000 support.
there isArticle InformationsComment Information
Category column

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