我做的一个程序,用了系统自带控件listview视图为报表视图,怎么使标题不能随用户改变宽度大小.
好像要用sendmessage, 不过我不知道消息类型, 随便用什么语言给个例子就行了. (看到这里人气比较旺)
找了半天终于找到一个VB版的. 发出来共享一下. 版主转移.
Option Explicit
Private Sub Command1_Click()
Call LockHead(ListView1.hwnd)
End Sub
Private Sub Command2_Click()
Call UnLockHead(ListView1.hwnd)
End Sub
Private Sub Form_Load()
Dim i As Long
ListView1.ColumnHeaders.Add , , "asdf", ListView1.Width / 4
ListView1.ColumnHeaders.Add , , "qwre", ListView1.Width / 4
ListView1.ColumnHeaders.Add , , "zxcv", ListView1.Width / 4
For i = 0 To 30
ListView1.ListItems.Add , , CStr(i)
Next i
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 LockHead(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