|
Public Sub Listbox_Paint()
Dim fntMetrics As TEXTMETRIC
Dim recPos As RECT
Dim hdcLst As Long
Dim lngItem As Long
Dim hdlNewFont As Long
Dim hdlOldFont As Long
Dim hdlNewPen As Long
Dim hdlOldPen As Long
Dim hdlNewBrush As Long
Dim hdlOldBrush As Long
Dim lngBold As Long
Dim lngColor As Long
Dim lngBkColor As Long
hdcLst = GetDC(Me.lstColor.hwnd)
GetTextMetrics hdcLst, fntMetrics
If Me.lstColor.Font.Bold Then
lngBold = 700
Else
lngBold = 400
End If
With fntMetrics
hdlNewFont = CreateFont(-MulDiv(Me.lstColor.Font.Size, _
GetDeviceCaps(hdcLst, LOGPIXELSY), 72), 0, _
0, 0, lngBold, .tmItalic, .tmUnderlined, .tmStruckOut, _
.tmCharSet, 4, &H10, 2, .tmPitchAndFamily, _
Me.lstColor.Font.Name)
End With
hdlOldFont = SelectObject(hdcLst, hdlNewFont)
For lngItem = 0 To Me.lstColor.ListCount - 1
If Not Me.lstColor.Selected(lngItem) Then
SendMessage Me.lstColor.hwnd, LB_GETITEMRECT, lngItem, _
VarPtr(recPos)
lngColor = TranslateSystemColor(MlngLstColor(lngItem))
lngBkColor = TranslateSystemColor(MlngLstBKColor(lngItem))
If Me.chkBkColor.Value = 1 Then
hdlNewPen = CreatePen(PS_SOLID, 1, lngBkColor)
hdlOldPen = SelectObject(hdcLst, hdlNewPen)
hdlNewBrush = CreateSolidBrush(lngBkColor)
hdlOldBrush = SelectObject(hdcLst, hdlNewBrush)
Rectangle hdcLst, recPos.Left, recPos.Top, recPos.Right, _
recPos.Bottom
SelectObject hdcLst, hdlOldBrush
SelectObject hdcLst, hdlOldPen
DeleteObject hdlNewPen
DeleteObject hdlNewBrush
End If
SetBkColor hdcLst, lngBkColor
SetTextColor hdcLst, lngColor
TextOut hdcLst, 2 + recPos.Left, recPos.Top, _
Me.lstColor.List(lngItem) & " ", _
Len(Me.lstColor.List(lngItem)) + 1
End If
Next lngItem
SelectObject hdcLst, hdlOldFont
DeleteObject hdlNewFont
ReleaseDC Me.lstColor.hwnd, hdcLst
End Sub
|
|