如题

解决方案 »

  1.   

    /*-==============================================================
      * 增加命令提示,并将控件中的文字总数取得,以便后来确定只读的区域
      * str为在CommandEdit控件中的提示语句
      * bBold 判断显示的字是否为加粗
      * clr   为新增加的字使用什么颜色
      * =================================================================*/
    void CVSCommandEdit::AddText(CString str,BOOL bBold,COLORREF clr)
    {
    //str = "\n" + str;
    LONG nStart,nEnd; 
        //插入传入的字符串
        this->SetSel(0,-1);
        this->GetSel(nStart,nEnd);
        this->SetSel(nEnd,nEnd + 1);
    this->ReplaceSel(str);
        int nLen        = str.GetLength();
        SetSel(nEnd - 1,nEnd + nLen);    DWORD dwEffects = bBold ? CFE_BOLD : 0;
        CHARFORMAT2 cfm;
        cfm.cbSize      = sizeof(cfm);
        cfm.dwEffects   = CFE_BOLD;
        cfm.crTextColor = clr;
      
        //设置字高
        //  cfm.wWeight     = 22;
        //  cfm.yHeight     = 196;
        //  cfm.dwMask      = bBold ? (CFM_BOLD | CFM_COLOR | CFM_SIZE | CFM_WEIGHT) : CFM_COLOR | CFM_SIZE | CFM_WEIGHT;
        cfm.dwMask      = bBold ? (CFM_BOLD | CFM_COLOR) : CFM_COLOR;
        SetSelectionCharFormat(cfm); this->SetSel(0,-1);
    this->GetSel(this->m_crReadOnlyPos.cpMin,this->m_crReadOnlyPos.cpMax);
    this->m_crReadOnlyPos.cpMax -= 1;
    this->SetSel(this->m_crReadOnlyPos.cpMax + 1,-1);
        this->EnableScrollBar(SB_BOTH,ESB_DISABLE_BOTH);
    }