怎样用VC把BMP图片保存在word文档中?有例子最好

解决方案 »

  1.   

    vckbase里面有把文字保存到word文档中的例子
      

  2.   

    http://www.vckbase.com/document/viewdoc/?id=1174
      

  3.   

    通过_Application, _Document取到inlineshapes
    调用inlineshapes.AddPicture()
      

  4.   

    // ok...
    // Office !! Word !!!
    _Application app;
    app.CreateDispatch(_T("Word.Application")); Documents docs = app.GetDocuments();
    CComVariant Template(_T("")), NewTemplate(false), DocumentType(0), Visible;
    // app.SetVisible(TRUE);
    docs.Add(&Template, &NewTemplate, &DocumentType, &Visible); Selection sel = app.GetSelection();
    _Document doc = app.GetActiveDocument();
    sel.TypeText(_T("HELLO\r\nHello World!!"));
    sel.TypeParagraph(); // add picture.
    CComVariant picLinkToFile(false), SaveWithDocument(true);
    CComVariant picRange(sel.GetRange());
    // picRange.vt = VT_DISPATCH;
    // picRange.pdispVal = sel.GetRange();
    InlineShapes picInShapes = sel.GetInlineShapes();
    picInShapes.AddPicture(m_strImageName, &picLinkToFile, &SaveWithDocument, &picRange); // save as.
    CComVariant FileName(m_strPathName);
    CComVariant FileFormat(0);
    CComVariant LockComments(false), Password(_T(""));
    CComVariant AddToRecentFiles(true), WritePassword(_T(""));
    CComVariant ReadOnlyRecommended(false), EmbedTrueTypeFonts(false);
    CComVariant SaveNativePictureFormat(false), SaveFormsData(false);
    CComVariant SaveAsAOCELetter(false);
    CComVariant Encoding, InsertLineBreaks, AllowSubstitutions, LineEnding, AddBiDiMarks; doc.SaveAs(&FileName,&FileFormat,&LockComments,&Password,
    &AddToRecentFiles,&WritePassword,&ReadOnlyRecommended,
    &EmbedTrueTypeFonts,&SaveNativePictureFormat,&SaveFormsData, &SaveAsAOCELetter);

    // release and quit.
    doc.ReleaseDispatch();
    sel.ReleaseDispatch();
    docs.ReleaseDispatch();
    CComVariant SaveChanges(false), OriginalFormat, RouteDocument;
    app.Quit(&SaveChanges, &OriginalFormat, &RouteDocument);
    app.ReleaseDispatch();