在CRichEditCtrl控件中,打开文件显示的字体跟我输入的字体不一样,该怎么设置字体呢?

lxw_6 2003-10-15 03:48:57
我有一个CRichEditCtrl控件,我在打开一个文件时显示了文件的内容后,我手动输入一些内容,结果我输入的内容跟原来打开文件的内容的字体不一样,也就是说有两种字体在显示,该怎么设置字体呢?
...全文
124 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cxjd 2003-12-29
  • 打赏
  • 举报
回复
up
lxw_6 2003-10-15
  • 打赏
  • 举报
回复
我用了SetFont也不行啊。

谁能给点SetFont的代码??
lxw_6 2003-10-15
  • 打赏
  • 举报
回复
这样也不行啊。

顺便还可以看看这个问题:
http://expert.csdn.net/Expert/topic/2358/2358672.xml?temp=.9338037
FlyYang 2003-10-15
  • 打赏
  • 举报
回复
SetFont可以设置所有的字体
其他效果用SetDefaultCharFormat设置

---------
++C++
---------
zxq80 2003-10-15
  • 打赏
  • 举报
回复
int CRichEditEx::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CRichEditCtrl::OnCreate(lpCreateStruct) == -1)
return -1;

CHARFORMAT cf;
cf.cbSize = sizeof (CHARFORMAT);
cf.dwMask = CFM_FACE | CFM_SIZE;
//cf.dwEffects;
cf.yHeight = 180;
//cf.yOffset;
//cf.crTextColor=RGB(250,0,0);
//cf.bCharSet;
//cf.bPitchAndFamily;
sprintf(cf.szFaceName, "MS Sans Serif");
SetDefaultCharFormat(cf);


return 0;
}

void CRichEditEx::AddText(LPCTSTR szText, COLORREF crText, BOOL bBold)
{
int iTotalTextLength = GetWindowTextLength();
SetSel(iTotalTextLength, iTotalTextLength);
ReplaceSel((LPCTSTR)szText);
int iStartPos = iTotalTextLength;

CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);
cf.dwMask = CFM_COLOR | CFM_BOLD;
cf.dwEffects |= bBold ? CFE_BOLD : cf.dwEffects;
cf.crTextColor = crText;//RGB(0, 0, 0);

int iEndPos = GetWindowTextLength();
SetSel(iStartPos, iEndPos);
SetSelectionCharFormat(cf);
HideSelection(TRUE, FALSE);

}
//--------------------------------------------------------------------
//设置文本靠中心
//--------------------------------------------------------------------
void
CRichEditEx::SetParagraphCenter()
{
PARAFORMAT paraFormat;
paraFormat.cbSize = sizeof(PARAFORMAT);
paraFormat.dwMask = PFM_ALIGNMENT;
paraFormat.wAlignment = PFA_CENTER;

SetParaFormat(paraFormat); // Set the paragraph.
}
//--------------------------------------------------------------------
//设置文本靠左
//--------------------------------------------------------------------
void
CRichEditEx::SetParagraphLeft()
{
PARAFORMAT paraFormat;
paraFormat.cbSize = sizeof(PARAFORMAT);
paraFormat.dwMask = PFM_ALIGNMENT;
paraFormat.wAlignment = PFA_LEFT;

SetParaFormat(paraFormat);

}
//--------------------------------------------------------------------
//设置文本靠右
//--------------------------------------------------------------------
void
CRichEditEx::SetParagraphRight()
{
PARAFORMAT paraFormat;
paraFormat.cbSize = sizeof(PARAFORMAT);
paraFormat.dwMask = PFM_ALIGNMENT;
paraFormat.wAlignment = PFA_RIGHT;

SetParaFormat(paraFormat);

}
//--------------------------------------------------------------------
//设置字体大小
//--------------------------------------------------------------------
void
CRichEditEx::SetFontSize(int nPointSize)
{
CHARFORMAT cf = GetCharFormat();

nPointSize *= 20; // convert from to twips
cf.yHeight = nPointSize;

cf.dwMask = CFM_SIZE;

SetSelectionCharFormat(cf);
}
//--------------------------------------------------------------------
//设置字体名字
//--------------------------------------------------------------------
void
CRichEditEx::SetFontName(CString sFontName)
{
CHARFORMAT cf = GetCharFormat();

// Set the font name.
for (int i = 0; i <= sFontName.GetLength()-1; i++)
cf.szFaceName[i] = sFontName[i];

cf.dwMask = CFM_FACE;

SetSelectionCharFormat(cf);
}
//--------------------------------------------------------------------
//获取当前字符的格式
//--------------------------------------------------------------------
CHARFORMAT
CRichEditEx::GetCharFormat(DWORD dwMask)
{
CHARFORMAT cf;
cf.cbSize = sizeof(CHARFORMAT);

cf.dwMask = dwMask;

GetSelectionCharFormat(cf);

return cf;

}
lxw_6 2003-10-15
  • 打赏
  • 举报
回复
up

16,467

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧