|
-
October 4th, 2010, 02:59 PM
#2
Re: How to use CDocManager in CDocument OnSaveAs override ?
Perhaps you are having problems because RichEdit controls (and most other controls) violate the doc/view architecture: Unlike doc/view, RichEdits invariably store their contents inside the control itself, rather than inside some document that's separated from the view.
If this is the cause of your problem (a guess), then it might be helpful to look at the CRichEdit::StreamOut function. If you were doing this from the Main Frame (you're not), then code might look like this. Note that this is "found" code, and is not correct insofar as Unicode usage is concerned (please confirm that you are building a non-Unicode build, since your sample code is non-Unicode too). It should not be used as-is, but is merely being offered to prompt you with some ideas:
Code:
void CMainFrame::OnFileSaveas()
{
// szFilters is a text string that includes two file name filters:
// "*.txt" for "Text Files" and "*.*" for "All Files."
char szFilters[]= "Text Files (*.txt)|*.txt|All Files (*.*)|*.*||";
// Create an Open dialog; the default file name extension is ".my".
CFileDialog fileDlg (FALSE, "txt", "*.txt",
OFN_OVERWRITEPROMPT| OFN_HIDEREADONLY, szFilters, this);
// Display the file dialog. When user clicks OK, fileDlg.DoModal()
// returns IDOK.
if( fileDlg.DoModal ()==IDOK )
{
m_strPathname = fileDlg.GetPathName();
CFile cFile(m_strPathname, CFile::modeCreate|CFile::modeWrite);
EDITSTREAM es;
es.dwCookie = (DWORD) &cFile;
es.pfnCallback = (EDITSTREAMCALLBACK) MyStreamOutCallback;
m_RichEdit.StreamOut(SF_RTF,es); // Perform the streaming
}
}
/* The following function MyStreamOutCallback must be declared as
"static"
in the header file*/
DWORD CALLBACK MyStreamOutCallback(CFile* dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb)
{
// Required for StreamOut
CFile* pFile = (CFile*) dwCookie;
pFile->Write(pbBuff, cb);
*pcb = cb;
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|