0

I have a vector that stores pairs. Each pair contains a CString and a bool. If the CString is meant to be underlined then bool is true, else it is false.

I want to output the text in the vector to the screen making sure that text is underlined in the correct places.

So far I have the following code:

void CEmergenceView::AppendText( CString msg ) {
   int nBegin;
   CRichEditCtrl &rec = GetRichEditCtrl();
   nBegin = rec.GetTextLength();
   rec.SetSel(nBegin, nBegin);   // Select last character
   rec.ReplaceSel(msg);          // Append, move cursor to end of text
   rec.SetSel(-1,0);             // Remove Black selection bars
   nBegin = rec.GetTextLength(); // Get New Length
   rec.SetSel(nBegin,nBegin);    // Cursor to End of new text
   // Fix annoying "do you want to save your changes?" when program exits
   GetDocument()->SetModifiedFlag(FALSE); // -Optional- (sometimes you want this)
}

int nEnd = 0;

// loop through start of text to end of text
for(int k = 0; k < groups.size(); k++) {
    rEditCtrl.SetSel(nEnd, nEnd);
    rEditCtrl.GetSelectionCharFormat(cf);
    if(groups.at(k).second) {
        if(!cf.dwEffects & !CFE_UNDERLINE) {
            CRichEditView::OnCharUnderline();
        }
    }
    else if(!groups.at(k).second) {
                    if(cf.dwEffects & CFE_UNDERLINE) {
            CRichEditView::OnCharUnderline();
        }
    }    
    AppendText(groups.at(k).first);
    nEnd = nEnd + (groups.at(k).first.GetLength());
}

However, this is not underlining at all....Can anyone tell me what I'm doing wrong?? Thanks!

user3126297
  • 159
  • 2
  • 3
  • 10

1 Answers1

0

I think you should implement the OnCharUnderline

Try to call yours own function instead of the default one:

You can get it from here:

void CMyRichEditView::OnCharUnderline ()
{
    CHARFORMAT2 cf;
    cf = GetCharFormatSelection();

    if (!(cf.dwMask & CFM_UNDERLINE) || !(cf.dwEffects & CFE_UNDERLINE))
        cf.dwEffects = CFE_UNDERLINE;
    else
        cf.dwEffects = 0;

    cf.dwMask = CFM_UNDERLINE;
    SetCharFormat(cf);
}
SHR
  • 7,940
  • 9
  • 38
  • 57