丰富的Edit控件保存到文件 [英] Rich Edit control save to file

查看:145
本文介绍了丰富的Edit控件保存到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用丰富的编辑控件为C ++创建文本编辑器.
我使用CFileDialog将Rich编辑中的代码保存到* .cpp或* .h文件中. 当我保存它,然后在Visual C ++环境中打开它时,它向我显示行尾消息,并且在每行代码之间放置一个空行.

我该如何解决?

Hi,

I''m making a text editor for C++ using rich edit control.
I use CFileDialog to save the code in Rich edit to a *.cpp or *.h file.
When I save it and then open it with Visual C++ environment, it shows me Line endings message and it puts an empty line between every line of code.

How can I fix it?

Thanks in advance!

推荐答案

我宁愿删除丰富的编辑控件,并使用类似以下内容的内容:
在MFC中使用Scintilla进行语法着色 [
I''d rather drop the rich edit control and use something like:
Using Scintilla for syntax coloring in MFC[^]

It will save you a lot of time, and add a number of nifty features :)

Best regards
Espen Harlinn


您可能会以文本模式打开输出文件以保存RE内容.您可以在保存时尝试将其打开为二进制文件(当然也可以加载).

技术说明:您将从控件中获得RE内容,并且保留完整的行尾字符,即0x0d 0x0a("\ r \ n"),MS OS将其用作行尾标记.保存时,RTL例程将所有0x0a("\ n")字符替换为0x0d 0x0a("\ r \ n"),然后行尾已变为0x0d 0x0d 0x0a("\ r \ r \ n").通过VC ++编辑器打开此文件时,它将抱怨这些意外的EOL标记,然后将其解释为双行结尾.



您没有以二进制模式打开文件.您应该指定CFile :: typeBinary标志.如果未指定,则默认模式为CStdioFile的typeText.
You probably open output file as text mode to save RE content. You can try to open it as binary when saving (and loading, too, of course).

Technical explanation: You get RE content from control with end of line chars intact, that is, 0x0d 0x0a ("\r\n") which are used by MS OSes as being end of line marker. When saving, RTL routine replaces all 0x0a (''\n'') chars with 0x0d 0x0a ("\r\n"), then end of lines have become 0x0d 0x0d 0x0a ("\r\r\n"). When opening this file by VC++ editor, it complains for these unexpected EOL markers, then interprets them double end of lines.



You aren''t opening the file as binary mode. You should specify CFile::typeBinary flag. If you don''t specify it, the default mode is typeText for CStdioFile.
CFileDialog dlg(FALSE, NULL, NULL, OFN_OVERWRITEPROMPT, 
	 L"C++ Source Files (*.cpp)|*.cpp|C++ Header Files (*.h)|*.h|");

CStdioFile file; 
CString buffer; 
CString textfile; 
if(dlg.DoModal() == IDOK) 
{ 
    file.Open(dlg.GetPathName(), // more appropriate instead of GetFileName()
      CFile::typeBinary | CStdioFile::modeCreate | CStdioFile::modeWrite);
    text.GetWindowText(buffer);
    file.Write((void*)(LPCTSTR)buffer, buffer.GetLength() * sizeof(TCHAR));
    file.Close();
}



您不会为上述代码的UNICODE转换做任何事情.如果您没有将项目设置更改为MBCS,则保存的文件仍应为UNICODE.



You aren''t doing anything for UNICODE conversion with above code. If you didn''t change project settings to MBCS, saved file should still be UNICODE.


这篇关于丰富的Edit控件保存到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆