我想根据自己的需要,让ClistBox每行的输出都不同颜色,我是这样做的:先创建一个MyListBox类:
  class MyListBox : public CListBox然后重载DrawItem()方法:
  void MyListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
{
// TODO: Add your message handler code here
ASSERT(lpDrawItemStruct->CtlType == ODT_LISTBOX);
LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;
ASSERT(lpszText != NULL);
COLORREF clr=GetItemData(lpDrawItemStruct->itemID);//itemID 是当前绘制那行的索引 CDC dc; dc.Attach(lpDrawItemStruct->hDC); dc.SetTextColor(clr);
dc.DrawText(
lpszText,
strlen(lpszText),
&lpDrawItemStruct->rcItem,
DT_CENTER|DT_SINGLELINE|DT_VCENTER);
dc.Detach();
}然后添加了一MyListBox类型的控键变量m_myList,接着这样调用:
void CTaskDlg::OnButtonPrint() 
{
// TODO: Add your control notification handler code here
CString str1("aaa"),str2("bbb");
COLORREF clr1=0x000000ff,clr2=0x00ff0000;
int nIndex;
nIndex=m_myList.AddString(str1);
m_myList.SetItemData(nIndex,clr1);
nIndex=m_myList.AddString(str2);
m_myList.SetItemData(nIndex,clr2);}但是为什么不出效果呀~按了按钮之后,只显示两行"aaa"和"bbb",但颜色并没有改变??本人学VC,没多久,请讲得详细点~
谢谢!!!!!!!!!!!!!!