列表类设置背景图片(VC+MFC)

在重载的类里添加消息响应函数
HBRUSH CBitmapListBox::CtlColor(CDC* pDC, UINT nCtlColor)
{
CBrush m_brHollow;
m_brHollow.CreateStockObject(HOLLOW_BRUSH);
pDC->SetBkMode(TRANSPARENT);
pDC->SetTextColor(RGB(64,32,0));//设置文字颜色;
return m_brHollow;
}

CBitmapListBox为重载的类
BOOLCBitmapListBox::OnEraseBkgnd(CDC* pDC)
{
CDC dc;
dc.CreateCompatibleDC(pDC);
dc.SelectObject(&m_bitmap);
BITMAP map;
m_bitmap.GetBitmap(&map);

CRect rect;
GetClientRect(&rect);
pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,map.bmWidth,
map.bmHeight,SRCCOPY);
ReleaseDC(&dc);
return true;
//return CListBox::OnEraseBkgnd(pDC);
}

还要在类里重载OnSelchange和OnVScroll消息

在2个函数里添加Invalidate();

你可能感兴趣的:(mfc,vc++)