分割窗口里面的CListBox重绘就不显示.在线等
重绘的代码:
void CTabList::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
//设置颜色
COLORREF crOldTextColor = dc.GetTextColor();
COLORREF crOldBkColor = dc.GetBkColor();
COLORREF crTest = RGB(255,200,10) ; //测试用
COLORREF m_clrCenter = RGB(100,50,10) ; //渐变色用 中间的颜色
COLORREF m_clrEnds = RGB(255,200,10) ; //渐变色用 2边的颜色
CRect rcItem = lpDrawItemStruct->rcItem; //下面的函数要用到,必须写.不然没有默认值;
rcItem.DeflateRect(1, 1);
//----------------------------------------------
// If this item is selected, set the background color
// and the text color to appropriate values. Also, erase
// rect by filling it with the background color.
if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&
(lpDrawItemStruct->itemState & ODS_SELECTED))
{
dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
//设置背景色 并添充
dc.SetBkColor(crTest);
dc.FillSolidRect(&lpDrawItemStruct->rcItem,
crTest);
}
else
{
dc.FillSolidRect(&lpDrawItemStruct->rcItem, crOldBkColor);
////设置渐变色分隔线 自定义下划线函数
DrawCurvLine(&dc,
CPoint(rcItem.left + 6, rcItem.bottom),
CPoint(rcItem.right - 6, rcItem.bottom),
m_clrCenter,
m_clrEnds);
}
//If this item has the focus, draw a red frame around the
//item's rect.
if ((lpDrawItemStruct->itemAction | ODA_FOCUS) &&
(lpDrawItemStruct->itemState & ODS_FOCUS))
{
CBrush br(RGB(100, 100, 150));
//设置选中的边框颜色
dc.FrameRect(&lpDrawItemStruct->rcItem, &br);
}
//----------------------------------------------
//显示图标
CImageList m_image;
m_image.Create(16, //Create(宽,高
15,
TRUE,
20, // number of initial images
20);
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAP1);
m_image.Add( &bmp, RGB(255,255,255));
bmp.DeleteObject();
CPoint Pt(lpDrawItemStruct->rcItem.left+20 , lpDrawItemStruct->rcItem.top+8 );
m_image.Draw(&dc,0, Pt ,ILD_NORMAL);
//----------------------------------------------
//输出文本
GetText(lpDrawItemStruct->itemID, strText); //这样得到Text
dc.DrawText(
strText,
wcslen(strText),
&lpDrawItemStruct->rcItem,
DT_SINGLELINE|DT_VCENTER |DT_CENTER); //DT_CENTER居中
//----------------------------------------------
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(crOldBkColor);
dc.Detach();
}
//----------------
调用的代码:
void CLeftView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
DWORD dwStyle = WS_CHILD | WS_VISIBLE | LBS_OWNERDRAWVARIABLE |
LBS_NOTIFY | LBS_HASSTRINGS;
m_TabList.Create(dwStyle,CRect(10,10,200,200), this, ID_TABLIST);
m_TabList.AddString( _T("ok1 ") );
m_TabList.AddString( _T("ok2 ") );
m_TabList.AddString( _T("气水 ") );
}
只要在建创的时候选择重绘风格LBS_OWNERDRAWVARIABLE 列表就不显示.为空白.为什么在线等.