想实现一个类似QQ聊天窗口的程序,就是我输入一行文字“123”,然后可以在显示框里显示出
Memory_Off(1111111) 11:23:30
123
并且 Memory_Off(1111111) 11:23:30 这一行的颜色(红色)和123这一行的颜色(蓝色)不一样。在网上找了个代码,他的代码的确是可以做到。然后原封不动的移植到我的程序里就不行了,123中1是红色,23是蓝色。最后发现他用的是richedit控件
而我用的是richedit2.0控件 但想不明白的是为什么2.0控件就不行下面是他的代码
void CMyRichEditCtrl::SetTitle(CString &strTitle, COLORREF &title_color)
{
// 写信息头 在 RichEdit 里面
int ititleLength = GetWindowTextLength();
SetSel(ititleLength, ititleLength);
ReplaceSel((LPCTSTR)strTitle);
int iStartPos = ititleLength; // 格式化 信息头
CHARFORMAT cf;
cf.cbSize = sizeof (CHARFORMAT);
cf.dwMask = CFM_COLOR;
cf.dwEffects = (unsigned long)~(CFE_AUTOCOLOR);
cf.crTextColor = title_color; //RGB=(0,128,0); // The last ititleLength is The iStartPos
// After Replace the strTitle, ReCall GetWindowTextLength()
//and the return value is iEndPos..
int iEndPos = GetWindowTextLength();
SetSel(iStartPos, iEndPos);
SetSelectionCharFormat(cf);
HideSelection(TRUE, FALSE);
LineScroll(1);
}void CMyRichEditCtrl::SetMainInfo(CString &maininfo, COLORREF infocolor, LOGFONT info_lf)
{
int ititleLength = GetWindowTextLength();
SetSel(ititleLength, ititleLength);
ReplaceSel((LPCTSTR)maininfo);
int iStartPos = ititleLength; // 格式化 主信息
CHARFORMAT cf;
cf.cbSize = sizeof (CHARFORMAT);
cf.dwMask = CFM_COLOR | CFM_UNDERLINE | CFM_BOLD | CFM_FACE | CFM_CHARSET | CFM_SIZE | CFM_STRIKEOUT | CFM_ITALIC;
cf.dwEffects = (unsigned long)~(CFE_AUTOCOLOR | CFE_BOLD | CFE_ITALIC | CFE_STRIKEOUT | CFE_UNDERLINE );
cf.dwEffects |= info_lf.lfUnderline ? CFE_UNDERLINE : cf.dwEffects ;
cf.dwEffects |= info_lf.lfWeight==FW_BOLD ? CFE_BOLD : cf.dwEffects ;
cf.dwEffects |= info_lf.lfItalic ? CFE_ITALIC : cf.dwEffects ;
cf.dwEffects |= info_lf.lfStrikeOut ? CFE_STRIKEOUT : cf.dwEffects ;
cf.yHeight=-info_lf.lfHeight*15;
cf.crTextColor = infocolor; //RGB=(0,128,0);
sprintf(cf.szFaceName, info_lf.lfFaceName);
// The last ititleLength is The iStartPos
// After Replace the strTitle, ReCall GetWindowTextLength()
//and the return value is iEndPos..
int iEndPos = GetWindowTextLength();
SetSel(iStartPos, iEndPos);
SetSelectionCharFormat(cf);
HideSelection(TRUE, FALSE);
LineScroll(1);
}
Memory_Off(1111111) 11:23:30
123
并且 Memory_Off(1111111) 11:23:30 这一行的颜色(红色)和123这一行的颜色(蓝色)不一样。在网上找了个代码,他的代码的确是可以做到。然后原封不动的移植到我的程序里就不行了,123中1是红色,23是蓝色。最后发现他用的是richedit控件
而我用的是richedit2.0控件 但想不明白的是为什么2.0控件就不行下面是他的代码
void CMyRichEditCtrl::SetTitle(CString &strTitle, COLORREF &title_color)
{
// 写信息头 在 RichEdit 里面
int ititleLength = GetWindowTextLength();
SetSel(ititleLength, ititleLength);
ReplaceSel((LPCTSTR)strTitle);
int iStartPos = ititleLength; // 格式化 信息头
CHARFORMAT cf;
cf.cbSize = sizeof (CHARFORMAT);
cf.dwMask = CFM_COLOR;
cf.dwEffects = (unsigned long)~(CFE_AUTOCOLOR);
cf.crTextColor = title_color; //RGB=(0,128,0); // The last ititleLength is The iStartPos
// After Replace the strTitle, ReCall GetWindowTextLength()
//and the return value is iEndPos..
int iEndPos = GetWindowTextLength();
SetSel(iStartPos, iEndPos);
SetSelectionCharFormat(cf);
HideSelection(TRUE, FALSE);
LineScroll(1);
}void CMyRichEditCtrl::SetMainInfo(CString &maininfo, COLORREF infocolor, LOGFONT info_lf)
{
int ititleLength = GetWindowTextLength();
SetSel(ititleLength, ititleLength);
ReplaceSel((LPCTSTR)maininfo);
int iStartPos = ititleLength; // 格式化 主信息
CHARFORMAT cf;
cf.cbSize = sizeof (CHARFORMAT);
cf.dwMask = CFM_COLOR | CFM_UNDERLINE | CFM_BOLD | CFM_FACE | CFM_CHARSET | CFM_SIZE | CFM_STRIKEOUT | CFM_ITALIC;
cf.dwEffects = (unsigned long)~(CFE_AUTOCOLOR | CFE_BOLD | CFE_ITALIC | CFE_STRIKEOUT | CFE_UNDERLINE );
cf.dwEffects |= info_lf.lfUnderline ? CFE_UNDERLINE : cf.dwEffects ;
cf.dwEffects |= info_lf.lfWeight==FW_BOLD ? CFE_BOLD : cf.dwEffects ;
cf.dwEffects |= info_lf.lfItalic ? CFE_ITALIC : cf.dwEffects ;
cf.dwEffects |= info_lf.lfStrikeOut ? CFE_STRIKEOUT : cf.dwEffects ;
cf.yHeight=-info_lf.lfHeight*15;
cf.crTextColor = infocolor; //RGB=(0,128,0);
sprintf(cf.szFaceName, info_lf.lfFaceName);
// The last ititleLength is The iStartPos
// After Replace the strTitle, ReCall GetWindowTextLength()
//and the return value is iEndPos..
int iEndPos = GetWindowTextLength();
SetSel(iStartPos, iEndPos);
SetSelectionCharFormat(cf);
HideSelection(TRUE, FALSE);
LineScroll(1);
}
解决方案 »
- MFC数据类型转化时出现的问题...
- 请问:如何在VC中让编辑框edit把输入的内容象Word中那样自动换行啊?
- sdk保存文件名问题请教?
- 关于在htmlview的模式变为可编辑后,如何把table上的那个该死的可移动的方框给除掉
- 我是一个编程初学者我想问一下现在学什么编程语言最好,又好学又有发展前景?????
- 指针问题
- COM对多线程的支持是怎么样的?
- OFFICE XP以及金山词霸的漂亮菜单如何实现的??有源代码可以参考吗??
- 判断一个控件是否被按下并弹起
- 如果在程序中做100次加法,怎样计算这100次加法共花的时间?
- wince下窗口移动问题
- 如何获得scintilla控件中的变量列表
---
没用什么控制呀 就是在界面上放一个cricheditctrl