当用API改变listview的列头为扁平后,他就不能响应ColumnClick事件了,有没有解决办法?
Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ?1996-2005 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Const HDS_BUTTONS As Long = &H2
Private Const LVM_FIRST As Long = &H1000
Private Const LVM_GETHEADER As Long = (LVM_FIRST + 31)
Private Const GWL_STYLE As Long = (-16)
Private Const SWP_DRAWFRAME As Long = &H20
Private Const SWP_NOMOVE As Long = &H2
Private Const SWP_NOSIZE As Long = &H1
Private Const SWP_NOZORDER As Long = &H4
Private Const SWP_FLAGS As Long = SWP_NOZORDER Or _
SWP_NOSIZE Or _
SWP_NOMOVE Or _
SWP_DRAWFRAME
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" _
Alias "SetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As Long, _
ByVal x As Long, ByVal Y As Long, _
ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As Long) As Long
Private Sub Form_Load()
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "main"
ListView1.ColumnHeaders.Add , , "sub1"
ListView1.ColumnHeaders.Add , , "sub2"
ListView1.ListItems.Add , "test1", "test1"
ListView1.ListItems("test1").SubItems(1) = "test1-1"
ListView1.ListItems("test1").SubItems(2) = "test1-2"
ListView1.ListItems.Add , "test2", "test2"
ListView1.ListItems("test2").SubItems(1) = "test2-1"
ListView1.ListItems("test2").SubItems(2) = "test2-2"
ListView1.FullRowSelect = True
End Sub
Private Sub ListView1_ColumnClick(ByVal ColumnHeader As MSComctlLib.ColumnHeader)
MsgBox "FF"
End Sub
Private Sub Check1_Click()
Dim style As Long
Dim hHeader As Long
'get the handle to the listview header
hHeader = SendMessage(ListView1.hwnd, LVM_GETHEADER, 0, ByVal 0&)
'get the current style attributes for the header
style = GetWindowLong(hHeader, GWL_STYLE)
'modify the style by toggling the HDS_BUTTONS style
style = style Xor HDS_BUTTONS
'set the new style and redraw the listview
If style Then
Call SetWindowLong(hHeader, GWL_STYLE, style)
Call SetWindowPos(ListView1.hwnd, Form1.hwnd, 0, 0, 0, 0, SWP_FLAGS)
End If
End Sub
相关推荐
LVColHeader.rar_ListView
**ColumnClick事件**: 当用户单击ListView控件的列头时,该事件被触发。这通常是用来实现按所点击的列进行数据排序的关键。
VC++ MFC类库中文手册实战指南:从核心架构到高级编程
在Windows桌面开发领域,应用程序框架是构建原生界面的核心基础。MFC(Microsoft Foundation Classes)作为经典的C++框架,通过文档-视图架构和消息映射机制,实现了数据与界面的高效分离。其技术价值在于为高性能、高稳定性的工业控制、金融交易等专业领域提供了坚实的开发基础。理解MFC的运行时类信息、序列化等机制,对于维护海量遗留系统和深入掌握Windows平台编程思想至关重要。本文聚焦于**MFC核心架构**与**高级编程实战**,通过系统化的中文指南,帮助开发者解决实际开发中的
WIN32汇编 listview排序源码
**ListView排序机制** 在Windows API中,ListView的排序功能通常是通过响应LVN_COLUMNCLICK通知来实现的。
vb6源码:ListView控件应用报表(有多种排列方式).rar
**列排序**:通过处理ListView的ColumnClick事件,可以实现在用户点击列头时按指定列进行升序或降序排序。这涉及到比较函数和数组操作,以便重新排序列表项。3.
MULTISORT_LISTVIEW.rar_ListView_ListView Visual C++_MULTISORT_LI
**响应排序事件**:用户通常通过点击列标题来触发排序。开发者需要捕获这一事件,通常是WM_NOTIFY消息,其中包含了LVN_COLUMNCLICK通知代码。2.


控件
