First, the definition of font Charformat CF;
ZeroMemory (& CF, sizeof (Charformat));
Cf1.dwmask = Cfm_bold | Cfm_color | Cfm_face | Cfm_italic | Cfm_size | Cfm_underline;
Cf1.dweffects = Cfe_bold; Bold (or other cfe_italic,cfe_strikeout, cfe_underline)
Cf1.yheight = 18 * 18; Text height
Cf1.crtextcolor = RGB (0, 0, 255); Text color--------Blue
strcpy (Cf1.szfacename, _t ("Fixedsys")); Font
The variables that are assumed to be associated with a RichEdit control are M_strrich and M_ctrlrich. The following is the set full text default font: M_ctrlrich.setsel (-1,-1);
M_ctrlrich.replacesel (M_strrich);
M_ctrlrich.setsel (0,-1);
M_ctrlrich.setselectioncharformat (CF);
Third, suppose to set the range of special fonts is the M_strrich of the first to the J-character M_ctrlrich.setsel (I, j);
M_ctrlrich.setselectioncharformat (Cf_blue);
If you want the characters between all Tag1 and Tag2 in M_strrich to set a special font (TAG1 to CString) Findtextex A, B;
a.chrg.cpmin = b.chrg.cpmin = 0;
A.chrg.cpmax = B.chrg.cpmax =-1;
A.lpstrtext = Tag1. GetBuffer (0); Tag1. ReleaseBuffer ();
B.lpstrtext = Tag2. GetBuffer (0); Tag2. ReleaseBuffer ();
M_ctrlrich.findtext (0, & a);
M_ctrlrich.findtext (0, & B);
while (A.chrgtext.cpmax >-1 && b.chrgtext.cpmin > A.chrgtext.cpmax)
... {
M_ctrlrich.setsel (A.chrgtext.cpmax, b.chrgtext.cpmin-1);
M_ctrlrich.setselectioncharformat (CF);
A.chrg.cpmin = B.chrgtext.cpmax;
B.chrg.cpmin = B.chrgtext.cpmax;
M_ctrlrich.findtext (0, &a);
M_ctrlrich.findtext (0, &b);
}
Note: The above is a more complex way to find Tag1, because the position returned is inaccurate when M_strrich.find (TAG1) is positioned tag1, especially when the M_strrich contains special characters such as alpha, beta, φ, which offsets the range of the markup.