是真的隐藏,不是把宽度变为0,因为那样用户可能还是把它拉开的。
20 个解决方案
#1
本身LISTVIEW就没有这个功能。
有和种解决办法就是自动生成列标头。
当需要显示的时候动态用listview.ColumnHeaders.add 来动态增加列标头
有和种解决办法就是自动生成列标头。
当需要显示的时候动态用listview.ColumnHeaders.add 来动态增加列标头
#2
你可以把那列的值存储在 其他的 ColumnHeader.key 属性里 ....
#3
TO hot1kang1(许仙)
首先,每个列标头的Key都有用,没有空的。
其次,即使有空的Key,如何把每行对应的数据存在里面呢?
它是列标头啊,不是行哦:)
To cool_man(土豆) :
光动态增加列标头,没有数据是不行的,
有时候加载列表的数据是没有Key值的,
也就是说只有第一次增加ListItem的时候才能获得全部数据(比如一个动态的查找循环)。
而一旦加载完成,就无法再加载某个子项的数据了,
所以,临时添加数据不可行
(只能一次加载所有数据,再根据需要显示部分列)
看下来,好像系统自己的ListView都有一个自带的列标头编辑器(XP)
在这个编辑器里可以动态调整列标头顺序和是否显示,
怀疑这可能是ListView的一个新样式,因为在WMP里也有这个功能。
不知道我们能否调用它呢?
如果可用的话,几乎不用写代码就获得了完美的列标头编辑功能了,呵呵:)
首先,每个列标头的Key都有用,没有空的。
其次,即使有空的Key,如何把每行对应的数据存在里面呢?
它是列标头啊,不是行哦:)
To cool_man(土豆) :
光动态增加列标头,没有数据是不行的,
有时候加载列表的数据是没有Key值的,
也就是说只有第一次增加ListItem的时候才能获得全部数据(比如一个动态的查找循环)。
而一旦加载完成,就无法再加载某个子项的数据了,
所以,临时添加数据不可行
(只能一次加载所有数据,再根据需要显示部分列)
看下来,好像系统自己的ListView都有一个自带的列标头编辑器(XP)
在这个编辑器里可以动态调整列标头顺序和是否显示,
怀疑这可能是ListView的一个新样式,因为在WMP里也有这个功能。
不知道我们能否调用它呢?
如果可用的话,几乎不用写代码就获得了完美的列标头编辑功能了,呵呵:)
#4
//看下来,好像系统自己的ListView都有一个自带的列标头编辑器(XP)
它是新建列表头办到的,每次更改后重新填充数据
由于资源管理器每次只填充看得见的项目的数据,看不见的项目的数据用另一个线程慢慢添加,所以感觉速度很快
所以还是想办法保存数据、再动态添加吧
它是新建列表头办到的,每次更改后重新填充数据
由于资源管理器每次只填充看得见的项目的数据,看不见的项目的数据用另一个线程慢慢添加,所以感觉速度很快
所以还是想办法保存数据、再动态添加吧
#5
把宽度设为0,然后用子类处理一下列标头的事件
#6
新鲜出炉的代码:
http://rainstormmaster.cnblogs.com/archive/2006/01/20/321050.html
http://rainstormmaster.cnblogs.com/archive/2006/01/20/321050.html
#7
老大,为什么偶总是取不到HDN_BEGINTRACK消息呢?
#8
这个不好说啊,你什么系统?
#9
XP
就照老大的代码,其它都能取到,就是那个不行
就照老大的代码,其它都能取到,就是那个不行
#10
还有,不好意思问一下(偶真的不知道)
Const WM_NCLButtonDown = &HA1
Const HTCaption = 2
ReleaseCapture
SendMessage hWnd, WM_NCLButtonDown, HTCaption, ByVal 0&
能否把以上代码放到TLB中做成一个函数过程?
(不知道TLB中是否只能定义接口?)
还有,哪里有C和B的数据类型对照表?
Const WM_NCLButtonDown = &HA1
Const HTCaption = 2
ReleaseCapture
SendMessage hWnd, WM_NCLButtonDown, HTCaption, ByVal 0&
能否把以上代码放到TLB中做成一个函数过程?
(不知道TLB中是否只能定义接口?)
还有,哪里有C和B的数据类型对照表?
#11
模块代码:
Option Explicit
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Const GWL_WNDPROC As Long = -4
Public Const GWL_STYLE As Long = -16
Public Const WM_NOTIFY As Long = &H4E&
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal wNewWord As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Any, lParam As Any) As Long
Public Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Public Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hWnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Const LVM_FIRST = &H1000
Private Const LVM_GETHEADER = (LVM_FIRST + 31)
Private Type NMHDR
hWndFrom As Long
idfrom As Long
code As Long
End Type
Private Type HD_HITTESTINFO
pt As POINTAPI
flags As Long
iItem As Long
End Type
Private Const HHT_ONHEADER = &H2
Private Const HHT_ONDIVIDER = &H4
Private Const HDM_HITTEST As Long = &H1206
Private Const HDN_FIRST As Long = -300&
Private Const HDN_ITEMCLICK As Long = (HDN_FIRST - 2)
Private Const HDN_DIVIDERDBLCLICK As Long = (HDN_FIRST - 5)
Private Const HDN_BEGINTRACK As Long = (HDN_FIRST - 6)
Private Const HDN_ENDTRACK As Long = (HDN_FIRST - 7)
Private Const HDN_TRACK As Long = (HDN_FIRST - 8)
Private Const HDN_GETDISPINFO As Long = (HDN_FIRST - 9)
Private Const HDN_BEGINDRAG As Long = (HDN_FIRST - 10)
Private Const HDN_ENDDRAG As Long = (HDN_FIRST - 11)
Private Const HDN_ITEMCHANGING As Long = (HDN_FIRST - 0)
Private Const HDN_ITEMCHANGED As Long = (HDN_FIRST - 1)
Private Const HDN_ITEMDBLCLICK As Long = (HDN_FIRST - 3)
Private Const HDN_NM_RCLICK As Long = -5
' 列标头事件
Public Enum lvHeaderActions
lvHeaderActionClick = 1
lvHeaderActionRightClick = 2
lvHeaderActionDividerDoubleClick = 3
lvHeaderActionResizeBegin = 4
lvHeaderActionResizeEnd = 5
lvHeaderActionChanging = 6
lvHeaderActionChanged = 7
lvHeaderActionDragBegin = 8
lvHeaderActionDragEnd = 9
End Enum
Private RegisteredListViewControls As New Collection
Public Sub RegisterListView(ByVal ListViewControl As ListView)
Call SetProp(ListViewControl.hWnd, "OrigWindowProc", GetWindowLong(ListViewControl.hWnd, GWL_WNDPROC))
Call SetWindowLong(ListViewControl.hWnd, GWL_WNDPROC, AddressOf HandleListViewHeaderMsgs)
Call RegisteredListViewControls.Add(ListViewControl, CStr(ListViewControl.hWnd))
End Sub
Public Sub UnregisterListView(ByVal ListViewControl As ListView)
Dim OrigWindowProc As Long
OrigWindowProc = GetProp(ListViewControl.hWnd, "OrigWindowProc")
If (OrigWindowProc <> 0) Then
Call SetWindowLong(ListViewControl.hWnd, GWL_WNDPROC, OrigWindowProc)
End If
Call RegisteredListViewControls.Remove(CStr(ListViewControl.hWnd))
End Sub
Public Function HandleListViewHeaderMsgs(ByVal ListViewhWnd As Long, ByVal msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
Const EVENT_SUFFIX As String = "_HeaderEvent"
Dim ListViewControl As ListView
Dim NmHdrMsg As NMHDR
Dim PointStruct As POINTAPI
Dim HitTestInfo As HD_HITTESTINFO
Dim HeaderhWnd As Long
Dim HeaderAction As lvHeaderActions
Dim CancelMsg As Boolean
If msg = WM_NOTIFY Then
HandleListViewHeaderMsgs = CallWindowProc(GetProp(ListViewhWnd, "OrigWindowProc"), ListViewhWnd, msg, wp, lp)
Call CopyMemory(NmHdrMsg, ByVal lp, Len(NmHdrMsg))
HeaderhWnd = SendMessage(ListViewhWnd, LVM_GETHEADER, 0&, ByVal 0&)
If (HeaderhWnd <> 0) Then
Call GetCursorPos(PointStruct)
Call ScreenToClient(HeaderhWnd, PointStruct)
HitTestInfo.flags = HHT_ONHEADER Or HHT_ONDIVIDER
HitTestInfo.pt = PointStruct
Call SendMessage(HeaderhWnd, HDM_HITTEST, 0&, HitTestInfo)
Select Case NmHdrMsg.code
Case HDN_ITEMCLICK: HeaderAction = lvHeaderActionClick
Case HDN_NM_RCLICK: HeaderAction = lvHeaderActionRightClick
Case HDN_DIVIDERDBLCLICK: HeaderAction = lvHeaderActionDividerDoubleClick
Case HDN_BEGINTRACK: HeaderAction = lvHeaderActionResizeBegin
Case HDN_ENDTRACK: HeaderAction = lvHeaderActionResizeEnd
Case HDN_ITEMCHANGING: HeaderAction = lvHeaderActionChanging
Case HDN_ITEMCHANGED: HeaderAction = lvHeaderActionChanged
Case HDN_BEGINDRAG: HeaderAction = lvHeaderActionDragBegin
Case HDN_ENDDRAG: HeaderAction = lvHeaderActionDragEnd
End Select
If HeaderAction <> 0 Then
On Error Resume Next
Set ListViewControl = RegisteredListViewControls(CStr(ListViewhWnd))
CancelMsg = CallByName(ListViewControl.Parent, ListViewControl.Name & EVENT_SUFFIX, VbCallType.VbMethod, HeaderAction, HitTestInfo.iItem + 1)
On Error GoTo 0
If CancelMsg Then
HandleListViewHeaderMsgs = 1
Exit Function
End If
End If
End If
End If
HandleListViewHeaderMsgs = CallWindowProc(GetProp(ListViewhWnd, "OrigWindowProc"), ListViewhWnd, msg, wp, lp)
End Function
Public Sub ListViewHeaderEventDebugPrint(ByVal ListViewControl As ListView, ByVal Action As lvHeaderActions, ByVal Column As Long)
Dim msg As String
Select Case Action
Case lvHeaderActionClick: msg = "clicked"
Case lvHeaderActionRightClick: msg = "right-clicked"
Case lvHeaderActionDividerDoubleClick: msg = "divider dbl-clicked"
Case lvHeaderActionResizeBegin: msg = "resize begin"
Case lvHeaderActionResizeEnd: msg = "resize end"
Case lvHeaderActionChanging: msg = "changing"
Case lvHeaderActionChanged: msg = "changed"
Case lvHeaderActionDragBegin: msg = "drag begin"
Case lvHeaderActionDragEnd: msg = "drag end"
End Select
Debug.Print ListViewControl.Parent.Name & "." & ListViewControl.Name & ": " & msg & " (col=" & CStr(Column) & ")"
End Sub
Option Explicit
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Const GWL_WNDPROC As Long = -4
Public Const GWL_STYLE As Long = -16
Public Const WM_NOTIFY As Long = &H4E&
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal wNewWord As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Any, lParam As Any) As Long
Public Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Public Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hWnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Const LVM_FIRST = &H1000
Private Const LVM_GETHEADER = (LVM_FIRST + 31)
Private Type NMHDR
hWndFrom As Long
idfrom As Long
code As Long
End Type
Private Type HD_HITTESTINFO
pt As POINTAPI
flags As Long
iItem As Long
End Type
Private Const HHT_ONHEADER = &H2
Private Const HHT_ONDIVIDER = &H4
Private Const HDM_HITTEST As Long = &H1206
Private Const HDN_FIRST As Long = -300&
Private Const HDN_ITEMCLICK As Long = (HDN_FIRST - 2)
Private Const HDN_DIVIDERDBLCLICK As Long = (HDN_FIRST - 5)
Private Const HDN_BEGINTRACK As Long = (HDN_FIRST - 6)
Private Const HDN_ENDTRACK As Long = (HDN_FIRST - 7)
Private Const HDN_TRACK As Long = (HDN_FIRST - 8)
Private Const HDN_GETDISPINFO As Long = (HDN_FIRST - 9)
Private Const HDN_BEGINDRAG As Long = (HDN_FIRST - 10)
Private Const HDN_ENDDRAG As Long = (HDN_FIRST - 11)
Private Const HDN_ITEMCHANGING As Long = (HDN_FIRST - 0)
Private Const HDN_ITEMCHANGED As Long = (HDN_FIRST - 1)
Private Const HDN_ITEMDBLCLICK As Long = (HDN_FIRST - 3)
Private Const HDN_NM_RCLICK As Long = -5
' 列标头事件
Public Enum lvHeaderActions
lvHeaderActionClick = 1
lvHeaderActionRightClick = 2
lvHeaderActionDividerDoubleClick = 3
lvHeaderActionResizeBegin = 4
lvHeaderActionResizeEnd = 5
lvHeaderActionChanging = 6
lvHeaderActionChanged = 7
lvHeaderActionDragBegin = 8
lvHeaderActionDragEnd = 9
End Enum
Private RegisteredListViewControls As New Collection
Public Sub RegisterListView(ByVal ListViewControl As ListView)
Call SetProp(ListViewControl.hWnd, "OrigWindowProc", GetWindowLong(ListViewControl.hWnd, GWL_WNDPROC))
Call SetWindowLong(ListViewControl.hWnd, GWL_WNDPROC, AddressOf HandleListViewHeaderMsgs)
Call RegisteredListViewControls.Add(ListViewControl, CStr(ListViewControl.hWnd))
End Sub
Public Sub UnregisterListView(ByVal ListViewControl As ListView)
Dim OrigWindowProc As Long
OrigWindowProc = GetProp(ListViewControl.hWnd, "OrigWindowProc")
If (OrigWindowProc <> 0) Then
Call SetWindowLong(ListViewControl.hWnd, GWL_WNDPROC, OrigWindowProc)
End If
Call RegisteredListViewControls.Remove(CStr(ListViewControl.hWnd))
End Sub
Public Function HandleListViewHeaderMsgs(ByVal ListViewhWnd As Long, ByVal msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
Const EVENT_SUFFIX As String = "_HeaderEvent"
Dim ListViewControl As ListView
Dim NmHdrMsg As NMHDR
Dim PointStruct As POINTAPI
Dim HitTestInfo As HD_HITTESTINFO
Dim HeaderhWnd As Long
Dim HeaderAction As lvHeaderActions
Dim CancelMsg As Boolean
If msg = WM_NOTIFY Then
HandleListViewHeaderMsgs = CallWindowProc(GetProp(ListViewhWnd, "OrigWindowProc"), ListViewhWnd, msg, wp, lp)
Call CopyMemory(NmHdrMsg, ByVal lp, Len(NmHdrMsg))
HeaderhWnd = SendMessage(ListViewhWnd, LVM_GETHEADER, 0&, ByVal 0&)
If (HeaderhWnd <> 0) Then
Call GetCursorPos(PointStruct)
Call ScreenToClient(HeaderhWnd, PointStruct)
HitTestInfo.flags = HHT_ONHEADER Or HHT_ONDIVIDER
HitTestInfo.pt = PointStruct
Call SendMessage(HeaderhWnd, HDM_HITTEST, 0&, HitTestInfo)
Select Case NmHdrMsg.code
Case HDN_ITEMCLICK: HeaderAction = lvHeaderActionClick
Case HDN_NM_RCLICK: HeaderAction = lvHeaderActionRightClick
Case HDN_DIVIDERDBLCLICK: HeaderAction = lvHeaderActionDividerDoubleClick
Case HDN_BEGINTRACK: HeaderAction = lvHeaderActionResizeBegin
Case HDN_ENDTRACK: HeaderAction = lvHeaderActionResizeEnd
Case HDN_ITEMCHANGING: HeaderAction = lvHeaderActionChanging
Case HDN_ITEMCHANGED: HeaderAction = lvHeaderActionChanged
Case HDN_BEGINDRAG: HeaderAction = lvHeaderActionDragBegin
Case HDN_ENDDRAG: HeaderAction = lvHeaderActionDragEnd
End Select
If HeaderAction <> 0 Then
On Error Resume Next
Set ListViewControl = RegisteredListViewControls(CStr(ListViewhWnd))
CancelMsg = CallByName(ListViewControl.Parent, ListViewControl.Name & EVENT_SUFFIX, VbCallType.VbMethod, HeaderAction, HitTestInfo.iItem + 1)
On Error GoTo 0
If CancelMsg Then
HandleListViewHeaderMsgs = 1
Exit Function
End If
End If
End If
End If
HandleListViewHeaderMsgs = CallWindowProc(GetProp(ListViewhWnd, "OrigWindowProc"), ListViewhWnd, msg, wp, lp)
End Function
Public Sub ListViewHeaderEventDebugPrint(ByVal ListViewControl As ListView, ByVal Action As lvHeaderActions, ByVal Column As Long)
Dim msg As String
Select Case Action
Case lvHeaderActionClick: msg = "clicked"
Case lvHeaderActionRightClick: msg = "right-clicked"
Case lvHeaderActionDividerDoubleClick: msg = "divider dbl-clicked"
Case lvHeaderActionResizeBegin: msg = "resize begin"
Case lvHeaderActionResizeEnd: msg = "resize end"
Case lvHeaderActionChanging: msg = "changing"
Case lvHeaderActionChanged: msg = "changed"
Case lvHeaderActionDragBegin: msg = "drag begin"
Case lvHeaderActionDragEnd: msg = "drag end"
End Select
Debug.Print ListViewControl.Parent.Name & "." & ListViewControl.Name & ": " & msg & " (col=" & CStr(Column) & ")"
End Sub
#12
窗体上一个listview,两个按钮:
Option Explicit
Dim HideFlag As Boolean, OldWidth As Single
Private Sub Command1_Click()
HideFlag = True
OldWidth = ListView1.ColumnHeaders(2).Width
ListView1.ColumnHeaders(2).Width = 0
End Sub
Private Sub Command2_Click()
HideFlag = False
ListView1.ColumnHeaders(2).Width = OldWidth
End Sub
Private Sub Form_Load()
Command1.Caption = "隐藏第2列"
Command2.Caption = "显示第2列"
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "第1列"
ListView1.ColumnHeaders.Add , , "第2列"
ListView1.ColumnHeaders.Add , , "第3列"
With ListView1.ListItems.Add(, , "d")
.ListSubItems.Add , , "d1"
.ListSubItems.Add , , "d2"
End With
With ListView1.ListItems.Add(, , "e")
.ListSubItems.Add , , "e1"
.ListSubItems.Add , , "e2"
End With
With ListView1.ListItems.Add(, , "f")
.ListSubItems.Add , , "f1"
.ListSubItems.Add , , "f2"
End With
Call RegisterListView(ListView1)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnregisterListView(ListView1)
End Sub
Public Function ListView1_HeaderEvent(ByVal Action As lvHeaderActions, ByVal Column As Long) As Boolean
If Column = 2 And HideFlag = True Then
ListView1_HeaderEvent = True
End If
End Function
Option Explicit
Dim HideFlag As Boolean, OldWidth As Single
Private Sub Command1_Click()
HideFlag = True
OldWidth = ListView1.ColumnHeaders(2).Width
ListView1.ColumnHeaders(2).Width = 0
End Sub
Private Sub Command2_Click()
HideFlag = False
ListView1.ColumnHeaders(2).Width = OldWidth
End Sub
Private Sub Form_Load()
Command1.Caption = "隐藏第2列"
Command2.Caption = "显示第2列"
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "第1列"
ListView1.ColumnHeaders.Add , , "第2列"
ListView1.ColumnHeaders.Add , , "第3列"
With ListView1.ListItems.Add(, , "d")
.ListSubItems.Add , , "d1"
.ListSubItems.Add , , "d2"
End With
With ListView1.ListItems.Add(, , "e")
.ListSubItems.Add , , "e1"
.ListSubItems.Add , , "e2"
End With
With ListView1.ListItems.Add(, , "f")
.ListSubItems.Add , , "f1"
.ListSubItems.Add , , "f2"
End With
Call RegisterListView(ListView1)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnregisterListView(ListView1)
End Sub
Public Function ListView1_HeaderEvent(ByVal Action As lvHeaderActions, ByVal Column As Long) As Boolean
If Column = 2 And HideFlag = True Then
ListView1_HeaderEvent = True
End If
End Function
#13
老大,为什么偶取到的
HDN_BeginTrack 竟然=(HDN_FIRST-26) '=-326
而
HDN_EndTrack=(HDN_FIRST-7)
一个是UNICODE,一个是非 UNICODE,晕死,怎么回事啊?
更晕的是,刚刚又试了下,
HDN_EndTrack 竟然也变成了=(HDN_FIRST-27)
正奇怪啊,怎么会变来变去的呢?
HDN_BeginTrack 竟然=(HDN_FIRST-26) '=-326
而
HDN_EndTrack=(HDN_FIRST-7)
一个是UNICODE,一个是非 UNICODE,晕死,怎么回事啊?
更晕的是,刚刚又试了下,
HDN_EndTrack 竟然也变成了=(HDN_FIRST-27)
正奇怪啊,怎么会变来变去的呢?
#14
你看錯了吧?
#15
老大,你上面的CallByName在哪里啊?
#16
直接把代碼COPY到模塊和窗體裏,
沒有用嗎?
我可是測試過的啊。
沒有用嗎?
我可是測試過的啊。
#17
哦,原来是VB6的一个专用函数啊,偶可是VB5的,没有CallByName的
现在偶到是很想知道如何自编代码实现CallByName功能?
不过偶用的不是你上面的代码,偶原来用的是叶老大的机器码捕捉SubClass,
结果得到的HDN_BeginTrack 竟然=(HDN_FIRST-26) ,所以,后来偶直接使用
共用模块中的标准SubClass,这两天NmHdrMsg.code确实是固定了
HDN_BeginTrack =(HDN_FIRST-26)
HDN_EndTrack=(HDN_FIRST-27)
天哪,这可是Unicode中的定义啊,晕死
其它的NmHdrMsg.code都是HDN_ITEMCLICK = (HDN_FIRST - 2)之类的非Unicode定义
而且,实测下来NmHdrMsg.hwndFrom 永远不等于ListView1.hWnd
奇怪,现有的例子中不是都应该相等的吗?
有一点没搞懂,WM_NOTIFY消息到底是在Form1.hWnd 上SubClass,还是在ListView1.hWnd上SubClass?
现在偶到是很想知道如何自编代码实现CallByName功能?
不过偶用的不是你上面的代码,偶原来用的是叶老大的机器码捕捉SubClass,
结果得到的HDN_BeginTrack 竟然=(HDN_FIRST-26) ,所以,后来偶直接使用
共用模块中的标准SubClass,这两天NmHdrMsg.code确实是固定了
HDN_BeginTrack =(HDN_FIRST-26)
HDN_EndTrack=(HDN_FIRST-27)
天哪,这可是Unicode中的定义啊,晕死
其它的NmHdrMsg.code都是HDN_ITEMCLICK = (HDN_FIRST - 2)之类的非Unicode定义
而且,实测下来NmHdrMsg.hwndFrom 永远不等于ListView1.hWnd
奇怪,现有的例子中不是都应该相等的吗?
有一点没搞懂,WM_NOTIFY消息到底是在Form1.hWnd 上SubClass,还是在ListView1.hWnd上SubClass?
#18
//现在偶到是很想知道如何自编代码实现CallByName功能?
这个容易,用tli即可实现
这个容易,用tli即可实现
#19
具体的看这里:
http://www.vbforums.com/showthread.php?referrerid=43870&t=342808
http://www.vbforums.com/showthread.php?referrerid=43870&t=342808
#20
虽然偶看到E文就头大,
但想到既然是老大推荐的,能实现偶要的功能,嗯,再头疼也要看
谢谢老大!
不过还是有一点没搞清楚,现在偶用SubClass ListView1.Parent.hWnd
终于取到了 WM_NOTIFY 但唯独
HDN_BeginTrack =(HDN_FIRST-26)
HDN_EndTrack=(HDN_FIRST-27)
为什么还是这两个?
其它的都是正常的非UNICODE定义的消息
就像 HDN_BEGINDRAG As Long = (HDN_FIRST - 10)
难道不同的机子上会变?
晕晕,先解决CallByName去喽:)
但想到既然是老大推荐的,能实现偶要的功能,嗯,再头疼也要看
谢谢老大!
不过还是有一点没搞清楚,现在偶用SubClass ListView1.Parent.hWnd
终于取到了 WM_NOTIFY 但唯独
HDN_BeginTrack =(HDN_FIRST-26)
HDN_EndTrack=(HDN_FIRST-27)
为什么还是这两个?
其它的都是正常的非UNICODE定义的消息
就像 HDN_BEGINDRAG As Long = (HDN_FIRST - 10)
难道不同的机子上会变?
晕晕,先解决CallByName去喽:)
#21
#1
本身LISTVIEW就没有这个功能。
有和种解决办法就是自动生成列标头。
当需要显示的时候动态用listview.ColumnHeaders.add 来动态增加列标头
有和种解决办法就是自动生成列标头。
当需要显示的时候动态用listview.ColumnHeaders.add 来动态增加列标头
#2
你可以把那列的值存储在 其他的 ColumnHeader.key 属性里 ....
#3
TO hot1kang1(许仙)
首先,每个列标头的Key都有用,没有空的。
其次,即使有空的Key,如何把每行对应的数据存在里面呢?
它是列标头啊,不是行哦:)
To cool_man(土豆) :
光动态增加列标头,没有数据是不行的,
有时候加载列表的数据是没有Key值的,
也就是说只有第一次增加ListItem的时候才能获得全部数据(比如一个动态的查找循环)。
而一旦加载完成,就无法再加载某个子项的数据了,
所以,临时添加数据不可行
(只能一次加载所有数据,再根据需要显示部分列)
看下来,好像系统自己的ListView都有一个自带的列标头编辑器(XP)
在这个编辑器里可以动态调整列标头顺序和是否显示,
怀疑这可能是ListView的一个新样式,因为在WMP里也有这个功能。
不知道我们能否调用它呢?
如果可用的话,几乎不用写代码就获得了完美的列标头编辑功能了,呵呵:)
首先,每个列标头的Key都有用,没有空的。
其次,即使有空的Key,如何把每行对应的数据存在里面呢?
它是列标头啊,不是行哦:)
To cool_man(土豆) :
光动态增加列标头,没有数据是不行的,
有时候加载列表的数据是没有Key值的,
也就是说只有第一次增加ListItem的时候才能获得全部数据(比如一个动态的查找循环)。
而一旦加载完成,就无法再加载某个子项的数据了,
所以,临时添加数据不可行
(只能一次加载所有数据,再根据需要显示部分列)
看下来,好像系统自己的ListView都有一个自带的列标头编辑器(XP)
在这个编辑器里可以动态调整列标头顺序和是否显示,
怀疑这可能是ListView的一个新样式,因为在WMP里也有这个功能。
不知道我们能否调用它呢?
如果可用的话,几乎不用写代码就获得了完美的列标头编辑功能了,呵呵:)
#4
//看下来,好像系统自己的ListView都有一个自带的列标头编辑器(XP)
它是新建列表头办到的,每次更改后重新填充数据
由于资源管理器每次只填充看得见的项目的数据,看不见的项目的数据用另一个线程慢慢添加,所以感觉速度很快
所以还是想办法保存数据、再动态添加吧
它是新建列表头办到的,每次更改后重新填充数据
由于资源管理器每次只填充看得见的项目的数据,看不见的项目的数据用另一个线程慢慢添加,所以感觉速度很快
所以还是想办法保存数据、再动态添加吧
#5
把宽度设为0,然后用子类处理一下列标头的事件
#6
新鲜出炉的代码:
http://rainstormmaster.cnblogs.com/archive/2006/01/20/321050.html
http://rainstormmaster.cnblogs.com/archive/2006/01/20/321050.html
#7
老大,为什么偶总是取不到HDN_BEGINTRACK消息呢?
#8
这个不好说啊,你什么系统?
#9
XP
就照老大的代码,其它都能取到,就是那个不行
就照老大的代码,其它都能取到,就是那个不行
#10
还有,不好意思问一下(偶真的不知道)
Const WM_NCLButtonDown = &HA1
Const HTCaption = 2
ReleaseCapture
SendMessage hWnd, WM_NCLButtonDown, HTCaption, ByVal 0&
能否把以上代码放到TLB中做成一个函数过程?
(不知道TLB中是否只能定义接口?)
还有,哪里有C和B的数据类型对照表?
Const WM_NCLButtonDown = &HA1
Const HTCaption = 2
ReleaseCapture
SendMessage hWnd, WM_NCLButtonDown, HTCaption, ByVal 0&
能否把以上代码放到TLB中做成一个函数过程?
(不知道TLB中是否只能定义接口?)
还有,哪里有C和B的数据类型对照表?
#11
模块代码:
Option Explicit
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Const GWL_WNDPROC As Long = -4
Public Const GWL_STYLE As Long = -16
Public Const WM_NOTIFY As Long = &H4E&
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal wNewWord As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Any, lParam As Any) As Long
Public Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Public Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hWnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Const LVM_FIRST = &H1000
Private Const LVM_GETHEADER = (LVM_FIRST + 31)
Private Type NMHDR
hWndFrom As Long
idfrom As Long
code As Long
End Type
Private Type HD_HITTESTINFO
pt As POINTAPI
flags As Long
iItem As Long
End Type
Private Const HHT_ONHEADER = &H2
Private Const HHT_ONDIVIDER = &H4
Private Const HDM_HITTEST As Long = &H1206
Private Const HDN_FIRST As Long = -300&
Private Const HDN_ITEMCLICK As Long = (HDN_FIRST - 2)
Private Const HDN_DIVIDERDBLCLICK As Long = (HDN_FIRST - 5)
Private Const HDN_BEGINTRACK As Long = (HDN_FIRST - 6)
Private Const HDN_ENDTRACK As Long = (HDN_FIRST - 7)
Private Const HDN_TRACK As Long = (HDN_FIRST - 8)
Private Const HDN_GETDISPINFO As Long = (HDN_FIRST - 9)
Private Const HDN_BEGINDRAG As Long = (HDN_FIRST - 10)
Private Const HDN_ENDDRAG As Long = (HDN_FIRST - 11)
Private Const HDN_ITEMCHANGING As Long = (HDN_FIRST - 0)
Private Const HDN_ITEMCHANGED As Long = (HDN_FIRST - 1)
Private Const HDN_ITEMDBLCLICK As Long = (HDN_FIRST - 3)
Private Const HDN_NM_RCLICK As Long = -5
' 列标头事件
Public Enum lvHeaderActions
lvHeaderActionClick = 1
lvHeaderActionRightClick = 2
lvHeaderActionDividerDoubleClick = 3
lvHeaderActionResizeBegin = 4
lvHeaderActionResizeEnd = 5
lvHeaderActionChanging = 6
lvHeaderActionChanged = 7
lvHeaderActionDragBegin = 8
lvHeaderActionDragEnd = 9
End Enum
Private RegisteredListViewControls As New Collection
Public Sub RegisterListView(ByVal ListViewControl As ListView)
Call SetProp(ListViewControl.hWnd, "OrigWindowProc", GetWindowLong(ListViewControl.hWnd, GWL_WNDPROC))
Call SetWindowLong(ListViewControl.hWnd, GWL_WNDPROC, AddressOf HandleListViewHeaderMsgs)
Call RegisteredListViewControls.Add(ListViewControl, CStr(ListViewControl.hWnd))
End Sub
Public Sub UnregisterListView(ByVal ListViewControl As ListView)
Dim OrigWindowProc As Long
OrigWindowProc = GetProp(ListViewControl.hWnd, "OrigWindowProc")
If (OrigWindowProc <> 0) Then
Call SetWindowLong(ListViewControl.hWnd, GWL_WNDPROC, OrigWindowProc)
End If
Call RegisteredListViewControls.Remove(CStr(ListViewControl.hWnd))
End Sub
Public Function HandleListViewHeaderMsgs(ByVal ListViewhWnd As Long, ByVal msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
Const EVENT_SUFFIX As String = "_HeaderEvent"
Dim ListViewControl As ListView
Dim NmHdrMsg As NMHDR
Dim PointStruct As POINTAPI
Dim HitTestInfo As HD_HITTESTINFO
Dim HeaderhWnd As Long
Dim HeaderAction As lvHeaderActions
Dim CancelMsg As Boolean
If msg = WM_NOTIFY Then
HandleListViewHeaderMsgs = CallWindowProc(GetProp(ListViewhWnd, "OrigWindowProc"), ListViewhWnd, msg, wp, lp)
Call CopyMemory(NmHdrMsg, ByVal lp, Len(NmHdrMsg))
HeaderhWnd = SendMessage(ListViewhWnd, LVM_GETHEADER, 0&, ByVal 0&)
If (HeaderhWnd <> 0) Then
Call GetCursorPos(PointStruct)
Call ScreenToClient(HeaderhWnd, PointStruct)
HitTestInfo.flags = HHT_ONHEADER Or HHT_ONDIVIDER
HitTestInfo.pt = PointStruct
Call SendMessage(HeaderhWnd, HDM_HITTEST, 0&, HitTestInfo)
Select Case NmHdrMsg.code
Case HDN_ITEMCLICK: HeaderAction = lvHeaderActionClick
Case HDN_NM_RCLICK: HeaderAction = lvHeaderActionRightClick
Case HDN_DIVIDERDBLCLICK: HeaderAction = lvHeaderActionDividerDoubleClick
Case HDN_BEGINTRACK: HeaderAction = lvHeaderActionResizeBegin
Case HDN_ENDTRACK: HeaderAction = lvHeaderActionResizeEnd
Case HDN_ITEMCHANGING: HeaderAction = lvHeaderActionChanging
Case HDN_ITEMCHANGED: HeaderAction = lvHeaderActionChanged
Case HDN_BEGINDRAG: HeaderAction = lvHeaderActionDragBegin
Case HDN_ENDDRAG: HeaderAction = lvHeaderActionDragEnd
End Select
If HeaderAction <> 0 Then
On Error Resume Next
Set ListViewControl = RegisteredListViewControls(CStr(ListViewhWnd))
CancelMsg = CallByName(ListViewControl.Parent, ListViewControl.Name & EVENT_SUFFIX, VbCallType.VbMethod, HeaderAction, HitTestInfo.iItem + 1)
On Error GoTo 0
If CancelMsg Then
HandleListViewHeaderMsgs = 1
Exit Function
End If
End If
End If
End If
HandleListViewHeaderMsgs = CallWindowProc(GetProp(ListViewhWnd, "OrigWindowProc"), ListViewhWnd, msg, wp, lp)
End Function
Public Sub ListViewHeaderEventDebugPrint(ByVal ListViewControl As ListView, ByVal Action As lvHeaderActions, ByVal Column As Long)
Dim msg As String
Select Case Action
Case lvHeaderActionClick: msg = "clicked"
Case lvHeaderActionRightClick: msg = "right-clicked"
Case lvHeaderActionDividerDoubleClick: msg = "divider dbl-clicked"
Case lvHeaderActionResizeBegin: msg = "resize begin"
Case lvHeaderActionResizeEnd: msg = "resize end"
Case lvHeaderActionChanging: msg = "changing"
Case lvHeaderActionChanged: msg = "changed"
Case lvHeaderActionDragBegin: msg = "drag begin"
Case lvHeaderActionDragEnd: msg = "drag end"
End Select
Debug.Print ListViewControl.Parent.Name & "." & ListViewControl.Name & ": " & msg & " (col=" & CStr(Column) & ")"
End Sub
Option Explicit
Public Type POINTAPI
X As Long
Y As Long
End Type
Public Const GWL_WNDPROC As Long = -4
Public Const GWL_STYLE As Long = -16
Public Const WM_NOTIFY As Long = &H4E&
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal wNewWord As Long) As Long
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Public Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Any, lParam As Any) As Long
Public Declare Function GetProp Lib "user32" Alias "GetPropA" (ByVal hWnd As Long, ByVal lpString As String) As Long
Public Declare Function SetProp Lib "user32" Alias "SetPropA" (ByVal hWnd As Long, ByVal lpString As String, ByVal hData As Long) As Long
Private Const LVM_FIRST = &H1000
Private Const LVM_GETHEADER = (LVM_FIRST + 31)
Private Type NMHDR
hWndFrom As Long
idfrom As Long
code As Long
End Type
Private Type HD_HITTESTINFO
pt As POINTAPI
flags As Long
iItem As Long
End Type
Private Const HHT_ONHEADER = &H2
Private Const HHT_ONDIVIDER = &H4
Private Const HDM_HITTEST As Long = &H1206
Private Const HDN_FIRST As Long = -300&
Private Const HDN_ITEMCLICK As Long = (HDN_FIRST - 2)
Private Const HDN_DIVIDERDBLCLICK As Long = (HDN_FIRST - 5)
Private Const HDN_BEGINTRACK As Long = (HDN_FIRST - 6)
Private Const HDN_ENDTRACK As Long = (HDN_FIRST - 7)
Private Const HDN_TRACK As Long = (HDN_FIRST - 8)
Private Const HDN_GETDISPINFO As Long = (HDN_FIRST - 9)
Private Const HDN_BEGINDRAG As Long = (HDN_FIRST - 10)
Private Const HDN_ENDDRAG As Long = (HDN_FIRST - 11)
Private Const HDN_ITEMCHANGING As Long = (HDN_FIRST - 0)
Private Const HDN_ITEMCHANGED As Long = (HDN_FIRST - 1)
Private Const HDN_ITEMDBLCLICK As Long = (HDN_FIRST - 3)
Private Const HDN_NM_RCLICK As Long = -5
' 列标头事件
Public Enum lvHeaderActions
lvHeaderActionClick = 1
lvHeaderActionRightClick = 2
lvHeaderActionDividerDoubleClick = 3
lvHeaderActionResizeBegin = 4
lvHeaderActionResizeEnd = 5
lvHeaderActionChanging = 6
lvHeaderActionChanged = 7
lvHeaderActionDragBegin = 8
lvHeaderActionDragEnd = 9
End Enum
Private RegisteredListViewControls As New Collection
Public Sub RegisterListView(ByVal ListViewControl As ListView)
Call SetProp(ListViewControl.hWnd, "OrigWindowProc", GetWindowLong(ListViewControl.hWnd, GWL_WNDPROC))
Call SetWindowLong(ListViewControl.hWnd, GWL_WNDPROC, AddressOf HandleListViewHeaderMsgs)
Call RegisteredListViewControls.Add(ListViewControl, CStr(ListViewControl.hWnd))
End Sub
Public Sub UnregisterListView(ByVal ListViewControl As ListView)
Dim OrigWindowProc As Long
OrigWindowProc = GetProp(ListViewControl.hWnd, "OrigWindowProc")
If (OrigWindowProc <> 0) Then
Call SetWindowLong(ListViewControl.hWnd, GWL_WNDPROC, OrigWindowProc)
End If
Call RegisteredListViewControls.Remove(CStr(ListViewControl.hWnd))
End Sub
Public Function HandleListViewHeaderMsgs(ByVal ListViewhWnd As Long, ByVal msg As Long, ByVal wp As Long, ByVal lp As Long) As Long
Const EVENT_SUFFIX As String = "_HeaderEvent"
Dim ListViewControl As ListView
Dim NmHdrMsg As NMHDR
Dim PointStruct As POINTAPI
Dim HitTestInfo As HD_HITTESTINFO
Dim HeaderhWnd As Long
Dim HeaderAction As lvHeaderActions
Dim CancelMsg As Boolean
If msg = WM_NOTIFY Then
HandleListViewHeaderMsgs = CallWindowProc(GetProp(ListViewhWnd, "OrigWindowProc"), ListViewhWnd, msg, wp, lp)
Call CopyMemory(NmHdrMsg, ByVal lp, Len(NmHdrMsg))
HeaderhWnd = SendMessage(ListViewhWnd, LVM_GETHEADER, 0&, ByVal 0&)
If (HeaderhWnd <> 0) Then
Call GetCursorPos(PointStruct)
Call ScreenToClient(HeaderhWnd, PointStruct)
HitTestInfo.flags = HHT_ONHEADER Or HHT_ONDIVIDER
HitTestInfo.pt = PointStruct
Call SendMessage(HeaderhWnd, HDM_HITTEST, 0&, HitTestInfo)
Select Case NmHdrMsg.code
Case HDN_ITEMCLICK: HeaderAction = lvHeaderActionClick
Case HDN_NM_RCLICK: HeaderAction = lvHeaderActionRightClick
Case HDN_DIVIDERDBLCLICK: HeaderAction = lvHeaderActionDividerDoubleClick
Case HDN_BEGINTRACK: HeaderAction = lvHeaderActionResizeBegin
Case HDN_ENDTRACK: HeaderAction = lvHeaderActionResizeEnd
Case HDN_ITEMCHANGING: HeaderAction = lvHeaderActionChanging
Case HDN_ITEMCHANGED: HeaderAction = lvHeaderActionChanged
Case HDN_BEGINDRAG: HeaderAction = lvHeaderActionDragBegin
Case HDN_ENDDRAG: HeaderAction = lvHeaderActionDragEnd
End Select
If HeaderAction <> 0 Then
On Error Resume Next
Set ListViewControl = RegisteredListViewControls(CStr(ListViewhWnd))
CancelMsg = CallByName(ListViewControl.Parent, ListViewControl.Name & EVENT_SUFFIX, VbCallType.VbMethod, HeaderAction, HitTestInfo.iItem + 1)
On Error GoTo 0
If CancelMsg Then
HandleListViewHeaderMsgs = 1
Exit Function
End If
End If
End If
End If
HandleListViewHeaderMsgs = CallWindowProc(GetProp(ListViewhWnd, "OrigWindowProc"), ListViewhWnd, msg, wp, lp)
End Function
Public Sub ListViewHeaderEventDebugPrint(ByVal ListViewControl As ListView, ByVal Action As lvHeaderActions, ByVal Column As Long)
Dim msg As String
Select Case Action
Case lvHeaderActionClick: msg = "clicked"
Case lvHeaderActionRightClick: msg = "right-clicked"
Case lvHeaderActionDividerDoubleClick: msg = "divider dbl-clicked"
Case lvHeaderActionResizeBegin: msg = "resize begin"
Case lvHeaderActionResizeEnd: msg = "resize end"
Case lvHeaderActionChanging: msg = "changing"
Case lvHeaderActionChanged: msg = "changed"
Case lvHeaderActionDragBegin: msg = "drag begin"
Case lvHeaderActionDragEnd: msg = "drag end"
End Select
Debug.Print ListViewControl.Parent.Name & "." & ListViewControl.Name & ": " & msg & " (col=" & CStr(Column) & ")"
End Sub
#12
窗体上一个listview,两个按钮:
Option Explicit
Dim HideFlag As Boolean, OldWidth As Single
Private Sub Command1_Click()
HideFlag = True
OldWidth = ListView1.ColumnHeaders(2).Width
ListView1.ColumnHeaders(2).Width = 0
End Sub
Private Sub Command2_Click()
HideFlag = False
ListView1.ColumnHeaders(2).Width = OldWidth
End Sub
Private Sub Form_Load()
Command1.Caption = "隐藏第2列"
Command2.Caption = "显示第2列"
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "第1列"
ListView1.ColumnHeaders.Add , , "第2列"
ListView1.ColumnHeaders.Add , , "第3列"
With ListView1.ListItems.Add(, , "d")
.ListSubItems.Add , , "d1"
.ListSubItems.Add , , "d2"
End With
With ListView1.ListItems.Add(, , "e")
.ListSubItems.Add , , "e1"
.ListSubItems.Add , , "e2"
End With
With ListView1.ListItems.Add(, , "f")
.ListSubItems.Add , , "f1"
.ListSubItems.Add , , "f2"
End With
Call RegisterListView(ListView1)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnregisterListView(ListView1)
End Sub
Public Function ListView1_HeaderEvent(ByVal Action As lvHeaderActions, ByVal Column As Long) As Boolean
If Column = 2 And HideFlag = True Then
ListView1_HeaderEvent = True
End If
End Function
Option Explicit
Dim HideFlag As Boolean, OldWidth As Single
Private Sub Command1_Click()
HideFlag = True
OldWidth = ListView1.ColumnHeaders(2).Width
ListView1.ColumnHeaders(2).Width = 0
End Sub
Private Sub Command2_Click()
HideFlag = False
ListView1.ColumnHeaders(2).Width = OldWidth
End Sub
Private Sub Form_Load()
Command1.Caption = "隐藏第2列"
Command2.Caption = "显示第2列"
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "第1列"
ListView1.ColumnHeaders.Add , , "第2列"
ListView1.ColumnHeaders.Add , , "第3列"
With ListView1.ListItems.Add(, , "d")
.ListSubItems.Add , , "d1"
.ListSubItems.Add , , "d2"
End With
With ListView1.ListItems.Add(, , "e")
.ListSubItems.Add , , "e1"
.ListSubItems.Add , , "e2"
End With
With ListView1.ListItems.Add(, , "f")
.ListSubItems.Add , , "f1"
.ListSubItems.Add , , "f2"
End With
Call RegisterListView(ListView1)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnregisterListView(ListView1)
End Sub
Public Function ListView1_HeaderEvent(ByVal Action As lvHeaderActions, ByVal Column As Long) As Boolean
If Column = 2 And HideFlag = True Then
ListView1_HeaderEvent = True
End If
End Function
#13
老大,为什么偶取到的
HDN_BeginTrack 竟然=(HDN_FIRST-26) '=-326
而
HDN_EndTrack=(HDN_FIRST-7)
一个是UNICODE,一个是非 UNICODE,晕死,怎么回事啊?
更晕的是,刚刚又试了下,
HDN_EndTrack 竟然也变成了=(HDN_FIRST-27)
正奇怪啊,怎么会变来变去的呢?
HDN_BeginTrack 竟然=(HDN_FIRST-26) '=-326
而
HDN_EndTrack=(HDN_FIRST-7)
一个是UNICODE,一个是非 UNICODE,晕死,怎么回事啊?
更晕的是,刚刚又试了下,
HDN_EndTrack 竟然也变成了=(HDN_FIRST-27)
正奇怪啊,怎么会变来变去的呢?
#14
你看錯了吧?
#15
老大,你上面的CallByName在哪里啊?
#16
直接把代碼COPY到模塊和窗體裏,
沒有用嗎?
我可是測試過的啊。
沒有用嗎?
我可是測試過的啊。
#17
哦,原来是VB6的一个专用函数啊,偶可是VB5的,没有CallByName的
现在偶到是很想知道如何自编代码实现CallByName功能?
不过偶用的不是你上面的代码,偶原来用的是叶老大的机器码捕捉SubClass,
结果得到的HDN_BeginTrack 竟然=(HDN_FIRST-26) ,所以,后来偶直接使用
共用模块中的标准SubClass,这两天NmHdrMsg.code确实是固定了
HDN_BeginTrack =(HDN_FIRST-26)
HDN_EndTrack=(HDN_FIRST-27)
天哪,这可是Unicode中的定义啊,晕死
其它的NmHdrMsg.code都是HDN_ITEMCLICK = (HDN_FIRST - 2)之类的非Unicode定义
而且,实测下来NmHdrMsg.hwndFrom 永远不等于ListView1.hWnd
奇怪,现有的例子中不是都应该相等的吗?
有一点没搞懂,WM_NOTIFY消息到底是在Form1.hWnd 上SubClass,还是在ListView1.hWnd上SubClass?
现在偶到是很想知道如何自编代码实现CallByName功能?
不过偶用的不是你上面的代码,偶原来用的是叶老大的机器码捕捉SubClass,
结果得到的HDN_BeginTrack 竟然=(HDN_FIRST-26) ,所以,后来偶直接使用
共用模块中的标准SubClass,这两天NmHdrMsg.code确实是固定了
HDN_BeginTrack =(HDN_FIRST-26)
HDN_EndTrack=(HDN_FIRST-27)
天哪,这可是Unicode中的定义啊,晕死
其它的NmHdrMsg.code都是HDN_ITEMCLICK = (HDN_FIRST - 2)之类的非Unicode定义
而且,实测下来NmHdrMsg.hwndFrom 永远不等于ListView1.hWnd
奇怪,现有的例子中不是都应该相等的吗?
有一点没搞懂,WM_NOTIFY消息到底是在Form1.hWnd 上SubClass,还是在ListView1.hWnd上SubClass?
#18
//现在偶到是很想知道如何自编代码实现CallByName功能?
这个容易,用tli即可实现
这个容易,用tli即可实现
#19
具体的看这里:
http://www.vbforums.com/showthread.php?referrerid=43870&t=342808
http://www.vbforums.com/showthread.php?referrerid=43870&t=342808
#20
虽然偶看到E文就头大,
但想到既然是老大推荐的,能实现偶要的功能,嗯,再头疼也要看
谢谢老大!
不过还是有一点没搞清楚,现在偶用SubClass ListView1.Parent.hWnd
终于取到了 WM_NOTIFY 但唯独
HDN_BeginTrack =(HDN_FIRST-26)
HDN_EndTrack=(HDN_FIRST-27)
为什么还是这两个?
其它的都是正常的非UNICODE定义的消息
就像 HDN_BEGINDRAG As Long = (HDN_FIRST - 10)
难道不同的机子上会变?
晕晕,先解决CallByName去喽:)
但想到既然是老大推荐的,能实现偶要的功能,嗯,再头疼也要看
谢谢老大!
不过还是有一点没搞清楚,现在偶用SubClass ListView1.Parent.hWnd
终于取到了 WM_NOTIFY 但唯独
HDN_BeginTrack =(HDN_FIRST-26)
HDN_EndTrack=(HDN_FIRST-27)
为什么还是这两个?
其它的都是正常的非UNICODE定义的消息
就像 HDN_BEGINDRAG As Long = (HDN_FIRST - 10)
难道不同的机子上会变?
晕晕,先解决CallByName去喽:)