各位,大家好:
我在网上找个listview的程序,可以用sendmessage添加4个属性:1.可以整行选择LVS_EX_FULLROWSELECT = &H20
2.具有表格结构LVS_EX_GRIDLINES = &H1\\3.有鼠标单击响应LVS_EX_ONECLICKACTIVATE = &H40\\4.有鼠标双击响应LVS_EX_TWOCLICKACTIVATE = &H80.这个控件在他原来的程序上可以正常运行,能够实现其功能.问题是我在窗体上又建了一个listview2,函数的功能也是一样,程序也写的一样,却不能够实现其功能.但是如果把他的控件COPY一个新的,调试后就有那样的功能.这是怎么回事,我初学,望前辈帮我解释一下.谢谢.
我在网上找个listview的程序,可以用sendmessage添加4个属性:1.可以整行选择LVS_EX_FULLROWSELECT = &H20
2.具有表格结构LVS_EX_GRIDLINES = &H1\\3.有鼠标单击响应LVS_EX_ONECLICKACTIVATE = &H40\\4.有鼠标双击响应LVS_EX_TWOCLICKACTIVATE = &H80.这个控件在他原来的程序上可以正常运行,能够实现其功能.问题是我在窗体上又建了一个listview2,函数的功能也是一样,程序也写的一样,却不能够实现其功能.但是如果把他的控件COPY一个新的,调试后就有那样的功能.这是怎么回事,我初学,望前辈帮我解释一下.谢谢.
一般LVS_EX_开头的样式都是扩展样式
需要用SendMessage发送一个消息获得:LVM_GETEXTENDEDLISTVIEWSTYLE
当SendMessage返回扩展样式后,再用SendMessage发送LVM_SETEXTENDEDLISTVIEWSTYLE消息进行设置。
Public Const LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54
Public Const LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55
Public Const LVS_EX_FULLROWSELECT = &H20
Public Const LVS_EX_GRIDLINES = &H1Public Const LVS_EX_ONECLICKACTIVATE = &H40
Public Const LVS_EX_TWOCLICKACTIVATE = &H80Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
'该函数将指定的消息发送到一个或多个窗口。此函数为指定的窗口调用窗口程序,
'直到窗口程序处理完消息再返回。而函数PostMessage不同,将一个消息寄送到一个线程的
'消息队列后立即返回?
Public Sub ListViewStyle_Click()
Dim rStyle As Long
Dim r As Long
'使ListView控件可以整行选择
rStyle = SendMessageLong(frmData.ListView1.hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&)
'rStyle = rStyle Xor LVS_EX_FULLROWSELECT'不可以整行选择
rStyle = rStyle Or LVS_EX_FULLROWSELECT '可以整行选择
'set the new ListView style
r = SendMessageLong(frmData.ListView1.hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, rStyle)
End Sub
Public Sub ListViewStyleBiaoG_Click()
Dim rStyle As Long
Dim r As Long
'使ListView控件有表格风格
rStyle = SendMessageLong(frmData.ListView1.hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&)
'rStyle = rStyle Xor LVS_EX_GRIDLINES '没有表格风格
rStyle = rStyle Or LVS_EX_GRIDLINES '有表格风格
'set the new ListView style
r = SendMessageLong(frmData.ListView1.hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, rStyle)
End Sub
Public Sub ListViewStyleOne_Click() '允许单击选择
Dim rStyle As Long
Dim r As Long
'get the current ListView style
rStyle = SendMessageLong(frmData.ListView1.hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&)
'set the extended style bit
rStyle = rStyle Or LVS_EX_ONECLICKACTIVATE
'set the new ListView style
r = SendMessageLong(frmData.ListView1.hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, rStyle)
End SubPublic Sub ListViewStyleTwo_Click() '允许双击选择
Dim rStyle As Long
Dim r As Long
'get the current ListView style
rStyle = SendMessageLong(frmData.ListView1.hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&)
'set the extended style bit
rStyle = rStyle Or LVS_EX_TWOCLICKACTIVATE
'set the new ListView style
r = SendMessageLong(frmData.ListView1.hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, rStyle)
End Sub
Public Sub ListViewStyle1_Click()
Dim rStyle As Long
Dim r As Long
'使ListView控件可以整行选择
rStyle = SendMessageLong(ChangPart.ListView1.hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&)
'rStyle = rStyle Xor LVS_EX_FULLROWSELECT'不可以整行选择
rStyle = rStyle Or LVS_EX_FULLROWSELECT '可以整行选择
'set the new ListView style
r = SendMessageLong(ChangPart.ListView1.hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, rStyle)
End Sub
Public Sub ListViewStyleBiaoG1_Click()
Dim rStyle As Long
Dim r As Long
'使ListView控件有表格风格
rStyle = SendMessageLong(ChangPart.ListView1.hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&)
'rStyle = rStyle Xor LVS_EX_GRIDLINES '没有表格风格
rStyle = rStyle Or LVS_EX_GRIDLINES '有表格风格
'set the new ListView style
r = SendMessageLong(ChangPart.ListView1.hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, rStyle)
End Sub
Public Sub ListViewStyleOne1_Click() '允许单击选择
Dim rStyle As Long
Dim r As Long
'get the current ListView style
rStyle = SendMessageLong(ChangPart.ListView1.hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&)
'set the extended style bit
rStyle = rStyle Or LVS_EX_ONECLICKACTIVATE
'set the new ListView style
r = SendMessageLong(ChangPart.ListView1.hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, rStyle)
End SubPublic Sub ListViewStyleTwo1_Click() '允许双击选择
Dim rStyle As Long
Dim r As Long
'get the current ListView style
rStyle = SendMessageLong(ChangPart.ListView1.hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, 0&)
'set the extended style bit
rStyle = rStyle Or LVS_EX_TWOCLICKACTIVATE
'set the new ListView style
r = SendMessageLong(ChangPart.ListView1.hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, rStyle)
End Sub
初始化时候调用一下就可以了
他原来的程序是用5.0的,我是在他原来的程序上改的.程序也一样,条件也一样.怎么拷贝的可以,新建的不可以.
我想可能也是版本的问题.只是不知道具体哪里的问题,想搞清楚一下,总不能一直考他的控件,我自己就不能够新建么?
如果你的listview1也有用,那么就必须增添多一行了。