Subclassing Listview
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Subclassing Listview

  1. #1
    Join Date
    Sep 2011
    Posts
    3

    Subclassing Listview

    I have been trying to subclass my Listview so I can do some custom drawing, but, it seems no matter what I try it glitches out.

    This is my current Code

    Code:
     
    
    Public Function WindowProcChannel(ByVal hwnd As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        On Error Resume Next
        
        If ((uMsg And WM_DRAWITEM) = WM_DRAWITEM) Then
            Dim udtDIS As DRAWITEMSTRUCT
            
            If ((lParam = 0) Or (wParam > 0)) Then
                Exit Function
            End If
            
            Call CopyMemory(udtDIS, ByVal lParam, Len(udtDIS))
            
            Select Case (udtDIS.ItemAction)
                Case ODA_DRAWENTIRE:
                    If (udtDIS.ItemId = -1) Then
                        Exit Function
                    End If
     
                    DrawChannel udtDIS, hwnd
                    Exit Function
            End Select
       ' ElseIf ((uMsg And WM_NOTIFY) = WM_NOTIFY) Then
           ' Dim udtNMHDR As NMHDR
        
            'If ((lParam = 0) Or (wParam > 0)) Then
               ' Exit Function
            'End If
        
            'Call CopyMemory(udtNMHDR, ByVal lParam, LenB(udtNMHDR))
        
            'Select Case (udtNMHDR.code)
               ' Case LVN_BEGINDRAG:  Exit Function
               ' Case LVN_BEGINRDRAG: Exit Function
           ' End Select
        End If
    
        WindowProcChannel = CallWindowProc(hWnd_Config, hwnd, uMsg, wParam, lParam)
    End Function
    
    Public Sub DrawChannel(ByRef udtDIS As DRAWITEMSTRUCT, hwnd As Long)
        Dim uRECT   As RECT
        Dim hDC     As Long
        
        Dim Index As Integer
        
        Dim Brush As Long
        Dim Pen As Long
        
        Dim PingPOS As Long
            PingPOS = 180
        Index = udtDIS.ItemId + 1
        
         With uRECT
            .Top = udtDIS.rcItem.Top
            .Bottom = udtDIS.rcItem.Bottom
            .Left = udtDIS.rcItem.Left
            .Right = udtDIS.rcItem.Right + 100
        End With
        
        
        Brush = CreateSolidBrush(vbBlack)
            
        DrawFocusRect udtDIS.hDC, uRECT
        
        FillRect udtDIS.hDC, uRECT, Brush
            
        DeleteObject Brush
        
        
         With udtDIS.rcItem
            .Left = (udtDIS.rcItem.Left + 1)
            .Top = (udtDIS.rcItem.Top + 1)
        End With
        
        If frmMain.lvChannel(View).ListItems.Count > SendMessage(frmMain.lvChannel(View).hwnd, LVM_GETCOUNTPERPAGE, 0&, ByVal 0&) Then
            PingPOS = 160
            
        Else
            PingPOS = 180
            
        End If
         
        hDC = CreateCompatibleDC(udtDIS.hDC)
       
        SelectObject hDC, frmMain.ClientImages.ListImages(PickIcon(Profiles.Profile(View).Channel.User(Index).Product, Profiles.Profile(View).Channel.User(Index).Flags)).Picture.Handle
        BitBlt udtDIS.hDC, udtDIS.rcItem.Left, udtDIS.rcItem.Top, 36, 17, hDC, 0, 0, vbSrcCopy
        
        With uRECT
            .Left = (udtDIS.rcItem.Left + 40)
            .Right = udtDIS.rcItem.Right
            .Top = udtDIS.rcItem.Top + 2
            .Bottom = (udtDIS.rcItem.Top + 17)
        End With
        
        'draw the Username
        
        SetTextColor udtDIS.hDC, PickColor(Profiles.Profile(View).Channel.User(Index).Product, Profiles.Profile(View).Channel.User(Index).Flags)
        DrawText udtDIS.hDC, Profiles.Profile(View).Channel.User(Index).Username, Len(Profiles.Profile(View).Channel.User(Index).Username), uRECT, (DT_VCENTER Or DT_LEFT)
        
         'Draw the PING ICON
        
        SelectObject hDC, frmMain.ClientImages.ListImages(GetLag(Profiles.Profile(View).Channel.User(Index).Ping, Profiles.Profile(View).Channel.User(Index).Flags)).Picture.Handle
        BitBlt udtDIS.hDC, PingPOS, udtDIS.rcItem.Top, 35, 17, hDC, 0, 0, vbSrcCopy
        
        If (udtDIS.ItemState And ODS_SELECTED) Then
            
            Brush = SelectObject(udtDIS.hDC, GetStockObject(NULL_BRUSH))
            Pen = SelectObject(udtDIS.hDC, CreatePen(0, 1, vbBotNet))
            
            Rectangle udtDIS.hDC, udtDIS.rcItem.Left, udtDIS.rcItem.Top, udtDIS.rcItem.Right, udtDIS.rcItem.Bottom
            
            DeleteDC Brush
            DeleteDC Pen
        Else
            Brush = SelectObject(udtDIS.hDC, GetStockObject(NULL_BRUSH))
            Pen = SelectObject(udtDIS.hDC, CreatePen(0, 1, vbBlack))
            
            Rectangle udtDIS.hDC, udtDIS.rcItem.Left, udtDIS.rcItem.Top, udtDIS.rcItem.Right, (udtDIS.rcItem.Top + 17)
            
            DeleteDC Brush
            DeleteDC Pen
        End If
       
    
        DeleteDC hDC
    End Sub
    It's a bit sloppy now, but its just some trail and error coding, maybe I can get some insight on what i'm doing wrong?

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    15,002

    Re: Subclassing Listview

    Explain what you even *think* you're trying to do... Really can't tell if it's good, evil, or what?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Subclassing Listview

    Subclassing is always difficult to debug.
    You should at least describe what kind of "glitching" happens, and if you had tried to determine in which part/line of the program it happens.

  4. #4
    Join Date
    Sep 2011
    Posts
    3

    Re: Subclassing Listview

    Soo, in response, the glitching happens when all of a sudden i add multiple entry's at once.

    or, I scroll thought the list. Seems that the Listview either lags out, and "glitches", or for some reason im not getting the drawing messages anymore.

    Basically What i really want to ask is if I am Subclassing the listview correctly. to grab the event of an entry being added or removed or edited.

  5. #5
    Join Date
    Sep 2011
    Posts
    3

    Re: Subclassing Listview

    I cant find where to edit the post but, It happens in the draw function, im going to assume when im drawing, im not doing it right, or something.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center