![]() |
#2
rjsp2018-09-14 15:12
|
注:用户要求,新的提示消息需要在底部显示,所以不能用倒序显示来解决该问题;
网上搜过,但没看懂,感觉不好操作,望各位能指导详细点的解决办法,附带简单讲解,万分感谢!
/*问题已解决,图片已删除,因涉及商业性的东西,不便一直展示,故请谅解,上面文字有详细的问题描述*/
该控件我目前放置在一个Dialog中,对话框及控件的消息处理函数如下:

void CDlgAlarm::OnLbnSelchangeListAlarm()
{
// TODO: 在此添加控件通知处理程序代码
}
HBRUSH CDlgAlarm::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: 在此更改 DC 的任何属性
if (pWnd->GetDlgCtrlID() == IDC_LIST_Alarm)
{
pDC-> SetBkColor(WHITE); //字体背景色
pDC->SetBkMode(TRANSPARENT);//设置背景透明
/*return ::CreateSolidBrush(RGB(255, 12,12));*/
hbr = (HBRUSH)m_brush;
}
// TODO: 如果默认的不是所需画笔,则返回另一个画笔
return hbr;
}
BOOL CDlgAlarm::OnInitDialog()
{
CDialog::OnInitDialog();
m_ListBoxContent.SetTextColor(BLACK);
// TODO: 在此添加额外的初始化
m_brush.CreateSolidBrush(WHITE);
return TRUE; // return TRUE unless you set the focus to a control
// 异常: OCX 属性页应返回 FALSE
}
在对该控件增加信息的时候,我调用的函数如下:

void CColorListBox::AddItem(COLORREF cr,CString str)
{
Item *it = new Item;
it->cr = cr;
strcpy( it->str , (LPSTR)(LPCTSTR)str );
m_colorList.push_back( it );
int index=AddString(CString(" "));
SetItemData( index, (DWORD)it );
SetItemHeight(index,m_height);
}
调用函数案例如下:
str.Format("%4d-%2d-%2d %02d:%02d:%02d %s:自动闭塞双接故障恢复!",t.GetYear(),t.GetMonth(),t.GetDay(),t.GetHour(),t.GetMinute(),t.GetSecond(),xhd->m_strName);
alarmDlg->m_ListBoxContent.AddItem(WHITE,str);
[此贴子已经被作者于2018-9-14 15:33编辑过]