Results 1 to 7 of 7

Thread: [RESOLVED] rerstrict event on hedaer column of listview

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    2,393

    Resolved [RESOLVED] rerstrict event on hedaer column of listview

    I need to check, with mousemove event, if the cursor is on header of each column of listview, and get the name of column name...
    possible?

  2. #2
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    3,499

    Re: rerstrict event on hedaer column of listview

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    2,393

    Re: rerstrict event on hedaer column of listview

    tks bro.
    but wath is the correct code tread?

    This peraphs?
    https://www.vbforums.com/showthread....=1#post1806168

  4. #4
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    3,603

    Re: rerstrict event on hedaer column of listview

    You don't get VB MouseMove events on the Column Headers themselves; the linked code above will only tell you the column of the ListItem you're on. I don't think it can be done without subclassing.

    In module:
    Code:
    Public hHdr As Long
    
    Public Function Subclass2(hWnd As Long, lpFN As Long, Optional uId As Long = 0&, Optional dwRefData As Long = 0&) As Boolean
    If uId = 0 Then uId = hWnd
        Subclass2 = SetWindowSubclass(hWnd, lpFN, uId, dwRefData):      Debug.Assert Subclass2
    End Function
    
    Public Function UnSubclass2(hWnd As Long, ByVal lpFN As Long, pid As Long) As Boolean
        UnSubclass2 = RemoveWindowSubclass(hWnd, lpFN, pid)
    End Function
    
    Public Function HDRWndProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long, ByVal uIdSubclass As Long, ByVal dwRefData As Long) As Long
    
    Select Case uMsg
               
        Case WM_MOUSEMOVE
            Dim hti As HDHITTESTINFO
            Dim pt As POINTAPI
            GetCursorPos pt
            ScreenToClient hHdr, pt
            hti.pt.x = pt.x: hti.pt.y = pt.y
            SendMessage hHdr, HDM_HITTEST, 0&, hti
            If (hti.Flags And HHT_ONHEADER) = HHT_ONHEADER Then
                If hti.iItem >= 0& Then Debug.Print "Current column (" & hti.iItem & ")=" & Form1.ListView1.ColumnHeaders(hti.iItem + 1).Text
            End If
        
        Case WM_DESTROY
            Call UnSubclass2(hWnd, PtrHDRWndProc, uIdSubclass)
    End Select
    HDRWndProc = DefSubclassProc(hWnd, uMsg, wParam, lParam)
    End Function
    Public Function PtrHDRWndProc() As Long
    PtrHDRWndProc = FARPROC(AddressOf HDRWndProc)
    End Function
    Public Function FARPROC(pfn As Long) As Long
      FARPROC = pfn
    End Function
    In the form after you added the columns and put it in report view, you'd subclass it with

    Code:
    hHdr = SendMessage(ListView1.hWnd, LVM_GETHEADER, 0&, ByVal 0&)
    
    Subclass2 hHdr, AddressOf HDRWndProc, hHdr
    API declares:

    Code:
    Public Declare Function DefSubclassProc Lib "comctl32.dll" Alias "#413" (ByVal hWnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Public Declare Function SetWindowSubclass Lib "comctl32.dll" Alias "#410" (ByVal hWnd As Long, ByVal pfnSubclass As Long, ByVal uIdSubclass As Long, Optional ByVal dwRefData As Long) As Long
    Public Declare Function RemoveWindowSubclass Lib "comctl32.dll" Alias "#412" (ByVal hWnd As Long, ByVal pfnSubclass As Long, ByVal uIdSubclass As Long) As Long
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As Any) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As Any) As Long
    
    Public Type POINTAPI
        x As Long
        y As Long
    End Type
    Public Const LVM_FIRST = &H1000
    Public Const LVM_GETHEADER = (LVM_FIRST + 31)
    Public Enum HeaderHitTestFlags
        HHT_NOWHERE = &H1
        HHT_ONHEADER = &H2
        HHT_ONDIVIDER = &H4
        HHT_ONDIVOPEN = &H8
    '#if (_WIN32_IE >= =&h0500)
        HHT_ONFILTER = &H10
        HHT_ONFILTERBUTTON = &H20
    '#End If
        HHT_ABOVE = &H100
        HHT_BELOW = &H200
        HHT_TORIGHT = &H400
        HHT_TOLEFT = &H800
    '#if _WIN32_WINNT >= =&h0600
        HHT_ONITEMSTATEICON = &H1000
        HHT_ONDROPDOWN = &H2000
        HHT_ONOVERFLOW = &H4000
    End Enum
    Public Type HDHITTESTINFO
        pt As POINTAPI
        Flags As HeaderHitTestFlags
        iItem As Long
    End Type
    Public Const HDM_FIRST As Long = &H1200
    Public Const HDM_HITTEST = (HDM_FIRST + 6)
    
    Public Const WM_DESTROY = &H2
    Public Const WM_MOUSEMOVE = &H200

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    2,393

    Re: rerstrict event on hedaer column of listview

    Quote Originally Posted by luca90 View Post
    tks bro.
    but wath is the correct code tread?

    This peraphs?
    https://www.vbforums.com/showthread....=1#post1806168
    HI faf.
    you suggest to add during i add via code the columns:

    hHdr = SendMessage(ListView1.hWnd, LVM_GETHEADER, 0&, ByVal 0&)

    Subclass2 hHdr, AddressOf HDRWndProc, hHdr

    but i just have set the column directlly via property custom of listview...

    is this required to add column via code?

  6. #6

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Location
    Italy-Napoli
    Posts
    2,393

    Re: [RESOLVED] rerstrict event on hedaer column of listview

    Tks faf

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width