1. Add the Code related to RichEdit initialization to initinstance ().
Afxinitrichedit ();
M_hrichedit = loadlibrary ("richedw.dll ");
(The hmodule m_hrichedit is defined in the corresponding header file)
2. Set the text display style in RichEdit
Charformat CF;
Zeromemory (& CF, sizeof (charformat ));
Cf. cbsize = sizeof (charformat );
Cf. dwmask = cfm_bold | cfm_color | cfm_face |
Cfm_italic | cfm_size | cfm_underline;
Cf. dweffects = cfe_underline;
Cf. yheight = 12*12; // text height
Cf. crtextcolor = RGB (200,100,255); // text color
Strcpy (Cf. szfacename, _ T (""); // set the font
M_ctrlmyrichedit.setdefacharcharformat (CF );
(Cricheditctrl m_ctrlmyrichedit; defined in the header file of the corresponding dialog box,
And this variable is associated with a RichEdit control in the dialog box)
3. display text
Cstring strtext = "Hello, world! /R/nby Colin ";
M_ctrlmyrichedit.setwindowtext (strtext );
(/R/n indicates line feed. Of course, the premise of line feed is that the multiline option of the RichEdit control has been selected)
4. release resources related to RichEdit in exitinstance ()
Freelibrary (m_hrichedit );