第1个回答 2014-04-27
void CMyRichEdit::OnSelectfont() { // TODO: Add your command handler code here CHARFORMAT cf; LOGFONT lf; memset(&cf, 0, sizeof(CHARFORMAT)); memset(&lf, 0, sizeof(LOGFONT)); //判断是否选择了内容 BOOL m_bSelect = (GetSelectionType() != SEL_EMPTY) ? TRUE : FALSE; if (m_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 (m_bSelect) SetSelectionCharFormat(cf); //为选定的内容设定所选字体 else SetWordCharFormat(cf); //为将要输入的内容设定字体 } }