加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

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

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有