下面的函數(shù)將返回控件能顯示的行數(shù)。
Function GetVisibleLines(CTextBox As TextBox) As Long
Dim rc As RECT
Dim hDC&, lfont&, oldfont&
Dim di&, lc&
Dim tm As TEXTMETRIC
lc = SendMessage(CTextBox.hwnd, EM_GETRECT, 0, rc)
lfont = SendMessage(CTextBox.hwnd, WM_GETFONT, 0, 0)
hDC = GetDC(CTextBox.hwnd)
If lfont <> 0 Then oldfont = SelectObject(hDC, lfont)
di = GetTextMetrics(hDC, tm)
If lfont <> 0 Then lfont = SelectObject(hDC, oldfont)
GetVisibleLines = (rc.bottom - rc.top) / tm.tmHeight
di = ReleaseDC(CTextBox.hwnd, hDC)
End Function
下面的函數(shù)能夠滾動(dòng)控件,不過在滾動(dòng)之前最好判斷控件的文本行數(shù)和能夠顯示的行數(shù),以免滾動(dòng)時(shí)發(fā)生混亂。函數(shù)SendMessageBynum是一個(gè)SendMessage函數(shù)的安全聲明函數(shù),其定義與SendMessage函數(shù)完全相同,只是函數(shù)名不同。
Function ScrollTextBox(CTextBox As TextBox, nVal As Long, Optional nVertical As Boolean = True) As Long
If nVertical Then
ScrollTextBox = SendMessageBynum(CTextBox.hwnd, EM_LINESCROLL, 0, nVal)
Else
ScrollTextBox = SendMessageBynum(CTextBox.hwnd, EM_LINESCROLL, nVal, 0)
End If
End Function
下面的函數(shù)能夠返回控件指定行的文本。SendMessageBystring與SendMessageBynum類似。
Function GetLineText(CTextBox As TextBox, LineIndex As Long) As String
Dim lc&, linechar&
linechar = SendMessageBynum(CTextBox.hwnd, EM_LINEINDEX, LineIndex, 0)
lc = SendMessageBynum(CTextBox.hwnd, EM_LINELENGTH, linechar, 0) + 1
GetLineText = String$(lc + 2, 0)
Mid$(GetLineText, 1, 1) = Chr(lc And &HFF)
Mid$(GetLineText, 2, 1) = Chr(lc \ &H100)
lc = SendMessageBystring(CTextBox.hwnd, EM_GETLINE, LineIndex, GetLineText)
GetLineText = left(GetLineText, lc)
End Function
下面的函數(shù)可以設(shè)置控件的左邊距。
Public Const EM_SETMARGINS& = &HD3
Public Const EC_LEFTMARGIN& = &H1
Function SetMargins(CTextBox As TextBox, nVal As Long) As Long
SetMargins = SendMessageBynum(CTextBox.hwnd, EM_SETMARGINS, EC_LEFTMARGIN, nVal)
End Function
相關(guān)推薦:2010年9月計(jì)算機(jī)等級考試成績查詢時(shí)間匯總
北京 | 天津 | 上海 | 江蘇 | 山東 |
安徽 | 浙江 | 江西 | 福建 | 深圳 |
廣東 | 河北 | 湖南 | 廣西 | 河南 |
海南 | 湖北 | 四川 | 重慶 | 云南 |
貴州 | 西藏 | 新疆 | 陜西 | 山西 |
寧夏 | 甘肅 | 青海 | 遼寧 | 吉林 |
黑龍江 | 內(nèi)蒙古 |