步骤:
1、CButton* pBtn = new CButton
2、pBtn->Create("Caption",WS_CHILD|WS_VISIBLE,CRect(你计算你的位置),List的指针, YOURID)
3、在CListCtrl派生类中相应命令,ON_COMMAND(YOURID, OnCmd)
4、在OnCmd()中实现你的逻辑。
首先你要从CListCtrl继承一个类,实现NM_CUSTOMDRAW消息或者重载DrawItem()函数。加控件Button可以在响应NM_CUSTOMDRAW自绘消息时new出来,但是这样会比较慢,而且无法消除闪烁效果。
最好是自绘一个图片做出button的效果来,在NM_CUSTOMDRAW响应函数判断消息类型是CDDS_ITEMPREPAINT或者CDDS_ITEMPREPAINT是画一张图片上去,并响应
ON_WM_MOUSEMOVE(),ON_WM_MOUSELEAVE(),ON_WM_LBUTTONDOWN(),ON_WM_LBUTTONUP()等消息动态绘制效果。如
BEGIN_MESSAGE_MAP()
ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, &CXXXList::OnNMCustomdraw)
ON_WM_MOUSEMOVE()
ON_WM_MOUSELEAVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
END_MESSAGE_MAP()
void CXXXList::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR )
*pResult = CDRF_DODEFAULT
switch (pLVCD->nmcd.dwDrawStage)
{
case CDDS_ITEMPREPAINT:
*pResult = ItemPrePaint(pLVCD)
break
case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
*pResult = SubItemPrePaint(pLVCD)
break
default:
break
}
}
DWORD CXXXList::SubItemPrePaint(NMLVCUSTOMDRAW* pLVCD)
{
//画图片
CDC* pDc = CDC::FromHandle(pLVCD->nmcd.hdc)
return CDRF_NOTIFYPOSTPAINT
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)