扩展金山提示框,使之带颜色

1.提示过多时,有时需要颜色,便于用户查看。

2.调查发现CBkRichText有对颜色的设置,在此可重用。

    BOOL SetRichText(UINT uItemID, LPCSTR lpszXml)
    {
        T* pT = static_cast<T*>(this);
        CBkWindow *pWnd = pT->FindChildByCmdID(uItemID);

        if (!pWnd)
            return FALSE;

        if (!pWnd->IsClass(CBkRichText::GetClassName()))
            return FALSE;

        TiXmlDocument xmlDoc;

        { // Free stack
            CStringA strXml;
            strXml = L'<';
            strXml += CBkRichText::GetClassName();
            strXml += L'>';
            strXml += lpszXml;
            strXml += L'<';
            strXml += L'/';
            strXml += CBkRichText::GetClassName();
            strXml += L'>';
            xmlDoc.Parse(strXml, NULL, TIXML_ENCODING_UTF8);
        }

        if (xmlDoc.Error())
            return FALSE;

        CBkRichText *pWndRichText = (CBkRichText *)pWnd;
        pWndRichText->LoadChilds(xmlDoc.RootElement());

        pT->_InvalidateControl(pWnd);

        if (pWnd->IsVisible(TRUE))
            pWnd->BkSendMessage(WM_SHOWWINDOW, TRUE);

        return TRUE;
    }
3.对应的xml得用 richtext

        <dlg pos="0,0,-0,-20">
          <icon id="60005" pos="20,20" src="32516" oem="1" size="32"/>
          <richtext id="60006" pos="70,20,-0,-0" />
        </dlg>

4.弹出提示框前对字体做下设置

"<c color='0000ff'>更新成功!</c><br/>\n"

5.细心的朋友会发现,金山的对话框是自适应的,根据字符数确定提示框的宽度,根据行数确定高度,但弱国我们把要提示的内容加上了颜色

,那么计算的字符数势必比原先的大的多,这就会使提示框很难看。于是要把颜色字符给去掉。

CRect CAutoRunMsgBox4::GetTextRect(CString strTxt)
{
	CWindowDC dc(::GetDesktopWindow());
	CRect rcText(0, 0, 1000, 1000);

	const BkStyle& textStyle = BkStyle::GetStyle("msgtext");

	dc.SelectFont(textStyle.m_ftText);

	int nPos1 = strTxt.Find('<');
	if (nPos1!=-1)
	{
		CString strName = strTxt.Left(nPos1);

		int npos2 = strTxt.Find('>');
		strTxt= strTxt.Right(strTxt.GetLength()-npos2-1);
		int nPos3 = strTxt.Find('<');
		strTxt = strTxt.Left(nPos3);
		strTxt = strName+strTxt;
	}

	dc.DrawText(strTxt, strTxt.GetLength(), rcText, textStyle.m_nTextAlign | DT_CALCRECT);

	return rcText;
}

完毕。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值