由于工作上需要,把软件移植到英文版的os上(软件已是unicode版本的),发现richedit控件上显示的字体(本来内容应该显示为中文)乱码了。

发生乱码的具体代码:
         SetDlgItemText(IDCE_MEMO, m_Results[nIdx].Content);
IDCE_MEMO为richedit的资源名,m_Results[nIdx].Content为要显示的字符串内容(已经是unicode编码的了)。

查找原因:可能是控件不了解字符串已经是unicode代码,所以控件根据locale 的code page来硬性将代码转换为unicode显示,所以出现乱码。

解决方法:
#ifdef UNICODE
  //请注意,因为是unicode版本,所以codepage要用1200,以告诉RichEdit传过去的文本已经是unicode,以免出现乱码,详情请看MSDN。
  SETTEXTEX SetTxtEx;
  SetTxtEx.flags = ST_DEFAULT;
  SetTxtEx.codepage = 1200;
  BOOL bRet = ::SendMessage(::GetDlgItem(m_hWnd, IDCE_MEMO), EM_SETTEXTEX, (WPARAM)&SetTxtEx, (LPARAM)m_Results[nIdx].Content);
  ASSERT(bRet);
#else
  SetDlgItemText(IDCE_MEMO, m_Results[nIdx].Content);
#endif

The code page used to translate the text to Unicode. If codepage is 1200 (Unicode code page), no translation is done. If codepage is CP_ACP, the system code page is used.


posted on 2005-12-28 17:01 Jeffrey.Coding 阅读(645) 评论(0)  编辑 收藏 引用 所属分类: 技术点

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理