Caption = "This sample program uses VB Messenger to trap the WM_DRAWITEM message that gets sent to the form (the parent of the list box) and draws a picture with text for each item. This sample also uses the Windows API extensively."
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
ForeColor = &H00FF0000&
Height = 1035
Left = 180
TabIndex = 5
Top = 3450
Width = 3435
End
Begin Label Label2
BackStyle = 0 'Transparent
Caption = "When an item in the list box needs to be drawn (i.e., because of a repaint or if focus or the selection has changed), Windows sends the parent control (or form) a WM_DRAWITEM message. With that message comes a pointer to a data structure (or Type) that contains all the information needed to draw the item (such as the rectangle in which to draw it)"
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
ForeColor = &H00FF0000&
Height = 1665
Left = 180
TabIndex = 4
Top = 1680
Width = 3435
End
Begin Label Label1
BackStyle = 0 'Transparent
Caption = "This sample program uses VB Messenger to display an owner-draw list box. Owner-draw means that all drawing of text and/or pictures that appear in the list box is drawn by the programmer, rather than automatically handled by the list box itself."
FontBold = 0 'False
FontItalic = 0 'False
FontName = "MS Sans Serif"
FontSize = 8.25
FontStrikethru = 0 'False
FontUnderline = 0 'False
ForeColor = &H00FF0000&
Height = 1170
Left = 180
TabIndex = 3
Top = 360
Width = 3435
WordWrap = -1 'True
End
End
Begin ListBox lstOwnerDraw
Height = 2175
Left = 180
TabIndex = 0
Top = 210
Width = 3495
End
Option Explicit
Sub Command1_Click ()
End
End Sub
Sub DrawItem (lpdis As DRAWITEMSTRUCT)
Dim rc&
Dim lpstr$
Dim hdcSource%, cx%, cy%
Dim cSelBack&
'If no items in list box yet, indicate focus for
'specified rectangle
If (lpdis.itemID = -1) Then
DrawFocusRect lpdis.hDC, lpdis.rcItem
Exit Sub
End If
'If Windows wants us to draw the entire item of just change
'the selection state, we do this stuff
If (lpdis.itemAction And ODA_DRAWENTIRE) Or (lpdis.itemAction And ODA_SELECT) Then
'If the item it is selected, fill in the rectangle
'with the system color for highlight. If not selected,
'fill the rectangle with the standard window color.