MFC:在 CRichEditCtrl 中突出显示一条线一段时间,然后恢复

MFC: Highlight a line in CRichEditCtrl for some duration and revert back

本文关键字:一条 一段时间 恢复 然后 显示 CRichEditCtrl MFC      更新时间:2023-10-16

我对MFC很陌生,C++编程,请帮助我解决这个问题。在编辑框(使用 CRichEditCtrl 创建)中,有几行。我需要突出显示一行(红色)一段时间(例如:突出显示第 1 行 1 秒,然后恢复线条颜色)。

我该怎么做?提前致谢

首先像这样设置你的设置

'

// Select your string (start is the index in characters (not in lines)
GetRichEditCtrl().SetSel( nStart, nStart + nLength);
// Get the CHARFORMAT structure ready
CHARFORMAT cf;
cf.cbSize       = sizeof (cf);
cf.dwEffects    = 0;
cf.dwMask       = CFM_COLOR;
cf.crTextColor = RGB(255,0,0);
GetRichEditCtrl().SetSelectionCharFormat(cf);

'

然后创建一个像SetTimer(WMT_MYTIMER,1000,NULL)一样的计时器,覆盖OnTimer,用KillTimer停止计时器并重置颜色,如上所示

希望这有帮助!