【问题标题】:Output formatted text to Screen将格式化文本输出到屏幕
【发布时间】:2013-12-23 09:17:46
【问题描述】:

我有一个存储对的向量。每对包含一个 CString 和一个布尔值。 如果 CString 要加下划线,则 bool 为真,否则为假。

我想将向量中的文本输出到屏幕上,确保文本在正确的位置带有下划线。

到目前为止,我有以下代码:

void CEmergenceView::AppendText( CString msg ) {
   int nBegin;
   CRichEditCtrl &rec = GetRichEditCtrl();
   nBegin = rec.GetTextLength();
   rec.SetSel(nBegin, nBegin);   // Select last character
   rec.ReplaceSel(msg);          // Append, move cursor to end of text
   rec.SetSel(-1,0);             // Remove Black selection bars
   nBegin = rec.GetTextLength(); // Get New Length
   rec.SetSel(nBegin,nBegin);    // Cursor to End of new text
   // Fix annoying "do you want to save your changes?" when program exits
   GetDocument()->SetModifiedFlag(FALSE); // -Optional- (sometimes you want this)
}

int nEnd = 0;

// loop through start of text to end of text
for(int k = 0; k < groups.size(); k++) {
    rEditCtrl.SetSel(nEnd, nEnd);
    rEditCtrl.GetSelectionCharFormat(cf);
    if(groups.at(k).second) {
        if(!cf.dwEffects & !CFE_UNDERLINE) {
            CRichEditView::OnCharUnderline();
        }
    }
    else if(!groups.at(k).second) {
                    if(cf.dwEffects & CFE_UNDERLINE) {
            CRichEditView::OnCharUnderline();
        }
    }    
    AppendText(groups.at(k).first);
    nEnd = nEnd + (groups.at(k).first.GetLength());
}

但是,这根本不是下划线......谁能告诉我我做错了什么?谢谢!

【问题讨论】:

  • 你如何选择带有这个rEditCtrl.SetSel(nEnd, nEnd);的所有文本?您正在选择端到端。
  • 不...它只是将光标放在位置 nEnd。

标签: c++ richedit-control


【解决方案1】:

我认为你应该实现 OnCharUnderline

尝试调用你自己的函数而不是默认函数:

您可以从here获取它:

void CMyRichEditView::OnCharUnderline ()
{
    CHARFORMAT2 cf;
    cf = GetCharFormatSelection();

    if (!(cf.dwMask & CFM_UNDERLINE) || !(cf.dwEffects & CFE_UNDERLINE))
        cf.dwEffects = CFE_UNDERLINE;
    else
        cf.dwEffects = 0;

    cf.dwMask = CFM_UNDERLINE;
    SetCharFormat(cf);
}

【讨论】:

  • 这有什么用?
猜你喜欢
  • 1970-01-01
  • 2017-12-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多