多么简单的问题啊,折腾我够呛。
strName += TEXT("\r\n"); CHARFORMAT cf; cf.cbSize = sizeof (CHARFORMAT); cf.dwMask = CFM_COLOR | CFM_UNDERLINE | CFM_BOLD; cf.dwEffects = (unsigned long)~(CFE_AUTOCOLOR | CFE_UNDERLINE | CFE_BOLD); if(is_self) cf.crTextColor = RGB(0x91, 0xe0, 0x2a); else cf.crTextColor = RGB(0x59, 0xb5, 0xff); long start = GetTextLength(); SetSel(start, start); ReplaceSel((LPCTSTR)strName); long end = GetTextLength(); int line = GetLineCount(); SetSel(start - (line-2)*1, end - (line-2)*1); SetSelectionCharFormat(cf); SetSel(-1, -1); HideSelection(TRUE, FALSE); PostMessage(WM_VSCROLL, SB_BOTTOM, 0);update @ 2010.03.25 精益求精,上面的代码有隐患,应该用下面更安全、简洁的处理方法:
CHARFORMAT cf; cf.cbSize = sizeof (CHARFORMAT); cf.dwMask = CFM_COLOR | CFM_UNDERLINE | CFM_BOLD; cf.dwEffects = (unsigned long)~(CFE_AUTOCOLOR | CFE_UNDERLINE | CFE_BOLD); cf.crTextColor = is_me?RGB(0x91, 0xe0, 0x2a):RGB(0x59, 0xb5, 0xff); SetSel(-1, -1); SetSelectionCharFormat(cf); ReplaceSel((LPCTSTR)strName); SetSel(-1, -1); ReplaceSel((LPCTSTR)"\n"); PostMessage(WM_VSCROLL, SB_BOTTOM, 0);
没有评论 :
发表评论