리치 에디트 컨트롤에서 문자열을 한 줄씩 추가하는 방법
페이지 정보
본문
리치 에디트 컨트롤을 이용해서 간단한 채팅 창을 만들고 있습니다. 그런데 글꼴과 색상을 바꿔가며 한 줄씩 추가하는 것이 잘 안됩니다.
다음 함수는 m_reChat라는 이름의 리치 에디트 컨트롤에 strTextIn으로 지정한 메시지를 추가합니다. crNewColor로 지정한 색상과 sSize로 지정한 크기와 lpszFontName으로 지정한 글꼴로 추가되는 메시지를 만들어 추가합니다.
void Cxxx::AddText(CString &strTextIn, COLORREF &crNewColor, int sSize, LPCSTR lpszFontName)
{
// m_reChat은 채팅 컨트롤
int iTotalTextLength = m_reChat.GetWindowTextLength();
m_reChat.SetSel(iTotalTextLength, iTotalTextLength);
m_reChat.ReplaceSel((LPCTSTR)strTextIn);
int iStartPos = iTotalTextLength;
CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR | CFM_UNDERLINE | CFM_BOLD | CFM_FACE | CFM_SIZE;
cf.dwEffects = (unsigned long)~( CFE_AUTOCOLOR | CFE_UNDERLINE | CFE_BOLD);
cf.crTextColor = crNewColor;//RGB(0, 0, 0);
cf.yHeight = sSize * 20;
strcpy(cf.szFaceName, lpszFontName);
int iEndPos = m_reChat.GetWindowTextLength();
m_reChat.SetSel(iStartPos, iEndPos);
m_reChat.SetSelectionCharFormat(cf);
m_reChat.HideSelection(TRUE, FALSE);
m_reChat.LineScroll(1);
}
다음 함수는 m_reChat라는 이름의 리치 에디트 컨트롤에 strTextIn으로 지정한 메시지를 추가합니다. crNewColor로 지정한 색상과 sSize로 지정한 크기와 lpszFontName으로 지정한 글꼴로 추가되는 메시지를 만들어 추가합니다.
void Cxxx::AddText(CString &strTextIn, COLORREF &crNewColor, int sSize, LPCSTR lpszFontName)
{
// m_reChat은 채팅 컨트롤
int iTotalTextLength = m_reChat.GetWindowTextLength();
m_reChat.SetSel(iTotalTextLength, iTotalTextLength);
m_reChat.ReplaceSel((LPCTSTR)strTextIn);
int iStartPos = iTotalTextLength;
CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR | CFM_UNDERLINE | CFM_BOLD | CFM_FACE | CFM_SIZE;
cf.dwEffects = (unsigned long)~( CFE_AUTOCOLOR | CFE_UNDERLINE | CFE_BOLD);
cf.crTextColor = crNewColor;//RGB(0, 0, 0);
cf.yHeight = sSize * 20;
strcpy(cf.szFaceName, lpszFontName);
int iEndPos = m_reChat.GetWindowTextLength();
m_reChat.SetSel(iStartPos, iEndPos);
m_reChat.SetSelectionCharFormat(cf);
m_reChat.HideSelection(TRUE, FALSE);
m_reChat.LineScroll(1);
}
댓글목록
등록된 댓글이 없습니다.