继承了 CRichEditView 的单文档程序,view 中默认显示的字体好难看,我该怎么改变它呢?1 一开始就改变默认字体,我该修改哪里?百度找到的方法没有效果:
  
void C****View::OnDraw(CDC* pDC) 
{
// TODO: Add your specialized code here and/or call the base class LOGFONT logFont;
ZeroMemory((void*)&logFont,sizeof(logFont));
lstrcpy(logFont.lfFaceName,_T("Times New Roman"));
logFont.lfHeight = -12;
logFont.lfWeight = 400;
logFont.lfCharSet = SHIFTJIS_CHARSET;
logFont.lfOutPrecision = 3;
logFont.lfClipPrecision = 2; 
logFont.lfQuality = 1;
logFont.lfPitchAndFamily = 2;
m_font.CreateFontIndirect(&logFont); //m_font是成员变量
SetFont(&m_font);

// 设置字体   
/*  CFont*   pFont   =   GetFont();   
  LOGFONT   lf;   
if   (pFont   !=   NULL)   
pFont->GetObject(sizeof(LOGFONT),   &lf);   
else   
::GetObject(GetStockObject(SYSTEM_FONT),   sizeof(LOGFONT),   &lf);   
    
CFontDialog   dlg(&lf,   CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT);   
if   (dlg.DoModal()   ==   IDOK)   
{   
//   switch   to   new   font.   
   m_font.DeleteObject();   
   if   (m_font.CreateFontIndirect(&lf))   
   {   
   CWaitCursor   wait;   
   SetFont(&m_font);   
   }   
   }   
*/

}  2 如果我想动态的改变字体(改变view内的),又该怎么做呢?谢谢了

解决方案 »

  1.   

        void CxxView::OnInitialUpdate() 在这个函数里加入这个,你可以自己改合适的字体,我这用的是fixedsys字体:
          CHARFORMAT   cf/*   =   GetCharFormatSelection()*/;   
    GetRichEditCtrl().GetDefaultCharFormat(cf);   
    cf.cbSize   =   sizeof(CHARFORMAT);   
    cf.dwMask   =   CFM_FACE|CFM_BOLD;   
    cf.dwEffects   =   !CFE_BOLD;   
    strcpy(cf.szFaceName,   "Fixedsys");   
    GetRichEditCtrl().SetDefaultCharFormat(cf); 其他地方如果想要动态改字体
    CHARFORMAT cf;
    GetRichEditCtrl().GetDefaultCharFormat(cf); 
    然后设置cf.cbSize   =   sizeof(CHARFORMAT);   
    cf.dwMask   =   CFM_FACE|CFM_BOLD;   
    cf.dwEffects   =   !CFE_BOLD;   
    strcpy(cf.szFaceName,   "Fixedsys");  
    等cf属性,最后GetRichEditCtrl().SetSelectionCharFormat(cf);、不管用,你来骂我
      

  2.   

    应该用CHARFORMAT2
    例如:
    CHARFORMAT2 cf2; 
    memset(&cf2, 0, sizeof(CHARFORMAT2));
    cf2.cbSize = sizeof(CHARFORMAT2);
    cf2.dwMask = CFM_FACE ;_tcscpy(cf2.szFaceName, _T("Times New Roman"));::SendMessage(m_hWnd, EM_SETCHARFORMAT, 0, (LPARAM)&cf2);
      

  3.   

    谢谢 oktsl 和 xylicon ,够快,呵呵,而且很好用!