CSDN博客

img yinweihong

LockListViewHead

发表于2004/9/27 2:28:00  799人阅读

Option Explicit
Private Sub Command1_Click()
    Call LockListViewHead(ListView1.hwnd)
End Sub
Private Sub Command2_Click()
    Call UnLockHead(ListView1.hwnd)
End Sub
Private Sub Form_Load()
Dim i As Long
    ListView1.View = 3
    ListView1.ColumnHeaders.Add , , "asdf", ListView1.Width / 3
    ListView1.ColumnHeaders.Add , , "qwre", ListView1.Width / 3
    ListView1.ColumnHeaders.Add , , ".......", ListView1.Width / 3
End Sub
Option Explicit
Public Type NMHDR
    hwndFrom As Long
    idFrom As Long
    code As Long
End Type
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length 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 Const GWL_WNDPROC = (-4)
Public Const WM_NOTIFY = &H4E
Public Const HDN_FIRST = -300
Public Const HDN_DIVIDERDBLCLICKA = HDN_FIRST - 5
Public Const HDN_DIVIDERDBLCLICKW = HDN_FIRST - 25
Public Const HDN_BEGINTRACKA = HDN_FIRST - 6
Public Const HDN_BEGINTRACKW = HDN_FIRST - 26
Private lpPrevWndFunc  As Long
Public Function WindowProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Select Case uMsg
      Case WM_NOTIFY
        Dim x As NMHDR
        CopyMemory x, ByVal lParam, Len(x)
        If x.code = HDN_BEGINTRACKA Or x.code = HDN_BEGINTRACKW Or _
           x.code = HDN_DIVIDERDBLCLICKA Or _
           x.code = HDN_DIVIDERDBLCLICKW Then
            WindowProc = 1
            Exit Function
        End If
    End Select
    WindowProc = CallWindowProc(lpPrevWndFunc, hwnd, uMsg, wParam, lParam)
End Function
Public Sub LockListViewHead(ByVal hwnd As Long)
    lpPrevWndFunc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindowProc)
End Sub
Public Sub UnLockHead(ByVal hwnd As Long)
    SetWindowLong hwnd, GWL_WNDPROC, lpPrevWndFunc
End Sub
阅读全文
0 0

相关文章推荐

img
取 消
img