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;
}
完毕。