MFC怎么给CListCtrl添加背景图片?

 我来答
  • 你的回答被采纳后将获得:
  • 系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
志当存高远389
2015-06-02 · 知道合伙人互联网行家
志当存高远389
知道合伙人互联网行家
采纳数:11236 获赞数:20407
08年毕业,一直从事计算机行业,从基层做起。有较强的实践操作能力。

向TA提问 私信TA
展开全部
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."));

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
栖凤婷
2015-06-02 · TA获得超过551个赞
知道小有建树答主
回答量:468
采纳率:0%
帮助的人:378万
展开全部
自绘啊,实现控件的子类化。用系统自身的控件是做不到的。
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式