这个代码返回中文为什么会是乱码,麻烦各位大哥帮忙看看,谢谢!

u010684553 2017-12-12 08:48:45

int CBasicTextBox::AddMultiTextLongestLine ( MULTITEXT strText )
{
if ( !m_pFont )
{
GASSERT ( 0 && " " );
return 0;
}

STEXTPART sTEXTPART;
STEXTLINE sTEXTLINE;

int nLength = 0;
for ( int i = 0; i < 100; i++ )
{
if ( strText.strText[i] == "" ) continue;
if ( !strText.strText[i] ) continue;

CString strCurText = strText.strText[i];
for( int j = 0; j < strCurText.GetLength(); j++ )
{
if ( nLength < MULTITEXTSPLIT_LENGTH )
{
STEXTWORD sTEXTWORD;
sTEXTWORD.strWord = strCurText[j];
sTEXTWORD.dwColor = strText.dwColor[i];
m_pFont->GetTextExtent ( sTEXTWORD.strWord.GetString(), sTEXTWORD.strSize );

if( strCurText.GetLength() ) m_pFont->PushText( sTEXTWORD.strWord.GetString() );

sTEXTLINE.vectorWord.push_back ( sTEXTWORD );

sTEXTLINE.strSize.cx += sTEXTWORD.strSize.cx;
sTEXTLINE.strSize.cy = sTEXTWORD.strSize.cy;
}
else
{
sTEXTPART.dequeLine.push_back ( sTEXTLINE );
m_TextBox.push_back ( sTEXTPART );
m_nTotalLine++;

for ( ; m_nLimitLine < m_nTotalLine; --m_nTotalLine )
{
sTEXTPART = m_TextBox.front ();
DEQUETEXTLINE& dequeLine = sTEXTPART.dequeLine;

dequeLine.pop_front ();

if ( dequeLine.size () < 1 )
{
if ( m_ImageList.size () )
{
DeleteControl ( m_ImageList[0], 0 );
m_ImageList.pop_front ();
}
m_TextBox.pop_front ();
}
}

ReCalcRenderPos ();

sTEXTPART = STEXTPART();
sTEXTLINE = STEXTLINE();

STEXTWORD sTEXTWORD;
sTEXTWORD.strWord = strCurText[j];
sTEXTWORD.dwColor = strText.dwColor[i];
m_pFont->GetTextExtent ( sTEXTWORD.strWord.GetString(), sTEXTWORD.strSize );

if( strCurText.GetLength() ) m_pFont->PushText( sTEXTWORD.strWord.GetString() );

sTEXTLINE.vectorWord.push_back ( sTEXTWORD );

sTEXTLINE.strSize.cx += sTEXTWORD.strSize.cx;
sTEXTLINE.strSize.cy = sTEXTWORD.strSize.cy;

nLength = 0;
}
nLength++;
}
}

if ( nLength )
{
sTEXTPART.dequeLine.push_back ( sTEXTLINE );
m_TextBox.push_back ( sTEXTPART );
m_nTotalLine++;

for ( ; m_nLimitLine < m_nTotalLine; --m_nTotalLine )
{
sTEXTPART = m_TextBox.front ();
DEQUETEXTLINE& dequeLine = sTEXTPART.dequeLine;

dequeLine.pop_front ();

if ( dequeLine.size () < 1 )
{
if ( m_ImageList.size () )
{
DeleteControl ( m_ImageList[0], 0 );
m_ImageList.pop_front ();
}
m_TextBox.pop_front ();
}
}

ReCalcRenderPos ();
}

return (int)m_TextBox.size () - 1;
}
...全文
203 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
u010684553 2017-12-14
  • 打赏
  • 举报
回复
虽然不能解决,但还是谢谢这位大哥!
u010684553 2017-12-12
  • 打赏
  • 举报
回复
各位大哥麻烦帮看一下, 谢谢!
赵4老师 2017-12-12
  • 打赏
  • 举报
回复
对电脑而言没有乱码,只有二进制字节;对人脑才有乱码。啊 GBK:0xB0 0xA1,Unicode-16 LE:0x4A 0x55,Unicode-16 BE:0x55 0x4A,UTF-8:0xE5 0x95 0x8A 仅供参考:
void HexDump(char *buf,int len,int addr) {
    int i,j,k;
    char binstr[80];

    for (i=0;i<len;i++) {
        if (0==(i%16)) {
            sprintf(binstr,"%08x -",i+addr);
            sprintf(binstr,"%s %02x",binstr,(unsigned char)buf[i]);
        } else if (15==(i%16)) {
            sprintf(binstr,"%s %02x",binstr,(unsigned char)buf[i]);
            sprintf(binstr,"%s  ",binstr);
            for (j=i-15;j<=i;j++) {
                sprintf(binstr,"%s%c",binstr,('!'<buf[j]&&buf[j]<='~')?buf[j]:'.');
            }
            printf("%s\n",binstr);
        } else {
            sprintf(binstr,"%s %02x",binstr,(unsigned char)buf[i]);
        }
    }
    if (0!=(i%16)) {
        k=16-(i%16);
        for (j=0;j<k;j++) {
            sprintf(binstr,"%s   ",binstr);
        }
        sprintf(binstr,"%s  ",binstr);
        k=16-k;
        for (j=i-k;j<i;j++) {
            sprintf(binstr,"%s%c",binstr,('!'<buf[j]&&buf[j]<='~')?buf[j]:'.');
        }
        printf("%s\n",binstr);
    }
}

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧