VB 固定listview的列宽,不让列宽改变
(2017-01-01 12:48:08)
标签:
vb固定listview的列宽 |
分类: VB |
'用子类化截取列改变的消息,吃掉,就行了
'===================
'模块
''禁止 Call
LockHead(ListView1.hwnd)
'允许 Call
UnLockHead(ListView1.hwnd)
'===================
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
前一篇:java初学笔记(二)
后一篇:vb 热键和笨方法与好方法