从MSDN上看到,好象还要执行个什么初始化类的函数?
"Because the list view control uses OLE COM to manipulate the background images, the calling application must call CoInitialize or OleInitialize before using this macro. It is best to call one of these functions when the application is initialized, and call either CoUnitialize or OleUnitialize when the application is terminating. "
"Because the list view control uses OLE COM to manipulate the background images, the calling application must call CoInitialize or OleInitialize before using this macro. It is best to call one of these functions when the application is initialized, and call either CoUnitialize or OleUnitialize when the application is terminating. "
2.在CMyListCtrl重载WM_ERASEBKGND,然后如下:
BOOL CMyListCtrl::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
if(!bBitmapSet)
return CListCtrl::OnEraseBkgnd(pDC);
//
BITMAP bm;
CDC dcMem;
CSize sizeBg;
CRect rectClip,rectTile;
//
mBitmap.GetObject(sizeof(bm),(LPVOID)&bm);
sizeBg.cx=bm.bmWidth;
sizeBg.cy=bm.bmHeight;
//
pDC=GetDC();
dcMem.CreateCompatibleDC(pDC);
CBitmap *pbmOld=dcMem.SelectObject(&mBitmap);
//
pDC->GetClipBox(&rectClip);
rectTile=CRect(0,0,sizeBg.cx,sizeBg.cy);
while(rectTile.top<=rectClip.bottom){
while(rectTile.left<=rectClip.right){
if(!(rectTile & rectClip).IsRectEmpty())
pDC->BitBlt(rectTile.left,rectTile.top,sizeBg.cx,sizeBg.cy,&dcMem,0,0,SRCCOPY);
rectTile.left+=sizeBg.cx;
rectTile.right+=sizeBg.cx;
}
rectTile.left=0;
rectTile.right=sizeBg.cy;
rectTile.top+=sizeBg.cy;
rectTile.bottom+=sizeBg.cy;
}
//
dcMem.SelectObject(pbmOld);
dcMem.DeleteDC();
//
return TRUE;
}
3.构造
CMyListCtrl::CMyListCtrl()
{
if(mBitmap.LoadBitmap(IDB_BITMAP))
bBitmapSet=TRUE;
else
bBitmapSet=FALSE;
//
}
4.在MyListCtrl.h里加入
private:
BOOL bBitmapSet;
CBitmap mBitmap;
5.在你的对框头文件改成如下:
//CListCtrl m_myList;
CMyListCtrl m_myList;
6.全部完成。
OleInitialize();
然后在调用ListCtrl的地方:
m_myList.SetBkImage("d:\\work\\bk.bmp");
就OK了:)