-
September 25th, 2011, 10:14 PM
#1
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?
-
September 26th, 2011, 12:01 AM
#2
Re: Subclassing Listview
Explain what you even *think* you're trying to do... Really can't tell if it's good, evil, or what?
-
September 26th, 2011, 11:14 AM
#3
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.
-
October 2nd, 2011, 05:13 PM
#4
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.
-
October 2nd, 2011, 05:15 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|