
MFC怎么给CListCtrl添加背景图片?
- 你的回答被采纳后将获得:
- 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
2015-06-02 · 知道合伙人互联网行家
关注

展开全部
if (bEnable)
{
/*
There are two ways to include a background image:
(1) Specify a valid filepath and load the bitmap handle from there
(2) Specify a valid URL using the res:protocol (preferred).
(2) Is preferable because you don't need to include a separate file
with your application. You can embed the BMP in the resource fork
and use the RES: protocol to have the ListControl load it. See
www.microsoft.com/...99.asp for more
information about the RES: syntax. This idea was suggested by Nick Hodapp
(www.codetools.com/...id=162)
Both methods are included for completeness, but the sample
application uses the embedded BMP. Note that specifying a HBITMAP
in the struct is not currently supported.
*/
// Load the resource and apply it to the background
TCHAR szBuffer[_MAX_PATH];
VERIFY(::GetModuleFileName(AfxGetInstanceHandle(), szBuffer, _MAX_PATH));
CString sPath;
sPath.Format(_T("res://%s/#2/#142"),szBuffer);
LVBKIMAGE bki;
bki.ulFlags = LVBKIF_STYLE_TILE | LVBKIF_SOURCE_URL ;
bki.pszImage = sPath.GetBuffer(sPath.GetLength());
bki.cchImageMax = sPath.GetLength();
VERIFY(m_cListCtrl.SetBkImage( &bki));
/*
Construct the path to the BMP. Although the CListCtrl::SetBkImage docs
indicate that you can use a n HBITMAP, the latest docs on the LVBKIMAGE
underlying struct indicates that the LVBKIMAGE.hbm member is not used.
*/
/*
TCHAR szBuffer[_MAX_PATH];
VERIFY(::GetModuleFileName(AfxGetInstanceHandle(), szBuffer, _MAX_PATH));
CString sPath = (CString)szBuffer;
sPath = sPath.Left(sPath.ReverseFind('\\') + 1);
sPath += "bk.bmp";
m_cListCtrl.SetBkImage( sPath.GetBuffer(sPath.GetLength()), TRUE);
sPath.ReleaseBuffer();
*/
// Whichever one you choose, log the path used
CString str;
str.Format(_T("Set background image: %s"), sPath.GetBuffer(sPath.GetLength()));
m_Log.AppendString(str);
sPath.ReleaseBuffer();
}
else
{
m_cListCtrl.SetBkImage( HBITMAP(0));
m_Log.AppendString(_T("Cleared background image."));
}
{
/*
There are two ways to include a background image:
(1) Specify a valid filepath and load the bitmap handle from there
(2) Specify a valid URL using the res:protocol (preferred).
(2) Is preferable because you don't need to include a separate file
with your application. You can embed the BMP in the resource fork
and use the RES: protocol to have the ListControl load it. See
www.microsoft.com/...99.asp for more
information about the RES: syntax. This idea was suggested by Nick Hodapp
(www.codetools.com/...id=162)
Both methods are included for completeness, but the sample
application uses the embedded BMP. Note that specifying a HBITMAP
in the struct is not currently supported.
*/
// Load the resource and apply it to the background
TCHAR szBuffer[_MAX_PATH];
VERIFY(::GetModuleFileName(AfxGetInstanceHandle(), szBuffer, _MAX_PATH));
CString sPath;
sPath.Format(_T("res://%s/#2/#142"),szBuffer);
LVBKIMAGE bki;
bki.ulFlags = LVBKIF_STYLE_TILE | LVBKIF_SOURCE_URL ;
bki.pszImage = sPath.GetBuffer(sPath.GetLength());
bki.cchImageMax = sPath.GetLength();
VERIFY(m_cListCtrl.SetBkImage( &bki));
/*
Construct the path to the BMP. Although the CListCtrl::SetBkImage docs
indicate that you can use a n HBITMAP, the latest docs on the LVBKIMAGE
underlying struct indicates that the LVBKIMAGE.hbm member is not used.
*/
/*
TCHAR szBuffer[_MAX_PATH];
VERIFY(::GetModuleFileName(AfxGetInstanceHandle(), szBuffer, _MAX_PATH));
CString sPath = (CString)szBuffer;
sPath = sPath.Left(sPath.ReverseFind('\\') + 1);
sPath += "bk.bmp";
m_cListCtrl.SetBkImage( sPath.GetBuffer(sPath.GetLength()), TRUE);
sPath.ReleaseBuffer();
*/
// Whichever one you choose, log the path used
CString str;
str.Format(_T("Set background image: %s"), sPath.GetBuffer(sPath.GetLength()));
m_Log.AppendString(str);
sPath.ReleaseBuffer();
}
else
{
m_cListCtrl.SetBkImage( HBITMAP(0));
m_Log.AppendString(_T("Cleared background image."));
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询