简体   繁体   中英

C++ MFC VC 6.0 to VS2013 lStreamReturn = GetRichEditCtrl().StreamIn(SF_RTF, es);

Found an issue when converting the Tool from the VC++ 6.0 to VS2013. The error is not an actual error in the code as the code compiles with no "errors" and it works just fine. The program has been adjusted minimally, almost no real change to the code, to allow the program to run and function correctly in VS2013, or so I thought. When we tested the code to read from a external memory device, it displayed the RichText tree in the left pane of the application which seemed to work or function with what seemed to be all the data present, but the Rich Text we are so used to visually seeing was not present in the Right pane of the main application. What peaked my interest was the fact that in the original program you couldn't edit the text, but in our newest compiled program, you could see that the area had not changed from its original state. Almost as if that the data was getting to the application, but for some odd reason was getting dismissed or deleted right before displaying to the pane.

So here's the problem, when the WCARichEdit.cpp does this "

EDITSTREAM es;    
es.dwError=0;    
es.dwCookie =  (DWORD) &Report;    
es.pfnCallback = CBStreamIn;    
lStreamReturn  = GetRichEditCtrl().StreamIn(SF_RTF, es);    
GetRichEditCtrl().SetReadOnly(TRUE);

"
It breaks or throws the error 0 unless SF_RTF is changed to SF_TEXT. The code then generates all the data, but the formatting is read into the stream of text. One giant stream that is. We are under some assumption that the formatting in this code is the culprit as to why the text is not showing up when we compile our code. So when the SplitterFrame.CPP does this

"

Void CSplitterFrame::DisplayReport(CString Report)

{

   CWcaRichEdit*RichEditView = (CWcaRichEdit*) m_wndSplitter.GetPane(0,1);

   CH1_MainteanceToolDoc*pDoc = (CH1_MainteanceToolDoc*)
      ((CMainFrame *)AfxGetMainWnd())->GetActiveDocument();

   RichEditView->DisplayReport(pDoc, Report);
}

" The RichEditView->DisplayReport(pDoc, Report) doesn't seem to be getting any code as it just gets zeroed out. This is confirmed by the dwError=0 displaying no change when SF_RTF is left unchanged.

Any Thoughts as to how to get this Rich Text to display?

During troubleshooting this code below was written to push the string to a text file.

#if
DWORD dwError;

CFile testfile;
if (0 == testfile.Open ("C:\\...rtftestfile.txt", CFile::modeCreate | CFile:modeWrite | CFile::shareDenyNone))
{
    dwError = GetLastError();
{
testfile.Write((LPCTSTR) Report, Report.GetLength());
testfile.Close();
#endif

The file was created successfully, and out of a whim, the decision was made to save the file after opening the .text file in WordPad. We then saved the file as a new .rtf file extension. Oddly enough the program didn't view all of our formatting but rather added some code in the mix as the size of the wordpad file and the text file varied by size. We then took each file and "Drag and Drop" 'ed them into the notepad program for further review. Strangely enough a "\\rtf1" was added to the beginning of our gigantic string. Odd, why would WordPad add that...wait. The realization came and we went back and changed our code from

const char RTF_Header[] = "{\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fontbl{\\f0\\fnil\\fcharset0 Courier New;}}\\viewkind4\\uc1\\pard\\fs17 ";

to

const char RTF_Header[] = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fontbl{\\f0\\fnil\\fcharset0 Courier New;}}\\viewkind4\\uc1\\pard\\fs17 ";

The learning point is this, if you know your formatting is breaking your code, print that giant string to a file to see what it's doing and push it into something that will place the rtf formatting where it is missing.

The other option is to have someone on hand that loves to utilize the awesome power of Rich Text and can remember all the ways to format it.

Also here is the Microsoft Forum discussion if you want to brave it:

Microsoft Forum GetRichEditCtrl().StreamIn breaks on formating

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM