listctrl添加按钮

yezi163 2010-10-20 02:21:56
想自定义一个listctrl,能够在里面添加按钮
要怎么继承clistctrl呢?
重写哪些方法?
如果有示例代码最好了

我百度了一下,很多都讲得模糊不清
...全文
454 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jinszhang 2010-10-21
  • 打赏
  • 举报
回复
3楼的,点解会每增加一项都要加一个按键呢,当列表的项多起后,你的程序还运动得起啊,只要生成一个,在选中项中显示按键就可以了。这样又高效又方便。
yezi163 2010-10-21
  • 打赏
  • 举报
回复
给点代码吧
zhangweiit 2010-10-21
  • 打赏
  • 举报
回复
不好意思,那个属性我打错了
是LVS_OWNERDRAWFIXED
zhangweiit 2010-10-21
  • 打赏
  • 举报
回复
如果要自己加按钮,那要设置ModifyStyle,添加一个LVC_DRAWITEMFIXED
同时,重截DrawItem方法
zhangweiit 2010-10-21
  • 打赏
  • 举报
回复
http://www.codeproject.com/KB/list/LVChecked.aspx
这个例子你看一下,先从加入默认的checkbox开始,
j8daxue 2010-10-20
  • 打赏
  • 举报
回复
3楼那个hackchina的例子不错,正在研究中
大家继续指点
MYNAMELIULI 2010-10-20
  • 打赏
  • 举报
回复
3楼那个hackchina的例子不错,正在研究中
大家继续指点
yezi163 2010-10-20
  • 打赏
  • 举报
回复
3楼那个hackchina的例子不错,正在研究中
大家继续指点
yezi163 2010-10-20
  • 打赏
  • 举报
回复
二楼的,我看过这个codeproject的代码,好复杂啊
wjhuangjin 2010-10-20
  • 打赏
  • 举报
回复

void CButtonListBox::AddItem(LPCTSTR ButtonText)
{

CLedButton* pAddedButton;
static int count = 0;
CRect rect;
CRect ButtonRect;

count++;
GetClientRect( rect );

pAddedButton = new CLedButton(ButtonText,this);
ButtonRect.SetRect( 0, 0, rect.Width(), (rect.Height() / NUMBER_OF_BUTTONS_IN_LIST_VIEW) );
pAddedButton->Create( "", WS_CHILD|BS_OWNERDRAW, ButtonRect, this, 1001+count );

int AddedAt = m_ButtonArray.Add( pAddedButton );

//Adds a string and assigns nIndex the index of the current item
int nIndex = AddString( "" );

// Set a hight for the data item
CListBox::SetItemHeight( nIndex, rect.Height() / NUMBER_OF_BUTTONS_IN_LIST_VIEW );

//If no error, associates the index with the button
if( nIndex!=LB_ERR && nIndex!=LB_ERRSPACE )
SetItemData( nIndex, (DWORD)m_ButtonArray.ElementAt(AddedAt) );
}

http://www.hackchina.com/cont/3470
Eleven 2010-10-20
  • 打赏
  • 举报
回复
codeproject上搜索一下
visualwind 2010-10-20
  • 打赏
  • 举报
回复

15,978

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧