A quick test application, and I was able to change these colors, however it requires special attention to make it work the way you expect.
First, you may have to modify your dialog resource to identify the control as the old RICHEDIT. In visual studio 2010, the .rc file generated in my dialog box had a control specified as "RichEditCtrl20A
, and when the control was identified as such, I could not make significant changes to the highlight color. Changing the control type to "RICHEDIT"
allowed me to make changes to the color of the selection without noticing a loss of functionality.You need to change the .rc file in a text editor, find an instance of the RichEdit control and make changes.
After that, you can change the color of the selection (in fact, significantly more selection attributes) using the CRichEditCtrl::SetSelectionCharFormat
.
The simple test I did was to create a new Dialog-based MFC application, add a rich editing control to it, modify the RC file as described above, and add the following OnOK () handler:
void CTestMFCDlg::OnBnClickedOk() { m_rec.SetWindowText("This is a test of stuff"); m_rec.SetFocus(); CHARRANGE cr; cr.cpMin = 0; cr.cpMax = 16; m_rec.SetSel(cr); CHARFORMAT2A cf; m_rec.GetSelectionCharFormat(cf); cf.dwEffects = 0; cf.dwMask = CFM_BACKCOLOR | CFM_COLOR | CFM_FACE; cf.crBackColor = 0; cf.crTextColor = RGB(15, 15, 255); strcpy(cf.szFaceName, "Times New Roman"); m_rec.SetSelectionCharFormat(cf); }
Once this handler was in place, clicking the "OK" button in the dialog box would fill in the advanced editing control, select the first 17 characters and change the highlight color.
You can find the documentation for this feature on MSDN:
source share