vc++ listctrl(report风格的) 添加图标(或按钮,图片) 怎么实现??

vc++ listctrl(report风格的) 添加图标(或按钮,图片) 怎么实现??,第1张

首先要设置 LVS_EX_SUBITEMIMAGES 属性:

SetExtendedStyle(LVS_EX_SUBITEMIMAGES)

加添图标,需要有一个CImageList 把资源里的图片添加CIamgeList里.

第一个加入的图标编号为0 以此类推.

SetItem()函数 设置图片,具体参数 参考msdn

例子:

i行 j列

SetItem(i,j,LVIF_IMAGE, NULL, 0,LVIS_SELECTED,LVIS_SELECTED,0)

最后几个参数既是 图标在CimageList里的位置.

附:添加图标到CImageList.

首先要知道你的资源文件是什么格式?bmp ioc?

2种格式的添加方法是不一样.

CImageLIst m_myimg

m_myimg.Create(.....)//图标的属性设置

m_myimg.Add(...)//资源ID

m_myimg.SetImageList(...)

参数查MSDN.

在ListCtrl的Item内 添加一个按钮.我也做过,代码没了.

给你个思路.

写个MyButton类,或者直接用CButton.

获得Item的Rect 把按钮Create上去(按钮的Rect大小,自己算一下即可)

1.定义成员变量:

CComboBox

m_Cmb

、、将它与组合框控件关联,

CEdit

m_Edit;、、将它与编辑框控件关联,

int

m_row,m_col

//记录用户点击的那个单元格所在的行与列号

2.添加listctrl的单击响应消息主要是完成了单击后将控件显示出来。添加代码如下

void

CControllerDialogAdd::OnClickListDoor(NMHDR*

pNMHDR,

LRESULT*

pResult)

{

//

TODO:

Add

your

control

notification

handler

code

here

LPNMLISTVIEW

pNMTreeView

=

reinterpret_cast<LPNMLISTVIEW>(pNMHDR)

//

TODO:

在此添加控件通知处理程序代码

POINT

PT

GetCursorPos(&PT)

m_DoorList.ScreenToClient(&PT)

LVHITTESTINFO

hitInfo

hitInfo.pt=PT

//hitem=m_Tree.GetSelectedItem()

m_DoorList.SubItemHitTest(&hitInfo)

if(hitInfo.flags

&

LVHT_ONITEMLABEL)//判断是否单击在文本上

{

CRect

rect

//

m_DoorList.GetSubItemRect(hitInfo.iItem,hitInfo.iSubItem,LVIR_BOUNDS,rect)

m_DoorList.GetSubItemRect(hitInfo.iItem,hitInfo.iSubItem,LVIR_BOUNDS,rect)

if

(hitInfo.iSubItem==0)

{

rect.right=rect.left+m_DoorList.GetColumnWidth(0)

}

else

if(hitInfo.iSubItem==1)//对列进行判断在这里我是1,2为edit,3,4为combo

box

{

CString

mes=m_DoorList.GetItemText(hitInfo.iItem,hitInfo.iSubItem)

//

rect.InflateRect(0,0,0,0)//增大组合框的高度使其可以容纳整行文本。

m_col=hitInfo.iSubItem

m_row=hitInfo.iItem

m_Edit.MoveWindow(&rect,TRUE)

m_Edit.ShowWindow(SW_NORMAL)

m_Edit.SetWindowText(mes)

m_Edit.BringWindowToTop()

m_Edit.SetFocus()//使组合框聚焦

}

else

if(hitInfo.iSubItem==2)

{

CString

mes=m_DoorList.GetItemText(hitInfo.iItem,hitInfo.iSubItem)

//

rect.InflateRect(0,0,0,0)//增大组合框的高度使其可以容纳整行文本。

m_col=hitInfo.iSubItem

m_row=hitInfo.iItem

m_Edit.MoveWindow(&rect,TRUE)

m_Edit.ShowWindow(SW_NORMAL)

m_Edit.SetWindowText(mes)

m_Edit.BringWindowToTop()

m_Edit.SetFocus()//使组合框聚焦

}

else

if(hitInfo.iSubItem==3)

{

CString

mes=m_DoorList.GetItemText(hitInfo.iItem,hitInfo.iSubItem)

//

rect.InflateRect(0,0,0,0)//增大组合框的高度使其可以容纳整行文本。

m_col=hitInfo.iSubItem

m_row=hitInfo.iItem

m_ComAct.MoveWindow(&rect,TRUE)

m_ComAct.ShowWindow(SW_NORMAL)

m_ComAct.SetWindowText(mes)

m_ComAct.BringWindowToTop()

m_ComAct.SetFocus()//使组合框聚焦

}

else

if

(hitInfo.iSubItem==4)

{

CString

mes=m_DoorList.GetItemText(hitInfo.iItem,hitInfo.iSubItem)

//

rect.InflateRect(0,0,0,0)//增大组合框的高度使其可以容纳整行文本。

m_col=hitInfo.iSubItem

m_row=hitInfo.iItem

你是的意思是在listView的每一项里都加一个固定的按钮或图片吗,那就将它写到一个xml中,然后inflate到listView中,这样listView的每一项的布局就都是xml中的布局了。

<LinearLayout xmlns:android="

android:orientation="vertical"

android:layout_width="fill_parent"

android:layout_height="fill_parent"

>

<Button

android:id="@+id/button"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Button"

/>

<ListView

android:id="@+id/listView"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

/>

</LinearLayout>

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState)

setContentView(R.layout.listview)

String[] data = {"a", "b", "c", "d", "a", "b", "c", "d", "a", "b", "c", "d"}

ListView listView = (ListView) findViewById(R.id.listView)

listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, data))


欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/bake/11958351.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-20
下一篇 2023-05-20

发表评论

登录后才能评论

评论列表(0条)

保存