In a C++ Word Plugin how to create a blank RTF document?

craig20120
craig20120 used Ask the Experts™
on
I am using C++ MFC / ATL in a Word 2003 plugin and need to know how to create a new Word document using the RTF document type.  Cuurently, I am doing the following to create a blank Word doc.

MSWord::_DocumentPtr pdoc = NULL;
pdoc = m_spApp->Documents->Add(&Opt, (&Opt, (&Opt, COleVariant((short)true));

The third argument is the Document type, but how do I specify this to be RTF.  
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
AndyAinscowFreelance programmer / Consultant

Commented:
Don't you specify the document type when saving, not when creating a new document?

Author

Commented:
Syntax correction below... Sorry cut and pasted the arguments.

MSWord::_DocumentPtr pdoc = NULL;
pdoc = m_spApp->Documents->Add(&Opt, &Opt, &Opt, COleVariant((short)true));

To Answer the above question. I'm not sure.  After doing some more research, I found the following on MSDN.

DocumentType  Optional Variant. Can be one of the following WdNewDocumentType constants: wdNewBlankDocument, wdNewEmailMessage, wdNewFrameset, or wdNewWebPage. The default constant is wdNewBlankDocument.

I had thought that RTF was one of the document types.  

So plan B...   How can I create an RTF document to be copied to the clipboard Without first saving the doc as RTF??
AndyAinscowFreelance programmer / Consultant

Commented:
I think for a new document there isn't any rtf specifier.  That is with the SaveAs...

There shouldn't be anything to stop you saving to a temporary file as an rtf first, you can always delete it afterwards.

Author

Commented:
I really want to avoid writing it out first.  These documents could be huge.  Does anyone know of a way to create an RTF doc in Word without saving first???

Author of the Year 2009
Commented:
It seems to me that if you use the standard Copy operation, WORD will place multiple data formats on the clipboard, probably including "Unformatted Text", "Word document", and "RTF"

So any program that gets the data from the clipboard should be able to choose the RTF format.

Thus:  Create the empty document (or maybe just a one-character document), and select all, then copy to the clipboard, then extract just the RTF version of the data.   It might also be possible to delete the other formats to avoid confusing a "dumb" clipboard-target client.

If you explain your specific need (e.g., to what are you passing this data, and why do you need it to be RTF, etc.) I might be able to be more specific.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial