개발은 하는건가..

[MFC] CRichEditCtrl 텍스트 컬러 지정 본문

C, C++, MFC

[MFC] CRichEditCtrl 텍스트 컬러 지정

수동애비 2023. 5. 15. 17:01
반응형

아래의 함수에서  m_edClientLog 는 richEdit 의 컨트롤 변수이다.
 로그 출력용 richEdit 에 1000 라인까지만 출력하도록 하는 기능

void outRichEditText(TCHAR *pwszLog, COLORREF color) {
   
    CPoint point;
    int first_pos = m_edClientLog.LineIndex(m_edClientLog.GetLineCount());

    m_edClientLog.SetSel(first_pos, first_pos);

    point = m_edClientLog.PosFromChar(first_pos);

    m_edClientLog.SetCaretPos(point);

    CHARFORMAT cf;
    memset(&cf, 0, sizeof(CHARFORMAT));
    cf.cbSize = sizeof(CHARFORMAT);
    cf.dwMask = CFM_COLOR;
    cf.crTextColor = color;

    m_edClientLog.SetSelectionCharFormat(cf);
    m_edClientLog.ReplaceSel(pwszLog);

    CRect rcClientLog;
    int pageLineCnt;

    m_edClientLog.GetClientRect(&rcClientLog);
    pageLineCnt = rcClientLog.Height() / 15;

    int nDoLineScroll = m_edClientLog.GetLineCount() - pageLineCnt - m_edClientLog.GetFirstVisibleLine();

    if (nDoLineScroll > 0 && m_chkScrollLock.GetCheck() == 0) {
        m_edClientLog.LineScroll(nDoLineScroll);
    }

    if (m_edClientLog.GetLineCount() > 1000) {
        m_edClientLog.SetRedraw(FALSE);
        m_edClientLog.SetReadOnly(FALSE);

        // 새로 추가된 내용 만큼 삭제 
        m_edClientLog.SetSel(0, (int)wcslen(pwszLog));
        m_edClientLog.Clear();

        // 라인 단위로 삭제하기 위해 첫라인 전체 삭제
        int nFirstLineLen = m_edClientLog.LineLength(0);
        m_edClientLog.SetSel(0, nFirstLineLen + 1);
        m_edClientLog.Clear();

        m_edClientLog.SetReadOnly(TRUE);
        m_edClientLog.SetRedraw(TRUE);
    }
 }

 

 

'C, C++, MFC' 카테고리의 다른 글

간단한 FFT 계산 함수  (0) 2023.08.04
[VC++] 프로그램 중복 실행 방지  (0) 2023.05.23
[WinApi] 조이스틱 사용 방법  (0) 2023.04.26
GPS 위도, 경도 위치 간 거리 계산  (0) 2023.04.06
OpenSSL VC++ 용 빌드하기  (0) 2023.03.27
Comments