请问怎么改变RichEditView输入的字体??
我用GetRichEditCtrl().SetDefaultCharFormat(cf);改变其默认字体怎么不行啊?

解决方案 »

  1.   

    我在OnInitialUpdate()中修改了字体如下:
    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);
    输入的字体有所改变(和不加这些代码相比),但是不是"Fixedsys"字体。我在OnTime()中又增加了以下代码:
    void CMyRichEditView::OnTimer(UINT nIDEvent) 
    {
    // TODO: Add your message handler code here and/or call default
    CHARFORMAT &cf = GetCharFormatSelection();
    cf.cbSize = sizeof(CHARFORMAT);
    cf.dwMask = CFM_FACE|CFM_BOLD;
    cf.dwEffects = !CFE_BOLD;
    strcpy(cf.szFaceName, "Fixedsys");
    SetCharFormat(cf);
    CRichEditView::OnTimer(nIDEvent);
    }
    这时候当我选中输入的文字后,被选中文字变成了"Fixedsys"字体。
    真不知道是为什么,这两个地方都设置了相同的字体,为什么输入的时候的字体却不正确呢??
    请高手指点。
      

  2.   

    CFont *tmpFont;
         LOGFONT lf;
         memset( (void *)&lf, 0, sizeof( LOGFONT ) );
         strcpy( lf.lfFaceName, _t("Fixedsys") );     CFont font;
         font.CreateFontIndirect( &lf );
         SetFont( &font );
      

  3.   

    先使用 
    GetRichEditCtrl().SetSel( GetRichEditCtrl().GetTextLength(), -1);
    GetRichEditCtrl().SetSelectionCharFormat(cf);
    试试。
    要不在你的程序中

    #ifdef _DEBUG
       GetRichEditCtrl().GetDefaultCharFormat(cf);
       ASSERT((cf.dwMask&(CFM_FACE|CFM_BOLD)) == 
          (CFM_FACE|CFM_BOLD));
       ASSERT((cf.dwEffects(CFE_FACE|CFE_BOLD)) == !CFE_BOLD);
    #endif