ListHBar.bas
资源名称:IE_VB.rar [点击查看]
上传用户:davilee3
上传日期:2015-04-22
资源大小:986k
文件大小:2k
源码类别:
浏览器
开发平台:
Visual Basic
- Attribute VB_Name = "mListHBar"
- Option Explicit
- Private Type nFont
- name As String
- size As Currency
- bold As Boolean
- italic As Boolean
- End Type
- Private Type RECT
- Left As Long
- Top As Long
- Right As Long
- Bottom As Long
- End Type
- Private Declare Function DrawText Lib "user32" Alias "DrawTextA" _
- (ByVal hdc As Long, _
- ByVal lpStr As String, _
- ByVal nCount As Long, _
- lpRect As RECT, _
- ByVal wFormat As Long) As Long
- Private 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 Const LB_SETHORIZONTALEXTENT = &H194
- Private Const DT_CALCRECT = &H400
- Private Function ListTextWidth(ByRef lstThis As ListBox) As Long
- Dim i As Long
- Dim tR As RECT
- Dim lW As Long
- Dim lWidth As Long
- Dim lHDC As Long
- Dim oFont As nFont
- With lstThis.Parent.Font
- oFont.name = .name
- oFont.size = .size
- oFont.bold = .bold
- oFont.italic = .italic
- .name = lstThis.Font.name
- .size = lstThis.Font.size
- .bold = lstThis.Font.bold
- .italic = lstThis.Font.italic
- End With
- lHDC = lstThis.Parent.hdc
- '便历所有的列表项以找到最长的项
- For i = 0 To lstThis.ListCount - 1
- DrawText lHDC, lstThis.List(i), -1, tR, DT_CALCRECT
- lW = tR.Right - tR.Left + 4
- If (lW > lWidth) Then
- lWidth = lW
- End If
- Next i
- '返回最长列表项的长度(像素)
- ListTextWidth = lWidth
- With lstThis.Parent.Font
- .name = oFont.name
- .size = oFont.size
- .bold = oFont.bold
- .italic = oFont.italic
- End With
- End Function
- Public Sub Show_Listbox_HScrollebar(nListbox As ListBox)
- Dim lstLength As Long
- lstLength = ListTextWidth(nListbox)
- SendMessage nListbox.hwnd, LB_SETHORIZONTALEXTENT, lstLength, 0
- End Sub