Frage

Say I have a very basic text editor, like the one described here:

http://aclacl.brinkster.net/MFC/ch12e.htm

This text editor is able to create, save, and open a file that contains the following formatted text:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Now imagine that the text in italics is UNDERLINED as well.

Is there a way to get each instance of underlined text in the above passage as Strings?

Also, is there a method available to get any text that is currently selected as a String?

War es hilfreich?

Lösung

Just, I would like to show you a clue between several methods.

CHARFORMAT cf;
CString text;
GetDlgItemText(IDC_RICHEDIT21, text);

//loop for all text in rich edit control
for(int i = 0; i < text.GetLength(); i++)
{
    m_rich->SetSel(0 + i, i + 1); //from start to end character
    m_rich->GetSelectionCharFormat(cf);

    if(cf.dwEffects & CFE_UNDERLINE) //check whether underline character
    {
        //get underline character using GetSelText() etc.
    }
}

However, this code does not concern any aspect of performance, so if there are many string and underlined characters in rich edit control, you have to check execute time, etc. Also, I think xMRi's reply is basic and correct method.

I would like to recommend below articles, also.

how to print data in tabular format in rich edit control

How to get text with RTF format from Rich Edit Win API?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top