title: CRichEditCtrl GetLine 中文
author: Love02xp
date: 2019-07-03 06:59:55
category: [编程代码]
tags: [代码,VC6]
用msdn例子先是各种崩溃,然后网上找原因,最后不崩了,取中文又有问题,最后没问题的代码如下
<!--more-->
int nLineIndex, nLineLength, i = m_richMsg.LineFromChar(-1);
for(;i>=0; i--)
{
nLineIndex = m_richMsg.LineIndex(i);
nLineLength = m_richMsg.LineLength(nLineIndex);
char* achLine=new char[nLineLength+4]; //缓冲区必须足够大,否则读取中文时可能会有乱码
int nLen = m_richMsg.GetLine(i, achLine, nLineLength+4);
delete[] achLine;
}
参考
http://technet.microsoft.com/zh-cn/library/z0z83tcz%28v=vs.110%29.aspx(还是不要参考了,当然我水平也不足)
http://topic.csdn.net/u/20100715/18/a9a422c9-d29f-42d5-ad00-9aad1341ea96.html(解决msdn例子崩溃)
http://en.verysource.com/code/2313471_1/myricheditctrl.cpp.html(解决中文乱码)