用CFontDialog设置richEdit内容的字体和颜色 及其他
2013-10-24 11:04
295 查看
一:用CFontDialog设置richEdit内容的字体和颜色
CHARFORMAT cf;
memset(&cf,0,sizeof(CHARFORMAT));
CFontDialog dlg;
if (IDOK == dlg.DoModal())
{
dlg.GetCharFormat(cf);
m_ctrWordMake.SetDefaultCharFormat(cf);
UpdateData(FALSE);
memset(&cf,0,sizeof(CHARFORMAT));
CFontDialog dlg;
if (IDOK == dlg.DoModal())
{
dlg.GetCharFormat(cf);
m_ctrWordMake.SetDefaultCharFormat(cf);
UpdateData(FALSE);
Invalidate(TRUE);
}
附加:获取CHARFORMAT cf中相应的值
CHARFORMAT cf;
LOGFONT lf;
memset(&cf, 0, sizeof(CHARFORMAT));
memset(&lf, 0, sizeof(LOGFONT));
//判断是否选择了内容
BOOL bSelect = (GetSelectionType() != SEL_EMPTY) ? TRUE : FALSE;
if (bSelect)
{
GetSelectionCharFormat(cf);
}
else
{
GetDefaultCharFormat(cf);
}
//得到相关字体属性
BOOL bIsBold = cf.dwEffects & CFE_BOLD;
BOOL bIsItalic = cf.dwEffects & CFE_ITALIC;
BOOL bIsUnderline = cf.dwEffects & CFE_UNDERLINE;
BOOL bIsStrickout = cf.dwEffects & CFE_STRIKEOUT;
//设置属性
lf.lfCharSet = cf.bCharSet;
lf.lfHeight = cf.yHeight/15;
lf.lfPitchAndFamily = cf.bPitchAndFamily;
lf.lfItalic = bIsItalic;
lf.lfWeight = (bIsBold ? FW_BOLD : FW_NORMAL);
lf.lfUnderline = bIsUnderline;
lf.lfStrikeOut = bIsStrickout;
sprintf(lf.lfFaceName, cf.szFaceName);
CFontDialog dlg(&lf);
dlg.m_cf.rgbColors = cf.crTextColor;
if (dlg.DoModal() == IDOK)
{
dlg.GetCharFormat(cf);//获得所选字体的属性
if (bSelect)
SetSelectionCharFormat(cf); //为选定的内容设定所选字体
else
SetWordCharFormat(cf); //为将要输入的内容设定字体
// SetDefaultCharFormat(cf);
}
二.其他
1.字体大小
LOGFONT lf;
CFontDialog dlg(&lf);
if (IDOK == dlg.DoModal())
{
static CFont font;
dlg.GetCurrentFont(&lf);
font.DeleteObject();
font.CreateFontIndirect(&lf);
GetDlgItem(IDC_RICHEDIT_WORD)->SetFont(&font);
COLORREF m_FontColor=dlg.GetColor();
CDC *pDC=GetDlgItem(IDC_RICHEDIT_WORD)->GetDC();
pDC->SetTextColor(m_FontColor);
UpdateData(FALSE);
GetDlgItem(IDC_RICHEDIT_WORD)->Invalidate();
}
2.字体大小
CFont m_Font;
CRichEditCtrl* pEdt=(CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT_WORD);
CFont *TempFont=pEdt->GetFont();
// LOGFONT LogFont;
// TempFont->GetLogFont(&LogFont);
CFontDialog cfd;
if(cfd.DoModal()==IDOK)
{
m_Font.Detach();
LOGFONT temp;
cfd.GetCurrentFont(&temp);
m_Font.CreateFontIndirect(&temp);
pEdt->SetFont (&m_Font);
DEMOINPUTCOLOR = cfd.GetColor();
UpdateData(FALSE);
// m_ctrWordMake.Invalidate();
// m_ctrWordMake.UpdateWindow();
GetDlgItem(IDC_RICHEDIT_WORD)->Invalidate();
GetDlgItem(IDC_RICHEDIT_WORD)->UpdateWindow();
}
三.参考网址
http://blog.chinaunix.net/uid-7667983-id-2046556.html http://blog.sina.com.cn/s/blog_7d1dc9de01011gdh.html
charformat的解析 http://huigezrx.blog.163.com/blog/static/32101652201022055236155/
修改字体大小及颜色 http://hi.baidu.com/sports98/item/f1e3ee15060b9a731109b56d
CHARFORMAT cf;
memset(&cf,0,sizeof(CHARFORMAT));
CFontDialog dlg;
if (IDOK == dlg.DoModal())
{
dlg.GetCharFormat(cf);
m_ctrWordMake.SetDefaultCharFormat(cf);
UpdateData(FALSE);
memset(&cf,0,sizeof(CHARFORMAT));
CFontDialog dlg;
if (IDOK == dlg.DoModal())
{
dlg.GetCharFormat(cf);
m_ctrWordMake.SetDefaultCharFormat(cf);
UpdateData(FALSE);
Invalidate(TRUE);
}
附加:获取CHARFORMAT cf中相应的值
CHARFORMAT cf;
LOGFONT lf;
memset(&cf, 0, sizeof(CHARFORMAT));
memset(&lf, 0, sizeof(LOGFONT));
//判断是否选择了内容
BOOL bSelect = (GetSelectionType() != SEL_EMPTY) ? TRUE : FALSE;
if (bSelect)
{
GetSelectionCharFormat(cf);
}
else
{
GetDefaultCharFormat(cf);
}
//得到相关字体属性
BOOL bIsBold = cf.dwEffects & CFE_BOLD;
BOOL bIsItalic = cf.dwEffects & CFE_ITALIC;
BOOL bIsUnderline = cf.dwEffects & CFE_UNDERLINE;
BOOL bIsStrickout = cf.dwEffects & CFE_STRIKEOUT;
//设置属性
lf.lfCharSet = cf.bCharSet;
lf.lfHeight = cf.yHeight/15;
lf.lfPitchAndFamily = cf.bPitchAndFamily;
lf.lfItalic = bIsItalic;
lf.lfWeight = (bIsBold ? FW_BOLD : FW_NORMAL);
lf.lfUnderline = bIsUnderline;
lf.lfStrikeOut = bIsStrickout;
sprintf(lf.lfFaceName, cf.szFaceName);
CFontDialog dlg(&lf);
dlg.m_cf.rgbColors = cf.crTextColor;
if (dlg.DoModal() == IDOK)
{
dlg.GetCharFormat(cf);//获得所选字体的属性
if (bSelect)
SetSelectionCharFormat(cf); //为选定的内容设定所选字体
else
SetWordCharFormat(cf); //为将要输入的内容设定字体
// SetDefaultCharFormat(cf);
}
二.其他
1.字体大小
LOGFONT lf;
CFontDialog dlg(&lf);
if (IDOK == dlg.DoModal())
{
static CFont font;
dlg.GetCurrentFont(&lf);
font.DeleteObject();
font.CreateFontIndirect(&lf);
GetDlgItem(IDC_RICHEDIT_WORD)->SetFont(&font);
COLORREF m_FontColor=dlg.GetColor();
CDC *pDC=GetDlgItem(IDC_RICHEDIT_WORD)->GetDC();
pDC->SetTextColor(m_FontColor);
UpdateData(FALSE);
GetDlgItem(IDC_RICHEDIT_WORD)->Invalidate();
}
2.字体大小
CFont m_Font;
CRichEditCtrl* pEdt=(CRichEditCtrl*)GetDlgItem(IDC_RICHEDIT_WORD);
CFont *TempFont=pEdt->GetFont();
// LOGFONT LogFont;
// TempFont->GetLogFont(&LogFont);
CFontDialog cfd;
if(cfd.DoModal()==IDOK)
{
m_Font.Detach();
LOGFONT temp;
cfd.GetCurrentFont(&temp);
m_Font.CreateFontIndirect(&temp);
pEdt->SetFont (&m_Font);
DEMOINPUTCOLOR = cfd.GetColor();
UpdateData(FALSE);
// m_ctrWordMake.Invalidate();
// m_ctrWordMake.UpdateWindow();
GetDlgItem(IDC_RICHEDIT_WORD)->Invalidate();
GetDlgItem(IDC_RICHEDIT_WORD)->UpdateWindow();
}
三.参考网址
http://blog.chinaunix.net/uid-7667983-id-2046556.html http://blog.sina.com.cn/s/blog_7d1dc9de01011gdh.html
charformat的解析 http://huigezrx.blog.163.com/blog/static/32101652201022055236155/
修改字体大小及颜色 http://hi.baidu.com/sports98/item/f1e3ee15060b9a731109b56d
相关文章推荐
- 3、excel 导出。适合用于将界面上的内容所见及所得的输出,可以设置单元格的的合并,大小,字体,颜色等等
- 使用CFontDialog修改Richedit的字体
- 一个控件(View或者是其他控件)设置不同的字体颜色
- TextView内容设置显示不同的字体颜色和不同的字体大小
- Android 部分内容设置颜色、字体、超链接、图片
- #java#设置textfield或其他组件字体的颜色
- Android TextView内容设置超链接、颜色、字体
- CRichedit在结尾添加一行,同时设置字体,大小及颜色,并在添加后自动滚屏到末行,
- android TextView、EditText对部分内容设置颜色、字体、超链接、图片
- TextView内容设置显示不同的字体颜色和不同的字体大小
- android TextView 结合SpannableString对部分内容设置颜色、字体、超链接、图片
- android TextView、EditText对部分内容设置颜色、字体、超链接、图片
- MFC RICHEDIT设置等宽字体
- richedit 设置某一行颜色
- 【工作笔记】android TextView、EditText对部分内容设置颜色、字体、超链接、图片
- cxGrid 设置斑马线 根据记录内容更改字体颜色
- android TextView、EditText对部分内容设置颜色、字体、超链接、图片
- Textview部分内容设置颜色、字体、超链接、图片
- Android-PickerView 三级联动选择器的标题和内容的字体大小、颜色设置
- 在html中向table中动态添加内容,并设置cell字体颜色