VC-mfc-如何在列表框中显示位图?
HBRUSHCNewDlg::OnCtlColor(CDC*pDC,CWnd*pWnd,UINTnCtlColor){HBRUSHhbr=CDialog::OnCtlCo...
HBRUSH CNewDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(pWnd->GetDlgCtrlID()==IDC_LIST1)
{ //pDC->SetBkMode(TRANSPARENT);
CBrush *poldbrush=CBrush::FromHandle((HBRUSH) GetStockObject(NULL_BRUSH));
pDC->SelectObject(poldbrush);
CBitmap bit;
bit.LoadBitmap(IDB_BITMAP1);
BITMAP b;
bit.GetBitmap(&b);
CDC dc;
dc.CreateCompatibleDC(pDC);
dc.SelectObject(&bit);
CRect rc;
GetDlgItem(IDC_LIST1)->GetWindowRect(rc);
pDC->FillRect(rc,poldbrush);
ScreenToClient(rc);
pDC->StretchBlt(0,0,rc.Width(),rc.Height(),&dc,0,0,b.bmWidth,b.bmHeight,SRCCOPY);
return (HBRUSH)poldbrush;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
被白色部分挡着。
怎么改阿? 谢谢。没分了。 展开
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(pWnd->GetDlgCtrlID()==IDC_LIST1)
{ //pDC->SetBkMode(TRANSPARENT);
CBrush *poldbrush=CBrush::FromHandle((HBRUSH) GetStockObject(NULL_BRUSH));
pDC->SelectObject(poldbrush);
CBitmap bit;
bit.LoadBitmap(IDB_BITMAP1);
BITMAP b;
bit.GetBitmap(&b);
CDC dc;
dc.CreateCompatibleDC(pDC);
dc.SelectObject(&bit);
CRect rc;
GetDlgItem(IDC_LIST1)->GetWindowRect(rc);
pDC->FillRect(rc,poldbrush);
ScreenToClient(rc);
pDC->StretchBlt(0,0,rc.Width(),rc.Height(),&dc,0,0,b.bmWidth,b.bmHeight,SRCCOPY);
return (HBRUSH)poldbrush;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
被白色部分挡着。
怎么改阿? 谢谢。没分了。 展开
2个回答
展开全部
声明一个成员CBursh m_brush;
然后在窗口的OnInitDialog()里写上
CBitmap *pBitmap = new CBitmap;
pBitmap->LoadBitmap(IDB_BITMAP1);
m_brush.CreatePatternBrush(pBitmap);
delete pBitmap;
然后在OnCtlColor()里写:
if(pWnd->GetDlgCtrlID()==IDC_LIST1)
{
return (HBRUSH) m_brush.GetSafeHandle() ;
}
然后运行看下效果
然后在窗口的OnInitDialog()里写上
CBitmap *pBitmap = new CBitmap;
pBitmap->LoadBitmap(IDB_BITMAP1);
m_brush.CreatePatternBrush(pBitmap);
delete pBitmap;
然后在OnCtlColor()里写:
if(pWnd->GetDlgCtrlID()==IDC_LIST1)
{
return (HBRUSH) m_brush.GetSafeHandle() ;
}
然后运行看下效果
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询