Stackcat's Blog
CRichEditCtrl Encoding Error 본문
CRichEditCtrl을 사용할때는 대부분 rtf 파일을 읽어들여서 그대로 출력하는 경우가 많지만, rtf파일을 사용하지않고 수동으로 직접 데이터를 입력할 때가 있다.
이 때 ReplaceSel등을 사용하면 일부 언어의 경우 인코딩이 깨지는 등 제대로 출력이 되지않는데,
다음과 같이 SendMessage를 통해 데이터를 입력하도록하자.
사내 제품에서 사용중인 소스여서 일부 소스는 수정하여 게시하였음.
{생략}
map::iterator mpIter_cs = m_mpExtCategoryString.begin();
CString strResultExtList;
// 분류된 확장자들을 순서대로 타이틀 생성하며 출력한다.
for(;mpIter_cs != m_mpExtCategoryString.end(); mpIter_cs++)
{
CString strTitle, strTemp;
// 마지막 위치로 이동.
int last_pos = m_REditExt.LineIndex(m_REditExt.GetLineCount());
m_REditExt.SetSel(last_pos, last_pos);
CPoint point;
point = m_REditExt.PosFromChar(last_pos);
m_REditExt.SetCaretPos(point);
m_REditExt.SetFocus();
strTitle.Format(_T("%s\r\n"), mpIter_cs->second);
// 타이틀은 색 + 굵게 하이라이팅해줘야함..
COLORREF clrRGB = RGB(0, 89, 166);
CHARFORMAT cf;
memset(&cf, 0, sizeof(CHARFORMAT));
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_BOLD | CFM_COLOR;
cf.dwEffects = CFE_BOLD;
cf.crTextColor = clrRGB;
SETTEXTEX ste;
ste.flags = ST_SELECTION;
ste.codepage = 1200; // UNICODE
// 타이틀 출력 - 타이틀은 언어별로 인코딩이 깨질수 있기 때문에 ReplaceSel 대신 SetTextEx를 이용하여 작업한다.
m_REditExt.SetSelectionCharFormat(cf);
m_REditExt.SendMessage(EM_SETTEXTEX, (WPARAM)&ste, (LPARAM)(LPCTSTR)strTitle);
{생략}
'프로그래밍 > C, C++, MFC, Win API....' 카테고리의 다른 글
| UTC String to Local Time (1) | 2018.06.04 |
|---|---|
| Read File Encoding Error (0) | 2018.06.04 |
| CString to CFile (0) | 2018.06.04 |
Comments