To set font formatting in RichEdit controls __VC tips

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.